@kanonak-protocol/sdk 2.4.0 → 2.5.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.
@@ -6,5 +6,5 @@ export type { IKanonakObjectValidator } from './IKanonakObjectValidator.js';
6
6
  export { KanonakObjectValidator } from './KanonakObjectValidator.js';
7
7
  export type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
8
8
  export type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
9
- export { NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakNoExplicitTypeRule } from './rules/document/index.js';
10
- export { ImportExistenceRule, UnresolvedReferenceRule, TypeAmbiguityRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule } from './rules/repository/index.js';
9
+ export { NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule } from './rules/document/index.js';
10
+ export { ImportExistenceRule, UnresolvedReferenceRule, TypeAmbiguityRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule } from './rules/repository/index.js';
@@ -1,47 +1,42 @@
1
- var P=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(o=>(o.Warning="Warning",o.Error="Error",o))(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 ee=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new d;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};import*as Z from"js-yaml";var G=class{parse(e){let o=this.parseWithErrors(e);if(!o.isValid){let t=o.errors[0];throw new Error(`YAML parse error at line ${t.line}, column ${t.column}: ${t.message}`)}return o.document}parseWithErrors(e){let o=[],t;try{e=e.replace(/^\uFEFF/,"");let i=Z.load(e);if(!i||typeof i!="object")return t={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:t,errors:o,isValid:!0};let r=this.extractMetadata(i),n=this.extractBody(i,r);return t={metadata:r,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:t,errors:o,isValid:!0}}catch(i){let r=i,n={message:r.message||"Unknown parse error",line:r.mark?.line??0,column:r.mark?.column??0,errorType:r.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${r.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${r.mark?.line??0}: ${r.message||"Unknown parse error"}`};return o.push(n),{document:void 0,errors:o,isValid:!1}}}save(e){let o={};if(e.metadata.namespace_){let t=e.metadata.namespace_,i={type:"Package",publisher:t.publisher};t.version&&(i.version=`${t.version.major}.${t.version.minor}.${t.version.patch}`),e.metadata.imports&&(i.imports=this.serializeImports(e.metadata.imports)),o[t.package_]=i}return Object.assign(o,e.body),Z.dump(o,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let o=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!o)return[];let t=[];for(let i of Object.values(o))t.push(...i);return t},enumerable:!0,configurable:!0}),e}createVersion(e,o,t){return{major:e,minor:o,patch:t,toString:()=>`${e}.${o}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===o&&r.patch===t,getHashCode:()=>e<<20|o<<10|t,compareTo:r=>e!==r.major?e-r.major:o!==r.minor?o-r.minor:t-r.patch}}extractMetadata(e){let o=this.createEmptyMetadata();for(let[t,i]of Object.entries(e))if(i&&typeof i=="object"&&i.type==="Package"){o.type_="Package";let r=t,n=i.publisher,p=i.version?this.parseVersion(i.version):void 0;return n&&r&&(o.namespace_={publisher:n,package_:r,version:p,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:a=>!a||typeof a!="object"?!1:a.publisher===n&&a.package_===r&&(!p||!a.version||p.equals(a.version)),getHashCode:()=>{let a=0;for(let s=0;s<n.length;s++)a=(a<<5)-a+n.charCodeAt(s);for(let s=0;s<r.length;s++)a=(a<<5)-a+r.charCodeAt(s);return a|0}}),i.imports&&Array.isArray(i.imports)&&(o.imports=this.parseImportsV3(i.imports)),this.addAllImportsGetter(o)}if(e.kanonak&&typeof e.kanonak=="object"){let t=e.kanonak;return(t.publisher||t.package||t.version)&&(o.namespace_=this.parseNamespace(t)),t.imports&&typeof t.imports=="object"&&(o.imports=this.parseImportsLegacy(t.imports)),this.addAllImportsGetter(o)}return o}extractBody(e,o){let t={},i;for(let[r,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){i=r;break}for(let[r,n]of Object.entries(e))r!==i&&r!=="kanonak"&&r!=="namespace"&&r!=="imports"&&(t[r]=n);return t}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let n=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:n,toString:()=>e,equals:p=>!p||typeof p!="object"?!1:p.publisher===r[1]&&p.package_===r[2]&&(!n||!p.version||n.equals(p.version)),getHashCode:()=>{let p=0;for(let a=0;a<r[1].length;a++)p=(p<<5)-p+r[1].charCodeAt(a);for(let a=0;a<r[2].length;a++)p=(p<<5)-p+r[2].charCodeAt(a);return p|0}}}}let o=e.publisher||"",t=e.package||"",i=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:o,package_:t,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:r=>!r||typeof r!="object"?!1:r.publisher===o&&r.package_===t&&(!i||!r.version||i.equals(r.version)),getHashCode:()=>{let r=0;for(let n=0;n<o.length;n++)r=(r<<5)-r+o.charCodeAt(n);for(let n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n);return r|0}}}parseVersion(e){if(typeof e=="string"){let o=e.split(".").map(Number);return this.createVersion(o[0]||0,o[1]||0,o[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let o={};for(let t of e)if(!(!t||typeof t!="object"))if(t.packages&&Array.isArray(t.packages)){let i=t.publisher;if(!i)throw new Error("PublisherImport requires 'publisher' property");o[i]||(o[i]=[]);for(let r of t.packages){if(!r||typeof r!="object")continue;let n=this.parseImportFromEmbeddedObject(r,i);o[i].push(n)}}else{let i=this.parseImportFromEmbeddedObject(t,t.publisher),r=i.publisher||"";o[r]||(o[r]=[]),o[r].push(i)}return o}parseImportsLegacy(e){let o={};for(let[t,i]of Object.entries(e))Array.isArray(i)&&(o[t]=i.map(r=>this.parseImport(r,t)));return o}parseImportFromEmbeddedObject(e,o){let t=e.package;if(!t)throw new Error("Import requires 'package' property");let i=e.match;if(!i)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let n=this.parseVersion(r),p=this.parseVersionOperator(i),a=this.calculateMaxVersion(i,n),s=e.alias;return{package_:`${t} ${i} ${n.toString()}`,publisher:o,packageName:t,versionOperator:p,version:n,alias:s,minVersion:n,maxVersion:a,toEmbeddedObject:()=>{let c={package:t,match:i,version:n.toString()};return s&&(c.alias=s),c},toString:()=>s?`${t} ${i} ${n.toString()} as ${s}`:`${t} ${i} ${n.toString()}`}}parseImport(e,o){if(typeof e=="string"){let a=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(a){let c=a[1].trim(),l=a[2],y=this.parseVersion(a[3].trim()),m=a[4].trim(),u=this.parseVersionOperator(l),f=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:c,versionOperator:u,version:y,alias:m,minVersion:y,maxVersion:f,toEmbeddedObject:()=>{let g={package:c,match:l,version:y.toString()};return m&&(g.alias=m),g},toString:()=>`${c} ${l} ${y.toString()} as ${m}`}}let s=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(s){let c=s[1].trim(),l=s[2],y=this.parseVersion(s[3].trim()),m=this.parseVersionOperator(l),u=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:c,versionOperator:m,version:y,alias:void 0,minVersion:y,maxVersion:u,toEmbeddedObject:()=>({package:c,match:l,version:y.toString()}),toString:()=>`${c} ${l} ${y.toString()}`}}}let t=this.parseVersionOperator(e.operator||"~"),i=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",n=["=","~","^","*"][t],p=this.calculateMaxVersion(e.operator||"~",i);return{package_:e.package||"",publisher:o,packageName:r,versionOperator:t,version:i,alias:e.alias,minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let a={package:r,match:n,version:i.toString()};return e.alias&&(a.alias=e.alias),a},toString:()=>`${r} ${n} ${i.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,o){switch(e){case"~":return this.createVersion(o.major,o.minor+1,0);case"^":return o.major===0?this.createVersion(0,o.minor+1,0):this.createVersion(o.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let o=[];for(let[t,i]of Object.entries(e)){let r={publisher:t,packages:i.map(n=>{let p=["=","~","^","*"][n.versionOperator],a={package:n.packageName,match:p,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(a.alias=n.alias),a})};o.push(r)}return o}};var I=class d{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,i]of Object.entries(e.body))i&&typeof i=="object"&&!Array.isArray(i)&&this.validateEntity(t,i,o);return o}validateEntity(e,o,t){for(let[i,r]of Object.entries(o)){let n=r?.toString()??"";if(n&&d.NAMESPACE_PREFIX_PATTERN.test(n)){let p=this.getSuggestionForPrefixedValue(n),a=e.split(".")[0],s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=a,s.propertyName=e,s.actualValue=i,s.expectedValue=p,s.message=`Invalid namespace prefix '${n}'. Use '${p}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${i}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var D=class d{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[i,r]of Object.entries(e.body)){if(!t&&d.RESERVED_WORDS.has(i.toLowerCase())){let n=new h;n.ruleType=this.ruleName,n.severity="Error",n.entityName=i,n.message=`Entity name '${i}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(n);continue}if(!d.VALID_NAME_PATTERN.test(i)){let n;/^\d/.test(i)?n="Entity names must start with a letter, not a number.":i.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let p=new h;p.ruleType=this.ruleName,p.severity="Error",p.entityName=i,p.message=`Invalid entity name '${i}'. ${n}`,p.suggestion=n,o.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(i,r,o)}return o}validatePropertyNames(e,o,t){for(let i of Object.keys(o))if(!d.VALID_PROPERTIES.has(i)&&!d.VALID_PROPERTY_NAME_PATTERN.test(i)){let r=new h;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=i,r.message=`Property name '${i}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var O=class d{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[i,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let n=r,p=n.type;if(p){let a=[];if(Array.isArray(p))for(let s of p){let c=s?.toString();c&&c==="Property"&&!t&&a.push(c)}else{let s=p?.toString();s&&s==="Property"&&!t&&a.push(s)}for(let s of a){let c=this.getPropertyValue(n,"range"),l=this.determinePropertyType(c),y=new h;y.ruleType=this.ruleName,y.severity="Error",y.entityName=i,y.propertyName="type",y.actualValue=s,y.expectedValue=l,y.message=`Invalid property type '${s}'. Use '${l}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(y)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let i=o.type;if(i){let r=i.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var $=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=i,n="type"in r,p=r.type?.toString().trim();if(!n||!p){let a=new h;a.ruleType=this.ruleName,a.severity="Error",a.entityName=t,a.propertyName="type",a.message=`Subject Kanonak '${t}' must have a 'type' property.`,a.suggestion=`Add a type statement like:
1
+ var P=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(o=>(o.Warning="Warning",o.Error="Error",o))(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 ee=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new d;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};import*as Z from"js-yaml";var G=class{parse(e){let o=this.parseWithErrors(e);if(!o.isValid){let t=o.errors[0];throw new Error(`YAML parse error at line ${t.line}, column ${t.column}: ${t.message}`)}return o.document}parseWithErrors(e){let o=[],t;try{e=e.replace(/^\uFEFF/,"");let i=Z.load(e);if(!i||typeof i!="object")return t={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:t,errors:o,isValid:!0};let r=this.extractMetadata(i),n=this.extractBody(i,r);return t={metadata:r,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:t,errors:o,isValid:!0}}catch(i){let r=i,n={message:r.message||"Unknown parse error",line:r.mark?.line??0,column:r.mark?.column??0,errorType:r.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${r.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${r.mark?.line??0}: ${r.message||"Unknown parse error"}`};return o.push(n),{document:void 0,errors:o,isValid:!1}}}save(e){let o={};if(e.metadata.namespace_){let t=e.metadata.namespace_,i={type:"Package",publisher:t.publisher};t.version&&(i.version=`${t.version.major}.${t.version.minor}.${t.version.patch}`),e.metadata.imports&&(i.imports=this.serializeImports(e.metadata.imports)),o[t.package_]=i}return Object.assign(o,e.body),Z.dump(o,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let o=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!o)return[];let t=[];for(let i of Object.values(o))t.push(...i);return t},enumerable:!0,configurable:!0}),e}createVersion(e,o,t){return{major:e,minor:o,patch:t,toString:()=>`${e}.${o}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===o&&r.patch===t,getHashCode:()=>e<<20|o<<10|t,compareTo:r=>e!==r.major?e-r.major:o!==r.minor?o-r.minor:t-r.patch}}extractMetadata(e){let o=this.createEmptyMetadata();for(let[t,i]of Object.entries(e))if(i&&typeof i=="object"&&i.type==="Package"){o.type_="Package";let r=t,n=i.publisher,a=i.version?this.parseVersion(i.version):void 0;return n&&r&&(o.namespace_={publisher:n,package_:r,version:a,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:p=>!p||typeof p!="object"?!1:p.publisher===n&&p.package_===r&&(!a||!p.version||a.equals(p.version)),getHashCode:()=>{let p=0;for(let s=0;s<n.length;s++)p=(p<<5)-p+n.charCodeAt(s);for(let s=0;s<r.length;s++)p=(p<<5)-p+r.charCodeAt(s);return p|0}}),i.imports&&Array.isArray(i.imports)&&(o.imports=this.parseImportsV3(i.imports)),this.addAllImportsGetter(o)}if(e.kanonak&&typeof e.kanonak=="object"){let t=e.kanonak;return(t.publisher||t.package||t.version)&&(o.namespace_=this.parseNamespace(t)),t.imports&&typeof t.imports=="object"&&(o.imports=this.parseImportsLegacy(t.imports)),this.addAllImportsGetter(o)}return o}extractBody(e,o){let t={},i;for(let[r,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){i=r;break}for(let[r,n]of Object.entries(e))r!==i&&r!=="kanonak"&&r!=="namespace"&&r!=="imports"&&(t[r]=n);return t}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let n=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:n,toString:()=>e,equals:a=>!a||typeof a!="object"?!1:a.publisher===r[1]&&a.package_===r[2]&&(!n||!a.version||n.equals(a.version)),getHashCode:()=>{let a=0;for(let p=0;p<r[1].length;p++)a=(a<<5)-a+r[1].charCodeAt(p);for(let p=0;p<r[2].length;p++)a=(a<<5)-a+r[2].charCodeAt(p);return a|0}}}}let o=e.publisher||"",t=e.package||"",i=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:o,package_:t,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:r=>!r||typeof r!="object"?!1:r.publisher===o&&r.package_===t&&(!i||!r.version||i.equals(r.version)),getHashCode:()=>{let r=0;for(let n=0;n<o.length;n++)r=(r<<5)-r+o.charCodeAt(n);for(let n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n);return r|0}}}parseVersion(e){if(typeof e=="string"){let o=e.split(".").map(Number);return this.createVersion(o[0]||0,o[1]||0,o[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let o={};for(let t of e)if(!(!t||typeof t!="object"))if(t.packages&&Array.isArray(t.packages)){let i=t.publisher;if(!i)throw new Error("PublisherImport requires 'publisher' property");o[i]||(o[i]=[]);for(let r of t.packages){if(!r||typeof r!="object")continue;let n=this.parseImportFromEmbeddedObject(r,i);o[i].push(n)}}else{let i=this.parseImportFromEmbeddedObject(t,t.publisher),r=i.publisher||"";o[r]||(o[r]=[]),o[r].push(i)}return o}parseImportsLegacy(e){let o={};for(let[t,i]of Object.entries(e))Array.isArray(i)&&(o[t]=i.map(r=>this.parseImport(r,t)));return o}parseImportFromEmbeddedObject(e,o){let t=e.package;if(!t)throw new Error("Import requires 'package' property");let i=e.match;if(!i)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let n=this.parseVersion(r),a=this.parseVersionOperator(i),p=this.calculateMaxVersion(i,n),s=e.alias;return{package_:`${t} ${i} ${n.toString()}`,publisher:o,packageName:t,versionOperator:a,version:n,alias:s,minVersion:n,maxVersion:p,toEmbeddedObject:()=>{let c={package:t,match:i,version:n.toString()};return s&&(c.alias=s),c},toString:()=>s?`${t} ${i} ${n.toString()} as ${s}`:`${t} ${i} ${n.toString()}`}}parseImport(e,o){if(typeof e=="string"){let p=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(p){let c=p[1].trim(),l=p[2],y=this.parseVersion(p[3].trim()),u=p[4].trim(),m=this.parseVersionOperator(l),f=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:c,versionOperator:m,version:y,alias:u,minVersion:y,maxVersion:f,toEmbeddedObject:()=>{let g={package:c,match:l,version:y.toString()};return u&&(g.alias=u),g},toString:()=>`${c} ${l} ${y.toString()} as ${u}`}}let s=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(s){let c=s[1].trim(),l=s[2],y=this.parseVersion(s[3].trim()),u=this.parseVersionOperator(l),m=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:c,versionOperator:u,version:y,alias:void 0,minVersion:y,maxVersion:m,toEmbeddedObject:()=>({package:c,match:l,version:y.toString()}),toString:()=>`${c} ${l} ${y.toString()}`}}}let t=this.parseVersionOperator(e.operator||"~"),i=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",n=["=","~","^","*"][t],a=this.calculateMaxVersion(e.operator||"~",i);return{package_:e.package||"",publisher:o,packageName:r,versionOperator:t,version:i,alias:e.alias,minVersion:i,maxVersion:a,toEmbeddedObject:()=>{let p={package:r,match:n,version:i.toString()};return e.alias&&(p.alias=e.alias),p},toString:()=>`${r} ${n} ${i.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,o){switch(e){case"~":return this.createVersion(o.major,o.minor+1,0);case"^":return o.major===0?this.createVersion(0,o.minor+1,0):this.createVersion(o.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let o=[];for(let[t,i]of Object.entries(e)){let r={publisher:t,packages:i.map(n=>{let a=["=","~","^","*"][n.versionOperator],p={package:n.packageName,match:a,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(p.alias=n.alias),p})};o.push(r)}return o}};var I=class d{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,i]of Object.entries(e.body))i&&typeof i=="object"&&!Array.isArray(i)&&this.validateEntity(t,i,o);return o}validateEntity(e,o,t){for(let[i,r]of Object.entries(o)){let n=r?.toString()??"";if(n&&d.NAMESPACE_PREFIX_PATTERN.test(n)){let a=this.getSuggestionForPrefixedValue(n),p=e.split(".")[0],s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=p,s.propertyName=e,s.actualValue=i,s.expectedValue=a,s.message=`Invalid namespace prefix '${n}'. Use '${a}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${i}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var D=class d{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[i,r]of Object.entries(e.body)){if(!t&&d.RESERVED_WORDS.has(i.toLowerCase())){let n=new h;n.ruleType=this.ruleName,n.severity="Error",n.entityName=i,n.message=`Entity name '${i}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(n);continue}if(!d.VALID_NAME_PATTERN.test(i)){let n;/^\d/.test(i)?n="Entity names must start with a letter, not a number.":i.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let a=new h;a.ruleType=this.ruleName,a.severity="Error",a.entityName=i,a.message=`Invalid entity name '${i}'. ${n}`,a.suggestion=n,o.push(a)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(i,r,o)}return o}validatePropertyNames(e,o,t){for(let i of Object.keys(o))if(!d.VALID_PROPERTIES.has(i)&&!d.VALID_PROPERTY_NAME_PATTERN.test(i)){let r=new h;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=i,r.message=`Property name '${i}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var O=class d{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[i,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let n=r,a=n.type;if(a){let p=[];if(Array.isArray(a))for(let s of a){let c=s?.toString();c&&c==="Property"&&!t&&p.push(c)}else{let s=a?.toString();s&&s==="Property"&&!t&&p.push(s)}for(let s of p){let c=this.getPropertyValue(n,"range"),l=this.determinePropertyType(c),y=new h;y.ruleType=this.ruleName,y.severity="Error",y.entityName=i,y.propertyName="type",y.actualValue=s,y.expectedValue=l,y.message=`Invalid property type '${s}'. Use '${l}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(y)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let i=o.type;if(i){let r=i.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var $=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=i,n="type"in r,a=r.type?.toString().trim();if(!n||!a){let p=new h;p.ruleType=this.ruleName,p.severity="Error",p.entityName=t,p.propertyName="type",p.message=`Subject Kanonak '${t}' must have a 'type' property.`,p.suggestion=`Add a type statement like:
2
2
  type: Scene
3
3
 
4
- Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,a.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(a)}}return o}};var w=class{get ruleName(){return"EmbeddedKanonakNoExplicitType"}validate(e){let o=[];for(let[t,i]of Object.entries(e.body))typeof i=="object"&&i!==null&&!Array.isArray(i)&&this.checkForEmbeddedTypeViolations(t,i,o,0);return o}checkForEmbeddedTypeViolations(e,o,t,i){for(let[r,n]of Object.entries(o)){let p=r;if(i>0&&p.toLowerCase()==="type"){let a=n?.toString(),s=e.split(".")[0],c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue="type",c.message=`Embedded object at '${e}' cannot have explicit 'type' property.`,c.suggestion=`Remove the 'type: ${a}' line.
5
-
6
- Type is automatically inferred from the containing property's range.
7
- If you need a different type, modify the 'range' of the parent property and version it appropriately.
8
-
9
- Example: If the parent property is 'hasCharacter' with range 'Character', all embedded objects in that property will be typed as 'Character' automatically.`,c.expectedValue="No explicit type (inferred from parent property's range)",t.push(c)}if(typeof n=="object"&&n!==null)if(Array.isArray(n))for(let a=0;a<n.length;a++){let s=n[a];typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.checkForEmbeddedTypeViolations(`${e}.${p}[${a}]`,s,t,i+1)}else this.checkForEmbeddedTypeViolations(`${e}.${p}`,n,t,i+1)}}};var E=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let i=await o.getAllDocumentsAsync();for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n)if(!await o.getHighestCompatibleVersionAsync(r,p)){let s=await this.determineImportErrorAsync(o,r,p,i),c=new h;c.ruleType=this.ruleName,c.severity="Error",c.message=s.message,c.suggestion=s.suggestion,c.entityName=`Import: ${r}/${p.packageName}`,c.actualValue=p.toString(),c.expectedValue=s.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,o,t,i){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=i.filter(m=>m.metadata.namespace_?.publisher===o).map(m=>m.metadata.namespace_.package_).filter((m,u,f)=>f.indexOf(m)===u),c=this.findSimilarPackages(t.packageName,s),l=`Import '${o}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${o}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:l,suggestion:y,expectedValue:"Existing package"}}let p=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),a=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${p}. Required: ${a}`,expectedValue:a}}getAcceptableVersionRange(e){switch(e.versionOperator){case 0:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case 1:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case 2:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case 3:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(n=>n.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(n.toLowerCase()));if(t.length>0)return t.sort((n,p)=>n.length-p.length);let i=o.map(n=>({package:n,distance:this.levenshteinDistance(e.toLowerCase(),n.toLowerCase())})).sort((n,p)=>n.distance-p.distance),r=Math.max(3,Math.floor(e.length*.4));return i.filter(n=>n.distance<=r).map(n=>n.package)}levenshteinDistance(e,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,i=o.length,r=Array(t+1).fill(null).map(()=>Array(i+1).fill(0));for(let n=0;n<=t;n++)r[n][0]=n;for(let n=0;n<=i;n++)r[0][n]=n;for(let n=1;n<=t;n++)for(let p=1;p<=i;p++){let a=e[n-1]===o[p-1]?0:1;r[n][p]=Math.min(Math.min(r[n-1][p]+1,r[n][p-1]+1),r[n-1][p-1]+a)}return r[t][i]}};var Y=class d{constructor(e,o,t,i){this.publisher=e;this.package_=o;this.name=t;this.version=i}publisher;package_;name;version;static parse(e){if(!e||e.trim().length===0)throw new Error("Kanonak URI string cannot be null or empty");let o=e.split("/");if(o.length!==3)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let[t,i,r]=o;if(!t||!i||!r)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let n=i.indexOf("@");if(n===-1)return new d(t,i,r,void 0);let p=i.substring(0,n),a=i.substring(n+1);if(!p||!a)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let s=a.split(".").map(Number),c=oe(s[0]||0,s[1]||0,s[2]||0);return new d(t,p,r,c)}toString(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}/${this.name}`:`${this.publisher}/${this.package_}/${this.name}`}};function oe(d,e,o){return{major:d,minor:e,patch:o,toString:()=>`${d}.${e}.${o}`,equals:t=>!t||typeof t!="object"?!1:t.major===d&&t.minor===e&&t.patch===o,getHashCode:()=>d<<20|e<<10|o,compareTo:t=>d!==t.major?d-t.major:e!==t.minor?e-t.minor:o-t.patch}}function k(d){if(Array.isArray(d))return d.map(o=>o?.toString()??"").filter(o=>o.length>0);let e=d?.toString();return e?[e]:[]}var V=class{cache=new Map;repository;logger;constructor(e,o){this.repository=e,this.logger=o}async resolveEntityAsync(e,o){let t=o.metadata?.namespace_?.toString()??"unknown",i=this.cache.get(t);if(i){let n=i.get(e);if(n)return n}let r=await this.buildEntityIndexAsyncInternal(o,new Set,"");return this.cache.set(t,r),r.get(e)??null}async resolveAllEntitiesAsync(e,o){let t=await this.buildAllEntitiesIndexAsync(o,new Set,"");if(e.includes(".")){let i=e.split("."),r=i[0],n=i[1],p=await this.findDocumentForAlias(o,r);return p?await this.resolveAllEntitiesAsync(n,p):[]}return t.filter(i=>i.entityName===e)}async buildAllEntitiesIndexAsync(e,o,t){let i=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`;for(let[p,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let s=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.push({entityName:p,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,p,s),entity:a,definedInNamespace:r,isImported:t.length>0,importPath:n})}if(this.logger?.debug?.(`Collected ${i.length} entities from ${r}`),e.metadata?.imports){let p=Object.values(e.metadata.imports).reduce((a,s)=>a+s.length,0);this.logger?.debug?.(`Processing ${p} import(s) for ${r}`);for(let[a,s]of Object.entries(e.metadata.imports))for(let c of s)try{this.logger?.debug?.(`Resolving import: ${a}/${c.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(a,c);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let y=await this.buildAllEntitiesIndexAsync(l,o,n);i.push(...y),this.logger?.debug?.(`Added ${y.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${a}/${c.packageName}`)}catch(l){let y=l;throw this.logger?.error?.(`Failed to process import ${a}/${c.packageName} for namespace ${r}. Error: ${y.message}`,y),new Error(`Failed to process import ${a}/${c.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return i}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,o,t){let i=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`,p=0;for(let[a,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)&&!i.has(a)){let c=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.set(a,{entityName:a,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,a,c),entity:s,definedInNamespace:r,isImported:t.length>0,importPath:n}),p++}if(this.logger?.debug?.(`Indexed ${p} entities from ${r}`),e.metadata?.imports){let a=Object.values(e.metadata.imports).reduce((s,c)=>s+c.length,0);this.logger?.debug?.(`Processing ${a} import(s) for ${r}`);for(let[s,c]of Object.entries(e.metadata.imports))for(let l of c)try{this.logger?.debug?.(`Resolving import: ${s}/${l.packageName}`);let y=await this.repository.getHighestCompatibleVersionAsync(s,l);if(y){this.logger?.debug?.(`Successfully loaded import: ${y.metadata?.namespace_?.toString()}`);let m=await this.buildEntityIndexAsyncInternal(y,o,n),u=0;for(let[f,g]of m.entries())if(i.has(f)||(i.set(f,g),u++),l.alias&&!f.includes(".")){let R=`${l.alias}.${f}`;i.has(R)||(i.set(R,g),u++)}this.logger?.debug?.(`Merged ${u} entities from import ${y.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${s}/${l.packageName}`)}catch(y){let m=y;throw this.logger?.error?.(`Failed to process import ${s}/${l.packageName} for namespace ${r}. Error: ${m.message}`,m),new Error(`Failed to process import ${s}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:y})}}return i}async findDocumentForAlias(e,o){if(!e.metadata?.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i){if(r.alias===o)return await this.repository.getHighestCompatibleVersionAsync(t,r);if(!r.alias&&r.packageName===o)return await this.repository.getHighestCompatibleVersionAsync(t,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubclassOfRecursiveAsync(e,o,t,i)}async isSubclassOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subClassOf;if(n){let p=k(n);for(let a of p)if(a===o||await this.isSubclassOfRecursiveAsync(a,o,t,i))return!0}return!1}async isSubpropertyOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubpropertyOfRecursiveAsync(e,o,t,i)}async isSubpropertyOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subPropertyOf;if(n){let p=k(n);for(let a of p)if(a===o||await this.isSubpropertyOfRecursiveAsync(a,o,t,i))return!0}return!1}};var j=class{ruleName="UnresolvedReference";async validateAsync(e,o){let t=[],i=new V(o),r=await i.buildEntityIndexAsync(e),n=new Set;for(let[p,a]of r.entries()){let s=a.entity.type;if(s){let c=s.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&n.add(p)}}for(let[p,a]of Object.entries(e.body)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a,c=this.getPropertyValue(s,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[l,y]of Object.entries(s))l==="type"||l==="label"||l==="comment"||!(n.has(l)||Array.from(n).some(u=>u.endsWith(`.${l}`)))||await this.validateReferenceValue(p,l,y,e,i,t)}return t}async validateReferenceValue(e,o,t,i,r,n){if(t!=null){if(typeof t=="string")await r.resolveEntityAsync(t,i)||n.push(this.createUnresolvedReferenceError(e,o,t));else if(Array.isArray(t))for(let p=0;p<t.length;p++){let a=t[p];typeof a=="string"&&(await r.resolveEntityAsync(a,i)||n.push(this.createUnresolvedReferenceError(e,`${o}[${p}]`,a)))}}}createUnresolvedReferenceError(e,o,t){let i=`The entity '${t}' cannot be found in the current document or any imported namespaces.
4
+ Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,p.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(p)}}return o}};var Y=class d{constructor(e,o,t,i){this.publisher=e;this.package_=o;this.name=t;this.version=i}publisher;package_;name;version;static parse(e){if(!e||e.trim().length===0)throw new Error("Kanonak URI string cannot be null or empty");let o=e.split("/");if(o.length!==3)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let[t,i,r]=o;if(!t||!i||!r)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let n=i.indexOf("@");if(n===-1)return new d(t,i,r,void 0);let a=i.substring(0,n),p=i.substring(n+1);if(!a||!p)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let s=p.split(".").map(Number),c=oe(s[0]||0,s[1]||0,s[2]||0);return new d(t,a,r,c)}toString(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}/${this.name}`:`${this.publisher}/${this.package_}/${this.name}`}};function oe(d,e,o){return{major:d,minor:e,patch:o,toString:()=>`${d}.${e}.${o}`,equals:t=>!t||typeof t!="object"?!1:t.major===d&&t.minor===e&&t.patch===o,getHashCode:()=>d<<20|e<<10|o,compareTo:t=>d!==t.major?d-t.major:e!==t.minor?e-t.minor:o-t.patch}}function k(d){if(Array.isArray(d))return d.map(o=>o?.toString()??"").filter(o=>o.length>0);let e=d?.toString();return e?[e]:[]}var V=class{cache=new Map;repository;logger;constructor(e,o){this.repository=e,this.logger=o}async resolveEntityAsync(e,o){let t=o.metadata?.namespace_?.toString()??"unknown",i=this.cache.get(t);if(i){let n=i.get(e);if(n)return n}let r=await this.buildEntityIndexAsyncInternal(o,new Set,"");return this.cache.set(t,r),r.get(e)??null}async resolveAllEntitiesAsync(e,o){let t=await this.buildAllEntitiesIndexAsync(o,new Set,"");if(e.includes(".")){let i=e.split("."),r=i[0],n=i[1],a=await this.findDocumentForAlias(o,r);return a?await this.resolveAllEntitiesAsync(n,a):[]}return t.filter(i=>i.entityName===e)}async buildAllEntitiesIndexAsync(e,o,t){let i=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`;for(let[a,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let s=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.push({entityName:a,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,a,s),entity:p,definedInNamespace:r,isImported:t.length>0,importPath:n})}if(this.logger?.debug?.(`Collected ${i.length} entities from ${r}`),e.metadata?.imports){let a=Object.values(e.metadata.imports).reduce((p,s)=>p+s.length,0);this.logger?.debug?.(`Processing ${a} import(s) for ${r}`);for(let[p,s]of Object.entries(e.metadata.imports))for(let c of s)try{this.logger?.debug?.(`Resolving import: ${p}/${c.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(p,c);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let y=await this.buildAllEntitiesIndexAsync(l,o,n);i.push(...y),this.logger?.debug?.(`Added ${y.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${p}/${c.packageName}`)}catch(l){let y=l;throw this.logger?.error?.(`Failed to process import ${p}/${c.packageName} for namespace ${r}. Error: ${y.message}`,y),new Error(`Failed to process import ${p}/${c.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return i}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,o,t){let i=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`,a=0;for(let[p,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)&&!i.has(p)){let c=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.set(p,{entityName:p,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,p,c),entity:s,definedInNamespace:r,isImported:t.length>0,importPath:n}),a++}if(this.logger?.debug?.(`Indexed ${a} entities from ${r}`),e.metadata?.imports){let p=Object.values(e.metadata.imports).reduce((s,c)=>s+c.length,0);this.logger?.debug?.(`Processing ${p} import(s) for ${r}`);for(let[s,c]of Object.entries(e.metadata.imports))for(let l of c)try{this.logger?.debug?.(`Resolving import: ${s}/${l.packageName}`);let y=await this.repository.getHighestCompatibleVersionAsync(s,l);if(y){this.logger?.debug?.(`Successfully loaded import: ${y.metadata?.namespace_?.toString()}`);let u=await this.buildEntityIndexAsyncInternal(y,o,n),m=0;for(let[f,g]of u.entries())if(i.has(f)||(i.set(f,g),m++),l.alias&&!f.includes(".")){let R=`${l.alias}.${f}`;i.has(R)||(i.set(R,g),m++)}this.logger?.debug?.(`Merged ${m} entities from import ${y.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${s}/${l.packageName}`)}catch(y){let u=y;throw this.logger?.error?.(`Failed to process import ${s}/${l.packageName} for namespace ${r}. Error: ${u.message}`,u),new Error(`Failed to process import ${s}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:y})}}return i}async findDocumentForAlias(e,o){if(!e.metadata?.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i){if(r.alias===o)return await this.repository.getHighestCompatibleVersionAsync(t,r);if(!r.alias&&r.packageName===o)return await this.repository.getHighestCompatibleVersionAsync(t,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubclassOfRecursiveAsync(e,o,t,i)}async isSubclassOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subClassOf;if(n){let a=k(n);for(let p of a)if(p===o||await this.isSubclassOfRecursiveAsync(p,o,t,i))return!0}return!1}async isSubpropertyOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubpropertyOfRecursiveAsync(e,o,t,i)}async isSubpropertyOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subPropertyOf;if(n){let a=k(n);for(let p of a)if(p===o||await this.isSubpropertyOfRecursiveAsync(p,o,t,i))return!0}return!1}};var w=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,o){let t=[],i=new V(o),r=await this.buildPropertyRangeMap(e,i);for(let[n,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&await this.checkEmbeddedTypes(n,a,void 0,r,i,e,t,0);return t}async checkEmbeddedTypes(e,o,t,i,r,n,a,p){if(p>0){let s=o.type;if(s!=null){let c=await this.validateEmbeddedType(e,String(s),t,r,n);c&&a.push(c)}}for(let[s,c]of Object.entries(o)){let l=this.localName(s),y=i.has(l)?i.get(l):t;if(typeof c=="object"&&c!==null)if(Array.isArray(c))for(let u=0;u<c.length;u++){let m=c[u];typeof m=="object"&&m!==null&&!Array.isArray(m)&&await this.checkEmbeddedTypes(`${e}.${s}[${u}]`,m,y,i,r,n,a,p+1)}else await this.checkEmbeddedTypes(`${e}.${s}`,c,y,i,r,n,a,p+1)}}async validateEmbeddedType(e,o,t,i,r){if(o.length===0||!t)return null;let n=this.localName(o),a=this.localName(t);if(a==="Resource"||a==="Class")return null;let p=e.split(".")[0];if(n===a){let c=new h;return c.ruleType=this.ruleName,c.severity="Warning",c.entityName=p,c.propertyName=e,c.actualValue=o,c.expectedValue=t,c.message=`Embedded object at '${e}' declares 'type: ${o}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,c.suggestion=`Remove the 'type: ${o}' line, or keep it if explicitness is preferred over concision.`,c}if(await i.isSubclassOfAsync(o,t,r)||(n!==o||a!==t)&&await i.isSubclassOfAsync(n,a,r))return null;let s=new h;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=p,s.propertyName=e,s.actualValue=o,s.expectedValue=t,s.message=`Embedded object at '${e}' has 'type: ${o}', which is not a subclass of the parent property's range '${t}'.`,s.suggestion=`Either remove the 'type: ${o}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${o}' class definition so the relationship holds.`,s}localName(e){let o=e.lastIndexOf(".");return o<0||o===e.length-1?e:e.substring(o+1)}async buildPropertyRangeMap(e,o){let t=new Map,i=await o.buildEntityIndexAsync(e);for(let[r,n]of i){let a=n.entity.type;if(a==null)continue;let p=String(a),s=this.localName(p);if(!(s==="Property"||s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty"))continue;let l=n.entity.range;if(l==null)continue;let y=String(l);y.length!==0&&t.set(this.localName(r),y)}return t}};var E=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let i=await o.getAllDocumentsAsync();for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n)if(!await o.getHighestCompatibleVersionAsync(r,a)){let s=await this.determineImportErrorAsync(o,r,a,i),c=new h;c.ruleType=this.ruleName,c.severity="Error",c.message=s.message,c.suggestion=s.suggestion,c.entityName=`Import: ${r}/${a.packageName}`,c.actualValue=a.toString(),c.expectedValue=s.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,o,t,i){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=i.filter(u=>u.metadata.namespace_?.publisher===o).map(u=>u.metadata.namespace_.package_).filter((u,m,f)=>f.indexOf(u)===m),c=this.findSimilarPackages(t.packageName,s),l=`Import '${o}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${o}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:l,suggestion:y,expectedValue:"Existing package"}}let a=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),p=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${a}. Required: ${p}`,expectedValue:p}}getAcceptableVersionRange(e){switch(e.versionOperator){case 0:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case 1:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case 2:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case 3:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(n=>n.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(n.toLowerCase()));if(t.length>0)return t.sort((n,a)=>n.length-a.length);let i=o.map(n=>({package:n,distance:this.levenshteinDistance(e.toLowerCase(),n.toLowerCase())})).sort((n,a)=>n.distance-a.distance),r=Math.max(3,Math.floor(e.length*.4));return i.filter(n=>n.distance<=r).map(n=>n.package)}levenshteinDistance(e,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,i=o.length,r=Array(t+1).fill(null).map(()=>Array(i+1).fill(0));for(let n=0;n<=t;n++)r[n][0]=n;for(let n=0;n<=i;n++)r[0][n]=n;for(let n=1;n<=t;n++)for(let a=1;a<=i;a++){let p=e[n-1]===o[a-1]?0:1;r[n][a]=Math.min(Math.min(r[n-1][a]+1,r[n][a-1]+1),r[n-1][a-1]+p)}return r[t][i]}};var S=class{ruleName="UnresolvedReference";async validateAsync(e,o){let t=[],i=new V(o),r=await i.buildEntityIndexAsync(e),n=new Set;for(let[a,p]of r.entries()){let s=p.entity.type;if(s){let c=s.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&n.add(a)}}for(let[a,p]of Object.entries(e.body)){if(!p||typeof p!="object"||Array.isArray(p))continue;let s=p,c=this.getPropertyValue(s,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[l,y]of Object.entries(s))l==="type"||l==="label"||l==="comment"||!(n.has(l)||Array.from(n).some(m=>m.endsWith(`.${l}`)))||await this.validateReferenceValue(a,l,y,e,i,t)}return t}async validateReferenceValue(e,o,t,i,r,n){if(t!=null){if(typeof t=="string")await r.resolveEntityAsync(t,i)||n.push(this.createUnresolvedReferenceError(e,o,t));else if(Array.isArray(t))for(let a=0;a<t.length;a++){let p=t[a];typeof p=="string"&&(await r.resolveEntityAsync(p,i)||n.push(this.createUnresolvedReferenceError(e,`${o}[${a}]`,p)))}}}createUnresolvedReferenceError(e,o,t){let i=`The entity '${t}' cannot be found in the current document or any imported namespaces.
10
5
 
11
6
  Possible solutions:
12
7
  \u2022 Add import if the entity is defined in another namespace:
13
8
  kanonak namespace add-import <publisher>/<package>@<version>
14
9
  \u2022 Check for typos in the reference name '${t}'
15
10
  \u2022 Define '${t}' in the current namespace or an appropriate namespace
16
- \u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,r=new h;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t,r.message=`Reference to '${t}' could not be resolved`,r.suggestion=i,r.expectedValue="A valid entity reference that exists in the current document or imported namespaces",r}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,o){let t=[],i=new Map,r=[];if(e.metadata?.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){r.push({doc:s,import:a,publisher:n});let c=await this.getTransitiveImportsAsync(o,s,new Set);r.push(...c.map(l=>({doc:l,import:null,publisher:n})))}}for(let{doc:n,import:p}of r){let a=n.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(n.body))i.has(s)||i.set(s,[]),i.get(s).push({namespace:a,import:p})}for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p;this.checkAmbiguousReference(a,"type",i,n,t),this.checkAmbiguousReference(a,"subClassOf",i,n,t),this.checkAmbiguousReference(a,"subPropertyOf",i,n,t),this.checkAmbiguousReference(a,"domain",i,n,t),this.checkAmbiguousReference(a,"range",i,n,t)}return t}checkAmbiguousReference(e,o,t,i,r){let n=e[o];if(!n)return;let p=k(n);for(let a of p){if(a.includes("."))continue;let s=t.get(a);if(s&&s.length>1){let c=s.map(u=>u.namespace).join(", "),l=[];for(let{namespace:u,import:f}of s)if(f?.alias)l.push(`${f.alias}.${a}`);else{let g=u.split("/"),v=g[g.length-1]?.split("@")[0]??"alias";l.push(`${v}.${a}`)}let y=l.length>0?`Use one of: ${l.join(", ")}`:"Consider adding namespace aliases to your imports",m=new h;m.ruleType=this.ruleName,m.severity="Warning",m.entityName=i,m.propertyName=o,m.actualValue=a,m.message=`Type '${a}' is ambiguous. It's defined in: ${c}`,m.suggestion=y,r.push(m)}}}async getTransitiveImportsAsync(e,o,t){let i=[],r=o.metadata?.namespace_?.toString()??"";if(t.has(r))return i;if(t.add(r),o.metadata?.imports)for(let[n,p]of Object.entries(o.metadata.imports))for(let a of p){let s=await e.getHighestCompatibleVersionAsync(n,a);if(s){i.push(s);let c=await this.getTransitiveImportsAsync(e,s,t);i.push(...c)}}return i}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildClassHierarchy(e,o,i,r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type,c=a.subClassOf;if(s?.toString()==="Class"&&c){let l=n,y=this.detectCycle(l,i);if(y){let m=y.join(" \u2192 "),u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${m}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=l,u.propertyName="subClassOf",u.actualValue=m,t.push(u);break}}}return t}async buildClassHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type,c=a.subClassOf;if(s?.toString()==="Class"&&c){let l=k(c);l.length>0&&t.set(n,l)}}if(e.metadata?.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);s&&await this.buildClassHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),p=t.slice(n);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let p=this.detectCycleRecursive(n,o,t,i);if(p)return p}return t.pop(),null}};var K=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildPropertyHierarchy(e,o,i,r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)&&p.subPropertyOf){let c=n,l=this.detectCycle(c,i);if(l){let y=l.join(" \u2192 "),m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${y}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=c,m.propertyName="subPropertyOf",m.actualValue=y,t.push(m);break}}return t}async buildPropertyHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type;if(s){let c=s.toString();if(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"){let l=a.subPropertyOf;if(l){let y=k(l);y.length>0&&t.set(n,y)}}}}if(e.metadata?.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);s&&await this.buildPropertyHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),p=t.slice(n);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let p=this.detectCycleRecursive(n,o,t,i);if(p)return p}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,o){let t=[];for(let[i,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let n=r,p=n.type?.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p?.endsWith(".DatatypeProperty")||p?.endsWith(".ObjectProperty")){let a="range"in n,s=n.range?.toString().trim();if(!a||!s){let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=i,c.propertyName="range",c.message=`Property '${i}' must have a 'range' defined.`,c.suggestion=p==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",c.expectedValue=p==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(c)}}}return t}};var x=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();(a==="Class"||a&&a.endsWith(".Class"))&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=k(n.subClassOf);for(let s=0;s<a.length;s++){let c=a[s];if(this.builtInClasses.has(c)||i.has(c))continue;if(!await this.isClassAvailableInImports(e,o,c)){let y=a.length>1?`[${s}]`:"",m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Class '${c}' referenced in subClassOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a Class, or import a namespace that contains it`,m.entityName=r,m.propertyName="subClassOf",m.actualValue=c,m.expectedValue="Defined or imported class",t.push(m)}}}return t}async isClassAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(u==="Class"||u&&u.endsWith(".Class"))return!0}let y=new Set;if(await this.isClassAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isClassAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="Class"||y&&y.endsWith(".Class"))return!0}if(await this.isClassAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var T=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();(a==="DatatypeProperty"||a==="ObjectProperty"||a==="AnnotationProperty")&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=k(n.subPropertyOf);for(let s=0;s<a.length;s++){let c=a[s];if(this.builtInProperties.has(c)||i.has(c))continue;if(!await this.isPropertyAvailableInImports(e,o,c)){let y=a.length>1?`[${s}]`:"",m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${c}' referenced in subPropertyOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,m.entityName=r,m.propertyName="subPropertyOf",m.actualValue=c,m.expectedValue="Defined or imported property",t.push(m)}}}return t}async isPropertyAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let y=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var _=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],i=e.metadata.namespace_?.toString();if(!i)return t;let r=new Map,n=new Set;await this.buildImportGraph(e,o,r,n);let p=this.detectCycle(i,r);if(p){let a=p.join(" \u2192 "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${a}`,s.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=a,t.push(s)}return t}async buildImportGraph(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!(!r||i.has(r))&&(i.add(r),e.metadata.imports)){let n=[];for(let[p,a]of Object.entries(e.metadata.imports))for(let s of a){let c=`${p}/${s.packageName}@${s.version}`;n.push(c);let l=await o.getHighestCompatibleVersionAsync(p,s);l&&await this.buildImportGraph(l,o,t,i)}n.length>0&&t.set(r,n)}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){let r=t.indexOf(e);if(r>=0){let p=t.slice(r);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let n=o.get(e);if(n)for(let p of n){let a=this.detectCycleRecursive(p,o,t,i);if(a)return a}return t.pop(),null}};var M=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();this.isPropertyType(a)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=p.type?.toString();if(this.isPropertyType(a)||this.isClassType(a))continue;for(let[s,c]of Object.entries(p)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let u=s.lastIndexOf(".");y=s.substring(0,u),l=s.substring(u+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${s}' is not defined or imported`,u.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
11
+ \u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,r=new h;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t,r.message=`Reference to '${t}' could not be resolved`,r.suggestion=i,r.expectedValue="A valid entity reference that exists in the current document or imported namespaces",r}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}};var j=class{ruleName="TypeAmbiguity";async validateAsync(e,o){let t=[],i=new Map,r=[];if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){r.push({doc:s,import:p,publisher:n});let c=await this.getTransitiveImportsAsync(o,s,new Set);r.push(...c.map(l=>({doc:l,import:null,publisher:n})))}}for(let{doc:n,import:a}of r){let p=n.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(n.body))i.has(s)||i.set(s,[]),i.get(s).push({namespace:p,import:a})}for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let p=a;this.checkAmbiguousReference(p,"type",i,n,t),this.checkAmbiguousReference(p,"subClassOf",i,n,t),this.checkAmbiguousReference(p,"subPropertyOf",i,n,t),this.checkAmbiguousReference(p,"domain",i,n,t),this.checkAmbiguousReference(p,"range",i,n,t)}return t}checkAmbiguousReference(e,o,t,i,r){let n=e[o];if(!n)return;let a=k(n);for(let p of a){if(p.includes("."))continue;let s=t.get(p);if(s&&s.length>1){let c=s.map(m=>m.namespace).join(", "),l=[];for(let{namespace:m,import:f}of s)if(f?.alias)l.push(`${f.alias}.${p}`);else{let g=m.split("/"),v=g[g.length-1]?.split("@")[0]??"alias";l.push(`${v}.${p}`)}let y=l.length>0?`Use one of: ${l.join(", ")}`:"Consider adding namespace aliases to your imports",u=new h;u.ruleType=this.ruleName,u.severity="Warning",u.entityName=i,u.propertyName=o,u.actualValue=p,u.message=`Type '${p}' is ambiguous. It's defined in: ${c}`,u.suggestion=y,r.push(u)}}}async getTransitiveImportsAsync(e,o,t){let i=[],r=o.metadata?.namespace_?.toString()??"";if(t.has(r))return i;if(t.add(r),o.metadata?.imports)for(let[n,a]of Object.entries(o.metadata.imports))for(let p of a){let s=await e.getHighestCompatibleVersionAsync(n,p);if(s){i.push(s);let c=await this.getTransitiveImportsAsync(e,s,t);i.push(...c)}}return i}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildClassHierarchy(e,o,i,r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let p=a,s=p.type,c=p.subClassOf;if(s?.toString()==="Class"&&c){let l=n,y=this.detectCycle(l,i);if(y){let u=y.join(" \u2192 "),m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular class hierarchy detected: ${u}`,m.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",m.entityName=l,m.propertyName="subClassOf",m.actualValue=u,t.push(m);break}}}return t}async buildClassHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let p=a,s=p.type,c=p.subClassOf;if(s?.toString()==="Class"&&c){let l=k(c);l.length>0&&t.set(n,l)}}if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);s&&await this.buildClassHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),a=t.slice(n);return a.push(e),a}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let a=this.detectCycleRecursive(n,o,t,i);if(a)return a}return t.pop(),null}};var K=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildPropertyHierarchy(e,o,i,r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)&&a.subPropertyOf){let c=n,l=this.detectCycle(c,i);if(l){let y=l.join(" \u2192 "),u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular property hierarchy detected: ${y}`,u.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",u.entityName=c,u.propertyName="subPropertyOf",u.actualValue=y,t.push(u);break}}return t}async buildPropertyHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let p=a,s=p.type;if(s){let c=s.toString();if(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"){let l=p.subPropertyOf;if(l){let y=k(l);y.length>0&&t.set(n,y)}}}}if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);s&&await this.buildPropertyHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),a=t.slice(n);return a.push(e),a}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let a=this.detectCycleRecursive(n,o,t,i);if(a)return a}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,o){let t=[];for(let[i,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let n=r,a=n.type?.toString();if(a==="DatatypeProperty"||a==="ObjectProperty"||a?.endsWith(".DatatypeProperty")||a?.endsWith(".ObjectProperty")){let p="range"in n,s=n.range?.toString().trim();if(!p||!s){let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=i,c.propertyName="range",c.message=`Property '${i}' must have a 'range' defined.`,c.suggestion=a==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",c.expectedValue=a==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(c)}}}return t}};var x=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n.type?.toString();(p==="Class"||p&&p.endsWith(".Class"))&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=k(n.subClassOf);for(let s=0;s<p.length;s++){let c=p[s];if(this.builtInClasses.has(c)||i.has(c))continue;if(!await this.isClassAvailableInImports(e,o,c)){let y=p.length>1?`[${s}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Class '${c}' referenced in subClassOf${y} is not defined or imported`,u.suggestion=`Define '${c}' as a Class, or import a namespace that contains it`,u.entityName=r,u.propertyName="subClassOf",u.actualValue=c,u.expectedValue="Defined or imported class",t.push(u)}}}return t}async isClassAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){if(i!==null&&p.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let m=l.type?.toString();if(m==="Class"||m&&m.endsWith(".Class"))return!0}let y=new Set;if(await this.isClassAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isClassAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="Class"||y&&y.endsWith(".Class"))return!0}if(await this.isClassAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var T=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n.type?.toString();(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty")&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=k(n.subPropertyOf);for(let s=0;s<p.length;s++){let c=p[s];if(this.builtInProperties.has(c)||i.has(c))continue;if(!await this.isPropertyAvailableInImports(e,o,c)){let y=p.length>1?`[${s}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${c}' referenced in subPropertyOf${y} is not defined or imported`,u.suggestion=`Define '${c}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,u.entityName=r,u.propertyName="subPropertyOf",u.actualValue=c,u.expectedValue="Defined or imported property",t.push(u)}}}return t}async isPropertyAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){if(i!==null&&p.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let m=l.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}let y=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var _=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],i=e.metadata.namespace_?.toString();if(!i)return t;let r=new Map,n=new Set;await this.buildImportGraph(e,o,r,n);let a=this.detectCycle(i,r);if(a){let p=a.join(" \u2192 "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${p}`,s.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=p,t.push(s)}return t}async buildImportGraph(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!(!r||i.has(r))&&(i.add(r),e.metadata.imports)){let n=[];for(let[a,p]of Object.entries(e.metadata.imports))for(let s of p){let c=`${a}/${s.packageName}@${s.version}`;n.push(c);let l=await o.getHighestCompatibleVersionAsync(a,s);l&&await this.buildImportGraph(l,o,t,i)}n.length>0&&t.set(r,n)}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){let r=t.indexOf(e);if(r>=0){let a=t.slice(r);return a.push(e),a}if(i.has(e))return null;t.push(e),i.add(e);let n=o.get(e);if(n)for(let a of n){let p=this.detectCycleRecursive(a,o,t,i);if(p)return p}return t.pop(),null}};var M=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n.type?.toString();this.isPropertyType(p)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,p=a.type?.toString();if(this.isPropertyType(p)||this.isClassType(p))continue;for(let[s,c]of Object.entries(a)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let m=s.lastIndexOf(".");y=s.substring(0,m),l=s.substring(m+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${s}' is not defined or imported`,m.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
17
12
  1. Verify the namespace is imported with the correct alias
18
13
  2. Check if the property name is spelled correctly
19
14
  3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
20
15
  1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
21
16
  2. Import the namespace that contains '${s}', OR
22
- 3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,u.entityName=r,u.propertyName=s,u.actualValue=c?.toString(),u.expectedValue="A defined or imported property",t.push(u)}}}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,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){if(i!==null&&p.alias!==i)continue;let a=await o.getHighestCompatibleVersionAsync(r,p);if(a){let s=a.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(a,o,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();this.isPropertyType(a)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=p.type?.toString();if(!this.isPropertyType(a)&&!this.isClassType(a))continue;for(let[s,c]of Object.entries(p)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let u=s.lastIndexOf(".");y=s.substring(0,u),l=s.substring(u+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let u=this.isClassType(a)?"class":"property",f=new h;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${s}' used on ${u} '${r}' is not defined or imported`,f.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
17
+ 3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,m.entityName=r,m.propertyName=s,m.actualValue=c?.toString(),m.expectedValue="A defined or imported property",t.push(m)}}}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,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){if(i!==null&&a.alias!==i)continue;let p=await o.getHighestCompatibleVersionAsync(r,a);if(p){let s=p.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(p,o,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n.type?.toString();this.isPropertyType(p)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,p=a.type?.toString();if(!this.isPropertyType(p)&&!this.isClassType(p))continue;for(let[s,c]of Object.entries(a)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let m=s.lastIndexOf(".");y=s.substring(0,m),l=s.substring(m+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let m=this.isClassType(p)?"class":"property",f=new h;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${s}' used on ${m} '${r}' is not defined or imported`,f.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
23
18
  1. Verify the namespace is imported with the correct alias
24
19
  2. Check if the property name is spelled correctly
25
20
  3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
26
21
  1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
27
22
  2. Import the namespace that contains '${s}', OR
28
- 3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=r,f.propertyName=s,f.actualValue=c?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){if(i!==null&&p.alias!==i)continue;let a=await o.getHighestCompatibleVersionAsync(r,p);if(a){let s=a.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(a,o,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var L=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,o){let t=[],i=new Set,r=[];for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=!1,c=a.type;if(Array.isArray(c)){for(let l of c)if(l?.toString()==="DatatypeProperty"){s=!0;break}}else c?.toString()==="DatatypeProperty"&&(s=!0);if(s){r.push(n);let l=this.getPropertyValue(a,"range");l&&this.xsdTypes.has(l)&&i.add(l)}}if(i.size>0&&!await this.checkXsdImportAsync(e.metadata,o)){let p=Array.from(i).sort().join(", "),a=r.sort().join(", "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`XSD namespace not imported but XSD types are used: ${p}`,s.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${a}`,s.entityName="imports",t.push(s)}return t}async checkXsdImportAsync(e,o,t=new Set){if(!e?.imports)return!1;let i=e.namespace_?.toString()??"";if(i&&t.has(i))return!1;i&&t.add(i);for(let[,r]of Object.entries(e.imports))for(let n of r)if(n.packageName==="xsd"||n.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[r,n]of Object.entries(e.imports))for(let p of n){let a=await o.getHighestCompatibleVersionAsync(r,p);if(a?.metadata&&await this.checkXsdImportAsync(a.metadata,o,t))return!0}return!1}getPropertyValue(e,o){return e[o]?.toString()}};var H=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,o){let t=[],i=await this.buildEntitySourceMapAsync(e,o),r=await this.buildDatatypePropertyNamesAsync(e,o);for(let[n,p]of Object.entries(e.body))typeof p=="object"&&p!==null&&!Array.isArray(p)&&this.validateEntityReferences(n,p,i,r,e,t);return t}async buildEntitySourceMapAsync(e,o){let t=new Map,i=new Set;for(let r of Object.keys(e.body)){let n=e.metadata.namespace_?.toString()??"";t.has(r)||t.set(r,[]),t.get(r).push(`(local:${n})`)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){let a=await o.getHighestCompatibleVersionAsync(r,p);a&&await this.collectEntitiesRecursivelyAsync(a,t,i,o)}return t}async collectEntitiesRecursivelyAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let n of Object.keys(e.body)){o.has(n)||o.set(n,[]);let p=o.get(n);p.includes(r)||p.push(r)}if(e.metadata.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await i.getHighestCompatibleVersionAsync(n,a);s&&await this.collectEntitiesRecursivelyAsync(s,o,t,i)}}}async buildDatatypePropertyNamesAsync(e,o){let t=new Set,i=new Set;if(await this.collectDatatypePropertiesAsync(e,t,i,o),e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){let a=await o.getHighestCompatibleVersionAsync(r,p);a&&await this.collectDatatypePropertiesAsync(a,t,i,o)}return t}async collectDatatypePropertiesAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let[n,p]of Object.entries(e.body)){if(typeof p!="object"||p===null||Array.isArray(p))continue;let a=p.type;if(typeof a!="string")continue;(a.includes(".")?a.substring(a.lastIndexOf(".")+1):a)==="DatatypeProperty"&&o.add(n)}if(e.metadata.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await i.getHighestCompatibleVersionAsync(n,a);s&&await this.collectDatatypePropertiesAsync(s,o,t,i)}}}validateEntityReferences(e,o,t,i,r,n){for(let[p,a]of Object.entries(o)){let s=p;if(s&&!s.includes(".")){let c=t.get(s);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,r,!0,s))}}this.validatePropertyValue(e,s,a,t,i,r,n)}}validatePropertyValue(e,o,t,i,r,n,p){if(t==null)return;let a=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o,s=!!a&&r.has(a);if(typeof t=="string"&&!t.includes(".")&&!s){let c=i.get(t);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&p.push(this.createAmbiguityError(e,o,`Reference '${t}'`,y,n,!1,t))}}else if(Array.isArray(t))for(let c=0;c<t.length;c++){let l=`${e}.${o}[${c}]`;this.validatePropertyValue(l,o,t[c],i,r,n,p)}else if(typeof t=="object"&&!Array.isArray(t)){let c=o?`${e}.${o}`:e;this.validateEntityReferences(c,t,i,r,n,p)}}createAmbiguityError(e,o,t,i,r,n,p){let a=[];for(let f of i){let g=this.findAliasForNamespace(r,f);if(g){let R=o?.split(".").pop()??o;a.push(`${g}.${R}`)}}let s=a.length>0?`Use one of: ${a.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${o}')`,c=i.map(f=>` \u2022 ${f}`).join(`
29
- `),l=e.split(".")[0],y=e.includes(".")?e:o,m=new h;m.ruleType=this.ruleName,m.severity="Error",m.entityName=l,y&&(m.propertyName=y);let u=p??o;return u&&(m.actualValue=u),m.message=`${t} is ambiguous - defined in multiple imported namespaces`,m.suggestion=`${s}
23
+ 3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=r,f.propertyName=s,f.actualValue=c?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){if(i!==null&&a.alias!==i)continue;let p=await o.getHighestCompatibleVersionAsync(r,a);if(p){let s=p.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(p,o,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var L=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,o){let t=[],i=new Set,r=[];for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let p=a,s=!1,c=p.type;if(Array.isArray(c)){for(let l of c)if(l?.toString()==="DatatypeProperty"){s=!0;break}}else c?.toString()==="DatatypeProperty"&&(s=!0);if(s){r.push(n);let l=this.getPropertyValue(p,"range");l&&this.xsdTypes.has(l)&&i.add(l)}}if(i.size>0&&!await this.checkXsdImportAsync(e.metadata,o)){let a=Array.from(i).sort().join(", "),p=r.sort().join(", "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`XSD namespace not imported but XSD types are used: ${a}`,s.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${p}`,s.entityName="imports",t.push(s)}return t}async checkXsdImportAsync(e,o,t=new Set){if(!e?.imports)return!1;let i=e.namespace_?.toString()??"";if(i&&t.has(i))return!1;i&&t.add(i);for(let[,r]of Object.entries(e.imports))for(let n of r)if(n.packageName==="xsd"||n.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[r,n]of Object.entries(e.imports))for(let a of n){let p=await o.getHighestCompatibleVersionAsync(r,a);if(p?.metadata&&await this.checkXsdImportAsync(p.metadata,o,t))return!0}return!1}getPropertyValue(e,o){return e[o]?.toString()}};var H=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,o){let t=[],i=await this.buildEntitySourceMapAsync(e,o),r=await this.buildDatatypePropertyNamesAsync(e,o);for(let[n,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&this.validateEntityReferences(n,a,i,r,e,t);return t}async buildEntitySourceMapAsync(e,o){let t=new Map,i=new Set;for(let r of Object.keys(e.body)){let n=e.metadata.namespace_?.toString()??"";t.has(r)||t.set(r,[]),t.get(r).push(`(local:${n})`)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){let p=await o.getHighestCompatibleVersionAsync(r,a);p&&await this.collectEntitiesRecursivelyAsync(p,t,i,o)}return t}async collectEntitiesRecursivelyAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let n of Object.keys(e.body)){o.has(n)||o.set(n,[]);let a=o.get(n);a.includes(r)||a.push(r)}if(e.metadata.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await i.getHighestCompatibleVersionAsync(n,p);s&&await this.collectEntitiesRecursivelyAsync(s,o,t,i)}}}async buildDatatypePropertyNamesAsync(e,o){let t=new Set,i=new Set;if(await this.collectDatatypePropertiesAsync(e,t,i,o),e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let a of n){let p=await o.getHighestCompatibleVersionAsync(r,a);p&&await this.collectDatatypePropertiesAsync(p,t,i,o)}return t}async collectDatatypePropertiesAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let[n,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let p=a.type;if(typeof p!="string")continue;(p.includes(".")?p.substring(p.lastIndexOf(".")+1):p)==="DatatypeProperty"&&o.add(n)}if(e.metadata.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await i.getHighestCompatibleVersionAsync(n,p);s&&await this.collectDatatypePropertiesAsync(s,o,t,i)}}}validateEntityReferences(e,o,t,i,r,n){for(let[a,p]of Object.entries(o)){let s=a;if(s&&!s.includes(".")){let c=t.get(s);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(u=>!u.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,r,!0,s))}}this.validatePropertyValue(e,s,p,t,i,r,n)}}validatePropertyValue(e,o,t,i,r,n,a){if(t==null)return;let p=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o,s=!!p&&r.has(p);if(typeof t=="string"&&!t.includes(".")&&!s){let c=i.get(t);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(u=>!u.startsWith("(local:"));y.length>1&&a.push(this.createAmbiguityError(e,o,`Reference '${t}'`,y,n,!1,t))}}else if(Array.isArray(t))for(let c=0;c<t.length;c++){let l=`${e}.${o}[${c}]`;this.validatePropertyValue(l,o,t[c],i,r,n,a)}else if(typeof t=="object"&&!Array.isArray(t)){let c=o?`${e}.${o}`:e;this.validateEntityReferences(c,t,i,r,n,a)}}createAmbiguityError(e,o,t,i,r,n,a){let p=[];for(let f of i){let g=this.findAliasForNamespace(r,f);if(g){let R=o?.split(".").pop()??o;p.push(`${g}.${R}`)}}let s=p.length>0?`Use one of: ${p.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${o}')`,c=i.map(f=>` \u2022 ${f}`).join(`
24
+ `),l=e.split(".")[0],y=e.includes(".")?e:o,u=new h;u.ruleType=this.ruleName,u.severity="Error",u.entityName=l,y&&(u.propertyName=y);let m=a??o;return m&&(u.actualValue=m),u.message=`${t} is ambiguous - defined in multiple imported namespaces`,u.suggestion=`${s}
30
25
 
31
26
  Defined in:
32
- ${c}`,m.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",m}findAliasForNamespace(e,o){if(!e.metadata.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i)if(`${t}/${r.packageName}@${r.version}`===o&&r.alias)return r.alias;return null}};var F=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,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();this.isValidRangeTargetType(a)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=p.type?.toString();if(a!=="DatatypeProperty"&&a!=="ObjectProperty"&&!a?.endsWith(".DatatypeProperty")&&!a?.endsWith(".ObjectProperty"))continue;let s=p.range;if(!s)continue;let c=[];if(Array.isArray(s))for(let l of s){let y=l?.toString();y&&c.push(y)}else{let l=s?.toString();l&&c.push(l)}if(c.length===0)continue;for(let l of c){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||i.has(l))continue;if(!await this.isTypeAvailableInImports(e,o,l)){let m=a?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${r}' has range '${l}' which is not defined or imported`,u.suggestion=m==="ObjectProperty"?`For ObjectProperty:
27
+ ${c}`,u.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",u}findAliasForNamespace(e,o){if(!e.metadata.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i)if(`${t}/${r.packageName}@${r.version}`===o&&r.alias)return r.alias;return null}};var F=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,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n.type?.toString();this.isValidRangeTargetType(p)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,p=a.type?.toString();if(p!=="DatatypeProperty"&&p!=="ObjectProperty"&&!p?.endsWith(".DatatypeProperty")&&!p?.endsWith(".ObjectProperty"))continue;let s=a.range;if(!s)continue;let c=[];if(Array.isArray(s))for(let l of s){let y=l?.toString();y&&c.push(y)}else{let l=s?.toString();l&&c.push(l)}if(c.length===0)continue;for(let l of c){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||i.has(l))continue;if(!await this.isTypeAvailableInImports(e,o,l)){let u=p?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${r}' has range '${l}' which is not defined or imported`,m.suggestion=u==="ObjectProperty"?`For ObjectProperty:
33
28
  1. Define '${l}' as a Class in this namespace, OR
34
29
  2. Import the namespace that contains '${l}', OR
35
30
  3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
36
31
  1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
37
- 2. If '${l}' should be a class, change property type to ObjectProperty`,u.entityName=r,u.propertyName="range",u.actualValue=l,u.expectedValue=m==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(this.isValidRangeTargetType(u))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var U=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,o){let t=[],i=new Map,r=new V(o);await r.buildEntityIndexAsync(e);for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=!1,c=a.type;if(Array.isArray(c)){for(let l of c)if(l?.toString()==="ObjectProperty"){s=!0;break}}else c?.toString()==="ObjectProperty"&&(s=!0);if(s){let l=a.range,y=[];if(Array.isArray(l))for(let m of l){let u=m?.toString();u&&y.push(u)}else{let m=l?.toString();m&&y.push(m)}for(let m of y)this.xsdTypes.has(m)||(i.has(m)||i.set(m,[]),i.get(m).push(n))}}for(let[n,p]of i)if(!await r.resolveEntityAsync(n,e))for(let s of p){let c=new h;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${n}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${n}' is imported, or define '${n}' in this document`,c.entityName=s,c.propertyName="range",c.actualValue=n,t.push(c)}return t}};var J=class d{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","bool","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.xsd"&&d.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.rdf"&&e.name==="Literal":!1}isKnownXsdDatatypeName(e){let o=e.includes(".")?e.split(".")[1]:e;return d.KNOWN_XSD_DATATYPES.has(o.toLowerCase())}async isClassTypeAsync(e,o){if(this.isKnownXsdDatatypeName(e))return!1;let t=await this.resourceResolver.resolveEntityAsync(e,o);if(t){let i=t.entity.type;if(i){let r=String(i);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,o){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(o)||e==="Property"&&this.isLiteralType(o))}isEffectiveObjectProperty(e,o){return!!(e==="ObjectProperty"||e==="Property"&&o&&!this.isXsdDatatype(o)&&!this.isLiteralType(o))}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,o){let t=[],i=new V(o),r=new J(i),n=await i.buildEntityIndexAsync(e),p=await this.buildPropertyMetadataAsync(e,o,i,n);for(let[a,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,a,"",p,i,r,e,t);return t}async scanEntityForObjectProperties(e,o,t,i,r,n,p,a){for(let[s,c]of Object.entries(e)){if(this.standardProperties.has(s))continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let m=i.get(l);if(m&&n.isEffectiveObjectProperty(m.propertyType,m.rangeUri)){let f=t?`${t}.${s}`:s;if(typeof c=="string"&&c.trim().length>0){let g=c.trim();if(g.includes(",")){let v=g.split(",").map(A=>A.trim()).filter(A=>A.length>0);a.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
32
+ 2. If '${l}' should be a class, change property type to ObjectProperty`,m.entityName=r,m.propertyName="range",m.actualValue=l,m.expectedValue=u==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(m)}}}return t}async isTypeAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){if(i!==null&&p.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let m=l.type?.toString();if(this.isValidRangeTargetType(m))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(n,p);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var U=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,o){let t=[],i=new Map,r=new V(o);await r.buildEntityIndexAsync(e);for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let p=a,s=!1,c=p.type;if(Array.isArray(c)){for(let l of c)if(l?.toString()==="ObjectProperty"){s=!0;break}}else c?.toString()==="ObjectProperty"&&(s=!0);if(s){let l=p.range,y=[];if(Array.isArray(l))for(let u of l){let m=u?.toString();m&&y.push(m)}else{let u=l?.toString();u&&y.push(u)}for(let u of y)this.xsdTypes.has(u)||(i.has(u)||i.set(u,[]),i.get(u).push(n))}}for(let[n,a]of i)if(!await r.resolveEntityAsync(n,e))for(let s of a){let c=new h;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${n}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${n}' is imported, or define '${n}' in this document`,c.entityName=s,c.propertyName="range",c.actualValue=n,t.push(c)}return t}};var J=class d{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","bool","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.xsd"&&d.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.rdf"&&e.name==="Literal":!1}isKnownXsdDatatypeName(e){let o=e.includes(".")?e.split(".")[1]:e;return d.KNOWN_XSD_DATATYPES.has(o.toLowerCase())}async isClassTypeAsync(e,o){if(this.isKnownXsdDatatypeName(e))return!1;let t=await this.resourceResolver.resolveEntityAsync(e,o);if(t){let i=t.entity.type;if(i){let r=String(i);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,o){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(o)||e==="Property"&&this.isLiteralType(o))}isEffectiveObjectProperty(e,o){return!!(e==="ObjectProperty"||e==="Property"&&o&&!this.isXsdDatatype(o)&&!this.isLiteralType(o))}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,o){let t=[],i=new V(o),r=new J(i),n=await i.buildEntityIndexAsync(e),a=await this.buildPropertyMetadataAsync(e,o,i,n);for(let[p,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,p,"",a,i,r,e,t);return t}async scanEntityForObjectProperties(e,o,t,i,r,n,a,p){for(let[s,c]of Object.entries(e)){if(this.standardProperties.has(s))continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let u=i.get(l);if(u&&n.isEffectiveObjectProperty(u.propertyType,u.rangeUri)){let f=t?`${t}.${s}`:s;if(typeof c=="string"&&c.trim().length>0){let g=c.trim();if(g.includes(",")){let v=g.split(",").map(A=>A.trim()).filter(A=>A.length>0);p.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
38
33
  ${s}:
39
34
  - ${v[0]}
40
35
  ${v.slice(1).map(A=>` - ${A}`).join(`
41
- `)}`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:`A single reference to ${m.range??"an entity"} OR a YAML list`});continue}let R=await r.resolveEntityAsync(g,p);if(R)m.range&&(await this.validateRangeType(R,m.range,r,p)||a.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${m.range}, but '${g}' may not be a ${m.range}`,suggestion:`Ensure '${g}' is defined with appropriate type`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:m.range}));else{let v=m.range??"entity";a.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${g}' which is not defined or imported`,suggestion:`Define '${g}' or import a namespace that contains it. Expected range: ${v}`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let g=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,g,i,r,n,p,a)}else if(Array.isArray(c))for(let g=0;g<c.length;g++){let R=c[g];if(typeof R=="string"&&R.trim().length>0){let v=R.trim(),A=await r.resolveEntityAsync(v,p);if(A){if(m.range&&!await this.validateRangeType(A,m.range,r,p)){let Q=t?`${t}.${s}[${g}]`:`${s}[${g}]`;a.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${m.range}, but '${v}' may not be a ${m.range}`,suggestion:`Ensure '${v}' is defined with appropriate type`,entityName:o,propertyName:`${s}[${g}]`,propertyPath:Q,actualValue:v,expectedValue:m.range})}}else{let re=m.range??"entity",Q=t?`${t}.${s}[${g}]`:`${s}[${g}]`;a.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${v}' which is not defined or imported`,suggestion:`Define '${v}' or import a namespace that contains it. Expected range: ${re}`,entityName:o,propertyName:`${s}[${g}]`,propertyPath:Q,actualValue:v,expectedValue:"Defined or imported entity"})}}else if(typeof R=="object"&&R!==null&&!Array.isArray(R)){let v=t?`${t}.${s}[${g}]`:`${s}[${g}]`;await this.scanEntityForObjectProperties(R,o,v,i,r,n,p,a)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!i.has(s)){let u=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,u,i,r,n,p,a)}else if(Array.isArray(c))for(let u=0;u<c.length;u++){let f=c[u];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let g=t?`${t}.${s}[${u}]`:`${s}[${u}]`;await this.scanEntityForObjectProperties(f,o,g,i,r,n,p,a)}}}}async validateRangeType(e,o,t,i){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(o))return!0;let n=e.entity.type;if(n){let p=[];if(Array.isArray(n))for(let a of n){let s=a?.toString();s&&s.trim().length>0&&p.push(s)}else{let a=n?.toString();a&&a.trim().length>0&&p.push(a)}for(let a of p){let s=a.includes(".")?a.split(".")[1]:a;if(s===o||o==="Property"&&(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")||o==="Class"&&s==="Class"||await t.isSubclassOfAsync(a,o,i))return!0}}return!1}async buildPropertyMetadataAsync(e,o,t,i){let r=new Map;for(let[n,p]of i){let a=p.entity.type;if(a){let s=[];if(Array.isArray(a))for(let y of a){let m=y?.toString();m&&m.trim().length>0&&s.push(m)}else{let y=a?.toString();y&&y.trim().length>0&&s.push(y)}let c=!1,l="Property";for(let y of s){let m=y.includes(".")?y.split(".")[1]:y;if(m==="Property"||m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty"){c=!0,l=y;break}}if(c){let y={propertyType:l},m=p.entity.range;if(m){let u=m?.toString();if(u&&u.trim().length>0){y.range=u;let f=await t.resolveEntityAsync(u,e);f&&(y.rangeUri=f.uri)}}r.set(n,y)}}}return r}};var X=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,o){let t=[],i=new Map;for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=this.getPropertyValue(a,"type");(s==="DatatypeProperty"||s?.endsWith(".DatatypeProperty")||s==="ObjectProperty"||s?.endsWith(".ObjectProperty")||s==="AnnotationProperty"||s?.endsWith(".AnnotationProperty"))&&i.set(n,a)}let r=await this.buildCompleteClassHierarchyAsync(e,o);for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=this.getPropertyValue(a,"type");if(!s||s==="Class"||s.endsWith(".Class")||s.endsWith("Property")||s==="AnnotationProperty")continue;this.validateEntityProperties(a,n,s,i,r,t)}return t}async buildCompleteClassHierarchyAsync(e,o){let t=new Map,i=new Set,r=async(p,a)=>{if(!i.has(a)){i.add(a);for(let[s,c]of Object.entries(p.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let l=c,y=this.getPropertyValue(l,"type");if(y==="Class"||y?.endsWith(".Class")){let m=l.subClassOf;if(m===void 0){for(let f of Object.keys(l))if(f.endsWith(".subClassOf")){m=l[f];break}}let u=k(m);u.length>0&&t.set(s,u)}}if(p.metadata.imports)for(let[s,c]of Object.entries(p.metadata.imports))for(let l of c)try{let y=await o.getHighestCompatibleVersionAsync(s,l);if(y){let m=`${s}/${l.packageName}@${l.version}`;await r(y,m)}}catch{}}},n=e.metadata.namespace_?.toString()??"unknown";return await r(e,n),t}validateEntityProperties(e,o,t,i,r,n){for(let[p,a]of Object.entries(e)){if(this.standardProperties.has(p))continue;let s=p,c=p.lastIndexOf(".");c>0&&c<p.length-1&&(s=p.substring(c+1));let l=i.get(s);if(!l)continue;let y=this.getPropertyValue(l,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,r)){let m=o.split(".")[0];n.push({ruleType:this.ruleName,severity:"Error",entityName:m,propertyName:o,actualValue:p,message:`Property '${p}' has domain '${y}' but is used on '${t}' at '${o}'`,suggestion:`Either:
36
+ `)}`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:`A single reference to ${u.range??"an entity"} OR a YAML list`});continue}let R=await r.resolveEntityAsync(g,a);if(R)u.range&&(await this.validateRangeType(R,u.range,r,a)||p.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${u.range}, but '${g}' may not be a ${u.range}`,suggestion:`Ensure '${g}' is defined with appropriate type`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:u.range}));else{let v=u.range??"entity";p.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${g}' which is not defined or imported`,suggestion:`Define '${g}' or import a namespace that contains it. Expected range: ${v}`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let g=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,g,i,r,n,a,p)}else if(Array.isArray(c))for(let g=0;g<c.length;g++){let R=c[g];if(typeof R=="string"&&R.trim().length>0){let v=R.trim(),A=await r.resolveEntityAsync(v,a);if(A){if(u.range&&!await this.validateRangeType(A,u.range,r,a)){let Q=t?`${t}.${s}[${g}]`:`${s}[${g}]`;p.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${u.range}, but '${v}' may not be a ${u.range}`,suggestion:`Ensure '${v}' is defined with appropriate type`,entityName:o,propertyName:`${s}[${g}]`,propertyPath:Q,actualValue:v,expectedValue:u.range})}}else{let re=u.range??"entity",Q=t?`${t}.${s}[${g}]`:`${s}[${g}]`;p.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${v}' which is not defined or imported`,suggestion:`Define '${v}' or import a namespace that contains it. Expected range: ${re}`,entityName:o,propertyName:`${s}[${g}]`,propertyPath:Q,actualValue:v,expectedValue:"Defined or imported entity"})}}else if(typeof R=="object"&&R!==null&&!Array.isArray(R)){let v=t?`${t}.${s}[${g}]`:`${s}[${g}]`;await this.scanEntityForObjectProperties(R,o,v,i,r,n,a,p)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!i.has(s)){let m=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,m,i,r,n,a,p)}else if(Array.isArray(c))for(let m=0;m<c.length;m++){let f=c[m];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let g=t?`${t}.${s}[${m}]`:`${s}[${m}]`;await this.scanEntityForObjectProperties(f,o,g,i,r,n,a,p)}}}}async validateRangeType(e,o,t,i){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(o))return!0;let n=e.entity.type;if(n){let a=[];if(Array.isArray(n))for(let p of n){let s=p?.toString();s&&s.trim().length>0&&a.push(s)}else{let p=n?.toString();p&&p.trim().length>0&&a.push(p)}for(let p of a){let s=p.includes(".")?p.split(".")[1]:p;if(s===o||o==="Property"&&(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")||o==="Class"&&s==="Class"||await t.isSubclassOfAsync(p,o,i))return!0}}return!1}async buildPropertyMetadataAsync(e,o,t,i){let r=new Map;for(let[n,a]of i){let p=a.entity.type;if(p){let s=[];if(Array.isArray(p))for(let y of p){let u=y?.toString();u&&u.trim().length>0&&s.push(u)}else{let y=p?.toString();y&&y.trim().length>0&&s.push(y)}let c=!1,l="Property";for(let y of s){let u=y.includes(".")?y.split(".")[1]:y;if(u==="Property"||u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty"){c=!0,l=y;break}}if(c){let y={propertyType:l},u=a.entity.range;if(u){let m=u?.toString();if(m&&m.trim().length>0){y.range=m;let f=await t.resolveEntityAsync(m,e);f&&(y.rangeUri=f.uri)}}r.set(n,y)}}}return r}};var X=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,o){let t=[],i=new Map;for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let p=a,s=this.getPropertyValue(p,"type");(s==="DatatypeProperty"||s?.endsWith(".DatatypeProperty")||s==="ObjectProperty"||s?.endsWith(".ObjectProperty")||s==="AnnotationProperty"||s?.endsWith(".AnnotationProperty"))&&i.set(n,p)}let r=await this.buildCompleteClassHierarchyAsync(e,o);for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let p=a,s=this.getPropertyValue(p,"type");if(!s||s==="Class"||s.endsWith(".Class")||s.endsWith("Property")||s==="AnnotationProperty")continue;this.validateEntityProperties(p,n,s,i,r,t)}return t}async buildCompleteClassHierarchyAsync(e,o){let t=new Map,i=new Set,r=async(a,p)=>{if(!i.has(p)){i.add(p);for(let[s,c]of Object.entries(a.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let l=c,y=this.getPropertyValue(l,"type");if(y==="Class"||y?.endsWith(".Class")){let u=l.subClassOf;if(u===void 0){for(let f of Object.keys(l))if(f.endsWith(".subClassOf")){u=l[f];break}}let m=k(u);m.length>0&&t.set(s,m)}}if(a.metadata.imports)for(let[s,c]of Object.entries(a.metadata.imports))for(let l of c)try{let y=await o.getHighestCompatibleVersionAsync(s,l);if(y){let u=`${s}/${l.packageName}@${l.version}`;await r(y,u)}}catch{}}},n=e.metadata.namespace_?.toString()??"unknown";return await r(e,n),t}validateEntityProperties(e,o,t,i,r,n){for(let[a,p]of Object.entries(e)){if(this.standardProperties.has(a))continue;let s=a,c=a.lastIndexOf(".");c>0&&c<a.length-1&&(s=a.substring(c+1));let l=i.get(s);if(!l)continue;let y=this.getPropertyValue(l,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,r)){let u=o.split(".")[0];n.push({ruleType:this.ruleName,severity:"Error",entityName:u,propertyName:o,actualValue:a,message:`Property '${a}' has domain '${y}' but is used on '${t}' at '${o}'`,suggestion:`Either:
42
37
  1. Use this property only on '${y}' instances
43
38
  2. Change the property domain to include '${t}'
44
- 3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let m=a,u=this.getPropertyValue(m,"type");if(u){let f=`${o}.${p}`;this.validateEntityProperties(m,f,u,i,r,n)}else{let f=this.getPropertyValue(l,"range");if(f){let g=`${o}.${p}`;this.validateEntityProperties(m,g,f,i,r,n)}}}else if(Array.isArray(a))for(let m=0;m<a.length;m++){let u=a[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,g=this.getPropertyValue(f,"type");if(g){let R=`${o}.${p}[${m}]`;this.validateEntityProperties(f,R,g,i,r,n)}else{let R=this.getPropertyValue(l,"range");if(R){let v=`${o}.${p}[${m}]`;this.validateEntityProperties(f,v,R,i,r,n)}}}}}}}isTypeCompatibleWithDomain(e,o,t){if(e===o)return!0;let i=new Set,r=[e];for(;r.length>0;){let n=r.shift();if(i.has(n))continue;i.add(n);let p=t.get(n);if(p)for(let a of p){if(a===o)return!0;r.push(a)}}return!1}getPropertyValue(e,o){if(o in e){let t=e[o];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${o}`)){let i=e[t];return this.extractFirstValue(i)}}extractFirstValue(e){if(Array.isArray(e)){let o=[];for(let t of e)o.push(t?.toString()??"");return o.length>0?o[0]:void 0}return e?.toString()}};var B=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,o){let t=[],i=new Map;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=this.getPropertyValue(p,"type");(a==="DatatypeProperty"||a==="ObjectProperty")&&i.set(r,p)}for(let[r,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n))continue;let p=n,a=this.getPropertyValue(p,"type");if(!(!a||a==="Class"||a.endsWith("Property")||a==="AnnotationProperty"))for(let[s,c]of Object.entries(p)){if(s==="type"||s==="label"||s==="comment")continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let m=i.get(l);if(!m)continue;let u=this.getPropertyValue(m,"type"),f=this.getPropertyValue(m,"range");if(u==="DatatypeProperty"){if(typeof c=="object"&&c!==null&&!Array.isArray(c)||Array.isArray(c))t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' is a DatatypeProperty with range '${f}' but instance '${r}' has a complex object value`,suggestion:`Either:
39
+ 3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let u=p,m=this.getPropertyValue(u,"type");if(m){let f=`${o}.${a}`;this.validateEntityProperties(u,f,m,i,r,n)}else{let f=this.getPropertyValue(l,"range");if(f){let g=`${o}.${a}`;this.validateEntityProperties(u,g,f,i,r,n)}}}else if(Array.isArray(p))for(let u=0;u<p.length;u++){let m=p[u];if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=m,g=this.getPropertyValue(f,"type");if(g){let R=`${o}.${a}[${u}]`;this.validateEntityProperties(f,R,g,i,r,n)}else{let R=this.getPropertyValue(l,"range");if(R){let v=`${o}.${a}[${u}]`;this.validateEntityProperties(f,v,R,i,r,n)}}}}}}}isTypeCompatibleWithDomain(e,o,t){if(e===o)return!0;let i=new Set,r=[e];for(;r.length>0;){let n=r.shift();if(i.has(n))continue;i.add(n);let a=t.get(n);if(a)for(let p of a){if(p===o)return!0;r.push(p)}}return!1}getPropertyValue(e,o){if(o in e){let t=e[o];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${o}`)){let i=e[t];return this.extractFirstValue(i)}}extractFirstValue(e){if(Array.isArray(e)){let o=[];for(let t of e)o.push(t?.toString()??"");return o.length>0?o[0]:void 0}return e?.toString()}};var B=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,o){let t=[],i=new Map;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,p=this.getPropertyValue(a,"type");(p==="DatatypeProperty"||p==="ObjectProperty")&&i.set(r,a)}for(let[r,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n))continue;let a=n,p=this.getPropertyValue(a,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[s,c]of Object.entries(a)){if(s==="type"||s==="label"||s==="comment")continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let u=i.get(l);if(!u)continue;let m=this.getPropertyValue(u,"type"),f=this.getPropertyValue(u,"range");if(m==="DatatypeProperty"){if(typeof c=="object"&&c!==null&&!Array.isArray(c)||Array.isArray(c))t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' is a DatatypeProperty with range '${f}' but instance '${r}' has a complex object value`,suggestion:`Either:
45
40
  1. Create a class for this data and change '${s}' to an ObjectProperty
46
41
  2. Store as a JSON string to keep it as DatatypeProperty
47
- 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let g={ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' expects type '${f}' but instance '${r}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(g.expectedValue=f),t.push(g)}}else if(u==="ObjectProperty")if(Array.isArray(c))for(let g=0;g<c.length;g++){let R=c[g];typeof R!="string"&&(typeof R!="object"||R===null||Array.isArray(R))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:`${s}[${g}]`,message:`ObjectProperty '${s}' array item ${g} in instance '${r}' has invalid type '${this.getValueTypeName(R)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`ObjectProperty '${s}' in instance '${r}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,o){switch(e?.toLowerCase()){case"string":return typeof o=="string";case"integer":case"int":return typeof o=="number"&&Number.isInteger(o);case"decimal":return typeof o=="number";case"boolean":return typeof o=="boolean";case"float":case"double":return typeof o=="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,o){if(o in e){let t=e[o];if(Array.isArray(t)){let i=[];for(let r of t)i.push(r?.toString()??"");return i.length>0?i[0]:void 0}return t?.toString()}}};var z=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,o){let t=[],i=new Map,r=new Set;for(let[p,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a.type;if(c)if(Array.isArray(c))for(let l of c){let y=l?.toString();if(y==="Class"||y&&y.endsWith(".Class")){r.add(p);break}}else{let l=c?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&r.add(p)}}for(let[p,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let s=a,c=s.type;if(c)if(Array.isArray(c)){let l=!1;for(let y of c){let m=y?.toString();if(m&&this.isDefinitionType(m)){l=!0;break}}if(!l)for(let y of c){let m=y?.toString();m&&m.trim().length>0&&(i.has(m)||i.set(m,[]),i.get(m).push(p))}}else{let l=c?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(i.has(l)||i.set(l,[]),i.get(l).push(p)))}this.checkNestedTypes(s,p,i,p)}let n=new V(o);for(let[p,a]of i){if(this.builtInClasses.has(p)||r.has(p))continue;let s=await n.resolveEntityAsync(p,e);if(!(s&&this.isClassEntity(s.entity))){let l=Array.from(new Set(a)).sort();for(let y of l)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${p}' is not defined or imported`,suggestion:`Define '${p}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:p,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,o,t,i){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let r=e,n=r.type;if(n){let p=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(n))for(let a of n){let s=a?.toString();s&&s.trim().length>0&&!p.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(i))}else{let a=n?.toString();a&&a.trim().length>0&&!p.has(a)&&(t.has(a)||t.set(a,[]),t.get(a).push(i))}}for(let[p,a]of Object.entries(r))if(p!=="type"){let s=`${i}.${p}`;this.checkNestedTypes(a,o,t,s)}}else if(Array.isArray(e))for(let r=0;r<e.length;r++){let n=`${i}[${r}]`;this.checkNestedTypes(e[r],o,t,n)}}isClassEntity(e){if(!e)return!1;let o=e.type;if(!o)return!1;if(Array.isArray(o))for(let t of o){let i=t?.toString();if(i==="Class"||i&&i.endsWith(".Class"))return!0}else{let t=o?.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 te=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new G,this.documentRules=[new I,new D,new O,new $,new w],this.repositoryRules=[new E,new j,new S,new N,new K,new C,new x,new T,new _,new M,new W,new L,new H,new F,new U,new q,new X,new B,new z]}async validateAsync(e,o){let t=new P;for(let i of this.documentRules)try{let r=i.validate(e);this.addErrorsToResult(t,r)}catch(r){let n=new h;n.ruleType=i.ruleName,n.severity="Error",n.message=`Validation rule '${i.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,t.errors.push(n)}if(o){let i=[];for(let r of this.repositoryRules)try{let n=await r.validateAsync(e,o);this.addErrorsToResult(t,n)}catch(n){let p=n instanceof Error?n.message:String(n);i.push({ruleName:r.ruleName,cause:p})}if(i.length>0){let r=new Map;for(let{ruleName:n,cause:p}of i){let a=r.get(p);a?a.push(n):r.set(p,[n])}for(let[n,p]of r){let a=new h;a.ruleType=p[0],a.severity="Error",p.length===1?a.message=`Validation rule '${p[0]}' failed: ${n}`:a.message=`${n} (affects ${p.length} rules: ${p.join(", ")})`,t.errors.push(a)}}}return t.isValid=t.errors.length===0,t}async validateYamlAsync(e,o){let t=this.parser.parseWithErrors(e);if(!t.isValid){let i=new P;i.isValid=!1;for(let r of t.errors){let n=new h;n.ruleType="ParseError",n.severity="Error",n.lineNumber=r.line,n.column=r.column,n.message=r.message,r.keyName&&(n.entityName=r.keyName),r.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),i.errors.push(n)}return i}return await this.validateAsync(t.document,o)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let o=this.documentRules.findIndex(t=>t instanceof e);o>=0&&this.documentRules.splice(o,1)}removeRepositoryRule(e){let o=this.repositoryRules.findIndex(t=>t instanceof e);o>=0&&this.repositoryRules.splice(o,1)}addErrorsToResult(e,o){for(let t of o)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{H as AmbiguousReferenceRule,z as ClassDefinitionRule,N as ClassHierarchyCycleRule,W as DefinitionPropertyReferenceRule,w as EmbeddedKanonakNoExplicitTypeRule,E as ImportExistenceRule,M as InstancePropertyReferenceRule,te as KanonakObjectValidator,_ as NamespaceImportCycleRule,I as NamespacePrefixRule,U as ObjectPropertyImportRule,q as ObjectPropertyValueValidationRule,h as OntologyValidationError,P as OntologyValidationResult,X as PropertyDomainRule,K as PropertyHierarchyCycleRule,F as PropertyRangeReferenceRule,C as PropertyRangeRequiredRule,O as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,D as ResourceNamingRule,x as SubClassOfReferenceRule,T as SubPropertyOfReferenceRule,$ as SubjectKanonakTypeRequiredRule,S as TypeAmbiguityRule,j as UnresolvedReferenceRule,ee as ValidationContext,b as ValidationSeverity,L as XsdImportRule};
42
+ 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let g={ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' expects type '${f}' but instance '${r}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(g.expectedValue=f),t.push(g)}}else if(m==="ObjectProperty")if(Array.isArray(c))for(let g=0;g<c.length;g++){let R=c[g];typeof R!="string"&&(typeof R!="object"||R===null||Array.isArray(R))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:`${s}[${g}]`,message:`ObjectProperty '${s}' array item ${g} in instance '${r}' has invalid type '${this.getValueTypeName(R)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`ObjectProperty '${s}' in instance '${r}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,o){switch(e?.toLowerCase()){case"string":return typeof o=="string";case"integer":case"int":return typeof o=="number"&&Number.isInteger(o);case"decimal":return typeof o=="number";case"boolean":return typeof o=="boolean";case"float":case"double":return typeof o=="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,o){if(o in e){let t=e[o];if(Array.isArray(t)){let i=[];for(let r of t)i.push(r?.toString()??"");return i.length>0?i[0]:void 0}return t?.toString()}}};var z=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,o){let t=[],i=new Map,r=new Set;for(let[a,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let c=p.type;if(c)if(Array.isArray(c))for(let l of c){let y=l?.toString();if(y==="Class"||y&&y.endsWith(".Class")){r.add(a);break}}else{let l=c?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&r.add(a)}}for(let[a,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let s=p,c=s.type;if(c)if(Array.isArray(c)){let l=!1;for(let y of c){let u=y?.toString();if(u&&this.isDefinitionType(u)){l=!0;break}}if(!l)for(let y of c){let u=y?.toString();u&&u.trim().length>0&&(i.has(u)||i.set(u,[]),i.get(u).push(a))}}else{let l=c?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(i.has(l)||i.set(l,[]),i.get(l).push(a)))}this.checkNestedTypes(s,a,i,a)}let n=new V(o);for(let[a,p]of i){if(this.builtInClasses.has(a)||r.has(a))continue;let s=await n.resolveEntityAsync(a,e);if(!(s&&this.isClassEntity(s.entity))){let l=Array.from(new Set(p)).sort();for(let y of l)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${a}' is not defined or imported`,suggestion:`Define '${a}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:a,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,o,t,i){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let r=e,n=r.type;if(n){let a=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(n))for(let p of n){let s=p?.toString();s&&s.trim().length>0&&!a.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(i))}else{let p=n?.toString();p&&p.trim().length>0&&!a.has(p)&&(t.has(p)||t.set(p,[]),t.get(p).push(i))}}for(let[a,p]of Object.entries(r))if(a!=="type"){let s=`${i}.${a}`;this.checkNestedTypes(p,o,t,s)}}else if(Array.isArray(e))for(let r=0;r<e.length;r++){let n=`${i}[${r}]`;this.checkNestedTypes(e[r],o,t,n)}}isClassEntity(e){if(!e)return!1;let o=e.type;if(!o)return!1;if(Array.isArray(o))for(let t of o){let i=t?.toString();if(i==="Class"||i&&i.endsWith(".Class"))return!0}else{let t=o?.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 te=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new G,this.documentRules=[new I,new D,new O,new $],this.repositoryRules=[new w,new E,new S,new j,new N,new K,new C,new x,new T,new _,new M,new W,new L,new H,new F,new U,new q,new X,new B,new z]}async validateAsync(e,o){let t=new P;for(let i of this.documentRules)try{let r=i.validate(e);this.addErrorsToResult(t,r)}catch(r){let n=new h;n.ruleType=i.ruleName,n.severity="Error",n.message=`Validation rule '${i.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,t.errors.push(n)}if(o){let i=[];for(let r of this.repositoryRules)try{let n=await r.validateAsync(e,o);this.addErrorsToResult(t,n)}catch(n){let a=n instanceof Error?n.message:String(n);i.push({ruleName:r.ruleName,cause:a})}if(i.length>0){let r=new Map;for(let{ruleName:n,cause:a}of i){let p=r.get(a);p?p.push(n):r.set(a,[n])}for(let[n,a]of r){let p=new h;p.ruleType=a[0],p.severity="Error",a.length===1?p.message=`Validation rule '${a[0]}' failed: ${n}`:p.message=`${n} (affects ${a.length} rules: ${a.join(", ")})`,t.errors.push(p)}}}return t.isValid=t.errors.length===0,t}async validateYamlAsync(e,o){let t=this.parser.parseWithErrors(e);if(!t.isValid){let i=new P;i.isValid=!1;for(let r of t.errors){let n=new h;n.ruleType="ParseError",n.severity="Error",n.lineNumber=r.line,n.column=r.column,n.message=r.message,r.keyName&&(n.entityName=r.keyName),r.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),i.errors.push(n)}return i}return await this.validateAsync(t.document,o)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let o=this.documentRules.findIndex(t=>t instanceof e);o>=0&&this.documentRules.splice(o,1)}removeRepositoryRule(e){let o=this.repositoryRules.findIndex(t=>t instanceof e);o>=0&&this.repositoryRules.splice(o,1)}addErrorsToResult(e,o){for(let t of o)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{H as AmbiguousReferenceRule,z as ClassDefinitionRule,N as ClassHierarchyCycleRule,W as DefinitionPropertyReferenceRule,w as EmbeddedKanonakTypeRule,E as ImportExistenceRule,M as InstancePropertyReferenceRule,te as KanonakObjectValidator,_ as NamespaceImportCycleRule,I as NamespacePrefixRule,U as ObjectPropertyImportRule,q as ObjectPropertyValueValidationRule,h as OntologyValidationError,P as OntologyValidationResult,X as PropertyDomainRule,K as PropertyHierarchyCycleRule,F as PropertyRangeReferenceRule,C as PropertyRangeRequiredRule,O as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,D as ResourceNamingRule,x as SubClassOfReferenceRule,T as SubPropertyOfReferenceRule,$ as SubjectKanonakTypeRequiredRule,j as TypeAmbiguityRule,S as UnresolvedReferenceRule,ee as ValidationContext,b as ValidationSeverity,L as XsdImportRule};
@@ -3,4 +3,3 @@ export { NamespacePrefixRule } from './NamespacePrefixRule.js';
3
3
  export { ResourceNamingRule } from './ResourceNamingRule.js';
4
4
  export { PropertyTypeSpecificityRule } from './PropertyTypeSpecificityRule.js';
5
5
  export { SubjectKanonakTypeRequiredRule } from './SubjectKanonakTypeRequiredRule.js';
6
- export { EmbeddedKanonakNoExplicitTypeRule } from './EmbeddedKanonakNoExplicitTypeRule.js';
@@ -0,0 +1,75 @@
1
+ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
2
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
3
+ import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
4
+ import { OntologyValidationError } from '../../OntologyValidationError.js';
5
+ /**
6
+ * Validates `type:` declarations on embedded kanonaks.
7
+ *
8
+ * An embedded object MAY declare a `type:` property. If declared, the
9
+ * declared type must be a subclass of (or equal to) the range of the
10
+ * parent property under which the object is embedded. This relaxes
11
+ * the previous "no explicit type on embeddeds" rule so authors can
12
+ * model tagged-union / discriminated-union hierarchies with proper
13
+ * OWL `subClassOf` semantics instead of working around the validator
14
+ * with a separate discriminator class and named-instance enumeration.
15
+ *
16
+ * - Equal-to-range declarations are accepted but emit a Warning
17
+ * ("redundant"). Authors who want explicit redundancy can opt in
18
+ * by ignoring the warning.
19
+ * - Strict-subclass declarations are accepted (no diagnostic).
20
+ * - Non-subclass declarations error with a suggestion to either
21
+ * drop the type or add a matching `subClassOf:` to the declared
22
+ * class.
23
+ * - When the parent property has no `range:`, or the range is a
24
+ * "universal" class (`Resource`, `Class`), no constraint is
25
+ * enforced — every declared embedded type is accepted.
26
+ *
27
+ * Why this is a repository rule rather than a document rule: deciding
28
+ * whether `cp.OrCondition` is a subclass of `Condition` requires
29
+ * walking `subClassOf` across the importing document's transitive
30
+ * imports, which the document-only validator interface can't reach.
31
+ * The class hierarchy walk is delegated to
32
+ * `ResourceResolver.isSubclassOfAsync`, the same helper other
33
+ * range-aware rules already share.
34
+ */
35
+ export declare class EmbeddedKanonakTypeRule implements IRepositoryValidationRule {
36
+ get ruleName(): string;
37
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
38
+ /**
39
+ * Recursively descend through a YAML dict, validating any `type:`
40
+ * declarations encountered at depth > 0 against the closest known
41
+ * parent-property range.
42
+ *
43
+ * `parentPropertyRange` flows down from the property under which
44
+ * this dict sits. Two cases preserve it correctly:
45
+ *
46
+ * 1. **Single embedded under a property** — keys here are the
47
+ * embedded's properties; we look up each key's own range and
48
+ * pass it down for the next level.
49
+ * 2. **Dict-keyed list of embeddeds** (e.g.
50
+ * `hasArgument: { foo: {...}, bar: {...} }`) — keys are labels
51
+ * rather than properties, so they resolve to no range. In that
52
+ * case we propagate the OUTER property's range through the
53
+ * label level so the embedded values still get checked.
54
+ *
55
+ * List items are handled identically: a list under property P
56
+ * means each item is an embedded under P, regardless of whether
57
+ * the list is positional (`- item`) or dict-keyed.
58
+ */
59
+ private checkEmbeddedTypes;
60
+ private validateEmbeddedType;
61
+ private localName;
62
+ /**
63
+ * Build a map from property local name → declared range string.
64
+ * Includes properties declared in the current document AND every
65
+ * imported (transitively visible) entity, courtesy of
66
+ * `ResourceResolver.buildEntityIndexAsync`.
67
+ *
68
+ * Local-name keys mirror the lookup the recursion does on each
69
+ * dict key, so aliased forms (`cp.foo`) resolve cleanly when their
70
+ * local name (`foo`) is also unambiguous in the workspace. This
71
+ * matches the convention used by other range-aware rules
72
+ * (`PropertyValueTypeRule`, `ObjectPropertyValueValidationRule`).
73
+ */
74
+ private buildPropertyRangeMap;
75
+ }
@@ -18,3 +18,4 @@ export { ObjectPropertyValueValidationRule } from './ObjectPropertyValueValidati
18
18
  export { PropertyDomainRule } from './PropertyDomainRule.js';
19
19
  export { PropertyValueTypeRule } from './PropertyValueTypeRule.js';
20
20
  export { ClassDefinitionRule } from './ClassDefinitionRule.js';
21
+ export { EmbeddedKanonakTypeRule } from './EmbeddedKanonakTypeRule.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -105,7 +105,7 @@
105
105
  "yaml-parser"
106
106
  ],
107
107
  "dependencies": {
108
- "@kanonak-protocol/types": "^2.4.0",
108
+ "@kanonak-protocol/types": "^2.5.0",
109
109
  "ignore": "^7.0.5",
110
110
  "js-yaml": "^4.1.0",
111
111
  "yaml": "^2.7.0"
@@ -1,8 +0,0 @@
1
- import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
2
- import type { IDocumentValidationRule } from './IDocumentValidationRule.js';
3
- import { OntologyValidationError } from '../../OntologyValidationError.js';
4
- export declare class EmbeddedKanonakNoExplicitTypeRule implements IDocumentValidationRule {
5
- get ruleName(): string;
6
- validate(document: KanonakDocument): OntologyValidationError[];
7
- private checkForEmbeddedTypeViolations;
8
- }