@kanonak-protocol/sdk 6.3.0 → 6.4.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.
- package/dist/auth/credentialConfig.d.ts +0 -2
- package/dist/browser.d.ts +3 -1
- package/dist/browser.js +1 -1
- package/dist/{chunk-ED35OFGD.js → chunk-5AMN6MW7.js} +1 -1
- package/dist/{chunk-7JBKOJB4.js → chunk-5ZRVFYCP.js} +1 -1
- package/dist/{chunk-ADSDFJUO.js → chunk-7TNZ7ICK.js} +1 -1
- package/dist/{chunk-VORVR5BZ.js → chunk-A224OOBZ.js} +1 -1
- package/dist/{chunk-A3HRXFVX.js → chunk-AAYMTPG7.js} +1 -1
- package/dist/{chunk-R4LVLXAC.js → chunk-BDTJIUS4.js} +1 -1
- package/dist/{chunk-GKIX3OD6.js → chunk-FB5QKDNM.js} +1 -1
- package/dist/chunk-GGK6A6QK.js +1 -0
- package/dist/{chunk-TYVZXABI.js → chunk-GXEKJFXG.js} +1 -1
- package/dist/{chunk-66GZUKYS.js → chunk-K76UUREI.js} +1 -1
- package/dist/{chunk-22DSABP6.js → chunk-LKJVNKCN.js} +1 -1
- package/dist/{chunk-EKD2ZLKQ.js → chunk-MSOUPUUB.js} +1 -1
- package/dist/chunk-PC3MYDGL.js +1 -0
- package/dist/{chunk-MWJSYONH.js → chunk-Q57XCPAQ.js} +1 -1
- package/dist/chunk-WXUMROTA.js +1 -0
- package/dist/{chunk-6VIUXP4N.js → chunk-WXXZOJ4O.js} +1 -1
- package/dist/{chunk-D2X6J77P.js → chunk-X4V6DEZL.js} +1 -1
- package/dist/chunk-Z2444SWM.js +2 -0
- package/dist/config/packageUrlTemplatesConfig.d.ts +22 -0
- package/dist/config/userConfig.d.ts +10 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +2 -2
- package/dist/lock/LockFile.d.ts +7 -0
- package/dist/lock/index.d.ts +1 -1
- package/dist/parsing/index.js +1 -1
- package/dist/producer/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/HttpKanonakDocumentRepository.d.ts +9 -7
- package/dist/repositories/PackageUrlTemplates.d.ts +37 -0
- package/dist/repositories/PublisherIndex.d.ts +37 -1
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/buildLocalFirstRepository.d.ts +5 -1
- package/dist/repositories/index.d.ts +2 -0
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +5 -5
- package/dist/server/loadResourceModel.d.ts +3 -0
- package/dist/server/requestRouter.d.ts +3 -0
- package/dist/server/types.d.ts +8 -1
- package/dist/transformations/index.js +1 -1
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-D4QGPMRW.js +0 -1
- package/dist/chunk-MD4CAJIO.js +0 -2
- package/dist/chunk-NUTHBBDZ.js +0 -1
- package/dist/chunk-QILEJIFU.js +0 -1
|
@@ -2,8 +2,6 @@ import type { CredentialProvider } from './CredentialProvider.js';
|
|
|
2
2
|
import type { OAuthDiscovery } from './OAuthDiscovery.js';
|
|
3
3
|
/** The environment variable naming a credential helper's command line. */
|
|
4
4
|
export declare const CREDENTIAL_HELPER_ENV = "KANONAK_CREDENTIAL_HELPER";
|
|
5
|
-
/** The user-level config file: `~/.kanonak/config.json`. */
|
|
6
|
-
export declare function userConfigPath(): string;
|
|
7
5
|
export interface CredentialProviderConfigOptions {
|
|
8
6
|
/** Environment to read; `process.env` by default. */
|
|
9
7
|
env?: Record<string, string | undefined>;
|
package/dist/browser.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export { KanonakVocabulary } from './reasoning/KanonakVocabulary.js';
|
|
|
27
27
|
export { SHACL_PUBLISHER, SHACL_PACKAGE, SH_SHAPE, SH_NODE_SHAPE, SH_PROPERTY_SHAPE, } from './shacl/uris.js';
|
|
28
28
|
export { PublisherConfigResolver } from './repositories/PublisherConfig.js';
|
|
29
29
|
export type { PublisherConfig } from './repositories/PublisherConfig.js';
|
|
30
|
+
export { ANY_PUBLISHER, checkPackageUrlTemplates, checkPackageUrlTemplate, packageUrlTemplateFor, fillPackageUrlTemplate, } from './repositories/PackageUrlTemplates.js';
|
|
31
|
+
export type { PackageUrlTemplates } from './repositories/PackageUrlTemplates.js';
|
|
30
32
|
export { findDerivation } from './derivation/index.js';
|
|
31
33
|
export type { DerivationEntityUri, TransformationReferenceTuple, DerivationLookupResult, } from './derivation/index.js';
|
|
32
34
|
export { canonicalForm, canonicalHash, CANONICAL_FORM_VERSION, Carrier, carrierOf, } from './canonical/index.js';
|
|
@@ -39,7 +41,7 @@ export type { AuthenticatedFetchFn, AuthChallenge, Credential, CredentialAnswer,
|
|
|
39
41
|
export { kanonakFetch, setKanonakUserAgent, getKanonakUserAgent, KANONAK_USER_AGENT, } from './http/kanonakFetch.js';
|
|
40
42
|
export { KanonakHttpError, httpError, describeResponse, retryAfterSecondsOf } from './http/HttpError.js';
|
|
41
43
|
export type { ProblemDetails } from './http/HttpError.js';
|
|
42
|
-
export { parseLockFile, serializeLockFile, computeIntegrityAsync, INTEGRITY_PREFIX, } from './lock/LockFile.js';
|
|
44
|
+
export { parseLockFile, serializeLockFile, computeIntegrityAsync, assertIntegrityAsync, INTEGRITY_PREFIX, } from './lock/LockFile.js';
|
|
43
45
|
export type { LockFile, LockEntry } from './lock/LockFile.js';
|
|
44
46
|
export { PackageBuilder, ImportBook, contentAddressedName, sanitizeName, ProducerRepository, EntitlementProducer, EntitlementDeniedError, allowAllPolicy, noopMeter, } from './producer/index.js';
|
|
45
47
|
export type { BuiltPackage, ImportEntry, IPackageProducer, ProduceResult, VersionRange, IEntitlementPolicy, IMeter, ProduceContext, PackageAddress, EntitlementDecision, RequestPrincipal, } from './producer/index.js';
|
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as ce,b as me,c as de,d as Ze,e as $e,f as er,g as rr,i as or,j as tr,k as nr,l as ar,m as ir,n as sr,o as pr,p as lr,q as cr,r as mr,s as dr}from"./chunk-MSOUPUUB.js";import{a as ur}from"./chunk-5AMN6MW7.js";import{a as qe,b as We,c as Ye,d as ze,e as Xe,f as Je,g as Qe,h as Rr,i as fr,j as yr,k as kr,l as Pr}from"./chunk-7TNZ7ICK.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 I,m as h,o as A,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 ue,b as Re,c as fe}from"./chunk-FB5QKDNM.js";import{a as ye}from"./chunk-X4V6DEZL.js";import"./chunk-SC5M74NM.js";import{A as we,B as Fe,C as Me,M as Ge,a as ke,b as Pe,c as xe,d as Ee,g as Ce,h as Se,i as ge,j as Ie,l as he,m as Ae,n as Ke,o as Oe,p as De,q as be,r as je,s as Ne,t as Te,u as Ve,v as He,w as _e,x as ve,y as Le,z as Ue}from"./chunk-Q57XCPAQ.js";import"./chunk-A224OOBZ.js";import{m as Be}from"./chunk-GXEKJFXG.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 ie,g as se,h as pe,k as le}from"./chunk-LKJVNKCN.js";import{a as l}from"./chunk-5ZRVFYCP.js";import"./chunk-PEJALHXK.js";import{a as Y,b as z,h as Q,i as Z,j as $,k as ee,ka as oe,l as re,ma as te}from"./chunk-WXUMROTA.js";import{G as ne,H as ae,a as T,b as V,c as H,d as _,e as v,g as L,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-PC3MYDGL.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,He as AmbiguousReferenceRule,M as BooleanStatement,Ye as CANONICAL_FORM_VERSION,pr as CREDENTIAL_EXPIRY_SKEW_SECONDS,tr as CREDENTIAL_HELPER_PROTOCOL_VERSION,se as Carrier,Fe as ClassDefinitionRule,Oe as ClassHierarchyCycleRule,R as CredentialError,V as DefinedKanonak,me as EdgeType,_ as EmbeddedKanonak,he as EmbeddedKanonakTypeRule,G as EmbeddedStatement,kr as EntitlementDeniedError,Pr as EntitlementProducer,de as GraphBuilder,N as HttpKanonakDocumentRepository,A as INTEGRITY_PREFIX,Je as ImportBook,Ae as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,f as KANONAK_USER_AGENT,T as Kanonak,Re as KanonakDocumentPositions,c as KanonakHttpError,le as KanonakObjectParser,Ge as KanonakObjectValidator,l as KanonakParser,x as KanonakUri,ye as KanonakUriBuilder,oe as KanonakVocabulary,q as ListStatement,Me as MarkdownLinkRule,W as MarkdownStatement,Te as NamespaceImportCycleRule,Ce as NamespacePrefixRule,ce as NodeType,F as NumberStatement,or as OAuthDiscovery,ve as ObjectPropertyValueValidationRule,xe as OntologyValidationError,ke as OntologyValidationResult,ze as PackageBuilder,Rr as ProducerRepository,Le as PropertyDomainRule,De as PropertyHierarchyCycleRule,Ue as PropertyKindRangeConsistencyRule,ue as PropertyMetadata,_e as PropertyRangeReferenceRule,be as PropertyRangeRequiredRule,ge as PropertyTypeSpecificityRule,h as PublisherConfigResolver,j as PublisherIndex,v as ReferenceKanonak,B as ReferenceStatement,we as ReservedNameShadowRule,Se as ResourceNamingRule,Y as ResourceResolver,te 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,L as Statement,w as StringStatement,je as SubClassOfReferenceRule,Ne as SubPropertyOfReferenceRule,H as SubjectKanonak,Ie as SubjectKanonakTypeRequiredRule,cr as TOKEN_ENV,dr as TokenCredentialProvider,z as TypeResolver,Ve as UnresolvedPredicateRule,Ke as UnresolvedReferenceRule,Ee as ValidationContext,Pe as ValidationSeverity,fr as allowAllPolicy,b as assertIntegrityAsync,Be as buildOntologyModel,qe as canonicalForm,We as canonicalHash,pe as carrierOf,nr as checkCredentialAnswer,ar as checkHelperAnswer,ir as checkHelperEraseAnswer,S as checkPackageUrlTemplate,C as checkPackageUrlTemplates,e as compareVersions,D as computeIntegrityAsync,Xe as contentAddressedName,lr as createCredentialedFetch,t as createVersion,d as describeResponse,I as fillPackageUrlTemplate,ur as findDerivation,o as formatVersion,k as getKanonakUserAgent,m as httpError,a as isCompatibleVersion,i as isMajorCompatible,P as kanonakFetch,rr as narrowestScope,yr as noopMeter,Ze as normalizeHost,g as packageUrlTemplateFor,K as parseLockFile,$e as parseScope,n as parseVersionString,fe as parseWithPositions,sr as parseWwwAuthenticate,s as pickHighestDocument,J as referenceUris,u as retryAfterSecondsOf,Qe as sanitizeName,er as scopeContains,O as serializeLockFile,y as setKanonakUserAgent,ae as subjectAddress,mr as tokenEnvKeyFor,X as typeReferenceUris,ne as valuesOf,r as versionsEqual,ie as walkDefinedKanonaks};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as j,d as D,e as m,i as R,l as p,m as K,n as k}from"./chunk-
|
|
1
|
+
import{c as j,d as D,e as m,i as R,l as p,m as K,n as k}from"./chunk-PC3MYDGL.js";import{c as b,g as u}from"./chunk-GGK6A6QK.js";function F(a,e,n,t){let i=g(a);if(i.length>0){let s=v(i,e,n);return s?{transformation:s.transformation,source:"instance"}:void 0}let r=new Set,o=O(a);for(;o.length>0;){let s=o.shift(),f=_(s.subject);if(r.has(f))continue;r.add(f);let l=S(t,s.subject);if(l.length===0)continue;let U=l.flatMap(g),h=v(U,e,n);if(h)return{transformation:h.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let T of l)for(let P of $(T))o.push(P)}let c={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!r.has(_(c))){let s=S(t,c).flatMap(g),f=v(s,e,n);if(f)return{transformation:f.transformation,source:c}}}function g(a){let e=[];for(let n of a.statement)if(n instanceof k&&d(n,"kanonak.org","derivation","derivations"))for(let t of n.object??[]){if(!(t instanceof D))continue;let i=x(t);i&&e.push(i)}return e}function v(a,e,n){let t=a.filter(o=>E(o.format,e)&&E(o.variant,n));if(t.length<=1)return t[0];let i=t[0].transformation,r=t[0];for(let o of t){let c=o.transformation;if(c.publisher!==i.publisher||c.package_!==i.package_||c.name!==i.name)continue;let s=u(r.transformation.version),f=u(c.version);s&&f&&b(f,s)>0&&(r=o)}return r}function x(a){let e,n,t;for(let i of a.statement)i instanceof p?d(i,"kanonak.org","derivation","format")?e=y(i):d(i,"kanonak.org","derivation","variant")&&(n=y(i)):i instanceof K&&d(i,"kanonak.org","derivation","transformation")&&(t=C(i.object));if(!(!e||!t))return n||(n={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:e,variant:n,transformation:t}}function C(a){let e,n,t,i;for(let r of a.statement){if(!(r instanceof R))continue;let o=r.predicate?.subject?.name;o==="publisher"?e=r.object:o==="package"?n=r.object:o==="version"?t=r.object:o==="name"&&(i=r.object)}if(!(!e||!n||!t||!i))return{publisher:e,package_:n,version:t,name:i}}function O(a){let e=[];for(let n of a.statement)n instanceof p&&n.predicate?.subject?.name==="type"&&n.object instanceof m&&e.push(n.object);return e}function $(a){let e=[];for(let n of a.statement)if(n instanceof p){if(n.predicate?.subject?.name!=="subClassOf")continue;n.object instanceof m&&e.push(n.object)}else if(n instanceof k){if(n.predicate?.subject?.name!=="subClassOf")continue;for(let t of n.object??[])t instanceof m&&e.push(t)}return e}function S(a,e){let n=[];for(let t of a){if(!(t instanceof j)||t.name!==e.name)continue;(t.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(t)}return n.sort((t,i)=>{let r=u((t.namespace||"").split("@")[1]??""),o=u((i.namespace||"").split("@")[1]??"");return!r||!o?0:b(o,r)}),n}function d(a,e,n,t){let i=a.predicate?.subject;return i?i.publisher===e&&i.package_===n&&i.name===t:!1}function y(a){let e=a.object.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}function E(a,e){return a.publisher===e.publisher&&a.package_===e.package_&&a.name===e.name}function _(a){return`${a.publisher}/${a.package_}/${a.name}`}export{F as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./chunk-F67UH4FD.js";import{a as l,b as h}from"./chunk-
|
|
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 +1 @@
|
|
|
1
|
-
import{g as U,k as B}from"./chunk-
|
|
1
|
+
import{g as U,k as B}from"./chunk-LKJVNKCN.js";import{a as K}from"./chunk-5ZRVFYCP.js";import{ga as _}from"./chunk-WXUMROTA.js";import{J as N,b as E,c as d,d as m,e as p,f as R,h as $,i as A,j as v,k as S,l as V,m as D,n as g}from"./chunk-PC3MYDGL.js";import{b as C,e as l,l as j}from"./chunk-GGK6A6QK.js";import*as P from"js-yaml";import{canonicalForm as Y,canonicalHash as ee}from"@kanonak-protocol/canonical";function k(n){return typeof n=="object"&&n!==null&&Array.isArray(n.subjects)}import{CANONICAL_FORM_VERSION as Pe}from"@kanonak-protocol/canonical";function ke(n){return Y(k(n)?n:F(n))}function O(n){return ee(k(n)?n:F(n))}function F(n){let e=[];for(let t of n)t instanceof d&&e.push({uri:se(t),statements:h(t.statement)});return{subjects:e}}function h(n){let e=[];for(let t of n){let r=ie(t);if(!r)continue;if(t instanceof g&&ne(t.predicate.subject)){e.push(...re(t,r));continue}let o=oe(t);o&&e.push({predicate:r,value:o})}return e}function ne(n){let e=_("type");return e!==void 0&&n.name==="type"&&n.publisher===e.publisher&&n.package_===e.package_}var H=new TextEncoder;function te(n,e){let t=H.encode(n),r=H.encode(e),o=Math.min(t.length,r.length);for(let a=0;a<o;a++)if(t[a]!==r[a])return t[a]-r[a];return t.length-r.length}function re(n,e){let t=[];for(let r of n.object){if(!(r instanceof p))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(b(r))}t.sort(te);for(let r=1;r<t.length;r++)if(t[r-1]===t[r])throw new Error(`canonicalForm: duplicate type ${t[r]} in a multi-valued type statement`);return t.map(r=>({predicate:e,value:{ref:r}}))}function oe(n){if(n instanceof $&&n.carrier)return{lit:n.lexical??String(n.object),datatype:z(n.carrier)};if(n instanceof A)return{raw:n.object};if(n instanceof v)return{raw:n.lexical??String(n.object)};if(n instanceof S)return{raw:n.lexical??String(n.object)};if(n instanceof V)return{ref:b(n.object)};if(n instanceof D)return M(n.object);if(n instanceof g)return{list:n.object.map(ae)}}function M(n){let e=h(n.statement);return n.name&&n.name.length>0?{embed:{name:n.name,statements:e}}:{embed:{statements:e}}}function ae(n){if(n instanceof p)return{ref:b(n)};if(n instanceof m)return M(n);if(n instanceof R){if(n.carrier)return{lit:n.lexical??String(n.value),datatype:z(n.carrier)};let e=n.value;if(typeof e=="string")return{raw:e};if(typeof e=="number")return{raw:String(e)};if(typeof e=="boolean")return{raw:String(e)}}if(n instanceof E)return{embed:{statements:h(n.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${n.constructor?.name??typeof n}); add canonicalization support before hashing data that contains it`)}function z(n){return n===U.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${n}`}function ie(n){let e=n.predicate;if(e)return L(e.subject)}function se(n){let e=n.namespace??"",t=n.name??"";return`${e}/${t}`}function b(n){return L(n.subject)}function L(n){let e=n.version;return e&&typeof e.major=="number"?`${n.publisher}/${n.package_}@${e.major}.${e.minor}.${e.patch}/${n.name}`:`${n.publisher}/${n.package_}/${n.name}`}import{VersionOperator as T}from"@kanonak-protocol/types/document/models/enums";var ce="0.0.0",w=class{constructor(e,t=new K,r){this.repository=e;this.parser=t;this.objectParser=r??new B(this.parser)}repository;parser;objectParser;imports(){return new f}serializeValue(e,t){return G(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),r=await this.hashBody(e.publisher,t,e.body),o=Z(r),a={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(a[e.contentHashProperty]=r),Object.assign(a,e.header??{}),a.imports=t;let i={[o]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:W(s),contentHash:r,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),r={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),r[e.contentHashProperty]=o),Object.assign(r,e.header??{}),r.imports=t;let a={[e.name]:r,...e.body},i=this.dump(a),s={yaml:i,byteCount:W(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return P.dump(e,{lineWidth:-1})}async hashBody(e,t,r){let o={[q]:{type:"EphemeralPackage",publisher:e,imports:t},...r},a=this.parser.parse(P.dump(o,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new N(a,this.repository))).filter(u=>u instanceof d&&u.namespace===i&&u.name!==q);for(let u of c)u.namespace="ephemeral";return O(c)}},q="__pkgbuilder_probe__";function W(n){return new TextEncoder().encode(n).length}function Z(n){let e="sha256:",t=n.startsWith(e)?e.length:0;return`q-${n.slice(t,t+16)}`}var f=class{byKey=new Map;aliases=new Set;ensure(e,t,r,o,a=T.Major){let i=`${e}/${t}@${r}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(i,{publisher:e,package_:t,version:r,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,l(e.version),e.package_)}.${e.name}`}refLatest(e,t,r,o){return`${this.ensure(e,t,ce,o??t,T.Any)}.${r}`}toImports(){let e=new Map;for(let r of this.byKey.values()){let o=e.get(r.publisher)??[];o.push(r),e.set(r.publisher,o)}return[...e.keys()].sort().map(r=>({publisher:r,packages:e.get(r).sort((o,a)=>o.package_<a.package_?-1:1).map(o=>({package:o.package_,match:C(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=J(e)||"pkg",r=t,o=2;for(;this.aliases.has(r);)r=`${t}${o++}`;return this.aliases.add(r),r}};function G(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof p)return e.ref(n.subject);if(Array.isArray(n)){let t=n.map(r=>G(r,e)).filter(r=>r!==void 0);return t.length>0?t:void 0}if(n instanceof m)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(ue(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function J(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function ue(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var I=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(r=>r.canProduce(e,t))}async produceCached(e,t,r,o){let a=`${t}/${r}@${l(o)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(t,r,o);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,t){let r=this.producerFor(e,t.packageName);if(!r)return null;let o={operator:t.versionOperator,version:t.version},a=await r.resolveVersion(e,t.packageName,o);return a?this.produceCached(r,e,t.packageName,a):null}async getDocumentAsync(e){let t;try{t=j(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let r=this.producerFor(t.publisher,t.package_);return r?this.produceCached(r,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(r=>{let o=r.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var Q={async authorize(){return{allowed:!0}}},X={async record(){}},y=class extends Error{constructor(t,r){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${r?`: ${r}`:""}`);this.address=t;this.reason=r;this.name="EntitlementDeniedError"}address;reason},x=class{inner;ctx;policy;meter;constructor(e,t,r=Q,o=X){this.inner=e,this.ctx=t,this.policy=r,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,r){return await this.assertAllowed({publisher:e,package_:t,version:r.version}),this.inner.resolveVersion(e,t,r)}async produce(e,t,r){let o={publisher:e,package_:t,version:r};await this.assertAllowed(o);let a=await this.inner.produce(e,t,r);return await this.meter.record(this.ctx,o,a),a}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new y(e,t.reason)}};export{ke as a,O as b,Pe as c,w as d,Z as e,f,J as g,I as h,Q as i,X as j,y as k,x as l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as D}from"./chunk-F67UH4FD.js";import{b as y,e as m}from"./chunk-
|
|
1
|
+
import{b as D}from"./chunk-F67UH4FD.js";import{b as y,e as m}from"./chunk-GGK6A6QK.js";function k(t){let e=t.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}function v(t){let e=t.metadata?.namespace_;if(e)return e.version?`${e.publisher}/${e.package_}@${m(e.version)}`:`${e.publisher}/${e.package_}`}async function I(t,e,n={}){let o=new Set,u=new Set,a=[...t];for(;a.length>0;){let s=a.shift(),l=k(s),i=v(s);if(!l||!i||u.has(i))continue;u.add(i),o.add(l),n.onDocument?.(s);let p=s.metadata?.imports;if(p)for(let[g,h]of Object.entries(p))for(let r of h){if(D(r))continue;let c=null,d="no-compatible-version";try{c=await e.getHighestCompatibleVersionAsync(g,r)}catch{d="resolution-error"}c?a.push(c):n.onUnresolvedEdge?.({fromNamespace:i,publisher:g,packageName:r.packageName,constraint:`${y(r.versionOperator)}${m(r.version)}`,reason:d})}}return o}var f=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let o=k(n);return o!==void 0&&this.scope.has(o)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};export{I as a,f as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{k as $}from"./chunk-
|
|
1
|
+
import{k as $}from"./chunk-LKJVNKCN.js";import{c as l,d as u,e as b,f as C,g as a,ka as U}from"./chunk-WXUMROTA.js";import{c as S,d as j,e as O,f as x,i as I,j as T,k as g,l as v,m as L,n as q}from"./chunk-PC3MYDGL.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let r=b(e);return this.all.has(r)?!1:(this.all.add(r),this.tripleList.push(e),h(this.byPIdx,e.p,e),h(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&h(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let r=this.byPIdx.get(e);return r?r.slice():[]}bySubjectPredicate(e,r){let t=this.bySPIdx.get(`${e}|${r}`);return t?t.slice():[]}byPredicateObject(e,r){let t=this.byPOIdx.get(`${e}|${r}`);return t?t.slice():[]}subjectsWithPredicateObject(e,r){let t=this.byPOIdx.get(`${e}|${r}`);if(!t)return[];let s=new Set;for(let n of t)s.add(n.s);return Array.from(s)}uriObjectsOf(e,r){let t=this.bySPIdx.get(`${e}|${r}`);if(!t)return[];let s=new Set;for(let n of t)n.o.kind==="uri"&&s.add(n.o.key);return Array.from(s)}hasUri(e,r,t){return this.all.has(`${e}|${r}|u:${t}`)}hasTriple(e,r,t){return this.all.has(`${e}|${r}|${C(t)}`)}};function h(o,e,r){let t=o.get(e);t?t.push(r):o.set(e,[r])}var _={name:"rdfs2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.domain)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},E={name:"rdfs3",apply(o,e){let r=!1;for(let t of o.byPredicate(e.range)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))i.o.kind==="uri"&&o.add(a(i.o.key,e.type,n))&&(r=!0)}return r}},A={name:"rdfs5",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subPropertyOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.bySubjectPredicate(n,e.subPropertyOf))i.o.kind==="uri"&&o.add(a(s,e.subPropertyOf,i.o.key))&&(r=!0)}return r}},V={name:"rdfs7",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subPropertyOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(s)){let p={s:i.s,p:n,o:i.o};o.add(p)&&(r=!0)}}return r}},W={name:"rdfs9",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subClassOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},F={name:"rdfs11",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subClassOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.bySubjectPredicate(n,e.subClassOf))i.o.kind==="uri"&&o.add(a(s,e.subClassOf,i.o.key))&&(r=!0)}return r}},k=[_,E,A,V,W,F];var N={name:"prp-trp",apply(o,e){let r=!1,t=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let s of t){let n=o.byPredicate(s);for(let i of n){if(i.o.kind!=="uri")continue;let p=i.o.key;for(let c of o.bySubjectPredicate(p,s))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(a(i.s,s,c.o.key))&&(r=!0)}}return r}},D={name:"prp-symp",apply(o,e){let r=!1,t=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let s of t)for(let n of o.byPredicate(s))n.o.kind==="uri"&&o.add(a(n.o.key,s,n.s))&&(r=!0);return r}},M={name:"prp-inv1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.inverseOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))i.o.kind==="uri"&&o.add(a(i.o.key,n,i.s))&&(r=!0)}return r}},z={name:"prp-inv2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.inverseOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(a(i.o.key,s,i.s))&&(r=!0)}return r}},B={name:"prp-eqp1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentProperty)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(s))o.add({s:i.s,p:n,o:i.o})&&(r=!0)}return r}},H={name:"prp-eqp2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentProperty)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(n))o.add({s:i.s,p:s,o:i.o})&&(r=!0)}return r}},G={name:"cax-eqc1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentClass)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},J={name:"cax-eqc2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentClass)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,n))o.add(a(i.s,e.type,s))&&(r=!0)}return r}},Q={name:"eq-rep-s",apply(o,e){let r=!1;for(let t of o.byPredicate(e.sameAs)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n){for(let i of o.snapshot())i.s===s&&o.add({s:n,p:i.p,o:i.o})&&(r=!0);for(let i of o.snapshot())i.s===n&&o.add({s,p:i.p,o:i.o})&&(r=!0)}}return r}},X={name:"eq-rep-o",apply(o,e){let r=!1;for(let t of o.byPredicate(e.sameAs)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===s?o.add(a(i.s,i.p,n))&&(r=!0):i.o.key===n&&o.add(a(i.s,i.p,s))&&(r=!0))}return r}},K=[N,D,M,z,B,H,G,J,Q,X];var y=class{constructor(e,r){this.store=e;this.vocabulary=r}store;vocabulary;getInstancesOfClass(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,r)}getSubclasses(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,r).filter(s=>s!==r)}getSuperclasses(e){let r=f(e);return this.store.uriObjectsOf(r,this.vocabulary.subClassOf).filter(t=>t!==r)}getTypesOfIndividual(e){return this.store.uriObjectsOf(f(e),this.vocabulary.type)}isInstanceOf(e,r){return this.store.hasUri(f(e),this.vocabulary.type,f(r))}getPropertyClosure(e){let r=f(e),t={},s=new Map;for(let n of this.store.byPredicate(r)){if(n.o.kind!=="uri")continue;let i=s.get(n.s);i||(i=new Set,s.set(n.s,i),t[n.s]=[]),i.has(n.o.key)||(i.add(n.o.key),t[n.s].push(n.o.key))}return t}getPropertyClosures(e){let r={};for(let t of e)r[f(t)]=this.getPropertyClosure(t);return r}triples(){return this.store.snapshot()}size(){return this.store.size()}};function f(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var P=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new U,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let r=new d,s=await new $().parseKanonaks(e),n=new R;for(let c of s)if(c instanceof S){let m=Y(c);if(!m)continue;for(let w of c.statement)this.emitStatement(m,w,r,n)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let p=0;for(;p<this.maxIterations;){let c=!1;for(let m of i)m.apply(r,this.vocabulary)&&(c=!0);if(!c)break;p++}return new y(r,this.vocabulary)}emitStatement(e,r,t,s){let n=Z(r);if(n){if(r instanceof I){t.add({s:e,p:n,o:{kind:"literal",lexical:r.object,datatype:"string"}});return}if(r instanceof T){t.add({s:e,p:n,o:{kind:"literal",lexical:String(r.object),datatype:"number"}});return}if(r instanceof g){t.add({s:e,p:n,o:{kind:"literal",lexical:String(r.object),datatype:"boolean"}});return}if(r instanceof v){let i=l(r.object.subject);t.add(a(e,n,i));return}if(r instanceof L){let i=s.next();t.add({s:e,p:n,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r.object,t,s);return}if(r instanceof q){for(let i of r.object??[])this.emitListItem(e,n,i,t,s);return}}}emitListItem(e,r,t,s,n){if(t instanceof O)s.add(a(e,r,l(t.subject)));else if(t instanceof j){let i=n.next();s.add({s:e,p:r,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t,s,n)}else if(t instanceof x){let i=typeof t.value=="number"?"number":typeof t.value=="boolean"?"boolean":"string";s.add({s:e,p:r,o:{kind:"literal",lexical:String(t.value),datatype:i}})}}emitEmbedded(e,r,t,s){let n=`_:${e}`;for(let i of r.statement)this.emitStatement(n,i,t,s)}},R=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",r=e.indexOf("@"),t=r===-1?e:e.substring(0,r),s=t.indexOf("/");if(s===-1)return null;let n=t.substring(0,s),i=t.substring(s+1);return!n||!i||!o.name?null:u(n,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,P as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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,3 +1,3 @@
|
|
|
1
|
-
import{j as A}from"./chunk-
|
|
1
|
+
import{j as A}from"./chunk-LKJVNKCN.js";import{a as E}from"./chunk-5ZRVFYCP.js";import{na as $}from"./chunk-WXUMROTA.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-PC3MYDGL.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as l}from"./chunk-FUUTGGJS.js";import{VersionOperator as s}from"@kanonak-protocol/types/document/models/enums";function x(e){switch(e){case"=":return s.Exact;case"~":return s.Compatible;case"^":return s.Major;case"*":return s.Any;default:return s.Compatible}}function d(e){switch(e){case s.Exact:return"=";case s.Compatible:return"~";case s.Major:return"^";case s.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 m(e,r){return e.major===r.major&&e.minor===r.minor&&e.patch===r.patch}function f(e){return`${e.major}.${e.minor}.${e.patch}`}function g(e,r,o){let n=`${e}.${r}.${o}`;return{major:e,minor:r,patch:o,toString:()=>n,equals:t=>t?.major===e&&t?.minor===r&&t?.patch===o,getHashCode:()=>e<<20|r<<10|o,compareTo:t=>e!==t.major?e-t.major:r!==t.minor?r-t.minor:o-t.patch}}function y(e){let r=/^(\d+)\.(\d+)\.(\d+)$/.exec(e);return r?g(Number(r[1]),Number(r[2]),Number(r[3])):null}function k(e,r){return c(e,r)>=0&&e.major===r.major&&e.minor===r.minor}function h(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,r){switch(r.versionOperator){case s.Exact:return m(e,r.version);case s.Compatible:return k(e,r.version);case s.Major:return h(e,r.version);case s.Any:return c(e,r.minVersion)>=0;default:return!1}}function K(e,r={}){let{requestedVersion:o}=r;if(e.length===0)return{chosen:null,alternatives:[],multipleVersionsPresent:!1,exactRequestedVersionMissing:!!o};if(o){let t=e.find(i=>{let a=i.metadata.namespace_?.version;return!!a&&f(a)===o});return t?{chosen:t,alternatives:e.filter(i=>i!==t),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((t,i)=>{let a=t.metadata.namespace_?.version,u=i.metadata.namespace_?.version;return!a&&!u?0:a?u?c(u,a):-1:1});return{chosen:n[0],alternatives:n.slice(1),multipleVersionsPresent:!0,exactRequestedVersionMissing:!1}}function M(e){if(!e||e.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let r=e.trim(),o=r.split("/");if(o.length===1){let n=o[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(o.length===2){let[n,t]=o;if(!n||!t)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher/package[@version].`);let i=t.indexOf("@");if(i===-1)return{kind:"package",publisher:n,package_:t};let a=t.substring(0,i),u=t.substring(i+1);if(!a||!u)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher/package[@version].`);let p=V(u);return{kind:"package",publisher:n,package_:a,version:p}}return{kind:"resource",uri:l.parse(r)}}function C(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 V(e){let r=e.split(".").map(Number);return b(r[0]||0,r[1]||0,r[2]||0)}function b(e,r,o){return{major:e,minor:r,patch:o,toString:()=>`${e}.${r}.${o}`,equals:n=>!n||typeof n!="object"?!1:n.major===e&&n.minor===r&&n.patch===o,getHashCode:()=>e<<20|r<<10|o,compareTo:n=>e!==n.major?e-n.major:r!==n.minor?r-n.minor:o-n.patch}}export{x as a,d as b,c,m as d,f as e,g as f,y as g,k as h,h as i,$ as j,K as k,M as l,C as m};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as lt}from"./chunk-6VIUXP4N.js";import{e as ke,f as u,k as Sn}from"./chunk-22DSABP6.js";import{a as ut}from"./chunk-7JBKOJB4.js";import{a as yt}from"./chunk-PEJALHXK.js";import{$ as kt,_ as gt,ma as tn,na as we,oa as an,pa as $n,ta as bt}from"./chunk-NUTHBBDZ.js";import{A as oe,B as pt,C as un,D as Ye,E as xe,F as Ue,G as mt,H as Mn,I as vn,L as ht,b as Te,c as Y,d as D,e as O,i as ae,j as he,k as ge,l as J,m as le,n as ue,o as Ne,r as H,s as re,t as dt,u as ft,v as je,w as Ee,x as _,z as Fe}from"./chunk-D4QGPMRW.js";import{a as yn}from"./chunk-FUUTGGJS.js";import{c as hn,d as it,e as bn,g as ct}from"./chunk-QILEJIFU.js";import{ExpressionError as La,evaluates as Ca,validateMatchesPattern as Ua}from"@kanonak-protocol/expression";var q=class extends Error{constructor(n,t){super(`${n} (at ${t})`);this.path=t}path};function gi(r,e){let n=r.name,t=Wa(e),a={catalog:e,depth:0};if(_(r,u.InstanceTransformation))return Oa(r,n,a,t);if(_(r,u.SetTransformation))return Ia(r,n,a,t);throw new q("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function Oa(r,e,n,t){return{kind:"instance",name:r.name,inputPattern:Kt(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:Rt(r,`${e}.outputs`),overrides:Et(r,`${e}.formatOverrides`,n),fragments:t}}function Ia(r,e,n,t){let a=Pe(r,u.partitionBy);return{kind:"set",name:r.name,inputPattern:Kt(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:Rt(r,`${e}.outputs`),overrides:Et(r,`${e}.formatOverrides`,n),partitionBy:a,fragments:t}}function Kt(r,e){let n=xt(r,u.inputPattern);if(!n)throw new q("inputPattern is required",e);return Ta(n,`${e}.inputPattern`)}function Ta(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 J)t.push(Hn(o.object.subject));else if(o instanceof ue)for(let i of o.object)i instanceof O&&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(vt(i,`${e}.sortBy[${s++}]`));else o instanceof le&&a.push(vt(o.object,`${e}.sortBy[${s++}]`));return{matchesClass:n,requires:t,sortBy:a}}function vt(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 He(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 O){let c=Fe(t.catalog,a.item.subject);if(!c)throw new q(`references '${H(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 He(r,e,n){if(r instanceof Y){let t=we(r),a=t?H(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 $t(r,a,{...n,visiting:new Set([...s,a])})}return $t(r,e,n)}function $t(r,e,n){if(_(r,u.StringLiteral))return{kind:"string-literal",value:be(r,u.stringLiteral,e)};if(_(r,u.IntegerLiteral))return{kind:"integer-literal",value:jt(r,u.integerLiteral,e)};if(_(r,u.DecimalLiteral))return{kind:"decimal-literal",value:jt(r,u.decimalLiteral,e)};if(_(r,u.BooleanLiteral))return{kind:"boolean-literal",value:Qa(r,u.booleanLiteral,e)};if(_(r,u.VarRef))return{kind:"var-ref",varName:be(r,u.varName,e)};if(_(r,u.PropertyRead))return{kind:"property-read",source:w(r,u.readSource,`${e}.readSource`,n),readProp:De(r,u.readProp,e,"readProp")};if(_(r,u.Traverse))return{kind:"traverse",source:w(r,u.traverseSource,`${e}.traverseSource`,n),through:De(r,u.through,e,"through"),step:w(r,u.step,`${e}.step`,n)};if(_(r,u.BuildAstNode))return{kind:"build-ast-node",astClass:De(r,u.astClass,e,"astClass"),set:Ma(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:Va(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:De(r,u.refTo,e,"refTo")};if(_(r,u.DisplayLabel))return{kind:"display-label",labelTarget:De(r,u.labelTarget,e,"labelTarget"),labelSource:De(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:Da(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:De(r,u.renderProp,e,"renderProp"),format:Ba(r,e)};if(_(r,u.IsSet))return{kind:"is-set",check:w(r,u.checkExpr,`${e}.checkExpr`,n)};if(_(r,u.CallFragment))return Ga(r,e,n);if(_(r,u.Join))return{kind:"join",source:w(r,u.source,`${e}.source`,n),separator:be(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:be(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:be(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:be(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:be(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:be(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:qa(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=Be(r,u.currencyCode);return{kind:"number-format",source:w(r,u.numberSource,`${e}.numberSource`,n),style:Ha(r,e),...a!==void 0?{fractionDigits:a}:{},...s!==void 0?{currencyCode:s}:{}}}let t=Aa.find(a=>_(r,a.type));if(t){let a=H(t.type);if(!Ca(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:be(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:be(r,u.firstVar,e),secondVar:be(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:be(r,u.stateVar,e),elementVar:be(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=be(r,u.pattern,e);try{Ua(a)}catch(s){throw s instanceof La?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:be(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 Fa=[u.arithLeft,u.arithRight],Pa=[u.value],Aa=[...[u.Add,u.Subtract,u.Multiply,u.Divide,ke.Power,ke.Modulo,ke.Minimum,ke.Maximum].map(r=>({type:r,operands:Fa})),...[u.Abs,u.Negate,ke.Exp,ke.Ln,ke.Log10,ke.Sqrt,ke.Floor,ke.Ceil,ke.Round,ke.Sign].map(r=>({type:r,operands:Pa})),{type:ke.Clip,operands:[ke.clipValue,ke.clipLower,ke.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 He(a,n,t)}function Va(r,e,n,t){let a=Gn(r,e,n,t);if(a)return He(a,n,t)}function Nn(r,e,n,t){return qn(r,e,n,t).map((a,s)=>He(a,`${n}[${s}]`,t))}function Ma(r,e,n){return qn(r,u.set,e,n).map((t,a)=>Na(t,`${e}[${a}]`,n))}function Na(r,e,n){return{field:De(r,u.field,e,"field"),value:w(r,u.bindValue,`${e}.bindValue`,n)}}function Da(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 Ba(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 St=new Set(["decimal","percent","basis-points","currency","compact"]);function Ha(r,e){let n=Be(r,u.numberStyle);if(n===void 0)throw new q("numberStyle is required",e);if(!St.has(n))throw new q(`Unknown numberStyle "${n}"; supported: ${[...St].join(", ")}`,e);return n}var wt=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function qa(r,e){let n=Be(r,u.dateFormat);if(!n)throw new q("dateFormat is required",e);if(!wt.has(n))throw new q(`Unknown dateFormat "${n}"; supported: ${[...wt].join(", ")}`,e);return n}function Ga(r,e,n){let t=Pe(r,u.fragmentRef);if(!t)throw new q("fragmentRef is required",e);if(!Ya(n.catalog,t))throw new q(`ExpressionFragment not found: ${t.publisher}/${t.package_}/${t.name}`,e);return{kind:"call-fragment",fragmentKey:za(t)}}function za(r){return`${r.publisher}/${r.package_}/${r.name}`}function Wa(r){let e=new Map,n=[];for(let t of r){if(!(t instanceof Y)||!_(t,u.ExpressionFragment))continue;let a=xt(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=He(t.bodyEmb,`fragment(${t.pubPkgName})`,{catalog:r,depth:0});e.set(t.key,a)}return e}function Ya(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 Rt(r,e){let n=new Set;for(let t of Le(r,u.outputs))if(t instanceof J)n.add(t.object.subject.name);else if(t instanceof ue)for(let a of t.object)a instanceof O&&n.add(a.subject.name);if(n.size===0)throw new q("outputs is required (at least one OutputFormat)",e);return n}function Et(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]=_t(o,`${e}[${a++}]`);t.set(i,c)}}else if(s instanceof le){let[o,i]=_t(s.object,`${e}[${a++}]`);t.set(o,i)}return t}function _t(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=Be(c,u.fromKey),d=Be(c,u.toKey);l&&d&&a.set(l,d)}}else if(i instanceof le){let c=i.object,l=Be(c,u.fromKey),d=Be(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 Xa(r){return r.predicate?.subject}function Le(r,e){let n=[];for(let t of r.statement){let a=Xa(t);a&&re(a,e)&&n.push(t)}return n}function xt(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 J)return Hn(n.object.subject)}function Be(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 he)return n.object}function Bn(r,e){for(let n of Le(r,e))if(n instanceof ge)return n.object}function be(r,e,n){let t=Be(r,e);if(t===void 0)throw new q(`${e.name} (string) is required`,n);return t}function jt(r,e,n){let t=Dn(r,e);if(t===void 0)throw new q(`${e.name} (number) is required`,n);return t}function Qa(r,e,n){let t=Bn(r,e);if(t===void 0)throw new q(`${e.name} (boolean) is required`,n);return t}function De(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 Xe="kanonak.org",It="look",dn="core-rdf",Tt={publisher:Xe,package_:It,name:"displayLabel"},Ft={publisher:Xe,package_:It,name:"displaySummary"},Ja={publisher:Xe,package_:dn,name:"subClassOf"},Za={publisher:Xe,package_:dn,name:"label"},er={publisher:Xe,package_:dn,name:"comment"},Lt=new yn(Xe,dn,"Resource"),nr=8;function G(r,e){return Pt(r,e,new Set)}function Pt(r,e,n){let t=Ot(r,e,Tt)??Za,a=Ot(r,e,Ft)??er,s=Ct(r,e,t,n)??e.name,o=Ct(r,e,a,n);return{label:s,summary:o}}function Ct(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 he||a instanceof ge)return String(a.object);if(a instanceof J)return Ut(r,a.object.subject,t);if(a instanceof ue){let o=[];for(let i of a.object??[])if(i instanceof O){let c=Ut(r,i.subject,t);c&&o.push(c)}if(o.length>0)return o.join(", ")}return}}}function Ut(r,e,n){let t=H(e);if(n.has(t)||n.size>=nr)return e.name;let[a]=oe(r,e);if(!a)return e.name;let s=new Set(n);return s.add(t),Pt(r,a,s).label}function Ot(r,e,n){let t=Ue(e,n);if(t)return t;let a=new Set,s=je(e,tr);for(;s.length>0;){let o=s.shift(),i=H(o);if(a.has(i))continue;a.add(i);let c=oe(r,o);for(let l of c){let d=Ue(l,n);if(d)return d}for(let l of c)s.push(...je(l,Ja))}if(!a.has(H(Lt)))for(let o of oe(r,Lt)){let i=Ue(o,n);if(i)return i}}var tr={publisher:Xe,package_:dn,name:"type"};var ar="kanonak.org",Qe=(r,e)=>({publisher:ar,package_:r,name:e}),rr=Qe("look","source"),At=Qe("look","connectors"),sr=Qe("look","relation"),or=Qe("look","lineStyle"),ir=Qe("look","participants"),cr=Qe("core-owl","SymmetricProperty"),lr=Qe("core-owl","inverseOf"),Vt=new Set(["solid","dotted","open","thick"]);function Mt(r){return Ue(r,rr)}function Nt(r,e){let n=mt(e,At),t=n?[n]:Mn(e,At),a=[];for(let s of t){if(!(s instanceof D))continue;let o=Ue(s,sr);if(!o)continue;let i=xe(s,or),c=i!==void 0&&Vt.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 Dt(r,e){let n=[];for(let t of Mn(e,ir)){if(!(t instanceof O))continue;let a=oe(r,t.subject)[0];a&&n.push(a)}return n}function fn(r,e,n){for(let t of ft(e))if(re(t,n)||an(r,t).some(a=>re(a,n)))return!0;return!1}function Bt(r,e,n){let t=!!e.subject&&fn(r,e.subject,cr);return e.declaredStyle?{style:e.declaredStyle,undirected:t}:e.subject&&je(e.subject,lr).some(s=>n.some(o=>re(s,o.relation)))?{style:"dotted",undirected:t}:{style:"solid",undirected:t}}function zn(r,e,n){let t=Mt(n);if(!t)return _n("the band declares no look.source");let a=Nt(r,n);if(a.length===0)return _n("the band declares no look.connectors \u2014 nothing can be a message");let s=pt(e,t);if(!s)return{..._n(),sourceAbsent:!0};if(!(s instanceof Ne))return _n(`look.source ${H(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(F=>re(p,F.relation)):a,y=we(b),v=we(f),E=[],K=[];for(let F of m){let{style:L,undirected:S}=Bt(r,F,a);y&&je(f,F.relation).some(W=>H(W)===H(y))?E.push({from:f,to:b,relation:F.relation,style:L,undirected:S}):v&&je(b,F.relation).some(W=>H(W)===H(v))&&K.push({from:b,to:f,relation:F.relation,style:L,undirected:S})}let U=E.length>0?E:K;l.push(...U),U.length===0&&Ae(f)!==Ae(b)&&d.push({prev:f,next:b,selected:p}),p=void 0}f=b}let g=new Map;for(let h of Dt(r,n))g.set(Ae(h),h);for(let h of l)g.has(Ae(h.from))||g.set(Ae(h.from),h.from),g.has(Ae(h.to))||g.set(Ae(h.to),h.to);return{messages:l,gaps:d,lifelines:[...g.values()],mentions:c,strayPropertyRefs:i,sourceAbsent:!1}}function Ae(r){return`${r.namespace}/${r.name}`}function _n(r){return{messages:[],gaps:[],lifelines:[],mentions:0,strayPropertyRefs:[],sourceAbsent:!1,...r?{problem:r}:{}}}var ur="kanonak.org",dr="core-shacl",_e=r=>({publisher:ur,package_:dr,name:r}),fr=_e("NodeShape"),pr=_e("targetClass"),mr=_e("property"),gr=_e("path"),kr=_e("minCount"),hr=_e("maxCount"),br=_e("in"),yr=_e("pattern"),vr=_e("flags"),$r=_e("minLength"),Sr=_e("maxLength"),wr=_e("minInclusive"),_r=_e("maxInclusive"),jr=_e("message");function rn(r){return typeof r=="number"?r:void 0}function Kr(r){let e={},n=rn(Ye(r,kr)),t=rn(Ye(r,hr));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let a=rn(Ye(r,$r)),s=rn(Ye(r,Sr));a!==void 0&&(e.minLength=a),s!==void 0&&(e.maxLength=s);let o=rn(Ye(r,wr)),i=rn(Ye(r,_r));o!==void 0&&(e.minInclusive=o),i!==void 0&&(e.maxInclusive=i);let c=xe(r,yr);if(c!==void 0){let f=xe(r,vr);e.pattern=f!==void 0?{regex:c,flags:f}:{regex:c}}let l=Ee(r,br).map(f=>f.item).filter(f=>"literal"in f).map(f=>f.value);l.length>0&&(e.enumValues=l);let d=xe(r,jr);return d!==void 0&&(e.message=d),e}function Rr(r,e){let n=[];for(let{item:t}of Ee(e,mr))if(t instanceof D)n.push(t);else if(t instanceof O){let a=Fe(r,t.subject);a&&n.push(a)}return n}function Er(r){let e=new Map;for(let n of r){if(!(n instanceof Y)||!_(n,fr))continue;let t=Ue(n,pr);if(!t)continue;let a=H(t);for(let s of Rr(r,n)){let o=Ue(s,gr);if(!o)continue;let i=Kr(s);if(xr(s,i))continue;let c={pathKey:H(o),constraints:i},l=e.get(a);l?l.push(c):e.set(a,[c])}}return e}var Ht=new WeakMap;function pn(r){let e=Ht.get(r);return e||(e=Er(r),Ht.set(r,e)),e}function xr(r,e){return un(r,gt)||un(r,kt)?Object.keys(e).every(t=>t==="message"):!1}function Lr(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 qt(r,e,n){let t=H(n),a=!1,s={};for(let o=e.length-1;o>=0;o--){let i=r.get(H(e[o]));if(i)for(let c of i)c.pathKey===t&&(a=!0,Lr(s,c.constraints))}if(a)return s.cardinality=s.maxCount===1?"single":"list",s.required=(s.minCount??0)>=1,s}var Je="kanonak.org",Kn="core-rdf",Gt="core-xsd",Cr={publisher:Je,package_:Kn,name:"subClassOf"},zt={publisher:Je,package_:Kn,name:"label"},Wt={publisher:Je,package_:Kn,name:"comment"},Yt={publisher:Je,package_:"core-owl",name:"oneOf"},Xt=r=>r;function Ur(r,e,n){if(e.publisher===Je&&e.package_===Kn&&e.name==="Literal")return{kind:"datatype",uri:e};let a=Fe(r,e);if(a){let s=Xt(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===Je&&e.package_===Gt?{kind:"datatype",uri:e}:n==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function Or(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=Ur(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(Je,Gt,r);function Ir(r){return typeof r=="boolean"?jn("boolean"):typeof r=="number"?Number.isInteger(r)?jn("integer"):jn("decimal"):jn("string")}function Tr(r,e,n){let t=[];for(let a of vn(e,Yt,r,H(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,zt):void 0,c=s?xe(s,Wt):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:Ir(a.value)});return t}function Rn(r,e,n,t){let a=an(r,e),s=H(e);return bt(r,e).filter(i=>n?!0:i.domains.some(c=>H(c)===s)).map(i=>Or(r,i,qt(t,a,i.uri)))}async function Gi(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&&!it(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(Xt(p))))continue;let h=H(g);if(d.has(h))continue;d.add(h);let b=je(p,Cr).map(v=>({uri:v,localName:v.name})),m=xe(p,zt),y=xe(p,Wt);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,Yt)&&l.push({uri:g,localName:g.name,members:Tr(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 lt}from"./chunk-WXXZOJ4O.js";import{e as ke,f as u,k as Sn}from"./chunk-LKJVNKCN.js";import{a as ut}from"./chunk-5ZRVFYCP.js";import{a as yt}from"./chunk-PEJALHXK.js";import{$ as kt,_ as gt,ma as tn,na as we,oa as an,pa as $n,ta as bt}from"./chunk-WXUMROTA.js";import{A as un,B as Ye,C as xe,D as Ue,E as mt,F as Mn,G as vn,J as ht,b as Te,c as Y,d as D,e as O,i as ae,j as he,k as ge,l as J,m as le,n as ue,o as Ne,p as H,q as re,r as dt,s as ft,t as je,u as Ee,v as _,x as Fe,y as oe,z as pt}from"./chunk-PC3MYDGL.js";import{c as hn,d as it,e as bn,g as ct}from"./chunk-GGK6A6QK.js";import{a as yn}from"./chunk-FUUTGGJS.js";import{ExpressionError as La,evaluates as Ca,validateMatchesPattern as Ua}from"@kanonak-protocol/expression";var q=class extends Error{constructor(n,t){super(`${n} (at ${t})`);this.path=t}path};function gi(r,e){let n=r.name,t=Wa(e),a={catalog:e,depth:0};if(_(r,u.InstanceTransformation))return Oa(r,n,a,t);if(_(r,u.SetTransformation))return Ia(r,n,a,t);throw new q("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function Oa(r,e,n,t){return{kind:"instance",name:r.name,inputPattern:Kt(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:Rt(r,`${e}.outputs`),overrides:Et(r,`${e}.formatOverrides`,n),fragments:t}}function Ia(r,e,n,t){let a=Pe(r,u.partitionBy);return{kind:"set",name:r.name,inputPattern:Kt(r,e),rule:wn(r,u.rule,`${e}.rule`,n),artifactName:wn(r,u.artifactName,`${e}.artifactName`,n),outputs:Rt(r,`${e}.outputs`),overrides:Et(r,`${e}.formatOverrides`,n),partitionBy:a,fragments:t}}function Kt(r,e){let n=xt(r,u.inputPattern);if(!n)throw new q("inputPattern is required",e);return Ta(n,`${e}.inputPattern`)}function Ta(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 J)t.push(Hn(o.object.subject));else if(o instanceof ue)for(let i of o.object)i instanceof O&&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(vt(i,`${e}.sortBy[${s++}]`));else o instanceof le&&a.push(vt(o.object,`${e}.sortBy[${s++}]`));return{matchesClass:n,requires:t,sortBy:a}}function vt(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 He(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 O){let c=Fe(t.catalog,a.item.subject);if(!c)throw new q(`references '${H(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 He(r,e,n){if(r instanceof Y){let t=we(r),a=t?H(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 $t(r,a,{...n,visiting:new Set([...s,a])})}return $t(r,e,n)}function $t(r,e,n){if(_(r,u.StringLiteral))return{kind:"string-literal",value:be(r,u.stringLiteral,e)};if(_(r,u.IntegerLiteral))return{kind:"integer-literal",value:jt(r,u.integerLiteral,e)};if(_(r,u.DecimalLiteral))return{kind:"decimal-literal",value:jt(r,u.decimalLiteral,e)};if(_(r,u.BooleanLiteral))return{kind:"boolean-literal",value:Qa(r,u.booleanLiteral,e)};if(_(r,u.VarRef))return{kind:"var-ref",varName:be(r,u.varName,e)};if(_(r,u.PropertyRead))return{kind:"property-read",source:w(r,u.readSource,`${e}.readSource`,n),readProp:De(r,u.readProp,e,"readProp")};if(_(r,u.Traverse))return{kind:"traverse",source:w(r,u.traverseSource,`${e}.traverseSource`,n),through:De(r,u.through,e,"through"),step:w(r,u.step,`${e}.step`,n)};if(_(r,u.BuildAstNode))return{kind:"build-ast-node",astClass:De(r,u.astClass,e,"astClass"),set:Ma(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:Va(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:De(r,u.refTo,e,"refTo")};if(_(r,u.DisplayLabel))return{kind:"display-label",labelTarget:De(r,u.labelTarget,e,"labelTarget"),labelSource:De(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:Da(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:De(r,u.renderProp,e,"renderProp"),format:Ba(r,e)};if(_(r,u.IsSet))return{kind:"is-set",check:w(r,u.checkExpr,`${e}.checkExpr`,n)};if(_(r,u.CallFragment))return Ga(r,e,n);if(_(r,u.Join))return{kind:"join",source:w(r,u.source,`${e}.source`,n),separator:be(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:be(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:be(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:be(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:be(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:be(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:qa(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=Be(r,u.currencyCode);return{kind:"number-format",source:w(r,u.numberSource,`${e}.numberSource`,n),style:Ha(r,e),...a!==void 0?{fractionDigits:a}:{},...s!==void 0?{currencyCode:s}:{}}}let t=Aa.find(a=>_(r,a.type));if(t){let a=H(t.type);if(!Ca(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:be(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:be(r,u.firstVar,e),secondVar:be(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:be(r,u.stateVar,e),elementVar:be(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=be(r,u.pattern,e);try{Ua(a)}catch(s){throw s instanceof La?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:be(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 Fa=[u.arithLeft,u.arithRight],Pa=[u.value],Aa=[...[u.Add,u.Subtract,u.Multiply,u.Divide,ke.Power,ke.Modulo,ke.Minimum,ke.Maximum].map(r=>({type:r,operands:Fa})),...[u.Abs,u.Negate,ke.Exp,ke.Ln,ke.Log10,ke.Sqrt,ke.Floor,ke.Ceil,ke.Round,ke.Sign].map(r=>({type:r,operands:Pa})),{type:ke.Clip,operands:[ke.clipValue,ke.clipLower,ke.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 He(a,n,t)}function Va(r,e,n,t){let a=Gn(r,e,n,t);if(a)return He(a,n,t)}function Nn(r,e,n,t){return qn(r,e,n,t).map((a,s)=>He(a,`${n}[${s}]`,t))}function Ma(r,e,n){return qn(r,u.set,e,n).map((t,a)=>Na(t,`${e}[${a}]`,n))}function Na(r,e,n){return{field:De(r,u.field,e,"field"),value:w(r,u.bindValue,`${e}.bindValue`,n)}}function Da(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 Ba(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 St=new Set(["decimal","percent","basis-points","currency","compact"]);function Ha(r,e){let n=Be(r,u.numberStyle);if(n===void 0)throw new q("numberStyle is required",e);if(!St.has(n))throw new q(`Unknown numberStyle "${n}"; supported: ${[...St].join(", ")}`,e);return n}var wt=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function qa(r,e){let n=Be(r,u.dateFormat);if(!n)throw new q("dateFormat is required",e);if(!wt.has(n))throw new q(`Unknown dateFormat "${n}"; supported: ${[...wt].join(", ")}`,e);return n}function Ga(r,e,n){let t=Pe(r,u.fragmentRef);if(!t)throw new q("fragmentRef is required",e);if(!Ya(n.catalog,t))throw new q(`ExpressionFragment not found: ${t.publisher}/${t.package_}/${t.name}`,e);return{kind:"call-fragment",fragmentKey:za(t)}}function za(r){return`${r.publisher}/${r.package_}/${r.name}`}function Wa(r){let e=new Map,n=[];for(let t of r){if(!(t instanceof Y)||!_(t,u.ExpressionFragment))continue;let a=xt(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=He(t.bodyEmb,`fragment(${t.pubPkgName})`,{catalog:r,depth:0});e.set(t.key,a)}return e}function Ya(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 Rt(r,e){let n=new Set;for(let t of Le(r,u.outputs))if(t instanceof J)n.add(t.object.subject.name);else if(t instanceof ue)for(let a of t.object)a instanceof O&&n.add(a.subject.name);if(n.size===0)throw new q("outputs is required (at least one OutputFormat)",e);return n}function Et(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]=_t(o,`${e}[${a++}]`);t.set(i,c)}}else if(s instanceof le){let[o,i]=_t(s.object,`${e}[${a++}]`);t.set(o,i)}return t}function _t(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=Be(c,u.fromKey),d=Be(c,u.toKey);l&&d&&a.set(l,d)}}else if(i instanceof le){let c=i.object,l=Be(c,u.fromKey),d=Be(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 Xa(r){return r.predicate?.subject}function Le(r,e){let n=[];for(let t of r.statement){let a=Xa(t);a&&re(a,e)&&n.push(t)}return n}function xt(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 J)return Hn(n.object.subject)}function Be(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 he)return n.object}function Bn(r,e){for(let n of Le(r,e))if(n instanceof ge)return n.object}function be(r,e,n){let t=Be(r,e);if(t===void 0)throw new q(`${e.name} (string) is required`,n);return t}function jt(r,e,n){let t=Dn(r,e);if(t===void 0)throw new q(`${e.name} (number) is required`,n);return t}function Qa(r,e,n){let t=Bn(r,e);if(t===void 0)throw new q(`${e.name} (boolean) is required`,n);return t}function De(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 Xe="kanonak.org",It="look",dn="core-rdf",Tt={publisher:Xe,package_:It,name:"displayLabel"},Ft={publisher:Xe,package_:It,name:"displaySummary"},Ja={publisher:Xe,package_:dn,name:"subClassOf"},Za={publisher:Xe,package_:dn,name:"label"},er={publisher:Xe,package_:dn,name:"comment"},Lt=new yn(Xe,dn,"Resource"),nr=8;function G(r,e){return Pt(r,e,new Set)}function Pt(r,e,n){let t=Ot(r,e,Tt)??Za,a=Ot(r,e,Ft)??er,s=Ct(r,e,t,n)??e.name,o=Ct(r,e,a,n);return{label:s,summary:o}}function Ct(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 he||a instanceof ge)return String(a.object);if(a instanceof J)return Ut(r,a.object.subject,t);if(a instanceof ue){let o=[];for(let i of a.object??[])if(i instanceof O){let c=Ut(r,i.subject,t);c&&o.push(c)}if(o.length>0)return o.join(", ")}return}}}function Ut(r,e,n){let t=H(e);if(n.has(t)||n.size>=nr)return e.name;let[a]=oe(r,e);if(!a)return e.name;let s=new Set(n);return s.add(t),Pt(r,a,s).label}function Ot(r,e,n){let t=Ue(e,n);if(t)return t;let a=new Set,s=je(e,tr);for(;s.length>0;){let o=s.shift(),i=H(o);if(a.has(i))continue;a.add(i);let c=oe(r,o);for(let l of c){let d=Ue(l,n);if(d)return d}for(let l of c)s.push(...je(l,Ja))}if(!a.has(H(Lt)))for(let o of oe(r,Lt)){let i=Ue(o,n);if(i)return i}}var tr={publisher:Xe,package_:dn,name:"type"};var ar="kanonak.org",Qe=(r,e)=>({publisher:ar,package_:r,name:e}),rr=Qe("look","source"),At=Qe("look","connectors"),sr=Qe("look","relation"),or=Qe("look","lineStyle"),ir=Qe("look","participants"),cr=Qe("core-owl","SymmetricProperty"),lr=Qe("core-owl","inverseOf"),Vt=new Set(["solid","dotted","open","thick"]);function Mt(r){return Ue(r,rr)}function Nt(r,e){let n=mt(e,At),t=n?[n]:Mn(e,At),a=[];for(let s of t){if(!(s instanceof D))continue;let o=Ue(s,sr);if(!o)continue;let i=xe(s,or),c=i!==void 0&&Vt.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 Dt(r,e){let n=[];for(let t of Mn(e,ir)){if(!(t instanceof O))continue;let a=oe(r,t.subject)[0];a&&n.push(a)}return n}function fn(r,e,n){for(let t of ft(e))if(re(t,n)||an(r,t).some(a=>re(a,n)))return!0;return!1}function Bt(r,e,n){let t=!!e.subject&&fn(r,e.subject,cr);return e.declaredStyle?{style:e.declaredStyle,undirected:t}:e.subject&&je(e.subject,lr).some(s=>n.some(o=>re(s,o.relation)))?{style:"dotted",undirected:t}:{style:"solid",undirected:t}}function zn(r,e,n){let t=Mt(n);if(!t)return _n("the band declares no look.source");let a=Nt(r,n);if(a.length===0)return _n("the band declares no look.connectors \u2014 nothing can be a message");let s=pt(e,t);if(!s)return{..._n(),sourceAbsent:!0};if(!(s instanceof Ne))return _n(`look.source ${H(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(F=>re(p,F.relation)):a,y=we(b),v=we(f),E=[],K=[];for(let F of m){let{style:L,undirected:S}=Bt(r,F,a);y&&je(f,F.relation).some(W=>H(W)===H(y))?E.push({from:f,to:b,relation:F.relation,style:L,undirected:S}):v&&je(b,F.relation).some(W=>H(W)===H(v))&&K.push({from:b,to:f,relation:F.relation,style:L,undirected:S})}let U=E.length>0?E:K;l.push(...U),U.length===0&&Ae(f)!==Ae(b)&&d.push({prev:f,next:b,selected:p}),p=void 0}f=b}let g=new Map;for(let h of Dt(r,n))g.set(Ae(h),h);for(let h of l)g.has(Ae(h.from))||g.set(Ae(h.from),h.from),g.has(Ae(h.to))||g.set(Ae(h.to),h.to);return{messages:l,gaps:d,lifelines:[...g.values()],mentions:c,strayPropertyRefs:i,sourceAbsent:!1}}function Ae(r){return`${r.namespace}/${r.name}`}function _n(r){return{messages:[],gaps:[],lifelines:[],mentions:0,strayPropertyRefs:[],sourceAbsent:!1,...r?{problem:r}:{}}}var ur="kanonak.org",dr="core-shacl",_e=r=>({publisher:ur,package_:dr,name:r}),fr=_e("NodeShape"),pr=_e("targetClass"),mr=_e("property"),gr=_e("path"),kr=_e("minCount"),hr=_e("maxCount"),br=_e("in"),yr=_e("pattern"),vr=_e("flags"),$r=_e("minLength"),Sr=_e("maxLength"),wr=_e("minInclusive"),_r=_e("maxInclusive"),jr=_e("message");function rn(r){return typeof r=="number"?r:void 0}function Kr(r){let e={},n=rn(Ye(r,kr)),t=rn(Ye(r,hr));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let a=rn(Ye(r,$r)),s=rn(Ye(r,Sr));a!==void 0&&(e.minLength=a),s!==void 0&&(e.maxLength=s);let o=rn(Ye(r,wr)),i=rn(Ye(r,_r));o!==void 0&&(e.minInclusive=o),i!==void 0&&(e.maxInclusive=i);let c=xe(r,yr);if(c!==void 0){let f=xe(r,vr);e.pattern=f!==void 0?{regex:c,flags:f}:{regex:c}}let l=Ee(r,br).map(f=>f.item).filter(f=>"literal"in f).map(f=>f.value);l.length>0&&(e.enumValues=l);let d=xe(r,jr);return d!==void 0&&(e.message=d),e}function Rr(r,e){let n=[];for(let{item:t}of Ee(e,mr))if(t instanceof D)n.push(t);else if(t instanceof O){let a=Fe(r,t.subject);a&&n.push(a)}return n}function Er(r){let e=new Map;for(let n of r){if(!(n instanceof Y)||!_(n,fr))continue;let t=Ue(n,pr);if(!t)continue;let a=H(t);for(let s of Rr(r,n)){let o=Ue(s,gr);if(!o)continue;let i=Kr(s);if(xr(s,i))continue;let c={pathKey:H(o),constraints:i},l=e.get(a);l?l.push(c):e.set(a,[c])}}return e}var Ht=new WeakMap;function pn(r){let e=Ht.get(r);return e||(e=Er(r),Ht.set(r,e)),e}function xr(r,e){return un(r,gt)||un(r,kt)?Object.keys(e).every(t=>t==="message"):!1}function Lr(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 qt(r,e,n){let t=H(n),a=!1,s={};for(let o=e.length-1;o>=0;o--){let i=r.get(H(e[o]));if(i)for(let c of i)c.pathKey===t&&(a=!0,Lr(s,c.constraints))}if(a)return s.cardinality=s.maxCount===1?"single":"list",s.required=(s.minCount??0)>=1,s}var Je="kanonak.org",Kn="core-rdf",Gt="core-xsd",Cr={publisher:Je,package_:Kn,name:"subClassOf"},zt={publisher:Je,package_:Kn,name:"label"},Wt={publisher:Je,package_:Kn,name:"comment"},Yt={publisher:Je,package_:"core-owl",name:"oneOf"},Xt=r=>r;function Ur(r,e,n){if(e.publisher===Je&&e.package_===Kn&&e.name==="Literal")return{kind:"datatype",uri:e};let a=Fe(r,e);if(a){let s=Xt(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===Je&&e.package_===Gt?{kind:"datatype",uri:e}:n==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function Or(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=Ur(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(Je,Gt,r);function Ir(r){return typeof r=="boolean"?jn("boolean"):typeof r=="number"?Number.isInteger(r)?jn("integer"):jn("decimal"):jn("string")}function Tr(r,e,n){let t=[];for(let a of vn(e,Yt,r,H(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,zt):void 0,c=s?xe(s,Wt):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:Ir(a.value)});return t}function Rn(r,e,n,t){let a=an(r,e),s=H(e);return bt(r,e).filter(i=>n?!0:i.domains.some(c=>H(c)===s)).map(i=>Or(r,i,qt(t,a,i.uri)))}async function Gi(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&&!it(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(Xt(p))))continue;let h=H(g);if(d.has(h))continue;d.add(h);let b=je(p,Cr).map(v=>({uri:v,localName:v.name})),m=xe(p,zt),y=xe(p,Wt);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,Yt)&&l.push({uri:g,localName:g.name,members:Tr(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-${Jt(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&&Qt(n[a+1])){let l=Wn(s),d=Fr(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(Pr(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{i as F,o as P}from"./chunk-MD4CAJIO.js";import{a as A}from"./chunk-6VIUXP4N.js";import{a as f}from"./chunk-7JBKOJB4.js";import{c as K,g as I,j as R}from"./chunk-QILEJIFU.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 u=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return K(l,u)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let u=o.split("/"),l=u[0],h=u[1].replace("@","@")+".kan.yml";n=i.join(this.rootPath,l,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[u,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(u)===n&&l.metadata.namespace_){s=l.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 u=s.metadata.namespace_.toString();this.documentCache.set(u,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(u,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 N}from"path";function d(){let c=process.env.KANONAK_PACKAGE_CACHE;return c||N(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 B}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:B.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 V,readdirSync as $}from"fs";import{join as _}from"path";var j=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(c,e=[]){for(let t of $(c,{withFileTypes:!0}))t.isDirectory()?j.has(t.name)||C(_(c,t.name),e):t.name.endsWith(".kan.yml")&&e.push(_(c,t.name));return e}async function E(c,e=new f,t={}){let n=new A(e);for(let u of C(c))try{let l=e.parse(V(u,"utf-8")),p=l.metadata?.namespace_,h=p?.version;p&&h&&await n.saveDocumentAsync(l,`${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:(u,l,p)=>s.get(`${u}|${l}|${p}`)??null,onFetch:(u,l,p,h)=>{s.set(`${u}|${l}|${p}`,h)}},r=new P({getFromCache:a.getFromCache,onFetch:a.onFetch,...t.fetchFn?{fetchFn:t.fetchFn}:{}});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,E as i};
|
|
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};
|