@kanonak-protocol/sdk 3.69.0 → 3.71.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 (57) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/chunk-4NO7MHS7.js +1 -0
  3. package/dist/{chunk-N224PFBI.js → chunk-BGQKZBNE.js} +1 -1
  4. package/dist/chunk-CRKSKIAL.js +1 -0
  5. package/dist/chunk-F5ANO7MJ.js +1 -0
  6. package/dist/chunk-FX7JDGL6.js +1 -0
  7. package/dist/chunk-G2DKKSZ4.js +1 -0
  8. package/dist/{chunk-7JZUJ2K4.js → chunk-GN2XODVC.js} +1 -1
  9. package/dist/chunk-HAR3BNTB.js +2 -0
  10. package/dist/chunk-IOMNZBK4.js +1 -0
  11. package/dist/chunk-MCU5IAMS.js +148 -0
  12. package/dist/chunk-OFSARZX6.js +1 -0
  13. package/dist/chunk-RRODBYIK.js +74 -0
  14. package/dist/chunk-SHDHMKMJ.js +1 -0
  15. package/dist/chunk-TJPQETHV.js +1 -0
  16. package/dist/chunk-Y7TGQ7UF.js +2 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +26 -26
  19. package/dist/look/LookRenderer.d.ts +29 -1
  20. package/dist/parsing/index.js +1 -1
  21. package/dist/reasoning/index.js +1 -1
  22. package/dist/repositories/browser.js +1 -1
  23. package/dist/repositories/index.js +1 -1
  24. package/dist/resolution/index.js +1 -1
  25. package/dist/search/index.js +1 -1
  26. package/dist/server/index.js +2 -2
  27. package/dist/server/route.d.ts +1 -1
  28. package/dist/transformations/index.js +47 -47
  29. package/dist/transformations/v3/CompiledTransformationV3.d.ts +6 -2
  30. package/dist/transformations/v3/ExpressionEngineV3.d.ts +13 -1
  31. package/dist/transformations/v3/TransformationLoaderV3.d.ts +19 -2
  32. package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +5 -0
  33. package/dist/uri-helpers/UriHelpers.d.ts +18 -0
  34. package/dist/uri-helpers/index.d.ts +1 -1
  35. package/dist/uri-helpers/index.js +1 -1
  36. package/dist/validation/TxExpressionPathChecker.d.ts +39 -0
  37. package/dist/validation/index.d.ts +1 -1
  38. package/dist/validation/index.js +1 -1
  39. package/dist/validation/rules/repository/LookSemanticSvgPathRule.d.ts +26 -0
  40. package/dist/validation/rules/repository/TxExpressionPathRule.d.ts +28 -0
  41. package/dist/validation/rules/repository/index.d.ts +2 -0
  42. package/dist/view/ViewMaterializer.d.ts +71 -0
  43. package/dist/view/index.d.ts +2 -0
  44. package/package.json +2 -2
  45. package/dist/chunk-64TVBQFR.js +0 -1
  46. package/dist/chunk-767XYRNU.js +0 -1
  47. package/dist/chunk-CA2EATJR.js +0 -1
  48. package/dist/chunk-FXKT6OI4.js +0 -148
  49. package/dist/chunk-H2LEQLVD.js +0 -1
  50. package/dist/chunk-KSTGTV35.js +0 -2
  51. package/dist/chunk-OIVACCMQ.js +0 -59
  52. package/dist/chunk-ORFSMEMM.js +0 -1
  53. package/dist/chunk-Q4DKP5DO.js +0 -1
  54. package/dist/chunk-Q6QTQWR2.js +0 -1
  55. package/dist/chunk-QHJ6EY3Y.js +0 -1
  56. package/dist/chunk-RSIZQAFL.js +0 -2
  57. /package/dist/{chunk-3NEUHF7E.js → chunk-QHABFCRC.js} +0 -0
@@ -1,59 +0,0 @@
1
- import{a as ue,c as v}from"./chunk-Q6QTQWR2.js";import{a as le,c as ye}from"./chunk-H2LEQLVD.js";import{a as ae}from"./chunk-ORFSMEMM.js";import{d as de,f as ge,g as he}from"./chunk-N224PFBI.js";import{i as fe,l as J}from"./chunk-Q4DKP5DO.js";import{a as P,b as D,c as me}from"./chunk-64TVBQFR.js";import{c as G,k as ce,l as pe}from"./chunk-W6T7MOKY.js";import{e as V}from"./chunk-2ACBWC7K.js";var A=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(r=>(r.Warning="Warning",r.Error="Error",r))(R||{});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 te=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let r=new d;return r.resolvedDocuments=this.resolvedDocuments,r.currentEntityPath=e,r}};var oe=class{constructor(e){this.underlying=e;this.repository=new ne(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new v().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let r=this.importClosureCache.get(e);return r||(r=this.computeImportClosure(e),this.importClosureCache.set(e,r),r)}async getClassDeclarations(e){let r=this.classDeclarationsCache.get(e);return r||(r=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,r),r)}async getPropertyNames(e){let r=this.propertyNamesCache.get(e);return r||(r=this.computePropertyNames(e),this.propertyNamesCache.set(e,r),r)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let r=new Set([e]),t=[e],o=await this.buildDocsByIdIndex();for(;t.length>0;){let s=t.shift(),i=o.get(s);if(i?.metadata.imports)for(let[n,l]of Object.entries(i.metadata.imports))for(let a of l){let c=await this.repository.getHighestCompatibleVersionAsync(n,a);if(!c)continue;let p=re(c);!p||r.has(p)||(r.add(p),t.push(p))}}return r}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),r=new Map;for(let t of e){let o=re(t);o&&r.set(o,t)}return r}async computeClassDeclarations(e){let r=await this.findDocById(e),t=new Map;if(!r)return t;for(let[o,s]of Object.entries(r.body)){if(!be(s))continue;let i=s,n=Re(i,"type");if(n==="Class"||n?.endsWith(".Class")){let l=ve(i);t.set(o,l)}}return t}async computePropertyNames(e){let r=await this.findDocById(e),t=new Set;if(!r)return t;for(let[o,s]of Object.entries(r.body)){if(!be(s))continue;let n=Re(s,"type");(n==="ObjectProperty"||n?.endsWith(".ObjectProperty")||n==="DatatypeProperty"||n?.endsWith(".DatatypeProperty")||n==="AnnotationProperty"||n?.endsWith(".AnnotationProperty")||n==="Property"||n?.endsWith(".Property"))&&t.add(o)}return t}async findDocById(e){let r=await this.getAllDocuments();for(let t of r)if(re(t)===e)return t}};function re(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}function be(d){return typeof d=="object"&&d!==null&&!Array.isArray(d)}function Re(d,e){if(e in d)return ke(d[e]);for(let r of Object.keys(d))if(r.endsWith(`.${e}`))return ke(d[r])}function ke(d){return Array.isArray(d)?d.length>0?String(d[0]):void 0:d==null?void 0:String(d)}function ve(d){let e=d.subClassOf;if(e===void 0){for(let r of Object.keys(d))if(r.endsWith(".subClassOf")){e=d[r];break}}return P(e)}var ne=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,r){let t=`${e}/${r}`,o=this.byNamespaceCache.get(t);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,r),this.byNamespaceCache.set(t,o),o)}getHighestCompatibleVersionAsync(e,r){let t=r.version,o=t?`${t.major}.${t.minor}.${t.patch}`:"",s=`${e}/${r.packageName}@${r.versionOperator}:${o}`,i=this.highestVersionCache.get(s);return i||(i=this.inner.getHighestCompatibleVersionAsync(e,r),this.highestVersionCache.set(s,i),i)}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 I=class d{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 r=[];for(let[t,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(t,o,r);return r}validateEntity(e,r,t){for(let[o,s]of Object.entries(r)){let i=s?.toString()??"";if(i&&d.NAMESPACE_PREFIX_PATTERN.test(i)){let n=this.getSuggestionForPrefixedValue(i),l=e.split(".")[0],a=new g;a.ruleType=this.ruleName,a.severity="Error",a.entityName=l,a.propertyName=e,a.actualValue=o,a.expectedValue=n,a.message=`Invalid namespace prefix '${i}'. Use '${n}' without prefix.`,a.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(a)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validateEntity(`${e}.${o}`,s,t)}}getSuggestionForPrefixedValue(e){let r=e.toLowerCase();if(r==="rdfs:class"||r==="owl:class")return"Class";if(r==="rdfs:property"||r==="rdf:property")return"DatatypeProperty or ObjectProperty";if(r.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var O=class d{static RESERVED_WORDS=new Set(["kanonak","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 r=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,s]of Object.entries(e.body)){let i=d.VALID_AUGMENTATION_PATTERN.test(o);if(!i&&!t&&d.RESERVED_WORDS.has(o.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=o,n.message=`Entity name '${o}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",r.push(n);continue}if(!i&&!d.VALID_NAME_PATTERN.test(o)){let n;/^\d/.test(o)?n="Entity names must start with a letter, not a number.":o.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=o,l.message=`Invalid entity name '${o}'. ${n}`,l.suggestion=n,r.push(l)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validatePropertyNames(o,s,r)}return r}validatePropertyNames(e,r,t){for(let o of Object.keys(r))if(!d.VALID_PROPERTIES.has(o)&&!d.VALID_PROPERTY_NAME_PATTERN.test(o)){let s=new g;s.ruleType=this.ruleName,s.severity="Warning",s.entityName=e,s.propertyName=o,s.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,s.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(s)}}};var w=class d{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 r=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return r;let t=this.isPropertyDefinedAsClass(e);for(let[o,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)){let i=s,n=i.type;if(n){let l=[];if(Array.isArray(n))for(let a of n){let c=a?.toString();c&&c==="Property"&&!t&&l.push(c)}else{let a=n?.toString();a&&a==="Property"&&!t&&l.push(a)}for(let a of l){let c=this.getPropertyValue(i,"range"),p=this.determinePropertyType(c),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.entityName=o,y.propertyName="type",y.actualValue=a,y.expectedValue=p,y.message=`Invalid property type '${a}'. Use '${p}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",r.push(y)}}}return r}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,r){let t=e[r];return t?t.toString():null}isPropertyDefinedAsClass(e){let r=e.body.Property;if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r.type;if(o){let s=o.toString();return s==="Class"||s.endsWith(".Class")}}return!1}};var j=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let r=[];for(let[t,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||t.includes("."))continue;let s=o,i="type"in s,n=s.type?.toString().trim();if(!i||!n){let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=t,l.propertyName="type",l.message=`Subject Kanonak '${t}' must have a 'type' property.`,l.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.`,l.expectedValue="A valid class name (Scene, Character, Story, etc.)",r.push(l)}}return r}};var E=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,r){let t=[],o=new D(r),s=await this.buildPropertyRangeMap(e,o);for(let[i,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(i,n,void 0,s,o,e,t,0);return t}pickRange(e,r,t){if(e.length===0)return;if(e.length===1)return e[0].range;let o=r.indexOf(".");if(o>0){let s=r.substring(0,o),i=e.find(n=>n.declaringAlias===s);if(i)return i.range}if(t){let s=this.localName(t),i=e.find(n=>this.localName(n.domain)===s);if(i)return i.range}return e[0].range}async checkEmbeddedTypes(e,r,t,o,s,i,n,l){if(l>0){let c=r.type;if(c!=null){let p=await this.validateEmbeddedType(e,String(c),t,s,i);p&&n.push(p)}}let a=r.type!==void 0&&r.type!==null?String(r.type):void 0;for(let[c,p]of Object.entries(r)){let y=this.localName(c),m=o.get(y),f=(m!==void 0?this.pickRange(m,c,a):void 0)??t;if(typeof p=="object"&&p!==null)if(Array.isArray(p))for(let b=0;b<p.length;b++){let h=p[b];typeof h=="object"&&h!==null&&!Array.isArray(h)&&await this.checkEmbeddedTypes(`${e}.${c}[${b}]`,h,f,o,s,i,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${c}`,p,f,o,s,i,n,l+1)}}async validateEmbeddedType(e,r,t,o,s){if(r.length===0||!t)return null;let i=this.localName(r),n=this.localName(t);if(n==="Resource"||n==="Class")return null;let l=e.split(".")[0];if(i===n){let c=new g;return c.ruleType=this.ruleName,c.severity="Warning",c.entityName=l,c.propertyName=e,c.actualValue=r,c.expectedValue=t,c.message=`Embedded object at '${e}' declares 'type: ${r}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,c.suggestion=`Remove the 'type: ${r}' line, or keep it if explicitness is preferred over concision.`,c}if(await o.isSubclassOfAsync(r,t,s)||(i!==r||n!==t)&&await o.isSubclassOfAsync(i,n,s))return null;let a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=l,a.propertyName=e,a.actualValue=r,a.expectedValue=t,a.message=`Embedded object at '${e}' has 'type: ${r}', which is not a subclass of the parent property's range '${t}'.`,a.suggestion=`Either remove the 'type: ${r}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${r}' class definition so the relationship holds.`,a}localName(e){let r=e.lastIndexOf(".");return r<0||r===e.length-1?e:e.substring(r+1)}async buildPropertyRangeMap(e,r){let t=new Map,o=await r.buildEntityIndexAsync(e),s=new Map;for(let[i,n]of o){let l=n.entity.type;if(l==null)continue;let a=String(l),c=this.localName(a);if(!(c==="Property"||c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"))continue;let y=n.entity.range;if(y==null)continue;let m=String(y);if(m.length===0)continue;let u=n.entity.domain,f=u!=null?String(u):"",b=n.uri.toString(),h=s.get(b),k=i.includes(".");(!h||k&&!h.entityName.includes("."))&&s.set(b,{entityName:i,domain:f,range:m})}for(let i of s.values()){let n=this.localName(i.entityName),l=i.entityName.indexOf("."),a=l>0?i.entityName.substring(0,l):void 0,c=t.get(n)??[];c.push({domain:i.domain,range:i.range,declaringAlias:a}),t.set(n,c)}return t}};import{VersionOperator as Q}from"@kanonak-protocol/types/document/models/enums";var $=class{ruleName="ImportExistence";async validateAsync(e,r){let t=[];if(!e.metadata?.imports)return t;let o=await r.getAllDocumentsAsync();for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i)if(!await r.getHighestCompatibleVersionAsync(s,n)){let a=await this.determineImportErrorAsync(r,s,n,o),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=a.message,c.suggestion=a.suggestion,c.entityName=`Import: ${s}/${n.packageName}`,c.actualValue=n.toString(),c.expectedValue=a.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,r,t,o){let s=await e.getDocumentsByNamespaceAsync(r,t.packageName);if(s.length===0){let a=o.filter(m=>m.metadata.namespace_?.publisher===r).map(m=>m.metadata.namespace_.package_).filter((m,u,f)=>f.indexOf(m)===u),c=this.findSimilarPackages(t.packageName,a),p=`Import '${r}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:a.length>0?`Available packages in ${r}: ${a.slice(0,5).join(", ")}`:`No packages found for publisher '${r}'. Verify the publisher name is correct.`;return{message:p,suggestion:y,expectedValue:"Existing package"}}let n=s.filter(a=>a.metadata.namespace_?.version).map(a=>a.metadata.namespace_.version.toString()).sort().join(", "),l=this.getAcceptableVersionRange(t);return{message:`Import '${r}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${n}. Required: ${l}`,expectedValue:l}}getAcceptableVersionRange(e){switch(e.versionOperator){case Q.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Q.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Q.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Q.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,r){if(r.length===0)return[];let t=r.filter(i=>i.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(i.toLowerCase()));if(t.length>0)return t.sort((i,n)=>i.length-n.length);let o=r.map(i=>({package:i,distance:this.levenshteinDistance(e.toLowerCase(),i.toLowerCase())})).sort((i,n)=>i.distance-n.distance),s=Math.max(3,Math.floor(e.length*.4));return o.filter(i=>i.distance<=s).map(i=>i.package)}levenshteinDistance(e,r){if(!e||e.length===0)return r?.length??0;if(!r||r.length===0)return e.length;let t=e.length,o=r.length,s=Array(t+1).fill(null).map(()=>Array(o+1).fill(0));for(let i=0;i<=t;i++)s[i][0]=i;for(let i=0;i<=o;i++)s[0][i]=i;for(let i=1;i<=t;i++)for(let n=1;n<=o;n++){let l=e[i-1]===r[n-1]?0:1;s[i][n]=Math.min(Math.min(s[i-1][n]+1,s[i][n-1]+1),s[i-1][n-1]+l)}return s[t][o]}};var S=class{ruleName="UnresolvedReference";async validateAsync(e,r){let t=[],o=new D(r),s=await o.buildEntityIndexAsync(e),i=new Set;for(let[n,l]of s.entries()){let a=l.entity.type;if(a){let c=a.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&i.add(n)}}for(let[n,l]of Object.entries(e.body)){if(!l||typeof l!="object"||Array.isArray(l))continue;let a=l,c=this.getPropertyValue(a,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[p,y]of Object.entries(a))p==="type"||p==="label"||p==="comment"||!(i.has(p)||Array.from(i).some(u=>u.endsWith(`.${p}`)))||await this.validateReferenceValue(n,p,y,e,o,t)}return t}async validateReferenceValue(e,r,t,o,s,i){if(t!=null){if(typeof t=="string")await s.resolveEntityAsync(t,o)||i.push(this.createUnresolvedReferenceError(e,r,t));else if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=t[n];typeof l=="string"&&(await s.resolveEntityAsync(l,o)||i.push(this.createUnresolvedReferenceError(e,`${r}[${n}]`,l)))}}}createUnresolvedReferenceError(e,r,t){let o=`The entity '${t}' cannot be found in the current document or any imported namespaces.
5
-
6
- Possible solutions:
7
- \u2022 Add import if the entity is defined in another namespace:
8
- kanonak namespace add-import <publisher>/<package>@<version>
9
- \u2022 Check for typos in the reference name '${t}'
10
- \u2022 Define '${t}' in the current namespace or an appropriate namespace
11
- \u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,s=new g;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=r,s.actualValue=t,s.message=`Reference to '${t}' could not be resolved`,s.suggestion=o,s.expectedValue="A valid entity reference that exists in the current document or imported namespaces",s}getPropertyValue(e,r){let t=e[r];return t?t.toString():null}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,r){let t=[],o=new Map,s=new Set;await this.buildClassHierarchy(e,r,o,s);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,a=l.type,c=l.subClassOf;if(a?.toString()==="Class"&&c){let p=i,y=this.detectCycle(p,o);if(y){let m=y.join(" \u2192 "),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${m}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=p,u.propertyName="subClassOf",u.actualValue=m,t.push(u);break}}}return t}async buildClassHierarchy(e,r,t,o){let s=e.metadata?.namespace_?.toString()??"";if(!(s&&o.has(s))){s&&o.add(s);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,a=l.type,c=l.subClassOf;if(a?.toString()==="Class"&&c){let p=P(c);p.length>0&&t.set(i,p)}}if(e.metadata?.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);a&&await this.buildClassHierarchy(a,r,t,o)}}}detectCycle(e,r){let t=[],o=new Set;return this.detectCycleRecursive(e,r,t,o)}detectCycleRecursive(e,r,t,o){if(t.includes(e)){let i=t.indexOf(e),n=t.slice(i);return n.push(e),n}if(o.has(e))return null;t.push(e),o.add(e);let s=r.get(e);if(s)for(let i of s){let n=this.detectCycleRecursive(i,r,t,o);if(n)return n}return t.pop(),null}};var C=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,r){let t=[],o=new Map,s=new Set;await this.buildPropertyHierarchy(e,r,o,s);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.subPropertyOf){let c=i,p=this.detectCycle(c,o);if(p){let y=p.join(" \u2192 "),m=new g;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${y}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=c,m.propertyName="subPropertyOf",m.actualValue=y,t.push(m);break}}return t}async buildPropertyHierarchy(e,r,t,o){let s=e.metadata?.namespace_?.toString()??"";if(!(s&&o.has(s))){s&&o.add(s);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,a=l.type;if(a){let c=a.toString();if(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"){let p=l.subPropertyOf;if(p){let y=P(p);y.length>0&&t.set(i,y)}}}}if(e.metadata?.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);a&&await this.buildPropertyHierarchy(a,r,t,o)}}}detectCycle(e,r){let t=[],o=new Set;return this.detectCycleRecursive(e,r,t,o)}detectCycleRecursive(e,r,t,o){if(t.includes(e)){let i=t.indexOf(e),n=t.slice(i);return n.push(e),n}if(o.has(e))return null;t.push(e),o.add(e);let s=r.get(e);if(s)for(let i of s){let n=this.detectCycleRecursive(i,r,t,o);if(n)return n}return t.pop(),null}};var K=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,r){let t=[];for(let[o,s]of Object.entries(e.body)){if(typeof s!="object"||s===null||Array.isArray(s))continue;let i=s,n=i.type?.toString();if(n==="DatatypeProperty"||n==="ObjectProperty"||n?.endsWith(".DatatypeProperty")||n?.endsWith(".ObjectProperty")){let l="range"in i,a=i.range?.toString().trim();if(!l||!a){let c=new g;c.ruleType=this.ruleName,c.severity="Error",c.entityName=o,c.propertyName="range",c.message=`Property '${o}' must have a 'range' defined.`,c.suggestion=n==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",c.expectedValue=n==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(c)}}}return t}};var T=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,r){let t=[],o=new Set;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isClassLikeType(l)&&o.add(s)}for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=P(i.subClassOf);for(let a=0;a<l.length;a++){let c=l[a];if(this.builtInClasses.has(c)||o.has(c))continue;if(!await this.isClassAvailableInImports(e,r,c)){let y=l.length>1?`[${a}]`:"",m=new g;m.ruleType=this.ruleName,m.severity="Error",m.message=`Class '${c}' referenced in subClassOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a Class, or import a namespace that contains it`,m.entityName=s,m.propertyName="subClassOf",m.actualValue=c,m.expectedValue="Defined or imported class",t.push(m)}}}return t}async isClassAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,s=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],s=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=o!==null?s:t,p=a.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isClassLikeType(u))return!0}let y=new Set;if(await this.isClassAvailableInImportsRecursive(a,r,c,y))return!0}}return!1}async isClassAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isClassLikeType(y))return!0}if(await this.isClassAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}};var x=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,r){let t=[],o=new Set;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();(l==="DatatypeProperty"||l==="ObjectProperty"||l==="AnnotationProperty")&&o.add(s)}for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=P(i.subPropertyOf);for(let a=0;a<l.length;a++){let c=l[a];if(this.builtInProperties.has(c)||o.has(c))continue;if(!await this.isPropertyAvailableInImports(e,r,c)){let y=l.length>1?`[${a}]`:"",m=new g;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${c}' referenced in subPropertyOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,m.entityName=s,m.propertyName="subPropertyOf",m.actualValue=c,m.expectedValue="Defined or imported property",t.push(m)}}}return t}async isPropertyAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,s=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],s=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=o!==null?s:t,p=a.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let y=new Set;if(await this.isPropertyAvailableInImportsRecursive(a,r,c,y))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}};var M=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,r){let t=[],o=e.metadata.namespace_?.toString();if(!o)return t;let s=new Map,i=new Set;await this.buildImportGraph(e,r,s,i);let n=this.detectCycle(o,s);if(n){let l=n.join(" \u2192 "),a=new g;a.ruleType=this.ruleName,a.severity="Error",a.message=`Circular namespace import detected: ${l}`,a.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",a.entityName="imports",a.propertyName="imports",a.actualValue=l,t.push(a)}return t}async buildImportGraph(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(!(!s||o.has(s))&&(o.add(s),e.metadata.imports)){let i=[];for(let[n,l]of Object.entries(e.metadata.imports))for(let a of l){let c=`${n}/${a.packageName}@${a.version}`;i.push(c);let p=await r.getHighestCompatibleVersionAsync(n,a);p&&await this.buildImportGraph(p,r,t,o)}i.length>0&&t.set(s,i)}}detectCycle(e,r){let t=[],o=new Set;return this.detectCycleRecursive(e,r,t,o)}detectCycleRecursive(e,r,t,o){let s=t.indexOf(e);if(s>=0){let n=t.slice(s);return n.push(e),n}if(o.has(e))return null;t.push(e),o.add(e);let i=r.get(e);if(i)for(let n of i){let l=this.detectCycleRecursive(n,r,t,o);if(l)return l}return t.pop(),null}};var L=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,r,t){let o=[],s=new Set,i=t?await this.closurePropertyNamesViaCache(e,t):void 0,n=t?await this.aliasClosurePropertyNamesViaCache(e,t):void 0;for(let[l,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let p=a.type?.toString();this.isPropertyType(p)&&s.add(l)}for(let[l,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a,p=c.type?.toString();if(this.isPropertyType(p)||this.isClassType(p))continue;for(let[y,m]of Object.entries(c)){if(!y||this.metadataKeys.has(y))continue;let u=y,f=null;if(y.includes(".")){let h=y.lastIndexOf(".");f=y.substring(0,h),u=y.substring(h+1)}if(s.has(u))continue;if(!await this.isPropertyAvailable(e,r,u,f,i,n)){let h=new g;h.ruleType=this.ruleName,h.severity="Error",h.message=`Property '${y}' is not defined or imported`,h.suggestion=f?`The property '${u}' is not found in the imported namespace with alias '${f}'.
12
- 1. Verify the namespace is imported with the correct alias
13
- 2. Check if the property name is spelled correctly
14
- 3. Ensure the imported namespace version contains this property`:`The property '${y}' is not defined in this namespace or any imported namespace.
15
- 1. Define '${y}' as an ObjectProperty or DatatypeProperty in this namespace, OR
16
- 2. Import the namespace that contains '${y}', OR
17
- 3. Use a qualified reference like 'alias.${y}' if already imported with an alias`,h.entityName=l,h.propertyName=y,h.actualValue=m?.toString(),h.expectedValue="A defined or imported property",o.push(h)}}}return o}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 isPropertyAvailable(e,r,t,o,s,i){if(s!==void 0&&i!==void 0){if(o===null)return s.has(t);let n=i.get(o);return n?n.has(t):!1}return await this.isPropertyAvailableInImports(e,r,t,o)}async closurePropertyNamesViaCache(e,r){let t=new Set,o=Pe(e);if(!o)return t;let s=await r.getImportClosure(o);for(let i of s)if(i!==o)for(let n of await r.getPropertyNames(i))t.add(n);return t}async aliasClosurePropertyNamesViaCache(e,r){let t=new Map;if(!e.metadata.imports)return t;for(let[o,s]of Object.entries(e.metadata.imports))for(let i of s){if(!i.alias)continue;let n=await r.repository.getHighestCompatibleVersionAsync(o,i);if(!n)continue;let l=Pe(n);if(!l)continue;let a=await r.getImportClosure(l),c=t.get(i.alias)??new Set;for(let p of a)for(let y of await r.getPropertyNames(p))c.add(y);t.set(i.alias,c)}return t}async isPropertyAvailableInImports(e,r,t,o){if(!e.metadata.imports)return!1;for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i){if(o!==null&&n.alias!==o)continue;let l=await r.getHighestCompatibleVersionAsync(s,n);if(l){let a=l.body[t];if(a&&typeof a=="object"&&!Array.isArray(a)){let y=a.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,r,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}};function Pe(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,r){let t=[],o=new Set;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isPropertyType(l)&&o.add(s)}for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=n.type?.toString();if(!this.isPropertyType(l)&&!this.isClassType(l))continue;for(let[a,c]of Object.entries(n)){if(!a||this.metadataKeys.has(a))continue;let p=a,y=null;if(a.includes(".")){let u=a.lastIndexOf(".");y=a.substring(0,u),p=a.substring(u+1)}if(o.has(p))continue;if(!await this.isPropertyAvailableInImports(e,r,p,y)){let u=this.isClassType(l)?"class":"property",f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${a}' used on ${u} '${s}' is not defined or imported`,f.suggestion=y?`The property '${p}' is not found in the imported namespace with alias '${y}'.
18
- 1. Verify the namespace is imported with the correct alias
19
- 2. Check if the property name is spelled correctly
20
- 3. Ensure the imported namespace version contains this property`:`The property '${a}' is not defined in this namespace or any imported namespace.
21
- 1. Define '${a}' as an ObjectProperty or DatatypeProperty in this namespace, OR
22
- 2. Import the namespace that contains '${a}', OR
23
- 3. Use a qualified reference like 'alias.${a}' if already imported with an alias`,f.entityName=s,f.propertyName=a,f.actualValue=c?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}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,r,t,o){if(!e.metadata.imports)return!1;for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i){if(o!==null&&n.alias!==o)continue;let l=await r.getHighestCompatibleVersionAsync(s,n);if(l){let a=l.body[t];if(a&&typeof a=="object"&&!Array.isArray(a)){let y=a.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,r,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}};var _=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,r){let t=[],o=new Set,s=[];for(let[i,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,a=!1,c=l.type;if(Array.isArray(c)){for(let p of c)if(p?.toString()==="DatatypeProperty"){a=!0;break}}else c?.toString()==="DatatypeProperty"&&(a=!0);if(a){s.push(i);let p=this.getPropertyValue(l,"range");p&&this.xsdTypes.has(p)&&o.add(p)}}if(o.size>0&&!await this.checkXsdImportAsync(e.metadata,r)){let n=Array.from(o).sort().join(", "),l=s.sort().join(", "),a=new g;a.ruleType=this.ruleName,a.severity="Error",a.message=`XSD namespace not imported but XSD types are used: ${n}`,a.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${l}`,a.entityName="imports",t.push(a)}return t}async checkXsdImportAsync(e,r,t=new Set){if(!e?.imports)return!1;let o=e.namespace_?.toString()??"";if(o&&t.has(o))return!1;o&&t.add(o);for(let[,s]of Object.entries(e.imports))for(let i of s)if(i.packageName==="xsd"||i.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[s,i]of Object.entries(e.imports))for(let n of i){let l=await r.getHighestCompatibleVersionAsync(s,n);if(l?.metadata&&await this.checkXsdImportAsync(l.metadata,r,t))return!0}return!1}getPropertyValue(e,r){return e[r]?.toString()}};var U=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,r){let t=[],o=await this.buildEntitySourceMapAsync(e,r),s=await this.buildDatatypePropertyNamesAsync(e,r);for(let[i,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&this.validateEntityReferences(i,n,o,s,e,t);return t}async buildEntitySourceMapAsync(e,r){let t=new Map,o=new Set;for(let s of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";t.has(s)||t.set(s,[]),t.get(s).push(`(local:${i})`)}if(e.metadata.imports)for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i){let l=await r.getHighestCompatibleVersionAsync(s,n);l&&await this.collectEntitiesRecursivelyAsync(l,t,o,r)}return t}async collectEntitiesRecursivelyAsync(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(!t.has(s)){t.add(s);for(let i of Object.keys(e.body)){r.has(i)||r.set(i,[]);let n=r.get(i);n.includes(s)||n.push(s)}if(e.metadata.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await o.getHighestCompatibleVersionAsync(i,l);a&&await this.collectEntitiesRecursivelyAsync(a,r,t,o)}}}async buildDatatypePropertyNamesAsync(e,r){let t=new Set,o=new Set;if(await this.collectDatatypePropertiesAsync(e,t,o,r),e.metadata.imports)for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i){let l=await r.getHighestCompatibleVersionAsync(s,n);l&&await this.collectDatatypePropertiesAsync(l,t,o,r)}return t}async collectDatatypePropertiesAsync(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(!t.has(s)){t.add(s);for(let[i,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n))continue;let l=n.type;if(typeof l!="string")continue;(l.includes(".")?l.substring(l.lastIndexOf(".")+1):l)==="DatatypeProperty"&&r.add(i)}if(e.metadata.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await o.getHighestCompatibleVersionAsync(i,l);a&&await this.collectDatatypePropertiesAsync(a,r,t,o)}}}validateEntityReferences(e,r,t,o,s,i){for(let[n,l]of Object.entries(r)){let a=n;if(a&&!a.includes(".")){let c=t.get(a);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&i.push(this.createAmbiguityError(e,a,`Property '${a}'`,y,s,!0,a))}}this.validatePropertyValue(e,a,l,t,o,s,i)}}validatePropertyValue(e,r,t,o,s,i,n){if(t==null)return;let l=r&&r.includes(".")?r.substring(r.lastIndexOf(".")+1):r,a=!!l&&s.has(l);if(typeof t=="string"&&!t.includes(".")&&!a){let c=o.get(t);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,r,`Reference '${t}'`,y,i,!1,t))}}else if(Array.isArray(t))for(let c=0;c<t.length;c++){let p=`${e}.${r}[${c}]`;this.validatePropertyValue(p,r,t[c],o,s,i,n)}else if(typeof t=="object"&&!Array.isArray(t)){let c=r?`${e}.${r}`:e;this.validateEntityReferences(c,t,o,s,i,n)}}createAmbiguityError(e,r,t,o,s,i,n){let l=[];for(let f of o){let b=this.findAliasForNamespace(s,f);if(b){let h=r?.split(".").pop()??r;l.push(`${b}.${h}`)}}let a=l.length>0?`Use one of: ${l.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${r}')`,c=o.map(f=>` \u2022 ${f}`).join(`
24
- `),p=e.split(".")[0],y=e.includes(".")?e:r,m=new g;m.ruleType=this.ruleName,m.severity="Error",m.entityName=p,y&&(m.propertyName=y);let u=n??r;return u&&(m.actualValue=u),m.message=`${t} is ambiguous - defined in multiple imported namespaces`,m.suggestion=`${a}
25
-
26
- Defined in:
27
- ${c}`,m.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",m}findAliasForNamespace(e,r){if(!e.metadata.imports)return null;for(let[t,o]of Object.entries(e.metadata.imports))for(let s of o)if(`${t}/${s.packageName}@${s.version}`===r&&s.alias)return s.alias;return null}};var H=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,r){let t=[],o=new Set;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isValidRangeTargetType(l)&&o.add(s)}for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=n.type?.toString();if(l!=="DatatypeProperty"&&l!=="ObjectProperty"&&!l?.endsWith(".DatatypeProperty")&&!l?.endsWith(".ObjectProperty"))continue;let a=n.range;if(!a)continue;let c=[];if(Array.isArray(a))for(let p of a){let y=p?.toString();y&&c.push(y)}else{let p=a?.toString();p&&c.push(p)}if(c.length===0)continue;for(let p of c){if(this.primitiveTypes.has(p)||this.builtInClasses.has(p)||o.has(p))continue;if(!await this.isTypeAvailableInImports(e,r,p)){let m=l?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${s}' has range '${p}' which is not defined or imported`,u.suggestion=m==="ObjectProperty"?`For ObjectProperty:
28
- 1. Define '${p}' as a Class in this namespace, OR
29
- 2. Import the namespace that contains '${p}', OR
30
- 3. Use a qualified reference like 'alias.${p}' if already imported with an alias`:`For DatatypeProperty:
31
- 1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
32
- 2. If '${p}' should be a class, change property type to ObjectProperty`,u.entityName=s,u.propertyName="range",u.actualValue=p,u.expectedValue=m==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,s=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],s=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=o!==null?s:t,p=a.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isValidRangeTargetType(u))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(a,r,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var F=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,r){let t=[],o=new Map,s=new D(r);await s.buildEntityIndexAsync(e);for(let[i,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,a=!1,c=l.type;if(Array.isArray(c)){for(let p of c)if(p?.toString()==="ObjectProperty"){a=!0;break}}else c?.toString()==="ObjectProperty"&&(a=!0);if(a){let p=l.range,y=[];if(Array.isArray(p))for(let m of p){let u=m?.toString();u&&y.push(u)}else{let m=p?.toString();m&&y.push(m)}for(let m of y)this.xsdTypes.has(m)||(o.has(m)||o.set(m,[]),o.get(m).push(i))}}for(let[i,n]of o)if(!await s.resolveEntityAsync(i,e))for(let a of n){let c=new g;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${i}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${i}' is imported, or define '${i}' in this document`,c.entityName=a,c.propertyName="range",c.actualValue=i,t.push(c)}return t}};var B=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,r){let t=[],o=new D(r),s=new me(o),i=await o.buildEntityIndexAsync(e),n=await this.buildPropertyMetadataAsync(e,r,o,i);for(let[l,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&await this.scanEntityForObjectProperties(a,l,"",n,o,s,e,t);return t}async scanEntityForObjectProperties(e,r,t,o,s,i,n,l){for(let[a,c]of Object.entries(e)){if(this.standardProperties.has(a))continue;let p,y=await s.resolveEntityAsync(a,n);if(y?.uri){let m=`${y.uri.publisher}/${y.uri.package_}/${y.uri.name}`;p=o.get(m)}if(!p){let m=a,u=a.lastIndexOf(".");u>0&&u<a.length-1&&(m=a.substring(u+1)),p=o.get(m)}if(p&&i.isEffectiveObjectProperty(p.propertyType,p.rangeUri)){let u=t?`${t}.${a}`:a;if(typeof c=="string"&&c.trim().length>0){let f=c.trim();if(f.includes(",")){let h=f.split(",").map(k=>k.trim()).filter(k=>k.length>0);l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
33
- ${a}:
34
- - ${h[0]}
35
- ${h.slice(1).map(k=>` - ${k}`).join(`
36
- `)}`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:`A single reference to ${p.range??"an entity"} OR a YAML list`});continue}let b=await s.resolveEntityAsync(f,n);if(b)p.range&&(await this.validateRangeType(b,p.range,s,n)||l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${a}' expects a ${p.range}, but '${f}' may not be a ${p.range}`,suggestion:`Ensure '${f}' is defined with appropriate type`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:p.range}));else{let h=p.range??"entity";l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' references '${f}' which is not defined or imported`,suggestion:`Define '${f}' or import a namespace that contains it. Expected range: ${h}`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let f=t?`${t}.${a}`:a;await this.scanEntityForObjectProperties(c,r,f,o,s,i,n,l)}else if(Array.isArray(c))for(let f=0;f<c.length;f++){let b=c[f];if(typeof b=="string"&&b.trim().length>0){let h=b.trim(),k=await s.resolveEntityAsync(h,n);if(k){if(p.range&&!await this.validateRangeType(k,p.range,s,n)){let ee=t?`${t}.${a}[${f}]`:`${a}[${f}]`;l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${a}' expects a ${p.range}, but '${h}' may not be a ${p.range}`,suggestion:`Ensure '${h}' is defined with appropriate type`,entityName:r,propertyName:`${a}[${f}]`,propertyPath:ee,actualValue:h,expectedValue:p.range})}}else{let se=p.range??"entity",ee=t?`${t}.${a}[${f}]`:`${a}[${f}]`;l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' references '${h}' which is not defined or imported`,suggestion:`Define '${h}' or import a namespace that contains it. Expected range: ${se}`,entityName:r,propertyName:`${a}[${f}]`,propertyPath:ee,actualValue:h,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let h=t?`${t}.${a}[${f}]`:`${a}[${f}]`;await this.scanEntityForObjectProperties(b,r,h,o,s,i,n,l)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!o.has(a)){let m=t?`${t}.${a}`:a;await this.scanEntityForObjectProperties(c,r,m,o,s,i,n,l)}else if(Array.isArray(c))for(let m=0;m<c.length;m++){let u=c[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=t?`${t}.${a}[${m}]`:`${a}[${m}]`;await this.scanEntityForObjectProperties(u,r,f,o,s,i,n,l)}}}}async validateRangeType(e,r,t,o){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(r))return!0;let i=e.entity.type;if(i){let n=[];if(Array.isArray(i))for(let l of i){let a=l?.toString();a&&a.trim().length>0&&n.push(a)}else{let l=i?.toString();l&&l.trim().length>0&&n.push(l)}for(let l of n){let a=l.includes(".")?l.split(".")[1]:l;if(a===r||r==="Property"&&(a==="DatatypeProperty"||a==="ObjectProperty"||a==="AnnotationProperty")||r==="Class"&&a==="Class"||await t.isSubclassOfAsync(l,r,o))return!0}}return!1}async buildPropertyMetadataAsync(e,r,t,o){let s=new Map;for(let[i,n]of o){let l=n.entity.type;if(l){let a=[];if(Array.isArray(l))for(let y of l){let m=y?.toString();m&&m.trim().length>0&&a.push(m)}else{let y=l?.toString();y&&y.trim().length>0&&a.push(y)}let c=!1,p="Property";for(let y of a){let m=y.includes(".")?y.split(".")[1]:y;if(m==="Property"||m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty"){c=!0,p=y;break}}if(c){let y={propertyType:p},m=n.entity.range;if(m){let u=m?.toString();if(u&&u.trim().length>0){y.range=u;let f=await t.resolveEntityAsync(u,e);f&&(y.rangeUri=f.uri)}}if(s.set(i,y),n.uri){let u=`${n.uri.publisher}/${n.uri.package_}/${n.uri.name}`;s.set(u,y)}}}}return s}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,r,t){let o=[],s=new Map;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=this.getPropertyValue(a,"type");(c==="DatatypeProperty"||c?.endsWith(".DatatypeProperty")||c==="ObjectProperty"||c?.endsWith(".ObjectProperty")||c==="AnnotationProperty"||c?.endsWith(".AnnotationProperty"))&&s.set(n,a)}let i=t?await this.buildClassHierarchyViaCache(e,t):await this.buildCompleteClassHierarchyAsync(e,r);for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=this.getPropertyValue(a,"type");if(!c||c==="Class"||c.endsWith(".Class")||c.endsWith("Property")||c==="AnnotationProperty")continue;this.validateEntityProperties(a,n,c,s,i,o)}return o}async buildClassHierarchyViaCache(e,r){let t=new Map,o=Ae(e);if(!o)return t;let s=await r.getImportClosure(o);for(let i of s){let n=await r.getClassDeclarations(i);for(let[l,a]of n)a.length>0&&t.set(l,a)}return t}async buildCompleteClassHierarchyAsync(e,r){let t=new Map,o=new Set,s=async(n,l)=>{if(!o.has(l)){o.add(l);for(let[a,c]of Object.entries(n.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let p=c,y=this.getPropertyValue(p,"type");if(y==="Class"||y?.endsWith(".Class")){let m=p.subClassOf;if(m===void 0){for(let f of Object.keys(p))if(f.endsWith(".subClassOf")){m=p[f];break}}let u=P(m);u.length>0&&t.set(a,u)}}if(n.metadata.imports)for(let[a,c]of Object.entries(n.metadata.imports))for(let p of c)try{let y=await r.getHighestCompatibleVersionAsync(a,p);if(y){let m=`${a}/${p.packageName}@${p.version}`;await s(y,m)}}catch{}}},i=e.metadata.namespace_?.toString()??"unknown";return await s(e,i),t}validateEntityProperties(e,r,t,o,s,i){for(let[n,l]of Object.entries(e)){if(this.standardProperties.has(n))continue;let a=n,c=n.lastIndexOf(".");c>0&&c<n.length-1&&(a=n.substring(c+1));let p=o.get(a);if(!p)continue;let y=this.getPropertyValue(p,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,s)){let m=r.split(".")[0];i.push({ruleType:this.ruleName,severity:"Error",entityName:m,propertyName:r,actualValue:n,message:`Property '${n}' has domain '${y}' but is used on '${t}' at '${r}'`,suggestion:`Either:
37
- 1. Use this property only on '${y}' instances
38
- 2. Change the property domain to include '${t}'
39
- 3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let m=l,u=this.getPropertyValue(m,"type");if(u){let f=`${r}.${n}`;this.validateEntityProperties(m,f,u,o,s,i)}else{let f=this.getPropertyValue(p,"range");if(f){let b=`${r}.${n}`;this.validateEntityProperties(m,b,f,o,s,i)}}}else if(Array.isArray(l))for(let m=0;m<l.length;m++){let u=l[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,b=this.getPropertyValue(f,"type");if(b){let h=`${r}.${n}[${m}]`;this.validateEntityProperties(f,h,b,o,s,i)}else{let h=this.getPropertyValue(p,"range");if(h){let k=`${r}.${n}[${m}]`;this.validateEntityProperties(f,k,h,o,s,i)}}}}}}}isTypeCompatibleWithDomain(e,r,t){if(e===r)return!0;let o=new Set,s=[e];for(;s.length>0;){let i=s.shift();if(o.has(i))continue;o.add(i);let n=t.get(i);if(n)for(let l of n){if(l===r)return!0;s.push(l)}}return!1}getPropertyValue(e,r){if(r in e){let t=e[r];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${r}`)){let o=e[t];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let r=[];for(let t of e)r.push(t?.toString()??"");return r.length>0?r[0]:void 0}return e?.toString()}};function Ae(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var X=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,r){let t=[],o=new Map;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=this.getPropertyValue(n,"type");(l==="DatatypeProperty"||l==="ObjectProperty")&&o.set(s,n)}for(let[s,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let n=i,l=this.getPropertyValue(n,"type");if(!(!l||l==="Class"||l.endsWith("Property")||l==="AnnotationProperty"))for(let[a,c]of Object.entries(n)){if(a==="type"||a==="label"||a==="comment")continue;let p=a,y=a.lastIndexOf(".");y>0&&y<a.length-1&&(p=a.substring(y+1));let m=o.get(p);if(!m)continue;let u=this.getPropertyValue(m,"type"),f=this.getPropertyValue(m,"range");if(u==="DatatypeProperty"){if(typeof c=="object"&&c!==null&&!Array.isArray(c)||Array.isArray(c))t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`Property '${a}' is a DatatypeProperty with range '${f}' but instance '${s}' has a complex object value`,suggestion:`Either:
40
- 1. Create a class for this data and change '${a}' to an ObjectProperty
41
- 2. Store as a JSON string to keep it as DatatypeProperty
42
- 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let b={ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`Property '${a}' expects type '${f}' but instance '${s}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(b.expectedValue=f),t.push(b)}}else if(u==="ObjectProperty")if(Array.isArray(c))for(let b=0;b<c.length;b++){let h=c[b];typeof h!="string"&&(typeof h!="object"||h===null||Array.isArray(h))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:`${a}[${b}]`,message:`ObjectProperty '${a}' array item ${b} in instance '${s}' has invalid type '${this.getValueTypeName(h)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`ObjectProperty '${a}' in instance '${s}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,r){switch(e?.toLowerCase()){case"string":return typeof r=="string";case"integer":case"int":return typeof r=="number"&&Number.isInteger(r);case"decimal":return typeof r=="number";case"boolean":return typeof r=="boolean";case"float":case"double":return typeof r=="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,r){if(r in e){let t=e[r];if(Array.isArray(t)){let o=[];for(let s of t)o.push(s?.toString()??"");return o.length>0?o[0]:void 0}return t?.toString()}}};var z=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,r){let t=[],o=new Map,s=new Set;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let c=l.type;if(c)if(Array.isArray(c))for(let p of c){let y=p?.toString();if(y==="Class"||y&&y.endsWith(".Class")){s.add(n);break}}else{let p=c?.toString();(p==="Class"||p&&p.endsWith(".Class"))&&s.add(n)}}for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=a.type;if(c)if(Array.isArray(c)){let p=!1;for(let y of c){let m=y?.toString();if(m&&this.isDefinitionType(m)){p=!0;break}}if(!p)for(let y of c){let m=y?.toString();m&&m.trim().length>0&&(o.has(m)||o.set(m,[]),o.get(m).push(n))}}else{let p=c?.toString();p&&p.trim().length>0&&(this.isDefinitionType(p)||(o.has(p)||o.set(p,[]),o.get(p).push(n)))}this.checkNestedTypes(a,n,o,n)}let i=new D(r);for(let[n,l]of o){if(this.builtInClasses.has(n)||s.has(n))continue;let a=await i.resolveEntityAsync(n,e);if(!(a&&this.isClassEntity(a.entity))){let p=Array.from(new Set(l)).sort();for(let y of p)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${n}' is not defined or imported`,suggestion:`Define '${n}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:n,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,r,t,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let s=e,i=s.type;if(i){let n=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(i))for(let l of i){let a=l?.toString();a&&a.trim().length>0&&!n.has(a)&&(t.has(a)||t.set(a,[]),t.get(a).push(o))}else{let l=i?.toString();l&&l.trim().length>0&&!n.has(l)&&(t.has(l)||t.set(l,[]),t.get(l).push(o))}}for(let[n,l]of Object.entries(s))if(n!=="type"){let a=`${o}.${n}`;this.checkNestedTypes(l,r,t,a)}}else if(Array.isArray(e))for(let s=0;s<e.length;s++){let i=`${o}[${s}]`;this.checkNestedTypes(e[s],r,t,i)}}isClassEntity(e){if(!e)return!1;let r=e.type;if(!r)return!1;if(Array.isArray(r))for(let t of r){let o=t?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let t=r?.toString();if(t==="Class"||t&&t.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 Y=class{ruleName="MarkdownLink";async validateAsync(e,r,t){let o=[],s;if(t){let i=await t.getKanonaks(),n=Ie(e);s=n?i.filter(l=>l instanceof G&&l.namespace===n):[]}else{let i=new J(e,r);s=await new v().parseKanonaks(i)}for(let i of s)i instanceof G&&this.checkDefined(i,i.name,o);return o}checkDefined(e,r,t){for(let o of e.statement)if(o instanceof ye){let s=o.predicate.subject?.name??"(unknown)";for(let i of o.links)i.target||t.push(this.unresolvedLinkError(r,s,i.reference));for(let i of ue(o.object))t.push(this.malformedLinkError(r,s,i.snippet))}else if(o instanceof ce)this.checkDefined(o.object,r,t);else if(o instanceof pe)for(let s of o.object)s instanceof le&&this.checkDefined(s,r,t)}unresolvedLinkError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Warning",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`Embedded link [[${t}]] in '${r}' could not be resolved`,o.expectedValue="A reference resolvable through the document's import closure",o.suggestion=`The reference '${t}' inside a markdown value cannot be found in the current document or any imported namespace.
43
-
44
- Possible solutions:
45
- \u2022 Import the package that defines '${t}' so the link can resolve
46
- \u2022 Check for typos in the reference name
47
- \u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,o}malformedLinkError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`Malformed embedded reference near '${t}' in '${r}'`,o.expectedValue="A single-line [[reference]] with no internal line break",o.suggestion=`A '[[' in '${r}' does not form a complete [[reference]] link.
48
-
49
- A reference may not span a line break \u2014 the most common cause is wrapping a
50
- long reference across two lines in a block scalar, e.g.:
51
- ... read for [[persistent-energy-
52
- shock]] held ...
53
- which is parsed as literal text, not a link. Keep each [[reference]] on one
54
- line (let the line run long), or check for an unterminated [[.`,o}};function Ie(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var Ve="kanonak.org",De="look",Oe={publisher:Ve,package_:De,name:"displayLabel"},we={publisher:Ve,package_:De,name:"displaySummary"},Z=class{ruleName="DisplayLensScope";async validateAsync(e,r,t){let o=[],s;t?s=await t.getKanonaks():s=await new v().parseKanonaks(new J(e,r));let i=je(e);if(!i)return o;for(let n of s)n instanceof G&&n.namespace===i&&(this.checkLens(s,n,Oe,"displayLabel",o),this.checkLens(s,n,we,"displaySummary",o));return o}checkLens(e,r,t,o,s){let i=fe(r,t);if(!i)return;let n=[],l=de(r);if(l&&n.push(l),n.push(...he(r)),n.length===0)return;n.some(c=>ge(e,c,i).ok)||s.push(this.scopeError(r.name,o,i.name))}scopeError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Warning",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`${r} points at '${t}', 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=`'${t}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
55
-
56
- Possible solutions:
57
- \u2022 Point ${r} at a property declared on this class (or an ancestor / rdfs.Resource)
58
- \u2022 Set the property's domain to this class if it should apply here
59
- \u2022 Use rdfs.label / rdfs.comment for the universal default`,o}};function je(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var ie=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new ae,this.documentRules=[new I,new O,new w,new j],this.repositoryRules=[new E,new $,new S,new N,new C,new K,new T,new x,new M,new L,new W,new _,new U,new H,new F,new B,new q,new X,new z,new Y,new Z]}async validateAsync(e,r,t){let o=new A;for(let s of this.documentRules)try{let i=s.validate(e);this.addErrorsToResult(o,i)}catch(i){let n=new g;n.ruleType=s.ruleName,n.severity="Error",n.message=`Validation rule '${s.ruleName}' failed: ${i instanceof Error?i.message:String(i)}`,o.errors.push(n)}if(r){let s=[],i=t?.repository??r;for(let n of this.repositoryRules)try{let l=await n.validateAsync(e,i,t);this.addErrorsToResult(o,l)}catch(l){let a=l instanceof Error?l.message:String(l);s.push({ruleName:n.ruleName,cause:a})}if(s.length>0){let n=new Map;for(let{ruleName:l,cause:a}of s){let c=n.get(a);c?c.push(l):n.set(a,[l])}for(let[l,a]of n){let c=new g;c.ruleType=a[0],c.severity="Error",a.length===1?c.message=`Validation rule '${a[0]}' failed: ${l}`:c.message=`${l} (affects ${a.length} rules: ${a.join(", ")})`,o.errors.push(c)}}}return o.isValid=o.errors.length===0,o}async validateYamlAsync(e,r,t){let o=this.parser.parseWithErrors(e);if(!o.isValid){let s=new A;s.isValid=!1;for(let i of o.errors){let n=new g;n.ruleType="ParseError",n.severity="Error",n.lineNumber=i.line,n.column=i.column,n.message=i.message,i.keyName&&(n.entityName=i.keyName),i.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),s.errors.push(n)}return s}return await this.validateAsync(o.document,r,t)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let r=this.documentRules.findIndex(t=>t instanceof e);r>=0&&this.documentRules.splice(r,1)}removeRepositoryRule(e){let r=this.repositoryRules.findIndex(t=>t instanceof e);r>=0&&this.repositoryRules.splice(r,1)}addErrorsToResult(e,r){for(let t of r)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{A as a,R as b,g as c,te as d,oe as e,I as f,O as g,w as h,j as i,E as j,$ as k,S as l,N as m,C as n,K as o,T as p,x as q,M as r,L as s,W as t,_ as u,U as v,H as w,F as x,B as y,q as z,X as A,z as B,Y as C,Z as D,ie as E};
@@ -1 +0,0 @@
1
- import{a as y,b as g}from"./chunk-2ACBWC7K.js";import*as h from"js-yaml";var k=class{parse(e){let t=this.parseWithErrors(e);if(!t.isValid){let a=t.errors[0];throw new Error(`YAML parse error at line ${a.line}, column ${a.column}: ${a.message}`)}return t.document}parseWithErrors(e){let t=[],a;try{e=e.replace(/^\uFEFF/,"");let s=h.load(e);if(!s||typeof s!="object")return a={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:a,errors:t,isValid:!0};let r=this.extractMetadata(s),n=this.extractBody(s,r);return a={metadata:r,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:a,errors:t,isValid:!0}}catch(s){let r=s,n={message:r.message||"Unknown parse error",line:r.mark?.line??0,column:r.mark?.column??0,errorType:r.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${r.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${r.mark?.line??0}: ${r.message||"Unknown parse error"}`};return t.push(n),{document:void 0,errors:t,isValid:!1}}}save(e){let t={};if(e.metadata.namespace_){let a=e.metadata.namespace_,s={type:"Package",publisher:a.publisher};a.version&&(s.version=`${a.version.major}.${a.version.minor}.${a.version.patch}`),e.metadata.imports&&(s.imports=this.serializeImports(e.metadata.imports)),t[a.package_]=s}return Object.assign(t,e.body),h.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let t=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!t)return[];let a=[];for(let s of Object.values(t))a.push(...s);return a},enumerable:!0,configurable:!0}),e}createVersion(e,t,a){return{major:e,minor:t,patch:a,toString:()=>`${e}.${t}.${a}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===t&&r.patch===a,getHashCode:()=>e<<20|t<<10|a,compareTo:r=>e!==r.major?e-r.major:t!==r.minor?t-r.minor:a-r.patch}}extractMetadata(e){let t=this.createEmptyMetadata();for(let[a,s]of Object.entries(e))if(s&&typeof s=="object"&&s.type==="Package"){t.type_="Package";let r=a,n=s.publisher,i=s.version?this.parseVersion(s.version):void 0;return n&&r&&(t.namespace_={publisher:n,package_:r,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===n&&o.package_===r&&(!i||!o.version||i.equals(o.version)),getHashCode:()=>{let o=0;for(let c=0;c<n.length;c++)o=(o<<5)-o+n.charCodeAt(c);for(let c=0;c<r.length;c++)o=(o<<5)-o+r.charCodeAt(c);return o|0}}),s.imports&&Array.isArray(s.imports)&&(t.imports=this.parseImportsV3(s.imports)),this.addAllImportsGetter(t)}if(e.kanonak&&typeof e.kanonak=="object"){let a=e.kanonak;return(a.publisher||a.package||a.version)&&(t.namespace_=this.parseNamespace(a)),a.imports&&typeof a.imports=="object"&&(t.imports=this.parseImportsLegacy(a.imports)),this.addAllImportsGetter(t)}return t}extractBody(e,t){let a={};for(let[s,r]of Object.entries(e))if(!(s==="kanonak"||s==="namespace"||s==="imports"))if(r&&typeof r=="object"&&r.type==="Package"){let n={};for(let[i,o]of Object.entries(r))i==="publisher"||i==="version"||i==="imports"||(n[i]=o);a[s]=n}else a[s]=r;return a}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let n=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:n,toString:()=>e,equals:i=>!i||typeof i!="object"?!1:i.publisher===r[1]&&i.package_===r[2]&&(!n||!i.version||n.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<r[1].length;o++)i=(i<<5)-i+r[1].charCodeAt(o);for(let o=0;o<r[2].length;o++)i=(i<<5)-i+r[2].charCodeAt(o);return i|0}}}}let t=e.publisher||"",a=e.package||"",s=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:t,package_:a,version:s,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:r=>!r||typeof r!="object"?!1:r.publisher===t&&r.package_===a&&(!s||!r.version||s.equals(r.version)),getHashCode:()=>{let r=0;for(let n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n);for(let n=0;n<a.length;n++)r=(r<<5)-r+a.charCodeAt(n);return r|0}}}parseVersion(e){if(typeof e=="string"){let t=e.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let t={};for(let a of e)if(!(!a||typeof a!="object"))if(a.packages&&Array.isArray(a.packages)){let s=a.publisher;if(!s)throw new Error("PublisherImport requires 'publisher' property");t[s]||(t[s]=[]);for(let r of a.packages){if(!r||typeof r!="object")continue;let n=this.parseImportFromEmbeddedObject(r,s);t[s].push(n)}}else{let s=this.parseImportFromEmbeddedObject(a,a.publisher),r=s.publisher||"";t[r]||(t[r]=[]),t[r].push(s)}return t}parseImportsLegacy(e){let t={};for(let[a,s]of Object.entries(e))Array.isArray(s)&&(t[a]=s.map(r=>this.parseImport(r,a)));return t}parseImportFromEmbeddedObject(e,t){let a=e.package;if(!a)throw new Error("Import requires 'package' property");let s=e.match;if(!s)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let n=this.parseVersion(r),i=this.parseVersionOperator(s),o=this.calculateMaxVersion(s,n),c=e.alias;return{package_:`${a} ${s} ${n.toString()}`,publisher:t,packageName:a,versionOperator:i,version:n,alias:c,minVersion:n,maxVersion:o,toEmbeddedObject:()=>{let m={package:a,match:s,version:n.toString()};return c&&(m.alias=c),m},toString:()=>c?`${a} ${s} ${n.toString()} as ${c}`:`${a} ${s} ${n.toString()}`}}buildImport(e,t,a,s){return this.parseImport({packageName:e,operator:t,version:a},s)}parseImport(e,t){if(typeof e=="string"){let o=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(o){let m=o[1].trim(),u=o[2],p=this.parseVersion(o[3].trim()),l=o[4].trim(),d=this.parseVersionOperator(u),v=this.calculateMaxVersion(u,p);return{package_:e,publisher:t,packageName:m,versionOperator:d,version:p,alias:l,minVersion:p,maxVersion:v,toEmbeddedObject:()=>{let f={package:m,match:u,version:p.toString()};return l&&(f.alias=l),f},toString:()=>`${m} ${u} ${p.toString()} as ${l}`}}let c=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let m=c[1].trim(),u=c[2],p=this.parseVersion(c[3].trim()),l=this.parseVersionOperator(u),d=this.calculateMaxVersion(u,p);return{package_:e,publisher:t,packageName:m,versionOperator:l,version:p,alias:void 0,minVersion:p,maxVersion:d,toEmbeddedObject:()=>({package:m,match:u,version:p.toString()}),toString:()=>`${m} ${u} ${p.toString()}`}}}let a=this.parseVersionOperator(e.operator||"~"),s=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",n=g(a),i=this.calculateMaxVersion(e.operator||"~",s);return{package_:e.package||"",publisher:t,packageName:r,versionOperator:a,version:s,alias:e.alias,minVersion:s,maxVersion:i,toEmbeddedObject:()=>{let o={package:r,match:n,version:s.toString()};return e.alias&&(o.alias=e.alias),o},toString:()=>`${r} ${n} ${s.toString()}`}}parseVersionOperator(e){return y(e)}calculateMaxVersion(e,t){switch(e){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let t=[];for(let[a,s]of Object.entries(e)){let r={publisher:a,packages:s.map(n=>{let i=g(n.versionOperator),o={package:n.packageName,match:i,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(o.alias=n.alias),o})};t.push(r)}return t}};export{k as a};
@@ -1 +0,0 @@
1
- import{b as f,c as i,g as p,h as d,i as y,j as s,k as l,l as g}from"./chunk-W6T7MOKY.js";function K(t){return`${t.publisher}/${t.package_}/${t.name}`}function c(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}function D(t){let e=t.version;return e&&typeof e.major=="number"?`https://${t.publisher}/${t.package_}/${e.major}.${e.minor}.${e.patch}/${t.name}`:`https://${t.publisher}/${t.package_}/${t.name}`}function b(t,e){if(!(t instanceof f))return!1;for(let n of t.statement)if(n.predicate?.subject?.name==="type"&&n instanceof s){let r=n.object;if(c(r.subject,e))return!0}return!1}function h(t,e){let n=[];for(let o of t)o instanceof i&&b(o,e)&&n.push(o);return n}function S(t,e){let n=e.version,o=n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}`:void 0;for(let r of t){if(!(r instanceof i)||r.name!==e.name)continue;let u=r.namespace||"";if(o!==void 0){if(u===o)return r}else if(u.startsWith(`${e.publisher}/${e.package_}@`))return r}}function a(t,e){for(let n of t.statement){let o=n.predicate;if(o?.subject&&c(o.subject,e))return n}}function k(t,e){let n=a(t,e);if(n&&(n instanceof p||n instanceof d||n instanceof y))return n.object}function j(t,e){let n=k(t,e);return typeof n=="string"?n:void 0}function U(t,e){let n=a(t,e);if(n instanceof s)return n.object.subject}function E(t,e){let n=a(t,e);if(n instanceof l)return n.object}function $(t,e){let n=a(t,e);return n instanceof g?n.object??[]:[]}var m=class{constructor(e,n){this.doc=e;this.broader=n}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(e){return this.broader.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,n){return this.broader.getDocumentsByNamespaceAsync(e,n)}async getHighestCompatibleVersionAsync(e,n){return this.broader.getHighestCompatibleVersionAsync(e,n)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}async getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}};export{K as a,c as b,D as c,b as d,h as e,S as f,k as g,j as h,U as i,E as j,$ as k,m as l};
@@ -1 +0,0 @@
1
- import{a as j,b as P,c as T}from"./chunk-H2LEQLVD.js";import{a as x}from"./chunk-ORFSMEMM.js";import{b as L,c as N,i as O}from"./chunk-64TVBQFR.js";import{c as h,d as g,g as K,h as I,i as D,j as R,k as S,l as w}from"./chunk-W6T7MOKY.js";var V=/\[\[([^\[\]\n]+)\]\]/g,C=/\[\[/g,$=/```[\s\S]*?```|`[^`\n]*`/g;function B(p){let e=[];for(let t of p.matchAll($))e.push([t.index,t.index+t[0].length]);return e}function U(p){if(!p||!p.includes("[["))return[];let e=B(p),t=o=>e.some(([n,s])=>o>=n&&o<s),r=new Set(A(p).map(o=>o.startOffset)),a=[];for(let o of p.matchAll(C)){let n=o.index;if(t(n)||r.has(n))continue;let s=p.slice(n,n+48).replace(/\s+/g," ").trim();a.push({startOffset:n,snippet:s})}return a}function A(p){if(!p||!p.includes("[["))return[];let e=[];for(let a of p.matchAll($))e.push([a.index,a.index+a[0].length]);let t=a=>e.some(([o,n])=>a>=o&&a<n),r=[];for(let a of p.matchAll(V)){let o=a.index;if(t(o))continue;let n=a[1],s=n.indexOf("|"),c=(s===-1?n:n.slice(0,s)).trim();if(c.length===0)continue;let m=s===-1?"":n.slice(s+1).trim(),f={reference:c,startOffset:o,endOffset:o+a[0].length};m.length>0&&(f.displayText=m),r.push(f)}return r}var _=class{constructor(e){}async parseKanonaks(e){let t=[],r=await e.getAllDocumentsAsync(),a=new L(e),o=new N(a);for(let i of r){let u=i.metadata.namespace_?.toString()??"";for(let[y,l]of Object.entries(i.body)){let k=new h,d=this.resolveCanonicalEntity(y,i,u);k.namespace=d.namespace,k.name=d.name,k.statement=[];let b=await this.parseStatements(l,i,a,o,e);k.statement.push(...b),t.push(k)}}let n=new Map,s=new Map,c=[];for(let i of t)if(i instanceof h){let u=`${i.namespace}/${i.name}`,y=n.get(u);if(y){let l=s.get(u);for(let k of i.statement){let d=v(k);l.has(d)||(l.add(d),y.statement.push(k))}}else{let l=new Set,k=[];for(let d of i.statement){let b=v(d);l.has(b)||(l.add(b),k.push(d))}i.statement=k,s.set(u,l),n.set(u,i),c.push(i)}}else c.push(i);let m=new Set;for(let i of c)if(i instanceof h){let u=i.namespace||"",y=u.indexOf("/"),l=y>=0?u.slice(0,y):"",k=y>=0?u.slice(y+1):"",d=k.indexOf("@"),b=d>=0?k.slice(0,d):k;m.add(`${l}/${b}/${i.name}`)}let f=i=>m.has(`${i.publisher}/${i.package_}/${i.name}`);for(let i of c)i instanceof h&&this.canonicalizeStatementBuiltins(i.statement,f);return c}canonicalizeStatementBuiltins(e,t){for(let r of e){let a=r.predicate?.subject;if(O(a,t),r instanceof R)r.object instanceof g&&O(r.object.subject,t);else if(r instanceof S)r.object&&this.canonicalizeStatementBuiltins(r.object.statement,t);else if(r instanceof w)for(let o of r.object??[])o instanceof g?O(o.subject,t):o instanceof j&&this.canonicalizeStatementBuiltins(o.statement,t)}}resolveCanonicalEntity(e,t,r){if(!e.includes(".")||!t.metadata?.imports)return{namespace:r,name:e};let a=e.indexOf("."),o=e.substring(0,a),n=e.substring(a+1);for(let[s,c]of Object.entries(t.metadata.imports))for(let m of c)if((m.alias??m.packageName)===o){let i=m.version;return{namespace:`${s}/${m.packageName}@${i.major}.${i.minor}.${i.patch}`,name:n}}return{namespace:r,name:e}}async parseStatements(e,t,r,a,o){let n=[];if(typeof e!="object"||e===null||Array.isArray(e))return n;for(let[s,c]of Object.entries(e))try{let m=await this.getPropertyMetadata(s,t,r,o,a);if(!m)continue;let f=await this.parsePropertyValue(s,c,m,t,r,a);f&&n.push(f)}catch(m){console.error(`Error parsing property ${s}:`,m)}return n}async getPropertyMetadata(e,t,r,a,o){let n=await r.resolveEntityAsync(e,t);if(!n)return;let s=n.entity,c=s.type?.toString()??"",m=c.includes(".")?c.substring(c.lastIndexOf(".")+1):c;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(m))return;let i=o.getPropertyTypeClassification(c),u=s.range?.toString(),y;if(i==="ObjectProperty")y="ObjectProperty";else if(i==="DatatypeProperty")y="DatatypeProperty";else{let d=u&&u.includes(".")?u.substring(u.lastIndexOf(".")+1):u??"";(u?o.isKnownXsdDatatypeName(u):!1)||d==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let l;if(u){let d=t;if(n.isImported&&n.definedInNamespace&&typeof a.getDocumentAsync=="function"){let M=await a.getDocumentAsync(n.definedInNamespace);M&&(d=M)}l=(await r.resolveEntityAsync(u,d))?.uri}return{propertyUri:n.uri.toString(),propertyType:y,range:u,rangeUri:l,isImported:n.isImported,definedInNamespace:n.definedInNamespace}}async parsePropertyValue(e,t,r,a,o,n){let s=r.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(s,t,r,a,o,n);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(s,t,r,a,o,n);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(s,t,r,a,o,n)}}async parseDatatypeValue(e,t,r,a,o,n){if(t instanceof Date)return K.parse(e,t.toISOString());if(typeof t=="string")return n.isSubstitutableDatatype(r.rangeUri)?await this.parseSubstitutableValue(e,t,a,o):K.parse(e,t);if(typeof t=="number")return I.parse(e,t);if(typeof t=="boolean"){let s=new D;return s.predicate=g.parse(e),s.object=t,s}}async parseSubstitutableValue(e,t,r,a){let o=new T;o.predicate=g.parse(e),o.object=t;for(let n of A(t)){let s=await a.resolveEntityAsync(n.reference,r),c;s&&(c=new g,c.subject=s.uri);let m={reference:n.reference,startOffset:n.startOffset,endOffset:n.endOffset};n.displayText!==void 0&&(m.displayText=n.displayText),c!==void 0&&(m.target=c),o.links.push(m)}return o}async parseObjectValue(e,t,r,a,o,n){if(typeof t=="string"){let s=await this.resolveReference(t,a,o);if(!s)return;let c=new R;return c.predicate=g.parse(e),c.object=s,c}if(typeof t=="object"&&!Array.isArray(t)){let s=new j;if(s.statement=await this.parseStatements(t,a,o,n,{}),s.statement.length>0){let f=new S;return f.predicate=g.parse(e),f.object=s,f}let c=[];for(let[f,i]of Object.entries(t))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let u=new j;u.name=f,u.statement=await this.parseStatements(i,a,o,n,{}),c.push(u)}else if(typeof i=="string"){let u=await this.resolveReference(i,a,o);u&&c.push(u)}if(c.length>0){let f=new w;return f.predicate=g.parse(e),f.object=c,f}let m=new S;return m.predicate=g.parse(e),m.object=s,m}}async parseListValue(e,t,r,a,o,n){let s=[],c=r.propertyType==="DatatypeProperty";for(let f of t){if(c&&(typeof f=="string"||typeof f=="number"||typeof f=="boolean")){let i=new P;i.value=f,s.push(i);continue}if(c&&f instanceof Date){let i=new P;i.value=f.toISOString(),s.push(i);continue}if(typeof f=="string"){let i=await this.resolveReference(f,a,o);i&&s.push(i)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let i=new j;i.statement=await this.parseStatements(f,a,o,n,{}),s.push(i)}}let m=new w;return m.predicate=g.parse(e),m.object=s,m}async resolveReference(e,t,r){let a=await r.resolveEntityAsync(e,t);if(a){let n=new g;return n.subject=a.uri,n}let o=t.metadata?.namespace_;if(o){let{KanonakUri:n}=await import("./KanonakUri-4VJGV3FN.js"),s=o.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let m=e.indexOf("."),f=e.substring(0,m),i=e.substring(m+1);if(t.metadata?.imports){for(let[u,y]of Object.entries(t.metadata.imports))for(let l of y)if((l.alias??l.packageName)===f){let d=new g;return d.subject=new n(u,l.packageName,i,l.version),d}}}let c=new g;return c.subject=new n(o.publisher,o.package_,e,s),c}return null}async saveKanonaks(e,t){let r=new Map;for(let a of e)a instanceof h&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,o]of r){let n=await this.convertKanonaksToDocument(a,o),s=`${a.split("@")[0]}.yml`;await t.saveDocumentAsync(n,s)}}async serializeToYaml(e,t){let r=e.filter(n=>n instanceof h&&n.namespace===t);if(r.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let a=await this.convertKanonaksToDocument(t,r);return new x().save(a)}async convertKanonaksToDocument(e,t){let a={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let n=[];for(let s of Object.values(this.imports))n.push(...s);return n}},body:{}},o=new Map;for(let n of t){let s={};for(let c of n.statement){let[m,f]=this.convertStatementToProperty(c);m&&f!==null&&f!==void 0&&(s[m]=f),this.collectImportsFromStatement(c,e,o)}a.body[n.name]=s}return a}convertStatementToProperty(e){if(e instanceof K)return[e.predicate.subject.name,e.object];if(e instanceof I)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object];if(e instanceof R)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof w){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof S){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let r of e)r instanceof g?t.push(r.subject.name):r instanceof j&&t.push(this.convertEmbeddedKanonakToValue(r));return t}convertEmbeddedKanonakToValue(e){let t={};for(let r of e.statement){let[a,o]=this.convertStatementToProperty(r);a&&o!==null&&o!==void 0&&(t[a]=o)}return t}collectImportsFromStatement(e,t,r){}};function v(p){let e=p.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+z(p)}function z(p){return p instanceof T?"m:"+String(p.object):p instanceof K?"s:"+String(p.object):p instanceof I?"n:"+String(p.object):p instanceof D?"b:"+String(p.object):p instanceof R?"r:"+E(p.object):p instanceof S?"e:"+E(p.object):p instanceof w?"l:["+(p.object??[]).map(E).join("|")+"]":"x"}function E(p){if(!p)return"";if(p instanceof g){let e=p.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return p instanceof j?"E("+(p.statement??[]).map(v).join(";")+")":p instanceof P?"L("+String(p.value)+")":"N"}export{U as a,A as b,_ as c};
@@ -1 +0,0 @@
1
- import{c as _}from"./chunk-Q6QTQWR2.js";import{a as j,b as x}from"./chunk-H2LEQLVD.js";import{d as l,e as u,f as b,g as $,h as s,j as h}from"./chunk-64TVBQFR.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-W6T7MOKY.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let t=b(e);return this.all.has(t)?!1:(this.all.add(t),this.tripleList.push(e),P(this.byPIdx,e.p,e),P(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&P(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let t=this.byPIdx.get(e);return t?t.slice():[]}bySubjectPredicate(e,t){let r=this.bySPIdx.get(`${e}|${t}`);return r?r.slice():[]}byPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);return r?r.slice():[]}subjectsWithPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)n.add(a.s);return Array.from(n)}uriObjectsOf(e,t){let r=this.bySPIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)a.o.kind==="uri"&&n.add(a.o.key);return Array.from(n)}hasUri(e,t,r){return this.all.has(`${e}|${t}|u:${r}`)}hasTriple(e,t,r){return this.all.has(`${e}|${t}|${$(r)}`)}};function P(o,e,t){let r=o.get(e);r?r.push(t):o.set(e,[t])}var w={name:"rdfs2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.domain)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},C={name:"rdfs3",apply(o,e){let t=!1;for(let r of o.byPredicate(e.range)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,e.type,a))&&(t=!0)}return t}},A={name:"rdfs5",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subPropertyOf))i.o.kind==="uri"&&o.add(s(n,e.subPropertyOf,i.o.key))&&(t=!0)}return t}},V={name:"rdfs7",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n)){let f={s:i.s,p:a,o:i.o};o.add(f)&&(t=!0)}}return t}},W={name:"rdfs9",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},F={name:"rdfs11",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subClassOf))i.o.kind==="uri"&&o.add(s(n,e.subClassOf,i.o.key))&&(t=!0)}return t}},k=[w,C,A,V,W,F];var N={name:"prp-trp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let n of r){let a=o.byPredicate(n);for(let i of a){if(i.o.kind!=="uri")continue;let f=i.o.key;for(let c of o.bySubjectPredicate(f,n))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(s(i.s,n,c.o.key))&&(t=!0)}}return t}},D={name:"prp-symp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let n of r)for(let a of o.byPredicate(n))a.o.kind==="uri"&&o.add(s(a.o.key,n,a.s))&&(t=!0);return t}},z={name:"prp-inv1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,a,i.s))&&(t=!0)}return t}},B={name:"prp-inv2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(a))i.o.kind==="uri"&&o.add(s(i.o.key,n,i.s))&&(t=!0)}return t}},M={name:"prp-eqp1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n))o.add({s:i.s,p:a,o:i.o})&&(t=!0)}return t}},G={name:"prp-eqp2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(a))o.add({s:i.s,p:n,o:i.o})&&(t=!0)}return t}},H={name:"cax-eqc1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},J={name:"cax-eqc2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,a))o.add(s(i.s,e.type,n))&&(t=!0)}return t}},Q={name:"eq-rep-s",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a){for(let i of o.snapshot())i.s===n&&o.add({s:a,p:i.p,o:i.o})&&(t=!0);for(let i of o.snapshot())i.s===a&&o.add({s:n,p:i.p,o:i.o})&&(t=!0)}}return t}},X={name:"eq-rep-o",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===n?o.add(s(i.s,i.p,a))&&(t=!0):i.o.key===a&&o.add(s(i.s,i.p,n))&&(t=!0))}return t}},K=[N,D,z,B,M,G,H,J,Q,X];var y=class{constructor(e,t){this.store=e;this.vocabulary=t}store;vocabulary;getInstancesOfClass(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,t)}getSubclasses(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,t).filter(n=>n!==t)}getSuperclasses(e){let t=p(e);return this.store.uriObjectsOf(t,this.vocabulary.subClassOf).filter(r=>r!==t)}getTypesOfIndividual(e){return this.store.uriObjectsOf(p(e),this.vocabulary.type)}isInstanceOf(e,t){return this.store.hasUri(p(e),this.vocabulary.type,p(t))}triples(){return this.store.snapshot()}size(){return this.store.size()}};function p(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new h,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let t=new d,n=await new _().parseKanonaks(e),a=new U;for(let c of n)if(c instanceof S){let m=Y(c);if(!m)continue;for(let E of c.statement)this.emitStatement(m,E,t,a)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let f=0;for(;f<this.maxIterations;){let c=!1;for(let m of i)m.apply(t,this.vocabulary)&&(c=!0);if(!c)break;f++}return new y(t,this.vocabulary)}emitStatement(e,t,r,n){let a=Z(t);if(a){if(t instanceof I){r.add({s:e,p:a,o:{kind:"literal",lexical:t.object,datatype:"string"}});return}if(t instanceof T){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"number"}});return}if(t instanceof g){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"boolean"}});return}if(t instanceof v){let i=l(t.object.subject);r.add(s(e,a,i));return}if(t instanceof L){let i=n.next();r.add({s:e,p:a,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t.object,r,n);return}if(t instanceof q){for(let i of t.object??[])this.emitListItem(e,a,i,r,n);return}}}emitListItem(e,t,r,n,a){if(r instanceof O)n.add(s(e,t,l(r.subject)));else if(r instanceof j){let i=a.next();n.add({s:e,p:t,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r,n,a)}else if(r instanceof x){let i=typeof r.value=="number"?"number":typeof r.value=="boolean"?"boolean":"string";n.add({s:e,p:t,o:{kind:"literal",lexical:String(r.value),datatype:i}})}}emitEmbedded(e,t,r,n){let a=`_:${e}`;for(let i of t.statement)this.emitStatement(a,i,r,n)}},U=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",t=e.indexOf("@"),r=t===-1?e:e.substring(0,t),n=r.indexOf("/");if(n===-1)return null;let a=r.substring(0,n),i=r.substring(n+1);return!a||!i||!o.name?null:u(a,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,R as e};
@@ -1,2 +0,0 @@
1
- import{a as y}from"./chunk-SC5M74NM.js";import{a as C}from"./chunk-ORFSMEMM.js";import{c as d,d as k,h as v,i as P}from"./chunk-2ACBWC7K.js";import{VersionOperator as u}from"@kanonak-protocol/types/document/models/enums";var x=class{documents=new Map;documentContents=new Map;parser;constructor(t){this.parser=t}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(t){return this.documents.get(t)??null}async getDocumentsByNamespaceAsync(t,e){let r=[];for(let n of this.documents.values())n.metadata?.namespace_?.publisher===t&&n.metadata?.namespace_?.package_===e&&r.push(n);return r}async getHighestCompatibleVersionAsync(t,e){let r=[];for(let s of this.documents.values())s.metadata?.namespace_?.publisher===t&&s.metadata?.namespace_?.package_===e.packageName&&s.metadata?.namespace_?.version!==void 0&&r.push(s);if(r.length===0)return null;let n=r.filter(s=>{let a=s.metadata.namespace_.version;if(!a)return!1;switch(e.versionOperator){case u.Exact:return k(a,e.version);case u.Compatible:return v(a,e.version);case u.Major:return P(a,e.version);case u.Any:return d(a,e.minVersion)>=0;default:return!1}});return n.length===0?null:(n.sort((s,a)=>{let o=s.metadata.namespace_.version,c=a.metadata.namespace_.version;return!o&&!c?0:o?c?d(c,o):-1:1}),n[0])}async saveDocumentAsync(t,e){this.documents.set(e,t);let r=this.parser.save(t);this.documentContents.set(e,r)}async deleteDocumentAsync(t){this.documents.delete(t),this.documentContents.delete(t)}async clearNamespaceAsync(t,e){let r=[];for(let[n,s]of this.documents.entries())s.metadata?.namespace_?.publisher===t&&s.metadata?.namespace_?.package_===e&&r.push(n);for(let n of r)this.documents.delete(n),this.documentContents.delete(n)}async getAllDocumentReferencesAsync(){let t=[];for(let e of this.documents.values())e.metadata?.namespace_&&t.push({identifier:e.metadata.namespace_.toString(),uri:`kanonak://${e.metadata.namespace_}`,hasParseError:!1});return t}async getDocumentContentAsync(t){let e=this.documentContents.get(t);if(e!==void 0)return e;let r=this.documents.get(t);return r!==void 0?this.parser.save(r):null}async getDocumentUriAsync(t){let e=this.documents.get(t);return e?e.metadata?.namespace_?`kanonak://${e.metadata.namespace_}`:`kanonak://${t}`:null}};var D="https://{publisher}/index.txt",F="https://{publisher}/{package}/{version}.kan.yml",w={version:1};function K(i){return{version:1,index:D.replaceAll("{publisher}",i),package:F.replaceAll("{publisher}",i),auth:"none"}}var g=class{cache=new Map;getConfig(t){let e=this.cache.get(t);return e||(e=this.fetchConfig(t),this.cache.set(t,e),e.catch(()=>{this.cache.get(t)===e&&this.cache.delete(t)})),e}async fetchConfig(t){let e=`https://${t}/.well-known/kanonak.json`,r;try{r=await fetch(e)}catch{return w}if(r.status===404)return w;if(!r.ok)throw new Error(`Failed to fetch publisher config: ${e} (${r.status} ${r.statusText})`);let n=await r.json();if(typeof n.version!="number")throw new Error(`Invalid publisher config at ${e}: missing or invalid "version" field`);let s={version:n.version};return typeof n.index=="string"&&(s.index=n.index),typeof n.package=="string"&&(s.package=n.package),(n.auth==="none"||n.auth==="oauth"||n.auth==="bearer")&&(s.auth=n.auth),Array.isArray(n.render)&&n.render.every(a=>typeof a=="string")&&(s.render=n.render),s}resolveIndexUrl(t,e){let r=e.index??D;return A(r,{publisher:t})}resolvePackageUrl(t,e,r,n){let s=n.package??F;return A(s,{publisher:t,package:e,version:r})}};function A(i,t){let e=i;for(let[n,s]of Object.entries(t))e=e.replaceAll(`{${n}}`,s);let r=e.match(/\{[a-z]+\}/);if(r)throw new Error(`Unresolved variable ${r[0]} in URL template: ${i}`);return e}import{VersionOperator as l}from"@kanonak-protocol/types/document/models/enums";var m=class i{indexCache=new Map;configResolver;fetchFn;constructor(t){this.configResolver=t?.configResolver??new g,this.fetchFn=t?.fetchFn}async resolveVersion(t,e){let r=await this.getPackageVersions(t,e.packageName);if(r.length===0)return null;let n=r.filter(s=>this.isVersionCompatible(s,e.version,e.versionOperator));return n.length===0?null:(n.sort((s,a)=>this.compareVersionStrings(a,s)),n[0])}async getHighestVersion(t,e){let r=await this.getPackageVersions(t,e);return r.length===0?null:[...r].sort((s,a)=>this.compareVersionStrings(a,s))[0]}async listLatestPackages(t){let e=await this.getIndex(t),r=[];for(let[n,s]of e){if(s.length===0)continue;let a=[...s].sort((o,c)=>this.compareVersionStrings(c,o));r.push({packageName:n,version:a[0]})}return r.sort((n,s)=>n.packageName.localeCompare(s.packageName)),r}async getPackageUrl(t,e,r){let n=await this.configResolver.getConfig(t);return this.configResolver.resolvePackageUrl(t,e,r,n)}async getPackageVersions(t,e){return(await this.getIndex(t)).get(e)??[]}getIndex(t){let e=this.indexCache.get(t);return e||(e=this.fetchIndex(t),this.indexCache.set(t,e),e.catch(()=>{this.indexCache.get(t)===e&&this.indexCache.delete(t)})),e}async fetchIndex(t){let e=await this.configResolver.getConfig(t),r=this.configResolver.resolveIndexUrl(t,e),n=this.fetchFn?await this.fetchFn(r,t):await fetch(r);if(!n.ok)throw new Error(`Failed to fetch publisher index: ${r} (${n.status} ${n.statusText})`);let s=await n.text();return i.parseIndex(s)}static parseIndex(t){let e=new Map;for(let r of t.split(`
2
- `)){let n=r.trim();if(!n||n.startsWith("#"))continue;let s=n.indexOf("/");if(s===-1)continue;let a=n.substring(0,s),o=n.substring(s+1);if(!a||!o)continue;let c=e.get(a);c?c.push(o):e.set(a,[o])}return e}isVersionCompatible(t,e,r){let n=i.parseVersion(t);if(!n)return!1;switch(r){case l.Any:return!0;case l.Exact:return n.major===e.major&&n.minor===e.minor&&n.patch===e.patch;case l.Compatible:return n.major===e.major&&n.minor===e.minor&&n.patch>=e.patch;case l.Major:return n.major!==e.major?!1:n.minor>e.minor?!0:n.minor===e.minor?n.patch>=e.patch:!1;default:return!1}}static parseVersion(t){let e=t.split(".");if(e.length<2)return null;let r=parseInt(e[0],10),n=parseInt(e[1],10),s=e.length>=3?parseInt(e[2],10):0;return isNaN(r)||isNaN(n)||isNaN(s)?null:{major:r,minor:n,patch:s}}compareVersionStrings(t,e){let r=i.parseVersion(t),n=i.parseVersion(e);return!r&&!n?0:r?n?r.major!==n.major?r.major-n.major:r.minor!==n.minor?r.minor-n.minor:r.patch-n.patch:1:-1}};var b=class{parser=new C;publisherIndex;documents=new Map;contentCache=new Map;fetchFn;onFetch;getFromCache;constructor(t){this.onFetch=t?.onFetch,this.getFromCache=t?.getFromCache,this.fetchFn=t?.fetchFn,this.publisherIndex=t?.fetchFn?new m({fetchFn:t.fetchFn}):new m}async getHighestCompatibleVersionAsync(t,e){let r=await this.publisherIndex.resolveVersion(t,e);if(!r)return null;let n=`${t}/${e.packageName}@${r}`,s=this.documents.get(n);if(s)return s;if(this.getFromCache){let p=this.getFromCache(t,e.packageName,r);if(p){let f=this.parser.parse(p);return y(f,t,e.packageName,r),this.documents.set(n,f),this.contentCache.set(n,p),f}}let a=await this.publisherIndex.getPackageUrl(t,e.packageName,r),o=this.fetchFn?await this.fetchFn(a,t):await fetch(a);if(!o.ok)throw new Error(`Failed to fetch Kanonak package: ${a} (${o.status} ${o.statusText})`);let c=await o.text(),h=this.parser.parse(c);return y(h,t,e.packageName,r),this.onFetch&&this.onFetch(t,e.packageName,r,c),this.documents.set(n,h),this.contentCache.set(n,c),h}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(t){return this.documents.get(t)??null}async getDocumentsByNamespaceAsync(t,e){return Array.from(this.documents.values()).filter(r=>{let n=r.metadata.namespace_;return n&&n.publisher===t&&n.package_===e})}async saveDocumentAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async deleteDocumentAsync(t){throw new Error("HttpKanonakDocumentRepository is read-only")}async clearNamespaceAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(t){return this.contentCache.get(t)??null}async getDocumentUriAsync(t){let e=t.match(/^(.+?)\/(.+?)@(.+)$/);if(!e)return null;let[,r,n,s]=e;return this.publisherIndex.getPackageUrl(r,n,s)}};export{x as a,K as b,g as c,m as d,b as e};
File without changes