@kanonak-protocol/sdk 2.2.0 → 2.4.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.
- package/dist/browser.js +17 -17
- package/dist/index.d.ts +3 -3
- package/dist/index.js +50 -50
- package/dist/kanonaks/EmbeddedKanonak.d.ts +16 -0
- package/dist/parsing/KanonakDocumentPositions.d.ts +59 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/resolution/KanonakAddress.d.ts +58 -0
- package/dist/resolution/KanonakUri.d.ts +49 -2
- package/dist/resolution/index.d.ts +2 -0
- package/dist/resolution/index.js +1 -1
- package/dist/validation/index.js +15 -15
- package/dist/validation/rules/repository/AmbiguousReferenceRule.d.ts +11 -0
- package/package.json +2 -2
package/dist/validation/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
var P=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(n=>(n.Warning="Warning",n.Error="Error",n))(b||{});var g=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var ee=class h{resolvedDocuments=[];currentEntityPath;withPath(e){let n=new h;return n.resolvedDocuments=this.resolvedDocuments,n.currentEntityPath=e,n}};import*as Z from"js-yaml";var G=class{parse(e){let n=this.parseWithErrors(e);if(!n.isValid){let t=n.errors[0];throw new Error(`YAML parse error at line ${t.line}, column ${t.column}: ${t.message}`)}return n.document}parseWithErrors(e){let n=[],t;try{e=e.replace(/^\uFEFF/,"");let i=Z.load(e);if(!i||typeof i!="object")return t={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:t,errors:n,isValid:!0};let r=this.extractMetadata(i),o=this.extractBody(i,r);return t={metadata:r,body:o,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:t,errors:n,isValid:!0}}catch(i){let r=i,o={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 n.push(o),{document:void 0,errors:n,isValid:!1}}}save(e){let n={};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)),n[t.package_]=i}return Object.assign(n,e.body),Z.dump(n,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let n=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!n)return[];let t=[];for(let i of Object.values(n))t.push(...i);return t},enumerable:!0,configurable:!0}),e}createVersion(e,n,t){return{major:e,minor:n,patch:t,toString:()=>`${e}.${n}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===n&&r.patch===t,getHashCode:()=>e<<20|n<<10|t,compareTo:r=>e!==r.major?e-r.major:n!==r.minor?n-r.minor:t-r.patch}}extractMetadata(e){let n=this.createEmptyMetadata();for(let[t,i]of Object.entries(e))if(i&&typeof i=="object"&&i.type==="Package"){n.type_="Package";let r=t,o=i.publisher,p=i.version?this.parseVersion(i.version):void 0;return o&&r&&(n.namespace_={publisher:o,package_:r,version:p,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:a=>!a||typeof a!="object"?!1:a.publisher===o&&a.package_===r&&(!p||!a.version||p.equals(a.version)),getHashCode:()=>{let a=0;for(let s=0;s<o.length;s++)a=(a<<5)-a+o.charCodeAt(s);for(let s=0;s<r.length;s++)a=(a<<5)-a+r.charCodeAt(s);return a|0}}),i.imports&&Array.isArray(i.imports)&&(n.imports=this.parseImportsV3(i.imports)),this.addAllImportsGetter(n)}if(e.kanonak&&typeof e.kanonak=="object"){let t=e.kanonak;return(t.publisher||t.package||t.version)&&(n.namespace_=this.parseNamespace(t)),t.imports&&typeof t.imports=="object"&&(n.imports=this.parseImportsLegacy(t.imports)),this.addAllImportsGetter(n)}return n}extractBody(e,n){let t={},i;for(let[r,o]of Object.entries(e))if(o&&typeof o=="object"&&o.type==="Package"){i=r;break}for(let[r,o]of Object.entries(e))r!==i&&r!=="kanonak"&&r!=="namespace"&&r!=="imports"&&(t[r]=o);return t}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let o=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:o,toString:()=>e,equals:p=>!p||typeof p!="object"?!1:p.publisher===r[1]&&p.package_===r[2]&&(!o||!p.version||o.equals(p.version)),getHashCode:()=>{let p=0;for(let a=0;a<r[1].length;a++)p=(p<<5)-p+r[1].charCodeAt(a);for(let a=0;a<r[2].length;a++)p=(p<<5)-p+r[2].charCodeAt(a);return p|0}}}}let n=e.publisher||"",t=e.package||"",i=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:n,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===n&&r.package_===t&&(!i||!r.version||i.equals(r.version)),getHashCode:()=>{let r=0;for(let o=0;o<n.length;o++)r=(r<<5)-r+n.charCodeAt(o);for(let o=0;o<t.length;o++)r=(r<<5)-r+t.charCodeAt(o);return r|0}}}parseVersion(e){if(typeof e=="string"){let n=e.split(".").map(Number);return this.createVersion(n[0]||0,n[1]||0,n[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let n={};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");n[i]||(n[i]=[]);for(let r of t.packages){if(!r||typeof r!="object")continue;let o=this.parseImportFromEmbeddedObject(r,i);n[i].push(o)}}else{let i=this.parseImportFromEmbeddedObject(t,t.publisher),r=i.publisher||"";n[r]||(n[r]=[]),n[r].push(i)}return n}parseImportsLegacy(e){let n={};for(let[t,i]of Object.entries(e))Array.isArray(i)&&(n[t]=i.map(r=>this.parseImport(r,t)));return n}parseImportFromEmbeddedObject(e,n){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 o=this.parseVersion(r),p=this.parseVersionOperator(i),a=this.calculateMaxVersion(i,o),s=e.alias;return{package_:`${t} ${i} ${o.toString()}`,publisher:n,packageName:t,versionOperator:p,version:o,alias:s,minVersion:o,maxVersion:a,toEmbeddedObject:()=>{let c={package:t,match:i,version:o.toString()};return s&&(c.alias=s),c},toString:()=>s?`${t} ${i} ${o.toString()} as ${s}`:`${t} ${i} ${o.toString()}`}}parseImport(e,n){if(typeof e=="string"){let a=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(a){let c=a[1].trim(),l=a[2],m=this.parseVersion(a[3].trim()),y=a[4].trim(),u=this.parseVersionOperator(l),f=this.calculateMaxVersion(l,m);return{package_:e,publisher:n,packageName:c,versionOperator:u,version:m,alias:y,minVersion:m,maxVersion:f,toEmbeddedObject:()=>{let d={package:c,match:l,version:m.toString()};return y&&(d.alias=y),d},toString:()=>`${c} ${l} ${m.toString()} as ${y}`}}let s=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(s){let c=s[1].trim(),l=s[2],m=this.parseVersion(s[3].trim()),y=this.parseVersionOperator(l),u=this.calculateMaxVersion(l,m);return{package_:e,publisher:n,packageName:c,versionOperator:y,version:m,alias:void 0,minVersion:m,maxVersion:u,toEmbeddedObject:()=>({package:c,match:l,version:m.toString()}),toString:()=>`${c} ${l} ${m.toString()}`}}}let t=this.parseVersionOperator(e.operator||"~"),i=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",o=["=","~","^","*"][t],p=this.calculateMaxVersion(e.operator||"~",i);return{package_:e.package||"",publisher:n,packageName:r,versionOperator:t,version:i,alias:e.alias,minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let a={package:r,match:o,version:i.toString()};return e.alias&&(a.alias=e.alias),a},toString:()=>`${r} ${o} ${i.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,n){switch(e){case"~":return this.createVersion(n.major,n.minor+1,0);case"^":return n.major===0?this.createVersion(0,n.minor+1,0):this.createVersion(n.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let n=[];for(let[t,i]of Object.entries(e)){let r={publisher:t,packages:i.map(o=>{let p=["=","~","^","*"][o.versionOperator],a={package:o.packageName,match:p,version:`${o.version.major}.${o.version.minor}.${o.version.patch}`};return o.alias&&(a.alias=o.alias),a})};n.push(r)}return n}};var I=class h{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let n=[];for(let[t,i]of Object.entries(e.body))i&&typeof i=="object"&&!Array.isArray(i)&&this.validateEntity(t,i,n);return n}validateEntity(e,n,t){for(let[i,r]of Object.entries(n)){let o=r?.toString()??"";if(o&&h.NAMESPACE_PREFIX_PATTERN.test(o)){let p=this.getSuggestionForPrefixedValue(o),a=e.split(".")[0],s=new g;s.ruleType=this.ruleName,s.severity="Error",s.entityName=a,s.propertyName=e,s.actualValue=i,s.expectedValue=p,s.message=`Invalid namespace prefix '${o}'. Use '${p}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${i}`,r,t)}}getSuggestionForPrefixedValue(e){let n=e.toLowerCase();if(n==="rdfs:class"||n==="owl:class")return"Class";if(n==="rdfs:property"||n==="rdf:property")return"DatatypeProperty or ObjectProperty";if(n.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var D=class h{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let n=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[i,r]of Object.entries(e.body)){if(!t&&h.RESERVED_WORDS.has(i.toLowerCase())){let o=new g;o.ruleType=this.ruleName,o.severity="Error",o.entityName=i,o.message=`Entity name '${i}' is a reserved word and cannot be used.`,o.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",n.push(o);continue}if(!h.VALID_NAME_PATTERN.test(i)){let o;/^\d/.test(i)?o="Entity names must start with a letter, not a number.":i.includes(" ")?o="Entity names cannot contain spaces. Use camelCase or underscores instead.":o="Entity names must start with a letter and contain only letters, numbers, and underscores.";let p=new g;p.ruleType=this.ruleName,p.severity="Error",p.entityName=i,p.message=`Invalid entity name '${i}'. ${o}`,p.suggestion=o,n.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(i,r,n)}return n}validatePropertyNames(e,n,t){for(let i of Object.keys(n))if(!h.VALID_PROPERTIES.has(i)&&!h.VALID_PROPERTY_NAME_PATTERN.test(i)){let r=new g;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 h{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let n=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return n;let t=this.isPropertyDefinedAsClass(e);for(let[i,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r,p=o.type;if(p){let a=[];if(Array.isArray(p))for(let s of p){let c=s?.toString();c&&c==="Property"&&!t&&a.push(c)}else{let s=p?.toString();s&&s==="Property"&&!t&&a.push(s)}for(let s of a){let c=this.getPropertyValue(o,"range"),l=this.determinePropertyType(c),m=new g;m.ruleType=this.ruleName,m.severity="Error",m.entityName=i,m.propertyName="type",m.actualValue=s,m.expectedValue=l,m.message=`Invalid property type '${s}'. Use '${l}' instead.`,m.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",n.push(m)}}}return n}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":h.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,n){let t=e[n];return t?t.toString():null}isPropertyDefinedAsClass(e){let n=e.body.Property;if(n&&typeof n=="object"&&!Array.isArray(n)){let i=n.type;if(i){let r=i.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var $=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let n=[];for(let[t,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=i,o="type"in r,p=r.type?.toString().trim();if(!o||!p){let a=new g;a.ruleType=this.ruleName,a.severity="Error",a.entityName=t,a.propertyName="type",a.message=`Subject Kanonak '${t}' must have a 'type' property.`,a.suggestion=`Add a type statement like:
|
|
1
|
+
var P=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(o=>(o.Warning="Warning",o.Error="Error",o))(b||{});var h=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var ee=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new d;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};import*as Z from"js-yaml";var G=class{parse(e){let o=this.parseWithErrors(e);if(!o.isValid){let t=o.errors[0];throw new Error(`YAML parse error at line ${t.line}, column ${t.column}: ${t.message}`)}return o.document}parseWithErrors(e){let o=[],t;try{e=e.replace(/^\uFEFF/,"");let i=Z.load(e);if(!i||typeof i!="object")return t={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:t,errors:o,isValid:!0};let r=this.extractMetadata(i),n=this.extractBody(i,r);return t={metadata:r,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:t,errors:o,isValid:!0}}catch(i){let r=i,n={message:r.message||"Unknown parse error",line:r.mark?.line??0,column:r.mark?.column??0,errorType:r.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${r.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${r.mark?.line??0}: ${r.message||"Unknown parse error"}`};return o.push(n),{document:void 0,errors:o,isValid:!1}}}save(e){let o={};if(e.metadata.namespace_){let t=e.metadata.namespace_,i={type:"Package",publisher:t.publisher};t.version&&(i.version=`${t.version.major}.${t.version.minor}.${t.version.patch}`),e.metadata.imports&&(i.imports=this.serializeImports(e.metadata.imports)),o[t.package_]=i}return Object.assign(o,e.body),Z.dump(o,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let o=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!o)return[];let t=[];for(let i of Object.values(o))t.push(...i);return t},enumerable:!0,configurable:!0}),e}createVersion(e,o,t){return{major:e,minor:o,patch:t,toString:()=>`${e}.${o}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===o&&r.patch===t,getHashCode:()=>e<<20|o<<10|t,compareTo:r=>e!==r.major?e-r.major:o!==r.minor?o-r.minor:t-r.patch}}extractMetadata(e){let o=this.createEmptyMetadata();for(let[t,i]of Object.entries(e))if(i&&typeof i=="object"&&i.type==="Package"){o.type_="Package";let r=t,n=i.publisher,p=i.version?this.parseVersion(i.version):void 0;return n&&r&&(o.namespace_={publisher:n,package_:r,version:p,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:a=>!a||typeof a!="object"?!1:a.publisher===n&&a.package_===r&&(!p||!a.version||p.equals(a.version)),getHashCode:()=>{let a=0;for(let s=0;s<n.length;s++)a=(a<<5)-a+n.charCodeAt(s);for(let s=0;s<r.length;s++)a=(a<<5)-a+r.charCodeAt(s);return a|0}}),i.imports&&Array.isArray(i.imports)&&(o.imports=this.parseImportsV3(i.imports)),this.addAllImportsGetter(o)}if(e.kanonak&&typeof e.kanonak=="object"){let t=e.kanonak;return(t.publisher||t.package||t.version)&&(o.namespace_=this.parseNamespace(t)),t.imports&&typeof t.imports=="object"&&(o.imports=this.parseImportsLegacy(t.imports)),this.addAllImportsGetter(o)}return o}extractBody(e,o){let t={},i;for(let[r,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){i=r;break}for(let[r,n]of Object.entries(e))r!==i&&r!=="kanonak"&&r!=="namespace"&&r!=="imports"&&(t[r]=n);return t}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let n=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:n,toString:()=>e,equals:p=>!p||typeof p!="object"?!1:p.publisher===r[1]&&p.package_===r[2]&&(!n||!p.version||n.equals(p.version)),getHashCode:()=>{let p=0;for(let a=0;a<r[1].length;a++)p=(p<<5)-p+r[1].charCodeAt(a);for(let a=0;a<r[2].length;a++)p=(p<<5)-p+r[2].charCodeAt(a);return p|0}}}}let o=e.publisher||"",t=e.package||"",i=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:o,package_:t,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:r=>!r||typeof r!="object"?!1:r.publisher===o&&r.package_===t&&(!i||!r.version||i.equals(r.version)),getHashCode:()=>{let r=0;for(let n=0;n<o.length;n++)r=(r<<5)-r+o.charCodeAt(n);for(let n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n);return r|0}}}parseVersion(e){if(typeof e=="string"){let o=e.split(".").map(Number);return this.createVersion(o[0]||0,o[1]||0,o[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let o={};for(let t of e)if(!(!t||typeof t!="object"))if(t.packages&&Array.isArray(t.packages)){let i=t.publisher;if(!i)throw new Error("PublisherImport requires 'publisher' property");o[i]||(o[i]=[]);for(let r of t.packages){if(!r||typeof r!="object")continue;let n=this.parseImportFromEmbeddedObject(r,i);o[i].push(n)}}else{let i=this.parseImportFromEmbeddedObject(t,t.publisher),r=i.publisher||"";o[r]||(o[r]=[]),o[r].push(i)}return o}parseImportsLegacy(e){let o={};for(let[t,i]of Object.entries(e))Array.isArray(i)&&(o[t]=i.map(r=>this.parseImport(r,t)));return o}parseImportFromEmbeddedObject(e,o){let t=e.package;if(!t)throw new Error("Import requires 'package' property");let i=e.match;if(!i)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let n=this.parseVersion(r),p=this.parseVersionOperator(i),a=this.calculateMaxVersion(i,n),s=e.alias;return{package_:`${t} ${i} ${n.toString()}`,publisher:o,packageName:t,versionOperator:p,version:n,alias:s,minVersion:n,maxVersion:a,toEmbeddedObject:()=>{let c={package:t,match:i,version:n.toString()};return s&&(c.alias=s),c},toString:()=>s?`${t} ${i} ${n.toString()} as ${s}`:`${t} ${i} ${n.toString()}`}}parseImport(e,o){if(typeof e=="string"){let a=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(a){let c=a[1].trim(),l=a[2],y=this.parseVersion(a[3].trim()),m=a[4].trim(),u=this.parseVersionOperator(l),f=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:c,versionOperator:u,version:y,alias:m,minVersion:y,maxVersion:f,toEmbeddedObject:()=>{let g={package:c,match:l,version:y.toString()};return m&&(g.alias=m),g},toString:()=>`${c} ${l} ${y.toString()} as ${m}`}}let s=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(s){let c=s[1].trim(),l=s[2],y=this.parseVersion(s[3].trim()),m=this.parseVersionOperator(l),u=this.calculateMaxVersion(l,y);return{package_:e,publisher:o,packageName:c,versionOperator:m,version:y,alias:void 0,minVersion:y,maxVersion:u,toEmbeddedObject:()=>({package:c,match:l,version:y.toString()}),toString:()=>`${c} ${l} ${y.toString()}`}}}let t=this.parseVersionOperator(e.operator||"~"),i=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",n=["=","~","^","*"][t],p=this.calculateMaxVersion(e.operator||"~",i);return{package_:e.package||"",publisher:o,packageName:r,versionOperator:t,version:i,alias:e.alias,minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let a={package:r,match:n,version:i.toString()};return e.alias&&(a.alias=e.alias),a},toString:()=>`${r} ${n} ${i.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,o){switch(e){case"~":return this.createVersion(o.major,o.minor+1,0);case"^":return o.major===0?this.createVersion(0,o.minor+1,0):this.createVersion(o.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let o=[];for(let[t,i]of Object.entries(e)){let r={publisher:t,packages:i.map(n=>{let p=["=","~","^","*"][n.versionOperator],a={package:n.packageName,match:p,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(a.alias=n.alias),a})};o.push(r)}return o}};var I=class d{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,i]of Object.entries(e.body))i&&typeof i=="object"&&!Array.isArray(i)&&this.validateEntity(t,i,o);return o}validateEntity(e,o,t){for(let[i,r]of Object.entries(o)){let n=r?.toString()??"";if(n&&d.NAMESPACE_PREFIX_PATTERN.test(n)){let p=this.getSuggestionForPrefixedValue(n),a=e.split(".")[0],s=new h;s.ruleType=this.ruleName,s.severity="Error",s.entityName=a,s.propertyName=e,s.actualValue=i,s.expectedValue=p,s.message=`Invalid namespace prefix '${n}'. Use '${p}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${i}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var D=class d{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[i,r]of Object.entries(e.body)){if(!t&&d.RESERVED_WORDS.has(i.toLowerCase())){let n=new h;n.ruleType=this.ruleName,n.severity="Error",n.entityName=i,n.message=`Entity name '${i}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(n);continue}if(!d.VALID_NAME_PATTERN.test(i)){let n;/^\d/.test(i)?n="Entity names must start with a letter, not a number.":i.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let p=new h;p.ruleType=this.ruleName,p.severity="Error",p.entityName=i,p.message=`Invalid entity name '${i}'. ${n}`,p.suggestion=n,o.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(i,r,o)}return o}validatePropertyNames(e,o,t){for(let i of Object.keys(o))if(!d.VALID_PROPERTIES.has(i)&&!d.VALID_PROPERTY_NAME_PATTERN.test(i)){let r=new h;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=i,r.message=`Property name '${i}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var O=class d{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[i,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let n=r,p=n.type;if(p){let a=[];if(Array.isArray(p))for(let s of p){let c=s?.toString();c&&c==="Property"&&!t&&a.push(c)}else{let s=p?.toString();s&&s==="Property"&&!t&&a.push(s)}for(let s of a){let c=this.getPropertyValue(n,"range"),l=this.determinePropertyType(c),y=new h;y.ruleType=this.ruleName,y.severity="Error",y.entityName=i,y.propertyName="type",y.actualValue=s,y.expectedValue=l,y.message=`Invalid property type '${s}'. Use '${l}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(y)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let i=o.type;if(i){let r=i.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var $=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=i,n="type"in r,p=r.type?.toString().trim();if(!n||!p){let a=new h;a.ruleType=this.ruleName,a.severity="Error",a.entityName=t,a.propertyName="type",a.message=`Subject Kanonak '${t}' must have a 'type' property.`,a.suggestion=`Add a type statement like:
|
|
2
2
|
type: Scene
|
|
3
3
|
|
|
4
|
-
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,a.expectedValue="A valid class name (Scene, Character, Story, etc.)",
|
|
4
|
+
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,a.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(a)}}return o}};var w=class{get ruleName(){return"EmbeddedKanonakNoExplicitType"}validate(e){let o=[];for(let[t,i]of Object.entries(e.body))typeof i=="object"&&i!==null&&!Array.isArray(i)&&this.checkForEmbeddedTypeViolations(t,i,o,0);return o}checkForEmbeddedTypeViolations(e,o,t,i){for(let[r,n]of Object.entries(o)){let p=r;if(i>0&&p.toLowerCase()==="type"){let a=n?.toString(),s=e.split(".")[0],c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue="type",c.message=`Embedded object at '${e}' cannot have explicit 'type' property.`,c.suggestion=`Remove the 'type: ${a}' line.
|
|
5
5
|
|
|
6
6
|
Type is automatically inferred from the containing property's range.
|
|
7
7
|
If you need a different type, modify the 'range' of the parent property and version it appropriately.
|
|
8
8
|
|
|
9
|
-
Example: If the parent property is 'hasCharacter' with range 'Character', all embedded objects in that property will be typed as 'Character' automatically.`,c.expectedValue="No explicit type (inferred from parent property's range)",t.push(c)}if(typeof o=="object"&&o!==null)if(Array.isArray(o))for(let a=0;a<o.length;a++){let s=o[a];typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.checkForEmbeddedTypeViolations(`${e}.${p}[${a}]`,s,t,i+1)}else this.checkForEmbeddedTypeViolations(`${e}.${p}`,o,t,i+1)}}};var w=class{ruleName="ImportExistence";async validateAsync(e,n){let t=[];if(!e.metadata?.imports)return t;let i=await n.getAllDocumentsAsync();for(let[r,o]of Object.entries(e.metadata.imports))for(let p of o)if(!await n.getHighestCompatibleVersionAsync(r,p)){let s=await this.determineImportErrorAsync(n,r,p,i),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=s.message,c.suggestion=s.suggestion,c.entityName=`Import: ${r}/${p.packageName}`,c.actualValue=p.toString(),c.expectedValue=s.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,n,t,i){let r=await e.getDocumentsByNamespaceAsync(n,t.packageName);if(r.length===0){let s=i.filter(y=>y.metadata.namespace_?.publisher===n).map(y=>y.metadata.namespace_.package_).filter((y,u,f)=>f.indexOf(y)===u),c=this.findSimilarPackages(t.packageName,s),l=`Import '${n}/${t.package_}' not found - package does not exist`,m=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${n}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${n}'. Verify the publisher name is correct.`;return{message:l,suggestion:m,expectedValue:"Existing package"}}let p=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),a=this.getAcceptableVersionRange(t);return{message:`Import '${n}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${p}. Required: ${a}`,expectedValue:a}}getAcceptableVersionRange(e){switch(e.versionOperator){case 0:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case 1:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case 2:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case 3:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,n){if(n.length===0)return[];let t=n.filter(o=>o.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(o.toLowerCase()));if(t.length>0)return t.sort((o,p)=>o.length-p.length);let i=n.map(o=>({package:o,distance:this.levenshteinDistance(e.toLowerCase(),o.toLowerCase())})).sort((o,p)=>o.distance-p.distance),r=Math.max(3,Math.floor(e.length*.4));return i.filter(o=>o.distance<=r).map(o=>o.package)}levenshteinDistance(e,n){if(!e||e.length===0)return n?.length??0;if(!n||n.length===0)return e.length;let t=e.length,i=n.length,r=Array(t+1).fill(null).map(()=>Array(i+1).fill(0));for(let o=0;o<=t;o++)r[o][0]=o;for(let o=0;o<=i;o++)r[0][o]=o;for(let o=1;o<=t;o++)for(let p=1;p<=i;p++){let a=e[o-1]===n[p-1]?0:1;r[o][p]=Math.min(Math.min(r[o-1][p]+1,r[o][p-1]+1),r[o-1][p-1]+a)}return r[t][i]}};var Y=class h{constructor(e,n,t,i){this.publisher=e;this.package_=n;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 n=e.split("@");if(n.length!==2)throw new Error(`Invalid kanonak URI format: ${e}. Expected format: publisher/package/name@version`);let t=n[0],i=n[1],r=t.split("/");if(r.length!==3)throw new Error(`Invalid kanonak URI path format: ${t}. Expected format: publisher/package/name`);let o=i.split(".").map(Number),p={major:o[0]||0,minor:o[1]||0,patch:o[2]||0,toString:()=>`${o[0]||0}.${o[1]||0}.${o[2]||0}`,equals:a=>!a||typeof a!="object"?!1:a.major===(o[0]||0)&&a.minor===(o[1]||0)&&a.patch===(o[2]||0),getHashCode:()=>(o[0]||0)<<20|(o[1]||0)<<10|(o[2]||0),compareTo:a=>(o[0]||0)!==a.major?(o[0]||0)-a.major:(o[1]||0)!==a.minor?(o[1]||0)-a.minor:(o[2]||0)-a.patch};return new h(r[0],r[1],r[2],p)}toString(){return`${this.publisher}/${this.package_}/${this.name}@${this.version.major}.${this.version.minor}.${this.version.patch}`}};function v(h){if(Array.isArray(h))return h.map(n=>n?.toString()??"").filter(n=>n.length>0);let e=h?.toString();return e?[e]:[]}var V=class{cache=new Map;repository;logger;constructor(e,n){this.repository=e,this.logger=n}async resolveEntityAsync(e,n){let t=n.metadata?.namespace_?.toString()??"unknown",i=this.cache.get(t);if(i){let o=i.get(e);if(o)return o}let r=await this.buildEntityIndexAsyncInternal(n,new Set,"");return this.cache.set(t,r),r.get(e)??null}async resolveAllEntitiesAsync(e,n){let t=await this.buildAllEntitiesIndexAsync(n,new Set,"");if(e.includes(".")){let i=e.split("."),r=i[0],o=i[1],p=await this.findDocumentForAlias(n,r);return p?await this.resolveAllEntitiesAsync(o,p):[]}return t.filter(i=>i.entityName===e)}async buildAllEntitiesIndexAsync(e,n,t){let i=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),n.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;n.add(r);let o=t.length===0?r:`${t} \u2192 ${r}`;for(let[p,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let s=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.push({entityName:p,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,p,s),entity:a,definedInNamespace:r,isImported:t.length>0,importPath:o})}if(this.logger?.debug?.(`Collected ${i.length} entities from ${r}`),e.metadata?.imports){let p=Object.values(e.metadata.imports).reduce((a,s)=>a+s.length,0);this.logger?.debug?.(`Processing ${p} import(s) for ${r}`);for(let[a,s]of Object.entries(e.metadata.imports))for(let c of s)try{this.logger?.debug?.(`Resolving import: ${a}/${c.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(a,c);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let m=await this.buildAllEntitiesIndexAsync(l,n,o);i.push(...m),this.logger?.debug?.(`Added ${m.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${a}/${c.packageName}`)}catch(l){let m=l;throw this.logger?.error?.(`Failed to process import ${a}/${c.packageName} for namespace ${r}. Error: ${m.message}`,m),new Error(`Failed to process import ${a}/${c.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return i}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,n,t){let i=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),n.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;n.add(r);let o=t.length===0?r:`${t} \u2192 ${r}`,p=0;for(let[a,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)&&!i.has(a)){let c=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.set(a,{entityName:a,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,a,c),entity:s,definedInNamespace:r,isImported:t.length>0,importPath:o}),p++}if(this.logger?.debug?.(`Indexed ${p} entities from ${r}`),e.metadata?.imports){let a=Object.values(e.metadata.imports).reduce((s,c)=>s+c.length,0);this.logger?.debug?.(`Processing ${a} import(s) for ${r}`);for(let[s,c]of Object.entries(e.metadata.imports))for(let l of c)try{this.logger?.debug?.(`Resolving import: ${s}/${l.packageName}`);let m=await this.repository.getHighestCompatibleVersionAsync(s,l);if(m){this.logger?.debug?.(`Successfully loaded import: ${m.metadata?.namespace_?.toString()}`);let y=await this.buildEntityIndexAsyncInternal(m,n,o),u=0;for(let[f,d]of y.entries())if(i.has(f)||(i.set(f,d),u++),l.alias&&!f.includes(".")){let R=`${l.alias}.${f}`;i.has(R)||(i.set(R,d),u++)}this.logger?.debug?.(`Merged ${u} entities from import ${m.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${s}/${l.packageName}`)}catch(m){let y=m;throw this.logger?.error?.(`Failed to process import ${s}/${l.packageName} for namespace ${r}. Error: ${y.message}`,y),new Error(`Failed to process import ${s}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:m})}}return i}async findDocumentForAlias(e,n){if(!e.metadata?.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i){if(r.alias===n)return await this.repository.getHighestCompatibleVersionAsync(t,r);if(!r.alias&&r.packageName===n)return await this.repository.getHighestCompatibleVersionAsync(t,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,n,t){if(e===n)return!0;let i=new Set;return await this.isSubclassOfRecursiveAsync(e,n,t,i)}async isSubclassOfRecursiveAsync(e,n,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let o=r.entity.subClassOf;if(o){let p=v(o);for(let a of p)if(a===n||await this.isSubclassOfRecursiveAsync(a,n,t,i))return!0}return!1}async isSubpropertyOfAsync(e,n,t){if(e===n)return!0;let i=new Set;return await this.isSubpropertyOfRecursiveAsync(e,n,t,i)}async isSubpropertyOfRecursiveAsync(e,n,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let o=r.entity.subPropertyOf;if(o){let p=v(o);for(let a of p)if(a===n||await this.isSubpropertyOfRecursiveAsync(a,n,t,i))return!0}return!1}};var j=class{ruleName="UnresolvedReference";async validateAsync(e,n){let t=[],i=new V(n),r=await i.buildEntityIndexAsync(e),o=new Set;for(let[p,a]of r.entries()){let s=a.entity.type;if(s){let c=s.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&o.add(p)}}for(let[p,a]of Object.entries(e.body)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a,c=this.getPropertyValue(s,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[l,m]of Object.entries(s))l==="type"||l==="label"||l==="comment"||!(o.has(l)||Array.from(o).some(u=>u.endsWith(`.${l}`)))||await this.validateReferenceValue(p,l,m,e,i,t)}return t}async validateReferenceValue(e,n,t,i,r,o){if(t!=null){if(typeof t=="string")await r.resolveEntityAsync(t,i)||o.push(this.createUnresolvedReferenceError(e,n,t));else if(Array.isArray(t))for(let p=0;p<t.length;p++){let a=t[p];typeof a=="string"&&(await r.resolveEntityAsync(a,i)||o.push(this.createUnresolvedReferenceError(e,`${n}[${p}]`,a)))}}}createUnresolvedReferenceError(e,n,t){let i=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
9
|
+
Example: If the parent property is 'hasCharacter' with range 'Character', all embedded objects in that property will be typed as 'Character' automatically.`,c.expectedValue="No explicit type (inferred from parent property's range)",t.push(c)}if(typeof n=="object"&&n!==null)if(Array.isArray(n))for(let a=0;a<n.length;a++){let s=n[a];typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.checkForEmbeddedTypeViolations(`${e}.${p}[${a}]`,s,t,i+1)}else this.checkForEmbeddedTypeViolations(`${e}.${p}`,n,t,i+1)}}};var E=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let i=await o.getAllDocumentsAsync();for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n)if(!await o.getHighestCompatibleVersionAsync(r,p)){let s=await this.determineImportErrorAsync(o,r,p,i),c=new h;c.ruleType=this.ruleName,c.severity="Error",c.message=s.message,c.suggestion=s.suggestion,c.entityName=`Import: ${r}/${p.packageName}`,c.actualValue=p.toString(),c.expectedValue=s.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,o,t,i){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=i.filter(m=>m.metadata.namespace_?.publisher===o).map(m=>m.metadata.namespace_.package_).filter((m,u,f)=>f.indexOf(m)===u),c=this.findSimilarPackages(t.packageName,s),l=`Import '${o}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${o}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:l,suggestion:y,expectedValue:"Existing package"}}let p=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),a=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${p}. Required: ${a}`,expectedValue:a}}getAcceptableVersionRange(e){switch(e.versionOperator){case 0:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case 1:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case 2:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case 3:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(n=>n.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(n.toLowerCase()));if(t.length>0)return t.sort((n,p)=>n.length-p.length);let i=o.map(n=>({package:n,distance:this.levenshteinDistance(e.toLowerCase(),n.toLowerCase())})).sort((n,p)=>n.distance-p.distance),r=Math.max(3,Math.floor(e.length*.4));return i.filter(n=>n.distance<=r).map(n=>n.package)}levenshteinDistance(e,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,i=o.length,r=Array(t+1).fill(null).map(()=>Array(i+1).fill(0));for(let n=0;n<=t;n++)r[n][0]=n;for(let n=0;n<=i;n++)r[0][n]=n;for(let n=1;n<=t;n++)for(let p=1;p<=i;p++){let a=e[n-1]===o[p-1]?0:1;r[n][p]=Math.min(Math.min(r[n-1][p]+1,r[n][p-1]+1),r[n-1][p-1]+a)}return r[t][i]}};var Y=class d{constructor(e,o,t,i){this.publisher=e;this.package_=o;this.name=t;this.version=i}publisher;package_;name;version;static parse(e){if(!e||e.trim().length===0)throw new Error("Kanonak URI string cannot be null or empty");let o=e.split("/");if(o.length!==3)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let[t,i,r]=o;if(!t||!i||!r)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let n=i.indexOf("@");if(n===-1)return new d(t,i,r,void 0);let p=i.substring(0,n),a=i.substring(n+1);if(!p||!a)throw new Error(`Invalid Kanonak URI: ${e}. Expected format: publisher/package[@version]/name`);let s=a.split(".").map(Number),c=oe(s[0]||0,s[1]||0,s[2]||0);return new d(t,p,r,c)}toString(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}/${this.name}`:`${this.publisher}/${this.package_}/${this.name}`}};function oe(d,e,o){return{major:d,minor:e,patch:o,toString:()=>`${d}.${e}.${o}`,equals:t=>!t||typeof t!="object"?!1:t.major===d&&t.minor===e&&t.patch===o,getHashCode:()=>d<<20|e<<10|o,compareTo:t=>d!==t.major?d-t.major:e!==t.minor?e-t.minor:o-t.patch}}function k(d){if(Array.isArray(d))return d.map(o=>o?.toString()??"").filter(o=>o.length>0);let e=d?.toString();return e?[e]:[]}var V=class{cache=new Map;repository;logger;constructor(e,o){this.repository=e,this.logger=o}async resolveEntityAsync(e,o){let t=o.metadata?.namespace_?.toString()??"unknown",i=this.cache.get(t);if(i){let n=i.get(e);if(n)return n}let r=await this.buildEntityIndexAsyncInternal(o,new Set,"");return this.cache.set(t,r),r.get(e)??null}async resolveAllEntitiesAsync(e,o){let t=await this.buildAllEntitiesIndexAsync(o,new Set,"");if(e.includes(".")){let i=e.split("."),r=i[0],n=i[1],p=await this.findDocumentForAlias(o,r);return p?await this.resolveAllEntitiesAsync(n,p):[]}return t.filter(i=>i.entityName===e)}async buildAllEntitiesIndexAsync(e,o,t){let i=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`;for(let[p,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let s=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.push({entityName:p,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,p,s),entity:a,definedInNamespace:r,isImported:t.length>0,importPath:n})}if(this.logger?.debug?.(`Collected ${i.length} entities from ${r}`),e.metadata?.imports){let p=Object.values(e.metadata.imports).reduce((a,s)=>a+s.length,0);this.logger?.debug?.(`Processing ${p} import(s) for ${r}`);for(let[a,s]of Object.entries(e.metadata.imports))for(let c of s)try{this.logger?.debug?.(`Resolving import: ${a}/${c.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(a,c);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let y=await this.buildAllEntitiesIndexAsync(l,o,n);i.push(...y),this.logger?.debug?.(`Added ${y.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${a}/${c.packageName}`)}catch(l){let y=l;throw this.logger?.error?.(`Failed to process import ${a}/${c.packageName} for namespace ${r}. Error: ${y.message}`,y),new Error(`Failed to process import ${a}/${c.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return i}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,o,t){let i=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),o.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),i;o.add(r);let n=t.length===0?r:`${t} \u2192 ${r}`,p=0;for(let[a,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)&&!i.has(a)){let c=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};i.set(a,{entityName:a,uri:new Y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,a,c),entity:s,definedInNamespace:r,isImported:t.length>0,importPath:n}),p++}if(this.logger?.debug?.(`Indexed ${p} entities from ${r}`),e.metadata?.imports){let a=Object.values(e.metadata.imports).reduce((s,c)=>s+c.length,0);this.logger?.debug?.(`Processing ${a} import(s) for ${r}`);for(let[s,c]of Object.entries(e.metadata.imports))for(let l of c)try{this.logger?.debug?.(`Resolving import: ${s}/${l.packageName}`);let y=await this.repository.getHighestCompatibleVersionAsync(s,l);if(y){this.logger?.debug?.(`Successfully loaded import: ${y.metadata?.namespace_?.toString()}`);let m=await this.buildEntityIndexAsyncInternal(y,o,n),u=0;for(let[f,g]of m.entries())if(i.has(f)||(i.set(f,g),u++),l.alias&&!f.includes(".")){let R=`${l.alias}.${f}`;i.has(R)||(i.set(R,g),u++)}this.logger?.debug?.(`Merged ${u} entities from import ${y.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${s}/${l.packageName}`)}catch(y){let m=y;throw this.logger?.error?.(`Failed to process import ${s}/${l.packageName} for namespace ${r}. Error: ${m.message}`,m),new Error(`Failed to process import ${s}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:y})}}return i}async findDocumentForAlias(e,o){if(!e.metadata?.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i){if(r.alias===o)return await this.repository.getHighestCompatibleVersionAsync(t,r);if(!r.alias&&r.packageName===o)return await this.repository.getHighestCompatibleVersionAsync(t,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubclassOfRecursiveAsync(e,o,t,i)}async isSubclassOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subClassOf;if(n){let p=k(n);for(let a of p)if(a===o||await this.isSubclassOfRecursiveAsync(a,o,t,i))return!0}return!1}async isSubpropertyOfAsync(e,o,t){if(e===o)return!0;let i=new Set;return await this.isSubpropertyOfRecursiveAsync(e,o,t,i)}async isSubpropertyOfRecursiveAsync(e,o,t,i){if(i.has(e))return!1;i.add(e);let r=await this.resolveEntityAsync(e,t);if(!r?.entity)return!1;let n=r.entity.subPropertyOf;if(n){let p=k(n);for(let a of p)if(a===o||await this.isSubpropertyOfRecursiveAsync(a,o,t,i))return!0}return!1}};var j=class{ruleName="UnresolvedReference";async validateAsync(e,o){let t=[],i=new V(o),r=await i.buildEntityIndexAsync(e),n=new Set;for(let[p,a]of r.entries()){let s=a.entity.type;if(s){let c=s.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&n.add(p)}}for(let[p,a]of Object.entries(e.body)){if(!a||typeof a!="object"||Array.isArray(a))continue;let s=a,c=this.getPropertyValue(s,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[l,y]of Object.entries(s))l==="type"||l==="label"||l==="comment"||!(n.has(l)||Array.from(n).some(u=>u.endsWith(`.${l}`)))||await this.validateReferenceValue(p,l,y,e,i,t)}return t}async validateReferenceValue(e,o,t,i,r,n){if(t!=null){if(typeof t=="string")await r.resolveEntityAsync(t,i)||n.push(this.createUnresolvedReferenceError(e,o,t));else if(Array.isArray(t))for(let p=0;p<t.length;p++){let a=t[p];typeof a=="string"&&(await r.resolveEntityAsync(a,i)||n.push(this.createUnresolvedReferenceError(e,`${o}[${p}]`,a)))}}}createUnresolvedReferenceError(e,o,t){let i=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
10
10
|
|
|
11
11
|
Possible solutions:
|
|
12
12
|
\u2022 Add import if the entity is defined in another namespace:
|
|
13
13
|
kanonak namespace add-import <publisher>/<package>@<version>
|
|
14
14
|
\u2022 Check for typos in the reference name '${t}'
|
|
15
15
|
\u2022 Define '${t}' in the current namespace or an appropriate namespace
|
|
16
|
-
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,r=new g;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,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,n){let t=e[n];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,n){let t=[],i=new Map,r=[];if(e.metadata?.imports)for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await n.getHighestCompatibleVersionAsync(o,a);if(s){r.push({doc:s,import:a,publisher:o});let c=await this.getTransitiveImportsAsync(n,s,new Set);r.push(...c.map(l=>({doc:l,import:null,publisher:o})))}}for(let{doc:o,import:p}of r){let a=o.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(o.body))i.has(s)||i.set(s,[]),i.get(s).push({namespace:a,import:p})}for(let[o,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p;this.checkAmbiguousReference(a,"type",i,o,t),this.checkAmbiguousReference(a,"subClassOf",i,o,t),this.checkAmbiguousReference(a,"subPropertyOf",i,o,t),this.checkAmbiguousReference(a,"domain",i,o,t),this.checkAmbiguousReference(a,"range",i,o,t)}return t}checkAmbiguousReference(e,n,t,i,r){let o=e[n];if(!o)return;let p=v(o);for(let a of p){if(a.includes("."))continue;let s=t.get(a);if(s&&s.length>1){let c=s.map(u=>u.namespace).join(", "),l=[];for(let{namespace:u,import:f}of s)if(f?.alias)l.push(`${f.alias}.${a}`);else{let d=u.split("/"),k=d[d.length-1]?.split("@")[0]??"alias";l.push(`${k}.${a}`)}let m=l.length>0?`Use one of: ${l.join(", ")}`:"Consider adding namespace aliases to your imports",y=new g;y.ruleType=this.ruleName,y.severity="Warning",y.entityName=i,y.propertyName=n,y.actualValue=a,y.message=`Type '${a}' is ambiguous. It's defined in: ${c}`,y.suggestion=m,r.push(y)}}}async getTransitiveImportsAsync(e,n,t){let i=[],r=n.metadata?.namespace_?.toString()??"";if(t.has(r))return i;if(t.add(r),n.metadata?.imports)for(let[o,p]of Object.entries(n.metadata.imports))for(let a of p){let s=await e.getHighestCompatibleVersionAsync(o,a);if(s){i.push(s);let c=await this.getTransitiveImportsAsync(e,s,t);i.push(...c)}}return i}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,n){let t=[],i=new Map,r=new Set;await this.buildClassHierarchy(e,n,i,r);for(let[o,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type,c=a.subClassOf;if(s?.toString()==="Class"&&c){let l=o,m=this.detectCycle(l,i);if(m){let y=m.join(" \u2192 "),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${y}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=l,u.propertyName="subClassOf",u.actualValue=y,t.push(u);break}}}return t}async buildClassHierarchy(e,n,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[o,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type,c=a.subClassOf;if(s?.toString()==="Class"&&c){let l=v(c);l.length>0&&t.set(o,l)}}if(e.metadata?.imports)for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await n.getHighestCompatibleVersionAsync(o,a);s&&await this.buildClassHierarchy(s,n,t,i)}}}detectCycle(e,n){let t=[],i=new Set;return this.detectCycleRecursive(e,n,t,i)}detectCycleRecursive(e,n,t,i){if(t.includes(e)){let o=t.indexOf(e),p=t.slice(o);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let r=n.get(e);if(r)for(let o of r){let p=this.detectCycleRecursive(o,n,t,i);if(p)return p}return t.pop(),null}};var C=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,n){let t=[],i=new Map,r=new Set;await this.buildPropertyHierarchy(e,n,i,r);for(let[o,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)&&p.subPropertyOf){let c=o,l=this.detectCycle(c,i);if(l){let m=l.join(" \u2192 "),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Circular property hierarchy detected: ${m}`,y.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",y.entityName=c,y.propertyName="subPropertyOf",y.actualValue=m,t.push(y);break}}return t}async buildPropertyHierarchy(e,n,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[o,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type;if(s){let c=s.toString();if(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"){let l=a.subPropertyOf;if(l){let m=v(l);m.length>0&&t.set(o,m)}}}}if(e.metadata?.imports)for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await n.getHighestCompatibleVersionAsync(o,a);s&&await this.buildPropertyHierarchy(s,n,t,i)}}}detectCycle(e,n){let t=[],i=new Set;return this.detectCycleRecursive(e,n,t,i)}detectCycleRecursive(e,n,t,i){if(t.includes(e)){let o=t.indexOf(e),p=t.slice(o);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let r=n.get(e);if(r)for(let o of r){let p=this.detectCycleRecursive(o,n,t,i);if(p)return p}return t.pop(),null}};var K=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,n){let t=[];for(let[i,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let o=r,p=o.type?.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p?.endsWith(".DatatypeProperty")||p?.endsWith(".ObjectProperty")){let a="range"in o,s=o.range?.toString().trim();if(!a||!s){let c=new g;c.ruleType=this.ruleName,c.severity="Error",c.entityName=i,c.propertyName="range",c.message=`Property '${i}' must have a 'range' defined.`,c.suggestion=p==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",c.expectedValue=p==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(c)}}}return t}};var x=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}async validateAsync(e,n){let t=[],i=new Set;for(let[r,o]of Object.entries(e.body))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let a=o.type?.toString();(a==="Class"||a&&a.endsWith(".Class"))&&i.add(r)}for(let[r,o]of Object.entries(e.body))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let a=v(o.subClassOf);for(let s=0;s<a.length;s++){let c=a[s];if(this.builtInClasses.has(c)||i.has(c))continue;if(!await this.isClassAvailableInImports(e,n,c)){let m=a.length>1?`[${s}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Class '${c}' referenced in subClassOf${m} is not defined or imported`,y.suggestion=`Define '${c}' as a Class, or import a namespace that contains it`,y.entityName=r,y.propertyName="subClassOf",y.actualValue=c,y.expectedValue="Defined or imported class",t.push(y)}}}return t}async isClassAvailableInImports(e,n,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let o=t.split(".",2);i=o[0],r=o[1]}for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await n.getHighestCompatibleVersionAsync(o,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(u==="Class"||u&&u.endsWith(".Class"))return!0}let m=new Set;if(await this.isClassAvailableInImportsRecursive(s,n,c,m))return!0}}return!1}async isClassAvailableInImportsRecursive(e,n,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await n.getHighestCompatibleVersionAsync(o,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let m=c.type?.toString();if(m==="Class"||m&&m.endsWith(".Class"))return!0}if(await this.isClassAvailableInImportsRecursive(s,n,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,n){let t=[],i=new Set;for(let[r,o]of Object.entries(e.body))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let a=o.type?.toString();(a==="DatatypeProperty"||a==="ObjectProperty"||a==="AnnotationProperty")&&i.add(r)}for(let[r,o]of Object.entries(e.body))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let a=v(o.subPropertyOf);for(let s=0;s<a.length;s++){let c=a[s];if(this.builtInProperties.has(c)||i.has(c))continue;if(!await this.isPropertyAvailableInImports(e,n,c)){let m=a.length>1?`[${s}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Property '${c}' referenced in subPropertyOf${m} is not defined or imported`,y.suggestion=`Define '${c}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,y.entityName=r,y.propertyName="subPropertyOf",y.actualValue=c,y.expectedValue="Defined or imported property",t.push(y)}}}return t}async isPropertyAvailableInImports(e,n,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let o=t.split(".",2);i=o[0],r=o[1]}for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await n.getHighestCompatibleVersionAsync(o,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let m=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,n,c,m))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,n,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[o,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await n.getHighestCompatibleVersionAsync(o,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let m=c.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(s,n,t,i))return!0}}return!1}};var _=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,n){let t=[],i=e.metadata.namespace_?.toString();if(!i)return t;let r=new Map,o=new Set;await this.buildImportGraph(e,n,r,o);let p=this.detectCycle(i,r);if(p){let a=p.join(" \u2192 "),s=new g;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${a}`,s.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=a,t.push(s)}return t}async buildImportGraph(e,n,t,i){let r=e.metadata.namespace_?.toString()??"";if(!(!r||i.has(r))&&(i.add(r),e.metadata.imports)){let o=[];for(let[p,a]of Object.entries(e.metadata.imports))for(let s of a){let c=`${p}/${s.packageName}@${s.version}`;o.push(c);let l=await n.getHighestCompatibleVersionAsync(p,s);l&&await this.buildImportGraph(l,n,t,i)}o.length>0&&t.set(r,o)}}detectCycle(e,n){let t=[],i=new Set;return this.detectCycleRecursive(e,n,t,i)}detectCycleRecursive(e,n,t,i){let r=t.indexOf(e);if(r>=0){let p=t.slice(r);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let o=n.get(e);if(o)for(let p of o){let a=this.detectCycleRecursive(p,n,t,i);if(a)return a}return t.pop(),null}};var M=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,n){let t=[],i=new Set;for(let[r,o]of Object.entries(e.body))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let a=o.type?.toString();this.isPropertyType(a)&&i.add(r)}for(let[r,o]of Object.entries(e.body))if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let p=o,a=p.type?.toString();if(this.isPropertyType(a)||this.isClassType(a))continue;for(let[s,c]of Object.entries(p)){if(!s||this.metadataKeys.has(s))continue;let l=s,m=null;if(s.includes(".")){let u=s.lastIndexOf(".");m=s.substring(0,u),l=s.substring(u+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,n,l,m)){let u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${s}' is not defined or imported`,u.suggestion=m?`The property '${l}' is not found in the imported namespace with alias '${m}'.
|
|
16
|
+
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,r=new h;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t,r.message=`Reference to '${t}' could not be resolved`,r.suggestion=i,r.expectedValue="A valid entity reference that exists in the current document or imported namespaces",r}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,o){let t=[],i=new Map,r=[];if(e.metadata?.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){r.push({doc:s,import:a,publisher:n});let c=await this.getTransitiveImportsAsync(o,s,new Set);r.push(...c.map(l=>({doc:l,import:null,publisher:n})))}}for(let{doc:n,import:p}of r){let a=n.metadata?.namespace_?.toString()??"unknown";for(let s of Object.keys(n.body))i.has(s)||i.set(s,[]),i.get(s).push({namespace:a,import:p})}for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p;this.checkAmbiguousReference(a,"type",i,n,t),this.checkAmbiguousReference(a,"subClassOf",i,n,t),this.checkAmbiguousReference(a,"subPropertyOf",i,n,t),this.checkAmbiguousReference(a,"domain",i,n,t),this.checkAmbiguousReference(a,"range",i,n,t)}return t}checkAmbiguousReference(e,o,t,i,r){let n=e[o];if(!n)return;let p=k(n);for(let a of p){if(a.includes("."))continue;let s=t.get(a);if(s&&s.length>1){let c=s.map(u=>u.namespace).join(", "),l=[];for(let{namespace:u,import:f}of s)if(f?.alias)l.push(`${f.alias}.${a}`);else{let g=u.split("/"),v=g[g.length-1]?.split("@")[0]??"alias";l.push(`${v}.${a}`)}let y=l.length>0?`Use one of: ${l.join(", ")}`:"Consider adding namespace aliases to your imports",m=new h;m.ruleType=this.ruleName,m.severity="Warning",m.entityName=i,m.propertyName=o,m.actualValue=a,m.message=`Type '${a}' is ambiguous. It's defined in: ${c}`,m.suggestion=y,r.push(m)}}}async getTransitiveImportsAsync(e,o,t){let i=[],r=o.metadata?.namespace_?.toString()??"";if(t.has(r))return i;if(t.add(r),o.metadata?.imports)for(let[n,p]of Object.entries(o.metadata.imports))for(let a of p){let s=await e.getHighestCompatibleVersionAsync(n,a);if(s){i.push(s);let c=await this.getTransitiveImportsAsync(e,s,t);i.push(...c)}}return i}};var N=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildClassHierarchy(e,o,i,r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type,c=a.subClassOf;if(s?.toString()==="Class"&&c){let l=n,y=this.detectCycle(l,i);if(y){let m=y.join(" \u2192 "),u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${m}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=l,u.propertyName="subClassOf",u.actualValue=m,t.push(u);break}}}return t}async buildClassHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type,c=a.subClassOf;if(s?.toString()==="Class"&&c){let l=k(c);l.length>0&&t.set(n,l)}}if(e.metadata?.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);s&&await this.buildClassHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),p=t.slice(n);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let p=this.detectCycleRecursive(n,o,t,i);if(p)return p}return t.pop(),null}};var K=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o){let t=[],i=new Map,r=new Set;await this.buildPropertyHierarchy(e,o,i,r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)&&p.subPropertyOf){let c=n,l=this.detectCycle(c,i);if(l){let y=l.join(" \u2192 "),m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${y}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=c,m.propertyName="subPropertyOf",m.actualValue=y,t.push(m);break}}return t}async buildPropertyHierarchy(e,o,t,i){let r=e.metadata?.namespace_?.toString()??"";if(!(r&&i.has(r))){r&&i.add(r);for(let[n,p]of Object.entries(e.body))if(p&&typeof p=="object"&&!Array.isArray(p)){let a=p,s=a.type;if(s){let c=s.toString();if(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"){let l=a.subPropertyOf;if(l){let y=k(l);y.length>0&&t.set(n,y)}}}}if(e.metadata?.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);s&&await this.buildPropertyHierarchy(s,o,t,i)}}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){if(t.includes(e)){let n=t.indexOf(e),p=t.slice(n);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let r=o.get(e);if(r)for(let n of r){let p=this.detectCycleRecursive(n,o,t,i);if(p)return p}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,o){let t=[];for(let[i,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let n=r,p=n.type?.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p?.endsWith(".DatatypeProperty")||p?.endsWith(".ObjectProperty")){let a="range"in n,s=n.range?.toString().trim();if(!a||!s){let c=new h;c.ruleType=this.ruleName,c.severity="Error",c.entityName=i,c.propertyName="range",c.message=`Property '${i}' must have a 'range' defined.`,c.suggestion=p==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",c.expectedValue=p==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(c)}}}return t}};var x=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();(a==="Class"||a&&a.endsWith(".Class"))&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=k(n.subClassOf);for(let s=0;s<a.length;s++){let c=a[s];if(this.builtInClasses.has(c)||i.has(c))continue;if(!await this.isClassAvailableInImports(e,o,c)){let y=a.length>1?`[${s}]`:"",m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Class '${c}' referenced in subClassOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a Class, or import a namespace that contains it`,m.entityName=r,m.propertyName="subClassOf",m.actualValue=c,m.expectedValue="Defined or imported class",t.push(m)}}}return t}async isClassAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(u==="Class"||u&&u.endsWith(".Class"))return!0}let y=new Set;if(await this.isClassAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isClassAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="Class"||y&&y.endsWith(".Class"))return!0}if(await this.isClassAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var T=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();(a==="DatatypeProperty"||a==="ObjectProperty"||a==="AnnotationProperty")&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=k(n.subPropertyOf);for(let s=0;s<a.length;s++){let c=a[s];if(this.builtInProperties.has(c)||i.has(c))continue;if(!await this.isPropertyAvailableInImports(e,o,c)){let y=a.length>1?`[${s}]`:"",m=new h;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${c}' referenced in subPropertyOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,m.entityName=r,m.propertyName="subPropertyOf",m.actualValue=c,m.expectedValue="Defined or imported property",t.push(m)}}}return t}async isPropertyAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let y=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var _=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],i=e.metadata.namespace_?.toString();if(!i)return t;let r=new Map,n=new Set;await this.buildImportGraph(e,o,r,n);let p=this.detectCycle(i,r);if(p){let a=p.join(" \u2192 "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${a}`,s.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=a,t.push(s)}return t}async buildImportGraph(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!(!r||i.has(r))&&(i.add(r),e.metadata.imports)){let n=[];for(let[p,a]of Object.entries(e.metadata.imports))for(let s of a){let c=`${p}/${s.packageName}@${s.version}`;n.push(c);let l=await o.getHighestCompatibleVersionAsync(p,s);l&&await this.buildImportGraph(l,o,t,i)}n.length>0&&t.set(r,n)}}detectCycle(e,o){let t=[],i=new Set;return this.detectCycleRecursive(e,o,t,i)}detectCycleRecursive(e,o,t,i){let r=t.indexOf(e);if(r>=0){let p=t.slice(r);return p.push(e),p}if(i.has(e))return null;t.push(e),i.add(e);let n=o.get(e);if(n)for(let p of n){let a=this.detectCycleRecursive(p,o,t,i);if(a)return a}return t.pop(),null}};var M=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();this.isPropertyType(a)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=p.type?.toString();if(this.isPropertyType(a)||this.isClassType(a))continue;for(let[s,c]of Object.entries(p)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let u=s.lastIndexOf(".");y=s.substring(0,u),l=s.substring(u+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${s}' is not defined or imported`,u.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
|
|
17
17
|
1. Verify the namespace is imported with the correct alias
|
|
18
18
|
2. Check if the property name is spelled correctly
|
|
19
19
|
3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
|
|
20
20
|
1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
21
21
|
2. Import the namespace that contains '${s}', OR
|
|
22
|
-
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,u.entityName=r,u.propertyName=s,u.actualValue=c?.toString(),u.expectedValue="A defined or imported property",t.push(u)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,
|
|
22
|
+
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,u.entityName=r,u.propertyName=s,u.actualValue=c?.toString(),u.expectedValue="A defined or imported property",t.push(u)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){if(i!==null&&p.alias!==i)continue;let a=await o.getHighestCompatibleVersionAsync(r,p);if(a){let s=a.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(a,o,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();this.isPropertyType(a)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=p.type?.toString();if(!this.isPropertyType(a)&&!this.isClassType(a))continue;for(let[s,c]of Object.entries(p)){if(!s||this.metadataKeys.has(s))continue;let l=s,y=null;if(s.includes(".")){let u=s.lastIndexOf(".");y=s.substring(0,u),l=s.substring(u+1)}if(i.has(l))continue;if(!await this.isPropertyAvailableInImports(e,o,l,y)){let u=this.isClassType(a)?"class":"property",f=new h;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${s}' used on ${u} '${r}' is not defined or imported`,f.suggestion=y?`The property '${l}' is not found in the imported namespace with alias '${y}'.
|
|
23
23
|
1. Verify the namespace is imported with the correct alias
|
|
24
24
|
2. Check if the property name is spelled correctly
|
|
25
25
|
3. Ensure the imported namespace version contains this property`:`The property '${s}' is not defined in this namespace or any imported namespace.
|
|
26
26
|
1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
27
27
|
2. Import the namespace that contains '${s}', OR
|
|
28
|
-
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=r,f.propertyName=s,f.actualValue=c?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,
|
|
29
|
-
`),l=e.split(".")[0],
|
|
28
|
+
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=r,f.propertyName=s,f.actualValue=c?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,o,t,i){if(!e.metadata.imports)return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){if(i!==null&&p.alias!==i)continue;let a=await o.getHighestCompatibleVersionAsync(r,p);if(a){let s=a.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(a,o,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}};var L=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"XsdImport"}async validateAsync(e,o){let t=[],i=new Set,r=[];for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=!1,c=a.type;if(Array.isArray(c)){for(let l of c)if(l?.toString()==="DatatypeProperty"){s=!0;break}}else c?.toString()==="DatatypeProperty"&&(s=!0);if(s){r.push(n);let l=this.getPropertyValue(a,"range");l&&this.xsdTypes.has(l)&&i.add(l)}}if(i.size>0&&!await this.checkXsdImportAsync(e.metadata,o)){let p=Array.from(i).sort().join(", "),a=r.sort().join(", "),s=new h;s.ruleType=this.ruleName,s.severity="Error",s.message=`XSD namespace not imported but XSD types are used: ${p}`,s.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${a}`,s.entityName="imports",t.push(s)}return t}async checkXsdImportAsync(e,o,t=new Set){if(!e?.imports)return!1;let i=e.namespace_?.toString()??"";if(i&&t.has(i))return!1;i&&t.add(i);for(let[,r]of Object.entries(e.imports))for(let n of r)if(n.packageName==="xsd"||n.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[r,n]of Object.entries(e.imports))for(let p of n){let a=await o.getHighestCompatibleVersionAsync(r,p);if(a?.metadata&&await this.checkXsdImportAsync(a.metadata,o,t))return!0}return!1}getPropertyValue(e,o){return e[o]?.toString()}};var H=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,o){let t=[],i=await this.buildEntitySourceMapAsync(e,o),r=await this.buildDatatypePropertyNamesAsync(e,o);for(let[n,p]of Object.entries(e.body))typeof p=="object"&&p!==null&&!Array.isArray(p)&&this.validateEntityReferences(n,p,i,r,e,t);return t}async buildEntitySourceMapAsync(e,o){let t=new Map,i=new Set;for(let r of Object.keys(e.body)){let n=e.metadata.namespace_?.toString()??"";t.has(r)||t.set(r,[]),t.get(r).push(`(local:${n})`)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){let a=await o.getHighestCompatibleVersionAsync(r,p);a&&await this.collectEntitiesRecursivelyAsync(a,t,i,o)}return t}async collectEntitiesRecursivelyAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let n of Object.keys(e.body)){o.has(n)||o.set(n,[]);let p=o.get(n);p.includes(r)||p.push(r)}if(e.metadata.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await i.getHighestCompatibleVersionAsync(n,a);s&&await this.collectEntitiesRecursivelyAsync(s,o,t,i)}}}async buildDatatypePropertyNamesAsync(e,o){let t=new Set,i=new Set;if(await this.collectDatatypePropertiesAsync(e,t,i,o),e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let p of n){let a=await o.getHighestCompatibleVersionAsync(r,p);a&&await this.collectDatatypePropertiesAsync(a,t,i,o)}return t}async collectDatatypePropertiesAsync(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let[n,p]of Object.entries(e.body)){if(typeof p!="object"||p===null||Array.isArray(p))continue;let a=p.type;if(typeof a!="string")continue;(a.includes(".")?a.substring(a.lastIndexOf(".")+1):a)==="DatatypeProperty"&&o.add(n)}if(e.metadata.imports)for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await i.getHighestCompatibleVersionAsync(n,a);s&&await this.collectDatatypePropertiesAsync(s,o,t,i)}}}validateEntityReferences(e,o,t,i,r,n){for(let[p,a]of Object.entries(o)){let s=p;if(s&&!s.includes(".")){let c=t.get(s);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,r,!0,s))}}this.validatePropertyValue(e,s,a,t,i,r,n)}}validatePropertyValue(e,o,t,i,r,n,p){if(t==null)return;let a=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o,s=!!a&&r.has(a);if(typeof t=="string"&&!t.includes(".")&&!s){let c=i.get(t);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&p.push(this.createAmbiguityError(e,o,`Reference '${t}'`,y,n,!1,t))}}else if(Array.isArray(t))for(let c=0;c<t.length;c++){let l=`${e}.${o}[${c}]`;this.validatePropertyValue(l,o,t[c],i,r,n,p)}else if(typeof t=="object"&&!Array.isArray(t)){let c=o?`${e}.${o}`:e;this.validateEntityReferences(c,t,i,r,n,p)}}createAmbiguityError(e,o,t,i,r,n,p){let a=[];for(let f of i){let g=this.findAliasForNamespace(r,f);if(g){let R=o?.split(".").pop()??o;a.push(`${g}.${R}`)}}let s=a.length>0?`Use one of: ${a.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${o}')`,c=i.map(f=>` \u2022 ${f}`).join(`
|
|
29
|
+
`),l=e.split(".")[0],y=e.includes(".")?e:o,m=new h;m.ruleType=this.ruleName,m.severity="Error",m.entityName=l,y&&(m.propertyName=y);let u=p??o;return u&&(m.actualValue=u),m.message=`${t} is ambiguous - defined in multiple imported namespaces`,m.suggestion=`${s}
|
|
30
30
|
|
|
31
31
|
Defined in:
|
|
32
|
-
${c}`,
|
|
32
|
+
${c}`,m.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",m}findAliasForNamespace(e,o){if(!e.metadata.imports)return null;for(let[t,i]of Object.entries(e.metadata.imports))for(let r of i)if(`${t}/${r.packageName}@${r.version}`===o&&r.alias)return r.alias;return null}};var F=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]);primitiveTypes=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","dateTime","date","time","duration","anyURI","anySimpleType","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte","base64Binary","hexBinary","Literal","Resource"]);get ruleName(){return"PropertyRangeReference"}async validateAsync(e,o){let t=[],i=new Set;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let a=n.type?.toString();this.isValidRangeTargetType(a)&&i.add(r)}for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=p.type?.toString();if(a!=="DatatypeProperty"&&a!=="ObjectProperty"&&!a?.endsWith(".DatatypeProperty")&&!a?.endsWith(".ObjectProperty"))continue;let s=p.range;if(!s)continue;let c=[];if(Array.isArray(s))for(let l of s){let y=l?.toString();y&&c.push(y)}else{let l=s?.toString();l&&c.push(l)}if(c.length===0)continue;for(let l of c){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||i.has(l))continue;if(!await this.isTypeAvailableInImports(e,o,l)){let m=a?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",u=new h;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${r}' has range '${l}' which is not defined or imported`,u.suggestion=m==="ObjectProperty"?`For ObjectProperty:
|
|
33
33
|
1. Define '${l}' as a Class in this namespace, OR
|
|
34
34
|
2. Import the namespace that contains '${l}', OR
|
|
35
35
|
3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
|
|
36
36
|
1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
|
|
37
|
-
2. If '${l}' should be a class, change property type to ObjectProperty`,u.entityName=r,u.propertyName="range",u.actualValue=l,u.expectedValue=
|
|
37
|
+
2. If '${l}' should be a class, change property type to ObjectProperty`,u.entityName=r,u.propertyName="range",u.actualValue=l,u.expectedValue=m==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,o,t){if(!e.metadata.imports)return!1;let i=null,r=t;if(t.includes(".")){let n=t.split(".",2);i=n[0],r=n[1]}for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){if(i!==null&&a.alias!==i)continue;let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=i!==null?r:t,l=s.body[c];if(l&&typeof l=="object"&&!Array.isArray(l)){let u=l.type?.toString();if(this.isValidRangeTargetType(u))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(s,o,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,o,t,i){let r=e.metadata.namespace_?.toString()??"";if(r&&i.has(r)||(r&&i.add(r),!e.metadata.imports))return!1;for(let[n,p]of Object.entries(e.metadata.imports))for(let a of p){let s=await o.getHighestCompatibleVersionAsync(n,a);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(s,o,t,i))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var U=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,o){let t=[],i=new Map,r=new V(o);await r.buildEntityIndexAsync(e);for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=!1,c=a.type;if(Array.isArray(c)){for(let l of c)if(l?.toString()==="ObjectProperty"){s=!0;break}}else c?.toString()==="ObjectProperty"&&(s=!0);if(s){let l=a.range,y=[];if(Array.isArray(l))for(let m of l){let u=m?.toString();u&&y.push(u)}else{let m=l?.toString();m&&y.push(m)}for(let m of y)this.xsdTypes.has(m)||(i.has(m)||i.set(m,[]),i.get(m).push(n))}}for(let[n,p]of i)if(!await r.resolveEntityAsync(n,e))for(let s of p){let c=new h;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${n}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${n}' is imported, or define '${n}' in this document`,c.entityName=s,c.propertyName="range",c.actualValue=n,t.push(c)}return t}};var J=class d{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","bool","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.xsd"&&d.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core.rdf"&&e.name==="Literal":!1}isKnownXsdDatatypeName(e){let o=e.includes(".")?e.split(".")[1]:e;return d.KNOWN_XSD_DATATYPES.has(o.toLowerCase())}async isClassTypeAsync(e,o){if(this.isKnownXsdDatatypeName(e))return!1;let t=await this.resourceResolver.resolveEntityAsync(e,o);if(t){let i=t.entity.type;if(i){let r=String(i);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,o){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(o)||e==="Property"&&this.isLiteralType(o))}isEffectiveObjectProperty(e,o){return!!(e==="ObjectProperty"||e==="Property"&&o&&!this.isXsdDatatype(o)&&!this.isLiteralType(o))}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,o){let t=[],i=new V(o),r=new J(i),n=await i.buildEntityIndexAsync(e),p=await this.buildPropertyMetadataAsync(e,o,i,n);for(let[a,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,a,"",p,i,r,e,t);return t}async scanEntityForObjectProperties(e,o,t,i,r,n,p,a){for(let[s,c]of Object.entries(e)){if(this.standardProperties.has(s))continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let m=i.get(l);if(m&&n.isEffectiveObjectProperty(m.propertyType,m.rangeUri)){let f=t?`${t}.${s}`:s;if(typeof c=="string"&&c.trim().length>0){let g=c.trim();if(g.includes(",")){let v=g.split(",").map(A=>A.trim()).filter(A=>A.length>0);a.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
|
|
38
38
|
${s}:
|
|
39
|
-
- ${
|
|
40
|
-
${
|
|
41
|
-
`)}`,entityName:
|
|
42
|
-
1. Use this property only on '${
|
|
39
|
+
- ${v[0]}
|
|
40
|
+
${v.slice(1).map(A=>` - ${A}`).join(`
|
|
41
|
+
`)}`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:`A single reference to ${m.range??"an entity"} OR a YAML list`});continue}let R=await r.resolveEntityAsync(g,p);if(R)m.range&&(await this.validateRangeType(R,m.range,r,p)||a.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${m.range}, but '${g}' may not be a ${m.range}`,suggestion:`Ensure '${g}' is defined with appropriate type`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:m.range}));else{let v=m.range??"entity";a.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${g}' which is not defined or imported`,suggestion:`Define '${g}' or import a namespace that contains it. Expected range: ${v}`,entityName:o,propertyName:s,propertyPath:f,actualValue:g,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let g=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,g,i,r,n,p,a)}else if(Array.isArray(c))for(let g=0;g<c.length;g++){let R=c[g];if(typeof R=="string"&&R.trim().length>0){let v=R.trim(),A=await r.resolveEntityAsync(v,p);if(A){if(m.range&&!await this.validateRangeType(A,m.range,r,p)){let Q=t?`${t}.${s}[${g}]`:`${s}[${g}]`;a.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${m.range}, but '${v}' may not be a ${m.range}`,suggestion:`Ensure '${v}' is defined with appropriate type`,entityName:o,propertyName:`${s}[${g}]`,propertyPath:Q,actualValue:v,expectedValue:m.range})}}else{let re=m.range??"entity",Q=t?`${t}.${s}[${g}]`:`${s}[${g}]`;a.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${v}' which is not defined or imported`,suggestion:`Define '${v}' or import a namespace that contains it. Expected range: ${re}`,entityName:o,propertyName:`${s}[${g}]`,propertyPath:Q,actualValue:v,expectedValue:"Defined or imported entity"})}}else if(typeof R=="object"&&R!==null&&!Array.isArray(R)){let v=t?`${t}.${s}[${g}]`:`${s}[${g}]`;await this.scanEntityForObjectProperties(R,o,v,i,r,n,p,a)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!i.has(s)){let u=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,o,u,i,r,n,p,a)}else if(Array.isArray(c))for(let u=0;u<c.length;u++){let f=c[u];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let g=t?`${t}.${s}[${u}]`:`${s}[${u}]`;await this.scanEntityForObjectProperties(f,o,g,i,r,n,p,a)}}}}async validateRangeType(e,o,t,i){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(o))return!0;let n=e.entity.type;if(n){let p=[];if(Array.isArray(n))for(let a of n){let s=a?.toString();s&&s.trim().length>0&&p.push(s)}else{let a=n?.toString();a&&a.trim().length>0&&p.push(a)}for(let a of p){let s=a.includes(".")?a.split(".")[1]:a;if(s===o||o==="Property"&&(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")||o==="Class"&&s==="Class"||await t.isSubclassOfAsync(a,o,i))return!0}}return!1}async buildPropertyMetadataAsync(e,o,t,i){let r=new Map;for(let[n,p]of i){let a=p.entity.type;if(a){let s=[];if(Array.isArray(a))for(let y of a){let m=y?.toString();m&&m.trim().length>0&&s.push(m)}else{let y=a?.toString();y&&y.trim().length>0&&s.push(y)}let c=!1,l="Property";for(let y of s){let m=y.includes(".")?y.split(".")[1]:y;if(m==="Property"||m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty"){c=!0,l=y;break}}if(c){let y={propertyType:l},m=p.entity.range;if(m){let u=m?.toString();if(u&&u.trim().length>0){y.range=u;let f=await t.resolveEntityAsync(u,e);f&&(y.rangeUri=f.uri)}}r.set(n,y)}}}return r}};var X=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,o){let t=[],i=new Map;for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=this.getPropertyValue(a,"type");(s==="DatatypeProperty"||s?.endsWith(".DatatypeProperty")||s==="ObjectProperty"||s?.endsWith(".ObjectProperty")||s==="AnnotationProperty"||s?.endsWith(".AnnotationProperty"))&&i.set(n,a)}let r=await this.buildCompleteClassHierarchyAsync(e,o);for(let[n,p]of Object.entries(e.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let a=p,s=this.getPropertyValue(a,"type");if(!s||s==="Class"||s.endsWith(".Class")||s.endsWith("Property")||s==="AnnotationProperty")continue;this.validateEntityProperties(a,n,s,i,r,t)}return t}async buildCompleteClassHierarchyAsync(e,o){let t=new Map,i=new Set,r=async(p,a)=>{if(!i.has(a)){i.add(a);for(let[s,c]of Object.entries(p.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let l=c,y=this.getPropertyValue(l,"type");if(y==="Class"||y?.endsWith(".Class")){let m=l.subClassOf;if(m===void 0){for(let f of Object.keys(l))if(f.endsWith(".subClassOf")){m=l[f];break}}let u=k(m);u.length>0&&t.set(s,u)}}if(p.metadata.imports)for(let[s,c]of Object.entries(p.metadata.imports))for(let l of c)try{let y=await o.getHighestCompatibleVersionAsync(s,l);if(y){let m=`${s}/${l.packageName}@${l.version}`;await r(y,m)}}catch{}}},n=e.metadata.namespace_?.toString()??"unknown";return await r(e,n),t}validateEntityProperties(e,o,t,i,r,n){for(let[p,a]of Object.entries(e)){if(this.standardProperties.has(p))continue;let s=p,c=p.lastIndexOf(".");c>0&&c<p.length-1&&(s=p.substring(c+1));let l=i.get(s);if(!l)continue;let y=this.getPropertyValue(l,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,r)){let m=o.split(".")[0];n.push({ruleType:this.ruleName,severity:"Error",entityName:m,propertyName:o,actualValue:p,message:`Property '${p}' has domain '${y}' but is used on '${t}' at '${o}'`,suggestion:`Either:
|
|
42
|
+
1. Use this property only on '${y}' instances
|
|
43
43
|
2. Change the property domain to include '${t}'
|
|
44
|
-
3. Create a different property for '${t}'`,expectedValue:`Property used on ${
|
|
44
|
+
3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let m=a,u=this.getPropertyValue(m,"type");if(u){let f=`${o}.${p}`;this.validateEntityProperties(m,f,u,i,r,n)}else{let f=this.getPropertyValue(l,"range");if(f){let g=`${o}.${p}`;this.validateEntityProperties(m,g,f,i,r,n)}}}else if(Array.isArray(a))for(let m=0;m<a.length;m++){let u=a[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,g=this.getPropertyValue(f,"type");if(g){let R=`${o}.${p}[${m}]`;this.validateEntityProperties(f,R,g,i,r,n)}else{let R=this.getPropertyValue(l,"range");if(R){let v=`${o}.${p}[${m}]`;this.validateEntityProperties(f,v,R,i,r,n)}}}}}}}isTypeCompatibleWithDomain(e,o,t){if(e===o)return!0;let i=new Set,r=[e];for(;r.length>0;){let n=r.shift();if(i.has(n))continue;i.add(n);let p=t.get(n);if(p)for(let a of p){if(a===o)return!0;r.push(a)}}return!1}getPropertyValue(e,o){if(o in e){let t=e[o];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${o}`)){let i=e[t];return this.extractFirstValue(i)}}extractFirstValue(e){if(Array.isArray(e)){let o=[];for(let t of e)o.push(t?.toString()??"");return o.length>0?o[0]:void 0}return e?.toString()}};var B=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,o){let t=[],i=new Map;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let p=n,a=this.getPropertyValue(p,"type");(a==="DatatypeProperty"||a==="ObjectProperty")&&i.set(r,p)}for(let[r,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n))continue;let p=n,a=this.getPropertyValue(p,"type");if(!(!a||a==="Class"||a.endsWith("Property")||a==="AnnotationProperty"))for(let[s,c]of Object.entries(p)){if(s==="type"||s==="label"||s==="comment")continue;let l=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(l=s.substring(y+1));let m=i.get(l);if(!m)continue;let u=this.getPropertyValue(m,"type"),f=this.getPropertyValue(m,"range");if(u==="DatatypeProperty"){if(typeof c=="object"&&c!==null&&!Array.isArray(c)||Array.isArray(c))t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' is a DatatypeProperty with range '${f}' but instance '${r}' has a complex object value`,suggestion:`Either:
|
|
45
45
|
1. Create a class for this data and change '${s}' to an ObjectProperty
|
|
46
46
|
2. Store as a JSON string to keep it as DatatypeProperty
|
|
47
|
-
3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let
|
|
47
|
+
3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let g={ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`Property '${s}' expects type '${f}' but instance '${r}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(g.expectedValue=f),t.push(g)}}else if(u==="ObjectProperty")if(Array.isArray(c))for(let g=0;g<c.length;g++){let R=c[g];typeof R!="string"&&(typeof R!="object"||R===null||Array.isArray(R))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:`${s}[${g}]`,message:`ObjectProperty '${s}' array item ${g} in instance '${r}' has invalid type '${this.getValueTypeName(R)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:r,propertyName:s,message:`ObjectProperty '${s}' in instance '${r}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,o){switch(e?.toLowerCase()){case"string":return typeof o=="string";case"integer":case"int":return typeof o=="number"&&Number.isInteger(o);case"decimal":return typeof o=="number";case"boolean":return typeof o=="boolean";case"float":case"double":return typeof o=="number";default:return!0}}getValueTypeName(e){return typeof e=="string"?"string":typeof e=="number"?Number.isInteger(e)?"integer":"decimal":typeof e=="boolean"?"boolean":Array.isArray(e)?"array":typeof e=="object"&&e!==null?"object":e===null?"null":e===void 0?"undefined":typeof e}getPropertyValue(e,o){if(o in e){let t=e[o];if(Array.isArray(t)){let i=[];for(let r of t)i.push(r?.toString()??"");return i.length>0?i[0]:void 0}return t?.toString()}}};var z=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,o){let t=[],i=new Map,r=new Set;for(let[p,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let c=a.type;if(c)if(Array.isArray(c))for(let l of c){let y=l?.toString();if(y==="Class"||y&&y.endsWith(".Class")){r.add(p);break}}else{let l=c?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&r.add(p)}}for(let[p,a]of Object.entries(e.body))if(typeof a=="object"&&a!==null&&!Array.isArray(a)){let s=a,c=s.type;if(c)if(Array.isArray(c)){let l=!1;for(let y of c){let m=y?.toString();if(m&&this.isDefinitionType(m)){l=!0;break}}if(!l)for(let y of c){let m=y?.toString();m&&m.trim().length>0&&(i.has(m)||i.set(m,[]),i.get(m).push(p))}}else{let l=c?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(i.has(l)||i.set(l,[]),i.get(l).push(p)))}this.checkNestedTypes(s,p,i,p)}let n=new V(o);for(let[p,a]of i){if(this.builtInClasses.has(p)||r.has(p))continue;let s=await n.resolveEntityAsync(p,e);if(!(s&&this.isClassEntity(s.entity))){let l=Array.from(new Set(a)).sort();for(let y of l)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${p}' is not defined or imported`,suggestion:`Define '${p}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:p,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,o,t,i){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let r=e,n=r.type;if(n){let p=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(n))for(let a of n){let s=a?.toString();s&&s.trim().length>0&&!p.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(i))}else{let a=n?.toString();a&&a.trim().length>0&&!p.has(a)&&(t.has(a)||t.set(a,[]),t.get(a).push(i))}}for(let[p,a]of Object.entries(r))if(p!=="type"){let s=`${i}.${p}`;this.checkNestedTypes(a,o,t,s)}}else if(Array.isArray(e))for(let r=0;r<e.length;r++){let n=`${i}[${r}]`;this.checkNestedTypes(e[r],o,t,n)}}isClassEntity(e){if(!e)return!1;let o=e.type;if(!o)return!1;if(Array.isArray(o))for(let t of o){let i=t?.toString();if(i==="Class"||i&&i.endsWith(".Class"))return!0}else{let t=o?.toString();if(t==="Class"||t&&t.endsWith(".Class"))return!0}return!1}isDefinitionType(e){return!e||e.trim().length===0?!1:new Set(["Class","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(e)?!0:e.endsWith(".Class")||e.endsWith(".Property")||e.endsWith(".DatatypeProperty")||e.endsWith(".ObjectProperty")||e.endsWith(".AnnotationProperty")}};var te=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new G,this.documentRules=[new I,new D,new O,new $,new w],this.repositoryRules=[new E,new j,new S,new N,new K,new C,new x,new T,new _,new M,new W,new L,new H,new F,new U,new q,new X,new B,new z]}async validateAsync(e,o){let t=new P;for(let i of this.documentRules)try{let r=i.validate(e);this.addErrorsToResult(t,r)}catch(r){let n=new h;n.ruleType=i.ruleName,n.severity="Error",n.message=`Validation rule '${i.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,t.errors.push(n)}if(o){let i=[];for(let r of this.repositoryRules)try{let n=await r.validateAsync(e,o);this.addErrorsToResult(t,n)}catch(n){let p=n instanceof Error?n.message:String(n);i.push({ruleName:r.ruleName,cause:p})}if(i.length>0){let r=new Map;for(let{ruleName:n,cause:p}of i){let a=r.get(p);a?a.push(n):r.set(p,[n])}for(let[n,p]of r){let a=new h;a.ruleType=p[0],a.severity="Error",p.length===1?a.message=`Validation rule '${p[0]}' failed: ${n}`:a.message=`${n} (affects ${p.length} rules: ${p.join(", ")})`,t.errors.push(a)}}}return t.isValid=t.errors.length===0,t}async validateYamlAsync(e,o){let t=this.parser.parseWithErrors(e);if(!t.isValid){let i=new P;i.isValid=!1;for(let r of t.errors){let n=new h;n.ruleType="ParseError",n.severity="Error",n.lineNumber=r.line,n.column=r.column,n.message=r.message,r.keyName&&(n.entityName=r.keyName),r.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),i.errors.push(n)}return i}return await this.validateAsync(t.document,o)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let o=this.documentRules.findIndex(t=>t instanceof e);o>=0&&this.documentRules.splice(o,1)}removeRepositoryRule(e){let o=this.repositoryRules.findIndex(t=>t instanceof e);o>=0&&this.repositoryRules.splice(o,1)}addErrorsToResult(e,o){for(let t of o)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{H as AmbiguousReferenceRule,z as ClassDefinitionRule,N as ClassHierarchyCycleRule,W as DefinitionPropertyReferenceRule,w as EmbeddedKanonakNoExplicitTypeRule,E as ImportExistenceRule,M as InstancePropertyReferenceRule,te as KanonakObjectValidator,_ as NamespaceImportCycleRule,I as NamespacePrefixRule,U as ObjectPropertyImportRule,q as ObjectPropertyValueValidationRule,h as OntologyValidationError,P as OntologyValidationResult,X as PropertyDomainRule,K as PropertyHierarchyCycleRule,F as PropertyRangeReferenceRule,C as PropertyRangeRequiredRule,O as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,D as ResourceNamingRule,x as SubClassOfReferenceRule,T as SubPropertyOfReferenceRule,$ as SubjectKanonakTypeRequiredRule,S as TypeAmbiguityRule,j as UnresolvedReferenceRule,ee as ValidationContext,b as ValidationSeverity,L as XsdImportRule};
|
|
@@ -7,6 +7,17 @@ export declare class AmbiguousReferenceRule implements IRepositoryValidationRule
|
|
|
7
7
|
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
|
|
8
8
|
private buildEntitySourceMapAsync;
|
|
9
9
|
private collectEntitiesRecursivelyAsync;
|
|
10
|
+
/**
|
|
11
|
+
* Collect every entity name in the import closure that is declared
|
|
12
|
+
* as `owl.DatatypeProperty` (or its short form `DatatypeProperty`).
|
|
13
|
+
* Values bound to such properties are literals — not entity
|
|
14
|
+
* references — so the ambiguity check must not run against them,
|
|
15
|
+
* even when the literal happens to match an unqualified entity
|
|
16
|
+
* name imported from somewhere else (the `name` / `description`
|
|
17
|
+
* / `license` kind of collision).
|
|
18
|
+
*/
|
|
19
|
+
private buildDatatypePropertyNamesAsync;
|
|
20
|
+
private collectDatatypePropertiesAsync;
|
|
10
21
|
private validateEntityReferences;
|
|
11
22
|
private validatePropertyValue;
|
|
12
23
|
private createAmbiguityError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"yaml-parser"
|
|
106
106
|
],
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"@kanonak-protocol/types": "^2.
|
|
108
|
+
"@kanonak-protocol/types": "^2.4.0",
|
|
109
109
|
"ignore": "^7.0.5",
|
|
110
110
|
"js-yaml": "^4.1.0",
|
|
111
111
|
"yaml": "^2.7.0"
|