@kanonak-protocol/sdk 6.6.0 → 6.8.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 (44) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +1 -1
  3. package/dist/{chunk-OHF4RIKS.js → chunk-2GV6GXRF.js} +1 -1
  4. package/dist/{chunk-BDTJIUS4.js → chunk-3ABGZHKM.js} +1 -1
  5. package/dist/{chunk-5ZRVFYCP.js → chunk-6CI3HTKF.js} +1 -1
  6. package/dist/chunk-6USORWEP.js +1 -0
  7. package/dist/chunk-7IMLHHSA.js +1 -0
  8. package/dist/{chunk-CPENAANM.js → chunk-AZFLKLPB.js} +1 -1
  9. package/dist/{chunk-K76UUREI.js → chunk-F4UHQVGA.js} +1 -1
  10. package/dist/{chunk-I2T6ORSG.js → chunk-FCRP7KXR.js} +16 -16
  11. package/dist/{chunk-DQGXJDQU.js → chunk-FKLZDYWF.js} +1 -1
  12. package/dist/{chunk-IWPCPQQY.js → chunk-FYAZ345F.js} +1 -1
  13. package/dist/{chunk-FS7UGDEX.js → chunk-IT37WOHT.js} +1 -1
  14. package/dist/{chunk-WXXZOJ4O.js → chunk-NYCGUDVW.js} +1 -1
  15. package/dist/{chunk-TF23WBSZ.js → chunk-PXUSA72Q.js} +1 -1
  16. package/dist/chunk-Q2ZUKZEU.js +1 -0
  17. package/dist/{chunk-VJUZKHQU.js → chunk-QRF7AT2M.js} +1 -1
  18. package/dist/{chunk-LIN5SG5I.js → chunk-TR7PC72M.js} +1 -1
  19. package/dist/chunk-TVMOJ2QS.js +1 -0
  20. package/dist/{chunk-Z2444SWM.js → chunk-X2URIXH7.js} +1 -1
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +3 -3
  23. package/dist/parsing/KanonakObjectParser.d.ts +22 -2
  24. package/dist/parsing/index.js +1 -1
  25. package/dist/producer/index.js +1 -1
  26. package/dist/reasoning/index.js +1 -1
  27. package/dist/repositories/browser.js +1 -1
  28. package/dist/repositories/index.js +1 -1
  29. package/dist/resolution/index.js +1 -1
  30. package/dist/resolution/linkTargets.d.ts +45 -0
  31. package/dist/search/index.js +1 -1
  32. package/dist/server/index.js +1 -1
  33. package/dist/shacl/ConformanceScope.d.ts +34 -6
  34. package/dist/shacl/index.d.ts +2 -2
  35. package/dist/transformations/index.js +1 -1
  36. package/dist/uri-helpers/index.js +1 -1
  37. package/dist/validation/index.js +1 -1
  38. package/package.json +2 -2
  39. package/dist/KanonakUri-4VJGV3FN.js +0 -1
  40. package/dist/chunk-6WOPXTIL.js +0 -1
  41. package/dist/chunk-FUUTGGJS.js +0 -1
  42. package/dist/chunk-GGK6A6QK.js +0 -1
  43. package/dist/chunk-LK5SHY4B.js +0 -1
  44. package/dist/chunk-SBWD7EOG.js +0 -1
package/dist/browser.d.ts CHANGED
@@ -24,7 +24,7 @@ export { InMemoryKanonakDocumentRepository } from './repositories/InMemoryKanona
24
24
  export { HttpKanonakDocumentRepository } from './repositories/HttpKanonakDocumentRepository.js';
25
25
  export { PublisherIndex } from './repositories/PublisherIndex.js';
26
26
  export { KanonakVocabulary, OWL_HAS_KEY } from './reasoning/KanonakVocabulary.js';
27
- export { SHACL_PUBLISHER, SHACL_PACKAGE, SH_SHAPE, SH_NODE_SHAPE, SH_PROPERTY_SHAPE, } from './shacl/uris.js';
27
+ export { SHACL_PUBLISHER, SHACL_PACKAGE, SH_SHAPE, SH_NODE_SHAPE, SH_PROPERTY_SHAPE, SH_COMP_MIN_COUNT, SH_COMP_MAX_COUNT, SH_COMP_DATATYPE, SH_COMP_CLASS, SH_COMP_IN, SH_COMP_PATTERN, SH_COMP_MIN_LENGTH, SH_COMP_MAX_LENGTH, SH_COMP_MIN_INCLUSIVE, SH_COMP_MAX_INCLUSIVE, SH_COMP_NODE_KIND, SH_COMP_CLOSED, SH_COMP_HAS_VALUE, SH_COMP_QUALIFIED_MIN_COUNT, SH_COMP_QUALIFIED_MAX_COUNT, SH_COMP_HAS_KEY, } from './shacl/uris.js';
28
28
  export { PublisherConfigResolver } from './repositories/PublisherConfig.js';
29
29
  export type { PublisherConfig } from './repositories/PublisherConfig.js';
30
30
  export { ANY_PUBLISHER, checkPackageUrlTemplates, checkPackageUrlTemplate, packageUrlTemplateFor, fillPackageUrlTemplate, } from './repositories/PackageUrlTemplates.js';
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- import{a as me,b as de,c as ue,d as $e,e as er,f as rr,g as or,i as tr,j as nr,k as ar,l as ir,m as sr,n as pr,o as lr,p as cr,q as mr,r as dr,s as ur}from"./chunk-TF23WBSZ.js";import{a as Rr}from"./chunk-IWPCPQQY.js";import{a as We,b as Ye,c as ze,d as Xe,e as Je,f as Qe,g as Ze,h as fr,i as yr,j as kr,k as Pr,l as xr}from"./chunk-FS7UGDEX.js";import{a as f,b as y,c as k,e as P,g as E,h as C,i as S,j as g,k as A,m as I,o as h,p as K,q as O,r as D,s as b,t as j,u as N}from"./chunk-Z2444SWM.js";import{a as Re,b as fe,c as ye}from"./chunk-OHF4RIKS.js";import{a as ke}from"./chunk-LIN5SG5I.js";import"./chunk-SC5M74NM.js";import{A as Fe,B as Me,C as Be,M as qe,a as Pe,b as xe,c as Ee,d as Ce,g as Se,h as ge,i as Ae,j as Ie,l as he,m as Ke,n as Oe,o as De,p as be,q as je,r as Ne,s as Te,t as Ve,u as He,v as _e,w as Le,x as ve,y as Ue,z as we}from"./chunk-I2T6ORSG.js";import"./chunk-VJUZKHQU.js";import{m as Ge}from"./chunk-CPENAANM.js";import"./chunk-QHABFCRC.js";import{a as c,b as m,c as d,d as u,e as R}from"./chunk-5FVUBF7N.js";import{a as p}from"./chunk-WXXZOJ4O.js";import{a as se,g as pe,h as le,k as ce}from"./chunk-SBWD7EOG.js";import{a as l}from"./chunk-5ZRVFYCP.js";import"./chunk-PEJALHXK.js";import{a as Y,b as z,ga as oe,h as Q,i as Z,j as $,k as ee,l as re,ma as te,oa as ne}from"./chunk-6WOPXTIL.js";import{H as ae,I as ie,a as T,b as V,c as H,d as _,e as L,g as v,h as U,i as w,j as F,k as M,l as B,m as G,n as q,o as W,s as X,t as J}from"./chunk-LK5SHY4B.js";import"./chunk-F67UH4FD.js";import{c as e,d as r,e as o,f as t,g as n,h as a,i,k as s}from"./chunk-GGK6A6QK.js";import{a as x}from"./chunk-FUUTGGJS.js";export{E as ANY_PUBLISHER,_e as AmbiguousReferenceRule,M as BooleanStatement,ze as CANONICAL_FORM_VERSION,lr as CREDENTIAL_EXPIRY_SKEW_SECONDS,nr as CREDENTIAL_HELPER_PROTOCOL_VERSION,pe as Carrier,Me as ClassDefinitionRule,De as ClassHierarchyCycleRule,R as CredentialError,V as DefinedKanonak,de as EdgeType,_ as EmbeddedKanonak,he as EmbeddedKanonakTypeRule,G as EmbeddedStatement,Pr as EntitlementDeniedError,xr as EntitlementProducer,ue as GraphBuilder,N as HttpKanonakDocumentRepository,h as INTEGRITY_PREFIX,Qe as ImportBook,Ke as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,f as KANONAK_USER_AGENT,T as Kanonak,fe as KanonakDocumentPositions,c as KanonakHttpError,ce as KanonakObjectParser,qe as KanonakObjectValidator,l as KanonakParser,x as KanonakUri,ke as KanonakUriBuilder,te as KanonakVocabulary,q as ListStatement,Be as MarkdownLinkRule,W as MarkdownStatement,Ve as NamespaceImportCycleRule,Se as NamespacePrefixRule,me as NodeType,F as NumberStatement,tr as OAuthDiscovery,oe as OWL_HAS_KEY,ve as ObjectPropertyValueValidationRule,Ee as OntologyValidationError,Pe as OntologyValidationResult,Xe as PackageBuilder,fr as ProducerRepository,Ue as PropertyDomainRule,be as PropertyHierarchyCycleRule,we as PropertyKindRangeConsistencyRule,Re as PropertyMetadata,Le as PropertyRangeReferenceRule,je as PropertyRangeRequiredRule,Ae as PropertyTypeSpecificityRule,I as PublisherConfigResolver,j as PublisherIndex,L as ReferenceKanonak,B as ReferenceStatement,Fe as ReservedNameShadowRule,ge as ResourceNamingRule,Y as ResourceResolver,ne as ResourceTypeClassifier,Z as SHACL_PACKAGE,Q as SHACL_PUBLISHER,ee as SH_NODE_SHAPE,re as SH_PROPERTY_SHAPE,$ as SH_SHAPE,U as ScalarStatement,v as Statement,w as StringStatement,Ne as SubClassOfReferenceRule,Te as SubPropertyOfReferenceRule,H as SubjectKanonak,Ie as SubjectKanonakTypeRequiredRule,mr as TOKEN_ENV,ur as TokenCredentialProvider,z as TypeResolver,He as UnresolvedPredicateRule,Oe as UnresolvedReferenceRule,Ce as ValidationContext,xe as ValidationSeverity,yr as allowAllPolicy,b as assertIntegrityAsync,Ge as buildOntologyModel,We as canonicalForm,Ye as canonicalHash,le as carrierOf,ar as checkCredentialAnswer,ir as checkHelperAnswer,sr as checkHelperEraseAnswer,S as checkPackageUrlTemplate,C as checkPackageUrlTemplates,e as compareVersions,D as computeIntegrityAsync,Je as contentAddressedName,cr as createCredentialedFetch,t as createVersion,d as describeResponse,A as fillPackageUrlTemplate,Rr as findDerivation,o as formatVersion,k as getKanonakUserAgent,m as httpError,a as isCompatibleVersion,i as isMajorCompatible,P as kanonakFetch,or as narrowestScope,kr as noopMeter,$e as normalizeHost,g as packageUrlTemplateFor,K as parseLockFile,er as parseScope,n as parseVersionString,ye as parseWithPositions,pr as parseWwwAuthenticate,s as pickHighestDocument,J as referenceUris,u as retryAfterSecondsOf,Ze as sanitizeName,rr as scopeContains,O as serializeLockFile,y as setKanonakUserAgent,ie as subjectAddress,dr as tokenEnvKeyFor,X as typeReferenceUris,ae as valuesOf,r as versionsEqual,se as walkDefinedKanonaks};
1
+ import{a as He,b as Ne,c as ge,d as Rr,e as fr,f as yr,g as kr,i as Cr,j as Sr,k as _r,l as Er,m as xr,n as Or,o as Ir,p as Ar,q as Hr,r as Nr,s as gr}from"./chunk-PXUSA72Q.js";import{a as Mr}from"./chunk-FYAZ345F.js";import{a as pr,b as lr,c as cr,d as mr,e as dr,f as ur,g as Pr,h as Kr,i as Dr,j as Tr,k as hr,l as Lr}from"./chunk-IT37WOHT.js";import{a as R,b as f,c as y,e as k,g as S,h as _,i as E,j as x,k as O,m as I,o as A,p as H,q as N,r as g,s as M,t as K,u as D}from"./chunk-X2URIXH7.js";import{a as Me,b as Ke,c as De}from"./chunk-2GV6GXRF.js";import{a as Te}from"./chunk-TR7PC72M.js";import"./chunk-SC5M74NM.js";import{A as rr,B as or,C as tr,D as nr,E as ar,O as sr,a as he,b as Le,c as Ve,d as be,i as je,j as Ue,k as ve,l as we,n as Fe,o as Be,p as Ge,q as Ye,r as qe,s as We,t as Xe,u as ze,v as Qe,w as Je,x as Ze,y as $e,z as er}from"./chunk-FCRP7KXR.js";import"./chunk-QRF7AT2M.js";import{m as ir}from"./chunk-AZFLKLPB.js";import"./chunk-QHABFCRC.js";import{a as c,b as m,c as d,d as u,e as P}from"./chunk-5FVUBF7N.js";import{a as p}from"./chunk-NYCGUDVW.js";import{a as xe,g as Oe,h as Ie,k as Ae}from"./chunk-Q2ZUKZEU.js";import{a as l}from"./chunk-6CI3HTKF.js";import"./chunk-PEJALHXK.js";import{O as oe,P as te,Q as ne,R as ae,S as ie,T as se,U as pe,V as le,W as ce,X as me,Y as de,Z as ue,a as W,b as X,ca as Pe,da as Re,ea as fe,fa as ye,ga as ke,h as J,i as Z,j as $,k as ee,l as re,ma as Ce,oa as Se}from"./chunk-TVMOJ2QS.js";import{H as _e,I as Ee,a as T,b as h,c as L,d as V,e as b,g as j,h as U,i as v,j as w,k as F,l as B,m as G,n as Y,o as q,s as z,t as Q}from"./chunk-6USORWEP.js";import"./chunk-F67UH4FD.js";import{c as e,d as r,e as o,f as t,g as n,h as a,i,k as s,l as C}from"./chunk-7IMLHHSA.js";export{S as ANY_PUBLISHER,Ze as AmbiguousReferenceRule,F as BooleanStatement,cr as CANONICAL_FORM_VERSION,Ir as CREDENTIAL_EXPIRY_SKEW_SECONDS,Sr as CREDENTIAL_HELPER_PROTOCOL_VERSION,Oe as Carrier,nr as ClassDefinitionRule,Ye as ClassHierarchyCycleRule,P as CredentialError,h as DefinedKanonak,Ne as EdgeType,V as EmbeddedKanonak,Fe as EmbeddedKanonakTypeRule,G as EmbeddedStatement,hr as EntitlementDeniedError,Lr as EntitlementProducer,ge as GraphBuilder,D as HttpKanonakDocumentRepository,A as INTEGRITY_PREFIX,ur as ImportBook,Be as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,R as KANONAK_USER_AGENT,T as Kanonak,Ke as KanonakDocumentPositions,c as KanonakHttpError,Ae as KanonakObjectParser,sr as KanonakObjectValidator,l as KanonakParser,C as KanonakUri,Te as KanonakUriBuilder,Ce as KanonakVocabulary,Y as ListStatement,ar as MarkdownLinkRule,q as MarkdownStatement,Qe as NamespaceImportCycleRule,je as NamespacePrefixRule,He as NodeType,w as NumberStatement,Cr as OAuthDiscovery,ke as OWL_HAS_KEY,er as ObjectPropertyValueValidationRule,Ve as OntologyValidationError,he as OntologyValidationResult,mr as PackageBuilder,Kr as ProducerRepository,rr as PropertyDomainRule,qe as PropertyHierarchyCycleRule,or as PropertyKindRangeConsistencyRule,Me as PropertyMetadata,$e as PropertyRangeReferenceRule,We as PropertyRangeRequiredRule,ve as PropertyTypeSpecificityRule,I as PublisherConfigResolver,K as PublisherIndex,b as ReferenceKanonak,B as ReferenceStatement,tr as ReservedNameShadowRule,Ue as ResourceNamingRule,W as ResourceResolver,Se as ResourceTypeClassifier,Z as SHACL_PACKAGE,J as SHACL_PUBLISHER,ae as SH_COMP_CLASS,ue as SH_COMP_CLOSED,ne as SH_COMP_DATATYPE,ye as SH_COMP_HAS_KEY,Pe as SH_COMP_HAS_VALUE,ie as SH_COMP_IN,te as SH_COMP_MAX_COUNT,me as SH_COMP_MAX_INCLUSIVE,le as SH_COMP_MAX_LENGTH,oe as SH_COMP_MIN_COUNT,ce as SH_COMP_MIN_INCLUSIVE,pe as SH_COMP_MIN_LENGTH,de as SH_COMP_NODE_KIND,se as SH_COMP_PATTERN,fe as SH_COMP_QUALIFIED_MAX_COUNT,Re as SH_COMP_QUALIFIED_MIN_COUNT,ee as SH_NODE_SHAPE,re as SH_PROPERTY_SHAPE,$ as SH_SHAPE,U as ScalarStatement,j as Statement,v as StringStatement,Xe as SubClassOfReferenceRule,ze as SubPropertyOfReferenceRule,L as SubjectKanonak,we as SubjectKanonakTypeRequiredRule,Hr as TOKEN_ENV,gr as TokenCredentialProvider,X as TypeResolver,Je as UnresolvedPredicateRule,Ge as UnresolvedReferenceRule,be as ValidationContext,Le as ValidationSeverity,Dr as allowAllPolicy,M as assertIntegrityAsync,ir as buildOntologyModel,pr as canonicalForm,lr as canonicalHash,Ie as carrierOf,_r as checkCredentialAnswer,Er as checkHelperAnswer,xr as checkHelperEraseAnswer,E as checkPackageUrlTemplate,_ as checkPackageUrlTemplates,e as compareVersions,g as computeIntegrityAsync,dr as contentAddressedName,Ar as createCredentialedFetch,t as createVersion,d as describeResponse,O as fillPackageUrlTemplate,Mr as findDerivation,o as formatVersion,y as getKanonakUserAgent,m as httpError,a as isCompatibleVersion,i as isMajorCompatible,k as kanonakFetch,kr as narrowestScope,Tr as noopMeter,Rr as normalizeHost,x as packageUrlTemplateFor,H as parseLockFile,fr as parseScope,n as parseVersionString,De as parseWithPositions,Or as parseWwwAuthenticate,s as pickHighestDocument,Q as referenceUris,u as retryAfterSecondsOf,Pr as sanitizeName,yr as scopeContains,N as serializeLockFile,f as setKanonakUserAgent,Ee as subjectAddress,Nr as tokenEnvKeyFor,z as typeReferenceUris,_e as valuesOf,r as versionsEqual,xe as walkDefinedKanonaks};
@@ -1,3 +1,3 @@
1
- import{j as A}from"./chunk-SBWD7EOG.js";import{a as E}from"./chunk-5ZRVFYCP.js";import{pa as $}from"./chunk-6WOPXTIL.js";import{c as V,d as I,e as N,f as x,g as U,l as W,m as J,n as _,o as B}from"./chunk-LK5SHY4B.js";var R=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as H,LineCounter as Q,isMap as b,isPair as f,isScalar as l,isSeq as j}from"yaml";var L=class r{entities=new Map;entityBlocks=new Map;properties=new Map;propertyValues=new Map;valueListItems=new Map;importPackages=new Map;nestedKeys=new Map;nestedValues=new Map;static fromContent(e){let n=new r,t=new Q,o=H(e,{lineCounter:t});if(o.errors.length>0||!b(o.contents))return n;O(o.contents,[],t,n);for(let i of o.contents.items){if(!f(i)||!l(i.key))continue;let s=String(i.key.value),u=i.key.range;if(!u)continue;n.entities.set(s,g(u,t));let a=i.value,c=a&&typeof a=="object"&&"range"in a?a.range:void 0;if(c?n.entityBlocks.set(s,g([u[0],u[1],c[2]],t)):n.entityBlocks.set(s,g(u,t)),b(i.value)){let k=new Map,d=new Map,p=new Map;for(let S of i.value.items){if(!f(S)||!l(S.key))continue;let h=String(S.key.value),m=S.key.range;m&&k.set(h,g(m,t));let P=S.value;if(P&&typeof P=="object"&&"range"in P&&Array.isArray(P.range)){let v=P.range;d.set(h,g(v,t))}if(j(P)){let v=[];for(let K of P.items)K&&typeof K=="object"&&"range"in K&&Array.isArray(K.range)&&v.push(g(K.range,t));v.length>0&&p.set(h,v)}}k.size>0&&n.properties.set(s,k),d.size>0&&n.propertyValues.set(s,d),p.size>0&&n.valueListItems.set(s,p);let y=Y(i.value,t);y.length>0&&n.importPackages.set(s,y)}}return n}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,n){for(let[t,o]of this.entityBlocks)if(C(o,e,n))return t}findPropertyAtPosition(e,n){let t=this.findEntityAtPosition(e,n);if(!t)return;let o=this.properties.get(t),i=this.propertyValues.get(t);if(!o&&!i)return{entityName:t};let s,u;if(i)for(let[a,c]of i)C(c,e,n)&&(!u||q(c,u))&&(s=a,u=c);if(o)for(let[a,c]of o)C(c,e,n)&&(!u||q(c,u))&&(s=a,u=c);return s?{entityName:t,propertyName:s}:{entityName:t}}getPropertyPosition(e,n){return this.properties.get(e)?.get(n)}getPropertyValuePosition(e,n){return this.propertyValues.get(e)?.get(n)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[n,t]of this.importPackages)for(let o of t)e.push({entityName:n,entry:o});return e}findPropertySourceName(e,n){let t=this.properties.get(e);if(t){if(t.has(n))return n;for(let o of t.keys()){let i=o.lastIndexOf(".");if((i===-1?o:o.substring(i+1))===n)return o}}}getListItemPosition(e,n,t){let o=this.valueListItems.get(e)?.get(n);if(!(!o||t<0||t>=o.length))return o[t]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,n){this.nestedKeys.set(e,n)}setNestedValuePosition(e,n){this.nestedValues.set(e,n)}getMostSpecificPosition(e,n,t){if(e){if(n!==void 0){if(t!==void 0){let s=this.getListItemPosition(e,n,t);if(s)return s}let o=this.getPropertyValuePosition(e,n);if(o)return o;let i=this.getPropertyPosition(e,n);if(i)return i}return this.getEntityPosition(e)}}};function Y(r,e){let n=[];if(!b(r))return n;let t=r.items.find(o=>f(o)&&l(o.key)&&String(o.key.value)==="imports");if(!t||!f(t)||!j(t.value))return n;for(let o of t.value.items){if(!b(o))continue;let i=o.items.find(a=>f(a)&&l(a.key)&&String(a.key.value)==="publisher");if(!i||!f(i)||!l(i.value))continue;let s=String(i.value.value),u=o.items.find(a=>f(a)&&l(a.key)&&String(a.key.value)==="packages");if(!(!u||!f(u)||!j(u.value)))for(let a of u.value.items){if(!b(a))continue;let c=a.items.find(m=>f(m)&&l(m.key)&&String(m.key.value)==="package");if(!c||!f(c)||!l(c.value)||!c.value.range)continue;let k=String(c.value.value),d=a.items.find(m=>f(m)&&l(m.key)&&String(m.key.value)==="version"),p=d&&f(d)&&l(d.value)?String(d.value.value):"",y=a.items.find(m=>f(m)&&l(m.key)&&String(m.key.value)==="alias"),S=y&&f(y)&&l(y.value)?String(y.value.value):void 0,h=S!==void 0?{publisher:s,package_:k,version:p,alias:S,position:g(c.value.range,e)}:{publisher:s,package_:k,version:p,position:g(c.value.range,e)};n.push(h)}}return n}function C(r,e,n){return!(e<r.line||e>r.endLine||e===r.line&&n<r.column||e===r.endLine&&n>r.endColumn)}function q(r,e){let n=r.endLine-r.line,t=e.endLine-e.line;if(n!==t)return n<t;let o=r.endLine===r.line?r.endColumn-r.column:Number.MAX_SAFE_INTEGER,i=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return o<i}function O(r,e,n,t){if(b(r)){for(let o of r.items){if(!f(o)||!l(o.key))continue;let i=String(o.key.value),s=[...e,i],u=JSON.stringify(s);o.key.range&&t.setNestedKeyPosition(u,g(o.key.range,n));let a=o.value,c=z(a);c&&t.setNestedValuePosition(u,g(c,n)),O(a,s,n,t)}return}if(j(r)){for(let o=0;o<r.items.length;o++){let i=r.items[o],s=[...e,o],u=JSON.stringify(s),a=z(i);a&&t.setNestedValuePosition(u,g(a,n)),O(i,s,n,t)}return}}function z(r){if(!r||typeof r!="object"||!("range"in r))return;let e=r.range;return Array.isArray(e)&&e.length>=3?e:void 0}function g(r,e){let n=e.linePos(r[0]),t=e.linePos(r[2]);return{line:n.line-1,column:n.col-1,endLine:t.line-1,endColumn:t.col-1}}function Z(r,e){let t=(e??new E).parse(r),o=L.fromContent(r);return{document:t,positions:o}}function T(r,e,n,t,o){if(e<t.line||e>t.endLine||e===t.line&&n<t.column||e===t.endLine&&n>=t.endColumn)return;let i=M(o,t.line,t.column),s=M(o,t.endLine,t.endColumn);if(i<0||s<0)return;let u=o.substring(i,s),a=A(u);if(a.length!==r.links.length)return;let c=e-t.line,k=e===t.line?n-t.column:n,d=M(u,c,k);if(!(d<0))for(let p=0;p<a.length;p++){let y=a[p];if(d>=y.startOffset&&d<y.endOffset)return r.links[p]}}function G(r,e){let n=M(e,r.line,r.column),t=M(e,r.endLine,r.endColumn);if(n<0||t<0)return;let o=e.substring(n,t);return A(o).map(i=>{let s=F(e,n+i.startOffset),u=F(e,n+i.endOffset);return{line:s.line,column:s.column,endLine:u.line,endColumn:u.column}})}function F(r,e){let n=0,t=0;for(let o=0;o<e&&o<r.length;o++)r[o]===`
1
+ import{j as A}from"./chunk-Q2ZUKZEU.js";import{a as E}from"./chunk-6CI3HTKF.js";import{pa as $}from"./chunk-TVMOJ2QS.js";import{c as V,d as I,e as N,f as x,g as U,l as W,m as J,n as _,o as B}from"./chunk-6USORWEP.js";var R=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as H,LineCounter as Q,isMap as b,isPair as f,isScalar as l,isSeq as j}from"yaml";var L=class r{entities=new Map;entityBlocks=new Map;properties=new Map;propertyValues=new Map;valueListItems=new Map;importPackages=new Map;nestedKeys=new Map;nestedValues=new Map;static fromContent(e){let n=new r,t=new Q,o=H(e,{lineCounter:t});if(o.errors.length>0||!b(o.contents))return n;O(o.contents,[],t,n);for(let i of o.contents.items){if(!f(i)||!l(i.key))continue;let s=String(i.key.value),u=i.key.range;if(!u)continue;n.entities.set(s,g(u,t));let a=i.value,c=a&&typeof a=="object"&&"range"in a?a.range:void 0;if(c?n.entityBlocks.set(s,g([u[0],u[1],c[2]],t)):n.entityBlocks.set(s,g(u,t)),b(i.value)){let k=new Map,d=new Map,p=new Map;for(let S of i.value.items){if(!f(S)||!l(S.key))continue;let h=String(S.key.value),m=S.key.range;m&&k.set(h,g(m,t));let P=S.value;if(P&&typeof P=="object"&&"range"in P&&Array.isArray(P.range)){let v=P.range;d.set(h,g(v,t))}if(j(P)){let v=[];for(let K of P.items)K&&typeof K=="object"&&"range"in K&&Array.isArray(K.range)&&v.push(g(K.range,t));v.length>0&&p.set(h,v)}}k.size>0&&n.properties.set(s,k),d.size>0&&n.propertyValues.set(s,d),p.size>0&&n.valueListItems.set(s,p);let y=Y(i.value,t);y.length>0&&n.importPackages.set(s,y)}}return n}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,n){for(let[t,o]of this.entityBlocks)if(C(o,e,n))return t}findPropertyAtPosition(e,n){let t=this.findEntityAtPosition(e,n);if(!t)return;let o=this.properties.get(t),i=this.propertyValues.get(t);if(!o&&!i)return{entityName:t};let s,u;if(i)for(let[a,c]of i)C(c,e,n)&&(!u||q(c,u))&&(s=a,u=c);if(o)for(let[a,c]of o)C(c,e,n)&&(!u||q(c,u))&&(s=a,u=c);return s?{entityName:t,propertyName:s}:{entityName:t}}getPropertyPosition(e,n){return this.properties.get(e)?.get(n)}getPropertyValuePosition(e,n){return this.propertyValues.get(e)?.get(n)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[n,t]of this.importPackages)for(let o of t)e.push({entityName:n,entry:o});return e}findPropertySourceName(e,n){let t=this.properties.get(e);if(t){if(t.has(n))return n;for(let o of t.keys()){let i=o.lastIndexOf(".");if((i===-1?o:o.substring(i+1))===n)return o}}}getListItemPosition(e,n,t){let o=this.valueListItems.get(e)?.get(n);if(!(!o||t<0||t>=o.length))return o[t]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,n){this.nestedKeys.set(e,n)}setNestedValuePosition(e,n){this.nestedValues.set(e,n)}getMostSpecificPosition(e,n,t){if(e){if(n!==void 0){if(t!==void 0){let s=this.getListItemPosition(e,n,t);if(s)return s}let o=this.getPropertyValuePosition(e,n);if(o)return o;let i=this.getPropertyPosition(e,n);if(i)return i}return this.getEntityPosition(e)}}};function Y(r,e){let n=[];if(!b(r))return n;let t=r.items.find(o=>f(o)&&l(o.key)&&String(o.key.value)==="imports");if(!t||!f(t)||!j(t.value))return n;for(let o of t.value.items){if(!b(o))continue;let i=o.items.find(a=>f(a)&&l(a.key)&&String(a.key.value)==="publisher");if(!i||!f(i)||!l(i.value))continue;let s=String(i.value.value),u=o.items.find(a=>f(a)&&l(a.key)&&String(a.key.value)==="packages");if(!(!u||!f(u)||!j(u.value)))for(let a of u.value.items){if(!b(a))continue;let c=a.items.find(m=>f(m)&&l(m.key)&&String(m.key.value)==="package");if(!c||!f(c)||!l(c.value)||!c.value.range)continue;let k=String(c.value.value),d=a.items.find(m=>f(m)&&l(m.key)&&String(m.key.value)==="version"),p=d&&f(d)&&l(d.value)?String(d.value.value):"",y=a.items.find(m=>f(m)&&l(m.key)&&String(m.key.value)==="alias"),S=y&&f(y)&&l(y.value)?String(y.value.value):void 0,h=S!==void 0?{publisher:s,package_:k,version:p,alias:S,position:g(c.value.range,e)}:{publisher:s,package_:k,version:p,position:g(c.value.range,e)};n.push(h)}}return n}function C(r,e,n){return!(e<r.line||e>r.endLine||e===r.line&&n<r.column||e===r.endLine&&n>r.endColumn)}function q(r,e){let n=r.endLine-r.line,t=e.endLine-e.line;if(n!==t)return n<t;let o=r.endLine===r.line?r.endColumn-r.column:Number.MAX_SAFE_INTEGER,i=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return o<i}function O(r,e,n,t){if(b(r)){for(let o of r.items){if(!f(o)||!l(o.key))continue;let i=String(o.key.value),s=[...e,i],u=JSON.stringify(s);o.key.range&&t.setNestedKeyPosition(u,g(o.key.range,n));let a=o.value,c=z(a);c&&t.setNestedValuePosition(u,g(c,n)),O(a,s,n,t)}return}if(j(r)){for(let o=0;o<r.items.length;o++){let i=r.items[o],s=[...e,o],u=JSON.stringify(s),a=z(i);a&&t.setNestedValuePosition(u,g(a,n)),O(i,s,n,t)}return}}function z(r){if(!r||typeof r!="object"||!("range"in r))return;let e=r.range;return Array.isArray(e)&&e.length>=3?e:void 0}function g(r,e){let n=e.linePos(r[0]),t=e.linePos(r[2]);return{line:n.line-1,column:n.col-1,endLine:t.line-1,endColumn:t.col-1}}function Z(r,e){let t=(e??new E).parse(r),o=L.fromContent(r);return{document:t,positions:o}}function T(r,e,n,t,o){if(e<t.line||e>t.endLine||e===t.line&&n<t.column||e===t.endLine&&n>=t.endColumn)return;let i=M(o,t.line,t.column),s=M(o,t.endLine,t.endColumn);if(i<0||s<0)return;let u=o.substring(i,s),a=A(u);if(a.length!==r.links.length)return;let c=e-t.line,k=e===t.line?n-t.column:n,d=M(u,c,k);if(!(d<0))for(let p=0;p<a.length;p++){let y=a[p];if(d>=y.startOffset&&d<y.endOffset)return r.links[p]}}function G(r,e){let n=M(e,r.line,r.column),t=M(e,r.endLine,r.endColumn);if(n<0||t<0)return;let o=e.substring(n,t);return A(o).map(i=>{let s=F(e,n+i.startOffset),u=F(e,n+i.endOffset);return{line:s.line,column:s.column,endLine:u.line,endColumn:u.column}})}function F(r,e){let n=0,t=0;for(let o=0;o<e&&o<r.length;o++)r[o]===`
2
2
  `&&(n++,t=o+1);return{line:n,column:e-t}}function M(r,e,n){let t=0,o=0;for(let i=0;i<r.length;i++){if(t===e)return Math.min(o+n,r.length);r[i]===`
3
3
  `&&(t++,o=i+1)}return t===e?Math.min(o+n,r.length):-1}function ee(r,e,n){let t=[];for(let o of r){if(!(o instanceof V)||typeof o.sourceKey!="string")continue;let i=[o.sourceKey],s=$(o);s&&t.push({role:"subject",uri:s,range:w(e.getEntityPosition(o.sourceKey),i,"key"),path:i}),D(o.statement,i,e,n,t)}return t}function ne(r,e,n){let t;for(let o of r)te(o.range,e,n)&&(!t||oe(o.range,t.range))&&(t=o);return t}function D(r,e,n,t,o){for(let i of r){if(!(i instanceof U)||i.sourceKey===void 0)continue;let s=[...e,i.sourceKey],u=i.predicate?.subject;if(u&&o.push({role:"predicate",uri:u,range:w(n.getNodeKeyPosition(s),s,"key"),path:s}),i instanceof W)o.push({role:"reference",uri:i.object.subject,range:w(n.getNodeValuePosition(s),s,"value"),path:s});else if(i instanceof B)X(i.links,s,n,t,o);else if(i instanceof J)i.object&&D(i.object.statement,s,n,t,o);else if(i instanceof _)for(let a of i.object??[]){if(!(a instanceof N||a instanceof I||a instanceof x)||a.sourceKey===void 0)continue;let c=[...s,a.sourceKey];a instanceof N?o.push({role:"reference",uri:a.subject,range:w(n.getNodeValuePosition(c),c,"value"),path:c}):a instanceof I?D(a.statement,c,n,t,o):a.links&&X(a.links,c,n,t,o)}}}function X(r,e,n,t,o){if(t===void 0||r.length===0)return;let i=G(w(n.getNodeValuePosition(e),e,"value"),t);if(!i||i.length!==r.length)throw new Error(`sourceSymbols: the prose value at ${JSON.stringify(e)} has ${r.length} resolved [[reference]](s) but ${i?.length??0} in its source text \u2014 the source text is not the text this document was parsed from.`);r.forEach((s,u)=>{s.target&&o.push({role:"reference",uri:s.target.subject,range:i[u],path:e})})}function w(r,e,n){if(!r)throw new Error(`sourceSymbols: no source ${n} position for ${JSON.stringify(e)}. The object model has a node the position index does not \u2014 the positions were not built from the text this document was parsed from.`);return r}function te(r,e,n){return!(e<r.line||e>r.endLine||e===r.line&&n<r.column||e===r.endLine&&n>r.endColumn)}function oe(r,e){let n=r.endLine-r.line,t=e.endLine-e.line;return n!==t?n<t:r.endColumn-r.column<e.endColumn-e.column}export{R as a,L as b,Z as c,T as d,ee as e,ne as f};
@@ -1 +1 @@
1
- import{o as i,p as o,q as r}from"./chunk-Z2444SWM.js";import{readFileSync as c,writeFileSync as l,existsSync as s}from"fs";import{createHash as a}from"crypto";var n="kanonak.lock";function f(e=n){return s(e)?o(c(e,"utf-8")):null}function k(e,t=n){e.lastUpdated=new Date().toISOString(),l(t,r(e),"utf-8")}function L(e){let t=a("sha256").update(e).digest("hex");return`${i}${t}`}export{f as a,k as b,L as c};
1
+ import{o as i,p as o,q as r}from"./chunk-X2URIXH7.js";import{readFileSync as c,writeFileSync as l,existsSync as s}from"fs";import{createHash as a}from"crypto";var n="kanonak.lock";function f(e=n){return s(e)?o(c(e,"utf-8")):null}function k(e,t=n){e.lastUpdated=new Date().toISOString(),l(t,r(e),"utf-8")}function L(e){let t=a("sha256").update(e).digest("hex");return`${i}${t}`}export{f as a,k as b,L as c};
@@ -1 +1 @@
1
- import{a as d}from"./chunk-F67UH4FD.js";import{a as l,b as h}from"./chunk-GGK6A6QK.js";import*as c from"js-yaml";var y=new Set(["Package","EphemeralPackage"]);function f(m){return typeof m=="string"&&y.has(m)}var g=class{parse(e){let r=this.parseWithErrors(e);if(!r.isValid){let n=r.errors[0];throw new Error(`YAML parse error at line ${n.line}, column ${n.column}: ${n.message}`)}return r.document}parseWithErrors(e){let r=[],n;try{e=e.replace(/^\uFEFF/,"");let a=c.load(e,{schema:c.FAILSAFE_SCHEMA});if(!a||typeof a!="object")return n={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:n,errors:r,isValid:!0};let t=this.extractMetadata(a),o=this.extractBody(a,t);return n={metadata:t,body:o,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:n,errors:r,isValid:!0}}catch(a){let t=a,o=t.mark?t.mark.line+1:0,i=t.mark?t.mark.column+1:0,s={message:t.message||"Unknown parse error",line:o,column:i,errorType:t.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${t.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${o}: ${t.message||"Unknown parse error"}`};return r.push(s),{document:void 0,errors:r,isValid:!1}}}save(e){let r={};if(e.metadata.namespace_){let n=e.metadata.namespace_,a={type:"Package",publisher:n.publisher};n.version&&(a.version=`${n.version.major}.${n.version.minor}.${n.version.patch}`),e.metadata.imports&&(a.imports=this.serializeImports(e.metadata.imports)),r[n.package_]=a}return Object.assign(r,e.body),c.dump(r,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let r=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!r)return[];let n=[];for(let a of Object.values(r))n.push(...a);return n},enumerable:!0,configurable:!0}),e}createVersion(e,r,n){return{major:e,minor:r,patch:n,toString:()=>`${e}.${r}.${n}`,equals:t=>!t||typeof t!="object"?!1:t.major===e&&t.minor===r&&t.patch===n,getHashCode:()=>e<<20|r<<10|n,compareTo:t=>e!==t.major?e-t.major:r!==t.minor?r-t.minor:n-t.patch}}extractMetadata(e){let r=this.createEmptyMetadata();for(let[n,a]of Object.entries(e))if(a&&typeof a=="object"&&f(a.type)){r.type_=a.type;let t=n,o=a.publisher,i=a.version?this.parseVersion(a.version):void 0;return o&&t&&(r.namespace_={publisher:o,package_:t,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:s=>!s||typeof s!="object"?!1:s.publisher===o&&s.package_===t&&(!i||!s.version||i.equals(s.version)),getHashCode:()=>{let s=0;for(let p=0;p<o.length;p++)s=(s<<5)-s+o.charCodeAt(p);for(let p=0;p<t.length;p++)s=(s<<5)-s+t.charCodeAt(p);return s|0}}),a.imports&&Array.isArray(a.imports)&&(r.imports=this.parseImportsV3(a.imports)),this.addAllImportsGetter(r)}return r}extractBody(e,r){let n={};for(let[a,t]of Object.entries(e))if(t&&typeof t=="object"&&f(t.type)){let o={};for(let[i,s]of Object.entries(t))i==="publisher"||i==="version"||i==="imports"||(o[i]=s);n[a]=o}else n[a]=t;return n}parseVersion(e){if(typeof e=="string"){let r=e.split(".").map(Number);return this.createVersion(r[0]||0,r[1]||0,r[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let r={};for(let n of e)if(!(!n||typeof n!="object"))if(n.packages&&Array.isArray(n.packages)){let a=n.publisher;if(!a)throw new Error("PublisherImport requires 'publisher' property");r[a]||(r[a]=[]);for(let t of n.packages){if(!t||typeof t!="object")continue;let o=this.parseImportFromEmbeddedObject(t,a);r[a].push(o)}}else{let a=this.parseImportFromEmbeddedObject(n,n.publisher),t=a.publisher||"";r[t]||(r[t]=[]),r[t].push(a)}return r}parseImportFromEmbeddedObject(e,r){let n=e.package;if(!n)throw new Error("Import requires 'package' property");let a=e.match;if(!a)throw new Error("Import requires 'match' property");let t=e.version;if(!t)throw new Error("Import requires 'version' property");let o;if(e.mode!==void 0&&e.mode!==null){if(!d.includes(e.mode))throw new Error(`Import '${n}' has an unknown mode '${e.mode}'; expected one of: ${d.join(", ")}`);o=e.mode}return this.makeImport(n,a,t,r,e.alias,o)}makeImport(e,r,n,a,t,o){let i=this.parseVersion(n),s=this.parseVersionOperator(r),p=this.calculateMaxVersion(r,i);return{package_:`${e} ${r} ${i.toString()}`,publisher:a,packageName:e,versionOperator:s,version:i,alias:t,...o?{mode:o}:{},minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let u={package:e,match:r,version:i.toString()};return t&&(u.alias=t),o&&(u.mode=o),u},toString:()=>t?`${e} ${r} ${i.toString()} as ${t}`:`${e} ${r} ${i.toString()}`}}buildImport(e,r,n,a){return this.makeImport(e,r,n,a)}parseVersionOperator(e){return l(e)}calculateMaxVersion(e,r){switch(e){case"~":return this.createVersion(r.major,r.minor+1,0);case"^":return r.major===0?this.createVersion(0,r.minor+1,0):this.createVersion(r.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let r=[];for(let[n,a]of Object.entries(e)){let t={publisher:n,packages:a.map(o=>{let i=h(o.versionOperator),s={package:o.packageName,match:i,version:`${o.version.major}.${o.version.minor}.${o.version.patch}`};return o.alias&&(s.alias=o.alias),s})};r.push(t)}return r}};export{g as a};
1
+ import{a as d}from"./chunk-F67UH4FD.js";import{a as l,b as h}from"./chunk-7IMLHHSA.js";import*as c from"js-yaml";var y=new Set(["Package","EphemeralPackage"]);function f(m){return typeof m=="string"&&y.has(m)}var g=class{parse(e){let r=this.parseWithErrors(e);if(!r.isValid){let n=r.errors[0];throw new Error(`YAML parse error at line ${n.line}, column ${n.column}: ${n.message}`)}return r.document}parseWithErrors(e){let r=[],n;try{e=e.replace(/^\uFEFF/,"");let a=c.load(e,{schema:c.FAILSAFE_SCHEMA});if(!a||typeof a!="object")return n={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:n,errors:r,isValid:!0};let t=this.extractMetadata(a),o=this.extractBody(a,t);return n={metadata:t,body:o,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:n,errors:r,isValid:!0}}catch(a){let t=a,o=t.mark?t.mark.line+1:0,i=t.mark?t.mark.column+1:0,s={message:t.message||"Unknown parse error",line:o,column:i,errorType:t.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${t.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${o}: ${t.message||"Unknown parse error"}`};return r.push(s),{document:void 0,errors:r,isValid:!1}}}save(e){let r={};if(e.metadata.namespace_){let n=e.metadata.namespace_,a={type:"Package",publisher:n.publisher};n.version&&(a.version=`${n.version.major}.${n.version.minor}.${n.version.patch}`),e.metadata.imports&&(a.imports=this.serializeImports(e.metadata.imports)),r[n.package_]=a}return Object.assign(r,e.body),c.dump(r,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let r=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!r)return[];let n=[];for(let a of Object.values(r))n.push(...a);return n},enumerable:!0,configurable:!0}),e}createVersion(e,r,n){return{major:e,minor:r,patch:n,toString:()=>`${e}.${r}.${n}`,equals:t=>!t||typeof t!="object"?!1:t.major===e&&t.minor===r&&t.patch===n,getHashCode:()=>e<<20|r<<10|n,compareTo:t=>e!==t.major?e-t.major:r!==t.minor?r-t.minor:n-t.patch}}extractMetadata(e){let r=this.createEmptyMetadata();for(let[n,a]of Object.entries(e))if(a&&typeof a=="object"&&f(a.type)){r.type_=a.type;let t=n,o=a.publisher,i=a.version?this.parseVersion(a.version):void 0;return o&&t&&(r.namespace_={publisher:o,package_:t,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:s=>!s||typeof s!="object"?!1:s.publisher===o&&s.package_===t&&(!i||!s.version||i.equals(s.version)),getHashCode:()=>{let s=0;for(let p=0;p<o.length;p++)s=(s<<5)-s+o.charCodeAt(p);for(let p=0;p<t.length;p++)s=(s<<5)-s+t.charCodeAt(p);return s|0}}),a.imports&&Array.isArray(a.imports)&&(r.imports=this.parseImportsV3(a.imports)),this.addAllImportsGetter(r)}return r}extractBody(e,r){let n={};for(let[a,t]of Object.entries(e))if(t&&typeof t=="object"&&f(t.type)){let o={};for(let[i,s]of Object.entries(t))i==="publisher"||i==="version"||i==="imports"||(o[i]=s);n[a]=o}else n[a]=t;return n}parseVersion(e){if(typeof e=="string"){let r=e.split(".").map(Number);return this.createVersion(r[0]||0,r[1]||0,r[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let r={};for(let n of e)if(!(!n||typeof n!="object"))if(n.packages&&Array.isArray(n.packages)){let a=n.publisher;if(!a)throw new Error("PublisherImport requires 'publisher' property");r[a]||(r[a]=[]);for(let t of n.packages){if(!t||typeof t!="object")continue;let o=this.parseImportFromEmbeddedObject(t,a);r[a].push(o)}}else{let a=this.parseImportFromEmbeddedObject(n,n.publisher),t=a.publisher||"";r[t]||(r[t]=[]),r[t].push(a)}return r}parseImportFromEmbeddedObject(e,r){let n=e.package;if(!n)throw new Error("Import requires 'package' property");let a=e.match;if(!a)throw new Error("Import requires 'match' property");let t=e.version;if(!t)throw new Error("Import requires 'version' property");let o;if(e.mode!==void 0&&e.mode!==null){if(!d.includes(e.mode))throw new Error(`Import '${n}' has an unknown mode '${e.mode}'; expected one of: ${d.join(", ")}`);o=e.mode}return this.makeImport(n,a,t,r,e.alias,o)}makeImport(e,r,n,a,t,o){let i=this.parseVersion(n),s=this.parseVersionOperator(r),p=this.calculateMaxVersion(r,i);return{package_:`${e} ${r} ${i.toString()}`,publisher:a,packageName:e,versionOperator:s,version:i,alias:t,...o?{mode:o}:{},minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let u={package:e,match:r,version:i.toString()};return t&&(u.alias=t),o&&(u.mode=o),u},toString:()=>t?`${e} ${r} ${i.toString()} as ${t}`:`${e} ${r} ${i.toString()}`}}buildImport(e,r,n,a){return this.makeImport(e,r,n,a)}parseVersionOperator(e){return l(e)}calculateMaxVersion(e,r){switch(e){case"~":return this.createVersion(r.major,r.minor+1,0);case"^":return r.major===0?this.createVersion(0,r.minor+1,0):this.createVersion(r.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let r=[];for(let[n,a]of Object.entries(e)){let t={publisher:n,packages:a.map(o=>{let i=h(o.versionOperator),s={package:o.packageName,match:i,version:`${o.version.major}.${o.version.minor}.${o.version.patch}`};return o.alias&&(s.alias=o.alias),s})};r.push(t)}return r}};export{g as a};
@@ -0,0 +1 @@
1
+ import{c as v,g as D,l as L,m as I}from"./chunk-7IMLHHSA.js";var u=class{};var f=class extends u{statement=[];unresolvedPredicates=[];sourceDoc="";sourceKey};var p=class extends f{namespace;name;icon};var k=class extends f{name;rangeType};var s=class e extends u{subject;sourceKey;static parse(n){let t=new e;return t.subject=L.parse(n),t}};var h=class extends u{value;carrier;lexical;links;sourceKey};var c=class{predicate;object;sourceKey};var l=class extends c{carrier;lexical};var y=class e extends l{static parse(n,t){let r=new e;return r.predicate=s.parse(n),r.object=t,r}};var K=class e extends l{static parse(n,t){let r=new e;return r.predicate=s.parse(n),r.object=t,r}};var x=class extends l{};var b=class e extends c{static parse(n,t){let r=new e;return r.predicate=s.parse(n),r.object=s.parse(t),r}};var j=class extends c{};var S=class extends c{};var U=class extends y{links=[]};function R(e){return`${e.publisher}/${e.package_}/${e.name}`}function w(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}function T(e){let n=e.version;return n&&typeof n.major=="number"?`https://${e.publisher}/${e.package_}/${n.major}.${n.minor}.${n.patch}/${e.name}`:`https://${e.publisher}/${e.package_}/${e.name}`}function B(e){return A(e,N)}var N={publisher:"kanonak.org",package_:"core-rdf",name:"type"};function A(e,n){let t=[];for(let r of $(e,n))r.item instanceof s&&t.push(r.item.subject);return t}function $(e,n){return M(e,n).flat()}function M(e,n){if(!(e instanceof f))return[];let t=[];for(let r of e.statement){let o=r.predicate;if(!(!o?.subject||!w(o.subject,n)))if(r instanceof b)t.push([{item:r.object,fromList:!1}]);else if(r instanceof j)t.push([{item:r.object,fromList:!1}]);else if(r instanceof U)t.push([{item:{literal:!0,value:r.object,carrier:r.carrier,lexical:r.lexical,links:r.links},fromList:!1}]);else if(r instanceof y||r instanceof K||r instanceof x)t.push([{item:{literal:!0,value:r.object,carrier:r.carrier,lexical:r.lexical},fromList:!1}]);else if(r instanceof S){let i=[];for(let a of r.object??[])if(a instanceof s||a instanceof k)i.push({item:a,fromList:!0});else if(a instanceof h)i.push({item:{literal:!0,value:a.value,carrier:a.carrier,lexical:a.lexical,links:a.links},fromList:!0});else throw new Error(`rawValuesOf: a list value of '${n.name}' is a ${a?.constructor?.name??typeof a}; list items are references, embedded values or literals.`);t.push(i)}else throw new Error(`rawValuesOf: '${n.name}' has a statement of unknown kind ${r?.constructor?.name??typeof r}.`)}return t}function O(e,n){if(!(e instanceof f))return!1;for(let t of e.statement)if(t.predicate?.subject?.name==="type"&&t instanceof b){let o=t.object;if(w(o.subject,n))return!0}return!1}function H(e,n){let t=[];for(let r of e)r instanceof p&&O(r,n)&&t.push(r);return t}function W(e,n){let t=n.version,r=t&&typeof t.major=="number"?`${n.publisher}/${n.package_}@${t.major}.${t.minor}.${t.patch}`:void 0;for(let o of e){if(!(o instanceof p)||o.name!==n.name)continue;let i=o.namespace||"";if(r!==void 0){if(i===r)return o}else if(i.startsWith(`${n.publisher}/${n.package_}@`))return o}}function F(e,n){let t=[];for(let r of e){if(!(r instanceof p)||r.name!==n.name)continue;(r.namespace||"").startsWith(`${n.publisher}/${n.package_}@`)&&t.push(r)}return t.sort((r,o)=>{let i=D((r.namespace||"").split("@")[1]??""),a=D((o.namespace||"").split("@")[1]??"");return i?a?v(a,i):-1:a?1:0}),t}function g(e,n){for(let t of e.statement){let r=t.predicate;if(r?.subject&&w(r.subject,n))return t}}function Y(e,n){return g(e,n)!==void 0}function _(e,n){let t=g(e,n);if(t&&(t instanceof y||t instanceof K||t instanceof x))return t.object}function q(e,n){let t=_(e,n);return typeof t=="string"?t:void 0}function z(e,n){let t=g(e,n);if(t instanceof b)return t.object.subject}function G(e,n){let t=g(e,n);if(t instanceof j)return t.object}function J(e,n){let t=g(e,n);return t instanceof S?t.object??[]:[]}function Q(e,n,t,r){let o=Z(e,n,r);if(o.length===0)return[];let i=ee(t);return o.map(({value:a,address:m})=>{let d=a.fromList;if(a.item instanceof s){let P=i.resolve(a.item.subject);return P?{kind:"subject",node:P,uri:a.item.subject,address:m,fromList:d}:{kind:"unresolved",uri:a.item.subject,address:m,fromList:d}}if(a.item instanceof k)return{kind:"embedded",node:a.item,address:m,fromList:d};let V={kind:"literal",value:a.item.value,carrier:a.item.carrier,lexical:a.item.lexical,address:m,fromList:d};return a.item.links&&(V.links=a.item.links),V})}function X(e){let n=I(`${e.namespace}/${e.name}`);if(n.kind!=="resource")throw new Error(`subjectAddress: '${e.namespace}/${e.name}' is not a resource address`);return R(n.uri)}function Z(e,n,t){let r=$(e,n);if(r.length===0)return[];let o=t.includes("#")?`${t}.${n.name}`:`${t}#${n.name}`,i=r.length>1||r.some(a=>a.fromList);return r.map((a,m)=>({value:a,address:a.item instanceof k&&a.item.name?`${o}.${a.item.name}`:i?`${o}[${m}]`:o}))}var C=new WeakMap;function ee(e){let n=C.get(e);if(n)return n;let t=new Map,r=new Map;for(let o of e){if(!(o instanceof p))continue;let i=o.namespace||"",a=`${i}\0${o.name}`;t.has(a)||t.set(a,o);let m=i.indexOf("@");if(m>=0){let d=`${i.slice(0,m)}\0${o.name}`;r.has(d)||r.set(d,o)}}return n={resolve(o){let i=o.version;return i&&typeof i.major=="number"?t.get(`${o.publisher}/${o.package_}@${i.major}.${i.minor}.${i.patch}\0${o.name}`):r.get(`${o.publisher}/${o.package_}\0${o.name}`)}},C.set(e,n),n}var E=class{constructor(n,t){this.doc=n;this.broader=t}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(n){return this.broader.getDocumentAsync(n)}async getDocumentsByNamespaceAsync(n,t){return this.broader.getDocumentsByNamespaceAsync(n,t)}async getHighestCompatibleVersionAsync(n,t){return this.broader.getHighestCompatibleVersionAsync(n,t)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(n){return this.broader.getDocumentContentAsync(n)}async getDocumentUriAsync(n){return this.broader.getDocumentUriAsync(n)}};export{u as a,f as b,p as c,k as d,s as e,h as f,c as g,l as h,y as i,K as j,x as k,b as l,j as m,S as n,U as o,R as p,w as q,T as r,B as s,A as t,$ as u,M as v,O as w,H as x,W as y,F as z,g as A,Y as B,_ as C,q as D,z as E,G as F,J as G,Q as H,X as I,Z as J,E as K};
@@ -0,0 +1 @@
1
+ import{VersionOperator as a}from"@kanonak-protocol/types/document/models/enums";function y(e){switch(e){case"=":return a.Exact;case"~":return a.Compatible;case"^":return a.Major;case"*":return a.Any;default:return a.Compatible}}function w(e){switch(e){case a.Exact:return"=";case a.Compatible:return"~";case a.Major:return"^";case a.Any:return"*";default:return"~"}}function c(e,r){return e.major!==r.major?e.major-r.major:e.minor!==r.minor?e.minor-r.minor:e.patch-r.patch}function g(e,r){return e.major===r.major&&e.minor===r.minor&&e.patch===r.patch}function h(e){return`${e.major}.${e.minor}.${e.patch}`}function k(e,r,t){let n=`${e}.${r}.${t}`;return{major:e,minor:r,patch:t,toString:()=>n,equals:s=>s?.major===e&&s?.minor===r&&s?.patch===t,getHashCode:()=>e<<20|r<<10|t,compareTo:s=>e!==s.major?e-s.major:r!==s.minor?r-s.minor:t-s.patch}}function K(e){let r=/^(\d+)\.(\d+)\.(\d+)$/.exec(e);return r?k(Number(r[1]),Number(r[2]),Number(r[3])):null}function b(e,r){return c(e,r)>=0&&e.major===r.major&&e.minor===r.minor}function v(e,r){return r.major===0?c(e,r)>=0&&e.major===0&&e.minor===r.minor:c(e,r)>=0&&e.major===r.major}function E(e,r){switch(r.versionOperator){case a.Exact:return g(e,r.version);case a.Compatible:return b(e,r.version);case a.Major:return v(e,r.version);case a.Any:return c(e,r.minVersion)>=0;default:return!1}}function I(e,r={}){let{requestedVersion:t}=r;if(e.length===0)return{chosen:null,alternatives:[],multipleVersionsPresent:!1,exactRequestedVersionMissing:!!t};if(t){let s=e.find(i=>{let o=i.metadata.namespace_?.version;return!!o&&h(o)===t});return s?{chosen:s,alternatives:e.filter(i=>i!==s),multipleVersionsPresent:e.length>1,exactRequestedVersionMissing:!1}:{chosen:null,alternatives:e,multipleVersionsPresent:e.length>1,exactRequestedVersionMissing:!0}}if(e.length===1)return{chosen:e[0],alternatives:[],multipleVersionsPresent:!1,exactRequestedVersionMissing:!1};let n=[...e].sort((s,i)=>{let o=s.metadata.namespace_?.version,u=i.metadata.namespace_?.version;return!o&&!u?0:o?u?c(u,o):-1:1});return{chosen:n[0],alternatives:n.slice(1),multipleVersionsPresent:!0,exactRequestedVersionMissing:!1}}var p=class e{constructor(r,t,n,s){this.publisher=r;this.package_=t;this.name=n;this.version=s}publisher;package_;name;version;static parse(r){if(!r||r.trim().length===0)throw new Error("Kanonak URI string cannot be null or empty");let t=r.split("/");if(t.length!==3)throw new Error(`Invalid Kanonak URI: ${r}. Expected format: publisher/package[@version]/name`);let[n,s,i]=t;if(!n||!s||!i)throw new Error(`Invalid Kanonak URI: ${r}. Expected format: publisher/package[@version]/name`);let o=s.indexOf("@");if(o===-1)return new e(n,s,i,void 0);let u=s.substring(0,o),l=s.substring(o+1);if(!u||!l)throw new Error(`Invalid Kanonak URI: ${r}. Expected format: publisher/package[@version]/name`);let m=l.split(".").map(Number),f=V(m[0]||0,m[1]||0,m[2]||0);return new e(n,u,i,f)}toString(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}/${this.name}`:`${this.publisher}/${this.package_}/${this.name}`}};function V(e,r,t){return{major:e,minor:r,patch:t,toString:()=>`${e}.${r}.${t}`,equals:n=>!n||typeof n!="object"?!1:n.major===e&&n.minor===r&&n.patch===t,getHashCode:()=>e<<20|r<<10|t,compareTo:n=>e!==n.major?e-n.major:r!==n.minor?r-n.minor:t-n.patch}}function R(e){if(!e||e.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let r=e.trim(),t=r.split("/");if(t.length===1){let n=t[0];if(!n)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(n.includes("@"))throw new Error(`Invalid Kanonak address: "${e}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:n}}if(t.length===2){let[n,s]=t;if(!n||!s)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher/package[@version].`);let i=s.indexOf("@");if(i===-1)return{kind:"package",publisher:n,package_:s};let o=s.substring(0,i),u=s.substring(i+1);if(!o||!u)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher/package[@version].`);let l=d(u);return{kind:"package",publisher:n,package_:o,version:l}}return{kind:"resource",uri:p.parse(r)}}function A(e){switch(e.kind){case"publisher":return e.publisher;case"package":return e.version?`${e.publisher}/${e.package_}@${e.version.major}.${e.version.minor}.${e.version.patch}`:`${e.publisher}/${e.package_}`;case"resource":return e.uri.toString()}}function d(e){let r=e.split(".").map(Number);return $(r[0]||0,r[1]||0,r[2]||0)}function $(e,r,t){return{major:e,minor:r,patch:t,toString:()=>`${e}.${r}.${t}`,equals:n=>!n||typeof n!="object"?!1:n.major===e&&n.minor===r&&n.patch===t,getHashCode:()=>e<<20|r<<10|t,compareTo:n=>e!==n.major?e-n.major:r!==n.minor?r-n.minor:t-n.patch}}export{y as a,w as b,c,g as d,h as e,k as f,K as g,b as h,v as i,E as j,I as k,p as l,R as m,A as n};
@@ -1,4 +1,4 @@
1
- import{a as dt}from"./chunk-WXXZOJ4O.js";import{e as he,f as u,k as Sn}from"./chunk-SBWD7EOG.js";import{a as ft}from"./chunk-5ZRVFYCP.js";import{a as $t}from"./chunk-PEJALHXK.js";import{$ as bt,_ as ht,oa as tn,pa as we,qa as an,ra as $n,va as vt}from"./chunk-6WOPXTIL.js";import{A as gt,B as un,C as Xe,D as xe,E as Oe,F as kt,G as Mn,H as vn,K as yt,b as Ue,c as Y,d as D,e as U,i as ae,j as be,k as ke,l as Q,m as le,n as ue,o as De,p as B,q as re,r as pt,s as mt,t as je,u as Ee,w as _,y as Te,z as oe}from"./chunk-LK5SHY4B.js";import{c as hn,d as lt,e as bn,g as ut}from"./chunk-GGK6A6QK.js";import{a as yn}from"./chunk-FUUTGGJS.js";import{ExpressionError as Oa,evaluates as Ia,validateMatchesPattern as Fa}from"@kanonak-protocol/expression";var q=class extends Error{constructor(n,t){super(`${n} (at ${t})`);this.path=t}path};function bi(r,e){let n=r.name,t=Ja(e),a={catalog:e,depth:0};if(_(r,u.InstanceTransformation))return Ta(r,n,a,t);if(_(r,u.SetTransformation))return Pa(r,n,a,t);throw new q("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function Ta(r,e,n,t){return{kind:"instance",name:r.name,inputPattern:Et(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:xt(r,`${e}.outputs`),overrides:Lt(r,`${e}.formatOverrides`,n),fragments:t}}function Pa(r,e,n,t){let a=Pe(r,u.partitionBy);return{kind:"set",name:r.name,inputPattern:Et(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:xt(r,`${e}.outputs`),overrides:Lt(r,`${e}.formatOverrides`,n),partitionBy:a,fragments:t}}function Et(r,e){let n=Ct(r,u.inputPattern);if(!n)throw new q("inputPattern is required",e);return Va(n,`${e}.inputPattern`)}function Va(r,e){let n=Pe(r,u.matchesClass);if(!n)throw new q("matchesClass is required",e);let t=[];for(let o of Le(r,u.requires))if(o instanceof Q)t.push(Hn(o.object.subject));else if(o instanceof ue)for(let i of o.object)i instanceof U&&t.push(Hn(i.subject));let a=[],s=0;for(let o of Le(r,u.sortBy))if(o instanceof ue)for(let i of o.object)i instanceof D&&a.push(St(i,`${e}.sortBy[${s++}]`));else o instanceof le&&a.push(St(o.object,`${e}.sortBy[${s++}]`));return{matchesClass:n,requires:t,sortBy:a}}function St(r,e){let n=Pe(r,u.byProperty);if(!n)throw new q("SortKey.byProperty is required",e);let t=Pe(r,u.order);if(!t)throw new q("SortKey.order is required",e);if(re(t,u.ascending))return{byProperty:n,order:"ascending"};if(re(t,u.descending))return{byProperty:n,order:"descending"};throw new q(`SortKey.order must reference tx.ascending or tx.descending; got ${t.publisher}/${t.package_}/${t.name}`,e)}function wn(r,e,n,t){let a=Gn(r,e,n,t);if(!a)throw new q("expression is required",n);return qe(a,n,t)}function qn(r,e,n,t){return Ee(r,e).map((a,s,o)=>{let i=o.length>1||a.fromList?`${n}[${s}]`:n;if(a.item instanceof D)return a.item;if(a.item instanceof U){let c=Te(t.catalog,a.item.subject);if(!c)throw new q(`references '${B(a.item.subject)}', which does not resolve in the catalog`,i);return c}throw new q(`expects a node, not the literal ${JSON.stringify(a.item.value)}`,i)})}function Gn(r,e,n,t){let a=qn(r,e,n,t);if(a.length>1)throw new q(`expects one expression, has ${a.length}`,n);return a[0]}function qe(r,e,n){if(r instanceof Y){let t=we(r),a=t?B(t):`${r.namespace}/${r.name}`,s=n.visiting??new Set;if(s.has(a))throw new q(`named expressions form a cycle: ${[...s,a].join(" -> ")}`,e);return wt(r,a,{...n,visiting:new Set([...s,a])})}return wt(r,e,n)}function wt(r,e,n){if(_(r,u.StringLiteral))return{kind:"string-literal",value:ye(r,u.stringLiteral,e)};if(_(r,u.IntegerLiteral))return{kind:"integer-literal",value:Rt(r,u.integerLiteral,e)};if(_(r,u.DecimalLiteral))return{kind:"decimal-literal",value:Rt(r,u.decimalLiteral,e)};if(_(r,u.BooleanLiteral))return{kind:"boolean-literal",value:er(r,u.booleanLiteral,e)};if(_(r,u.VarRef))return{kind:"var-ref",varName:ye(r,u.varName,e)};if(_(r,u.PropertyRead))return{kind:"property-read",source:w(r,u.readSource,`${e}.readSource`,n),readProp:Be(r,u.readProp,e,"readProp")};if(_(r,u.Traverse))return{kind:"traverse",source:w(r,u.traverseSource,`${e}.traverseSource`,n),through:Be(r,u.through,e,"through"),step:w(r,u.step,`${e}.step`,n)};if(_(r,u.BuildAstNode))return{kind:"build-ast-node",astClass:Be(r,u.astClass,e,"astClass"),set:Ba(r,`${e}.set`,n)};if(_(r,u.When))return{kind:"when",condition:w(r,u.condition,`${e}.condition`,n),thenBuild:w(r,u.thenBuild,`${e}.thenBuild`,n),elseBuild:Da(r,u.elseBuild,`${e}.elseBuild`,n)};if(_(r,u.Concat))return{kind:"concat",parts:Nn(r,u.parts,`${e}.parts`,n)};if(_(r,u.Fallback))return{kind:"fallback",primary:w(r,u.primary,`${e}.primary`,n),alternate:w(r,u.alternate,`${e}.alternate`,n)};if(_(r,u.UriName))return{kind:"uri-name",source:w(r,u.uriNameOf,`${e}.uriNameOf`,n)};if(_(r,u.UriPublisher))return{kind:"uri-publisher",source:w(r,u.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(_(r,u.UriPackage))return{kind:"uri-package",source:w(r,u.uriPackageOf,`${e}.uriPackageOf`,n)};if(_(r,u.UriVersion))return{kind:"uri-version",source:w(r,u.uriVersionOf,`${e}.uriVersionOf`,n)};if(_(r,u.SubjectUri))return{kind:"subject-uri",source:w(r,u.subjectOf,`${e}.subjectOf`,n)};if(_(r,u.UriLiteral))return{kind:"uri-literal",refTo:Be(r,u.refTo,e,"refTo")};if(_(r,u.DisplayLabel))return{kind:"display-label",labelTarget:Be(r,u.labelTarget,e,"labelTarget"),labelSource:Be(r,u.labelSource,e,"labelSource")};if(_(r,u.ResolveRef))return{kind:"resolve-ref",source:w(r,u.resolveSource,`${e}.resolveSource`,n)};if(_(r,u.Normalize))return{kind:"normalize",source:w(r,u.normSource,`${e}.normSource`,n),normKind:qa(r,e)};if(_(r,u.UnescapedString))return{kind:"unescaped-string",source:w(r,u.unescapedSource,`${e}.unescapedSource`,n)};if(_(r,u.RenderMarkdown))return{kind:"render-markdown",source:w(r,u.renderSource,`${e}.renderSource`,n),readProp:Be(r,u.renderProp,e,"renderProp"),format:Ga(r,e)};if(_(r,u.IsSet))return{kind:"is-set",check:w(r,u.checkExpr,`${e}.checkExpr`,n)};if(_(r,u.CallFragment))return Ya(r,e,n);if(_(r,u.Join))return{kind:"join",source:w(r,u.source,`${e}.source`,n),separator:ye(r,u.separator,e)};if(_(r,u.Count))return{kind:"count",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Sum))return{kind:"sum",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Min))return{kind:"min",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Max))return{kind:"max",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Average))return{kind:"average",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.ForEach))return{kind:"for-each",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),emit:w(r,u.emit,`${e}.emit`,n)};if(_(r,u.ListMap))return{kind:"list-map",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),mapBody:w(r,u.mapBody,`${e}.mapBody`,n)};if(_(r,u.Filter))return{kind:"filter",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),predicate:w(r,u.predicate,`${e}.predicate`,n)};if(_(r,u.PartitionBy))return{kind:"partition-by",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),partitionKey:w(r,u.partitionKey,`${e}.partitionKey`,n)};if(_(r,u.DistinctBy))return{kind:"distinct-by",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),distinctKey:w(r,u.distinctKey,`${e}.distinctKey`,n)};if(_(r,u.AllStatements))return{kind:"all-statements",source:w(r,u.statementsOf,`${e}.statementsOf`,n)};if(_(r,u.StatementPredicate))return{kind:"statement-predicate",source:w(r,u.predicateOf,`${e}.predicateOf`,n)};if(_(r,u.StatementValue))return{kind:"statement-value",source:w(r,u.valueOf,`${e}.valueOf`,n)};if(_(r,u.DateFormat))return{kind:"date-format",source:w(r,u.dateSource,`${e}.dateSource`,n),format:Wa(r,e)};if(_(r,u.NumberFormat)){let a=Dn(r,u.fractionDigits);if(a!==void 0&&(!Number.isInteger(a)||a<0||a>20))throw new q(`fractionDigits must be an integer between 0 and 20; got ${a}`,e);let s=He(r,u.currencyCode);return{kind:"number-format",source:w(r,u.numberSource,`${e}.numberSource`,n),style:za(r,e),...a!==void 0?{fractionDigits:a}:{},...s!==void 0?{currencyCode:s}:{}}}let t=Na.find(a=>_(r,a.type));if(t){let a=B(t.type);if(!Ia(a))throw new q(`${a} is a numeric operator the expression runtime does not evaluate`,e);return{kind:"numeric-op",type:a,name:t.type.name,operands:t.operands.map(s=>({name:s.name,expr:w(r,s,`${e}.${s.name}`,n)}))}}if(_(r,u.Reverse))return{kind:"reverse",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.WindowedMap)){let a=Dn(r,u.windowSize);if(a===void 0||!Number.isInteger(a)||a<1)throw new q("windowSize must be a positive integer",`${e}.windowSize`);return{kind:"windowed-map",source:w(r,u.source,`${e}.source`,n),windowSize:a,windowVar:ye(r,u.windowVar,e),windowBody:w(r,u.windowBody,`${e}.windowBody`,n)}}if(_(r,u.PairwiseMap))return{kind:"pairwise-map",source:w(r,u.source,`${e}.source`,n),firstVar:ye(r,u.firstVar,e),secondVar:ye(r,u.secondVar,e),pairBody:w(r,u.pairBody,`${e}.pairBody`,n)};if(_(r,u.Scan))return{kind:"scan",source:w(r,u.source,`${e}.source`,n),initialState:w(r,u.initialState,`${e}.initialState`,n),stateVar:ye(r,u.stateVar,e),elementVar:ye(r,u.elementVar,e),accumulate:w(r,u.accumulate,`${e}.accumulate`,n)};if(_(r,u.ListItemAt))return{kind:"list-item-at",source:w(r,u.source,`${e}.source`,n),itemIndex:w(r,u.itemIndex,`${e}.itemIndex`,n)};if(_(r,u.Equals))return{kind:"equals",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.GreaterThan))return{kind:"greater-than",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.LessThan))return{kind:"less-than",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.LessThanOrEqual))return{kind:"less-than-or-equal",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.Not))return{kind:"not",operand:w(r,u.operand,`${e}.operand`,n)};if(_(r,u.And))return{kind:"and",operands:Nn(r,u.operands,`${e}.operands`,n)};if(_(r,u.Or))return{kind:"or",operands:Nn(r,u.operands,`${e}.operands`,n)};if(_(r,u.Contains))return{kind:"contains",haystack:w(r,u.haystack,`${e}.haystack`,n),needle:w(r,u.needle,`${e}.needle`,n)};if(_(r,u.Matches)){let a=ye(r,u.pattern,e);try{Fa(a)}catch(s){throw s instanceof Oa?new q(s.message,`${e}.pattern`):s}return{kind:"matches",source:w(r,u.matchSource,`${e}.matchSource`,n),pattern:a}}if(_(r,u.IsReference))return{kind:"is-reference",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsEmbedded))return{kind:"is-embedded",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsList))return{kind:"is-list",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsString))return{kind:"is-string",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsNumber))return{kind:"is-number",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsBoolean))return{kind:"is-boolean",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.StatementObject))return{kind:"statement-object",source:w(r,u.statementSource,`${e}.statementSource`,n)};if(_(r,u.Let))return{kind:"let",bindName:ye(r,u.letName,e),bindValue:w(r,u.letValue,`${e}.letValue`,n),body:w(r,u.letBody,`${e}.letBody`,n)};if(_(r,u.GetStatementByName))return{kind:"get-statement-by-name",inSubject:w(r,u.inSubject,`${e}.inSubject`,n),byName:w(r,u.byName,`${e}.byName`,n)};throw new q("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}var Aa=[u.arithLeft,u.arithRight],Ma=[u.value],Na=[...[u.Add,u.Subtract,u.Multiply,u.Divide,he.Power,he.Modulo,he.Minimum,he.Maximum].map(r=>({type:r,operands:Aa})),...[u.Abs,u.Negate,he.Exp,he.Ln,he.Log10,he.Sqrt,he.Floor,he.Ceil,he.Round,he.Sign].map(r=>({type:r,operands:Ma})),{type:he.Clip,operands:[he.clipValue,he.clipLower,he.clipUpper]}];function w(r,e,n,t){let a=Gn(r,e,n,t);if(!a)throw new q("child expression is required",n);return qe(a,n,t)}function Da(r,e,n,t){let a=Gn(r,e,n,t);if(a)return qe(a,n,t)}function Nn(r,e,n,t){return qn(r,e,n,t).map((a,s)=>qe(a,`${n}[${s}]`,t))}function Ba(r,e,n){return qn(r,u.set,e,n).map((t,a)=>Ha(t,`${e}[${a}]`,n))}function Ha(r,e,n){return{field:Be(r,u.field,e,"field"),value:w(r,u.bindValue,`${e}.bindValue`,n)}}function qa(r,e){let n=Pe(r,u.normKind);if(!n)throw new q("normKind is required",e);if(re(n,u.NORM_TRIM_END))return"trim-end";if(re(n,u.NORM_TO_UPPER))return"to-upper";if(re(n,u.NORM_TO_LOWER))return"to-lower";if(re(n,u.NORM_FIRST_CHAR))return"first-char";throw new q(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function Ga(r,e){let n=Pe(r,u.renderFormat);if(!n)throw new q("renderFormat is required",e);if(re(n,u.RENDER_HTML))return"html";if(re(n,u.RENDER_MARKDOWN))return"markdown";throw new q(`Unknown RenderFormat: ${n.publisher}/${n.package_}/${n.name}`,e)}var _t=new Set(["decimal","percent","basis-points","currency","compact"]);function za(r,e){let n=He(r,u.numberStyle);if(n===void 0)throw new q("numberStyle is required",e);if(!_t.has(n))throw new q(`Unknown numberStyle "${n}"; supported: ${[..._t].join(", ")}`,e);return n}var jt=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function Wa(r,e){let n=He(r,u.dateFormat);if(!n)throw new q("dateFormat is required",e);if(!jt.has(n))throw new q(`Unknown dateFormat "${n}"; supported: ${[...jt].join(", ")}`,e);return n}function Ya(r,e,n){let t=Pe(r,u.fragmentRef);if(!t)throw new q("fragmentRef is required",e);if(!Qa(n.catalog,t))throw new q(`ExpressionFragment not found: ${t.publisher}/${t.package_}/${t.name}`,e);return{kind:"call-fragment",fragmentKey:Xa(t)}}function Xa(r){return`${r.publisher}/${r.package_}/${r.name}`}function Ja(r){let e=new Map,n=[];for(let t of r){if(!(t instanceof Y)||!_(t,u.ExpressionFragment))continue;let a=Ct(t,u.body);if(!a)continue;let s=(t.namespace||"").split("@")[0]||"",o=s.indexOf("/");if(o<0)continue;let i=s.substring(0,o),c=s.substring(o+1),l=`${i}/${c}/${t.name}`;n.push({key:l,subject:t,bodyEmb:a,pubPkgName:`${s}/${t.name}`})}for(let t of n){let a=qe(t.bodyEmb,`fragment(${t.pubPkgName})`,{catalog:r,depth:0});e.set(t.key,a)}return e}function Qa(r,e){for(let n of r)if(!(!(n instanceof Y)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&_(n,u.ExpressionFragment))return n}function xt(r,e){let n=new Set;for(let t of Le(r,u.outputs))if(t instanceof Q)n.add(t.object.subject.name);else if(t instanceof ue)for(let a of t.object)a instanceof U&&n.add(a.subject.name);if(n.size===0)throw new q("outputs is required (at least one OutputFormat)",e);return n}function Lt(r,e,n){let t=new Map,a=0;for(let s of Le(r,u.formatOverrides))if(s instanceof ue){for(let o of s.object)if(o instanceof D){let[i,c]=Kt(o,`${e}[${a++}]`);t.set(i,c)}}else if(s instanceof le){let[o,i]=Kt(s.object,`${e}[${a++}]`);t.set(o,i)}return t}function Kt(r,e){let n=Pe(r,u.formatTarget);if(!n)throw new q("formatTarget is required",e);let t=[];for(let i of Le(r,u.metadataKeys))if(i instanceof ae)t.push(i.object);else if(i instanceof ue)for(let c of i.object){let l=c.value;typeof l=="string"&&t.push(l)}let a=new Map;for(let i of Le(r,u.metadataRenames))if(i instanceof ue){for(let c of i.object)if(c instanceof D){let l=He(c,u.fromKey),d=He(c,u.toKey);l&&d&&a.set(l,d)}}else if(i instanceof le){let c=i.object,l=He(c,u.fromKey),d=He(c,u.toKey);l&&d&&a.set(l,d)}let s=Bn(r,u.trailingNewline),o=Bn(r,u.omitWrapper);return[n.name,{metadataKeys:t.length>0?t:void 0,metadataRenames:a,trailingNewline:s,omitWrapper:o}]}function Za(r){return r.predicate?.subject}function Le(r,e){let n=[];for(let t of r.statement){let a=Za(t);a&&re(a,e)&&n.push(t)}return n}function Ct(r,e){for(let n of Le(r,e))if(n instanceof le)return n.object}function Pe(r,e){for(let n of Le(r,e))if(n instanceof Q)return Hn(n.object.subject)}function He(r,e){for(let n of Le(r,e))if(n instanceof ae)return n.object}function Dn(r,e){for(let n of Le(r,e))if(n instanceof be)return n.object}function Bn(r,e){for(let n of Le(r,e))if(n instanceof ke)return n.object}function ye(r,e,n){let t=He(r,e);if(t===void 0)throw new q(`${e.name} (string) is required`,n);return t}function Rt(r,e,n){let t=Dn(r,e);if(t===void 0)throw new q(`${e.name} (number) is required`,n);return t}function er(r,e,n){let t=Bn(r,e);if(t===void 0)throw new q(`${e.name} (boolean) is required`,n);return t}function Be(r,e,n,t){let a=Pe(r,e);if(!a)throw new q(`${t} (URI reference) is required`,n);return a}function Hn(r){return{publisher:r.publisher,package_:r.package_,name:r.name}}var Je="kanonak.org",Tt="look",dn="core-rdf",Pt={publisher:Je,package_:Tt,name:"displayLabel"},Vt={publisher:Je,package_:Tt,name:"displaySummary"},nr={publisher:Je,package_:dn,name:"subClassOf"},tr={publisher:Je,package_:dn,name:"label"},ar={publisher:Je,package_:dn,name:"comment"},Ut=new yn(Je,dn,"Resource"),rr=8;function G(r,e){return At(r,e,new Set)}function At(r,e,n){let t=Ft(r,e,Pt)??tr,a=Ft(r,e,Vt)??ar,s=Ot(r,e,t,n)??e.name,o=Ot(r,e,a,n);return{label:s,summary:o}}function Ot(r,e,n,t){for(let a of e.statement){let s=a.predicate;if(!(!s?.subject||!re(s.subject,n))){if(a instanceof ae)return a.object;if(a instanceof be||a instanceof ke)return String(a.object);if(a instanceof Q)return It(r,a.object.subject,t);if(a instanceof ue){let o=[];for(let i of a.object??[])if(i instanceof U){let c=It(r,i.subject,t);c&&o.push(c)}if(o.length>0)return o.join(", ")}return}}}function It(r,e,n){let t=B(e);if(n.has(t)||n.size>=rr)return e.name;let[a]=oe(r,e);if(!a)return e.name;let s=new Set(n);return s.add(t),At(r,a,s).label}function Ft(r,e,n){let t=Oe(e,n);if(t)return t;let a=new Set,s=je(e,sr);for(;s.length>0;){let o=s.shift(),i=B(o);if(a.has(i))continue;a.add(i);let c=oe(r,o);for(let l of c){let d=Oe(l,n);if(d)return d}for(let l of c)s.push(...je(l,nr))}if(!a.has(B(Ut)))for(let o of oe(r,Ut)){let i=Oe(o,n);if(i)return i}}var sr={publisher:Je,package_:dn,name:"type"};var or="kanonak.org",Qe=(r,e)=>({publisher:or,package_:r,name:e}),ir=Qe("look","source"),Mt=Qe("look","connectors"),cr=Qe("look","relation"),lr=Qe("look","lineStyle"),ur=Qe("look","participants"),dr=Qe("core-owl","SymmetricProperty"),fr=Qe("core-owl","inverseOf"),Nt=new Set(["solid","dotted","open","thick"]);function Dt(r){return Oe(r,ir)}function Bt(r,e){let n=kt(e,Mt),t=n?[n]:Mn(e,Mt),a=[];for(let s of t){if(!(s instanceof D))continue;let o=Oe(s,cr);if(!o)continue;let i=xe(s,lr),c=i!==void 0&&Nt.has(i);a.push({relation:o,subject:oe(r,o)[0],declaredStyle:c?i:void 0,invalidStyle:i!==void 0&&!c?i:void 0})}return a}function Ht(r,e){let n=[];for(let t of Mn(e,ur)){if(!(t instanceof U))continue;let a=oe(r,t.subject)[0];a&&n.push(a)}return n}function fn(r,e,n){for(let t of mt(e))if(re(t,n)||an(r,t).some(a=>re(a,n)))return!0;return!1}function qt(r,e,n){let t=!!e.subject&&fn(r,e.subject,dr);return e.declaredStyle?{style:e.declaredStyle,undirected:t}:e.subject&&je(e.subject,fr).some(s=>n.some(o=>re(s,o.relation)))?{style:"dotted",undirected:t}:{style:"solid",undirected:t}}function zn(r,e,n){let t=Dt(n);if(!t)return _n("the band declares no look.source");let a=Bt(r,n);if(a.length===0)return _n("the band declares no look.connectors \u2014 nothing can be a message");let s=gt(e,t);if(!s)return{..._n(),sourceAbsent:!0};if(!(s instanceof De))return _n(`look.source ${B(t)} is not a Markdown-ranged property \u2014 the order of a sequence comes from prose [[references]]`);let o=[],i=[],c=0;for(let h of s.links){if(!h.target)continue;let b=h.target.subject,m=oe(r,b)[0];m&&($n(r,m)!==void 0?a.some(y=>re(b,y.relation))?o.push({kind:"selector",relation:b}):i.push(b):(o.push({kind:"participant",subject:m}),c++))}let l=[],d=[],f,p;for(let h of o){if(h.kind==="selector"){p=h.relation;continue}let b=h.subject;if(f){let m=p?a.filter(T=>re(p,T.relation)):a,y=we(b),v=we(f),E=[],K=[];for(let T of m){let{style:L,undirected:S}=qt(r,T,a);y&&je(f,T.relation).some(W=>B(W)===B(y))?E.push({from:f,to:b,relation:T.relation,style:L,undirected:S}):v&&je(b,T.relation).some(W=>B(W)===B(v))&&K.push({from:b,to:f,relation:T.relation,style:L,undirected:S})}let O=E.length>0?E:K;l.push(...O),O.length===0&&Ve(f)!==Ve(b)&&d.push({prev:f,next:b,selected:p}),p=void 0}f=b}let g=new Map;for(let h of Ht(r,n))g.set(Ve(h),h);for(let h of l)g.has(Ve(h.from))||g.set(Ve(h.from),h.from),g.has(Ve(h.to))||g.set(Ve(h.to),h.to);return{messages:l,gaps:d,lifelines:[...g.values()],mentions:c,strayPropertyRefs:i,sourceAbsent:!1}}function Ve(r){return`${r.namespace}/${r.name}`}function _n(r){return{messages:[],gaps:[],lifelines:[],mentions:0,strayPropertyRefs:[],sourceAbsent:!1,...r?{problem:r}:{}}}var pr="kanonak.org",mr="core-shacl",_e=r=>({publisher:pr,package_:mr,name:r}),gr=_e("NodeShape"),kr=_e("targetClass"),hr=_e("property"),br=_e("path"),yr=_e("minCount"),vr=_e("maxCount"),$r=_e("in"),Sr=_e("pattern"),wr=_e("flags"),_r=_e("minLength"),jr=_e("maxLength"),Kr=_e("minInclusive"),Rr=_e("maxInclusive"),Er=_e("message");function rn(r){return typeof r=="number"?r:void 0}function xr(r){let e={},n=rn(Xe(r,yr)),t=rn(Xe(r,vr));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let a=rn(Xe(r,_r)),s=rn(Xe(r,jr));a!==void 0&&(e.minLength=a),s!==void 0&&(e.maxLength=s);let o=rn(Xe(r,Kr)),i=rn(Xe(r,Rr));o!==void 0&&(e.minInclusive=o),i!==void 0&&(e.maxInclusive=i);let c=xe(r,Sr);if(c!==void 0){let f=xe(r,wr);e.pattern=f!==void 0?{regex:c,flags:f}:{regex:c}}let l=Ee(r,$r).map(f=>f.item).filter(f=>"literal"in f).map(f=>f.value);l.length>0&&(e.enumValues=l);let d=xe(r,Er);return d!==void 0&&(e.message=d),e}function Lr(r,e){let n=[];for(let{item:t}of Ee(e,hr))if(t instanceof D)n.push(t);else if(t instanceof U){let a=Te(r,t.subject);a&&n.push(a)}return n}function Cr(r){let e=new Map;for(let n of r){if(!(n instanceof Y)||!_(n,gr))continue;let t=Oe(n,kr);if(!t)continue;let a=B(t);for(let s of Lr(r,n)){let o=Oe(s,br);if(!o)continue;let i=xr(s);if(Ur(s,i))continue;let c={pathKey:B(o),constraints:i},l=e.get(a);l?l.push(c):e.set(a,[c])}}return e}var Gt=new WeakMap;function pn(r){let e=Gt.get(r);return e||(e=Cr(r),Gt.set(r,e)),e}function Ur(r,e){return un(r,ht)||un(r,bt)?Object.keys(e).every(t=>t==="message"):!1}function Or(r,e){e.minCount!==void 0&&(r.minCount=e.minCount),e.maxCount!==void 0&&(r.maxCount=e.maxCount),e.minLength!==void 0&&(r.minLength=e.minLength),e.maxLength!==void 0&&(r.maxLength=e.maxLength),e.minInclusive!==void 0&&(r.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(r.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(r.pattern=e.pattern),e.enumValues!==void 0&&(r.enumValues=e.enumValues),e.message!==void 0&&(r.message=e.message)}function zt(r,e,n){let t=B(n),a=!1,s={};for(let o=e.length-1;o>=0;o--){let i=r.get(B(e[o]));if(i)for(let c of i)c.pathKey===t&&(a=!0,Or(s,c.constraints))}if(a)return s.cardinality=s.maxCount===1?"single":"list",s.required=(s.minCount??0)>=1,s}var Ze="kanonak.org",Kn="core-rdf",Wt="core-xsd",Ir={publisher:Ze,package_:Kn,name:"subClassOf"},Yt={publisher:Ze,package_:Kn,name:"label"},Xt={publisher:Ze,package_:Kn,name:"comment"},Jt={publisher:Ze,package_:"core-owl",name:"oneOf"},Qt=r=>r;function Fr(r,e,n){if(e.publisher===Ze&&e.package_===Kn&&e.name==="Literal")return{kind:"datatype",uri:e};let a=Te(r,e);if(a){let s=Qt(a);if(tn.isDatatypeType(s))return{kind:"datatype",uri:e};if(tn.isClassType(s))return{kind:"class",uri:we(a)??e,localName:a.name}}return e.publisher===Ze&&e.package_===Wt?{kind:"datatype",uri:e}:n==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function Tr(r,e,n){if(!e.range)throw new Error(`Property ${e.uri.publisher}/${e.uri.package_}/${e.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let t=Fr(r,e.range,e.kind),a=e.kind==="object"?"object":e.kind==="datatype"?"datatype":t.kind==="class"?"object":"datatype";return{uri:e.uri,localName:e.uri.name,kind:a,range:t,...e.label!==void 0?{label:e.label}:{},...e.comment!==void 0?{comment:e.comment}:{},...n??{}}}var jn=r=>new yn(Ze,Wt,r);function Pr(r){return typeof r=="boolean"?jn("boolean"):typeof r=="number"?Number.isInteger(r)?jn("integer"):jn("decimal"):jn("string")}function Vr(r,e,n){let t=[];for(let a of vn(e,Jt,r,B(n)))if(a.kind==="subject"||a.kind==="unresolved"){let s=a.kind==="subject"?a.node:void 0,o=(s?we(s):void 0)??a.uri,i=s?xe(s,Yt):void 0,c=s?xe(s,Xt):void 0;t.push({kind:"individual",uri:o,localName:o.name,...i!==void 0?{label:i}:{},...c!==void 0?{comment:c}:{}})}else a.kind==="literal"&&t.push({kind:"literal",value:a.value,datatype:Pr(a.value)});return t}function Rn(r,e,n,t){let a=an(r,e),s=B(e);return vt(r,e).filter(i=>n?!0:i.domains.some(c=>B(c)===s)).map(i=>Tr(r,i,zt(t,a,i.uri)))}async function Yi(r,e,n){let t=r.metadata?.namespace_;if(!t)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let a=n?.includeInherited??!1,s=Array.isArray(e)?e:await new Sn().parseKanonaks(e),o=pn(s),i=p=>p.publisher===t.publisher&&p.package_===t.package_&&!(p.version&&t.version&&!lt(p.version,t.version)),c=[],l=[],d=new Set,f=!1;for(let p of s){if(!(p instanceof Y))continue;let g=we(p);if(!g||!i(g)||(f=!0,!tn.isClassType(Qt(p))))continue;let h=B(g);if(d.has(h))continue;d.add(h);let b=je(p,Ir).map(v=>({uri:v,localName:v.name})),m=xe(p,Yt),y=xe(p,Xt);c.push({uri:g,localName:g.name,superClasses:b,properties:Rn(s,g,a,o),...m!==void 0?{label:m}:{},...y!==void 0?{comment:y}:{}}),un(p,Jt)&&l.push({uri:g,localName:g.name,members:Vr(s,p,g),...m!==void 0?{label:m}:{},...y!==void 0?{comment:y}:{}})}if(!f)throw new Error(`buildOntologyModel: ${t.toString()} is not in the ${Array.isArray(e)?"catalog":"repository"} \u2014 a model can only be built for a document ${Array.isArray(e)?"the catalog was parsed from":"the repository holds"}.`);return{classes:c,enums:l}}function mn(r,e={}){let n=r.replace(/\r\n/g,`
1
+ import{a as dt}from"./chunk-NYCGUDVW.js";import{e as he,f as u,k as Sn}from"./chunk-Q2ZUKZEU.js";import{a as ft}from"./chunk-6CI3HTKF.js";import{a as $t}from"./chunk-PEJALHXK.js";import{$ as bt,_ as ht,oa as tn,pa as we,qa as an,ra as $n,va as vt}from"./chunk-TVMOJ2QS.js";import{A as gt,B as un,C as Xe,D as xe,E as Oe,F as kt,G as Mn,H as vn,K as yt,b as Ue,c as Y,d as D,e as U,i as ae,j as be,k as ke,l as Q,m as le,n as ue,o as De,p as B,q as re,r as pt,s as mt,t as je,u as Ee,w as _,y as Te,z as oe}from"./chunk-6USORWEP.js";import{c as hn,d as lt,e as bn,g as ut,l as yn}from"./chunk-7IMLHHSA.js";import{ExpressionError as Oa,evaluates as Ia,validateMatchesPattern as Fa}from"@kanonak-protocol/expression";var q=class extends Error{constructor(n,t){super(`${n} (at ${t})`);this.path=t}path};function bi(r,e){let n=r.name,t=Ja(e),a={catalog:e,depth:0};if(_(r,u.InstanceTransformation))return Ta(r,n,a,t);if(_(r,u.SetTransformation))return Pa(r,n,a,t);throw new q("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function Ta(r,e,n,t){return{kind:"instance",name:r.name,inputPattern:Et(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:xt(r,`${e}.outputs`),overrides:Lt(r,`${e}.formatOverrides`,n),fragments:t}}function Pa(r,e,n,t){let a=Pe(r,u.partitionBy);return{kind:"set",name:r.name,inputPattern:Et(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:xt(r,`${e}.outputs`),overrides:Lt(r,`${e}.formatOverrides`,n),partitionBy:a,fragments:t}}function Et(r,e){let n=Ct(r,u.inputPattern);if(!n)throw new q("inputPattern is required",e);return Va(n,`${e}.inputPattern`)}function Va(r,e){let n=Pe(r,u.matchesClass);if(!n)throw new q("matchesClass is required",e);let t=[];for(let o of Le(r,u.requires))if(o instanceof Q)t.push(Hn(o.object.subject));else if(o instanceof ue)for(let i of o.object)i instanceof U&&t.push(Hn(i.subject));let a=[],s=0;for(let o of Le(r,u.sortBy))if(o instanceof ue)for(let i of o.object)i instanceof D&&a.push(St(i,`${e}.sortBy[${s++}]`));else o instanceof le&&a.push(St(o.object,`${e}.sortBy[${s++}]`));return{matchesClass:n,requires:t,sortBy:a}}function St(r,e){let n=Pe(r,u.byProperty);if(!n)throw new q("SortKey.byProperty is required",e);let t=Pe(r,u.order);if(!t)throw new q("SortKey.order is required",e);if(re(t,u.ascending))return{byProperty:n,order:"ascending"};if(re(t,u.descending))return{byProperty:n,order:"descending"};throw new q(`SortKey.order must reference tx.ascending or tx.descending; got ${t.publisher}/${t.package_}/${t.name}`,e)}function wn(r,e,n,t){let a=Gn(r,e,n,t);if(!a)throw new q("expression is required",n);return qe(a,n,t)}function qn(r,e,n,t){return Ee(r,e).map((a,s,o)=>{let i=o.length>1||a.fromList?`${n}[${s}]`:n;if(a.item instanceof D)return a.item;if(a.item instanceof U){let c=Te(t.catalog,a.item.subject);if(!c)throw new q(`references '${B(a.item.subject)}', which does not resolve in the catalog`,i);return c}throw new q(`expects a node, not the literal ${JSON.stringify(a.item.value)}`,i)})}function Gn(r,e,n,t){let a=qn(r,e,n,t);if(a.length>1)throw new q(`expects one expression, has ${a.length}`,n);return a[0]}function qe(r,e,n){if(r instanceof Y){let t=we(r),a=t?B(t):`${r.namespace}/${r.name}`,s=n.visiting??new Set;if(s.has(a))throw new q(`named expressions form a cycle: ${[...s,a].join(" -> ")}`,e);return wt(r,a,{...n,visiting:new Set([...s,a])})}return wt(r,e,n)}function wt(r,e,n){if(_(r,u.StringLiteral))return{kind:"string-literal",value:ye(r,u.stringLiteral,e)};if(_(r,u.IntegerLiteral))return{kind:"integer-literal",value:Rt(r,u.integerLiteral,e)};if(_(r,u.DecimalLiteral))return{kind:"decimal-literal",value:Rt(r,u.decimalLiteral,e)};if(_(r,u.BooleanLiteral))return{kind:"boolean-literal",value:er(r,u.booleanLiteral,e)};if(_(r,u.VarRef))return{kind:"var-ref",varName:ye(r,u.varName,e)};if(_(r,u.PropertyRead))return{kind:"property-read",source:w(r,u.readSource,`${e}.readSource`,n),readProp:Be(r,u.readProp,e,"readProp")};if(_(r,u.Traverse))return{kind:"traverse",source:w(r,u.traverseSource,`${e}.traverseSource`,n),through:Be(r,u.through,e,"through"),step:w(r,u.step,`${e}.step`,n)};if(_(r,u.BuildAstNode))return{kind:"build-ast-node",astClass:Be(r,u.astClass,e,"astClass"),set:Ba(r,`${e}.set`,n)};if(_(r,u.When))return{kind:"when",condition:w(r,u.condition,`${e}.condition`,n),thenBuild:w(r,u.thenBuild,`${e}.thenBuild`,n),elseBuild:Da(r,u.elseBuild,`${e}.elseBuild`,n)};if(_(r,u.Concat))return{kind:"concat",parts:Nn(r,u.parts,`${e}.parts`,n)};if(_(r,u.Fallback))return{kind:"fallback",primary:w(r,u.primary,`${e}.primary`,n),alternate:w(r,u.alternate,`${e}.alternate`,n)};if(_(r,u.UriName))return{kind:"uri-name",source:w(r,u.uriNameOf,`${e}.uriNameOf`,n)};if(_(r,u.UriPublisher))return{kind:"uri-publisher",source:w(r,u.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(_(r,u.UriPackage))return{kind:"uri-package",source:w(r,u.uriPackageOf,`${e}.uriPackageOf`,n)};if(_(r,u.UriVersion))return{kind:"uri-version",source:w(r,u.uriVersionOf,`${e}.uriVersionOf`,n)};if(_(r,u.SubjectUri))return{kind:"subject-uri",source:w(r,u.subjectOf,`${e}.subjectOf`,n)};if(_(r,u.UriLiteral))return{kind:"uri-literal",refTo:Be(r,u.refTo,e,"refTo")};if(_(r,u.DisplayLabel))return{kind:"display-label",labelTarget:Be(r,u.labelTarget,e,"labelTarget"),labelSource:Be(r,u.labelSource,e,"labelSource")};if(_(r,u.ResolveRef))return{kind:"resolve-ref",source:w(r,u.resolveSource,`${e}.resolveSource`,n)};if(_(r,u.Normalize))return{kind:"normalize",source:w(r,u.normSource,`${e}.normSource`,n),normKind:qa(r,e)};if(_(r,u.UnescapedString))return{kind:"unescaped-string",source:w(r,u.unescapedSource,`${e}.unescapedSource`,n)};if(_(r,u.RenderMarkdown))return{kind:"render-markdown",source:w(r,u.renderSource,`${e}.renderSource`,n),readProp:Be(r,u.renderProp,e,"renderProp"),format:Ga(r,e)};if(_(r,u.IsSet))return{kind:"is-set",check:w(r,u.checkExpr,`${e}.checkExpr`,n)};if(_(r,u.CallFragment))return Ya(r,e,n);if(_(r,u.Join))return{kind:"join",source:w(r,u.source,`${e}.source`,n),separator:ye(r,u.separator,e)};if(_(r,u.Count))return{kind:"count",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Sum))return{kind:"sum",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Min))return{kind:"min",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Max))return{kind:"max",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.Average))return{kind:"average",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.ForEach))return{kind:"for-each",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),emit:w(r,u.emit,`${e}.emit`,n)};if(_(r,u.ListMap))return{kind:"list-map",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),mapBody:w(r,u.mapBody,`${e}.mapBody`,n)};if(_(r,u.Filter))return{kind:"filter",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),predicate:w(r,u.predicate,`${e}.predicate`,n)};if(_(r,u.PartitionBy))return{kind:"partition-by",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),partitionKey:w(r,u.partitionKey,`${e}.partitionKey`,n)};if(_(r,u.DistinctBy))return{kind:"distinct-by",source:w(r,u.source,`${e}.source`,n),loopVar:ye(r,u.loopVar,e),distinctKey:w(r,u.distinctKey,`${e}.distinctKey`,n)};if(_(r,u.AllStatements))return{kind:"all-statements",source:w(r,u.statementsOf,`${e}.statementsOf`,n)};if(_(r,u.StatementPredicate))return{kind:"statement-predicate",source:w(r,u.predicateOf,`${e}.predicateOf`,n)};if(_(r,u.StatementValue))return{kind:"statement-value",source:w(r,u.valueOf,`${e}.valueOf`,n)};if(_(r,u.DateFormat))return{kind:"date-format",source:w(r,u.dateSource,`${e}.dateSource`,n),format:Wa(r,e)};if(_(r,u.NumberFormat)){let a=Dn(r,u.fractionDigits);if(a!==void 0&&(!Number.isInteger(a)||a<0||a>20))throw new q(`fractionDigits must be an integer between 0 and 20; got ${a}`,e);let s=He(r,u.currencyCode);return{kind:"number-format",source:w(r,u.numberSource,`${e}.numberSource`,n),style:za(r,e),...a!==void 0?{fractionDigits:a}:{},...s!==void 0?{currencyCode:s}:{}}}let t=Na.find(a=>_(r,a.type));if(t){let a=B(t.type);if(!Ia(a))throw new q(`${a} is a numeric operator the expression runtime does not evaluate`,e);return{kind:"numeric-op",type:a,name:t.type.name,operands:t.operands.map(s=>({name:s.name,expr:w(r,s,`${e}.${s.name}`,n)}))}}if(_(r,u.Reverse))return{kind:"reverse",source:w(r,u.source,`${e}.source`,n)};if(_(r,u.WindowedMap)){let a=Dn(r,u.windowSize);if(a===void 0||!Number.isInteger(a)||a<1)throw new q("windowSize must be a positive integer",`${e}.windowSize`);return{kind:"windowed-map",source:w(r,u.source,`${e}.source`,n),windowSize:a,windowVar:ye(r,u.windowVar,e),windowBody:w(r,u.windowBody,`${e}.windowBody`,n)}}if(_(r,u.PairwiseMap))return{kind:"pairwise-map",source:w(r,u.source,`${e}.source`,n),firstVar:ye(r,u.firstVar,e),secondVar:ye(r,u.secondVar,e),pairBody:w(r,u.pairBody,`${e}.pairBody`,n)};if(_(r,u.Scan))return{kind:"scan",source:w(r,u.source,`${e}.source`,n),initialState:w(r,u.initialState,`${e}.initialState`,n),stateVar:ye(r,u.stateVar,e),elementVar:ye(r,u.elementVar,e),accumulate:w(r,u.accumulate,`${e}.accumulate`,n)};if(_(r,u.ListItemAt))return{kind:"list-item-at",source:w(r,u.source,`${e}.source`,n),itemIndex:w(r,u.itemIndex,`${e}.itemIndex`,n)};if(_(r,u.Equals))return{kind:"equals",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.GreaterThan))return{kind:"greater-than",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.LessThan))return{kind:"less-than",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.LessThanOrEqual))return{kind:"less-than-or-equal",left:w(r,u.compareLeft,`${e}.compareLeft`,n),right:w(r,u.compareRight,`${e}.compareRight`,n)};if(_(r,u.Not))return{kind:"not",operand:w(r,u.operand,`${e}.operand`,n)};if(_(r,u.And))return{kind:"and",operands:Nn(r,u.operands,`${e}.operands`,n)};if(_(r,u.Or))return{kind:"or",operands:Nn(r,u.operands,`${e}.operands`,n)};if(_(r,u.Contains))return{kind:"contains",haystack:w(r,u.haystack,`${e}.haystack`,n),needle:w(r,u.needle,`${e}.needle`,n)};if(_(r,u.Matches)){let a=ye(r,u.pattern,e);try{Fa(a)}catch(s){throw s instanceof Oa?new q(s.message,`${e}.pattern`):s}return{kind:"matches",source:w(r,u.matchSource,`${e}.matchSource`,n),pattern:a}}if(_(r,u.IsReference))return{kind:"is-reference",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsEmbedded))return{kind:"is-embedded",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsList))return{kind:"is-list",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsString))return{kind:"is-string",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsNumber))return{kind:"is-number",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.IsBoolean))return{kind:"is-boolean",check:w(r,u.kindCheck,`${e}.kindCheck`,n)};if(_(r,u.StatementObject))return{kind:"statement-object",source:w(r,u.statementSource,`${e}.statementSource`,n)};if(_(r,u.Let))return{kind:"let",bindName:ye(r,u.letName,e),bindValue:w(r,u.letValue,`${e}.letValue`,n),body:w(r,u.letBody,`${e}.letBody`,n)};if(_(r,u.GetStatementByName))return{kind:"get-statement-by-name",inSubject:w(r,u.inSubject,`${e}.inSubject`,n),byName:w(r,u.byName,`${e}.byName`,n)};throw new q("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}var Aa=[u.arithLeft,u.arithRight],Ma=[u.value],Na=[...[u.Add,u.Subtract,u.Multiply,u.Divide,he.Power,he.Modulo,he.Minimum,he.Maximum].map(r=>({type:r,operands:Aa})),...[u.Abs,u.Negate,he.Exp,he.Ln,he.Log10,he.Sqrt,he.Floor,he.Ceil,he.Round,he.Sign].map(r=>({type:r,operands:Ma})),{type:he.Clip,operands:[he.clipValue,he.clipLower,he.clipUpper]}];function w(r,e,n,t){let a=Gn(r,e,n,t);if(!a)throw new q("child expression is required",n);return qe(a,n,t)}function Da(r,e,n,t){let a=Gn(r,e,n,t);if(a)return qe(a,n,t)}function Nn(r,e,n,t){return qn(r,e,n,t).map((a,s)=>qe(a,`${n}[${s}]`,t))}function Ba(r,e,n){return qn(r,u.set,e,n).map((t,a)=>Ha(t,`${e}[${a}]`,n))}function Ha(r,e,n){return{field:Be(r,u.field,e,"field"),value:w(r,u.bindValue,`${e}.bindValue`,n)}}function qa(r,e){let n=Pe(r,u.normKind);if(!n)throw new q("normKind is required",e);if(re(n,u.NORM_TRIM_END))return"trim-end";if(re(n,u.NORM_TO_UPPER))return"to-upper";if(re(n,u.NORM_TO_LOWER))return"to-lower";if(re(n,u.NORM_FIRST_CHAR))return"first-char";throw new q(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function Ga(r,e){let n=Pe(r,u.renderFormat);if(!n)throw new q("renderFormat is required",e);if(re(n,u.RENDER_HTML))return"html";if(re(n,u.RENDER_MARKDOWN))return"markdown";throw new q(`Unknown RenderFormat: ${n.publisher}/${n.package_}/${n.name}`,e)}var _t=new Set(["decimal","percent","basis-points","currency","compact"]);function za(r,e){let n=He(r,u.numberStyle);if(n===void 0)throw new q("numberStyle is required",e);if(!_t.has(n))throw new q(`Unknown numberStyle "${n}"; supported: ${[..._t].join(", ")}`,e);return n}var jt=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function Wa(r,e){let n=He(r,u.dateFormat);if(!n)throw new q("dateFormat is required",e);if(!jt.has(n))throw new q(`Unknown dateFormat "${n}"; supported: ${[...jt].join(", ")}`,e);return n}function Ya(r,e,n){let t=Pe(r,u.fragmentRef);if(!t)throw new q("fragmentRef is required",e);if(!Qa(n.catalog,t))throw new q(`ExpressionFragment not found: ${t.publisher}/${t.package_}/${t.name}`,e);return{kind:"call-fragment",fragmentKey:Xa(t)}}function Xa(r){return`${r.publisher}/${r.package_}/${r.name}`}function Ja(r){let e=new Map,n=[];for(let t of r){if(!(t instanceof Y)||!_(t,u.ExpressionFragment))continue;let a=Ct(t,u.body);if(!a)continue;let s=(t.namespace||"").split("@")[0]||"",o=s.indexOf("/");if(o<0)continue;let i=s.substring(0,o),c=s.substring(o+1),l=`${i}/${c}/${t.name}`;n.push({key:l,subject:t,bodyEmb:a,pubPkgName:`${s}/${t.name}`})}for(let t of n){let a=qe(t.bodyEmb,`fragment(${t.pubPkgName})`,{catalog:r,depth:0});e.set(t.key,a)}return e}function Qa(r,e){for(let n of r)if(!(!(n instanceof Y)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&_(n,u.ExpressionFragment))return n}function xt(r,e){let n=new Set;for(let t of Le(r,u.outputs))if(t instanceof Q)n.add(t.object.subject.name);else if(t instanceof ue)for(let a of t.object)a instanceof U&&n.add(a.subject.name);if(n.size===0)throw new q("outputs is required (at least one OutputFormat)",e);return n}function Lt(r,e,n){let t=new Map,a=0;for(let s of Le(r,u.formatOverrides))if(s instanceof ue){for(let o of s.object)if(o instanceof D){let[i,c]=Kt(o,`${e}[${a++}]`);t.set(i,c)}}else if(s instanceof le){let[o,i]=Kt(s.object,`${e}[${a++}]`);t.set(o,i)}return t}function Kt(r,e){let n=Pe(r,u.formatTarget);if(!n)throw new q("formatTarget is required",e);let t=[];for(let i of Le(r,u.metadataKeys))if(i instanceof ae)t.push(i.object);else if(i instanceof ue)for(let c of i.object){let l=c.value;typeof l=="string"&&t.push(l)}let a=new Map;for(let i of Le(r,u.metadataRenames))if(i instanceof ue){for(let c of i.object)if(c instanceof D){let l=He(c,u.fromKey),d=He(c,u.toKey);l&&d&&a.set(l,d)}}else if(i instanceof le){let c=i.object,l=He(c,u.fromKey),d=He(c,u.toKey);l&&d&&a.set(l,d)}let s=Bn(r,u.trailingNewline),o=Bn(r,u.omitWrapper);return[n.name,{metadataKeys:t.length>0?t:void 0,metadataRenames:a,trailingNewline:s,omitWrapper:o}]}function Za(r){return r.predicate?.subject}function Le(r,e){let n=[];for(let t of r.statement){let a=Za(t);a&&re(a,e)&&n.push(t)}return n}function Ct(r,e){for(let n of Le(r,e))if(n instanceof le)return n.object}function Pe(r,e){for(let n of Le(r,e))if(n instanceof Q)return Hn(n.object.subject)}function He(r,e){for(let n of Le(r,e))if(n instanceof ae)return n.object}function Dn(r,e){for(let n of Le(r,e))if(n instanceof be)return n.object}function Bn(r,e){for(let n of Le(r,e))if(n instanceof ke)return n.object}function ye(r,e,n){let t=He(r,e);if(t===void 0)throw new q(`${e.name} (string) is required`,n);return t}function Rt(r,e,n){let t=Dn(r,e);if(t===void 0)throw new q(`${e.name} (number) is required`,n);return t}function er(r,e,n){let t=Bn(r,e);if(t===void 0)throw new q(`${e.name} (boolean) is required`,n);return t}function Be(r,e,n,t){let a=Pe(r,e);if(!a)throw new q(`${t} (URI reference) is required`,n);return a}function Hn(r){return{publisher:r.publisher,package_:r.package_,name:r.name}}var Je="kanonak.org",Tt="look",dn="core-rdf",Pt={publisher:Je,package_:Tt,name:"displayLabel"},Vt={publisher:Je,package_:Tt,name:"displaySummary"},nr={publisher:Je,package_:dn,name:"subClassOf"},tr={publisher:Je,package_:dn,name:"label"},ar={publisher:Je,package_:dn,name:"comment"},Ut=new yn(Je,dn,"Resource"),rr=8;function G(r,e){return At(r,e,new Set)}function At(r,e,n){let t=Ft(r,e,Pt)??tr,a=Ft(r,e,Vt)??ar,s=Ot(r,e,t,n)??e.name,o=Ot(r,e,a,n);return{label:s,summary:o}}function Ot(r,e,n,t){for(let a of e.statement){let s=a.predicate;if(!(!s?.subject||!re(s.subject,n))){if(a instanceof ae)return a.object;if(a instanceof be||a instanceof ke)return String(a.object);if(a instanceof Q)return It(r,a.object.subject,t);if(a instanceof ue){let o=[];for(let i of a.object??[])if(i instanceof U){let c=It(r,i.subject,t);c&&o.push(c)}if(o.length>0)return o.join(", ")}return}}}function It(r,e,n){let t=B(e);if(n.has(t)||n.size>=rr)return e.name;let[a]=oe(r,e);if(!a)return e.name;let s=new Set(n);return s.add(t),At(r,a,s).label}function Ft(r,e,n){let t=Oe(e,n);if(t)return t;let a=new Set,s=je(e,sr);for(;s.length>0;){let o=s.shift(),i=B(o);if(a.has(i))continue;a.add(i);let c=oe(r,o);for(let l of c){let d=Oe(l,n);if(d)return d}for(let l of c)s.push(...je(l,nr))}if(!a.has(B(Ut)))for(let o of oe(r,Ut)){let i=Oe(o,n);if(i)return i}}var sr={publisher:Je,package_:dn,name:"type"};var or="kanonak.org",Qe=(r,e)=>({publisher:or,package_:r,name:e}),ir=Qe("look","source"),Mt=Qe("look","connectors"),cr=Qe("look","relation"),lr=Qe("look","lineStyle"),ur=Qe("look","participants"),dr=Qe("core-owl","SymmetricProperty"),fr=Qe("core-owl","inverseOf"),Nt=new Set(["solid","dotted","open","thick"]);function Dt(r){return Oe(r,ir)}function Bt(r,e){let n=kt(e,Mt),t=n?[n]:Mn(e,Mt),a=[];for(let s of t){if(!(s instanceof D))continue;let o=Oe(s,cr);if(!o)continue;let i=xe(s,lr),c=i!==void 0&&Nt.has(i);a.push({relation:o,subject:oe(r,o)[0],declaredStyle:c?i:void 0,invalidStyle:i!==void 0&&!c?i:void 0})}return a}function Ht(r,e){let n=[];for(let t of Mn(e,ur)){if(!(t instanceof U))continue;let a=oe(r,t.subject)[0];a&&n.push(a)}return n}function fn(r,e,n){for(let t of mt(e))if(re(t,n)||an(r,t).some(a=>re(a,n)))return!0;return!1}function qt(r,e,n){let t=!!e.subject&&fn(r,e.subject,dr);return e.declaredStyle?{style:e.declaredStyle,undirected:t}:e.subject&&je(e.subject,fr).some(s=>n.some(o=>re(s,o.relation)))?{style:"dotted",undirected:t}:{style:"solid",undirected:t}}function zn(r,e,n){let t=Dt(n);if(!t)return _n("the band declares no look.source");let a=Bt(r,n);if(a.length===0)return _n("the band declares no look.connectors \u2014 nothing can be a message");let s=gt(e,t);if(!s)return{..._n(),sourceAbsent:!0};if(!(s instanceof De))return _n(`look.source ${B(t)} is not a Markdown-ranged property \u2014 the order of a sequence comes from prose [[references]]`);let o=[],i=[],c=0;for(let h of s.links){if(!h.target)continue;let b=h.target.subject,m=oe(r,b)[0];m&&($n(r,m)!==void 0?a.some(y=>re(b,y.relation))?o.push({kind:"selector",relation:b}):i.push(b):(o.push({kind:"participant",subject:m}),c++))}let l=[],d=[],f,p;for(let h of o){if(h.kind==="selector"){p=h.relation;continue}let b=h.subject;if(f){let m=p?a.filter(T=>re(p,T.relation)):a,y=we(b),v=we(f),E=[],K=[];for(let T of m){let{style:L,undirected:S}=qt(r,T,a);y&&je(f,T.relation).some(W=>B(W)===B(y))?E.push({from:f,to:b,relation:T.relation,style:L,undirected:S}):v&&je(b,T.relation).some(W=>B(W)===B(v))&&K.push({from:b,to:f,relation:T.relation,style:L,undirected:S})}let O=E.length>0?E:K;l.push(...O),O.length===0&&Ve(f)!==Ve(b)&&d.push({prev:f,next:b,selected:p}),p=void 0}f=b}let g=new Map;for(let h of Ht(r,n))g.set(Ve(h),h);for(let h of l)g.has(Ve(h.from))||g.set(Ve(h.from),h.from),g.has(Ve(h.to))||g.set(Ve(h.to),h.to);return{messages:l,gaps:d,lifelines:[...g.values()],mentions:c,strayPropertyRefs:i,sourceAbsent:!1}}function Ve(r){return`${r.namespace}/${r.name}`}function _n(r){return{messages:[],gaps:[],lifelines:[],mentions:0,strayPropertyRefs:[],sourceAbsent:!1,...r?{problem:r}:{}}}var pr="kanonak.org",mr="core-shacl",_e=r=>({publisher:pr,package_:mr,name:r}),gr=_e("NodeShape"),kr=_e("targetClass"),hr=_e("property"),br=_e("path"),yr=_e("minCount"),vr=_e("maxCount"),$r=_e("in"),Sr=_e("pattern"),wr=_e("flags"),_r=_e("minLength"),jr=_e("maxLength"),Kr=_e("minInclusive"),Rr=_e("maxInclusive"),Er=_e("message");function rn(r){return typeof r=="number"?r:void 0}function xr(r){let e={},n=rn(Xe(r,yr)),t=rn(Xe(r,vr));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let a=rn(Xe(r,_r)),s=rn(Xe(r,jr));a!==void 0&&(e.minLength=a),s!==void 0&&(e.maxLength=s);let o=rn(Xe(r,Kr)),i=rn(Xe(r,Rr));o!==void 0&&(e.minInclusive=o),i!==void 0&&(e.maxInclusive=i);let c=xe(r,Sr);if(c!==void 0){let f=xe(r,wr);e.pattern=f!==void 0?{regex:c,flags:f}:{regex:c}}let l=Ee(r,$r).map(f=>f.item).filter(f=>"literal"in f).map(f=>f.value);l.length>0&&(e.enumValues=l);let d=xe(r,Er);return d!==void 0&&(e.message=d),e}function Lr(r,e){let n=[];for(let{item:t}of Ee(e,hr))if(t instanceof D)n.push(t);else if(t instanceof U){let a=Te(r,t.subject);a&&n.push(a)}return n}function Cr(r){let e=new Map;for(let n of r){if(!(n instanceof Y)||!_(n,gr))continue;let t=Oe(n,kr);if(!t)continue;let a=B(t);for(let s of Lr(r,n)){let o=Oe(s,br);if(!o)continue;let i=xr(s);if(Ur(s,i))continue;let c={pathKey:B(o),constraints:i},l=e.get(a);l?l.push(c):e.set(a,[c])}}return e}var Gt=new WeakMap;function pn(r){let e=Gt.get(r);return e||(e=Cr(r),Gt.set(r,e)),e}function Ur(r,e){return un(r,ht)||un(r,bt)?Object.keys(e).every(t=>t==="message"):!1}function Or(r,e){e.minCount!==void 0&&(r.minCount=e.minCount),e.maxCount!==void 0&&(r.maxCount=e.maxCount),e.minLength!==void 0&&(r.minLength=e.minLength),e.maxLength!==void 0&&(r.maxLength=e.maxLength),e.minInclusive!==void 0&&(r.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(r.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(r.pattern=e.pattern),e.enumValues!==void 0&&(r.enumValues=e.enumValues),e.message!==void 0&&(r.message=e.message)}function zt(r,e,n){let t=B(n),a=!1,s={};for(let o=e.length-1;o>=0;o--){let i=r.get(B(e[o]));if(i)for(let c of i)c.pathKey===t&&(a=!0,Or(s,c.constraints))}if(a)return s.cardinality=s.maxCount===1?"single":"list",s.required=(s.minCount??0)>=1,s}var Ze="kanonak.org",Kn="core-rdf",Wt="core-xsd",Ir={publisher:Ze,package_:Kn,name:"subClassOf"},Yt={publisher:Ze,package_:Kn,name:"label"},Xt={publisher:Ze,package_:Kn,name:"comment"},Jt={publisher:Ze,package_:"core-owl",name:"oneOf"},Qt=r=>r;function Fr(r,e,n){if(e.publisher===Ze&&e.package_===Kn&&e.name==="Literal")return{kind:"datatype",uri:e};let a=Te(r,e);if(a){let s=Qt(a);if(tn.isDatatypeType(s))return{kind:"datatype",uri:e};if(tn.isClassType(s))return{kind:"class",uri:we(a)??e,localName:a.name}}return e.publisher===Ze&&e.package_===Wt?{kind:"datatype",uri:e}:n==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function Tr(r,e,n){if(!e.range)throw new Error(`Property ${e.uri.publisher}/${e.uri.package_}/${e.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let t=Fr(r,e.range,e.kind),a=e.kind==="object"?"object":e.kind==="datatype"?"datatype":t.kind==="class"?"object":"datatype";return{uri:e.uri,localName:e.uri.name,kind:a,range:t,...e.label!==void 0?{label:e.label}:{},...e.comment!==void 0?{comment:e.comment}:{},...n??{}}}var jn=r=>new yn(Ze,Wt,r);function Pr(r){return typeof r=="boolean"?jn("boolean"):typeof r=="number"?Number.isInteger(r)?jn("integer"):jn("decimal"):jn("string")}function Vr(r,e,n){let t=[];for(let a of vn(e,Jt,r,B(n)))if(a.kind==="subject"||a.kind==="unresolved"){let s=a.kind==="subject"?a.node:void 0,o=(s?we(s):void 0)??a.uri,i=s?xe(s,Yt):void 0,c=s?xe(s,Xt):void 0;t.push({kind:"individual",uri:o,localName:o.name,...i!==void 0?{label:i}:{},...c!==void 0?{comment:c}:{}})}else a.kind==="literal"&&t.push({kind:"literal",value:a.value,datatype:Pr(a.value)});return t}function Rn(r,e,n,t){let a=an(r,e),s=B(e);return vt(r,e).filter(i=>n?!0:i.domains.some(c=>B(c)===s)).map(i=>Tr(r,i,zt(t,a,i.uri)))}async function Yi(r,e,n){let t=r.metadata?.namespace_;if(!t)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let a=n?.includeInherited??!1,s=Array.isArray(e)?e:await new Sn().parseKanonaks(e),o=pn(s),i=p=>p.publisher===t.publisher&&p.package_===t.package_&&!(p.version&&t.version&&!lt(p.version,t.version)),c=[],l=[],d=new Set,f=!1;for(let p of s){if(!(p instanceof Y))continue;let g=we(p);if(!g||!i(g)||(f=!0,!tn.isClassType(Qt(p))))continue;let h=B(g);if(d.has(h))continue;d.add(h);let b=je(p,Ir).map(v=>({uri:v,localName:v.name})),m=xe(p,Yt),y=xe(p,Xt);c.push({uri:g,localName:g.name,superClasses:b,properties:Rn(s,g,a,o),...m!==void 0?{label:m}:{},...y!==void 0?{comment:y}:{}}),un(p,Jt)&&l.push({uri:g,localName:g.name,members:Vr(s,p,g),...m!==void 0?{label:m}:{},...y!==void 0?{comment:y}:{}})}if(!f)throw new Error(`buildOntologyModel: ${t.toString()} is not in the ${Array.isArray(e)?"catalog":"repository"} \u2014 a model can only be built for a document ${Array.isArray(e)?"the catalog was parsed from":"the repository holds"}.`);return{classes:c,enums:l}}function mn(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
  `),p=l&&e.highlight?e.highlight(l,f):on(f),g=l?` class="language-${ea(l)}"`:"";t.push(`<pre class="kan-code"><code${g}>${p}</code></pre>`);continue}let i=/^(#{1,6})\s+(.*)$/.exec(s);if(i){let l=i[1].length,d=sn(i[2].trim());t.push(`<h${l}>${d}</h${l}>`),a++;continue}if(s.includes("|")&&a+1<n.length&&Zt(n[a+1])){let l=Wn(s),d=Ar(n[a+1]);a+=2;let f=[];for(;a<n.length&&n[a].trim()!==""&&n[a].includes("|");)f.push(Wn(n[a])),a++;t.push(Mr(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>${sn(d.join(" ").trim())}</li>`)}t.push(`<ul>
@@ -1 +1 @@
1
- import{n as F,u as A}from"./chunk-Z2444SWM.js";import{a as P}from"./chunk-WXXZOJ4O.js";import{a as f}from"./chunk-5ZRVFYCP.js";import{c as K,g as I,j as R}from"./chunk-GGK6A6QK.js";import*as m from"fs/promises";import*as i 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=i.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=i.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=i.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 l=a.metadata.namespace_.version,u=r.metadata.namespace_.version;return K(u,l)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let l=o.split("/"),u=l[0],h=l[1].replace("@","@")+".kan.yml";n=i.join(this.rootPath,u,h)}else n=i.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=i.dirname(n);await m.mkdir(s,{recursive:!0});let a=this.parser.save(e);await m.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=i.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 m.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=i.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=i.join(this.rootPath,e);try{let s=await m.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await m.unlink(i.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[l,u]of this.documentCache.entries())if(this.filePathsByIdentifier.get(l)===n&&u.metadata.namespace_){s=u.metadata.namespace_.toString();break}let a=s??i.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 m.access(e),t=e}catch{let n=i.join(this.rootPath,e);try{await m.access(n),t=n}catch{return null}}try{return await m.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await m.access(e),t=e}catch{let n=i.join(this.rootPath,e);try{await m.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 m.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await m.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=i.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let l=s.metadata.namespace_.toString();this.documentCache.set(l,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(l,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 m.readdir(e,{withFileTypes:!0});for(let s of o){let a=i.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 S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),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 H}from"os";import{join as T}from"path";function d(){let c=process.env.KANONAK_PACKAGE_CACHE;return c||T(H(),".kanonak","packages")}var w=class c{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 c.createComposite(t,n,e)}};var k=class{repos;constructor(...e){this.repos=e}async firstAnswer(e,t,n){let o=[];for(let s of this.repos)try{let a=await e(s);if(t(a))return a}catch(a){o.push(a)}return x(o),n}async getHighestCompatibleVersionAsync(e,t){return this.firstAnswer(n=>n.getHighestCompatibleVersionAsync(e,t),n=>n!==null,null)}async getAllDocumentsAsync(){let e=[],t=new Set,n=[];for(let o of this.repos)try{for(let s of await o.getAllDocumentsAsync()){let a=s.metadata?.namespace_,r=a?a.version?`${a.publisher}/${a.package_}@${a.version.major}.${a.version.minor}.${a.version.patch}`:`${a.publisher}/${a.package_}`:void 0;if(r!==void 0){if(t.has(r))continue;t.add(r)}e.push(s)}}catch(s){n.push(s)}return x(n),e}async getDocumentAsync(e){return this.firstAnswer(t=>t.getDocumentAsync(e),t=>t!==null,null)}async getDocumentsByNamespaceAsync(e,t){return this.firstAnswer(n=>n.getDocumentsByNamespaceAsync(e,t),n=>n.length>0,[])}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){return this.firstAnswer(t=>t.getDocumentContentAsync(e),t=>!!t,null)}async getDocumentUriAsync(e){return this.firstAnswer(t=>t.getDocumentUriAsync(e),t=>!!t,null)}};function x(c){if(c.length===1)throw c[0];if(c.length>1)throw new Error(c.map(e=>e instanceof Error?e.message:String(e)).join("; "))}import{VersionOperator as N}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 F(this.lock,e,t)}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=I(n);if(o){let s={...t,versionOperator:N.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 B,readdirSync as U}from"fs";import{join as _}from"path";var V=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(c,e=[]){for(let t of U(c,{withFileTypes:!0}))t.isDirectory()?V.has(t.name)||C(_(c,t.name),e):t.name.endsWith(".kan.yml")&&e.push(_(c,t.name));return e}async function $(c,e=new f,t={}){let n=new P(e);for(let l of C(c))try{let u=e.parse(B(l,"utf-8")),p=u.metadata?.namespace_,h=p?.version;p&&h&&await n.saveDocumentAsync(u,`${p.publisher}/${p.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:(l,u,p)=>s.get(`${l}|${u}|${p}`)??null,onFetch:(l,u,p,h)=>{s.set(`${l}|${u}|${p}`,h)}},r=new A({getFromCache:a.getFromCache,onFetch:a.onFetch,...t.fetchFn?{fetchFn:t.fetchFn}:{},...t.packageUrlTemplates?{packageUrlTemplates:t.packageUrlTemplates}:{}});return new k(n,o,r)}export{y as a,S as b,D as c,d,w as e,k as f,v as g,C as h,$ as i};
1
+ import{n as F,u as A}from"./chunk-X2URIXH7.js";import{a as P}from"./chunk-NYCGUDVW.js";import{a as f}from"./chunk-6CI3HTKF.js";import{c as K,g as I,j as R}from"./chunk-7IMLHHSA.js";import*as m from"fs/promises";import*as i 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=i.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=i.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=i.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 l=a.metadata.namespace_.version,u=r.metadata.namespace_.version;return K(u,l)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let l=o.split("/"),u=l[0],h=l[1].replace("@","@")+".kan.yml";n=i.join(this.rootPath,u,h)}else n=i.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=i.dirname(n);await m.mkdir(s,{recursive:!0});let a=this.parser.save(e);await m.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=i.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 m.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=i.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=i.join(this.rootPath,e);try{let s=await m.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await m.unlink(i.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[l,u]of this.documentCache.entries())if(this.filePathsByIdentifier.get(l)===n&&u.metadata.namespace_){s=u.metadata.namespace_.toString();break}let a=s??i.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 m.access(e),t=e}catch{let n=i.join(this.rootPath,e);try{await m.access(n),t=n}catch{return null}}try{return await m.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await m.access(e),t=e}catch{let n=i.join(this.rootPath,e);try{await m.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 m.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await m.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=i.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let l=s.metadata.namespace_.toString();this.documentCache.set(l,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(l,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 m.readdir(e,{withFileTypes:!0});for(let s of o){let a=i.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 S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),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 H}from"os";import{join as T}from"path";function d(){let c=process.env.KANONAK_PACKAGE_CACHE;return c||T(H(),".kanonak","packages")}var w=class c{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 c.createComposite(t,n,e)}};var k=class{repos;constructor(...e){this.repos=e}async firstAnswer(e,t,n){let o=[];for(let s of this.repos)try{let a=await e(s);if(t(a))return a}catch(a){o.push(a)}return x(o),n}async getHighestCompatibleVersionAsync(e,t){return this.firstAnswer(n=>n.getHighestCompatibleVersionAsync(e,t),n=>n!==null,null)}async getAllDocumentsAsync(){let e=[],t=new Set,n=[];for(let o of this.repos)try{for(let s of await o.getAllDocumentsAsync()){let a=s.metadata?.namespace_,r=a?a.version?`${a.publisher}/${a.package_}@${a.version.major}.${a.version.minor}.${a.version.patch}`:`${a.publisher}/${a.package_}`:void 0;if(r!==void 0){if(t.has(r))continue;t.add(r)}e.push(s)}}catch(s){n.push(s)}return x(n),e}async getDocumentAsync(e){return this.firstAnswer(t=>t.getDocumentAsync(e),t=>t!==null,null)}async getDocumentsByNamespaceAsync(e,t){return this.firstAnswer(n=>n.getDocumentsByNamespaceAsync(e,t),n=>n.length>0,[])}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){return this.firstAnswer(t=>t.getDocumentContentAsync(e),t=>!!t,null)}async getDocumentUriAsync(e){return this.firstAnswer(t=>t.getDocumentUriAsync(e),t=>!!t,null)}};function x(c){if(c.length===1)throw c[0];if(c.length>1)throw new Error(c.map(e=>e instanceof Error?e.message:String(e)).join("; "))}import{VersionOperator as N}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 F(this.lock,e,t)}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=I(n);if(o){let s={...t,versionOperator:N.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 B,readdirSync as U}from"fs";import{join as _}from"path";var V=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(c,e=[]){for(let t of U(c,{withFileTypes:!0}))t.isDirectory()?V.has(t.name)||C(_(c,t.name),e):t.name.endsWith(".kan.yml")&&e.push(_(c,t.name));return e}async function $(c,e=new f,t={}){let n=new P(e);for(let l of C(c))try{let u=e.parse(B(l,"utf-8")),p=u.metadata?.namespace_,h=p?.version;p&&h&&await n.saveDocumentAsync(u,`${p.publisher}/${p.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:(l,u,p)=>s.get(`${l}|${u}|${p}`)??null,onFetch:(l,u,p,h)=>{s.set(`${l}|${u}|${p}`,h)}},r=new A({getFromCache:a.getFromCache,onFetch:a.onFetch,...t.fetchFn?{fetchFn:t.fetchFn}:{},...t.packageUrlTemplates?{packageUrlTemplates:t.packageUrlTemplates}:{}});return new k(n,o,r)}export{y as a,S as b,D as c,d,w as e,k as f,v as g,C as h,$ as i};