@kanonak-protocol/sdk 3.78.0 → 4.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 (38) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/canonical/CanonicalHash.d.ts +8 -0
  3. package/dist/canonical/Datatypes.d.ts +98 -0
  4. package/dist/canonical/index.d.ts +2 -1
  5. package/dist/{chunk-RVOMWGIN.js → chunk-4OSNT57C.js} +1 -1
  6. package/dist/{chunk-KXVSGB6Q.js → chunk-6I4BYZVA.js} +1 -1
  7. package/dist/{chunk-Z5ELOT2C.js → chunk-NC3FSY3R.js} +1 -1
  8. package/dist/{chunk-XQS5LDSO.js → chunk-PBNVHBS3.js} +1 -1
  9. package/dist/chunk-T3JR2SV6.js +1 -0
  10. package/dist/{chunk-QXFO6X6V.js → chunk-V3YPCUA6.js} +1 -1
  11. package/dist/chunk-VNKX52D5.js +2 -0
  12. package/dist/chunk-WUAKDYY6.js +1 -0
  13. package/dist/{chunk-IOMNZBK4.js → chunk-XYEY6HUC.js} +1 -1
  14. package/dist/{chunk-LKBG2MK6.js → chunk-YCV4H6H5.js} +1 -1
  15. package/dist/{chunk-PJMOM5H7.js → chunk-YI5GLYMB.js} +1 -1
  16. package/dist/{chunk-ATH6636H.js → chunk-YWUKDEZA.js} +1 -1
  17. package/dist/{chunk-XWRVENU6.js → chunk-ZRMF5QLN.js} +1 -1
  18. package/dist/chunk-ZYAABYDS.js +1 -0
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.js +26 -26
  21. package/dist/kanonaks/LiteralKanonak.d.ts +4 -0
  22. package/dist/parsing/KanonakObjectParser.d.ts +13 -0
  23. package/dist/parsing/index.js +1 -1
  24. package/dist/reasoning/index.js +1 -1
  25. package/dist/repositories/browser.js +1 -1
  26. package/dist/repositories/index.js +1 -1
  27. package/dist/resolution/index.js +1 -1
  28. package/dist/search/index.js +1 -1
  29. package/dist/server/index.js +1 -1
  30. package/dist/statements/ScalarStatement.d.ts +14 -0
  31. package/dist/transformations/index.js +1 -1
  32. package/dist/uri-helpers/index.js +1 -1
  33. package/dist/validation/index.js +1 -1
  34. package/package.json +2 -2
  35. package/dist/chunk-GIYURKX6.js +0 -2
  36. package/dist/chunk-IUZZDC2U.js +0 -1
  37. package/dist/chunk-TJPQETHV.js +0 -1
  38. package/dist/chunk-W6T7MOKY.js +0 -1
@@ -1 +1 @@
1
- import{d as v}from"./chunk-LKBG2MK6.js";import{a as A}from"./chunk-4NO7MHS7.js";import{a as f}from"./chunk-TJPQETHV.js";import{c as w,d as I,h as R,i as F}from"./chunk-2ACBWC7K.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";import{VersionOperator as P}from"@kanonak-protocol/types/document/models/enums";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=c.resolve(e),this.recursive=t,this.parser=n??new f,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=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.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(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;switch(t.versionOperator){case P.Exact:return I(r,t.version);case P.Compatible:return R(r,t.version);case P.Major:return F(r,t.version);case P.Any:return w(r,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return w(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],p=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,p)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.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 r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,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 o=b(n).toString(),s;for(let[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return b(t).toString()}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 i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as d from"fs";var S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;d.existsSync(e)||d.mkdirSync(e,{recursive:!0}),d.existsSync(t)||d.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}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 o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}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),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,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 _}from"os";import{join as N}from"path";function g(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||N(_(),".kanonak","packages")}var C=class u{static createComposite(e,t,n){let o=e??g(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=g(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{readFileSync as B,readdirSync as H}from"fs";import{join as x}from"path";var $=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function K(u,e=[]){for(let t of H(u,{withFileTypes:!0}))t.isDirectory()?$.has(t.name)||K(x(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(x(u,t.name));return e}async function j(u,e=new f,t={}){let n=new A(e);for(let m of K(u))try{let l=e.parse(B(m,"utf-8")),h=l.metadata?.namespace_,p=h?.version;h&&p&&await n.saveDocumentAsync(l,`${h.publisher}/${h.package_}@${p.major}.${p.minor}.${p.patch}`)}catch{}let o=new y(g(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,l,h)=>s.get(`${m}|${l}|${h}`)??null,onFetch:(m,l,h,p)=>{s.set(`${m}|${l}|${h}`,p)}},r=new v({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,S as b,k as c,g as d,C as e,D as f,K as g,j as h};
1
+ import{d as v}from"./chunk-YCV4H6H5.js";import{a as A}from"./chunk-4NO7MHS7.js";import{a as f}from"./chunk-ZYAABYDS.js";import{c as w,d as I,h as R,i as F}from"./chunk-2ACBWC7K.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";import{VersionOperator as P}from"@kanonak-protocol/types/document/models/enums";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=c.resolve(e),this.recursive=t,this.parser=n??new f,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=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.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(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;switch(t.versionOperator){case P.Exact:return I(r,t.version);case P.Compatible:return R(r,t.version);case P.Major:return F(r,t.version);case P.Any:return w(r,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return w(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],p=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,p)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.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 r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,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 o=b(n).toString(),s;for(let[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return b(t).toString()}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 i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as d from"fs";var S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;d.existsSync(e)||d.mkdirSync(e,{recursive:!0}),d.existsSync(t)||d.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}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 o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}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),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,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 _}from"os";import{join as N}from"path";function g(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||N(_(),".kanonak","packages")}var C=class u{static createComposite(e,t,n){let o=e??g(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=g(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{readFileSync as B,readdirSync as H}from"fs";import{join as x}from"path";var $=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function K(u,e=[]){for(let t of H(u,{withFileTypes:!0}))t.isDirectory()?$.has(t.name)||K(x(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(x(u,t.name));return e}async function j(u,e=new f,t={}){let n=new A(e);for(let m of K(u))try{let l=e.parse(B(m,"utf-8")),h=l.metadata?.namespace_,p=h?.version;h&&p&&await n.saveDocumentAsync(l,`${h.publisher}/${h.package_}@${p.major}.${p.minor}.${p.patch}`)}catch{}let o=new y(g(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,l,h)=>s.get(`${m}|${l}|${h}`)??null,onFetch:(m,l,h,p)=>{s.set(`${m}|${l}|${h}`,p)}},r=new v({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,S as b,k as c,g as d,C as e,D as f,K as g,j as h};
@@ -1,4 +1,4 @@
1
- import{a as Fn}from"./chunk-4NO7MHS7.js";import{a as Mn}from"./chunk-PEJALHXK.js";import{d as u}from"./chunk-SHDHMKMJ.js";import{a as x,c as xe,f as An}from"./chunk-IUZZDC2U.js";import{a as Vn}from"./chunk-TJPQETHV.js";import{a as pn,b as ue,c as xn,d as w,f as Pe,g as ke,j as gn,k as qe,m as Pn,n as Nn}from"./chunk-XQS5LDSO.js";import{b as Oe,c as G,d as E,g as X,h as me,i as re,j as T,k as H,l as V}from"./chunk-W6T7MOKY.js";import{a as Tn}from"./chunk-FUUTGGJS.js";import{c as en,g as $e}from"./chunk-2ACBWC7K.js";var Ve="kanonak.org",zn="look",We="core-rdf",Kt={publisher:Ve,package_:zn,name:"displayLabel"},Rt={publisher:Ve,package_:zn,name:"displaySummary"},Lt={publisher:Ve,package_:We,name:"type"},Ot={publisher:Ve,package_:We,name:"subClassOf"},Ut={publisher:Ve,package_:We,name:"label"},It={publisher:Ve,package_:We,name:"comment"},Dn=new Tn(Ve,We,"Resource");function D(r,e){let n=Bn(r,e,Kt)??Ut,t=Bn(r,e,Rt)??It,a=gn(e,n)??e.name,s=gn(e,t);return{label:a,summary:s}}function Bn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Hn(e,Lt);for(;s.length>0;){let o=s.shift(),i=pn(o);if(a.has(i))continue;a.add(i);let c=Pe(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Hn(c,Ot))}if(!a.has(pn(Dn))){let o=Pe(r,Dn);if(o){let i=qe(o,n);if(i)return i}}}function Hn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of Pn(r,e))a instanceof E&&t.push(a.subject);return t}function Ye(r,e={}){let n=r.replace(/\r\n/g,`
1
+ import{a as Fn}from"./chunk-4NO7MHS7.js";import{a as Mn}from"./chunk-PEJALHXK.js";import{d as u}from"./chunk-SHDHMKMJ.js";import{a as x,c as xe,w as An}from"./chunk-WUAKDYY6.js";import{a as Vn}from"./chunk-ZYAABYDS.js";import{a as pn,b as ue,c as xn,d as w,f as Pe,g as ke,j as gn,k as qe,m as Pn,n as Nn}from"./chunk-PBNVHBS3.js";import{b as Oe,c as G,d as E,g as X,h as me,i as re,j as T,k as H,l as V}from"./chunk-T3JR2SV6.js";import{a as Tn}from"./chunk-FUUTGGJS.js";import{c as en,g as $e}from"./chunk-2ACBWC7K.js";var Ve="kanonak.org",zn="look",We="core-rdf",Kt={publisher:Ve,package_:zn,name:"displayLabel"},Rt={publisher:Ve,package_:zn,name:"displaySummary"},Lt={publisher:Ve,package_:We,name:"type"},Ot={publisher:Ve,package_:We,name:"subClassOf"},Ut={publisher:Ve,package_:We,name:"label"},It={publisher:Ve,package_:We,name:"comment"},Dn=new Tn(Ve,We,"Resource");function D(r,e){let n=Bn(r,e,Kt)??Ut,t=Bn(r,e,Rt)??It,a=gn(e,n)??e.name,s=gn(e,t);return{label:a,summary:s}}function Bn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Hn(e,Lt);for(;s.length>0;){let o=s.shift(),i=pn(o);if(a.has(i))continue;a.add(i);let c=Pe(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Hn(c,Ot))}if(!a.has(pn(Dn))){let o=Pe(r,Dn);if(o){let i=qe(o,n);if(i)return i}}}function Hn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of Pn(r,e))a instanceof E&&t.push(a.subject);return t}function Ye(r,e={}){let n=r.replace(/\r\n/g,`
2
2
  `).split(`
3
3
  `),t=[],a=0;for(;a<n.length;){let s=n[a];if(s.trim()===""){a++;continue}let o=/^(\s*)```(\S*)\s*$/.exec(s);if(o){let l=o[2],d=[];for(a++;a<n.length&&!/^(\s*)```\s*$/.test(n[a]);)d.push(n[a]),a++;a++;let f=d.join(`
4
4
  `),g=l&&e.highlight?e.highlight(l,f):De(f),m=l?` class="language-${qn(l)}"`:"";t.push(`<pre class="kan-code"><code${m}>${g}</code></pre>`);continue}let i=/^(#{1,6})\s+(.*)$/.exec(s);if(i){let l=i[1].length,d=Ne(i[2].trim());t.push(`<h${l}>${d}</h${l}>`),a++;continue}if(s.includes("|")&&a+1<n.length&&Gn(n[a+1])){let l=mn(s),d=Ct(n[a+1]);a+=2;let f=[];for(;a<n.length&&n[a].trim()!==""&&n[a].includes("|");)f.push(mn(n[a])),a++;t.push(Ft(l,d,f));continue}if(/^\s*[-*]\s+/.test(s)){let l=[];for(;a<n.length&&/^\s*[-*]\s+/.test(n[a]);){let d=[n[a].replace(/^\s*[-*]\s+/,"")];for(a++;a<n.length&&n[a].trim()!==""&&!/^\s*[-*]\s+/.test(n[a])&&!/^\s*\d+\.\s+/.test(n[a]);)d.push(n[a]),a++;a<n.length&&n[a].trim()===""&&a++,l.push(`<li>${Ne(d.join(" ").trim())}</li>`)}t.push(`<ul>
@@ -0,0 +1 @@
1
+ import{a as k,b as f}from"./chunk-2ACBWC7K.js";import*as h from"js-yaml";var b=new Set(["Package","EphemeralPackage"]);function v(d){return typeof d=="string"&&b.has(d)}var $=class{parse(r){let t=this.parseWithErrors(r);if(!t.isValid){let a=t.errors[0];throw new Error(`YAML parse error at line ${a.line}, column ${a.column}: ${a.message}`)}return t.document}parseWithErrors(r){let t=[],a;try{r=r.replace(/^\uFEFF/,"");let s=h.load(r,{schema:h.FAILSAFE_SCHEMA});if(!s||typeof s!="object")return a={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:a,errors:t,isValid:!0};let e=this.extractMetadata(s),n=this.extractBody(s,e);return a={metadata:e,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:a,errors:t,isValid:!0}}catch(s){let e=s,n={message:e.message||"Unknown parse error",line:e.mark?.line??0,column:e.mark?.column??0,errorType:e.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${e.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${e.mark?.line??0}: ${e.message||"Unknown parse error"}`};return t.push(n),{document:void 0,errors:t,isValid:!1}}}save(r){let t={};if(r.metadata.namespace_){let a=r.metadata.namespace_,s={type:"Package",publisher:a.publisher};a.version&&(s.version=`${a.version.major}.${a.version.minor}.${a.version.patch}`),r.metadata.imports&&(s.imports=this.serializeImports(r.metadata.imports)),t[a.package_]=s}return Object.assign(t,r.body),h.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(r){let t=r.imports;return Object.defineProperty(r,"allImports",{get:function(){if(!t)return[];let a=[];for(let s of Object.values(t))a.push(...s);return a},enumerable:!0,configurable:!0}),r}createVersion(r,t,a){return{major:r,minor:t,patch:a,toString:()=>`${r}.${t}.${a}`,equals:e=>!e||typeof e!="object"?!1:e.major===r&&e.minor===t&&e.patch===a,getHashCode:()=>r<<20|t<<10|a,compareTo:e=>r!==e.major?r-e.major:t!==e.minor?t-e.minor:a-e.patch}}extractMetadata(r){let t=this.createEmptyMetadata();for(let[a,s]of Object.entries(r))if(s&&typeof s=="object"&&v(s.type)){t.type_=s.type;let e=a,n=s.publisher,i=s.version?this.parseVersion(s.version):void 0;return n&&e&&(t.namespace_={publisher:n,package_:e,version:i,toString:function(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}`:`${this.publisher}/${this.package_}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===n&&o.package_===e&&(!i||!o.version||i.equals(o.version)),getHashCode:()=>{let o=0;for(let c=0;c<n.length;c++)o=(o<<5)-o+n.charCodeAt(c);for(let c=0;c<e.length;c++)o=(o<<5)-o+e.charCodeAt(c);return o|0}}),s.imports&&Array.isArray(s.imports)&&(t.imports=this.parseImportsV3(s.imports)),this.addAllImportsGetter(t)}if(r.kanonak&&typeof r.kanonak=="object"){let a=r.kanonak;return(a.publisher||a.package||a.version)&&(t.namespace_=this.parseNamespace(a)),a.imports&&typeof a.imports=="object"&&(t.imports=this.parseImportsLegacy(a.imports)),this.addAllImportsGetter(t)}return t}extractBody(r,t){let a={};for(let[s,e]of Object.entries(r))if(!(s==="kanonak"||s==="namespace"||s==="imports"))if(e&&typeof e=="object"&&v(e.type)){let n={};for(let[i,o]of Object.entries(e))i==="publisher"||i==="version"||i==="imports"||(n[i]=o);a[s]=n}else a[s]=e;return a}parseNamespace(r){if(typeof r=="string"){let e=r.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(e){let n=e[3]?this.parseVersion(e[3]):this.createVersion(1,0,0);return{publisher:e[1],package_:e[2],version:n,toString:()=>r,equals:i=>!i||typeof i!="object"?!1:i.publisher===e[1]&&i.package_===e[2]&&(!n||!i.version||n.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<e[1].length;o++)i=(i<<5)-i+e[1].charCodeAt(o);for(let o=0;o<e[2].length;o++)i=(i<<5)-i+e[2].charCodeAt(o);return i|0}}}}let t=r.publisher||"",a=r.package||"",s=r.version?this.parseVersion(r.version):this.createVersion(1,0,0);return{publisher:t,package_:a,version:s,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:e=>!e||typeof e!="object"?!1:e.publisher===t&&e.package_===a&&(!s||!e.version||s.equals(e.version)),getHashCode:()=>{let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n);for(let n=0;n<a.length;n++)e=(e<<5)-e+a.charCodeAt(n);return e|0}}}parseVersion(r){if(typeof r=="string"){let t=r.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(r.major||0,r.minor||0,r.patch||0)}parseImportsV3(r){let t={};for(let a of r)if(!(!a||typeof a!="object"))if(a.packages&&Array.isArray(a.packages)){let s=a.publisher;if(!s)throw new Error("PublisherImport requires 'publisher' property");t[s]||(t[s]=[]);for(let e of a.packages){if(!e||typeof e!="object")continue;let n=this.parseImportFromEmbeddedObject(e,s);t[s].push(n)}}else{let s=this.parseImportFromEmbeddedObject(a,a.publisher),e=s.publisher||"";t[e]||(t[e]=[]),t[e].push(s)}return t}parseImportsLegacy(r){let t={};for(let[a,s]of Object.entries(r))Array.isArray(s)&&(t[a]=s.map(e=>this.parseImport(e,a)));return t}parseImportFromEmbeddedObject(r,t){let a=r.package;if(!a)throw new Error("Import requires 'package' property");let s=r.match;if(!s)throw new Error("Import requires 'match' property");let e=r.version;if(!e)throw new Error("Import requires 'version' property");let n=this.parseVersion(e),i=this.parseVersionOperator(s),o=this.calculateMaxVersion(s,n),c=r.alias;return{package_:`${a} ${s} ${n.toString()}`,publisher:t,packageName:a,versionOperator:i,version:n,alias:c,minVersion:n,maxVersion:o,toEmbeddedObject:()=>{let m={package:a,match:s,version:n.toString()};return c&&(m.alias=c),m},toString:()=>c?`${a} ${s} ${n.toString()} as ${c}`:`${a} ${s} ${n.toString()}`}}buildImport(r,t,a,s){return this.parseImport({packageName:r,operator:t,version:a},s)}parseImport(r,t){if(typeof r=="string"){let o=r.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(o){let m=o[1].trim(),u=o[2],p=this.parseVersion(o[3].trim()),l=o[4].trim(),g=this.parseVersionOperator(u),V=this.calculateMaxVersion(u,p);return{package_:r,publisher:t,packageName:m,versionOperator:g,version:p,alias:l,minVersion:p,maxVersion:V,toEmbeddedObject:()=>{let y={package:m,match:u,version:p.toString()};return l&&(y.alias=l),y},toString:()=>`${m} ${u} ${p.toString()} as ${l}`}}let c=r.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let m=c[1].trim(),u=c[2],p=this.parseVersion(c[3].trim()),l=this.parseVersionOperator(u),g=this.calculateMaxVersion(u,p);return{package_:r,publisher:t,packageName:m,versionOperator:l,version:p,alias:void 0,minVersion:p,maxVersion:g,toEmbeddedObject:()=>({package:m,match:u,version:p.toString()}),toString:()=>`${m} ${u} ${p.toString()}`}}}let a=this.parseVersionOperator(r.operator||"~"),s=this.parseVersion(r.version||"1.0.0"),e=r.packageName||r.package||"",n=f(a),i=this.calculateMaxVersion(r.operator||"~",s);return{package_:r.package||"",publisher:t,packageName:e,versionOperator:a,version:s,alias:r.alias,minVersion:s,maxVersion:i,toEmbeddedObject:()=>{let o={package:e,match:n,version:s.toString()};return r.alias&&(o.alias=r.alias),o},toString:()=>`${e} ${n} ${s.toString()}`}}parseVersionOperator(r){return k(r)}calculateMaxVersion(r,t){switch(r){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(r){let t=[];for(let[a,s]of Object.entries(r)){let e={publisher:a,packages:s.map(n=>{let i=f(n.versionOperator),o={package:n.packageName,match:i,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(o.alias=n.alias),o})};t.push(e)}return t}};export{$ as a};
package/dist/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export { ViewMaterializer } from './view/index.js';
33
33
  export type { MaterializeOptions, MaterializeResult } from './view/index.js';
34
34
  export { PackageBuilder, ImportBook, contentAddressedName, sanitizeName, ProducerRepository, EntitlementProducer, EntitlementDeniedError, allowAllPolicy, noopMeter, } from './producer/index.js';
35
35
  export type { BuiltPackage, ImportEntry, IPackageProducer, ProduceResult, VersionRange, IEntitlementPolicy, IMeter, ProduceContext, PackageAddress, EntitlementDecision, RequestPrincipal, } from './producer/index.js';
36
- export { canonicalForm, canonicalHash } from './canonical/index.js';
36
+ export { canonicalForm, canonicalHash, CANONICAL_FORM_VERSION } from './canonical/index.js';
37
+ export { Carrier, carrierOf, canonicalInteger, canonicalDecimal, canonicalDouble, canonicalFloat, canonicalBoolean, canonicalString, canonicalAnyUri, canonicalLangString, canonicalLanguageTag, canonicalHexBinary, canonicalBase64, canonicalDateTime, canonicalDate, canonicalTime, canonicalScalarLexical, } from './canonical/index.js';
37
38
  export { buildOntologyModel } from './introspection/index.js';
38
39
  export type { OntologyModel, ClassDef, PropertyDef, ClassRef, TypeRef, EnumDef, EnumMember, BuildOntologyModelOptions, } from './introspection/index.js';
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import{a as sr,b as cr,c as lr,d as ur,e as ye}from"./chunk-KXVSGB6Q.js";import{a as tn,c as be,e as Oe,h as Ne,i as Ue,j as rn}from"./chunk-XWRVENU6.js";import{a as or,b as ir,c as ar,d as U,e as _,f as l,g as nn}from"./chunk-GIYURKX6.js";import{a as en}from"./chunk-RVOMWGIN.js";import"./chunk-QHABFCRC.js";import{a as Bt,b as At,c as Vt,d as Dt,e as Tt,f as Lt,g as Ft,h as Mt}from"./chunk-ATH6636H.js";import{b as Ot,c as Nt,d as _t}from"./chunk-LKBG2MK6.js";import{a as jt}from"./chunk-4NO7MHS7.js";import{a as pr,b as mr,c as fr,d as yr}from"./chunk-PJMOM5H7.js";import{a as gr,b as Rr}from"./chunk-PEUTCG3B.js";import{a as kr}from"./chunk-PEJALHXK.js";import{a as Ut}from"./chunk-SC5M74NM.js";import{A as Yr,B as Zr,C as Xr,L as Qr,a as Er,b as Cr,c as vr,d as xr,e as Kr,f as $r,g as Ir,h as jr,i as Br,j as Ar,k as Vr,l as Dr,m as Tr,n as Or,o as Nr,p as Ur,q as _r,r as Lr,s as Fr,t as Mr,u as Hr,v as zr,w as Wr,x as Gr,y as Jr,z as qr}from"./chunk-QXFO6X6V.js";import"./chunk-SHDHMKMJ.js";import{a as y,b as ce,c as Jt,d as tr,e as rr,f as E}from"./chunk-IUZZDC2U.js";import{a as S}from"./chunk-TJPQETHV.js";import{a as nr,b as ge,c as hr,d as g,e as br,f as Pr,g as wr,h as Sr}from"./chunk-Z5ELOT2C.js";import{f as N,k as C,l as he,m as ke,n as Te}from"./chunk-XQS5LDSO.js";import{b as qt,c as Yt,d as R,e as Zt,f as Xt,h as Qt,j as er}from"./chunk-IOMNZBK4.js";import{a as Ht,b as se,c as f,d as k,e as Wt,f as Gt,g as le,h as ue,i as de,j as pe,k as me,l as fe}from"./chunk-W6T7MOKY.js";import{a as zt}from"./chunk-FUUTGGJS.js";import{a as Et,b as ae,c as O,d as Ct,e as h,f as vt,g as xt,h as Kt,i as $t,j as It}from"./chunk-2ACBWC7K.js";import{a as dr}from"./chunk-ODIECDN7.js";import{VersionOperator as ca}from"@kanonak-protocol/types/document/models/enums";import{existsSync as Sn,readFileSync as Rn}from"fs";import{homedir as En}from"os";import{join as Cn}from"path";import{execFile as on}from"child_process";import{promisify as an}from"util";var L=an(on),F="kanonak",M="/usr/bin/security",v=class{async get(e){let t=l(e);try{let{stdout:n}=await L(M,["find-generic-password","-s",F,"-a",t,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${t}' is corrupted (not valid JSON).
2
- Run 'kanonak logout ${t}' then 'kanonak login ${t}' to fix.`)}}catch(n){if(_e(n,44))return null;throw new Error(`macOS Keychain read failed for '${t}': ${H(n)}
1
+ import{a as xr,b as Ir,c as Kr,d as $r,e as he}from"./chunk-6I4BYZVA.js";import{a as Sn,c as we,e as tt,h as rt,i as nt,j as Rn}from"./chunk-ZRMF5QLN.js";import{a as Cr,b as Er,c as vr,d as U,e as _,f as l,g as Cn}from"./chunk-VNKX52D5.js";import{a as wn}from"./chunk-4OSNT57C.js";import"./chunk-QHABFCRC.js";import{a as Qt,b as er,c as tr,d as rr,e as nr,f as cr,g as lr,h as ur}from"./chunk-YWUKDEZA.js";import{b as or,c as ar,d as sr}from"./chunk-YCV4H6H5.js";import{a as Xt}from"./chunk-4NO7MHS7.js";import{a as Br,b as Ar,c as Dr,d as Vr}from"./chunk-YI5GLYMB.js";import{a as Tr,b as Mr}from"./chunk-PEUTCG3B.js";import{a as Nr}from"./chunk-PEJALHXK.js";import{a as ir}from"./chunk-SC5M74NM.js";import{A as hn,B as kn,C as bn,L as Pn,a as Hr,b as zr,c as Wr,d as Gr,e as Jr,f as qr,g as Yr,h as Zr,i as Xr,j as Qr,k as en,l as tn,m as rn,n as nn,o as on,p as an,q as sn,r as cn,s as ln,t as un,u as dn,v as pn,w as mn,x as fn,y as yn,z as gn}from"./chunk-V3YPCUA6.js";import"./chunk-SHDHMKMJ.js";import{a as y,b as le,c as fr,d as Ne,e as Le,f as Ue,g as _e,h as Fe,i as Me,j as He,k as ze,l as We,m as Ge,n as Je,o as qe,p as Ye,q as Ze,r as Xe,s as Qe,t as R,u as wr,v as Sr,w as E}from"./chunk-WUAKDYY6.js";import{a as S}from"./chunk-ZYAABYDS.js";import{a as Rr,b as ke,c as Or,d as g,e as Lr,f as Ur,g as _r,h as Fr}from"./chunk-NC3FSY3R.js";import{f as L,k as v,l as be,m as Pe,n as et}from"./chunk-PBNVHBS3.js";import{b as yr,c as gr,d as C,e as hr,f as kr,h as br,j as Pr}from"./chunk-XYEY6HUC.js";import{a as dr,b as ce,c as f,d as k,e as mr,f as ue,g as de,h as pe,i as me,j as fe,k as ye,l as ge}from"./chunk-T3JR2SV6.js";import{a as pr}from"./chunk-FUUTGGJS.js";import{a as zt,b as se,c as N,d as Wt,e as h,f as Gt,g as Jt,h as qt,i as Yt,j as Zt}from"./chunk-2ACBWC7K.js";import{a as jr}from"./chunk-ODIECDN7.js";import{VersionOperator as ji}from"@kanonak-protocol/types/document/models/enums";import{existsSync as Fn,readFileSync as Mn}from"fs";import{homedir as Hn}from"os";import{join as zn}from"path";import{execFile as En}from"child_process";import{promisify as vn}from"util";var F=vn(En),M="kanonak",H="/usr/bin/security",x=class{async get(e){let t=l(e);try{let{stdout:n}=await F(H,["find-generic-password","-s",M,"-a",t,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${t}' is corrupted (not valid JSON).
2
+ Run 'kanonak logout ${t}' then 'kanonak login ${t}' to fix.`)}}catch(n){if(ot(n,44))return null;throw new Error(`macOS Keychain read failed for '${t}': ${z(n)}
3
3
  The Keychain may be locked or inaccessible.
4
- Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,t){let n=l(e),o=JSON.stringify(t);try{await L(M,["add-generic-password","-s",F,"-a",n,"-U","-w",o],{timeout:1e4})}catch(i){throw new Error(`macOS Keychain write failed for '${n}': ${H(i)}
4
+ Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,t){let n=l(e),o=JSON.stringify(t);try{await F(H,["add-generic-password","-s",M,"-a",n,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${n}': ${z(a)}
5
5
  Ensure the Keychain is unlocked and the CLI has write permission.
6
- On managed devices, your IT policy may block credential storage.`)}}async remove(e){let t=l(e);try{await L(M,["delete-generic-password","-s",F,"-a",t],{timeout:1e4})}catch(n){if(_e(n,44))return;console.warn(` Warning: macOS Keychain delete failed for '${t}': ${H(n)}
7
- The credential may not have been fully removed.`)}}async list(){try{let{stdout:e}=await L(M,["dump-keychain"],{timeout:1e4}),t=[],n=!1;for(let o of e.split(`
8
- `))if(o.includes(`"svce"<blob>="${F}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let i=o.match(/"acct"<blob>="([^"]+)"/);i&&t.push(i[1]),n=!1}return t}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${H(e)}`),[]}}};function _e(r,e){return typeof r=="object"&&r!==null&&"code"in r&&r.code===e}function H(r){return r instanceof Error?r.message:String(r)}import{execFile as sn}from"child_process";import{promisify as cn}from"util";var ln=cn(sn),z="kanonak:",x=class{async get(e){let t=z+l(e),n=`
9
- ${G}
6
+ On managed devices, your IT policy may block credential storage.`)}}async remove(e){let t=l(e);try{await F(H,["delete-generic-password","-s",M,"-a",t],{timeout:1e4})}catch(n){if(ot(n,44))return;console.warn(` Warning: macOS Keychain delete failed for '${t}': ${z(n)}
7
+ The credential may not have been fully removed.`)}}async list(){try{let{stdout:e}=await F(H,["dump-keychain"],{timeout:1e4}),t=[],n=!1;for(let o of e.split(`
8
+ `))if(o.includes(`"svce"<blob>="${M}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&t.push(a[1]),n=!1}return t}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${z(e)}`),[]}}};function ot(r,e){return typeof r=="object"&&r!==null&&"code"in r&&r.code===e}function z(r){return r instanceof Error?r.message:String(r)}import{execFile as xn}from"child_process";import{promisify as In}from"util";var Kn=In(xn),W="kanonak:",I=class{async get(e){let t=W+l(e),n=`
9
+ ${J}
10
10
  $target = [Console]::In.ReadLine()
11
11
  $ptr = [IntPtr]::Zero
12
12
  $result = [CredMan]::CredRead($target, 1, 0, [ref]$ptr)
@@ -18,8 +18,8 @@ try {
18
18
  [System.Text.Encoding]::Unicode.GetString($bytes)
19
19
  } finally {
20
20
  [CredMan]::CredFree($ptr)
21
- }`;try{let{stdout:o}=await W(n,t),i=o.trim();return i?JSON.parse(i):null}catch{return null}}async store(e,t){let n=z+l(e),o=JSON.stringify(t),i=`
22
- ${G}
21
+ }`;try{let{stdout:o}=await G(n,t),a=o.trim();return a?JSON.parse(a):null}catch{return null}}async store(e,t){let n=W+l(e),o=JSON.stringify(t),a=`
22
+ ${J}
23
23
  $target = [Console]::In.ReadLine()
24
24
  $json = [Console]::In.ReadLine()
25
25
  $bytes = [System.Text.Encoding]::Unicode.GetBytes($json)
@@ -35,13 +35,13 @@ try {
35
35
  if (-not $result) { throw "CredWrite failed" }
36
36
  } finally {
37
37
  [System.Runtime.InteropServices.Marshal]::FreeHGlobal($cred.CredentialBlob)
38
- }`;try{await W(i,`${n}
39
- ${o}`)}catch(a){throw new Error(`Windows Credential Manager write failed: ${String(a)}`)}}async remove(e){let t=z+l(e),n=`
40
- ${G}
38
+ }`;try{await G(a,`${n}
39
+ ${o}`)}catch(i){throw new Error(`Windows Credential Manager write failed: ${String(i)}`)}}async remove(e){let t=W+l(e),n=`
40
+ ${J}
41
41
  $target = [Console]::In.ReadLine()
42
- [CredMan]::CredDelete($target, 1, 0) | Out-Null`;try{await W(n,t)}catch{}}async list(){let e=`
43
- ${G}
44
- ${un}
42
+ [CredMan]::CredDelete($target, 1, 0) | Out-Null`;try{await G(n,t)}catch{}}async list(){let e=`
43
+ ${J}
44
+ ${$n}
45
45
  $prefix = [Console]::In.ReadLine()
46
46
  $count = 0
47
47
  $pCreds = [IntPtr]::Zero
@@ -55,8 +55,8 @@ if ([CredMan]::CredEnumerate($null, 0, [ref]$count, [ref]$pCreds)) {
55
55
  }
56
56
  }
57
57
  [CredMan]::CredFree($pCreds)
58
- }`;try{let{stdout:t}=await W(e,z);return t.trim().split(`
59
- `).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function W(r,e){for(let t of["pwsh","powershell"])try{return await ln(t,["-NoProfile","-NonInteractive","-Command",r],{timeout:15e3,...e!==void 0&&{input:e}})}catch(n){if(t==="powershell")throw n}throw new Error("Neither pwsh nor powershell found")}var G=`
58
+ }`;try{let{stdout:t}=await G(e,W);return t.trim().split(`
59
+ `).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function G(r,e){for(let t of["pwsh","powershell"])try{return await Kn(t,["-NoProfile","-NonInteractive","-Command",r],{timeout:15e3,...e!==void 0&&{input:e}})}catch(n){if(t==="powershell")throw n}throw new Error("Neither pwsh nor powershell found")}var J=`
60
60
  Add-Type -TypeDefinition @"
61
61
  using System;
62
62
  using System.Runtime.InteropServices;
@@ -87,13 +87,13 @@ public class CredMan {
87
87
  [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
88
88
  public static extern bool CredEnumerate(string filter, int flags, out int count, out IntPtr credentials);
89
89
  }
90
- "@`,un="";import{execFile as dn,spawn as pn}from"child_process";import{promisify as mn}from"util";var q=mn(dn),J="kanonak",K=class{async get(e){let t=l(e);try{let{stdout:n}=await q("secret-tool",["lookup","service",J,"publisher",t],{timeout:1e4}),o=n.trim();return o?JSON.parse(o):null}catch{return null}}async store(e,t){let n=l(e),o=JSON.stringify(t);await new Promise((i,a)=>{let s=pn("secret-tool",["store","--label",`Kanonak: ${n}`,"service",J,"publisher",n],{stdio:["pipe","ignore","ignore"],timeout:1e4});s.stdin.write(o),s.stdin.end(),s.on("close",c=>{c===0?i():a(new Error(`secret-tool store exited with code ${c}`))}),s.on("error",a)})}async remove(e){let t=l(e);try{await q("secret-tool",["clear","service",J,"publisher",t],{timeout:1e4})}catch{}}async list(){try{let{stdout:e}=await q("secret-tool",["search","service",J],{timeout:1e4}),t=[];for(let n of e.split(`
91
- `)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&t.push(o[1].trim())}return t}catch{return[]}}};async function Pe(){try{return await q("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as Le,mkdirSync as Fe,readFileSync as Me,writeFileSync as He}from"fs";import{createCipheriv as fn,createDecipheriv as yn,randomBytes as ze}from"crypto";import{homedir as gn}from"os";import{join as Re,dirname as We}from"path";var Je=Re(gn(),".config","kanonak"),$=Re(Je,"keyring.key"),Y=Re(Je,"credentials.enc"),Ge="aes-256-gcm",we=32,b=12,Se=16,I=class{async get(e){let t=this.loadStore(),n=l(e);return t[n]??null}async store(e,t){let n=this.loadStore(),o=l(e);n[o]=t,this.saveStore(n)}async remove(e){let t=this.loadStore(),n=l(e);delete t[n],this.saveStore(t)}async list(){let e=this.loadStore();return Object.keys(e)}loadStore(){if(!Le(Y))return{};try{let e=this.getOrCreateKey(),t=Me(Y);if(t.length<b+Se)return{};let n=t.subarray(0,b),o=t.subarray(b,b+Se),i=t.subarray(b+Se),a=yn(Ge,e,n);a.setAuthTag(o);let s=Buffer.concat([a.update(i),a.final()]);return JSON.parse(s.toString("utf-8"))}catch{return{}}}saveStore(e){let t=this.getOrCreateKey(),n=ze(b),o=fn(Ge,t,n),i=Buffer.from(JSON.stringify(e),"utf-8"),a=Buffer.concat([o.update(i),o.final()]),s=o.getAuthTag(),c=Buffer.concat([n,s,a]);Fe(We(Y),{recursive:!0}),He(Y,c,{mode:384})}getOrCreateKey(){if(Le($)){let t=Me($);if(t.length!==we)throw new Error(`Credential keyring key is corrupted (expected ${we} bytes, got ${t.length}). Delete ${$} and re-authenticate.`);return t}let e=ze(we);return Fe(We($),{recursive:!0}),He($,e,{mode:384}),e}};import{execFile as hn}from"child_process";import{promisify as kn}from"util";var bn=kn(hn),qe=3e4,j=class{constructor(e){this.helperPath=e}helperPath;async get(e){let t=l(e);try{let o=(await this.runHelper("get",{publisher:t})).trim();return o?JSON.parse(o):null}catch(n){throw new Error(`Credential helper '${this.helperPath}' failed to read credential for '${t}': ${Z(n)}
90
+ "@`,$n="";import{execFile as jn,spawn as Bn}from"child_process";import{promisify as An}from"util";var Y=An(jn),q="kanonak",K=class{async get(e){let t=l(e);try{let{stdout:n}=await Y("secret-tool",["lookup","service",q,"publisher",t],{timeout:1e4}),o=n.trim();return o?JSON.parse(o):null}catch{return null}}async store(e,t){let n=l(e),o=JSON.stringify(t);await new Promise((a,i)=>{let s=Bn("secret-tool",["store","--label",`Kanonak: ${n}`,"service",q,"publisher",n],{stdio:["pipe","ignore","ignore"],timeout:1e4});s.stdin.write(o),s.stdin.end(),s.on("close",c=>{c===0?a():i(new Error(`secret-tool store exited with code ${c}`))}),s.on("error",i)})}async remove(e){let t=l(e);try{await Y("secret-tool",["clear","service",q,"publisher",t],{timeout:1e4})}catch{}}async list(){try{let{stdout:e}=await Y("secret-tool",["search","service",q],{timeout:1e4}),t=[];for(let n of e.split(`
91
+ `)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&t.push(o[1].trim())}return t}catch{return[]}}};async function Se(){try{return await Y("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as at,mkdirSync as it,readFileSync as st,writeFileSync as ct}from"fs";import{createCipheriv as Dn,createDecipheriv as Vn,randomBytes as lt}from"crypto";import{homedir as Tn}from"os";import{join as Ee,dirname as ut}from"path";var pt=Ee(Tn(),".config","kanonak"),$=Ee(pt,"keyring.key"),Z=Ee(pt,"credentials.enc"),dt="aes-256-gcm",Re=32,b=12,Ce=16,j=class{async get(e){let t=this.loadStore(),n=l(e);return t[n]??null}async store(e,t){let n=this.loadStore(),o=l(e);n[o]=t,this.saveStore(n)}async remove(e){let t=this.loadStore(),n=l(e);delete t[n],this.saveStore(t)}async list(){let e=this.loadStore();return Object.keys(e)}loadStore(){if(!at(Z))return{};try{let e=this.getOrCreateKey(),t=st(Z);if(t.length<b+Ce)return{};let n=t.subarray(0,b),o=t.subarray(b,b+Ce),a=t.subarray(b+Ce),i=Vn(dt,e,n);i.setAuthTag(o);let s=Buffer.concat([i.update(a),i.final()]);return JSON.parse(s.toString("utf-8"))}catch{return{}}}saveStore(e){let t=this.getOrCreateKey(),n=lt(b),o=Dn(dt,t,n),a=Buffer.from(JSON.stringify(e),"utf-8"),i=Buffer.concat([o.update(a),o.final()]),s=o.getAuthTag(),c=Buffer.concat([n,s,i]);it(ut(Z),{recursive:!0}),ct(Z,c,{mode:384})}getOrCreateKey(){if(at($)){let t=st($);if(t.length!==Re)throw new Error(`Credential keyring key is corrupted (expected ${Re} bytes, got ${t.length}). Delete ${$} and re-authenticate.`);return t}let e=lt(Re);return it(ut($),{recursive:!0}),ct($,e,{mode:384}),e}};import{execFile as On}from"child_process";import{promisify as Nn}from"util";var Ln=Nn(On),mt=3e4,B=class{constructor(e){this.helperPath=e}helperPath;async get(e){let t=l(e);try{let o=(await this.runHelper("get",{publisher:t})).trim();return o?JSON.parse(o):null}catch(n){throw new Error(`Credential helper '${this.helperPath}' failed to read credential for '${t}': ${X(n)}
92
92
  Verify the helper binary exists, is executable, and implements the Kanonak credential helper protocol.
93
- Check the 'credentialHelper' path in ~/.kanonak/config.json.`)}}async store(e,t){let n=l(e);try{await this.runHelper("store",{publisher:n,credential:t})}catch(o){throw new Error(`Credential helper '${this.helperPath}' failed to store credential for '${n}': ${Z(o)}
94
- Verify the helper binary supports the 'store' action.`)}}async remove(e){let t=l(e);try{await this.runHelper("erase",{publisher:t})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${t}': ${Z(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${Z(e)}`),[]}}async runHelper(e,t){try{let{stdout:n}=await bn(this.helperPath,[e],{...t&&{input:JSON.stringify(t)},timeout:qe});return n}catch(n){throw Pn(n)?new Error(`Credential helper not found at '${this.helperPath}'.
95
- Check the 'credentialHelper' path in ~/.kanonak/config.json.`):wn(n)?new Error(`Credential helper '${this.helperPath}' timed out after ${qe/1e3}s on '${e}'.
96
- The helper may be waiting for authentication to an external vault.`):n}}};function Z(r){return r instanceof Error?r.message:String(r)}function Pn(r){return r instanceof Error&&"code"in r&&r.code==="ENOENT"}function wn(r){return r instanceof Error&&"killed"in r&&r.killed}var Ee=Cn(En(),".kanonak","config.json"),X=class{backend=null;backendReady=null;async getBackend(){if(this.backend)return this.backend;if(this.backendReady)return this.backendReady;this.backendReady=this.resolveBackend();try{return this.backend=await this.backendReady,this.backend}catch(e){throw this.backendReady=null,e}}async getToken(e){let t=vn(e);if(t)return t;let o=await(await this.getBackend()).get(e);return!o||!_(o)?null:o.accessToken??null}async getCredential(e){return(await this.getBackend()).get(e)}async store(e,t){return(await this.getBackend()).store(e,t)}async remove(e){return(await this.getBackend()).remove(e)}async list(){return(await this.getBackend()).list()}async resolveBackend(){let e=xn();return e.credentialHelper?new j(e.credentialHelper):process.platform==="darwin"?new v:process.platform==="win32"?new x:await Pe()?new K:new I}};function vn(r){let t="KANONAK_TOKEN_"+l(r).replace(/[.\-]/g,"_").toUpperCase();return process.env[t]??null}function xn(){if(!Sn(Ee))return{};try{return JSON.parse(Rn(Ee,"utf-8"))}catch(r){let e=r instanceof Error?r.message:String(r);return console.warn(` Warning: Failed to parse ${Ee}: ${e}
97
- Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as Kn,createPrivateKey as $n,generateKeyPairSync as In,randomUUID as jn,sign as Bn}from"crypto";function Ze(){let{publicKey:r,privateKey:e}=In("ec",{namedCurve:"P-256"});return{publicKey:r.export({format:"jwk"}),privateKey:e.export({format:"jwk"})}}function B(r,e,t,n,o,i){let a={alg:"ES256",typ:"dpop+jwt",jwk:{kty:e.kty,crv:e.crv,x:e.x,y:e.y}},s={jti:jn(),htm:t.toUpperCase(),htu:n,iat:Math.floor(Date.now()/1e3)};return o&&(s.ath=Kn("sha256").update(o).digest("base64url")),i&&(s.nonce=i),An(a,s,r)}function Xe(r){return!r||r.length===0?!1:r.some(e=>e.toUpperCase()==="ES256")}function An(r,e,t){let n=Ye(JSON.stringify(r)),o=Ye(JSON.stringify(e)),i=`${n}.${o}`,a=$n({key:t,format:"jwk"}),c=Bn("SHA256",Buffer.from(i),{key:a,dsaEncoding:"ieee-p1363"}).toString("base64url");return`${i}.${c}`}function Ye(r){return Buffer.from(r,"utf-8").toString("base64url")}function Qe(r){let e=new Map;return async(t,n,o="GET")=>{if(!r)return fetch(t,{method:o});let i=await r.getCredential(n);if(!i?.accessToken)return fetch(t,{method:o});U(i)&&console.warn(` Warning: Access token for '${n}' is expired. Run 'kanonak login ${n}' to re-authenticate.`);let a={};if(i.dpopKeyPair){let c=e.get(n);try{let u=B(i.dpopKeyPair.privateKey,i.dpopKeyPair.publicKey,o,t,i.accessToken,c);a.Authorization=`DPoP ${i.accessToken}`,a.DPoP=u}catch(u){let d=u instanceof Error?u.message:String(u);console.error(` Error: Failed to create DPoP proof for '${n}': ${d}
98
- The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),a.Authorization=`Bearer ${i.accessToken}`}}else a.Authorization=`Bearer ${i.accessToken}`;let s=await fetch(t,{method:o,headers:a});if(s.status===401&&i.dpopKeyPair){let c=s.headers.get("DPoP-Nonce");if(c){e.set(n,c);try{let u=B(i.dpopKeyPair.privateKey,i.dpopKeyPair.publicKey,o,t,i.accessToken,c);a.DPoP=u,s=await fetch(t,{method:o,headers:a})}catch{}}}return s}}import{readFileSync as Vn,writeFileSync as Dn,existsSync as Tn}from"fs";import{createHash as On}from"crypto";import et from"js-yaml";var tt="kanonak.lock",Nn=`# This file is generated by Kanonak CLI. Do not edit manually.
99
- `;function rt(r=tt){if(!Tn(r))return null;let e=Vn(r,"utf-8"),t=et.load(e);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??new Date().toISOString(),packages:t.packages??{}}}function nt(r,e=tt){r.lastUpdated=new Date().toISOString();let t={};for(let o of Object.keys(r.packages).sort())t[o]=r.packages[o];r.packages=t;let n=et.dump(r,{lineWidth:-1,sortKeys:!1,quotingType:'"'});Dn(e,Nn+n,"utf-8")}function ot(r){return`sha256:${On("sha256").update(r).digest("hex")}`}import*as xe from"js-yaml";import{createHash as Un}from"crypto";function Ce(r){let e=[];for(let n of r)n instanceof f&&e.push(_n(n));return e.sort((n,o)=>n.uri<o.uri?-1:n.uri>o.uri?1:0),JSON.stringify({subjects:e})}function Q(r){let e=Ce(r);return`sha256:${Un("sha256").update(e,"utf8").digest("hex")}`}function _n(r){let e=Wn(r),t=ve(r.statement);return{uri:e,statements:t}}function ve(r){let e=[];for(let t of r){let n=Ln(t);n&&e.push(n)}return e.sort((t,n)=>t.predicate<n.predicate?-1:t.predicate>n.predicate?1:0),e}function Ln(r){let e=zn(r);if(!e)return;let t=Fn(r);if(t)return Hn(e,t)}function Fn(r){if(r instanceof le)return{type:"string",value:r.object};if(r instanceof ue)return{type:"number",value:ct(r.object)};if(r instanceof de)return{type:"boolean",value:r.object};if(r instanceof pe)return{type:"ref",value:at(r.object)};if(r instanceof me){let e=r.object;return it(e)}if(r instanceof fe)return{type:"list",items:r.object.map(Mn)}}function it(r){let e=ve(r.statement);return r.name&&r.name.length>0?{type:"embedded",name:r.name,statements:e}:{type:"embedded",statements:e}}function Mn(r){if(r instanceof k)return{type:"ref",value:at(r)};if(r instanceof y)return it(r);if(r instanceof ce){let e=r.value;if(typeof e=="string")return{type:"string",value:e};if(typeof e=="number")return{type:"number",value:ct(e)};if(typeof e=="boolean")return{type:"boolean",value:e}}if(r instanceof se)return{type:"embedded",statements:ve(r.statement)};throw new Error(`canonicalForm: list item of unrecognized kind (${r.constructor?.name??typeof r}); add canonicalization support before hashing data that contains it`)}function Hn(r,e){switch(e.type){case"string":return{predicate:r,type:"string",value:e.value};case"number":return{predicate:r,type:"number",value:e.value};case"boolean":return{predicate:r,type:"boolean",value:e.value};case"ref":return{predicate:r,type:"ref",value:e.value};case"embedded":return e.name!==void 0?{predicate:r,type:"embedded",name:e.name,statements:e.statements}:{predicate:r,type:"embedded",statements:e.statements};case"list":return{predicate:r,type:"list",items:e.items}}}function zn(r){let e=r.predicate;if(e)return st(e.subject)}function Wn(r){let e=r.namespace??"",t=r.name??"";return`${e}/${t}`}function at(r){return st(r.subject)}function st(r){let e=r.version;return e&&typeof e.major=="number"?`${r.publisher}/${r.package_}@${e.major}.${e.minor}.${e.patch}/${r.name}`:`${r.publisher}/${r.package_}/${r.name}`}function ct(r){if(Number.isNaN(r))throw new Error("canonicalForm: NaN cannot be canonicalized");if(!Number.isFinite(r))throw new Error("canonicalForm: \xB1Infinity cannot be canonicalized");return Object.is(r,-0)?"0":String(r)}import{VersionOperator as lt}from"@kanonak-protocol/types/document/models/enums";var Gn="0.0.0",P=class{constructor(e,t=new S,n){this.repository=e;this.parser=t;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new A}serializeValue(e,t){return pt(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),n=await this.hashBody(e.publisher,t,e.body),o=Ke(n),i={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(i[e.contentHashProperty]=n),Object.assign(i,e.header??{}),i.imports=t;let a={[o]:i,...e.body},s=this.dump(a);return{yaml:s,byteCount:dt(s),contentHash:n,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),n[e.contentHashProperty]=o),Object.assign(n,e.header??{}),n.imports=t;let i={[e.name]:n,...e.body},a=this.dump(i),s={yaml:a,byteCount:dt(a),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return xe.dump(e,{lineWidth:-1})}async hashBody(e,t,n){let o={[ut]:{type:"EphemeralPackage",publisher:e,imports:t},...n},i=this.parser.parse(xe.dump(o,{lineWidth:-1})),a=i.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new Te(i,this.repository))).filter(u=>u instanceof f&&u.namespace===a&&u.name!==ut);for(let u of c)u.namespace="ephemeral";return Q(c)}},ut="__pkgbuilder_probe__";function dt(r){return new TextEncoder().encode(r).length}function Ke(r){let e="sha256:",t=r.startsWith(e)?e.length:0;return`q-${r.slice(t,t+16)}`}var A=class{byKey=new Map;aliases=new Set;ensure(e,t,n,o,i=lt.Major){let a=`${e}/${t}@${n}`,s=this.byKey.get(a);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(a,{publisher:e,package_:t,version:n,alias:c,match:i}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,h(e.version),e.package_)}.${e.name}`}refLatest(e,t,n,o){return`${this.ensure(e,t,Gn,o??t,lt.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let o=e.get(n.publisher)??[];o.push(n),e.set(n.publisher,o)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((o,i)=>o.package_<i.package_?-1:1).map(o=>({package:o.package_,match:ae(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=V(e)||"pkg",n=t,o=2;for(;this.aliases.has(n);)n=`${t}${o++}`;return this.aliases.add(n),n}};function pt(r,e){if(r!=null){if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r instanceof k)return e.ref(r.subject);if(Array.isArray(r)){let t=r.map(n=>pt(n,e)).filter(n=>n!==void 0);return t.length>0?t:void 0}if(r instanceof y)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(Jn(r))throw new Error(`Value produced a bare URI without a version (${r.publisher}/${r.package_}/${r.name}); cannot serialize it as a reference.`)}}function V(r){return r.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Jn(r){return typeof r=="object"&&r!==null&&typeof r.publisher=="string"&&typeof r.package_=="string"&&typeof r.name=="string"}var ee=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(n=>n.canProduce(e,t))}async produceCached(e,t,n,o){let i=`${t}/${n}@${h(o)}`,a=this.produced.get(i);if(a)return a;let{document:s}=await e.produce(t,n,o);return this.produced.set(i,s),s}async getHighestCompatibleVersionAsync(e,t){let n=this.producerFor(e,t.packageName);if(!n)return null;let o={operator:t.versionOperator,version:t.version},i=await n.resolveVersion(e,t.packageName,o);return i?this.produceCached(n,e,t.packageName,i):null}async getDocumentAsync(e){let t;try{t=ge(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let n=this.producerFor(t.publisher,t.package_);return n?this.produceCached(n,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(n=>{let o=n.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var $e={async authorize(){return{allowed:!0}}},Ie={async record(){}},D=class extends Error{constructor(t,n){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${n?`: ${n}`:""}`);this.address=t;this.reason=n;this.name="EntitlementDeniedError"}address;reason},te=class{inner;ctx;policy;meter;constructor(e,t,n=$e,o=Ie){this.inner=e,this.ctx=t,this.policy=n,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,n){return await this.assertAllowed({publisher:e,package_:t,version:n.version}),this.inner.resolveVersion(e,t,n)}async produce(e,t,n){let o={publisher:e,package_:t,version:n};await this.assertAllowed(o);let i=await this.inner.produce(e,t,n);return await this.meter.record(this.ctx,o,i),i}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new D(e,t.reason)}};var p="kanonak.org",m="view",mt="core-kanonak",qn={publisher:p,package_:m,name:"rootView"},Yn={publisher:p,package_:m,name:"bind"},Zn={publisher:p,package_:m,name:"produces"},Xn={publisher:p,package_:m,name:"projections"},Qn={publisher:p,package_:m,name:"where"},eo={publisher:p,package_:m,name:"value"},to={publisher:p,package_:m,name:"as"},re=class{constructor(e,t=new S){this.repository=e;this.parser=t;this.objectParser=new E(this.parser),this.builder=new P(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,t={}){let n=await this.objectParser.parseKanonaks(this.repository),o=this.resolveView(n,e),i=C(o,Yn);if(!i)throw new Error(`View ${o.namespace}/${o.name} declares no view.bind; cannot materialize.`);let a=C(o,Zn);if(!a)throw new Error(`View ${o.namespace}/${o.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let s=ro(o),c=ft(n,p,mt),u=ft(n,p,m),d=this.builder.imports(),ne=d.ensure(p,mt,c,"ck"),gt=d.ensure(p,m,u,"v"),ht=d.ref(a),kt=new Ue(this.repository,this.parser,this.objectParser),je=new Oe(kt,n),bt=this.readProjections(n,o),Pt=io(o,Qn),wt=this.findInstances(n,i,await this.reason(t)),Be={},St=new Set;for(let T of wt){if(!await this.passesWhere(je,n,Pt,T))continue;let ie={type:ht};for(let Ve of bt){let Rt=await this.evaluateValue(je,n,Ve.value,T),De=this.builder.serializeValue(yt(Rt),d);De!==void 0&&(ie[d.ref(Ve.as)]=De)}let Ae=g(T);Ae&&(ie[`${gt}.derivedFrom`]=d.ref(Ae)),Be[this.rowName(T,St)]=ie}let oe={};t.resolvedAt&&(oe[`${ne}.resolvedAt`]=t.resolvedAt),t.invocationId&&(oe[`${ne}.id`]=t.invocationId);let w=await this.builder.buildContentAddressed({publisher:s,book:d,body:Be,contentHashProperty:`${ne}.contentHash`,header:oe});return{yaml:w.yaml,contentHash:w.contentHash,packageName:w.packageName,publisher:w.publisher,rowCount:w.resourceCount}}resolveView(e,t){let n=N(e,t);if(!n)throw new Error(`View ${t.publisher}/${t.package_}/${t.name} not found in the catalog.`);let o=C(n,qn);if(o){let i=N(e,o);if(!i)throw new Error(`ViewPackage ${t.name} names rootView ${o.name}, which is not in the catalog.`);return i}return n}readProjections(e,t){let n=[];for(let o of ke(t,Xn)){let i=o instanceof y?o:o instanceof k?N(e,o.subject):void 0;if(!i)continue;let a=he(i,eo),s=C(i,to);a&&s&&n.push({value:a,as:s})}return n}async reason(e){return new ye({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,t,n){let o=oo(e),i=[],a=new Set;for(let s of n.getInstancesOfClass(t)){if(a.has(s))continue;a.add(s);let c=o.get(s);c&&i.push(c)}return i.sort((s,c)=>{let u=R(g(s)),d=R(g(c));return u<d?-1:u>d?1:0}),i}async passesWhere(e,t,n,o){for(let i of n){let a=await this.evaluateValue(e,t,i,o);if(!ao(a))return!1}return!0}async evaluateValue(e,t,n,o){let i=Ne(n,"view-projection",{catalog:t,depth:0}),a=new Map([["input",o]]);return e.evaluate(i,a)}rowName(e,t){let n=V(e.name)||"row",o=n,i=2;for(;t.has(o);)o=`${n}-${i++}`;return t.add(o),o}};function yt(r){return be(r)?r.value:Array.isArray(r)?r.map(yt):r}function ro(r){let e=g(r);if(!e)throw new Error(`Could not derive a publisher from view ${r.namespace}/${r.name}.`);return e.publisher}function ft(r,e,t){let n=no(r,e,t);if(!n)throw new Error(`Package ${e}/${t} is not in the catalog; it must be importable to materialize a view.`);return n}function no(r,e,t){let n;for(let o of r){if(!(o instanceof f))continue;let i=g(o);!i||i.publisher!==e||i.package_!==t||!i.version||(!n||O(i.version,n)>0)&&(n=i.version)}return n?h(n):void 0}function oo(r){let e=new Map,t=new Map;for(let n of r){if(!(n instanceof f))continue;let o=g(n);if(!o||!o.version)continue;let i=R(o),a=t.get(i);(!a||O(o.version,a)>0)&&(t.set(i,o.version),e.set(i,n))}return e}function io(r,e){let t=he(r,e);return t?[t]:ke(r,e).filter(n=>n instanceof y)}function ao(r){return r===!0?!0:r===!1||r===void 0||r===null?!1:typeof r=="string"?r.length>0:typeof r=="number"?r!==0:be(r)?r.value.length>0:Array.isArray(r)?r.length>0:!!r}export{zr as AmbiguousReferenceRule,de as BooleanStatement,Zr as ClassDefinitionRule,Tr as ClassHierarchyCycleRule,Vt as CompositeKanonakDocumentRepository,X as CredentialStore,se as DefinedKanonak,Mr as DefinitionPropertyReferenceRule,At as DocumentLocation,ir as EdgeType,y as EmbeddedKanonak,Ar as EmbeddedKanonakTypeRule,me as EmbeddedStatement,D as EntitlementDeniedError,te as EntitlementProducer,Bt as FileSystemKanonakDocumentRepository,dr as GitIgnoreFilter,ar as GraphBuilder,_t as HttpKanonakDocumentRepository,A as ImportBook,Vr as ImportExistenceRule,jt as InMemoryKanonakDocumentRepository,Fr as InstancePropertyReferenceRule,Ht as Kanonak,mr as KanonakDocumentPositions,E as KanonakObjectParser,Qr as KanonakObjectValidator,S as KanonakParser,zt as KanonakUri,gr as KanonakUriBuilder,kr as KanonakUrlResolver,er as KanonakVocabulary,fe as ListStatement,ce as LiteralKanonak,Lt as LocalFirstRepository,rn as LookRenderer,Xr as MarkdownLinkRule,Jt as MarkdownStatement,Lr as NamespaceImportCycleRule,$r as NamespacePrefixRule,or as NodeType,ue as NumberStatement,lr as OWL_RL_CLASSIFICATION_RULES,Gr as ObjectPropertyImportRule,Jr as ObjectPropertyValueValidationRule,vr as OntologyValidationError,Er as OntologyValidationResult,P as PackageBuilder,ee as ProducerRepository,qr as PropertyDomainRule,Or as PropertyHierarchyCycleRule,pr as PropertyMetadata,Wr as PropertyRangeReferenceRule,Nr as PropertyRangeRequiredRule,jr as PropertyTypeSpecificityRule,Yr as PropertyValueTypeRule,Ot as PublisherConfigResolver,Nt as PublisherIndex,cr as RDFS_RULES,ye as Reasoner,ur as ReasoningResult,k as ReferenceKanonak,pe as ReferenceStatement,Tt as RepositoryFactory,Ir as ResourceNamingRule,qt as ResourceResolver,nr as ResourceTypeClassifier,Gt as ScalarStatement,Wt as Statement,le as StringStatement,Ur as SubClassOfReferenceRule,_r as SubPropertyOfReferenceRule,f as SubjectKanonak,Br as SubjectKanonakTypeRequiredRule,sr as TripleStore,Yt as TypeResolver,Dr as UnresolvedReferenceRule,Kr as ValidationCache,xr as ValidationContext,Cr as ValidationSeverity,ca as VersionOperator,re as ViewMaterializer,Hr as XsdImportRule,$e as allowAllPolicy,Ut as assertPackageIdentity,Mt as buildLocalFirstRepository,nn as buildOntologyModel,Ce as canonicalForm,Q as canonicalHash,Ft as collectKanonakFiles,O as compareVersions,ot as computeIntegrity,Ke as contentAddressedName,Sr as contextTypesOf,Qe as createAuthenticatedFetch,B as createDPoPProof,vt as createVersion,rr as extractMarkdownLinks,en as findDerivation,Rr as findInstancesByType,tr as findMalformedReferences,yr as findMarkdownLinkAt,hr as formatKanonakAddress,h as formatVersion,Ze as generateDPoPKeyPair,Dt as getGlobalCachePath,_ as hasValidToken,Kt as isCompatibleVersion,U as isExpired,$t as isMajorCompatible,rt as loadLockFile,Zt as makeUriKey,Ie as noopMeter,l as normalizeHost,ge as parseKanonakAddress,xt as parseVersionString,fr as parseWithPositions,It as pickHighestDocument,Pr as propertiesInScope,tn as resolveDisplayValue,wr as resolvePropertyStep,V as sanitizeName,nt as saveLockFile,Xe as serverSupportsDPoP,g as subjectUri,br as superClassChain,Xt as tripleKey,R as uriKey,Qt as uriTriple,Et as versionOperatorFromChar,ae as versionOperatorToChar,Ct as versionsEqual};
93
+ Check the 'credentialHelper' path in ~/.kanonak/config.json.`)}}async store(e,t){let n=l(e);try{await this.runHelper("store",{publisher:n,credential:t})}catch(o){throw new Error(`Credential helper '${this.helperPath}' failed to store credential for '${n}': ${X(o)}
94
+ Verify the helper binary supports the 'store' action.`)}}async remove(e){let t=l(e);try{await this.runHelper("erase",{publisher:t})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${t}': ${X(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${X(e)}`),[]}}async runHelper(e,t){try{let{stdout:n}=await Ln(this.helperPath,[e],{...t&&{input:JSON.stringify(t)},timeout:mt});return n}catch(n){throw Un(n)?new Error(`Credential helper not found at '${this.helperPath}'.
95
+ Check the 'credentialHelper' path in ~/.kanonak/config.json.`):_n(n)?new Error(`Credential helper '${this.helperPath}' timed out after ${mt/1e3}s on '${e}'.
96
+ The helper may be waiting for authentication to an external vault.`):n}}};function X(r){return r instanceof Error?r.message:String(r)}function Un(r){return r instanceof Error&&"code"in r&&r.code==="ENOENT"}function _n(r){return r instanceof Error&&"killed"in r&&r.killed}var ve=zn(Hn(),".kanonak","config.json"),Q=class{backend=null;backendReady=null;async getBackend(){if(this.backend)return this.backend;if(this.backendReady)return this.backendReady;this.backendReady=this.resolveBackend();try{return this.backend=await this.backendReady,this.backend}catch(e){throw this.backendReady=null,e}}async getToken(e){let t=Wn(e);if(t)return t;let o=await(await this.getBackend()).get(e);return!o||!_(o)?null:o.accessToken??null}async getCredential(e){return(await this.getBackend()).get(e)}async store(e,t){return(await this.getBackend()).store(e,t)}async remove(e){return(await this.getBackend()).remove(e)}async list(){return(await this.getBackend()).list()}async resolveBackend(){let e=Gn();return e.credentialHelper?new B(e.credentialHelper):process.platform==="darwin"?new x:process.platform==="win32"?new I:await Se()?new K:new j}};function Wn(r){let t="KANONAK_TOKEN_"+l(r).replace(/[.\-]/g,"_").toUpperCase();return process.env[t]??null}function Gn(){if(!Fn(ve))return{};try{return JSON.parse(Mn(ve,"utf-8"))}catch(r){let e=r instanceof Error?r.message:String(r);return console.warn(` Warning: Failed to parse ${ve}: ${e}
97
+ Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as Jn,createPrivateKey as qn,generateKeyPairSync as Yn,randomUUID as Zn,sign as Xn}from"crypto";function yt(){let{publicKey:r,privateKey:e}=Yn("ec",{namedCurve:"P-256"});return{publicKey:r.export({format:"jwk"}),privateKey:e.export({format:"jwk"})}}function A(r,e,t,n,o,a){let i={alg:"ES256",typ:"dpop+jwt",jwk:{kty:e.kty,crv:e.crv,x:e.x,y:e.y}},s={jti:Zn(),htm:t.toUpperCase(),htu:n,iat:Math.floor(Date.now()/1e3)};return o&&(s.ath=Jn("sha256").update(o).digest("base64url")),a&&(s.nonce=a),Qn(i,s,r)}function gt(r){return!r||r.length===0?!1:r.some(e=>e.toUpperCase()==="ES256")}function Qn(r,e,t){let n=ft(JSON.stringify(r)),o=ft(JSON.stringify(e)),a=`${n}.${o}`,i=qn({key:t,format:"jwk"}),c=Xn("SHA256",Buffer.from(a),{key:i,dsaEncoding:"ieee-p1363"}).toString("base64url");return`${a}.${c}`}function ft(r){return Buffer.from(r,"utf-8").toString("base64url")}function ht(r){let e=new Map;return async(t,n,o="GET")=>{if(!r)return fetch(t,{method:o});let a=await r.getCredential(n);if(!a?.accessToken)return fetch(t,{method:o});U(a)&&console.warn(` Warning: Access token for '${n}' is expired. Run 'kanonak login ${n}' to re-authenticate.`);let i={};if(a.dpopKeyPair){let c=e.get(n);try{let u=A(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,t,a.accessToken,c);i.Authorization=`DPoP ${a.accessToken}`,i.DPoP=u}catch(u){let d=u instanceof Error?u.message:String(u);console.error(` Error: Failed to create DPoP proof for '${n}': ${d}
98
+ The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),i.Authorization=`Bearer ${a.accessToken}`}}else i.Authorization=`Bearer ${a.accessToken}`;let s=await fetch(t,{method:o,headers:i});if(s.status===401&&a.dpopKeyPair){let c=s.headers.get("DPoP-Nonce");if(c){e.set(n,c);try{let u=A(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,t,a.accessToken,c);i.DPoP=u,s=await fetch(t,{method:o,headers:i})}catch{}}}return s}}import{readFileSync as eo,writeFileSync as to,existsSync as ro}from"fs";import{createHash as no}from"crypto";import kt from"js-yaml";var bt="kanonak.lock",oo=`# This file is generated by Kanonak CLI. Do not edit manually.
99
+ `;function Pt(r=bt){if(!ro(r))return null;let e=eo(r,"utf-8"),t=kt.load(e);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??new Date().toISOString(),packages:t.packages??{}}}function wt(r,e=bt){r.lastUpdated=new Date().toISOString();let t={};for(let o of Object.keys(r.packages).sort())t[o]=r.packages[o];r.packages=t;let n=kt.dump(r,{lineWidth:-1,sortKeys:!1,quotingType:'"'});to(e,oo+n,"utf-8")}function St(r){return`sha256:${no("sha256").update(r).digest("hex")}`}import*as Ke from"js-yaml";import{createHash as ao}from"crypto";var Ct="1",Rt=new TextEncoder;function Et(r,e){let t=Rt.encode(r),n=Rt.encode(e),o=Math.min(t.length,n.length);for(let a=0;a<o;a++)if(t[a]!==n[a])return t[a]-n[a];return t.length-n.length}function xe(r){let e=[];for(let n of r)n instanceof f&&e.push(io(n));return e.sort((n,o)=>Et(n.uri,o.uri)),JSON.stringify({subjects:e})}function ee(r){let e=xe(r);return`sha256:${ao("sha256").update(e,"utf8").digest("hex")}`}function io(r){let e=mo(r),t=Ie(r.statement);return{uri:e,statements:t}}function Ie(r){let e=[];for(let t of r){let n=so(t);n&&e.push(n)}return e.sort((t,n)=>Et(t.predicate,n.predicate)),e}function so(r){let e=po(r);if(!e)return;let t=co(r);if(t)return uo(e,t)}function co(r){if(r instanceof ue&&r.carrier)return{type:"typed",carrier:r.carrier,value:R(r.carrier,r.lexical??String(r.object))};if(r instanceof de)return{type:"string",value:r.object};if(r instanceof pe)return{type:"number",value:Kt(r.object)};if(r instanceof me)return{type:"boolean",value:r.object};if(r instanceof fe)return{type:"ref",value:xt(r.object)};if(r instanceof ye){let e=r.object;return vt(e)}if(r instanceof ge)return{type:"list",items:r.object.map(lo)}}function vt(r){let e=Ie(r.statement);return r.name&&r.name.length>0?{type:"embedded",name:r.name,statements:e}:{type:"embedded",statements:e}}function lo(r){if(r instanceof k)return{type:"ref",value:xt(r)};if(r instanceof y)return vt(r);if(r instanceof le){if(r.carrier)return{type:"typed",carrier:r.carrier,value:R(r.carrier,r.lexical??String(r.value))};let e=r.value;if(typeof e=="string")return{type:"string",value:e};if(typeof e=="number")return{type:"number",value:Kt(e)};if(typeof e=="boolean")return{type:"boolean",value:e}}if(r instanceof ce)return{type:"embedded",statements:Ie(r.statement)};throw new Error(`canonicalForm: list item of unrecognized kind (${r.constructor?.name??typeof r}); add canonicalization support before hashing data that contains it`)}function uo(r,e){switch(e.type){case"string":return{predicate:r,type:"string",value:e.value};case"number":return{predicate:r,type:"number",value:e.value};case"boolean":return{predicate:r,type:"boolean",value:e.value};case"typed":return{predicate:r,type:"typed",carrier:e.carrier,value:e.value};case"ref":return{predicate:r,type:"ref",value:e.value};case"embedded":return e.name!==void 0?{predicate:r,type:"embedded",name:e.name,statements:e.statements}:{predicate:r,type:"embedded",statements:e.statements};case"list":return{predicate:r,type:"list",items:e.items}}}function po(r){let e=r.predicate;if(e)return It(e.subject)}function mo(r){let e=r.namespace??"",t=r.name??"";return`${e}/${t}`}function xt(r){return It(r.subject)}function It(r){let e=r.version;return e&&typeof e.major=="number"?`${r.publisher}/${r.package_}@${e.major}.${e.minor}.${e.patch}/${r.name}`:`${r.publisher}/${r.package_}/${r.name}`}function Kt(r){if(Number.isNaN(r))throw new Error("canonicalForm: NaN cannot be canonicalized");if(!Number.isFinite(r))throw new Error("canonicalForm: \xB1Infinity cannot be canonicalized");return Object.is(r,-0)?"0":String(r)}import{VersionOperator as $t}from"@kanonak-protocol/types/document/models/enums";var fo="0.0.0",P=class{constructor(e,t=new S,n){this.repository=e;this.parser=t;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new D}serializeValue(e,t){return At(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),n=await this.hashBody(e.publisher,t,e.body),o=$e(n),a={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(a[e.contentHashProperty]=n),Object.assign(a,e.header??{}),a.imports=t;let i={[o]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:Bt(s),contentHash:n,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),n[e.contentHashProperty]=o),Object.assign(n,e.header??{}),n.imports=t;let a={[e.name]:n,...e.body},i=this.dump(a),s={yaml:i,byteCount:Bt(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return Ke.dump(e,{lineWidth:-1})}async hashBody(e,t,n){let o={[jt]:{type:"EphemeralPackage",publisher:e,imports:t},...n},a=this.parser.parse(Ke.dump(o,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new et(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==jt);for(let u of c)u.namespace="ephemeral";return ee(c)}},jt="__pkgbuilder_probe__";function Bt(r){return new TextEncoder().encode(r).length}function $e(r){let e="sha256:",t=r.startsWith(e)?e.length:0;return`q-${r.slice(t,t+16)}`}var D=class{byKey=new Map;aliases=new Set;ensure(e,t,n,o,a=$t.Major){let i=`${e}/${t}@${n}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(i,{publisher:e,package_:t,version:n,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,h(e.version),e.package_)}.${e.name}`}refLatest(e,t,n,o){return`${this.ensure(e,t,fo,o??t,$t.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let o=e.get(n.publisher)??[];o.push(n),e.set(n.publisher,o)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((o,a)=>o.package_<a.package_?-1:1).map(o=>({package:o.package_,match:se(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=V(e)||"pkg",n=t,o=2;for(;this.aliases.has(n);)n=`${t}${o++}`;return this.aliases.add(n),n}};function At(r,e){if(r!=null){if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r instanceof k)return e.ref(r.subject);if(Array.isArray(r)){let t=r.map(n=>At(n,e)).filter(n=>n!==void 0);return t.length>0?t:void 0}if(r instanceof y)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(yo(r))throw new Error(`Value produced a bare URI without a version (${r.publisher}/${r.package_}/${r.name}); cannot serialize it as a reference.`)}}function V(r){return r.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function yo(r){return typeof r=="object"&&r!==null&&typeof r.publisher=="string"&&typeof r.package_=="string"&&typeof r.name=="string"}var te=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(n=>n.canProduce(e,t))}async produceCached(e,t,n,o){let a=`${t}/${n}@${h(o)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(t,n,o);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,t){let n=this.producerFor(e,t.packageName);if(!n)return null;let o={operator:t.versionOperator,version:t.version},a=await n.resolveVersion(e,t.packageName,o);return a?this.produceCached(n,e,t.packageName,a):null}async getDocumentAsync(e){let t;try{t=ke(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let n=this.producerFor(t.publisher,t.package_);return n?this.produceCached(n,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(n=>{let o=n.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var je={async authorize(){return{allowed:!0}}},Be={async record(){}},T=class extends Error{constructor(t,n){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${n?`: ${n}`:""}`);this.address=t;this.reason=n;this.name="EntitlementDeniedError"}address;reason},re=class{inner;ctx;policy;meter;constructor(e,t,n=je,o=Be){this.inner=e,this.ctx=t,this.policy=n,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,n){return await this.assertAllowed({publisher:e,package_:t,version:n.version}),this.inner.resolveVersion(e,t,n)}async produce(e,t,n){let o={publisher:e,package_:t,version:n};await this.assertAllowed(o);let a=await this.inner.produce(e,t,n);return await this.meter.record(this.ctx,o,a),a}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new T(e,t.reason)}};var p="kanonak.org",m="view",Dt="core-kanonak",go={publisher:p,package_:m,name:"rootView"},ho={publisher:p,package_:m,name:"bind"},ko={publisher:p,package_:m,name:"produces"},bo={publisher:p,package_:m,name:"projections"},Po={publisher:p,package_:m,name:"where"},wo={publisher:p,package_:m,name:"value"},So={publisher:p,package_:m,name:"as"},ne=class{constructor(e,t=new S){this.repository=e;this.parser=t;this.objectParser=new E(this.parser),this.builder=new P(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,t={}){let n=await this.objectParser.parseKanonaks(this.repository),o=this.resolveView(n,e),a=v(o,ho);if(!a)throw new Error(`View ${o.namespace}/${o.name} declares no view.bind; cannot materialize.`);let i=v(o,ko);if(!i)throw new Error(`View ${o.namespace}/${o.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let s=Ro(o),c=Vt(n,p,Dt),u=Vt(n,p,m),d=this.builder.imports(),oe=d.ensure(p,Dt,c,"ck"),Ot=d.ensure(p,m,u,"v"),Nt=d.ref(i),Lt=new nt(this.repository,this.parser,this.objectParser),Ae=new tt(Lt,n),Ut=this.readProjections(n,o),_t=vo(o,Po),Ft=this.findInstances(n,a,await this.reason(t)),De={},Mt=new Set;for(let O of Ft){if(!await this.passesWhere(Ae,n,_t,O))continue;let ie={type:Nt};for(let Te of Ut){let Ht=await this.evaluateValue(Ae,n,Te.value,O),Oe=this.builder.serializeValue(Tt(Ht),d);Oe!==void 0&&(ie[d.ref(Te.as)]=Oe)}let Ve=g(O);Ve&&(ie[`${Ot}.derivedFrom`]=d.ref(Ve)),De[this.rowName(O,Mt)]=ie}let ae={};t.resolvedAt&&(ae[`${oe}.resolvedAt`]=t.resolvedAt),t.invocationId&&(ae[`${oe}.id`]=t.invocationId);let w=await this.builder.buildContentAddressed({publisher:s,book:d,body:De,contentHashProperty:`${oe}.contentHash`,header:ae});return{yaml:w.yaml,contentHash:w.contentHash,packageName:w.packageName,publisher:w.publisher,rowCount:w.resourceCount}}resolveView(e,t){let n=L(e,t);if(!n)throw new Error(`View ${t.publisher}/${t.package_}/${t.name} not found in the catalog.`);let o=v(n,go);if(o){let a=L(e,o);if(!a)throw new Error(`ViewPackage ${t.name} names rootView ${o.name}, which is not in the catalog.`);return a}return n}readProjections(e,t){let n=[];for(let o of Pe(t,bo)){let a=o instanceof y?o:o instanceof k?L(e,o.subject):void 0;if(!a)continue;let i=be(a,wo),s=v(a,So);i&&s&&n.push({value:i,as:s})}return n}async reason(e){return new he({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,t,n){let o=Eo(e),a=[],i=new Set;for(let s of n.getInstancesOfClass(t)){if(i.has(s))continue;i.add(s);let c=o.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=C(g(s)),d=C(g(c));return u<d?-1:u>d?1:0}),a}async passesWhere(e,t,n,o){for(let a of n){let i=await this.evaluateValue(e,t,a,o);if(!xo(i))return!1}return!0}async evaluateValue(e,t,n,o){let a=rt(n,"view-projection",{catalog:t,depth:0}),i=new Map([["input",o]]);return e.evaluate(a,i)}rowName(e,t){let n=V(e.name)||"row",o=n,a=2;for(;t.has(o);)o=`${n}-${a++}`;return t.add(o),o}};function Tt(r){return we(r)?r.value:Array.isArray(r)?r.map(Tt):r}function Ro(r){let e=g(r);if(!e)throw new Error(`Could not derive a publisher from view ${r.namespace}/${r.name}.`);return e.publisher}function Vt(r,e,t){let n=Co(r,e,t);if(!n)throw new Error(`Package ${e}/${t} is not in the catalog; it must be importable to materialize a view.`);return n}function Co(r,e,t){let n;for(let o of r){if(!(o instanceof f))continue;let a=g(o);!a||a.publisher!==e||a.package_!==t||!a.version||(!n||N(a.version,n)>0)&&(n=a.version)}return n?h(n):void 0}function Eo(r){let e=new Map,t=new Map;for(let n of r){if(!(n instanceof f))continue;let o=g(n);if(!o||!o.version)continue;let a=C(o),i=t.get(a);(!i||N(o.version,i)>0)&&(t.set(a,o.version),e.set(a,n))}return e}function vo(r,e){let t=be(r,e);return t?[t]:Pe(r,e).filter(n=>n instanceof y)}function xo(r){return r===!0?!0:r===!1||r===void 0||r===null?!1:typeof r=="string"?r.length>0:typeof r=="number"?r!==0:we(r)?r.value.length>0:Array.isArray(r)?r.length>0:!!r}export{pn as AmbiguousReferenceRule,me as BooleanStatement,Ct as CANONICAL_FORM_VERSION,Ne as Carrier,kn as ClassDefinitionRule,rn as ClassHierarchyCycleRule,tr as CompositeKanonakDocumentRepository,Q as CredentialStore,ce as DefinedKanonak,un as DefinitionPropertyReferenceRule,er as DocumentLocation,Er as EdgeType,y as EmbeddedKanonak,Qr as EmbeddedKanonakTypeRule,ye as EmbeddedStatement,T as EntitlementDeniedError,re as EntitlementProducer,Qt as FileSystemKanonakDocumentRepository,jr as GitIgnoreFilter,vr as GraphBuilder,sr as HttpKanonakDocumentRepository,D as ImportBook,en as ImportExistenceRule,Xt as InMemoryKanonakDocumentRepository,ln as InstancePropertyReferenceRule,dr as Kanonak,Ar as KanonakDocumentPositions,E as KanonakObjectParser,Pn as KanonakObjectValidator,S as KanonakParser,pr as KanonakUri,Tr as KanonakUriBuilder,Nr as KanonakUrlResolver,Pr as KanonakVocabulary,ge as ListStatement,le as LiteralKanonak,cr as LocalFirstRepository,Rn as LookRenderer,bn as MarkdownLinkRule,fr as MarkdownStatement,cn as NamespaceImportCycleRule,qr as NamespacePrefixRule,Cr as NodeType,pe as NumberStatement,Kr as OWL_RL_CLASSIFICATION_RULES,fn as ObjectPropertyImportRule,yn as ObjectPropertyValueValidationRule,Wr as OntologyValidationError,Hr as OntologyValidationResult,P as PackageBuilder,te as ProducerRepository,gn as PropertyDomainRule,nn as PropertyHierarchyCycleRule,Br as PropertyMetadata,mn as PropertyRangeReferenceRule,on as PropertyRangeRequiredRule,Zr as PropertyTypeSpecificityRule,hn as PropertyValueTypeRule,or as PublisherConfigResolver,ar as PublisherIndex,Ir as RDFS_RULES,he as Reasoner,$r as ReasoningResult,k as ReferenceKanonak,fe as ReferenceStatement,nr as RepositoryFactory,Yr as ResourceNamingRule,yr as ResourceResolver,Rr as ResourceTypeClassifier,ue as ScalarStatement,mr as Statement,de as StringStatement,an as SubClassOfReferenceRule,sn as SubPropertyOfReferenceRule,f as SubjectKanonak,Xr as SubjectKanonakTypeRequiredRule,xr as TripleStore,gr as TypeResolver,tn as UnresolvedReferenceRule,Jr as ValidationCache,Gr as ValidationContext,zr as ValidationSeverity,ji as VersionOperator,ne as ViewMaterializer,dn as XsdImportRule,je as allowAllPolicy,ir as assertPackageIdentity,ur as buildLocalFirstRepository,Cn as buildOntologyModel,We as canonicalAnyUri,Ye as canonicalBase64,He as canonicalBoolean,Xe as canonicalDate,Ze as canonicalDateTime,_e as canonicalDecimal,Fe as canonicalDouble,Me as canonicalFloat,xe as canonicalForm,ee as canonicalHash,qe as canonicalHexBinary,Ue as canonicalInteger,Ge as canonicalLangString,Je as canonicalLanguageTag,R as canonicalScalarLexical,ze as canonicalString,Qe as canonicalTime,Le as carrierOf,lr as collectKanonakFiles,N as compareVersions,St as computeIntegrity,$e as contentAddressedName,Fr as contextTypesOf,ht as createAuthenticatedFetch,A as createDPoPProof,Gt as createVersion,Sr as extractMarkdownLinks,wn as findDerivation,Mr as findInstancesByType,wr as findMalformedReferences,Vr as findMarkdownLinkAt,Or as formatKanonakAddress,h as formatVersion,yt as generateDPoPKeyPair,rr as getGlobalCachePath,_ as hasValidToken,qt as isCompatibleVersion,U as isExpired,Yt as isMajorCompatible,Pt as loadLockFile,hr as makeUriKey,Be as noopMeter,l as normalizeHost,ke as parseKanonakAddress,Jt as parseVersionString,Dr as parseWithPositions,Zt as pickHighestDocument,Ur as propertiesInScope,Sn as resolveDisplayValue,_r as resolvePropertyStep,V as sanitizeName,wt as saveLockFile,gt as serverSupportsDPoP,g as subjectUri,Lr as superClassChain,kr as tripleKey,C as uriKey,br as uriTriple,zt as versionOperatorFromChar,se as versionOperatorToChar,Wt as versionsEqual};
@@ -21,4 +21,8 @@ import { Kanonak } from './Kanonak.js';
21
21
  */
22
22
  export declare class LiteralKanonak extends Kanonak {
23
23
  value: string | number | boolean;
24
+ /** Canonical-form datatype carrier (a `Carrier` string) when range-typed; see {@link ScalarStatement}. */
25
+ carrier?: string;
26
+ /** Raw lexical token, the precise canonicalization input; `value` may be a lossy native projection. */
27
+ lexical?: string;
24
28
  }
@@ -37,6 +37,19 @@ export declare class KanonakObjectParser implements IKanonakObjectParser {
37
37
  private getPropertyMetadata;
38
38
  private parsePropertyValue;
39
39
  private parseDatatypeValue;
40
+ /**
41
+ * Type a raw scalar lexical token by its property's resolved range, so the
42
+ * ontology — not the YAML reader — decides the datatype. A numeric carrier
43
+ * yields a NumberStatement (its `object` a native projection, possibly lossy;
44
+ * `lexical` the exact token), a boolean carrier a BooleanStatement, and
45
+ * everything else a StringStatement carrying the raw token. The carrier (when
46
+ * the range resolves to one) drives datatype-precise canonical identity;
47
+ * untyped/open-world values carry no carrier and canonicalize as their raw
48
+ * token (the lossless open-world tier).
49
+ */
50
+ private typedScalarStatement;
51
+ /** A datatype-list literal, range-typed like {@link typedScalarStatement}. */
52
+ private typedListLiteral;
40
53
  /**
41
54
  * Build a MarkdownStatement for a core-prose datatype value: the raw
42
55
  * string becomes the statement `object`, and every `[[reference]]`
@@ -1 +1 @@
1
- import{a as c,b as d,c as e,d as f}from"../chunk-PJMOM5H7.js";import{f as b}from"../chunk-IUZZDC2U.js";import{a}from"../chunk-TJPQETHV.js";import"../chunk-IOMNZBK4.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
1
+ import{a as c,b as d,c as e,d as f}from"../chunk-YI5GLYMB.js";import{w as b}from"../chunk-WUAKDYY6.js";import{a}from"../chunk-ZYAABYDS.js";import"../chunk-XYEY6HUC.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
@@ -1 +1 @@
1
- import{a as g,b as h,c as i,d as j,e as k}from"../chunk-KXVSGB6Q.js";import"../chunk-IUZZDC2U.js";import"../chunk-TJPQETHV.js";import{d as a,e as b,f as c,h as d,i as e,j as f}from"../chunk-IOMNZBK4.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
1
+ import{a as g,b as h,c as i,d as j,e as k}from"../chunk-6I4BYZVA.js";import"../chunk-WUAKDYY6.js";import"../chunk-ZYAABYDS.js";import{d as a,e as b,f as c,h as d,i as e,j as f}from"../chunk-XYEY6HUC.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
@@ -1 +1 @@
1
- import{b as e,c as r,d as n}from"../chunk-LKBG2MK6.js";import{a as o}from"../chunk-4NO7MHS7.js";import"../chunk-SC5M74NM.js";import"../chunk-TJPQETHV.js";import"../chunk-2ACBWC7K.js";export{n as HttpKanonakDocumentRepository,o as InMemoryKanonakDocumentRepository,e as PublisherConfigResolver,r as PublisherIndex};
1
+ import{b as e,c as r,d as n}from"../chunk-YCV4H6H5.js";import{a as o}from"../chunk-4NO7MHS7.js";import"../chunk-SC5M74NM.js";import"../chunk-ZYAABYDS.js";import"../chunk-2ACBWC7K.js";export{n as HttpKanonakDocumentRepository,o as InMemoryKanonakDocumentRepository,e as PublisherConfigResolver,r as PublisherIndex};
@@ -1 +1 @@
1
- import{a as b,b as c,c as d,d as e,e as f,f as k,g as l,h as m}from"../chunk-ATH6636H.js";import{a as g,b as h,c as i,d as j}from"../chunk-LKBG2MK6.js";import{a}from"../chunk-4NO7MHS7.js";import"../chunk-SC5M74NM.js";import"../chunk-TJPQETHV.js";import"../chunk-2ACBWC7K.js";export{d as CompositeKanonakDocumentRepository,c as DocumentLocation,b as FileSystemKanonakDocumentRepository,j as HttpKanonakDocumentRepository,a as InMemoryKanonakDocumentRepository,k as LocalFirstRepository,h as PublisherConfigResolver,i as PublisherIndex,f as RepositoryFactory,m as buildLocalFirstRepository,l as collectKanonakFiles,g as defaultPublisherConfig,e as getGlobalCachePath};
1
+ import{a as b,b as c,c as d,d as e,e as f,f as k,g as l,h as m}from"../chunk-YWUKDEZA.js";import{a as g,b as h,c as i,d as j}from"../chunk-YCV4H6H5.js";import{a}from"../chunk-4NO7MHS7.js";import"../chunk-SC5M74NM.js";import"../chunk-ZYAABYDS.js";import"../chunk-2ACBWC7K.js";export{d as CompositeKanonakDocumentRepository,c as DocumentLocation,b as FileSystemKanonakDocumentRepository,j as HttpKanonakDocumentRepository,a as InMemoryKanonakDocumentRepository,k as LocalFirstRepository,h as PublisherConfigResolver,i as PublisherIndex,f as RepositoryFactory,m as buildLocalFirstRepository,l as collectKanonakFiles,g as defaultPublisherConfig,e as getGlobalCachePath};
@@ -1 +1 @@
1
- import{a as p,b as y}from"../chunk-PEUTCG3B.js";import{a as s}from"../chunk-PEJALHXK.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as o,b as q,c as r,d as t,e as u,f as v,g as w,h as x}from"../chunk-Z5ELOT2C.js";import"../chunk-XQS5LDSO.js";import{b as m,c as n}from"../chunk-IOMNZBK4.js";import"../chunk-W6T7MOKY.js";import{a as l}from"../chunk-FUUTGGJS.js";import{a,b,c,d,e,f,g,h,i,j}from"../chunk-2ACBWC7K.js";export{l as KanonakUri,p as KanonakUriBuilder,s as KanonakUrlResolver,m as ResourceResolver,o as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,x as contextTypesOf,f as createVersion,y as findInstancesByType,r as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,i as isMajorCompatible,q as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,v as propertiesInScope,w as resolvePropertyStep,t as subjectUri,u as superClassChain,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
1
+ import{a as p,b as y}from"../chunk-PEUTCG3B.js";import{a as s}from"../chunk-PEJALHXK.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as o,b as q,c as r,d as t,e as u,f as v,g as w,h as x}from"../chunk-NC3FSY3R.js";import"../chunk-PBNVHBS3.js";import{b as m,c as n}from"../chunk-XYEY6HUC.js";import"../chunk-T3JR2SV6.js";import{a as l}from"../chunk-FUUTGGJS.js";import{a,b,c,d,e,f,g,h,i,j}from"../chunk-2ACBWC7K.js";export{l as KanonakUri,p as KanonakUriBuilder,s as KanonakUrlResolver,m as ResourceResolver,o as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,x as contextTypesOf,f as createVersion,y as findInstancesByType,r as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,i as isMajorCompatible,q as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,v as propertiesInScope,w as resolvePropertyStep,t as subjectUri,u as superClassChain,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
@@ -1,4 +1,4 @@
1
- import{a as g}from"../chunk-XWRVENU6.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import"../chunk-IUZZDC2U.js";import"../chunk-TJPQETHV.js";import{d as m,h as S}from"../chunk-Z5ELOT2C.js";import{a as p,f as E}from"../chunk-XQS5LDSO.js";import"../chunk-IOMNZBK4.js";import{c as v}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as x}from"../chunk-2ACBWC7K.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
1
+ import{a as g}from"../chunk-ZRMF5QLN.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import"../chunk-WUAKDYY6.js";import"../chunk-ZYAABYDS.js";import{d as m,h as S}from"../chunk-NC3FSY3R.js";import{a as p,f as E}from"../chunk-PBNVHBS3.js";import"../chunk-XYEY6HUC.js";import{c as v}from"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import{c as x}from"../chunk-2ACBWC7K.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
2
2
  Install it with:
3
3
  npm install @huggingface/transformers
4
4
  (underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`
@@ -1,3 +1,3 @@
1
- import{j as E}from"../chunk-XWRVENU6.js";import"../chunk-QHABFCRC.js";import{a as Z,d as A,f as te,g as N}from"../chunk-ATH6636H.js";import{a as ee,b as re,c as V,d as I}from"../chunk-LKBG2MK6.js";import{a as X}from"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import{a as oe}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import{f as L}from"../chunk-IUZZDC2U.js";import{a as D}from"../chunk-TJPQETHV.js";import{b as O}from"../chunk-Z5ELOT2C.js";import"../chunk-XQS5LDSO.js";import"../chunk-IOMNZBK4.js";import{c as ne}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as F,e as z,f as K,g as Q}from"../chunk-2ACBWC7K.js";import{readFileSync as ue,existsSync as de,readdirSync as me,writeFileSync as ge,mkdirSync as fe}from"fs";import{join as q}from"path";function se(n){let e=n.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function M(n,e){let t=new Set,r=[...n];for(;r.length>0;){let o=r.shift(),i=se(o);if(!i||t.has(i))continue;t.add(i);let d=o.metadata?.imports;if(d)for(let[c,f]of Object.entries(d))for(let g of f)try{let l=await e.getHighestCompatibleVersionAsync(c,g);l&&r.push(l)}catch{}}return t}var j=class{constructor(e,t){this.inner=e;this.scope=t}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(t=>{let r=se(t);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){return this.inner.getDocumentsByNamespaceAsync(e,t)}getHighestCompatibleVersionAsync(e,t){return this.inner.getHighestCompatibleVersionAsync(e,t)}saveDocumentAsync(e,t){return this.inner.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.inner.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var ae=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function C(n){let e=n?.render;if(e&&e.length>0){let t=[];for(let r of e)try{let o=O(r);o.kind==="package"?t.push({publisher:o.publisher,package_:o.package_}):o.kind==="resource"&&t.push({publisher:o.uri.publisher,package_:o.uri.package_})}catch{}if(t.length>0)return t}return ae}function H(n){return`${n.publisher}/${n.package_}`}function B(n){let{publisher:e,availablePublishers:t,catalog:r,lookRenderer:o,localNamespaces:i,rawByNsKey:d,producers:c}=n,f=new Map,g=new Map,l=new Map,a=new Set;for(let m of r){if(!(m instanceof ne))continue;let y=m.namespace||"";if(!i.has(y))continue;f.set(`${y}/${m.name}`,m);let v=y.split("/")[1]??"",[x,p]=v.split("@");if(!x||!p)continue;let b=Q(p);b&&(a.has(v)||(a.add(v),g.has(x)||g.set(x,[]),g.get(x).push({verStr:p,version:b})),m.name===x&&l.set(v,m))}for(let m of g.values())m.sort((y,v)=>F(v.version,y.version));return{publisher:e,availablePublishers:t,catalog:r,lookRenderer:o,localNamespaces:i,rawByNsKey:d,bySubject:f,pkgVersions:g,pkgSelfByVer:l,...c?{producers:c}:{}}}async function T(n,e={}){let t=new D,r=new X(t),o=[],i=[];for(let p of N(n)){let b;try{b=ue(p,"utf-8")}catch{continue}let w;try{w=t.parse(b).metadata?.namespace_}catch{continue}if(!w?.version)continue;let $=w.version;i.push({publisher:w.publisher,package_:w.package_,verStr:`${$.major}.${$.minor}.${$.patch}`,version:$,source:b})}i.sort((p,b)=>F(b.version,p.version));for(let p of i)await r.saveDocumentAsync(t.parse(p.source),`${p.publisher}/${p.package_}@${p.verStr}`),o.push({publisher:p.publisher,package_:p.package_,verStr:p.verStr,source:p.source});let d=[...new Set(o.map(p=>p.publisher))].sort(),c=e.publisher;if(c){if(!d.includes(c))throw new Error(`Publisher "${c}" not found in workspace. Available: ${d.join(", ")||"(none)"}`)}else if(d.length===1)c=d[0];else throw d.length===0?new Error(`No Kanonak packages found under ${n}`):new Error(`Workspace has multiple publishers (${d.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,g=new Map;for(let p of o)p.publisher===c&&(f.add(`${p.publisher}/${p.package_}@${p.verStr}`),g.set(`${p.package_}@${p.verStr}`,p.source));let l=new Z(A(),!0,t),a=e.repository??new te(r,l,new I(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),m=C(void 0);if(!e.repository){let p=A(),b=s=>{let h=q(p,s);return de(h)?new Set(me(h).filter(k=>k.endsWith(".kan.yml")).map(k=>k.split("@")[0])):new Set},w=(s,h)=>o.some(k=>k.publisher===s&&k.package_===h),$=new V,u=new Map;for(let s of m)if(u.has(s.publisher)||u.set(s.publisher,b(s.publisher)),!(u.get(s.publisher).has(s.package_)||w(s.publisher,s.package_)))try{let h=await $.getHighestVersion(s.publisher,s.package_);if(!h)continue;let k=await $.getPackageUrl(s.publisher,s.package_,h),_=await fetch(k);if(!_.ok)continue;let le=await _.text(),J=q(p,s.publisher);fe(J,{recursive:!0}),ge(q(J,`${s.package_}@${h}.kan.yml`),le,"utf-8")}catch{}}let y=a;if(!e.repository){let p=(await r.getAllDocumentsAsync()).filter(w=>w.metadata.namespace_?.publisher===c),b=await M(p,a);for(let w of m)b.add(H(w));y=new j(a,b)}let v=await new L(t).parseKanonaks(y),x=new E(v);return B({publisher:c,availablePublishers:d,catalog:v,lookRenderer:x,localNamespaces:f,rawByNsKey:g})}import{existsSync as he,readFileSync as ke,writeFileSync as ye,mkdirSync as ve}from"fs";import{join as ie}from"path";async function U(n,e={}){let t=new D,r=O(n),o=r.kind==="resource"?r.uri.publisher:r.publisher,i=e.cacheRoot??A(),d=(u,s,h)=>ie(i,u,`${s}@${h}.kan.yml`),c=new I({getFromCache:(u,s,h)=>{let k=d(u,s,h);return he(k)?ke(k,"utf-8"):null},onFetch:(u,s,h,k)=>{let _=ie(i,u);ve(_,{recursive:!0}),ye(d(u,s,h),k,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),f=new V(e.fetchFn?{fetchFn:e.fetchFn}:void 0),g;if(r.kind==="resource"){let u=r.uri.version;g=[u?{package_:r.uri.package_,version:`${u.major}.${u.minor}.${u.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let u=r.version;g=[u?{package_:r.package_,version:`${u.major}.${u.minor}.${u.patch}`}:{package_:r.package_}]}else g=(await f.listLatestPackages(o)).map(s=>({package_:s.packageName}));let l=async(u,s,h)=>{try{let k=h?t.buildImport(s,"=",h,u):t.buildImport(s,"*","0.0.0",u);return await c.getHighestCompatibleVersionAsync(u,k)}catch{return null}},a=[];for(let u of g){let s=await l(o,u.package_,u.version);s&&a.push(s)}if(a.length===0)throw new Error(`Could not fetch any package for address "${n}" from publisher "${o}".`);let m=await new re().getConfig(o).catch(()=>{}),y=[];for(let u of C(m)){let s=await l(u.publisher,u.package_,void 0);s&&y.push(s)}let v=await M([...a,...y],c),x=new j(c,v),p=await new L(t).parseKanonaks(x),b=new E(p),w=new Set,$=new Map;for(let u of await c.getAllDocumentsAsync()){let s=u.metadata.namespace_;if(!s||s.publisher!==o)continue;let h=`${s.version.major}.${s.version.minor}.${s.version.patch}`,k=`${s.publisher}/${s.package_}@${h}`;w.add(k);let _=await c.getDocumentContentAsync(k);_!==null&&$.set(`${s.package_}@${h}`,_)}return B({publisher:o,availablePublishers:[o],catalog:p,lookRenderer:b,localNamespaces:w,rawByNsKey:$})}import{VersionOperator as W}from"@kanonak-protocol/types/document/models/enums";var S={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},R=(n,e,t,r)=>({status:n,headers:{"Content-Type":e,...r||{}},body:t}),P=n=>R(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${n}</p>`),be=n=>({status:301,headers:{Location:n},body:""}),we=n=>({status:302,headers:{Location:n},body:""});function Se(n){switch(n.kind){case"exact":return{operator:W.Exact,version:K(n.major,n.minor,n.patch)};case"minor-pin":return{operator:W.Compatible,version:K(n.major,n.minor,0)};case"major-pin":return{operator:W.Major,version:K(n.major,0,0)};default:return{operator:W.Any,version:K(0,0,0)}}}async function Re(n,e,t,r){if(!r)return null;let o=n.producers?.find(f=>f.canProduce(n.publisher,e));if(!o)return null;let i=await o.resolveVersion(n.publisher,e,Se(t));if(!i)return null;let d=z(i);if(t.kind!=="exact")return we(`/${e}/${d}.kan.yml`);let{source:c}=await o.produce(n.publisher,e,i);return R(200,S[".kan.yml"],c)}function ce(n,e,t){let r=n.pkgVersions.get(e);if(!r||r.length===0)return null;switch(t.kind){case"any":return r[0].verStr;case"major-pin":return r.find(o=>o.version.major===t.major)?.verStr??null;case"minor-pin":return r.find(o=>o.version.major===t.major&&o.version.minor===t.minor)?.verStr??null;case"exact":return r.find(o=>o.version.major===t.major&&o.version.minor===t.minor&&o.version.patch===t.patch)?.verStr??null;default:return null}}async function G(n,e,t=""){let{lookRenderer:r,publisher:o}=n;if(e==="/.well-known/kanonak.json"){let a=ee(o);return n.producers&&n.producers.length>0&&(a.resolveByRedirect=!0),R(200,S[".json"],JSON.stringify(a,null,2))}if(e==="/index.txt"){let a=[...n.localNamespaces].map(m=>m.split("/")[1].replace("@","/")).sort();return R(200,S[".txt"],a.join(`
1
+ import{j as E}from"../chunk-ZRMF5QLN.js";import"../chunk-QHABFCRC.js";import{a as Z,d as A,f as te,g as N}from"../chunk-YWUKDEZA.js";import{a as ee,b as re,c as V,d as I}from"../chunk-YCV4H6H5.js";import{a as X}from"../chunk-4NO7MHS7.js";import"../chunk-PEUTCG3B.js";import{a as oe}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-SHDHMKMJ.js";import{w as L}from"../chunk-WUAKDYY6.js";import{a as D}from"../chunk-ZYAABYDS.js";import{b as O}from"../chunk-NC3FSY3R.js";import"../chunk-PBNVHBS3.js";import"../chunk-XYEY6HUC.js";import{c as ne}from"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import{c as F,e as z,f as K,g as Q}from"../chunk-2ACBWC7K.js";import{readFileSync as ue,existsSync as de,readdirSync as me,writeFileSync as ge,mkdirSync as fe}from"fs";import{join as q}from"path";function se(n){let e=n.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function M(n,e){let t=new Set,r=[...n];for(;r.length>0;){let o=r.shift(),i=se(o);if(!i||t.has(i))continue;t.add(i);let d=o.metadata?.imports;if(d)for(let[c,f]of Object.entries(d))for(let g of f)try{let l=await e.getHighestCompatibleVersionAsync(c,g);l&&r.push(l)}catch{}}return t}var j=class{constructor(e,t){this.inner=e;this.scope=t}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(t=>{let r=se(t);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){return this.inner.getDocumentsByNamespaceAsync(e,t)}getHighestCompatibleVersionAsync(e,t){return this.inner.getHighestCompatibleVersionAsync(e,t)}saveDocumentAsync(e,t){return this.inner.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.inner.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var ae=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function C(n){let e=n?.render;if(e&&e.length>0){let t=[];for(let r of e)try{let o=O(r);o.kind==="package"?t.push({publisher:o.publisher,package_:o.package_}):o.kind==="resource"&&t.push({publisher:o.uri.publisher,package_:o.uri.package_})}catch{}if(t.length>0)return t}return ae}function H(n){return`${n.publisher}/${n.package_}`}function B(n){let{publisher:e,availablePublishers:t,catalog:r,lookRenderer:o,localNamespaces:i,rawByNsKey:d,producers:c}=n,f=new Map,g=new Map,l=new Map,a=new Set;for(let m of r){if(!(m instanceof ne))continue;let y=m.namespace||"";if(!i.has(y))continue;f.set(`${y}/${m.name}`,m);let v=y.split("/")[1]??"",[x,p]=v.split("@");if(!x||!p)continue;let b=Q(p);b&&(a.has(v)||(a.add(v),g.has(x)||g.set(x,[]),g.get(x).push({verStr:p,version:b})),m.name===x&&l.set(v,m))}for(let m of g.values())m.sort((y,v)=>F(v.version,y.version));return{publisher:e,availablePublishers:t,catalog:r,lookRenderer:o,localNamespaces:i,rawByNsKey:d,bySubject:f,pkgVersions:g,pkgSelfByVer:l,...c?{producers:c}:{}}}async function T(n,e={}){let t=new D,r=new X(t),o=[],i=[];for(let p of N(n)){let b;try{b=ue(p,"utf-8")}catch{continue}let w;try{w=t.parse(b).metadata?.namespace_}catch{continue}if(!w?.version)continue;let $=w.version;i.push({publisher:w.publisher,package_:w.package_,verStr:`${$.major}.${$.minor}.${$.patch}`,version:$,source:b})}i.sort((p,b)=>F(b.version,p.version));for(let p of i)await r.saveDocumentAsync(t.parse(p.source),`${p.publisher}/${p.package_}@${p.verStr}`),o.push({publisher:p.publisher,package_:p.package_,verStr:p.verStr,source:p.source});let d=[...new Set(o.map(p=>p.publisher))].sort(),c=e.publisher;if(c){if(!d.includes(c))throw new Error(`Publisher "${c}" not found in workspace. Available: ${d.join(", ")||"(none)"}`)}else if(d.length===1)c=d[0];else throw d.length===0?new Error(`No Kanonak packages found under ${n}`):new Error(`Workspace has multiple publishers (${d.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,g=new Map;for(let p of o)p.publisher===c&&(f.add(`${p.publisher}/${p.package_}@${p.verStr}`),g.set(`${p.package_}@${p.verStr}`,p.source));let l=new Z(A(),!0,t),a=e.repository??new te(r,l,new I(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),m=C(void 0);if(!e.repository){let p=A(),b=s=>{let h=q(p,s);return de(h)?new Set(me(h).filter(k=>k.endsWith(".kan.yml")).map(k=>k.split("@")[0])):new Set},w=(s,h)=>o.some(k=>k.publisher===s&&k.package_===h),$=new V,u=new Map;for(let s of m)if(u.has(s.publisher)||u.set(s.publisher,b(s.publisher)),!(u.get(s.publisher).has(s.package_)||w(s.publisher,s.package_)))try{let h=await $.getHighestVersion(s.publisher,s.package_);if(!h)continue;let k=await $.getPackageUrl(s.publisher,s.package_,h),_=await fetch(k);if(!_.ok)continue;let le=await _.text(),J=q(p,s.publisher);fe(J,{recursive:!0}),ge(q(J,`${s.package_}@${h}.kan.yml`),le,"utf-8")}catch{}}let y=a;if(!e.repository){let p=(await r.getAllDocumentsAsync()).filter(w=>w.metadata.namespace_?.publisher===c),b=await M(p,a);for(let w of m)b.add(H(w));y=new j(a,b)}let v=await new L(t).parseKanonaks(y),x=new E(v);return B({publisher:c,availablePublishers:d,catalog:v,lookRenderer:x,localNamespaces:f,rawByNsKey:g})}import{existsSync as he,readFileSync as ke,writeFileSync as ye,mkdirSync as ve}from"fs";import{join as ie}from"path";async function U(n,e={}){let t=new D,r=O(n),o=r.kind==="resource"?r.uri.publisher:r.publisher,i=e.cacheRoot??A(),d=(u,s,h)=>ie(i,u,`${s}@${h}.kan.yml`),c=new I({getFromCache:(u,s,h)=>{let k=d(u,s,h);return he(k)?ke(k,"utf-8"):null},onFetch:(u,s,h,k)=>{let _=ie(i,u);ve(_,{recursive:!0}),ye(d(u,s,h),k,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),f=new V(e.fetchFn?{fetchFn:e.fetchFn}:void 0),g;if(r.kind==="resource"){let u=r.uri.version;g=[u?{package_:r.uri.package_,version:`${u.major}.${u.minor}.${u.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let u=r.version;g=[u?{package_:r.package_,version:`${u.major}.${u.minor}.${u.patch}`}:{package_:r.package_}]}else g=(await f.listLatestPackages(o)).map(s=>({package_:s.packageName}));let l=async(u,s,h)=>{try{let k=h?t.buildImport(s,"=",h,u):t.buildImport(s,"*","0.0.0",u);return await c.getHighestCompatibleVersionAsync(u,k)}catch{return null}},a=[];for(let u of g){let s=await l(o,u.package_,u.version);s&&a.push(s)}if(a.length===0)throw new Error(`Could not fetch any package for address "${n}" from publisher "${o}".`);let m=await new re().getConfig(o).catch(()=>{}),y=[];for(let u of C(m)){let s=await l(u.publisher,u.package_,void 0);s&&y.push(s)}let v=await M([...a,...y],c),x=new j(c,v),p=await new L(t).parseKanonaks(x),b=new E(p),w=new Set,$=new Map;for(let u of await c.getAllDocumentsAsync()){let s=u.metadata.namespace_;if(!s||s.publisher!==o)continue;let h=`${s.version.major}.${s.version.minor}.${s.version.patch}`,k=`${s.publisher}/${s.package_}@${h}`;w.add(k);let _=await c.getDocumentContentAsync(k);_!==null&&$.set(`${s.package_}@${h}`,_)}return B({publisher:o,availablePublishers:[o],catalog:p,lookRenderer:b,localNamespaces:w,rawByNsKey:$})}import{VersionOperator as W}from"@kanonak-protocol/types/document/models/enums";var S={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},R=(n,e,t,r)=>({status:n,headers:{"Content-Type":e,...r||{}},body:t}),P=n=>R(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${n}</p>`),be=n=>({status:301,headers:{Location:n},body:""}),we=n=>({status:302,headers:{Location:n},body:""});function Se(n){switch(n.kind){case"exact":return{operator:W.Exact,version:K(n.major,n.minor,n.patch)};case"minor-pin":return{operator:W.Compatible,version:K(n.major,n.minor,0)};case"major-pin":return{operator:W.Major,version:K(n.major,0,0)};default:return{operator:W.Any,version:K(0,0,0)}}}async function Re(n,e,t,r){if(!r)return null;let o=n.producers?.find(f=>f.canProduce(n.publisher,e));if(!o)return null;let i=await o.resolveVersion(n.publisher,e,Se(t));if(!i)return null;let d=z(i);if(t.kind!=="exact")return we(`/${e}/${d}.kan.yml`);let{source:c}=await o.produce(n.publisher,e,i);return R(200,S[".kan.yml"],c)}function ce(n,e,t){let r=n.pkgVersions.get(e);if(!r||r.length===0)return null;switch(t.kind){case"any":return r[0].verStr;case"major-pin":return r.find(o=>o.version.major===t.major)?.verStr??null;case"minor-pin":return r.find(o=>o.version.major===t.major&&o.version.minor===t.minor)?.verStr??null;case"exact":return r.find(o=>o.version.major===t.major&&o.version.minor===t.minor&&o.version.patch===t.patch)?.verStr??null;default:return null}}async function G(n,e,t=""){let{lookRenderer:r,publisher:o}=n;if(e==="/.well-known/kanonak.json"){let a=ee(o);return n.producers&&n.producers.length>0&&(a.resolveByRedirect=!0),R(200,S[".json"],JSON.stringify(a,null,2))}if(e==="/index.txt"){let a=[...n.localNamespaces].map(m=>m.split("/")[1].replace("@","/")).sort();return R(200,S[".txt"],a.join(`
2
2
  `)+`
3
3
  `)}if(e==="/"||e==="/index.html"||e==="/index.css"){let a=r.publisherSubject(o);return e==="/index.css"?R(200,S[".css"],r.renderStylesheet(a)):R(200,S[".html"],await r.renderDocument(a,{rootIndex:!0}))}let i=".html",d=!1,c=e;for(let a of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(a)){i=a,d=!0,c=e.slice(0,-a.length);break}let f=!d&&/application\/yaml|text\/yaml/i.test(t),g=c.endsWith("/");g&&c!=="/"&&(c=c.slice(0,-1));let l=oe.parse(c,o);if(!l)return P(e);if(l.kind==="package"){let a=ce(n,l.package_,l.versionSpec);if(!a)return await Re(n,l.package_,l.versionSpec,i===".kan.yml"||f)??P(e);if(i===".kan.yml"||f){let v=n.rawByNsKey.get(`${l.package_}@${a}`);return v!==void 0?R(200,S[".kan.yml"],v):P(e)}let m=n.pkgSelfByVer.get(`${l.package_}@${a}`);if(!m)return P(e);if(i===".css")return R(200,S[".css"],r.renderStylesheet(m));if(!g)return be(c+"/");let y=l.versionSpec.kind==="any";if(y&&!r.hasDeclaredView(m)){let v=(n.pkgVersions.get(l.package_)||[]).map(x=>x.verStr);return R(200,S[".html"],r.renderPackageVersionList(l.package_,v,m))}return R(200,S[".html"],await r.renderDocument(m,y?{bareOverview:!0}:void 0))}if(l.kind==="resource"){let a=ce(n,l.package_,l.versionSpec);if(!a)return P(e);let m=n.bySubject.get(`${o}/${l.package_}@${a}/${l.name}`);if(!m)return P(e);switch(i){case".css":return R(200,S[".css"],r.renderStylesheet(m));case".svg":return R(200,S[".svg"],await r.renderSvg(m));case".md":{let y=r.renderRawMarkdown(m);return y===void 0?P(e):R(200,S[".md"],y)}default:return R(200,S[".html"],await r.renderDocument(m))}}return P(e)}import{readFileSync as xe}from"fs";var Y=class{constructor(e={}){this.options=e}options;models=new Map;workspaceIndex;clearCache(){this.models.clear(),this.workspaceIndex=void 0}getWorkspaceIndex(){if(this.workspaceIndex)return this.workspaceIndex;let e=new Set,t=new Set;if(this.options.root!==void 0){let r=new D;for(let o of N(this.options.root))try{let i=r.parse(xe(o,"utf-8")).metadata?.namespace_;if(!i?.version)continue;let d=i.version;e.add(`${i.publisher}/${i.package_}@${d.major}.${d.minor}.${d.patch}`),t.add(`${i.publisher}/${i.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:t},this.workspaceIndex}async modelFor(e,t,r){let o=this.getWorkspaceIndex(),i=this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},d=t?r?o.exact.has(`${e}/${t}@${r}`):o.pkgs.has(`${e}/${t}`):[...o.pkgs].some(a=>a.startsWith(`${e}/`)),c,f;if(d&&this.options.root!==void 0){let a=this.options.root;c=`ws:${e}`,f=()=>T(a,{publisher:e})}else{let a=t?r?`${e}/${t}@${r}`:`${e}/${t}`:e;c=`rm:${a}`,f=()=>U(a,i)}let g=this.models.get(c);if(g)return g;let l=await f();return l.lookRenderer.setLinkMode("open-world"),this.models.set(c,l),l}async handle(e,t=""){let r=e.split("/").filter(Boolean);if(r.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:pe()};let o=r[0];if(!o.includes("."))return{status:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:"<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Expected a publisher domain as the first path segment: <code>/{publisher}/{package}/{version}/{resource}</code></p>"};let i=r.length>=2&&(r[1]==="index.html"||r[1]==="index.css"||r[1]==="index.txt"||r[1]===".well-known"),d=!i&&r.length>=2?r[1]:void 0,c=!i&&r.length>=3&&/^\d+\.\d+\.\d+$/.test(r[2])?r[2]:void 0,f=await this.modelFor(o,d,c),g=e.endsWith("/")&&r.length>1?"/":"",l="/"+r.slice(1).join("/")+g,a=await G(f,l,t);return a.headers.Location?{...a,headers:{...a.headers,Location:`/${o}${a.headers.Location}`}}:a}};function pe(){return'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Kanonak origin</title></head><body style="font-family:system-ui;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>Kanonak request-driven origin</h1><p>Open a resource by its address:</p><p><code>/{publisher}/{package}/{version}/{resource}</code></p><p>e.g. <code>/kanonak.org/capabilities/2.0.0/Capability</code></p></body></html>'}export{j as ClosureScopedRepository,Y as RequestRouter,ae as UNIVERSAL_RENDER_BASE,M as deriveImportClosure,pe as landingPage,U as loadResourceModel,T as loadServerModel,H as renderRefKey,C as resolveRenderContract,G as route};
@@ -1,3 +1,17 @@
1
1
  import { Statement } from './Statement.js';
2
2
  export declare abstract class ScalarStatement<TScalar> extends Statement<TScalar> {
3
+ /**
4
+ * Canonical-form datatype carrier (a `Carrier` value, held as its string)
5
+ * when the value was typed by its property's resolved range. Drives
6
+ * datatype-precise canonicalization; absent for untyped/open-world values,
7
+ * which canonicalize as their raw lexical token. Stored as a plain string to
8
+ * avoid a statements→canonical import cycle.
9
+ */
10
+ carrier?: string;
11
+ /**
12
+ * The raw lexical token as authored — the precise, lossless input to
13
+ * canonicalization (e.g. `1.10`, a full-precision epoch-nanosecond integer).
14
+ * `object` may be a lossy native projection of this; `lexical` is exact.
15
+ */
16
+ lexical?: string;
3
17
  }
@@ -1,4 +1,4 @@
1
- import{b as Y,c as An,d as Sn,e as ce,f as Te,g as O,h as wn,i as X,j as q}from"../chunk-XWRVENU6.js";import{a as se}from"../chunk-RVOMWGIN.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-PJMOM5H7.js";import"../chunk-PEJALHXK.js";import{a as kn,b as bn,c as hn,d as Dn}from"../chunk-SHDHMKMJ.js";import{f as ie}from"../chunk-IUZZDC2U.js";import{a as ae}from"../chunk-TJPQETHV.js";import{b as L,c as A,f as S}from"../chunk-XQS5LDSO.js";import"../chunk-IOMNZBK4.js";import{b as N,c as D,d as K,g as M,h as P,i as F,j as W,l as H}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{g as oe}from"../chunk-2ACBWC7K.js";var $e="kanonak.org",Ue="document-ast",i=e=>({publisher:$e,package_:Ue,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ue(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var j=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=xe(n.metadata,t),o=Le(n.children),s=["---",...r,"---","",o].join(`
1
+ import{b as Y,c as An,d as Sn,e as ce,f as Te,g as O,h as wn,i as X,j as q}from"../chunk-ZRMF5QLN.js";import{a as se}from"../chunk-4OSNT57C.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-YI5GLYMB.js";import"../chunk-PEJALHXK.js";import{a as kn,b as bn,c as hn,d as Dn}from"../chunk-SHDHMKMJ.js";import{w as ie}from"../chunk-WUAKDYY6.js";import{a as ae}from"../chunk-ZYAABYDS.js";import{b as L,c as A,f as S}from"../chunk-PBNVHBS3.js";import"../chunk-XYEY6HUC.js";import{b as N,c as D,d as K,g as M,h as P,i as F,j as W,l as H}from"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import{g as oe}from"../chunk-2ACBWC7K.js";var $e="kanonak.org",Ue="document-ast",i=e=>({publisher:$e,package_:Ue,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ue(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var j=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=xe(n.metadata,t),o=Le(n.children),s=["---",...r,"---","",o].join(`
2
2
  `);return t?.trailingNewline&&(s.endsWith(`
3
3
  `)||(s+=`
4
4
  `)),s}};function xe(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(I(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(I(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(I),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=I(f??c),d=me(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function I(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function me(e,n){switch(e.kind){case"StringScalar":return Ve(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=me(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function Ve(e,n){return!n||ue(n,m.ESC_RAW)?e:ue(n,m.ESC_YAML_SAFE)?ve(e):e}function ve(e){return e.includes(`
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"../chunk-XQS5LDSO.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{n as SingleDocumentRepository,g as findAllResourcesByCanonicalUri,f as findSubjectByUri,e as findSubjectsByType,i as getDatatypeValue,l as getEmbeddedValue,m as getListValues,k as getReferenceUri,j as getStringValue,h as hasProperty,d as hasType,c as toCanonicalUrl,a as uriKey,b as uriMatches};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"../chunk-PBNVHBS3.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{n as SingleDocumentRepository,g as findAllResourcesByCanonicalUri,f as findSubjectByUri,e as findSubjectsByType,i as getDatatypeValue,l as getEmbeddedValue,m as getListValues,k as getReferenceUri,j as getStringValue,h as hasProperty,d as hasType,c as toCanonicalUrl,a as uriKey,b as uriMatches};
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,K as I,L as J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-QXFO6X6V.js";import"../chunk-SHDHMKMJ.js";import"../chunk-IUZZDC2U.js";import"../chunk-TJPQETHV.js";import"../chunk-Z5ELOT2C.js";import"../chunk-XQS5LDSO.js";import"../chunk-IOMNZBK4.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,I as DiamondNameClashRule,D as DisplayLensScopeRule,j as EmbeddedKanonakTypeRule,k as ImportExistenceRule,s as InstancePropertyReferenceRule,J as KanonakObjectValidator,E as LookSemanticSvgPathRule,C as MarkdownLinkRule,r as NamespaceImportCycleRule,f as NamespacePrefixRule,x as ObjectPropertyImportRule,y as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,H as OwlOneOfRule,z as PropertyDomainRule,n as PropertyHierarchyCycleRule,w as PropertyRangeReferenceRule,o as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,g as ResourceNamingRule,G as ShaclShapeRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,F as TxExpressionPathRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
1
+ import{A,B,C,D,E,F,G,H,K as I,L as J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-V3YPCUA6.js";import"../chunk-SHDHMKMJ.js";import"../chunk-WUAKDYY6.js";import"../chunk-ZYAABYDS.js";import"../chunk-NC3FSY3R.js";import"../chunk-PBNVHBS3.js";import"../chunk-XYEY6HUC.js";import"../chunk-T3JR2SV6.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,I as DiamondNameClashRule,D as DisplayLensScopeRule,j as EmbeddedKanonakTypeRule,k as ImportExistenceRule,s as InstancePropertyReferenceRule,J as KanonakObjectValidator,E as LookSemanticSvgPathRule,C as MarkdownLinkRule,r as NamespaceImportCycleRule,f as NamespacePrefixRule,x as ObjectPropertyImportRule,y as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,H as OwlOneOfRule,z as PropertyDomainRule,n as PropertyHierarchyCycleRule,w as PropertyRangeReferenceRule,o as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,g as ResourceNamingRule,G as ShaclShapeRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,F as TxExpressionPathRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.78.0",
3
+ "version": "4.0.0",
4
4
  "description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -122,7 +122,7 @@
122
122
  "yaml-parser"
123
123
  ],
124
124
  "dependencies": {
125
- "@kanonak-protocol/types": "^3.78.0",
125
+ "@kanonak-protocol/types": "^4.0.0",
126
126
  "ignore": "^7.0.5",
127
127
  "js-yaml": "^4.1.0",
128
128
  "yaml": "^2.7.0"