@kanonak-protocol/sdk 5.23.0 → 5.24.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.js CHANGED
@@ -1 +1 @@
1
- import{a as _,b as q,c as w,d as he,e as Ke,f as Se,g as Ie,i as be,j as je,k as Oe,l as De,m as ve}from"./chunk-FNLI7URD.js";import{a as Ve}from"./chunk-APWYAZMI.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 g}from"./chunk-M7OWTFTC.js";import{a as B,b as z,c as W}from"./chunk-ULHACEE2.js";import{a as X}from"./chunk-PEB52US5.js";import"./chunk-SC5M74NM.js";import{A as Pe,B as ge,L as Ce,a as Y,b as J,c as Q,d as Z,f as $,g as ee,h as oe,i as te,k as re,l as ne,m as ae,n as ie,o as se,p as pe,q as le,r as me,s as ce,t as ue,u as de,v as Re,w as ye,x as fe,y as ke,z as xe}from"./chunk-BPIAKTAV.js";import"./chunk-BRCVOR7A.js";import"./chunk-YM2V52DK.js";import{a as p}from"./chunk-6VIUXP4N.js";import{a as S,c as A,i as U,j as G,m as H}from"./chunk-LMD432SO.js";import{a as l}from"./chunk-KOWDHKBN.js";import"./chunk-PEJALHXK.js";import{a as F,b as L,o as M}from"./chunk-O6YV2SDB.js";import{a as C,b as h,c as K,d as b,e as j,f as O,g as D,h as V,i as v,j as E,k as N,l as T}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{de as AmbiguousReferenceRule,v as BooleanStatement,Se as CANONICAL_FORM_VERSION,U as Carrier,Pe as ClassDefinitionRule,ie as ClassHierarchyCycleRule,h as DefinedKanonak,q as EdgeType,S as EmbeddedKanonak,re as EmbeddedKanonakTypeRule,N as EmbeddedStatement,w as GraphBuilder,g as HttpKanonakDocumentRepository,y as INTEGRITY_PREFIX,ne as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,m as KANONAK_USER_AGENT,C as Kanonak,z as KanonakDocumentPositions,H as KanonakObjectParser,Ce as KanonakObjectValidator,l as KanonakParser,I as KanonakUri,X as KanonakUriBuilder,T as ListStatement,ge as MarkdownLinkRule,A as MarkdownStatement,ce as NamespaceImportCycleRule,$ as NamespacePrefixRule,_ as NodeType,V as NumberStatement,be as OAuthDiscovery,ye as ObjectPropertyValueValidationRule,Q as OntologyValidationError,Y as OntologyValidationResult,fe as PropertyDomainRule,se as PropertyHierarchyCycleRule,ke as PropertyKindRangeConsistencyRule,B as PropertyMetadata,Re as PropertyRangeReferenceRule,pe as PropertyRangeRequiredRule,oe as PropertyTypeSpecificityRule,R as PublisherConfigResolver,P as PublisherIndex,b as ReferenceKanonak,E as ReferenceStatement,xe as ReservedNameShadowRule,ee as ResourceNamingRule,F as ResourceResolver,M as ResourceTypeClassifier,O as ScalarStatement,j as Statement,D as StringStatement,le as SubClassOfReferenceRule,me as SubPropertyOfReferenceRule,K as SubjectKanonak,te as SubjectKanonakTypeRequiredRule,De as TokenCredentialProvider,L as TypeResolver,ue as UnresolvedPredicateRule,ae as UnresolvedReferenceRule,Z as ValidationContext,J as ValidationSeverity,ve as buildOntologyModel,he as canonicalForm,Ke as canonicalHash,G as carrierOf,e as compareVersions,x as computeIntegrityAsync,Oe as createCredentialedFetch,r as createVersion,Ve as findDerivation,t as formatVersion,u as getKanonakUserAgent,a as isCompatibleVersion,i as isMajorCompatible,d as kanonakFetch,Ie as normalizeHost,je as parseAuthChallenge,f as parseLockFile,n as parseVersionString,W as parseWithPositions,s as pickHighestDocument,k as serializeLockFile,c as setKanonakUserAgent,o as versionsEqual};
1
+ import{a as _,b as q,c as w,d as he,e as Ke,f as Se,g as Ie,i as be,j as je,k as Oe,l as De,m as ve}from"./chunk-RZ4WYL2X.js";import{a as Ve}from"./chunk-5GFOZL7D.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 g}from"./chunk-M7OWTFTC.js";import{a as B,b as z,c as W}from"./chunk-6YX2TDI5.js";import{a as X}from"./chunk-PEB52US5.js";import"./chunk-SC5M74NM.js";import{A as Pe,B as ge,L as Ce,a as Y,b as J,c as Q,d as Z,f as $,g as ee,h as oe,i as te,k as re,l as ne,m as ae,n as ie,o as se,p as pe,q as le,r as me,s as ce,t as ue,u as de,v as Re,w as ye,x as fe,y as ke,z as xe}from"./chunk-3XOXKMYB.js";import"./chunk-BRCVOR7A.js";import"./chunk-AND44TIS.js";import{a as p}from"./chunk-6VIUXP4N.js";import{a as S,c as A,i as U,j as G,m as H}from"./chunk-YU2VGLOT.js";import{a as l}from"./chunk-KOWDHKBN.js";import"./chunk-PEJALHXK.js";import{a as F,b as L,o as M}from"./chunk-O6YV2SDB.js";import{a as C,b as h,c as K,d as b,e as j,f as O,g as D,h as V,i as v,j as E,k as N,l as T}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{de as AmbiguousReferenceRule,v as BooleanStatement,Se as CANONICAL_FORM_VERSION,U as Carrier,Pe as ClassDefinitionRule,ie as ClassHierarchyCycleRule,h as DefinedKanonak,q as EdgeType,S as EmbeddedKanonak,re as EmbeddedKanonakTypeRule,N as EmbeddedStatement,w as GraphBuilder,g as HttpKanonakDocumentRepository,y as INTEGRITY_PREFIX,ne as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,m as KANONAK_USER_AGENT,C as Kanonak,z as KanonakDocumentPositions,H as KanonakObjectParser,Ce as KanonakObjectValidator,l as KanonakParser,I as KanonakUri,X as KanonakUriBuilder,T as ListStatement,ge as MarkdownLinkRule,A as MarkdownStatement,ce as NamespaceImportCycleRule,$ as NamespacePrefixRule,_ as NodeType,V as NumberStatement,be as OAuthDiscovery,ye as ObjectPropertyValueValidationRule,Q as OntologyValidationError,Y as OntologyValidationResult,fe as PropertyDomainRule,se as PropertyHierarchyCycleRule,ke as PropertyKindRangeConsistencyRule,B as PropertyMetadata,Re as PropertyRangeReferenceRule,pe as PropertyRangeRequiredRule,oe as PropertyTypeSpecificityRule,R as PublisherConfigResolver,P as PublisherIndex,b as ReferenceKanonak,E as ReferenceStatement,xe as ReservedNameShadowRule,ee as ResourceNamingRule,F as ResourceResolver,M as ResourceTypeClassifier,O as ScalarStatement,j as Statement,D as StringStatement,le as SubClassOfReferenceRule,me as SubPropertyOfReferenceRule,K as SubjectKanonak,te as SubjectKanonakTypeRequiredRule,De as TokenCredentialProvider,L as TypeResolver,ue as UnresolvedPredicateRule,ae as UnresolvedReferenceRule,Z as ValidationContext,J as ValidationSeverity,ve as buildOntologyModel,he as canonicalForm,Ke as canonicalHash,G as carrierOf,e as compareVersions,x as computeIntegrityAsync,Oe as createCredentialedFetch,r as createVersion,Ve as findDerivation,t as formatVersion,u as getKanonakUserAgent,a as isCompatibleVersion,i as isMajorCompatible,d as kanonakFetch,Ie as normalizeHost,je as parseAuthChallenge,f as parseLockFile,n as parseVersionString,W as parseWithPositions,s as pickHighestDocument,k as serializeLockFile,c as setKanonakUserAgent,o as versionsEqual};
@@ -1,4 +1,4 @@
1
- import{a as ut}from"./chunk-BRCVOR7A.js";import{k as dt}from"./chunk-YM2V52DK.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-LMD432SO.js";import{a as at}from"./chunk-KOWDHKBN.js";import{j as Ye,k as ct,o as v,p as w,q as z,r as W,s as Y,v as pt,w as L,x as lt}from"./chunk-O6YV2SDB.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:
1
+ import{a as ut}from"./chunk-BRCVOR7A.js";import{k as dt}from"./chunk-AND44TIS.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-YU2VGLOT.js";import{a as at}from"./chunk-KOWDHKBN.js";import{j as Ye,k as ct,o as v,p as w,q as z,r as W,s as Y,v as pt,w as L,x as lt}from"./chunk-O6YV2SDB.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{a as D}from"./chunk-LMD432SO.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};
1
+ import{a as D}from"./chunk-YU2VGLOT.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};
@@ -1,2 +1,2 @@
1
- import{l as V}from"./chunk-LMD432SO.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]===`
1
+ import{l as V}from"./chunk-YU2VGLOT.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};
@@ -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-LMD432SO.js";import{a as xn}from"./chunk-KOWDHKBN.js";import{a as zn}from"./chunk-PEJALHXK.js";import{p as Nn,q as Dn,r as Bn}from"./chunk-O6YV2SDB.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,`
1
+ import{a as Fn}from"./chunk-6VIUXP4N.js";import{a as V,c as Fe,h as u,m as Hn}from"./chunk-YU2VGLOT.js";import{a as xn}from"./chunk-KOWDHKBN.js";import{a as zn}from"./chunk-PEJALHXK.js";import{p as Nn,q as Dn,r as Bn}from"./chunk-O6YV2SDB.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,2 +1,2 @@
1
- import{e as F}from"./chunk-M7OWTFTC.js";import{I as me,J as he}from"./chunk-BPIAKTAV.js";import{a as te,b as $,c as le,i as z,m as D}from"./chunk-LMD432SO.js";import{k as ue,o as O,p as x,q as ge,r as B,v as ye}from"./chunk-O6YV2SDB.js";import{b as ne,c as T,d as _,f as oe,g as se,h as ae,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=(a=>(a.Class="Class",a.DatatypeProperty="DatatypeProperty",a.ObjectProperty="ObjectProperty",a.AnnotationProperty="AnnotationProperty",a.Instance="Instance",a.Datatype="Datatype",a.Unknown="Unknown",a))(Ce||{}),Se=(i=>(i.InstanceOf="instanceOf",i.SubClassOf="subClassOf",i.Domain="domain",i.Range="range",i.ObjectRelationship="objectRelationship",i.SubPropertyOf="subPropertyOf",i.PropertyValue="propertyValue",i.EmbeddedLink="embeddedLink",i))(Se||{}),H=class{static async buildFromRepository(n,t){let o=await new D().parseKanonaks(n),s=await n.getAllDocumentsAsync(),c=[],a=[],i=new Set,d=new Set,f=new Map;for(let g of o){let u=g;if(u.name&&(O.isClassType(u)&&i.add(u.name),g instanceof T)){let l=B(o,g);(l==="ObjectProperty"||l==="Property")&&d.add(u.name)}}for(let g of s)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 s){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 R=C,j=C instanceof T?B(o,C):void 0;O.isClassType(R)?k="Class":j==="ObjectProperty"?k="ObjectProperty":j==="DatatypeProperty"?k="DatatypeProperty":j==="AnnotationProperty"?k="AnnotationProperty":O.isDatatypeType(R)?k="Datatype":j==="Property"?k="ObjectProperty":O.isInstanceOfKnownClass(R,i)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,Z={};for(let[R,j]of Object.entries(y))R!=="type"&&(typeof j!="object"||j===null)&&(Z[R]=j);c.push({id:S,label:y.label??h,type:k,namespace:l,properties:Z}),be(S,y,k,i,d,a,l,m,b,t),q(S,y,d,f,c,a,l,m,b),Le(S,C,a)}}return{nodes:c,edges:a}}static buildFromDocument(n,t){let r=[],o=[],s=n.metadata.namespace_,c=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",a=s?`${s.publisher}/${s.package_}`:"",i=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)&&i.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,i,p),y=a&&c?`${a}/${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:a,properties:C}),be(y,m,h,i,d,o,a,c,p,t),q(y,m,d,f,r,o,a,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 s of o){let c=s.alias??s.packageName,a=s.version,i=`${a.major}.${a.minor}.${a.patch}`;t.set(c,{publisher:r,package_:s.packageName,version:i})}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),s=n.get(r);if(s)return`${s.publisher}/${s.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 a=o.split("/").pop()?.split("@")[0]??"";return t.has(a)?"Instance":"Unknown"}let s=e.split(".").pop()??e;return t.has(s)?"Instance":"Unknown"}var ve=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function be(e,n,t,r,o,s,c,a,i,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"&&s.push({source:e,target:v(y,c,a,i),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"&&s.push({source:e,target:v(y,c,a,i),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"&&s.push({source:e,target:v(S,c,a,i),type:C,label:k})}if(t==="Instance"&&f){let h=f.split(".").pop()??f;s.push({source:e,target:v(h,c,a,i),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)&&s.push({source:e,target:v(k,c,a,i),type:"propertyValue",label:h,propertyId:v(h,c,a,i)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||u&&l)&&u&&l){let h=typeof u=="string"?u:null,y=typeof l=="string"?l:null;h&&y&&s.push({source:v(h,c,a,i),target:v(y,c,a,i),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function q(e,n,t,r,o,s,c,a,i){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&&a?`${c}/${d}@${a}`:d;s.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?b:void 0}),u&&s.push({source:g,target:v(l,c,a,i),type:"instanceOf",label:"type (inferred)"}),q(g,p,t,r,o,s,c,a,i)}}function Le(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let o of r){if(!(o instanceof le))continue;let s=o.predicate?.subject?.name??"";for(let c of o.links){let a=c.target?.subject;if(!a)continue;let i=a.version,d=i&&typeof i.major=="number"?`@${i.major}.${i.minor}.${i.patch}`:"";t.push({source:e,target:`${a.publisher}/${a.package_}/${a.name}${d}`,type:"embeddedLink",label:s})}}}function Ge(e){return!(!e||e.includes(" ")||e.includes(`
1
+ import{e as F}from"./chunk-M7OWTFTC.js";import{I as me,J as he}from"./chunk-3XOXKMYB.js";import{a as te,b as $,c as le,i as z,m as D}from"./chunk-YU2VGLOT.js";import{k as ue,o as O,p as x,q as ge,r as B,v as ye}from"./chunk-O6YV2SDB.js";import{b as ne,c as T,d as _,f as oe,g as se,h as ae,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=(a=>(a.Class="Class",a.DatatypeProperty="DatatypeProperty",a.ObjectProperty="ObjectProperty",a.AnnotationProperty="AnnotationProperty",a.Instance="Instance",a.Datatype="Datatype",a.Unknown="Unknown",a))(Ce||{}),Se=(i=>(i.InstanceOf="instanceOf",i.SubClassOf="subClassOf",i.Domain="domain",i.Range="range",i.ObjectRelationship="objectRelationship",i.SubPropertyOf="subPropertyOf",i.PropertyValue="propertyValue",i.EmbeddedLink="embeddedLink",i))(Se||{}),H=class{static async buildFromRepository(n,t){let o=await new D().parseKanonaks(n),s=await n.getAllDocumentsAsync(),c=[],a=[],i=new Set,d=new Set,f=new Map;for(let g of o){let u=g;if(u.name&&(O.isClassType(u)&&i.add(u.name),g instanceof T)){let l=B(o,g);(l==="ObjectProperty"||l==="Property")&&d.add(u.name)}}for(let g of s)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 s){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 R=C,j=C instanceof T?B(o,C):void 0;O.isClassType(R)?k="Class":j==="ObjectProperty"?k="ObjectProperty":j==="DatatypeProperty"?k="DatatypeProperty":j==="AnnotationProperty"?k="AnnotationProperty":O.isDatatypeType(R)?k="Datatype":j==="Property"?k="ObjectProperty":O.isInstanceOfKnownClass(R,i)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,Z={};for(let[R,j]of Object.entries(y))R!=="type"&&(typeof j!="object"||j===null)&&(Z[R]=j);c.push({id:S,label:y.label??h,type:k,namespace:l,properties:Z}),be(S,y,k,i,d,a,l,m,b,t),q(S,y,d,f,c,a,l,m,b),Le(S,C,a)}}return{nodes:c,edges:a}}static buildFromDocument(n,t){let r=[],o=[],s=n.metadata.namespace_,c=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",a=s?`${s.publisher}/${s.package_}`:"",i=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)&&i.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,i,p),y=a&&c?`${a}/${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:a,properties:C}),be(y,m,h,i,d,o,a,c,p,t),q(y,m,d,f,r,o,a,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 s of o){let c=s.alias??s.packageName,a=s.version,i=`${a.major}.${a.minor}.${a.patch}`;t.set(c,{publisher:r,package_:s.packageName,version:i})}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),s=n.get(r);if(s)return`${s.publisher}/${s.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 a=o.split("/").pop()?.split("@")[0]??"";return t.has(a)?"Instance":"Unknown"}let s=e.split(".").pop()??e;return t.has(s)?"Instance":"Unknown"}var ve=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function be(e,n,t,r,o,s,c,a,i,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"&&s.push({source:e,target:v(y,c,a,i),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"&&s.push({source:e,target:v(y,c,a,i),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"&&s.push({source:e,target:v(S,c,a,i),type:C,label:k})}if(t==="Instance"&&f){let h=f.split(".").pop()??f;s.push({source:e,target:v(h,c,a,i),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)&&s.push({source:e,target:v(k,c,a,i),type:"propertyValue",label:h,propertyId:v(h,c,a,i)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||u&&l)&&u&&l){let h=typeof u=="string"?u:null,y=typeof l=="string"?l:null;h&&y&&s.push({source:v(h,c,a,i),target:v(y,c,a,i),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function q(e,n,t,r,o,s,c,a,i){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&&a?`${c}/${d}@${a}`:d;s.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?b:void 0}),u&&s.push({source:g,target:v(l,c,a,i),type:"instanceOf",label:"type (inferred)"}),q(g,p,t,r,o,s,c,a,i)}}function Le(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let o of r){if(!(o instanceof le))continue;let s=o.predicate?.subject?.name??"";for(let c of o.links){let a=c.target?.subject;if(!a)continue;let i=a.version,d=i&&typeof i.major=="number"?`@${i.major}.${i.minor}.${i.patch}`:"";t.push({source:e,target:`${a.publisher}/${a.package_}/${a.name}${d}`,type:"embeddedLink",label:s})}}}function Ge(e){return!(!e||e.includes(" ")||e.includes(`
2
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("."),s=e.substring(0,o),c=e.substring(o+1);if(r){let a=r.get(s);if(a)return`${a.publisher}/${a.package_}/${c}@${a.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 T&&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 s=0;s<o;s++)if(t[s]!==r[s])return t[s]-r[s];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 se)return{raw:e.object};if(e instanceof ae)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),s=o&&Array.isArray(o.authorization_servers)?o.authorization_servers.filter(a=>typeof a=="string"):[],c=s.length>0?s: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 s=`https://${t}/.well-known/openid-configuration`;o=await this.tryEndpoint(s)}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 s=o instanceof Error?o.message:String(o);return s.includes("ENOTFOUND")||s.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${n} \u2014 host unreachable (${s})`),console.error(" If the server is behind a VPN, ensure you are connected.")):s.includes("CERT")||s.includes("SSL")||s.includes("TLS")?(console.error(` OAuth discovery: ${n} \u2014 TLS error (${s})`),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: ${s}`),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,s=async i=>{let d=r.get(i);if(d!==void 0)return d;let f=null,p=await t.discoverProtectedResource(i).catch(()=>null);return p&&p.length>0&&(f=rn(p[0])),r.set(i,f),f},c=async(i,d)=>{if(!e)return null;if(!(d.forceRefresh||d.challenge)&&o.has(i))return o.get(i);let p=await e.resolve(i,d).catch(()=>null);return o.set(i,p),p},a=async(i,d,f,p)=>{let g=await s(d);if(!g)return{res:await F(i,{method:f,redirect:"manual"}),authed:!1};let u=await c(g,{method:f,url:i,...p}),l=u?.headers??{};return{res:await F(i,{method:f,redirect:"manual",headers:l}),authed:!!u}};return async(i,d,f="GET")=>{let p=await a(i,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 a(i,d,f,u)).res}return p.res}}var _e="KANONAK_TOKEN";function sn(){return typeof process<"u"&&process.env?process.env:{}}function an(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??sn()}async resolve(n,t){let r=A(n),o=this.tokens[r]??this.env[an(r)]??this.env[_e];return o?{headers:{Authorization:`Bearer ${o}`}}:null}};var E="kanonak.org",U="core-rdf",Ie="core-xsd",Ae={publisher:E,package_:U,name:"subClassOf"},Ne={publisher:E,package_:U,name:"label"},$e={publisher:E,package_:U,name:"comment"},Ke={publisher:E,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===E&&n.package_===U&&n.name==="Literal")return{kind:"datatype",uri:n};let o=G(e,n);if(o){let s=xe(o);if(O.isDatatypeType(s))return{kind:"datatype",uri:n};if(O.isClassType(s))return{kind:"class",uri:x(o)??n,localName:o.name}}return n.publisher===E&&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(E,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),s=(o?x(o):void 0)??r.subject,c=o?I(o,Ne):void 0,a=o?I(o,$e):void 0;t.push({kind:"individual",uri:s,localName:s.name,...c!==void 0?{label:c}:{},...a!==void 0?{comment:a}:{}})}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),s=K(n);return ye(e,n).filter(a=>t?!0:a.domains.some(i=>K(i)===s)).map(a=>ln(e,a,he(r,o,a.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,s=await new D().parseKanonaks(n),c=me(s),a=[],i=[],d=new Set;for(let f of s){if(!(f instanceof T)||!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);a.push({uri:p,localName:p.name,superClasses:u,properties:fn(s,p,o,c),...l!==void 0?{label:l}:{},...m!==void 0?{comment:m}:{}}),de(f,Ke)&&i.push({uri:p,localName:p.name,members:dn(s,f),...l!==void 0?{label:l}:{},...m!==void 0?{comment:m}:{}})}return{classes:a,enums:i}}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 j,b as x,m as $}from"./chunk-LMD432SO.js";import{e as l,f as u,g as b,h as C,i as a,m as U}from"./chunk-O6YV2SDB.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};
1
+ import{a as j,b as x,m as $}from"./chunk-YU2VGLOT.js";import{e as l,f as u,g as b,h as C,i as a,m as U}from"./chunk-O6YV2SDB.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 @@
1
+ import{a as G}from"./chunk-KOWDHKBN.js";import{a as H,b as J,j as Y,k as N,l as A,r as Z}from"./chunk-O6YV2SDB.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};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as Jt,b as Zt,c as Qt,d as eo,e as T}from"./chunk-GFLQ5TPR.js";import{a as qe,b as Xe,c as Ye}from"./chunk-DUM5Q4MH.js";import{a as qt,b as Xt,c as Yt,d as qo,e as Ee,f as Xo,g as Yo,h as Jo,i as Zo,j as Qo,k as er,l as nr,m as or}from"./chunk-FNLI7URD.js";import{a as tr}from"./chunk-APWYAZMI.js";import{a as dt,b as mt,c as ft,d as yt,e as kt,f as It,g as Kt,h as vt,i as wt}from"./chunk-WKLSD5DQ.js";import{a as ht,b as gt,c as St,d as bt,e as Et,f as Pt,h as Rt,i as Me,j as De,k as $e,l as Te,m as xt,n as Ct}from"./chunk-M7OWTFTC.js";import{a as to,b as oo,c as ro,d as ao}from"./chunk-ULHACEE2.js";import{a as io}from"./chunk-PEB52US5.js";import{a as _t}from"./chunk-SC5M74NM.js";import{A as Vo,B as jo,C as Uo,D as Ho,E as Mo,F as Fo,G as Bo,H as Go,K as Wo,L as zo,a as co,b as uo,c as po,d as lo,e as mo,f as fo,g as yo,h as ko,i as ho,j as go,k as So,l as bo,m as Eo,n as Po,o as Ro,p as xo,q as _o,r as Co,s as Io,t as Ko,u as vo,v as wo,w as No,x as Oo,y as Ao,z as Lo}from"./chunk-BPIAKTAV.js";import"./chunk-BRCVOR7A.js";import{a as Do,c as be,e as Ge,h as We,i as ze,j as $o,k as To}from"./chunk-YM2V52DK.js";import{a as le}from"./chunk-6VIUXP4N.js";import{a as x,b as D,c as ke,i as V,j as Se,k as Wt,l as zt,m as O}from"./chunk-LMD432SO.js";import{a as L}from"./chunk-KOWDHKBN.js";import{a as so}from"./chunk-PEJALHXK.js";import{a as jt,b as Ut,c as he,d as Ht,e as $,f as Mt,g as Dt,i as $t,m as Tt,o as Ft,p as g,q as Z,v as Bt,w as Gt,x as Q}from"./chunk-O6YV2SDB.js";import{a as Nt,b as Ot,c as S,d as k,e as Lt,f as Vt,g as de,h as me,i as fe,j as q,k as ye,l as X,m as p,p as Fe,r as _,t as Be,u as w,v as Y,w as h,x as ge,y as N,z as J}from"./chunk-H6UAD2LP.js";import{a as At}from"./chunk-FUUTGGJS.js";import{a as rt,b as pe,c as z,d as at,e as I,f as it,g as st,h as ct,i as ut,j as pt,k as lt}from"./chunk-QILEJIFU.js";import{a as no}from"./chunk-ODIECDN7.js";async function Je(n){let e=await new O().parseKanonaks(n),o=await new T().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Ze(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Qe(n,e){let o=e??new le(new L);return{kind:"standalone",catalog:await new O().parseKanonaks(new J(n,o))}}var Pe="kanonak.org",Re="core-shacl",c=n=>({publisher:Pe,package_:Re,name:n}),en=c("NodeShape"),Fr=c("PropertyShape"),nn=c("targetClass"),tn=c("property"),on=c("path"),rn=c("minCount"),an=c("maxCount"),sn=c("datatype"),cn=c("class"),xe=c("in"),un=c("pattern"),pn=c("flags"),ln=c("minLength"),dn=c("maxLength"),mn=c("minInclusive"),fn=c("maxInclusive"),yn=c("message"),kn=c("targetNode"),hn=c("targetSubjectsOf"),gn=c("targetObjectsOf"),Sn=c("closed"),bn=c("ignoredProperties"),En=c("nodeKind"),Pn=c("IRI"),Rn=c("BlankNode"),xn=c("Literal"),_e=c("severity"),_n=c("Violation"),Cn=c("Warning"),In=c("Info"),Br=c("ValidationReport"),Gr=c("conforms"),Wr=c("result"),zr=c("ValidationResult"),qr=c("focusNode"),Xr=c("resultPath"),Yr=c("resultMessage"),Jr=c("resultSeverity"),Zr=c("sourceShape"),Qr=c("value"),ea=c("sourceConstraintComponent"),Kn=c("MinCountConstraintComponent"),vn=c("MaxCountConstraintComponent"),wn=c("DatatypeConstraintComponent"),Nn=c("ClassConstraintComponent"),On=c("InConstraintComponent"),An=c("PatternConstraintComponent"),Ln=c("MinLengthConstraintComponent"),Vn=c("MaxLengthConstraintComponent"),jn=c("MinInclusiveConstraintComponent"),Un=c("MaxInclusiveConstraintComponent"),Hn=c("NodeKindConstraintComponent"),Ce=c("ClosedConstraintComponent");function H(n){return typeof n=="number"?n:void 0}function rr(n){if(!n)return;let e=p(n);if(e===p(Pn))return"IRI";if(e===p(Rn))return"BlankNode";if(e===p(xn))return"Literal"}function Mn(n){if(!n)return;let e=p(n);if(e===p(_n))return"Violation";if(e===p(Cn))return"Warning";if(e===p(In))return"Info"}function Ie(n,e){let o=h(n,e);if(o)return[o];let t=[];for(let r of N(n,e))r instanceof k&&t.push(r.subject);return t}function ar(n,e){let o=h(n,on);if(!o)return;let t={path:o},r=H(w(n,rn)),a=H(w(n,an));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=H(w(n,ln)),i=H(w(n,dn));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let u=H(w(n,mn)),d=H(w(n,fn));u!==void 0&&(t.minInclusive=u),d!==void 0&&(t.maxInclusive=d);let m=Y(n,un);if(m!==void 0){let P=Y(n,pn);t.pattern=P!==void 0?{regex:m,flags:P}:{regex:m}}if(Be(n,xe)){let P=[],j=[];for(let U of N(n,xe))U instanceof D?P.push(U.value):U instanceof k&&j.push(U.subject);P.length>0&&(t.inValues=P),j.length>0&&(t.inRefs=j)}let b=h(n,sn);b&&(t.datatype=b);let E=h(n,cn);E&&(t.classRef=E);let l=rr(h(n,En));l&&(t.nodeKind=l);let f=Y(n,yn);f!==void 0&&(t.message=f);let y=Mn(h(n,_e))??e;return y&&(t.severity=y),t}function ee(n){let e=[];for(let o of n){if(!(o instanceof S)||!Fe(o,en))continue;let t=Mn(h(o,_e)),r={name:o.name,uri:g(o),targetClass:h(o,nn),targetNodes:Ie(o,kn),targetSubjectsOf:Ie(o,hn),targetObjectsOf:Ie(o,gn),closed:w(o,Sn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of N(o,bn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of N(o,tn)){let s;if(a instanceof x?s=a:a instanceof k&&(s=_(n,a.subject)),!s)continue;let i=ar(s,t);i&&r.properties.push(i)}e.push(r)}return e}var C="kanonak.org/transformations",ne="values";var te="allowed",K=n=>({type:`${C}/VarRef`,varName:n}),Ke=n=>({type:`${C}/IntegerLiteral`,integerLiteral:n}),ir=n=>({type:`${C}/DecimalLiteral`,decimalLiteral:n}),Dn=n=>Number.isInteger(n)?Ke(n):ir(n),$n=n=>({type:`${C}/Count`,source:n}),Tn=(n,e)=>({type:`${C}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Fn=(n,e)=>({type:`${C}/LessThanOrEqual`,compareLeft:n,compareRight:e});function ve(n,e){if(!e||e.length===0)return n;let o=new Set(["i","m","s"]),t=[...new Set(e.split(""))];if(t.filter(a=>!o.has(a)).length>0)throw new Error(`sh:flags '${e}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${t.sort().join("")})${n}`}function oe(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Tn($n(K(ne)),Ke(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Fn($n(K(ne)),Ke(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${C}/Contains`,haystack:K(te),needle:K("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:ve(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Tn(K("v"),Dn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Fn(K("v"),Dn(n.maxInclusive))}),e}import{evaluate as cr,ExpressionError as ur}from"@kanonak-protocol/expression";function Wn(n,e){let o=pr(e)?e:ee(e),t=[];for(let r of o)for(let a of lr(n,r))fr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function pr(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function re(n){let e=n.predicate;return e instanceof k?e:void 0}function lr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof S),r=a=>{let s=g(a);o.set(s?p(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=p(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let u=g(i);u&&s.has(p(u))&&r(i)}}else for(let s of t)Q(s).some(u=>p(u)===a||Z(n.catalog,u).some(d=>p(d)===a))&&r(s)}for(let a of e.targetNodes){let s=_(n.catalog,a);s instanceof S&&r(s)}for(let a of e.targetSubjectsOf){let s=p(a);for(let i of t)i.statement.some(u=>{let d=re(u);return d&&p(d.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=p(a);for(let i of t)for(let u of i.statement){let d=re(u);if(!(!d||p(d.subject)!==s))for(let m of dr(u)){let b=_(n.catalog,m);b instanceof S&&r(b)}}}return[...o.values()]}function dr(n){return n instanceof q?[n.object.subject]:n instanceof X?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function mr(n,e,o){let t=[];for(let r of n.statement){let a=re(r);if(!(!a||p(a.subject)!==e)){if(r instanceof de||r instanceof ke)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof me)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof fe)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof q)t.push({kernel:{ref:p(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof ye)t.push(Bn(r.object,o,t.length));else if(r instanceof X){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:p(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof x)t.push(Bn(s,o,t.length));else if(s instanceof D){let i=s.value;typeof i=="boolean"?t.push({kernel:i?1:0,kind:"boolean",literal:i}):t.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return t}function Bn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function fr(n,e,o,t){let r=g(o),a=r?p(r):`${o.namespace}/${o.name}`;for(let s of e.properties)kr(n,e,o,a,r,s,t);e.closed&&Er(e,o,a,r,t)}function we(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??zn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function zn(n){return n.severity??"Violation"}var yr={minCount:Kn,maxCount:vn,in:On,pattern:An,minLength:Ln,maxLength:Vn,minInclusive:jn,maxInclusive:Un};function kr(n,e,o,t,r,a,s){let i=p(a.path),u=mr(o,i,t),d=a.severity??zn(e),m=a.path.name,b=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:p(l)}))],E=(l,f,y)=>{s.push(we(e,t,r,l,a.message??f,{resultPath:a.path,value:y?.literal,valueRef:y?.ref},d))};for(let l of oe(a)){let f=yr[l.component];if(l.per==="node"){Gn(l,{[ne]:u.map(P=>P.kernel),[te]:b})||E(f,l.component==="minCount"?`'${m}' has ${u.length} value(s); minCount is ${a.minCount}.`:`'${m}' has ${u.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let y of u){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&y.kind!=="string"){E(f,`'${m}' value is not a string; ${l.component} applies to string values.`,y);continue}Gn(l,{v:y.kernel,[te]:b})||E(f,hr(l,m,a,y),y)}}if(a.nodeKind)for(let l of u)gr(a.nodeKind,l)||E(Hn,`'${m}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of u){let f=Sr(a.datatype,l);f&&E(wn,`'${m}' ${f}`,l)}if(a.classRef)for(let l of u){let f=br(n,a.classRef,l);f&&E(Nn,`'${m}' ${f}`,l)}}function hr(n,e,o,t){let r=t.ref?p(t.ref):JSON.stringify(t.literal);switch(n.component){case"in":return`'${e}' value ${r} is not in the permitted set.`;case"pattern":return`'${e}' value ${r} does not match pattern ${o.pattern?.regex}.`;case"minLength":return`'${e}' value ${r} is shorter than minLength ${o.minLength}.`;case"maxLength":return`'${e}' value ${r} is longer than maxLength ${o.maxLength}.`;case"minInclusive":return`'${e}' value ${r} is below minInclusive ${o.minInclusive} (or not numeric).`;case"maxInclusive":return`'${e}' value ${r} is above maxInclusive ${o.maxInclusive} (or not numeric).`;default:return`'${e}' value ${r} violates ${n.component}.`}}function Gn(n,e){let o=t=>{let r=t.varName;if(t.type==="kanonak.org/transformations/VarRef"&&typeof r=="string"&&r in e)return e[r];throw new ur(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return cr(n.expr,void 0,o)===1}function gr(n,e){switch(n){case"IRI":return e.kind==="reference";case"BlankNode":return e.kind==="embedded";case"Literal":return e.kind==="string"||e.kind==="number"||e.kind==="boolean"}}function Sr(n,e){if(e.kind==="reference"||e.kind==="embedded")return`value is a ${e.kind}; sh:datatype requires a literal of ${n.name}.`;let o=Se(n);if(o!==void 0)switch(o){case V.Boolean:return e.kind==="boolean"?void 0:`value is not a boolean (${n.name}).`;case V.Integer:return e.kind!=="number"?`value is not a number (${n.name}).`:Number.isInteger(e.literal)?void 0:`value is not an integer (${n.name}).`;case V.Decimal:case V.Double:case V.Float:return e.kind==="number"?void 0:`value is not a number (${n.name}).`;default:return e.kind==="string"?void 0:`value is not a string-carried literal (${n.name}).`}}function br(n,e,o){if(o.kind!=="reference"||!o.ref)return`value is not a reference; sh:class requires an instance of ${e.name}.`;let t=p(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`;let r=_(n.catalog,o.ref);return r instanceof S?Q(r).some(s=>p(s)===t||Z(n.catalog,s).some(i=>p(i)===t))?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`:`value ${p(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function Er(n,e,o,t,r){let a=new Set([...n.properties.map(i=>p(i.path)),...n.ignoredProperties.map(i=>p(i))]),s=new Set;for(let i of e.statement){let u=re(i);if(!u)continue;let d=p(u.subject);a.has(d)||s.has(d)||(s.add(d),r.push(we(n,o,t,Ce,`'${e.name}' carries undeclared property '${u.subject.name}' (closed shape).`,{resultPath:u.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(we(n,o,t,Ce,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Ne from"js-yaml";import{VersionOperator as qn}from"@kanonak-protocol/types/document/models/enums";var Pr="0.0.0",A=class{constructor(e,o=new L,t){this.repository=e;this.parser=o;this.objectParser=t??new O(this.parser)}repository;parser;objectParser;imports(){return new F}serializeValue(e,o){return Jn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Oe(t),a={type:"EphemeralPackage",publisher:e.publisher,imports:o};e.contentHashProperty&&(a[e.contentHashProperty]=t),Object.assign(a,e.header??{}),a.imports=o;let s={[r]:a,...e.body},i=this.dump(s);return{yaml:i,byteCount:Yn(i),contentHash:t,packageName:r,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let o=e.book.toImports(),t={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:o},r;e.contentHashProperty&&(r=await this.hashBody(e.publisher,o,e.body),t[e.contentHashProperty]=r),Object.assign(t,e.header??{}),t.imports=o;let a={[e.name]:t,...e.body},s=this.dump(a),i={yaml:s,byteCount:Yn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Ne.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Xn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Ne.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),u=(await this.objectParser.parseKanonaks(new J(a,this.repository))).filter(d=>d instanceof S&&d.namespace===s&&d.name!==Xn);for(let d of u)d.namespace="ephemeral";return Ee(u)}},Xn="__pkgbuilder_probe__";function Yn(n){return new TextEncoder().encode(n).length}function Oe(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var F=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=qn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let u=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:u,match:a}),u}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,I(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Pr,r??o,qn.Any)}.${t}`}toImports(){let e=new Map;for(let t of this.byKey.values()){let r=e.get(t.publisher)??[];r.push(t),e.set(t.publisher,r)}return[...e.keys()].sort().map(t=>({publisher:t,packages:e.get(t).sort((r,a)=>r.package_<a.package_?-1:1).map(r=>({package:r.package_,match:pe(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=B(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Jn(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof k)return e.ref(n.subject);if(Array.isArray(n)){let o=n.map(t=>Jn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof x)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(Rr(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function B(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Rr(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var xr="1.1.0";async function Zn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Pe,Re,xr,"sh"),r=(i,u)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,I(i.version),i.package_)}.${i.name}`:u,a={},s=[];return n.result.results.forEach((i,u)=>{let d=`result-${u+1}`;s.push(d);let m={type:`${t}.ValidationResult`,[`${t}.focusNode`]:r(i.focusUri,i.focusNode),[`${t}.resultMessage`]:i.message,[`${t}.resultSeverity`]:`${t}.${i.severity}`,[`${t}.sourceConstraintComponent`]:`${t}.${i.constraintComponent.name}`};i.resultPath&&(m[`${t}.resultPath`]=r(i.resultPath,p(i.resultPath))),i.sourceShapeUri&&(m[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?m[`${t}.value`]=r(i.valueRef,p(i.valueRef)):i.value!==void 0&&(m[`${t}.value`]=i.value),a[d]=m}),a.report={type:`${t}.ValidationReport`,[`${t}.conforms`]:n.result.conforms,...s.length>0?{[`${t}.result`]:s}:{}},e.buildContentAddressed({publisher:n.publisher,book:o,body:a,...n.header!==void 0?{header:n.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as Hi}from"@kanonak-protocol/types/document/models/enums";var ae=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,o){return this.producers.find(t=>t.canProduce(e,o))}async produceCached(e,o,t,r){let a=`${o}/${t}@${I(r)}`,s=this.produced.get(a);if(s)return s;let{document:i}=await e.produce(o,t,r);return this.produced.set(a,i),i}async getHighestCompatibleVersionAsync(e,o){let t=this.producerFor(e,o.packageName);if(!t)return null;let r={operator:o.versionOperator,version:o.version},a=await t.resolveVersion(e,o.packageName,r);return a?this.produceCached(t,e,o.packageName,a):null}async getDocumentAsync(e){let o;try{o=he(e)}catch{return null}if(o.kind!=="package"||!o.version)return null;let t=this.producerFor(o.publisher,o.package_);return t?this.produceCached(t,o.publisher,o.package_,o.version):null}async getDocumentsByNamespaceAsync(e,o){return Array.from(this.produced.values()).filter(t=>{let r=t.metadata.namespace_;return r!=null&&r.publisher===e&&r.package_===o})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var Ae={async authorize(){return{allowed:!0}}},Le={async record(){}},G=class extends Error{constructor(o,t){let r=`${o.publisher}/${o.package_}${o.version?`@${o.version.major}.${o.version.minor}.${o.version.patch}`:""}`;super(`Not entitled to produce ${r}${t?`: ${t}`:""}`);this.address=o;this.reason=t;this.name="EntitlementDeniedError"}address;reason},ie=class{inner;ctx;policy;meter;constructor(e,o,t=Ae,r=Le){this.inner=e,this.ctx=o,this.policy=t,this.meter=r}canProduce(e,o){return this.inner.canProduce(e,o)}async resolveVersion(e,o,t){return await this.assertAllowed({publisher:e,package_:o,version:t.version}),this.inner.resolveVersion(e,o,t)}async produce(e,o,t){let r={publisher:e,package_:o,version:t};await this.assertAllowed(r);let a=await this.inner.produce(e,o,t);return await this.meter.record(this.ctx,r,a),a}async assertAllowed(e){let o=await this.policy.authorize(this.ctx,e);if(!o.allowed)throw new G(e,o.reason)}};var R="kanonak.org",v="view",Qn="core-kanonak",_r={publisher:R,package_:v,name:"rootView"},Cr={publisher:R,package_:v,name:"bind"},Ir={publisher:R,package_:v,name:"produces"},Kr={publisher:R,package_:v,name:"projections"},vr={publisher:R,package_:v,name:"where"},wr={publisher:R,package_:v,name:"value"},Nr={publisher:R,package_:v,name:"as"},se=class{constructor(e,o=new L){this.repository=e;this.parser=o;this.objectParser=new O(this.parser),this.builder=new A(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,o={}){let t=await this.objectParser.parseKanonaks(this.repository),r=this.resolveView(t,e),a=h(r,Cr);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=h(r,Ir);if(!s)throw new Error(`View ${r.namespace}/${r.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let i=Or(r),u=et(t,R,Qn),d=et(t,R,v),m=this.builder.imports(),b=m.ensure(R,Qn,u,"ck"),E=m.ensure(R,v,d,"v"),l=m.ref(s),f=new ze(this.repository,this.parser,this.objectParser),y=new Ge(f,t),P=this.readProjections(t,r),j=Vr(r,vr),U=this.findInstances(t,a,await this.reason(o)),Ve={},tt=new Set;for(let W of U){if(!await this.passesWhere(y,t,j,W))continue;let ue={type:l};for(let Ue of P){let ot=await this.evaluateValue(y,t,Ue.value,W),He=this.builder.serializeValue(nt(ot),m);He!==void 0&&(ue[m.ref(Ue.as)]=He)}let je=g(W);je&&(ue[`${E}.derivedFrom`]=m.ref(je)),Ve[this.rowName(W,tt)]=ue}let ce={};o.resolvedAt&&(ce[`${b}.resolvedAt`]=o.resolvedAt),o.invocationId&&(ce[`${b}.id`]=o.invocationId);let M=await this.builder.buildContentAddressed({publisher:i,book:m,body:Ve,contentHashProperty:`${b}.contentHash`,header:ce});return{yaml:M.yaml,contentHash:M.contentHash,packageName:M.packageName,publisher:M.publisher,rowCount:M.resourceCount}}resolveView(e,o){let t=_(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=h(t,_r);if(r){let a=_(e,r);if(!a)throw new Error(`ViewPackage ${o.name} names rootView ${r.name}, which is not in the catalog.`);return a}return t}readProjections(e,o){let t=[];for(let r of N(o,Kr)){let a=r instanceof x?r:r instanceof k?_(e,r.subject):void 0;if(!a)continue;let s=ge(a,wr),i=h(a,Nr);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new T({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Lr(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let u=r.get(i);u&&a.push(u)}return a.sort((i,u)=>{let d=$(g(i)),m=$(g(u));return d<m?-1:d>m?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!jr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=We(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=B(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function nt(n){return be(n)?n.value:Array.isArray(n)?n.map(nt):n}function Or(n){let e=g(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function et(n,e,o){let t=Ar(n,e,o);if(!t)throw new Error(`Package ${e}/${o} is not in the catalog; it must be importable to materialize a view.`);return t}function Ar(n,e,o){let t;for(let r of n){if(!(r instanceof S))continue;let a=g(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?I(t):void 0}function Lr(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof S))continue;let r=g(t);if(!r||!r.version)continue;let a=$(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Vr(n,e){let o=ge(n,e);return o?[o]:N(n,e).filter(t=>t instanceof x)}function jr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:be(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{vo as AmbiguousReferenceRule,fe as BooleanStatement,Xo as CANONICAL_FORM_VERSION,V as Carrier,Vo as ClassDefinitionRule,Po as ClassHierarchyCycleRule,ft as CompositeKanonakDocumentRepository,Jo as DEFAULT_CONSENT_BINDING_PARAM,Ot as DefinedKanonak,Wo as DiamondNameClashRule,Uo as DisplayLensScopeRule,mt as DocumentLocation,Xt as EdgeType,x as EmbeddedKanonak,So as EmbeddedKanonakTypeRule,ye as EmbeddedStatement,G as EntitlementDeniedError,ie as EntitlementProducer,dt as FileSystemKanonakDocumentRepository,no as GitIgnoreFilter,Yt as GraphBuilder,Ct as HttpKanonakDocumentRepository,Me as INTEGRITY_PREFIX,F as ImportBook,bo as ImportExistenceRule,le as InMemoryKanonakDocumentRepository,ht as KANONAK_USER_AGENT,Nt as Kanonak,oo as KanonakDocumentPositions,O as KanonakObjectParser,zo as KanonakObjectValidator,L as KanonakParser,At as KanonakUri,io as KanonakUriBuilder,so as KanonakUrlResolver,Tt as KanonakVocabulary,X as ListStatement,D as LiteralKanonak,It as LocalFirstRepository,Kt as LockAwareRepository,Mo as LookBandPathRule,$o as LookRenderer,Ho as LookSemanticSvgPathRule,jo as MarkdownLinkRule,ke as MarkdownStatement,Io as NamespaceImportCycleRule,fo as NamespacePrefixRule,qt as NodeType,me as NumberStatement,Zo as OAuthDiscovery,Qt as OWL_RL_CLASSIFICATION_RULES,No as ObjectPropertyValueValidationRule,po as OntologyValidationError,co as OntologyValidationResult,Go as OwlOneOfRule,A as PackageBuilder,go as PackageHeaderRule,ae as ProducerRepository,Oo as PropertyDomainRule,Ro as PropertyHierarchyCycleRule,Ao as PropertyKindRangeConsistencyRule,to as PropertyMetadata,wo as PropertyRangeReferenceRule,xo as PropertyRangeRequiredRule,ko as PropertyTypeSpecificityRule,Rt as PublisherConfigResolver,xt as PublisherIndex,Zt as RDFS_RULES,T as Reasoner,eo as ReasoningResult,k as ReferenceKanonak,q as ReferenceStatement,kt as RepositoryFactory,Lo as ReservedNameShadowRule,yo as ResourceNamingRule,jt as ResourceResolver,Ft as ResourceTypeClassifier,Vt as ScalarStatement,Bo as ShaclShapeRule,Lt as Statement,de as StringStatement,_o as SubClassOfReferenceRule,Co as SubPropertyOfReferenceRule,S as SubjectKanonak,ho as SubjectKanonakTypeRequiredRule,nr as TokenCredentialProvider,Jt as TripleStore,Fo as TxExpressionPathRule,Ut as TypeResolver,Ko as UnresolvedPredicateRule,Eo as UnresolvedReferenceRule,mo as ValidationCache,lo as ValidationContext,uo as ValidationSeverity,Hi as VersionOperator,se as ViewMaterializer,Ae as allowAllPolicy,bt as assertHttpsUrl,_t as assertPackageIdentity,wt as buildLocalFirstRepository,or as buildOntologyModel,Zn as buildReportPackageAsync,ee as buildShapesModel,qo as canonicalForm,Ee as canonicalHash,Se as carrierOf,vt as collectKanonakFiles,z as compareVersions,Ye as computeIntegrity,Te as computeIntegrityAsync,Oe as contentAddressedName,Q as contextTypesOf,er as createCredentialedFetch,it as createVersion,Wn as evaluateConformance,zt as extractMarkdownLinks,tr as findDerivation,Wt as findMalformedReferences,ao as findMarkdownLinkAt,ve as foldFlagsIntoPattern,Ht as formatKanonakAddress,I as formatVersion,yt as getGlobalCachePath,St as getKanonakUserAgent,ct as isCompatibleVersion,ut as isMajorCompatible,Et as kanonakFetch,qe as loadLockFile,oe as lowerConstraint,Mt as makeUriKey,Le as noopMeter,Yo as normalizeHost,Qo as parseAuthChallenge,he as parseKanonakAddress,De as parseLockFile,st as parseVersionString,ro as parseWithPositions,lt as pickHighestDocument,Bt as propertiesInScope,Do as resolveDisplayValue,Gt as resolvePropertyStep,B as sanitizeName,pt as satisfiesVersionOperator,Xe as saveLockFile,Ze as scopeFromCatalog,Qe as scopeFromDocumentAsync,Je as scopeFromRepositoryAsync,$e as serializeLockFile,Pt as setKanonakFetchRetries,gt as setKanonakUserAgent,g as subjectUri,Z as superClassChain,To as supportedBandKeys,Dt as tripleKey,$ as uriKey,$t as uriTriple,rt as versionOperatorFromChar,pe as versionOperatorToChar,at as versionsEqual};
1
+ import{a as Jt,b as Zt,c as Qt,d as eo,e as T}from"./chunk-USQLCG3Q.js";import{a as qe,b as Xe,c as Ye}from"./chunk-DUM5Q4MH.js";import{a as qt,b as Xt,c as Yt,d as qo,e as Ee,f as Xo,g as Yo,h as Jo,i as Zo,j as Qo,k as er,l as nr,m as or}from"./chunk-RZ4WYL2X.js";import{a as tr}from"./chunk-5GFOZL7D.js";import{a as dt,b as mt,c as ft,d as yt,e as kt,f as It,g as Kt,h as vt,i as wt}from"./chunk-WKLSD5DQ.js";import{a as ht,b as gt,c as St,d as bt,e as Et,f as Pt,h as Rt,i as Me,j as De,k as $e,l as Te,m as xt,n as Ct}from"./chunk-M7OWTFTC.js";import{a as to,b as oo,c as ro,d as ao}from"./chunk-6YX2TDI5.js";import{a as io}from"./chunk-PEB52US5.js";import{a as _t}from"./chunk-SC5M74NM.js";import{A as Vo,B as jo,C as Uo,D as Ho,E as Mo,F as Fo,G as Bo,H as Go,K as Wo,L as zo,a as co,b as uo,c as po,d as lo,e as mo,f as fo,g as yo,h as ko,i as ho,j as go,k as So,l as bo,m as Eo,n as Po,o as Ro,p as xo,q as _o,r as Co,s as Io,t as Ko,u as vo,v as wo,w as No,x as Oo,y as Ao,z as Lo}from"./chunk-3XOXKMYB.js";import"./chunk-BRCVOR7A.js";import{a as Do,c as be,e as Ge,h as We,i as ze,j as $o,k as To}from"./chunk-AND44TIS.js";import{a as le}from"./chunk-6VIUXP4N.js";import{a as x,b as D,c as ke,i as V,j as Se,k as Wt,l as zt,m as O}from"./chunk-YU2VGLOT.js";import{a as L}from"./chunk-KOWDHKBN.js";import{a as so}from"./chunk-PEJALHXK.js";import{a as jt,b as Ut,c as he,d as Ht,e as $,f as Mt,g as Dt,i as $t,m as Tt,o as Ft,p as g,q as Z,v as Bt,w as Gt,x as Q}from"./chunk-O6YV2SDB.js";import{a as Nt,b as Ot,c as S,d as k,e as Lt,f as Vt,g as de,h as me,i as fe,j as q,k as ye,l as X,m as p,p as Fe,r as _,t as Be,u as w,v as Y,w as h,x as ge,y as N,z as J}from"./chunk-H6UAD2LP.js";import{a as At}from"./chunk-FUUTGGJS.js";import{a as rt,b as pe,c as z,d as at,e as I,f as it,g as st,h as ct,i as ut,j as pt,k as lt}from"./chunk-QILEJIFU.js";import{a as no}from"./chunk-ODIECDN7.js";async function Je(n){let e=await new O().parseKanonaks(n),o=await new T().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Ze(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Qe(n,e){let o=e??new le(new L);return{kind:"standalone",catalog:await new O().parseKanonaks(new J(n,o))}}var Pe="kanonak.org",Re="core-shacl",c=n=>({publisher:Pe,package_:Re,name:n}),en=c("NodeShape"),Fr=c("PropertyShape"),nn=c("targetClass"),tn=c("property"),on=c("path"),rn=c("minCount"),an=c("maxCount"),sn=c("datatype"),cn=c("class"),xe=c("in"),un=c("pattern"),pn=c("flags"),ln=c("minLength"),dn=c("maxLength"),mn=c("minInclusive"),fn=c("maxInclusive"),yn=c("message"),kn=c("targetNode"),hn=c("targetSubjectsOf"),gn=c("targetObjectsOf"),Sn=c("closed"),bn=c("ignoredProperties"),En=c("nodeKind"),Pn=c("IRI"),Rn=c("BlankNode"),xn=c("Literal"),_e=c("severity"),_n=c("Violation"),Cn=c("Warning"),In=c("Info"),Br=c("ValidationReport"),Gr=c("conforms"),Wr=c("result"),zr=c("ValidationResult"),qr=c("focusNode"),Xr=c("resultPath"),Yr=c("resultMessage"),Jr=c("resultSeverity"),Zr=c("sourceShape"),Qr=c("value"),ea=c("sourceConstraintComponent"),Kn=c("MinCountConstraintComponent"),vn=c("MaxCountConstraintComponent"),wn=c("DatatypeConstraintComponent"),Nn=c("ClassConstraintComponent"),On=c("InConstraintComponent"),An=c("PatternConstraintComponent"),Ln=c("MinLengthConstraintComponent"),Vn=c("MaxLengthConstraintComponent"),jn=c("MinInclusiveConstraintComponent"),Un=c("MaxInclusiveConstraintComponent"),Hn=c("NodeKindConstraintComponent"),Ce=c("ClosedConstraintComponent");function H(n){return typeof n=="number"?n:void 0}function rr(n){if(!n)return;let e=p(n);if(e===p(Pn))return"IRI";if(e===p(Rn))return"BlankNode";if(e===p(xn))return"Literal"}function Mn(n){if(!n)return;let e=p(n);if(e===p(_n))return"Violation";if(e===p(Cn))return"Warning";if(e===p(In))return"Info"}function Ie(n,e){let o=h(n,e);if(o)return[o];let t=[];for(let r of N(n,e))r instanceof k&&t.push(r.subject);return t}function ar(n,e){let o=h(n,on);if(!o)return;let t={path:o},r=H(w(n,rn)),a=H(w(n,an));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=H(w(n,ln)),i=H(w(n,dn));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let u=H(w(n,mn)),d=H(w(n,fn));u!==void 0&&(t.minInclusive=u),d!==void 0&&(t.maxInclusive=d);let m=Y(n,un);if(m!==void 0){let P=Y(n,pn);t.pattern=P!==void 0?{regex:m,flags:P}:{regex:m}}if(Be(n,xe)){let P=[],j=[];for(let U of N(n,xe))U instanceof D?P.push(U.value):U instanceof k&&j.push(U.subject);P.length>0&&(t.inValues=P),j.length>0&&(t.inRefs=j)}let b=h(n,sn);b&&(t.datatype=b);let E=h(n,cn);E&&(t.classRef=E);let l=rr(h(n,En));l&&(t.nodeKind=l);let f=Y(n,yn);f!==void 0&&(t.message=f);let y=Mn(h(n,_e))??e;return y&&(t.severity=y),t}function ee(n){let e=[];for(let o of n){if(!(o instanceof S)||!Fe(o,en))continue;let t=Mn(h(o,_e)),r={name:o.name,uri:g(o),targetClass:h(o,nn),targetNodes:Ie(o,kn),targetSubjectsOf:Ie(o,hn),targetObjectsOf:Ie(o,gn),closed:w(o,Sn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of N(o,bn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of N(o,tn)){let s;if(a instanceof x?s=a:a instanceof k&&(s=_(n,a.subject)),!s)continue;let i=ar(s,t);i&&r.properties.push(i)}e.push(r)}return e}var C="kanonak.org/transformations",ne="values";var te="allowed",K=n=>({type:`${C}/VarRef`,varName:n}),Ke=n=>({type:`${C}/IntegerLiteral`,integerLiteral:n}),ir=n=>({type:`${C}/DecimalLiteral`,decimalLiteral:n}),Dn=n=>Number.isInteger(n)?Ke(n):ir(n),$n=n=>({type:`${C}/Count`,source:n}),Tn=(n,e)=>({type:`${C}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Fn=(n,e)=>({type:`${C}/LessThanOrEqual`,compareLeft:n,compareRight:e});function ve(n,e){if(!e||e.length===0)return n;let o=new Set(["i","m","s"]),t=[...new Set(e.split(""))];if(t.filter(a=>!o.has(a)).length>0)throw new Error(`sh:flags '${e}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${t.sort().join("")})${n}`}function oe(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Tn($n(K(ne)),Ke(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Fn($n(K(ne)),Ke(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${C}/Contains`,haystack:K(te),needle:K("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:ve(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${C}/Matches`,matchSource:K("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Tn(K("v"),Dn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Fn(K("v"),Dn(n.maxInclusive))}),e}import{evaluate as cr,ExpressionError as ur}from"@kanonak-protocol/expression";function Wn(n,e){let o=pr(e)?e:ee(e),t=[];for(let r of o)for(let a of lr(n,r))fr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function pr(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function re(n){let e=n.predicate;return e instanceof k?e:void 0}function lr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof S),r=a=>{let s=g(a);o.set(s?p(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=p(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let u=g(i);u&&s.has(p(u))&&r(i)}}else for(let s of t)Q(s).some(u=>p(u)===a||Z(n.catalog,u).some(d=>p(d)===a))&&r(s)}for(let a of e.targetNodes){let s=_(n.catalog,a);s instanceof S&&r(s)}for(let a of e.targetSubjectsOf){let s=p(a);for(let i of t)i.statement.some(u=>{let d=re(u);return d&&p(d.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=p(a);for(let i of t)for(let u of i.statement){let d=re(u);if(!(!d||p(d.subject)!==s))for(let m of dr(u)){let b=_(n.catalog,m);b instanceof S&&r(b)}}}return[...o.values()]}function dr(n){return n instanceof q?[n.object.subject]:n instanceof X?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function mr(n,e,o){let t=[];for(let r of n.statement){let a=re(r);if(!(!a||p(a.subject)!==e)){if(r instanceof de||r instanceof ke)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof me)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof fe)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof q)t.push({kernel:{ref:p(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof ye)t.push(Bn(r.object,o,t.length));else if(r instanceof X){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:p(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof x)t.push(Bn(s,o,t.length));else if(s instanceof D){let i=s.value;typeof i=="boolean"?t.push({kernel:i?1:0,kind:"boolean",literal:i}):t.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return t}function Bn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function fr(n,e,o,t){let r=g(o),a=r?p(r):`${o.namespace}/${o.name}`;for(let s of e.properties)kr(n,e,o,a,r,s,t);e.closed&&Er(e,o,a,r,t)}function we(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??zn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function zn(n){return n.severity??"Violation"}var yr={minCount:Kn,maxCount:vn,in:On,pattern:An,minLength:Ln,maxLength:Vn,minInclusive:jn,maxInclusive:Un};function kr(n,e,o,t,r,a,s){let i=p(a.path),u=mr(o,i,t),d=a.severity??zn(e),m=a.path.name,b=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:p(l)}))],E=(l,f,y)=>{s.push(we(e,t,r,l,a.message??f,{resultPath:a.path,value:y?.literal,valueRef:y?.ref},d))};for(let l of oe(a)){let f=yr[l.component];if(l.per==="node"){Gn(l,{[ne]:u.map(P=>P.kernel),[te]:b})||E(f,l.component==="minCount"?`'${m}' has ${u.length} value(s); minCount is ${a.minCount}.`:`'${m}' has ${u.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let y of u){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&y.kind!=="string"){E(f,`'${m}' value is not a string; ${l.component} applies to string values.`,y);continue}Gn(l,{v:y.kernel,[te]:b})||E(f,hr(l,m,a,y),y)}}if(a.nodeKind)for(let l of u)gr(a.nodeKind,l)||E(Hn,`'${m}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of u){let f=Sr(a.datatype,l);f&&E(wn,`'${m}' ${f}`,l)}if(a.classRef)for(let l of u){let f=br(n,a.classRef,l);f&&E(Nn,`'${m}' ${f}`,l)}}function hr(n,e,o,t){let r=t.ref?p(t.ref):JSON.stringify(t.literal);switch(n.component){case"in":return`'${e}' value ${r} is not in the permitted set.`;case"pattern":return`'${e}' value ${r} does not match pattern ${o.pattern?.regex}.`;case"minLength":return`'${e}' value ${r} is shorter than minLength ${o.minLength}.`;case"maxLength":return`'${e}' value ${r} is longer than maxLength ${o.maxLength}.`;case"minInclusive":return`'${e}' value ${r} is below minInclusive ${o.minInclusive} (or not numeric).`;case"maxInclusive":return`'${e}' value ${r} is above maxInclusive ${o.maxInclusive} (or not numeric).`;default:return`'${e}' value ${r} violates ${n.component}.`}}function Gn(n,e){let o=t=>{let r=t.varName;if(t.type==="kanonak.org/transformations/VarRef"&&typeof r=="string"&&r in e)return e[r];throw new ur(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return cr(n.expr,void 0,o)===1}function gr(n,e){switch(n){case"IRI":return e.kind==="reference";case"BlankNode":return e.kind==="embedded";case"Literal":return e.kind==="string"||e.kind==="number"||e.kind==="boolean"}}function Sr(n,e){if(e.kind==="reference"||e.kind==="embedded")return`value is a ${e.kind}; sh:datatype requires a literal of ${n.name}.`;let o=Se(n);if(o!==void 0)switch(o){case V.Boolean:return e.kind==="boolean"?void 0:`value is not a boolean (${n.name}).`;case V.Integer:return e.kind!=="number"?`value is not a number (${n.name}).`:Number.isInteger(e.literal)?void 0:`value is not an integer (${n.name}).`;case V.Decimal:case V.Double:case V.Float:return e.kind==="number"?void 0:`value is not a number (${n.name}).`;default:return e.kind==="string"?void 0:`value is not a string-carried literal (${n.name}).`}}function br(n,e,o){if(o.kind!=="reference"||!o.ref)return`value is not a reference; sh:class requires an instance of ${e.name}.`;let t=p(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`;let r=_(n.catalog,o.ref);return r instanceof S?Q(r).some(s=>p(s)===t||Z(n.catalog,s).some(i=>p(i)===t))?void 0:`value ${p(o.ref)} is not an instance of ${e.name}.`:`value ${p(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function Er(n,e,o,t,r){let a=new Set([...n.properties.map(i=>p(i.path)),...n.ignoredProperties.map(i=>p(i))]),s=new Set;for(let i of e.statement){let u=re(i);if(!u)continue;let d=p(u.subject);a.has(d)||s.has(d)||(s.add(d),r.push(we(n,o,t,Ce,`'${e.name}' carries undeclared property '${u.subject.name}' (closed shape).`,{resultPath:u.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(we(n,o,t,Ce,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Ne from"js-yaml";import{VersionOperator as qn}from"@kanonak-protocol/types/document/models/enums";var Pr="0.0.0",A=class{constructor(e,o=new L,t){this.repository=e;this.parser=o;this.objectParser=t??new O(this.parser)}repository;parser;objectParser;imports(){return new F}serializeValue(e,o){return Jn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Oe(t),a={type:"EphemeralPackage",publisher:e.publisher,imports:o};e.contentHashProperty&&(a[e.contentHashProperty]=t),Object.assign(a,e.header??{}),a.imports=o;let s={[r]:a,...e.body},i=this.dump(s);return{yaml:i,byteCount:Yn(i),contentHash:t,packageName:r,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let o=e.book.toImports(),t={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:o},r;e.contentHashProperty&&(r=await this.hashBody(e.publisher,o,e.body),t[e.contentHashProperty]=r),Object.assign(t,e.header??{}),t.imports=o;let a={[e.name]:t,...e.body},s=this.dump(a),i={yaml:s,byteCount:Yn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Ne.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Xn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Ne.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),u=(await this.objectParser.parseKanonaks(new J(a,this.repository))).filter(d=>d instanceof S&&d.namespace===s&&d.name!==Xn);for(let d of u)d.namespace="ephemeral";return Ee(u)}},Xn="__pkgbuilder_probe__";function Yn(n){return new TextEncoder().encode(n).length}function Oe(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var F=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=qn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let u=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,alias:u,match:a}),u}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,I(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Pr,r??o,qn.Any)}.${t}`}toImports(){let e=new Map;for(let t of this.byKey.values()){let r=e.get(t.publisher)??[];r.push(t),e.set(t.publisher,r)}return[...e.keys()].sort().map(t=>({publisher:t,packages:e.get(t).sort((r,a)=>r.package_<a.package_?-1:1).map(r=>({package:r.package_,match:pe(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=B(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Jn(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof k)return e.ref(n.subject);if(Array.isArray(n)){let o=n.map(t=>Jn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof x)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(Rr(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function B(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function Rr(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var xr="1.1.0";async function Zn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Pe,Re,xr,"sh"),r=(i,u)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,I(i.version),i.package_)}.${i.name}`:u,a={},s=[];return n.result.results.forEach((i,u)=>{let d=`result-${u+1}`;s.push(d);let m={type:`${t}.ValidationResult`,[`${t}.focusNode`]:r(i.focusUri,i.focusNode),[`${t}.resultMessage`]:i.message,[`${t}.resultSeverity`]:`${t}.${i.severity}`,[`${t}.sourceConstraintComponent`]:`${t}.${i.constraintComponent.name}`};i.resultPath&&(m[`${t}.resultPath`]=r(i.resultPath,p(i.resultPath))),i.sourceShapeUri&&(m[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?m[`${t}.value`]=r(i.valueRef,p(i.valueRef)):i.value!==void 0&&(m[`${t}.value`]=i.value),a[d]=m}),a.report={type:`${t}.ValidationReport`,[`${t}.conforms`]:n.result.conforms,...s.length>0?{[`${t}.result`]:s}:{}},e.buildContentAddressed({publisher:n.publisher,book:o,body:a,...n.header!==void 0?{header:n.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as Hi}from"@kanonak-protocol/types/document/models/enums";var ae=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,o){return this.producers.find(t=>t.canProduce(e,o))}async produceCached(e,o,t,r){let a=`${o}/${t}@${I(r)}`,s=this.produced.get(a);if(s)return s;let{document:i}=await e.produce(o,t,r);return this.produced.set(a,i),i}async getHighestCompatibleVersionAsync(e,o){let t=this.producerFor(e,o.packageName);if(!t)return null;let r={operator:o.versionOperator,version:o.version},a=await t.resolveVersion(e,o.packageName,r);return a?this.produceCached(t,e,o.packageName,a):null}async getDocumentAsync(e){let o;try{o=he(e)}catch{return null}if(o.kind!=="package"||!o.version)return null;let t=this.producerFor(o.publisher,o.package_);return t?this.produceCached(t,o.publisher,o.package_,o.version):null}async getDocumentsByNamespaceAsync(e,o){return Array.from(this.produced.values()).filter(t=>{let r=t.metadata.namespace_;return r!=null&&r.publisher===e&&r.package_===o})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,o){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var Ae={async authorize(){return{allowed:!0}}},Le={async record(){}},G=class extends Error{constructor(o,t){let r=`${o.publisher}/${o.package_}${o.version?`@${o.version.major}.${o.version.minor}.${o.version.patch}`:""}`;super(`Not entitled to produce ${r}${t?`: ${t}`:""}`);this.address=o;this.reason=t;this.name="EntitlementDeniedError"}address;reason},ie=class{inner;ctx;policy;meter;constructor(e,o,t=Ae,r=Le){this.inner=e,this.ctx=o,this.policy=t,this.meter=r}canProduce(e,o){return this.inner.canProduce(e,o)}async resolveVersion(e,o,t){return await this.assertAllowed({publisher:e,package_:o,version:t.version}),this.inner.resolveVersion(e,o,t)}async produce(e,o,t){let r={publisher:e,package_:o,version:t};await this.assertAllowed(r);let a=await this.inner.produce(e,o,t);return await this.meter.record(this.ctx,r,a),a}async assertAllowed(e){let o=await this.policy.authorize(this.ctx,e);if(!o.allowed)throw new G(e,o.reason)}};var R="kanonak.org",v="view",Qn="core-kanonak",_r={publisher:R,package_:v,name:"rootView"},Cr={publisher:R,package_:v,name:"bind"},Ir={publisher:R,package_:v,name:"produces"},Kr={publisher:R,package_:v,name:"projections"},vr={publisher:R,package_:v,name:"where"},wr={publisher:R,package_:v,name:"value"},Nr={publisher:R,package_:v,name:"as"},se=class{constructor(e,o=new L){this.repository=e;this.parser=o;this.objectParser=new O(this.parser),this.builder=new A(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,o={}){let t=await this.objectParser.parseKanonaks(this.repository),r=this.resolveView(t,e),a=h(r,Cr);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=h(r,Ir);if(!s)throw new Error(`View ${r.namespace}/${r.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let i=Or(r),u=et(t,R,Qn),d=et(t,R,v),m=this.builder.imports(),b=m.ensure(R,Qn,u,"ck"),E=m.ensure(R,v,d,"v"),l=m.ref(s),f=new ze(this.repository,this.parser,this.objectParser),y=new Ge(f,t),P=this.readProjections(t,r),j=Vr(r,vr),U=this.findInstances(t,a,await this.reason(o)),Ve={},tt=new Set;for(let W of U){if(!await this.passesWhere(y,t,j,W))continue;let ue={type:l};for(let Ue of P){let ot=await this.evaluateValue(y,t,Ue.value,W),He=this.builder.serializeValue(nt(ot),m);He!==void 0&&(ue[m.ref(Ue.as)]=He)}let je=g(W);je&&(ue[`${E}.derivedFrom`]=m.ref(je)),Ve[this.rowName(W,tt)]=ue}let ce={};o.resolvedAt&&(ce[`${b}.resolvedAt`]=o.resolvedAt),o.invocationId&&(ce[`${b}.id`]=o.invocationId);let M=await this.builder.buildContentAddressed({publisher:i,book:m,body:Ve,contentHashProperty:`${b}.contentHash`,header:ce});return{yaml:M.yaml,contentHash:M.contentHash,packageName:M.packageName,publisher:M.publisher,rowCount:M.resourceCount}}resolveView(e,o){let t=_(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=h(t,_r);if(r){let a=_(e,r);if(!a)throw new Error(`ViewPackage ${o.name} names rootView ${r.name}, which is not in the catalog.`);return a}return t}readProjections(e,o){let t=[];for(let r of N(o,Kr)){let a=r instanceof x?r:r instanceof k?_(e,r.subject):void 0;if(!a)continue;let s=ge(a,wr),i=h(a,Nr);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new T({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Lr(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let u=r.get(i);u&&a.push(u)}return a.sort((i,u)=>{let d=$(g(i)),m=$(g(u));return d<m?-1:d>m?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!jr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=We(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=B(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function nt(n){return be(n)?n.value:Array.isArray(n)?n.map(nt):n}function Or(n){let e=g(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function et(n,e,o){let t=Ar(n,e,o);if(!t)throw new Error(`Package ${e}/${o} is not in the catalog; it must be importable to materialize a view.`);return t}function Ar(n,e,o){let t;for(let r of n){if(!(r instanceof S))continue;let a=g(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?I(t):void 0}function Lr(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof S))continue;let r=g(t);if(!r||!r.version)continue;let a=$(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Vr(n,e){let o=ge(n,e);return o?[o]:N(n,e).filter(t=>t instanceof x)}function jr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:be(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{vo as AmbiguousReferenceRule,fe as BooleanStatement,Xo as CANONICAL_FORM_VERSION,V as Carrier,Vo as ClassDefinitionRule,Po as ClassHierarchyCycleRule,ft as CompositeKanonakDocumentRepository,Jo as DEFAULT_CONSENT_BINDING_PARAM,Ot as DefinedKanonak,Wo as DiamondNameClashRule,Uo as DisplayLensScopeRule,mt as DocumentLocation,Xt as EdgeType,x as EmbeddedKanonak,So as EmbeddedKanonakTypeRule,ye as EmbeddedStatement,G as EntitlementDeniedError,ie as EntitlementProducer,dt as FileSystemKanonakDocumentRepository,no as GitIgnoreFilter,Yt as GraphBuilder,Ct as HttpKanonakDocumentRepository,Me as INTEGRITY_PREFIX,F as ImportBook,bo as ImportExistenceRule,le as InMemoryKanonakDocumentRepository,ht as KANONAK_USER_AGENT,Nt as Kanonak,oo as KanonakDocumentPositions,O as KanonakObjectParser,zo as KanonakObjectValidator,L as KanonakParser,At as KanonakUri,io as KanonakUriBuilder,so as KanonakUrlResolver,Tt as KanonakVocabulary,X as ListStatement,D as LiteralKanonak,It as LocalFirstRepository,Kt as LockAwareRepository,Mo as LookBandPathRule,$o as LookRenderer,Ho as LookSemanticSvgPathRule,jo as MarkdownLinkRule,ke as MarkdownStatement,Io as NamespaceImportCycleRule,fo as NamespacePrefixRule,qt as NodeType,me as NumberStatement,Zo as OAuthDiscovery,Qt as OWL_RL_CLASSIFICATION_RULES,No as ObjectPropertyValueValidationRule,po as OntologyValidationError,co as OntologyValidationResult,Go as OwlOneOfRule,A as PackageBuilder,go as PackageHeaderRule,ae as ProducerRepository,Oo as PropertyDomainRule,Ro as PropertyHierarchyCycleRule,Ao as PropertyKindRangeConsistencyRule,to as PropertyMetadata,wo as PropertyRangeReferenceRule,xo as PropertyRangeRequiredRule,ko as PropertyTypeSpecificityRule,Rt as PublisherConfigResolver,xt as PublisherIndex,Zt as RDFS_RULES,T as Reasoner,eo as ReasoningResult,k as ReferenceKanonak,q as ReferenceStatement,kt as RepositoryFactory,Lo as ReservedNameShadowRule,yo as ResourceNamingRule,jt as ResourceResolver,Ft as ResourceTypeClassifier,Vt as ScalarStatement,Bo as ShaclShapeRule,Lt as Statement,de as StringStatement,_o as SubClassOfReferenceRule,Co as SubPropertyOfReferenceRule,S as SubjectKanonak,ho as SubjectKanonakTypeRequiredRule,nr as TokenCredentialProvider,Jt as TripleStore,Fo as TxExpressionPathRule,Ut as TypeResolver,Ko as UnresolvedPredicateRule,Eo as UnresolvedReferenceRule,mo as ValidationCache,lo as ValidationContext,uo as ValidationSeverity,Hi as VersionOperator,se as ViewMaterializer,Ae as allowAllPolicy,bt as assertHttpsUrl,_t as assertPackageIdentity,wt as buildLocalFirstRepository,or as buildOntologyModel,Zn as buildReportPackageAsync,ee as buildShapesModel,qo as canonicalForm,Ee as canonicalHash,Se as carrierOf,vt as collectKanonakFiles,z as compareVersions,Ye as computeIntegrity,Te as computeIntegrityAsync,Oe as contentAddressedName,Q as contextTypesOf,er as createCredentialedFetch,it as createVersion,Wn as evaluateConformance,zt as extractMarkdownLinks,tr as findDerivation,Wt as findMalformedReferences,ao as findMarkdownLinkAt,ve as foldFlagsIntoPattern,Ht as formatKanonakAddress,I as formatVersion,yt as getGlobalCachePath,St as getKanonakUserAgent,ct as isCompatibleVersion,ut as isMajorCompatible,Et as kanonakFetch,qe as loadLockFile,oe as lowerConstraint,Mt as makeUriKey,Le as noopMeter,Yo as normalizeHost,Qo as parseAuthChallenge,he as parseKanonakAddress,De as parseLockFile,st as parseVersionString,ro as parseWithPositions,lt as pickHighestDocument,Bt as propertiesInScope,Do as resolveDisplayValue,Gt as resolvePropertyStep,B as sanitizeName,pt as satisfiesVersionOperator,Xe as saveLockFile,Ze as scopeFromCatalog,Qe as scopeFromDocumentAsync,Je as scopeFromRepositoryAsync,$e as serializeLockFile,Pt as setKanonakFetchRetries,gt as setKanonakUserAgent,g as subjectUri,Z as superClassChain,To as supportedBandKeys,Dt as tripleKey,$ as uriKey,$t as uriTriple,rt as versionOperatorFromChar,pe as versionOperatorToChar,at as versionsEqual};
@@ -59,6 +59,32 @@ export declare class KanonakObjectParser implements IKanonakObjectParser {
59
59
  private resolveCanonicalEntity;
60
60
  private parseStatements;
61
61
  private getPropertyMetadata;
62
+ /**
63
+ * Read a slot off a raw entity body by the IDENTITY of its key, not its
64
+ * spelling (kanonak-protocol/typescript#103).
65
+ *
66
+ * During the first pass there is no catalog, so a property's definition
67
+ * is still the raw YAML body — keys exactly as authored. An alias is
68
+ * document-local and arbitrary: `range`, `rdfs.range`, and `xyz.range`
69
+ * may all name core-rdf's range. A literal `entity.range` read is
70
+ * therefore a SPELLING test, not an identity test — it misses every
71
+ * qualified form, and it trusts the bare form even when a local resource
72
+ * named `range` shadows the built-in. Both failures are silent.
73
+ *
74
+ * Candidate keys are those whose local name equals the target's. That is
75
+ * an exact prefilter, not a heuristic: `alias.name` can only ever resolve
76
+ * to `<package>/name`. The RESOLVER then decides, in the scope of the
77
+ * document that DEFINES the entity — the same way the statement path
78
+ * resolves predicates. A key that resolves to some other entity is not
79
+ * this slot. A bare key that resolves to nothing at all is accepted only
80
+ * when the name is a reserved built-in whose home is the target's
81
+ * package: the same rule by which a document importing no vocabulary may
82
+ * still write `range:` (see `isBuiltinTerm` in `parseStatements`).
83
+ *
84
+ * `definingDocument` is a thunk so a possibly-remote defining document is
85
+ * fetched only when a candidate key actually exists.
86
+ */
87
+ private readDefinitionSlot;
62
88
  private parsePropertyValue;
63
89
  private parseDatatypeValue;
64
90
  /**
@@ -1 +1 @@
1
- import{a as c,b as d,c as e,d as f}from"../chunk-ULHACEE2.js";import{m as b}from"../chunk-LMD432SO.js";import{a}from"../chunk-KOWDHKBN.js";import"../chunk-O6YV2SDB.js";import"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
1
+ import{a as c,b as d,c as e,d as f}from"../chunk-6YX2TDI5.js";import{m as b}from"../chunk-YU2VGLOT.js";import{a}from"../chunk-KOWDHKBN.js";import"../chunk-O6YV2SDB.js";import"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
@@ -1 +1 @@
1
- import{a as g,b as h,c as i,d as j,e as k}from"../chunk-GFLQ5TPR.js";import"../chunk-LMD432SO.js";import"../chunk-KOWDHKBN.js";import{e as a,f as b,g as c,i as d,l as e,m as f}from"../chunk-O6YV2SDB.js";import"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
1
+ import{a as g,b as h,c as i,d as j,e as k}from"../chunk-USQLCG3Q.js";import"../chunk-YU2VGLOT.js";import"../chunk-KOWDHKBN.js";import{e as a,f as b,g as c,i as d,l as e,m as f}from"../chunk-O6YV2SDB.js";import"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
@@ -1,4 +1,4 @@
1
- import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as g}from"../chunk-YM2V52DK.js";import"../chunk-6VIUXP4N.js";import"../chunk-LMD432SO.js";import"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import{p as m,x as S}from"../chunk-O6YV2SDB.js";import{c as v,m as p,r as E}from"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import{c as x}from"../chunk-QILEJIFU.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
1
+ import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as g}from"../chunk-AND44TIS.js";import"../chunk-6VIUXP4N.js";import"../chunk-YU2VGLOT.js";import"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import{p as m,x as S}from"../chunk-O6YV2SDB.js";import{c as v,m as p,r as E}from"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import{c as x}from"../chunk-QILEJIFU.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
2
2
  Install it with:
3
3
  npm install @huggingface/transformers
4
4
  (underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`
@@ -1,4 +1,4 @@
1
- import{c as Pe}from"../chunk-DUM5Q4MH.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-WKLSD5DQ.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-M7OWTFTC.js";import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-BRCVOR7A.js";import{j as oe}from"../chunk-YM2V52DK.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{m as te}from"../chunk-LMD432SO.js";import{a as O}from"../chunk-KOWDHKBN.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-O6YV2SDB.js";import{c as we,s as re}from"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import{c as V,e as K,f as W,g as ke}from"../chunk-QILEJIFU.js";import{readFileSync as de,writeFileSync as Ce,mkdirSync as Fe}from"fs";import{join as se}from"path";import Me from"js-yaml";var _e=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(t){return _e}function N(t){return`${t.publisher}/${t.package_}`}function z(t,e=[]){let c={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let o of t)if(o.origin==="missing"){let s=N(o),m=c[s]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${s} is MISSING (${o.reason??"unknown reason"}) \u2014 ${m}. Fix: kanonak install ${s} (as the user running the render), or restore network access to ${o.publisher}.`)}else o.resolvedButNotInCatalog&&r.push(`Render-stack package ${N(o)} resolved (${o.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let o of e)r.push(`Import edge ${o.fromNamespace} \u2192 ${o.publisher}/${o.packageName} ${o.constraint} did NOT resolve (${o.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${o.fromNamespace} authors against ${o.publisher}/${o.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${o.constraint}-compatible version of ${o.publisher}/${o.packageName} to the workspace or cache (kanonak install ${o.publisher}/${o.packageName}), or bump the import in ${o.fromNamespace}.`);return r}function ne(t){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,renderStack:d,producers:f,lockSource:l,configSource:h}=t,a=new Map,g=new Map,S=new Map,v=new Set;for(let $ of r){if(!($ instanceof we))continue;let w=$.namespace||"";if(!s.has(w))continue;a.set(`${w}/${$.name}`,$);let P=w.split("/")[1]??"",[_,M]=P.split("@");if(!_||!M)continue;let D=ke(M);D&&(v.has(P)||(v.add(P),g.has(_)||g.set(_,[]),g.get(_).push({verStr:M,version:D})),$.name===_&&S.set(P,$))}for(let $ of g.values())$.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,bySubject:a,pkgVersions:g,pkgSelfByVer:S,renderStack:d,...f?{producers:f}:{},...l?{lockSource:l}:{},...h?{configSource:h}:{}}}async function pe(t,e={}){let c=new O,r=new ye(c),o=[],s=[];for(let i of ee(t)){let u;try{u=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(u).metadata?.namespace_}catch{continue}if(!n?.version)continue;let p=n.version;s.push({publisher:n.publisher,package_:n.package_,verStr:K(p),version:p,source:u})}s.sort((i,u)=>V(u.version,i.version));for(let i of s)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),o.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let m=[...new Set(o.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!m.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)d=m[0];else throw m.length===0?new Error(`No Kanonak packages found under ${t}`):new Error(`Workspace has multiple publishers (${m.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,l=new Map;for(let i of o)i.publisher===d&&(f.add(`${i.publisher}/${i.package_}@${i.verStr}`),l.set(`${i.package_}@${i.verStr}`,i.source));let h=X(),a=new be(h,!0,c),g={};e.httpCache&&(g.getFromCache=e.httpCache.getFromCache,g.onFetch=e.httpCache.onFetch),e.fetchFn&&(g.fetchFn=e.fetchFn);let S=e.repository??new Se(r,a,new Z(g)),v=e.log??(()=>{}),$=q(void 0),w=[],P=i=>i.map(u=>u.metadata.namespace_?.version).filter(u=>u!==void 0).sort((u,n)=>V(n,u)).map(K);if(!e.repository){v(`[render-stack] resolving ${$.length} ambient look-stack package(s); cache: ${h}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let u of $){let n=N(u),p=await r.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(p.length>0){let y=P(p);w.push({...u,origin:"workspace",versions:y}),v(`[render-stack] ${n} \u2014 workspace (${y.join(", ")})`);continue}let k=await a.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(k.length>0){let y=P(k);w.push({...u,origin:"cache",versions:y}),v(`[render-stack] ${n} \u2014 cache (${y.join(", ")})`);continue}try{let b=(await i.getLock(u.publisher))?.packages[`${u.publisher}/${u.package_}`];if(!b){let j=`publisher ${u.publisher} reachable but its lock does not pin ${u.package_}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let C=b.version,T=b.resolved,Q=await(e.fetchFn?e.fetchFn(T,u.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${u.publisher}/${u.package_}@${C}`);try{let j=se(h,u.publisher);Fe(j,{recursive:!0}),Ce(se(j,`${u.package_}@${C}.kan.yml`),fe,"utf-8"),w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, but cache ${h} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(y){let b=`fetch failed: ${y.message}`;w.push({...u,origin:"missing",reason:b}),v(`[render-stack] ${n} \u2014 MISSING: ${b}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of $)_.push(...await S.getDocumentsByNamespaceAsync(i.publisher,i.package_));let M=[],D=await H(_,S,{onUnresolvedEdge:i=>M.push(i)}),A=S;if(!e.repository){for(let i of $)D.add(N(i));A=new G(S,D)}let B=await new te(c).parseKanonaks(A),ce=new oe(B),le=(i,u)=>re(B,{publisher:i,package_:u,name:u}).length>0,I;if(e.repository){I=[];for(let i of $){let u=await S.getDocumentsByNamespaceAsync(i.publisher,i.package_);I.push(u.length>0?{...i,origin:"repository",versions:P(u)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else I=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(I,M);for(let i of Y)v(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:h,packages:I,warnings:Y},E;try{E=de(se(t,"kanonak.lock"),"utf-8")}catch{E=De(d,o,c)}let L;try{L=de(se(t,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:m,catalog:B,lookRenderer:ce,localNamespaces:f,rawByNsKey:l,renderStack:J,...E?{lockSource:E}:{},...L?{configSource:L}:{}})}function De(t,e,c){let r=new Map;for(let s of e)s.publisher===t&&(r.has(s.package_)||r.set(s.package_,{verStr:s.verStr,source:s.source}));if(r.size===0)return;let o={};for(let s of[...r.keys()].sort()){let{verStr:m,source:d}=r.get(s),f={},l;try{l=c.parse(d).metadata?.imports}catch{l=void 0}for(let a of l?.[t]??[]){let g=r.get(a.packageName);g&&(f[`${t}/${a.packageName}`]=g.verStr)}let h={};for(let a of Object.keys(f).sort())h[a]=f[a];o[`${t}/${s}`]={version:m,resolved:`https://${t}/${s}/${m}.kan.yml`,integrity:Pe(d),dependencies:h}}return Me.dump({version:"1",lastUpdated:"",packages:o},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ke,readFileSync as Ee,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(t,e={}){let c=new O,r=Re(t),o=r.kind==="resource"?r.uri.publisher:r.publisher,s=e.log??(()=>{}),m=e.cacheRoot??X(),d=(n,p,k)=>je(m,n,`${p}@${k}.kan.yml`),f=new Set,l=new Set,h=new Map,a=new Z({getFromCache:(n,p,k)=>{let y=d(n,p,k),b=Ke(y)?Ee(y,"utf-8"):null;return b!==null&&f.add(`${n}/${p}`),b},onFetch:(n,p,k,y)=>{l.add(`${n}/${p}`);try{let b=je(m,n);Ae(b,{recursive:!0}),Ve(d(n,p,k),y,"utf-8")}catch(b){h.set(`${n}/${p}`,b.message),s(`[render] fetched ${n}/${p}@${k} but cache ${m} is NOT WRITABLE (${b.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),S;if(r.kind==="resource"){let n=r.uri.version;S=[n?{package_:r.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let n=r.version;S=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else S=((await g.getConfig(o)).featured_packages??[]).map(p=>({package_:p}));let v=async(n,p,k)=>{try{let y=k?c.buildImport(p,"=",k,n):c.buildImport(p,"*","0.0.0",n),b=await a.getHighestCompatibleVersionAsync(n,y);return b?{doc:b}:{doc:null,error:`${n} did not resolve ${p}${k?`@${k}`:""} (not in its index, or unreachable)`}}catch(y){return{doc:null,error:y.message}}},$=[],w=[];for(let n of S){let{doc:p,error:k}=await v(o,n.package_,n.version);p?$.push(p):k&&w.push(k)}if($.length===0)throw new Error(`Could not fetch any package for address "${t}" from publisher "${o}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",M=n=>n.map(p=>p.metadata.namespace_?.version).filter(p=>p!==void 0).sort((p,k)=>V(k,p)).map(K);s(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${m}`);let D=[],A=[];for(let n of P){let p=N(n),{doc:k,error:y}=await v(n.publisher,n.package_,void 0);if(k){D.push(k);let b=M([k]),C=l.has(p)?"fetched":f.has(p)?"cache":"fetched";A.push({...n,origin:C,versions:b}),s(`[render-stack] ${p} \u2014 ${C} (${b.join(", ")})`+(h.has(p)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:y??"unresolved"}),s(`[render-stack] ${p} \u2014 MISSING: ${y??"unresolved"}`)}let B=[],ce=await H([...$,...D],a,{onUnresolvedEdge:n=>B.push(n)}),le=new G(a,ce),I=await new te(c).parseKanonaks(le),Y=new oe(I),J=A.map(n=>n.origin==="missing"||re(I,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),E=z(J,B);for(let n of E)s(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:m,packages:J,warnings:E},i=new Set,u=new Map;for(let n of await a.getAllDocumentsAsync()){let p=n.metadata.namespace_;if(!p?.version||p.publisher!==o)continue;let k=K(p.version),y=`${p.publisher}/${p.package_}@${k}`;i.add(y);let b=await a.getDocumentContentAsync(y);b!==null&&u.set(`${p.package_}@${k}`,b)}return ne({publisher:o,availablePublishers:[o],catalog:I,lookRenderer:Y,localNamespaces:i,rawByNsKey:u,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(t){let{lookRenderer:e,publisher:c,renderStack:r,catalog:o}=t,s=e.explainStylesheet(e.publisherSubject(c)),m=[...s.tokens.entries()].map(([a,g])=>({name:a,value:g.value,source:`${g.sourceNamespace}/${g.sourceName}`,level:g.level})),d=s.baseStylesheet,f={present:d.css!==void 0,...d.sourceNamespace!==void 0?{source:d.sourceNamespace}:{},...d.scope!==void 0?{scope:d.scope}:{},...d.css!==void 0?{bytes:d.css.length}:{},...d.problem!==void 0?{problem:d.problem}:{},candidates:d.candidates},l=new Map;for(let a of o){let g=a.namespace;g&&l.set(g,(l.get(g)??0)+1)}let h=[...l.entries()].map(([a,g])=>({namespace:a,resources:g})).sort((a,g)=>a.namespace.localeCompare(g.namespace));return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(a=>({package_:N(a),origin:a.origin,...a.versions!==void 0?{versions:a.versions}:{},...a.reason!==void 0?{reason:a.reason}:{},...a.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:a.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:m,baseStylesheet:f,...s.look?{look:{sourceClass:`${s.look.sourceClass.publisher}/${s.look.sourceClass.package_}/${s.look.sourceClass.name}`}}:{}},catalog:h,warnings:[...r.warnings,...s.warnings.filter(a=>!r.warnings.includes(a))]}}function Be(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ge(t){let e=Be,c=t.warnings.length===0,r=t.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':t.warnings.map(l=>`<div class="warn">\u26A0 ${e(l)}</div>`).join(`
1
+ import{c as Pe}from"../chunk-DUM5Q4MH.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-WKLSD5DQ.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-M7OWTFTC.js";import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-BRCVOR7A.js";import{j as oe}from"../chunk-AND44TIS.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{m as te}from"../chunk-YU2VGLOT.js";import{a as O}from"../chunk-KOWDHKBN.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-O6YV2SDB.js";import{c as we,s as re}from"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import{c as V,e as K,f as W,g as ke}from"../chunk-QILEJIFU.js";import{readFileSync as de,writeFileSync as Ce,mkdirSync as Fe}from"fs";import{join as se}from"path";import Me from"js-yaml";var _e=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(t){return _e}function N(t){return`${t.publisher}/${t.package_}`}function z(t,e=[]){let c={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let o of t)if(o.origin==="missing"){let s=N(o),m=c[s]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${s} is MISSING (${o.reason??"unknown reason"}) \u2014 ${m}. Fix: kanonak install ${s} (as the user running the render), or restore network access to ${o.publisher}.`)}else o.resolvedButNotInCatalog&&r.push(`Render-stack package ${N(o)} resolved (${o.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let o of e)r.push(`Import edge ${o.fromNamespace} \u2192 ${o.publisher}/${o.packageName} ${o.constraint} did NOT resolve (${o.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${o.fromNamespace} authors against ${o.publisher}/${o.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${o.constraint}-compatible version of ${o.publisher}/${o.packageName} to the workspace or cache (kanonak install ${o.publisher}/${o.packageName}), or bump the import in ${o.fromNamespace}.`);return r}function ne(t){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,renderStack:d,producers:f,lockSource:l,configSource:h}=t,a=new Map,g=new Map,S=new Map,v=new Set;for(let $ of r){if(!($ instanceof we))continue;let w=$.namespace||"";if(!s.has(w))continue;a.set(`${w}/${$.name}`,$);let P=w.split("/")[1]??"",[_,M]=P.split("@");if(!_||!M)continue;let D=ke(M);D&&(v.has(P)||(v.add(P),g.has(_)||g.set(_,[]),g.get(_).push({verStr:M,version:D})),$.name===_&&S.set(P,$))}for(let $ of g.values())$.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:o,localNamespaces:s,rawByNsKey:m,bySubject:a,pkgVersions:g,pkgSelfByVer:S,renderStack:d,...f?{producers:f}:{},...l?{lockSource:l}:{},...h?{configSource:h}:{}}}async function pe(t,e={}){let c=new O,r=new ye(c),o=[],s=[];for(let i of ee(t)){let u;try{u=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(u).metadata?.namespace_}catch{continue}if(!n?.version)continue;let p=n.version;s.push({publisher:n.publisher,package_:n.package_,verStr:K(p),version:p,source:u})}s.sort((i,u)=>V(u.version,i.version));for(let i of s)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),o.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let m=[...new Set(o.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!m.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)d=m[0];else throw m.length===0?new Error(`No Kanonak packages found under ${t}`):new Error(`Workspace has multiple publishers (${m.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let f=new Set,l=new Map;for(let i of o)i.publisher===d&&(f.add(`${i.publisher}/${i.package_}@${i.verStr}`),l.set(`${i.package_}@${i.verStr}`,i.source));let h=X(),a=new be(h,!0,c),g={};e.httpCache&&(g.getFromCache=e.httpCache.getFromCache,g.onFetch=e.httpCache.onFetch),e.fetchFn&&(g.fetchFn=e.fetchFn);let S=e.repository??new Se(r,a,new Z(g)),v=e.log??(()=>{}),$=q(void 0),w=[],P=i=>i.map(u=>u.metadata.namespace_?.version).filter(u=>u!==void 0).sort((u,n)=>V(n,u)).map(K);if(!e.repository){v(`[render-stack] resolving ${$.length} ambient look-stack package(s); cache: ${h}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let u of $){let n=N(u),p=await r.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(p.length>0){let y=P(p);w.push({...u,origin:"workspace",versions:y}),v(`[render-stack] ${n} \u2014 workspace (${y.join(", ")})`);continue}let k=await a.getDocumentsByNamespaceAsync(u.publisher,u.package_);if(k.length>0){let y=P(k);w.push({...u,origin:"cache",versions:y}),v(`[render-stack] ${n} \u2014 cache (${y.join(", ")})`);continue}try{let b=(await i.getLock(u.publisher))?.packages[`${u.publisher}/${u.package_}`];if(!b){let j=`publisher ${u.publisher} reachable but its lock does not pin ${u.package_}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let C=b.version,T=b.resolved,Q=await(e.fetchFn?e.fetchFn(T,u.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...u,origin:"missing",reason:j}),v(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${u.publisher}/${u.package_}@${C}`);try{let j=se(h,u.publisher);Fe(j,{recursive:!0}),Ce(se(j,`${u.package_}@${C}.kan.yml`),fe,"utf-8"),w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...u,origin:"fetched",versions:[C]}),v(`[render-stack] ${n}@${C} \u2014 fetched from ${T}, but cache ${h} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(y){let b=`fetch failed: ${y.message}`;w.push({...u,origin:"missing",reason:b}),v(`[render-stack] ${n} \u2014 MISSING: ${b}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of $)_.push(...await S.getDocumentsByNamespaceAsync(i.publisher,i.package_));let M=[],D=await H(_,S,{onUnresolvedEdge:i=>M.push(i)}),A=S;if(!e.repository){for(let i of $)D.add(N(i));A=new G(S,D)}let B=await new te(c).parseKanonaks(A),ce=new oe(B),le=(i,u)=>re(B,{publisher:i,package_:u,name:u}).length>0,I;if(e.repository){I=[];for(let i of $){let u=await S.getDocumentsByNamespaceAsync(i.publisher,i.package_);I.push(u.length>0?{...i,origin:"repository",versions:P(u)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else I=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(I,M);for(let i of Y)v(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:h,packages:I,warnings:Y},E;try{E=de(se(t,"kanonak.lock"),"utf-8")}catch{E=De(d,o,c)}let L;try{L=de(se(t,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:m,catalog:B,lookRenderer:ce,localNamespaces:f,rawByNsKey:l,renderStack:J,...E?{lockSource:E}:{},...L?{configSource:L}:{}})}function De(t,e,c){let r=new Map;for(let s of e)s.publisher===t&&(r.has(s.package_)||r.set(s.package_,{verStr:s.verStr,source:s.source}));if(r.size===0)return;let o={};for(let s of[...r.keys()].sort()){let{verStr:m,source:d}=r.get(s),f={},l;try{l=c.parse(d).metadata?.imports}catch{l=void 0}for(let a of l?.[t]??[]){let g=r.get(a.packageName);g&&(f[`${t}/${a.packageName}`]=g.verStr)}let h={};for(let a of Object.keys(f).sort())h[a]=f[a];o[`${t}/${s}`]={version:m,resolved:`https://${t}/${s}/${m}.kan.yml`,integrity:Pe(d),dependencies:h}}return Me.dump({version:"1",lastUpdated:"",packages:o},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ke,readFileSync as Ee,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(t,e={}){let c=new O,r=Re(t),o=r.kind==="resource"?r.uri.publisher:r.publisher,s=e.log??(()=>{}),m=e.cacheRoot??X(),d=(n,p,k)=>je(m,n,`${p}@${k}.kan.yml`),f=new Set,l=new Set,h=new Map,a=new Z({getFromCache:(n,p,k)=>{let y=d(n,p,k),b=Ke(y)?Ee(y,"utf-8"):null;return b!==null&&f.add(`${n}/${p}`),b},onFetch:(n,p,k,y)=>{l.add(`${n}/${p}`);try{let b=je(m,n);Ae(b,{recursive:!0}),Ve(d(n,p,k),y,"utf-8")}catch(b){h.set(`${n}/${p}`,b.message),s(`[render] fetched ${n}/${p}@${k} but cache ${m} is NOT WRITABLE (${b.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),S;if(r.kind==="resource"){let n=r.uri.version;S=[n?{package_:r.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let n=r.version;S=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else S=((await g.getConfig(o)).featured_packages??[]).map(p=>({package_:p}));let v=async(n,p,k)=>{try{let y=k?c.buildImport(p,"=",k,n):c.buildImport(p,"*","0.0.0",n),b=await a.getHighestCompatibleVersionAsync(n,y);return b?{doc:b}:{doc:null,error:`${n} did not resolve ${p}${k?`@${k}`:""} (not in its index, or unreachable)`}}catch(y){return{doc:null,error:y.message}}},$=[],w=[];for(let n of S){let{doc:p,error:k}=await v(o,n.package_,n.version);p?$.push(p):k&&w.push(k)}if($.length===0)throw new Error(`Could not fetch any package for address "${t}" from publisher "${o}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",M=n=>n.map(p=>p.metadata.namespace_?.version).filter(p=>p!==void 0).sort((p,k)=>V(k,p)).map(K);s(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${m}`);let D=[],A=[];for(let n of P){let p=N(n),{doc:k,error:y}=await v(n.publisher,n.package_,void 0);if(k){D.push(k);let b=M([k]),C=l.has(p)?"fetched":f.has(p)?"cache":"fetched";A.push({...n,origin:C,versions:b}),s(`[render-stack] ${p} \u2014 ${C} (${b.join(", ")})`+(h.has(p)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:y??"unresolved"}),s(`[render-stack] ${p} \u2014 MISSING: ${y??"unresolved"}`)}let B=[],ce=await H([...$,...D],a,{onUnresolvedEdge:n=>B.push(n)}),le=new G(a,ce),I=await new te(c).parseKanonaks(le),Y=new oe(I),J=A.map(n=>n.origin==="missing"||re(I,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),E=z(J,B);for(let n of E)s(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:m,packages:J,warnings:E},i=new Set,u=new Map;for(let n of await a.getAllDocumentsAsync()){let p=n.metadata.namespace_;if(!p?.version||p.publisher!==o)continue;let k=K(p.version),y=`${p.publisher}/${p.package_}@${k}`;i.add(y);let b=await a.getDocumentContentAsync(y);b!==null&&u.set(`${p.package_}@${k}`,b)}return ne({publisher:o,availablePublishers:[o],catalog:I,lookRenderer:Y,localNamespaces:i,rawByNsKey:u,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(t){let{lookRenderer:e,publisher:c,renderStack:r,catalog:o}=t,s=e.explainStylesheet(e.publisherSubject(c)),m=[...s.tokens.entries()].map(([a,g])=>({name:a,value:g.value,source:`${g.sourceNamespace}/${g.sourceName}`,level:g.level})),d=s.baseStylesheet,f={present:d.css!==void 0,...d.sourceNamespace!==void 0?{source:d.sourceNamespace}:{},...d.scope!==void 0?{scope:d.scope}:{},...d.css!==void 0?{bytes:d.css.length}:{},...d.problem!==void 0?{problem:d.problem}:{},candidates:d.candidates},l=new Map;for(let a of o){let g=a.namespace;g&&l.set(g,(l.get(g)??0)+1)}let h=[...l.entries()].map(([a,g])=>({namespace:a,resources:g})).sort((a,g)=>a.namespace.localeCompare(g.namespace));return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(a=>({package_:N(a),origin:a.origin,...a.versions!==void 0?{versions:a.versions}:{},...a.reason!==void 0?{reason:a.reason}:{},...a.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:a.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:m,baseStylesheet:f,...s.look?{look:{sourceClass:`${s.look.sourceClass.publisher}/${s.look.sourceClass.package_}/${s.look.sourceClass.name}`}}:{}},catalog:h,warnings:[...r.warnings,...s.warnings.filter(a=>!r.warnings.includes(a))]}}function Be(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ge(t){let e=Be,c=t.warnings.length===0,r=t.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':t.warnings.map(l=>`<div class="warn">\u26A0 ${e(l)}</div>`).join(`
2
2
  `),o=t.renderStack.packages.map(l=>{let h=l.origin!=="missing"&&!l.resolvedButNotInCatalog,a=l.origin==="missing"?'<span class="bad">MISSING</span>':l.resolvedButNotInCatalog?`<span class="bad">${e(l.origin)} (not in catalog)</span>`:`<span class="good">${e(l.origin)}</span>`,g=l.reason?e(l.reason):e((l.versions??[]).join(", "));return`<tr class="${h?"":"row-bad"}"><td><code>${e(l.package_)}</code></td><td>${a}</td><td>${g}</td></tr>`}).join(`
3
3
  `),s=t.stylesheet.baseStylesheet,m=s.present?`<p><span class="good">\u2713 present</span> \u2014 <code>${e(s.source??"")}</code> (${s.bytes} bytes, ${e(s.scope??"")})</p>`:`<p><span class="bad">\u2717 MISSING</span>${s.problem?` \u2014 ${e(s.problem)}`:""}${s.candidates.length>0?`<br>candidates considered: ${s.candidates.map(l=>`<code>${e(l)}</code>`).join(", ")}`:""}</p><p>Without the base stylesheet, generated CSS stops at the <code>:root</code> token block and pages appear unstyled.</p>`,d=t.stylesheet.tokens.map(l=>`<tr><td><code>--kan-${e(l.name)}</code></td><td><code>${e(l.value)}</code></td><td><code>${e(l.source)}</code></td><td>${e(l.level)}</td></tr>`).join(`
4
4
  `),f=t.catalog.map(l=>`<tr><td><code>${e(l.namespace)}</code></td><td>${l.resources}</td></tr>`).join(`
@@ -1,4 +1,4 @@
1
- import{a as pe}from"../chunk-APWYAZMI.js";import"../chunk-ULHACEE2.js";import{b as X,c as Un,d as Vn,e as le,f as ve,g as M,h as Rn,i as q,j as G}from"../chunk-YM2V52DK.js";import"../chunk-6VIUXP4N.js";import{a as ce,b as ue,c as de,e as $n,f as Tn,g as Bn,h as xn,m as fe}from"../chunk-LMD432SO.js";import{a as se}from"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import{e as U}from"../chunk-O6YV2SDB.js";import{b as Y,c as D,d as E,g as $,h as T,i as B,j as w,k as me,l as x,n as N,o as S,r as A}from"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import{g as ie}from"../chunk-QILEJIFU.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
1
+ import{a as pe}from"../chunk-5GFOZL7D.js";import"../chunk-6YX2TDI5.js";import{b as X,c as Un,d as Vn,e as le,f as ve,g as M,h as Rn,i as q,j as G}from"../chunk-AND44TIS.js";import"../chunk-6VIUXP4N.js";import{a as ce,b as ue,c as de,e as $n,f as Tn,g as Bn,h as xn,m as fe}from"../chunk-YU2VGLOT.js";import{a as se}from"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import{e as U}from"../chunk-O6YV2SDB.js";import{b as Y,c as D,d as E,g as $,h as T,i as B,j as w,k as me,l as x,n as N,o as S,r as A}from"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import{g as ie}from"../chunk-QILEJIFU.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
2
2
  `);return t?.trailingNewline&&(s.endsWith(`
3
3
  `)||(s+=`
4
4
  `)),s}};function Ie(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(P(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(P(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(P),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=P(f??c),d=ye(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function P(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function ye(e,n){switch(e.kind){case"StringScalar":return _e(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=ye(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function _e(e,n){return!n||ge(n,m.ESC_RAW)?e:ge(n,m.ESC_YAML_SAFE)?Ce(e):e}function Ce(e){return e.includes(`
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,K as I,L as J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-BPIAKTAV.js";import"../chunk-BRCVOR7A.js";import"../chunk-YM2V52DK.js";import"../chunk-6VIUXP4N.js";import"../chunk-LMD432SO.js";import"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import"../chunk-O6YV2SDB.js";import"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{u as AmbiguousReferenceRule,A as ClassDefinitionRule,n as ClassHierarchyCycleRule,I as DiamondNameClashRule,C as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,J as KanonakObjectValidator,E as LookBandPathRule,D as LookSemanticSvgPathRule,B as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,w as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,H as OwlOneOfRule,j as PackageHeaderRule,x as PropertyDomainRule,o as PropertyHierarchyCycleRule,y as PropertyKindRangeConsistencyRule,v as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,z as ReservedNameShadowRule,g as ResourceNamingRule,G as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,F as TxExpressionPathRule,t as UnresolvedPredicateRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
1
+ import{A,B,C,D,E,F,G,H,K as I,L as J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-3XOXKMYB.js";import"../chunk-BRCVOR7A.js";import"../chunk-AND44TIS.js";import"../chunk-6VIUXP4N.js";import"../chunk-YU2VGLOT.js";import"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import"../chunk-O6YV2SDB.js";import"../chunk-H6UAD2LP.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{u as AmbiguousReferenceRule,A as ClassDefinitionRule,n as ClassHierarchyCycleRule,I as DiamondNameClashRule,C as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,J as KanonakObjectValidator,E as LookBandPathRule,D as LookSemanticSvgPathRule,B as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,w as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,H as OwlOneOfRule,j as PackageHeaderRule,x as PropertyDomainRule,o as PropertyHierarchyCycleRule,y as PropertyKindRangeConsistencyRule,v as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,z as ReservedNameShadowRule,g as ResourceNamingRule,G as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,F as TxExpressionPathRule,t as UnresolvedPredicateRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "5.23.0",
3
+ "version": "5.24.0",
4
4
  "description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -126,7 +126,7 @@
126
126
  ],
127
127
  "dependencies": {
128
128
  "@kanonak-protocol/canonical": "^0.1.3",
129
- "@kanonak-protocol/types": "^5.23.0",
129
+ "@kanonak-protocol/types": "^5.24.0",
130
130
  "ignore": "^7.0.5",
131
131
  "js-yaml": "^4.1.0",
132
132
  "yaml": "^2.7.0",
@@ -1 +0,0 @@
1
- import{a as F}from"./chunk-KOWDHKBN.js";import{a as W,b as G,j as X,l as T,r as J}from"./chunk-O6YV2SDB.js";import{a as $,b as z,c as S,d as g,g as P,h as I,i as L,j,k as w,l as K,m as E,n as q,r as H}from"./chunk-H6UAD2LP.js";import{a as D}from"./chunk-FUUTGGJS.js";import{k as U}from"./chunk-QILEJIFU.js";var b=class extends z{name};var R=class extends ${value;carrier;lexical};var v=class extends P{links=[]};var ne="kanonak.org",re="transformations",ge=3,e=m=>({publisher:ne,package_:re,name:m}),M={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 ae}from"@kanonak-protocol/canonical";function N(m){return ae(`${m.publisher}/${m.package_}/${m.name}`)}var oe=/\[\[([^\[\]\n]+)\]\]/g,se=/\[\[/g,Y=/```[\s\S]*?```|`[^`\n]*`/g;function ie(m){let t=[];for(let n of m.matchAll(Y))t.push([n.index,n.index+n[0].length]);return t}function Se(m){if(!m||!m.includes("[["))return[];let t=ie(m),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(x(m).map(s=>s.startOffset)),a=[];for(let s of m.matchAll(se)){let o=s.index;if(n(o)||r.has(o))continue;let c=m.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function x(m){if(!m||!m.includes("[["))return[];let t=[];for(let a of m.matchAll(Y))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 m.matchAll(oe)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),p=(c===-1?o:o.slice(0,c)).trim();if(p.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),l={reference:p,startOffset:s,endOffset:s+a[0].length};i.length>0&&(l.displayText=i),r.push(l)}return r}function Z(m,t){for(let n of m)n instanceof S&&_(n,n.name,t)}function _(m,t,n){n({kanonak:m,path:t});for(let r of m.statement)if(r instanceof w)_(r.object,Q(t,r.object),n);else if(r instanceof K)for(let a of r.object)a instanceof b&&_(a,Q(t,a),n)}function Q(m,t){let n=t instanceof b&&t.name?t.name:"<embedded>";return`${m}/${n}`}var ee=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new W(t),s=new G(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let p of n){let i=p.metadata.namespace_?.toString();i&&a.set(i,p)}let s=[],o=new Set;Z(t,({kanonak:p})=>{for(let i of p.unresolvedPredicates){let l=`${i.sourceDoc}::${i.key}`;o.has(l)||(o.add(l),s.push(i))}});let c=!1;for(let p of s){let i=a.get(p.sourceDoc);if(!i)continue;let l=await r.resolveEntityAsync(p.key,i);if(!l)continue;let u=E(l.uri);if(this.knownPropertyClasses.has(u))continue;let f=H(t,l.uri);if(!f)continue;let d=J(t,f);d&&(this.knownPropertyClasses.set(u,d),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[p,i]of Object.entries(o.body)){let l=new S,u=this.resolveCanonicalEntity(p,o,c);l.namespace=u.namespace,l.name=u.name,l.statement=[];let f=await this.parseStatements(i,o,n,r,a);l.statement.push(...f.statements),l.unresolvedPredicates=f.unresolved,B(l,c),s.push(l)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof S){let l=`${i.namespace}/${i.name}`,u=r.get(l);if(u){let f=a.get(l);for(let d of i.statement){let y=C(d);f.has(y)||(f.add(y),u.statement.push(d))}for(let d of i.unresolvedPredicates)u.unresolvedPredicates.some(y=>y.key===d.key&&y.sourceDoc===d.sourceDoc)||u.unresolvedPredicates.push(d)}else{let f=new S;f.namespace=i.namespace,f.name=i.name,f.sourceDoc=i.sourceDoc;let d=new Set;for(let y of i.statement){let k=C(y);d.has(k)||(d.add(k),f.statement.push(y))}f.unresolvedPredicates=[...i.unresolvedPredicates],a.set(l,d),r.set(l,f),s.push(f)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof S){let l=i.namespace||"",u=l.indexOf("/"),f=u>=0?l.slice(0,u):"",d=u>=0?l.slice(u+1):"",y=d.indexOf("@"),k=y>=0?d.slice(0,y):d;o.add(`${f}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),p=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let l=await n.getDocumentsByNamespaceAsync("kanonak.org",i);p.set(i,U(l).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof S&&this.canonicalizeStatementBuiltins(i.statement,c,p);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(T(s,n,r),a instanceof j)a.object instanceof g&&T(a.object.subject,n,r);else if(a instanceof w)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof K)for(let o of a.object??[])o instanceof g?T(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,p]of Object.entries(n.metadata.imports))for(let i of p)if((i.alias??i.packageName)===s){let u=i.version;return{namespace:`${c}/${i.packageName}@${u.major}.${u.minor}.${u.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let p=n.metadata.namespace_?.toString()??"";for(let[i,l]of Object.entries(t))try{let u=await this.getPropertyMetadata(i,n,r,s,a);if(!u){let d=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;X(d)||c.push({key:i,sourceDoc:p});continue}let f=await this.parsePropertyValue(i,l,u,n,r,a,s);f&&o.push(f)}catch(u){throw new Error(`Failed to parse property '${i}': ${u.message}`,{cause:u})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,p=c.type?.toString()??"",i=p.includes(".")?p.substring(p.lastIndexOf(".")+1):p,l=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),u=this.knownPropertyClasses.get(E(o.uri));if(!l.has(i)&&!u)return;let f=u??s.getPropertyTypeClassification(p),d=c.range?.toString(),y;if(f==="ObjectProperty")y="ObjectProperty";else if(f==="DatatypeProperty")y="DatatypeProperty";else{let O=d&&d.includes(".")?d.substring(d.lastIndexOf(".")+1):d??"";(d?s.isKnownXsdDatatypeName(d):!1)||O==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let k;if(d){let O=n;if(o.isImported&&o.definedInNamespace){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 A=await a.getDocumentAsync(o.definedInNamespace);if(!A)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);O=A}k=(await r.resolveEntityAsync(d,O))?.uri}return{propertyUri:o.uri.toString(),propertyType:y,range:d,rangeUri:k,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async parsePropertyValue(t,n,r,a,s,o,c){let p=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(p,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(p,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(p,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?N(r.rangeUri):void 0;if(s===h.Boolean){let c=new L;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 I;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=P.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new R,a=n.rangeUri?N(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 v;s.predicate=g.parse(t),s.object=n;for(let o of x(n)){let c=await a.resolveEntityAsync(o.reference,r),p;c&&(p=new g,p.subject=c.uri);let i={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(i.displayText=o.displayText),p!==void 0&&(i.target=p),s.links.push(i)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&q(r.rangeUri,M.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let p=await this.resolveReference(n,a,s);if(!p)return;let i=new j;return i.predicate=g.parse(t),i.object=p,i}if(typeof n=="object"&&!Array.isArray(n)){let p=await this.parseStatements(n,a,s,o,c);if(p.statements.length>0){let u=new b;u.statement=p.statements,u.unresolvedPredicates=p.unresolved;let f=new w;return f.predicate=g.parse(t),f.object=u,f}let i=[];for(let[u,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=new b;d.name=u;let y=await this.parseStatements(f,a,s,o,c);d.statement=y.statements,d.unresolvedPredicates=y.unresolved,i.push(d)}else if(typeof f=="string"){let d=await this.resolveReference(f,a,s);d&&i.push(d)}if(i.length>0){let u=new K;return u.predicate=g.parse(t),u.object=i,u}let l=new w;return l.predicate=g.parse(t),l.object=new b,l}}coerceExpressionLiteral(t,n,r){let a=new b,s=new j,o=new g;o.subject=new D("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new D(r.publisher,r.package_,M.StringLiteral.name,r.version),s.object=c;let p=new P,i=new g;i.subject=new D(r.publisher,r.package_,M.stringLiteral.name,r.version),p.predicate=i,p.object=n,a.statement=[s,p];let l=new w;return l.predicate=g.parse(t),l.object=a,l}async parseListValue(t,n,r,a,s,o,c){let p=[],i=r.propertyType==="DatatypeProperty",l=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 d=typeof f=="string"||typeof f=="number"||typeof f=="boolean";if(i&&d){let y=typeof f=="string"?f:String(f);p.push(this.typedListLiteral(y,r));continue}if(l&&d){if(typeof f=="string"){let y=await s.resolveEntityAsync(f,a);if(y){let k=new g;k.subject=y.uri,p.push(k)}else{let k=new R;k.value=f,p.push(k)}}else{let y=new R;y.value=f,p.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&p.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,p.push(y)}}let u=new K;return u.predicate=g.parse(t),u.object=p,u}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 p=t.indexOf("."),i=t.substring(0,p),l=t.substring(p+1);if(n.metadata?.imports){for(let[u,f]of Object.entries(n.metadata.imports))for(let d of f)if((d.alias??d.packageName)===i){let k=new g;return k.subject=new o(u,d.packageName,l,d.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 S&&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 S&&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 F().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let p of o.statement){let[i,l]=this.convertStatementToProperty(p);i&&l!==null&&l!==void 0&&(c[i]=l),this.collectImportsFromStatement(p,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof P)return[t.predicate.subject.name,t.object];if(t instanceof I)return[t.predicate.subject.name,t.object];if(t instanceof L)return[t.predicate.subject.name,t.object];if(t instanceof j)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof K){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof w){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 B(m,t){m.sourceDoc=t;for(let n of m.statement)if(n instanceof w)B(n.object,t);else if(n instanceof K)for(let r of n.object)r instanceof b&&B(r,t)}function C(m){let t=m.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+ce(m)}function ce(m){return m instanceof v?"m:"+String(m.object):m instanceof P?"s:"+String(m.object):m instanceof I?"n:"+String(m.object):m instanceof L?"b:"+String(m.object):m instanceof j?"r:"+V(m.object):m instanceof w?"e:"+V(m.object):m instanceof K?"l:["+(m.object??[]).map(V).join("|")+"]":"x"}function V(m){if(!m)return"";if(m instanceof g){let t=m.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return m instanceof b?"E("+(m.statement??[]).map(C).join(";")+")":m instanceof R?"L("+String(m.value)+")":"N"}export{b as a,R as b,v as c,Z as d,ne as e,re as f,ge as g,M as h,h as i,N as j,Se as k,x as l,ee as m};