@kanonak-protocol/sdk 3.23.0 → 3.24.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 +1 -1
- package/dist/{chunk-VRZUCZEF.js → chunk-4TJZIM7A.js} +1 -1
- package/dist/chunk-7U6IOH7G.js +165 -0
- package/dist/{chunk-CNM3SY5S.js → chunk-AV4AVTI6.js} +1 -1
- package/dist/{chunk-3JRHG2JH.js → chunk-AZSZXLEH.js} +1 -1
- package/dist/chunk-NIGFQYVA.js +1 -0
- package/dist/chunk-PB2RWBJN.js +47 -0
- package/dist/{chunk-GD4SYMXW.js → chunk-VLBP5CHO.js} +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +17 -17
- package/dist/look/LookRenderer.d.ts +141 -0
- package/dist/look/index.d.ts +1 -0
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/KanonakUrlResolver.d.ts +114 -0
- package/dist/resolution/index.d.ts +2 -0
- package/dist/resolution/index.js +1 -1
- package/dist/transformations/TransformationEngine.d.ts +33 -0
- package/dist/transformations/index.js +44 -44
- package/dist/validation/IKanonakObjectValidator.d.ts +3 -2
- package/dist/validation/KanonakObjectValidator.d.ts +3 -2
- package/dist/validation/ValidationCache.d.ts +94 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/IRepositoryValidationRule.d.ts +2 -1
- package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +23 -1
- package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +2 -1
- package/dist/validation/rules/repository/PropertyDomainRule.d.ts +11 -1
- package/package.json +2 -2
- package/dist/chunk-LPUWDJMI.js +0 -47
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-
|
|
1
|
+
import{A,B,C,D,E,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-PB2RWBJN.js";import"../chunk-FJ35VIV6.js";import"../chunk-R2V7IXWN.js";import"../chunk-W6T7MOKY.js";import"../chunk-MYITGTGJ.js";import"../chunk-FQHALFRR.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";export{w as AmbiguousReferenceRule,C as ClassDefinitionRule,n as ClassHierarchyCycleRule,u as DefinitionPropertyReferenceRule,j as EmbeddedKanonakTypeRule,k as ImportExistenceRule,t as InstancePropertyReferenceRule,E as KanonakObjectValidator,D as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,y as ObjectPropertyImportRule,z as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,A as PropertyDomainRule,o as PropertyHierarchyCycleRule,x as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,B as PropertyValueTypeRule,g as ResourceNamingRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,m as TypeAmbiguityRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,v as XsdImportRule};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
2
2
|
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
3
3
|
import type { OntologyValidationError } from '../../OntologyValidationError.js';
|
|
4
|
+
import type { ValidationCache } from '../../ValidationCache.js';
|
|
4
5
|
export interface IRepositoryValidationRule {
|
|
5
6
|
readonly ruleName: string;
|
|
6
|
-
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
|
|
7
|
+
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
|
|
7
8
|
}
|
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
2
2
|
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
3
3
|
import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
|
|
4
|
+
import type { ValidationCache } from '../../ValidationCache.js';
|
|
4
5
|
import { OntologyValidationError } from '../../OntologyValidationError.js';
|
|
5
6
|
export declare class InstancePropertyReferenceRule implements IRepositoryValidationRule {
|
|
6
7
|
private readonly metadataKeys;
|
|
7
8
|
get ruleName(): string;
|
|
8
|
-
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
|
|
9
|
+
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
|
|
9
10
|
private isPropertyType;
|
|
10
11
|
private isClassType;
|
|
12
|
+
/**
|
|
13
|
+
* Cache-aware availability check. When the cache supplied
|
|
14
|
+
* precomputed closure sets, do a constant-time `Set.has(propName)`
|
|
15
|
+
* lookup. Otherwise fall back to the recursive walk for callers
|
|
16
|
+
* (CLI single-document validation) that pass no cache.
|
|
17
|
+
*/
|
|
18
|
+
private isPropertyAvailable;
|
|
19
|
+
/**
|
|
20
|
+
* Union of property names declared anywhere in the document's
|
|
21
|
+
* transitive import closure. Used for non-aliased reference
|
|
22
|
+
* lookups, which can match any imported property.
|
|
23
|
+
*/
|
|
24
|
+
private closurePropertyNamesViaCache;
|
|
25
|
+
/**
|
|
26
|
+
* Per-alias property-name sets. For each top-level import that
|
|
27
|
+
* has an alias, computes the union of property names across the
|
|
28
|
+
* imported document's full transitive closure — so a reference
|
|
29
|
+
* written as `alias.foo` resolves against precisely the closure
|
|
30
|
+
* that alias points at.
|
|
31
|
+
*/
|
|
32
|
+
private aliasClosurePropertyNamesViaCache;
|
|
11
33
|
private isPropertyAvailableInImports;
|
|
12
34
|
private isPropertyAvailableInImportsRecursive;
|
|
13
35
|
}
|
|
@@ -2,6 +2,7 @@ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/documen
|
|
|
2
2
|
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
3
3
|
import { OntologyValidationError } from '../../OntologyValidationError.js';
|
|
4
4
|
import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
|
|
5
|
+
import type { ValidationCache } from '../../ValidationCache.js';
|
|
5
6
|
/**
|
|
6
7
|
* Validates `[[reference]]` placeholders embedded in core-prose datatype
|
|
7
8
|
* values (`Markdown` / `SubstitutableString`). Every placeholder must
|
|
@@ -17,7 +18,7 @@ import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
|
|
|
17
18
|
*/
|
|
18
19
|
export declare class MarkdownLinkRule implements IRepositoryValidationRule {
|
|
19
20
|
readonly ruleName = "MarkdownLink";
|
|
20
|
-
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
|
|
21
|
+
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
|
|
21
22
|
/**
|
|
22
23
|
* Walk a defined kanonak's statements for `MarkdownStatement`s,
|
|
23
24
|
* recursing through embedded kanonaks — a Markdown-ranged property
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
2
2
|
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
3
3
|
import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
|
|
4
|
+
import type { ValidationCache } from '../../ValidationCache.js';
|
|
4
5
|
import { OntologyValidationError } from '../../OntologyValidationError.js';
|
|
5
6
|
export declare class PropertyDomainRule implements IRepositoryValidationRule {
|
|
6
7
|
private readonly standardProperties;
|
|
7
8
|
get ruleName(): string;
|
|
8
|
-
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
|
|
9
|
+
validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Cache-driven hierarchy: union of `getClassDeclarations(docId)`
|
|
12
|
+
* across the document's transitive import closure. Each closure
|
|
13
|
+
* document's body is walked at most once per validation pass
|
|
14
|
+
* regardless of how many workspace documents share that closure
|
|
15
|
+
* member. Result shape matches `buildCompleteClassHierarchyAsync`
|
|
16
|
+
* so downstream `isTypeCompatibleWithDomain` works unchanged.
|
|
17
|
+
*/
|
|
18
|
+
private buildClassHierarchyViaCache;
|
|
9
19
|
private buildCompleteClassHierarchyAsync;
|
|
10
20
|
private validateEntityProperties;
|
|
11
21
|
private isTypeCompatibleWithDomain;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.24.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"yaml-parser"
|
|
114
114
|
],
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"@kanonak-protocol/types": "^3.
|
|
116
|
+
"@kanonak-protocol/types": "^3.24.0",
|
|
117
117
|
"ignore": "^7.0.5",
|
|
118
118
|
"js-yaml": "^4.1.0",
|
|
119
119
|
"yaml": "^2.7.0"
|
package/dist/chunk-LPUWDJMI.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import{a as le}from"./chunk-FJ35VIV6.js";import{a as re,c as ie,e as ae}from"./chunk-R2V7IXWN.js";import{c as te,k as oe,l as ne}from"./chunk-W6T7MOKY.js";import{a as ee}from"./chunk-MYITGTGJ.js";import{a as k,b as A,c as se}from"./chunk-IXE5THUW.js";var v=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(i=>(i.Warning="Warning",i.Error="Error",i))(R||{});var g=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var G=class h{resolvedDocuments=[];currentEntityPath;withPath(e){let i=new h;return i.resolvedDocuments=this.resolvedDocuments,i.currentEntityPath=e,i}};var D=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 i=[];for(let[t,s]of Object.entries(e.body))s&&typeof s=="object"&&!Array.isArray(s)&&this.validateEntity(t,s,i);return i}validateEntity(e,i,t){for(let[s,a]of Object.entries(i)){let r=a?.toString()??"";if(r&&h.NAMESPACE_PREFIX_PATTERN.test(r)){let n=this.getSuggestionForPrefixedValue(r),l=e.split(".")[0],o=new g;o.ruleType=this.ruleName,o.severity="Error",o.entityName=l,o.propertyName=e,o.actualValue=s,o.expectedValue=n,o.message=`Invalid namespace prefix '${r}'. Use '${n}' without prefix.`,o.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(o)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(`${e}.${s}`,a,t)}}getSuggestionForPrefixedValue(e){let i=e.toLowerCase();if(i==="rdfs:class"||i==="owl:class")return"Class";if(i==="rdfs:property"||i==="rdf:property")return"DatatypeProperty or ObjectProperty";if(i.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var I=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_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let i=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[s,a]of Object.entries(e.body)){let r=h.VALID_AUGMENTATION_PATTERN.test(s);if(!r&&!t&&h.RESERVED_WORDS.has(s.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=s,n.message=`Entity name '${s}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",i.push(n);continue}if(!r&&!h.VALID_NAME_PATTERN.test(s)){let n;/^\d/.test(s)?n="Entity names must start with a letter, not a number.":s.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=s,l.message=`Invalid entity name '${s}'. ${n}`,l.suggestion=n,i.push(l)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validatePropertyNames(s,a,i)}return i}validatePropertyNames(e,i,t){for(let s of Object.keys(i))if(!h.VALID_PROPERTIES.has(s)&&!h.VALID_PROPERTY_NAME_PATTERN.test(s)){let a=new g;a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=s,a.message=`Property name '${s}' in entity '${e}' doesn't follow naming conventions.`,a.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(a)}}};var 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 i=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return i;let t=this.isPropertyDefinedAsClass(e);for(let[s,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let r=a,n=r.type;if(n){let l=[];if(Array.isArray(n))for(let o of n){let p=o?.toString();p&&p==="Property"&&!t&&l.push(p)}else{let o=n?.toString();o&&o==="Property"&&!t&&l.push(o)}for(let o of l){let p=this.getPropertyValue(r,"range"),c=this.determinePropertyType(p),m=new g;m.ruleType=this.ruleName,m.severity="Error",m.entityName=s,m.propertyName="type",m.actualValue=o,m.expectedValue=c,m.message=`Invalid property type '${o}'. Use '${c}' instead.`,m.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",i.push(m)}}}return i}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,i){let t=e[i];return t?t.toString():null}isPropertyDefinedAsClass(e){let i=e.body.Property;if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i.type;if(s){let a=s.toString();return a==="Class"||a.endsWith(".Class")}}return!1}};var j=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let i=[];for(let[t,s]of Object.entries(e.body)){if(typeof s!="object"||s===null||Array.isArray(s)||t.includes("."))continue;let a=s,r="type"in a,n=a.type?.toString().trim();if(!r||!n){let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=t,l.propertyName="type",l.message=`Subject Kanonak '${t}' must have a 'type' property.`,l.suggestion=`Add a type statement like:
|
|
2
|
-
type: Scene
|
|
3
|
-
|
|
4
|
-
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,l.expectedValue="A valid class name (Scene, Character, Story, etc.)",i.push(l)}}return i}};var w=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,i){let t=[],s=new A(i),a=await this.buildPropertyRangeMap(e,s);for(let[r,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(r,n,void 0,a,s,e,t,0);return t}pickRange(e,i,t){if(e.length===0)return;if(e.length===1)return e[0].range;let s=i.indexOf(".");if(s>0){let a=i.substring(0,s),r=e.find(n=>n.declaringAlias===a);if(r)return r.range}if(t){let a=this.localName(t),r=e.find(n=>this.localName(n.domain)===a);if(r)return r.range}return e[0].range}async checkEmbeddedTypes(e,i,t,s,a,r,n,l){if(l>0){let p=i.type;if(p!=null){let c=await this.validateEmbeddedType(e,String(p),t,a,r);c&&n.push(c)}}let o=i.type!==void 0&&i.type!==null?String(i.type):void 0;for(let[p,c]of Object.entries(i)){let m=this.localName(p),y=s.get(m),f=(y!==void 0?this.pickRange(y,p,o):void 0)??t;if(typeof c=="object"&&c!==null)if(Array.isArray(c))for(let d=0;d<c.length;d++){let b=c[d];typeof b=="object"&&b!==null&&!Array.isArray(b)&&await this.checkEmbeddedTypes(`${e}.${p}[${d}]`,b,f,s,a,r,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,c,f,s,a,r,n,l+1)}}async validateEmbeddedType(e,i,t,s,a){if(i.length===0||!t)return null;let r=this.localName(i),n=this.localName(t);if(n==="Resource"||n==="Class")return null;let l=e.split(".")[0];if(r===n){let p=new g;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=l,p.propertyName=e,p.actualValue=i,p.expectedValue=t,p.message=`Embedded object at '${e}' declares 'type: ${i}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,p.suggestion=`Remove the 'type: ${i}' line, or keep it if explicitness is preferred over concision.`,p}if(await s.isSubclassOfAsync(i,t,a)||(r!==i||n!==t)&&await s.isSubclassOfAsync(r,n,a))return null;let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=l,o.propertyName=e,o.actualValue=i,o.expectedValue=t,o.message=`Embedded object at '${e}' has 'type: ${i}', which is not a subclass of the parent property's range '${t}'.`,o.suggestion=`Either remove the 'type: ${i}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${i}' class definition so the relationship holds.`,o}localName(e){let i=e.lastIndexOf(".");return i<0||i===e.length-1?e:e.substring(i+1)}async buildPropertyRangeMap(e,i){let t=new Map,s=await i.buildEntityIndexAsync(e),a=new Map;for(let[r,n]of s){let l=n.entity.type;if(l==null)continue;let o=String(l),p=this.localName(o);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let m=n.entity.range;if(m==null)continue;let y=String(m);if(y.length===0)continue;let u=n.entity.domain,f=u!=null?String(u):"",d=n.uri.toString(),b=a.get(d),V=r.includes(".");(!b||V&&!b.entityName.includes("."))&&a.set(d,{entityName:r,domain:f,range:y})}for(let r of a.values()){let n=this.localName(r.entityName),l=r.entityName.indexOf("."),o=l>0?r.entityName.substring(0,l):void 0,p=t.get(n)??[];p.push({domain:r.domain,range:r.range,declaringAlias:o}),t.set(n,p)}return t}};var E=class{ruleName="ImportExistence";async validateAsync(e,i){let t=[];if(!e.metadata?.imports)return t;let s=await i.getAllDocumentsAsync();for(let[a,r]of Object.entries(e.metadata.imports))for(let n of r)if(!await i.getHighestCompatibleVersionAsync(a,n)){let o=await this.determineImportErrorAsync(i,a,n,s),p=new g;p.ruleType=this.ruleName,p.severity="Error",p.message=o.message,p.suggestion=o.suggestion,p.entityName=`Import: ${a}/${n.packageName}`,p.actualValue=n.toString(),p.expectedValue=o.expectedValue,t.push(p)}return t}async determineImportErrorAsync(e,i,t,s){let a=await e.getDocumentsByNamespaceAsync(i,t.packageName);if(a.length===0){let o=s.filter(y=>y.metadata.namespace_?.publisher===i).map(y=>y.metadata.namespace_.package_).filter((y,u,f)=>f.indexOf(y)===u),p=this.findSimilarPackages(t.packageName,o),c=`Import '${i}/${t.package_}' not found - package does not exist`,m=p.length>0?`Did you mean: ${p.slice(0,3).join(", ")}?`:o.length>0?`Available packages in ${i}: ${o.slice(0,5).join(", ")}`:`No packages found for publisher '${i}'. Verify the publisher name is correct.`;return{message:c,suggestion:m,expectedValue:"Existing package"}}let n=a.filter(o=>o.metadata.namespace_?.version).map(o=>o.metadata.namespace_.version.toString()).sort().join(", "),l=this.getAcceptableVersionRange(t);return{message:`Import '${i}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${n}. Required: ${l}`,expectedValue:l}}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,i){if(i.length===0)return[];let t=i.filter(r=>r.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(r.toLowerCase()));if(t.length>0)return t.sort((r,n)=>r.length-n.length);let s=i.map(r=>({package:r,distance:this.levenshteinDistance(e.toLowerCase(),r.toLowerCase())})).sort((r,n)=>r.distance-n.distance),a=Math.max(3,Math.floor(e.length*.4));return s.filter(r=>r.distance<=a).map(r=>r.package)}levenshteinDistance(e,i){if(!e||e.length===0)return i?.length??0;if(!i||i.length===0)return e.length;let t=e.length,s=i.length,a=Array(t+1).fill(null).map(()=>Array(s+1).fill(0));for(let r=0;r<=t;r++)a[r][0]=r;for(let r=0;r<=s;r++)a[0][r]=r;for(let r=1;r<=t;r++)for(let n=1;n<=s;n++){let l=e[r-1]===i[n-1]?0:1;a[r][n]=Math.min(Math.min(a[r-1][n]+1,a[r][n-1]+1),a[r-1][n-1]+l)}return a[t][s]}};var N=class{ruleName="UnresolvedReference";async validateAsync(e,i){let t=[],s=new A(i),a=await s.buildEntityIndexAsync(e),r=new Set;for(let[n,l]of a.entries()){let o=l.entity.type;if(o){let p=o.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&r.add(n)}}for(let[n,l]of Object.entries(e.body)){if(!l||typeof l!="object"||Array.isArray(l))continue;let o=l,p=this.getPropertyValue(o,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[c,m]of Object.entries(o))c==="type"||c==="label"||c==="comment"||!(r.has(c)||Array.from(r).some(u=>u.endsWith(`.${c}`)))||await this.validateReferenceValue(n,c,m,e,s,t)}return t}async validateReferenceValue(e,i,t,s,a,r){if(t!=null){if(typeof t=="string")await a.resolveEntityAsync(t,s)||r.push(this.createUnresolvedReferenceError(e,i,t));else if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=t[n];typeof l=="string"&&(await a.resolveEntityAsync(l,s)||r.push(this.createUnresolvedReferenceError(e,`${i}[${n}]`,l)))}}}createUnresolvedReferenceError(e,i,t){let s=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
5
|
-
|
|
6
|
-
Possible solutions:
|
|
7
|
-
\u2022 Add import if the entity is defined in another namespace:
|
|
8
|
-
kanonak namespace add-import <publisher>/<package>@<version>
|
|
9
|
-
\u2022 Check for typos in the reference name '${t}'
|
|
10
|
-
\u2022 Define '${t}' in the current namespace or an appropriate namespace
|
|
11
|
-
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=i,a.actualValue=t,a.message=`Reference to '${t}' could not be resolved`,a.suggestion=s,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,i){let t=e[i];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,i){let t=[],s=new Map,a=[];if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){a.push({doc:o,import:l,publisher:r});let p=await this.getTransitiveImportsAsync(i,o,new Set);a.push(...p.map(c=>({doc:c,import:null,publisher:r})))}}for(let{doc:r,import:n}of a){let l=r.metadata?.namespace_?.toString()??"unknown";for(let o of Object.keys(r.body))s.has(o)||s.set(o,[]),s.get(o).push({namespace:l,import:n})}for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n;this.checkAmbiguousReference(l,"type",s,r,t),this.checkAmbiguousReference(l,"subClassOf",s,r,t),this.checkAmbiguousReference(l,"subPropertyOf",s,r,t),this.checkAmbiguousReference(l,"domain",s,r,t),this.checkAmbiguousReference(l,"range",s,r,t)}return t}checkAmbiguousReference(e,i,t,s,a){let r=e[i];if(!r)return;let n=k(r);for(let l of n){if(l.includes("."))continue;let o=t.get(l);if(o&&o.length>1){let p=o.map(u=>u.namespace).join(", "),c=[];for(let{namespace:u,import:f}of o)if(f?.alias)c.push(`${f.alias}.${l}`);else{let d=u.split("/"),V=d[d.length-1]?.split("@")[0]??"alias";c.push(`${V}.${l}`)}let m=c.length>0?`Use one of: ${c.join(", ")}`:"Consider adding namespace aliases to your imports",y=new g;y.ruleType=this.ruleName,y.severity="Warning",y.entityName=s,y.propertyName=i,y.actualValue=l,y.message=`Type '${l}' is ambiguous. It's defined in: ${p}`,y.suggestion=m,a.push(y)}}}async getTransitiveImportsAsync(e,i,t){let s=[],a=i.metadata?.namespace_?.toString()??"";if(t.has(a))return s;if(t.add(a),i.metadata?.imports)for(let[r,n]of Object.entries(i.metadata.imports))for(let l of n){let o=await e.getHighestCompatibleVersionAsync(r,l);if(o){s.push(o);let p=await this.getTransitiveImportsAsync(e,o,t);s.push(...p)}}return s}};var $=class{ruleName="ClassHierarchyCycle";async validateAsync(e,i){let t=[],s=new Map,a=new Set;await this.buildClassHierarchy(e,i,s,a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type,p=l.subClassOf;if(o?.toString()==="Class"&&p){let c=r,m=this.detectCycle(c,s);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=c,u.propertyName="subClassOf",u.actualValue=y,t.push(u);break}}}return t}async buildClassHierarchy(e,i,t,s){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&s.has(a))){a&&s.add(a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type,p=l.subClassOf;if(o?.toString()==="Class"&&p){let c=k(p);c.length>0&&t.set(r,c)}}if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);o&&await this.buildClassHierarchy(o,i,t,s)}}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let a=i.get(e);if(a)for(let r of a){let n=this.detectCycleRecursive(r,i,t,s);if(n)return n}return t.pop(),null}};var T=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,i){let t=[],s=new Map,a=new Set;await this.buildPropertyHierarchy(e,i,s,a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.subPropertyOf){let p=r,c=this.detectCycle(p,s);if(c){let m=c.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=p,y.propertyName="subPropertyOf",y.actualValue=m,t.push(y);break}}return t}async buildPropertyHierarchy(e,i,t,s){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&s.has(a))){a&&s.add(a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type;if(o){let p=o.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let c=l.subPropertyOf;if(c){let m=k(c);m.length>0&&t.set(r,m)}}}}if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);o&&await this.buildPropertyHierarchy(o,i,t,s)}}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let a=i.get(e);if(a)for(let r of a){let n=this.detectCycleRecursive(r,i,t,s);if(n)return n}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,i){let t=[];for(let[s,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let r=a,n=r.type?.toString();if(n==="DatatypeProperty"||n==="ObjectProperty"||n?.endsWith(".DatatypeProperty")||n?.endsWith(".ObjectProperty")){let l="range"in r,o=r.range?.toString().trim();if(!l||!o){let p=new g;p.ruleType=this.ruleName,p.severity="Error",p.entityName=s,p.propertyName="range",p.message=`Property '${s}' must have a 'range' defined.`,p.suggestion=n==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=n==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(p)}}}return t}};var K=class{builtInClasses=new Set(["Resource","Class","Datatype","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}isClassLikeType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isClassLikeType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=k(r.subClassOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInClasses.has(p)||s.has(p))continue;if(!await this.isClassAvailableInImports(e,i,p)){let m=l.length>1?`[${o}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Class '${p}' referenced in subClassOf${m} is not defined or imported`,y.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,y.entityName=a,y.propertyName="subClassOf",y.actualValue=p,y.expectedValue="Defined or imported class",t.push(y)}}}return t}async isClassAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(this.isClassLikeType(u))return!0}let m=new Set;if(await this.isClassAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isClassAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isClassLikeType(m))return!0}if(await this.isClassAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var x=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();(l==="DatatypeProperty"||l==="ObjectProperty"||l==="AnnotationProperty")&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=k(r.subPropertyOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInProperties.has(p)||s.has(p))continue;if(!await this.isPropertyAvailableInImports(e,i,p)){let m=l.length>1?`[${o}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Property '${p}' referenced in subPropertyOf${m} is not defined or imported`,y.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,y.entityName=a,y.propertyName="subPropertyOf",y.actualValue=p,y.expectedValue="Defined or imported property",t.push(y)}}}return t}async isPropertyAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let m=new Set;if(await this.isPropertyAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var M=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,i){let t=[],s=e.metadata.namespace_?.toString();if(!s)return t;let a=new Map,r=new Set;await this.buildImportGraph(e,i,a,r);let n=this.detectCycle(s,a);if(n){let l=n.join(" \u2192 "),o=new g;o.ruleType=this.ruleName,o.severity="Error",o.message=`Circular namespace import detected: ${l}`,o.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",o.entityName="imports",o.propertyName="imports",o.actualValue=l,t.push(o)}return t}async buildImportGraph(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(!(!a||s.has(a))&&(s.add(a),e.metadata.imports)){let r=[];for(let[n,l]of Object.entries(e.metadata.imports))for(let o of l){let p=`${n}/${o.packageName}@${o.version}`;r.push(p);let c=await i.getHighestCompatibleVersionAsync(n,o);c&&await this.buildImportGraph(c,i,t,s)}r.length>0&&t.set(a,r)}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){let a=t.indexOf(e);if(a>=0){let n=t.slice(a);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let r=i.get(e);if(r)for(let n of r){let l=this.detectCycleRecursive(n,i,t,s);if(l)return l}return t.pop(),null}};var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isPropertyType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r,l=n.type?.toString();if(this.isPropertyType(l)||this.isClassType(l))continue;for(let[o,p]of Object.entries(n)){if(!o||this.metadataKeys.has(o))continue;let c=o,m=null;if(o.includes(".")){let u=o.lastIndexOf(".");m=o.substring(0,u),c=o.substring(u+1)}if(s.has(c))continue;if(!await this.isPropertyAvailableInImports(e,i,c,m)){let u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${o}' is not defined or imported`,u.suggestion=m?`The property '${c}' is not found in the imported namespace with alias '${m}'.
|
|
12
|
-
1. Verify the namespace is imported with the correct alias
|
|
13
|
-
2. Check if the property name is spelled correctly
|
|
14
|
-
3. Ensure the imported namespace version contains this property`:`The property '${o}' is not defined in this namespace or any imported namespace.
|
|
15
|
-
1. Define '${o}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
16
|
-
2. Import the namespace that contains '${o}', OR
|
|
17
|
-
3. Use a qualified reference like 'alias.${o}' if already imported with an alias`,u.entityName=a,u.propertyName=o,u.actualValue=p?.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,i,t,s){if(!e.metadata.imports)return!1;for(let[a,r]of Object.entries(e.metadata.imports))for(let n of r){if(s!==null&&n.alias!==s)continue;let l=await i.getHighestCompatibleVersionAsync(a,n);if(l){let o=l.body[t];if(o&&typeof o=="object"&&!Array.isArray(o)){let m=o.type?.toString();if(this.isPropertyType(m))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,i,t,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isPropertyType(m))return!0}if(await this.isPropertyAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var L=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isPropertyType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r,l=n.type?.toString();if(!this.isPropertyType(l)&&!this.isClassType(l))continue;for(let[o,p]of Object.entries(n)){if(!o||this.metadataKeys.has(o))continue;let c=o,m=null;if(o.includes(".")){let u=o.lastIndexOf(".");m=o.substring(0,u),c=o.substring(u+1)}if(s.has(c))continue;if(!await this.isPropertyAvailableInImports(e,i,c,m)){let u=this.isClassType(l)?"class":"property",f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${o}' used on ${u} '${a}' is not defined or imported`,f.suggestion=m?`The property '${c}' is not found in the imported namespace with alias '${m}'.
|
|
18
|
-
1. Verify the namespace is imported with the correct alias
|
|
19
|
-
2. Check if the property name is spelled correctly
|
|
20
|
-
3. Ensure the imported namespace version contains this property`:`The property '${o}' is not defined in this namespace or any imported namespace.
|
|
21
|
-
1. Define '${o}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
22
|
-
2. Import the namespace that contains '${o}', OR
|
|
23
|
-
3. Use a qualified reference like 'alias.${o}' if already imported with an alias`,f.entityName=a,f.propertyName=o,f.actualValue=p?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,i,t,s){if(!e.metadata.imports)return!1;for(let[a,r]of Object.entries(e.metadata.imports))for(let n of r){if(s!==null&&n.alias!==s)continue;let l=await i.getHighestCompatibleVersionAsync(a,n);if(l){let o=l.body[t];if(o&&typeof o=="object"&&!Array.isArray(o)){let m=o.type?.toString();if(this.isPropertyType(m))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,i,t,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isPropertyType(m))return!0}if(await this.isPropertyAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var _=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"XsdImport"}async validateAsync(e,i){let t=[],s=new Set,a=[];for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,o=!1,p=l.type;if(Array.isArray(p)){for(let c of p)if(c?.toString()==="DatatypeProperty"){o=!0;break}}else p?.toString()==="DatatypeProperty"&&(o=!0);if(o){a.push(r);let c=this.getPropertyValue(l,"range");c&&this.xsdTypes.has(c)&&s.add(c)}}if(s.size>0&&!await this.checkXsdImportAsync(e.metadata,i)){let n=Array.from(s).sort().join(", "),l=a.sort().join(", "),o=new g;o.ruleType=this.ruleName,o.severity="Error",o.message=`XSD namespace not imported but XSD types are used: ${n}`,o.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${l}`,o.entityName="imports",t.push(o)}return t}async checkXsdImportAsync(e,i,t=new Set){if(!e?.imports)return!1;let s=e.namespace_?.toString()??"";if(s&&t.has(s))return!1;s&&t.add(s);for(let[,a]of Object.entries(e.imports))for(let r of a)if(r.packageName==="xsd"||r.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[a,r]of Object.entries(e.imports))for(let n of r){let l=await i.getHighestCompatibleVersionAsync(a,n);if(l?.metadata&&await this.checkXsdImportAsync(l.metadata,i,t))return!0}return!1}getPropertyValue(e,i){return e[i]?.toString()}};var H=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,i){let t=[],s=await this.buildEntitySourceMapAsync(e,i),a=await this.buildDatatypePropertyNamesAsync(e,i);for(let[r,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&this.validateEntityReferences(r,n,s,a,e,t);return t}async buildEntitySourceMapAsync(e,i){let t=new Map,s=new Set;for(let a of Object.keys(e.body)){let r=e.metadata.namespace_?.toString()??"";t.has(a)||t.set(a,[]),t.get(a).push(`(local:${r})`)}if(e.metadata.imports)for(let[a,r]of Object.entries(e.metadata.imports))for(let n of r){let l=await i.getHighestCompatibleVersionAsync(a,n);l&&await this.collectEntitiesRecursivelyAsync(l,t,s,i)}return t}async collectEntitiesRecursivelyAsync(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(!t.has(a)){t.add(a);for(let r of Object.keys(e.body)){i.has(r)||i.set(r,[]);let n=i.get(r);n.includes(a)||n.push(a)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await s.getHighestCompatibleVersionAsync(r,l);o&&await this.collectEntitiesRecursivelyAsync(o,i,t,s)}}}async buildDatatypePropertyNamesAsync(e,i){let t=new Set,s=new Set;if(await this.collectDatatypePropertiesAsync(e,t,s,i),e.metadata.imports)for(let[a,r]of Object.entries(e.metadata.imports))for(let n of r){let l=await i.getHighestCompatibleVersionAsync(a,n);l&&await this.collectDatatypePropertiesAsync(l,t,s,i)}return t}async collectDatatypePropertiesAsync(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(!t.has(a)){t.add(a);for(let[r,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n))continue;let l=n.type;if(typeof l!="string")continue;(l.includes(".")?l.substring(l.lastIndexOf(".")+1):l)==="DatatypeProperty"&&i.add(r)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await s.getHighestCompatibleVersionAsync(r,l);o&&await this.collectDatatypePropertiesAsync(o,i,t,s)}}}validateEntityReferences(e,i,t,s,a,r){for(let[n,l]of Object.entries(i)){let o=n;if(o&&!o.includes(".")){let p=t.get(o);if(p&&p.length>1&&!p.some(m=>m.startsWith("(local:"))){let m=p.filter(y=>!y.startsWith("(local:"));m.length>1&&r.push(this.createAmbiguityError(e,o,`Property '${o}'`,m,a,!0,o))}}this.validatePropertyValue(e,o,l,t,s,a,r)}}validatePropertyValue(e,i,t,s,a,r,n){if(t==null)return;let l=i&&i.includes(".")?i.substring(i.lastIndexOf(".")+1):i,o=!!l&&a.has(l);if(typeof t=="string"&&!t.includes(".")&&!o){let p=s.get(t);if(p&&p.length>1&&!p.some(m=>m.startsWith("(local:"))){let m=p.filter(y=>!y.startsWith("(local:"));m.length>1&&n.push(this.createAmbiguityError(e,i,`Reference '${t}'`,m,r,!1,t))}}else if(Array.isArray(t))for(let p=0;p<t.length;p++){let c=`${e}.${i}[${p}]`;this.validatePropertyValue(c,i,t[p],s,a,r,n)}else if(typeof t=="object"&&!Array.isArray(t)){let p=i?`${e}.${i}`:e;this.validateEntityReferences(p,t,s,a,r,n)}}createAmbiguityError(e,i,t,s,a,r,n){let l=[];for(let f of s){let d=this.findAliasForNamespace(a,f);if(d){let b=i?.split(".").pop()??i;l.push(`${d}.${b}`)}}let o=l.length>0?`Use one of: ${l.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${i}')`,p=s.map(f=>` \u2022 ${f}`).join(`
|
|
24
|
-
`),c=e.split(".")[0],m=e.includes(".")?e:i,y=new g;y.ruleType=this.ruleName,y.severity="Error",y.entityName=c,m&&(y.propertyName=m);let u=n??i;return u&&(y.actualValue=u),y.message=`${t} is ambiguous - defined in multiple imported namespaces`,y.suggestion=`${o}
|
|
25
|
-
|
|
26
|
-
Defined in:
|
|
27
|
-
${p}`,y.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",y}findAliasForNamespace(e,i){if(!e.metadata.imports)return null;for(let[t,s]of Object.entries(e.metadata.imports))for(let a of s)if(`${t}/${a.packageName}@${a.version}`===i&&a.alias)return a.alias;return null}};var U=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]);primitiveTypes=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","dateTime","date","time","duration","anyURI","anySimpleType","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte","base64Binary","hexBinary","Literal","Resource"]);get ruleName(){return"PropertyRangeReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isValidRangeTargetType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r,l=n.type?.toString();if(l!=="DatatypeProperty"&&l!=="ObjectProperty"&&!l?.endsWith(".DatatypeProperty")&&!l?.endsWith(".ObjectProperty"))continue;let o=n.range;if(!o)continue;let p=[];if(Array.isArray(o))for(let c of o){let m=c?.toString();m&&p.push(m)}else{let c=o?.toString();c&&p.push(c)}if(p.length===0)continue;for(let c of p){if(this.primitiveTypes.has(c)||this.builtInClasses.has(c)||s.has(c))continue;if(!await this.isTypeAvailableInImports(e,i,c)){let y=l?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${a}' has range '${c}' which is not defined or imported`,u.suggestion=y==="ObjectProperty"?`For ObjectProperty:
|
|
28
|
-
1. Define '${c}' as a Class in this namespace, OR
|
|
29
|
-
2. Import the namespace that contains '${c}', OR
|
|
30
|
-
3. Use a qualified reference like 'alias.${c}' if already imported with an alias`:`For DatatypeProperty:
|
|
31
|
-
1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
|
|
32
|
-
2. If '${c}' should be a class, change property type to ObjectProperty`,u.entityName=a,u.propertyName="range",u.actualValue=c,u.expectedValue=y==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(this.isValidRangeTargetType(u))return!0}let m=new Set;if(await this.isTypeAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isValidRangeTargetType(m))return!0}if(await this.isTypeAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var F=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,i){let t=[],s=new Map,a=new A(i);await a.buildEntityIndexAsync(e);for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,o=!1,p=l.type;if(Array.isArray(p)){for(let c of p)if(c?.toString()==="ObjectProperty"){o=!0;break}}else p?.toString()==="ObjectProperty"&&(o=!0);if(o){let c=l.range,m=[];if(Array.isArray(c))for(let y of c){let u=y?.toString();u&&m.push(u)}else{let y=c?.toString();y&&m.push(y)}for(let y of m)this.xsdTypes.has(y)||(s.has(y)||s.set(y,[]),s.get(y).push(r))}}for(let[r,n]of s)if(!await a.resolveEntityAsync(r,e))for(let o of n){let p=new g;p.ruleType=this.ruleName,p.severity="Warning",p.message=`ObjectProperty references class '${r}' which may not be imported`,p.suggestion=`Ensure the namespace containing '${r}' is imported, or define '${r}' in this document`,p.entityName=o,p.propertyName="range",p.actualValue=r,t.push(p)}return t}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,i){let t=[],s=new A(i),a=new se(s),r=await s.buildEntityIndexAsync(e),n=await this.buildPropertyMetadataAsync(e,i,s,r);for(let[l,o]of Object.entries(e.body))typeof o=="object"&&o!==null&&!Array.isArray(o)&&await this.scanEntityForObjectProperties(o,l,"",n,s,a,e,t);return t}async scanEntityForObjectProperties(e,i,t,s,a,r,n,l){for(let[o,p]of Object.entries(e)){if(this.standardProperties.has(o))continue;let c=o,m=o.lastIndexOf(".");m>0&&m<o.length-1&&(c=o.substring(m+1));let y=s.get(c);if(y&&r.isEffectiveObjectProperty(y.propertyType,y.rangeUri)){let f=t?`${t}.${o}`:o;if(typeof p=="string"&&p.trim().length>0){let d=p.trim();if(d.includes(",")){let V=d.split(",").map(P=>P.trim()).filter(P=>P.length>0);l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${o}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
|
|
33
|
-
${o}:
|
|
34
|
-
- ${V[0]}
|
|
35
|
-
${V.slice(1).map(P=>` - ${P}`).join(`
|
|
36
|
-
`)}`,entityName:i,propertyName:o,propertyPath:f,actualValue:d,expectedValue:`A single reference to ${y.range??"an entity"} OR a YAML list`});continue}let b=await a.resolveEntityAsync(d,n);if(b)y.range&&(await this.validateRangeType(b,y.range,a,n)||l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${o}' expects a ${y.range}, but '${d}' may not be a ${y.range}`,suggestion:`Ensure '${d}' is defined with appropriate type`,entityName:i,propertyName:o,propertyPath:f,actualValue:d,expectedValue:y.range}));else{let V=y.range??"entity";l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${o}' references '${d}' which is not defined or imported`,suggestion:`Define '${d}' or import a namespace that contains it. Expected range: ${V}`,entityName:i,propertyName:o,propertyPath:f,actualValue:d,expectedValue:"Defined or imported entity"})}}else if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let d=t?`${t}.${o}`:o;await this.scanEntityForObjectProperties(p,i,d,s,a,r,n,l)}else if(Array.isArray(p))for(let d=0;d<p.length;d++){let b=p[d];if(typeof b=="string"&&b.trim().length>0){let V=b.trim(),P=await a.resolveEntityAsync(V,n);if(P){if(y.range&&!await this.validateRangeType(P,y.range,a,n)){let Z=t?`${t}.${o}[${d}]`:`${o}[${d}]`;l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${o}' expects a ${y.range}, but '${V}' may not be a ${y.range}`,suggestion:`Ensure '${V}' is defined with appropriate type`,entityName:i,propertyName:`${o}[${d}]`,propertyPath:Z,actualValue:V,expectedValue:y.range})}}else{let Q=y.range??"entity",Z=t?`${t}.${o}[${d}]`:`${o}[${d}]`;l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${o}' references '${V}' which is not defined or imported`,suggestion:`Define '${V}' or import a namespace that contains it. Expected range: ${Q}`,entityName:i,propertyName:`${o}[${d}]`,propertyPath:Z,actualValue:V,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let V=t?`${t}.${o}[${d}]`:`${o}[${d}]`;await this.scanEntityForObjectProperties(b,i,V,s,a,r,n,l)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!s.has(o)){let u=t?`${t}.${o}`:o;await this.scanEntityForObjectProperties(p,i,u,s,a,r,n,l)}else if(Array.isArray(p))for(let u=0;u<p.length;u++){let f=p[u];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=t?`${t}.${o}[${u}]`:`${o}[${u}]`;await this.scanEntityForObjectProperties(f,i,d,s,a,r,n,l)}}}}async validateRangeType(e,i,t,s){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(i))return!0;let r=e.entity.type;if(r){let n=[];if(Array.isArray(r))for(let l of r){let o=l?.toString();o&&o.trim().length>0&&n.push(o)}else{let l=r?.toString();l&&l.trim().length>0&&n.push(l)}for(let l of n){let o=l.includes(".")?l.split(".")[1]:l;if(o===i||i==="Property"&&(o==="DatatypeProperty"||o==="ObjectProperty"||o==="AnnotationProperty")||i==="Class"&&o==="Class"||await t.isSubclassOfAsync(l,i,s))return!0}}return!1}async buildPropertyMetadataAsync(e,i,t,s){let a=new Map;for(let[r,n]of s){let l=n.entity.type;if(l){let o=[];if(Array.isArray(l))for(let m of l){let y=m?.toString();y&&y.trim().length>0&&o.push(y)}else{let m=l?.toString();m&&m.trim().length>0&&o.push(m)}let p=!1,c="Property";for(let m of o){let y=m.includes(".")?m.split(".")[1]:m;if(y==="Property"||y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty"){p=!0,c=m;break}}if(p){let m={propertyType:c},y=n.entity.range;if(y){let u=y?.toString();if(u&&u.trim().length>0){m.range=u;let f=await t.resolveEntityAsync(u,e);f&&(m.rangeUri=f.uri)}}a.set(r,m)}}}return a}};var X=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,i){let t=[],s=new Map;for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,o=this.getPropertyValue(l,"type");(o==="DatatypeProperty"||o?.endsWith(".DatatypeProperty")||o==="ObjectProperty"||o?.endsWith(".ObjectProperty")||o==="AnnotationProperty"||o?.endsWith(".AnnotationProperty"))&&s.set(r,l)}let a=await this.buildCompleteClassHierarchyAsync(e,i);for(let[r,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,o=this.getPropertyValue(l,"type");if(!o||o==="Class"||o.endsWith(".Class")||o.endsWith("Property")||o==="AnnotationProperty")continue;this.validateEntityProperties(l,r,o,s,a,t)}return t}async buildCompleteClassHierarchyAsync(e,i){let t=new Map,s=new Set,a=async(n,l)=>{if(!s.has(l)){s.add(l);for(let[o,p]of Object.entries(n.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let c=p,m=this.getPropertyValue(c,"type");if(m==="Class"||m?.endsWith(".Class")){let y=c.subClassOf;if(y===void 0){for(let f of Object.keys(c))if(f.endsWith(".subClassOf")){y=c[f];break}}let u=k(y);u.length>0&&t.set(o,u)}}if(n.metadata.imports)for(let[o,p]of Object.entries(n.metadata.imports))for(let c of p)try{let m=await i.getHighestCompatibleVersionAsync(o,c);if(m){let y=`${o}/${c.packageName}@${c.version}`;await a(m,y)}}catch{}}},r=e.metadata.namespace_?.toString()??"unknown";return await a(e,r),t}validateEntityProperties(e,i,t,s,a,r){for(let[n,l]of Object.entries(e)){if(this.standardProperties.has(n))continue;let o=n,p=n.lastIndexOf(".");p>0&&p<n.length-1&&(o=n.substring(p+1));let c=s.get(o);if(!c)continue;let m=this.getPropertyValue(c,"domain");if(m){if(!this.isTypeCompatibleWithDomain(t,m,a)){let y=i.split(".")[0];r.push({ruleType:this.ruleName,severity:"Error",entityName:y,propertyName:i,actualValue:n,message:`Property '${n}' has domain '${m}' but is used on '${t}' at '${i}'`,suggestion:`Either:
|
|
37
|
-
1. Use this property only on '${m}' instances
|
|
38
|
-
2. Change the property domain to include '${t}'
|
|
39
|
-
3. Create a different property for '${t}'`,expectedValue:`Property used on ${m} or its subclasses`})}if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let y=l,u=this.getPropertyValue(y,"type");if(u){let f=`${i}.${n}`;this.validateEntityProperties(y,f,u,s,a,r)}else{let f=this.getPropertyValue(c,"range");if(f){let d=`${i}.${n}`;this.validateEntityProperties(y,d,f,s,a,r)}}}else if(Array.isArray(l))for(let y=0;y<l.length;y++){let u=l[y];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,d=this.getPropertyValue(f,"type");if(d){let b=`${i}.${n}[${y}]`;this.validateEntityProperties(f,b,d,s,a,r)}else{let b=this.getPropertyValue(c,"range");if(b){let V=`${i}.${n}[${y}]`;this.validateEntityProperties(f,V,b,s,a,r)}}}}}}}isTypeCompatibleWithDomain(e,i,t){if(e===i)return!0;let s=new Set,a=[e];for(;a.length>0;){let r=a.shift();if(s.has(r))continue;s.add(r);let n=t.get(r);if(n)for(let l of n){if(l===i)return!0;a.push(l)}}return!1}getPropertyValue(e,i){if(i in e){let t=e[i];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${i}`)){let s=e[t];return this.extractFirstValue(s)}}extractFirstValue(e){if(Array.isArray(e)){let i=[];for(let t of e)i.push(t?.toString()??"");return i.length>0?i[0]:void 0}return e?.toString()}};var z=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,i){let t=[],s=new Map;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r,l=this.getPropertyValue(n,"type");(l==="DatatypeProperty"||l==="ObjectProperty")&&s.set(a,n)}for(let[a,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let n=r,l=this.getPropertyValue(n,"type");if(!(!l||l==="Class"||l.endsWith("Property")||l==="AnnotationProperty"))for(let[o,p]of Object.entries(n)){if(o==="type"||o==="label"||o==="comment")continue;let c=o,m=o.lastIndexOf(".");m>0&&m<o.length-1&&(c=o.substring(m+1));let y=s.get(c);if(!y)continue;let u=this.getPropertyValue(y,"type"),f=this.getPropertyValue(y,"range");if(u==="DatatypeProperty"){if(typeof p=="object"&&p!==null&&!Array.isArray(p)||Array.isArray(p))t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:o,message:`Property '${o}' is a DatatypeProperty with range '${f}' but instance '${a}' has a complex object value`,suggestion:`Either:
|
|
40
|
-
1. Create a class for this data and change '${o}' to an ObjectProperty
|
|
41
|
-
2. Store as a JSON string to keep it as DatatypeProperty
|
|
42
|
-
3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,p)){let d={ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:o,message:`Property '${o}' expects type '${f}' but instance '${a}' has value of type '${this.getValueTypeName(p)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(d.expectedValue=f),t.push(d)}}else if(u==="ObjectProperty")if(Array.isArray(p))for(let d=0;d<p.length;d++){let b=p[d];typeof b!="string"&&(typeof b!="object"||b===null||Array.isArray(b))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:`${o}[${d}]`,message:`ObjectProperty '${o}' array item ${d} in instance '${a}' has invalid type '${this.getValueTypeName(b)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof p!="string"&&(typeof p!="object"||p===null||Array.isArray(p))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:o,message:`ObjectProperty '${o}' in instance '${a}' has invalid value type '${this.getValueTypeName(p)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,i){switch(e?.toLowerCase()){case"string":return typeof i=="string";case"integer":case"int":return typeof i=="number"&&Number.isInteger(i);case"decimal":return typeof i=="number";case"boolean":return typeof i=="boolean";case"float":case"double":return typeof i=="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,i){if(i in e){let t=e[i];if(Array.isArray(t)){let s=[];for(let a of t)s.push(a?.toString()??"");return s.length>0?s[0]:void 0}return t?.toString()}}};var B=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,i){let t=[],s=new Map,a=new Set;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let p=l.type;if(p)if(Array.isArray(p))for(let c of p){let m=c?.toString();if(m==="Class"||m&&m.endsWith(".Class")){a.add(n);break}}else{let c=p?.toString();(c==="Class"||c&&c.endsWith(".Class"))&&a.add(n)}}for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let o=l,p=o.type;if(p)if(Array.isArray(p)){let c=!1;for(let m of p){let y=m?.toString();if(y&&this.isDefinitionType(y)){c=!0;break}}if(!c)for(let m of p){let y=m?.toString();y&&y.trim().length>0&&(s.has(y)||s.set(y,[]),s.get(y).push(n))}}else{let c=p?.toString();c&&c.trim().length>0&&(this.isDefinitionType(c)||(s.has(c)||s.set(c,[]),s.get(c).push(n)))}this.checkNestedTypes(o,n,s,n)}let r=new A(i);for(let[n,l]of s){if(this.builtInClasses.has(n)||a.has(n))continue;let o=await r.resolveEntityAsync(n,e);if(!(o&&this.isClassEntity(o.entity))){let c=Array.from(new Set(l)).sort();for(let m of c)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${n}' is not defined or imported`,suggestion:`Define '${n}' as a Class in this document, or import a namespace that contains it`,entityName:m,propertyName:"type",actualValue:n,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,i,t,s){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=e,r=a.type;if(r){let n=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(r))for(let l of r){let o=l?.toString();o&&o.trim().length>0&&!n.has(o)&&(t.has(o)||t.set(o,[]),t.get(o).push(s))}else{let l=r?.toString();l&&l.trim().length>0&&!n.has(l)&&(t.has(l)||t.set(l,[]),t.get(l).push(s))}}for(let[n,l]of Object.entries(a))if(n!=="type"){let o=`${s}.${n}`;this.checkNestedTypes(l,i,t,o)}}else if(Array.isArray(e))for(let a=0;a<e.length;a++){let r=`${s}[${a}]`;this.checkNestedTypes(e[a],i,t,r)}}isClassEntity(e){if(!e)return!1;let i=e.type;if(!i)return!1;if(Array.isArray(i))for(let t of i){let s=t?.toString();if(s==="Class"||s&&s.endsWith(".Class"))return!0}else{let t=i?.toString();if(t==="Class"||t&&t.endsWith(".Class"))return!0}return!1}isDefinitionType(e){return!e||e.trim().length===0?!1:new Set(["Class","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(e)?!0:e.endsWith(".Class")||e.endsWith(".Property")||e.endsWith(".DatatypeProperty")||e.endsWith(".ObjectProperty")||e.endsWith(".AnnotationProperty")}};var Y=class{ruleName="MarkdownLink";async validateAsync(e,i){let t=[],s=new le(e,i),r=await new ae().parseKanonaks(s);for(let n of r)n instanceof te&&this.checkDefined(n,n.name,t);return t}checkDefined(e,i,t){for(let s of e.statement)if(s instanceof ie){let a=s.predicate.subject?.name??"(unknown)";for(let r of s.links)r.target||t.push(this.unresolvedLinkError(i,a,r.reference))}else if(s instanceof oe)this.checkDefined(s.object,i,t);else if(s instanceof ne)for(let a of s.object)a instanceof re&&this.checkDefined(a,i,t)}unresolvedLinkError(e,i,t){let s=new g;return s.ruleType=this.ruleName,s.severity="Warning",s.entityName=e,s.propertyName=i,s.actualValue=t,s.message=`Embedded link [[${t}]] in '${i}' could not be resolved`,s.expectedValue="A reference resolvable through the document's import closure",s.suggestion=`The reference '${t}' inside a markdown value cannot be found in the current document or any imported namespace.
|
|
43
|
-
|
|
44
|
-
Possible solutions:
|
|
45
|
-
\u2022 Import the package that defines '${t}' so the link can resolve
|
|
46
|
-
\u2022 Check for typos in the reference name
|
|
47
|
-
\u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,s}};var J=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new ee,this.documentRules=[new D,new I,new O,new j],this.repositoryRules=[new w,new E,new N,new S,new $,new T,new C,new K,new x,new M,new W,new L,new _,new H,new U,new F,new q,new X,new z,new B,new Y]}async validateAsync(e,i){let t=new v;for(let s of this.documentRules)try{let a=s.validate(e);this.addErrorsToResult(t,a)}catch(a){let r=new g;r.ruleType=s.ruleName,r.severity="Error",r.message=`Validation rule '${s.ruleName}' failed: ${a instanceof Error?a.message:String(a)}`,t.errors.push(r)}if(i){let s=[];for(let a of this.repositoryRules)try{let r=await a.validateAsync(e,i);this.addErrorsToResult(t,r)}catch(r){let n=r instanceof Error?r.message:String(r);s.push({ruleName:a.ruleName,cause:n})}if(s.length>0){let a=new Map;for(let{ruleName:r,cause:n}of s){let l=a.get(n);l?l.push(r):a.set(n,[r])}for(let[r,n]of a){let l=new g;l.ruleType=n[0],l.severity="Error",n.length===1?l.message=`Validation rule '${n[0]}' failed: ${r}`:l.message=`${r} (affects ${n.length} rules: ${n.join(", ")})`,t.errors.push(l)}}}return t.isValid=t.errors.length===0,t}async validateYamlAsync(e,i){let t=this.parser.parseWithErrors(e);if(!t.isValid){let s=new v;s.isValid=!1;for(let a of t.errors){let r=new g;r.ruleType="ParseError",r.severity="Error",r.lineNumber=a.line,r.column=a.column,r.message=a.message,a.keyName&&(r.entityName=a.keyName),a.errorType==="DuplicateKey"&&(r.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),s.errors.push(r)}return s}return await this.validateAsync(t.document,i)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let i=this.documentRules.findIndex(t=>t instanceof e);i>=0&&this.documentRules.splice(i,1)}removeRepositoryRule(e){let i=this.repositoryRules.findIndex(t=>t instanceof e);i>=0&&this.repositoryRules.splice(i,1)}addErrorsToResult(e,i){for(let t of i)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{v as a,R as b,g as c,G as d,D as e,I as f,O as g,j as h,w as i,E as j,N as k,S as l,$ as m,T as n,C as o,K as p,x as q,M as r,W as s,L as t,_ as u,H as v,U as w,F as x,q as y,X as z,z as A,B,Y as C,J as D};
|