@kanonak-protocol/sdk 5.36.0 → 5.38.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 (64) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/chunk-22DSABP6.js +1 -0
  3. package/dist/chunk-7JBKOJB4.js +1 -0
  4. package/dist/{chunk-4QXD6HKI.js → chunk-A3HRXFVX.js} +1 -1
  5. package/dist/{chunk-VENZTHCC.js → chunk-ADSDFJUO.js} +1 -1
  6. package/dist/chunk-D2X6J77P.js +1 -0
  7. package/dist/chunk-D4QGPMRW.js +1 -0
  8. package/dist/chunk-DONOB6RA.js +1 -0
  9. package/dist/{chunk-IN5VVPYH.js → chunk-ED35OFGD.js} +1 -1
  10. package/dist/chunk-GKIX3OD6.js +3 -0
  11. package/dist/chunk-HKX27KBZ.js +1 -0
  12. package/dist/{chunk-H7SX57L7.js → chunk-LBVHWFFL.js} +1 -1
  13. package/dist/chunk-NUTHBBDZ.js +1 -0
  14. package/dist/{chunk-6TEJENCD.js → chunk-O6SOU5Y2.js} +10 -10
  15. package/dist/{chunk-BZ3YTI3C.js → chunk-OOYGILH4.js} +2 -2
  16. package/dist/chunk-TYVZXABI.js +155 -0
  17. package/dist/chunk-VORVR5BZ.js +1 -0
  18. package/dist/index.d.ts +7 -7
  19. package/dist/index.js +1 -1
  20. package/dist/kanonaks/DefinedKanonak.d.ts +11 -0
  21. package/dist/kanonaks/LiteralKanonak.d.ts +2 -0
  22. package/dist/kanonaks/ReferenceKanonak.d.ts +2 -0
  23. package/dist/lock/LockFile.d.ts +6 -0
  24. package/dist/lock/index.d.ts +1 -1
  25. package/dist/look/displayValue.d.ts +3 -0
  26. package/dist/look/index.d.ts +1 -1
  27. package/dist/parsing/findMarkdownLinkAt.d.ts +8 -0
  28. package/dist/parsing/index.d.ts +2 -0
  29. package/dist/parsing/index.js +1 -1
  30. package/dist/parsing/sourceSymbols.d.ts +54 -0
  31. package/dist/producer/index.js +1 -1
  32. package/dist/reasoning/KanonakVocabulary.d.ts +21 -0
  33. package/dist/reasoning/index.d.ts +1 -1
  34. package/dist/reasoning/index.js +1 -1
  35. package/dist/repositories/LockAwareRepository.d.ts +1 -1
  36. package/dist/repositories/browser.js +1 -1
  37. package/dist/repositories/index.js +1 -1
  38. package/dist/resolution/ResourceTypeClassifier.d.ts +8 -1
  39. package/dist/resolution/index.d.ts +1 -0
  40. package/dist/resolution/index.js +1 -1
  41. package/dist/resolution/referenceSpelling.d.ts +14 -0
  42. package/dist/search/index.js +1 -1
  43. package/dist/server/closure.d.ts +8 -0
  44. package/dist/server/index.d.ts +1 -1
  45. package/dist/server/index.js +16 -16
  46. package/dist/server/requestRouter.d.ts +16 -0
  47. package/dist/statements/Statement.d.ts +9 -0
  48. package/dist/transformations/index.js +2 -2
  49. package/dist/transformations/v3/CompiledTransformationV3.d.ts +28 -27
  50. package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +27 -0
  51. package/dist/uri-helpers/index.js +1 -1
  52. package/dist/validation/KanonakObjectValidator.d.ts +7 -1
  53. package/dist/validation/index.js +1 -1
  54. package/package.json +3 -3
  55. package/dist/chunk-7TU55KLO.js +0 -1
  56. package/dist/chunk-HF5FJBS2.js +0 -1
  57. package/dist/chunk-IS3AQKB4.js +0 -1
  58. package/dist/chunk-KIBR3HAT.js +0 -1
  59. package/dist/chunk-Q2FG7DME.js +0 -1
  60. package/dist/chunk-ROKDCCJN.js +0 -155
  61. package/dist/chunk-V3DH67P3.js +0 -1
  62. package/dist/chunk-XK24CN3C.js +0 -1
  63. package/dist/chunk-XNEWQEB6.js +0 -1
  64. package/dist/chunk-YBHIELES.js +0 -2
@@ -1 +0,0 @@
1
- import{n as A}from"./chunk-BZ3YTI3C.js";import{a as P}from"./chunk-6VIUXP4N.js";import{a as f}from"./chunk-HF5FJBS2.js";import{c as K,g as I,j as R}from"./chunk-QILEJIFU.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";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;return R(r,t)});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,p=r.metadata.namespace_.version;return K(p,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),p=m[0],h=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,p,h)}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,p]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&p.metadata.namespace_){s=p.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 g from"fs";var F=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(F||{}),D=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.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 x}from"os";import{join as _}from"path";function d(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||_(x(),".kanonak","packages")}var w=class u{static createComposite(e,t,n){let o=e??d(),s=t??".";return new D(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var k=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{VersionOperator as H}from"@kanonak-protocol/types/document/models/enums";var v=class{constructor(e,t){this.base=e;this.lock=t}base;lock;pinnedVersion(e,t){return this.lock.packages[`${e}/${t}`]?.version}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=I(n);if(o){let s={...t,versionOperator:H.Exact,version:o};return this.base.getHighestCompatibleVersionAsync(e,s)}}return this.base.getHighestCompatibleVersionAsync(e,t)}async getDocumentsByNamespaceAsync(e,t){let n=await this.base.getDocumentsByNamespaceAsync(e,t),o=this.pinnedVersion(e,t);return o?n.filter(s=>{let a=s.metadata.namespace_?.version;return a?`${a.major}.${a.minor}.${a.patch}`===o:!1}):n}getAllDocumentsAsync(){return this.base.getAllDocumentsAsync()}getDocumentAsync(e){return this.base.getDocumentAsync(e)}saveDocumentAsync(e,t){return this.base.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.base.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.base.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.base.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.base.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.base.getDocumentUriAsync(e)}};import{readFileSync as N,readdirSync as $}from"fs";import{join as S}from"path";var B=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(u,e=[]){for(let t of $(u,{withFileTypes:!0}))t.isDirectory()?B.has(t.name)||C(S(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(S(u,t.name));return e}async function V(u,e=new f,t={}){let n=new P(e);for(let m of C(u))try{let p=e.parse(N(m,"utf-8")),l=p.metadata?.namespace_,h=l?.version;l&&h&&await n.saveDocumentAsync(p,`${l.publisher}/${l.package_}@${h.major}.${h.minor}.${h.patch}`)}catch{}let o=new y(d(),!0,e);if(t.offline)return new k(n,o);let s=new Map,a=t.httpCache??{getFromCache:(m,p,l)=>s.get(`${m}|${p}|${l}`)??null,onFetch:(m,p,l,h)=>{s.set(`${m}|${p}|${l}`,h)}},r=new A({getFromCache:a.getFromCache,onFetch:a.onFetch});return new k(n,o,r)}export{y as a,F as b,D as c,d,w as e,k as f,v as g,C as h,V as i};
@@ -1 +0,0 @@
1
- import{b as D}from"./chunk-F67UH4FD.js";import{b as y,e as m}from"./chunk-QILEJIFU.js";function h(t){let e=t.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}function v(t){let e=t.metadata?.namespace_;if(e)return e.version?`${e.publisher}/${e.package_}@${m(e.version)}`:`${e.publisher}/${e.package_}`}async function I(t,e,n={}){let o=new Set,u=new Set,i=[...t];for(;i.length>0;){let a=i.shift(),l=h(a),s=v(a);if(!l||!s||u.has(s))continue;u.add(s),o.add(l);let p=a.metadata?.imports;if(p)for(let[g,k]of Object.entries(p))for(let r of k){if(D(r))continue;let c=null,d="no-compatible-version";try{c=await e.getHighestCompatibleVersionAsync(g,r)}catch{d="resolution-error"}c?i.push(c):n.onUnresolvedEdge?.({fromNamespace:s,publisher:g,packageName:r.packageName,constraint:`${y(r.versionOperator)}${m(r.version)}`,reason:d})}}return o}var f=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let o=h(n);return o!==void 0&&this.scope.has(o)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};export{I as a,f as b};
@@ -1 +0,0 @@
1
- import{a as G}from"./chunk-HF5FJBS2.js";import{a as X,b as q,fa as J,ga as U,ha as M,na as Z}from"./chunk-7TU55KLO.js";import{J as Y,K as Q,c as w,d as h,e as g,f as D,i as I,j as L,k as T,l as j,m as K,n as P,o as E,r as N,s as x,z as H}from"./chunk-XNEWQEB6.js";import{a as O}from"./chunk-FUUTGGJS.js";import{b as W}from"./chunk-F67UH4FD.js";import{k as z}from"./chunk-QILEJIFU.js";function ee(f,t){for(let n of f)n instanceof w&&te(n,Y(n),n.name,t)}function te(f,t,n,r){let a=t.indexOf("#");r({kanonak:f,address:t,path:a<0?n:`${n}.${t.slice(a+1)}`});for(let s of ae(f))for(let{value:o,address:c}of Q(f,s,t))o.item instanceof h&&te(o.item,c,n,r)}function ae(f){let t=new Map;for(let n of f.statement){let r=n.predicate?.subject;if(!r)continue;let a=`${r.publisher}/${r.package_}/${r.name}`;t.has(a)||t.set(a,r)}return[...t.values()]}var oe="kanonak.org",se="transformations",Ke=3,e=f=>({publisher:oe,package_:se,name:f}),A={Transformation:e("Transformation"),InstanceTransformation:e("InstanceTransformation"),SetTransformation:e("SetTransformation"),inputPattern:e("inputPattern"),rule:e("rule"),artifactName:e("artifactName"),outputs:e("outputs"),formatOverrides:e("formatOverrides"),partitionBy:e("partitionBy"),InputPattern:e("InputPattern"),matchesClass:e("matchesClass"),requires:e("requires"),sortBy:e("sortBy"),SortKey:e("SortKey"),byProperty:e("byProperty"),order:e("order"),SortOrder:e("SortOrder"),ascending:e("ascending"),descending:e("descending"),OutputFormat:e("OutputFormat"),backendUri:e("backendUri"),FormatOverride:e("FormatOverride"),formatTarget:e("formatTarget"),metadataKeys:e("metadataKeys"),metadataRenames:e("metadataRenames"),trailingNewline:e("trailingNewline"),omitWrapper:e("omitWrapper"),RenameEntry:e("RenameEntry"),fromKey:e("fromKey"),toKey:e("toKey"),FMT_MARKDOWN_FRONTMATTER:e("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:e("plain-markdown"),FMT_TOML:e("toml"),FMT_JSON:e("json"),FMT_HTML:e("html"),FMT_SVG:e("svg"),Expression:e("Expression"),ListSourcedExpression:e("ListSourcedExpression"),ListAggregate:e("ListAggregate"),IteratingExpression:e("IteratingExpression"),BuildAstNode:e("BuildAstNode"),astClass:e("astClass"),set:e("set"),AstFieldBinding:e("AstFieldBinding"),field:e("field"),bindValue:e("bindValue"),When:e("When"),condition:e("condition"),thenBuild:e("thenBuild"),elseBuild:e("elseBuild"),Concat:e("Concat"),parts:e("parts"),Fallback:e("Fallback"),primary:e("primary"),alternate:e("alternate"),StringLiteral:e("StringLiteral"),stringLiteral:e("stringLiteral"),IntegerLiteral:e("IntegerLiteral"),integerLiteral:e("integerLiteral"),DecimalLiteral:e("DecimalLiteral"),decimalLiteral:e("decimalLiteral"),BooleanLiteral:e("BooleanLiteral"),booleanLiteral:e("booleanLiteral"),VarRef:e("VarRef"),varName:e("varName"),PropertyRead:e("PropertyRead"),readSource:e("readSource"),readProp:e("readProp"),Traverse:e("Traverse"),traverseSource:e("traverseSource"),through:e("through"),step:e("step"),UriName:e("UriName"),uriNameOf:e("uriNameOf"),UriPublisher:e("UriPublisher"),uriPublisherOf:e("uriPublisherOf"),UriPackage:e("UriPackage"),uriPackageOf:e("uriPackageOf"),UriVersion:e("UriVersion"),uriVersionOf:e("uriVersionOf"),SubjectUri:e("SubjectUri"),subjectOf:e("subjectOf"),UriLiteral:e("UriLiteral"),refTo:e("refTo"),DisplayLabel:e("DisplayLabel"),labelTarget:e("labelTarget"),labelSource:e("labelSource"),ResolveRef:e("ResolveRef"),resolveSource:e("resolveSource"),Normalize:e("Normalize"),normSource:e("normSource"),normKind:e("normKind"),NormalizeKind:e("NormalizeKind"),NORM_TRIM_END:e("trim-end"),NORM_TO_UPPER:e("to-upper"),NORM_TO_LOWER:e("to-lower"),NORM_FIRST_CHAR:e("first-char"),UnescapedString:e("UnescapedString"),unescapedSource:e("unescapedSource"),IsSet:e("IsSet"),checkExpr:e("checkExpr"),ExpressionFragment:e("ExpressionFragment"),body:e("body"),CallFragment:e("CallFragment"),fragmentRef:e("fragmentRef"),source:e("source"),Join:e("Join"),separator:e("separator"),Count:e("Count"),Sum:e("Sum"),Min:e("Min"),Max:e("Max"),Average:e("Average"),loopVar:e("loopVar"),ForEach:e("ForEach"),emit:e("emit"),ListMap:e("ListMap"),mapBody:e("mapBody"),Filter:e("Filter"),predicate:e("predicate"),PartitionBy:e("PartitionBy"),partitionKey:e("partitionKey"),DistinctBy:e("DistinctBy"),distinctKey:e("distinctKey"),Partition:e("Partition"),key:e("key"),members:e("members"),AllStatements:e("AllStatements"),statementsOf:e("statementsOf"),StatementPredicate:e("StatementPredicate"),predicateOf:e("predicateOf"),StatementValue:e("StatementValue"),valueOf:e("valueOf"),DateFormat:e("DateFormat"),dateSource:e("dateSource"),dateFormat:e("dateFormat"),NumberFormat:e("NumberFormat"),numberSource:e("numberSource"),numberStyle:e("numberStyle"),fractionDigits:e("fractionDigits"),currencyCode:e("currencyCode"),BinaryArithmetic:e("BinaryArithmetic"),arithLeft:e("arithLeft"),arithRight:e("arithRight"),Add:e("Add"),Subtract:e("Subtract"),Multiply:e("Multiply"),Divide:e("Divide"),Reverse:e("Reverse"),WindowedMap:e("WindowedMap"),windowSize:e("windowSize"),windowVar:e("windowVar"),windowBody:e("windowBody"),PairwiseMap:e("PairwiseMap"),firstVar:e("firstVar"),secondVar:e("secondVar"),pairBody:e("pairBody"),Scan:e("Scan"),initialState:e("initialState"),stateVar:e("stateVar"),elementVar:e("elementVar"),accumulate:e("accumulate"),ListItemAt:e("ListItemAt"),itemIndex:e("itemIndex"),BinaryComparison:e("BinaryComparison"),compareLeft:e("compareLeft"),compareRight:e("compareRight"),Equals:e("Equals"),GreaterThan:e("GreaterThan"),LessThan:e("LessThan"),GreaterThanOrEqual:e("GreaterThanOrEqual"),LessThanOrEqual:e("LessThanOrEqual"),Not:e("Not"),operand:e("operand"),BooleanLogic:e("BooleanLogic"),operands:e("operands"),And:e("And"),Or:e("Or"),Contains:e("Contains"),haystack:e("haystack"),needle:e("needle"),UnaryNumericOp:e("UnaryNumericOp"),value:e("value"),Abs:e("Abs"),Negate:e("Negate"),KindPredicate:e("KindPredicate"),IsReference:e("IsReference"),IsEmbedded:e("IsEmbedded"),IsList:e("IsList"),kindCheck:e("kindCheck"),IsString:e("IsString"),IsNumber:e("IsNumber"),IsBoolean:e("IsBoolean"),StatementObject:e("StatementObject"),statementSource:e("statementSource"),Let:e("Let"),letName:e("letName"),letValue:e("letValue"),letBody:e("letBody"),GetStatementByName:e("GetStatementByName"),inSubject:e("inSubject"),byName:e("byName"),RenderMarkdown:e("RenderMarkdown"),renderSource:e("renderSource"),renderProp:e("renderProp"),renderFormat:e("renderFormat"),RenderFormat:e("RenderFormat"),RENDER_HTML:e("render-html"),RENDER_MARKDOWN:e("render-markdown")};import{Carrier as S,carrierOf as ie}from"@kanonak-protocol/canonical";function _(f){return ie(`${f.publisher}/${f.package_}/${f.name}`)}var ce=/\[\[([^\[\]\n]+)\]\]/g,pe=/\[\[/g,ne=/```[\s\S]*?```|`[^`\n]*`/g;function fe(f){let t=[];for(let n of f.matchAll(ne))t.push([n.index,n.index+n[0].length]);return t}function ve(f){if(!f||!f.includes("[["))return[];let t=fe(f),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(V(f).map(s=>s.startOffset)),a=[];for(let s of f.matchAll(pe)){let o=s.index;if(n(o)||r.has(o))continue;let c=f.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function V(f){if(!f||!f.includes("[["))return[];let t=[];for(let a of f.matchAll(ne))t.push([a.index,a.index+a[0].length]);let n=a=>t.some(([s,o])=>a>=s&&a<o),r=[];for(let a of f.matchAll(ce)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),p=(c===-1?o:o.slice(0,c)).trim();if(p.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),m={reference:p,startOffset:s,endOffset:s+a[0].length};i.length>0&&(m.displayText=i),r.push(m)}return r}import{VersionOperator as me}from"@kanonak-protocol/types/document/models/enums";var ue={...U("range"),name:"range"};function le(f){let t=f.lastIndexOf(".");return t===-1?f:f.slice(t+1)}var re=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new X(t),s=new q(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let p of n){let i=p.metadata.namespace_?.toString();i&&a.set(i,p)}let s=[],o=new Set;ee(t,({kanonak:p})=>{for(let i of p.unresolvedPredicates){let m=`${i.sourceDoc}::${i.key}`;o.has(m)||(o.add(m),s.push(i))}});let c=!1;for(let p of s){let i=a.get(p.sourceDoc);if(!i)continue;let m=await r.resolveEntityAsync(p.key,i);if(!m)continue;let l=N(m.uri);if(this.knownPropertyClasses.has(l))continue;let u=H(t,m.uri);if(!u)continue;let y=Z(t,u);y&&(this.knownPropertyClasses.set(l,y),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[p,i]of Object.entries(o.body)){let m=new w,l=this.resolveCanonicalEntity(p,o,c);m.namespace=l.namespace,m.name=l.name,m.statement=[];let u=await this.parseStatements(i,o,n,r,a);m.statement.push(...u.statements),m.unresolvedPredicates=u.unresolved,C(m,c),s.push(m)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof w){let m=`${i.namespace}/${i.name}`,l=r.get(m);if(l){let u=a.get(m);for(let y of i.statement){let d=F(y);u.has(d)||(u.add(d),l.statement.push(y))}for(let y of i.unresolvedPredicates)l.unresolvedPredicates.some(d=>d.key===y.key&&d.sourceDoc===y.sourceDoc)||l.unresolvedPredicates.push(y)}else{let u=new w;u.namespace=i.namespace,u.name=i.name,u.sourceDoc=i.sourceDoc;let y=new Set;for(let d of i.statement){let k=F(d);y.has(k)||(y.add(k),u.statement.push(d))}u.unresolvedPredicates=[...i.unresolvedPredicates],a.set(m,y),r.set(m,u),s.push(u)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof w){let m=i.namespace||"",l=m.indexOf("/"),u=l>=0?m.slice(0,l):"",y=l>=0?m.slice(l+1):"",d=y.indexOf("@"),k=d>=0?y.slice(0,d):y;o.add(`${u}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),p=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let m=await n.getDocumentsByNamespaceAsync("kanonak.org",i);p.set(i,z(m).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,p);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(M(s,n,r),a instanceof j)a.object instanceof g&&M(a.object.subject,n,r);else if(a instanceof K)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof P)for(let o of a.object??[])o instanceof g?M(o.subject,n,r):o instanceof h&&this.canonicalizeStatementBuiltins(o.statement,n,r)}}resolveCanonicalEntity(t,n,r){if(!t.includes(".")||!n.metadata?.imports)return{namespace:r,name:t};let a=t.indexOf("."),s=t.substring(0,a),o=t.substring(a+1);for(let[c,p]of Object.entries(n.metadata.imports))for(let i of p)if((i.alias??i.packageName)===s){let l=i.version;return{namespace:`${c}/${i.packageName}@${l.major}.${l.minor}.${l.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let p=n.metadata.namespace_?.toString()??"";for(let[i,m]of Object.entries(t))try{let l=await this.getPropertyMetadata(i,n,r,s,a);if(!l){let y=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;J(y)||c.push({key:i,sourceDoc:p});continue}let u=await this.parsePropertyValue(i,m,l,n,r,a,s);u&&o.push(u)}catch(l){throw new Error(`Failed to parse property '${i}': ${l.message}`,{cause:l})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,p=c.type?.toString()??"",i=p.includes(".")?p.substring(p.lastIndexOf(".")+1):p,m=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),l=this.knownPropertyClasses.get(N(o.uri));if(!m.has(i)&&!l)return;let u=l??s.getPropertyTypeClassification(p),y,d=async()=>{if(y)return y;if(!(o.isImported&&o.definedInNamespace))return y=n,n;if(typeof a.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${t}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let R=await a.getDocumentAsync(o.definedInNamespace);if(!R)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);return y=R,R},k=await this.readDefinitionSlot(c,ue,d,r),b=k==null?void 0:String(k),v;if(u==="ObjectProperty")v="ObjectProperty";else if(u==="DatatypeProperty")v="DatatypeProperty";else{let R=b&&b.includes(".")?b.substring(b.lastIndexOf(".")+1):b??"";(b?s.isKnownXsdDatatypeName(b):!1)||R==="Literal"?v="DatatypeProperty":v="ObjectProperty"}let $;return b&&($=(await r.resolveEntityAsync(b,await d()))?.uri),{propertyUri:o.uri.toString(),propertyType:v,range:b,rangeUri:$,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>le(i)===n.name);if(s.length===0)return;let o=await r(),c=U(n.name),p=c!==void 0&&c.publisher===n.publisher&&c.package_===n.package_;for(let i of s){let m=await a.resolveEntityAsync(i,o);if(m){if(x(m.uri,n))return t[i];continue}if(!i.includes(".")&&p)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let p=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(p,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(p,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(p,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?_(r.rangeUri):void 0;if(s===S.Boolean){let c=new T;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===S.Integer||s===S.Decimal||s===S.Double||s===S.Float){let c=new L;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=I.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new D,a=n.rangeUri?_(n.rangeUri):void 0;return a===S.Boolean?r.value=t==="true"||t==="1":a===S.Integer||a===S.Decimal||a===S.Double||a===S.Float?r.value=Number(t):r.value=t,a&&(r.carrier=a,r.lexical=t),r}async parseSubstitutableValue(t,n,r,a){let s=new E;return s.predicate=g.parse(t),s.object=n,s.links=await this.resolveMarkdownLinks(n,r,a),s}async resolveMarkdownLinks(t,n,r){let a=[];for(let s of V(t)){let o=this.linkReference(s.reference,n);if(!o){let p=await r.resolveEntityAsync(s.reference,n);p&&(o=new g,o.subject=p.uri)}let c={reference:s.reference,startOffset:s.startOffset,endOffset:s.endOffset};s.displayText!==void 0&&(c.displayText=s.displayText),o!==void 0&&(c.target=o),a.push(c)}return a}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&x(r.rangeUri,A.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let p=await this.resolveReference(n,a,s);if(!p)return;let i=new j;return i.predicate=g.parse(t),i.object=p,i}if(typeof n=="object"&&!Array.isArray(n)){let p=await this.parseStatements(n,a,s,o,c);if(p.statements.length>0){let l=new h;l.statement=p.statements,l.unresolvedPredicates=p.unresolved,r.rangeUri&&(l.rangeType=r.rangeUri);let u=new K;return u.predicate=g.parse(t),u.object=l,u}let i=[];for(let[l,u]of Object.entries(n))if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let y=new h;y.name=l,r.rangeUri&&(y.rangeType=r.rangeUri);let d=await this.parseStatements(u,a,s,o,c);y.statement=d.statements,y.unresolvedPredicates=d.unresolved,i.push(y)}else if(typeof u=="string"){let y=await this.resolveReference(u,a,s);y&&i.push(y)}if(i.length>0){let l=new P;return l.predicate=g.parse(t),l.object=i,l}let m=new K;return m.predicate=g.parse(t),m.object=new h,r.rangeUri&&(m.object.rangeType=r.rangeUri),m}}coerceExpressionLiteral(t,n,r){let a=new h,s=new j,o=new g;o.subject=new O("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new O(r.publisher,r.package_,A.StringLiteral.name,r.version),s.object=c;let p=new I,i=new g;i.subject=new O(r.publisher,r.package_,A.stringLiteral.name,r.version),p.predicate=i,p.object=n,a.statement=[s,p];let m=new K;return m.predicate=g.parse(t),m.object=a,m}async parseListValue(t,n,r,a,s,o,c){let p=[],i=r.propertyType==="DatatypeProperty",m=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let u of n){let y=typeof u=="string"||typeof u=="number"||typeof u=="boolean";if(i&&y){let d=typeof u=="string"?u:String(u),k=this.typedListLiteral(d,r);o.isSubstitutableDatatype(r.rangeUri)&&(k.links=await this.resolveMarkdownLinks(d,a,s)),p.push(k);continue}if(m&&y){if(typeof u=="string"){let d=await s.resolveEntityAsync(u,a);if(d){let k=new g;k.subject=d.uri,p.push(k)}else{let k=new D;k.value=u,p.push(k)}}else{let d=new D;d.value=u,p.push(d)}continue}if(typeof u=="string"){let d=await this.resolveReference(u,a,s);d&&p.push(d)}else if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let d=new h;r.rangeUri&&(d.rangeType=r.rangeUri);let k=await this.parseStatements(u,a,s,o,c);d.statement=k.statements,d.unresolvedPredicates=k.unresolved,p.push(d)}}let l=new P;return l.predicate=g.parse(t),l.object=p,l}linkReference(t,n){let r=t.indexOf(".");if(r<=0||!n.metadata?.imports)return;let a=t.substring(0,r),s=t.substring(r+1);for(let[o,c]of Object.entries(n.metadata.imports))for(let p of c){if(!W(p)||(p.alias??p.packageName)!==a)continue;let i=new g,m=p.versionOperator===me.Exact?p.version:void 0;return i.subject=new O(o,p.packageName,s,m),i}}async resolveReference(t,n,r){let a=this.linkReference(t,n);if(a)return a;let s=await r.resolveEntityAsync(t,n);if(s){let c=new g;return c.subject=s.uri,c}let o=n.metadata?.namespace_;if(o){let{KanonakUri:c}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let i=t.indexOf("."),m=t.substring(0,i),l=t.substring(i+1);if(n.metadata?.imports){for(let[u,y]of Object.entries(n.metadata.imports))for(let d of y)if((d.alias??d.packageName)===m){let b=new g;return b.subject=new c(u,d.packageName,l,d.version),b}}}let p=new g;return p.subject=new c(o.publisher,o.package_,t,o.version??void 0),p}return null}async saveKanonaks(t,n){let r=new Map;for(let a of t)a instanceof w&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,s]of r){let o=await this.convertKanonaksToDocument(a,s),c=`${a.split("@")[0]}.yml`;await n.saveDocumentAsync(o,c)}}async serializeToYaml(t,n){let r=t.filter(o=>o instanceof w&&o.namespace===n);if(r.length===0)throw new Error(`No kanonaks found with namespace '${n}'`);let a=await this.convertKanonaksToDocument(n,r);return new G().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let p of o.statement){let[i,m]=this.convertStatementToProperty(p);i&&m!==null&&m!==void 0&&(c[i]=m),this.collectImportsFromStatement(p,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof I)return[t.predicate.subject.name,t.object];if(t instanceof L)return[t.predicate.subject.name,t.object];if(t instanceof T)return[t.predicate.subject.name,t.object];if(t instanceof j)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof P){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof K){let n=this.convertEmbeddedKanonakToValue(t.object);return[t.predicate.subject.name,n]}return[null,null]}convertKanonakListToValue(t){let n=[];for(let r of t)r instanceof g?n.push(r.subject.name):r instanceof h&&n.push(this.convertEmbeddedKanonakToValue(r));return n}convertEmbeddedKanonakToValue(t){let n={};for(let r of t.statement){let[a,s]=this.convertStatementToProperty(r);a&&s!==null&&s!==void 0&&(n[a]=s)}return n}collectImportsFromStatement(t,n,r){}};function C(f,t){f.sourceDoc=t;for(let n of f.statement)if(n instanceof K)C(n.object,t);else if(n instanceof P)for(let r of n.object)r instanceof h&&C(r,t)}function F(f){let t=f.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+de(f)}function de(f){return f instanceof E?"m:"+String(f.object):f instanceof I?"s:"+String(f.object):f instanceof L?"n:"+String(f.object):f instanceof T?"b:"+String(f.object):f instanceof j?"r:"+B(f.object):f instanceof K?"e:"+B(f.object):f instanceof P?"l:["+(f.object??[]).map(B).join("|")+"]":"x"}function B(f){if(!f)return"";if(f instanceof g){let t=f.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return f instanceof h?"E("+(f.statement??[]).map(F).join(";")+")":f instanceof D?"L("+String(f.value)+")":"N"}export{ee as a,oe as b,se as c,Ke as d,A as e,S as f,_ as g,ve as h,V as i,re as j};