@kanonak-protocol/sdk 3.77.0 → 4.0.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 (43) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/canonical/CanonicalHash.d.ts +8 -0
  3. package/dist/canonical/Datatypes.d.ts +98 -0
  4. package/dist/canonical/index.d.ts +2 -1
  5. package/dist/{chunk-RVOMWGIN.js → chunk-4OSNT57C.js} +1 -1
  6. package/dist/{chunk-KXVSGB6Q.js → chunk-6I4BYZVA.js} +1 -1
  7. package/dist/{chunk-Z5ELOT2C.js → chunk-NC3FSY3R.js} +1 -1
  8. package/dist/{chunk-XQS5LDSO.js → chunk-PBNVHBS3.js} +1 -1
  9. package/dist/chunk-T3JR2SV6.js +1 -0
  10. package/dist/chunk-V3YPCUA6.js +84 -0
  11. package/dist/chunk-VNKX52D5.js +2 -0
  12. package/dist/chunk-WUAKDYY6.js +1 -0
  13. package/dist/{chunk-IOMNZBK4.js → chunk-XYEY6HUC.js} +1 -1
  14. package/dist/{chunk-LKBG2MK6.js → chunk-YCV4H6H5.js} +1 -1
  15. package/dist/{chunk-PJMOM5H7.js → chunk-YI5GLYMB.js} +1 -1
  16. package/dist/{chunk-ATH6636H.js → chunk-YWUKDEZA.js} +1 -1
  17. package/dist/{chunk-XWRVENU6.js → chunk-ZRMF5QLN.js} +1 -1
  18. package/dist/chunk-ZYAABYDS.js +1 -0
  19. package/dist/index.d.ts +3 -2
  20. package/dist/index.js +26 -26
  21. package/dist/kanonaks/LiteralKanonak.d.ts +4 -0
  22. package/dist/parsing/KanonakObjectParser.d.ts +13 -0
  23. package/dist/parsing/index.js +1 -1
  24. package/dist/reasoning/index.js +1 -1
  25. package/dist/repositories/browser.js +1 -1
  26. package/dist/repositories/index.js +1 -1
  27. package/dist/resolution/index.js +1 -1
  28. package/dist/search/index.js +1 -1
  29. package/dist/server/index.js +1 -1
  30. package/dist/statements/ScalarStatement.d.ts +14 -0
  31. package/dist/transformations/index.js +1 -1
  32. package/dist/uri-helpers/index.js +1 -1
  33. package/dist/validation/IKanonakObjectValidator.d.ts +6 -0
  34. package/dist/validation/KanonakObjectValidator.d.ts +20 -2
  35. package/dist/validation/index.d.ts +1 -1
  36. package/dist/validation/index.js +1 -1
  37. package/dist/validation/rules/repository/DiamondNameClashRule.d.ts +8 -0
  38. package/package.json +2 -2
  39. package/dist/chunk-CG43Z65M.js +0 -2
  40. package/dist/chunk-IUZZDC2U.js +0 -1
  41. package/dist/chunk-NPEGVH4R.js +0 -84
  42. package/dist/chunk-TJPQETHV.js +0 -1
  43. package/dist/chunk-W6T7MOKY.js +0 -1
@@ -1,84 +0,0 @@
1
- import{d as T}from"./chunk-SHDHMKMJ.js";import{a as D,b as je,c as qe,d as Ye,f as A}from"./chunk-IUZZDC2U.js";import{a as Be}from"./chunk-TJPQETHV.js";import{a as H,d as M,e as Ge,f as Ze,g as w,h as Je}from"./chunk-Z5ELOT2C.js";import{a as _,d as E,f as N,h as we,i as C,j as U,k as V,l as O,m as S,n as L}from"./chunk-XQS5LDSO.js";import{a as j,b as x,c as ze}from"./chunk-IOMNZBK4.js";import{c as I,d as W,k as Fe,l as Xe}from"./chunk-W6T7MOKY.js";import{e as v}from"./chunk-2ACBWC7K.js";var q=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(n=>(n.Warning="Warning",n.Error="Error",n))(b||{});var h=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 xe=class y{resolvedDocuments=[];currentEntityPath;withPath(e){let n=new y;return n.resolvedDocuments=this.resolvedDocuments,n.currentEntityPath=e,n}};var Ue=class{constructor(e){this.underlying=e;this.repository=new Le(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new A().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let n=this.importClosureCache.get(e);return n||(n=this.computeImportClosure(e),this.importClosureCache.set(e,n),n)}async getClassDeclarations(e){let n=this.classDeclarationsCache.get(e);return n||(n=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,n),n)}async getPropertyNames(e){let n=this.propertyNamesCache.get(e);return n||(n=this.computePropertyNames(e),this.propertyNamesCache.set(e,n),n)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let n=new Set([e]),t=[e],o=await this.buildDocsByIdIndex();for(;t.length>0;){let a=t.shift(),r=o.get(a);if(r?.metadata.imports)for(let[i,s]of Object.entries(r.metadata.imports))for(let c of s){let p=await this.repository.getHighestCompatibleVersionAsync(i,c);if(!p)continue;let l=_e(p);!l||n.has(l)||(n.add(l),t.push(l))}}return n}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),n=new Map;for(let t of e){let o=_e(t);o&&n.set(o,t)}return n}async computeClassDeclarations(e){let n=await this.findDocById(e),t=new Map;if(!n)return t;for(let[o,a]of Object.entries(n.body)){if(!Qe(a))continue;let r=a,i=et(r,"type");if(i==="Class"||i?.endsWith(".Class")){let s=ut(r);t.set(o,s)}}return t}async computePropertyNames(e){let n=await this.findDocById(e),t=new Set;if(!n)return t;for(let[o,a]of Object.entries(n.body)){if(!Qe(a))continue;let i=et(a,"type");(i==="ObjectProperty"||i?.endsWith(".ObjectProperty")||i==="DatatypeProperty"||i?.endsWith(".DatatypeProperty")||i==="AnnotationProperty"||i?.endsWith(".AnnotationProperty")||i==="Property"||i?.endsWith(".Property"))&&t.add(o)}return t}async findDocById(e){let n=await this.getAllDocuments();for(let t of n)if(_e(t)===e)return t}};function _e(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}function Qe(y){return typeof y=="object"&&y!==null&&!Array.isArray(y)}function et(y,e){if(e in y)return tt(y[e]);for(let n of Object.keys(y))if(n.endsWith(`.${e}`))return tt(y[n])}function tt(y){return Array.isArray(y)?y.length>0?String(y[0]):void 0:y==null?void 0:String(y)}function ut(y){let e=y.subClassOf;if(e===void 0){for(let n of Object.keys(y))if(n.endsWith(".subClassOf")){e=y[n];break}}return j(e)}var Le=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,n){let t=`${e}/${n}`,o=this.byNamespaceCache.get(t);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,n),this.byNamespaceCache.set(t,o),o)}getHighestCompatibleVersionAsync(e,n){let t=n.version,o=t?`${t.major}.${t.minor}.${t.patch}`:"",a=`${e}/${n.packageName}@${n.versionOperator}:${o}`,r=this.highestVersionCache.get(a);return r||(r=this.inner.getHighestCompatibleVersionAsync(e,n),this.highestVersionCache.set(a,r),r)}saveDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}deleteDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}clearNamespaceAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var z=class y{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 n=[];for(let[t,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(t,o,n);return n}validateEntity(e,n,t){for(let[o,a]of Object.entries(n)){let r=a?.toString()??"";if(r&&y.NAMESPACE_PREFIX_PATTERN.test(r)){let i=this.getSuggestionForPrefixedValue(r),s=e.split(".")[0],c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=o,c.expectedValue=i,c.message=`Invalid namespace prefix '${r}'. Use '${i}' without prefix.`,c.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(c)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(`${e}.${o}`,a,t)}}getSuggestionForPrefixedValue(e){let n=e.toLowerCase();if(n==="rdfs:class"||n==="owl:class")return"Class";if(n==="rdfs:property"||n==="rdf:property")return"DatatypeProperty or ObjectProperty";if(n.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var Y=class y{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 n=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,a]of Object.entries(e.body)){let r=y.VALID_AUGMENTATION_PATTERN.test(o);if(!r&&!t&&y.RESERVED_WORDS.has(o.toLowerCase())){let i=new h;i.ruleType=this.ruleName,i.severity="Error",i.entityName=o,i.message=`Entity name '${o}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",n.push(i);continue}if(!r&&!y.VALID_NAME_PATTERN.test(o)){let i;/^\d/.test(o)?i="Entity names must start with a letter, not a number.":o.includes(" ")?i="Entity names cannot contain spaces. Use camelCase or underscores instead.":i="Entity names must start with a letter and contain only letters, numbers, and underscores.";let s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=o,s.message=`Invalid entity name '${o}'. ${i}`,s.suggestion=i,n.push(s)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validatePropertyNames(o,a,n)}return n}validatePropertyNames(e,n,t){for(let o of Object.keys(n))if(!y.VALID_PROPERTIES.has(o)&&!y.VALID_PROPERTY_NAME_PATTERN.test(o)){let a=new h;a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=o,a.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,a.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(a)}}};var G=class y{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 n=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return n;let t=this.isPropertyDefinedAsClass(e);for(let[o,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let r=a,i=r.type;if(i){let s=[];if(Array.isArray(i))for(let c of i){let p=c?.toString();p&&p==="Property"&&!t&&s.push(p)}else{let c=i?.toString();c&&c==="Property"&&!t&&s.push(c)}for(let c of s){let p=this.getPropertyValue(r,"range"),l=this.determinePropertyType(p),m=new h;m.ruleType=this.ruleName,m.severity="Error",m.entityName=o,m.propertyName="type",m.actualValue=c,m.expectedValue=l,m.message=`Invalid property type '${c}'. Use '${l}' instead.`,m.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",n.push(m)}}}return n}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":y.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,n){let t=e[n];return t?t.toString():null}isPropertyDefinedAsClass(e){let n=e.body.Property;if(n&&typeof n=="object"&&!Array.isArray(n)){let o=n.type;if(o){let a=o.toString();return a==="Class"||a.endsWith(".Class")}}return!1}};var Z=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let n=[];for(let[t,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||t.includes("."))continue;let a=o,r="type"in a,i=a.type?.toString().trim();if(!r||!i){let s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=t,s.propertyName="type",s.message=`Subject Kanonak '${t}' must have a 'type' property.`,s.suggestion=`Add a type statement like:
2
- type: Scene
3
-
4
- Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,s.expectedValue="A valid class name (Scene, Character, Story, etc.)",n.push(s)}}return n}};var J=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,n){let t=[],o=new x(n),a=await this.buildPropertyRangeMap(e,o);for(let[r,i]of Object.entries(e.body))typeof i=="object"&&i!==null&&!Array.isArray(i)&&await this.checkEmbeddedTypes(r,i,void 0,a,o,e,t,0);return t}pickRange(e,n,t){if(e.length===0)return;if(e.length===1)return e[0].range;let o=n.indexOf(".");if(o>0){let a=n.substring(0,o),r=e.find(i=>i.declaringAlias===a);if(r)return r.range}if(t){let a=this.localName(t),r=e.find(i=>this.localName(i.domain)===a);if(r)return r.range}return e[0].range}async checkEmbeddedTypes(e,n,t,o,a,r,i,s){if(s>0){let p=n.type;if(p!=null){let l=await this.validateEmbeddedType(e,String(p),t,a,r);l&&i.push(l)}}let c=n.type!==void 0&&n.type!==null?String(n.type):void 0;for(let[p,l]of Object.entries(n)){let m=this.localName(p),u=o.get(m),d=(u!==void 0?this.pickRange(u,p,c):void 0)??t;if(typeof l=="object"&&l!==null)if(Array.isArray(l))for(let k=0;k<l.length;k++){let g=l[k];typeof g=="object"&&g!==null&&!Array.isArray(g)&&await this.checkEmbeddedTypes(`${e}.${p}[${k}]`,g,d,o,a,r,i,s+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,l,d,o,a,r,i,s+1)}}async validateEmbeddedType(e,n,t,o,a){if(n.length===0||!t)return null;let r=this.localName(n),i=this.localName(t);if(i==="Resource"||i==="Class")return null;let s=e.split(".")[0];if(r===i){let p=new h;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=s,p.propertyName=e,p.actualValue=n,p.expectedValue=t,p.message=`Embedded object at '${e}' declares 'type: ${n}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,p.suggestion=`Remove the 'type: ${n}' line, or keep it if explicitness is preferred over concision.`,p}if(await o.isSubclassOfAsync(n,t,a)||(r!==n||i!==t)&&await o.isSubclassOfAsync(r,i,a))return null;let c=new h;return c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=n,c.expectedValue=t,c.message=`Embedded object at '${e}' has 'type: ${n}', which is not a subclass of the parent property's range '${t}'.`,c.suggestion=`Either remove the 'type: ${n}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${n}' class definition so the relationship holds.`,c}localName(e){let n=e.lastIndexOf(".");return n<0||n===e.length-1?e:e.substring(n+1)}async buildPropertyRangeMap(e,n){let t=new Map,o=await n.buildEntityIndexAsync(e),a=new Map;for(let[r,i]of o){let s=i.entity.type;if(s==null)continue;let c=String(s),p=this.localName(c);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let m=i.entity.range;if(m==null)continue;let u=String(m);if(u.length===0)continue;let f=i.entity.domain,d=f!=null?String(f):"",k=i.uri.toString(),g=a.get(k),P=r.includes(".");(!g||P&&!g.entityName.includes("."))&&a.set(k,{entityName:r,domain:d,range:u})}for(let r of a.values()){let i=this.localName(r.entityName),s=r.entityName.indexOf("."),c=s>0?r.entityName.substring(0,s):void 0,p=t.get(i)??[];p.push({domain:r.domain,range:r.range,declaringAlias:c}),t.set(i,p)}return t}};import{VersionOperator as Ne}from"@kanonak-protocol/types/document/models/enums";var Q=class{ruleName="ImportExistence";async validateAsync(e,n){let t=[];if(!e.metadata?.imports)return t;let o=await n.getAllDocumentsAsync();for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r)if(!await n.getHighestCompatibleVersionAsync(a,i)){let c=await this.determineImportErrorAsync(n,a,i,o),p=new h;p.ruleType=this.ruleName,p.severity="Error",p.message=c.message,p.suggestion=c.suggestion,p.entityName=`Import: ${a}/${i.packageName}`,p.actualValue=i.toString(),p.expectedValue=c.expectedValue,t.push(p)}return t}async determineImportErrorAsync(e,n,t,o){let a=await e.getDocumentsByNamespaceAsync(n,t.packageName);if(a.length===0){let c=o.filter(u=>u.metadata.namespace_?.publisher===n).map(u=>u.metadata.namespace_.package_).filter((u,f,d)=>d.indexOf(u)===f),p=this.findSimilarPackages(t.packageName,c),l=`Import '${n}/${t.package_}' not found - package does not exist`,m=p.length>0?`Did you mean: ${p.slice(0,3).join(", ")}?`:c.length>0?`Available packages in ${n}: ${c.slice(0,5).join(", ")}`:`No packages found for publisher '${n}'. Verify the publisher name is correct.`;return{message:l,suggestion:m,expectedValue:"Existing package"}}let i=a.filter(c=>c.metadata.namespace_?.version).map(c=>c.metadata.namespace_.version.toString()).sort().join(", "),s=this.getAcceptableVersionRange(t);return{message:`Import '${n}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${s}`,expectedValue:s}}getAcceptableVersionRange(e){switch(e.versionOperator){case Ne.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Ne.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Ne.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Ne.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,n){if(n.length===0)return[];let t=n.filter(r=>r.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(r.toLowerCase()));if(t.length>0)return t.sort((r,i)=>r.length-i.length);let o=n.map(r=>({package:r,distance:this.levenshteinDistance(e.toLowerCase(),r.toLowerCase())})).sort((r,i)=>r.distance-i.distance),a=Math.max(3,Math.floor(e.length*.4));return o.filter(r=>r.distance<=a).map(r=>r.package)}levenshteinDistance(e,n){if(!e||e.length===0)return n?.length??0;if(!n||n.length===0)return e.length;let t=e.length,o=n.length,a=Array(t+1).fill(null).map(()=>Array(o+1).fill(0));for(let r=0;r<=t;r++)a[r][0]=r;for(let r=0;r<=o;r++)a[0][r]=r;for(let r=1;r<=t;r++)for(let i=1;i<=o;i++){let s=e[r-1]===n[i-1]?0:1;a[r][i]=Math.min(Math.min(a[r-1][i]+1,a[r][i-1]+1),a[r-1][i-1]+s)}return a[t][o]}};var ee=class{ruleName="UnresolvedReference";async validateAsync(e,n){let t=[],o=new x(n),a=await o.buildEntityIndexAsync(e),r=new Set;for(let[i,s]of a.entries()){let c=s.entity.type;if(c){let p=c.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&r.add(i)}}for(let[i,s]of Object.entries(e.body)){if(!s||typeof s!="object"||Array.isArray(s))continue;let c=s,p=this.getPropertyValue(c,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[l,m]of Object.entries(c))l==="type"||l==="label"||l==="comment"||!(r.has(l)||Array.from(r).some(f=>f.endsWith(`.${l}`)))||await this.validateReferenceValue(i,l,m,e,o,t)}return t}async validateReferenceValue(e,n,t,o,a,r){if(t!=null){if(typeof t=="string")await a.resolveEntityAsync(t,o)||r.push(this.createUnresolvedReferenceError(e,n,t));else if(Array.isArray(t))for(let i=0;i<t.length;i++){let s=t[i];typeof s=="string"&&(await a.resolveEntityAsync(s,o)||r.push(this.createUnresolvedReferenceError(e,`${n}[${i}]`,s)))}}}createUnresolvedReferenceError(e,n,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`,a=new h;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=n,a.actualValue=t,a.message=`Reference to '${t}' could not be resolved`,a.suggestion=o,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,n){let t=e[n];return t?t.toString():null}};var te=class{ruleName="ClassHierarchyCycle";async validateAsync(e,n){let t=[],o=new Map,a=new Set;await this.buildClassHierarchy(e,n,o,a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type,p=s.subClassOf;if(c?.toString()==="Class"&&p){let l=r,m=this.detectCycle(l,o);if(m){let u=m.join(" \u2192 "),f=new h;f.ruleType=this.ruleName,f.severity="Error",f.message=`Circular class hierarchy detected: ${u}`,f.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",f.entityName=l,f.propertyName="subClassOf",f.actualValue=u,t.push(f);break}}}return t}async buildClassHierarchy(e,n,t,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type,p=s.subClassOf;if(c?.toString()==="Class"&&p){let l=j(p);l.length>0&&t.set(r,l)}}if(e.metadata?.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);c&&await this.buildClassHierarchy(c,n,t,o)}}}detectCycle(e,n){let t=[],o=new Set;return this.detectCycleRecursive(e,n,t,o)}detectCycleRecursive(e,n,t,o){if(t.includes(e)){let r=t.indexOf(e),i=t.slice(r);return i.push(e),i}if(o.has(e))return null;t.push(e),o.add(e);let a=n.get(e);if(a)for(let r of a){let i=this.detectCycleRecursive(r,n,t,o);if(i)return i}return t.pop(),null}};var ne=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,n){let t=[],o=new Map,a=new Set;await this.buildPropertyHierarchy(e,n,o,a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)&&i.subPropertyOf){let p=r,l=this.detectCycle(p,o);if(l){let m=l.join(" \u2192 "),u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular property hierarchy detected: ${m}`,u.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",u.entityName=p,u.propertyName="subPropertyOf",u.actualValue=m,t.push(u);break}}return t}async buildPropertyHierarchy(e,n,t,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type;if(c){let p=c.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let l=s.subPropertyOf;if(l){let m=j(l);m.length>0&&t.set(r,m)}}}}if(e.metadata?.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);c&&await this.buildPropertyHierarchy(c,n,t,o)}}}detectCycle(e,n){let t=[],o=new Set;return this.detectCycleRecursive(e,n,t,o)}detectCycleRecursive(e,n,t,o){if(t.includes(e)){let r=t.indexOf(e),i=t.slice(r);return i.push(e),i}if(o.has(e))return null;t.push(e),o.add(e);let a=n.get(e);if(a)for(let r of a){let i=this.detectCycleRecursive(r,n,t,o);if(i)return i}return t.pop(),null}};var oe=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,n){let t=[];for(let[o,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let r=a,i=r.type?.toString();if(i==="DatatypeProperty"||i==="ObjectProperty"||i?.endsWith(".DatatypeProperty")||i?.endsWith(".ObjectProperty")){let s="range"in r,c=r.range?.toString().trim();if(!s||!c){let p=new h;p.ruleType=this.ruleName,p.severity="Error",p.entityName=o,p.propertyName="range",p.message=`Property '${o}' must have a 'range' defined.`,p.suggestion=i==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=i==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(p)}}}return t}};var re=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,n){let t=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isClassLikeType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=j(r.subClassOf);for(let c=0;c<s.length;c++){let p=s[c];if(this.builtInClasses.has(p)||o.has(p))continue;if(!await this.isClassAvailableInImports(e,n,p)){let m=s.length>1?`[${c}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Class '${p}' referenced in subClassOf${m} is not defined or imported`,u.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,u.entityName=a,u.propertyName="subClassOf",u.actualValue=p,u.expectedValue="Defined or imported class",t.push(u)}}}return t}async isClassAvailableInImports(e,n,t){if(!e.metadata.imports)return!1;let o=null,a=t;if(t.includes(".")){let r=t.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:t,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(this.isClassLikeType(f))return!0}let m=new Set;if(await this.isClassAvailableInImportsRecursive(c,n,p,m))return!0}}return!1}async isClassAvailableInImportsRecursive(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isClassLikeType(m))return!0}if(await this.isClassAvailableInImportsRecursive(c,n,t,o))return!0}}return!1}};var ie=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,n){let t=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=j(r.subPropertyOf);for(let c=0;c<s.length;c++){let p=s[c];if(this.builtInProperties.has(p)||o.has(p))continue;if(!await this.isPropertyAvailableInImports(e,n,p)){let m=s.length>1?`[${c}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${p}' referenced in subPropertyOf${m} is not defined or imported`,u.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,u.entityName=a,u.propertyName="subPropertyOf",u.actualValue=p,u.expectedValue="Defined or imported property",t.push(u)}}}return t}async isPropertyAvailableInImports(e,n,t){if(!e.metadata.imports)return!1;let o=null,a=t;if(t.includes(".")){let r=t.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:t,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(f==="DatatypeProperty"||f==="ObjectProperty"||f==="AnnotationProperty")return!0}let m=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,n,p,m))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(c,n,t,o))return!0}}return!1}};var ae=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,n){let t=[],o=e.metadata.namespace_?.toString();if(!o)return t;let a=new Map,r=new Set;await this.buildImportGraph(e,n,a,r);let i=this.detectCycle(o,a);if(i){let s=i.join(" \u2192 "),c=new h;c.ruleType=this.ruleName,c.severity="Error",c.message=`Circular namespace import detected: ${s}`,c.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",c.entityName="imports",c.propertyName="imports",c.actualValue=s,t.push(c)}return t}async buildImportGraph(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(!(!a||o.has(a))&&(o.add(a),e.metadata.imports)){let r=[];for(let[i,s]of Object.entries(e.metadata.imports))for(let c of s){let p=`${i}/${c.packageName}@${c.version}`;r.push(p);let l=await n.getHighestCompatibleVersionAsync(i,c);l&&await this.buildImportGraph(l,n,t,o)}r.length>0&&t.set(a,r)}}detectCycle(e,n){let t=[],o=new Set;return this.detectCycleRecursive(e,n,t,o)}detectCycleRecursive(e,n,t,o){let a=t.indexOf(e);if(a>=0){let i=t.slice(a);return i.push(e),i}if(o.has(e))return null;t.push(e),o.add(e);let r=n.get(e);if(r)for(let i of r){let s=this.detectCycleRecursive(i,n,t,o);if(s)return s}return t.pop(),null}};var se=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,n,t){let o=[],a=new Set,r=t?await this.closurePropertyNamesViaCache(e,t):void 0,i=t?await this.aliasClosurePropertyNamesViaCache(e,t):void 0;for(let[s,c]of Object.entries(e.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let l=c.type?.toString();this.isPropertyType(l)&&a.add(s)}for(let[s,c]of Object.entries(e.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let p=c,l=p.type?.toString();if(this.isPropertyType(l)||this.isClassType(l))continue;for(let[m,u]of Object.entries(p)){if(!m||this.metadataKeys.has(m))continue;let f=m,d=null;if(m.includes(".")){let g=m.lastIndexOf(".");d=m.substring(0,g),f=m.substring(g+1)}if(a.has(f))continue;if(!await this.isPropertyAvailable(e,n,f,d,r,i)){let g=new h;g.ruleType=this.ruleName,g.severity="Error",g.message=`Property '${m}' is not defined or imported`,g.suggestion=d?`The property '${f}' is not found in the imported namespace with alias '${d}'.
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 '${m}' is not defined in this namespace or any imported namespace.
15
- 1. Define '${m}' as an ObjectProperty or DatatypeProperty in this namespace, OR
16
- 2. Import the namespace that contains '${m}', OR
17
- 3. Use a qualified reference like 'alias.${m}' if already imported with an alias`,g.entityName=s,g.propertyName=m,g.actualValue=u?.toString(),g.expectedValue="A defined or imported property",o.push(g)}}}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,n,t,o,a,r){if(a!==void 0&&r!==void 0){if(o===null)return a.has(t);let i=r.get(o);return i?i.has(t):!1}return await this.isPropertyAvailableInImports(e,n,t,o)}async closurePropertyNamesViaCache(e,n){let t=new Set,o=nt(e);if(!o)return t;let a=await n.getImportClosure(o);for(let r of a)if(r!==o)for(let i of await n.getPropertyNames(r))t.add(i);return t}async aliasClosurePropertyNamesViaCache(e,n){let t=new Map;if(!e.metadata.imports)return t;for(let[o,a]of Object.entries(e.metadata.imports))for(let r of a){if(!r.alias)continue;let i=await n.repository.getHighestCompatibleVersionAsync(o,r);if(!i)continue;let s=nt(i);if(!s)continue;let c=await n.getImportClosure(s),p=t.get(r.alias)??new Set;for(let l of c)for(let m of await n.getPropertyNames(l))p.add(m);t.set(r.alias,p)}return t}async isPropertyAvailableInImports(e,n,t,o){if(!e.metadata.imports)return!1;for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){if(o!==null&&i.alias!==o)continue;let s=await n.getHighestCompatibleVersionAsync(a,i);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let m=c.type?.toString();if(this.isPropertyType(m))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,n,t,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isPropertyType(m))return!0}if(await this.isPropertyAvailableInImportsRecursive(c,n,t,o))return!0}}return!1}};function nt(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var ce=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,n){let t=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isPropertyType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=i.type?.toString();if(!this.isPropertyType(s)&&!this.isClassType(s))continue;for(let[c,p]of Object.entries(i)){if(!c||this.metadataKeys.has(c))continue;let l=c,m=null;if(c.includes(".")){let f=c.lastIndexOf(".");m=c.substring(0,f),l=c.substring(f+1)}if(o.has(l))continue;if(!await this.isPropertyAvailableInImports(e,n,l,m)){let f=this.isClassType(s)?"class":"property",d=new h;d.ruleType=this.ruleName,d.severity="Error",d.message=`Property '${c}' used on ${f} '${a}' is not defined or imported`,d.suggestion=m?`The property '${l}' is not found in the imported namespace with alias '${m}'.
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 '${c}' is not defined in this namespace or any imported namespace.
21
- 1. Define '${c}' as an ObjectProperty or DatatypeProperty in this namespace, OR
22
- 2. Import the namespace that contains '${c}', OR
23
- 3. Use a qualified reference like 'alias.${c}' if already imported with an alias`,d.entityName=a,d.propertyName=c,d.actualValue=p?.toString(),d.expectedValue="A defined or imported property",t.push(d)}}}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,n,t,o){if(!e.metadata.imports)return!1;for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){if(o!==null&&i.alias!==o)continue;let s=await n.getHighestCompatibleVersionAsync(a,i);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let m=c.type?.toString();if(this.isPropertyType(m))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,n,t,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isPropertyType(m))return!0}if(await this.isPropertyAvailableInImportsRecursive(c,n,t,o))return!0}}return!1}};var pe=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,n){let t=[],o=new Set,a=[];for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let s=i,c=!1,p=s.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="DatatypeProperty"){c=!0;break}}else p?.toString()==="DatatypeProperty"&&(c=!0);if(c){a.push(r);let l=this.getPropertyValue(s,"range");l&&this.xsdTypes.has(l)&&o.add(l)}}if(o.size>0&&!await this.checkXsdImportAsync(e.metadata,n)){let i=Array.from(o).sort().join(", "),s=a.sort().join(", "),c=new h;c.ruleType=this.ruleName,c.severity="Error",c.message=`XSD namespace not imported but XSD types are used: ${i}`,c.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${s}`,c.entityName="imports",t.push(c)}return t}async checkXsdImportAsync(e,n,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[,a]of Object.entries(e.imports))for(let r of a)if(r.packageName==="xsd"||r.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[a,r]of Object.entries(e.imports))for(let i of r){let s=await n.getHighestCompatibleVersionAsync(a,i);if(s?.metadata&&await this.checkXsdImportAsync(s.metadata,n,t))return!0}return!1}getPropertyValue(e,n){return e[n]?.toString()}};var le=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,n){let t=[],{entitySources:o,importPaths:a}=await this.buildEntitySourceMapAsync(e,n),r=await this.buildDatatypePropertyNamesAsync(e,n);for(let[i,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.validateEntityReferences(i,s,o,a,r,e,t);return t}async buildEntitySourceMapAsync(e,n){let t=new Map,o=new Set,a=new Map;for(let r of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";t.has(r)||t.set(r,[]),t.get(r).push(`(local:${i})`)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(c,t,o,a,[p],n)}}return{entitySources:t,importPaths:a}}async collectEntitiesRecursivelyAsync(e,n,t,o,a,r){let i=e.metadata.namespace_?.toString()??"";if(!t.has(i)){t.add(i),o.has(i)||o.set(i,a);for(let s of Object.keys(e.body)){n.has(s)||n.set(s,[]);let c=n.get(s);c.includes(i)||c.push(i)}if(e.metadata.imports)for(let[s,c]of Object.entries(e.metadata.imports))for(let p of c){let l=await r.getHighestCompatibleVersionAsync(s,p);if(l){let m=l.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(l,n,t,o,[...a,m],r)}}}}async buildDatatypePropertyNamesAsync(e,n){let t=new Set,o=new Set;if(await this.collectDatatypePropertiesAsync(e,t,o,n),e.metadata.imports)for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){let s=await n.getHighestCompatibleVersionAsync(a,i);s&&await this.collectDatatypePropertiesAsync(s,t,o,n)}return t}async collectDatatypePropertiesAsync(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(!t.has(a)){t.add(a);for(let[r,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let s=i.type;if(typeof s!="string")continue;(s.includes(".")?s.substring(s.lastIndexOf(".")+1):s)==="DatatypeProperty"&&n.add(r)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await o.getHighestCompatibleVersionAsync(r,s);c&&await this.collectDatatypePropertiesAsync(c,n,t,o)}}}validateEntityReferences(e,n,t,o,a,r,i){for(let[s,c]of Object.entries(n)){let p=s;if(p&&!p.includes(".")){let l=t.get(p);if(l&&l.length>1&&!l.some(u=>u.startsWith("(local:"))){let u=l.filter(f=>!f.startsWith("(local:"));u.length>1&&i.push(this.createAmbiguityError(e,p,`Property '${p}'`,u,o,r,!0,p))}}this.validatePropertyValue(e,p,c,t,o,a,r,i)}}validatePropertyValue(e,n,t,o,a,r,i,s){if(t==null)return;let c=n&&n.includes(".")?n.substring(n.lastIndexOf(".")+1):n,p=!!c&&r.has(c);if(typeof t=="string"&&!t.includes(".")&&!p){let l=o.get(t);if(l&&l.length>1&&!l.some(u=>u.startsWith("(local:"))){let u=l.filter(f=>!f.startsWith("(local:"));u.length>1&&s.push(this.createAmbiguityError(e,n,`Reference '${t}'`,u,a,i,!1,t))}}else if(Array.isArray(t))for(let l=0;l<t.length;l++){let m=`${e}.${n}[${l}]`;this.validatePropertyValue(m,n,t[l],o,a,r,i,s)}else if(typeof t=="object"&&!Array.isArray(t)){let l=n?`${e}.${n}`:e;this.validateEntityReferences(l,t,o,a,r,i,s)}}createAmbiguityError(e,n,t,o,a,r,i,s){let c=[];for(let k of o){let g=this.findAliasForNamespace(r,k);if(g){let P=n?.split(".").pop()??n;c.push(`${g}.${P}`)}}let p=c.length>0?`Use one of: ${c.map(k=>`'${k}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${n}')`,l=o.map(k=>{let g=a.get(k);return!g||g.length===0?` \u2022 ${k}`:g.length===1?` \u2022 ${k} (direct import)`:` \u2022 ${k}
24
- imported via: ${g.join(" \u2192 ")}`}).join(`
25
- `),m=e.split(".")[0],u=e.includes(".")?e:n,f=new h;f.ruleType=this.ruleName,f.severity="Error",f.entityName=m,u&&(f.propertyName=u);let d=s??n;return d&&(f.actualValue=d),f.message=`${t} is ambiguous - defined in multiple imported namespaces`,f.suggestion=`${p}
26
-
27
- Defined in:
28
- ${l}`,f.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",f}findAliasForNamespace(e,n){if(!e.metadata.imports)return null;for(let[t,o]of Object.entries(e.metadata.imports))for(let a of o)if(`${t}/${a.packageName}@${a.version}`===n&&a.alias)return a.alias;return null}};var ye=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]);primitiveTypes=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","dateTime","date","time","duration","anyURI","anySimpleType","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte","base64Binary","hexBinary","Literal","Resource"]);get ruleName(){return"PropertyRangeReference"}async validateAsync(e,n){let t=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isValidRangeTargetType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=i.type?.toString();if(s!=="DatatypeProperty"&&s!=="ObjectProperty"&&!s?.endsWith(".DatatypeProperty")&&!s?.endsWith(".ObjectProperty"))continue;let c=i.range;if(!c)continue;let p=[];if(Array.isArray(c))for(let l of c){let m=l?.toString();m&&p.push(m)}else{let l=c?.toString();l&&p.push(l)}if(p.length===0)continue;for(let l of p){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||o.has(l))continue;if(!await this.isTypeAvailableInImports(e,n,l)){let u=s?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",f=new h;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${a}' has range '${l}' which is not defined or imported`,f.suggestion=u==="ObjectProperty"?`For ObjectProperty:
29
- 1. Define '${l}' as a Class in this namespace, OR
30
- 2. Import the namespace that contains '${l}', OR
31
- 3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
32
- 1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
33
- 2. If '${l}' should be a class, change property type to ObjectProperty`,f.entityName=a,f.propertyName="range",f.actualValue=l,f.expectedValue=u==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(f)}}}return t}async isTypeAvailableInImports(e,n,t){if(!e.metadata.imports)return!1;let o=null,a=t;if(t.includes(".")){let r=t.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:t,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(this.isValidRangeTargetType(f))return!0}let m=new Set;if(await this.isTypeAvailableInImportsRecursive(c,n,p,m))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,n,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isValidRangeTargetType(m))return!0}if(await this.isTypeAvailableInImportsRecursive(c,n,t,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var me=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,n){let t=[],o=new Map,a=new x(n);await a.buildEntityIndexAsync(e);for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let s=i,c=!1,p=s.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="ObjectProperty"){c=!0;break}}else p?.toString()==="ObjectProperty"&&(c=!0);if(c){let l=s.range,m=[];if(Array.isArray(l))for(let u of l){let f=u?.toString();f&&m.push(f)}else{let u=l?.toString();u&&m.push(u)}for(let u of m)this.xsdTypes.has(u)||(o.has(u)||o.set(u,[]),o.get(u).push(r))}}for(let[r,i]of o)if(!await a.resolveEntityAsync(r,e))for(let c of i){let p=new h;p.ruleType=this.ruleName,p.severity="Warning",p.message=`ObjectProperty references class '${r}' which may not be imported`,p.suggestion=`Ensure the namespace containing '${r}' is imported, or define '${r}' in this document`,p.entityName=c,p.propertyName="range",p.actualValue=r,t.push(p)}return t}};var ue=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,n){let t=[],o=new x(n),a=new ze(o),r=await o.buildEntityIndexAsync(e),i=await this.buildPropertyMetadataAsync(e,n,o,r);for(let[s,c]of Object.entries(e.body))typeof c=="object"&&c!==null&&!Array.isArray(c)&&await this.scanEntityForObjectProperties(c,s,"",i,o,a,e,t);return t}async scanEntityForObjectProperties(e,n,t,o,a,r,i,s){for(let[c,p]of Object.entries(e)){if(this.standardProperties.has(c))continue;let l,m=await a.resolveEntityAsync(c,i);if(m?.uri){let u=`${m.uri.publisher}/${m.uri.package_}/${m.uri.name}`;l=o.get(u)}if(!l){let u=c,f=c.lastIndexOf(".");f>0&&f<c.length-1&&(u=c.substring(f+1)),l=o.get(u)}if(l&&r.isEffectiveObjectProperty(l.propertyType,l.rangeUri)){let f=t?`${t}.${c}`:c;if(typeof p=="string"&&p.trim().length>0){let d=p.trim();if(d.includes(",")){let g=d.split(",").map(P=>P.trim()).filter(P=>P.length>0);s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
34
- ${c}:
35
- - ${g[0]}
36
- ${g.slice(1).map(P=>` - ${P}`).join(`
37
- `)}`,entityName:n,propertyName:c,propertyPath:f,actualValue:d,expectedValue:`A single reference to ${l.range??"an entity"} OR a YAML list`});continue}let k=await a.resolveEntityAsync(d,i);if(k)l.range&&(await this.validateRangeType(k,l.range,a,i)||s.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${c}' expects a ${l.range}, but '${d}' may not be a ${l.range}`,suggestion:`Ensure '${d}' is defined with appropriate type`,entityName:n,propertyName:c,propertyPath:f,actualValue:d,expectedValue:l.range}));else{let g=l.range??"entity";s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' references '${d}' which is not defined or imported`,suggestion:`Define '${d}' or import a namespace that contains it. Expected range: ${g}`,entityName:n,propertyName:c,propertyPath:f,actualValue:d,expectedValue:"Defined or imported entity"})}}else if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let d=t?`${t}.${c}`:c;await this.scanEntityForObjectProperties(p,n,d,o,a,r,i,s)}else if(Array.isArray(p))for(let d=0;d<p.length;d++){let k=p[d];if(typeof k=="string"&&k.trim().length>0){let g=k.trim(),P=await a.resolveEntityAsync(g,i);if(P){if(l.range&&!await this.validateRangeType(P,l.range,a,i)){let Ke=t?`${t}.${c}[${d}]`:`${c}[${d}]`;s.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${c}' expects a ${l.range}, but '${g}' may not be a ${l.range}`,suggestion:`Ensure '${g}' is defined with appropriate type`,entityName:n,propertyName:`${c}[${d}]`,propertyPath:Ke,actualValue:g,expectedValue:l.range})}}else{let X=l.range??"entity",Ke=t?`${t}.${c}[${d}]`:`${c}[${d}]`;s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' references '${g}' which is not defined or imported`,suggestion:`Define '${g}' or import a namespace that contains it. Expected range: ${X}`,entityName:n,propertyName:`${c}[${d}]`,propertyPath:Ke,actualValue:g,expectedValue:"Defined or imported entity"})}}else if(typeof k=="object"&&k!==null&&!Array.isArray(k)){let g=t?`${t}.${c}[${d}]`:`${c}[${d}]`;await this.scanEntityForObjectProperties(k,n,g,o,a,r,i,s)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!o.has(c)){let u=t?`${t}.${c}`:c;await this.scanEntityForObjectProperties(p,n,u,o,a,r,i,s)}else if(Array.isArray(p))for(let u=0;u<p.length;u++){let f=p[u];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=t?`${t}.${c}[${u}]`:`${c}[${u}]`;await this.scanEntityForObjectProperties(f,n,d,o,a,r,i,s)}}}}async validateRangeType(e,n,t,o){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(n))return!0;let r=e.entity.type;if(r){let i=[];if(Array.isArray(r))for(let s of r){let c=s?.toString();c&&c.trim().length>0&&i.push(c)}else{let s=r?.toString();s&&s.trim().length>0&&i.push(s)}for(let s of i){let c=s.includes(".")?s.split(".")[1]:s;if(c===n||n==="Property"&&(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty")||n==="Class"&&c==="Class"||await t.isSubclassOfAsync(s,n,o))return!0}}return!1}async buildPropertyMetadataAsync(e,n,t,o){let a=new Map;for(let[r,i]of o){let s=i.entity.type;if(s){let c=[];if(Array.isArray(s))for(let m of s){let u=m?.toString();u&&u.trim().length>0&&c.push(u)}else{let m=s?.toString();m&&m.trim().length>0&&c.push(m)}let p=!1,l="Property";for(let m of c){let u=m.includes(".")?m.split(".")[1]:m;if(u==="Property"||u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty"){p=!0,l=m;break}}if(p){let m={propertyType:l},u=i.entity.range;if(u){let f=u?.toString();if(f&&f.trim().length>0){m.range=f;let d=await t.resolveEntityAsync(f,e);d&&(m.rangeUri=d.uri)}}if(a.set(r,m),i.uri){let f=`${i.uri.publisher}/${i.uri.package_}/${i.uri.name}`;a.set(f,m)}}}}return a}};var fe=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,n,t){let o=[],a=new Map;for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=this.getPropertyValue(c,"type");(p==="DatatypeProperty"||p?.endsWith(".DatatypeProperty")||p==="ObjectProperty"||p?.endsWith(".ObjectProperty")||p==="AnnotationProperty"||p?.endsWith(".AnnotationProperty"))&&a.set(i,c)}let r=t?await this.buildClassHierarchyViaCache(e,t):await this.buildCompleteClassHierarchyAsync(e,n);for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=this.getPropertyValue(c,"type");if(!p||p==="Class"||p.endsWith(".Class")||p.endsWith("Property")||p==="AnnotationProperty")continue;this.validateEntityProperties(c,i,p,a,r,o)}return o}async buildClassHierarchyViaCache(e,n){let t=new Map,o=ft(e);if(!o)return t;let a=await n.getImportClosure(o);for(let r of a){let i=await n.getClassDeclarations(r);for(let[s,c]of i)c.length>0&&t.set(s,c)}return t}async buildCompleteClassHierarchyAsync(e,n){let t=new Map,o=new Set,a=async(i,s)=>{if(!o.has(s)){o.add(s);for(let[c,p]of Object.entries(i.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let l=p,m=this.getPropertyValue(l,"type");if(m==="Class"||m?.endsWith(".Class")){let u=l.subClassOf;if(u===void 0){for(let d of Object.keys(l))if(d.endsWith(".subClassOf")){u=l[d];break}}let f=j(u);f.length>0&&t.set(c,f)}}if(i.metadata.imports)for(let[c,p]of Object.entries(i.metadata.imports))for(let l of p)try{let m=await n.getHighestCompatibleVersionAsync(c,l);if(m){let u=`${c}/${l.packageName}@${l.version}`;await a(m,u)}}catch{}}},r=e.metadata.namespace_?.toString()??"unknown";return await a(e,r),t}validateEntityProperties(e,n,t,o,a,r){for(let[i,s]of Object.entries(e)){if(this.standardProperties.has(i))continue;let c=i,p=i.lastIndexOf(".");p>0&&p<i.length-1&&(c=i.substring(p+1));let l=o.get(c);if(!l)continue;let m=this.getPropertyValue(l,"domain");if(m){if(!this.isTypeCompatibleWithDomain(t,m,a)){let u=n.split(".")[0];r.push({ruleType:this.ruleName,severity:"Error",entityName:u,propertyName:n,actualValue:i,message:`Property '${i}' has domain '${m}' but is used on '${t}' at '${n}'`,suggestion:`Either:
38
- 1. Use this property only on '${m}' instances
39
- 2. Change the property domain to include '${t}'
40
- 3. Create a different property for '${t}'`,expectedValue:`Property used on ${m} or its subclasses`})}if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let u=s,f=this.getPropertyValue(u,"type");if(f){let d=`${n}.${i}`;this.validateEntityProperties(u,d,f,o,a,r)}else{let d=this.getPropertyValue(l,"range");if(d){let k=`${n}.${i}`;this.validateEntityProperties(u,k,d,o,a,r)}}}else if(Array.isArray(s))for(let u=0;u<s.length;u++){let f=s[u];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=f,k=this.getPropertyValue(d,"type");if(k){let g=`${n}.${i}[${u}]`;this.validateEntityProperties(d,g,k,o,a,r)}else{let g=this.getPropertyValue(l,"range");if(g){let P=`${n}.${i}[${u}]`;this.validateEntityProperties(d,P,g,o,a,r)}}}}}}}isTypeCompatibleWithDomain(e,n,t){if(e===n)return!0;let o=new Set,a=[e];for(;a.length>0;){let r=a.shift();if(o.has(r))continue;o.add(r);let i=t.get(r);if(i)for(let s of i){if(s===n)return!0;a.push(s)}}return!1}getPropertyValue(e,n){if(n in e){let t=e[n];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${n}`)){let o=e[t];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let n=[];for(let t of e)n.push(t?.toString()??"");return n.length>0?n[0]:void 0}return e?.toString()}};function ft(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var de=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,n){let t=[],o=new Map;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=this.getPropertyValue(i,"type");(s==="DatatypeProperty"||s==="ObjectProperty")&&o.set(a,i)}for(let[a,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let i=r,s=this.getPropertyValue(i,"type");if(!(!s||s==="Class"||s.endsWith("Property")||s==="AnnotationProperty"))for(let[c,p]of Object.entries(i)){if(c==="type"||c==="label"||c==="comment")continue;let l=c,m=c.lastIndexOf(".");m>0&&m<c.length-1&&(l=c.substring(m+1));let u=o.get(l);if(!u)continue;let f=this.getPropertyValue(u,"type"),d=this.getPropertyValue(u,"range");if(f==="DatatypeProperty"){if(typeof p=="object"&&p!==null&&!Array.isArray(p)||Array.isArray(p))t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`Property '${c}' is a DatatypeProperty with range '${d}' but instance '${a}' has a complex object value`,suggestion:`Either:
41
- 1. Create a class for this data and change '${c}' to an ObjectProperty
42
- 2. Store as a JSON string to keep it as DatatypeProperty
43
- 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${d}'`});else if(!this.validateDatatypeValue(d,p)){let k={ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`Property '${c}' expects type '${d}' but instance '${a}' has value of type '${this.getValueTypeName(p)}'`,suggestion:`Provide a value of type '${d}'`,toString:()=>""};d&&(k.expectedValue=d),t.push(k)}}else if(f==="ObjectProperty")if(Array.isArray(p))for(let k=0;k<p.length;k++){let g=p[k];typeof g!="string"&&(typeof g!="object"||g===null||Array.isArray(g))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:`${c}[${k}]`,message:`ObjectProperty '${c}' array item ${k} in instance '${a}' has invalid type '${this.getValueTypeName(g)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof p!="string"&&(typeof p!="object"||p===null||Array.isArray(p))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`ObjectProperty '${c}' in instance '${a}' has invalid value type '${this.getValueTypeName(p)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${d} or embedded ${d} object`})}}return t}validateDatatypeValue(e,n){switch(e?.toLowerCase()){case"string":return typeof n=="string";case"integer":case"int":return typeof n=="number"&&Number.isInteger(n);case"decimal":return typeof n=="number";case"boolean":return typeof n=="boolean";case"float":case"double":return typeof n=="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,n){if(n in e){let t=e[n];if(Array.isArray(t)){let o=[];for(let a of t)o.push(a?.toString()??"");return o.length>0?o[0]:void 0}return t?.toString()}}};var ge=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,n){let t=[],o=new Map,a=new Set;for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=s.type;if(p)if(Array.isArray(p))for(let l of p){let m=l?.toString();if(m==="Class"||m&&m.endsWith(".Class")){a.add(i);break}}else{let l=p?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&a.add(i)}}for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=c.type;if(p)if(Array.isArray(p)){let l=!1;for(let m of p){let u=m?.toString();if(u&&this.isDefinitionType(u)){l=!0;break}}if(!l)for(let m of p){let u=m?.toString();u&&u.trim().length>0&&(o.has(u)||o.set(u,[]),o.get(u).push(i))}}else{let l=p?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(o.has(l)||o.set(l,[]),o.get(l).push(i)))}this.checkNestedTypes(c,i,o,i)}let r=new x(n);for(let[i,s]of o){if(this.builtInClasses.has(i)||a.has(i))continue;let c=await r.resolveEntityAsync(i,e);if(!(c&&this.isClassEntity(c.entity))){let l=Array.from(new Set(s)).sort();for(let m of l)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${i}' is not defined or imported`,suggestion:`Define '${i}' as a Class in this document, or import a namespace that contains it`,entityName:m,propertyName:"type",actualValue:i,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,n,t,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=e,r=a.type;if(r){let i=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(r))for(let s of r){let c=s?.toString();c&&c.trim().length>0&&!i.has(c)&&(t.has(c)||t.set(c,[]),t.get(c).push(o))}else{let s=r?.toString();s&&s.trim().length>0&&!i.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(o))}}for(let[i,s]of Object.entries(a))if(i!=="type"){let c=`${o}.${i}`;this.checkNestedTypes(s,n,t,c)}}else if(Array.isArray(e))for(let a=0;a<e.length;a++){let r=`${o}[${a}]`;this.checkNestedTypes(e[a],n,t,r)}}isClassEntity(e){if(!e)return!1;let n=e.type;if(!n)return!1;if(Array.isArray(n))for(let t of n){let o=t?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let t=n?.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 he=class{ruleName="MarkdownLink";async validateAsync(e,n,t){let o=[],a;if(t){let r=await t.getKanonaks(),i=dt(e);a=i?r.filter(s=>s instanceof I&&s.namespace===i):[]}else{let r=new L(e,n);a=await new A().parseKanonaks(r)}for(let r of a)r instanceof I&&this.checkDefined(r,r.name,o);return o}checkDefined(e,n,t){for(let o of e.statement)if(o instanceof qe){let a=o.predicate.subject?.name??"(unknown)";for(let r of o.links)r.target||t.push(this.unresolvedLinkError(n,a,r.reference));for(let r of Ye(o.object))t.push(this.malformedLinkError(n,a,r.snippet))}else if(o instanceof Fe)this.checkDefined(o.object,n,t);else if(o instanceof Xe)for(let a of o.object)a instanceof D&&this.checkDefined(a,n,t)}unresolvedLinkError(e,n,t){let o=new h;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=n,o.actualValue=t,o.message=`Embedded link [[${t}]] in '${n}' 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.
44
-
45
- Possible solutions:
46
- \u2022 Import the package that defines '${t}' so the link can resolve
47
- \u2022 Check for typos in the reference name
48
- \u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,o}malformedLinkError(e,n,t){let o=new h;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=n,o.actualValue=t,o.message=`Malformed embedded reference near '${t}' in '${n}'`,o.expectedValue="A single-line [[reference]] with no internal line break",o.suggestion=`A '[[' in '${n}' does not form a complete [[reference]] link.
49
-
50
- A reference may not span a line break \u2014 the most common cause is wrapping a
51
- long reference across two lines in a block scalar, e.g.:
52
- ... read for [[persistent-energy-
53
- shock]] held ...
54
- which is parsed as literal text, not a link. Keep each [[reference]] on one
55
- line (let the line run long), or check for an unterminated [[.`,o}};function dt(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var ot="kanonak.org",rt="look",gt={publisher:ot,package_:rt,name:"displayLabel"},ht={publisher:ot,package_:rt,name:"displaySummary"},ke=class{ruleName="DisplayLensScope";async validateAsync(e,n,t){let o=[],a;t?a=await t.getKanonaks():a=await new A().parseKanonaks(new L(e,n));let r=kt(e);if(!r)return o;for(let i of a)i instanceof I&&i.namespace===r&&(this.checkLens(a,i,gt,"displayLabel",o),this.checkLens(a,i,ht,"displaySummary",o));return o}checkLens(e,n,t,o,a){let r=V(n,t);if(!r)return;let i=[],s=M(n);if(s&&i.push(s),i.push(...Je(n)),i.length===0)return;i.some(p=>w(e,p,r).ok)||a.push(this.scopeError(n.name,o,r.name))}scopeError(e,n,t){let o=new h;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=n,o.actualValue=t,o.message=`${n} 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.
56
-
57
- Possible solutions:
58
- \u2022 Point ${n} at a property declared on this class (or an ancestor / rdfs.Resource)
59
- \u2022 Set the property's domain to this class if it should apply here
60
- \u2022 Use rdfs.label / rdfs.comment for the universal default`,o}};function kt(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}function B(y,e,n){let t=[];return Oe(y,n,{input:e},t),t}function Oe(y,e,n,t){if(E(e,T.VarRef)){let r=U(e,T.varName);return r?n[r]:void 0}if(E(e,T.PropertyRead)){let r=O(e,T.readSource),i=r?Oe(y,r,n,t):void 0,s=V(e,T.readProp);if(!i||!s)return;let c=w(y,i,s);if(!c.ok){t.push({contextClass:i,propertyUri:s,via:"PropertyRead"});return}return c.descriptor?.range}if(E(e,T.Traverse)){let r=O(e,T.traverseSource),i=r?Oe(y,r,n,t):void 0,s=V(e,T.through),c;if(i&&s){let l=w(y,i,s);l.ok?c=l.descriptor?.range:t.push({contextClass:i,propertyUri:s,via:"Traverse"})}let p=O(e,T.step);return p?Oe(y,p,{...n,input:c},t):void 0}let o=U(e,T.loopVar),a=o?{...n,[o]:void 0}:n;for(let r of bt(e))Oe(y,r,a,t)}function bt(y){let e=[];for(let n of y.statement){let t=n.object;if(t instanceof D)e.push(t);else if(Array.isArray(t))for(let o of t)o instanceof D&&e.push(o)}return e}var Se="kanonak.org",$e="look",Rt={publisher:Se,package_:$e,name:"semanticSvg"},vt={publisher:Se,package_:$e,name:"tierChip"},Pt={publisher:Se,package_:$e,name:"tierIcon"},Vt={publisher:Se,package_:$e,name:"tierCard"},It={publisher:Se,package_:$e,name:"tierFull"},Dt=[vt,Pt,Vt,It],be=class{ruleName="LookSemanticSvgPath";async validateAsync(e,n,t){let o=[],a;t?a=await t.getKanonaks():a=await new A().parseKanonaks(new L(e,n));let r=At(e);if(!r)return o;for(let i of a)i instanceof I&&i.namespace===r&&this.checkSemanticSvg(a,i,o);return o}checkSemanticSvg(e,n,t){let o=O(n,Rt);if(!o)return;let a=M(n);if(a)for(let r of Dt){let i=O(o,r);if(i)for(let s of B(e,a,i))t.push(this.toError(n.name,r.name,s))}}toError(e,n,t){let o=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,a=t.contextClass.name,r=a===e?`'${e}' (the class this SemanticSvg is declared on)`:`'${a}', reached by traversal from '${e}' (the class this SemanticSvg is declared on)`,i=new h;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=`look.semanticSvg.${n}`,i.actualValue=o,i.message=`tx.${t.via} reads property '${t.propertyUri.name}' off the rendered instance, but its domain is not in scope for ${r}. The read would silently return undefined at render time.`,i.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,i.suggestion=`Property '${o}' is not in scope for '${a}'.
61
-
62
- Possible solutions:
63
- \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
64
- \u2022 If the property should apply to '${a}', adjust its domain
65
- \u2022 If the value comes from a pre-computed env binding, use tx.VarRef instead of PropertyRead`,i}};function At(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var Et="kanonak.org",R=(y,e)=>({publisher:Et,package_:y,name:e}),Ot=R("derivation","look"),St=R("look","bands"),$t=R("look","Distribution"),Ct=R("look","StatRow"),Kt=R("look","VersionDelta"),jt=R("look","Timeline"),wt=R("look","VersionDiff"),Nt=R("look","TimePlot"),Tt=R("look","ReferenceList"),xt=R("look","Diagram"),_t=R("look","alphaPath"),Ut=R("look","betaPath"),Me=R("look","metricPath"),it=R("look","lowerPath"),at=R("look","upperPath"),st=R("look","hueBy"),Lt=R("look","statPath"),Mt=R("look","laneBy"),ct=R("look","labelPath"),Wt=R("look","badgePath"),Ht=R("look","mapPath"),Bt=R("look","nodeNote"),Ft=R("look","edgeValue"),Xt=R("look","stats"),qt=R("look","facets"),zt=R("look","channels"),Yt=R("look","track"),Gt=R("look","source"),Zt=R("look","relation"),Jt=R("look","entries"),Ce=class{ruleName="LookBandPath";async validateAsync(e,n,t){let o=[],a;t?a=await t.getKanonaks():a=await new A().parseKanonaks(new L(e,n));let r=en(e);if(!r)return o;for(let i of a)i instanceof I&&i.namespace===r&&this.checkDeclaration(a,i,o);return o}checkDeclaration(e,n,t){let o=O(n,Ot);if(!o)return;let a=M(n);if(!a)return;let r=S(o,St).filter(i=>i instanceof D);for(let i of r)for(let s of this.carriersOf(e,i,a))for(let c of B(e,s.context,s.expr))t.push(this.toError(n.name,s.slot,c))}carriersOf(e,n,t){let o=[],a=(r,i)=>{let s=O(n,r);s&&o.push({slot:`look.${r.name}`,context:i,expr:s})};if(E(n,$t))for(let r of[_t,Ut,Me,it,at,st])a(r,t);if(E(n,Kt)&&a(Me,t),E(n,Ct)){let r=S(n,Xt).filter(i=>i instanceof D);for(let i of r){let s=O(i,Lt);s&&o.push({slot:"look.stats[].statPath",context:t,expr:s})}}if(E(n,jt)||E(n,wt)){let r=this.rangeOf(e,t,V(n,Yt));if(r)for(let i of[Me,it,at,st])a(i,r)}if(E(n,Nt)){let r=this.rangeOf(e,t,V(n,Gt));if(r)for(let i of[Mt,ct])a(i,r)}if(E(n,Tt))for(let r of S(n,Jt)){let i=r instanceof D?void 0:Qt(r),s=this.rangeOf(e,t,i);if(s)for(let c of[ct,Wt])a(c,s)}if(E(n,xt)){let r=S(n,qt).filter(i=>i instanceof D);for(let i of r){let s=this.rangeOf(e,t,V(i,Zt));if(!s)continue;let c=O(i,Bt);c&&o.push({slot:"look.facets[].nodeNote",context:s,expr:c});let p=O(i,Ft);p&&o.push({slot:"look.facets[].edgeValue",context:s,expr:p});let l=S(i,zt).filter(m=>m instanceof D);for(let m of l){let u=O(m,Ht);u&&o.push({slot:"look.facets[].channels[].mapPath",context:s,expr:u})}}}return o}rangeOf(e,n,t){if(!t)return;let o=w(e,n,t);return o.ok?o.descriptor?.range:void 0}toError(e,n,t){let o=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,a=t.contextClass.name,r=new h;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=n,r.actualValue=o,r.message=`tx.${t.via} reads property '${t.propertyUri.name}', but its domain is not in scope for '${a}' (the class this band carrier is evaluated against). The read would silently return undefined at render time and the band would render empty.`,r.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,r.suggestion=`Property '${o}' is not in scope for '${a}'.
66
-
67
- Possible solutions:
68
- \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
69
- \u2022 If the property should apply to '${a}', adjust its domain
70
- \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,r}};function Qt(y){let e=y.subject;return e&&typeof e.name=="string"?e:void 0}function en(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var ve="kanonak.org",Pe="view",tn={publisher:ve,package_:Pe,name:"bind"},nn={publisher:ve,package_:Pe,name:"produces"},on={publisher:ve,package_:Pe,name:"projections"},rn={publisher:ve,package_:Pe,name:"where"},an={publisher:ve,package_:Pe,name:"value"},sn={publisher:ve,package_:Pe,name:"as"},Re=class{ruleName="TxExpressionPath";async validateAsync(e,n,t){let o=[],a;t?a=await t.getKanonaks():a=await new A().parseKanonaks(new L(e,n));let r=ln(e);if(!r)return o;for(let i of a)i instanceof I&&i.namespace===r&&this.checkView(a,i,o);return o}checkView(e,n,t){let o=V(n,tn);if(!o)return;let a=V(n,nn),r=0;for(let s of pn(e,S(n,on))){let c=O(s,an);if(c)for(let l of B(e,o,c))t.push(this.toError(n.name,`view.projections[${r}].value`,o,l));let p=V(s,sn);p&&a&&(w(e,a,p).ok||t.push(this.asError(n.name,r,a,p))),r+=1}let i=0;for(let s of cn(n,rn)){for(let c of B(e,o,s))t.push(this.toError(n.name,`view.where[${i}]`,o,c));i+=1}}asError(e,n,t,o){let a=`${o.publisher}/${o.package_}/${o.name}`,r=new h;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=`view.projections[${n}].as`,r.actualValue=a,r.message=`Projection stores its value under property '${o.name}', but that property's domain is not in scope for the view's produces class '${t.name}'. The materialized result instance could not carry this value.`,r.expectedValue=`A property whose domain is '${t.name}', an ancestor, or rdfs.Resource`,r.suggestion=`Property '${a}' is not in scope for produces class '${t.name}'.
71
-
72
- Possible solutions:
73
- \u2022 Use an output property whose domain covers '${t.name}'
74
- \u2022 Define a new property in the ViewPackage with domain '${t.name}' and the right range
75
- \u2022 If the value belongs on a different output class, adjust the view's produces`,r}toError(e,n,t,o){let a=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,i=r===t.name?`the view's bound class '${t.name}'`:`'${r}', reached by traversal from the view's bound class '${t.name}'`,s=new h;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=n,s.actualValue=a,s.message=`tx.${o.via} reads property '${o.propertyUri.name}', but its domain is not in scope for ${i}. The read would silently return undefined when the view materializes.`,s.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,s.suggestion=`Property '${a}' is not in scope for '${r}'.
76
-
77
- Possible solutions:
78
- \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
79
- \u2022 If the property should apply to '${r}', adjust its domain
80
- \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,s}};function cn(y,e){let n=O(y,e);return n?[n]:S(y,e).filter(t=>t instanceof D)}function pn(y,e){let n=[];for(let t of e)if(t instanceof D)n.push(t);else if(t instanceof W){let o=N(y,t.subject);o&&n.push(o)}return n}function ln(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var Te="kanonak.org",yn="core-shacl",$=y=>({publisher:Te,package_:yn,name:y}),mn=$("NodeShape"),un=$("PropertyShape"),fn=$("targetClass"),dn=$("property"),gn=$("path"),hn=$("minCount"),kn=$("maxCount"),bn=$("datatype"),Rn=$("class"),pt=$("in"),vn=$("pattern"),Pn=$("flags"),Vn=$("minLength"),In=$("maxLength"),Dn=$("minInclusive"),An=$("maxInclusive"),En=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),We=y=>y,Ie=class{ruleName="ShaclShape";async validateAsync(e,n,t){let o=[],a=t?await t.getKanonaks():await new A().parseKanonaks(n),r=On(e);if(!r)return o;let i=new Set;for(let s of a){if(!(s instanceof I)||s.namespace!==r||!E(s,mn))continue;let c=V(s,fn);c?this.resolvesToClass(a,c)||o.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' sh:targetClass '${c.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",F(c))):o.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' has no sh:targetClass; it constrains nothing.`,"Add sh:targetClass naming the class this shape applies to."));for(let p of S(s,dn)){let l;if(p instanceof D)l=p;else if(p instanceof W){let m=N(a,p.subject);m&&(l=m,i.add(_(p.subject)))}l&&this.checkPropertyShape(a,s.name,l,c??void 0,o)}}for(let s of a){if(!(s instanceof I)||s.namespace!==r||!E(s,un))continue;let c=M(s);c&&i.has(_(c))||this.checkPropertyShape(a,s.name,s,void 0,o)}return o}checkPropertyShape(e,n,t,o,a){let r=V(t,gn);if(!r){a.push(this.err(n,"property.path","Error",`A PropertyShape on '${n}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=N(e,r),s=i?H.isAnyPropertyType(We(i)):!1;s?o&&(w(e,o,r).ok||a.push(this.err(n,"property.path","Warning",`sh:path '${r.name}' is not in scope for sh:targetClass '${o.name}'; the constraint would never bind a value.`,`Constrain a property whose domain is '${o.name}', an ancestor, or rdfs.Resource.`,F(r)))):a.push(this.err(n,"property.path","Error",`sh:path '${r.name}' on '${n}' does not resolve to a property.`,"Reference a defined or imported property.",F(r)));let c=V(t,bn),p=V(t,Rn);c&&p&&a.push(this.err(n,"property","Error",`A PropertyShape on '${n}' sets both sh:datatype and sh:class; a value is a literal or a node, not both.`,"Keep sh:datatype (literal values) or sh:class (node values), not both.")),c&&!this.resolvesToDatatype(e,c)&&a.push(this.err(n,"datatype","Error",`sh:datatype '${c.name}' on '${n}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",F(c))),p&&!this.resolvesToClass(e,p)&&a.push(this.err(n,"class","Error",`sh:class '${p.name}' on '${n}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",F(p)));let l=Ve(C(t,hn)),m=Ve(C(t,kn));this.checkOrder(n,"minCount",l,"maxCount",m,a);let u=Ve(C(t,Vn)),f=Ve(C(t,In));this.checkOrder(n,"minLength",u,"maxLength",f,a);let d=Ve(C(t,Dn)),k=Ve(C(t,An));this.checkOrder(n,"minInclusive",d,"maxInclusive",k,a);let g=U(t,vn);if(g!==void 0){let P=U(t,Pn);try{new RegExp(g,P)}catch{a.push(this.err(n,"pattern","Error",`sh:pattern on '${n}' is not a valid regular expression`+(P!==void 0?` (with flags '${P}')`:"")+`: ${g}`,"Provide a valid regular expression and flags.",g))}}if(we(t,pt)&&S(t,pt).length===0&&a.push(this.err(n,"in","Error",`sh:in on '${n}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),s&&o){let X=w(e,o,r).descriptor;X&&((g!==void 0||u!==void 0||f!==void 0)&&X.kind==="object"&&a.push(this.err(n,"pattern/minLength/maxLength","Warning",`String facets on '${n}' apply to '${r.name}', which is an object property; string facets constrain literal values.`,"Apply string facets to a datatype property, or use sh:class for node values.",F(r))),(d!==void 0||k!==void 0)&&!this.isNumericDatatypeRange(X.range)&&a.push(this.err(n,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${n}' apply to '${r.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",F(r))))}}checkOrder(e,n,t,o,a,r){t!==void 0&&a!==void 0&&t>a&&r.push(this.err(e,`${n}/${o}`,"Error",`${n} (${t}) exceeds ${o} (${a}) on '${e}'.`,`Set ${n} <= ${o}.`))}resolvesToClass(e,n){let t=N(e,n);return t?H.isClassType(We(t)):!1}resolvesToDatatype(e,n){if(n.publisher===Te&&n.package_==="core-rdf"&&n.name==="Literal")return!0;let t=N(e,n);return t?H.isDatatypeType(We(t)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Te&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Te&&e.package_==="core-xsd"&&En.has(e.name)}err(e,n,t,o,a,r){let i=new h;return i.ruleType=this.ruleName,i.severity=t,i.entityName=e,i.propertyName=n,i.message=o,i.suggestion=a,r!==void 0&&(i.actualValue=r),i}};function Ve(y){return typeof y=="number"?y:void 0}function F(y){return`${y.publisher}/${y.package_}/${y.name}`}function On(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var lt={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},Sn=y=>y,De=class{ruleName="OwlOneOf";async validateAsync(e,n,t){let o=[],a=t?await t.getKanonaks():await new A().parseKanonaks(n),r=$n(e);if(!r)return o;for(let i of a){if(!(i instanceof I)||i.namespace!==r||!we(i,lt))continue;let s=S(i,lt);if(s.length===0){o.push(this.err(i.name,"Warning",`owl:oneOf on '${i.name}' is empty; a closed enumeration must list at least one individual.`,"List the individuals that make up the enumeration, or remove owl:oneOf."));continue}for(let c of s)if(c instanceof je)o.push(this.err(i.name,"Error",`owl:oneOf member '${String(c.value)}' on '${i.name}' is not a named individual; a class enumeration is of individuals (a misspelled or unimported individual reads as a literal). For a closed set of literal VALUES, constrain a property with sh:in instead.`,"Reference a defined or imported individual, or move literal value sets to a property sh:in.",String(c.value)));else if(c instanceof W){let p=N(a,c.subject);p&&H.isSchemaDefinitionType(Sn(p))&&o.push(this.err(i.name,"Error",`owl:oneOf member '${c.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${c.subject.publisher}/${c.subject.package_}/${c.subject.name}`))}}return o}err(e,n,t,o,a){let r=new h;return r.ruleType=this.ruleName,r.severity=n,r.entityName=e,r.propertyName="oneOf",r.message=t,r.suggestion=o,a!==void 0&&(r.actualValue=a),r}};function $n(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var Cn="kanonak.org",Kn="core-shacl",K=y=>({publisher:Cn,package_:Kn,name:y}),jn=K("NodeShape"),wn=K("targetClass"),Nn=K("property"),Tn=K("path"),xn=K("minCount"),_n=K("maxCount"),Un=K("in"),Ln=K("pattern"),Mn=K("flags"),Wn=K("minLength"),Hn=K("maxLength"),Bn=K("minInclusive"),Fn=K("maxInclusive"),Xn=K("message");function Ae(y){return typeof y=="number"?y:void 0}function qn(y){let e={},n=Ae(C(y,xn)),t=Ae(C(y,_n));n!==void 0&&(e.minCount=n),t!==void 0&&(e.maxCount=t);let o=Ae(C(y,Wn)),a=Ae(C(y,Hn));o!==void 0&&(e.minLength=o),a!==void 0&&(e.maxLength=a);let r=Ae(C(y,Bn)),i=Ae(C(y,Fn));r!==void 0&&(e.minInclusive=r),i!==void 0&&(e.maxInclusive=i);let s=U(y,Ln);if(s!==void 0){let l=U(y,Mn);e.pattern=l!==void 0?{regex:s,flags:l}:{regex:s}}let c=S(y,Un).filter(l=>l instanceof je).map(l=>l.value);c.length>0&&(e.enumValues=c);let p=U(y,Xn);return p!==void 0&&(e.message=p),e}function zn(y,e){let n=[];for(let t of S(e,Nn))if(t instanceof D)n.push(t);else if(t instanceof W){let o=N(y,t.subject);o&&n.push(o)}return n}function yt(y){let e=new Map;for(let n of y){if(!(n instanceof I)||!E(n,jn))continue;let t=V(n,wn);if(!t)continue;let o=_(t);for(let a of zn(y,n)){let r=V(a,Tn);if(!r)continue;let i={pathKey:_(r),constraints:qn(a)},s=e.get(o);s?s.push(i):e.set(o,[i])}}return e}function Yn(y,e){e.minCount!==void 0&&(y.minCount=e.minCount),e.maxCount!==void 0&&(y.maxCount=e.maxCount),e.minLength!==void 0&&(y.minLength=e.minLength),e.maxLength!==void 0&&(y.maxLength=e.maxLength),e.minInclusive!==void 0&&(y.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(y.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(y.pattern=e.pattern),e.enumValues!==void 0&&(y.enumValues=e.enumValues),e.message!==void 0&&(y.message=e.message)}function mt(y,e,n){let t=_(n),o=!1,a={};for(let r=e.length-1;r>=0;r--){let i=y.get(_(e[r]));if(i)for(let s of i)s.pathKey===t&&(o=!0,Yn(a,s.constraints))}if(o)return a.cardinality=a.maxCount===1?"single":"list",a.required=(a.minCount??0)>=1,a}var Gn=y=>y,Ee=class{ruleName="DiamondNameClash";async validateAsync(e,n,t){let o=[],a=t?await t.getKanonaks():await new A().parseKanonaks(n),r=Zn(e);if(!r)return o;let i=yt(a);for(let s of a){if(!(s instanceof I)||s.namespace!==r||!H.isClassType(Gn(s)))continue;let c=M(s);if(!c)continue;let p=Ge(a,c),l=new Map;for(let m of Ze(a,c)){let u=l.get(m.uri.name);u?u.push(m):l.set(m.uri.name,[m])}for(let[m,u]of l){if(u.length<2)continue;let f=g=>mt(i,p,g.uri)?.cardinality,d=new Set(u.map(g=>g.range?_(g.range):void 0).filter(g=>g!==void 0)),k=new Set(u.map(f).filter(g=>g!==void 0));d.size<=1&&k.size<=1||o.push(this.toError(s.name,m,u,f))}}return o}toError(e,n,t,o){let a=s=>{let c=`${s.uri.publisher}/${s.uri.package_}/${s.uri.name}`,p=s.range?`${s.range.publisher}/${s.range.package_}/${s.range.name}`:"no range",l=o(s);return`${c} (range ${p}${l?`, ${l}`:""})`},r=t.map(a).join("; "),i=new h;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=n,i.actualValue=r,i.message=`Class '${e}' inherits ${t.length} distinct properties named '${n}' with incompatible range or cardinality: ${r}. The generated interface would multiply-inherit '${n}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${n}':
81
- \u2022 rename one of the properties, or
82
- \u2022 re-domain one so it is not inherited by '${e}', or
83
- \u2022 restructure the hierarchy so '${e}' inherits only one '${n}', or
84
- \u2022 make the ranges/cardinalities compatible (identical) if they are meant to be the same property.`,i}};function Zn(y){let e=y.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${v(e.version)}`}var He=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new Be,this.documentRules=[new z,new Y,new G,new Z],this.repositoryRules=[new J,new Q,new ee,new te,new ne,new oe,new re,new ie,new ae,new se,new ce,new pe,new le,new ye,new me,new ue,new fe,new de,new ge,new he,new ke,new be,new Ce,new Re,new Ie,new De,new Ee]}async validateAsync(e,n,t){let o=new q;for(let a of this.documentRules)try{let r=a.validate(e);this.addErrorsToResult(o,r)}catch(r){let i=new h;i.ruleType=a.ruleName,i.severity="Error",i.message=`Validation rule '${a.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,o.errors.push(i)}if(n){let a=[],r=t?.repository??n;for(let i of this.repositoryRules)try{let s=await i.validateAsync(e,r,t);this.addErrorsToResult(o,s)}catch(s){let c=s instanceof Error?s.message:String(s);a.push({ruleName:i.ruleName,cause:c})}if(a.length>0){let i=new Map;for(let{ruleName:s,cause:c}of a){let p=i.get(c);p?p.push(s):i.set(c,[s])}for(let[s,c]of i){let p=new h;p.ruleType=c[0],p.severity="Error",c.length===1?p.message=`Validation rule '${c[0]}' failed: ${s}`:p.message=`${s} (affects ${c.length} rules: ${c.join(", ")})`,o.errors.push(p)}}}return o.isValid=o.errors.length===0,o}async validateYamlAsync(e,n,t){let o=this.parser.parseWithErrors(e);if(!o.isValid){let a=new q;a.isValid=!1;for(let r of o.errors){let i=new h;i.ruleType="ParseError",i.severity="Error",i.lineNumber=r.line,i.column=r.column,i.message=r.message,r.keyName&&(i.entityName=r.keyName),r.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),a.errors.push(i)}return a}return await this.validateAsync(o.document,n,t)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let n=this.documentRules.findIndex(t=>t instanceof e);n>=0&&this.documentRules.splice(n,1)}removeRepositoryRule(e){let n=this.repositoryRules.findIndex(t=>t instanceof e);n>=0&&this.repositoryRules.splice(n,1)}addErrorsToResult(e,n){for(let t of n)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{q as a,b,h as c,xe as d,Ue as e,z as f,Y as g,G as h,Z as i,J as j,Q as k,ee as l,te as m,ne as n,oe as o,re as p,ie as q,ae as r,se as s,ce as t,pe as u,le as v,ye as w,me as x,ue as y,fe as z,de as A,ge as B,he as C,ke as D,be as E,Re as F,Ie as G,De as H,yt as I,mt as J,Ee as K,He as L};
@@ -1 +0,0 @@
1
- import{a as k,b as f}from"./chunk-2ACBWC7K.js";import*as h from"js-yaml";var b=new Set(["Package","EphemeralPackage"]);function v(d){return typeof d=="string"&&b.has(d)}var $=class{parse(r){let t=this.parseWithErrors(r);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(r){let t=[],a;try{r=r.replace(/^\uFEFF/,"");let s=h.load(r);if(!s||typeof s!="object")return a={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:a,errors:t,isValid:!0};let e=this.extractMetadata(s),n=this.extractBody(s,e);return a={metadata:e,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 e=s,n={message:e.message||"Unknown parse error",line:e.mark?.line??0,column:e.mark?.column??0,errorType:e.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${e.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${e.mark?.line??0}: ${e.message||"Unknown parse error"}`};return t.push(n),{document:void 0,errors:t,isValid:!1}}}save(r){let t={};if(r.metadata.namespace_){let a=r.metadata.namespace_,s={type:"Package",publisher:a.publisher};a.version&&(s.version=`${a.version.major}.${a.version.minor}.${a.version.patch}`),r.metadata.imports&&(s.imports=this.serializeImports(r.metadata.imports)),t[a.package_]=s}return Object.assign(t,r.body),h.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(r){let t=r.imports;return Object.defineProperty(r,"allImports",{get:function(){if(!t)return[];let a=[];for(let s of Object.values(t))a.push(...s);return a},enumerable:!0,configurable:!0}),r}createVersion(r,t,a){return{major:r,minor:t,patch:a,toString:()=>`${r}.${t}.${a}`,equals:e=>!e||typeof e!="object"?!1:e.major===r&&e.minor===t&&e.patch===a,getHashCode:()=>r<<20|t<<10|a,compareTo:e=>r!==e.major?r-e.major:t!==e.minor?t-e.minor:a-e.patch}}extractMetadata(r){let t=this.createEmptyMetadata();for(let[a,s]of Object.entries(r))if(s&&typeof s=="object"&&v(s.type)){t.type_=s.type;let e=a,n=s.publisher,i=s.version?this.parseVersion(s.version):void 0;return n&&e&&(t.namespace_={publisher:n,package_:e,version:i,toString:function(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}`:`${this.publisher}/${this.package_}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===n&&o.package_===e&&(!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<e.length;c++)o=(o<<5)-o+e.charCodeAt(c);return o|0}}),s.imports&&Array.isArray(s.imports)&&(t.imports=this.parseImportsV3(s.imports)),this.addAllImportsGetter(t)}if(r.kanonak&&typeof r.kanonak=="object"){let a=r.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(r,t){let a={};for(let[s,e]of Object.entries(r))if(!(s==="kanonak"||s==="namespace"||s==="imports"))if(e&&typeof e=="object"&&v(e.type)){let n={};for(let[i,o]of Object.entries(e))i==="publisher"||i==="version"||i==="imports"||(n[i]=o);a[s]=n}else a[s]=e;return a}parseNamespace(r){if(typeof r=="string"){let e=r.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(e){let n=e[3]?this.parseVersion(e[3]):this.createVersion(1,0,0);return{publisher:e[1],package_:e[2],version:n,toString:()=>r,equals:i=>!i||typeof i!="object"?!1:i.publisher===e[1]&&i.package_===e[2]&&(!n||!i.version||n.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<e[1].length;o++)i=(i<<5)-i+e[1].charCodeAt(o);for(let o=0;o<e[2].length;o++)i=(i<<5)-i+e[2].charCodeAt(o);return i|0}}}}let t=r.publisher||"",a=r.package||"",s=r.version?this.parseVersion(r.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:e=>!e||typeof e!="object"?!1:e.publisher===t&&e.package_===a&&(!s||!e.version||s.equals(e.version)),getHashCode:()=>{let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n);for(let n=0;n<a.length;n++)e=(e<<5)-e+a.charCodeAt(n);return e|0}}}parseVersion(r){if(typeof r=="string"){let t=r.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(r.major||0,r.minor||0,r.patch||0)}parseImportsV3(r){let t={};for(let a of r)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 e of a.packages){if(!e||typeof e!="object")continue;let n=this.parseImportFromEmbeddedObject(e,s);t[s].push(n)}}else{let s=this.parseImportFromEmbeddedObject(a,a.publisher),e=s.publisher||"";t[e]||(t[e]=[]),t[e].push(s)}return t}parseImportsLegacy(r){let t={};for(let[a,s]of Object.entries(r))Array.isArray(s)&&(t[a]=s.map(e=>this.parseImport(e,a)));return t}parseImportFromEmbeddedObject(r,t){let a=r.package;if(!a)throw new Error("Import requires 'package' property");let s=r.match;if(!s)throw new Error("Import requires 'match' property");let e=r.version;if(!e)throw new Error("Import requires 'version' property");let n=this.parseVersion(e),i=this.parseVersionOperator(s),o=this.calculateMaxVersion(s,n),c=r.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(r,t,a,s){return this.parseImport({packageName:r,operator:t,version:a},s)}parseImport(r,t){if(typeof r=="string"){let o=r.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(),g=this.parseVersionOperator(u),V=this.calculateMaxVersion(u,p);return{package_:r,publisher:t,packageName:m,versionOperator:g,version:p,alias:l,minVersion:p,maxVersion:V,toEmbeddedObject:()=>{let y={package:m,match:u,version:p.toString()};return l&&(y.alias=l),y},toString:()=>`${m} ${u} ${p.toString()} as ${l}`}}let c=r.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let m=c[1].trim(),u=c[2],p=this.parseVersion(c[3].trim()),l=this.parseVersionOperator(u),g=this.calculateMaxVersion(u,p);return{package_:r,publisher:t,packageName:m,versionOperator:l,version:p,alias:void 0,minVersion:p,maxVersion:g,toEmbeddedObject:()=>({package:m,match:u,version:p.toString()}),toString:()=>`${m} ${u} ${p.toString()}`}}}let a=this.parseVersionOperator(r.operator||"~"),s=this.parseVersion(r.version||"1.0.0"),e=r.packageName||r.package||"",n=f(a),i=this.calculateMaxVersion(r.operator||"~",s);return{package_:r.package||"",publisher:t,packageName:e,versionOperator:a,version:s,alias:r.alias,minVersion:s,maxVersion:i,toEmbeddedObject:()=>{let o={package:e,match:n,version:s.toString()};return r.alias&&(o.alias=r.alias),o},toString:()=>`${e} ${n} ${s.toString()}`}}parseVersionOperator(r){return k(r)}calculateMaxVersion(r,t){switch(r){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(r){let t=[];for(let[a,s]of Object.entries(r)){let e={publisher:a,packages:s.map(n=>{let i=f(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(e)}return t}};export{$ as a};
@@ -1 +0,0 @@
1
- import{a as c}from"./chunk-FUUTGGJS.js";var m=class{};var p=class extends m{statement=[]};var i=class extends p{namespace;name;icon};var a=class e extends m{subject;static parse(o){let n=new e;return n.subject=c.parse(o),n}};var r=class{predicate;object};var s=class extends r{};var f=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var k=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var x=class extends s{};var d=class e extends r{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=a.parse(n),t}};var l=class extends r{};var b=class extends r{};export{m as a,p as b,i as c,a as d,r as e,s as f,f as g,k as h,x as i,d as j,l as k,b as l};