@kanonak-protocol/sdk 5.24.0 → 5.26.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/browser.d.ts +2 -0
- package/dist/browser.js +1 -1
- package/dist/{chunk-AND44TIS.js → chunk-AUXSXDZB.js} +1 -1
- package/dist/{chunk-3XOXKMYB.js → chunk-CYXNYNE7.js} +1 -1
- package/dist/{chunk-DUM5Q4MH.js → chunk-D66LUZDB.js} +1 -1
- package/dist/chunk-EKSYQ6CU.js +1 -0
- package/dist/{chunk-6YX2TDI5.js → chunk-HND3PKKR.js} +1 -1
- package/dist/chunk-ITI65NHP.js +1 -0
- package/dist/{chunk-WKLSD5DQ.js → chunk-JFBPQN6T.js} +1 -1
- package/dist/chunk-P5VQEDBS.js +2 -0
- package/dist/chunk-Q3TDDWKS.js +1 -0
- package/dist/chunk-WVXOHCW2.js +2 -0
- package/dist/{chunk-5GFOZL7D.js → chunk-ZUWSZQAJ.js} +1 -1
- package/dist/graph/GraphBuilder.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/KanonakVocabulary.d.ts +3 -0
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/HttpKanonakDocumentRepository.d.ts +41 -2
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/buildLocalFirstRepository.d.ts +3 -2
- package/dist/repositories/index.d.ts +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/ResourceTypeClassifier.d.ts +8 -0
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +13 -13
- package/dist/shacl/index.d.ts +1 -0
- package/dist/shacl/uris.d.ts +1 -0
- package/dist/transformations/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-M7OWTFTC.js +0 -2
- package/dist/chunk-O6YV2SDB.js +0 -1
- package/dist/chunk-RZ4WYL2X.js +0 -2
- package/dist/chunk-USQLCG3Q.js +0 -1
- package/dist/chunk-YU2VGLOT.js +0 -1
package/dist/browser.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export type { ResourceResolutionResult, ILogger, DocumentVersionPick, } from './
|
|
|
23
23
|
export { InMemoryKanonakDocumentRepository } from './repositories/InMemoryKanonakDocumentRepository.js';
|
|
24
24
|
export { HttpKanonakDocumentRepository } from './repositories/HttpKanonakDocumentRepository.js';
|
|
25
25
|
export { PublisherIndex } from './repositories/PublisherIndex.js';
|
|
26
|
+
export { KanonakVocabulary } from './reasoning/KanonakVocabulary.js';
|
|
27
|
+
export { SHACL_PUBLISHER, SHACL_PACKAGE, SH_SHAPE, SH_NODE_SHAPE, SH_PROPERTY_SHAPE, } from './shacl/uris.js';
|
|
26
28
|
export { PublisherConfigResolver } from './repositories/PublisherConfig.js';
|
|
27
29
|
export type { PublisherConfig } from './repositories/PublisherConfig.js';
|
|
28
30
|
export { findDerivation } from './derivation/index.js';
|
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as Y,b as X,c as J,d as Oe,e as je,f as De,g as Ve,i as Ae,j as ve,k as Ne,l as He,m as Le}from"./chunk-WVXOHCW2.js";import{a as Te}from"./chunk-ZUWSZQAJ.js";import{a as m,b as c,c as u,e as d,h as R,i as y,j as f,k,l as x,m as P,n as S}from"./chunk-P5VQEDBS.js";import{a as Q,b as Z,c as $}from"./chunk-HND3PKKR.js";import{a as ee}from"./chunk-PEB52US5.js";import"./chunk-SC5M74NM.js";import{A as Ie,B as Ee,L as be,a as oe,b as te,c as re,d as ne,f as ae,g as ie,h as se,i as pe,k as le,l as me,m as ce,n as ue,o as de,p as Re,q as ye,r as fe,s as ke,t as xe,u as Pe,v as Se,w as Ce,x as ge,y as Ke,z as he}from"./chunk-CYXNYNE7.js";import"./chunk-BRCVOR7A.js";import"./chunk-AUXSXDZB.js";import{a as p}from"./chunk-6VIUXP4N.js";import{a as h,c as H,i as w,j as z,m as W}from"./chunk-ITI65NHP.js";import{a as l}from"./chunk-KOWDHKBN.js";import"./chunk-PEJALHXK.js";import{a as T,b as L,da as B,fa as q,j as _,k as F,l as M,m as U,n as G}from"./chunk-EKSYQ6CU.js";import{a as C,b as g,c as K,d as E,e as b,f as O,g as j,h as D,i as V,j as A,k as v,l as N}from"./chunk-H6UAD2LP.js";import{a as I}from"./chunk-FUUTGGJS.js";import{c as e,d as o,e as t,f as r,g as n,h as a,i,k as s}from"./chunk-QILEJIFU.js";export{Pe as AmbiguousReferenceRule,V as BooleanStatement,De as CANONICAL_FORM_VERSION,w as Carrier,Ie as ClassDefinitionRule,ue as ClassHierarchyCycleRule,g as DefinedKanonak,X as EdgeType,h as EmbeddedKanonak,le as EmbeddedKanonakTypeRule,v as EmbeddedStatement,J as GraphBuilder,S as HttpKanonakDocumentRepository,y as INTEGRITY_PREFIX,me as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,m as KANONAK_USER_AGENT,C as Kanonak,Z as KanonakDocumentPositions,W as KanonakObjectParser,be as KanonakObjectValidator,l as KanonakParser,I as KanonakUri,ee as KanonakUriBuilder,B as KanonakVocabulary,N as ListStatement,Ee as MarkdownLinkRule,H as MarkdownStatement,ke as NamespaceImportCycleRule,ae as NamespacePrefixRule,Y as NodeType,D as NumberStatement,Ae as OAuthDiscovery,Ce as ObjectPropertyValueValidationRule,re as OntologyValidationError,oe as OntologyValidationResult,ge as PropertyDomainRule,de as PropertyHierarchyCycleRule,Ke as PropertyKindRangeConsistencyRule,Q as PropertyMetadata,Se as PropertyRangeReferenceRule,Re as PropertyRangeRequiredRule,se as PropertyTypeSpecificityRule,R as PublisherConfigResolver,P as PublisherIndex,E as ReferenceKanonak,A as ReferenceStatement,he as ReservedNameShadowRule,ie as ResourceNamingRule,T as ResourceResolver,q as ResourceTypeClassifier,F as SHACL_PACKAGE,_ as SHACL_PUBLISHER,U as SH_NODE_SHAPE,G as SH_PROPERTY_SHAPE,M as SH_SHAPE,O as ScalarStatement,b as Statement,j as StringStatement,ye as SubClassOfReferenceRule,fe as SubPropertyOfReferenceRule,K as SubjectKanonak,pe as SubjectKanonakTypeRequiredRule,He as TokenCredentialProvider,L as TypeResolver,xe as UnresolvedPredicateRule,ce as UnresolvedReferenceRule,ne as ValidationContext,te as ValidationSeverity,Le as buildOntologyModel,Oe as canonicalForm,je as canonicalHash,z as carrierOf,e as compareVersions,x as computeIntegrityAsync,Ne as createCredentialedFetch,r as createVersion,Te as findDerivation,t as formatVersion,u as getKanonakUserAgent,a as isCompatibleVersion,i as isMajorCompatible,d as kanonakFetch,Ve as normalizeHost,ve as parseAuthChallenge,f as parseLockFile,n as parseVersionString,$ as parseWithPositions,s as pickHighestDocument,k as serializeLockFile,c as setKanonakUserAgent,o as versionsEqual};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Fn}from"./chunk-6VIUXP4N.js";import{a as V,c as Fe,h as u,m as Hn}from"./chunk-
|
|
1
|
+
import{a as Fn}from"./chunk-6VIUXP4N.js";import{a as V,c as Fe,h as u,m as Hn}from"./chunk-ITI65NHP.js";import{a as xn}from"./chunk-KOWDHKBN.js";import{a as zn}from"./chunk-PEJALHXK.js";import{ga as Nn,ha as Dn,ia as Bn}from"./chunk-EKSYQ6CU.js";import{b as je,c as q,d as j,g as W,h as ie,i as ae,j as x,k as H,l as I,m as mn,n as fe,o as Pn,p as w,r as Me,s as he,v as hn,w as qe,y as An,z as Mn}from"./chunk-H6UAD2LP.js";import{a as Vn}from"./chunk-FUUTGGJS.js";import{c as en,e as nn,g as Tn}from"./chunk-QILEJIFU.js";var xe="kanonak.org",Yn="look",We="core-rdf",Tt={publisher:xe,package_:Yn,name:"displayLabel"},Ft={publisher:xe,package_:Yn,name:"displaySummary"},xt={publisher:xe,package_:We,name:"type"},Vt={publisher:xe,package_:We,name:"subClassOf"},Pt={publisher:xe,package_:We,name:"label"},At={publisher:xe,package_:We,name:"comment"},Gn=new Vn(xe,We,"Resource");function N(r,e){let n=qn(r,e,Tt)??Pt,t=qn(r,e,Ft)??At,a=hn(e,n)??e.name,s=hn(e,t);return{label:a,summary:s}}function qn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Wn(e,xt);for(;s.length>0;){let o=s.shift(),i=mn(o);if(a.has(i))continue;a.add(i);let c=Me(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Wn(c,Vt))}if(!a.has(mn(Gn))){let o=Me(r,Gn);if(o){let i=qe(o,n);if(i)return i}}}function Wn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of An(r,e))a instanceof j&&t.push(a.subject);return t}function Ye(r,e={}){let n=r.replace(/\r\n/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`),t=[],a=0;for(;a<n.length;){let s=n[a];if(s.trim()===""){a++;continue}let o=/^(\s*)```(\S*)\s*$/.exec(s);if(o){let l=o[2],d=[];for(a++;a<n.length&&!/^(\s*)```\s*$/.test(n[a]);)d.push(n[a]),a++;a++;let f=d.join(`
|
|
4
4
|
`),p=l&&e.highlight?e.highlight(l,f):De(f),m=l?` class="language-${Jn(l)}"`:"";t.push(`<pre class="kan-code"><code${m}>${p}</code></pre>`);continue}let i=/^(#{1,6})\s+(.*)$/.exec(s);if(i){let l=i[1].length,d=Ne(i[2].trim());t.push(`<h${l}>${d}</h${l}>`),a++;continue}if(s.includes("|")&&a+1<n.length&&Xn(n[a+1])){let l=bn(s),d=Mt(n[a+1]);a+=2;let f=[];for(;a<n.length&&n[a].trim()!==""&&n[a].includes("|");)f.push(bn(n[a])),a++;t.push(Nt(l,d,f));continue}if(/^\s*[-*]\s+/.test(s)){let l=[];for(;a<n.length&&/^\s*[-*]\s+/.test(n[a]);){let d=[n[a].replace(/^\s*[-*]\s+/,"")];for(a++;a<n.length&&n[a].trim()!==""&&!/^\s*[-*]\s+/.test(n[a])&&!/^\s*\d+\.\s+/.test(n[a]);)d.push(n[a]),a++;a<n.length&&n[a].trim()===""&&a++,l.push(`<li>${Ne(d.join(" ").trim())}</li>`)}t.push(`<ul>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ut}from"./chunk-BRCVOR7A.js";import{k as dt}from"./chunk-
|
|
1
|
+
import{a as ut}from"./chunk-BRCVOR7A.js";import{k as dt}from"./chunk-AUXSXDZB.js";import{a as D,b as He,c as st,d as G,h as M,k as mt,m as S}from"./chunk-ITI65NHP.js";import{a as at}from"./chunk-KOWDHKBN.js";import{aa as Ye,ba as ct,fa as v,ga as w,ha as z,ia as W,ja as Y,ma as pt,na as L,oa as lt}from"./chunk-EKSYQ6CU.js";import{c as f,d as I,j as We,k as Q,l as q,m as b,n as X,p as O,r as R,t as ee,u as x,v as F,w as y,x as P,y as K,z as H}from"./chunk-H6UAD2LP.js";import{a as it}from"./chunk-FUUTGGJS.js";import{e as j}from"./chunk-QILEJIFU.js";var te=class{isValid=!1;errors=[];warnings=[];infos=[];get totalIssues(){return this.errors.length+this.warnings.length+this.infos.length}get allDiagnostics(){return[...this.errors,...this.warnings,...this.infos]}};var k=(o=>(o.Info="Info",o.Warning="Warning",o.Error="Error",o))(k||{});var u=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var Ze=class c{resolvedDocuments=[];currentEntityPath;withPath(e){let t=new c;return t.resolvedDocuments=this.resolvedDocuments,t.currentEntityPath=e,t}};var oe=class{constructor(e){this.underlying=e;this.repository=new Je(e)}underlying;repository;parsePromise=null;getKanonaks(){return this.parseOnce().then(e=>e.merged)}getAuthoredKanonaks(){return this.parseOnce().then(e=>e.authored)}parseOnce(){return this.parsePromise||(this.parsePromise=(async()=>{let e=await this.underlying.getAllDocumentsAsync();await ut(e,this.repository);let t={};return{merged:await new S().parseKanonaks(this.underlying,t),authored:t.authored??[]}})()),this.parsePromise}},Je=class{constructor(e){this.inner=e}inner;highestVersionCache=new Map;byNamespaceCache=new Map;getAllDocumentsAsync(){return this.inner.getAllDocumentsAsync()}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){let o=`${e}/${t}`,n=this.byNamespaceCache.get(o);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,t),this.byNamespaceCache.set(o,n),n)}getHighestCompatibleVersionAsync(e,t){let o=t.version,n=o?`${o.major}.${o.minor}.${o.patch}`:"",r=`${e}/${t.packageName}@${t.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,t),this.highestVersionCache.set(r,a),a)}saveDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}deleteDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}clearNamespaceAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};async function E(c,e,t){return t?t.getKanonaks():new S().parseKanonaks(new ne(c,e))}async function C(c,e,t){let o=await E(c,e,t),n=Ge(c);return n?o.filter(r=>r instanceof f&&r.namespace===n):[]}async function re(c,e,t){let o=Ge(c);if(!o)return[];let n;if(t)n=await t.getAuthoredKanonaks();else{let r={};await new S().parseKanonaks(new ne(c,e),r),n=r.authored??[]}return n.filter(r=>r instanceof f&&r.sourceDoc===o)}function Ge(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var ne=class{constructor(e,t){this.document=e;this.broader=t}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),t=(await this.broader.getAllDocumentsAsync()).filter(o=>o.metadata.namespace_?.toString()!==e);return[this.document,...t]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){return this.broader.getDocumentsByNamespaceAsync(e,t)}getHighestCompatibleVersionAsync(e,t){return this.broader.getHighestCompatibleVersionAsync(e,t)}getAllDocumentReferencesAsync(){return this.broader.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}saveDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}deleteDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}clearNamespaceAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}};var ae=class c{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let t=[];for(let[o,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(o,n,t);return t}validateEntity(e,t,o){for(let[n,r]of Object.entries(t)){let a=r?.toString()??"";if(a&&c.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),s=e.split(".")[0],p=new u;p.ruleType=this.ruleName,p.severity="Error",p.entityName=s,p.propertyName=e,p.actualValue=n,p.expectedValue=i,p.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,p.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",o.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,o)}}getSuggestionForPrefixedValue(e){let t=e.toLowerCase();if(t==="rdfs:class"||t==="owl:class")return"Class";if(t==="rdfs:property"||t==="rdf:property")return"DatatypeProperty or ObjectProperty";if(t.startsWith("xsd:"))return e.substring(4);let o=e.indexOf(":");return o>=0?e.substring(o+1):e}};var ie=class c{static RESERVED_WORDS=new Set(["imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let t=[],o=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=c.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!o&&c.RESERVED_WORDS.has(n.toLowerCase())){let i=new u;i.ruleType=this.ruleName,i.severity="Error",i.entityName=n,i.message=`Entity name '${n}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",t.push(i);continue}if(!a&&!c.VALID_NAME_PATTERN.test(n)){let i;/^\d/.test(n)?i="Entity names must start with a letter, not a number.":n.includes(" ")?i="Entity names cannot contain spaces. Use camelCase or underscores instead.":i="Entity names must start with a letter and contain only letters, numbers, and underscores.";let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=n,s.message=`Invalid entity name '${n}'. ${i}`,s.suggestion=i,t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,t)}return t}validatePropertyNames(e,t,o){for(let n of Object.keys(t))if(!c.VALID_PROPERTIES.has(n)&&!c.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new u;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",o.push(r)}}};var se=class c{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let t=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return t;let o=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let s=[];if(Array.isArray(i))for(let p of i){let l=p?.toString();l&&l==="Property"&&!o&&s.push(l)}else{let p=i?.toString();p&&p==="Property"&&!o&&s.push(p)}for(let p of s){let l=this.getPropertyValue(a,"range"),m=this.determinePropertyType(l),d=new u;d.ruleType=this.ruleName,d.severity="Error",d.entityName=n,d.propertyName="type",d.actualValue=p,d.expectedValue=m,d.message=`Invalid property type '${p}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",t.push(d)}}}return t}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":c.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,t){let o=e[t];return o?o.toString():null}isPropertyDefinedAsClass(e){let t=e.body.Property;if(t&&typeof t=="object"&&!Array.isArray(t)){let n=t.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var ce=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let t=[];for(let[o,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||o.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=o,s.propertyName="type",s.message=`Subject Kanonak '${o}' must have a 'type' property.`,s.suggestion=`Add a type statement like:
|
|
2
2
|
type: Scene
|
|
3
3
|
|
|
4
4
|
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,s.expectedValue="A valid class name (Scene, Character, Story, etc.)",t.push(s)}}return t}};var At=new Set(["EphemeralPackage"]),pe=class{get ruleName(){return"PackageHeader"}validate(e){let t=e.metadata;if(!t.type_)return[];let o=[],n=this.packageKey(e,t.type_);return t.namespace_?(!At.has(t.type_)&&!t.namespace_.version&&o.push(this.error(n,"version",`Package resource '${n}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i,j as o,k as r}from"./chunk-
|
|
1
|
+
import{i,j as o,k as r}from"./chunk-P5VQEDBS.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as B,d as G,m as h,n as X,r as Y,s as T,v,w as j,y as q}from"./chunk-H6UAD2LP.js";import{a as P}from"./chunk-FUUTGGJS.js";var W=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let r=t.metadata?.namespace_?.toString()??"unknown",o=this.cache.get(r);if(o){let i=o.get(e);if(i)return i}let a=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(r,a),a.get(e)??null}async resolveAllEntitiesAsync(e,t){let r=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let o=e.split("."),a=o[0],i=o[1],u=await this.findDocumentForAlias(t,a);return u?await this.resolveAllEntitiesAsync(i,u):[]}return r.filter(o=>o.entityName===e)}async buildAllEntitiesIndexAsync(e,t,r){let o=[],a=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${a}`),t.has(a))return this.logger?.debug?.(`Skipping ${a} - already visited (circular import prevention)`),o;t.add(a);let i=r.length===0?a:`${r} \u2192 ${a}`;for(let[u,c]of Object.entries(e.body))if(!u.includes(".")&&c&&typeof c=="object"&&!Array.isArray(c)){if(!e.metadata.namespace_)continue;let g=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};o.push({entityName:u,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,u,g),entity:c,definedInNamespace:a,isImported:r.length>0,importPath:i})}if(this.logger?.debug?.(`Collected ${o.length} entities from ${a}`),e.metadata?.imports){let u=Object.values(e.metadata.imports).reduce((c,g)=>c+g.length,0);this.logger?.debug?.(`Processing ${u} import(s) for ${a}`);for(let[c,g]of Object.entries(e.metadata.imports))for(let m of g)try{this.logger?.debug?.(`Resolving import: ${c}/${m.packageName}`);let d=await this.repository.getHighestCompatibleVersionAsync(c,m);if(d){this.logger?.debug?.(`Successfully loaded import: ${d.metadata?.namespace_?.toString()}`);let k=await this.buildAllEntitiesIndexAsync(d,t,i);o.push(...k),this.logger?.debug?.(`Added ${k.length} entities from import ${d.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${c}/${m.packageName}`)}catch(d){let k=d;throw this.logger?.error?.(`Failed to process import ${c}/${m.packageName} for namespace ${a}. Error: ${k.message}`,k),new Error(`Failed to process import ${c}/${m.packageName} for namespace ${a}. See inner exception for details.`,{cause:d})}}return o}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,r,o){let a=new Map,i=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${i}`),t.has(i))return this.logger?.debug?.(`Skipping ${i} - circular import in progress`),a;let u=o.get(i);if(u)return u;t.add(i);let c=r.length===0?i:`${r} \u2192 ${i}`,g=0;for(let[m,d]of Object.entries(e.body))if(!m.includes(".")&&d&&typeof d=="object"&&!Array.isArray(d)){if(!e.metadata.namespace_)continue;if(!a.has(m)){let k=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};a.set(m,{entityName:m,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,m,k),entity:d,definedInNamespace:i,isImported:r.length>0,importPath:c}),g++}}if(this.logger?.debug?.(`Indexed ${g} entities from ${i}`),e.metadata?.imports){let m=Object.values(e.metadata.imports).reduce((d,k)=>d+k.length,0);this.logger?.debug?.(`Processing ${m} import(s) for ${i}`);for(let[d,k]of Object.entries(e.metadata.imports))for(let K of k)try{this.logger?.debug?.(`Resolving import: ${d}/${K.packageName}`);let E=await this.repository.getHighestCompatibleVersionAsync(d,K);if(E){this.logger?.debug?.(`Successfully loaded import: ${E.metadata?.namespace_?.toString()}`);let U=await this.buildEntityIndexAsyncInternal(E,t,c,o),$=0;for(let[O,C]of U.entries()){let _=a.get(O);if(!_)a.set(O,C),$++;else if(_.isImported&&C.isImported&&(_.uri.publisher!==C.uri.publisher||_.uri.package_!==C.uri.package_)){let A=_.isAmbiguous?_:{..._,isAmbiguous:!0,ambiguousNamespaces:[_.definedInNamespace]};A.ambiguousNamespaces.includes(C.definedInNamespace)||A.ambiguousNamespaces.push(C.definedInNamespace),a.set(O,A),this.logger?.warn?.(`Ambiguous reference '${O}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(K.alias&&!O.includes(".")){let A=`${K.alias}.${O}`;a.has(A)||(a.set(A,C),$++)}}this.logger?.debug?.(`Merged ${$} entities from import ${E.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${d}/${K.packageName}`)}catch(E){let U=E;throw this.logger?.error?.(`Failed to process import ${d}/${K.packageName} for namespace ${i}. Error: ${U.message}`,U),new Error(`Failed to process import ${d}/${K.packageName} for namespace ${i}. See inner exception for details.`,{cause:E})}}return t.delete(i),o.set(i,a),a}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[r,o]of Object.entries(e.metadata.imports))for(let a of o){if(a.alias===t)return await this.repository.getHighestCompatibleVersionAsync(r,a);if(!a.alias&&a.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(r,a)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}};var z=class n{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-xsd"&&n.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return n.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let r=await this.resourceResolver.resolveEntityAsync(e,t);if(r){let o=r.entity.type;if(o){let a=String(o);return a==="Class"||a==="rdfs.Class"||a.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function J(n){if(!n||n.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let e=n.trim(),t=e.split("/");if(t.length===1){let r=t[0];if(!r)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(r.includes("@"))throw new Error(`Invalid Kanonak address: "${n}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:r}}if(t.length===2){let[r,o]=t;if(!r||!o)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let a=o.indexOf("@");if(a===-1)return{kind:"package",publisher:r,package_:o};let i=o.substring(0,a),u=o.substring(a+1);if(!i||!u)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let c=re(u);return{kind:"package",publisher:r,package_:i,version:c}}return{kind:"resource",uri:P.parse(e)}}function Oe(n){switch(n.kind){case"publisher":return n.publisher;case"package":return n.version?`${n.publisher}/${n.package_}@${n.version.major}.${n.version.minor}.${n.version.patch}`:`${n.publisher}/${n.package_}`;case"resource":return n.uri.toString()}}function re(n){let e=n.split(".").map(Number);return oe(e[0]||0,e[1]||0,e[2]||0)}function oe(n,e,t){return{major:n,minor:e,patch:t,toString:()=>`${n}.${e}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===n&&r.minor===e&&r.patch===t,getHashCode:()=>n<<20|e<<10|t,compareTo:r=>n!==r.major?n-r.major:e!==r.minor?e-r.minor:t-r.patch}}function Ne(n){return`${n.publisher}/${n.package_}/${n.name}`}function y(n,e,t){return`${n}/${e}/${t}`}function He(n){return`${n.s}|${n.p}|${ae(n.o)}`}function ae(n){switch(n.kind){case"uri":return`u:${n.key}`;case"literal":return`l:${n.datatype}:${n.lexical}`;case"blank":return`b:${n.id}`}}function Ie(n,e,t){return{s:n,p:e,o:{kind:"uri",key:t}}}var se="kanonak.org",ie="core-shacl",s=n=>({publisher:se,package_:ie,name:n}),N=s("Shape"),H=s("NodeShape"),I=s("PropertyShape"),$e=s("targetClass"),Te=s("property"),ve=s("path"),je=s("minCount"),we=s("maxCount"),Me=s("datatype"),Le=s("class"),Ve=s("in"),Fe=s("pattern"),Be=s("flags"),Ge=s("minLength"),Xe=s("maxLength"),Ye=s("minInclusive"),qe=s("maxInclusive"),We=s("message"),ze=s("targetNode"),Je=s("targetSubjectsOf"),Qe=s("targetObjectsOf"),Ze=s("closed"),et=s("ignoredProperties"),tt=s("nodeKind"),nt=s("IRI"),rt=s("BlankNode"),ot=s("Literal"),at=s("severity"),st=s("Violation"),it=s("Warning"),pt=s("Info"),ct=s("ValidationReport"),lt=s("conforms"),ut=s("result"),yt=s("ValidationResult"),dt=s("focusNode"),gt=s("resultPath"),mt=s("resultMessage"),ft=s("resultSeverity"),kt=s("sourceShape"),bt=s("value"),ht=s("sourceConstraintComponent"),St=s("MinCountConstraintComponent"),_t=s("MaxCountConstraintComponent"),Pt=s("DatatypeConstraintComponent"),Kt=s("ClassConstraintComponent"),Et=s("InConstraintComponent"),Ct=s("PatternConstraintComponent"),At=s("MinLengthConstraintComponent"),xt=s("MaxLengthConstraintComponent"),Rt=s("MinInclusiveConstraintComponent"),Ot=s("MaxInclusiveConstraintComponent"),Ut=s("NodeKindConstraintComponent"),Nt=s("ClosedConstraintComponent");var l="kanonak.org",p="core-rdf",f="core-owl",Z="core-kanonak",M=new Map([["type",p],["subClassOf",p],["subPropertyOf",p],["domain",p],["range",p],["label",p],["comment",p],["seeAlso",p],["isDefinedBy",p],["member",p],["Resource",p],["Class",p],["Property",p],["Datatype",p],["Literal",p],["List",p],["ObjectProperty",f],["DatatypeProperty",f],["AnnotationProperty",f],["Thing",f],["Nothing",f],["Package",Z]]),pe=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function $t(n){return M.has(n)}function Tt(n){let e=M.get(n);return e?{publisher:l,package_:e}:void 0}function L(n,e,t){if(!n||!n.name)return;let r=M.get(n.name);if(!r)return;let o=()=>{n.publisher=l,n.package_=r,t&&(n.version=t.get(r))};if(pe.has(n.name)){let a=n.publisher===l&&n.package_===r;n.publisher=l,n.package_=r,!a&&t&&(n.version=t.get(r));return}n.publisher===l&&n.package_===r||n.publisher&&n.publisher.length>0&&(!e||e(n))||o()}var Q=class{type=y(l,p,"type");subClassOf=y(l,p,"subClassOf");subPropertyOf=y(l,p,"subPropertyOf");domain=y(l,p,"domain");range=y(l,p,"range");label=y(l,p,"label");comment=y(l,p,"comment");resource=y(l,p,"Resource");class_=y(l,p,"Class");datatype=y(l,p,"Datatype");literal=y(l,p,"Literal");equivalentClass=y(l,f,"equivalentClass");equivalentProperty=y(l,f,"equivalentProperty");inverseOf=y(l,f,"inverseOf");sameAs=y(l,f,"sameAs");transitiveProperty=y(l,f,"TransitiveProperty");symmetricProperty=y(l,f,"SymmetricProperty");objectProperty=y(l,f,"ObjectProperty");datatypeProperty=y(l,f,"DatatypeProperty");annotationProperty=y(l,f,"AnnotationProperty");package_=y(l,Z,"Package");shape=w(N);nodeShape=w(H);propertyShape=w(I)};function w(n){return y(n.publisher,n.package_,n.name)}var ce=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function b(n){let e=n;if(e.entity&&typeof e.entity=="object"){let t=e.entity.type;if(typeof t=="string"){let o={publisher:"",package_:"",name:t.includes(".")?t.substring(t.lastIndexOf(".")+1):t};return L(o),{publisher:o.publisher,package_:o.package_,name:o.name}}}if(e.statement&&Array.isArray(e.statement)){for(let t of e.statement)if(t.predicate?.subject?.name==="type"&&t.object?.subject){let r=t.object.subject,o={publisher:r.publisher??"",package_:r.package_??"",name:r.name};return L(o),{publisher:o.publisher,package_:o.package_,name:o.name}}}return null}var le=[N,H,I];function S(n,e){return ce.has(`${n}/${e}`)}var ue=new Set(["Property","ObjectProperty","DatatypeProperty","AnnotationProperty"]);function V(n){if(S(n.publisher,n.package_))return ue.has(n.name)?n.name:void 0}var ee=class n{static getTypeUri(e){return b(e)}static isCoreOntologyType(e){return S(e.publisher,e.package_)}static isClassType(e){let t=b(e);return t?S(t.publisher,t.package_)&&t.name==="Class":!1}static isDatatypeType(e){let t=b(e);return t?S(t.publisher,t.package_)&&t.name==="Datatype":!1}static isDatatypePropertyType(e){let t=b(e);return t?S(t.publisher,t.package_)&&t.name==="DatatypeProperty":!1}static isObjectPropertyType(e){let t=b(e);return t?S(t.publisher,t.package_)&&t.name==="ObjectProperty":!1}static isAnnotationPropertyType(e){let t=b(e);return t?S(t.publisher,t.package_)&&t.name==="AnnotationProperty":!1}static isGenericPropertyType(e){let t=b(e);return t?S(t.publisher,t.package_)&&t.name==="Property":!1}static isAnyPropertyType(e){let t=b(e);return!t||!S(t.publisher,t.package_)?!1:t.name==="Property"||t.name==="DatatypeProperty"||t.name==="ObjectProperty"||t.name==="AnnotationProperty"}static isShapeType(e){let t=b(e);return t?le.some(r=>X(t,r)):!1}static isSchemaDefinitionType(e){if(n.isShapeType(e))return!0;let t=b(e);return!t||!S(t.publisher,t.package_)?!1:t.name==="Class"||t.name==="Property"||t.name==="DatatypeProperty"||t.name==="ObjectProperty"||t.name==="AnnotationProperty"||t.name==="Datatype"}static isInstanceOfKnownClass(e,t){if(n.isSchemaDefinitionType(e))return!1;let r=b(e);return r?t.has(r.name):!1}};var x="kanonak.org",R="core-rdf",ye={publisher:x,package_:R,name:"domain"},de={publisher:x,package_:R,name:"range"},ge={publisher:x,package_:R,name:"subClassOf"},me={publisher:x,package_:R,name:"type"},fe={publisher:x,package_:R,name:"label"},ke={publisher:x,package_:R,name:"comment"},be=new P(x,R,"Resource");function he(n){try{let e=J(`${n.namespace}/${n.name}`);return e.kind==="resource"?e.uri:void 0}catch{return}}function F(n,e){let t=j(n,e);if(t)return[t];let r=[];for(let o of q(n,e))o instanceof G&&r.push(o.subject);return r}function ne(n,e){let t=[],r=new Set,o="version"in e?e.version:void 0,a=[new P(e.publisher,e.package_,e.name,o??void 0)];for(;a.length>0;){let i=a.shift(),u=h(i);if(r.has(u))continue;r.add(u),t.push(i);let c=Se(n,i);c&&a.push(...F(c,ge))}return t}function Se(n,e){return e.version&&typeof e.version.major=="number"?Y(n,e)??T(n,e)[0]:T(n,e)[0]}function D(n,e){let t;for(let r of Ee(e)){let o=_e(n,r);if(o){if(o!=="Property")return o;t??=o}}return t}function _e(n,e){let t=V(e);if(t)return t;let r=te.get(n);r||(r=new Map,te.set(n,r));let o=e.version,a=o&&typeof o.major=="number"?`${h(e)}@${o.major}.${o.minor}.${o.patch}`:h(e),i=r.get(a);if(i!==void 0)return i??void 0;let u;for(let c of ne(n,e)){let g=V(c);if(g){if(g!=="Property"){u=g;break}u??="Property"}}return r.set(a,u??null),u}var te=new WeakMap;function qt(n,e){return D(n,e)!==void 0}function Wt(n,e){return D(n,e)==="ObjectProperty"}function zt(n,e){return D(n,e)==="DatatypeProperty"}function Pe(n,e){let t=new Set([h(be)]);for(let r of ne(n,e))t.add(h(r));return t}function Ke(n,e){let t=Pe(n,e),r=[],o=new Set;for(let a of n){if(!(a instanceof B))continue;let i=D(n,a);if(!i)continue;let u=F(a,ye);if(!u.some(m=>t.has(h(m))))continue;let c=he(a);if(!c)continue;let g=h(c);o.has(g)||(o.add(g),r.push({uri:c,label:v(a,fe),comment:v(a,ke),kind:i==="ObjectProperty"?"object":i==="DatatypeProperty"?"datatype":"other",range:j(a,de),domains:u}))}return r}function Jt(n,e,t){let r=Ke(n,e).find(o=>h(o.uri)===h(t));return r?{ok:!0,descriptor:r}:{ok:!1,message:`Property ${t.publisher}/${t.package_}/${t.name} is not in scope for ${e.publisher}/${e.package_}/${e.name}.`}}function Ee(n){return F(n,me)}export{W as a,z as b,J as c,Oe as d,Ne as e,y as f,He as g,ae as h,Ie as i,se as j,ie as k,N as l,H as m,I as n,$e as o,Te as p,ve as q,je as r,we as s,Me as t,Le as u,Ve as v,Fe as w,Be as x,Ge as y,Xe as z,Ye as A,qe as B,We as C,ze as D,Je as E,Qe as F,Ze as G,et as H,tt as I,nt as J,rt as K,ot as L,at as M,st as N,it as O,pt as P,St as Q,_t as R,Pt as S,Kt as T,Et as U,Ct as V,At as W,xt as X,Rt as Y,Ot as Z,Ut as _,Nt as $,$t as aa,Tt as ba,L as ca,Q as da,V as ea,ee as fa,he as ga,ne as ha,D as ia,qt as ja,Wt as ka,zt as la,Ke as ma,Jt as na,Ee as oa};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{l as V}from"./chunk-
|
|
1
|
+
import{l as V}from"./chunk-ITI65NHP.js";import{a as E}from"./chunk-KOWDHKBN.js";var L=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as O,LineCounter as R,isMap as h,isPair as f,isScalar as g,isSeq as I}from"yaml";var K=class i{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 t=new i,n=new R,r=O(e,{lineCounter:n});if(r.errors.length>0||!h(r.contents))return t;N(r.contents,[],n,t);for(let o of r.contents.items){if(!f(o)||!g(o.key))continue;let a=String(o.key.value),u=o.key.range;if(!u)continue;t.entities.set(a,d(u,n));let s=o.value,c=s&&typeof s=="object"&&"range"in s?s.range:void 0;if(c?t.entityBlocks.set(a,d([u[0],u[1],c[2]],n)):t.entityBlocks.set(a,d(u,n)),h(o.value)){let k=new Map,m=new Map,l=new Map;for(let P of o.value.items){if(!f(P)||!g(P.key))continue;let b=String(P.key.value),p=P.key.range;p&&k.set(b,d(p,n));let S=P.value;if(S&&typeof S=="object"&&"range"in S&&Array.isArray(S.range)){let v=S.range;m.set(b,d(v,n))}if(I(S)){let v=[];for(let M of S.items)M&&typeof M=="object"&&"range"in M&&Array.isArray(M.range)&&v.push(d(M.range,n));v.length>0&&l.set(b,v)}}k.size>0&&t.properties.set(a,k),m.size>0&&t.propertyValues.set(a,m),l.size>0&&t.valueListItems.set(a,l);let y=j(o.value,n);y.length>0&&t.importPackages.set(a,y)}}return t}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,t){for(let[n,r]of this.entityBlocks)if(w(r,e,t))return n}findPropertyAtPosition(e,t){let n=this.findEntityAtPosition(e,t);if(!n)return;let r=this.properties.get(n),o=this.propertyValues.get(n);if(!r&&!o)return{entityName:n};let a,u;if(o)for(let[s,c]of o)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);if(r)for(let[s,c]of r)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);return a?{entityName:n,propertyName:a}:{entityName:n}}getPropertyPosition(e,t){return this.properties.get(e)?.get(t)}getPropertyValuePosition(e,t){return this.propertyValues.get(e)?.get(t)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[t,n]of this.importPackages)for(let r of n)e.push({entityName:t,entry:r});return e}findPropertySourceName(e,t){let n=this.properties.get(e);if(n){if(n.has(t))return t;for(let r of n.keys()){let o=r.lastIndexOf(".");if((o===-1?r:r.substring(o+1))===t)return r}}}getListItemPosition(e,t,n){let r=this.valueListItems.get(e)?.get(t);if(!(!r||n<0||n>=r.length))return r[n]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,t){this.nestedKeys.set(e,t)}setNestedValuePosition(e,t){this.nestedValues.set(e,t)}getMostSpecificPosition(e,t,n){if(e){if(t!==void 0){if(n!==void 0){let a=this.getListItemPosition(e,t,n);if(a)return a}let r=this.getPropertyValuePosition(e,t);if(r)return r;let o=this.getPropertyPosition(e,t);if(o)return o}return this.getEntityPosition(e)}}};function j(i,e){let t=[];if(!h(i))return t;let n=i.items.find(r=>f(r)&&g(r.key)&&String(r.key.value)==="imports");if(!n||!f(n)||!I(n.value))return t;for(let r of n.value.items){if(!h(r))continue;let o=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="publisher");if(!o||!f(o)||!g(o.value))continue;let a=String(o.value.value),u=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="packages");if(!(!u||!f(u)||!I(u.value)))for(let s of u.value.items){if(!h(s))continue;let c=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="package");if(!c||!f(c)||!g(c.value)||!c.value.range)continue;let k=String(c.value.value),m=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="version"),l=m&&f(m)&&g(m.value)?String(m.value.value):"",y=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="alias"),P=y&&f(y)&&g(y.value)?String(y.value.value):void 0,b=P!==void 0?{publisher:a,package_:k,version:l,alias:P,position:d(c.value.range,e)}:{publisher:a,package_:k,version:l,position:d(c.value.range,e)};t.push(b)}}return t}function w(i,e,t){return!(e<i.line||e>i.endLine||e===i.line&&t<i.column||e===i.endLine&&t>i.endColumn)}function C(i,e){let t=i.endLine-i.line,n=e.endLine-e.line;if(t!==n)return t<n;let r=i.endLine===i.line?i.endColumn-i.column:Number.MAX_SAFE_INTEGER,o=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return r<o}function N(i,e,t,n){if(h(i)){for(let r of i.items){if(!f(r)||!g(r.key))continue;let o=String(r.key.value),a=[...e,o],u=JSON.stringify(a);r.key.range&&n.setNestedKeyPosition(u,d(r.key.range,t));let s=r.value,c=D(s);c&&n.setNestedValuePosition(u,d(c,t)),N(s,a,t,n)}return}if(I(i)){for(let r=0;r<i.items.length;r++){let o=i.items[r],a=[...e,r],u=JSON.stringify(a),s=D(o);s&&n.setNestedValuePosition(u,d(s,t)),N(o,a,t,n)}return}}function D(i){if(!i||typeof i!="object"||!("range"in i))return;let e=i.range;return Array.isArray(e)&&e.length>=3?e:void 0}function d(i,e){let t=e.linePos(i[0]),n=e.linePos(i[2]);return{line:t.line-1,column:t.col-1,endLine:n.line-1,endColumn:n.col-1}}function x(i,e){let n=(e??new E).parse(i),r=K.fromContent(i);return{document:n,positions:r}}function W(i,e,t,n,r){if(e<n.line||e>n.endLine||e===n.line&&t<n.column||e===n.endLine&&t>=n.endColumn)return;let o=A(r,n.line,n.column),a=A(r,n.endLine,n.endColumn);if(o<0||a<0)return;let u=r.substring(o,a),s=V(u);if(s.length!==i.links.length)return;let c=e-n.line,k=e===n.line?t-n.column:t,m=A(u,c,k);if(!(m<0))for(let l=0;l<s.length;l++){let y=s[l];if(m>=y.startOffset&&m<y.endOffset)return i.links[l]}}function A(i,e,t){let n=0,r=0;for(let o=0;o<i.length;o++){if(n===e)return Math.min(r+t,i.length);i[o]===`
|
|
2
2
|
`&&(n++,r=o+1)}return n===e?Math.min(r+t,i.length):-1}export{L as a,K as b,x as c,W as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as G}from"./chunk-KOWDHKBN.js";import{a as H,aa as Y,b as J,ba as N,ca as A,ia as Z}from"./chunk-EKSYQ6CU.js";import{a as X,b as q,c as w,d as g,g as R,h as T,i as M,j as O,k as K,l as P,m as x,n as _,r as Q}from"./chunk-H6UAD2LP.js";import{a as L}from"./chunk-FUUTGGJS.js";import{k as W}from"./chunk-QILEJIFU.js";var b=class extends q{name};var j=class extends X{value;carrier;lexical};var I=class extends R{links=[]};var ae="kanonak.org",oe="transformations",Ke=3,e=p=>({publisher:ae,package_:oe,name:p}),E={Transformation:e("Transformation"),InstanceTransformation:e("InstanceTransformation"),SetTransformation:e("SetTransformation"),inputPattern:e("inputPattern"),rule:e("rule"),artifactName:e("artifactName"),outputs:e("outputs"),formatOverrides:e("formatOverrides"),partitionBy:e("partitionBy"),InputPattern:e("InputPattern"),matchesClass:e("matchesClass"),requires:e("requires"),sortBy:e("sortBy"),SortKey:e("SortKey"),byProperty:e("byProperty"),order:e("order"),SortOrder:e("SortOrder"),ascending:e("ascending"),descending:e("descending"),OutputFormat:e("OutputFormat"),backendUri:e("backendUri"),FormatOverride:e("FormatOverride"),formatTarget:e("formatTarget"),metadataKeys:e("metadataKeys"),metadataRenames:e("metadataRenames"),trailingNewline:e("trailingNewline"),omitWrapper:e("omitWrapper"),RenameEntry:e("RenameEntry"),fromKey:e("fromKey"),toKey:e("toKey"),FMT_MARKDOWN_FRONTMATTER:e("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:e("plain-markdown"),FMT_TOML:e("toml"),FMT_JSON:e("json"),FMT_HTML:e("html"),FMT_SVG:e("svg"),Expression:e("Expression"),ListSourcedExpression:e("ListSourcedExpression"),ListAggregate:e("ListAggregate"),IteratingExpression:e("IteratingExpression"),BuildAstNode:e("BuildAstNode"),astClass:e("astClass"),set:e("set"),AstFieldBinding:e("AstFieldBinding"),field:e("field"),bindValue:e("bindValue"),When:e("When"),condition:e("condition"),thenBuild:e("thenBuild"),elseBuild:e("elseBuild"),Concat:e("Concat"),parts:e("parts"),Fallback:e("Fallback"),primary:e("primary"),alternate:e("alternate"),StringLiteral:e("StringLiteral"),stringLiteral:e("stringLiteral"),IntegerLiteral:e("IntegerLiteral"),integerLiteral:e("integerLiteral"),DecimalLiteral:e("DecimalLiteral"),decimalLiteral:e("decimalLiteral"),BooleanLiteral:e("BooleanLiteral"),booleanLiteral:e("booleanLiteral"),VarRef:e("VarRef"),varName:e("varName"),PropertyRead:e("PropertyRead"),readSource:e("readSource"),readProp:e("readProp"),Traverse:e("Traverse"),traverseSource:e("traverseSource"),through:e("through"),step:e("step"),UriName:e("UriName"),uriNameOf:e("uriNameOf"),UriPublisher:e("UriPublisher"),uriPublisherOf:e("uriPublisherOf"),UriPackage:e("UriPackage"),uriPackageOf:e("uriPackageOf"),UriVersion:e("UriVersion"),uriVersionOf:e("uriVersionOf"),SubjectUri:e("SubjectUri"),subjectOf:e("subjectOf"),UriLiteral:e("UriLiteral"),refTo:e("refTo"),DisplayLabel:e("DisplayLabel"),labelTarget:e("labelTarget"),labelSource:e("labelSource"),ResolveRef:e("ResolveRef"),resolveSource:e("resolveSource"),Normalize:e("Normalize"),normSource:e("normSource"),normKind:e("normKind"),NormalizeKind:e("NormalizeKind"),NORM_TRIM_END:e("trim-end"),NORM_TO_UPPER:e("to-upper"),NORM_TO_LOWER:e("to-lower"),NORM_FIRST_CHAR:e("first-char"),UnescapedString:e("UnescapedString"),unescapedSource:e("unescapedSource"),IsSet:e("IsSet"),checkExpr:e("checkExpr"),ExpressionFragment:e("ExpressionFragment"),body:e("body"),CallFragment:e("CallFragment"),fragmentRef:e("fragmentRef"),source:e("source"),Join:e("Join"),separator:e("separator"),Count:e("Count"),Sum:e("Sum"),Min:e("Min"),Max:e("Max"),Average:e("Average"),loopVar:e("loopVar"),ForEach:e("ForEach"),emit:e("emit"),ListMap:e("ListMap"),mapBody:e("mapBody"),Filter:e("Filter"),predicate:e("predicate"),PartitionBy:e("PartitionBy"),partitionKey:e("partitionKey"),DistinctBy:e("DistinctBy"),distinctKey:e("distinctKey"),Partition:e("Partition"),key:e("key"),members:e("members"),AllStatements:e("AllStatements"),statementsOf:e("statementsOf"),StatementPredicate:e("StatementPredicate"),predicateOf:e("predicateOf"),StatementValue:e("StatementValue"),valueOf:e("valueOf"),DateFormat:e("DateFormat"),dateSource:e("dateSource"),dateFormat:e("dateFormat"),BinaryArithmetic:e("BinaryArithmetic"),arithLeft:e("arithLeft"),arithRight:e("arithRight"),Add:e("Add"),Subtract:e("Subtract"),Multiply:e("Multiply"),Divide:e("Divide"),Reverse:e("Reverse"),WindowedMap:e("WindowedMap"),windowSize:e("windowSize"),windowVar:e("windowVar"),windowBody:e("windowBody"),PairwiseMap:e("PairwiseMap"),firstVar:e("firstVar"),secondVar:e("secondVar"),pairBody:e("pairBody"),Scan:e("Scan"),initialState:e("initialState"),stateVar:e("stateVar"),elementVar:e("elementVar"),accumulate:e("accumulate"),ListItemAt:e("ListItemAt"),itemIndex:e("itemIndex"),BinaryComparison:e("BinaryComparison"),compareLeft:e("compareLeft"),compareRight:e("compareRight"),Equals:e("Equals"),GreaterThan:e("GreaterThan"),LessThan:e("LessThan"),GreaterThanOrEqual:e("GreaterThanOrEqual"),LessThanOrEqual:e("LessThanOrEqual"),Not:e("Not"),operand:e("operand"),BooleanLogic:e("BooleanLogic"),operands:e("operands"),And:e("And"),Or:e("Or"),Contains:e("Contains"),haystack:e("haystack"),needle:e("needle"),UnaryNumericOp:e("UnaryNumericOp"),value:e("value"),Abs:e("Abs"),Negate:e("Negate"),KindPredicate:e("KindPredicate"),IsReference:e("IsReference"),IsEmbedded:e("IsEmbedded"),IsList:e("IsList"),kindCheck:e("kindCheck"),IsString:e("IsString"),IsNumber:e("IsNumber"),IsBoolean:e("IsBoolean"),StatementObject:e("StatementObject"),statementSource:e("statementSource"),Let:e("Let"),letName:e("letName"),letValue:e("letValue"),letBody:e("letBody"),GetStatementByName:e("GetStatementByName"),inSubject:e("inSubject"),byName:e("byName"),RenderMarkdown:e("RenderMarkdown"),renderSource:e("renderSource"),renderProp:e("renderProp"),renderFormat:e("renderFormat"),RenderFormat:e("RenderFormat"),RENDER_HTML:e("render-html"),RENDER_MARKDOWN:e("render-markdown")};import{Carrier as h,carrierOf as se}from"@kanonak-protocol/canonical";function B(p){return se(`${p.publisher}/${p.package_}/${p.name}`)}var ie=/\[\[([^\[\]\n]+)\]\]/g,ce=/\[\[/g,ee=/```[\s\S]*?```|`[^`\n]*`/g;function pe(p){let t=[];for(let n of p.matchAll(ee))t.push([n.index,n.index+n[0].length]);return t}function ve(p){if(!p||!p.includes("[["))return[];let t=pe(p),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(V(p).map(s=>s.startOffset)),a=[];for(let s of p.matchAll(ce)){let o=s.index;if(n(o)||r.has(o))continue;let c=p.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function V(p){if(!p||!p.includes("[["))return[];let t=[];for(let a of p.matchAll(ee))t.push([a.index,a.index+a[0].length]);let n=a=>t.some(([s,o])=>a>=s&&a<o),r=[];for(let a of p.matchAll(ie)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),m=(c===-1?o:o.slice(0,c)).trim();if(m.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),u={reference:m,startOffset:s,endOffset:s+a[0].length};i.length>0&&(u.displayText=i),r.push(u)}return r}function ne(p,t){for(let n of p)n instanceof w&&U(n,n.name,t)}function U(p,t,n){n({kanonak:p,path:t});for(let r of p.statement)if(r instanceof K)U(r.object,te(t,r.object),n);else if(r instanceof P)for(let a of r.object)a instanceof b&&U(a,te(t,a),n)}function te(p,t){let n=t instanceof b&&t.name?t.name:"<embedded>";return`${p}/${n}`}var me={...N("range"),name:"range"};function fe(p){let t=p.lastIndexOf(".");return t===-1?p:p.slice(t+1)}var re=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new H(t),s=new J(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let m of n){let i=m.metadata.namespace_?.toString();i&&a.set(i,m)}let s=[],o=new Set;ne(t,({kanonak:m})=>{for(let i of m.unresolvedPredicates){let u=`${i.sourceDoc}::${i.key}`;o.has(u)||(o.add(u),s.push(i))}});let c=!1;for(let m of s){let i=a.get(m.sourceDoc);if(!i)continue;let u=await r.resolveEntityAsync(m.key,i);if(!u)continue;let d=x(u.uri);if(this.knownPropertyClasses.has(d))continue;let f=Q(t,u.uri);if(!f)continue;let l=Z(t,f);l&&(this.knownPropertyClasses.set(d,l),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[m,i]of Object.entries(o.body)){let u=new w,d=this.resolveCanonicalEntity(m,o,c);u.namespace=d.namespace,u.name=d.name,u.statement=[];let f=await this.parseStatements(i,o,n,r,a);u.statement.push(...f.statements),u.unresolvedPredicates=f.unresolved,F(u,c),s.push(u)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof w){let u=`${i.namespace}/${i.name}`,d=r.get(u);if(d){let f=a.get(u);for(let l of i.statement){let y=$(l);f.has(y)||(f.add(y),d.statement.push(l))}for(let l of i.unresolvedPredicates)d.unresolvedPredicates.some(y=>y.key===l.key&&y.sourceDoc===l.sourceDoc)||d.unresolvedPredicates.push(l)}else{let f=new w;f.namespace=i.namespace,f.name=i.name,f.sourceDoc=i.sourceDoc;let l=new Set;for(let y of i.statement){let k=$(y);l.has(k)||(l.add(k),f.statement.push(y))}f.unresolvedPredicates=[...i.unresolvedPredicates],a.set(u,l),r.set(u,f),s.push(f)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof w){let u=i.namespace||"",d=u.indexOf("/"),f=d>=0?u.slice(0,d):"",l=d>=0?u.slice(d+1):"",y=l.indexOf("@"),k=y>=0?l.slice(0,y):l;o.add(`${f}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),m=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let u=await n.getDocumentsByNamespaceAsync("kanonak.org",i);m.set(i,W(u).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,m);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(A(s,n,r),a instanceof O)a.object instanceof g&&A(a.object.subject,n,r);else if(a instanceof K)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof P)for(let o of a.object??[])o instanceof g?A(o.subject,n,r):o instanceof b&&this.canonicalizeStatementBuiltins(o.statement,n,r)}}resolveCanonicalEntity(t,n,r){if(!t.includes(".")||!n.metadata?.imports)return{namespace:r,name:t};let a=t.indexOf("."),s=t.substring(0,a),o=t.substring(a+1);for(let[c,m]of Object.entries(n.metadata.imports))for(let i of m)if((i.alias??i.packageName)===s){let d=i.version;return{namespace:`${c}/${i.packageName}@${d.major}.${d.minor}.${d.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let m=n.metadata.namespace_?.toString()??"";for(let[i,u]of Object.entries(t))try{let d=await this.getPropertyMetadata(i,n,r,s,a);if(!d){let l=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;Y(l)||c.push({key:i,sourceDoc:m});continue}let f=await this.parsePropertyValue(i,u,d,n,r,a,s);f&&o.push(f)}catch(d){throw new Error(`Failed to parse property '${i}': ${d.message}`,{cause:d})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,m=c.type?.toString()??"",i=m.includes(".")?m.substring(m.lastIndexOf(".")+1):m,u=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),d=this.knownPropertyClasses.get(x(o.uri));if(!u.has(i)&&!d)return;let f=d??s.getPropertyTypeClassification(m),l,y=async()=>{if(l)return l;if(!(o.isImported&&o.definedInNamespace))return l=n,n;if(typeof a.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${t}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let v=await a.getDocumentAsync(o.definedInNamespace);if(!v)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);return l=v,v},k=await this.readDefinitionSlot(c,me,y,r),S=k==null?void 0:String(k),D;if(f==="ObjectProperty")D="ObjectProperty";else if(f==="DatatypeProperty")D="DatatypeProperty";else{let v=S&&S.includes(".")?S.substring(S.lastIndexOf(".")+1):S??"";(S?s.isKnownXsdDatatypeName(S):!1)||v==="Literal"?D="DatatypeProperty":D="ObjectProperty"}let z;return S&&(z=(await r.resolveEntityAsync(S,await y()))?.uri),{propertyUri:o.uri.toString(),propertyType:D,range:S,rangeUri:z,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>fe(i)===n.name);if(s.length===0)return;let o=await r(),c=N(n.name),m=c!==void 0&&c.publisher===n.publisher&&c.package_===n.package_;for(let i of s){let u=await a.resolveEntityAsync(i,o);if(u){if(_(u.uri,n))return t[i];continue}if(!i.includes(".")&&m)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let m=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(m,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(m,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(m,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?B(r.rangeUri):void 0;if(s===h.Boolean){let c=new M;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===h.Integer||s===h.Decimal||s===h.Double||s===h.Float){let c=new T;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=R.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new j,a=n.rangeUri?B(n.rangeUri):void 0;return a===h.Boolean?r.value=t==="true"||t==="1":a===h.Integer||a===h.Decimal||a===h.Double||a===h.Float?r.value=Number(t):r.value=t,a&&(r.carrier=a,r.lexical=t),r}async parseSubstitutableValue(t,n,r,a){let s=new I;s.predicate=g.parse(t),s.object=n;for(let o of V(n)){let c=await a.resolveEntityAsync(o.reference,r),m;c&&(m=new g,m.subject=c.uri);let i={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(i.displayText=o.displayText),m!==void 0&&(i.target=m),s.links.push(i)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&_(r.rangeUri,E.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let m=await this.resolveReference(n,a,s);if(!m)return;let i=new O;return i.predicate=g.parse(t),i.object=m,i}if(typeof n=="object"&&!Array.isArray(n)){let m=await this.parseStatements(n,a,s,o,c);if(m.statements.length>0){let d=new b;d.statement=m.statements,d.unresolvedPredicates=m.unresolved;let f=new K;return f.predicate=g.parse(t),f.object=d,f}let i=[];for(let[d,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let l=new b;l.name=d;let y=await this.parseStatements(f,a,s,o,c);l.statement=y.statements,l.unresolvedPredicates=y.unresolved,i.push(l)}else if(typeof f=="string"){let l=await this.resolveReference(f,a,s);l&&i.push(l)}if(i.length>0){let d=new P;return d.predicate=g.parse(t),d.object=i,d}let u=new K;return u.predicate=g.parse(t),u.object=new b,u}}coerceExpressionLiteral(t,n,r){let a=new b,s=new O,o=new g;o.subject=new L("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new L(r.publisher,r.package_,E.StringLiteral.name,r.version),s.object=c;let m=new R,i=new g;i.subject=new L(r.publisher,r.package_,E.stringLiteral.name,r.version),m.predicate=i,m.object=n,a.statement=[s,m];let u=new K;return u.predicate=g.parse(t),u.object=a,u}async parseListValue(t,n,r,a,s,o,c){let m=[],i=r.propertyType==="DatatypeProperty",u=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let f of n){let l=typeof f=="string"||typeof f=="number"||typeof f=="boolean";if(i&&l){let y=typeof f=="string"?f:String(f);m.push(this.typedListLiteral(y,r));continue}if(u&&l){if(typeof f=="string"){let y=await s.resolveEntityAsync(f,a);if(y){let k=new g;k.subject=y.uri,m.push(k)}else{let k=new j;k.value=f,m.push(k)}}else{let y=new j;y.value=f,m.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&m.push(y)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let y=new b,k=await this.parseStatements(f,a,s,o,c);y.statement=k.statements,y.unresolvedPredicates=k.unresolved,m.push(y)}}let d=new P;return d.predicate=g.parse(t),d.object=m,d}async resolveReference(t,n,r){let a=await r.resolveEntityAsync(t,n);if(a){let o=new g;return o.subject=a.uri,o}let s=n.metadata?.namespace_;if(s){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let m=t.indexOf("."),i=t.substring(0,m),u=t.substring(m+1);if(n.metadata?.imports){for(let[d,f]of Object.entries(n.metadata.imports))for(let l of f)if((l.alias??l.packageName)===i){let k=new g;return k.subject=new o(d,l.packageName,u,l.version),k}}}let c=new g;return c.subject=new o(s.publisher,s.package_,t,s.version??void 0),c}return null}async saveKanonaks(t,n){let r=new Map;for(let a of t)a instanceof w&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,s]of r){let o=await this.convertKanonaksToDocument(a,s),c=`${a.split("@")[0]}.yml`;await n.saveDocumentAsync(o,c)}}async serializeToYaml(t,n){let r=t.filter(o=>o instanceof w&&o.namespace===n);if(r.length===0)throw new Error(`No kanonaks found with namespace '${n}'`);let a=await this.convertKanonaksToDocument(n,r);return new G().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let m of o.statement){let[i,u]=this.convertStatementToProperty(m);i&&u!==null&&u!==void 0&&(c[i]=u),this.collectImportsFromStatement(m,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof R)return[t.predicate.subject.name,t.object];if(t instanceof T)return[t.predicate.subject.name,t.object];if(t instanceof M)return[t.predicate.subject.name,t.object];if(t instanceof O)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof P){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof K){let n=this.convertEmbeddedKanonakToValue(t.object);return[t.predicate.subject.name,n]}return[null,null]}convertKanonakListToValue(t){let n=[];for(let r of t)r instanceof g?n.push(r.subject.name):r instanceof b&&n.push(this.convertEmbeddedKanonakToValue(r));return n}convertEmbeddedKanonakToValue(t){let n={};for(let r of t.statement){let[a,s]=this.convertStatementToProperty(r);a&&s!==null&&s!==void 0&&(n[a]=s)}return n}collectImportsFromStatement(t,n,r){}};function F(p,t){p.sourceDoc=t;for(let n of p.statement)if(n instanceof K)F(n.object,t);else if(n instanceof P)for(let r of n.object)r instanceof b&&F(r,t)}function $(p){let t=p.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+ue(p)}function ue(p){return p instanceof I?"m:"+String(p.object):p instanceof R?"s:"+String(p.object):p instanceof T?"n:"+String(p.object):p instanceof M?"b:"+String(p.object):p instanceof O?"r:"+C(p.object):p instanceof K?"e:"+C(p.object):p instanceof P?"l:["+(p.object??[]).map(C).join("|")+"]":"x"}function C(p){if(!p)return"";if(p instanceof g){let t=p.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return p instanceof b?"E("+(p.statement??[]).map($).join(";")+")":p instanceof j?"L("+String(p.value)+")":"N"}export{b as a,j as b,I as c,ne as d,ae as e,oe as f,Ke as g,E as h,h as i,B as j,ve as k,V as l,re as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as A}from"./chunk-M7OWTFTC.js";import{a as P}from"./chunk-6VIUXP4N.js";import{a as f}from"./chunk-KOWDHKBN.js";import{c as K,g as I,j as R}from"./chunk-QILEJIFU.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=c.resolve(e),this.recursive=t,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;return R(r,t)});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return K(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],h=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,h)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let o=b(n).toString(),s;for(let[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return b(t).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as g from"fs";var F=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(F||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as x}from"os";import{join as _}from"path";function d(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||_(x(),".kanonak","packages")}var w=class u{static createComposite(e,t,n){let o=e??d(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{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 this.lock.packages[`${e}/${t}`]?.version}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=I(n);if(o){let s={...t,versionOperator: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 $,readdirSync as B}from"fs";import{join as S}from"path";var H=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(u,e=[]){for(let t of B(u,{withFileTypes:!0}))t.isDirectory()?H.has(t.name)||C(S(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(S(u,t.name));return e}async function V(u,e=new f,t={}){let n=new P(e);for(let m of C(u))try{let l=e.parse($(m,"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),s=new Map,a=t.httpCache??{getFromCache:(m,l,p)=>s.get(`${m}|${l}|${p}`)??null,onFetch:(m,l,p,h)=>{s.set(`${m}|${l}|${p}`,h)}},r=new A({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,F as b,k as c,d,w as e,D as f,v as g,C as h,V as i};
|
|
1
|
+
import{n as A}from"./chunk-P5VQEDBS.js";import{a as P}from"./chunk-6VIUXP4N.js";import{a as f}from"./chunk-KOWDHKBN.js";import{c as K,g as I,j as R}from"./chunk-QILEJIFU.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=c.resolve(e),this.recursive=t,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;return R(r,t)});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,p=r.metadata.namespace_.version;return K(p,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),p=m[0],h=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,p,h)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let o=b(n).toString(),s;for(let[m,p]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&p.metadata.namespace_){s=p.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return b(t).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as g from"fs";var F=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(F||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as x}from"os";import{join as _}from"path";function d(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||_(x(),".kanonak","packages")}var w=class u{static createComposite(e,t,n){let o=e??d(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{VersionOperator as H}from"@kanonak-protocol/types/document/models/enums";var v=class{constructor(e,t){this.base=e;this.lock=t}base;lock;pinnedVersion(e,t){return this.lock.packages[`${e}/${t}`]?.version}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=I(n);if(o){let s={...t,versionOperator:H.Exact,version:o};return this.base.getHighestCompatibleVersionAsync(e,s)}}return this.base.getHighestCompatibleVersionAsync(e,t)}async getDocumentsByNamespaceAsync(e,t){let n=await this.base.getDocumentsByNamespaceAsync(e,t),o=this.pinnedVersion(e,t);return o?n.filter(s=>{let a=s.metadata.namespace_?.version;return a?`${a.major}.${a.minor}.${a.patch}`===o:!1}):n}getAllDocumentsAsync(){return this.base.getAllDocumentsAsync()}getDocumentAsync(e){return this.base.getDocumentAsync(e)}saveDocumentAsync(e,t){return this.base.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.base.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.base.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.base.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.base.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.base.getDocumentUriAsync(e)}};import{readFileSync as N,readdirSync as $}from"fs";import{join as S}from"path";var B=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(u,e=[]){for(let t of $(u,{withFileTypes:!0}))t.isDirectory()?B.has(t.name)||C(S(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(S(u,t.name));return e}async function V(u,e=new f,t={}){let n=new P(e);for(let m of C(u))try{let p=e.parse(N(m,"utf-8")),l=p.metadata?.namespace_,h=l?.version;l&&h&&await n.saveDocumentAsync(p,`${l.publisher}/${l.package_}@${h.major}.${h.minor}.${h.patch}`)}catch{}let o=new y(d(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,p,l)=>s.get(`${m}|${p}|${l}`)??null,onFetch:(m,p,l,h)=>{s.set(`${m}|${p}|${l}`,h)}},r=new A({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,F as b,k as c,d,w as e,D as f,v as g,C as h,V as i};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as m}from"./chunk-SC5M74NM.js";import{a as P}from"./chunk-KOWDHKBN.js";import{e as p,g as w,j as v}from"./chunk-QILEJIFU.js";var _="@kanonak-protocol/sdk (+https://kanonak.org)",y=_;function j(o){y=o}function B(){return y}function g(o){let t;try{t=typeof o=="string"?new URL(o):o}catch{throw new Error(`Kanonak requires an absolute https:// URL \u2014 got an unparseable or relative URL: ${String(o)}`)}if(t.protocol!=="https:")throw new Error(`Kanonak requires HTTPS \u2014 refusing to fetch ${t.href} (only https:// is supported).`)}var D=new Set([429,502,503,504]),U=4,K=500,R=2e4;function u(o,t){g(o);let e=new Headers(t?.headers);return e.has("User-Agent")||e.set("User-Agent",y),b(o,{...t,headers:e})}var d=U;function W(o){d=Math.max(0,o)}async function b(o,t){let e;for(let n=0;n<=d;n++){let r;try{r=await fetch(o,t)}catch(s){if(e=s,n>=d)throw s;await A(C(n,null));continue}if(!D.has(r.status)||n>=d)return r;await A(C(n,r.headers.get("retry-after")))}throw e??new Error("kanonakFetch: exhausted retries")}function C(o,t){let e=I(t);if(e!=null)return Math.min(e,R);let n=Math.min(R,K*2**o);return Math.floor(n/2+Math.random()*(n/2))}function I(o){if(!o)return null;let t=Number(o);if(Number.isFinite(t))return Math.max(0,t*1e3);let e=Date.parse(o);return Number.isNaN(e)?null:Math.max(0,e-Date.now())}function A(o){return new Promise(t=>setTimeout(t,o))}var T="https://{publisher}/{package}/{version}.kan.yml",x={version:1};function G(){return{version:1}}var k=class{constructor(t){this.fetchFn=t}fetchFn;cache=new Map;getConfig(t){let e=this.cache.get(t);return e||(e=this.fetchConfig(t),this.cache.set(t,e),e.catch(()=>{this.cache.get(t)===e&&this.cache.delete(t)})),e}async fetchConfig(t){let e=`https://${t}/.well-known/kanonak.json`,n;try{n=await(this.fetchFn?this.fetchFn(e,t):u(e))}catch{return x}if(n.status===404)return x;if(!n.ok)throw new Error(`Failed to fetch publisher config: ${e} (${n.status} ${n.statusText})`);let r=await n.json();if(typeof r.version!="number")throw new Error(`Invalid publisher config at ${e}: missing or invalid "version" field`);let s={version:r.version};return typeof r.package_url_template=="string"&&(M(e,"package_url_template",r.package_url_template),s.package_url_template=r.package_url_template),Array.isArray(r.featured_packages)&&r.featured_packages.every(a=>typeof a=="string")&&(s.featured_packages=r.featured_packages),s}resolvePackageUrl(t,e,n,r){let s=r.package_url_template??T,a=H(s,{publisher:t,package:e,version:n});return g(a),a}};function M(o,t,e){if(!e.startsWith("https://"))throw new Error(`Invalid publisher config at ${o}: ${t} must be an absolute https:// URL template (got "${e}").`)}function H(o,t){let e=o;for(let[r,s]of Object.entries(t))e=e.replaceAll(`{${r}}`,s);let n=e.match(/\{[a-z]+\}/);if(n)throw new Error(`Unresolved variable ${n[0]} in URL template: ${o}`);return e}import E from"js-yaml";var S=`# This file is generated by Kanonak CLI. Do not edit manually.
|
|
2
|
+
`,O="sha256:";function $(o){let t=E.load(o);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??"",packages:t.packages??{}}}function Y(o){let t={};for(let n of Object.keys(o.packages).sort())t[n]=o.packages[n];let e=E.dump({...o,packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'});return S+e}async function J(o){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(o)),e=Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("");return`${O}${e}`}var f=class{configResolver;fetchFn;lockCache=new Map;constructor(t){this.configResolver=t?.configResolver??new k(t?.fetchFn),this.fetchFn=t?.fetchFn}getConfig(t){return this.configResolver.getConfig(t)}async getPackageUrl(t,e,n){let r=await this.configResolver.getConfig(t);return this.configResolver.resolvePackageUrl(t,e,n,r)}getLock(t){let e=this.lockCache.get(t);return e||(e=this.fetchLock(t),this.lockCache.set(t,e),e.catch(()=>{this.lockCache.get(t)===e&&this.lockCache.delete(t)})),e}async fetchLock(t){let e=`https://${t}/kanonak.lock`,n;try{n=this.fetchFn?await this.fetchFn(e,t):await u(e)}catch{return null}if(n.status===404)return null;if(!n.ok)throw new Error(`Failed to fetch publisher lock: ${e} (${n.status} ${n.statusText})`);return $(await n.text())}};import{VersionOperator as F}from"@kanonak-protocol/types/document/models/enums";function N(o,t){let e=w(o);return e?v(e,t):!1}var L=class{parser=new P;publisherIndex;documents=new Map;contentCache=new Map;fetchFn;onFetch;getFromCache;constructor(t){this.onFetch=t?.onFetch,this.getFromCache=t?.getFromCache,this.fetchFn=t?.fetchFn,this.publisherIndex=t?.fetchFn?new f({fetchFn:t.fetchFn}):new f}async getHighestCompatibleVersionAsync(t,e){if(e.versionOperator===F.Exact){let s=await this.fromMemoOrCache(t,e.packageName,p(e.version));if(s)return s}let r=(await this.publisherIndex.getLock(t))?.packages[`${t}/${e.packageName}`];return r&&N(r.version,e)?this.fetchPinned(t,e.packageName,r):r&&e.versionOperator!==F.Exact?null:this.resolveByDirectFetch(t,e)}async fetchPinned(t,e,n){let r=n.version,s=`${t}/${e}@${r}`,a=await this.fromMemoOrCache(t,e,r);if(a)return a;let i=n.resolved,c=this.fetchFn?await this.fetchFn(i,t):await u(i);if(!c.ok)throw new Error(`Failed to fetch Kanonak package: ${i} (${c.status} ${c.statusText})`);let l=await c.text(),h=this.parser.parse(l);return m(h,t,e,r),this.onFetch&&await this.onFetch(t,e,r,l),this.documents.set(s,h),this.contentCache.set(s,l),h}async fromMemoOrCache(t,e,n){let r=`${t}/${e}@${n}`,s=this.documents.get(r);if(s)return s;if(!this.getFromCache)return null;let a=await this.getFromCache(t,e,n);if(a==null)return null;let i;try{i=this.parser.parse(a),m(i,t,e,n)}catch(c){throw new Error(`Cached content for ${r} is not a usable copy of that package \u2014 refusing to fall through to a fetch that would hide it. ${c.message}`,{cause:c})}return this.documents.set(r,i),this.contentCache.set(r,a),i}async resolveByDirectFetch(t,e){let n=e.packageName,s=e.versionOperator===F.Exact?await this.publisherIndex.getPackageUrl(t,n,p(e.version)):`https://${t}/${n}.kan.yml`,a=await this.fetchFollowing(s,t);if(!a)return null;let i=this.parser.parse(a.content),c=i.metadata.namespace_;if(!c||!c.version)throw new Error(`Producer origin returned a package with no namespace/version for ${t}/${n}`);let l=p(c.version);m(i,t,n,l);let h=`${t}/${n}@${l}`;return this.onFetch&&await this.onFetch(t,n,l,a.content),this.documents.set(h,i),this.contentCache.set(h,a.content),i}async fetchFollowing(t,e,n=4){let r=t;for(let s=0;s<n;s++){g(r);let a=this.fetchFn?await this.fetchFn(r,e):await u(r,{redirect:"manual"});if(a.status===301||a.status===302){let i=a.headers.get("location");if(!i)throw new Error(`Redirect with no Location header from ${r}`);r=new URL(i,r).toString();continue}if(a.status===404)return null;if(!a.ok)throw new Error(`Failed to fetch Kanonak package: ${r} (${a.status} ${a.statusText})`);return{url:r,content:await a.text()}}throw new Error(`Too many redirects resolving ${t}`)}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(t){return this.documents.get(t)??null}async getDocumentsByNamespaceAsync(t,e){return Array.from(this.documents.values()).filter(n=>{let r=n.metadata.namespace_;return r&&r.publisher===t&&r.package_===e})}async saveDocumentAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async deleteDocumentAsync(t){throw new Error("HttpKanonakDocumentRepository is read-only")}async clearNamespaceAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(t){return this.contentCache.get(t)??null}async getDocumentUriAsync(t){let e=t.match(/^(.+?)\/(.+?)@(.+)$/);if(!e)return null;let[,n,r,s]=e;return this.publisherIndex.getPackageUrl(n,r,s)}};export{_ as a,j as b,B as c,g as d,u as e,W as f,G as g,k as h,O as i,$ as j,Y as k,J as l,f as m,L as n};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as j,b as x,m as $}from"./chunk-ITI65NHP.js";import{da as U,e as l,f as u,g as b,h as C,i as a}from"./chunk-EKSYQ6CU.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-H6UAD2LP.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}},G={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}},H={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,G,H,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 R=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 P;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)}},P=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,R as e};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{e as F}from"./chunk-P5VQEDBS.js";import{I as me,J as he}from"./chunk-CYXNYNE7.js";import{a as te,b as $,c as le,i as z,m as D}from"./chunk-ITI65NHP.js";import{ba as ue,fa as O,ga as x,ha as ge,ia as B,ma as ye}from"./chunk-EKSYQ6CU.js";import{b as ne,c as E,d as _,f as oe,g as ae,h as se,i as ie,j as ce,k as pe,l as L,m as K,r as G,t as de,v as I,w as fe,y as V}from"./chunk-H6UAD2LP.js";import{a as re}from"./chunk-FUUTGGJS.js";import{d as ee}from"./chunk-QILEJIFU.js";var Ce=(s=>(s.Class="Class",s.DatatypeProperty="DatatypeProperty",s.ObjectProperty="ObjectProperty",s.AnnotationProperty="AnnotationProperty",s.Instance="Instance",s.Datatype="Datatype",s.Shape="Shape",s.Unknown="Unknown",s))(Ce||{}),Se=(s=>(s.InstanceOf="instanceOf",s.SubClassOf="subClassOf",s.Domain="domain",s.Range="range",s.ObjectRelationship="objectRelationship",s.SubPropertyOf="subPropertyOf",s.PropertyValue="propertyValue",s.EmbeddedLink="embeddedLink",s))(Se||{}),H=class{static async buildFromRepository(n,t){let o=await new D().parseKanonaks(n),a=await n.getAllDocumentsAsync(),c=[],i=[],s=new Set,d=new Set,f=new Map;for(let g of o){let u=g;if(u.name&&(O.isClassType(u)&&s.add(u.name),g instanceof E)){let l=B(o,g);(l==="ObjectProperty"||l==="Property")&&d.add(u.name)}}for(let g of a)for(let[u,l]of Object.entries(g.body))d.has(u)&&l?.range&&typeof l.range=="string"&&f.set(u,l.range);let p=new Map;for(let g of o){let u=g;u.name&&p.set(u.name,u)}for(let g of a){let u=g.metadata.namespace_,l=u?`${u.publisher}/${u.package_}`:"",m=u?.version?`${u.version.major}.${u.version.minor}.${u.version.patch}`:"",b=ke(g);for(let[h,y]of Object.entries(g.body)){if(!y||typeof y!="object")continue;let C=p.get(h),k="Unknown";if(C){let T=C,j=C instanceof E?B(o,C):void 0;O.isClassType(T)?k="Class":j==="ObjectProperty"?k="ObjectProperty":j==="DatatypeProperty"?k="DatatypeProperty":j==="AnnotationProperty"?k="AnnotationProperty":O.isDatatypeType(T)?k="Datatype":j==="Property"?k="ObjectProperty":O.isShapeType(T)?k="Shape":O.isInstanceOfKnownClass(T,s)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,Z={};for(let[T,j]of Object.entries(y))T!=="type"&&(typeof j!="object"||j===null)&&(Z[T]=j);c.push({id:S,label:y.label??h,type:k,namespace:l,properties:Z}),be(S,y,k,s,d,i,l,m,b,t),q(S,y,d,f,c,i,l,m,b),Le(S,C,i)}}return{nodes:c,edges:i}}static buildFromDocument(n,t){let r=[],o=[],a=n.metadata.namespace_,c=a?.version?`${a.version.major}.${a.version.minor}.${a.version.patch}`:"",i=a?`${a.publisher}/${a.package_}`:"",s=new Set,d=new Set,f=new Map,p=ke(n);for(let[l,m]of Object.entries(n.body)){let b=m?.type;b&&(Me(b,p)&&s.add(l),Ue(b,p)&&(d.add(l),m.range&&typeof m.range=="string"&&f.set(l,m.range)))}for(let[l,m]of Object.entries(n.body)){if(!m||typeof m!="object")continue;let b=m.type,h=Fe(b,l,s,p),y=i&&c?`${i}/${l}@${c}`:l,C={};for(let[k,S]of Object.entries(m))k!=="type"&&(typeof S!="object"||S===null)&&(C[k]=S);r.push({id:y,label:m.label??l,type:h,namespace:i,properties:C}),be(y,m,h,s,d,o,i,c,p,t),q(y,m,d,f,r,o,i,c,p)}let g=new Set(r.map(l=>l.id)),u=o.filter(l=>g.has(l.source)&&g.has(l.target));return{nodes:r,edges:u}}};function ke(e,n){let t=new Map;if(e.metadata?.imports)for(let[r,o]of Object.entries(e.metadata.imports))for(let a of o){let c=a.alias??a.packageName,i=a.version,s=`${i.major}.${i.minor}.${i.patch}`;t.set(c,{publisher:r,package_:a.packageName,version:s})}return t}var Oe={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},De=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function W(e,n){if(e.includes(".")){let t=e.indexOf("."),r=e.substring(0,t),o=e.substring(t+1),a=n.get(r);if(a)return`${a.publisher}/${a.package_}/${o}`}return null}function Me(e,n){let t=W(e,n);return t?Oe[t]==="Class":!1}function Ue(e,n){let t=W(e,n);return t?De.has(t):!1}function Fe(e,n,t,r){if(!e||e==="Package")return"Unknown";let o=W(e,r);if(o){let c=Oe[o];if(c)return c;let i=o.split("/").pop()?.split("@")[0]??"";return t.has(i)?"Instance":"Unknown"}let a=e.split(".").pop()??e;return t.has(a)?"Instance":"Unknown"}var ve=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function be(e,n,t,r,o,a,c,i,s,d){let f=n.type,p=n.subClassOf;if(p){let h=Array.isArray(p)?p:[p];for(let y of h)typeof y=="string"&&a.push({source:e,target:v(y,c,i,s),type:"subClassOf",label:"subClassOf"})}let g=n.subPropertyOf;if(g){let h=Array.isArray(g)?g:[g];for(let y of h)typeof y=="string"&&a.push({source:e,target:v(y,c,i,s),type:"subPropertyOf",label:"subPropertyOf"})}let u=n.domain,l=n.range;if(d?.includePropertyEdges){let h=[[u,"domain","domain"],[l,"range","range"]];for(let[y,C,k]of h)if(y!=null)for(let S of Array.isArray(y)?y:[y])typeof S=="string"&&a.push({source:e,target:v(S,c,i,s),type:C,label:k})}if(t==="Instance"&&f){let h=f.split(".").pop()??f;a.push({source:e,target:v(h,c,i,s),type:"instanceOf",label:"type"})}if(t==="Instance")for(let[h,y]of Object.entries(n)){if(ve.has(h)||!o.has(h))continue;let C=Array.isArray(y)?y:[y];for(let k of C)typeof k=="string"&&Ge(k)&&a.push({source:e,target:v(k,c,i,s),type:"propertyValue",label:h,propertyId:v(h,c,i,s)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||u&&l)&&u&&l){let h=typeof u=="string"?u:null,y=typeof l=="string"?l:null;h&&y&&a.push({source:v(h,c,i,s),target:v(y,c,i,s),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function q(e,n,t,r,o,a,c,i,s){for(let[d,f]of Object.entries(n)){if(ve.has(d)||typeof f!="object"||f===null||Array.isArray(f))continue;let p=f,g=`${e}/${d}`,u=r.get(d),l=u?u.split(".").pop()??u:"Unknown",m={};for(let[h,y]of Object.entries(p))(typeof y!="object"||y===null)&&(m[h]=y);o.push({id:g,label:`${l} (embedded)`,type:"Instance",namespace:c,properties:m});let b=c&&i?`${c}/${d}@${i}`:d;a.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?b:void 0}),u&&a.push({source:g,target:v(l,c,i,s),type:"instanceOf",label:"type (inferred)"}),q(g,p,t,r,o,a,c,i,s)}}function Le(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let o of r){if(!(o instanceof le))continue;let a=o.predicate?.subject?.name??"";for(let c of o.links){let i=c.target?.subject;if(!i)continue;let s=i.version,d=s&&typeof s.major=="number"?`@${s.major}.${s.minor}.${s.patch}`:"";t.push({source:e,target:`${i.publisher}/${i.package_}/${i.name}${d}`,type:"embeddedLink",label:a})}}}function Ge(e){return!(!e||e.includes(" ")||e.includes(`
|
|
2
|
+
`)||e.startsWith("http://")||e.startsWith("https://")||/^\d{4}-\d{2}/.test(e)||/^\d+(\.\d+)?$/.test(e))}function v(e,n,t,r){if(e.includes("@")&&e.includes("/"))return e;if(e.includes(".")){let o=e.indexOf("."),a=e.substring(0,o),c=e.substring(o+1);if(r){let i=r.get(a);if(i)return`${i.publisher}/${i.package_}/${c}@${i.version}`}return n&&t?`${n}/${c}@${t}`:c}return n&&t?`${n}/${e}@${t}`:e}import{canonicalForm as Ve,canonicalHash as Be}from"@kanonak-protocol/canonical";function X(e){return typeof e=="object"&&e!==null&&Array.isArray(e.subjects)}import{CANONICAL_FORM_VERSION as en}from"@kanonak-protocol/canonical";function ze(e){return Ve(X(e)?e:Pe(e))}function He(e){return Be(X(e)?e:Pe(e))}function Pe(e){let n=[];for(let t of e)t instanceof E&&n.push({uri:Ze(t),statements:Y(t.statement)});return{subjects:n}}function Y(e){let n=[];for(let t of e){let r=Qe(t);if(!r)continue;if(t instanceof L&&qe(t.predicate.subject)){n.push(...Xe(t,r));continue}let o=Ye(t);o&&n.push({predicate:r,value:o})}return n}function qe(e){let n=ue("type");return n!==void 0&&e.name==="type"&&e.publisher===n.publisher&&e.package_===n.package_}var we=new TextEncoder;function We(e,n){let t=we.encode(e),r=we.encode(n),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 Xe(e,n){let t=[];for(let r of e.object){if(!(r instanceof _))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(J(r))}t.sort(We);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:n,value:{ref:r}}))}function Ye(e){if(e instanceof oe&&e.carrier)return{lit:e.lexical??String(e.object),datatype:Te(e.carrier)};if(e instanceof ae)return{raw:e.object};if(e instanceof se)return{raw:e.lexical??String(e.object)};if(e instanceof ie)return{raw:e.lexical??String(e.object)};if(e instanceof ce)return{ref:J(e.object)};if(e instanceof pe)return je(e.object);if(e instanceof L)return{list:e.object.map(Je)}}function je(e){let n=Y(e.statement);return e.name&&e.name.length>0?{embed:{name:e.name,statements:n}}:{embed:{statements:n}}}function Je(e){if(e instanceof _)return{ref:J(e)};if(e instanceof te)return je(e);if(e instanceof $){if(e.carrier)return{lit:e.lexical??String(e.value),datatype:Te(e.carrier)};let n=e.value;if(typeof n=="string")return{raw:n};if(typeof n=="number")return{raw:String(n)};if(typeof n=="boolean")return{raw:String(n)}}if(e instanceof ne)return{embed:{statements:Y(e.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${e.constructor?.name??typeof e}); add canonicalization support before hashing data that contains it`)}function Te(e){return e===z.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${e}`}function Qe(e){let n=e.predicate;if(n)return Ee(n.subject)}function Ze(e){let n=e.namespace??"",t=e.name??"";return`${n}/${t}`}function J(e){return Ee(e.subject)}function Ee(e){let n=e.version;return n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}/${e.name}`:`${e.publisher}/${e.package_}/${e.name}`}function A(e){let n=e.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!n)throw new Error("Publisher host cannot be empty");return n}var nn="key_thumbprint",N=class{cache=new Map;prCache=new Map;async discoverProtectedResource(n){let t=A(n);if(this.prCache.has(t))return this.prCache.get(t);let r=`https://${t}/.well-known/oauth-protected-resource`,o=await tn(r),a=o&&Array.isArray(o.authorization_servers)?o.authorization_servers.filter(i=>typeof i=="string"):[],c=a.length>0?a:null;return this.prCache.set(t,c),c}async discover(n){let t=A(n);if(this.cache.has(t))return this.cache.get(t);let r=`https://${t}/.well-known/oauth-authorization-server`,o=await this.tryEndpoint(r);if(!o){let a=`https://${t}/.well-known/openid-configuration`;o=await this.tryEndpoint(a)}return this.cache.set(t,o),o}async supportsOAuth(n){return await this.discover(n)!==null}static supportsPkceS256(n){return n.codeChallengeMethodsSupported?.some(t=>t.toUpperCase()==="S256")??!1}static supportsDynamicRegistration(n){return!!n.registrationEndpoint}static supportsAuthorizationCode(n){return n.responseTypesSupported?.some(t=>t.toLowerCase()==="code")??!1}static supportsEnrollment(n){return!!n.enrollmentEndpoint}static supportsSession(n){return!!n.sessionEndpoint}async tryEndpoint(n){let t;try{t=await fetch(n)}catch(o){let a=o instanceof Error?o.message:String(o);return a.includes("ENOTFOUND")||a.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${n} \u2014 host unreachable (${a})`),console.error(" If the server is behind a VPN, ensure you are connected.")):a.includes("CERT")||a.includes("SSL")||a.includes("TLS")?(console.error(` OAuth discovery: ${n} \u2014 TLS error (${a})`),console.error(" If using a custom CA certificate, set NODE_EXTRA_CA_CERTS=/path/to/ca.pem")):console.error(` OAuth discovery: ${n} \u2014 network error: ${a}`),null}if(!t.ok)return t.status===404||(t.status===403?(console.error(` OAuth discovery: ${n} \u2014 HTTP 403 Forbidden`),console.error(" Access may be blocked by a firewall, proxy, or WAF.")):t.status>=500&&(console.error(` OAuth discovery: ${n} \u2014 HTTP ${t.status} server error`),console.error(" The authorization server returned an internal error. Contact your IDP administrator."))),null;let r;try{r=await t.json()}catch{return console.error(` OAuth discovery: ${n} \u2014 response is not valid JSON`),console.error(" The endpoint may be returning HTML instead of JSON. Check IDP configuration."),null}return{issuer:w(r.issuer),authorizationEndpoint:w(r.authorization_endpoint),tokenEndpoint:w(r.token_endpoint),registrationEndpoint:w(r.registration_endpoint),revocationEndpoint:w(r.revocation_endpoint),scopesSupported:P(r.scopes_supported),responseTypesSupported:P(r.response_types_supported),grantTypesSupported:P(r.grant_types_supported),codeChallengeMethodsSupported:P(r.code_challenge_methods_supported),tokenEndpointAuthMethodsSupported:P(r.token_endpoint_auth_methods_supported),dpopSigningAlgValuesSupported:P(r.dpop_signing_alg_values_supported),enrollmentEndpoint:w(r.enrollment_endpoint),enrollmentIssuanceProtocols:P(r.enrollment_issuance_protocols),enrollmentKeyTypes:P(r.enrollment_key_types),enrollmentScopesSupported:P(r.enrollment_scopes_supported),enrollmentConsentBindingParam:w(r.enrollment_consent_binding_param),sessionEndpoint:w(r.session_endpoint),sessionEndpointAuthMethod:w(r.session_endpoint_auth_method)}}};async function tn(e){try{let n=await fetch(e);return n.ok?await n.json():null}catch{return null}}function w(e){return typeof e=="string"?e:null}function P(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):null}function Re(e){let n=e.headers.get("WWW-Authenticate")??void 0,t=e.headers.get("DPoP-Nonce")??void 0;if(!n&&!t)return;let r={wwwAuthenticate:n??""};if(t&&(r.nonce=t),n){let o=n.match(/acr_values\s*=\s*"([^"]*)"/i);o&&(r.acrValues=o[1])}return r}function rn(e){try{return new URL(e).host}catch{return null}}function on(e,n={}){let t=n.discovery??new N,r=new Map,o=new Map,a=async s=>{let d=r.get(s);if(d!==void 0)return d;let f=null,p=await t.discoverProtectedResource(s).catch(()=>null);return p&&p.length>0&&(f=rn(p[0])),r.set(s,f),f},c=async(s,d)=>{if(!e)return null;if(!(d.forceRefresh||d.challenge)&&o.has(s))return o.get(s);let p=await e.resolve(s,d).catch(()=>null);return o.set(s,p),p},i=async(s,d,f,p)=>{let g=await a(d);if(!g)return{res:await F(s,{method:f,redirect:"manual"}),authed:!1};let u=await c(g,{method:f,url:s,...p}),l=u?.headers??{};return{res:await F(s,{method:f,redirect:"manual",headers:l}),authed:!!u}};return async(s,d,f="GET")=>{let p=await i(s,d,f,{});if((p.res.status===401||p.res.status===403)&&p.authed){let g=Re(p.res),u={forceRefresh:g===void 0};return g&&(u.challenge=g),(await i(s,d,f,u)).res}return p.res}}var _e="KANONAK_TOKEN";function an(){return typeof process<"u"&&process.env?process.env:{}}function sn(e){return`${_e}_${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}var Q=class{tokens;env;constructor(n={}){this.tokens=n.tokens??{},this.env=n.env??an()}async resolve(n,t){let r=A(n),o=this.tokens[r]??this.env[sn(r)]??this.env[_e];return o?{headers:{Authorization:`Bearer ${o}`}}:null}};var R="kanonak.org",U="core-rdf",Ie="core-xsd",Ae={publisher:R,package_:U,name:"subClassOf"},Ne={publisher:R,package_:U,name:"label"},$e={publisher:R,package_:U,name:"comment"},Ke={publisher:R,package_:"core-owl",name:"oneOf"},xe=e=>e;function cn(e){let n=fe(e,Ae);if(n)return[n];let t=[];for(let r of V(e,Ae))r instanceof _&&t.push(r.subject);return t}function pn(e,n,t){if(n.publisher===R&&n.package_===U&&n.name==="Literal")return{kind:"datatype",uri:n};let o=G(e,n);if(o){let a=xe(o);if(O.isDatatypeType(a))return{kind:"datatype",uri:n};if(O.isClassType(a))return{kind:"class",uri:x(o)??n,localName:o.name}}return n.publisher===R&&n.package_===Ie?{kind:"datatype",uri:n}:t==="datatype"?{kind:"datatype",uri:n}:{kind:"class",uri:n,localName:n.name}}function ln(e,n,t){if(!n.range)throw new Error(`Property ${n.uri.publisher}/${n.uri.package_}/${n.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let r=pn(e,n.range,n.kind),o=n.kind==="object"?"object":n.kind==="datatype"?"datatype":r.kind==="class"?"object":"datatype";return{uri:n.uri,localName:n.uri.name,kind:o,range:r,...n.label!==void 0?{label:n.label}:{},...n.comment!==void 0?{comment:n.comment}:{},...t??{}}}var M=e=>new re(R,Ie,e);function un(e){return typeof e=="boolean"?M("boolean"):typeof e=="number"?Number.isInteger(e)?M("integer"):M("decimal"):M("string")}function dn(e,n){let t=[];for(let r of V(n,Ke))if(r instanceof _){let o=G(e,r.subject),a=(o?x(o):void 0)??r.subject,c=o?I(o,Ne):void 0,i=o?I(o,$e):void 0;t.push({kind:"individual",uri:a,localName:a.name,...c!==void 0?{label:c}:{},...i!==void 0?{comment:i}:{}})}else r instanceof $&&t.push({kind:"literal",value:r.value,datatype:un(r.value)});return t}function fn(e,n,t,r){let o=ge(e,n),a=K(n);return ye(e,n).filter(i=>t?!0:i.domains.some(s=>K(s)===a)).map(i=>ln(e,i,he(r,o,i.uri)))}async function gn(e,n,t){let r=e.metadata?.namespace_;if(!r)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let o=t?.includeInherited??!1,a=await new D().parseKanonaks(n),c=me(a),i=[],s=[],d=new Set;for(let f of a){if(!(f instanceof E)||!O.isClassType(xe(f)))continue;let p=x(f);if(!p||p.publisher!==r.publisher||p.package_!==r.package_||p.version&&r.version&&!ee(p.version,r.version))continue;let g=K(p);if(d.has(g))continue;d.add(g);let u=cn(f).map(b=>({uri:b,localName:b.name})),l=I(f,Ne),m=I(f,$e);i.push({uri:p,localName:p.name,superClasses:u,properties:fn(a,p,o,c),...l!==void 0?{label:l}:{},...m!==void 0?{comment:m}:{}}),de(f,Ke)&&s.push({uri:p,localName:p.name,members:dn(a,f),...l!==void 0?{label:l}:{},...m!==void 0?{comment:m}:{}})}return{classes:i,enums:s}}export{Ce as a,Se as b,H as c,ze as d,He as e,en as f,A as g,nn as h,N as i,Re as j,on as k,Q as l,gn as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as D}from"./chunk-
|
|
1
|
+
import{a as D}from"./chunk-ITI65NHP.js";import{c as j,d as m,g as R,j as p,k as K,l as k}from"./chunk-H6UAD2LP.js";import{c as b,g as u}from"./chunk-QILEJIFU.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};
|
|
@@ -10,6 +10,8 @@ export declare enum NodeType {
|
|
|
10
10
|
AnnotationProperty = "AnnotationProperty",
|
|
11
11
|
Instance = "Instance",
|
|
12
12
|
Datatype = "Datatype",
|
|
13
|
+
/** A core-shacl shape (`Shape` / `NodeShape` / `PropertyShape`) — schema, not data (typescript#106). */
|
|
14
|
+
Shape = "Shape",
|
|
13
15
|
Unknown = "Unknown"
|
|
14
16
|
}
|
|
15
17
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { InMemoryKanonakDocumentRepository, FileSystemKanonakDocumentRepository, CompositeKanonakDocumentRepository, RepositoryFactory, DocumentLocation, HttpKanonakDocumentRepository, LocalFirstRepository, LockAwareRepository, buildLocalFirstRepository, collectKanonakFiles, PublisherIndex, PublisherConfigResolver, getGlobalCachePath } from './repositories/index.js';
|
|
2
|
-
export type { PublisherConfig, HttpCacheHooks } from './repositories/index.js';
|
|
2
|
+
export type { PublisherConfig, HttpCacheHooks, HttpCacheRead, HttpCacheWrite } from './repositories/index.js';
|
|
3
3
|
export { GraphBuilder, NodeType, EdgeType } from './graph/index.js';
|
|
4
4
|
export type { GraphNode, GraphEdge, GraphData } from './graph/index.js';
|
|
5
5
|
export { Reasoner, ReasoningResult, TripleStore, KanonakVocabulary, uriKey, makeUriKey, tripleKey, uriTriple, RDFS_RULES, OWL_RL_CLASSIFICATION_RULES, } from './reasoning/index.js';
|
|
@@ -16,7 +16,7 @@ export type { MarkdownLink } from './statements/index.js';
|
|
|
16
16
|
export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement, MarkdownStatement } from './statements/index.js';
|
|
17
17
|
export { extractMarkdownLinks, findMalformedReferences, type RawMarkdownLink, type MalformedMarkdownLink, } from './parsing/extractMarkdownLinks.js';
|
|
18
18
|
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyKindRangeConsistencyRule, ReservedNameShadowRule, ClassDefinitionRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, LookBandPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './validation/index.js';
|
|
19
|
-
export { scopeFromRepositoryAsync, scopeFromCatalog, scopeFromDocumentAsync, buildShapesModel, lowerConstraint, foldFlagsIntoPattern, evaluateConformance, buildReportPackageAsync, } from './shacl/index.js';
|
|
19
|
+
export { scopeFromRepositoryAsync, scopeFromCatalog, scopeFromDocumentAsync, buildShapesModel, lowerConstraint, foldFlagsIntoPattern, evaluateConformance, buildReportPackageAsync, SHACL_PUBLISHER, SHACL_PACKAGE, SH_SHAPE, SH_NODE_SHAPE, SH_PROPERTY_SHAPE, } from './shacl/index.js';
|
|
20
20
|
export type { ConformanceScope, ShaclNodeShapeModel, ShaclPropertyConstraint, ShaclNodeKind, ShaclSeverity, LoweredCheck, LoweredExprNode, ShaclConformanceResult, ShaclFinding, } from './shacl/index.js';
|
|
21
21
|
export type { IKanonakObjectValidator, DocumentValidationResult, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
|
|
22
22
|
export type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|