@kanonak-protocol/sdk 4.10.0 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +2 -2
  3. package/dist/canonical/CanonicalHash.d.ts +13 -17
  4. package/dist/canonical/Datatypes.d.ts +19 -93
  5. package/dist/canonical/InputModel.d.ts +9 -46
  6. package/dist/chunk-4UT2CLAT.js +1 -0
  7. package/dist/{chunk-VKTFLHCW.js → chunk-7HRKWTBB.js} +1 -1
  8. package/dist/{chunk-PBNVHBS3.js → chunk-7TKJHKC2.js} +1 -1
  9. package/dist/chunk-BKVPSPG4.js +1 -0
  10. package/dist/{chunk-RWEGPZ23.js → chunk-CR55WXIN.js} +1 -1
  11. package/dist/{chunk-UK2OIPAB.js → chunk-IEOSSSB5.js} +1 -1
  12. package/dist/{chunk-RYOZTXI7.js → chunk-RGOBWOBB.js} +1 -1
  13. package/dist/{chunk-KGWDV7FW.js → chunk-U7LVFPEO.js} +1 -1
  14. package/dist/chunk-UBBZWWRB.js +86 -0
  15. package/dist/{chunk-OOR5SVNQ.js → chunk-V72IVYR4.js} +1 -1
  16. package/dist/{chunk-NV63IOB7.js → chunk-VWS25JH4.js} +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +26 -26
  19. package/dist/kanonaks/DefinedKanonak.d.ts +25 -0
  20. package/dist/parsing/index.js +1 -1
  21. package/dist/reasoning/KanonakVocabulary.d.ts +8 -0
  22. package/dist/reasoning/index.js +1 -1
  23. package/dist/resolution/index.js +1 -1
  24. package/dist/search/index.js +1 -1
  25. package/dist/server/index.js +1 -1
  26. package/dist/transformations/index.js +1 -1
  27. package/dist/uri-helpers/index.js +1 -1
  28. package/dist/validation/documentModel.d.ts +48 -0
  29. package/dist/validation/index.d.ts +1 -1
  30. package/dist/validation/index.js +1 -1
  31. package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +3 -4
  32. package/dist/validation/rules/repository/UnresolvedPredicateRule.d.ts +25 -0
  33. package/dist/validation/rules/repository/index.d.ts +1 -1
  34. package/package.json +3 -2
  35. package/dist/chunk-DSHPAWJQ.js +0 -1
  36. package/dist/chunk-IZRPJCQW.js +0 -86
  37. package/dist/chunk-T3JR2SV6.js +0 -1
  38. package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +0 -35
@@ -0,0 +1,86 @@
1
+ import{d as _}from"./chunk-SHDHMKMJ.js";import{a as I,b as Ne,c as Qe,f as tt,h as E}from"./chunk-BKVPSPG4.js";import{a as Ye}from"./chunk-NJ3AZYQD.js";import{a as B,d as W,e as nt,f as ot,g as x,h as rt}from"./chunk-IEOSSSB5.js";import{a as C,d as A,f as T,h as xe,i as w,j as L,k as V,l as O,m as S,n as M}from"./chunk-7TKJHKC2.js";import{a as N,b as U,c as et}from"./chunk-7HRKWTBB.js";import{c as D,d as H,k as Ze,l as Je}from"./chunk-4UT2CLAT.js";import{a as Ge}from"./chunk-FUUTGGJS.js";import{e as P}from"./chunk-2ACBWC7K.js";var q=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(t=>(t.Warning="Warning",t.Error="Error",t))(b||{});var g=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 Le=class m{resolvedDocuments=[];currentEntityPath;withPath(e){let t=new m;return t.resolvedDocuments=this.resolvedDocuments,t.currentEntityPath=e,t}};var Se=class{constructor(e){this.underlying=e;this.repository=new We(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new E().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let t=this.importClosureCache.get(e);return t||(t=this.computeImportClosure(e),this.importClosureCache.set(e,t),t)}async getClassDeclarations(e){let t=this.classDeclarationsCache.get(e);return t||(t=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,t),t)}async getPropertyNames(e){let t=this.propertyNamesCache.get(e);return t||(t=this.computePropertyNames(e),this.propertyNamesCache.set(e,t),t)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let t=new Set([e]),n=[e],o=await this.buildDocsByIdIndex();for(;n.length>0;){let a=n.shift(),r=o.get(a);if(r?.metadata.imports)for(let[i,s]of Object.entries(r.metadata.imports))for(let c of s){let p=await this.repository.getHighestCompatibleVersionAsync(i,c);if(!p)continue;let l=Me(p);!l||t.has(l)||(t.add(l),n.push(l))}}return t}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),t=new Map;for(let n of e){let o=Me(n);o&&t.set(o,n)}return t}async computeClassDeclarations(e){let t=await this.findDocById(e),n=new Map;if(!t)return n;for(let[o,a]of Object.entries(t.body)){if(!it(a))continue;let r=a,i=at(r,"type");if(i==="Class"||i?.endsWith(".Class")){let s=Rt(r);n.set(o,s)}}return n}async computePropertyNames(e){let t=await this.findDocById(e),n=new Set;if(!t)return n;for(let[o,a]of Object.entries(t.body)){if(!it(a))continue;let i=at(a,"type");(i==="ObjectProperty"||i?.endsWith(".ObjectProperty")||i==="DatatypeProperty"||i?.endsWith(".DatatypeProperty")||i==="AnnotationProperty"||i?.endsWith(".AnnotationProperty")||i==="Property"||i?.endsWith(".Property"))&&n.add(o)}return n}async findDocById(e){let t=await this.getAllDocuments();for(let n of t)if(Me(n)===e)return n}};function Me(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}function it(m){return typeof m=="object"&&m!==null&&!Array.isArray(m)}function at(m,e){if(e in m)return st(m[e]);for(let t of Object.keys(m))if(t.endsWith(`.${e}`))return st(m[t])}function st(m){return Array.isArray(m)?m.length>0?String(m[0]):void 0:m==null?void 0:String(m)}function Rt(m){let e=m.subClassOf;if(e===void 0){for(let t of Object.keys(m))if(t.endsWith(".subClassOf")){e=m[t];break}}return N(e)}var We=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 n=`${e}/${t}`,o=this.byNamespaceCache.get(n);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,t),this.byNamespaceCache.set(n,o),o)}getHighestCompatibleVersionAsync(e,t){let n=t.version,o=n?`${n.major}.${n.minor}.${n.patch}`:"",a=`${e}/${t.packageName}@${t.versionOperator}:${o}`,r=this.highestVersionCache.get(a);return r||(r=this.inner.getHighestCompatibleVersionAsync(e,t),this.highestVersionCache.set(a,r),r)}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)}};var z=class m{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[n,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(n,o,t);return t}validateEntity(e,t,n){for(let[o,a]of Object.entries(t)){let r=a?.toString()??"";if(r&&m.NAMESPACE_PREFIX_PATTERN.test(r)){let i=this.getSuggestionForPrefixedValue(r),s=e.split(".")[0],c=new g;c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=o,c.expectedValue=i,c.message=`Invalid namespace prefix '${r}'. Use '${i}' without prefix.`,c.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",n.push(c)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(`${e}.${o}`,a,n)}}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 n=e.indexOf(":");return n>=0?e.substring(n+1):e}};var Y=class m{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=[],n=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,a]of Object.entries(e.body)){let r=m.VALID_AUGMENTATION_PATTERN.test(o);if(!r&&!n&&m.RESERVED_WORDS.has(o.toLowerCase())){let i=new g;i.ruleType=this.ruleName,i.severity="Error",i.entityName=o,i.message=`Entity name '${o}' 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(!r&&!m.VALID_NAME_PATTERN.test(o)){let i;/^\d/.test(o)?i="Entity names must start with a letter, not a number.":o.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 g;s.ruleType=this.ruleName,s.severity="Error",s.entityName=o,s.message=`Invalid entity name '${o}'. ${i}`,s.suggestion=i,t.push(s)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validatePropertyNames(o,a,t)}return t}validatePropertyNames(e,t,n){for(let o of Object.keys(t))if(!m.VALID_PROPERTIES.has(o)&&!m.VALID_PROPERTY_NAME_PATTERN.test(o)){let a=new g;a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=o,a.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,a.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",n.push(a)}}};var G=class m{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 n=this.isPropertyDefinedAsClass(e);for(let[o,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let r=a,i=r.type;if(i){let s=[];if(Array.isArray(i))for(let c of i){let p=c?.toString();p&&p==="Property"&&!n&&s.push(p)}else{let c=i?.toString();c&&c==="Property"&&!n&&s.push(c)}for(let c of s){let p=this.getPropertyValue(r,"range"),l=this.determinePropertyType(p),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.entityName=o,u.propertyName="type",u.actualValue=c,u.expectedValue=l,u.message=`Invalid property type '${c}'. Use '${l}' instead.`,u.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",t.push(u)}}}return t}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":m.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,t){let n=e[t];return n?n.toString():null}isPropertyDefinedAsClass(e){let t=e.body.Property;if(t&&typeof t=="object"&&!Array.isArray(t)){let o=t.type;if(o){let a=o.toString();return a==="Class"||a.endsWith(".Class")}}return!1}};var Z=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let t=[];for(let[n,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||n.includes("."))continue;let a=o,r="type"in a,i=a.type?.toString().trim();if(!r||!i){let s=new g;s.ruleType=this.ruleName,s.severity="Error",s.entityName=n,s.propertyName="type",s.message=`Subject Kanonak '${n}' must have a 'type' property.`,s.suggestion=`Add a type statement like:
2
+ type: Scene
3
+
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 vt=new Set(["EphemeralPackage"]),J=class{get ruleName(){return"PackageHeader"}validate(e){let t=e.metadata;if(!t.type_)return[];let n=[],o=this.packageKey(e,t.type_);return t.namespace_?(!vt.has(t.type_)&&!t.namespace_.version&&n.push(this.error(o,"version",`Package resource '${o}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
5
+ version: 1.0.0`)),n):(n.push(this.error(o,"publisher",`Package resource '${o}' requires a 'publisher' property.`,`Add a publisher, e.g.:
6
+ publisher: example.org`)),n)}packageKey(e,t){for(let[n,o]of Object.entries(e.body))if(o&&typeof o=="object"&&!Array.isArray(o)&&o.type===t)return n;return t}error(e,t,n,o){let a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.message=n,a.suggestion=o,a}};var Q=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,t){let n=[],o=new U(t),a=await this.buildPropertyRangeMap(e,o);for(let[r,i]of Object.entries(e.body))typeof i=="object"&&i!==null&&!Array.isArray(i)&&await this.checkEmbeddedTypes(r,i,void 0,a,o,e,n,0);return n}pickRange(e,t,n){if(e.length===0)return;if(e.length===1)return e[0].range;let o=t.indexOf(".");if(o>0){let a=t.substring(0,o),r=e.find(i=>i.declaringAlias===a);if(r)return r.range}if(n){let a=this.localName(n),r=e.find(i=>this.localName(i.domain)===a);if(r)return r.range}return e[0].range}async checkEmbeddedTypes(e,t,n,o,a,r,i,s){if(s>0){let p=t.type;if(p!=null){let l=await this.validateEmbeddedType(e,String(p),n,a,r);l&&i.push(l)}}let c=t.type!==void 0&&t.type!==null?String(t.type):void 0;for(let[p,l]of Object.entries(t)){let u=this.localName(p),y=o.get(u),d=(y!==void 0?this.pickRange(y,p,c):void 0)??n;if(typeof l=="object"&&l!==null)if(Array.isArray(l))for(let k=0;k<l.length;k++){let h=l[k];typeof h=="object"&&h!==null&&!Array.isArray(h)&&await this.checkEmbeddedTypes(`${e}.${p}[${k}]`,h,d,o,a,r,i,s+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,l,d,o,a,r,i,s+1)}}async validateEmbeddedType(e,t,n,o,a){if(t.length===0||!n)return null;let r=this.localName(t),i=this.localName(n);if(i==="Resource"||i==="Class")return null;let s=e.split(".")[0];if(r===i){let p=new g;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=s,p.propertyName=e,p.actualValue=t,p.expectedValue=n,p.message=`Embedded object at '${e}' declares 'type: ${t}', which equals the parent property's range '${n}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,p.suggestion=`Remove the 'type: ${t}' line, or keep it if explicitness is preferred over concision.`,p}if(await o.isSubclassOfAsync(t,n,a)||(r!==t||i!==n)&&await o.isSubclassOfAsync(r,i,a))return null;let c=new g;return c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=t,c.expectedValue=n,c.message=`Embedded object at '${e}' has 'type: ${t}', which is not a subclass of the parent property's range '${n}'.`,c.suggestion=`Either remove the 'type: ${t}' line (so the type is inferred from the property's range '${n}'), or add 'subClassOf: ${n}' to the '${t}' class definition so the relationship holds.`,c}localName(e){let t=e.lastIndexOf(".");return t<0||t===e.length-1?e:e.substring(t+1)}async buildPropertyRangeMap(e,t){let n=new Map,o=await t.buildEntityIndexAsync(e),a=new Map;for(let[r,i]of o){let s=i.entity.type;if(s==null)continue;let c=String(s),p=this.localName(c);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let u=i.entity.range;if(u==null)continue;let y=String(u);if(y.length===0)continue;let f=i.entity.domain,d=f!=null?String(f):"",k=i.uri.toString(),h=a.get(k),v=r.includes(".");(!h||v&&!h.entityName.includes("."))&&a.set(k,{entityName:r,domain:d,range:y})}for(let r of a.values()){let i=this.localName(r.entityName),s=r.entityName.indexOf("."),c=s>0?r.entityName.substring(0,s):void 0,p=n.get(i)??[];p.push({domain:r.domain,range:r.range,declaringAlias:c}),n.set(i,p)}return n}};import{VersionOperator as Te}from"@kanonak-protocol/types/document/models/enums";var ee=class{ruleName="ImportExistence";async validateAsync(e,t){let n=[];if(!e.metadata?.imports)return n;let o=await t.getAllDocumentsAsync();for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r)if(!await t.getHighestCompatibleVersionAsync(a,i)){let c=await this.determineImportErrorAsync(t,a,i,o),p=new g;p.ruleType=this.ruleName,p.severity="Error",p.message=c.message,p.suggestion=c.suggestion,p.entityName=`Import: ${a}/${i.packageName}`,p.actualValue=i.toString(),p.expectedValue=c.expectedValue,n.push(p)}return n}async determineImportErrorAsync(e,t,n,o){let a=await e.getDocumentsByNamespaceAsync(t,n.packageName);if(a.length===0){let c=o.filter(y=>y.metadata.namespace_?.publisher===t).map(y=>y.metadata.namespace_.package_).filter((y,f,d)=>d.indexOf(y)===f),p=this.findSimilarPackages(n.packageName,c),l=`Import '${t}/${n.package_}' not found - package does not exist`,u=p.length>0?`Did you mean: ${p.slice(0,3).join(", ")}?`:c.length>0?`Available packages in ${t}: ${c.slice(0,5).join(", ")}`:`No packages found for publisher '${t}'. Verify the publisher name is correct.`;return{message:l,suggestion:u,expectedValue:"Existing package"}}let i=a.filter(c=>c.metadata.namespace_?.version).map(c=>c.metadata.namespace_.version.toString()).sort().join(", "),s=this.getAcceptableVersionRange(n);return{message:`Import '${t}/${n.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${s}`,expectedValue:s}}getAcceptableVersionRange(e){switch(e.versionOperator){case Te.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Te.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Te.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Te.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,t){if(t.length===0)return[];let n=t.filter(r=>r.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(r.toLowerCase()));if(n.length>0)return n.sort((r,i)=>r.length-i.length);let o=t.map(r=>({package:r,distance:this.levenshteinDistance(e.toLowerCase(),r.toLowerCase())})).sort((r,i)=>r.distance-i.distance),a=Math.max(3,Math.floor(e.length*.4));return o.filter(r=>r.distance<=a).map(r=>r.package)}levenshteinDistance(e,t){if(!e||e.length===0)return t?.length??0;if(!t||t.length===0)return e.length;let n=e.length,o=t.length,a=Array(n+1).fill(null).map(()=>Array(o+1).fill(0));for(let r=0;r<=n;r++)a[r][0]=r;for(let r=0;r<=o;r++)a[0][r]=r;for(let r=1;r<=n;r++)for(let i=1;i<=o;i++){let s=e[r-1]===t[i-1]?0:1;a[r][i]=Math.min(Math.min(a[r-1][i]+1,a[r][i-1]+1),a[r-1][i-1]+s)}return a[n][o]}};var te=class{ruleName="UnresolvedReference";async validateAsync(e,t){let n=[],o=new U(t),a=await o.buildEntityIndexAsync(e),r=new Set;for(let[i,s]of a.entries()){let c=s.entity.type;if(c){let p=c.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&r.add(i)}}for(let[i,s]of Object.entries(e.body)){if(!s||typeof s!="object"||Array.isArray(s))continue;let c=s,p=this.getPropertyValue(c,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[l,u]of Object.entries(c))l==="type"||l==="label"||l==="comment"||!(r.has(l)||Array.from(r).some(f=>f.endsWith(`.${l}`)))||await this.validateReferenceValue(i,l,u,e,o,n)}return n}async validateReferenceValue(e,t,n,o,a,r){if(n!=null){if(typeof n=="string")await a.resolveEntityAsync(n,o)||r.push(this.createUnresolvedReferenceError(e,t,n));else if(Array.isArray(n))for(let i=0;i<n.length;i++){let s=n[i];typeof s=="string"&&(await a.resolveEntityAsync(s,o)||r.push(this.createUnresolvedReferenceError(e,`${t}[${i}]`,s)))}}}createUnresolvedReferenceError(e,t,n){let o=`The entity '${n}' cannot be found in the current document or any imported namespaces.
7
+
8
+ Possible solutions:
9
+ \u2022 Add import if the entity is defined in another namespace:
10
+ kanonak namespace add-import <publisher>/<package>@<version>
11
+ \u2022 Check for typos in the reference name '${n}'
12
+ \u2022 Define '${n}' in the current namespace or an appropriate namespace
13
+ \u2022 Use 'kanonak search type ${n} --include-imports' to locate the entity`,a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.actualValue=n,a.message=`Reference to '${n}' could not be resolved`,a.suggestion=o,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,t){let n=e[t];return n?n.toString():null}};var ne=class{ruleName="ClassHierarchyCycle";async validateAsync(e,t){let n=[],o=new Map,a=new Set;await this.buildClassHierarchy(e,t,o,a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type,p=s.subClassOf;if(c?.toString()==="Class"&&p){let l=r,u=this.detectCycle(l,o);if(u){let y=u.join(" \u2192 "),f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Circular class hierarchy detected: ${y}`,f.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",f.entityName=l,f.propertyName="subClassOf",f.actualValue=y,n.push(f);break}}}return n}async buildClassHierarchy(e,t,n,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type,p=s.subClassOf;if(c?.toString()==="Class"&&p){let l=N(p);l.length>0&&n.set(r,l)}}if(e.metadata?.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);c&&await this.buildClassHierarchy(c,t,n,o)}}}detectCycle(e,t){let n=[],o=new Set;return this.detectCycleRecursive(e,t,n,o)}detectCycleRecursive(e,t,n,o){if(n.includes(e)){let r=n.indexOf(e),i=n.slice(r);return i.push(e),i}if(o.has(e))return null;n.push(e),o.add(e);let a=t.get(e);if(a)for(let r of a){let i=this.detectCycleRecursive(r,t,n,o);if(i)return i}return n.pop(),null}};var oe=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,t){let n=[],o=new Map,a=new Set;await this.buildPropertyHierarchy(e,t,o,a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)&&i.subPropertyOf){let p=r,l=this.detectCycle(p,o);if(l){let u=l.join(" \u2192 "),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Circular property hierarchy detected: ${u}`,y.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",y.entityName=p,y.propertyName="subPropertyOf",y.actualValue=u,n.push(y);break}}return n}async buildPropertyHierarchy(e,t,n,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type;if(c){let p=c.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let l=s.subPropertyOf;if(l){let u=N(l);u.length>0&&n.set(r,u)}}}}if(e.metadata?.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);c&&await this.buildPropertyHierarchy(c,t,n,o)}}}detectCycle(e,t){let n=[],o=new Set;return this.detectCycleRecursive(e,t,n,o)}detectCycleRecursive(e,t,n,o){if(n.includes(e)){let r=n.indexOf(e),i=n.slice(r);return i.push(e),i}if(o.has(e))return null;n.push(e),o.add(e);let a=t.get(e);if(a)for(let r of a){let i=this.detectCycleRecursive(r,t,n,o);if(i)return i}return n.pop(),null}};var re=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,t){let n=[];for(let[o,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let r=a,i=r.type?.toString();if(i==="DatatypeProperty"||i==="ObjectProperty"||i?.endsWith(".DatatypeProperty")||i?.endsWith(".ObjectProperty")){let s="range"in r,c=r.range?.toString().trim();if(!s||!c){let p=new g;p.ruleType=this.ruleName,p.severity="Error",p.entityName=o,p.propertyName="range",p.message=`Property '${o}' must have a 'range' defined.`,p.suggestion=i==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=i==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",n.push(p)}}}return n}};var ie=class{builtInClasses=new Set(["Resource","Class","Datatype","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}isClassLikeType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isClassLikeType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=N(r.subClassOf);for(let c=0;c<s.length;c++){let p=s[c];if(this.builtInClasses.has(p)||o.has(p))continue;if(!await this.isClassAvailableInImports(e,t,p)){let u=s.length>1?`[${c}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Class '${p}' referenced in subClassOf${u} is not defined or imported`,y.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,y.entityName=a,y.propertyName="subClassOf",y.actualValue=p,y.expectedValue="Defined or imported class",n.push(y)}}}return n}async isClassAvailableInImports(e,t,n){if(!e.metadata.imports)return!1;let o=null,a=n;if(n.includes(".")){let r=n.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:n,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(this.isClassLikeType(f))return!0}let u=new Set;if(await this.isClassAvailableInImportsRecursive(c,t,p,u))return!0}}return!1}async isClassAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isClassLikeType(u))return!0}if(await this.isClassAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}};var ae=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=N(r.subPropertyOf);for(let c=0;c<s.length;c++){let p=s[c];if(this.builtInProperties.has(p)||o.has(p))continue;if(!await this.isPropertyAvailableInImports(e,t,p)){let u=s.length>1?`[${c}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Property '${p}' referenced in subPropertyOf${u} is not defined or imported`,y.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,y.entityName=a,y.propertyName="subPropertyOf",y.actualValue=p,y.expectedValue="Defined or imported property",n.push(y)}}}return n}async isPropertyAvailableInImports(e,t,n){if(!e.metadata.imports)return!1;let o=null,a=n;if(n.includes(".")){let r=n.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:n,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(f==="DatatypeProperty"||f==="ObjectProperty"||f==="AnnotationProperty")return!0}let u=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,t,p,u))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}};var se=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,t){let n=[],o=e.metadata.namespace_?.toString();if(!o)return n;let a=new Map,r=new Set;await this.buildImportGraph(e,t,a,r);let i=this.detectCycle(o,a);if(i){let s=i.join(" \u2192 "),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=`Circular namespace import detected: ${s}`,c.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",c.entityName="imports",c.propertyName="imports",c.actualValue=s,n.push(c)}return n}async buildImportGraph(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(!(!a||o.has(a))&&(o.add(a),e.metadata.imports)){let r=[];for(let[i,s]of Object.entries(e.metadata.imports))for(let c of s){let p=`${i}/${c.packageName}@${c.version}`;r.push(p);let l=await t.getHighestCompatibleVersionAsync(i,c);l&&await this.buildImportGraph(l,t,n,o)}r.length>0&&n.set(a,r)}}detectCycle(e,t){let n=[],o=new Set;return this.detectCycleRecursive(e,t,n,o)}detectCycleRecursive(e,t,n,o){let a=n.indexOf(e);if(a>=0){let i=n.slice(a);return i.push(e),i}if(o.has(e))return null;n.push(e),o.add(e);let r=t.get(e);if(r)for(let i of r){let s=this.detectCycleRecursive(i,t,n,o);if(s)return s}return n.pop(),null}};async function Be(m,e,t){return t?t.getKanonaks():new E().parseKanonaks(new M(m,e))}async function pt(m,e,t){let n=await Be(m,e,t),o=Fe(m);return o?n.filter(a=>a instanceof D&&a.namespace===o):[]}function _e(m,e){for(let t of m)t instanceof D&&He(t,t.name,e)}function He(m,e,t){t({kanonak:m,path:e});for(let n of m.statement)if(n instanceof Ze)He(n.object,ct(e,n.object),t);else if(n instanceof Je)for(let o of n.object)o instanceof I&&He(o,ct(e,o),t)}function ct(m,e){let t=e instanceof I&&e.name?e.name:"<embedded>";return`${m}/${t}`}function Fe(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ce=class{ruleName="UnresolvedPredicate";async validateAsync(e,t,n){let o=[],a=Fe(e);if(!a)return o;let r=await Be(e,t,n);return _e(r,({kanonak:i,path:s})=>{for(let c of i.unresolvedPredicates)c.sourceDoc===a&&o.push(this.unresolvedPredicateError(s,c.key))}),o}unresolvedPredicateError(e,t){let n=t.lastIndexOf("."),o=n>0?t.slice(0,n):null,a=n>0?t.slice(n+1):t,r=new g;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=t,r.expectedValue="A defined or imported property",r.message=`Property '${t}' is not defined or imported`,r.suggestion=o?`The property '${a}' was not found in the namespace imported as '${o}'.
14
+ 1. Check '${a}' is spelled correctly
15
+ 2. Verify '${o}' is imported with the right alias and version
16
+ 3. Ensure that namespace version actually defines '${a}'`:`The property '${t}' is not defined in this namespace or any imported namespace.
17
+ 1. Define '${t}' as an ObjectProperty or DatatypeProperty here, OR
18
+ 2. Import the namespace that defines it, OR
19
+ 3. Alias-qualify it if it lives in an imported namespace ('alias.${t}')`,r}};var pe=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isPropertyType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=i.type?.toString();if(!this.isPropertyType(s)&&!this.isClassType(s))continue;for(let[c,p]of Object.entries(i)){if(!c||this.metadataKeys.has(c))continue;let l=c,u=null;if(c.includes(".")){let f=c.lastIndexOf(".");u=c.substring(0,f),l=c.substring(f+1)}if(o.has(l))continue;if(!await this.isPropertyAvailableInImports(e,t,l,u)){let f=this.isClassType(s)?"class":"property",d=new g;d.ruleType=this.ruleName,d.severity="Error",d.message=`Property '${c}' used on ${f} '${a}' is not defined or imported`,d.suggestion=u?`The property '${l}' is not found in the imported namespace with alias '${u}'.
20
+ 1. Verify the namespace is imported with the correct alias
21
+ 2. Check if the property name is spelled correctly
22
+ 3. Ensure the imported namespace version contains this property`:`The property '${c}' is not defined in this namespace or any imported namespace.
23
+ 1. Define '${c}' as an ObjectProperty or DatatypeProperty in this namespace, OR
24
+ 2. Import the namespace that contains '${c}', OR
25
+ 3. Use a qualified reference like 'alias.${c}' if already imported with an alias`,d.entityName=a,d.propertyName=c,d.actualValue=p?.toString(),d.expectedValue="A defined or imported property",n.push(d)}}}return n}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,t,n,o){if(!e.metadata.imports)return!1;for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){if(o!==null&&i.alias!==o)continue;let s=await t.getHighestCompatibleVersionAsync(a,i);if(s){let c=s.body[n];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(this.isPropertyType(u))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,t,n,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isPropertyType(u))return!0}if(await this.isPropertyAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}};var le=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"XsdImport"}async validateAsync(e,t){let n=[],o=new Set,a=[];for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let s=i,c=!1,p=s.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="DatatypeProperty"){c=!0;break}}else p?.toString()==="DatatypeProperty"&&(c=!0);if(c){a.push(r);let l=this.getPropertyValue(s,"range");l&&this.xsdTypes.has(l)&&o.add(l)}}if(o.size>0&&!await this.checkXsdImportAsync(e.metadata,t)){let i=Array.from(o).sort().join(", "),s=a.sort().join(", "),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=`XSD namespace not imported but XSD types are used: ${i}`,c.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${s}`,c.entityName="imports",n.push(c)}return n}async checkXsdImportAsync(e,t,n=new Set){if(!e?.imports)return!1;let o=e.namespace_?.toString()??"";if(o&&n.has(o))return!1;o&&n.add(o);for(let[,a]of Object.entries(e.imports))for(let r of a)if(r.packageName==="xsd"||r.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[a,r]of Object.entries(e.imports))for(let i of r){let s=await t.getHighestCompatibleVersionAsync(a,i);if(s?.metadata&&await this.checkXsdImportAsync(s.metadata,t,n))return!0}return!1}getPropertyValue(e,t){return e[t]?.toString()}};var me=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,t){let n=[],{entitySources:o,importPaths:a}=await this.buildEntitySourceMapAsync(e,t),r=await this.buildDatatypePropertyNamesAsync(e,t);for(let[i,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.validateEntityReferences(i,s,o,a,r,e,n);return n}async buildEntitySourceMapAsync(e,t){let n=new Map,o=new Set,a=new Map;for(let r of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";n.has(r)||n.set(r,[]),n.get(r).push(`(local:${i})`)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(c,n,o,a,[p],t)}}return{entitySources:n,importPaths:a}}async collectEntitiesRecursivelyAsync(e,t,n,o,a,r){let i=e.metadata.namespace_?.toString()??"";if(!n.has(i)){n.add(i),o.has(i)||o.set(i,a);for(let s of Object.keys(e.body)){t.has(s)||t.set(s,[]);let c=t.get(s);c.includes(i)||c.push(i)}if(e.metadata.imports)for(let[s,c]of Object.entries(e.metadata.imports))for(let p of c){let l=await r.getHighestCompatibleVersionAsync(s,p);if(l){let u=l.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(l,t,n,o,[...a,u],r)}}}}async buildDatatypePropertyNamesAsync(e,t){let n=new Set,o=new Set;if(await this.collectDatatypePropertiesAsync(e,n,o,t),e.metadata.imports)for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){let s=await t.getHighestCompatibleVersionAsync(a,i);s&&await this.collectDatatypePropertiesAsync(s,n,o,t)}return n}async collectDatatypePropertiesAsync(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(!n.has(a)){n.add(a);for(let[r,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let s=i.type;if(typeof s!="string")continue;(s.includes(".")?s.substring(s.lastIndexOf(".")+1):s)==="DatatypeProperty"&&t.add(r)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await o.getHighestCompatibleVersionAsync(r,s);c&&await this.collectDatatypePropertiesAsync(c,t,n,o)}}}validateEntityReferences(e,t,n,o,a,r,i){for(let[s,c]of Object.entries(t)){let p=s;if(p&&!p.includes(".")){let l=n.get(p);if(l&&l.length>1&&!l.some(y=>y.startsWith("(local:"))){let y=l.filter(f=>!f.startsWith("(local:"));y.length>1&&i.push(this.createAmbiguityError(e,p,`Property '${p}'`,y,o,r,!0,p))}}this.validatePropertyValue(e,p,c,n,o,a,r,i)}}validatePropertyValue(e,t,n,o,a,r,i,s){if(n==null)return;let c=t&&t.includes(".")?t.substring(t.lastIndexOf(".")+1):t,p=!!c&&r.has(c);if(typeof n=="string"&&!n.includes(".")&&!p){let l=o.get(n);if(l&&l.length>1&&!l.some(y=>y.startsWith("(local:"))){let y=l.filter(f=>!f.startsWith("(local:"));y.length>1&&s.push(this.createAmbiguityError(e,t,`Reference '${n}'`,y,a,i,!1,n))}}else if(Array.isArray(n))for(let l=0;l<n.length;l++){let u=`${e}.${t}[${l}]`;this.validatePropertyValue(u,t,n[l],o,a,r,i,s)}else if(typeof n=="object"&&!Array.isArray(n)){let l=t?`${e}.${t}`:e;this.validateEntityReferences(l,n,o,a,r,i,s)}}createAmbiguityError(e,t,n,o,a,r,i,s){let c=[];for(let k of o){let h=this.findAliasForNamespace(r,k);if(h){let v=t?.split(".").pop()??t;c.push(`${h}.${v}`)}}let p=c.length>0?`Use one of: ${c.map(k=>`'${k}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${t}')`,l=o.map(k=>{let h=a.get(k);return!h||h.length===0?` \u2022 ${k}`:h.length===1?` \u2022 ${k} (direct import)`:` \u2022 ${k}
26
+ imported via: ${h.join(" \u2192 ")}`}).join(`
27
+ `),u=e.split(".")[0],y=e.includes(".")?e:t,f=new g;f.ruleType=this.ruleName,f.severity="Error",f.entityName=u,y&&(f.propertyName=y);let d=s??t;return d&&(f.actualValue=d),f.message=`${n} is ambiguous - defined in multiple imported namespaces`,f.suggestion=`${p}
28
+
29
+ Defined in:
30
+ ${l}`,f.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",f}findAliasForNamespace(e,t){if(!e.metadata.imports)return null;for(let[n,o]of Object.entries(e.metadata.imports))for(let a of o)if(`${n}/${a.packageName}@${a.version}`===t&&a.alias)return a.alias;return null}};var ye=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]);primitiveTypes=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","Literal","Resource"]);get ruleName(){return"PropertyRangeReference"}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isValidRangeTargetType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=i.type?.toString();if(s!=="DatatypeProperty"&&s!=="ObjectProperty"&&!s?.endsWith(".DatatypeProperty")&&!s?.endsWith(".ObjectProperty"))continue;let c=i.range;if(!c)continue;let p=[];if(Array.isArray(c))for(let l of c){let u=l?.toString();u&&p.push(u)}else{let l=c?.toString();l&&p.push(l)}if(p.length===0)continue;for(let l of p){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||o.has(l))continue;if(!await this.isTypeAvailableInImports(e,t,l)){let y=s?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${a}' has range '${l}' which is not defined or imported`,f.suggestion=y==="ObjectProperty"?`For ObjectProperty:
31
+ 1. Define '${l}' as a Class in this namespace, OR
32
+ 2. Import the namespace that contains '${l}', OR
33
+ 3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
34
+ 1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
35
+ 2. If '${l}' should be a class, change property type to ObjectProperty`,f.entityName=a,f.propertyName="range",f.actualValue=l,f.expectedValue=y==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",n.push(f)}}}return n}async isTypeAvailableInImports(e,t,n){if(!e.metadata.imports)return!1;let o=null,a=n;if(n.includes(".")){let r=n.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:n,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(this.isValidRangeTargetType(f))return!0}let u=new Set;if(await this.isTypeAvailableInImportsRecursive(c,t,p,u))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isValidRangeTargetType(u))return!0}if(await this.isTypeAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var ue=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,t){let n=[],o=new Map,a=new U(t);await a.buildEntityIndexAsync(e);for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let s=i,c=!1,p=s.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="ObjectProperty"){c=!0;break}}else p?.toString()==="ObjectProperty"&&(c=!0);if(c){let l=s.range,u=[];if(Array.isArray(l))for(let y of l){let f=y?.toString();f&&u.push(f)}else{let y=l?.toString();y&&u.push(y)}for(let y of u)this.xsdTypes.has(y)||(o.has(y)||o.set(y,[]),o.get(y).push(r))}}for(let[r,i]of o)if(!await a.resolveEntityAsync(r,e))for(let c of i){let p=new g;p.ruleType=this.ruleName,p.severity="Warning",p.message=`ObjectProperty references class '${r}' which may not be imported`,p.suggestion=`Ensure the namespace containing '${r}' is imported, or define '${r}' in this document`,p.entityName=c,p.propertyName="range",p.actualValue=r,n.push(p)}return n}};var fe=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,t){let n=[],o=new U(t),a=new et(o),r=await o.buildEntityIndexAsync(e),i=await this.buildPropertyMetadataAsync(e,t,o,r);for(let[s,c]of Object.entries(e.body))typeof c=="object"&&c!==null&&!Array.isArray(c)&&await this.scanEntityForObjectProperties(c,s,"",i,o,a,e,n);return n}async scanEntityForObjectProperties(e,t,n,o,a,r,i,s){for(let[c,p]of Object.entries(e)){if(this.standardProperties.has(c))continue;let l,u=await a.resolveEntityAsync(c,i);if(u?.uri){let y=`${u.uri.publisher}/${u.uri.package_}/${u.uri.name}`;l=o.get(y)}if(!l){let y=c,f=c.lastIndexOf(".");f>0&&f<c.length-1&&(y=c.substring(f+1)),l=o.get(y)}if(l&&r.isEffectiveObjectProperty(l.propertyType,l.rangeUri)){let f=n?`${n}.${c}`:c;if(typeof p=="string"&&p.trim().length>0){let d=p.trim();if(d.includes(",")){let h=d.split(",").map(v=>v.trim()).filter(v=>v.length>0);s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
36
+ ${c}:
37
+ - ${h[0]}
38
+ ${h.slice(1).map(v=>` - ${v}`).join(`
39
+ `)}`,entityName:t,propertyName:c,propertyPath:f,actualValue:d,expectedValue:`A single reference to ${l.range??"an entity"} OR a YAML list`});continue}let k=await a.resolveEntityAsync(d,i);if(k)l.range&&(await this.validateRangeType(k,l.range,a,i)||s.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${c}' expects a ${l.range}, but '${d}' may not be a ${l.range}`,suggestion:`Ensure '${d}' is defined with appropriate type`,entityName:t,propertyName:c,propertyPath:f,actualValue:d,expectedValue:l.range}));else{let h=l.range??"entity";s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' references '${d}' which is not defined or imported`,suggestion:`Define '${d}' or import a namespace that contains it. Expected range: ${h}`,entityName:t,propertyName:c,propertyPath:f,actualValue:d,expectedValue:"Defined or imported entity"})}}else if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let d=n?`${n}.${c}`:c;await this.scanEntityForObjectProperties(p,t,d,o,a,r,i,s)}else if(Array.isArray(p))for(let d=0;d<p.length;d++){let k=p[d];if(typeof k=="string"&&k.trim().length>0){let h=k.trim(),v=await a.resolveEntityAsync(h,i);if(v){if(l.range&&!await this.validateRangeType(v,l.range,a,i)){let je=n?`${n}.${c}[${d}]`:`${c}[${d}]`;s.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${c}' expects a ${l.range}, but '${h}' may not be a ${l.range}`,suggestion:`Ensure '${h}' is defined with appropriate type`,entityName:t,propertyName:`${c}[${d}]`,propertyPath:je,actualValue:h,expectedValue:l.range})}}else{let $=l.range??"entity",je=n?`${n}.${c}[${d}]`:`${c}[${d}]`;s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' references '${h}' which is not defined or imported`,suggestion:`Define '${h}' or import a namespace that contains it. Expected range: ${$}`,entityName:t,propertyName:`${c}[${d}]`,propertyPath:je,actualValue:h,expectedValue:"Defined or imported entity"})}}else if(typeof k=="object"&&k!==null&&!Array.isArray(k)){let h=n?`${n}.${c}[${d}]`:`${c}[${d}]`;await this.scanEntityForObjectProperties(k,t,h,o,a,r,i,s)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!o.has(c)){let y=n?`${n}.${c}`:c;await this.scanEntityForObjectProperties(p,t,y,o,a,r,i,s)}else if(Array.isArray(p))for(let y=0;y<p.length;y++){let f=p[y];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=n?`${n}.${c}[${y}]`:`${c}[${y}]`;await this.scanEntityForObjectProperties(f,t,d,o,a,r,i,s)}}}}async validateRangeType(e,t,n,o){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(t))return!0;let r=e.entity.type;if(r){let i=[];if(Array.isArray(r))for(let s of r){let c=s?.toString();c&&c.trim().length>0&&i.push(c)}else{let s=r?.toString();s&&s.trim().length>0&&i.push(s)}for(let s of i){let c=s.includes(".")?s.split(".")[1]:s;if(c===t||t==="Property"&&(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty")||t==="Class"&&c==="Class"||await n.isSubclassOfAsync(s,t,o))return!0}}return!1}async buildPropertyMetadataAsync(e,t,n,o){let a=new Map;for(let[r,i]of o){let s=i.entity.type;if(s){let c=[];if(Array.isArray(s))for(let u of s){let y=u?.toString();y&&y.trim().length>0&&c.push(y)}else{let u=s?.toString();u&&u.trim().length>0&&c.push(u)}let p=!1,l="Property";for(let u of c){let y=u.includes(".")?u.split(".")[1]:u;if(y==="Property"||y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty"){p=!0,l=u;break}}if(p){let u={propertyType:l},y=i.entity.range;if(y){let f=y?.toString();if(f&&f.trim().length>0){u.range=f;let d=await n.resolveEntityAsync(f,e);d&&(u.rangeUri=d.uri)}}if(a.set(r,u),i.uri){let f=`${i.uri.publisher}/${i.uri.package_}/${i.uri.name}`;a.set(f,u)}}}}return a}};var de=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,t,n){let o=[],a=new Map;for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=this.getPropertyValue(c,"type");(p==="DatatypeProperty"||p?.endsWith(".DatatypeProperty")||p==="ObjectProperty"||p?.endsWith(".ObjectProperty")||p==="AnnotationProperty"||p?.endsWith(".AnnotationProperty"))&&a.set(i,c)}let r=n?await this.buildClassHierarchyViaCache(e,n):await this.buildCompleteClassHierarchyAsync(e,t);for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=this.getPropertyValue(c,"type");if(!p||p==="Class"||p.endsWith(".Class")||p.endsWith("Property")||p==="AnnotationProperty")continue;this.validateEntityProperties(c,i,p,a,r,o)}return o}async buildClassHierarchyViaCache(e,t){let n=new Map,o=Vt(e);if(!o)return n;let a=await t.getImportClosure(o);for(let r of a){let i=await t.getClassDeclarations(r);for(let[s,c]of i)c.length>0&&n.set(s,c)}return n}async buildCompleteClassHierarchyAsync(e,t){let n=new Map,o=new Set,a=async(i,s)=>{if(!o.has(s)){o.add(s);for(let[c,p]of Object.entries(i.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let l=p,u=this.getPropertyValue(l,"type");if(u==="Class"||u?.endsWith(".Class")){let y=l.subClassOf;if(y===void 0){for(let d of Object.keys(l))if(d.endsWith(".subClassOf")){y=l[d];break}}let f=N(y);f.length>0&&n.set(c,f)}}if(i.metadata.imports)for(let[c,p]of Object.entries(i.metadata.imports))for(let l of p)try{let u=await t.getHighestCompatibleVersionAsync(c,l);if(u){let y=`${c}/${l.packageName}@${l.version}`;await a(u,y)}}catch{}}},r=e.metadata.namespace_?.toString()??"unknown";return await a(e,r),n}validateEntityProperties(e,t,n,o,a,r){for(let[i,s]of Object.entries(e)){if(this.standardProperties.has(i))continue;let c=i,p=i.lastIndexOf(".");p>0&&p<i.length-1&&(c=i.substring(p+1));let l=o.get(c);if(!l)continue;let u=this.getPropertyValue(l,"domain");if(u){if(!this.isTypeCompatibleWithDomain(n,u,a)){let y=t.split(".")[0];r.push({ruleType:this.ruleName,severity:"Error",entityName:y,propertyName:t,actualValue:i,message:`Property '${i}' has domain '${u}' but is used on '${n}' at '${t}'`,suggestion:`Either:
40
+ 1. Use this property only on '${u}' instances
41
+ 2. Change the property domain to include '${n}'
42
+ 3. Create a different property for '${n}'`,expectedValue:`Property used on ${u} or its subclasses`})}if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let y=s,f=this.getPropertyValue(y,"type");if(f){let d=`${t}.${i}`;this.validateEntityProperties(y,d,f,o,a,r)}else{let d=this.getPropertyValue(l,"range");if(d){let k=`${t}.${i}`;this.validateEntityProperties(y,k,d,o,a,r)}}}else if(Array.isArray(s))for(let y=0;y<s.length;y++){let f=s[y];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=f,k=this.getPropertyValue(d,"type");if(k){let h=`${t}.${i}[${y}]`;this.validateEntityProperties(d,h,k,o,a,r)}else{let h=this.getPropertyValue(l,"range");if(h){let v=`${t}.${i}[${y}]`;this.validateEntityProperties(d,v,h,o,a,r)}}}}}}}isTypeCompatibleWithDomain(e,t,n){if(e===t)return!0;let o=new Set,a=[e];for(;a.length>0;){let r=a.shift();if(o.has(r))continue;o.add(r);let i=n.get(r);if(i)for(let s of i){if(s===t)return!0;a.push(s)}}return!1}getPropertyValue(e,t){if(t in e){let n=e[t];return this.extractFirstValue(n)}for(let n of Object.keys(e))if(n.endsWith(`.${t}`)){let o=e[n];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let t=[];for(let n of e)t.push(n?.toString()??"");return t.length>0?t[0]:void 0}return e?.toString()}};function Vt(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ge=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,t){let n=[],o=new Map;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=this.getPropertyValue(i,"type");(s==="DatatypeProperty"||s==="ObjectProperty")&&o.set(a,i)}for(let[a,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let i=r,s=this.getPropertyValue(i,"type");if(!(!s||s==="Class"||s.endsWith("Property")||s==="AnnotationProperty"))for(let[c,p]of Object.entries(i)){if(c==="type"||c==="label"||c==="comment")continue;let l=c,u=c.lastIndexOf(".");u>0&&u<c.length-1&&(l=c.substring(u+1));let y=o.get(l);if(!y)continue;let f=this.getPropertyValue(y,"type"),d=this.getPropertyValue(y,"range");if(f==="DatatypeProperty"){if(typeof p=="object"&&p!==null&&!Array.isArray(p)||Array.isArray(p))n.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`Property '${c}' is a DatatypeProperty with range '${d}' but instance '${a}' has a complex object value`,suggestion:`Either:
43
+ 1. Create a class for this data and change '${c}' to an ObjectProperty
44
+ 2. Store as a JSON string to keep it as DatatypeProperty
45
+ 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${d}'`});else if(!this.validateDatatypeValue(d,p)){let k={ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`Property '${c}' expects type '${d}' but instance '${a}' has value of type '${this.getValueTypeName(p)}'`,suggestion:`Provide a value of type '${d}'`,toString:()=>""};d&&(k.expectedValue=d),n.push(k)}}else if(f==="ObjectProperty")if(Array.isArray(p))for(let k=0;k<p.length;k++){let h=p[k];typeof h!="string"&&(typeof h!="object"||h===null||Array.isArray(h))&&n.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:`${c}[${k}]`,message:`ObjectProperty '${c}' array item ${k} in instance '${a}' has invalid type '${this.getValueTypeName(h)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof p!="string"&&(typeof p!="object"||p===null||Array.isArray(p))&&n.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`ObjectProperty '${c}' in instance '${a}' has invalid value type '${this.getValueTypeName(p)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${d} or embedded ${d} object`})}}return n}validateDatatypeValue(e,t){switch(e?.toLowerCase()){case"string":return typeof t=="string";case"integer":case"int":return typeof t=="number"&&Number.isInteger(t);case"decimal":return typeof t=="number";case"boolean":return typeof t=="boolean";case"float":case"double":return typeof t=="number";default:return!0}}getValueTypeName(e){return typeof e=="string"?"string":typeof e=="number"?Number.isInteger(e)?"integer":"decimal":typeof e=="boolean"?"boolean":Array.isArray(e)?"array":typeof e=="object"&&e!==null?"object":e===null?"null":e===void 0?"undefined":typeof e}getPropertyValue(e,t){if(t in e){let n=e[t];if(Array.isArray(n)){let o=[];for(let a of n)o.push(a?.toString()??"");return o.length>0?o[0]:void 0}return n?.toString()}}};var he=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty","Package"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,t){let n=[],o=new Map,a=new Set;for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=s.type;if(p)if(Array.isArray(p))for(let l of p){let u=l?.toString();if(u==="Class"||u&&u.endsWith(".Class")){a.add(i);break}}else{let l=p?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&a.add(i)}}for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=c.type;if(p)if(Array.isArray(p)){let l=!1;for(let u of p){let y=u?.toString();if(y&&this.isDefinitionType(y)){l=!0;break}}if(!l)for(let u of p){let y=u?.toString();y&&y.trim().length>0&&(o.has(y)||o.set(y,[]),o.get(y).push(i))}}else{let l=p?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(o.has(l)||o.set(l,[]),o.get(l).push(i)))}this.checkNestedTypes(c,i,o,i)}let r=new U(t);for(let[i,s]of o){if(this.builtInClasses.has(i)||a.has(i))continue;let c=await r.resolveEntityAsync(i,e);if(!(c&&this.isClassEntity(c.entity))){let l=Array.from(new Set(s)).sort();for(let u of l)n.push({ruleType:this.ruleName,severity:"Error",message:`Class '${i}' is not defined or imported`,suggestion:`Define '${i}' as a Class in this document, or import a namespace that contains it`,entityName:u,propertyName:"type",actualValue:i,expectedValue:"Defined or imported class"})}}return n}checkNestedTypes(e,t,n,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=e,r=a.type;if(r){let i=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(r))for(let s of r){let c=s?.toString();c&&c.trim().length>0&&!i.has(c)&&(n.has(c)||n.set(c,[]),n.get(c).push(o))}else{let s=r?.toString();s&&s.trim().length>0&&!i.has(s)&&(n.has(s)||n.set(s,[]),n.get(s).push(o))}}for(let[i,s]of Object.entries(a))if(i!=="type"){let c=`${o}.${i}`;this.checkNestedTypes(s,t,n,c)}}else if(Array.isArray(e))for(let a=0;a<e.length;a++){let r=`${o}[${a}]`;this.checkNestedTypes(e[a],t,n,r)}}isClassEntity(e){if(!e)return!1;let t=e.type;if(!t)return!1;if(Array.isArray(t))for(let n of t){let o=n?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let n=t?.toString();if(n==="Class"||n&&n.endsWith(".Class"))return!0}return!1}isDefinitionType(e){return!e||e.trim().length===0?!1:new Set(["Class","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(e)?!0:e.endsWith(".Class")||e.endsWith(".Property")||e.endsWith(".DatatypeProperty")||e.endsWith(".ObjectProperty")||e.endsWith(".AnnotationProperty")}};var ke=class{ruleName="MarkdownLink";async validateAsync(e,t,n){let o=[],a=await pt(e,t,n);return _e(a,({kanonak:r,path:i})=>{this.checkNode(r,i,o)}),o}checkNode(e,t,n){for(let o of e.statement){if(!(o instanceof Qe))continue;let a=o.predicate.subject?.name??"(unknown)";for(let r of o.links)r.target||n.push(this.unresolvedLinkError(t,a,r.reference));for(let r of tt(o.object))n.push(this.malformedLinkError(t,a,r.snippet))}}unresolvedLinkError(e,t,n){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=t,o.actualValue=n,o.message=`Embedded link [[${n}]] in '${t}' could not be resolved`,o.expectedValue="A reference resolvable through the document's import closure",o.suggestion=`The reference '${n}' inside a markdown value cannot be found in the current document or any imported namespace.
46
+
47
+ Possible solutions:
48
+ \u2022 Import the package that defines '${n}' so the link can resolve
49
+ \u2022 Check for typos in the reference name
50
+ \u2022 If the name collides across imports, alias-qualify it: [[alias.${n}]]`,o}malformedLinkError(e,t,n){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=t,o.actualValue=n,o.message=`Malformed embedded reference near '${n}' in '${t}'`,o.expectedValue="A single-line [[reference]] with no internal line break",o.suggestion=`A '[[' in '${t}' does not form a complete [[reference]] link.
51
+
52
+ A reference may not span a line break \u2014 the most common cause is wrapping a
53
+ long reference across two lines in a block scalar, e.g.:
54
+ ... read for [[persistent-energy-
55
+ shock]] held ...
56
+ which is parsed as literal text, not a link. Keep each [[reference]] on one
57
+ line (let the line run long), or check for an unterminated [[.`,o}};var lt="kanonak.org",mt="look",Pt={publisher:lt,package_:mt,name:"displayLabel"},Dt={publisher:lt,package_:mt,name:"displaySummary"},be=class{ruleName="DisplayLensScope";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=It(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&(this.checkLens(a,i,Pt,"displayLabel",o),this.checkLens(a,i,Dt,"displaySummary",o));return o}checkLens(e,t,n,o,a){let r=V(t,n);if(!r)return;let i=[],s=W(t);if(s&&i.push(s),i.push(...rt(t)),i.length===0)return;i.some(p=>x(e,p,r).ok)||a.push(this.scopeError(t.name,o,r.name))}scopeError(e,t,n){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=t,o.actualValue=n,o.message=`${t} points at '${n}', which is not a property in scope for '${e}'`,o.expectedValue="A property whose domain is this resource's class, an ancestor, or rdfs.Resource",o.suggestion=`'${n}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
58
+
59
+ Possible solutions:
60
+ \u2022 Point ${t} at a property declared on this class (or an ancestor / rdfs.Resource)
61
+ \u2022 Set the property's domain to this class if it should apply here
62
+ \u2022 Use rdfs.label / rdfs.comment for the universal default`,o}};function It(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}function F(m,e,t){let n=[];return Ke(m,t,{input:e},n),n}function Ke(m,e,t,n){if(A(e,_.VarRef)){let r=L(e,_.varName);return r?t[r]:void 0}if(A(e,_.PropertyRead)){let r=O(e,_.readSource),i=r?Ke(m,r,t,n):void 0,s=V(e,_.readProp);if(!i||!s)return;let c=x(m,i,s);if(!c.ok){n.push({contextClass:i,propertyUri:s,via:"PropertyRead"});return}return c.descriptor?.range}if(A(e,_.Traverse)){let r=O(e,_.traverseSource),i=r?Ke(m,r,t,n):void 0,s=V(e,_.through),c;if(i&&s){let l=x(m,i,s);l.ok?c=l.descriptor?.range:n.push({contextClass:i,propertyUri:s,via:"Traverse"})}let p=O(e,_.step);return p?Ke(m,p,{...t,input:c},n):void 0}let o=L(e,_.loopVar),a=o?{...t,[o]:void 0}:t;for(let r of Et(e))Ke(m,r,a,n)}function Et(m){let e=[];for(let t of m.statement){let n=t.object;if(n instanceof I)e.push(n);else if(Array.isArray(n))for(let o of n)o instanceof I&&e.push(o)}return e}var $e="kanonak.org",Ce="look",At={publisher:$e,package_:Ce,name:"semanticSvg"},Ot={publisher:$e,package_:Ce,name:"tierChip"},St={publisher:$e,package_:Ce,name:"tierIcon"},Kt={publisher:$e,package_:Ce,name:"tierCard"},$t={publisher:$e,package_:Ce,name:"tierFull"},Ct=[Ot,St,Kt,$t],Re=class{ruleName="LookSemanticSvgPath";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=wt(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&this.checkSemanticSvg(a,i,o);return o}checkSemanticSvg(e,t,n){let o=O(t,At);if(!o)return;let a=W(t);if(a)for(let r of Ct){let i=O(o,r);if(i)for(let s of F(e,a,i))n.push(this.toError(t.name,r.name,s))}}toError(e,t,n){let o=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,r=a===e?`'${e}' (the class this SemanticSvg is declared on)`:`'${a}', reached by traversal from '${e}' (the class this SemanticSvg is declared on)`,i=new g;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=`look.semanticSvg.${t}`,i.actualValue=o,i.message=`tx.${n.via} reads property '${n.propertyUri.name}' off the rendered instance, but its domain is not in scope for ${r}. The read would silently return undefined at render time.`,i.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,i.suggestion=`Property '${o}' is not in scope for '${a}'.
63
+
64
+ Possible solutions:
65
+ \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
66
+ \u2022 If the property should apply to '${a}', adjust its domain
67
+ \u2022 If the value comes from a pre-computed env binding, use tx.VarRef instead of PropertyRead`,i}};function wt(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var jt="kanonak.org",R=(m,e)=>({publisher:jt,package_:m,name:e}),Nt=R("derivation","look"),xt=R("look","bands"),Tt=R("look","Distribution"),_t=R("look","StatRow"),Ut=R("look","VersionDelta"),Lt=R("look","Timeline"),Mt=R("look","VersionDiff"),Wt=R("look","TimePlot"),Ht=R("look","ReferenceList"),Bt=R("look","Diagram"),Ft=R("look","alphaPath"),Xt=R("look","betaPath"),Xe=R("look","metricPath"),yt=R("look","lowerPath"),ut=R("look","upperPath"),ft=R("look","hueBy"),qt=R("look","statPath"),zt=R("look","laneBy"),dt=R("look","labelPath"),Yt=R("look","badgePath"),Gt=R("look","mapPath"),Zt=R("look","nodeNote"),Jt=R("look","edgeValue"),Qt=R("look","stats"),en=R("look","facets"),tn=R("look","channels"),nn=R("look","track"),on=R("look","source"),rn=R("look","relation"),an=R("look","entries"),we=class{ruleName="LookBandPath";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=cn(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&this.checkDeclaration(a,i,o);return o}checkDeclaration(e,t,n){let o=O(t,Nt);if(!o)return;let a=W(t);if(!a)return;let r=S(o,xt).filter(i=>i instanceof I);for(let i of r)for(let s of this.carriersOf(e,i,a))for(let c of F(e,s.context,s.expr))n.push(this.toError(t.name,s.slot,c))}carriersOf(e,t,n){let o=[],a=(r,i)=>{let s=O(t,r);s&&o.push({slot:`look.${r.name}`,context:i,expr:s})};if(A(t,Tt))for(let r of[Ft,Xt,Xe,yt,ut,ft])a(r,n);if(A(t,Ut)&&a(Xe,n),A(t,_t)){let r=S(t,Qt).filter(i=>i instanceof I);for(let i of r){let s=O(i,qt);s&&o.push({slot:"look.stats[].statPath",context:n,expr:s})}}if(A(t,Lt)||A(t,Mt)){let r=this.rangeOf(e,n,V(t,nn));if(r)for(let i of[Xe,yt,ut,ft])a(i,r)}if(A(t,Wt)){let r=this.rangeOf(e,n,V(t,on));if(r)for(let i of[zt,dt])a(i,r)}if(A(t,Ht))for(let r of S(t,an)){let i=r instanceof I?void 0:sn(r),s=this.rangeOf(e,n,i);if(s)for(let c of[dt,Yt])a(c,s)}if(A(t,Bt)){let r=S(t,en).filter(i=>i instanceof I);for(let i of r){let s=this.rangeOf(e,n,V(i,rn));if(!s)continue;let c=O(i,Zt);c&&o.push({slot:"look.facets[].nodeNote",context:s,expr:c});let p=O(i,Jt);p&&o.push({slot:"look.facets[].edgeValue",context:s,expr:p});let l=S(i,tn).filter(u=>u instanceof I);for(let u of l){let y=O(u,Gt);y&&o.push({slot:"look.facets[].channels[].mapPath",context:s,expr:y})}}}return o}rangeOf(e,t,n){if(!n)return;let o=x(e,t,n);return o.ok?o.descriptor?.range:void 0}toError(e,t,n){let o=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,r=new g;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=o,r.message=`tx.${n.via} reads property '${n.propertyUri.name}', but its domain is not in scope for '${a}' (the class this band carrier is evaluated against). The read would silently return undefined at render time and the band would render empty.`,r.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,r.suggestion=`Property '${o}' is not in scope for '${a}'.
68
+
69
+ Possible solutions:
70
+ \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
71
+ \u2022 If the property should apply to '${a}', adjust its domain
72
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,r}};function sn(m){let e=m.subject;return e&&typeof e.name=="string"?e:void 0}function cn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var Ve="kanonak.org",Pe="view",pn={publisher:Ve,package_:Pe,name:"bind"},ln={publisher:Ve,package_:Pe,name:"produces"},mn={publisher:Ve,package_:Pe,name:"projections"},yn={publisher:Ve,package_:Pe,name:"where"},un={publisher:Ve,package_:Pe,name:"value"},fn={publisher:Ve,package_:Pe,name:"as"},ve=class{ruleName="TxExpressionPath";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=hn(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&this.checkView(a,i,o);return o}checkView(e,t,n){let o=V(t,pn);if(!o)return;let a=V(t,ln),r=0;for(let s of gn(e,S(t,mn))){let c=O(s,un);if(c)for(let l of F(e,o,c))n.push(this.toError(t.name,`view.projections[${r}].value`,o,l));let p=V(s,fn);p&&a&&(x(e,a,p).ok||n.push(this.asError(t.name,r,a,p))),r+=1}let i=0;for(let s of dn(t,yn)){for(let c of F(e,o,s))n.push(this.toError(t.name,`view.where[${i}]`,o,c));i+=1}}asError(e,t,n,o){let a=`${o.publisher}/${o.package_}/${o.name}`,r=new g;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=`view.projections[${t}].as`,r.actualValue=a,r.message=`Projection stores its value under property '${o.name}', but that property's domain is not in scope for the view's produces class '${n.name}'. The materialized result instance could not carry this value.`,r.expectedValue=`A property whose domain is '${n.name}', an ancestor, or rdfs.Resource`,r.suggestion=`Property '${a}' is not in scope for produces class '${n.name}'.
73
+
74
+ Possible solutions:
75
+ \u2022 Use an output property whose domain covers '${n.name}'
76
+ \u2022 Define a new property in the ViewPackage with domain '${n.name}' and the right range
77
+ \u2022 If the value belongs on a different output class, adjust the view's produces`,r}toError(e,t,n,o){let a=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,i=r===n.name?`the view's bound class '${n.name}'`:`'${r}', reached by traversal from the view's bound class '${n.name}'`,s=new g;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=t,s.actualValue=a,s.message=`tx.${o.via} reads property '${o.propertyUri.name}', but its domain is not in scope for ${i}. The read would silently return undefined when the view materializes.`,s.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,s.suggestion=`Property '${a}' is not in scope for '${r}'.
78
+
79
+ Possible solutions:
80
+ \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
81
+ \u2022 If the property should apply to '${r}', adjust its domain
82
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,s}};function dn(m,e){let t=O(m,e);return t?[t]:S(m,e).filter(n=>n instanceof I)}function gn(m,e){let t=[];for(let n of e)if(n instanceof I)t.push(n);else if(n instanceof H){let o=T(m,n.subject);o&&t.push(o)}return t}function hn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var Ue="kanonak.org",kn="core-shacl",K=m=>({publisher:Ue,package_:kn,name:m}),bn=K("NodeShape"),Rn=K("PropertyShape"),vn=K("targetClass"),Vn=K("property"),Pn=K("path"),Dn=K("minCount"),In=K("maxCount"),En=K("datatype"),An=K("class"),gt=K("in"),On=K("pattern"),Sn=K("flags"),Kn=K("minLength"),$n=K("maxLength"),Cn=K("minInclusive"),wn=K("maxInclusive"),jn=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),qe=m=>m,Ie=class{ruleName="ShaclShape";async validateAsync(e,t,n){let o=[],a=n?await n.getKanonaks():await new E().parseKanonaks(t),r=Nn(e);if(!r)return o;let i=new Set;for(let s of a){if(!(s instanceof D)||s.namespace!==r||!A(s,bn))continue;let c=V(s,vn);c?this.resolvesToClass(a,c)||o.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' sh:targetClass '${c.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",X(c))):o.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' has no sh:targetClass; it constrains nothing.`,"Add sh:targetClass naming the class this shape applies to."));for(let p of S(s,Vn)){let l;if(p instanceof I)l=p;else if(p instanceof H){let u=T(a,p.subject);u&&(l=u,i.add(C(p.subject)))}l&&this.checkPropertyShape(a,s.name,l,c??void 0,o)}}for(let s of a){if(!(s instanceof D)||s.namespace!==r||!A(s,Rn))continue;let c=W(s);c&&i.has(C(c))||this.checkPropertyShape(a,s.name,s,void 0,o)}return o}checkPropertyShape(e,t,n,o,a){let r=V(n,Pn);if(!r){a.push(this.err(t,"property.path","Error",`A PropertyShape on '${t}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=T(e,r),s=i?B.isAnyPropertyType(qe(i)):!1;s?o&&(x(e,o,r).ok||a.push(this.err(t,"property.path","Warning",`sh:path '${r.name}' is not in scope for sh:targetClass '${o.name}'; the constraint would never bind a value.`,`Constrain a property whose domain is '${o.name}', an ancestor, or rdfs.Resource.`,X(r)))):a.push(this.err(t,"property.path","Error",`sh:path '${r.name}' on '${t}' does not resolve to a property.`,"Reference a defined or imported property.",X(r)));let c=V(n,En),p=V(n,An);c&&p&&a.push(this.err(t,"property","Error",`A PropertyShape on '${t}' sets both sh:datatype and sh:class; a value is a literal or a node, not both.`,"Keep sh:datatype (literal values) or sh:class (node values), not both.")),c&&!this.resolvesToDatatype(e,c)&&a.push(this.err(t,"datatype","Error",`sh:datatype '${c.name}' on '${t}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",X(c))),p&&!this.resolvesToClass(e,p)&&a.push(this.err(t,"class","Error",`sh:class '${p.name}' on '${t}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",X(p)));let l=De(w(n,Dn)),u=De(w(n,In));this.checkOrder(t,"minCount",l,"maxCount",u,a);let y=De(w(n,Kn)),f=De(w(n,$n));this.checkOrder(t,"minLength",y,"maxLength",f,a);let d=De(w(n,Cn)),k=De(w(n,wn));this.checkOrder(t,"minInclusive",d,"maxInclusive",k,a);let h=L(n,On);if(h!==void 0){let v=L(n,Sn);try{new RegExp(h,v)}catch{a.push(this.err(t,"pattern","Error",`sh:pattern on '${t}' is not a valid regular expression`+(v!==void 0?` (with flags '${v}')`:"")+`: ${h}`,"Provide a valid regular expression and flags.",h))}}if(xe(n,gt)&&S(n,gt).length===0&&a.push(this.err(t,"in","Error",`sh:in on '${t}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),s&&o){let $=x(e,o,r).descriptor;$&&((h!==void 0||y!==void 0||f!==void 0)&&$.kind==="object"&&a.push(this.err(t,"pattern/minLength/maxLength","Warning",`String facets on '${t}' apply to '${r.name}', which is an object property; string facets constrain literal values.`,"Apply string facets to a datatype property, or use sh:class for node values.",X(r))),(d!==void 0||k!==void 0)&&!this.isNumericDatatypeRange($.range)&&a.push(this.err(t,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${t}' apply to '${r.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",X(r))))}}checkOrder(e,t,n,o,a,r){n!==void 0&&a!==void 0&&n>a&&r.push(this.err(e,`${t}/${o}`,"Error",`${t} (${n}) exceeds ${o} (${a}) on '${e}'.`,`Set ${t} <= ${o}.`))}resolvesToClass(e,t){let n=T(e,t);return n?B.isClassType(qe(n)):!1}resolvesToDatatype(e,t){if(t.publisher===Ue&&t.package_==="core-rdf"&&t.name==="Literal")return!0;let n=T(e,t);return n?B.isDatatypeType(qe(n)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Ue&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Ue&&e.package_==="core-xsd"&&jn.has(e.name)}err(e,t,n,o,a,r){let i=new g;return i.ruleType=this.ruleName,i.severity=n,i.entityName=e,i.propertyName=t,i.message=o,i.suggestion=a,r!==void 0&&(i.actualValue=r),i}};function De(m){return typeof m=="number"?m:void 0}function X(m){return`${m.publisher}/${m.package_}/${m.name}`}function Nn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ht={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},xn=m=>m,Ee=class{ruleName="OwlOneOf";async validateAsync(e,t,n){let o=[],a=n?await n.getKanonaks():await new E().parseKanonaks(t),r=Tn(e);if(!r)return o;for(let i of a){if(!(i instanceof D)||i.namespace!==r||!xe(i,ht))continue;let s=S(i,ht);if(s.length===0){o.push(this.err(i.name,"Warning",`owl:oneOf on '${i.name}' is empty; a closed enumeration must list at least one individual.`,"List the individuals that make up the enumeration, or remove owl:oneOf."));continue}for(let c of s)if(c instanceof Ne)o.push(this.err(i.name,"Error",`owl:oneOf member '${String(c.value)}' on '${i.name}' is not a named individual; a class enumeration is of individuals (a misspelled or unimported individual reads as a literal). For a closed set of literal VALUES, constrain a property with sh:in instead.`,"Reference a defined or imported individual, or move literal value sets to a property sh:in.",String(c.value)));else if(c instanceof H){let p=T(a,c.subject);p&&B.isSchemaDefinitionType(xn(p))&&o.push(this.err(i.name,"Error",`owl:oneOf member '${c.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${c.subject.publisher}/${c.subject.package_}/${c.subject.name}`))}}return o}err(e,t,n,o,a){let r=new g;return r.ruleType=this.ruleName,r.severity=t,r.entityName=e,r.propertyName="oneOf",r.message=n,r.suggestion=o,a!==void 0&&(r.actualValue=a),r}};function Tn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var _n="kanonak.org",Un="core-shacl",j=m=>({publisher:_n,package_:Un,name:m}),Ln=j("NodeShape"),Mn=j("targetClass"),Wn=j("property"),Hn=j("path"),Bn=j("minCount"),Fn=j("maxCount"),Xn=j("in"),qn=j("pattern"),zn=j("flags"),Yn=j("minLength"),Gn=j("maxLength"),Zn=j("minInclusive"),Jn=j("maxInclusive"),Qn=j("message");function Ae(m){return typeof m=="number"?m:void 0}function eo(m){let e={},t=Ae(w(m,Bn)),n=Ae(w(m,Fn));t!==void 0&&(e.minCount=t),n!==void 0&&(e.maxCount=n);let o=Ae(w(m,Yn)),a=Ae(w(m,Gn));o!==void 0&&(e.minLength=o),a!==void 0&&(e.maxLength=a);let r=Ae(w(m,Zn)),i=Ae(w(m,Jn));r!==void 0&&(e.minInclusive=r),i!==void 0&&(e.maxInclusive=i);let s=L(m,qn);if(s!==void 0){let l=L(m,zn);e.pattern=l!==void 0?{regex:s,flags:l}:{regex:s}}let c=S(m,Xn).filter(l=>l instanceof Ne).map(l=>l.value);c.length>0&&(e.enumValues=c);let p=L(m,Qn);return p!==void 0&&(e.message=p),e}function to(m,e){let t=[];for(let n of S(e,Wn))if(n instanceof I)t.push(n);else if(n instanceof H){let o=T(m,n.subject);o&&t.push(o)}return t}function kt(m){let e=new Map;for(let t of m){if(!(t instanceof D)||!A(t,Ln))continue;let n=V(t,Mn);if(!n)continue;let o=C(n);for(let a of to(m,t)){let r=V(a,Hn);if(!r)continue;let i={pathKey:C(r),constraints:eo(a)},s=e.get(o);s?s.push(i):e.set(o,[i])}}return e}function no(m,e){e.minCount!==void 0&&(m.minCount=e.minCount),e.maxCount!==void 0&&(m.maxCount=e.maxCount),e.minLength!==void 0&&(m.minLength=e.minLength),e.maxLength!==void 0&&(m.maxLength=e.maxLength),e.minInclusive!==void 0&&(m.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(m.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(m.pattern=e.pattern),e.enumValues!==void 0&&(m.enumValues=e.enumValues),e.message!==void 0&&(m.message=e.message)}function bt(m,e,t){let n=C(t),o=!1,a={};for(let r=e.length-1;r>=0;r--){let i=m.get(C(e[r]));if(i)for(let s of i)s.pathKey===n&&(o=!0,no(a,s.constraints))}if(o)return a.cardinality=a.maxCount===1?"single":"list",a.required=(a.minCount??0)>=1,a}var oo=m=>m,ro=new Ge("kanonak.org","core-rdf","Resource"),Oe=class{ruleName="DiamondNameClash";async validateAsync(e,t,n){let o=[],a=n?await n.getKanonaks():await new E().parseKanonaks(t),r=io(e);if(!r)return o;let i=kt(a);for(let s of a){if(!(s instanceof D)||s.namespace!==r||!B.isClassType(oo(s)))continue;let c=W(s);if(!c)continue;let p=nt(a,c),l=C(c),u=new Set(p.map(f=>C(f)));u.delete(l),u.delete(C(ro));let y=new Map;for(let f of ot(a,c)){if(!f.domains.some(h=>u.has(C(h))))continue;let k=y.get(f.uri.name);k?k.push(f):y.set(f.uri.name,[f])}for(let[f,d]of y){if(d.length<2)continue;let k=$=>bt(i,p,$.uri)?.cardinality,h=new Set(d.map($=>$.range?C($.range):void 0).filter($=>$!==void 0)),v=new Set(d.map(k).filter($=>$!==void 0));h.size<=1&&v.size<=1||o.push(this.toError(s.name,f,d,k))}}return o}toError(e,t,n,o){let a=s=>{let c=`${s.uri.publisher}/${s.uri.package_}/${s.uri.name}`,p=s.range?`${s.range.publisher}/${s.range.package_}/${s.range.name}`:"no range",l=o(s);return`${c} (range ${p}${l?`, ${l}`:""})`},r=n.map(a).join("; "),i=new g;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=t,i.actualValue=r,i.message=`Class '${e}' inherits ${n.length} distinct properties named '${t}' with incompatible range or cardinality: ${r}. The generated interface would multiply-inherit '${t}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${t}':
83
+ \u2022 rename one of the properties, or
84
+ \u2022 re-domain one so it is not inherited by '${e}', or
85
+ \u2022 restructure the hierarchy so '${e}' inherits only one '${t}', or
86
+ \u2022 make the ranges/cardinalities compatible (identical) if they are meant to be the same property.`,i}};function io(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ze=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new Ye,this.documentRules=[new z,new Y,new G,new Z,new J],this.repositoryRules=[new Q,new ee,new te,new ne,new oe,new re,new ie,new ae,new se,new ce,new pe,new le,new me,new ye,new ue,new fe,new de,new ge,new he,new ke,new be,new Re,new we,new ve,new Ie,new Ee,new Oe]}async validateAsync(e,t,n){let o=new q;for(let a of this.documentRules)try{let r=a.validate(e);this.addErrorsToResult(o,r)}catch(r){let i=new g;i.ruleType=a.ruleName,i.severity="Error",i.message=`Validation rule '${a.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,o.errors.push(i)}if(t){let a=[],r=n?.repository??t;for(let i of this.repositoryRules)try{let s=await i.validateAsync(e,r,n);this.addErrorsToResult(o,s)}catch(s){let c=s instanceof Error?s.message:String(s);a.push({ruleName:i.ruleName,cause:c})}if(a.length>0){let i=new Map;for(let{ruleName:s,cause:c}of a){let p=i.get(c);p?p.push(s):i.set(c,[s])}for(let[s,c]of i){let p=new g;p.ruleType=c[0],p.severity="Error",c.length===1?p.message=`Validation rule '${c[0]}' failed: ${s}`:p.message=`${s} (affects ${c.length} rules: ${c.join(", ")})`,o.errors.push(p)}}}return o.isValid=o.errors.length===0,o}async validateDocumentsAsync(e,t){let n=new Se(t),o=[];for(let a of e){let r=await this.validateAsync(a,n.repository,n);o.push({document:a,result:r})}return o}async validateYamlAsync(e,t,n){let o=this.parser.parseWithErrors(e);if(!o.isValid){let a=new q;a.isValid=!1;for(let r of o.errors){let i=new g;i.ruleType="ParseError",i.severity="Error",i.lineNumber=r.line,i.column=r.column,i.message=r.message,r.keyName&&(i.entityName=r.keyName),r.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),a.errors.push(i)}return a}return await this.validateAsync(o.document,t,n)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let t=this.documentRules.findIndex(n=>n instanceof e);t>=0&&this.documentRules.splice(t,1)}removeRepositoryRule(e){let t=this.repositoryRules.findIndex(n=>n instanceof e);t>=0&&this.repositoryRules.splice(t,1)}addErrorsToResult(e,t){for(let n of t)n.severity==="Error"?e.errors.push(n):this.includeWarnings&&e.warnings.push(n)}};export{q as a,b,g as c,Le as d,Se as e,z as f,Y as g,G as h,Z as i,J as j,Q as k,ee as l,te as m,ne as n,oe as o,re as p,ie as q,ae as r,se as s,ce as t,pe as u,le as v,me as w,ye as x,ue as y,fe as z,de as A,ge as B,he as C,ke as D,be as E,Re as F,ve as G,Ie as H,Ee as I,kt as J,bt as K,Oe as L,ze as M};
@@ -1,4 +1,4 @@
1
- import{a as Cn}from"./chunk-4NO7MHS7.js";import{a as An}from"./chunk-PEJALHXK.js";import{d as u}from"./chunk-SHDHMKMJ.js";import{a as M,c as Me,i as Vn}from"./chunk-DSHPAWJQ.js";import{a as Fn}from"./chunk-NJ3AZYQD.js";import{a as pn,b as ue,c as xn,d as w,f as Ne,g as ke,j as gn,k as qe,m as Mn,n as Nn}from"./chunk-PBNVHBS3.js";import{b as Oe,c as G,d as E,g as X,h as me,i as re,j as V,k as H,l as T}from"./chunk-T3JR2SV6.js";import{a as Tn}from"./chunk-FUUTGGJS.js";import{c as en,g as ye}from"./chunk-2ACBWC7K.js";var Te="kanonak.org",Hn="look",We="core-rdf",Et={publisher:Te,package_:Hn,name:"displayLabel"},Kt={publisher:Te,package_:Hn,name:"displaySummary"},Rt={publisher:Te,package_:We,name:"type"},Lt={publisher:Te,package_:We,name:"subClassOf"},Ot={publisher:Te,package_:We,name:"label"},Ut={publisher:Te,package_:We,name:"comment"},Pn=new Tn(Te,We,"Resource");function D(r,e){let n=Dn(r,e,Et)??Ot,t=Dn(r,e,Kt)??Ut,a=gn(e,n)??e.name,s=gn(e,t);return{label:a,summary:s}}function Dn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Bn(e,Rt);for(;s.length>0;){let o=s.shift(),i=pn(o);if(a.has(i))continue;a.add(i);let c=Ne(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Bn(c,Lt))}if(!a.has(pn(Pn))){let o=Ne(r,Pn);if(o){let i=qe(o,n);if(i)return i}}}function Bn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of Mn(r,e))a instanceof E&&t.push(a.subject);return t}function Ye(r,e={}){let n=r.replace(/\r\n/g,`
1
+ import{a as Cn}from"./chunk-4NO7MHS7.js";import{a as An}from"./chunk-PEJALHXK.js";import{d as u}from"./chunk-SHDHMKMJ.js";import{a as M,c as Me,h as Vn}from"./chunk-BKVPSPG4.js";import{a as Fn}from"./chunk-NJ3AZYQD.js";import{a as pn,b as ue,c as xn,d as w,f as Ne,g as ke,j as gn,k as qe,m as Mn,n as Nn}from"./chunk-7TKJHKC2.js";import{b as Oe,c as G,d as E,g as X,h as me,i as re,j as V,k as H,l as T}from"./chunk-4UT2CLAT.js";import{a as Tn}from"./chunk-FUUTGGJS.js";import{c as en,g as ye}from"./chunk-2ACBWC7K.js";var Te="kanonak.org",Hn="look",We="core-rdf",Et={publisher:Te,package_:Hn,name:"displayLabel"},Kt={publisher:Te,package_:Hn,name:"displaySummary"},Rt={publisher:Te,package_:We,name:"type"},Lt={publisher:Te,package_:We,name:"subClassOf"},Ot={publisher:Te,package_:We,name:"label"},Ut={publisher:Te,package_:We,name:"comment"},Pn=new Tn(Te,We,"Resource");function D(r,e){let n=Dn(r,e,Et)??Ot,t=Dn(r,e,Kt)??Ut,a=gn(e,n)??e.name,s=gn(e,t);return{label:a,summary:s}}function Dn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Bn(e,Rt);for(;s.length>0;){let o=s.shift(),i=pn(o);if(a.has(i))continue;a.add(i);let c=Ne(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Bn(c,Lt))}if(!a.has(pn(Pn))){let o=Ne(r,Pn);if(o){let i=qe(o,n);if(i)return i}}}function Bn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of Mn(r,e))a instanceof E&&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
  `),g=l&&e.highlight?e.highlight(l,f):De(f),m=l?` class="language-${Gn(l)}"`:"";t.push(`<pre class="kan-code"><code${m}>${g}</code></pre>`);continue}let i=/^(#{1,6})\s+(.*)$/.exec(s);if(i){let l=i[1].length,d=Pe(i[2].trim());t.push(`<h${l}>${d}</h${l}>`),a++;continue}if(s.includes("|")&&a+1<n.length&&zn(n[a+1])){let l=mn(s),d=It(n[a+1]);a+=2;let f=[];for(;a<n.length&&n[a].trim()!==""&&n[a].includes("|");)f.push(mn(n[a])),a++;t.push(Ct(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>${Pe(d.join(" ").trim())}</li>`)}t.push(`<ul>
@@ -1 +1 @@
1
- import{a as D}from"./chunk-DSHPAWJQ.js";import{c as j,d as m,g as R,j as p,k as K,l as k}from"./chunk-T3JR2SV6.js";import{c as b,g as u}from"./chunk-2ACBWC7K.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-BKVPSPG4.js";import{c as j,d as m,g as R,j as p,k as K,l as k}from"./chunk-4UT2CLAT.js";import{c as b,g as u}from"./chunk-2ACBWC7K.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};
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export type { IStatement } from './statements/index.js';
15
15
  export type { MarkdownLink } from './statements/index.js';
16
16
  export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement, MarkdownStatement } from './statements/index.js';
17
17
  export { extractMarkdownLinks, findMalformedReferences, type RawMarkdownLink, type MalformedMarkdownLink, } from './parsing/extractMarkdownLinks.js';
18
- export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, MarkdownLinkRule } from './validation/index.js';
18
+ export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, MarkdownLinkRule } from './validation/index.js';
19
19
  export type { IKanonakObjectValidator, DocumentValidationResult, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
20
20
  export type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
21
21
  export type { IKanonakParser } from '@kanonak-protocol/types/document/parsing';
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import{a as Rn,b as En,c as xn,d as In,e as Pe}from"./chunk-RWEGPZ23.js";import{a as br,c as Re,e as ze,h as We,i as Ge,j as Pr}from"./chunk-OOR5SVNQ.js";import{a as wn,b as Sn,c as Cn,d as G,e as J,f as l,g as wr}from"./chunk-KGWDV7FW.js";import{a as hr}from"./chunk-NV63IOB7.js";import"./chunk-QHABFCRC.js";import{a as Wt,b as Gt,c as Jt,d as qt,e as Yt,f as on,g as an,h as sn,i as cn}from"./chunk-GMEPM2QQ.js";import{a as Zt,b as Xt,c as Qt,d as b,f as en,g as tn,h as rn}from"./chunk-JYBKSBB5.js";import{a as zt}from"./chunk-4NO7MHS7.js";import{a as Kn,b as $n,c as jn,d as An}from"./chunk-RYOZTXI7.js";import{a as Vn,b as Ln}from"./chunk-PEUTCG3B.js";import{a as On}from"./chunk-PEJALHXK.js";import{a as nn}from"./chunk-SC5M74NM.js";import{A as mr,B as fr,C as yr,D as gr,M as kr,a as Un,b as Fn,c as Mn,d as Hn,e as zn,f as Wn,g as Gn,h as Jn,i as qn,j as Yn,k as Zn,l as Xn,m as Qn,n as er,o as tr,p as nr,q as rr,r as or,s as ar,t as ir,u as sr,v as cr,w as lr,x as ur,y as pr,z as dr}from"./chunk-IZRPJCQW.js";import"./chunk-SHDHMKMJ.js";import{a as y,b as R,c as pn,d as Me,e as K,f as be,g as hn,h as bn,i as j}from"./chunk-DSHPAWJQ.js";import{a as C}from"./chunk-NJ3AZYQD.js";import{a as Pn,b as we,c as Bn,d as k,e as Nn,f as Dn,g as Tn,h as _n}from"./chunk-UK2OIPAB.js";import{f as W,k as A,l as Se,m as Ce,n as He}from"./chunk-PBNVHBS3.js";import{b as dn,c as mn,d as $,e as fn,f as yn,h as gn,j as kn}from"./chunk-VKTFLHCW.js";import{a as ln,b as ye,c as f,d as p,e as un,f as ge,g as E,h as ke,i as he,j as x,k as I,l as v}from"./chunk-T3JR2SV6.js";import{a as z}from"./chunk-FUUTGGJS.js";import{a as Tt,b as fe,c as H,d as _t,e as h,f as Lt,g as Ut,h as Ft,i as Mt,j as Ht}from"./chunk-2ACBWC7K.js";import{a as vn}from"./chunk-ODIECDN7.js";import{VersionOperator as Fi}from"@kanonak-protocol/types/document/models/enums";import{existsSync as _r,readFileSync as Lr}from"fs";import{homedir as Ur}from"os";import{join as Fr}from"path";import{execFile as Sr}from"child_process";import{promisify as Cr}from"util";var q=Cr(Sr),Y="kanonak",Z="/usr/bin/security",V=class{async get(e){let t=l(e);try{let{stdout:r}=await q(Z,["find-generic-password","-s",Y,"-a",t,"-w"],{timeout:1e4});try{return JSON.parse(r.trim())}catch{throw new Error(`Stored credential for '${t}' is corrupted (not valid JSON).
2
- Run 'kanonak logout ${t}' then 'kanonak login ${t}' to fix.`)}}catch(r){if(Je(r,44))return null;throw new Error(`macOS Keychain read failed for '${t}': ${X(r)}
1
+ import{a as kr,b as hr,c as br,d as Pr,e as he}from"./chunk-CR55WXIN.js";import{a as mn,c as Ce,e as Le,h as Fe,i as Me,j as fn}from"./chunk-V72IVYR4.js";import{a as fr,b as yr,c as gr,d as L,e as F,f as l,g as yn}from"./chunk-U7LVFPEO.js";import{a as dn}from"./chunk-VWS25JH4.js";import"./chunk-QHABFCRC.js";import{a as Ut,b as _t,c as Lt,d as Ft,e as Mt,f as Zt,g as Xt,h as Qt,i as er}from"./chunk-GMEPM2QQ.js";import{a as Ht,b as zt,c as Wt,d as b,f as Gt,g as Jt,h as Yt}from"./chunk-JYBKSBB5.js";import{a as Bt}from"./chunk-4NO7MHS7.js";import{a as Cr,b as Sr,c as Rr,d as Er}from"./chunk-RGOBWOBB.js";import{a as xr,b as Vr}from"./chunk-PEUTCG3B.js";import{a as vr}from"./chunk-PEJALHXK.js";import{a as qt}from"./chunk-SC5M74NM.js";import{A as sn,B as cn,C as ln,D as un,M as pn,a as Or,b as Dr,c as Tr,d as Nr,e as Br,f as Ur,g as _r,h as Lr,i as Fr,j as Mr,k as Hr,l as zr,m as Wr,n as Gr,o as Jr,p as qr,q as Yr,r as Zr,s as Xr,t as Qr,u as en,v as tn,w as rn,x as nn,y as on,z as an}from"./chunk-UBBZWWRB.js";import"./chunk-SHDHMKMJ.js";import{a as y,b as ue,c as or,d as U,e as Ue,f as pr,g as dr,h as E}from"./chunk-BKVPSPG4.js";import{a as S}from"./chunk-NJ3AZYQD.js";import{a as mr,b as be,c as Ir,d as g,e as Kr,f as $r,g as jr,h as Ar}from"./chunk-IEOSSSB5.js";import{f as _,k as x,l as Pe,m as we,n as _e}from"./chunk-7TKJHKC2.js";import{b as ar,c as ir,d as R,e as sr,f as cr,h as lr,k as ur}from"./chunk-7HRKWTBB.js";import{a as tr,b as le,c as f,d as h,e as nr,f as pe,g as de,h as me,i as fe,j as ye,k as ge,l as ke}from"./chunk-4UT2CLAT.js";import{a as rr}from"./chunk-FUUTGGJS.js";import{a as jt,b as ce,c as B,d as At,e as k,f as Vt,g as Ot,h as Dt,i as Tt,j as Nt}from"./chunk-2ACBWC7K.js";import{a as wr}from"./chunk-ODIECDN7.js";import{VersionOperator as Si}from"@kanonak-protocol/types/document/models/enums";import{existsSync as Vn,readFileSync as On}from"fs";import{homedir as Dn}from"os";import{join as Tn}from"path";import{execFile as gn}from"child_process";import{promisify as kn}from"util";var M=kn(gn),H="kanonak",z="/usr/bin/security",I=class{async get(e){let t=l(e);try{let{stdout:n}=await M(z,["find-generic-password","-s",H,"-a",t,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${t}' is corrupted (not valid JSON).
2
+ Run 'kanonak logout ${t}' then 'kanonak login ${t}' to fix.`)}}catch(n){if(He(n,44))return null;throw new Error(`macOS Keychain read failed for '${t}': ${W(n)}
3
3
  The Keychain may be locked or inaccessible.
4
- Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,t){let r=l(e),o=JSON.stringify(t);try{await q(Z,["add-generic-password","-s",Y,"-a",r,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${r}': ${X(a)}
4
+ Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,t){let n=l(e),o=JSON.stringify(t);try{await M(z,["add-generic-password","-s",H,"-a",n,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${n}': ${W(a)}
5
5
  Ensure the Keychain is unlocked and the CLI has write permission.
6
- On managed devices, your IT policy may block credential storage.`)}}async remove(e){let t=l(e);try{await q(Z,["delete-generic-password","-s",Y,"-a",t],{timeout:1e4})}catch(r){if(Je(r,44))return;console.warn(` Warning: macOS Keychain delete failed for '${t}': ${X(r)}
7
- The credential may not have been fully removed.`)}}async list(){try{let{stdout:e}=await q(Z,["dump-keychain"],{timeout:1e4}),t=[],r=!1;for(let o of e.split(`
8
- `))if(o.includes(`"svce"<blob>="${Y}"`)&&(r=!0),r&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&t.push(a[1]),r=!1}return t}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${X(e)}`),[]}}};function Je(n,e){return typeof n=="object"&&n!==null&&"code"in n&&n.code===e}function X(n){return n instanceof Error?n.message:String(n)}import{execFile as Rr}from"child_process";import{promisify as Er}from"util";var xr=Er(Rr),Q="kanonak:",B=class{async get(e){let t=Q+l(e),r=`
9
- ${te}
6
+ On managed devices, your IT policy may block credential storage.`)}}async remove(e){let t=l(e);try{await M(z,["delete-generic-password","-s",H,"-a",t],{timeout:1e4})}catch(n){if(He(n,44))return;console.warn(` Warning: macOS Keychain delete failed for '${t}': ${W(n)}
7
+ The credential may not have been fully removed.`)}}async list(){try{let{stdout:e}=await M(z,["dump-keychain"],{timeout:1e4}),t=[],n=!1;for(let o of e.split(`
8
+ `))if(o.includes(`"svce"<blob>="${H}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&t.push(a[1]),n=!1}return t}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${W(e)}`),[]}}};function He(r,e){return typeof r=="object"&&r!==null&&"code"in r&&r.code===e}function W(r){return r instanceof Error?r.message:String(r)}import{execFile as hn}from"child_process";import{promisify as bn}from"util";var Pn=bn(hn),G="kanonak:",v=class{async get(e){let t=G+l(e),n=`
9
+ ${q}
10
10
  $target = [Console]::In.ReadLine()
11
11
  $ptr = [IntPtr]::Zero
12
12
  $result = [CredMan]::CredRead($target, 1, 0, [ref]$ptr)
@@ -18,8 +18,8 @@ try {
18
18
  [System.Text.Encoding]::Unicode.GetString($bytes)
19
19
  } finally {
20
20
  [CredMan]::CredFree($ptr)
21
- }`;try{let{stdout:o}=await ee(r,t),a=o.trim();return a?JSON.parse(a):null}catch{return null}}async store(e,t){let r=Q+l(e),o=JSON.stringify(t),a=`
22
- ${te}
21
+ }`;try{let{stdout:o}=await J(n,t),a=o.trim();return a?JSON.parse(a):null}catch{return null}}async store(e,t){let n=G+l(e),o=JSON.stringify(t),a=`
22
+ ${q}
23
23
  $target = [Console]::In.ReadLine()
24
24
  $json = [Console]::In.ReadLine()
25
25
  $bytes = [System.Text.Encoding]::Unicode.GetBytes($json)
@@ -35,13 +35,13 @@ try {
35
35
  if (-not $result) { throw "CredWrite failed" }
36
36
  } finally {
37
37
  [System.Runtime.InteropServices.Marshal]::FreeHGlobal($cred.CredentialBlob)
38
- }`;try{await ee(a,`${r}
39
- ${o}`)}catch(i){throw new Error(`Windows Credential Manager write failed: ${String(i)}`)}}async remove(e){let t=Q+l(e),r=`
40
- ${te}
38
+ }`;try{await J(a,`${n}
39
+ ${o}`)}catch(i){throw new Error(`Windows Credential Manager write failed: ${String(i)}`)}}async remove(e){let t=G+l(e),n=`
40
+ ${q}
41
41
  $target = [Console]::In.ReadLine()
42
- [CredMan]::CredDelete($target, 1, 0) | Out-Null`;try{await ee(r,t)}catch{}}async list(){let e=`
43
- ${te}
44
- ${Ir}
42
+ [CredMan]::CredDelete($target, 1, 0) | Out-Null`;try{await J(n,t)}catch{}}async list(){let e=`
43
+ ${q}
44
+ ${wn}
45
45
  $prefix = [Console]::In.ReadLine()
46
46
  $count = 0
47
47
  $pCreds = [IntPtr]::Zero
@@ -55,8 +55,8 @@ if ([CredMan]::CredEnumerate($null, 0, [ref]$count, [ref]$pCreds)) {
55
55
  }
56
56
  }
57
57
  [CredMan]::CredFree($pCreds)
58
- }`;try{let{stdout:t}=await ee(e,Q);return t.trim().split(`
59
- `).map(r=>r.trim()).filter(Boolean)}catch{return[]}}};async function ee(n,e){for(let t of["pwsh","powershell"])try{return await xr(t,["-NoProfile","-NonInteractive","-Command",n],{timeout:15e3,...e!==void 0&&{input:e}})}catch(r){if(t==="powershell")throw r}throw new Error("Neither pwsh nor powershell found")}var te=`
58
+ }`;try{let{stdout:t}=await J(e,G);return t.trim().split(`
59
+ `).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function J(r,e){for(let t of["pwsh","powershell"])try{return await Pn(t,["-NoProfile","-NonInteractive","-Command",r],{timeout:15e3,...e!==void 0&&{input:e}})}catch(n){if(t==="powershell")throw n}throw new Error("Neither pwsh nor powershell found")}var q=`
60
60
  Add-Type -TypeDefinition @"
61
61
  using System;
62
62
  using System.Runtime.InteropServices;
@@ -87,13 +87,13 @@ public class CredMan {
87
87
  [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
88
88
  public static extern bool CredEnumerate(string filter, int flags, out int count, out IntPtr credentials);
89
89
  }
90
- "@`,Ir="";import{execFile as vr,spawn as Kr}from"child_process";import{promisify as $r}from"util";var re=$r(vr),ne="kanonak",O=class{async get(e){let t=l(e);try{let{stdout:r}=await re("secret-tool",["lookup","service",ne,"publisher",t],{timeout:1e4}),o=r.trim();return o?JSON.parse(o):null}catch{return null}}async store(e,t){let r=l(e),o=JSON.stringify(t);await new Promise((a,i)=>{let s=Kr("secret-tool",["store","--label",`Kanonak: ${r}`,"service",ne,"publisher",r],{stdio:["pipe","ignore","ignore"],timeout:1e4});s.stdin.write(o),s.stdin.end(),s.on("close",c=>{c===0?a():i(new Error(`secret-tool store exited with code ${c}`))}),s.on("error",i)})}async remove(e){let t=l(e);try{await re("secret-tool",["clear","service",ne,"publisher",t],{timeout:1e4})}catch{}}async list(){try{let{stdout:e}=await re("secret-tool",["search","service",ne],{timeout:1e4}),t=[];for(let r of e.split(`
91
- `)){let o=r.match(/attribute\.publisher\s*=\s*(.+)/);o&&t.push(o[1].trim())}return t}catch{return[]}}};async function Ee(){try{return await re("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as qe,mkdirSync as Ye,readFileSync as Ze,writeFileSync as Xe}from"fs";import{createCipheriv as jr,createDecipheriv as Ar,randomBytes as Qe}from"crypto";import{homedir as Vr}from"os";import{join as ve,dirname as et}from"path";var nt=ve(Vr(),".config","kanonak"),N=ve(nt,"keyring.key"),oe=ve(nt,"credentials.enc"),tt="aes-256-gcm",xe=32,P=12,Ie=16,D=class{async get(e){let t=this.loadStore(),r=l(e);return t[r]??null}async store(e,t){let r=this.loadStore(),o=l(e);r[o]=t,this.saveStore(r)}async remove(e){let t=this.loadStore(),r=l(e);delete t[r],this.saveStore(t)}async list(){let e=this.loadStore();return Object.keys(e)}loadStore(){if(!qe(oe))return{};try{let e=this.getOrCreateKey(),t=Ze(oe);if(t.length<P+Ie)return{};let r=t.subarray(0,P),o=t.subarray(P,P+Ie),a=t.subarray(P+Ie),i=Ar(tt,e,r);i.setAuthTag(o);let s=Buffer.concat([i.update(a),i.final()]);return JSON.parse(s.toString("utf-8"))}catch{return{}}}saveStore(e){let t=this.getOrCreateKey(),r=Qe(P),o=jr(tt,t,r),a=Buffer.from(JSON.stringify(e),"utf-8"),i=Buffer.concat([o.update(a),o.final()]),s=o.getAuthTag(),c=Buffer.concat([r,s,i]);Ye(et(oe),{recursive:!0}),Xe(oe,c,{mode:384})}getOrCreateKey(){if(qe(N)){let t=Ze(N);if(t.length!==xe)throw new Error(`Credential keyring key is corrupted (expected ${xe} bytes, got ${t.length}). Delete ${N} and re-authenticate.`);return t}let e=Qe(xe);return Ye(et(N),{recursive:!0}),Xe(N,e,{mode:384}),e}};import{execFile as Br}from"child_process";import{promisify as Or}from"util";var Nr=Or(Br),rt=3e4,T=class{constructor(e){this.helperPath=e}helperPath;async get(e){let t=l(e);try{let o=(await this.runHelper("get",{publisher:t})).trim();return o?JSON.parse(o):null}catch(r){throw new Error(`Credential helper '${this.helperPath}' failed to read credential for '${t}': ${ae(r)}
90
+ "@`,wn="";import{execFile as Cn,spawn as Sn}from"child_process";import{promisify as Rn}from"util";var Z=Rn(Cn),Y="kanonak",K=class{async get(e){let t=l(e);try{let{stdout:n}=await Z("secret-tool",["lookup","service",Y,"publisher",t],{timeout:1e4}),o=n.trim();return o?JSON.parse(o):null}catch{return null}}async store(e,t){let n=l(e),o=JSON.stringify(t);await new Promise((a,i)=>{let s=Sn("secret-tool",["store","--label",`Kanonak: ${n}`,"service",Y,"publisher",n],{stdio:["pipe","ignore","ignore"],timeout:1e4});s.stdin.write(o),s.stdin.end(),s.on("close",c=>{c===0?a():i(new Error(`secret-tool store exited with code ${c}`))}),s.on("error",i)})}async remove(e){let t=l(e);try{await Z("secret-tool",["clear","service",Y,"publisher",t],{timeout:1e4})}catch{}}async list(){try{let{stdout:e}=await Z("secret-tool",["search","service",Y],{timeout:1e4}),t=[];for(let n of e.split(`
91
+ `)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&t.push(o[1].trim())}return t}catch{return[]}}};async function Se(){try{return await Z("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as ze,mkdirSync as We,readFileSync as Ge,writeFileSync as Je}from"fs";import{createCipheriv as En,createDecipheriv as xn,randomBytes as qe}from"crypto";import{homedir as In}from"os";import{join as xe,dirname as Ye}from"path";var Xe=xe(In(),".config","kanonak"),$=xe(Xe,"keyring.key"),X=xe(Xe,"credentials.enc"),Ze="aes-256-gcm",Re=32,P=12,Ee=16,j=class{async get(e){let t=this.loadStore(),n=l(e);return t[n]??null}async store(e,t){let n=this.loadStore(),o=l(e);n[o]=t,this.saveStore(n)}async remove(e){let t=this.loadStore(),n=l(e);delete t[n],this.saveStore(t)}async list(){let e=this.loadStore();return Object.keys(e)}loadStore(){if(!ze(X))return{};try{let e=this.getOrCreateKey(),t=Ge(X);if(t.length<P+Ee)return{};let n=t.subarray(0,P),o=t.subarray(P,P+Ee),a=t.subarray(P+Ee),i=xn(Ze,e,n);i.setAuthTag(o);let s=Buffer.concat([i.update(a),i.final()]);return JSON.parse(s.toString("utf-8"))}catch{return{}}}saveStore(e){let t=this.getOrCreateKey(),n=qe(P),o=En(Ze,t,n),a=Buffer.from(JSON.stringify(e),"utf-8"),i=Buffer.concat([o.update(a),o.final()]),s=o.getAuthTag(),c=Buffer.concat([n,s,i]);We(Ye(X),{recursive:!0}),Je(X,c,{mode:384})}getOrCreateKey(){if(ze($)){let t=Ge($);if(t.length!==Re)throw new Error(`Credential keyring key is corrupted (expected ${Re} bytes, got ${t.length}). Delete ${$} and re-authenticate.`);return t}let e=qe(Re);return We(Ye($),{recursive:!0}),Je($,e,{mode:384}),e}};import{execFile as vn}from"child_process";import{promisify as Kn}from"util";var $n=Kn(vn),Qe=3e4,A=class{constructor(e){this.helperPath=e}helperPath;async get(e){let t=l(e);try{let o=(await this.runHelper("get",{publisher:t})).trim();return o?JSON.parse(o):null}catch(n){throw new Error(`Credential helper '${this.helperPath}' failed to read credential for '${t}': ${Q(n)}
92
92
  Verify the helper binary exists, is executable, and implements the Kanonak credential helper protocol.
93
- Check the 'credentialHelper' path in ~/.kanonak/config.json.`)}}async store(e,t){let r=l(e);try{await this.runHelper("store",{publisher:r,credential:t})}catch(o){throw new Error(`Credential helper '${this.helperPath}' failed to store credential for '${r}': ${ae(o)}
94
- Verify the helper binary supports the 'store' action.`)}}async remove(e){let t=l(e);try{await this.runHelper("erase",{publisher:t})}catch(r){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${t}': ${ae(r)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${ae(e)}`),[]}}async runHelper(e,t){try{let{stdout:r}=await Nr(this.helperPath,[e],{...t&&{input:JSON.stringify(t)},timeout:rt});return r}catch(r){throw Dr(r)?new Error(`Credential helper not found at '${this.helperPath}'.
95
- Check the 'credentialHelper' path in ~/.kanonak/config.json.`):Tr(r)?new Error(`Credential helper '${this.helperPath}' timed out after ${rt/1e3}s on '${e}'.
96
- The helper may be waiting for authentication to an external vault.`):r}}};function ae(n){return n instanceof Error?n.message:String(n)}function Dr(n){return n instanceof Error&&"code"in n&&n.code==="ENOENT"}function Tr(n){return n instanceof Error&&"killed"in n&&n.killed}var Ke=Fr(Ur(),".kanonak","config.json"),ie=class{backend=null;backendReady=null;async getBackend(){if(this.backend)return this.backend;if(this.backendReady)return this.backendReady;this.backendReady=this.resolveBackend();try{return this.backend=await this.backendReady,this.backend}catch(e){throw this.backendReady=null,e}}async getToken(e){let t=Mr(e);if(t)return t;let o=await(await this.getBackend()).get(e);return!o||!J(o)?null:o.accessToken??null}async getCredential(e){return(await this.getBackend()).get(e)}async store(e,t){return(await this.getBackend()).store(e,t)}async remove(e){return(await this.getBackend()).remove(e)}async list(){return(await this.getBackend()).list()}async resolveBackend(){let e=Hr();return e.credentialHelper?new T(e.credentialHelper):process.platform==="darwin"?new V:process.platform==="win32"?new B:await Ee()?new O:new D}};function Mr(n){let t="KANONAK_TOKEN_"+l(n).replace(/[.\-]/g,"_").toUpperCase();return process.env[t]??null}function Hr(){if(!_r(Ke))return{};try{return JSON.parse(Lr(Ke,"utf-8"))}catch(n){let e=n instanceof Error?n.message:String(n);return console.warn(` Warning: Failed to parse ${Ke}: ${e}
97
- Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as zr,createPrivateKey as Wr,generateKeyPairSync as Gr,randomUUID as Jr,sign as qr}from"crypto";function at(){let{publicKey:n,privateKey:e}=Gr("ec",{namedCurve:"P-256"});return{publicKey:n.export({format:"jwk"}),privateKey:e.export({format:"jwk"})}}function _(n,e,t,r,o,a){let i={alg:"ES256",typ:"dpop+jwt",jwk:{kty:e.kty,crv:e.crv,x:e.x,y:e.y}},s={jti:Jr(),htm:t.toUpperCase(),htu:r,iat:Math.floor(Date.now()/1e3)};return o&&(s.ath=zr("sha256").update(o).digest("base64url")),a&&(s.nonce=a),Yr(i,s,n)}function it(n){return!n||n.length===0?!1:n.some(e=>e.toUpperCase()==="ES256")}function Yr(n,e,t){let r=ot(JSON.stringify(n)),o=ot(JSON.stringify(e)),a=`${r}.${o}`,i=Wr({key:t,format:"jwk"}),c=qr("SHA256",Buffer.from(a),{key:i,dsaEncoding:"ieee-p1363"}).toString("base64url");return`${a}.${c}`}function ot(n){return Buffer.from(n,"utf-8").toString("base64url")}function st(n){let e=new Map;return async(t,r,o="GET")=>{if(!n)return b(t,{method:o});let a=await n.getCredential(r);if(!a?.accessToken)return b(t,{method:o});G(a)&&console.warn(` Warning: Access token for '${r}' is expired. Run 'kanonak login ${r}' to re-authenticate.`);let i={};if(a.dpopKeyPair){let c=e.get(r);try{let u=_(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,t,a.accessToken,c);i.Authorization=`DPoP ${a.accessToken}`,i.DPoP=u}catch(u){let d=u instanceof Error?u.message:String(u);console.error(` Error: Failed to create DPoP proof for '${r}': ${d}
98
- The stored key pair may be corrupted. Run 'kanonak login ${r}' to re-authenticate.`),i.Authorization=`Bearer ${a.accessToken}`}}else i.Authorization=`Bearer ${a.accessToken}`;let s=await b(t,{method:o,headers:i});if(s.status===401&&a.dpopKeyPair){let c=s.headers.get("DPoP-Nonce");if(c){e.set(r,c);try{let u=_(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,t,a.accessToken,c);i.DPoP=u,s=await b(t,{method:o,headers:i})}catch{}}}return s}}import{readFileSync as Zr,writeFileSync as Xr,existsSync as Qr}from"fs";import{createHash as eo}from"crypto";import ct from"js-yaml";var lt="kanonak.lock",to=`# This file is generated by Kanonak CLI. Do not edit manually.
99
- `;function ut(n=lt){if(!Qr(n))return null;let e=Zr(n,"utf-8"),t=ct.load(e);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??new Date().toISOString(),packages:t.packages??{}}}function pt(n,e=lt){n.lastUpdated=new Date().toISOString();let t={};for(let o of Object.keys(n.packages).sort())t[o]=n.packages[o];n.packages=t;let r=ct.dump(n,{lineWidth:-1,sortKeys:!1,quotingType:'"'});Xr(e,to+r,"utf-8")}function dt(n){return`sha256:${eo("sha256").update(n).digest("hex")}`}import*as Be from"js-yaml";import{createHash as ro}from"crypto";function $e(n){return typeof n=="object"&&n!==null&&Array.isArray(n.subjects)}function je(n){return n.subjects.map(e=>{let t=new f,r=e.uri.lastIndexOf("/");return t.namespace=e.uri.slice(0,r),t.name=e.uri.slice(r+1),t.statement=(e.statements??[]).map(o=>ft(o.predicate,o.value)),t})}function mt(n,e,t){let r=new E;return r.predicate=p.parse(n),r.object=t,e&&(r.carrier=e,r.lexical=t),r}function ft(n,e){if("lit"in e)return mt(n,K(z.parse(e.datatype)),e.lit);if("raw"in e)return mt(n,void 0,e.raw);if("ref"in e){let t=new x;return t.predicate=p.parse(n),t.object=p.parse(e.ref),t}if("embed"in e){let t=new I;return t.predicate=p.parse(n),t.object=yt(e.embed),t}if("list"in e){let t=new v;return t.predicate=p.parse(n),t.object=e.list.map(no),t}throw new Error(`canonical input: unknown value shape ${JSON.stringify(e)}`)}function yt(n){let e=new y;return n.name&&(e.name=n.name),e.statement=(n.statements??[]).map(t=>ft(t.predicate,t.value)),e}function no(n){if("ref"in n)return p.parse(n.ref);if("embed"in n)return yt(n.embed);let e=new R;if("lit"in n){e.value=n.lit;let t=K(z.parse(n.datatype));t&&(e.carrier=t,e.lexical=n.lit)}else if("raw"in n)e.value=n.raw;else throw new Error(`canonical input: unknown list item shape ${JSON.stringify(n)}`);return e}var kt="1",gt=new TextEncoder;function ht(n,e){let t=gt.encode(n),r=gt.encode(e),o=Math.min(t.length,r.length);for(let a=0;a<o;a++)if(t[a]!==r[a])return t[a]-r[a];return t.length-r.length}function Ae(n){let e=$e(n)?je(n):n,t=[];for(let o of e)o instanceof f&&t.push(oo(o));return t.sort((o,a)=>ht(o.uri,a.uri)),JSON.stringify({subjects:t})}function se(n){let e=$e(n)?je(n):n,t=Ae(e);return`sha256:${ro("sha256").update(t,"utf8").digest("hex")}`}function oo(n){let e=uo(n),t=Ve(n.statement);return{uri:e,statements:t}}function Ve(n){let e=[];for(let t of n){let r=ao(t);r&&e.push(r)}return e.sort((t,r)=>ht(t.predicate,r.predicate)),e}function ao(n){let e=lo(n);if(!e)return;let t=io(n);if(t)return co(e,t)}function io(n){if(n instanceof ge&&n.carrier)return{type:"typed",carrier:n.carrier,value:be(n.carrier,n.lexical??String(n.object))};if(n instanceof E)return{type:"string",value:n.object};if(n instanceof ke)return{type:"number",value:St(n.object)};if(n instanceof he)return{type:"boolean",value:n.object};if(n instanceof x)return{type:"ref",value:Pt(n.object)};if(n instanceof I){let e=n.object;return bt(e)}if(n instanceof v)return{type:"list",items:n.object.map(so)}}function bt(n){let e=Ve(n.statement);return n.name&&n.name.length>0?{type:"embedded",name:n.name,statements:e}:{type:"embedded",statements:e}}function so(n){if(n instanceof p)return{type:"ref",value:Pt(n)};if(n instanceof y)return bt(n);if(n instanceof R){if(n.carrier)return{type:"typed",carrier:n.carrier,value:be(n.carrier,n.lexical??String(n.value))};let e=n.value;if(typeof e=="string")return{type:"string",value:e};if(typeof e=="number")return{type:"number",value:St(e)};if(typeof e=="boolean")return{type:"boolean",value:e}}if(n instanceof ye)return{type:"embedded",statements:Ve(n.statement)};throw new Error(`canonicalForm: list item of unrecognized kind (${n.constructor?.name??typeof n}); add canonicalization support before hashing data that contains it`)}function co(n,e){switch(e.type){case"string":return{predicate:n,type:"string",value:e.value};case"number":return{predicate:n,type:"number",value:e.value};case"boolean":return{predicate:n,type:"boolean",value:e.value};case"typed":return{predicate:n,type:"typed",carrier:e.carrier,value:e.value};case"ref":return{predicate:n,type:"ref",value:e.value};case"embedded":return e.name!==void 0?{predicate:n,type:"embedded",name:e.name,statements:e.statements}:{predicate:n,type:"embedded",statements:e.statements};case"list":return{predicate:n,type:"list",items:e.items}}}function lo(n){let e=n.predicate;if(e)return wt(e.subject)}function uo(n){let e=n.namespace??"",t=n.name??"";return`${e}/${t}`}function Pt(n){return wt(n.subject)}function wt(n){let e=n.version;return e&&typeof e.major=="number"?`${n.publisher}/${n.package_}@${e.major}.${e.minor}.${e.patch}/${n.name}`:`${n.publisher}/${n.package_}/${n.name}`}function St(n){if(Number.isNaN(n))throw new Error("canonicalForm: NaN cannot be canonicalized");if(!Number.isFinite(n))throw new Error("canonicalForm: \xB1Infinity cannot be canonicalized");return Object.is(n,-0)?"0":String(n)}import{VersionOperator as Ct}from"@kanonak-protocol/types/document/models/enums";var po="0.0.0",w=class{constructor(e,t=new C,r){this.repository=e;this.parser=t;this.objectParser=r??new j(this.parser)}repository;parser;objectParser;imports(){return new L}serializeValue(e,t){return xt(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),r=await this.hashBody(e.publisher,t,e.body),o=Oe(r),a={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(a[e.contentHashProperty]=r),Object.assign(a,e.header??{}),a.imports=t;let i={[o]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:Et(s),contentHash:r,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),r={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),r[e.contentHashProperty]=o),Object.assign(r,e.header??{}),r.imports=t;let a={[e.name]:r,...e.body},i=this.dump(a),s={yaml:i,byteCount:Et(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return Be.dump(e,{lineWidth:-1})}async hashBody(e,t,r){let o={[Rt]:{type:"EphemeralPackage",publisher:e,imports:t},...r},a=this.parser.parse(Be.dump(o,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new He(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==Rt);for(let u of c)u.namespace="ephemeral";return se(c)}},Rt="__pkgbuilder_probe__";function Et(n){return new TextEncoder().encode(n).length}function Oe(n){let e="sha256:",t=n.startsWith(e)?e.length:0;return`q-${n.slice(t,t+16)}`}var L=class{byKey=new Map;aliases=new Set;ensure(e,t,r,o,a=Ct.Major){let i=`${e}/${t}@${r}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(i,{publisher:e,package_:t,version:r,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,h(e.version),e.package_)}.${e.name}`}refLatest(e,t,r,o){return`${this.ensure(e,t,po,o??t,Ct.Any)}.${r}`}toImports(){let e=new Map;for(let r of this.byKey.values()){let o=e.get(r.publisher)??[];o.push(r),e.set(r.publisher,o)}return[...e.keys()].sort().map(r=>({publisher:r,packages:e.get(r).sort((o,a)=>o.package_<a.package_?-1:1).map(o=>({package:o.package_,match:fe(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=U(e)||"pkg",r=t,o=2;for(;this.aliases.has(r);)r=`${t}${o++}`;return this.aliases.add(r),r}};function xt(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof p)return e.ref(n.subject);if(Array.isArray(n)){let t=n.map(r=>xt(r,e)).filter(r=>r!==void 0);return t.length>0?t:void 0}if(n instanceof y)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(mo(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 U(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function mo(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var ce=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(r=>r.canProduce(e,t))}async produceCached(e,t,r,o){let a=`${t}/${r}@${h(o)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(t,r,o);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,t){let r=this.producerFor(e,t.packageName);if(!r)return null;let o={operator:t.versionOperator,version:t.version},a=await r.resolveVersion(e,t.packageName,o);return a?this.produceCached(r,e,t.packageName,a):null}async getDocumentAsync(e){let t;try{t=we(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let r=this.producerFor(t.publisher,t.package_);return r?this.produceCached(r,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(r=>{let o=r.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var Ne={async authorize(){return{allowed:!0}}},De={async record(){}},F=class extends Error{constructor(t,r){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${r?`: ${r}`:""}`);this.address=t;this.reason=r;this.name="EntitlementDeniedError"}address;reason},le=class{inner;ctx;policy;meter;constructor(e,t,r=Ne,o=De){this.inner=e,this.ctx=t,this.policy=r,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,r){return await this.assertAllowed({publisher:e,package_:t,version:r.version}),this.inner.resolveVersion(e,t,r)}async produce(e,t,r){let o={publisher:e,package_:t,version:r};await this.assertAllowed(o);let a=await this.inner.produce(e,t,r);return await this.meter.record(this.ctx,o,a),a}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new F(e,t.reason)}};var m="kanonak.org",g="view",It="core-kanonak",fo={publisher:m,package_:g,name:"rootView"},yo={publisher:m,package_:g,name:"bind"},go={publisher:m,package_:g,name:"produces"},ko={publisher:m,package_:g,name:"projections"},ho={publisher:m,package_:g,name:"where"},bo={publisher:m,package_:g,name:"value"},Po={publisher:m,package_:g,name:"as"},ue=class{constructor(e,t=new C){this.repository=e;this.parser=t;this.objectParser=new j(this.parser),this.builder=new w(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,t={}){let r=await this.objectParser.parseKanonaks(this.repository),o=this.resolveView(r,e),a=A(o,yo);if(!a)throw new Error(`View ${o.namespace}/${o.name} declares no view.bind; cannot materialize.`);let i=A(o,go);if(!i)throw new Error(`View ${o.namespace}/${o.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 s=wo(o),c=vt(r,m,It),u=vt(r,m,g),d=this.builder.imports(),pe=d.ensure(m,It,c,"ck"),$t=d.ensure(m,g,u,"v"),jt=d.ref(i),At=new Ge(this.repository,this.parser,this.objectParser),Te=new ze(At,r),Vt=this.readProjections(r,o),Bt=Ro(o,ho),Ot=this.findInstances(r,a,await this.reason(t)),_e={},Nt=new Set;for(let M of Ot){if(!await this.passesWhere(Te,r,Bt,M))continue;let me={type:jt};for(let Ue of Vt){let Dt=await this.evaluateValue(Te,r,Ue.value,M),Fe=this.builder.serializeValue(Kt(Dt),d);Fe!==void 0&&(me[d.ref(Ue.as)]=Fe)}let Le=k(M);Le&&(me[`${$t}.derivedFrom`]=d.ref(Le)),_e[this.rowName(M,Nt)]=me}let de={};t.resolvedAt&&(de[`${pe}.resolvedAt`]=t.resolvedAt),t.invocationId&&(de[`${pe}.id`]=t.invocationId);let S=await this.builder.buildContentAddressed({publisher:s,book:d,body:_e,contentHashProperty:`${pe}.contentHash`,header:de});return{yaml:S.yaml,contentHash:S.contentHash,packageName:S.packageName,publisher:S.publisher,rowCount:S.resourceCount}}resolveView(e,t){let r=W(e,t);if(!r)throw new Error(`View ${t.publisher}/${t.package_}/${t.name} not found in the catalog.`);let o=A(r,fo);if(o){let a=W(e,o);if(!a)throw new Error(`ViewPackage ${t.name} names rootView ${o.name}, which is not in the catalog.`);return a}return r}readProjections(e,t){let r=[];for(let o of Ce(t,ko)){let a=o instanceof y?o:o instanceof p?W(e,o.subject):void 0;if(!a)continue;let i=Se(a,bo),s=A(a,Po);i&&s&&r.push({value:i,as:s})}return r}async reason(e){return new Pe({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,t,r){let o=Co(e),a=[],i=new Set;for(let s of r.getInstancesOfClass(t)){if(i.has(s))continue;i.add(s);let c=o.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=$(k(s)),d=$(k(c));return u<d?-1:u>d?1:0}),a}async passesWhere(e,t,r,o){for(let a of r){let i=await this.evaluateValue(e,t,a,o);if(!Eo(i))return!1}return!0}async evaluateValue(e,t,r,o){let a=We(r,"view-projection",{catalog:t,depth:0}),i=new Map([["input",o]]);return e.evaluate(a,i)}rowName(e,t){let r=U(e.name)||"row",o=r,a=2;for(;t.has(o);)o=`${r}-${a++}`;return t.add(o),o}};function Kt(n){return Re(n)?n.value:Array.isArray(n)?n.map(Kt):n}function wo(n){let e=k(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function vt(n,e,t){let r=So(n,e,t);if(!r)throw new Error(`Package ${e}/${t} is not in the catalog; it must be importable to materialize a view.`);return r}function So(n,e,t){let r;for(let o of n){if(!(o instanceof f))continue;let a=k(o);!a||a.publisher!==e||a.package_!==t||!a.version||(!r||H(a.version,r)>0)&&(r=a.version)}return r?h(r):void 0}function Co(n){let e=new Map,t=new Map;for(let r of n){if(!(r instanceof f))continue;let o=k(r);if(!o||!o.version)continue;let a=$(o),i=t.get(a);(!i||H(o.version,i)>0)&&(t.set(a,o.version),e.set(a,r))}return e}function Ro(n,e){let t=Se(n,e);return t?[t]:Ce(n,e).filter(r=>r instanceof y)}function Eo(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:Re(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{lr as AmbiguousReferenceRule,he as BooleanStatement,kt as CANONICAL_FORM_VERSION,Me as Carrier,yr as ClassDefinitionRule,er as ClassHierarchyCycleRule,Jt as CompositeKanonakDocumentRepository,ie as CredentialStore,ye as DefinedKanonak,sr as DefinitionPropertyReferenceRule,Gt as DocumentLocation,Sn as EdgeType,y as EmbeddedKanonak,Zn as EmbeddedKanonakTypeRule,I as EmbeddedStatement,F as EntitlementDeniedError,le as EntitlementProducer,Wt as FileSystemKanonakDocumentRepository,vn as GitIgnoreFilter,Cn as GraphBuilder,rn as HttpKanonakDocumentRepository,L as ImportBook,Xn as ImportExistenceRule,zt as InMemoryKanonakDocumentRepository,ir as InstancePropertyReferenceRule,Zt as KANONAK_USER_AGENT,ln as Kanonak,$n as KanonakDocumentPositions,j as KanonakObjectParser,kr as KanonakObjectValidator,C as KanonakParser,z as KanonakUri,Vn as KanonakUriBuilder,On as KanonakUrlResolver,kn as KanonakVocabulary,v as ListStatement,R as LiteralKanonak,on as LocalFirstRepository,an as LockAwareRepository,Pr as LookRenderer,gr as MarkdownLinkRule,pn as MarkdownStatement,ar as NamespaceImportCycleRule,Wn as NamespacePrefixRule,wn as NodeType,ke as NumberStatement,xn as OWL_RL_CLASSIFICATION_RULES,pr as ObjectPropertyImportRule,dr as ObjectPropertyValueValidationRule,Mn as OntologyValidationError,Un as OntologyValidationResult,w as PackageBuilder,Yn as PackageHeaderRule,ce as ProducerRepository,mr as PropertyDomainRule,tr as PropertyHierarchyCycleRule,Kn as PropertyMetadata,ur as PropertyRangeReferenceRule,nr as PropertyRangeRequiredRule,Jn as PropertyTypeSpecificityRule,fr as PropertyValueTypeRule,en as PublisherConfigResolver,tn as PublisherIndex,En as RDFS_RULES,Pe as Reasoner,In as ReasoningResult,p as ReferenceKanonak,x as ReferenceStatement,Yt as RepositoryFactory,Gn as ResourceNamingRule,dn as ResourceResolver,Pn as ResourceTypeClassifier,ge as ScalarStatement,un as Statement,E as StringStatement,rr as SubClassOfReferenceRule,or as SubPropertyOfReferenceRule,f as SubjectKanonak,qn as SubjectKanonakTypeRequiredRule,Rn as TripleStore,mn as TypeResolver,Qn as UnresolvedReferenceRule,zn as ValidationCache,Hn as ValidationContext,Fn as ValidationSeverity,Fi as VersionOperator,ue as ViewMaterializer,cr as XsdImportRule,Ne as allowAllPolicy,nn as assertPackageIdentity,cn as buildLocalFirstRepository,wr as buildOntologyModel,Ae as canonicalForm,se as canonicalHash,K as carrierOf,sn as collectKanonakFiles,H as compareVersions,dt as computeIntegrity,Oe as contentAddressedName,_n as contextTypesOf,st as createAuthenticatedFetch,_ as createDPoPProof,Lt as createVersion,bn as extractMarkdownLinks,hr as findDerivation,Ln as findInstancesByType,hn as findMalformedReferences,An as findMarkdownLinkAt,Bn as formatKanonakAddress,h as formatVersion,at as generateDPoPKeyPair,qt as getGlobalCachePath,Qt as getKanonakUserAgent,J as hasValidToken,Ft as isCompatibleVersion,G as isExpired,Mt as isMajorCompatible,b as kanonakFetch,ut as loadLockFile,fn as makeUriKey,De as noopMeter,l as normalizeHost,we as parseKanonakAddress,Ut as parseVersionString,jn as parseWithPositions,Ht as pickHighestDocument,Dn as propertiesInScope,br as resolveDisplayValue,Tn as resolvePropertyStep,U as sanitizeName,pt as saveLockFile,it as serverSupportsDPoP,Xt as setKanonakUserAgent,k as subjectUri,Nn as superClassChain,yn as tripleKey,$ as uriKey,gn as uriTriple,Tt as versionOperatorFromChar,fe as versionOperatorToChar,_t as versionsEqual};
93
+ Check the 'credentialHelper' path in ~/.kanonak/config.json.`)}}async store(e,t){let n=l(e);try{await this.runHelper("store",{publisher:n,credential:t})}catch(o){throw new Error(`Credential helper '${this.helperPath}' failed to store credential for '${n}': ${Q(o)}
94
+ Verify the helper binary supports the 'store' action.`)}}async remove(e){let t=l(e);try{await this.runHelper("erase",{publisher:t})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${t}': ${Q(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${Q(e)}`),[]}}async runHelper(e,t){try{let{stdout:n}=await $n(this.helperPath,[e],{...t&&{input:JSON.stringify(t)},timeout:Qe});return n}catch(n){throw jn(n)?new Error(`Credential helper not found at '${this.helperPath}'.
95
+ Check the 'credentialHelper' path in ~/.kanonak/config.json.`):An(n)?new Error(`Credential helper '${this.helperPath}' timed out after ${Qe/1e3}s on '${e}'.
96
+ The helper may be waiting for authentication to an external vault.`):n}}};function Q(r){return r instanceof Error?r.message:String(r)}function jn(r){return r instanceof Error&&"code"in r&&r.code==="ENOENT"}function An(r){return r instanceof Error&&"killed"in r&&r.killed}var Ie=Tn(Dn(),".kanonak","config.json"),ee=class{backend=null;backendReady=null;async getBackend(){if(this.backend)return this.backend;if(this.backendReady)return this.backendReady;this.backendReady=this.resolveBackend();try{return this.backend=await this.backendReady,this.backend}catch(e){throw this.backendReady=null,e}}async getToken(e){let t=Nn(e);if(t)return t;let o=await(await this.getBackend()).get(e);return!o||!F(o)?null:o.accessToken??null}async getCredential(e){return(await this.getBackend()).get(e)}async store(e,t){return(await this.getBackend()).store(e,t)}async remove(e){return(await this.getBackend()).remove(e)}async list(){return(await this.getBackend()).list()}async resolveBackend(){let e=Bn();return e.credentialHelper?new A(e.credentialHelper):process.platform==="darwin"?new I:process.platform==="win32"?new v:await Se()?new K:new j}};function Nn(r){let t="KANONAK_TOKEN_"+l(r).replace(/[.\-]/g,"_").toUpperCase();return process.env[t]??null}function Bn(){if(!Vn(Ie))return{};try{return JSON.parse(On(Ie,"utf-8"))}catch(r){let e=r instanceof Error?r.message:String(r);return console.warn(` Warning: Failed to parse ${Ie}: ${e}
97
+ Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as Un,createPrivateKey as _n,generateKeyPairSync as Ln,randomUUID as Fn,sign as Mn}from"crypto";function tt(){let{publicKey:r,privateKey:e}=Ln("ec",{namedCurve:"P-256"});return{publicKey:r.export({format:"jwk"}),privateKey:e.export({format:"jwk"})}}function V(r,e,t,n,o,a){let i={alg:"ES256",typ:"dpop+jwt",jwk:{kty:e.kty,crv:e.crv,x:e.x,y:e.y}},s={jti:Fn(),htm:t.toUpperCase(),htu:n,iat:Math.floor(Date.now()/1e3)};return o&&(s.ath=Un("sha256").update(o).digest("base64url")),a&&(s.nonce=a),Hn(i,s,r)}function rt(r){return!r||r.length===0?!1:r.some(e=>e.toUpperCase()==="ES256")}function Hn(r,e,t){let n=et(JSON.stringify(r)),o=et(JSON.stringify(e)),a=`${n}.${o}`,i=_n({key:t,format:"jwk"}),c=Mn("SHA256",Buffer.from(a),{key:i,dsaEncoding:"ieee-p1363"}).toString("base64url");return`${a}.${c}`}function et(r){return Buffer.from(r,"utf-8").toString("base64url")}function nt(r){let e=new Map;return async(t,n,o="GET")=>{if(!r)return b(t,{method:o});let a=await r.getCredential(n);if(!a?.accessToken)return b(t,{method:o});L(a)&&console.warn(` Warning: Access token for '${n}' is expired. Run 'kanonak login ${n}' to re-authenticate.`);let i={};if(a.dpopKeyPair){let c=e.get(n);try{let u=V(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,t,a.accessToken,c);i.Authorization=`DPoP ${a.accessToken}`,i.DPoP=u}catch(u){let p=u instanceof Error?u.message:String(u);console.error(` Error: Failed to create DPoP proof for '${n}': ${p}
98
+ The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),i.Authorization=`Bearer ${a.accessToken}`}}else i.Authorization=`Bearer ${a.accessToken}`;let s=await b(t,{method:o,headers:i});if(s.status===401&&a.dpopKeyPair){let c=s.headers.get("DPoP-Nonce");if(c){e.set(n,c);try{let u=V(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,t,a.accessToken,c);i.DPoP=u,s=await b(t,{method:o,headers:i})}catch{}}}return s}}import{readFileSync as zn,writeFileSync as Wn,existsSync as Gn}from"fs";import{createHash as Jn}from"crypto";import ot from"js-yaml";var at="kanonak.lock",qn=`# This file is generated by Kanonak CLI. Do not edit manually.
99
+ `;function it(r=at){if(!Gn(r))return null;let e=zn(r,"utf-8"),t=ot.load(e);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??new Date().toISOString(),packages:t.packages??{}}}function st(r,e=at){r.lastUpdated=new Date().toISOString();let t={};for(let o of Object.keys(r.packages).sort())t[o]=r.packages[o];r.packages=t;let n=ot.dump(r,{lineWidth:-1,sortKeys:!1,quotingType:'"'});Wn(e,qn+n,"utf-8")}function ct(r){return`sha256:${Jn("sha256").update(r).digest("hex")}`}import*as $e from"js-yaml";import{canonicalForm as Yn,canonicalHash as Zn}from"@kanonak-protocol/canonical";function ve(r){return typeof r=="object"&&r!==null&&Array.isArray(r.subjects)}import{CANONICAL_FORM_VERSION as yt}from"@kanonak-protocol/canonical";function lt(r){return Yn(ve(r)?r:ut(r))}function te(r){return Zn(ve(r)?r:ut(r))}function ut(r){let e=[];for(let t of r)t instanceof f&&e.push({uri:to(t),statements:Ke(t.statement)});return{subjects:e}}function Ke(r){let e=[];for(let t of r){let n=eo(t);if(!n)continue;let o=Xn(t);o&&e.push({predicate:n,value:o})}return e}function Xn(r){if(r instanceof pe&&r.carrier)return{lit:r.lexical??String(r.object),datatype:dt(r.carrier)};if(r instanceof de)return{raw:r.object};if(r instanceof me)return{raw:r.lexical??String(r.object)};if(r instanceof fe)return{raw:r.lexical??String(r.object)};if(r instanceof ye)return{ref:mt(r.object)};if(r instanceof ge)return pt(r.object);if(r instanceof ke)return{list:r.object.map(Qn)}}function pt(r){let e=Ke(r.statement);return r.name&&r.name.length>0?{embed:{name:r.name,statements:e}}:{embed:{statements:e}}}function Qn(r){if(r instanceof h)return{ref:mt(r)};if(r instanceof y)return pt(r);if(r instanceof ue){if(r.carrier)return{lit:r.lexical??String(r.value),datatype:dt(r.carrier)};let e=r.value;if(typeof e=="string")return{raw:e};if(typeof e=="number")return{raw:String(e)};if(typeof e=="boolean")return{raw:String(e)}}if(r instanceof le)return{embed:{statements:Ke(r.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${r.constructor?.name??typeof r}); add canonicalization support before hashing data that contains it`)}function dt(r){return r===U.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${r}`}function eo(r){let e=r.predicate;if(e)return ft(e.subject)}function to(r){let e=r.namespace??"",t=r.name??"";return`${e}/${t}`}function mt(r){return ft(r.subject)}function ft(r){let e=r.version;return e&&typeof e.major=="number"?`${r.publisher}/${r.package_}@${e.major}.${e.minor}.${e.patch}/${r.name}`:`${r.publisher}/${r.package_}/${r.name}`}import{VersionOperator as gt}from"@kanonak-protocol/types/document/models/enums";var ro="0.0.0",w=class{constructor(e,t=new S,n){this.repository=e;this.parser=t;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new O}serializeValue(e,t){return bt(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),n=await this.hashBody(e.publisher,t,e.body),o=je(n),a={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(a[e.contentHashProperty]=n),Object.assign(a,e.header??{}),a.imports=t;let i={[o]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:ht(s),contentHash:n,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),n[e.contentHashProperty]=o),Object.assign(n,e.header??{}),n.imports=t;let a={[e.name]:n,...e.body},i=this.dump(a),s={yaml:i,byteCount:ht(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return $e.dump(e,{lineWidth:-1})}async hashBody(e,t,n){let o={[kt]:{type:"EphemeralPackage",publisher:e,imports:t},...n},a=this.parser.parse($e.dump(o,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new _e(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==kt);for(let u of c)u.namespace="ephemeral";return te(c)}},kt="__pkgbuilder_probe__";function ht(r){return new TextEncoder().encode(r).length}function je(r){let e="sha256:",t=r.startsWith(e)?e.length:0;return`q-${r.slice(t,t+16)}`}var O=class{byKey=new Map;aliases=new Set;ensure(e,t,n,o,a=gt.Major){let i=`${e}/${t}@${n}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(i,{publisher:e,package_:t,version:n,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,k(e.version),e.package_)}.${e.name}`}refLatest(e,t,n,o){return`${this.ensure(e,t,ro,o??t,gt.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let o=e.get(n.publisher)??[];o.push(n),e.set(n.publisher,o)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((o,a)=>o.package_<a.package_?-1:1).map(o=>({package:o.package_,match:ce(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=D(e)||"pkg",n=t,o=2;for(;this.aliases.has(n);)n=`${t}${o++}`;return this.aliases.add(n),n}};function bt(r,e){if(r!=null){if(typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r instanceof h)return e.ref(r.subject);if(Array.isArray(r)){let t=r.map(n=>bt(n,e)).filter(n=>n!==void 0);return t.length>0?t:void 0}if(r instanceof y)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(no(r))throw new Error(`Value produced a bare URI without a version (${r.publisher}/${r.package_}/${r.name}); cannot serialize it as a reference.`)}}function D(r){return r.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function no(r){return typeof r=="object"&&r!==null&&typeof r.publisher=="string"&&typeof r.package_=="string"&&typeof r.name=="string"}var re=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(n=>n.canProduce(e,t))}async produceCached(e,t,n,o){let a=`${t}/${n}@${k(o)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(t,n,o);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,t){let n=this.producerFor(e,t.packageName);if(!n)return null;let o={operator:t.versionOperator,version:t.version},a=await n.resolveVersion(e,t.packageName,o);return a?this.produceCached(n,e,t.packageName,a):null}async getDocumentAsync(e){let t;try{t=be(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let n=this.producerFor(t.publisher,t.package_);return n?this.produceCached(n,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(n=>{let o=n.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,t){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var Ae={async authorize(){return{allowed:!0}}},Ve={async record(){}},T=class extends Error{constructor(t,n){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${n?`: ${n}`:""}`);this.address=t;this.reason=n;this.name="EntitlementDeniedError"}address;reason},ne=class{inner;ctx;policy;meter;constructor(e,t,n=Ae,o=Ve){this.inner=e,this.ctx=t,this.policy=n,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,n){return await this.assertAllowed({publisher:e,package_:t,version:n.version}),this.inner.resolveVersion(e,t,n)}async produce(e,t,n){let o={publisher:e,package_:t,version:n};await this.assertAllowed(o);let a=await this.inner.produce(e,t,n);return await this.meter.record(this.ctx,o,a),a}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new T(e,t.reason)}};var d="kanonak.org",m="view",Pt="core-kanonak",oo={publisher:d,package_:m,name:"rootView"},ao={publisher:d,package_:m,name:"bind"},io={publisher:d,package_:m,name:"produces"},so={publisher:d,package_:m,name:"projections"},co={publisher:d,package_:m,name:"where"},lo={publisher:d,package_:m,name:"value"},uo={publisher:d,package_:m,name:"as"},oe=class{constructor(e,t=new S){this.repository=e;this.parser=t;this.objectParser=new E(this.parser),this.builder=new w(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,t={}){let n=await this.objectParser.parseKanonaks(this.repository),o=this.resolveView(n,e),a=x(o,ao);if(!a)throw new Error(`View ${o.namespace}/${o.name} declares no view.bind; cannot materialize.`);let i=x(o,io);if(!i)throw new Error(`View ${o.namespace}/${o.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 s=po(o),c=wt(n,d,Pt),u=wt(n,d,m),p=this.builder.imports(),ae=p.ensure(d,Pt,c,"ck"),St=p.ensure(d,m,u,"v"),Rt=p.ref(i),Et=new Me(this.repository,this.parser,this.objectParser),Oe=new Le(Et,n),xt=this.readProjections(n,o),It=yo(o,co),vt=this.findInstances(n,a,await this.reason(t)),De={},Kt=new Set;for(let N of vt){if(!await this.passesWhere(Oe,n,It,N))continue;let se={type:Rt};for(let Ne of xt){let $t=await this.evaluateValue(Oe,n,Ne.value,N),Be=this.builder.serializeValue(Ct($t),p);Be!==void 0&&(se[p.ref(Ne.as)]=Be)}let Te=g(N);Te&&(se[`${St}.derivedFrom`]=p.ref(Te)),De[this.rowName(N,Kt)]=se}let ie={};t.resolvedAt&&(ie[`${ae}.resolvedAt`]=t.resolvedAt),t.invocationId&&(ie[`${ae}.id`]=t.invocationId);let C=await this.builder.buildContentAddressed({publisher:s,book:p,body:De,contentHashProperty:`${ae}.contentHash`,header:ie});return{yaml:C.yaml,contentHash:C.contentHash,packageName:C.packageName,publisher:C.publisher,rowCount:C.resourceCount}}resolveView(e,t){let n=_(e,t);if(!n)throw new Error(`View ${t.publisher}/${t.package_}/${t.name} not found in the catalog.`);let o=x(n,oo);if(o){let a=_(e,o);if(!a)throw new Error(`ViewPackage ${t.name} names rootView ${o.name}, which is not in the catalog.`);return a}return n}readProjections(e,t){let n=[];for(let o of we(t,so)){let a=o instanceof y?o:o instanceof h?_(e,o.subject):void 0;if(!a)continue;let i=Pe(a,lo),s=x(a,uo);i&&s&&n.push({value:i,as:s})}return n}async reason(e){return new he({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,t,n){let o=fo(e),a=[],i=new Set;for(let s of n.getInstancesOfClass(t)){if(i.has(s))continue;i.add(s);let c=o.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=R(g(s)),p=R(g(c));return u<p?-1:u>p?1:0}),a}async passesWhere(e,t,n,o){for(let a of n){let i=await this.evaluateValue(e,t,a,o);if(!go(i))return!1}return!0}async evaluateValue(e,t,n,o){let a=Fe(n,"view-projection",{catalog:t,depth:0}),i=new Map([["input",o]]);return e.evaluate(a,i)}rowName(e,t){let n=D(e.name)||"row",o=n,a=2;for(;t.has(o);)o=`${n}-${a++}`;return t.add(o),o}};function Ct(r){return Ce(r)?r.value:Array.isArray(r)?r.map(Ct):r}function po(r){let e=g(r);if(!e)throw new Error(`Could not derive a publisher from view ${r.namespace}/${r.name}.`);return e.publisher}function wt(r,e,t){let n=mo(r,e,t);if(!n)throw new Error(`Package ${e}/${t} is not in the catalog; it must be importable to materialize a view.`);return n}function mo(r,e,t){let n;for(let o of r){if(!(o instanceof f))continue;let a=g(o);!a||a.publisher!==e||a.package_!==t||!a.version||(!n||B(a.version,n)>0)&&(n=a.version)}return n?k(n):void 0}function fo(r){let e=new Map,t=new Map;for(let n of r){if(!(n instanceof f))continue;let o=g(n);if(!o||!o.version)continue;let a=R(o),i=t.get(a);(!i||B(o.version,i)>0)&&(t.set(a,o.version),e.set(a,n))}return e}function yo(r,e){let t=Pe(r,e);return t?[t]:we(r,e).filter(n=>n instanceof y)}function go(r){return r===!0?!0:r===!1||r===void 0||r===null?!1:typeof r=="string"?r.length>0:typeof r=="number"?r!==0:Ce(r)?r.value.length>0:Array.isArray(r)?r.length>0:!!r}export{rn as AmbiguousReferenceRule,fe as BooleanStatement,yt as CANONICAL_FORM_VERSION,U as Carrier,ln as ClassDefinitionRule,Gr as ClassHierarchyCycleRule,Lt as CompositeKanonakDocumentRepository,ee as CredentialStore,le as DefinedKanonak,en as DefinitionPropertyReferenceRule,_t as DocumentLocation,yr as EdgeType,y as EmbeddedKanonak,Hr as EmbeddedKanonakTypeRule,ge as EmbeddedStatement,T as EntitlementDeniedError,ne as EntitlementProducer,Ut as FileSystemKanonakDocumentRepository,wr as GitIgnoreFilter,gr as GraphBuilder,Yt as HttpKanonakDocumentRepository,O as ImportBook,zr as ImportExistenceRule,Bt as InMemoryKanonakDocumentRepository,Ht as KANONAK_USER_AGENT,tr as Kanonak,Sr as KanonakDocumentPositions,E as KanonakObjectParser,pn as KanonakObjectValidator,S as KanonakParser,rr as KanonakUri,xr as KanonakUriBuilder,vr as KanonakUrlResolver,ur as KanonakVocabulary,ke as ListStatement,ue as LiteralKanonak,Zt as LocalFirstRepository,Xt as LockAwareRepository,fn as LookRenderer,un as MarkdownLinkRule,or as MarkdownStatement,Xr as NamespaceImportCycleRule,Ur as NamespacePrefixRule,fr as NodeType,me as NumberStatement,br as OWL_RL_CLASSIFICATION_RULES,on as ObjectPropertyImportRule,an as ObjectPropertyValueValidationRule,Tr as OntologyValidationError,Or as OntologyValidationResult,w as PackageBuilder,Mr as PackageHeaderRule,re as ProducerRepository,sn as PropertyDomainRule,Jr as PropertyHierarchyCycleRule,Cr as PropertyMetadata,nn as PropertyRangeReferenceRule,qr as PropertyRangeRequiredRule,Lr as PropertyTypeSpecificityRule,cn as PropertyValueTypeRule,Gt as PublisherConfigResolver,Jt as PublisherIndex,hr as RDFS_RULES,he as Reasoner,Pr as ReasoningResult,h as ReferenceKanonak,ye as ReferenceStatement,Mt as RepositoryFactory,_r as ResourceNamingRule,ar as ResourceResolver,mr as ResourceTypeClassifier,pe as ScalarStatement,nr as Statement,de as StringStatement,Yr as SubClassOfReferenceRule,Zr as SubPropertyOfReferenceRule,f as SubjectKanonak,Fr as SubjectKanonakTypeRequiredRule,kr as TripleStore,ir as TypeResolver,Qr as UnresolvedPredicateRule,Wr as UnresolvedReferenceRule,Br as ValidationCache,Nr as ValidationContext,Dr as ValidationSeverity,Si as VersionOperator,oe as ViewMaterializer,tn as XsdImportRule,Ae as allowAllPolicy,qt as assertPackageIdentity,er as buildLocalFirstRepository,yn as buildOntologyModel,lt as canonicalForm,te as canonicalHash,Ue as carrierOf,Qt as collectKanonakFiles,B as compareVersions,ct as computeIntegrity,je as contentAddressedName,Ar as contextTypesOf,nt as createAuthenticatedFetch,V as createDPoPProof,Vt as createVersion,dr as extractMarkdownLinks,dn as findDerivation,Vr as findInstancesByType,pr as findMalformedReferences,Er as findMarkdownLinkAt,Ir as formatKanonakAddress,k as formatVersion,tt as generateDPoPKeyPair,Ft as getGlobalCachePath,Wt as getKanonakUserAgent,F as hasValidToken,Dt as isCompatibleVersion,L as isExpired,Tt as isMajorCompatible,b as kanonakFetch,it as loadLockFile,sr as makeUriKey,Ve as noopMeter,l as normalizeHost,be as parseKanonakAddress,Ot as parseVersionString,Rr as parseWithPositions,Nt as pickHighestDocument,$r as propertiesInScope,mn as resolveDisplayValue,jr as resolvePropertyStep,D as sanitizeName,st as saveLockFile,rt as serverSupportsDPoP,zt as setKanonakUserAgent,g as subjectUri,Kr as superClassChain,cr as tripleKey,R as uriKey,lr as uriTriple,jt as versionOperatorFromChar,ce as versionOperatorToChar,At as versionsEqual};