@kanonak-protocol/sdk 3.9.0 → 3.11.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.
@@ -1,42 +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 G from"js-yaml";var Z=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 n=G.load(e);if(!n||typeof n!="object")return t={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:t,errors:o,isValid:!0};let r=this.extractMetadata(n),i=this.extractBody(n,r);return t={metadata:r,body:i,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(n){let r=n,i={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(i),{document:void 0,errors:o,isValid:!1}}}save(e){let o={};if(e.metadata.namespace_){let t=e.metadata.namespace_,n={type:"Package",publisher:t.publisher};t.version&&(n.version=`${t.version.major}.${t.version.minor}.${t.version.patch}`),e.metadata.imports&&(n.imports=this.serializeImports(e.metadata.imports)),o[t.package_]=n}return Object.assign(o,e.body),G.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 n of Object.values(o))t.push(...n);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,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){o.type_="Package";let r=t,i=n.publisher,a=n.version?this.parseVersion(n.version):void 0;return i&&r&&(o.namespace_={publisher:i,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===i&&p.package_===r&&(!a||!p.version||a.equals(p.version)),getHashCode:()=>{let p=0;for(let s=0;s<i.length;s++)p=(p<<5)-p+i.charCodeAt(s);for(let s=0;s<r.length;s++)p=(p<<5)-p+r.charCodeAt(s);return p|0}}),n.imports&&Array.isArray(n.imports)&&(o.imports=this.parseImportsV3(n.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={},n;for(let[r,i]of Object.entries(e))if(i&&typeof i=="object"&&i.type==="Package"){n=r;break}for(let[r,i]of Object.entries(e))r!==n&&r!=="kanonak"&&r!=="namespace"&&r!=="imports"&&(t[r]=i);return t}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let i=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:i,toString:()=>e,equals:a=>!a||typeof a!="object"?!1:a.publisher===r[1]&&a.package_===r[2]&&(!i||!a.version||i.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||"",n=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:o,package_:t,version:n,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&&(!n||!r.version||n.equals(r.version)),getHashCode:()=>{let r=0;for(let i=0;i<o.length;i++)r=(r<<5)-r+o.charCodeAt(i);for(let i=0;i<t.length;i++)r=(r<<5)-r+t.charCodeAt(i);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 n=t.publisher;if(!n)throw new Error("PublisherImport requires 'publisher' property");o[n]||(o[n]=[]);for(let r of t.packages){if(!r||typeof r!="object")continue;let i=this.parseImportFromEmbeddedObject(r,n);o[n].push(i)}}else{let n=this.parseImportFromEmbeddedObject(t,t.publisher),r=n.publisher||"";o[r]||(o[r]=[]),o[r].push(n)}return o}parseImportsLegacy(e){let o={};for(let[t,n]of Object.entries(e))Array.isArray(n)&&(o[t]=n.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 n=e.match;if(!n)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let i=this.parseVersion(r),a=this.parseVersionOperator(n),p=this.calculateMaxVersion(n,i),s=e.alias;return{package_:`${t} ${n} ${i.toString()}`,publisher:o,packageName:t,versionOperator:a,version:i,alias:s,minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let c={package:t,match:n,version:i.toString()};return s&&(c.alias=s),c},toString:()=>s?`${t} ${n} ${i.toString()} as ${s}`:`${t} ${n} ${i.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||"~"),n=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",i=["=","~","^","*"][t],a=this.calculateMaxVersion(e.operator||"~",n);return{package_:e.package||"",publisher:o,packageName:r,versionOperator:t,version:n,alias:e.alias,minVersion:n,maxVersion:a,toEmbeddedObject:()=>{let p={package:r,match:i,version:n.toString()};return e.alias&&(p.alias=e.alias),p},toString:()=>`${r} ${i} ${n.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,n]of Object.entries(e)){let r={publisher:t,packages:n.map(i=>{let a=["=","~","^","*"][i.versionOperator],p={package:i.packageName,match:a,version:`${i.version.major}.${i.version.minor}.${i.version.patch}`};return i.alias&&(p.alias=i.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,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(t,n,o);return o}validateEntity(e,o,t){for(let[n,r]of Object.entries(o)){let i=r?.toString()??"";if(i&&d.NAMESPACE_PREFIX_PATTERN.test(i)){let a=this.getSuggestionForPrefixedValue(i),p=e.split(".")[0],s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=p,s.propertyName=e,s.actualValue=n,s.expectedValue=a,s.message=`Invalid namespace prefix '${i}'. 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}.${n}`,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_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let i=d.VALID_AUGMENTATION_PATTERN.test(n);if(!i&&!t&&d.RESERVED_WORDS.has(n.toLowerCase())){let a=new h;a.ruleType=this.ruleName,a.severity="Error",a.entityName=n,a.message=`Entity name '${n}' is a reserved word and cannot be used.`,a.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(a);continue}if(!i&&!d.VALID_NAME_PATTERN.test(n)){let a;/^\d/.test(n)?a="Entity names must start with a letter, not a number.":n.includes(" ")?a="Entity names cannot contain spaces. Use camelCase or underscores instead.":a="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=n,p.message=`Invalid entity name '${n}'. ${a}`,p.suggestion=a,o.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,o)}return o}validatePropertyNames(e,o,t){for(let n of Object.keys(o))if(!d.VALID_PROPERTIES.has(n)&&!d.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new h;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",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[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let i=r,a=i.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(i,"range"),l=this.determinePropertyType(c),y=new h;y.ruleType=this.ruleName,y.severity="Error",y.entityName=n,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 n=o.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var $=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||t.includes("."))continue;let r=n,i="type"in r,a=r.type?.toString().trim();if(!i||!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:
1
+ var P=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(o=>(o.Warning="Warning",o.Error="Error",o))(R||{});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 g{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new g;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};import*as G from"js-yaml";var Z=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=G.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),G.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:c=>!c||typeof c!="object"?!1:c.publisher===n&&c.package_===r&&(!a||!c.version||a.equals(c.version)),getHashCode:()=>{let c=0;for(let s=0;s<n.length;s++)c=(c<<5)-c+n.charCodeAt(s);for(let s=0;s<r.length;s++)c=(c<<5)-c+r.charCodeAt(s);return c|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 c=0;c<r[1].length;c++)a=(a<<5)-a+r[1].charCodeAt(c);for(let c=0;c<r[2].length;c++)a=(a<<5)-a+r[2].charCodeAt(c);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),c=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:c,toEmbeddedObject:()=>{let p={package:t,match:i,version:n.toString()};return s&&(p.alias=s),p},toString:()=>s?`${t} ${i} ${n.toString()} as ${s}`:`${t} ${i} ${n.toString()}`}}parseImport(e,o){if(typeof e=="string"){let c=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(c){let p=c[1].trim(),l=c[2],y=this.parseVersion(c[3].trim()),u=c[4].trim(),m=this.parseVersionOperator(l),f=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:p,versionOperator:m,version:y,alias:u,minVersion:y,maxVersion:f,toEmbeddedObject:()=>{let d={package:p,match:l,version:y.toString()};return u&&(d.alias=u),d},toString:()=>`${p} ${l} ${y.toString()} as ${u}`}}let s=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(s){let p=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:p,versionOperator:u,version:y,alias:void 0,minVersion:y,maxVersion:m,toEmbeddedObject:()=>({package:p,match:l,version:y.toString()}),toString:()=>`${p} ${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 c={package:r,match:n,version:i.toString()};return e.alias&&(c.alias=e.alias),c},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],c={package:n.packageName,match:a,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(c.alias=n.alias),c})};o.push(r)}return o}};var I=class g{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&&g.NAMESPACE_PREFIX_PATTERN.test(n)){let a=this.getSuggestionForPrefixedValue(n),c=e.split(".")[0],s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,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 g{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[i,r]of Object.entries(e.body)){let n=g.VALID_AUGMENTATION_PATTERN.test(i);if(!n&&!t&&g.RESERVED_WORDS.has(i.toLowerCase())){let a=new h;a.ruleType=this.ruleName,a.severity="Error",a.entityName=i,a.message=`Entity name '${i}' is a reserved word and cannot be used.`,a.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(a);continue}if(!n&&!g.VALID_NAME_PATTERN.test(i)){let a;/^\d/.test(i)?a="Entity names must start with a letter, not a number.":i.includes(" ")?a="Entity names cannot contain spaces. Use camelCase or underscores instead.":a="Entity names must start with a letter and contain only letters, numbers, and underscores.";let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=i,c.message=`Invalid entity name '${i}'. ${a}`,c.suggestion=a,o.push(c)}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(!g.VALID_PROPERTIES.has(i)&&!g.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 g{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 c=[];if(Array.isArray(a))for(let s of a){let p=s?.toString();p&&p==="Property"&&!t&&c.push(p)}else{let s=a?.toString();s&&s==="Property"&&!t&&c.push(s)}for(let s of c){let p=this.getPropertyValue(n,"range"),l=this.determinePropertyType(p),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":g.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)||t.includes("."))continue;let r=i,n="type"in r,a=r.type?.toString().trim();if(!n||!a){let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=t,c.propertyName="type",c.message=`Subject Kanonak '${t}' must have a 'type' property.`,c.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.`,p.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(p)}}return o}};var Y=class d{constructor(e,o,t,n){this.publisher=e;this.package_=o;this.name=t;this.version=n}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,n,r]=o;if(!t||!n||!r)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let i=n.indexOf("@");if(i===-1)return new d(t,n,r,void 0);let a=n.substring(0,i),p=n.substring(i+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 A=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",n=this.cache.get(t);if(n){let i=n.get(e);if(i)return i}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 n=e.split("."),r=n[0],i=n[1],a=await this.findDocumentForAlias(o,r);return a?await this.resolveAllEntitiesAsync(i,a):[]}return t.filter(n=>n.entityName===e)}async buildAllEntitiesIndexAsync(e,o,t){let n=[],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)`),n;o.add(r);let i=t.length===0?r:`${t} \u2192 ${r}`;for(let[a,p]of Object.entries(e.body))if(!a.includes(".")&&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};n.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:i})}if(this.logger?.debug?.(`Collected ${n.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,i);n.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 n}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,o,t){let n=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)`),n;o.add(r);let i=t.length===0?r:`${t} \u2192 ${r}`,a=0;for(let[p,s]of Object.entries(e.body))if(!p.includes(".")&&s&&typeof s=="object"&&!Array.isArray(s)&&!n.has(p)){let c=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.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:i}),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,i),m=0;for(let[f,g]of u.entries())if(n.has(f)||(n.set(f,g),m++),l.alias&&!f.includes(".")){let R=`${l.alias}.${f}`;n.has(R)||(n.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 n}async findDocumentForAlias(e,o){if(!e.metadata?.imports)return null;for(let[t,n]of Object.entries(e.metadata.imports))for(let r of n){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 n=new Set;return await this.isSubclassOfRecursiveAsync(e,o,t,n)}async isSubclassOfRecursiveAsync(e,o,t,n){if(n.has(e))return!1;n.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let i=r.entity.subClassOf;if(i){let a=k(i);for(let p of a)if(p===o||await this.isSubclassOfRecursiveAsync(p,o,t,n))return!0}return!1}async isSubpropertyOfAsync(e,o,t){if(e===o)return!0;let n=new Set;return await this.isSubpropertyOfRecursiveAsync(e,o,t,n)}async isSubpropertyOfRecursiveAsync(e,o,t,n){if(n.has(e))return!1;n.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let i=r.entity.subPropertyOf;if(i){let a=k(i);for(let p of a)if(p===o||await this.isSubpropertyOfRecursiveAsync(p,o,t,n))return!0}return!1}};var w=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,o){let t=[],n=new A(o),r=await this.buildPropertyRangeMap(e,n);for(let[i,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&await this.checkEmbeddedTypes(i,a,void 0,r,n,e,t,0);return t}async checkEmbeddedTypes(e,o,t,n,r,i,a,p){if(p>0){let s=o.type;if(s!=null){let c=await this.validateEmbeddedType(e,String(s),t,r,i);c&&a.push(c)}}for(let[s,c]of Object.entries(o)){let l=this.localName(s),y=n.has(l)?n.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,n,r,i,a,p+1)}else await this.checkEmbeddedTypes(`${e}.${s}`,c,y,n,r,i,a,p+1)}}async validateEmbeddedType(e,o,t,n,r){if(o.length===0||!t)return null;let i=this.localName(o),a=this.localName(t);if(a==="Resource"||a==="Class")return null;let p=e.split(".")[0];if(i===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 n.isSubclassOfAsync(o,t,r)||(i!==o||a!==t)&&await n.isSubclassOfAsync(i,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,n=await o.buildEntityIndexAsync(e);for(let[r,i]of n){let a=i.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=i.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 n=await o.getAllDocumentsAsync();for(let[r,i]of Object.entries(e.metadata.imports))for(let a of i)if(!await o.getHighestCompatibleVersionAsync(r,a)){let s=await this.determineImportErrorAsync(o,r,a,n),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,n){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=n.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(i=>i.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(i.toLowerCase()));if(t.length>0)return t.sort((i,a)=>i.length-a.length);let n=o.map(i=>({package:i,distance:this.levenshteinDistance(e.toLowerCase(),i.toLowerCase())})).sort((i,a)=>i.distance-a.distance),r=Math.max(3,Math.floor(e.length*.4));return n.filter(i=>i.distance<=r).map(i=>i.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,n=o.length,r=Array(t+1).fill(null).map(()=>Array(n+1).fill(0));for(let i=0;i<=t;i++)r[i][0]=i;for(let i=0;i<=n;i++)r[0][i]=i;for(let i=1;i<=t;i++)for(let a=1;a<=n;a++){let p=e[i-1]===o[a-1]?0:1;r[i][a]=Math.min(Math.min(r[i-1][a]+1,r[i][a-1]+1),r[i-1][a-1]+p)}return r[t][n]}};var S=class{ruleName="UnresolvedReference";async validateAsync(e,o){let t=[],n=new A(o),r=await n.buildEntityIndexAsync(e),i=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"))&&i.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"||!(i.has(l)||Array.from(i).some(m=>m.endsWith(`.${l}`)))||await this.validateReferenceValue(a,l,y,e,n,t)}return t}async validateReferenceValue(e,o,t,n,r,i){if(t!=null){if(typeof t=="string")await r.resolveEntityAsync(t,n)||i.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,n)||i.push(this.createUnresolvedReferenceError(e,`${o}[${a}]`,p)))}}}createUnresolvedReferenceError(e,o,t){let n=`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.`,c.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(c)}}return o}};var Y=class g{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 g(t,i,r,void 0);let a=i.substring(0,n),c=i.substring(n+1);if(!a||!c)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let s=c.split(".").map(Number),p=oe(s[0]||0,s[1]||0,s[2]||0);return new g(t,a,r,p)}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(g,e,o){return{major:g,minor:e,patch:o,toString:()=>`${g}.${e}.${o}`,equals:t=>!t||typeof t!="object"?!1:t.major===g&&t.minor===e&&t.patch===o,getHashCode:()=>g<<20|e<<10|o,compareTo:t=>g!==t.major?g-t.major:e!==t.minor?e-t.minor:o-t.patch}}function k(g){if(Array.isArray(g))return g.map(o=>o?.toString()??"").filter(o=>o.length>0);let e=g?.toString();return e?[e]:[]}var A=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,c]of Object.entries(e.body))if(!a.includes(".")&&c&&typeof c=="object"&&!Array.isArray(c)){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:c,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((c,s)=>c+s.length,0);this.logger?.debug?.(`Processing ${a} import(s) for ${r}`);for(let[c,s]of Object.entries(e.metadata.imports))for(let p of s)try{this.logger?.debug?.(`Resolving import: ${c}/${p.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(c,p);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: ${c}/${p.packageName}`)}catch(l){let y=l;throw this.logger?.error?.(`Failed to process import ${c}/${p.packageName} for namespace ${r}. Error: ${y.message}`,y),new Error(`Failed to process import ${c}/${p.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[c,s]of Object.entries(e.body))if(!c.includes(".")&&s&&typeof s=="object"&&!Array.isArray(s)&&!i.has(c)){let p=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.set(c,{entityName:c,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,c,p),entity:s,definedInNamespace:r,isImported:t.length>0,importPath:n}),a++}if(this.logger?.debug?.(`Indexed ${a} entities from ${r}`),e.metadata?.imports){let c=Object.values(e.metadata.imports).reduce((s,p)=>s+p.length,0);this.logger?.debug?.(`Processing ${c} import(s) for ${r}`);for(let[s,p]of Object.entries(e.metadata.imports))for(let l of p)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,d]of u.entries())if(i.has(f)||(i.set(f,d),m++),l.alias&&!f.includes(".")){let b=`${l.alias}.${f}`;i.has(b)||(i.set(b,d),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 c of a)if(c===o||await this.isSubclassOfRecursiveAsync(c,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 c of a)if(c===o||await this.isSubpropertyOfRecursiveAsync(c,o,t,i))return!0}return!1}};var w=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,o){let t=[],i=new A(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}pickRange(e,o,t){if(e.length===0)return;if(e.length===1)return e[0].range;let i=o.indexOf(".");if(i>0){let r=o.substring(0,i),n=e.find(a=>a.declaringAlias===r);if(n)return n.range}if(t){let r=this.localName(t),n=e.find(a=>this.localName(a.domain)===r);if(n)return n.range}return e[0].range}async checkEmbeddedTypes(e,o,t,i,r,n,a,c){if(c>0){let p=o.type;if(p!=null){let l=await this.validateEmbeddedType(e,String(p),t,r,n);l&&a.push(l)}}let s=o.type!==void 0&&o.type!==null?String(o.type):void 0;for(let[p,l]of Object.entries(o)){let y=this.localName(p),u=i.get(y),f=(u!==void 0?this.pickRange(u,p,s):void 0)??t;if(typeof l=="object"&&l!==null)if(Array.isArray(l))for(let d=0;d<l.length;d++){let b=l[d];typeof b=="object"&&b!==null&&!Array.isArray(b)&&await this.checkEmbeddedTypes(`${e}.${p}[${d}]`,b,f,i,r,n,a,c+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,l,f,i,r,n,a,c+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 c=e.split(".")[0];if(n===a){let p=new h;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=c,p.propertyName=e,p.actualValue=o,p.expectedValue=t,p.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.`,p.suggestion=`Remove the 'type: ${o}' line, or keep it if explicitness is preferred over concision.`,p}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=c,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),r=new Map;for(let[n,a]of i){let c=a.entity.type;if(c==null)continue;let s=String(c),p=this.localName(s);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let y=a.entity.range;if(y==null)continue;let u=String(y);if(u.length===0)continue;let m=a.entity.domain,f=m!=null?String(m):"",d=a.uri.toString(),b=r.get(d),v=n.includes(".");(!b||v&&!b.entityName.includes("."))&&r.set(d,{entityName:n,domain:f,range:u})}for(let n of r.values()){let a=this.localName(n.entityName),c=n.entityName.indexOf("."),s=c>0?n.entityName.substring(0,c):void 0,p=t.get(a)??[];p.push({domain:n.domain,range:n.range,declaringAlias:s}),t.set(a,p)}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),p=new h;p.ruleType=this.ruleName,p.severity="Error",p.message=s.message,p.suggestion=s.suggestion,p.entityName=`Import: ${r}/${a.packageName}`,p.actualValue=a.toString(),p.expectedValue=s.expectedValue,t.push(p)}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),p=this.findSimilarPackages(t.packageName,s),l=`Import '${o}/${t.package_}' not found - package does not exist`,y=p.length>0?`Did you mean: ${p.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(", "),c=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${a}. Required: ${c}`,expectedValue:c}}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 c=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]+c)}return r[t][i]}};var S=class{ruleName="UnresolvedReference";async validateAsync(e,o){let t=[],i=new A(o),r=await i.buildEntityIndexAsync(e),n=new Set;for(let[a,c]of r.entries()){let s=c.entity.type;if(s){let p=s.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&n.add(a)}}for(let[a,c]of Object.entries(e.body)){if(!c||typeof c!="object"||Array.isArray(c))continue;let s=c,p=this.getPropertyValue(s,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="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 c=t[a];typeof c=="string"&&(await r.resolveEntityAsync(c,i)||n.push(this.createUnresolvedReferenceError(e,`${o}[${a}]`,c)))}}}createUnresolvedReferenceError(e,o,t){let i=`The entity '${t}' cannot be found in the current document or any imported namespaces.
5
5
 
6
6
  Possible solutions:
7
7
  \u2022 Add import if the entity is defined in another namespace:
8
8
  kanonak namespace add-import <publisher>/<package>@<version>
9
9
  \u2022 Check for typos in the reference name '${t}'
10
10
  \u2022 Define '${t}' in the current namespace or an appropriate namespace
11
- \u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,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=n,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=[],n=new Map,r=[];if(e.metadata?.imports)for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,p);if(s){r.push({doc:s,import:p,publisher:i});let c=await this.getTransitiveImportsAsync(o,s,new Set);r.push(...c.map(l=>({doc:l,import:null,publisher:i})))}}for(let{doc:i,import:a}of r){let p=i.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(i.body))n.has(s)||n.set(s,[]),n.get(s).push({namespace:p,import:a})}for(let[i,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let p=a;this.checkAmbiguousReference(p,"type",n,i,t),this.checkAmbiguousReference(p,"subClassOf",n,i,t),this.checkAmbiguousReference(p,"subPropertyOf",n,i,t),this.checkAmbiguousReference(p,"domain",n,i,t),this.checkAmbiguousReference(p,"range",n,i,t)}return t}checkAmbiguousReference(e,o,t,n,r){let i=e[o];if(!i)return;let a=k(i);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=n,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 n=[],r=o.metadata?.namespace_?.toString()??"";if(t.has(r))return n;if(t.add(r),o.metadata?.imports)for(let[i,a]of Object.entries(o.metadata.imports))for(let p of a){let s=await e.getHighestCompatibleVersionAsync(i,p);if(s){n.push(s);let c=await this.getTransitiveImportsAsync(e,s,t);n.push(...c)}}return n}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o){let t=[],n=new Map,r=new Set;await this.buildClassHierarchy(e,o,n,r);for(let[i,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=i,y=this.detectCycle(l,n);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,n){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&n.has(r))){r&&n.add(r);for(let[i,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(i,l)}}if(e.metadata?.imports)for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,p);s&&await this.buildClassHierarchy(s,o,t,n)}}}detectCycle(e,o){let t=[],n=new Set;return this.detectCycleRecursive(e,o,t,n)}detectCycleRecursive(e,o,t,n){if(t.includes(e)){let i=t.indexOf(e),a=t.slice(i);return a.push(e),a}if(n.has(e))return null;t.push(e),n.add(e);let r=o.get(e);if(r)for(let i of r){let a=this.detectCycleRecursive(i,o,t,n);if(a)return a}return t.pop(),null}};var K=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o){let t=[],n=new Map,r=new Set;await this.buildPropertyHierarchy(e,o,n,r);for(let[i,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)&&a.subPropertyOf){let c=i,l=this.detectCycle(c,n);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,n){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&n.has(r))){r&&n.add(r);for(let[i,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(i,y)}}}}if(e.metadata?.imports)for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,p);s&&await this.buildPropertyHierarchy(s,o,t,n)}}}detectCycle(e,o){let t=[],n=new Set;return this.detectCycleRecursive(e,o,t,n)}detectCycleRecursive(e,o,t,n){if(t.includes(e)){let i=t.indexOf(e),a=t.slice(i);return a.push(e),a}if(n.has(e))return null;t.push(e),n.add(e);let r=o.get(e);if(r)for(let i of r){let a=this.detectCycleRecursive(i,o,t,n);if(a)return a}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,o){let t=[];for(let[n,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let i=r,a=i.type?.toString();if(a==="DatatypeProperty"||a==="ObjectProperty"||a?.endsWith(".DatatypeProperty")||a?.endsWith(".ObjectProperty")){let p="range"in i,s=i.range?.toString().trim();if(!p||!s){let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=n,c.propertyName="range",c.message=`Property '${n}' 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=[],n=new Set;for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=i.type?.toString();(p==="Class"||p&&p.endsWith(".Class"))&&n.add(r)}for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=k(i.subClassOf);for(let s=0;s<p.length;s++){let c=p[s];if(this.builtInClasses.has(c)||n.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 n=null,r=t;if(t.includes(".")){let i=t.split(".",2);n=i[0],r=i[1]}for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){if(n!==null&&p.alias!==n)continue;let s=await o.getHighestCompatibleVersionAsync(i,p);if(s){let c=n!==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,n){let r=e.metadata.namespace_?.toString()??"";if(r&&n.has(r)||(r&&n.add(r),!e.metadata.imports))return!1;for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,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,n))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=[],n=new Set;for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=i.type?.toString();(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty")&&n.add(r)}for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=k(i.subPropertyOf);for(let s=0;s<p.length;s++){let c=p[s];if(this.builtInProperties.has(c)||n.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 n=null,r=t;if(t.includes(".")){let i=t.split(".",2);n=i[0],r=i[1]}for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){if(n!==null&&p.alias!==n)continue;let s=await o.getHighestCompatibleVersionAsync(i,p);if(s){let c=n!==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,n){let r=e.metadata.namespace_?.toString()??"";if(r&&n.has(r)||(r&&n.add(r),!e.metadata.imports))return!1;for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,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,n))return!0}}return!1}};var _=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],n=e.metadata.namespace_?.toString();if(!n)return t;let r=new Map,i=new Set;await this.buildImportGraph(e,o,r,i);let a=this.detectCycle(n,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,n){let r=e.metadata.namespace_?.toString()??"";if(!(!r||n.has(r))&&(n.add(r),e.metadata.imports)){let i=[];for(let[a,p]of Object.entries(e.metadata.imports))for(let s of p){let c=`${a}/${s.packageName}@${s.version}`;i.push(c);let l=await o.getHighestCompatibleVersionAsync(a,s);l&&await this.buildImportGraph(l,o,t,n)}i.length>0&&t.set(r,i)}}detectCycle(e,o){let t=[],n=new Set;return this.detectCycleRecursive(e,o,t,n)}detectCycleRecursive(e,o,t,n){let r=t.indexOf(e);if(r>=0){let a=t.slice(r);return a.push(e),a}if(n.has(e))return null;t.push(e),n.add(e);let i=o.get(e);if(i)for(let a of i){let p=this.detectCycleRecursive(a,o,t,n);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=[],n=new Set;for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=i.type?.toString();this.isPropertyType(p)&&n.add(r)}for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let a=i,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(n.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}'.
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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){r.push({doc:s,import:c,publisher:n});let p=await this.getTransitiveImportsAsync(o,s,new Set);r.push(...p.map(l=>({doc:l,import:null,publisher:n})))}}for(let{doc:n,import:a}of r){let c=n.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(n.body))i.has(s)||i.set(s,[]),i.get(s).push({namespace:c,import:a})}for(let[n,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let c=a;this.checkAmbiguousReference(c,"type",i,n,t),this.checkAmbiguousReference(c,"subClassOf",i,n,t),this.checkAmbiguousReference(c,"subPropertyOf",i,n,t),this.checkAmbiguousReference(c,"domain",i,n,t),this.checkAmbiguousReference(c,"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 c of a){if(c.includes("."))continue;let s=t.get(c);if(s&&s.length>1){let p=s.map(m=>m.namespace).join(", "),l=[];for(let{namespace:m,import:f}of s)if(f?.alias)l.push(`${f.alias}.${c}`);else{let d=m.split("/"),v=d[d.length-1]?.split("@")[0]??"alias";l.push(`${v}.${c}`)}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=c,u.message=`Type '${c}' is ambiguous. It's defined in: ${p}`,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 c of a){let s=await e.getHighestCompatibleVersionAsync(n,c);if(s){i.push(s);let p=await this.getTransitiveImportsAsync(e,s,t);i.push(...p)}}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 c=a,s=c.type,p=c.subClassOf;if(s?.toString()==="Class"&&p){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 c=a,s=c.type,p=c.subClassOf;if(s?.toString()==="Class"&&p){let l=k(p);l.length>0&&t.set(n,l)}}if(e.metadata?.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);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 p=n,l=this.detectCycle(p,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=p,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 c=a,s=c.type;if(s){let p=s.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let l=c.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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);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 x=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 c="range"in n,s=n.range?.toString().trim();if(!c||!s){let p=new h;p.ruleType=this.ruleName,p.severity="Error",p.entityName=i,p.propertyName="range",p.message=`Property '${i}' must have a 'range' defined.`,p.suggestion=a==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=a==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(p)}}}return t}};var C=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 c=n.type?.toString();(c==="Class"||c&&c.endsWith(".Class"))&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=k(n.subClassOf);for(let s=0;s<c.length;s++){let p=c[s];if(this.builtInClasses.has(p)||i.has(p))continue;if(!await this.isClassAvailableInImports(e,o,p)){let y=c.length>1?`[${s}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Class '${p}' referenced in subClassOf${y} is not defined or imported`,u.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,u.entityName=r,u.propertyName="subClassOf",u.actualValue=p,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 c of a){if(i!==null&&c.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=i!==null?r:t,l=s.body[p];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,p,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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.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 c=n.type?.toString();(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty")&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let c=k(n.subPropertyOf);for(let s=0;s<c.length;s++){let p=c[s];if(this.builtInProperties.has(p)||i.has(p))continue;if(!await this.isPropertyAvailableInImports(e,o,p)){let y=c.length>1?`[${s}]`:"",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${p}' referenced in subPropertyOf${y} is not defined or imported`,u.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,u.entityName=r,u.propertyName="subPropertyOf",u.actualValue=p,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 c of a){if(i!==null&&c.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=i!==null?r:t,l=s.body[p];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,p,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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.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 c=a.join(" \u2192 "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${c}`,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=c,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,c]of Object.entries(e.metadata.imports))for(let s of c){let p=`${a}/${s.packageName}@${s.version}`;n.push(p);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 c=this.detectCycleRecursive(a,o,t,i);if(c)return c}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 c=n.type?.toString();this.isPropertyType(c)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=a.type?.toString();if(this.isPropertyType(c)||this.isClassType(c))continue;for(let[s,p]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}'.
12
12
  1. Verify the namespace is imported with the correct alias
13
13
  2. Check if the property name is spelled correctly
14
14
  3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
15
15
  1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
16
16
  2. Import the namespace that contains '${s}', OR
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,n){if(!e.metadata.imports)return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let a of i){if(n!==null&&a.alias!==n)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,n){let r=e.metadata.namespace_?.toString()??"";if(r&&n.has(r)||(r&&n.add(r),!e.metadata.imports))return!1;for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,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,n))return!0}}return!1}};var L=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=[],n=new Set;for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=i.type?.toString();this.isPropertyType(p)&&n.add(r)}for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let a=i,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(n.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}'.
17
+ 3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,m.entityName=r,m.propertyName=s,m.actualValue=p?.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 c=await o.getHighestCompatibleVersionAsync(r,a);if(c){let s=c.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,o,t,p))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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var L=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 c=n.type?.toString();this.isPropertyType(c)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=a.type?.toString();if(!this.isPropertyType(c)&&!this.isClassType(c))continue;for(let[s,p]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(c)?"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}'.
18
18
  1. Verify the namespace is imported with the correct alias
19
19
  2. Check if the property name is spelled correctly
20
20
  3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
21
21
  1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
22
22
  2. Import the namespace that contains '${s}', OR
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,n){if(!e.metadata.imports)return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let a of i){if(n!==null&&a.alias!==n)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,n){let r=e.metadata.namespace_?.toString()??"";if(r&&n.has(r)||(r&&n.add(r),!e.metadata.imports))return!1;for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,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,n))return!0}}return!1}};var W=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=[],n=new Set,r=[];for(let[i,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(i);let l=this.getPropertyValue(p,"range");l&&this.xsdTypes.has(l)&&n.add(l)}}if(n.size>0&&!await this.checkXsdImportAsync(e.metadata,o)){let a=Array.from(n).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 n=e.namespace_?.toString()??"";if(n&&t.has(n))return!1;n&&t.add(n);for(let[,r]of Object.entries(e.imports))for(let i of r)if(i.packageName==="xsd"||i.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[r,i]of Object.entries(e.imports))for(let a of i){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=[],n=await this.buildEntitySourceMapAsync(e,o),r=await this.buildDatatypePropertyNamesAsync(e,o);for(let[i,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&this.validateEntityReferences(i,a,n,r,e,t);return t}async buildEntitySourceMapAsync(e,o){let t=new Map,n=new Set;for(let r of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";t.has(r)||t.set(r,[]),t.get(r).push(`(local:${i})`)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let a of i){let p=await o.getHighestCompatibleVersionAsync(r,a);p&&await this.collectEntitiesRecursivelyAsync(p,t,n,o)}return t}async collectEntitiesRecursivelyAsync(e,o,t,n){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let i of Object.keys(e.body)){o.has(i)||o.set(i,[]);let a=o.get(i);a.includes(r)||a.push(r)}if(e.metadata.imports)for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await n.getHighestCompatibleVersionAsync(i,p);s&&await this.collectEntitiesRecursivelyAsync(s,o,t,n)}}}async buildDatatypePropertyNamesAsync(e,o){let t=new Set,n=new Set;if(await this.collectDatatypePropertiesAsync(e,t,n,o),e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let a of i){let p=await o.getHighestCompatibleVersionAsync(r,a);p&&await this.collectDatatypePropertiesAsync(p,t,n,o)}return t}async collectDatatypePropertiesAsync(e,o,t,n){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let[i,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(i)}if(e.metadata.imports)for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await n.getHighestCompatibleVersionAsync(i,p);s&&await this.collectDatatypePropertiesAsync(s,o,t,n)}}}validateEntityReferences(e,o,t,n,r,i){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&&i.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,r,!0,s))}}this.validatePropertyValue(e,s,p,t,n,r,i)}}validatePropertyValue(e,o,t,n,r,i,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=n.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,i,!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],n,r,i,a)}else if(typeof t=="object"&&!Array.isArray(t)){let c=o?`${e}.${o}`:e;this.validateEntityReferences(c,t,n,r,i,a)}}createAmbiguityError(e,o,t,n,r,i,a){let p=[];for(let f of n){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=n.map(f=>` \u2022 ${f}`).join(`
23
+ 3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=r,f.propertyName=s,f.actualValue=p?.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 c=await o.getHighestCompatibleVersionAsync(r,a);if(c){let s=c.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,o,t,p))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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var W=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 c=a,s=!1,p=c.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="DatatypeProperty"){s=!0;break}}else p?.toString()==="DatatypeProperty"&&(s=!0);if(s){r.push(n);let l=this.getPropertyValue(c,"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(", "),c=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: ${c}`,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 c=await o.getHighestCompatibleVersionAsync(r,a);if(c?.metadata&&await this.checkXsdImportAsync(c.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 c=await o.getHighestCompatibleVersionAsync(r,a);c&&await this.collectEntitiesRecursivelyAsync(c,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 c of a){let s=await i.getHighestCompatibleVersionAsync(n,c);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 c=await o.getHighestCompatibleVersionAsync(r,a);c&&await this.collectDatatypePropertiesAsync(c,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 c=a.type;if(typeof c!="string")continue;(c.includes(".")?c.substring(c.lastIndexOf(".")+1):c)==="DatatypeProperty"&&o.add(n)}if(e.metadata.imports)for(let[n,a]of Object.entries(e.metadata.imports))for(let c of a){let s=await i.getHighestCompatibleVersionAsync(n,c);s&&await this.collectDatatypePropertiesAsync(s,o,t,i)}}}validateEntityReferences(e,o,t,i,r,n){for(let[a,c]of Object.entries(o)){let s=a;if(s&&!s.includes(".")){let p=t.get(s);if(p&&p.length>1&&!p.some(y=>y.startsWith("(local:"))){let y=p.filter(u=>!u.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,r,!0,s))}}this.validatePropertyValue(e,s,c,t,i,r,n)}}validatePropertyValue(e,o,t,i,r,n,a){if(t==null)return;let c=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o,s=!!c&&r.has(c);if(typeof t=="string"&&!t.includes(".")&&!s){let p=i.get(t);if(p&&p.length>1&&!p.some(y=>y.startsWith("(local:"))){let y=p.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 p=0;p<t.length;p++){let l=`${e}.${o}[${p}]`;this.validatePropertyValue(l,o,t[p],i,r,n,a)}else if(typeof t=="object"&&!Array.isArray(t)){let p=o?`${e}.${o}`:e;this.validateEntityReferences(p,t,i,r,n,a)}}createAmbiguityError(e,o,t,i,r,n,a){let c=[];for(let f of i){let d=this.findAliasForNamespace(r,f);if(d){let b=o?.split(".").pop()??o;c.push(`${d}.${b}`)}}let s=c.length>0?`Use one of: ${c.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${o}')`,p=i.map(f=>` \u2022 ${f}`).join(`
24
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}
25
25
 
26
26
  Defined in:
27
- ${c}`,u.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",u}findAliasForNamespace(e,o){if(!e.metadata.imports)return null;for(let[t,n]of Object.entries(e.metadata.imports))for(let r of n)if(`${t}/${r.packageName}@${r.version}`===o&&r.alias)return r.alias;return null}};var U=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=[],n=new Set;for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=i.type?.toString();this.isValidRangeTargetType(p)&&n.add(r)}for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let a=i,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)||n.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:
27
+ ${p}`,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 U=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 c=n.type?.toString();this.isValidRangeTargetType(c)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n,c=a.type?.toString();if(c!=="DatatypeProperty"&&c!=="ObjectProperty"&&!c?.endsWith(".DatatypeProperty")&&!c?.endsWith(".ObjectProperty"))continue;let s=a.range;if(!s)continue;let p=[];if(Array.isArray(s))for(let l of s){let y=l?.toString();y&&p.push(y)}else{let l=s?.toString();l&&p.push(l)}if(p.length===0)continue;for(let l of p){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||i.has(l))continue;if(!await this.isTypeAvailableInImports(e,o,l)){let u=c?.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:
28
28
  1. Define '${l}' as a Class in this namespace, OR
29
29
  2. Import the namespace that contains '${l}', OR
30
30
  3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
31
31
  1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
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 n=null,r=t;if(t.includes(".")){let i=t.split(".",2);n=i[0],r=i[1]}for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){if(n!==null&&p.alias!==n)continue;let s=await o.getHighestCompatibleVersionAsync(i,p);if(s){let c=n!==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,n){let r=e.metadata.namespace_?.toString()??"";if(r&&n.has(r)||(r&&n.add(r),!e.metadata.imports))return!1;for(let[i,a]of Object.entries(e.metadata.imports))for(let p of a){let s=await o.getHighestCompatibleVersionAsync(i,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,n))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var F=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,o){let t=[],n=new Map,r=new A(o);await r.buildEntityIndexAsync(e);for(let[i,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)||(n.has(u)||n.set(u,[]),n.get(u).push(i))}}for(let[i,a]of n)if(!await r.resolveEntityAsync(i,e))for(let s of a){let c=new h;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${i}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${i}' is imported, or define '${i}' in this document`,c.entityName=s,c.propertyName="range",c.actualValue=i,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 n=t.entity.type;if(n){let r=String(n);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=[],n=new A(o),r=new J(n),i=await n.buildEntityIndexAsync(e),a=await this.buildPropertyMetadataAsync(e,o,n,i);for(let[p,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,p,"",a,n,r,e,t);return t}async scanEntityForObjectProperties(e,o,t,n,r,i,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=n.get(l);if(u&&i.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(V=>V.trim()).filter(V=>V.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:
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 c of a){if(i!==null&&c.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=i!==null?r:t,l=s.body[p];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,p,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 c of a){let s=await o.getHighestCompatibleVersionAsync(n,c);if(s){let p=s.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let y=p.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 F=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,o){let t=[],i=new Map,r=new A(o);await r.buildEntityIndexAsync(e);for(let[n,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a,s=!1,p=c.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="ObjectProperty"){s=!0;break}}else p?.toString()==="ObjectProperty"&&(s=!0);if(s){let l=c.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 p=new h;p.ruleType=this.ruleName,p.severity="Warning",p.message=`ObjectProperty references class '${n}' which may not be imported`,p.suggestion=`Ensure the namespace containing '${n}' is imported, or define '${n}' in this document`,p.entityName=s,p.propertyName="range",p.actualValue=n,t.push(p)}return t}};var J=class g{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"&&g.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 g.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 A(o),r=new J(i),n=await i.buildEntityIndexAsync(e),a=await this.buildPropertyMetadataAsync(e,o,i,n);for(let[c,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,c,"",a,i,r,e,t);return t}async scanEntityForObjectProperties(e,o,t,i,r,n,a,c){for(let[s,p]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 p=="string"&&p.trim().length>0){let d=p.trim();if(d.includes(",")){let v=d.split(",").map(V=>V.trim()).filter(V=>V.length>0);c.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:
33
33
  ${s}:
34
34
  - ${v[0]}
35
35
  ${v.slice(1).map(V=>` - ${V}`).join(`
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,n,r,i,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(),V=await r.resolveEntityAsync(v,a);if(V){if(u.range&&!await this.validateRangeType(V,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,n,r,i,a,p)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!n.has(s)){let m=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,m,n,r,i,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,n,r,i,a,p)}}}}async validateRangeType(e,o,t,n){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(o))return!0;let i=e.entity.type;if(i){let a=[];if(Array.isArray(i))for(let p of i){let s=p?.toString();s&&s.trim().length>0&&a.push(s)}else{let p=i?.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,n))return!0}}return!1}async buildPropertyMetadataAsync(e,o,t,n){let r=new Map;for(let[i,a]of n){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(i,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=[],n=new Map;for(let[i,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"))&&n.set(i,p)}let r=await this.buildCompleteClassHierarchyAsync(e,o);for(let[i,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,i,s,n,r,t)}return t}async buildCompleteClassHierarchyAsync(e,o){let t=new Map,n=new Set,r=async(a,p)=>{if(!n.has(p)){n.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{}}},i=e.metadata.namespace_?.toString()??"unknown";return await r(e,i),t}validateEntityProperties(e,o,t,n,r,i){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=n.get(s);if(!l)continue;let y=this.getPropertyValue(l,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,r)){let u=o.split(".")[0];i.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:
36
+ `)}`,entityName:o,propertyName:s,propertyPath:f,actualValue:d,expectedValue:`A single reference to ${u.range??"an entity"} OR a YAML list`});continue}let b=await r.resolveEntityAsync(d,a);if(b)u.range&&(await this.validateRangeType(b,u.range,r,a)||c.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${u.range}, but '${d}' may not be a ${u.range}`,suggestion:`Ensure '${d}' is defined with appropriate type`,entityName:o,propertyName:s,propertyPath:f,actualValue:d,expectedValue:u.range}));else{let v=u.range??"entity";c.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${d}' which is not defined or imported`,suggestion:`Define '${d}' or import a namespace that contains it. Expected range: ${v}`,entityName:o,propertyName:s,propertyPath:f,actualValue:d,expectedValue:"Defined or imported entity"})}}else if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let d=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(p,o,d,i,r,n,a,c)}else if(Array.isArray(p))for(let d=0;d<p.length;d++){let b=p[d];if(typeof b=="string"&&b.trim().length>0){let v=b.trim(),V=await r.resolveEntityAsync(v,a);if(V){if(u.range&&!await this.validateRangeType(V,u.range,r,a)){let Q=t?`${t}.${s}[${d}]`:`${s}[${d}]`;c.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}[${d}]`,propertyPath:Q,actualValue:v,expectedValue:u.range})}}else{let re=u.range??"entity",Q=t?`${t}.${s}[${d}]`:`${s}[${d}]`;c.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}[${d}]`,propertyPath:Q,actualValue:v,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let v=t?`${t}.${s}[${d}]`:`${s}[${d}]`;await this.scanEntityForObjectProperties(b,o,v,i,r,n,a,c)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!i.has(s)){let m=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(p,o,m,i,r,n,a,c)}else if(Array.isArray(p))for(let m=0;m<p.length;m++){let f=p[m];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=t?`${t}.${s}[${m}]`:`${s}[${m}]`;await this.scanEntityForObjectProperties(f,o,d,i,r,n,a,c)}}}}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 c of n){let s=c?.toString();s&&s.trim().length>0&&a.push(s)}else{let c=n?.toString();c&&c.trim().length>0&&a.push(c)}for(let c of a){let s=c.includes(".")?c.split(".")[1]:c;if(s===o||o==="Property"&&(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")||o==="Class"&&s==="Class"||await t.isSubclassOfAsync(c,o,i))return!0}}return!1}async buildPropertyMetadataAsync(e,o,t,i){let r=new Map;for(let[n,a]of i){let c=a.entity.type;if(c){let s=[];if(Array.isArray(c))for(let y of c){let u=y?.toString();u&&u.trim().length>0&&s.push(u)}else{let y=c?.toString();y&&y.trim().length>0&&s.push(y)}let p=!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"){p=!0,l=y;break}}if(p){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 c=a,s=this.getPropertyValue(c,"type");(s==="DatatypeProperty"||s?.endsWith(".DatatypeProperty")||s==="ObjectProperty"||s?.endsWith(".ObjectProperty")||s==="AnnotationProperty"||s?.endsWith(".AnnotationProperty"))&&i.set(n,c)}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 c=a,s=this.getPropertyValue(c,"type");if(!s||s==="Class"||s.endsWith(".Class")||s.endsWith("Property")||s==="AnnotationProperty")continue;this.validateEntityProperties(c,n,s,i,r,t)}return t}async buildCompleteClassHierarchyAsync(e,o){let t=new Map,i=new Set,r=async(a,c)=>{if(!i.has(c)){i.add(c);for(let[s,p]of Object.entries(a.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let l=p,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,p]of Object.entries(a.metadata.imports))for(let l of p)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,c]of Object.entries(e)){if(this.standardProperties.has(a))continue;let s=a,p=a.lastIndexOf(".");p>0&&p<a.length-1&&(s=a.substring(p+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:
37
37
  1. Use this property only on '${y}' instances
38
38
  2. Change the property domain to include '${t}'
39
- 3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof 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,n,r,i)}else{let f=this.getPropertyValue(l,"range");if(f){let g=`${o}.${a}`;this.validateEntityProperties(u,g,f,n,r,i)}}}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,n,r,i)}else{let R=this.getPropertyValue(l,"range");if(R){let v=`${o}.${a}[${u}]`;this.validateEntityProperties(f,v,R,n,r,i)}}}}}}}isTypeCompatibleWithDomain(e,o,t){if(e===o)return!0;let n=new Set,r=[e];for(;r.length>0;){let i=r.shift();if(n.has(i))continue;n.add(i);let a=t.get(i);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 n=e[t];return this.extractFirstValue(n)}}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 z=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,o){let t=[],n=new Map;for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let a=i,p=this.getPropertyValue(a,"type");(p==="DatatypeProperty"||p==="ObjectProperty")&&n.set(r,a)}for(let[r,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let a=i,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=n.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:
39
+ 3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let u=c,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 d=`${o}.${a}`;this.validateEntityProperties(u,d,f,i,r,n)}}}else if(Array.isArray(c))for(let u=0;u<c.length;u++){let m=c[u];if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=m,d=this.getPropertyValue(f,"type");if(d){let b=`${o}.${a}[${u}]`;this.validateEntityProperties(f,b,d,i,r,n)}else{let b=this.getPropertyValue(l,"range");if(b){let v=`${o}.${a}[${u}]`;this.validateEntityProperties(f,v,b,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 c of a){if(c===o)return!0;r.push(c)}}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 z=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,c=this.getPropertyValue(a,"type");(c==="DatatypeProperty"||c==="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,c=this.getPropertyValue(a,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[s,p]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 p=="object"&&p!==null&&!Array.isArray(p)||Array.isArray(p))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:
40
40
  1. Create a class for this data and change '${s}' to an ObjectProperty
41
41
  2. Store as a JSON string to keep it as DatatypeProperty
42
- 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let 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 n=[];for(let r of t)n.push(r?.toString()??"");return n.length>0?n[0]:void 0}return t?.toString()}}};var B=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=[],n=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&&(n.has(u)||n.set(u,[]),n.get(u).push(a))}}else{let l=c?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(n.has(l)||n.set(l,[]),n.get(l).push(a)))}this.checkNestedTypes(s,a,n,a)}let i=new A(o);for(let[a,p]of n){if(this.builtInClasses.has(a)||r.has(a))continue;let s=await i.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,n){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let r=e,i=r.type;if(i){let a=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(i))for(let p of i){let s=p?.toString();s&&s.trim().length>0&&!a.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(n))}else{let p=i?.toString();p&&p.trim().length>0&&!a.has(p)&&(t.has(p)||t.set(p,[]),t.get(p).push(n))}}for(let[a,p]of Object.entries(r))if(a!=="type"){let s=`${n}.${a}`;this.checkNestedTypes(p,o,t,s)}}else if(Array.isArray(e))for(let r=0;r<e.length;r++){let i=`${n}[${r}]`;this.checkNestedTypes(e[r],o,t,i)}}isClassEntity(e){if(!e)return!1;let o=e.type;if(!o)return!1;if(Array.isArray(o))for(let t of o){let n=t?.toString();if(n==="Class"||n&&n.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 Z,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 L,new W,new H,new U,new F,new q,new X,new z,new B]}async validateAsync(e,o){let t=new P;for(let n of this.documentRules)try{let r=n.validate(e);this.addErrorsToResult(t,r)}catch(r){let i=new h;i.ruleType=n.ruleName,i.severity="Error",i.message=`Validation rule '${n.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,t.errors.push(i)}if(o){let n=[];for(let r of this.repositoryRules)try{let i=await r.validateAsync(e,o);this.addErrorsToResult(t,i)}catch(i){let a=i instanceof Error?i.message:String(i);n.push({ruleName:r.ruleName,cause:a})}if(n.length>0){let r=new Map;for(let{ruleName:i,cause:a}of n){let p=r.get(a);p?p.push(i):r.set(a,[i])}for(let[i,a]of r){let p=new h;p.ruleType=a[0],p.severity="Error",a.length===1?p.message=`Validation rule '${a[0]}' failed: ${i}`:p.message=`${i} (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 n=new P;n.isValid=!1;for(let r of t.errors){let i=new h;i.ruleType="ParseError",i.severity="Error",i.lineNumber=r.line,i.column=r.column,i.message=r.message,r.keyName&&(i.entityName=r.keyName),r.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),n.errors.push(i)}return n}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,B as ClassDefinitionRule,N as ClassHierarchyCycleRule,L as DefinitionPropertyReferenceRule,w as EmbeddedKanonakTypeRule,E as ImportExistenceRule,M as InstancePropertyReferenceRule,te as KanonakObjectValidator,_ as NamespaceImportCycleRule,I as NamespacePrefixRule,F as ObjectPropertyImportRule,q as ObjectPropertyValueValidationRule,h as OntologyValidationError,P as OntologyValidationResult,X as PropertyDomainRule,K as PropertyHierarchyCycleRule,U as PropertyRangeReferenceRule,C as PropertyRangeRequiredRule,O as PropertyTypeSpecificityRule,z 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,W as XsdImportRule};
42
+ 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,p)){let d={ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' expects type '${f}' but instance '${r}' has value of type '${this.getValueTypeName(p)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(d.expectedValue=f),t.push(d)}}else if(m==="ObjectProperty")if(Array.isArray(p))for(let d=0;d<p.length;d++){let b=p[d];typeof b!="string"&&(typeof b!="object"||b===null||Array.isArray(b))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:`${s}[${d}]`,message:`ObjectProperty '${s}' array item ${d} in instance '${r}' has invalid type '${this.getValueTypeName(b)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof p!="string"&&(typeof p!="object"||p===null||Array.isArray(p))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`ObjectProperty '${s}' in instance '${r}' has invalid value type '${this.getValueTypeName(p)}'`,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 B=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,c]of Object.entries(e.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let p=c.type;if(p)if(Array.isArray(p))for(let l of p){let y=l?.toString();if(y==="Class"||y&&y.endsWith(".Class")){r.add(a);break}}else{let l=p?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&r.add(a)}}for(let[a,c]of Object.entries(e.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let s=c,p=s.type;if(p)if(Array.isArray(p)){let l=!1;for(let y of p){let u=y?.toString();if(u&&this.isDefinitionType(u)){l=!0;break}}if(!l)for(let y of p){let u=y?.toString();u&&u.trim().length>0&&(i.has(u)||i.set(u,[]),i.get(u).push(a))}}else{let l=p?.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 A(o);for(let[a,c]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(c)).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 c of n){let s=c?.toString();s&&s.trim().length>0&&!a.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(i))}else{let c=n?.toString();c&&c.trim().length>0&&!a.has(c)&&(t.has(c)||t.set(c,[]),t.get(c).push(i))}}for(let[a,c]of Object.entries(r))if(a!=="type"){let s=`${i}.${a}`;this.checkNestedTypes(c,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 Z,this.documentRules=[new I,new D,new O,new $],this.repositoryRules=[new w,new E,new S,new j,new N,new K,new x,new C,new T,new _,new M,new L,new W,new H,new U,new F,new q,new X,new z,new B]}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 c=r.get(a);c?c.push(n):r.set(a,[n])}for(let[n,a]of r){let c=new h;c.ruleType=a[0],c.severity="Error",a.length===1?c.message=`Validation rule '${a[0]}' failed: ${n}`:c.message=`${n} (affects ${a.length} rules: ${a.join(", ")})`,t.errors.push(c)}}}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,B as ClassDefinitionRule,N as ClassHierarchyCycleRule,L as DefinitionPropertyReferenceRule,w as EmbeddedKanonakTypeRule,E as ImportExistenceRule,M as InstancePropertyReferenceRule,te as KanonakObjectValidator,_ as NamespaceImportCycleRule,I as NamespacePrefixRule,F as ObjectPropertyImportRule,q as ObjectPropertyValueValidationRule,h as OntologyValidationError,P as OntologyValidationResult,X as PropertyDomainRule,K as PropertyHierarchyCycleRule,U as PropertyRangeReferenceRule,x as PropertyRangeRequiredRule,O as PropertyTypeSpecificityRule,z as PropertyValueTypeRule,D as ResourceNamingRule,C as SubClassOfReferenceRule,T as SubPropertyOfReferenceRule,$ as SubjectKanonakTypeRequiredRule,j as TypeAmbiguityRule,S as UnresolvedReferenceRule,ee as ValidationContext,R as ValidationSeverity,W as XsdImportRule};
@@ -35,6 +35,28 @@ import { OntologyValidationError } from '../../OntologyValidationError.js';
35
35
  export declare class EmbeddedKanonakTypeRule implements IRepositoryValidationRule {
36
36
  get ruleName(): string;
37
37
  validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
38
+ /**
39
+ * Pick the right property-range candidate when multiple packages
40
+ * declare a property with the same local name (e.g. `tx.Not.operand`
41
+ * range `Expression` vs. `wv.NotCondition.operand` range `Condition`).
42
+ *
43
+ * Disambiguation strategy, in priority order:
44
+ *
45
+ * 1. If the property name as authored is alias-prefixed
46
+ * (`tx.operand`), match candidates whose declaring entity
47
+ * shares the same alias prefix. This is the unambiguous case
48
+ * most authors hit — the YAML key carries the disambiguator.
49
+ * 2. Otherwise, if the parent dict has a `type:` declaration,
50
+ * match candidates whose `domain` local-name equals the parent
51
+ * class's local-name. The embedded under `type: tx.Not` only
52
+ * reasonably refers to the `operand` property whose domain is
53
+ * `tx.Not` (kanonak-protocol/typescript#17).
54
+ * 3. Last resort: return the first candidate. Authors who hit this
55
+ * branch have a genuinely ambiguous shape — bare property name,
56
+ * no parent type, multiple matching properties — and the rule
57
+ * can't tell which they meant.
58
+ */
59
+ private pickRange;
38
60
  /**
39
61
  * Recursively descend through a YAML dict, validating any `type:`
40
62
  * declarations encountered at depth > 0 against the closest known
@@ -60,16 +82,21 @@ export declare class EmbeddedKanonakTypeRule implements IRepositoryValidationRul
60
82
  private validateEmbeddedType;
61
83
  private localName;
62
84
  /**
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`.
85
+ * Build a map from property local name → list of candidate
86
+ * declarations (range + domain + declaring alias). Multiple
87
+ * candidates exist when more than one imported package declares a
88
+ * property with the same local name (e.g. `tx.Not.operand` range
89
+ * `Expression` AND `wv.NotCondition.operand` range `Condition`).
90
+ *
91
+ * Pre-#17, this map collapsed candidates by overwriting each prior
92
+ * entry, so the last-loaded property won and silently shadowed the
93
+ * others. Now all candidates are kept; `pickRange` picks the right
94
+ * one at lookup time using alias-prefix and parent-class context.
67
95
  *
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`).
96
+ * The local-name keying mirrors the lookup pattern in
97
+ * `checkEmbeddedTypes` (which uses `localName(propertyName)` for
98
+ * the lookup). Same convention as `PropertyValueTypeRule` and
99
+ * `ObjectPropertyValueValidationRule`.
73
100
  */
74
101
  private buildPropertyRangeMap;
75
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.9.0",
3
+ "version": "3.11.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": "^3.9.0",
108
+ "@kanonak-protocol/types": "^3.11.0",
109
109
  "ignore": "^7.0.5",
110
110
  "js-yaml": "^4.1.0",
111
111
  "yaml": "^2.7.0"