@kanonak-protocol/sdk 3.16.0 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/browser.d.ts +4 -5
  2. package/dist/browser.js +2 -2
  3. package/dist/chunk-2JQMUZWN.js +1 -0
  4. package/dist/{chunk-YENGFI2R.js → chunk-2SSUPRX3.js} +1 -1
  5. package/dist/chunk-BQIWYLBU.js +2 -0
  6. package/dist/chunk-C2WWLKWE.js +1 -0
  7. package/dist/chunk-CQLO62JP.js +1 -0
  8. package/dist/chunk-FJ35VIV6.js +1 -0
  9. package/dist/chunk-IXE5THUW.js +1 -0
  10. package/dist/chunk-L4HXBHJ4.js +47 -0
  11. package/dist/chunk-VRZUCZEF.js +1 -0
  12. package/dist/chunk-Z72IKY6C.js +1 -0
  13. package/dist/graph/GraphBuilder.d.ts +3 -1
  14. package/dist/index.d.ts +4 -5
  15. package/dist/index.js +15 -15
  16. package/dist/parsing/KanonakObjectParser.d.ts +11 -0
  17. package/dist/parsing/PropertyMetadata.d.ts +9 -0
  18. package/dist/parsing/extractMarkdownLinks.d.ts +31 -0
  19. package/dist/parsing/index.js +1 -1
  20. package/dist/reasoning/index.js +1 -1
  21. package/dist/resolution/TypeResolver.d.ts +12 -0
  22. package/dist/resolution/index.d.ts +1 -0
  23. package/dist/resolution/index.js +1 -1
  24. package/dist/statements/MarkdownStatement.d.ts +38 -0
  25. package/dist/statements/index.d.ts +2 -0
  26. package/dist/transformations/index.js +29 -29
  27. package/dist/transformations/v3/CompiledTransformationV3.d.ts +15 -1
  28. package/dist/transformations/v3/ExpressionEngineV3.d.ts +10 -0
  29. package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +7 -0
  30. package/dist/uri-helpers/UriHelpers.d.ts +24 -0
  31. package/dist/uri-helpers/index.d.ts +2 -2
  32. package/dist/uri-helpers/index.js +1 -1
  33. package/dist/validation/index.d.ts +1 -1
  34. package/dist/validation/index.js +1 -1
  35. package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +28 -0
  36. package/dist/validation/rules/repository/SubClassOfReferenceRule.d.ts +8 -0
  37. package/dist/validation/rules/repository/index.d.ts +1 -0
  38. package/package.json +2 -10
  39. package/dist/chunk-7M7XXZOV.js +0 -1
  40. package/dist/chunk-AFF2TQ7Y.js +0 -2
  41. package/dist/chunk-C54LRL2A.js +0 -42
  42. package/dist/chunk-CRR4BQKR.js +0 -1
  43. package/dist/chunk-GKQVJITL.js +0 -1
  44. package/dist/chunk-NPWF35XZ.js +0 -1
  45. package/dist/chunk-QJ66UBDY.js +0 -1
  46. package/dist/chunk-RGMZAKJV.js +0 -1
  47. package/dist/chunk-USLG7UIM.js +0 -4
  48. package/dist/ctl/CtlGraphResolver.d.ts +0 -14
  49. package/dist/ctl/CtlKanonakUri.d.ts +0 -28
  50. package/dist/ctl/CtlMarkdownRenderer.d.ts +0 -17
  51. package/dist/ctl/CtlParser.d.ts +0 -10
  52. package/dist/ctl/CtlValidator.d.ts +0 -12
  53. package/dist/ctl/index.d.ts +0 -12
  54. package/dist/ctl/index.js +0 -1
  55. /package/dist/{ctl → resolution}/ResourceTypeClassifier.d.ts +0 -0
@@ -5,6 +5,14 @@ import { OntologyValidationError } from '../../OntologyValidationError.js';
5
5
  export declare class SubClassOfReferenceRule implements IRepositoryValidationRule {
6
6
  private readonly builtInClasses;
7
7
  get ruleName(): string;
8
+ /**
9
+ * A valid `subClassOf` target is anything that is a Class — and per
10
+ * core-rdf's `Datatype subClassOf Class`, a Datatype is a Class. So
11
+ * datatype hierarchies (`xsd.integer subClassOf xsd.decimal`,
12
+ * `Markdown subClassOf SubstitutableString`) are well-formed and the
13
+ * target check must accept both `Class` and `Datatype` (aliased or not).
14
+ */
15
+ private isClassLikeType;
8
16
  validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository): Promise<OntologyValidationError[]>;
9
17
  private isClassAvailableInImports;
10
18
  private isClassAvailableInImportsRecursive;
@@ -19,3 +19,4 @@ export { PropertyDomainRule } from './PropertyDomainRule.js';
19
19
  export { PropertyValueTypeRule } from './PropertyValueTypeRule.js';
20
20
  export { ClassDefinitionRule } from './ClassDefinitionRule.js';
21
21
  export { EmbeddedKanonakTypeRule } from './EmbeddedKanonakTypeRule.js';
22
+ export { MarkdownLinkRule } from './MarkdownLinkRule.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -54,14 +54,6 @@
54
54
  "types": "./dist/filtering/index.d.ts",
55
55
  "default": "./dist/filtering/index.js"
56
56
  },
57
- "./ctl": {
58
- "browser": {
59
- "types": "./dist/ctl/index.d.ts",
60
- "default": "./dist/ctl/index.js"
61
- },
62
- "types": "./dist/ctl/index.d.ts",
63
- "default": "./dist/ctl/index.js"
64
- },
65
57
  "./reasoning": {
66
58
  "browser": {
67
59
  "types": "./dist/reasoning/index.d.ts",
@@ -121,7 +113,7 @@
121
113
  "yaml-parser"
122
114
  ],
123
115
  "dependencies": {
124
- "@kanonak-protocol/types": "^3.16.0",
116
+ "@kanonak-protocol/types": "^3.17.0",
125
117
  "ignore": "^7.0.5",
126
118
  "js-yaml": "^4.1.0",
127
119
  "yaml": "^2.7.0"
@@ -1 +0,0 @@
1
- import{a as M}from"./chunk-MYITGTGJ.js";var N=class{propertyUri;propertyType;range;isImported;definedInNamespace};import{parseDocument as R,LineCounter as x,isMap as S,isPair as p,isScalar as g,isSeq as E}from"yaml";var K=class o{entities=new Map;entityBlocks=new Map;properties=new Map;propertyValues=new Map;valueListItems=new Map;importPackages=new Map;nestedKeys=new Map;nestedValues=new Map;static fromContent(e){let n=new o,t=new x,i=R(e,{lineCounter:t});if(i.errors.length>0||!S(i.contents))return n;A(i.contents,[],t,n);for(let r of i.contents.items){if(!p(r)||!g(r.key))continue;let a=String(r.key.value),u=r.key.range;if(!u)continue;n.entities.set(a,l(u,t));let s=r.value,c=s&&typeof s=="object"&&"range"in s?s.range:void 0;if(c?n.entityBlocks.set(a,l([u[0],u[1],c[2]],t)):n.entityBlocks.set(a,l(u,t)),S(r.value)){let k=new Map,m=new Map,v=new Map;for(let y of r.value.items){if(!p(y)||!g(y.key))continue;let h=String(y.key.value),f=y.key.range;f&&k.set(h,l(f,t));let P=y.value;if(P&&typeof P=="object"&&"range"in P&&Array.isArray(P.range)){let b=P.range;m.set(h,l(b,t))}if(E(P)){let b=[];for(let I of P.items)I&&typeof I=="object"&&"range"in I&&Array.isArray(I.range)&&b.push(l(I.range,t));b.length>0&&v.set(h,b)}}k.size>0&&n.properties.set(a,k),m.size>0&&n.propertyValues.set(a,m),v.size>0&&n.valueListItems.set(a,v);let d=C(r.value,t);d.length>0&&n.importPackages.set(a,d)}}return n}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,n){for(let[t,i]of this.entityBlocks)if(L(i,e,n))return t}findPropertyAtPosition(e,n){let t=this.findEntityAtPosition(e,n);if(!t)return;let i=this.properties.get(t),r=this.propertyValues.get(t);if(!i&&!r)return{entityName:t};let a,u;if(r)for(let[s,c]of r)L(c,e,n)&&(!u||V(c,u))&&(a=s,u=c);if(i)for(let[s,c]of i)L(c,e,n)&&(!u||V(c,u))&&(a=s,u=c);return a?{entityName:t,propertyName:a}:{entityName:t}}getPropertyPosition(e,n){return this.properties.get(e)?.get(n)}getPropertyValuePosition(e,n){return this.propertyValues.get(e)?.get(n)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[n,t]of this.importPackages)for(let i of t)e.push({entityName:n,entry:i});return e}findPropertySourceName(e,n){let t=this.properties.get(e);if(t){if(t.has(n))return n;for(let i of t.keys()){let r=i.lastIndexOf(".");if((r===-1?i:i.substring(r+1))===n)return i}}}getListItemPosition(e,n,t){let i=this.valueListItems.get(e)?.get(n);if(!(!i||t<0||t>=i.length))return i[t]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,n){this.nestedKeys.set(e,n)}setNestedValuePosition(e,n){this.nestedValues.set(e,n)}getMostSpecificPosition(e,n,t){if(e){if(n!==void 0){if(t!==void 0){let a=this.getListItemPosition(e,n,t);if(a)return a}let i=this.getPropertyValuePosition(e,n);if(i)return i;let r=this.getPropertyPosition(e,n);if(r)return r}return this.getEntityPosition(e)}}};function C(o,e){let n=[];if(!S(o))return n;let t=o.items.find(i=>p(i)&&g(i.key)&&String(i.key.value)==="imports");if(!t||!p(t)||!E(t.value))return n;for(let i of t.value.items){if(!S(i))continue;let r=i.items.find(s=>p(s)&&g(s.key)&&String(s.key.value)==="publisher");if(!r||!p(r)||!g(r.value))continue;let a=String(r.value.value),u=i.items.find(s=>p(s)&&g(s.key)&&String(s.key.value)==="packages");if(!(!u||!p(u)||!E(u.value)))for(let s of u.value.items){if(!S(s))continue;let c=s.items.find(f=>p(f)&&g(f.key)&&String(f.key.value)==="package");if(!c||!p(c)||!g(c.value)||!c.value.range)continue;let k=String(c.value.value),m=s.items.find(f=>p(f)&&g(f.key)&&String(f.key.value)==="version"),v=m&&p(m)&&g(m.value)?String(m.value.value):"",d=s.items.find(f=>p(f)&&g(f.key)&&String(f.key.value)==="alias"),y=d&&p(d)&&g(d.value)?String(d.value.value):void 0,h=y!==void 0?{publisher:a,package_:k,version:v,alias:y,position:l(c.value.range,e)}:{publisher:a,package_:k,version:v,position:l(c.value.range,e)};n.push(h)}}return n}function L(o,e,n){return!(e<o.line||e>o.endLine||e===o.line&&n<o.column||e===o.endLine&&n>o.endColumn)}function V(o,e){let n=o.endLine-o.line,t=e.endLine-e.line;if(n!==t)return n<t;let i=o.endLine===o.line?o.endColumn-o.column:Number.MAX_SAFE_INTEGER,r=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return i<r}function A(o,e,n,t){if(S(o)){for(let i of o.items){if(!p(i)||!g(i.key))continue;let r=String(i.key.value),a=[...e,r],u=JSON.stringify(a);i.key.range&&t.setNestedKeyPosition(u,l(i.key.range,n));let s=i.value,c=w(s);c&&t.setNestedValuePosition(u,l(c,n)),A(s,a,n,t)}return}if(E(o)){for(let i=0;i<o.items.length;i++){let r=o.items[i],a=[...e,i],u=JSON.stringify(a),s=w(r);s&&t.setNestedValuePosition(u,l(s,n)),A(r,a,n,t)}return}}function w(o){if(!o||typeof o!="object"||!("range"in o))return;let e=o.range;return Array.isArray(e)&&e.length>=3?e:void 0}function l(o,e){let n=e.linePos(o[0]),t=e.linePos(o[2]);return{line:n.line-1,column:n.col-1,endLine:t.line-1,endColumn:t.col-1}}function D(o,e){let t=(e??new M).parse(o),i=K.fromContent(o);return{document:t,positions:i}}export{N as a,K as b,D as c};
@@ -1,2 +0,0 @@
1
- import{a as m}from"./chunk-USLG7UIM.js";import{c as S}from"./chunk-CRR4BQKR.js";var A=(t=>(t.Class="Class",t.DatatypeProperty="DatatypeProperty",t.ObjectProperty="ObjectProperty",t.AnnotationProperty="AnnotationProperty",t.Instance="Instance",t.Datatype="Datatype",t.Unknown="Unknown",t))(A||{}),v=(t=>(t.InstanceOf="instanceOf",t.SubClassOf="subClassOf",t.Domain="domain",t.Range="range",t.ObjectRelationship="objectRelationship",t.SubPropertyOf="subPropertyOf",t.PropertyValue="propertyValue",t))(v||{}),N=class{static async buildFromRepository(n){let y=await new S().parseKanonaks(n),c=await n.getAllDocumentsAsync(),i=[],s=[],t=new Set,f=new Set,u=new Map;for(let l of y){let a=l;a.name&&(m.isClassType(a)&&t.add(a.name),(m.isObjectPropertyType(a)||m.isGenericPropertyType(a))&&f.add(a.name))}for(let l of c)for(let[a,p]of Object.entries(l.body))f.has(a)&&p?.range&&typeof p.range=="string"&&u.set(a,p.range);let d=new Map;for(let l of y){let a=l;a.name&&d.set(a.name,a)}for(let l of c){let a=l.metadata.namespace_,p=a?`${a.publisher}/${a.package_}`:"",o=a?.version?`${a.version.major}.${a.version.minor}.${a.version.patch}`:"",g=R(l);for(let[h,b]of Object.entries(l.body)){if(!b||typeof b!="object")continue;let T=d.get(h),k="Unknown";if(T){let P=T;m.isClassType(P)?k="Class":m.isObjectPropertyType(P)?k="ObjectProperty":m.isDatatypePropertyType(P)?k="DatatypeProperty":m.isAnnotationPropertyType(P)?k="AnnotationProperty":m.isDatatypeType(P)?k="Datatype":m.isGenericPropertyType(P)?k="ObjectProperty":m.isInstanceOfKnownClass(P,t)&&(k="Instance")}let j=p&&o?`${p}/${h}@${o}`:h,C={};for(let[P,w]of Object.entries(b))P!=="type"&&(typeof w!="object"||w===null)&&(C[P]=w);i.push({id:j,label:b.label??h,type:k,namespace:p,properties:C}),x(j,b,k,t,f,s,p,o,g),$(j,b,f,u,i,s,p,o,g)}}return{nodes:i,edges:s}}static buildFromDocument(n){let r=[],y=[],c=n.metadata.namespace_,i=c?.version?`${c.version.major}.${c.version.minor}.${c.version.patch}`:"",s=c?`${c.publisher}/${c.package_}`:"",t=new Set,f=new Set,u=new Map,d=R(n);for(let[p,o]of Object.entries(n.body)){let g=o?.type;g&&(G(g,d)&&t.add(p),K(g,d)&&(f.add(p),o.range&&typeof o.range=="string"&&u.set(p,o.range)))}for(let[p,o]of Object.entries(n.body)){if(!o||typeof o!="object")continue;let g=o.type,h=M(g,p,t,d),b=s&&i?`${s}/${p}@${i}`:p,T={};for(let[k,j]of Object.entries(o))k!=="type"&&(typeof j!="object"||j===null)&&(T[k]=j);r.push({id:b,label:o.label??p,type:h,namespace:s,properties:T}),x(b,o,h,t,f,y,s,i,d),$(b,o,f,u,r,y,s,i,d)}let l=new Set(r.map(p=>p.id)),a=y.filter(p=>l.has(p.source)&&l.has(p.target));return{nodes:r,edges:a}}};function R(e,n){let r=new Map;if(e.metadata?.imports)for(let[y,c]of Object.entries(e.metadata.imports))for(let i of c){let s=i.alias??i.packageName,t=i.version,f=`${t.major}.${t.minor}.${t.patch}`;r.set(s,{publisher:y,package_:i.packageName,version:f})}return r}var E={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},_=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function D(e,n){if(e.includes(".")){let r=e.indexOf("."),y=e.substring(0,r),c=e.substring(r+1),i=n.get(y);if(i)return`${i.publisher}/${i.package_}/${c}`}return null}function G(e,n){let r=D(e,n);return r?E[r]==="Class":!1}function K(e,n){let r=D(e,n);return r?_.has(r):!1}function M(e,n,r,y){if(!e||e==="Package")return"Unknown";let c=D(e,y);if(c){let s=E[c];if(s)return s;let t=c.split("/").pop()?.split("@")[0]??"";return r.has(t)?"Instance":"Unknown"}let i=e.split(".").pop()??e;return r.has(i)?"Instance":"Unknown"}var I=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function x(e,n,r,y,c,i,s,t,f){let u=n.type,d=n.subClassOf;if(d){let o=Array.isArray(d)?d:[d];for(let g of o)typeof g=="string"&&i.push({source:e,target:O(g,s,t,f),type:"subClassOf",label:"subClassOf"})}let l=n.subPropertyOf;if(l){let o=Array.isArray(l)?l:[l];for(let g of o)typeof g=="string"&&i.push({source:e,target:O(g,s,t,f),type:"subPropertyOf",label:"subPropertyOf"})}if(r==="Instance"&&u){let o=u.split(".").pop()??u;i.push({source:e,target:O(o,s,t,f),type:"instanceOf",label:"type"})}if(r==="Instance")for(let[o,g]of Object.entries(n)){if(I.has(o)||!c.has(o))continue;let h=Array.isArray(g)?g:[g];for(let b of h)typeof b=="string"&&U(b)&&i.push({source:e,target:O(b,s,t,f),type:"propertyValue",label:o,propertyId:O(o,s,t,f)})}let a=r==="ObjectProperty"||r==="DatatypeProperty",p=n.domain&&n.range;if((a||p)&&n.domain&&n.range){let o=typeof n.domain=="string"?n.domain:null,g=typeof n.range=="string"?n.range:null;o&&g&&i.push({source:O(o,s,t,f),target:O(g,s,t,f),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function $(e,n,r,y,c,i,s,t,f){for(let[u,d]of Object.entries(n)){if(I.has(u)||typeof d!="object"||d===null||Array.isArray(d))continue;let l=d,a=`${e}/${u}`,p=y.get(u),o=p?p.split(".").pop()??p:"Unknown",g={};for(let[b,T]of Object.entries(l))(typeof T!="object"||T===null)&&(g[b]=T);c.push({id:a,label:`${o} (embedded)`,type:"Instance",namespace:s,properties:g});let h=s&&t?`${s}/${u}@${t}`:u;i.push({source:e,target:a,type:"propertyValue",label:u,propertyId:r.has(u)?h:void 0}),p&&i.push({source:a,target:O(o,s,t,f),type:"instanceOf",label:"type (inferred)"}),$(a,l,r,y,c,i,s,t,f)}}function U(e){return!(!e||e.includes(" ")||e.includes(`
2
- `)||e.startsWith("http://")||e.startsWith("https://")||/^\d{4}-\d{2}/.test(e)||/^\d+(\.\d+)?$/.test(e))}function O(e,n,r,y){if(e.includes("@")&&e.includes("/"))return e;if(e.includes(".")){let c=e.indexOf("."),i=e.substring(0,c),s=e.substring(c+1);if(y){let t=y.get(i);if(t)return`${t.publisher}/${t.package_}/${s}@${t.version}`}return n&&r?`${n}/${s}@${r}`:s}return n&&r?`${n}/${e}@${r}`:e}function V(e){if(!e.expiresAt)return!1;let n=new Date(e.expiresAt),r=300*1e3;return n.getTime()<=Date.now()+r}function H(e){return!!e.accessToken&&!V(e)}function q(e){let n=e.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!n)throw new Error("Publisher host cannot be empty");return n}export{A as a,v as b,N as c,V as d,H as e,q as f};
@@ -1,42 +0,0 @@
1
- import{a as Q}from"./chunk-MYITGTGJ.js";import{a as V,b as P,c as ee}from"./chunk-RGMZAKJV.js";var k=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 Z=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,a]of Object.entries(e.body))a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(t,a,i);return i}validateEntity(e,i,t){for(let[a,s]of Object.entries(i)){let r=s?.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=a,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)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validateEntity(`${e}.${a}`,s,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[a,s]of Object.entries(e.body)){let r=h.VALID_AUGMENTATION_PATTERN.test(a);if(!r&&!t&&h.RESERVED_WORDS.has(a.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=a,n.message=`Entity name '${a}' 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(a)){let n;/^\d/.test(a)?n="Entity names must start with a letter, not a number.":a.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=a,l.message=`Invalid entity name '${a}'. ${n}`,l.suggestion=n,i.push(l)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validatePropertyNames(a,s,i)}return i}validatePropertyNames(e,i,t){for(let a of Object.keys(i))if(!h.VALID_PROPERTIES.has(a)&&!h.VALID_PROPERTY_NAME_PATTERN.test(a)){let s=new g;s.ruleType=this.ruleName,s.severity="Warning",s.entityName=e,s.propertyName=a,s.message=`Property name '${a}' in entity '${e}' doesn't follow naming conventions.`,s.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(s)}}};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[a,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)){let r=s,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=a,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 a=i.type;if(a){let s=a.toString();return s==="Class"||s.endsWith(".Class")}}return!1}};var j=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let i=[];for(let[t,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a)||t.includes("."))continue;let s=a,r="type"in s,n=s.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=[],a=new P(i),s=await this.buildPropertyRangeMap(e,a);for(let[r,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(r,n,void 0,s,a,e,t,0);return t}pickRange(e,i,t){if(e.length===0)return;if(e.length===1)return e[0].range;let a=i.indexOf(".");if(a>0){let s=i.substring(0,a),r=e.find(n=>n.declaringAlias===s);if(r)return r.range}if(t){let s=this.localName(t),r=e.find(n=>this.localName(n.domain)===s);if(r)return r.range}return e[0].range}async checkEmbeddedTypes(e,i,t,a,s,r,n,l){if(l>0){let p=i.type;if(p!=null){let c=await this.validateEmbeddedType(e,String(p),t,s,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=a.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,a,s,r,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,c,f,a,s,r,n,l+1)}}async validateEmbeddedType(e,i,t,a,s){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 a.isSubclassOfAsync(i,t,s)||(r!==i||n!==t)&&await a.isSubclassOfAsync(r,n,s))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,a=await i.buildEntityIndexAsync(e),s=new Map;for(let[r,n]of a){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=s.get(d),A=r.includes(".");(!b||A&&!b.entityName.includes("."))&&s.set(d,{entityName:r,domain:f,range:y})}for(let r of s.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 a=await i.getAllDocumentsAsync();for(let[s,r]of Object.entries(e.metadata.imports))for(let n of r)if(!await i.getHighestCompatibleVersionAsync(s,n)){let o=await this.determineImportErrorAsync(i,s,n,a),p=new g;p.ruleType=this.ruleName,p.severity="Error",p.message=o.message,p.suggestion=o.suggestion,p.entityName=`Import: ${s}/${n.packageName}`,p.actualValue=n.toString(),p.expectedValue=o.expectedValue,t.push(p)}return t}async determineImportErrorAsync(e,i,t,a){let s=await e.getDocumentsByNamespaceAsync(i,t.packageName);if(s.length===0){let o=a.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=s.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 a=i.map(r=>({package:r,distance:this.levenshteinDistance(e.toLowerCase(),r.toLowerCase())})).sort((r,n)=>r.distance-n.distance),s=Math.max(3,Math.floor(e.length*.4));return a.filter(r=>r.distance<=s).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,a=i.length,s=Array(t+1).fill(null).map(()=>Array(a+1).fill(0));for(let r=0;r<=t;r++)s[r][0]=r;for(let r=0;r<=a;r++)s[0][r]=r;for(let r=1;r<=t;r++)for(let n=1;n<=a;n++){let l=e[r-1]===i[n-1]?0:1;s[r][n]=Math.min(Math.min(s[r-1][n]+1,s[r][n-1]+1),s[r-1][n-1]+l)}return s[t][a]}};var N=class{ruleName="UnresolvedReference";async validateAsync(e,i){let t=[],a=new P(i),s=await a.buildEntityIndexAsync(e),r=new Set;for(let[n,l]of s.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,a,t)}return t}async validateReferenceValue(e,i,t,a,s,r){if(t!=null){if(typeof t=="string")await s.resolveEntityAsync(t,a)||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 s.resolveEntityAsync(l,a)||r.push(this.createUnresolvedReferenceError(e,`${i}[${n}]`,l)))}}}createUnresolvedReferenceError(e,i,t){let a=`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`,s=new g;return s.ruleType=this.ruleName,s.severity="Warning",s.entityName=e,s.propertyName=i,s.actualValue=t,s.message=`Reference to '${t}' could not be resolved`,s.suggestion=a,s.expectedValue="A valid entity reference that exists in the current document or imported namespaces",s}getPropertyValue(e,i){let t=e[i];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,i){let t=[],a=new Map,s=[];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){s.push({doc:o,import:l,publisher:r});let p=await this.getTransitiveImportsAsync(i,o,new Set);s.push(...p.map(c=>({doc:c,import:null,publisher:r})))}}for(let{doc:r,import:n}of s){let l=r.metadata?.namespace_?.toString()??"unknown";for(let o of Object.keys(r.body))a.has(o)||a.set(o,[]),a.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",a,r,t),this.checkAmbiguousReference(l,"subClassOf",a,r,t),this.checkAmbiguousReference(l,"subPropertyOf",a,r,t),this.checkAmbiguousReference(l,"domain",a,r,t),this.checkAmbiguousReference(l,"range",a,r,t)}return t}checkAmbiguousReference(e,i,t,a,s){let r=e[i];if(!r)return;let n=V(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("/"),A=d[d.length-1]?.split("@")[0]??"alias";c.push(`${A}.${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=a,y.propertyName=i,y.actualValue=l,y.message=`Type '${l}' is ambiguous. It's defined in: ${p}`,y.suggestion=m,s.push(y)}}}async getTransitiveImportsAsync(e,i,t){let a=[],s=i.metadata?.namespace_?.toString()??"";if(t.has(s))return a;if(t.add(s),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){a.push(o);let p=await this.getTransitiveImportsAsync(e,o,t);a.push(...p)}}return a}};var $=class{ruleName="ClassHierarchyCycle";async validateAsync(e,i){let t=[],a=new Map,s=new Set;await this.buildClassHierarchy(e,i,a,s);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,a);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,a){let s=e.metadata?.namespace_?.toString()??"";if(!(s&&a.has(s))){s&&a.add(s);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=V(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,a)}}}detectCycle(e,i){let t=[],a=new Set;return this.detectCycleRecursive(e,i,t,a)}detectCycleRecursive(e,i,t,a){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(a.has(e))return null;t.push(e),a.add(e);let s=i.get(e);if(s)for(let r of s){let n=this.detectCycleRecursive(r,i,t,a);if(n)return n}return t.pop(),null}};var T=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,i){let t=[],a=new Map,s=new Set;await this.buildPropertyHierarchy(e,i,a,s);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,a);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,a){let s=e.metadata?.namespace_?.toString()??"";if(!(s&&a.has(s))){s&&a.add(s);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=V(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,a)}}}detectCycle(e,i){let t=[],a=new Set;return this.detectCycleRecursive(e,i,t,a)}detectCycleRecursive(e,i,t,a){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(a.has(e))return null;t.push(e),a.add(e);let s=i.get(e);if(s)for(let r of s){let n=this.detectCycleRecursive(r,i,t,a);if(n)return n}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,i){let t=[];for(let[a,s]of Object.entries(e.body)){if(typeof s!="object"||s===null||Array.isArray(s))continue;let r=s,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=a,p.propertyName="range",p.message=`Property '${a}' 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","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}async validateAsync(e,i){let t=[],a=new Set;for(let[s,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&a.add(s)}for(let[s,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=V(r.subClassOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInClasses.has(p)||a.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=s,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 a=null,s=t;if(t.includes(".")){let r=t.split(".",2);a=r[0],s=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(a!==null&&l.alias!==a)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=a!==null?s:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(u==="Class"||u&&u.endsWith(".Class"))return!0}let m=new Set;if(await this.isClassAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isClassAvailableInImportsRecursive(e,i,t,a){let s=e.metadata.namespace_?.toString()??"";if(s&&a.has(s)||(s&&a.add(s),!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==="Class"||m&&m.endsWith(".Class"))return!0}if(await this.isClassAvailableInImportsRecursive(o,i,t,a))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=[],a=new Set;for(let[s,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")&&a.add(s)}for(let[s,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=V(r.subPropertyOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInProperties.has(p)||a.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=s,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 a=null,s=t;if(t.includes(".")){let r=t.split(".",2);a=r[0],s=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(a!==null&&l.alias!==a)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=a!==null?s: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,a){let s=e.metadata.namespace_?.toString()??"";if(s&&a.has(s)||(s&&a.add(s),!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,a))return!0}}return!1}};var W=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,i){let t=[],a=e.metadata.namespace_?.toString();if(!a)return t;let s=new Map,r=new Set;await this.buildImportGraph(e,i,s,r);let n=this.detectCycle(a,s);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,a){let s=e.metadata.namespace_?.toString()??"";if(!(!s||a.has(s))&&(a.add(s),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,a)}r.length>0&&t.set(s,r)}}detectCycle(e,i){let t=[],a=new Set;return this.detectCycleRecursive(e,i,t,a)}detectCycleRecursive(e,i,t,a){let s=t.indexOf(e);if(s>=0){let n=t.slice(s);return n.push(e),n}if(a.has(e))return null;t.push(e),a.add(e);let r=i.get(e);if(r)for(let n of r){let l=this.detectCycleRecursive(n,i,t,a);if(l)return l}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,i){let t=[],a=new Set;for(let[s,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isPropertyType(l)&&a.add(s)}for(let[s,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(a.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=s,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,a){if(!e.metadata.imports)return!1;for(let[s,r]of Object.entries(e.metadata.imports))for(let n of r){if(a!==null&&n.alias!==a)continue;let l=await i.getHighestCompatibleVersionAsync(s,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,a){let s=e.metadata.namespace_?.toString()??"";if(s&&a.has(s)||(s&&a.add(s),!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,a))return!0}}return!1}};var _=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=[],a=new Set;for(let[s,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isPropertyType(l)&&a.add(s)}for(let[s,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(a.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} '${s}' 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=s,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,a){if(!e.metadata.imports)return!1;for(let[s,r]of Object.entries(e.metadata.imports))for(let n of r){if(a!==null&&n.alias!==a)continue;let l=await i.getHighestCompatibleVersionAsync(s,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,a){let s=e.metadata.namespace_?.toString()??"";if(s&&a.has(s)||(s&&a.add(s),!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,a))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,i){let t=[],a=new Set,s=[];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){s.push(r);let c=this.getPropertyValue(l,"range");c&&this.xsdTypes.has(c)&&a.add(c)}}if(a.size>0&&!await this.checkXsdImportAsync(e.metadata,i)){let n=Array.from(a).sort().join(", "),l=s.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 a=e.namespace_?.toString()??"";if(a&&t.has(a))return!1;a&&t.add(a);for(let[,s]of Object.entries(e.imports))for(let r of s)if(r.packageName==="xsd"||r.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[s,r]of Object.entries(e.imports))for(let n of r){let l=await i.getHighestCompatibleVersionAsync(s,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=[],a=await this.buildEntitySourceMapAsync(e,i),s=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,a,s,e,t);return t}async buildEntitySourceMapAsync(e,i){let t=new Map,a=new Set;for(let s of Object.keys(e.body)){let r=e.metadata.namespace_?.toString()??"";t.has(s)||t.set(s,[]),t.get(s).push(`(local:${r})`)}if(e.metadata.imports)for(let[s,r]of Object.entries(e.metadata.imports))for(let n of r){let l=await i.getHighestCompatibleVersionAsync(s,n);l&&await this.collectEntitiesRecursivelyAsync(l,t,a,i)}return t}async collectEntitiesRecursivelyAsync(e,i,t,a){let s=e.metadata.namespace_?.toString()??"";if(!t.has(s)){t.add(s);for(let r of Object.keys(e.body)){i.has(r)||i.set(r,[]);let n=i.get(r);n.includes(s)||n.push(s)}if(e.metadata.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await a.getHighestCompatibleVersionAsync(r,l);o&&await this.collectEntitiesRecursivelyAsync(o,i,t,a)}}}async buildDatatypePropertyNamesAsync(e,i){let t=new Set,a=new Set;if(await this.collectDatatypePropertiesAsync(e,t,a,i),e.metadata.imports)for(let[s,r]of Object.entries(e.metadata.imports))for(let n of r){let l=await i.getHighestCompatibleVersionAsync(s,n);l&&await this.collectDatatypePropertiesAsync(l,t,a,i)}return t}async collectDatatypePropertiesAsync(e,i,t,a){let s=e.metadata.namespace_?.toString()??"";if(!t.has(s)){t.add(s);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 a.getHighestCompatibleVersionAsync(r,l);o&&await this.collectDatatypePropertiesAsync(o,i,t,a)}}}validateEntityReferences(e,i,t,a,s,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,s,!0,o))}}this.validatePropertyValue(e,o,l,t,a,s,r)}}validatePropertyValue(e,i,t,a,s,r,n){if(t==null)return;let l=i&&i.includes(".")?i.substring(i.lastIndexOf(".")+1):i,o=!!l&&s.has(l);if(typeof t=="string"&&!t.includes(".")&&!o){let p=a.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],a,s,r,n)}else if(typeof t=="object"&&!Array.isArray(t)){let p=i?`${e}.${i}`:e;this.validateEntityReferences(p,t,a,s,r,n)}}createAmbiguityError(e,i,t,a,s,r,n){let l=[];for(let f of a){let d=this.findAliasForNamespace(s,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=a.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,a]of Object.entries(e.metadata.imports))for(let s of a)if(`${t}/${s.packageName}@${s.version}`===i&&s.alias)return s.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=[],a=new Set;for(let[s,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isValidRangeTargetType(l)&&a.add(s)}for(let[s,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)||a.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 '${s}' 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=s,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 a=null,s=t;if(t.includes(".")){let r=t.split(".",2);a=r[0],s=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(a!==null&&l.alias!==a)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=a!==null?s: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,a){let s=e.metadata.namespace_?.toString()??"";if(s&&a.has(s)||(s&&a.add(s),!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,a))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=[],a=new Map,s=new P(i);await s.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)||(a.has(y)||a.set(y,[]),a.get(y).push(r))}}for(let[r,n]of a)if(!await s.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=[],a=new P(i),s=new ee(a),r=await a.buildEntityIndexAsync(e),n=await this.buildPropertyMetadataAsync(e,i,a,r);for(let[l,o]of Object.entries(e.body))typeof o=="object"&&o!==null&&!Array.isArray(o)&&await this.scanEntityForObjectProperties(o,l,"",n,a,s,e,t);return t}async scanEntityForObjectProperties(e,i,t,a,s,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=a.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 A=d.split(",").map(v=>v.trim()).filter(v=>v.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
- - ${A[0]}
35
- ${A.slice(1).map(v=>` - ${v}`).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 s.resolveEntityAsync(d,n);if(b)y.range&&(await this.validateRangeType(b,y.range,s,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 A=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: ${A}`,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,a,s,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 A=b.trim(),v=await s.resolveEntityAsync(A,n);if(v){if(y.range&&!await this.validateRangeType(v,y.range,s,n)){let Y=t?`${t}.${o}[${d}]`:`${o}[${d}]`;l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${o}' expects a ${y.range}, but '${A}' may not be a ${y.range}`,suggestion:`Ensure '${A}' is defined with appropriate type`,entityName:i,propertyName:`${o}[${d}]`,propertyPath:Y,actualValue:A,expectedValue:y.range})}}else{let J=y.range??"entity",Y=t?`${t}.${o}[${d}]`:`${o}[${d}]`;l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${o}' references '${A}' which is not defined or imported`,suggestion:`Define '${A}' or import a namespace that contains it. Expected range: ${J}`,entityName:i,propertyName:`${o}[${d}]`,propertyPath:Y,actualValue:A,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let A=t?`${t}.${o}[${d}]`:`${o}[${d}]`;await this.scanEntityForObjectProperties(b,i,A,a,s,r,n,l)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!a.has(o)){let u=t?`${t}.${o}`:o;await this.scanEntityForObjectProperties(p,i,u,a,s,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,a,s,r,n,l)}}}}async validateRangeType(e,i,t,a){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,a))return!0}}return!1}async buildPropertyMetadataAsync(e,i,t,a){let s=new Map;for(let[r,n]of a){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)}}s.set(r,m)}}}return s}};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=[],a=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"))&&a.set(r,l)}let s=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,a,s,t)}return t}async buildCompleteClassHierarchyAsync(e,i){let t=new Map,a=new Set,s=async(n,l)=>{if(!a.has(l)){a.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=V(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 s(m,y)}}catch{}}},r=e.metadata.namespace_?.toString()??"unknown";return await s(e,r),t}validateEntityProperties(e,i,t,a,s,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=a.get(o);if(!c)continue;let m=this.getPropertyValue(c,"domain");if(m){if(!this.isTypeCompatibleWithDomain(t,m,s)){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,a,s,r)}else{let f=this.getPropertyValue(c,"range");if(f){let d=`${i}.${n}`;this.validateEntityProperties(y,d,f,a,s,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,a,s,r)}else{let b=this.getPropertyValue(c,"range");if(b){let A=`${i}.${n}[${y}]`;this.validateEntityProperties(f,A,b,a,s,r)}}}}}}}isTypeCompatibleWithDomain(e,i,t){if(e===i)return!0;let a=new Set,s=[e];for(;s.length>0;){let r=s.shift();if(a.has(r))continue;a.add(r);let n=t.get(r);if(n)for(let l of n){if(l===i)return!0;s.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 a=e[t];return this.extractFirstValue(a)}}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=[],a=new Map;for(let[s,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")&&a.set(s,n)}for(let[s,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=a.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:s,propertyName:o,message:`Property '${o}' is a DatatypeProperty with range '${f}' but instance '${s}' 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:s,propertyName:o,message:`Property '${o}' expects type '${f}' but instance '${s}' 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:s,propertyName:`${o}[${d}]`,message:`ObjectProperty '${o}' array item ${d} in instance '${s}' 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:s,propertyName:o,message:`ObjectProperty '${o}' in instance '${s}' 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 a=[];for(let s of t)a.push(s?.toString()??"");return a.length>0?a[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=[],a=new Map,s=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")){s.add(n);break}}else{let c=p?.toString();(c==="Class"||c&&c.endsWith(".Class"))&&s.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&&(a.has(y)||a.set(y,[]),a.get(y).push(n))}}else{let c=p?.toString();c&&c.trim().length>0&&(this.isDefinitionType(c)||(a.has(c)||a.set(c,[]),a.get(c).push(n)))}this.checkNestedTypes(o,n,a,n)}let r=new P(i);for(let[n,l]of a){if(this.builtInClasses.has(n)||s.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,a){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let s=e,r=s.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(a))}else{let l=r?.toString();l&&l.trim().length>0&&!n.has(l)&&(t.has(l)||t.set(l,[]),t.get(l).push(a))}}for(let[n,l]of Object.entries(s))if(n!=="type"){let o=`${a}.${n}`;this.checkNestedTypes(l,i,t,o)}}else if(Array.isArray(e))for(let s=0;s<e.length;s++){let r=`${a}[${s}]`;this.checkNestedTypes(e[s],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 a=t?.toString();if(a==="Class"||a&&a.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 G=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new Q,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 W,new M,new _,new L,new H,new U,new F,new q,new X,new z,new B]}async validateAsync(e,i){let t=new k;for(let a of this.documentRules)try{let s=a.validate(e);this.addErrorsToResult(t,s)}catch(s){let r=new g;r.ruleType=a.ruleName,r.severity="Error",r.message=`Validation rule '${a.ruleName}' failed: ${s instanceof Error?s.message:String(s)}`,t.errors.push(r)}if(i){let a=[];for(let s of this.repositoryRules)try{let r=await s.validateAsync(e,i);this.addErrorsToResult(t,r)}catch(r){let n=r instanceof Error?r.message:String(r);a.push({ruleName:s.ruleName,cause:n})}if(a.length>0){let s=new Map;for(let{ruleName:r,cause:n}of a){let l=s.get(n);l?l.push(r):s.set(n,[r])}for(let[r,n]of s){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 a=new k;a.isValid=!1;for(let s of t.errors){let r=new g;r.ruleType="ParseError",r.severity="Error",r.lineNumber=s.line,r.column=s.column,r.message=s.message,s.keyName&&(r.entityName=s.keyName),s.errorType==="DuplicateKey"&&(r.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),a.errors.push(r)}return a}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{k as a,R as b,g as c,Z 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,W as r,M as s,_ as t,L as u,H as v,U as w,F as x,q as y,X as z,z as A,B,G as C};
@@ -1 +0,0 @@
1
- import{a as v,b as T,c as k,d as u,g,h,i as w,j as S,k as K,l as j}from"./chunk-W6T7MOKY.js";import{a as R}from"./chunk-MYITGTGJ.js";import{b as O,c as A}from"./chunk-RGMZAKJV.js";var d=class extends T{name};var b=class extends v{value};var E=class{constructor(e){}async parseKanonaks(e){let t=[],o=await e.getAllDocumentsAsync(),n=new O(e),c=new A(n);for(let a of o){let p=a.metadata.namespace_?.toString()??"";for(let[i,m]of Object.entries(a.body)){let f=new k,y=this.resolveCanonicalEntity(i,a,p);f.namespace=y.namespace,f.name=y.name,f.statement=[];let l=await this.parseStatements(m,a,n,c,e);f.statement.push(...l),t.push(f)}}let r=new Map,s=[];for(let a of t)if(a instanceof k){let p=`${a.namespace}/${a.name}`,i=r.get(p);i?i.statement.push(...a.statement):(r.set(p,a),s.push(a))}else s.push(a);return s}resolveCanonicalEntity(e,t,o){if(!e.includes(".")||!t.metadata?.imports)return{namespace:o,name:e};let n=e.indexOf("."),c=e.substring(0,n),r=e.substring(n+1);for(let[s,a]of Object.entries(t.metadata.imports))for(let p of a)if((p.alias??p.packageName)===c){let m=p.version;return{namespace:`${s}/${p.packageName}@${m.major}.${m.minor}.${m.patch}`,name:r}}return{namespace:o,name:e}}async parseStatements(e,t,o,n,c){let r=[];if(typeof e!="object"||e===null||Array.isArray(e))return r;for(let[s,a]of Object.entries(e))try{let p=await this.getPropertyMetadata(s,t,o,c,n);if(!p)continue;let i=await this.parsePropertyValue(s,a,p,t,o,n);i&&r.push(i)}catch(p){console.error(`Error parsing property ${s}:`,p)}return r}async getPropertyMetadata(e,t,o,n,c){let r=await o.resolveEntityAsync(e,t);if(!r)return;let s=r.entity,a=s.type?.toString()??"",p=a.includes(".")?a.substring(a.lastIndexOf(".")+1):a;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(p))return;let m=c.getPropertyTypeClassification(a),f=s.range?.toString(),y;if(m==="ObjectProperty")y="ObjectProperty";else if(m==="DatatypeProperty")y="DatatypeProperty";else{let I=f&&f.includes(".")?f.substring(f.lastIndexOf(".")+1):f??"";(f?c.isKnownXsdDatatypeName(f):!1)||I==="Literal"?y="DatatypeProperty":y="ObjectProperty"}return{propertyUri:r.uri.toString(),propertyType:y,range:f,isImported:r.isImported,definedInNamespace:r.definedInNamespace}}async parsePropertyValue(e,t,o,n,c,r){let s=o.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(s,t,o,n,c,r);if(o.propertyType==="DatatypeProperty")return this.parseDatatypeValue(s,t,o);if(o.propertyType==="ObjectProperty")return this.parseObjectValue(s,t,o,n,c,r)}}parseDatatypeValue(e,t,o){if(t instanceof Date)return g.parse(e,t.toISOString());if(typeof t=="string")return g.parse(e,t);if(typeof t=="number")return h.parse(e,t);if(typeof t=="boolean"){let n=new w;return n.predicate=u.parse(e),n.object=t,n}}async parseObjectValue(e,t,o,n,c,r){if(typeof t=="string"){let s=await this.resolveReference(t,n,c);if(!s)return;let a=new S;return a.predicate=u.parse(e),a.object=s,a}if(typeof t=="object"&&!Array.isArray(t)){let s=new d;if(s.statement=await this.parseStatements(t,n,c,r,{}),s.statement.length>0){let i=new K;return i.predicate=u.parse(e),i.object=s,i}let a=[];for(let[i,m]of Object.entries(t))if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=new d;f.name=i,f.statement=await this.parseStatements(m,n,c,r,{}),a.push(f)}else if(typeof m=="string"){let f=await this.resolveReference(m,n,c);f&&a.push(f)}if(a.length>0){let i=new j;return i.predicate=u.parse(e),i.object=a,i}let p=new K;return p.predicate=u.parse(e),p.object=s,p}}async parseListValue(e,t,o,n,c,r){let s=[],a=o.propertyType==="DatatypeProperty";for(let i of t){if(a&&(typeof i=="string"||typeof i=="number"||typeof i=="boolean")){let m=new b;m.value=i,s.push(m);continue}if(a&&i instanceof Date){let m=new b;m.value=i.toISOString(),s.push(m);continue}if(typeof i=="string"){let m=await this.resolveReference(i,n,c);m&&s.push(m)}else if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let m=new d;m.statement=await this.parseStatements(i,n,c,r,{}),s.push(m)}}let p=new j;return p.predicate=u.parse(e),p.object=s,p}async resolveReference(e,t,o){let n=await o.resolveEntityAsync(e,t);if(n){let r=new u;return r.subject=n.uri,r}let c=t.metadata?.namespace_;if(c){let{KanonakUri:r}=await import("./KanonakUri-4VJGV3FN.js"),s=c.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let p=e.indexOf("."),i=e.substring(0,p),m=e.substring(p+1);if(t.metadata?.imports){for(let[f,y]of Object.entries(t.metadata.imports))for(let l of y)if((l.alias??l.packageName)===i){let P=new u;return P.subject=new r(f,l.packageName,m,l.version),P}}}let a=new u;return a.subject=new r(c.publisher,c.package_,e,s),a}return null}async saveKanonaks(e,t){let o=new Map;for(let n of e)n instanceof k&&n.namespace&&(o.has(n.namespace)||o.set(n.namespace,[]),o.get(n.namespace).push(n));for(let[n,c]of o){let r=await this.convertKanonaksToDocument(n,c),s=`${n.split("@")[0]}.yml`;await t.saveDocumentAsync(r,s)}}async serializeToYaml(e,t){let o=e.filter(r=>r instanceof k&&r.namespace===t);if(o.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let n=await this.convertKanonaksToDocument(t,o);return new R().save(n)}async convertKanonaksToDocument(e,t){let n={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let r=[];for(let s of Object.values(this.imports))r.push(...s);return r}},body:{}},c=new Map;for(let r of t){let s={};for(let a of r.statement){let[p,i]=this.convertStatementToProperty(a);p&&i!==null&&i!==void 0&&(s[p]=i),this.collectImportsFromStatement(a,e,c)}n.body[r.name]=s}return n}convertStatementToProperty(e){if(e instanceof g)return[e.predicate.subject.name,e.object];if(e instanceof h)return[e.predicate.subject.name,e.object];if(e instanceof w)return[e.predicate.subject.name,e.object];if(e instanceof S)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof j){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof K){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let o of e)o instanceof u?t.push(o.subject.name):o instanceof d&&t.push(this.convertEmbeddedKanonakToValue(o));return t}convertEmbeddedKanonakToValue(e){let t={};for(let o of e.statement){let[n,c]=this.convertStatementToProperty(o);n&&c!==null&&c!==void 0&&(t[n]=c)}return t}collectImportsFromStatement(e,t,o){}};export{d as a,b,E as c};
@@ -1 +0,0 @@
1
- import{a as h}from"./chunk-CRR4BQKR.js";import{c as v,d as m,g as j,j as p,k as S,l as k}from"./chunk-W6T7MOKY.js";function oe(t,n,e,r){let a=D(t);if(a.length>0){let i=a.find(f=>u(f.format,n)&&u(f.variant,e));return i?{transformation:i.transformation,source:"instance"}:void 0}let o=new Set,s=U(t);for(;s.length>0;){let i=s.shift(),f=x(i.subject);if(o.has(f))continue;o.add(f);let c=R(r,i.subject);if(!c)continue;let K=D(c).find(d=>u(d.format,n)&&u(d.variant,e));if(K)return{transformation:K.transformation,source:{publisher:i.subject.publisher,package_:i.subject.package_,name:i.subject.name}};for(let d of T(c))s.push(d)}let l={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!o.has(x(l))){let i=R(r,l);if(i){let c=D(i).find(g=>u(g.format,n)&&u(g.variant,e));if(c)return{transformation:c.transformation,source:l}}}}function D(t){let n=[];for(let e of t.statement)if(e instanceof k&&b(e,"kanonak.org","derivation","derivations"))for(let r of e.object??[]){if(!(r instanceof h))continue;let a=y(r);a&&n.push(a)}return n}function y(t){let n,e,r;for(let a of t.statement)a instanceof p?b(a,"kanonak.org","derivation","format")?n=E(a):b(a,"kanonak.org","derivation","variant")&&(e=E(a)):a instanceof S&&b(a,"kanonak.org","derivation","transformation")&&(r=_(a.object));if(!(!n||!r))return e||(e={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:n,variant:e,transformation:r}}function _(t){let n,e,r,a;for(let o of t.statement){if(!(o instanceof j))continue;let s=o.predicate?.subject?.name;s==="publisher"?n=o.object:s==="package"?e=o.object:s==="version"?r=o.object:s==="name"&&(a=o.object)}if(!(!n||!e||!r||!a))return{publisher:n,package_:e,version:r,name:a}}function U(t){let n=[];for(let e of t.statement)e instanceof p&&e.predicate?.subject?.name==="type"&&e.object instanceof m&&n.push(e.object);return n}function T(t){let n=[];for(let e of t.statement)if(e instanceof p){if(e.predicate?.subject?.name!=="subClassOf")continue;e.object instanceof m&&n.push(e.object)}else if(e instanceof k){if(e.predicate?.subject?.name!=="subClassOf")continue;for(let r of e.object??[])r instanceof m&&n.push(r)}return n}function R(t,n){for(let e of t){if(!(e instanceof v)||e.name!==n.name)continue;if((e.namespace||"").startsWith(`${n.publisher}/${n.package_}@`))return e}}function b(t,n,e,r){let a=t.predicate?.subject;return a?a.publisher===n&&a.package_===e&&a.name===r:!1}function E(t){let n=t.object.subject;return{publisher:n.publisher,package_:n.package_,name:n.name}}function u(t,n){return t.publisher===n.publisher&&t.package_===n.package_&&t.name===n.name}function x(t){return`${t.publisher}/${t.package_}/${t.name}`}export{oe as a};
@@ -1 +0,0 @@
1
- import{b as f,c as i,g as p,h as d,i as y,j as s,k as l,l as g}from"./chunk-W6T7MOKY.js";function K(t){return`${t.publisher}/${t.package_}/${t.name}`}function c(t,n){return t.publisher===n.publisher&&t.package_===n.package_&&t.name===n.name}function b(t,n){if(!(t instanceof f))return!1;for(let e of t.statement)if(e.predicate?.subject?.name==="type"&&e instanceof s){let r=e.object;if(c(r.subject,n))return!0}return!1}function D(t,n){let e=[];for(let o of t)o instanceof i&&b(o,n)&&e.push(o);return e}function S(t,n){let e=n.version,o=e&&typeof e.major=="number"?`${n.publisher}/${n.package_}@${e.major}.${e.minor}.${e.patch}`:void 0;for(let r of t){if(!(r instanceof i)||r.name!==n.name)continue;let u=r.namespace||"";if(o!==void 0){if(u===o)return r}else if(u.startsWith(`${n.publisher}/${n.package_}@`))return r}}function a(t,n){for(let e of t.statement){let o=e.predicate;if(o?.subject&&c(o.subject,n))return e}}function k(t,n){let e=a(t,n);if(e&&(e instanceof p||e instanceof d||e instanceof y))return e.object}function h(t,n){let e=k(t,n);return typeof e=="string"?e:void 0}function j(t,n){let e=a(t,n);if(e instanceof s)return e.object.subject}function U(t,n){let e=a(t,n);if(e instanceof l)return e.object}function E(t,n){let e=a(t,n);return e instanceof g?e.object??[]:[]}var m=class{constructor(n,e){this.doc=n;this.broader=e}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(n){return this.broader.getDocumentAsync(n)}async getDocumentsByNamespaceAsync(n,e){return this.broader.getDocumentsByNamespaceAsync(n,e)}async getHighestCompatibleVersionAsync(n,e){return this.broader.getHighestCompatibleVersionAsync(n,e)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(n){return this.broader.getDocumentContentAsync(n)}async getDocumentUriAsync(n){return this.broader.getDocumentUriAsync(n)}};export{K as a,c as b,b as c,D as d,S as e,k as f,h as g,j as h,U as i,E as j,m as k};
@@ -1 +0,0 @@
1
- import{a as p}from"./chunk-FUUTGGJS.js";var f=class{resourceResolver;constructor(r){this.resourceResolver=r}async buildFromNameAsync(r,o){return(await this.resourceResolver.resolveEntityAsync(r,o))?.uri??null}buildFromName(r,o,n){if(r.includes(".")){let t=r.split("."),a=t[0],i=t[1],c=this.findPackageNameForAlias(n,a);if(c){for(let u of o.values())if(u.entityName===i&&u.uri.package_===c)return u.uri}return null}let s=o.get(r);return s?s.uri:null}create(r,o,n,s){return new p(r,o,n,s)}findPackageNameForAlias(r,o){if(!r.metadata.imports)return null;for(let[n,s]of Object.entries(r.metadata.imports))for(let t of s)if(t.alias===o||!t.alias&&t.packageName===o)return t.packageName;return null}};function g(e){if(!e||e.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let r=e.trim(),o=r.split("/");if(o.length===1){let n=o[0];if(!n)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(n.includes("@"))throw new Error(`Invalid Kanonak address: "${e}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:n}}if(o.length===2){let[n,s]=o;if(!n||!s)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher/package[@version].`);let t=s.indexOf("@");if(t===-1)return{kind:"package",publisher:n,package_:s};let a=s.substring(0,t),i=s.substring(t+1);if(!a||!i)throw new Error(`Invalid Kanonak address: "${e}". Expected publisher/package[@version].`);let c=y(i);return{kind:"package",publisher:n,package_:a,version:c}}return{kind:"resource",uri:p.parse(r)}}function d(e){switch(e.kind){case"publisher":return e.publisher;case"package":return e.version?`${e.publisher}/${e.package_}@${e.version.major}.${e.version.minor}.${e.version.patch}`:`${e.publisher}/${e.package_}`;case"resource":return e.uri.toString()}}function y(e){let r=e.split(".").map(Number);return h(r[0]||0,r[1]||0,r[2]||0)}function h(e,r,o){return{major:e,minor:r,patch:o,toString:()=>`${e}.${r}.${o}`,equals:n=>!n||typeof n!="object"?!1:n.major===e&&n.minor===r&&n.patch===o,getHashCode:()=>e<<20|r<<10|o,compareTo:n=>e!==n.major?e-n.major:r!==n.minor?r-n.minor:o-n.patch}}async function R(e,r){let o=[],n=await e.getAllDocumentsAsync();for(let s of n){let t=s.metadata.namespace_;if(!t)continue;let a=t.publisher,i=t.package_,c=t.version?`${t.version.major}.${t.version.minor}.${t.version.patch}`:"0.0.0";for(let[u,l]of Object.entries(s.body)){if(!l||typeof l!="object")continue;let m=l.type;!m||typeof m!="string"||m!=="Package"&&b(m,r)&&o.push({entityName:u,entity:l,documentNamespace:`${a}/${i}@${c}`,publisher:a,package_:i,version:c})}}return o}function b(e,r){let o=k(e),n=k(r);return o===n}function k(e){let r=e.lastIndexOf(".");if(r!==-1)return e.substring(r+1);let o=e.lastIndexOf("/");return o!==-1?e.substring(o+1):e}export{f as a,g as b,d as c,R as d};
@@ -1 +0,0 @@
1
- import{a as y}from"./chunk-FUUTGGJS.js";function h(p){if(Array.isArray(p))return p.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=p?.toString();return e?[e]:[]}var k=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let s=t.metadata?.namespace_?.toString()??"unknown",n=this.cache.get(s);if(n){let a=n.get(e);if(a)return a}let r=await this.buildEntityIndexAsyncInternal(t,new Set,"");return this.cache.set(s,r),r.get(e)??null}async resolveAllEntitiesAsync(e,t){let s=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let n=e.split("."),r=n[0],a=n[1],c=await this.findDocumentForAlias(t,r);return c?await this.resolveAllEntitiesAsync(a,c):[]}return s.filter(n=>n.entityName===e)}async buildAllEntitiesIndexAsync(e,t,s){let n=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),t.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),n;t.add(r);let a=s.length===0?r:`${s} \u2192 ${r}`;for(let[c,o]of Object.entries(e.body))if(!c.includes(".")&&o&&typeof o=="object"&&!Array.isArray(o)){let i=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.push({entityName:c,uri:new y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,c,i),entity:o,definedInNamespace:r,isImported:s.length>0,importPath:a})}if(this.logger?.debug?.(`Collected ${n.length} entities from ${r}`),e.metadata?.imports){let c=Object.values(e.metadata.imports).reduce((o,i)=>o+i.length,0);this.logger?.debug?.(`Processing ${c} import(s) for ${r}`);for(let[o,i]of Object.entries(e.metadata.imports))for(let g of i)try{this.logger?.debug?.(`Resolving import: ${o}/${g.packageName}`);let l=await this.repository.getHighestCompatibleVersionAsync(o,g);if(l){this.logger?.debug?.(`Successfully loaded import: ${l.metadata?.namespace_?.toString()}`);let u=await this.buildAllEntitiesIndexAsync(l,t,a);n.push(...u),this.logger?.debug?.(`Added ${u.length} entities from import ${l.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${o}/${g.packageName}`)}catch(l){let u=l;throw this.logger?.error?.(`Failed to process import ${o}/${g.packageName} for namespace ${r}. Error: ${u.message}`,u),new Error(`Failed to process import ${o}/${g.packageName} for namespace ${r}. See inner exception for details.`,{cause:l})}}return n}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"")}async buildEntityIndexAsyncInternal(e,t,s){let n=new Map,r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${r}`),t.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),n;t.add(r);let a=s.length===0?r:`${s} \u2192 ${r}`,c=0;for(let[o,i]of Object.entries(e.body))if(!o.includes(".")&&i&&typeof i=="object"&&!Array.isArray(i)&&!n.has(o)){let g=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.set(o,{entityName:o,uri:new y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,o,g),entity:i,definedInNamespace:r,isImported:s.length>0,importPath:a}),c++}if(this.logger?.debug?.(`Indexed ${c} entities from ${r}`),e.metadata?.imports){let o=Object.values(e.metadata.imports).reduce((i,g)=>i+g.length,0);this.logger?.debug?.(`Processing ${o} import(s) for ${r}`);for(let[i,g]of Object.entries(e.metadata.imports))for(let l of g)try{this.logger?.debug?.(`Resolving import: ${i}/${l.packageName}`);let u=await this.repository.getHighestCompatibleVersionAsync(i,l);if(u){this.logger?.debug?.(`Successfully loaded import: ${u.metadata?.namespace_?.toString()}`);let d=await this.buildEntityIndexAsyncInternal(u,t,a),f=0;for(let[m,b]of d.entries())if(n.has(m)||(n.set(m,b),f++),l.alias&&!m.includes(".")){let R=`${l.alias}.${m}`;n.has(R)||(n.set(R,b),f++)}this.logger?.debug?.(`Merged ${f} entities from import ${u.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${i}/${l.packageName}`)}catch(u){let d=u;throw this.logger?.error?.(`Failed to process import ${i}/${l.packageName} for namespace ${r}. Error: ${d.message}`,d),new Error(`Failed to process import ${i}/${l.packageName} for namespace ${r}. See inner exception for details.`,{cause:u})}}return n}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[s,n]of Object.entries(e.metadata.imports))for(let r of n){if(r.alias===t)return await this.repository.getHighestCompatibleVersionAsync(s,r);if(!r.alias&&r.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(s,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,s){if(e===t)return!0;let n=new Set;return await this.isSubclassOfRecursiveAsync(e,t,s,n)}async isSubclassOfRecursiveAsync(e,t,s,n){if(n.has(e))return!1;n.add(e);let r=await this.resolveEntityAsync(e,s);if(!r?.entity)return!1;let a=r.entity.subClassOf;if(a){let c=h(a);for(let o of c)if(o===t||await this.isSubclassOfRecursiveAsync(o,t,s,n))return!0}return!1}async isSubpropertyOfAsync(e,t,s){if(e===t)return!0;let n=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,s,n)}async isSubpropertyOfRecursiveAsync(e,t,s,n){if(n.has(e))return!1;n.add(e);let r=await this.resolveEntityAsync(e,s);if(!r?.entity)return!1;let a=r.entity.subPropertyOf;if(a){let c=h(a);for(let o of c)if(o===t||await this.isSubpropertyOfRecursiveAsync(o,t,s,n))return!0}return!1}};var A=class p{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"&&p.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 t=e.includes(".")?e.split(".")[1]:e;return p.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let s=await this.resourceResolver.resolveEntityAsync(e,t);if(s){let n=s.entity.type;if(n){let r=String(n);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};export{h as a,k as b,A as c};
@@ -1,4 +0,0 @@
1
- import{CtlKanonakUriType as A,PathSegmentType as U}from"@kanonak-protocol/types/ctl/parsing/enums";var z=/\.?([a-zA-Z_][a-zA-Z0-9_-]*|\[\d+\])/g;function X(o){let e=o.split(".").map(Number),r=e[0]||0,t=e[1]||0,s=e[2]||0;return{major:r,minor:t,patch:s,toString:()=>`${r}.${t}.${s}`,equals:n=>n&&typeof n=="object"&&n.major===r&&n.minor===t&&n.patch===s,getHashCode:()=>r<<20|t<<10|s,compareTo:n=>r!==n.major?r-n.major:t!==n.minor?t-n.minor:s-n.patch}}var K=class o{scheme="kanonak";publisher;package_;version;resourceName;path;rawUri;constructor(e){this.publisher=e.publisher,this.package_=e.package_,this.version=e.version,this.resourceName=e.resourceName,this.path=e.path??[],this.rawUri=e.rawUri}get uriType(){return this.path.length>0?A.DeepLink:this.resourceName!=null?A.Resource:this.version!=null?A.VersionedPackage:this.package_!=null?A.Package:A.Publisher}get namespace_(){return this.package_==null?null:this.version==null?`${this.publisher}/${this.package_}`:`${this.publisher}/${this.package_}@${this.version}`}static parse(e){if(!e||e.trim().length===0)throw new Error("Kanonak URI string cannot be null or empty");if(!e.toLowerCase().startsWith("kanonak://"))throw new Error(`Invalid Kanonak URI: '${e}'. Must start with 'kanonak://'`);let r=e.substring(8);if(!r||r.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Publisher is required after 'kanonak://'`);let t=r.indexOf("#"),s=null,n;if(t>=0){if(n=r.substring(0,t),s=r.substring(t+1),!s||s.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Deep link path required after '#'`)}else n=r;let a,i=null,p=null,u=null,c=n.indexOf("@");if(c>=0){let l=n.substring(0,c),h=n.substring(c+1),y=l.indexOf("/");if(y<0)throw new Error(`Invalid Kanonak URI: '${e}'. Expected format: publisher/package@version/resource`);if(a=l.substring(0,y),i=l.substring(y+1),!a||a.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Publisher cannot be empty`);if(!i||i.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Package cannot be empty`);let m=h.indexOf("/");if(m<0)throw new Error(`Invalid Kanonak URI: '${e}'. CTL requires resource references (kanonak://publisher/package@version/resource)`);let g=h.substring(0,m);if(u=h.substring(m+1),!g||g.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Version required after '@'`);if(p=X(g),!u||u.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Resource name cannot be empty`)}else{let l=n.split("/");if(l.length<3)throw new Error(`Invalid Kanonak URI: '${e}'. CTL requires resource references (kanonak://publisher/package/resource)`);if(l.length>3)throw new Error(`Invalid Kanonak URI: '${e}'. Too many path segments. Expected: publisher/package/resource`);if(a=l[0],i=l[1],u=l[2],!a||a.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Publisher cannot be empty`);if(!i||i.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Package cannot be empty`);if(!u||u.trim().length===0)throw new Error(`Invalid Kanonak URI: '${e}'. Resource name cannot be empty`)}let f=[];return s!=null&&(f=Q(s,e)),new o({publisher:a,package_:i,version:p,resourceName:u,path:f,rawUri:e})}static tryParse(e){try{return o.parse(e)}catch{return null}}static isKanonakUri(e){return!!e&&e.trim().length>0&&e.toLowerCase().startsWith("kanonak://")}toString(){let e=`kanonak://${this.publisher}`;if(this.package_!=null&&(e+=`/${this.package_}`,this.version!=null&&(e+=`@${this.version}`),this.resourceName!=null&&(e+=`/${this.resourceName}`,this.path.length>0))){e+="#";let r=!0;for(let t of this.path)t.type_===U.Index?e+=`[${t.index}]`:(r||(e+="."),e+=t.name),r=!1}return e}equals(e){return e instanceof o?this.rawUri.toLowerCase()===e.rawUri.toLowerCase():!1}getHashCode(){let e=0,r=this.rawUri.toLowerCase();for(let t=0;t<r.length;t++)e=(e<<5)-e+r.charCodeAt(t),e|=0;return e}};function Q(o,e){let r=[],t=new RegExp(z.source,"g"),s=0,n;for(;(n=t.exec(o))!==null;){let a=n[1];if(a.startsWith("[")&&a.endsWith("]")){let i=a.substring(1,a.length-1),p=parseInt(i,10);if(isNaN(p))throw new Error(`Invalid Kanonak URI: '${e}'. Invalid array index: ${a}`);r.push({type_:U.Index,index:p,toString:()=>`[${p}]`})}else r.push({type_:U.Property,name:a,toString:()=>a});s+=n[0].length}if(s!==o.length)throw new Error(`Invalid Kanonak URI: '${e}'. Invalid path syntax in: ${o}`);return r}import{VersionOperator as T}from"@kanonak-protocol/types/document/models/enums";import*as F from"js-yaml";var Y=/\[([^\]]+)\]\((kanonak:\/\/[^)]+)\)/gi,Z=/\[([^\]]+)\]\(kan:\/\/([^)]+)\)/gi,J=/```[\s\S]*?```|`[^`]+`/g,ee=/^---\s*\n([\s\S]*?)\n---\s*\n/;function re(o,e,r){let t=`${o}.${e}.${r}`;return{major:o,minor:e,patch:r,toString:()=>t,equals:s=>s?.major===o&&s?.minor===e&&s?.patch===r,getHashCode:()=>o<<20|e<<10|r,compareTo:s=>o!==s.major?o-s.major:e!==s.minor?e-s.minor:r-s.patch}}function te(o,e,r,t,s){let n=t===T.Compatible?"~":t===T.Major?"^":t===T.Exact?"=":"*",a=`${e} ${n} ${r}`;return{package_:a,publisher:o,packageName:e,versionOperator:t,version:r,alias:s,get minVersion(){return r},get maxVersion(){return r},toEmbeddedObject(){let i={package:e,version:r.toString()};return s&&(i.alias=s),t!==T.Exact&&(i.match=n),i},toString(){return a}}}var L=class{parse(e,r){if(e==null)throw new Error("Content cannot be null");e.charCodeAt(0)===65279&&(e=e.substring(1));let t=ee.exec(e);return t?this.parseWithFrontmatter(e,t,r??null):this.parseInline(e,r??null)}async parseFileAsync(e){if(!e||e.trim().length===0)throw new Error("File path cannot be null or empty");let t=(await import("fs")).readFileSync(e,"utf-8");return this.parse(t,e)}parseWithFrontmatter(e,r,t){let s=r[1],n=e.substring(r[0].length),a=null,i=new Map;try{let u=F.load(s);if(!u)throw new Error("Frontmatter YAML is empty");if(!u.imports||!Array.isArray(u.imports))throw new Error("Frontmatter must contain an 'imports' sequence");let c={};for(let l of u.imports){if(!l||typeof l!="object")throw new Error("Each import entry must be a mapping with 'publisher' and 'packages'");let h=l.publisher?.toString();if(!h)throw new Error("Each import entry requires a 'publisher' property");if(!l.packages||!Array.isArray(l.packages))throw new Error(`Import entry for publisher '${h}' requires a 'packages' sequence`);c[h]||(c[h]=[]);for(let y of l.packages){if(!y||typeof y!="object")throw new Error(`Each package in publisher '${h}' must be a mapping`);let g=(y.version?.toString()??"1.0.0").split(".").map(Number),E=re(g[0]||0,g[1]||0,g[2]||0),R=y.match?.toString(),d=R==="^"?T.Major:R==="~"?T.Compatible:R==="*"?T.Any:T.Exact,k=te(h,y.package?.toString()??"",E,d,y.alias?.toString()??null);c[h].push(k)}}let f=[];for(let l of Object.values(c))f.push(...l);a={namespace_:void 0,imports:c,get allImports(){return f}},i=this.buildAliasMap(c)}catch(u){let c={displayText:"(frontmatter)",rawUri:"",startOffset:0,endOffset:r[0].length,line:1,column:1,isResolved:!1,error:`Failed to parse frontmatter: ${u.message}`,get fullMarkdownLink(){return`[${this.displayText}](${this.rawUri})`}};return S({metadata:null,rawMarkdown:n,frontmatterLength:r[0].length,filePath:t,references:[c]})}let p=this.parseMarkdownBody(n,i,r[0].length);return S({metadata:a,rawMarkdown:n,frontmatterLength:r[0].length,filePath:t,references:p})}parseInline(e,r){let t=this.parseMarkdownBody(e,new Map,0);return S({metadata:null,rawMarkdown:e,frontmatterLength:0,filePath:r,references:t})}parseMarkdownBody(e,r,t){let s=[],n=ne(e),a=new RegExp(Y.source,"gi"),i;for(;(i=a.exec(e))!==null;){if(M(i.index,n))continue;let u=i[1],c=i[2],{line:f,column:l}=N(e,i.index),h={displayText:u,rawUri:c,startOffset:i.index+t,endOffset:i.index+i[0].length+t,line:f,column:l,isResolved:!1,get fullMarkdownLink(){return`[${this.displayText}](${this.rawUri})`}};try{h.parsedUri=K.parse(c)}catch(y){h.error=y.message}s.push(h)}let p=new RegExp(Z.source,"gi");for(;(i=p.exec(e))!==null;){if(M(i.index,n))continue;let u=i[1],c=i[2],{line:f,column:l}=N(e,i.index),h=null,y=null;try{h=se(c,r)}catch(g){y=g.message}let m={displayText:u,rawUri:h??`kan://${c}`,startOffset:i.index+t,endOffset:i.index+i[0].length+t,line:f,column:l,isResolved:!1,error:y,get fullMarkdownLink(){return`[${this.displayText}](${this.rawUri})`}};if(h!=null&&y==null)try{m.parsedUri=K.parse(h)}catch(g){m.error=g.message}s.push(m)}return s.sort((u,c)=>u.startOffset-c.startOffset),s}buildAliasMap(e){let r=new Map;for(let[t,s]of Object.entries(e))for(let n of s){let a=n.alias??n.packageName;r.set(a.toLowerCase(),{publisher:t,package_:n.packageName,version:n.version})}return r}};function S(o){return{metadata:o.metadata,get hasFrontmatter(){return o.metadata!=null},rawMarkdown:o.rawMarkdown,frontmatterLength:o.frontmatterLength,filePath:o.filePath,references:o.references,get referenceCount(){return o.references.length},get allReferencesResolved(){return o.references.every(e=>e.isResolved)},get unresolvedReferences(){return o.references.filter(e=>!e.isResolved)},get errorReferences(){return o.references.filter(e=>e.error!=null)}}}function ne(o){let e=[],r=new RegExp(J.source,"g"),t;for(;(t=r.exec(o))!==null;)e.push([t.index,t.index+t[0].length]);return e}function M(o,e){for(let[r,t]of e)if(o>=r&&o<t)return!0;return!1}function N(o,e){let r=1,t=1;for(let s=0;s<e&&s<o.length;s++)o[s]===`
2
- `?(r++,t=1):t++;return{line:r,column:t}}function se(o,e){if(!o||o.trim().length===0)throw new Error("kan:// link cannot be empty");if(e.size===0)throw new Error("kan:// links require frontmatter with imports");let r=null,t=o,s=o.indexOf(".");if(s>0&&(r=o.substring(0,s),t=o.substring(s+1),!t||t.trim().length===0))throw new Error(`Resource name required after alias '${r}.'`);if(r!=null){let n=e.get(r.toLowerCase());if(!n){let a=Array.from(e.keys()).join(", ");throw new Error(`Unknown alias: '${r}'. Available: ${a}`)}return`kanonak://${n.publisher}/${n.package_}@${n.version}/${t}`}else{let n=e.values().next().value;if(!n)throw new Error(`Cannot resolve '${t}': no imports defined`);return`kanonak://${n.publisher}/${n.package_}@${n.version}/${t}`}}var oe=new Set(["kanonak.org/core-rdf","kanonak.org/core-rdfs","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]),G={Class:{publisher:"kanonak.org",package_:"core-owl"},ObjectProperty:{publisher:"kanonak.org",package_:"core-owl"},DatatypeProperty:{publisher:"kanonak.org",package_:"core-owl"},AnnotationProperty:{publisher:"kanonak.org",package_:"core-owl"},Property:{publisher:"kanonak.org",package_:"core-rdf"},Datatype:{publisher:"kanonak.org",package_:"core-rdfs"},Resource:{publisher:"kanonak.org",package_:"core-rdfs"},Literal:{publisher:"kanonak.org",package_:"core-rdfs"},Thing:{publisher:"kanonak.org",package_:"core-owl"},Nothing:{publisher:"kanonak.org",package_:"core-owl"}};function w(o){let e=o;if(e.entity&&typeof e.entity=="object"){let r=e.entity.type;if(typeof r=="string"){let t=G[r];return t?{publisher:t.publisher,package_:t.package_,name:r}:{publisher:"",package_:"",name:r}}}if(e.statement&&Array.isArray(e.statement)){for(let r of e.statement)if(r.predicate?.subject?.name==="type"&&r.object?.subject){let t=r.object.subject;if(!t.publisher&&!t.package_||t.publisher===""&&t.package_===""){let s=G[t.name];if(s)return{publisher:s.publisher,package_:s.package_,name:t.name}}return t}}return null}function $(o,e){return oe.has(`${o}/${e}`)}var b=class o{static getTypeUri(e){return w(e)}static isCoreOntologyType(e){return $(e.publisher,e.package_)}static isClassType(e){let r=w(e);return r?$(r.publisher,r.package_)&&r.name==="Class":!1}static isDatatypeType(e){let r=w(e);return r?$(r.publisher,r.package_)&&r.name==="Datatype":!1}static isDatatypePropertyType(e){let r=w(e);return r?$(r.publisher,r.package_)&&r.name==="DatatypeProperty":!1}static isObjectPropertyType(e){let r=w(e);return r?$(r.publisher,r.package_)&&r.name==="ObjectProperty":!1}static isAnnotationPropertyType(e){let r=w(e);return r?$(r.publisher,r.package_)&&r.name==="AnnotationProperty":!1}static isGenericPropertyType(e){let r=w(e);return r?$(r.publisher,r.package_)&&r.name==="Property":!1}static isAnyPropertyType(e){let r=w(e);return!r||!$(r.publisher,r.package_)?!1:r.name==="Property"||r.name==="DatatypeProperty"||r.name==="ObjectProperty"||r.name==="AnnotationProperty"}static isSchemaDefinitionType(e){let r=w(e);return!r||!$(r.publisher,r.package_)?!1:r.name==="Class"||r.name==="Property"||r.name==="DatatypeProperty"||r.name==="ObjectProperty"||r.name==="AnnotationProperty"||r.name==="Datatype"}static isInstanceOfKnownClass(e,r){if(o.isSchemaDefinitionType(e))return!1;let t=w(e);return t?r.has(t.name):!1}};import{CtlValidationErrorType as C,CtlValidationSeverity as P}from"@kanonak-protocol/types/ctl/models/enums";import{CtlKanonakUriType as q,PathSegmentType as W}from"@kanonak-protocol/types/ctl/parsing/enums";var O=class{repository;constructor(e){if(!e)throw new Error("Repository is required for CTL validation");this.repository=e}async validateAsync(e){if(!e)throw new Error("Document cannot be null");let r=[],t=[];for(let n of e.references){if(!n.parsedUri){r.push({errorType:C.InvalidUri,severity:P.Error,message:n.error??"Failed to parse Kanonak URI",reference:n,line:n.line,column:n.column,toString(){let a=this.line!=null?`(${this.line}:${this.column})`:"";return`${P[this.severity]}: ${this.message} ${a}`.trim()}});continue}try{await this.resolveReference(n,r,t)}catch(a){r.push({errorType:C.ParseError,severity:P.Error,message:`Error resolving reference: ${a.message}`,reference:n,line:n.line,column:n.column,toString(){let i=this.line!=null?`(${this.line}:${this.column})`:"";return`${P[this.severity]}: ${this.message} ${i}`.trim()}})}}return{isValid:r.length===0,document:e,errors:r,warnings:t,get totalReferences(){return e.referenceCount},get resolvedReferences(){return e.references.filter(n=>n.isResolved).length},get summary(){if(r.length===0)return`All ${e.referenceCount} references validated`;let n=e.references.filter(a=>a.isResolved).length;return`${r.length} error(s), ${n}/${e.referenceCount} references resolved`}}}async resolveReference(e,r,t){let s=e.parsedUri;switch(s.uriType){case q.Resource:await this.resolveResource(e,r);break;case q.DeepLink:await this.resolveDeepLink(e,r);break;default:r.push({errorType:C.InvalidUri,severity:P.Error,message:`Unsupported URI type: ${s.uriType}. CTL only supports resource references.`,reference:e,line:e.line,column:e.column,suggestion:"Use resource URIs: kanonak://publisher/package@version/resource",toString(){let n=this.line!=null?`(${this.line}:${this.column})`:"";return`${P[this.severity]}: ${this.message} ${n}`.trim()}});break}}async resolveResource(e,r){let t=e.parsedUri,s=t.namespace_,n=await this.repository.getDocumentAsync(s);if(!n){r.push(this.createError(C.PackageNotFound,`Package not found: ${s}`,e));return}if(n.body&&n.body[t.resourceName])e.isResolved=!0;else{let a=n.body?Object.keys(n.body).slice(0,5):[];r.push(this.createError(C.EntityNotFound,`Resource not found: ${t.resourceName} in ${s}`,e,a.length>0?`Available resources: ${a.join(", ")}`:void 0))}}async resolveDeepLink(e,r){let t=e.parsedUri,s=t.namespace_,n=await this.repository.getDocumentAsync(s);if(!n){r.push(this.createError(C.PackageNotFound,`Package not found: ${s}`,e));return}if(!n.body||!n.body[t.resourceName]){r.push(this.createError(C.EntityNotFound,`Resource not found: ${t.resourceName} in ${s}`,e));return}let a=n.body[t.resourceName],i=t.resourceName;for(let p of t.path){if(a==null){r.push(this.createError(C.PathNotFound,`Path not found: ${i}`,e));return}if(p.type_===W.Property){let u=p.name;i+=`.${u}`;let c=ae(a,u);if(c===void 0){let f=ce(a);r.push(this.createError(C.PathNotFound,`Path not found: ${i}`,e,f));return}a=c}else if(p.type_===W.Index){let u=p.index;i+=`[${u}]`;let c=ie(a,u);if(c===void 0){let f=le(a);r.push(this.createError(C.IndexOutOfBounds,`Index out of bounds: ${i}`,e,f));return}a=c}}e.isResolved=!0,e.resolvedValue=a}createError(e,r,t,s){return{errorType:e,severity:P.Error,message:r,reference:t,line:t.line,column:t.column,suggestion:s,toString(){let n=this.line!=null?`(${this.line}:${this.column})`:"";return`${P[this.severity]}: ${this.message} ${n}`.trim()}}}};function ae(o,e){if(o&&typeof o=="object"&&!Array.isArray(o)){if(e in o)return o[e];let r=Object.keys(o).find(t=>t.toLowerCase()===e.toLowerCase());if(r)return o[r]}}function ie(o,e){if(Array.isArray(o)&&e>=0&&e<o.length)return o[e]}function ce(o){if(o&&typeof o=="object"&&!Array.isArray(o)){let e=Object.keys(o).slice(0,5);if(e.length>0)return`Available properties: ${e.join(", ")}`}}function le(o){if(Array.isArray(o))return o.length>0?`Collection has ${o.length} items (valid indices: 0-${o.length-1})`:"Collection is empty"}import{ResolvedResourceType as x}from"@kanonak-protocol/types/ctl/resolution/enums";var pe=new Set(["kanonak.org/core-rdf","kanonak.org/core-rdfs","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);var D=class{repository;constructor(e){if(!e)throw new Error("Repository is required for CTL graph resolution");this.repository=e}async resolveAsync(e,r=1e3){if(!e)throw new Error("Document cannot be null");let t=new Set,s=[],n=[],a=[],i=[],p=new Set;for(let m of e.references)m.parsedUri&&p.add(m.parsedUri.toString());let u=new Map,c=new Map,f=await this.repository.getAllDocumentsAsync();for(let m of f){let g=m.metadata?.namespace_?.toString();if(!g||!m.body)continue;let E=[];for(let[R,d]of Object.entries(m.body))if(d&&typeof d=="object"&&!Array.isArray(d)){let k=this.createMockSubjectKanonak(R,d,g),I=`kanonak://${g}/${R}`;u.has(I)||u.set(I,{entity:k,namespace:g}),E.push(k)}c.set(g,E)}let l=0,h=!1;for(let m of e.references){if(!m.parsedUri){i.push({reference:m.rawUri,reason:m.error??"Failed to parse URI"});continue}let g=m.parsedUri.toString();if(t.has(g))continue;let E=await this.resolveEntityRecursive(g,null,null,0,r,t,p,s,n,a,i,u,c);l=Math.max(l,E),E>=r&&(h=!0)}let y=ge(e.rawMarkdown);return{sourceFile:e.filePath??null,originalContent:e.rawMarkdown,title:y,directReferences:s,inheritedReferences:n,foundationTypes:a,get totalResourceCount(){return s.length+n.length+a.length},get allResources(){return[...s,...n,...a]},maxDepthReached:l,wasTruncated:h,unresolvedResources:i}}async resolveEntityRecursive(e,r,t,s,n,a,i,p,u,c,f,l,h){if(a.has(e)||(a.add(e),s>=n))return s;if(!r){let d=l.get(e);if(!d)return f.push({reference:e,reason:"Resource not found in workspace"}),s;r=d.entity}let y=r,m=y.namespace??y.namespace_??"";!t&&m&&(t=await this.repository.getDocumentAsync(m));let g=this.createResolvedResource(r,e,s,h);switch(this.classifyTier(e,m,i)){case 0:p.push(g);break;case 2:c.push(g);break;default:u.push(g);break}let R=s;for(let d of g.parentClasses){let k=this.resolveReferenceToUri(d,m,t);if(k&&!a.has(k)){let I=l.get(k),_=await this.resolveEntityRecursive(k,I?.entity??null,null,s+1,n,a,i,p,u,c,f,l,h);R=Math.max(R,_)}}for(let d of g.properties.filter(k=>k.isObjectProperty)){let k=this.resolveReferenceToUri(d.rangeType,m,t);if(k&&!a.has(k)){let I=l.get(k),_=await this.resolveEntityRecursive(k,I?.entity??null,null,s+1,n,a,i,p,u,c,f,l,h);R=Math.max(R,_)}}if(g.instanceOf_){let d=this.resolveReferenceToUri(g.instanceOf_,m,t);if(d&&!a.has(d)){let k=l.get(d),I=await this.resolveEntityRecursive(d,k?.entity??null,null,s+1,n,a,i,p,u,c,f,l,h);R=Math.max(R,I)}}return R}createResolvedResource(e,r,t,s){let n=e,a=n.name??"",i=n.namespace??n.namespace_??"",p=this.classifyEntityType(e),u=B(e),c=fe(e),f=he(e),l=[];if(p===x.Class){let h=s.get(i);h&&(l=me(a,h))}return{name:a,kanonakUri:r,resource:e,resourceType:p,parentClass:c.length>0?c[0]:null,parentClasses:c,comment:u,properties:l,namespace_:i,resolutionDepth:t,instanceOf_:f}}classifyEntityType(e){if(b.isClassType(e))return x.Class;if(b.isAnnotationPropertyType(e))return x.AnnotationProperty;if(b.isDatatypePropertyType(e))return x.DatatypeProperty;if(b.isObjectPropertyType(e))return x.ObjectProperty;let r=b.getTypeUri(e);return r&&!b.isCoreOntologyType(r)?x.Instance:x.Other}classifyTier(e,r,t){return t.has(e)?0:ue(r)?2:1}resolveReferenceToUri(e,r,t){if(e.toLowerCase().startsWith("kanonak://"))return e;if(e.includes(".")&&t?.metadata){let s=e.indexOf("."),n=e.substring(0,s),a=e.substring(s+1);if(a){let i=t.metadata.allImports;if(i){for(let p of i)if((p.alias??p.packageName).toLowerCase()===n.toLowerCase())return`kanonak://${p.version?`${p.publisher}/${p.packageName}@${p.version}`:`${p.publisher}/${p.packageName}`}/${a}`}}}return!e.includes(".")&&r?`kanonak://${r}/${e}`:null}createMockSubjectKanonak(e,r,t){let s=[];for(let[n,a]of Object.entries(r))typeof a=="string"?n==="type"||n==="subClassOf"||n==="domain"||n==="range"||n==="subPropertyOf"?s.push({predicate:{subject:{name:n,publisher:"",package_:""}},object:{subject:{name:a,publisher:"",package_:""}}}):s.push({predicate:{subject:{name:n,publisher:"",package_:""}},object:a}):Array.isArray(a)&&s.push({predicate:{subject:{name:n,publisher:"",package_:""}},object:a.map(i=>typeof i=="string"?{subject:{name:i,publisher:"",package_:""}}:i)});return{name:e,namespace_:t,statement:s,entity:r}}};function ue(o){if(!o)return!1;let e=o.split("/");if(e.length<2)return!1;let r=e[0],t=e[1],s=t.includes("@")?t.split("@")[0]:t;return pe.has(`${r}/${s}`)}function B(o){let e=o;if(e.entity&&typeof e.entity=="object")return e.entity.comment??null;if(e.statement&&Array.isArray(e.statement)){for(let r of e.statement)if(r.predicate?.subject?.name==="comment"&&typeof r.object=="string")return r.object}return null}function fe(o){let e=[],r=o,t=r.name??"";if(r.entity&&typeof r.entity=="object"){let s=r.entity.subClassOf;if(typeof s=="string")s.toLowerCase()!==t.toLowerCase()&&e.push(s);else if(Array.isArray(s))for(let n of s){let a=typeof n=="string"?n:n?.subject?.name??n?.name;a&&a.toLowerCase()!==t.toLowerCase()&&e.push(a)}return e}if(r.statement&&Array.isArray(r.statement)){for(let s of r.statement)if(s.predicate?.subject?.name==="subClassOf"){if(s.object?.subject?.name){let n=s.object.subject.name;n.toLowerCase()!==t.toLowerCase()&&e.push(n)}else if(Array.isArray(s.object))for(let n of s.object){let a=n?.subject?.name??n?.name;a&&a.toLowerCase()!==t.toLowerCase()&&e.push(a)}}}return e}function he(o){let e=b.getTypeUri(o);return e?b.isCoreOntologyType(e)?null:e.name:null}function me(o,e){let r=[];for(let t of e){if(!b.isAnyPropertyType(t))continue;let s=t,n=[],a=[];if(s.entity&&typeof s.entity=="object"){let c=s.entity.domain;if(typeof c=="string")n.push(c);else if(Array.isArray(c))for(let l of c)n.push(typeof l=="string"?l:l?.name??String(l));let f=s.entity.range;if(typeof f=="string")a.push(f);else if(Array.isArray(f))for(let l of f)a.push(typeof l=="string"?l:l?.name??String(l))}if(!n.some(c=>c.toLowerCase()===o.toLowerCase()))continue;a.length===0&&a.push("unknown");let i=b.isObjectPropertyType(t),p=s.entity?.collection!=null,u=B(t);r.push({name:s.name??"",rangeTypes:a,domains:n,get rangeType(){return a.length>0?a.join(", "):"unknown"},isObjectProperty:i,isCollection:p,comment:u})}return r}function ge(o){let e=o.split(`
3
- `);for(let r of e){let t=r.trim();if(t.startsWith("# ")&&!t.startsWith("## "))return t.substring(2).trim()}return null}import{ResolvedResourceType as v}from"@kanonak-protocol/types/ctl/resolution/enums";var V=class{resolvedResourceNames=new Set;render(e){if(!e)throw new Error("Graph cannot be null");this.resolvedResourceNames=new Set(e.allResources.map(t=>t.name.toLowerCase()));let r=[];return r.push(this.transformTemplateLinks(e.originalContent)),r.push(""),r.push("---"),r.push(""),r.push("# Kanonak Resource Reference"),r.push(""),this.renderSummary(r,e),this.renderHierarchyDiagram(r,e),this.renderQuickReference(r,e),this.renderTier(r,"Direct References",e.directReferences,"Resources explicitly referenced in this template."),this.renderTier(r,"Inherited References",e.inheritedReferences,"Parent classes, property types, and other dependencies of directly referenced entities."),this.renderTier(r,"Foundation Types",e.foundationTypes,"Core ontology types that form the base of the type hierarchy."),e.unresolvedResources.length>0&&this.renderUnresolved(r,e.unresolvedResources),r.join(`
4
- `)}generateAnchor(e){return e.toLowerCase()}renderInternalLink(e){return this.resolvedResourceNames.has(e.toLowerCase())?`[${e}](#${this.generateAnchor(e)})`:e}renderInternalLinks(e){return e.map(r=>this.renderInternalLink(r)).join(", ")}transformTemplateLinks(e){let r=/\[([^\]]+)\]\(can:\/\/([^)]+)\)/g;return e.replace(r,(t,s,n)=>{let a;if(n.includes("#"))a=n.substring(n.indexOf("#")+1);else{let i=n.lastIndexOf(".");a=i>=0?n.substring(i+1):n}return this.resolvedResourceNames.has(a.toLowerCase())?`[${s}](#${this.generateAnchor(a)})`:t})}renderSummary(e,r){e.push(`**Total Resources**: ${r.totalResourceCount}`),e.push(`- Direct: ${r.directReferences.length}`),e.push(`- Inherited: ${r.inheritedReferences.length}`),e.push(`- Foundation: ${r.foundationTypes.length}`),r.wasTruncated&&(e.push(""),e.push(`**Resolution was truncated at depth ${r.maxDepthReached}** - some resources may be missing.`),e.push("To include more resources, re-run with a higher depth limit: `kanonak ctl resolve <file> --depth 2000`")),e.push("")}renderQuickReference(e,r){let t=r.allResources;if(t.length===0)return;e.push("## Quick Reference"),e.push("");let s=t.filter(c=>c.resourceType===v.Class),n=t.filter(c=>c.resourceType===v.AnnotationProperty),a=t.filter(c=>c.resourceType===v.DatatypeProperty),i=t.filter(c=>c.resourceType===v.ObjectProperty),p=t.filter(c=>c.resourceType===v.Instance);if(s.length>0){e.push(`### Classes (${s.length})`),e.push(""),e.push("| Class | Extends | Properties |"),e.push("|-------|---------|------------|");for(let c of[...s].sort((f,l)=>f.name.localeCompare(l.name))){let f=this.renderInternalLink(c.name),l=c.parentClasses.length>0?this.renderInternalLinks(c.parentClasses):"-";e.push(`| ${f} | ${l} | ${c.properties.length} |`)}e.push("")}let u=[...n,...a,...i];if(u.length>0){e.push(`### Properties (${u.length})`),e.push(""),e.push("| Property | Type | Description |"),e.push("|----------|------|-------------|");for(let c of[...u].sort((f,l)=>f.name.localeCompare(l.name))){let f=this.renderInternalLink(c.name),l=H(c.resourceType),h=ye(c.comment??"");e.push(`| ${f} | ${l} | ${h} |`)}e.push("")}if(p.length>0){let c=new Map;for(let f of p){let l=f.instanceOf_??"Unknown";c.has(l)||c.set(l,[]),c.get(l).push(f)}e.push("### Resources by Type"),e.push(""),e.push("| Type | Resources |"),e.push("|------|-----------|");for(let[f,l]of[...c.entries()].sort((h,y)=>h[0].localeCompare(y[0]))){let h=this.renderInternalLink(f),y=this.renderInternalLinks(l.map(m=>m.name));e.push(`| ${h} | ${y} |`)}e.push("")}}renderHierarchyDiagram(e,r){let t=r.allResources.filter(i=>i.resourceType===v.Class);if(t.length===0)return;let s=t.filter(i=>i.parentClasses.length>0);if(s.length===0)return;let n=new Set;for(let i of s)for(let p of i.parentClasses)n.add(p.toLowerCase());let a=new Set(t.map(i=>i.name.toLowerCase()));e.push("## Type Hierarchy"),e.push(""),e.push("```mermaid"),e.push("flowchart TB");for(let i of[...t].sort((p,u)=>p.name.localeCompare(u.name))){let p=j(i.name);e.push(` ${p}["${i.name}"]`)}for(let i of[...n])if(!a.has(i)){let p=i;for(let c of s)for(let f of c.parentClasses)f.toLowerCase()===i&&(p=f);let u=j(p);e.push(` ${u}["${p}"]:::external`)}e.push("");for(let i of s){let p=j(i.name);for(let u of i.parentClasses){let c=j(u);e.push(` ${c} --> ${p}`)}}e.push(""),e.push(" classDef external fill:#f9f9f9,stroke:#999,stroke-dasharray: 5 5"),e.push("```"),e.push("")}renderTier(e,r,t,s){if(t.length!==0){e.push(`## ${r} (${t.length})`),e.push(""),e.push(`*${s}*`),e.push("");for(let n of[...t].sort((a,i)=>a.name.localeCompare(i.name)))this.renderEntity(e,n)}}renderEntity(e,r){let t=this.generateAnchor(r.name);if(e.push(`### ${r.name}`),e.push(`<a id="${t}"></a>`),e.push(""),e.push("| Attribute | Value |"),e.push("|-----------|-------|"),e.push(`| **URI** | \`${r.kanonakUri}\` |`),e.push(`| **Type** | ${H(r.resourceType)} |`),r.parentClasses.length>0){let s=this.renderInternalLinks(r.parentClasses);e.push(`| **Extends** | ${s} |`)}if(r.instanceOf_){let s=this.renderInternalLink(r.instanceOf_);e.push(`| **Instance of** | ${s} |`)}e.push(""),r.comment&&(e.push(r.comment),e.push("")),r.resourceType===v.Class&&r.properties.length>0&&this.renderPropertiesTable(e,r.properties),e.push("---"),e.push("")}renderPropertiesTable(e,r){e.push("| Property | Type | Description |"),e.push("|----------|------|-------------|");for(let t of[...r].sort((s,n)=>s.name.localeCompare(n.name))){let n=t.rangeTypes.map(i=>{let p=this.renderInternalLink(i);return t.isObjectProperty?`-> ${p}`:p}).join(", ");t.isCollection&&(n=`${n}[]`);let a=(t.comment??"").replace(/\|/g,"\\|").replace(/\n/g," ").replace(/\r/g,"");e.push(`| ${t.name} | ${n} | ${a} |`)}e.push("")}renderUnresolved(e,r){e.push(`## Unresolved References (${r.length})`),e.push(""),e.push("*The following references could not be resolved:*"),e.push("");for(let t of r)e.push(`- \`${t.reference}\`: ${t.reason}`);e.push("")}};function H(o){switch(o){case v.Class:return"Class";case v.AnnotationProperty:return"Annotation Property";case v.DatatypeProperty:return"Datatype Property";case v.ObjectProperty:return"Object Property";case v.Instance:return"Instance";default:return"Other"}}function ye(o){return o?(o=o.replace(/\|/g,"\\|").replace(/\n/g," ").replace(/\r/g,""),o.length<=50?o:o.substring(0,47)+"..."):""}function j(o){return o.replace(/[^a-zA-Z0-9]/g,"_")}import{CtlValidationErrorType as Ve,CtlValidationSeverity as Me}from"@kanonak-protocol/types/ctl/models/enums";import{CtlKanonakUriType as Fe,PathSegmentType as Ge}from"@kanonak-protocol/types/ctl/parsing/enums";import{ResolvedResourceType as We}from"@kanonak-protocol/types/ctl/resolution/enums";export{b as a,K as b,L as c,O as d,D as e,V as f,Ve as g,Me as h,Fe as i,Ge as j,We as k};
@@ -1,14 +0,0 @@
1
- import type { CtlDocument } from '@kanonak-protocol/types/ctl/models/types';
2
- import type { ResolvedResourceGraph, CtlGraphResolver as ICtlGraphResolver } from '@kanonak-protocol/types/ctl/resolution/types';
3
- import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
4
- export declare class CtlGraphResolver implements ICtlGraphResolver {
5
- private readonly repository;
6
- constructor(repository: IKanonakDocumentRepository);
7
- resolveAsync(document: CtlDocument, maxDepth?: number): Promise<ResolvedResourceGraph>;
8
- private resolveEntityRecursive;
9
- private createResolvedResource;
10
- private classifyEntityType;
11
- private classifyTier;
12
- private resolveReferenceToUri;
13
- private createMockSubjectKanonak;
14
- }
@@ -1,28 +0,0 @@
1
- import type { CtlKanonakUri as ICtlKanonakUri, PathSegment } from '@kanonak-protocol/types/ctl/parsing/types';
2
- import { CtlKanonakUriType } from '@kanonak-protocol/types/ctl/parsing/enums';
3
- import type { Version } from '@kanonak-protocol/types/document/models/types';
4
- export declare class CtlKanonakUri implements ICtlKanonakUri {
5
- readonly scheme: string;
6
- publisher: string;
7
- package_?: string | null | undefined;
8
- version?: Version | null | undefined;
9
- resourceName?: string | null | undefined;
10
- path: readonly PathSegment[];
11
- rawUri: string;
12
- constructor(init: {
13
- publisher: string;
14
- package_?: string | null | undefined;
15
- version?: Version | null | undefined;
16
- resourceName?: string | null | undefined;
17
- path?: PathSegment[];
18
- rawUri: string;
19
- });
20
- get uriType(): CtlKanonakUriType;
21
- get namespace_(): string | null;
22
- static parse(uriString: string): CtlKanonakUri;
23
- static tryParse(uriString: string): CtlKanonakUri | null;
24
- static isKanonakUri(value: string): boolean;
25
- toString(): string;
26
- equals(obj: any): boolean;
27
- getHashCode(): number;
28
- }
@@ -1,17 +0,0 @@
1
- import type { ResolvedResourceGraph } from '@kanonak-protocol/types/ctl/resolution/types';
2
- import type { CtlMarkdownRenderer as ICtlMarkdownRenderer } from '@kanonak-protocol/types/exporters/ctl/markdown/types';
3
- export declare class CtlMarkdownRenderer implements ICtlMarkdownRenderer {
4
- private resolvedResourceNames;
5
- render(graph: ResolvedResourceGraph): string;
6
- private generateAnchor;
7
- private renderInternalLink;
8
- private renderInternalLinks;
9
- private transformTemplateLinks;
10
- private renderSummary;
11
- private renderQuickReference;
12
- private renderHierarchyDiagram;
13
- private renderTier;
14
- private renderEntity;
15
- private renderPropertiesTable;
16
- private renderUnresolved;
17
- }
@@ -1,10 +0,0 @@
1
- import type { CtlDocument } from '@kanonak-protocol/types/ctl/models/types';
2
- import type { CtlParser as ICtlParser } from '@kanonak-protocol/types/ctl/parsing/types';
3
- export declare class CtlParser implements ICtlParser {
4
- parse(content: string, filePath?: string | null): CtlDocument;
5
- parseFileAsync(filePath: string): Promise<CtlDocument>;
6
- private parseWithFrontmatter;
7
- private parseInline;
8
- private parseMarkdownBody;
9
- private buildAliasMap;
10
- }
@@ -1,12 +0,0 @@
1
- import type { CtlDocument, CtlValidationResult } from '@kanonak-protocol/types/ctl/models/types';
2
- import type { CtlValidator as ICtlValidator } from '@kanonak-protocol/types/ctl/validation/types';
3
- import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
4
- export declare class CtlValidator implements ICtlValidator {
5
- private readonly repository;
6
- constructor(repository: IKanonakDocumentRepository);
7
- validateAsync(document: CtlDocument): Promise<CtlValidationResult>;
8
- private resolveReference;
9
- private resolveResource;
10
- private resolveDeepLink;
11
- private createError;
12
- }
@@ -1,12 +0,0 @@
1
- export { CtlKanonakUri } from './CtlKanonakUri.js';
2
- export { CtlParser } from './CtlParser.js';
3
- export { ResourceTypeClassifier } from './ResourceTypeClassifier.js';
4
- export { CtlValidator } from './CtlValidator.js';
5
- export { CtlGraphResolver } from './CtlGraphResolver.js';
6
- export { CtlMarkdownRenderer } from './CtlMarkdownRenderer.js';
7
- export type { CtlDocument, KanonakReference, CtlValidationResult, CtlValidationError } from '@kanonak-protocol/types/ctl/models/types';
8
- export type { CtlKanonakUri as ICtlKanonakUri, PathSegment, ResolvedImport } from '@kanonak-protocol/types/ctl/parsing/types';
9
- export type { ResolvedResourceGraph, ResolvedResource, ResolvedProperty, UnresolvedResource } from '@kanonak-protocol/types/ctl/resolution/types';
10
- export { CtlValidationErrorType, CtlValidationSeverity } from '@kanonak-protocol/types/ctl/models/enums';
11
- export { CtlKanonakUriType, PathSegmentType } from '@kanonak-protocol/types/ctl/parsing/enums';
12
- export { ResolvedResourceType } from '@kanonak-protocol/types/ctl/resolution/enums';
package/dist/ctl/index.js DELETED
@@ -1 +0,0 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-USLG7UIM.js";export{e as CtlGraphResolver,b as CtlKanonakUri,i as CtlKanonakUriType,f as CtlMarkdownRenderer,c as CtlParser,g as CtlValidationErrorType,h as CtlValidationSeverity,d as CtlValidator,j as PathSegmentType,k as ResolvedResourceType,a as ResourceTypeClassifier};