@kanonak-protocol/sdk 3.40.0 → 3.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/{chunk-KE4QZNDZ.js → chunk-BFZZ6YGX.js} +1 -1
- package/dist/{chunk-SQDXESNM.js → chunk-FMYLEPMC.js} +1 -1
- package/dist/chunk-HEMBMX7T.js +1 -0
- package/dist/{chunk-4EWKM5LF.js → chunk-IOJMTW4T.js} +1 -1
- package/dist/{chunk-RZ57SDAT.js → chunk-NIJV5UYW.js} +1 -1
- package/dist/chunk-O4GZ6W5Z.js +116 -0
- package/dist/{chunk-EGHULU3U.js → chunk-RCI34BYO.js} +1 -1
- package/dist/chunk-SKTXJV4T.js +54 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -12
- package/dist/look/LookRenderer.d.ts +9 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/resolution/ResourceResolutionResult.d.ts +15 -0
- package/dist/resolution/index.js +1 -1
- package/dist/transformations/index.js +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist/chunk-5ILSX24H.js +0 -1
- package/dist/chunk-LKDDPNIW.js +0 -116
- package/dist/chunk-YRMZ5R2W.js +0 -54
- package/dist/validation/rules/repository/TypeAmbiguityRule.d.ts +0 -10
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import{a as ye}from"./chunk-FJ35VIV6.js";import{a as ie,c as le,d as pe,f as Y}from"./chunk-FMYLEPMC.js";import{c as G,k as se,l as ae}from"./chunk-W6T7MOKY.js";import{a as ne}from"./chunk-7CUTGGH3.js";import{c as A}from"./chunk-FQHALFRR.js";import{a as P,b as V,c as ce}from"./chunk-HEMBMX7T.js";var D=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(r=>(r.Warning="Warning",r.Error="Error",r))(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 J=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let r=new d;return r.resolvedDocuments=this.resolvedDocuments,r.currentEntityPath=e,r}};var ee=class{constructor(e){this.underlying=e;this.repository=new te(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new Y().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let r=this.importClosureCache.get(e);return r||(r=this.computeImportClosure(e),this.importClosureCache.set(e,r),r)}async getClassDeclarations(e){let r=this.classDeclarationsCache.get(e);return r||(r=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,r),r)}async getPropertyNames(e){let r=this.propertyNamesCache.get(e);return r||(r=this.computePropertyNames(e),this.propertyNamesCache.set(e,r),r)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let r=new Set([e]),t=[e],o=await this.buildDocsByIdIndex();for(;t.length>0;){let a=t.shift(),i=o.get(a);if(i?.metadata.imports)for(let[n,l]of Object.entries(i.metadata.imports))for(let s of l){let c=await this.repository.getHighestCompatibleVersionAsync(n,s);if(!c)continue;let p=Q(c);!p||r.has(p)||(r.add(p),t.push(p))}}return r}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),r=new Map;for(let t of e){let o=Q(t);o&&r.set(o,t)}return r}async computeClassDeclarations(e){let r=await this.findDocById(e),t=new Map;if(!r)return t;for(let[o,a]of Object.entries(r.body)){if(!me(a))continue;let i=a,n=ue(i,"type");if(n==="Class"||n?.endsWith(".Class")){let l=ge(i);t.set(o,l)}}return t}async computePropertyNames(e){let r=await this.findDocById(e),t=new Set;if(!r)return t;for(let[o,a]of Object.entries(r.body)){if(!me(a))continue;let n=ue(a,"type");(n==="ObjectProperty"||n?.endsWith(".ObjectProperty")||n==="DatatypeProperty"||n?.endsWith(".DatatypeProperty")||n==="AnnotationProperty"||n?.endsWith(".AnnotationProperty")||n==="Property"||n?.endsWith(".Property"))&&t.add(o)}return t}async findDocById(e){let r=await this.getAllDocuments();for(let t of r)if(Q(t)===e)return t}};function Q(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${A(e.version)}`}function me(d){return typeof d=="object"&&d!==null&&!Array.isArray(d)}function ue(d,e){if(e in d)return fe(d[e]);for(let r of Object.keys(d))if(r.endsWith(`.${e}`))return fe(d[r])}function fe(d){return Array.isArray(d)?d.length>0?String(d[0]):void 0:d==null?void 0:String(d)}function ge(d){let e=d.subClassOf;if(e===void 0){for(let r of Object.keys(d))if(r.endsWith(".subClassOf")){e=d[r];break}}return P(e)}var te=class{constructor(e){this.inner=e}inner;highestVersionCache=new Map;byNamespaceCache=new Map;getAllDocumentsAsync(){return this.inner.getAllDocumentsAsync()}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,r){let t=`${e}/${r}`,o=this.byNamespaceCache.get(t);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,r),this.byNamespaceCache.set(t,o),o)}getHighestCompatibleVersionAsync(e,r){let t=r.version,o=t?`${t.major}.${t.minor}.${t.patch}`:"",a=`${e}/${r.packageName}@${r.versionOperator}:${o}`,i=this.highestVersionCache.get(a);return i||(i=this.inner.getHighestCompatibleVersionAsync(e,r),this.highestVersionCache.set(a,i),i)}saveDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}deleteDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}clearNamespaceAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var v=class d{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let r=[];for(let[t,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(t,o,r);return r}validateEntity(e,r,t){for(let[o,a]of Object.entries(r)){let i=a?.toString()??"";if(i&&d.NAMESPACE_PREFIX_PATTERN.test(i)){let n=this.getSuggestionForPrefixedValue(i),l=e.split(".")[0],s=new g;s.ruleType=this.ruleName,s.severity="Error",s.entityName=l,s.propertyName=e,s.actualValue=o,s.expectedValue=n,s.message=`Invalid namespace prefix '${i}'. Use '${n}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(`${e}.${o}`,a,t)}}getSuggestionForPrefixedValue(e){let r=e.toLowerCase();if(r==="rdfs:class"||r==="owl:class")return"Class";if(r==="rdfs:property"||r==="rdf:property")return"DatatypeProperty or ObjectProperty";if(r.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var I=class d{static RESERVED_WORDS=new Set(["kanonak","imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let r=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,a]of Object.entries(e.body)){let i=d.VALID_AUGMENTATION_PATTERN.test(o);if(!i&&!t&&d.RESERVED_WORDS.has(o.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=o,n.message=`Entity name '${o}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",r.push(n);continue}if(!i&&!d.VALID_NAME_PATTERN.test(o)){let n;/^\d/.test(o)?n="Entity names must start with a letter, not a number.":o.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=o,l.message=`Invalid entity name '${o}'. ${n}`,l.suggestion=n,r.push(l)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validatePropertyNames(o,a,r)}return r}validatePropertyNames(e,r,t){for(let o of Object.keys(r))if(!d.VALID_PROPERTIES.has(o)&&!d.VALID_PROPERTY_NAME_PATTERN.test(o)){let a=new g;a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=o,a.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,a.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(a)}}};var O=class d{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let r=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return r;let t=this.isPropertyDefinedAsClass(e);for(let[o,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let i=a,n=i.type;if(n){let l=[];if(Array.isArray(n))for(let s of n){let c=s?.toString();c&&c==="Property"&&!t&&l.push(c)}else{let s=n?.toString();s&&s==="Property"&&!t&&l.push(s)}for(let s of l){let c=this.getPropertyValue(i,"range"),p=this.determinePropertyType(c),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.entityName=o,y.propertyName="type",y.actualValue=s,y.expectedValue=p,y.message=`Invalid property type '${s}'. Use '${p}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",r.push(y)}}}return r}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,r){let t=e[r];return t?t.toString():null}isPropertyDefinedAsClass(e){let r=e.body.Property;if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r.type;if(o){let a=o.toString();return a==="Class"||a.endsWith(".Class")}}return!1}};var w=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let r=[];for(let[t,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||t.includes("."))continue;let a=o,i="type"in a,n=a.type?.toString().trim();if(!i||!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.)",r.push(l)}}return r}};var j=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,r){let t=[],o=new V(r),a=await this.buildPropertyRangeMap(e,o);for(let[i,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(i,n,void 0,a,o,e,t,0);return t}pickRange(e,r,t){if(e.length===0)return;if(e.length===1)return e[0].range;let o=r.indexOf(".");if(o>0){let a=r.substring(0,o),i=e.find(n=>n.declaringAlias===a);if(i)return i.range}if(t){let a=this.localName(t),i=e.find(n=>this.localName(n.domain)===a);if(i)return i.range}return e[0].range}async checkEmbeddedTypes(e,r,t,o,a,i,n,l){if(l>0){let c=r.type;if(c!=null){let p=await this.validateEmbeddedType(e,String(c),t,a,i);p&&n.push(p)}}let s=r.type!==void 0&&r.type!==null?String(r.type):void 0;for(let[c,p]of Object.entries(r)){let y=this.localName(c),m=o.get(y),f=(m!==void 0?this.pickRange(m,c,s):void 0)??t;if(typeof p=="object"&&p!==null)if(Array.isArray(p))for(let b=0;b<p.length;b++){let h=p[b];typeof h=="object"&&h!==null&&!Array.isArray(h)&&await this.checkEmbeddedTypes(`${e}.${c}[${b}]`,h,f,o,a,i,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${c}`,p,f,o,a,i,n,l+1)}}async validateEmbeddedType(e,r,t,o,a){if(r.length===0||!t)return null;let i=this.localName(r),n=this.localName(t);if(n==="Resource"||n==="Class")return null;let l=e.split(".")[0];if(i===n){let c=new g;return c.ruleType=this.ruleName,c.severity="Warning",c.entityName=l,c.propertyName=e,c.actualValue=r,c.expectedValue=t,c.message=`Embedded object at '${e}' declares 'type: ${r}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,c.suggestion=`Remove the 'type: ${r}' line, or keep it if explicitness is preferred over concision.`,c}if(await o.isSubclassOfAsync(r,t,a)||(i!==r||n!==t)&&await o.isSubclassOfAsync(i,n,a))return null;let s=new g;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=l,s.propertyName=e,s.actualValue=r,s.expectedValue=t,s.message=`Embedded object at '${e}' has 'type: ${r}', which is not a subclass of the parent property's range '${t}'.`,s.suggestion=`Either remove the 'type: ${r}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${r}' class definition so the relationship holds.`,s}localName(e){let r=e.lastIndexOf(".");return r<0||r===e.length-1?e:e.substring(r+1)}async buildPropertyRangeMap(e,r){let t=new Map,o=await r.buildEntityIndexAsync(e),a=new Map;for(let[i,n]of o){let l=n.entity.type;if(l==null)continue;let s=String(l),c=this.localName(s);if(!(c==="Property"||c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"))continue;let y=n.entity.range;if(y==null)continue;let m=String(y);if(m.length===0)continue;let u=n.entity.domain,f=u!=null?String(u):"",b=n.uri.toString(),h=a.get(b),k=i.includes(".");(!h||k&&!h.entityName.includes("."))&&a.set(b,{entityName:i,domain:f,range:m})}for(let i of a.values()){let n=this.localName(i.entityName),l=i.entityName.indexOf("."),s=l>0?i.entityName.substring(0,l):void 0,c=t.get(n)??[];c.push({domain:i.domain,range:i.range,declaringAlias:s}),t.set(n,c)}return t}};var E=class{ruleName="ImportExistence";async validateAsync(e,r){let t=[];if(!e.metadata?.imports)return t;let o=await r.getAllDocumentsAsync();for(let[a,i]of Object.entries(e.metadata.imports))for(let n of i)if(!await r.getHighestCompatibleVersionAsync(a,n)){let s=await this.determineImportErrorAsync(r,a,n,o),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=s.message,c.suggestion=s.suggestion,c.entityName=`Import: ${a}/${n.packageName}`,c.actualValue=n.toString(),c.expectedValue=s.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,r,t,o){let a=await e.getDocumentsByNamespaceAsync(r,t.packageName);if(a.length===0){let s=o.filter(m=>m.metadata.namespace_?.publisher===r).map(m=>m.metadata.namespace_.package_).filter((m,u,f)=>f.indexOf(m)===u),c=this.findSimilarPackages(t.packageName,s),p=`Import '${r}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${r}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${r}'. Verify the publisher name is correct.`;return{message:p,suggestion:y,expectedValue:"Existing package"}}let n=a.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),l=this.getAcceptableVersionRange(t);return{message:`Import '${r}/${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,r){if(r.length===0)return[];let t=r.filter(i=>i.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(i.toLowerCase()));if(t.length>0)return t.sort((i,n)=>i.length-n.length);let o=r.map(i=>({package:i,distance:this.levenshteinDistance(e.toLowerCase(),i.toLowerCase())})).sort((i,n)=>i.distance-n.distance),a=Math.max(3,Math.floor(e.length*.4));return o.filter(i=>i.distance<=a).map(i=>i.package)}levenshteinDistance(e,r){if(!e||e.length===0)return r?.length??0;if(!r||r.length===0)return e.length;let t=e.length,o=r.length,a=Array(t+1).fill(null).map(()=>Array(o+1).fill(0));for(let i=0;i<=t;i++)a[i][0]=i;for(let i=0;i<=o;i++)a[0][i]=i;for(let i=1;i<=t;i++)for(let n=1;n<=o;n++){let l=e[i-1]===r[n-1]?0:1;a[i][n]=Math.min(Math.min(a[i-1][n]+1,a[i][n-1]+1),a[i-1][n-1]+l)}return a[t][o]}};var N=class{ruleName="UnresolvedReference";async validateAsync(e,r){let t=[],o=new V(r),a=await o.buildEntityIndexAsync(e),i=new Set;for(let[n,l]of a.entries()){let s=l.entity.type;if(s){let c=s.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&i.add(n)}}for(let[n,l]of Object.entries(e.body)){if(!l||typeof l!="object"||Array.isArray(l))continue;let s=l,c=this.getPropertyValue(s,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[p,y]of Object.entries(s))p==="type"||p==="label"||p==="comment"||!(i.has(p)||Array.from(i).some(u=>u.endsWith(`.${p}`)))||await this.validateReferenceValue(n,p,y,e,o,t)}return t}async validateReferenceValue(e,r,t,o,a,i){if(t!=null){if(typeof t=="string")await a.resolveEntityAsync(t,o)||i.push(this.createUnresolvedReferenceError(e,r,t));else if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=t[n];typeof l=="string"&&(await a.resolveEntityAsync(l,o)||i.push(this.createUnresolvedReferenceError(e,`${r}[${n}]`,l)))}}}createUnresolvedReferenceError(e,r,t){let o=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
5
|
+
|
|
6
|
+
Possible solutions:
|
|
7
|
+
\u2022 Add import if the entity is defined in another namespace:
|
|
8
|
+
kanonak namespace add-import <publisher>/<package>@<version>
|
|
9
|
+
\u2022 Check for typos in the reference name '${t}'
|
|
10
|
+
\u2022 Define '${t}' in the current namespace or an appropriate namespace
|
|
11
|
+
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=r,a.actualValue=t,a.message=`Reference to '${t}' could not be resolved`,a.suggestion=o,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,r){let t=e[r];return t?t.toString():null}};var $=class{ruleName="ClassHierarchyCycle";async validateAsync(e,r){let t=[],o=new Map,a=new Set;await this.buildClassHierarchy(e,r,o,a);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,s=l.type,c=l.subClassOf;if(s?.toString()==="Class"&&c){let p=i,y=this.detectCycle(p,o);if(y){let m=y.join(" \u2192 "),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${m}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=p,u.propertyName="subClassOf",u.actualValue=m,t.push(u);break}}}return t}async buildClassHierarchy(e,r,t,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,s=l.type,c=l.subClassOf;if(s?.toString()==="Class"&&c){let p=P(c);p.length>0&&t.set(i,p)}}if(e.metadata?.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);s&&await this.buildClassHierarchy(s,r,t,o)}}}detectCycle(e,r){let t=[],o=new Set;return this.detectCycleRecursive(e,r,t,o)}detectCycleRecursive(e,r,t,o){if(t.includes(e)){let i=t.indexOf(e),n=t.slice(i);return n.push(e),n}if(o.has(e))return null;t.push(e),o.add(e);let a=r.get(e);if(a)for(let i of a){let n=this.detectCycleRecursive(i,r,t,o);if(n)return n}return t.pop(),null}};var S=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,r){let t=[],o=new Map,a=new Set;await this.buildPropertyHierarchy(e,r,o,a);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.subPropertyOf){let c=i,p=this.detectCycle(c,o);if(p){let y=p.join(" \u2192 "),m=new g;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${y}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=c,m.propertyName="subPropertyOf",m.actualValue=y,t.push(m);break}}return t}async buildPropertyHierarchy(e,r,t,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[i,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,s=l.type;if(s){let c=s.toString();if(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"){let p=l.subPropertyOf;if(p){let y=P(p);y.length>0&&t.set(i,y)}}}}if(e.metadata?.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);s&&await this.buildPropertyHierarchy(s,r,t,o)}}}detectCycle(e,r){let t=[],o=new Set;return this.detectCycleRecursive(e,r,t,o)}detectCycleRecursive(e,r,t,o){if(t.includes(e)){let i=t.indexOf(e),n=t.slice(i);return n.push(e),n}if(o.has(e))return null;t.push(e),o.add(e);let a=r.get(e);if(a)for(let i of a){let n=this.detectCycleRecursive(i,r,t,o);if(n)return n}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,r){let t=[];for(let[o,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let i=a,n=i.type?.toString();if(n==="DatatypeProperty"||n==="ObjectProperty"||n?.endsWith(".DatatypeProperty")||n?.endsWith(".ObjectProperty")){let l="range"in i,s=i.range?.toString().trim();if(!l||!s){let c=new g;c.ruleType=this.ruleName,c.severity="Error",c.entityName=o,c.propertyName="range",c.message=`Property '${o}' must have a 'range' defined.`,c.suggestion=n==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",c.expectedValue=n==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(c)}}}return t}};var K=class{builtInClasses=new Set(["Resource","Class","Datatype","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}isClassLikeType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}async validateAsync(e,r){let t=[],o=new Set;for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isClassLikeType(l)&&o.add(a)}for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=P(i.subClassOf);for(let s=0;s<l.length;s++){let c=l[s];if(this.builtInClasses.has(c)||o.has(c))continue;if(!await this.isClassAvailableInImports(e,r,c)){let y=l.length>1?`[${s}]`:"",m=new g;m.ruleType=this.ruleName,m.severity="Error",m.message=`Class '${c}' referenced in subClassOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a Class, or import a namespace that contains it`,m.entityName=a,m.propertyName="subClassOf",m.actualValue=c,m.expectedValue="Defined or imported class",t.push(m)}}}return t}async isClassAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,a=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],a=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=o!==null?a:t,p=s.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isClassLikeType(u))return!0}let y=new Set;if(await this.isClassAvailableInImportsRecursive(s,r,c,y))return!0}}return!1}async isClassAvailableInImportsRecursive(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isClassLikeType(y))return!0}if(await this.isClassAvailableInImportsRecursive(s,r,t,o))return!0}}return!1}};var T=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,r){let t=[],o=new Set;for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();(l==="DatatypeProperty"||l==="ObjectProperty"||l==="AnnotationProperty")&&o.add(a)}for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=P(i.subPropertyOf);for(let s=0;s<l.length;s++){let c=l[s];if(this.builtInProperties.has(c)||o.has(c))continue;if(!await this.isPropertyAvailableInImports(e,r,c)){let y=l.length>1?`[${s}]`:"",m=new g;m.ruleType=this.ruleName,m.severity="Error",m.message=`Property '${c}' referenced in subPropertyOf${y} is not defined or imported`,m.suggestion=`Define '${c}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,m.entityName=a,m.propertyName="subPropertyOf",m.actualValue=c,m.expectedValue="Defined or imported property",t.push(m)}}}return t}async isPropertyAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,a=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],a=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=o!==null?a:t,p=s.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let y=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,r,c,y))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(s,r,t,o))return!0}}return!1}};var x=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,r){let t=[],o=e.metadata.namespace_?.toString();if(!o)return t;let a=new Map,i=new Set;await this.buildImportGraph(e,r,a,i);let n=this.detectCycle(o,a);if(n){let l=n.join(" \u2192 "),s=new g;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${l}`,s.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=l,t.push(s)}return t}async buildImportGraph(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(!(!a||o.has(a))&&(o.add(a),e.metadata.imports)){let i=[];for(let[n,l]of Object.entries(e.metadata.imports))for(let s of l){let c=`${n}/${s.packageName}@${s.version}`;i.push(c);let p=await r.getHighestCompatibleVersionAsync(n,s);p&&await this.buildImportGraph(p,r,t,o)}i.length>0&&t.set(a,i)}}detectCycle(e,r){let t=[],o=new Set;return this.detectCycleRecursive(e,r,t,o)}detectCycleRecursive(e,r,t,o){let a=t.indexOf(e);if(a>=0){let n=t.slice(a);return n.push(e),n}if(o.has(e))return null;t.push(e),o.add(e);let i=r.get(e);if(i)for(let n of i){let l=this.detectCycleRecursive(n,r,t,o);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,r,t){let o=[],a=new Set,i=t?await this.closurePropertyNamesViaCache(e,t):void 0,n=t?await this.aliasClosurePropertyNamesViaCache(e,t):void 0;for(let[l,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=s.type?.toString();this.isPropertyType(p)&&a.add(l)}for(let[l,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=c.type?.toString();if(this.isPropertyType(p)||this.isClassType(p))continue;for(let[y,m]of Object.entries(c)){if(!y||this.metadataKeys.has(y))continue;let u=y,f=null;if(y.includes(".")){let h=y.lastIndexOf(".");f=y.substring(0,h),u=y.substring(h+1)}if(a.has(u))continue;if(!await this.isPropertyAvailable(e,r,u,f,i,n)){let h=new g;h.ruleType=this.ruleName,h.severity="Error",h.message=`Property '${y}' is not defined or imported`,h.suggestion=f?`The property '${u}' is not found in the imported namespace with alias '${f}'.
|
|
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 '${y}' is not defined in this namespace or any imported namespace.
|
|
15
|
+
1. Define '${y}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
16
|
+
2. Import the namespace that contains '${y}', OR
|
|
17
|
+
3. Use a qualified reference like 'alias.${y}' if already imported with an alias`,h.entityName=l,h.propertyName=y,h.actualValue=m?.toString(),h.expectedValue="A defined or imported property",o.push(h)}}}return o}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 isPropertyAvailable(e,r,t,o,a,i){if(a!==void 0&&i!==void 0){if(o===null)return a.has(t);let n=i.get(o);return n?n.has(t):!1}return await this.isPropertyAvailableInImports(e,r,t,o)}async closurePropertyNamesViaCache(e,r){let t=new Set,o=de(e);if(!o)return t;let a=await r.getImportClosure(o);for(let i of a)if(i!==o)for(let n of await r.getPropertyNames(i))t.add(n);return t}async aliasClosurePropertyNamesViaCache(e,r){let t=new Map;if(!e.metadata.imports)return t;for(let[o,a]of Object.entries(e.metadata.imports))for(let i of a){if(!i.alias)continue;let n=await r.repository.getHighestCompatibleVersionAsync(o,i);if(!n)continue;let l=de(n);if(!l)continue;let s=await r.getImportClosure(l),c=t.get(i.alias)??new Set;for(let p of s)for(let y of await r.getPropertyNames(p))c.add(y);t.set(i.alias,c)}return t}async isPropertyAvailableInImports(e,r,t,o){if(!e.metadata.imports)return!1;for(let[a,i]of Object.entries(e.metadata.imports))for(let n of i){if(o!==null&&n.alias!==o)continue;let l=await r.getHighestCompatibleVersionAsync(a,n);if(l){let s=l.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,r,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,r,t,o))return!0}}return!1}};function de(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${A(e.version)}`}var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,r){let t=[],o=new Set;for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isPropertyType(l)&&o.add(a)}for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=n.type?.toString();if(!this.isPropertyType(l)&&!this.isClassType(l))continue;for(let[s,c]of Object.entries(n)){if(!s||this.metadataKeys.has(s))continue;let p=s,y=null;if(s.includes(".")){let u=s.lastIndexOf(".");y=s.substring(0,u),p=s.substring(u+1)}if(o.has(p))continue;if(!await this.isPropertyAvailableInImports(e,r,p,y)){let u=this.isClassType(l)?"class":"property",f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${s}' used on ${u} '${a}' is not defined or imported`,f.suggestion=y?`The property '${p}' is not found in the imported namespace with alias '${y}'.
|
|
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 '${s}' is not defined in this namespace or any imported namespace.
|
|
21
|
+
1. Define '${s}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
22
|
+
2. Import the namespace that contains '${s}', OR
|
|
23
|
+
3. Use a qualified reference like 'alias.${s}' if already imported with an alias`,f.entityName=a,f.propertyName=s,f.actualValue=c?.toString(),f.expectedValue="A defined or imported property",t.push(f)}}}return t}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,r,t,o){if(!e.metadata.imports)return!1;for(let[a,i]of Object.entries(e.metadata.imports))for(let n of i){if(o!==null&&n.alias!==o)continue;let l=await r.getHighestCompatibleVersionAsync(a,n);if(l){let s=l.body[t];if(s&&typeof s=="object"&&!Array.isArray(s)){let y=s.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,r,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(s,r,t,o))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,r){let t=[],o=new Set,a=[];for(let[i,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,s=!1,c=l.type;if(Array.isArray(c)){for(let p of c)if(p?.toString()==="DatatypeProperty"){s=!0;break}}else c?.toString()==="DatatypeProperty"&&(s=!0);if(s){a.push(i);let p=this.getPropertyValue(l,"range");p&&this.xsdTypes.has(p)&&o.add(p)}}if(o.size>0&&!await this.checkXsdImportAsync(e.metadata,r)){let n=Array.from(o).sort().join(", "),l=a.sort().join(", "),s=new g;s.ruleType=this.ruleName,s.severity="Error",s.message=`XSD namespace not imported but XSD types are used: ${n}`,s.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${l}`,s.entityName="imports",t.push(s)}return t}async checkXsdImportAsync(e,r,t=new Set){if(!e?.imports)return!1;let o=e.namespace_?.toString()??"";if(o&&t.has(o))return!1;o&&t.add(o);for(let[,a]of Object.entries(e.imports))for(let i of a)if(i.packageName==="xsd"||i.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[a,i]of Object.entries(e.imports))for(let n of i){let l=await r.getHighestCompatibleVersionAsync(a,n);if(l?.metadata&&await this.checkXsdImportAsync(l.metadata,r,t))return!0}return!1}getPropertyValue(e,r){return e[r]?.toString()}};var _=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,r){let t=[],o=await this.buildEntitySourceMapAsync(e,r),a=await this.buildDatatypePropertyNamesAsync(e,r);for(let[i,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&this.validateEntityReferences(i,n,o,a,e,t);return t}async buildEntitySourceMapAsync(e,r){let t=new Map,o=new Set;for(let a of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";t.has(a)||t.set(a,[]),t.get(a).push(`(local:${i})`)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let n of i){let l=await r.getHighestCompatibleVersionAsync(a,n);l&&await this.collectEntitiesRecursivelyAsync(l,t,o,r)}return t}async collectEntitiesRecursivelyAsync(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(!t.has(a)){t.add(a);for(let i of Object.keys(e.body)){r.has(i)||r.set(i,[]);let n=r.get(i);n.includes(a)||n.push(a)}if(e.metadata.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await o.getHighestCompatibleVersionAsync(i,l);s&&await this.collectEntitiesRecursivelyAsync(s,r,t,o)}}}async buildDatatypePropertyNamesAsync(e,r){let t=new Set,o=new Set;if(await this.collectDatatypePropertiesAsync(e,t,o,r),e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let n of i){let l=await r.getHighestCompatibleVersionAsync(a,n);l&&await this.collectDatatypePropertiesAsync(l,t,o,r)}return t}async collectDatatypePropertiesAsync(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(!t.has(a)){t.add(a);for(let[i,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"&&r.add(i)}if(e.metadata.imports)for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await o.getHighestCompatibleVersionAsync(i,l);s&&await this.collectDatatypePropertiesAsync(s,r,t,o)}}}validateEntityReferences(e,r,t,o,a,i){for(let[n,l]of Object.entries(r)){let s=n;if(s&&!s.includes(".")){let c=t.get(s);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&i.push(this.createAmbiguityError(e,s,`Property '${s}'`,y,a,!0,s))}}this.validatePropertyValue(e,s,l,t,o,a,i)}}validatePropertyValue(e,r,t,o,a,i,n){if(t==null)return;let l=r&&r.includes(".")?r.substring(r.lastIndexOf(".")+1):r,s=!!l&&a.has(l);if(typeof t=="string"&&!t.includes(".")&&!s){let c=o.get(t);if(c&&c.length>1&&!c.some(y=>y.startsWith("(local:"))){let y=c.filter(m=>!m.startsWith("(local:"));y.length>1&&n.push(this.createAmbiguityError(e,r,`Reference '${t}'`,y,i,!1,t))}}else if(Array.isArray(t))for(let c=0;c<t.length;c++){let p=`${e}.${r}[${c}]`;this.validatePropertyValue(p,r,t[c],o,a,i,n)}else if(typeof t=="object"&&!Array.isArray(t)){let c=r?`${e}.${r}`:e;this.validateEntityReferences(c,t,o,a,i,n)}}createAmbiguityError(e,r,t,o,a,i,n){let l=[];for(let f of o){let b=this.findAliasForNamespace(a,f);if(b){let h=r?.split(".").pop()??r;l.push(`${b}.${h}`)}}let s=l.length>0?`Use one of: ${l.map(f=>`'${f}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${r}')`,c=o.map(f=>` \u2022 ${f}`).join(`
|
|
24
|
+
`),p=e.split(".")[0],y=e.includes(".")?e:r,m=new g;m.ruleType=this.ruleName,m.severity="Error",m.entityName=p,y&&(m.propertyName=y);let u=n??r;return u&&(m.actualValue=u),m.message=`${t} is ambiguous - defined in multiple imported namespaces`,m.suggestion=`${s}
|
|
25
|
+
|
|
26
|
+
Defined in:
|
|
27
|
+
${c}`,m.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",m}findAliasForNamespace(e,r){if(!e.metadata.imports)return null;for(let[t,o]of Object.entries(e.metadata.imports))for(let a of o)if(`${t}/${a.packageName}@${a.version}`===r&&a.alias)return a.alias;return null}};var H=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,r){let t=[],o=new Set;for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isValidRangeTargetType(l)&&o.add(a)}for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=n.type?.toString();if(l!=="DatatypeProperty"&&l!=="ObjectProperty"&&!l?.endsWith(".DatatypeProperty")&&!l?.endsWith(".ObjectProperty"))continue;let s=n.range;if(!s)continue;let c=[];if(Array.isArray(s))for(let p of s){let y=p?.toString();y&&c.push(y)}else{let p=s?.toString();p&&c.push(p)}if(c.length===0)continue;for(let p of c){if(this.primitiveTypes.has(p)||this.builtInClasses.has(p)||o.has(p))continue;if(!await this.isTypeAvailableInImports(e,r,p)){let m=l?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${a}' has range '${p}' which is not defined or imported`,u.suggestion=m==="ObjectProperty"?`For ObjectProperty:
|
|
28
|
+
1. Define '${p}' as a Class in this namespace, OR
|
|
29
|
+
2. Import the namespace that contains '${p}', OR
|
|
30
|
+
3. Use a qualified reference like 'alias.${p}' if already imported with an alias`:`For DatatypeProperty:
|
|
31
|
+
1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
|
|
32
|
+
2. If '${p}' should be a class, change property type to ObjectProperty`,u.entityName=a,u.propertyName="range",u.actualValue=p,u.expectedValue=m==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,a=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],a=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=o!==null?a:t,p=s.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isValidRangeTargetType(u))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(s,r,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,r,t,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let s=await r.getHighestCompatibleVersionAsync(i,l);if(s){let c=s.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(s,r,t,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var U=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,r){let t=[],o=new Map,a=new V(r);await a.buildEntityIndexAsync(e);for(let[i,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,s=!1,c=l.type;if(Array.isArray(c)){for(let p of c)if(p?.toString()==="ObjectProperty"){s=!0;break}}else c?.toString()==="ObjectProperty"&&(s=!0);if(s){let p=l.range,y=[];if(Array.isArray(p))for(let m of p){let u=m?.toString();u&&y.push(u)}else{let m=p?.toString();m&&y.push(m)}for(let m of y)this.xsdTypes.has(m)||(o.has(m)||o.set(m,[]),o.get(m).push(i))}}for(let[i,n]of o)if(!await a.resolveEntityAsync(i,e))for(let s of n){let c=new g;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${i}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${i}' is imported, or define '${i}' in this document`,c.entityName=s,c.propertyName="range",c.actualValue=i,t.push(c)}return t}};var F=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,r){let t=[],o=new V(r),a=new ce(o),i=await o.buildEntityIndexAsync(e),n=await this.buildPropertyMetadataAsync(e,r,o,i);for(let[l,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&await this.scanEntityForObjectProperties(s,l,"",n,o,a,e,t);return t}async scanEntityForObjectProperties(e,r,t,o,a,i,n,l){for(let[s,c]of Object.entries(e)){if(this.standardProperties.has(s))continue;let p,y=await a.resolveEntityAsync(s,n);if(y?.uri){let m=`${y.uri.publisher}/${y.uri.package_}/${y.uri.name}`;p=o.get(m)}if(!p){let m=s,u=s.lastIndexOf(".");u>0&&u<s.length-1&&(m=s.substring(u+1)),p=o.get(m)}if(p&&i.isEffectiveObjectProperty(p.propertyType,p.rangeUri)){let u=t?`${t}.${s}`:s;if(typeof c=="string"&&c.trim().length>0){let f=c.trim();if(f.includes(",")){let h=f.split(",").map(k=>k.trim()).filter(k=>k.length>0);l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
|
|
33
|
+
${s}:
|
|
34
|
+
- ${h[0]}
|
|
35
|
+
${h.slice(1).map(k=>` - ${k}`).join(`
|
|
36
|
+
`)}`,entityName:r,propertyName:s,propertyPath:u,actualValue:f,expectedValue:`A single reference to ${p.range??"an entity"} OR a YAML list`});continue}let b=await a.resolveEntityAsync(f,n);if(b)p.range&&(await this.validateRangeType(b,p.range,a,n)||l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${p.range}, but '${f}' may not be a ${p.range}`,suggestion:`Ensure '${f}' is defined with appropriate type`,entityName:r,propertyName:s,propertyPath:u,actualValue:f,expectedValue:p.range}));else{let h=p.range??"entity";l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${f}' which is not defined or imported`,suggestion:`Define '${f}' or import a namespace that contains it. Expected range: ${h}`,entityName:r,propertyName:s,propertyPath:u,actualValue:f,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let f=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,r,f,o,a,i,n,l)}else if(Array.isArray(c))for(let f=0;f<c.length;f++){let b=c[f];if(typeof b=="string"&&b.trim().length>0){let h=b.trim(),k=await a.resolveEntityAsync(h,n);if(k){if(p.range&&!await this.validateRangeType(k,p.range,a,n)){let Z=t?`${t}.${s}[${f}]`:`${s}[${f}]`;l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${s}' expects a ${p.range}, but '${h}' may not be a ${p.range}`,suggestion:`Ensure '${h}' is defined with appropriate type`,entityName:r,propertyName:`${s}[${f}]`,propertyPath:Z,actualValue:h,expectedValue:p.range})}}else{let oe=p.range??"entity",Z=t?`${t}.${s}[${f}]`:`${s}[${f}]`;l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${s}' references '${h}' which is not defined or imported`,suggestion:`Define '${h}' or import a namespace that contains it. Expected range: ${oe}`,entityName:r,propertyName:`${s}[${f}]`,propertyPath:Z,actualValue:h,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let h=t?`${t}.${s}[${f}]`:`${s}[${f}]`;await this.scanEntityForObjectProperties(b,r,h,o,a,i,n,l)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!o.has(s)){let m=t?`${t}.${s}`:s;await this.scanEntityForObjectProperties(c,r,m,o,a,i,n,l)}else if(Array.isArray(c))for(let m=0;m<c.length;m++){let u=c[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=t?`${t}.${s}[${m}]`:`${s}[${m}]`;await this.scanEntityForObjectProperties(u,r,f,o,a,i,n,l)}}}}async validateRangeType(e,r,t,o){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(r))return!0;let i=e.entity.type;if(i){let n=[];if(Array.isArray(i))for(let l of i){let s=l?.toString();s&&s.trim().length>0&&n.push(s)}else{let l=i?.toString();l&&l.trim().length>0&&n.push(l)}for(let l of n){let s=l.includes(".")?l.split(".")[1]:l;if(s===r||r==="Property"&&(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")||r==="Class"&&s==="Class"||await t.isSubclassOfAsync(l,r,o))return!0}}return!1}async buildPropertyMetadataAsync(e,r,t,o){let a=new Map;for(let[i,n]of o){let l=n.entity.type;if(l){let s=[];if(Array.isArray(l))for(let y of l){let m=y?.toString();m&&m.trim().length>0&&s.push(m)}else{let y=l?.toString();y&&y.trim().length>0&&s.push(y)}let c=!1,p="Property";for(let y of s){let m=y.includes(".")?y.split(".")[1]:y;if(m==="Property"||m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty"){c=!0,p=y;break}}if(c){let y={propertyType:p},m=n.entity.range;if(m){let u=m?.toString();if(u&&u.trim().length>0){y.range=u;let f=await t.resolveEntityAsync(u,e);f&&(y.rangeUri=f.uri)}}if(a.set(i,y),n.uri){let u=`${n.uri.publisher}/${n.uri.package_}/${n.uri.name}`;a.set(u,y)}}}}return a}};var B=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,r,t){let o=[],a=new Map;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let s=l,c=this.getPropertyValue(s,"type");(c==="DatatypeProperty"||c?.endsWith(".DatatypeProperty")||c==="ObjectProperty"||c?.endsWith(".ObjectProperty")||c==="AnnotationProperty"||c?.endsWith(".AnnotationProperty"))&&a.set(n,s)}let i=t?await this.buildClassHierarchyViaCache(e,t):await this.buildCompleteClassHierarchyAsync(e,r);for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let s=l,c=this.getPropertyValue(s,"type");if(!c||c==="Class"||c.endsWith(".Class")||c.endsWith("Property")||c==="AnnotationProperty")continue;this.validateEntityProperties(s,n,c,a,i,o)}return o}async buildClassHierarchyViaCache(e,r){let t=new Map,o=he(e);if(!o)return t;let a=await r.getImportClosure(o);for(let i of a){let n=await r.getClassDeclarations(i);for(let[l,s]of n)s.length>0&&t.set(l,s)}return t}async buildCompleteClassHierarchyAsync(e,r){let t=new Map,o=new Set,a=async(n,l)=>{if(!o.has(l)){o.add(l);for(let[s,c]of Object.entries(n.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let p=c,y=this.getPropertyValue(p,"type");if(y==="Class"||y?.endsWith(".Class")){let m=p.subClassOf;if(m===void 0){for(let f of Object.keys(p))if(f.endsWith(".subClassOf")){m=p[f];break}}let u=P(m);u.length>0&&t.set(s,u)}}if(n.metadata.imports)for(let[s,c]of Object.entries(n.metadata.imports))for(let p of c)try{let y=await r.getHighestCompatibleVersionAsync(s,p);if(y){let m=`${s}/${p.packageName}@${p.version}`;await a(y,m)}}catch{}}},i=e.metadata.namespace_?.toString()??"unknown";return await a(e,i),t}validateEntityProperties(e,r,t,o,a,i){for(let[n,l]of Object.entries(e)){if(this.standardProperties.has(n))continue;let s=n,c=n.lastIndexOf(".");c>0&&c<n.length-1&&(s=n.substring(c+1));let p=o.get(s);if(!p)continue;let y=this.getPropertyValue(p,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,a)){let m=r.split(".")[0];i.push({ruleType:this.ruleName,severity:"Error",entityName:m,propertyName:r,actualValue:n,message:`Property '${n}' has domain '${y}' but is used on '${t}' at '${r}'`,suggestion:`Either:
|
|
37
|
+
1. Use this property only on '${y}' instances
|
|
38
|
+
2. Change the property domain to include '${t}'
|
|
39
|
+
3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let m=l,u=this.getPropertyValue(m,"type");if(u){let f=`${r}.${n}`;this.validateEntityProperties(m,f,u,o,a,i)}else{let f=this.getPropertyValue(p,"range");if(f){let b=`${r}.${n}`;this.validateEntityProperties(m,b,f,o,a,i)}}}else if(Array.isArray(l))for(let m=0;m<l.length;m++){let u=l[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,b=this.getPropertyValue(f,"type");if(b){let h=`${r}.${n}[${m}]`;this.validateEntityProperties(f,h,b,o,a,i)}else{let h=this.getPropertyValue(p,"range");if(h){let k=`${r}.${n}[${m}]`;this.validateEntityProperties(f,k,h,o,a,i)}}}}}}}isTypeCompatibleWithDomain(e,r,t){if(e===r)return!0;let o=new Set,a=[e];for(;a.length>0;){let i=a.shift();if(o.has(i))continue;o.add(i);let n=t.get(i);if(n)for(let l of n){if(l===r)return!0;a.push(l)}}return!1}getPropertyValue(e,r){if(r in e){let t=e[r];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${r}`)){let o=e[t];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let r=[];for(let t of e)r.push(t?.toString()??"");return r.length>0?r[0]:void 0}return e?.toString()}};function he(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${A(e.version)}`}var q=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,r){let t=[],o=new Map;for(let[a,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=this.getPropertyValue(n,"type");(l==="DatatypeProperty"||l==="ObjectProperty")&&o.set(a,n)}for(let[a,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let n=i,l=this.getPropertyValue(n,"type");if(!(!l||l==="Class"||l.endsWith("Property")||l==="AnnotationProperty"))for(let[s,c]of Object.entries(n)){if(s==="type"||s==="label"||s==="comment")continue;let p=s,y=s.lastIndexOf(".");y>0&&y<s.length-1&&(p=s.substring(y+1));let m=o.get(p);if(!m)continue;let u=this.getPropertyValue(m,"type"),f=this.getPropertyValue(m,"range");if(u==="DatatypeProperty"){if(typeof c=="object"&&c!==null&&!Array.isArray(c)||Array.isArray(c))t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:s,message:`Property '${s}' is a DatatypeProperty with range '${f}' but instance '${a}' has a complex object value`,suggestion:`Either:
|
|
40
|
+
1. Create a class for this data and change '${s}' 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,c)){let b={ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:s,message:`Property '${s}' expects type '${f}' but instance '${a}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(b.expectedValue=f),t.push(b)}}else if(u==="ObjectProperty")if(Array.isArray(c))for(let b=0;b<c.length;b++){let h=c[b];typeof h!="string"&&(typeof h!="object"||h===null||Array.isArray(h))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:`${s}[${b}]`,message:`ObjectProperty '${s}' array item ${b} in instance '${a}' has invalid type '${this.getValueTypeName(h)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:s,message:`ObjectProperty '${s}' in instance '${a}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,r){switch(e?.toLowerCase()){case"string":return typeof r=="string";case"integer":case"int":return typeof r=="number"&&Number.isInteger(r);case"decimal":return typeof r=="number";case"boolean":return typeof r=="boolean";case"float":case"double":return typeof r=="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,r){if(r in e){let t=e[r];if(Array.isArray(t)){let o=[];for(let a of t)o.push(a?.toString()??"");return o.length>0?o[0]:void 0}return t?.toString()}}};var X=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty","Package"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,r){let t=[],o=new Map,a=new Set;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let c=l.type;if(c)if(Array.isArray(c))for(let p of c){let y=p?.toString();if(y==="Class"||y&&y.endsWith(".Class")){a.add(n);break}}else{let p=c?.toString();(p==="Class"||p&&p.endsWith(".Class"))&&a.add(n)}}for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let s=l,c=s.type;if(c)if(Array.isArray(c)){let p=!1;for(let y of c){let m=y?.toString();if(m&&this.isDefinitionType(m)){p=!0;break}}if(!p)for(let y of c){let m=y?.toString();m&&m.trim().length>0&&(o.has(m)||o.set(m,[]),o.get(m).push(n))}}else{let p=c?.toString();p&&p.trim().length>0&&(this.isDefinitionType(p)||(o.has(p)||o.set(p,[]),o.get(p).push(n)))}this.checkNestedTypes(s,n,o,n)}let i=new V(r);for(let[n,l]of o){if(this.builtInClasses.has(n)||a.has(n))continue;let s=await i.resolveEntityAsync(n,e);if(!(s&&this.isClassEntity(s.entity))){let p=Array.from(new Set(l)).sort();for(let y of p)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:y,propertyName:"type",actualValue:n,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,r,t,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=e,i=a.type;if(i){let n=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(i))for(let l of i){let s=l?.toString();s&&s.trim().length>0&&!n.has(s)&&(t.has(s)||t.set(s,[]),t.get(s).push(o))}else{let l=i?.toString();l&&l.trim().length>0&&!n.has(l)&&(t.has(l)||t.set(l,[]),t.get(l).push(o))}}for(let[n,l]of Object.entries(a))if(n!=="type"){let s=`${o}.${n}`;this.checkNestedTypes(l,r,t,s)}}else if(Array.isArray(e))for(let a=0;a<e.length;a++){let i=`${o}[${a}]`;this.checkNestedTypes(e[a],r,t,i)}}isClassEntity(e){if(!e)return!1;let r=e.type;if(!r)return!1;if(Array.isArray(r))for(let t of r){let o=t?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let t=r?.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 z=class{ruleName="MarkdownLink";async validateAsync(e,r,t){let o=[],a;if(t){let i=await t.getKanonaks(),n=be(e);a=n?i.filter(l=>l instanceof G&&l.namespace===n):[]}else{let i=new ye(e,r);a=await new Y().parseKanonaks(i)}for(let i of a)i instanceof G&&this.checkDefined(i,i.name,o);return o}checkDefined(e,r,t){for(let o of e.statement)if(o instanceof le){let a=o.predicate.subject?.name??"(unknown)";for(let i of o.links)i.target||t.push(this.unresolvedLinkError(r,a,i.reference));for(let i of pe(o.object))t.push(this.malformedLinkError(r,a,i.snippet))}else if(o instanceof se)this.checkDefined(o.object,r,t);else if(o instanceof ae)for(let a of o.object)a instanceof ie&&this.checkDefined(a,r,t)}unresolvedLinkError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Warning",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`Embedded link [[${t}]] in '${r}' could not be resolved`,o.expectedValue="A reference resolvable through the document's import closure",o.suggestion=`The reference '${t}' inside a markdown value cannot be found in the current document or any imported namespace.
|
|
43
|
+
|
|
44
|
+
Possible solutions:
|
|
45
|
+
\u2022 Import the package that defines '${t}' so the link can resolve
|
|
46
|
+
\u2022 Check for typos in the reference name
|
|
47
|
+
\u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,o}malformedLinkError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`Malformed embedded reference near '${t}' in '${r}'`,o.expectedValue="A single-line [[reference]] with no internal line break",o.suggestion=`A '[[' in '${r}' does not form a complete [[reference]] link.
|
|
48
|
+
|
|
49
|
+
A reference may not span a line break \u2014 the most common cause is wrapping a
|
|
50
|
+
long reference across two lines in a block scalar, e.g.:
|
|
51
|
+
... read for [[persistent-energy-
|
|
52
|
+
shock]] held ...
|
|
53
|
+
which is parsed as literal text, not a link. Keep each [[reference]] on one
|
|
54
|
+
line (let the line run long), or check for an unterminated [[.`,o}};function be(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${A(e.version)}`}var re=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new ne,this.documentRules=[new v,new I,new O,new w],this.repositoryRules=[new j,new E,new N,new $,new S,new C,new K,new T,new x,new M,new W,new L,new _,new H,new U,new F,new B,new q,new X,new z]}async validateAsync(e,r,t){let o=new D;for(let a of this.documentRules)try{let i=a.validate(e);this.addErrorsToResult(o,i)}catch(i){let n=new g;n.ruleType=a.ruleName,n.severity="Error",n.message=`Validation rule '${a.ruleName}' failed: ${i instanceof Error?i.message:String(i)}`,o.errors.push(n)}if(r){let a=[],i=t?.repository??r;for(let n of this.repositoryRules)try{let l=await n.validateAsync(e,i,t);this.addErrorsToResult(o,l)}catch(l){let s=l instanceof Error?l.message:String(l);a.push({ruleName:n.ruleName,cause:s})}if(a.length>0){let n=new Map;for(let{ruleName:l,cause:s}of a){let c=n.get(s);c?c.push(l):n.set(s,[l])}for(let[l,s]of n){let c=new g;c.ruleType=s[0],c.severity="Error",s.length===1?c.message=`Validation rule '${s[0]}' failed: ${l}`:c.message=`${l} (affects ${s.length} rules: ${s.join(", ")})`,o.errors.push(c)}}}return o.isValid=o.errors.length===0,o}async validateYamlAsync(e,r,t){let o=this.parser.parseWithErrors(e);if(!o.isValid){let a=new D;a.isValid=!1;for(let i of o.errors){let n=new g;n.ruleType="ParseError",n.severity="Error",n.lineNumber=i.line,n.column=i.column,n.message=i.message,i.keyName&&(n.entityName=i.keyName),i.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),a.errors.push(n)}return a}return await this.validateAsync(o.document,r,t)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let r=this.documentRules.findIndex(t=>t instanceof e);r>=0&&this.documentRules.splice(r,1)}removeRepositoryRule(e){let r=this.repositoryRules.findIndex(t=>t instanceof e);r>=0&&this.repositoryRules.splice(r,1)}addErrorsToResult(e,r){for(let t of r)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{D as a,R as b,g as c,J as d,ee as e,v as f,I as g,O as h,w as i,j,E as k,N as l,$ as m,S as n,C as o,K as p,T as q,x as r,M as s,W as t,L as u,_ as v,H as w,U as x,F as y,B as z,q as A,X as B,z as C,re as D};
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type { IStatement } from './statements/index.js';
|
|
|
15
15
|
export type { MarkdownLink } from './statements/index.js';
|
|
16
16
|
export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement, MarkdownStatement } from './statements/index.js';
|
|
17
17
|
export { extractMarkdownLinks, findMalformedReferences, type RawMarkdownLink, type MalformedMarkdownLink, } from './parsing/extractMarkdownLinks.js';
|
|
18
|
-
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule,
|
|
18
|
+
export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, ValidationCache, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, MarkdownLinkRule } from './validation/index.js';
|
|
19
19
|
export type { IKanonakObjectValidator, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
|
|
20
20
|
export type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
21
21
|
export type { IKanonakParser } from '@kanonak-protocol/types/document/parsing';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{a as et,b as tt,c as rt,d as nt,e as ot,f as at,g as it,h as st,i as ct,j as lt}from"./chunk-
|
|
1
|
+
import{a as et,b as tt,c as rt,d as nt,e as ot,f as at,g as it,h as st,i as ct,j as lt}from"./chunk-IOJMTW4T.js";import{b as Xt}from"./chunk-O4GZ6W5Z.js";import{a as Xe,b as Ze,c as Qe,d as b,e as S,f as i}from"./chunk-RCI34BYO.js";import{a as Yt}from"./chunk-BFZZ6YGX.js";import{a as Te,b as je,c as Le,d as Fe,e as Ne}from"./chunk-5AH6GIPO.js";import{a as Be,b as De,c as Oe,d as Ae}from"./chunk-VQFL5C7Q.js";import{a as ut,b as pt,c as mt,d as ft}from"./chunk-NIJV5UYW.js";import{a as Ye,b as yt,c as gt,d as ht,e as bt}from"./chunk-4TJZIM7A.js";import{a as kt}from"./chunk-NIGFQYVA.js";import{A as Gt,B as Wt,C as Jt,D as qt,a as St,b as Ct,c as Pt,d as Rt,e as wt,f as xt,g as $t,h as vt,i as Et,j as Kt,k as Bt,l as It,m as Tt,n as jt,o as Lt,p as Ft,q as Nt,r as Dt,s as Ot,t as At,u as Ut,v as Mt,w as Vt,x as Ht,y as _t,z as zt}from"./chunk-SKTXJV4T.js";import"./chunk-FJ35VIV6.js";import{a as F,b as D,c as _e,d as We,e as Je,f as qe}from"./chunk-FMYLEPMC.js";import{a as Ue,b as j,c as L,d as N,e as Ve,f as He,g as O,h as A,i as U,j as M,k as V,l as H}from"./chunk-W6T7MOKY.js";import{a as Ie}from"./chunk-7CUTGGH3.js";import{a as Pe,b as Re,c as we,d as xe,e as $e,f as ve,g as Ee,h as Ke}from"./chunk-FQHALFRR.js";import{b as ze,c as Ge}from"./chunk-HEMBMX7T.js";import{a as Me}from"./chunk-FUUTGGJS.js";import{a as dt}from"./chunk-ODIECDN7.js";import{VersionOperator as io}from"@kanonak-protocol/types/document/models/enums";import{existsSync as yr,readFileSync as gr}from"fs";import{homedir as hr}from"os";import{join as kr}from"path";import{execFile as Zt}from"child_process";import{promisify as Qt}from"util";var C=Qt(Zt),P="kanonak",R="/usr/bin/security",p=class{async get(e){let r=i(e);try{let{stdout:n}=await C(R,["find-generic-password","-s",P,"-a",r,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${r}' is corrupted (not valid JSON).
|
|
2
2
|
Run 'kanonak logout ${r}' then 'kanonak login ${r}' to fix.`)}}catch(n){if(X(n,44))return null;throw new Error(`macOS Keychain read failed for '${r}': ${w(n)}
|
|
3
3
|
The Keychain may be locked or inaccessible.
|
|
4
4
|
Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,r){let n=i(e),o=JSON.stringify(r);try{await C(R,["add-generic-password","-s",P,"-a",n,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${n}': ${w(a)}
|
|
5
5
|
Ensure the Keychain is unlocked and the CLI has write permission.
|
|
6
6
|
On managed devices, your IT policy may block credential storage.`)}}async remove(e){let r=i(e);try{await C(R,["delete-generic-password","-s",P,"-a",r],{timeout:1e4})}catch(n){if(X(n,44))return;console.warn(` Warning: macOS Keychain delete failed for '${r}': ${w(n)}
|
|
7
7
|
The credential may not have been fully removed.`)}}async list(){try{let{stdout:e}=await C(R,["dump-keychain"],{timeout:1e4}),r=[],n=!1;for(let o of e.split(`
|
|
8
|
-
`))if(o.includes(`"svce"<blob>="${P}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&r.push(a[1]),n=!1}return r}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${w(e)}`),[]}}};function X(t,e){return typeof t=="object"&&t!==null&&"code"in t&&t.code===e}function w(t){return t instanceof Error?t.message:String(t)}import{execFile as
|
|
8
|
+
`))if(o.includes(`"svce"<blob>="${P}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&r.push(a[1]),n=!1}return r}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${w(e)}`),[]}}};function X(t,e){return typeof t=="object"&&t!==null&&"code"in t&&t.code===e}function w(t){return t instanceof Error?t.message:String(t)}import{execFile as er}from"child_process";import{promisify as tr}from"util";var rr=tr(er),x="kanonak:",m=class{async get(e){let r=x+i(e),n=`
|
|
9
9
|
${v}
|
|
10
10
|
$target = [Console]::In.ReadLine()
|
|
11
11
|
$ptr = [IntPtr]::Zero
|
|
@@ -41,7 +41,7 @@ ${v}
|
|
|
41
41
|
$target = [Console]::In.ReadLine()
|
|
42
42
|
[CredMan]::CredDelete($target, 1, 0) | Out-Null`;try{await $(n,r)}catch{}}async list(){let e=`
|
|
43
43
|
${v}
|
|
44
|
-
${
|
|
44
|
+
${nr}
|
|
45
45
|
$prefix = [Console]::In.ReadLine()
|
|
46
46
|
$count = 0
|
|
47
47
|
$pCreds = [IntPtr]::Zero
|
|
@@ -56,7 +56,7 @@ if ([CredMan]::CredEnumerate($null, 0, [ref]$count, [ref]$pCreds)) {
|
|
|
56
56
|
}
|
|
57
57
|
[CredMan]::CredFree($pCreds)
|
|
58
58
|
}`;try{let{stdout:r}=await $(e,x);return r.trim().split(`
|
|
59
|
-
`).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function $(t,e){for(let r of["pwsh","powershell"])try{return await
|
|
59
|
+
`).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function $(t,e){for(let r of["pwsh","powershell"])try{return await rr(r,["-NoProfile","-NonInteractive","-Command",t],{timeout:15e3,...e!==void 0&&{input:e}})}catch(n){if(r==="powershell")throw n}throw new Error("Neither pwsh nor powershell found")}var v=`
|
|
60
60
|
Add-Type -TypeDefinition @"
|
|
61
61
|
using System;
|
|
62
62
|
using System.Runtime.InteropServices;
|
|
@@ -87,13 +87,13 @@ public class CredMan {
|
|
|
87
87
|
[DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
88
88
|
public static extern bool CredEnumerate(string filter, int flags, out int count, out IntPtr credentials);
|
|
89
89
|
}
|
|
90
|
-
"@`,
|
|
91
|
-
`)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&r.push(o[1].trim())}return r}catch{return[]}}};async function _(){try{return await K("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as Z,mkdirSync as Q,readFileSync as ee,writeFileSync as te}from"fs";import{createCipheriv as
|
|
90
|
+
"@`,nr="";import{execFile as or,spawn as ar}from"child_process";import{promisify as ir}from"util";var K=ir(or),E="kanonak",f=class{async get(e){let r=i(e);try{let{stdout:n}=await K("secret-tool",["lookup","service",E,"publisher",r],{timeout:1e4}),o=n.trim();return o?JSON.parse(o):null}catch{return null}}async store(e,r){let n=i(e),o=JSON.stringify(r);await new Promise((a,s)=>{let c=ar("secret-tool",["store","--label",`Kanonak: ${n}`,"service",E,"publisher",n],{stdio:["pipe","ignore","ignore"],timeout:1e4});c.stdin.write(o),c.stdin.end(),c.on("close",l=>{l===0?a():s(new Error(`secret-tool store exited with code ${l}`))}),c.on("error",s)})}async remove(e){let r=i(e);try{await K("secret-tool",["clear","service",E,"publisher",r],{timeout:1e4})}catch{}}async list(){try{let{stdout:e}=await K("secret-tool",["search","service",E],{timeout:1e4}),r=[];for(let n of e.split(`
|
|
91
|
+
`)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&r.push(o[1].trim())}return r}catch{return[]}}};async function _(){try{return await K("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as Z,mkdirSync as Q,readFileSync as ee,writeFileSync as te}from"fs";import{createCipheriv as sr,createDecipheriv as cr,randomBytes as re}from"crypto";import{homedir as lr}from"os";import{join as W,dirname as ne}from"path";var ae=W(lr(),".config","kanonak"),y=W(ae,"keyring.key"),B=W(ae,"credentials.enc"),oe="aes-256-gcm",z=32,u=12,G=16,g=class{async get(e){let r=this.loadStore(),n=i(e);return r[n]??null}async store(e,r){let n=this.loadStore(),o=i(e);n[o]=r,this.saveStore(n)}async remove(e){let r=this.loadStore(),n=i(e);delete r[n],this.saveStore(r)}async list(){let e=this.loadStore();return Object.keys(e)}loadStore(){if(!Z(B))return{};try{let e=this.getOrCreateKey(),r=ee(B);if(r.length<u+G)return{};let n=r.subarray(0,u),o=r.subarray(u,u+G),a=r.subarray(u+G),s=cr(oe,e,n);s.setAuthTag(o);let c=Buffer.concat([s.update(a),s.final()]);return JSON.parse(c.toString("utf-8"))}catch{return{}}}saveStore(e){let r=this.getOrCreateKey(),n=re(u),o=sr(oe,r,n),a=Buffer.from(JSON.stringify(e),"utf-8"),s=Buffer.concat([o.update(a),o.final()]),c=o.getAuthTag(),l=Buffer.concat([n,c,s]);Q(ne(B),{recursive:!0}),te(B,l,{mode:384})}getOrCreateKey(){if(Z(y)){let r=ee(y);if(r.length!==z)throw new Error(`Credential keyring key is corrupted (expected ${z} bytes, got ${r.length}). Delete ${y} and re-authenticate.`);return r}let e=re(z);return Q(ne(y),{recursive:!0}),te(y,e,{mode:384}),e}};import{execFile as dr}from"child_process";import{promisify as ur}from"util";var pr=ur(dr),ie=3e4,h=class{constructor(e){this.helperPath=e}helperPath;async get(e){let r=i(e);try{let o=(await this.runHelper("get",{publisher:r})).trim();return o?JSON.parse(o):null}catch(n){throw new Error(`Credential helper '${this.helperPath}' failed to read credential for '${r}': ${I(n)}
|
|
92
92
|
Verify the helper binary exists, is executable, and implements the Kanonak credential helper protocol.
|
|
93
93
|
Check the 'credentialHelper' path in ~/.kanonak/config.json.`)}}async store(e,r){let n=i(e);try{await this.runHelper("store",{publisher:n,credential:r})}catch(o){throw new Error(`Credential helper '${this.helperPath}' failed to store credential for '${n}': ${I(o)}
|
|
94
|
-
Verify the helper binary supports the 'store' action.`)}}async remove(e){let r=i(e);try{await this.runHelper("erase",{publisher:r})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${r}': ${I(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${I(e)}`),[]}}async runHelper(e,r){try{let{stdout:n}=await
|
|
95
|
-
Check the 'credentialHelper' path in ~/.kanonak/config.json.`):
|
|
96
|
-
The helper may be waiting for authentication to an external vault.`):n}}};function I(t){return t instanceof Error?t.message:String(t)}function
|
|
97
|
-
Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as
|
|
98
|
-
The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),s.Authorization=`Bearer ${a.accessToken}`}}else s.Authorization=`Bearer ${a.accessToken}`;let c=await fetch(r,{method:o,headers:s});if(c.status===401&&a.dpopKeyPair){let l=c.headers.get("DPoP-Nonce");if(l){e.set(n,l);try{let d=k(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,r,a.accessToken,l);s.DPoP=d,c=await fetch(r,{method:o,headers:s})}catch{}}}return c}}import{readFileSync as
|
|
99
|
-
`;function me(t=pe){if(!
|
|
94
|
+
Verify the helper binary supports the 'store' action.`)}}async remove(e){let r=i(e);try{await this.runHelper("erase",{publisher:r})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${r}': ${I(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${I(e)}`),[]}}async runHelper(e,r){try{let{stdout:n}=await pr(this.helperPath,[e],{...r&&{input:JSON.stringify(r)},timeout:ie});return n}catch(n){throw mr(n)?new Error(`Credential helper not found at '${this.helperPath}'.
|
|
95
|
+
Check the 'credentialHelper' path in ~/.kanonak/config.json.`):fr(n)?new Error(`Credential helper '${this.helperPath}' timed out after ${ie/1e3}s on '${e}'.
|
|
96
|
+
The helper may be waiting for authentication to an external vault.`):n}}};function I(t){return t instanceof Error?t.message:String(t)}function mr(t){return t instanceof Error&&"code"in t&&t.code==="ENOENT"}function fr(t){return t instanceof Error&&"killed"in t&&t.killed}var J=kr(hr(),".kanonak","config.json"),T=class{backend=null;backendReady=null;async getBackend(){if(this.backend)return this.backend;if(this.backendReady)return this.backendReady;this.backendReady=this.resolveBackend();try{return this.backend=await this.backendReady,this.backend}catch(e){throw this.backendReady=null,e}}async getToken(e){let r=br(e);if(r)return r;let o=await(await this.getBackend()).get(e);return!o||!S(o)?null:o.accessToken??null}async getCredential(e){return(await this.getBackend()).get(e)}async store(e,r){return(await this.getBackend()).store(e,r)}async remove(e){return(await this.getBackend()).remove(e)}async list(){return(await this.getBackend()).list()}async resolveBackend(){let e=Sr();return e.credentialHelper?new h(e.credentialHelper):process.platform==="darwin"?new p:process.platform==="win32"?new m:await _()?new f:new g}};function br(t){let r="KANONAK_TOKEN_"+i(t).replace(/[.\-]/g,"_").toUpperCase();return process.env[r]??null}function Sr(){if(!yr(J))return{};try{return JSON.parse(gr(J,"utf-8"))}catch(t){let e=t instanceof Error?t.message:String(t);return console.warn(` Warning: Failed to parse ${J}: ${e}
|
|
97
|
+
Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as Cr,createPrivateKey as Pr,generateKeyPairSync as Rr,randomUUID as wr,sign as xr}from"crypto";function ce(){let{publicKey:t,privateKey:e}=Rr("ec",{namedCurve:"P-256"});return{publicKey:t.export({format:"jwk"}),privateKey:e.export({format:"jwk"})}}function k(t,e,r,n,o,a){let s={alg:"ES256",typ:"dpop+jwt",jwk:{kty:e.kty,crv:e.crv,x:e.x,y:e.y}},c={jti:wr(),htm:r.toUpperCase(),htu:n,iat:Math.floor(Date.now()/1e3)};return o&&(c.ath=Cr("sha256").update(o).digest("base64url")),a&&(c.nonce=a),$r(s,c,t)}function le(t){return!t||t.length===0?!1:t.some(e=>e.toUpperCase()==="ES256")}function $r(t,e,r){let n=se(JSON.stringify(t)),o=se(JSON.stringify(e)),a=`${n}.${o}`,s=Pr({key:r,format:"jwk"}),l=xr("SHA256",Buffer.from(a),{key:s,dsaEncoding:"ieee-p1363"}).toString("base64url");return`${a}.${l}`}function se(t){return Buffer.from(t,"utf-8").toString("base64url")}function de(t){let e=new Map;return async(r,n,o="GET")=>{if(!t)return fetch(r,{method:o});let a=await t.getCredential(n);if(!a?.accessToken)return fetch(r,{method:o});b(a)&&console.warn(` Warning: Access token for '${n}' is expired. Run 'kanonak login ${n}' to re-authenticate.`);let s={};if(a.dpopKeyPair){let l=e.get(n);try{let d=k(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,r,a.accessToken,l);s.Authorization=`DPoP ${a.accessToken}`,s.DPoP=d}catch(d){let Ce=d instanceof Error?d.message:String(d);console.error(` Error: Failed to create DPoP proof for '${n}': ${Ce}
|
|
98
|
+
The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),s.Authorization=`Bearer ${a.accessToken}`}}else s.Authorization=`Bearer ${a.accessToken}`;let c=await fetch(r,{method:o,headers:s});if(c.status===401&&a.dpopKeyPair){let l=c.headers.get("DPoP-Nonce");if(l){e.set(n,l);try{let d=k(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,r,a.accessToken,l);s.DPoP=d,c=await fetch(r,{method:o,headers:s})}catch{}}}return c}}import{readFileSync as vr,writeFileSync as Er,existsSync as Kr}from"fs";import{createHash as Br}from"crypto";import ue from"js-yaml";var pe="kanonak.lock",Ir=`# This file is generated by Kanonak CLI. Do not edit manually.
|
|
99
|
+
`;function me(t=pe){if(!Kr(t))return null;let e=vr(t,"utf-8"),r=ue.load(e);return!r||typeof r!="object"||r.version!=="1"?null:{version:"1",lastUpdated:r.lastUpdated??new Date().toISOString(),packages:r.packages??{}}}function fe(t,e=pe){t.lastUpdated=new Date().toISOString();let r={};for(let o of Object.keys(t.packages).sort())r[o]=t.packages[o];t.packages=r;let n=ue.dump(t,{lineWidth:-1,sortKeys:!1,quotingType:'"'});Er(e,Ir+n,"utf-8")}function ye(t){return`sha256:${Br("sha256").update(t).digest("hex")}`}import{createHash as Tr}from"crypto";function q(t){let e=[];for(let n of t)n instanceof L&&e.push(jr(n));return e.sort((n,o)=>n.uri<o.uri?-1:n.uri>o.uri?1:0),JSON.stringify({subjects:e})}function ge(t){let e=q(t);return`sha256:${Tr("sha256").update(e,"utf8").digest("hex")}`}function jr(t){let e=Ar(t),r=Y(t.statement);return{uri:e,statements:r}}function Y(t){let e=[];for(let r of t){let n=Lr(r);n&&e.push(n)}return e.sort((r,n)=>r.predicate<n.predicate?-1:r.predicate>n.predicate?1:0),e}function Lr(t){let e=Or(t);if(!e)return;let r=Fr(t);if(r)return Dr(e,r)}function Fr(t){if(t instanceof O)return{type:"string",value:t.object};if(t instanceof A)return{type:"number",value:Se(t.object)};if(t instanceof U)return{type:"boolean",value:t.object};if(t instanceof M)return{type:"ref",value:ke(t.object)};if(t instanceof V){let e=t.object;return he(e)}if(t instanceof H)return{type:"list",items:t.object.map(Nr)}}function he(t){let e=Y(t.statement);return t.name&&t.name.length>0?{type:"embedded",name:t.name,statements:e}:{type:"embedded",statements:e}}function Nr(t){if(t instanceof N)return{type:"ref",value:ke(t)};if(t instanceof F)return he(t);if(t instanceof D){let e=t.value;if(typeof e=="string")return{type:"string",value:e};if(typeof e=="number")return{type:"number",value:Se(e)};if(typeof e=="boolean")return{type:"boolean",value:e}}if(t instanceof j)return{type:"embedded",statements:Y(t.statement)};throw new Error(`canonicalForm: list item of unrecognized kind (${t.constructor?.name??typeof t}); add canonicalization support before hashing data that contains it`)}function Dr(t,e){switch(e.type){case"string":return{predicate:t,type:"string",value:e.value};case"number":return{predicate:t,type:"number",value:e.value};case"boolean":return{predicate:t,type:"boolean",value:e.value};case"ref":return{predicate:t,type:"ref",value:e.value};case"embedded":return e.name!==void 0?{predicate:t,type:"embedded",name:e.name,statements:e.statements}:{predicate:t,type:"embedded",statements:e.statements};case"list":return{predicate:t,type:"list",items:e.items}}}function Or(t){let e=t.predicate;if(e)return be(e.subject)}function Ar(t){let e=t.namespace??"",r=t.name??"";return`${e}/${r}`}function ke(t){return be(t.subject)}function be(t){let e=t.version;return e&&typeof e.major=="number"?`${t.publisher}/${t.package_}@${e.major}.${e.minor}.${e.patch}/${t.name}`:`${t.publisher}/${t.package_}/${t.name}`}function Se(t){if(Number.isNaN(t))throw new Error("canonicalForm: NaN cannot be canonicalized");if(!Number.isFinite(t))throw new Error("canonicalForm: \xB1Infinity cannot be canonicalized");return Object.is(t,-0)?"0":String(t)}export{Mt as AmbiguousReferenceRule,U as BooleanStatement,Wt as ClassDefinitionRule,Tt as ClassHierarchyCycleRule,Le as CompositeKanonakDocumentRepository,T as CredentialStore,j as DefinedKanonak,At as DefinitionPropertyReferenceRule,je as DocumentLocation,Ze as EdgeType,F as EmbeddedKanonak,Kt as EmbeddedKanonakTypeRule,V as EmbeddedStatement,Te as FileSystemKanonakDocumentRepository,dt as GitIgnoreFilter,Qe as GraphBuilder,Ae as HttpKanonakDocumentRepository,Bt as ImportExistenceRule,Be as InMemoryKanonakDocumentRepository,Ot as InstancePropertyReferenceRule,Ue as Kanonak,pt as KanonakDocumentPositions,qe as KanonakObjectParser,qt as KanonakObjectValidator,Ie as KanonakParser,Me as KanonakUri,yt as KanonakUriBuilder,kt as KanonakUrlResolver,at as KanonakVocabulary,H as ListStatement,D as LiteralKanonak,Xt as LookRenderer,Jt as MarkdownLinkRule,_e as MarkdownStatement,Dt as NamespaceImportCycleRule,xt as NamespacePrefixRule,Xe as NodeType,A as NumberStatement,st as OWL_RL_CLASSIFICATION_RULES,Ht as ObjectPropertyImportRule,_t as ObjectPropertyValueValidationRule,Pt as OntologyValidationError,St as OntologyValidationResult,zt as PropertyDomainRule,jt as PropertyHierarchyCycleRule,ut as PropertyMetadata,Vt as PropertyRangeReferenceRule,Lt as PropertyRangeRequiredRule,vt as PropertyTypeSpecificityRule,Gt as PropertyValueTypeRule,De as PublisherConfigResolver,Oe as PublisherIndex,it as RDFS_RULES,lt as Reasoner,ct as ReasoningResult,N as ReferenceKanonak,M as ReferenceStatement,Ne as RepositoryFactory,$t as ResourceNamingRule,ze as ResourceResolver,Ye as ResourceTypeClassifier,He as ScalarStatement,Ve as Statement,O as StringStatement,Ft as SubClassOfReferenceRule,Nt as SubPropertyOfReferenceRule,L as SubjectKanonak,Et as SubjectKanonakTypeRequiredRule,ot as TripleStore,Ge as TypeResolver,It as UnresolvedReferenceRule,wt as ValidationCache,Rt as ValidationContext,Ct as ValidationSeverity,io as VersionOperator,Ut as XsdImportRule,q as canonicalForm,ge as canonicalHash,Pe as compareVersions,ye as computeIntegrity,de as createAuthenticatedFetch,k as createDPoPProof,xe as createVersion,Je as extractMarkdownLinks,Yt as findDerivation,bt as findInstancesByType,We as findMalformedReferences,ft as findMarkdownLinkAt,ht as formatKanonakAddress,we as formatVersion,ce as generateDPoPKeyPair,Fe as getGlobalCachePath,S as hasValidToken,ve as isCompatibleVersion,b as isExpired,Ee as isMajorCompatible,me as loadLockFile,tt as makeUriKey,i as normalizeHost,gt as parseKanonakAddress,$e as parseVersionString,mt as parseWithPositions,Ke as pickHighestDocument,fe as saveLockFile,le as serverSupportsDPoP,rt as tripleKey,et as uriKey,nt as uriTriple,Re as versionsEqual};
|
|
@@ -269,6 +269,15 @@ export declare class LookRenderer {
|
|
|
269
269
|
* "why" is left to a neighbouring prose band. Ontology-neutral.
|
|
270
270
|
*/
|
|
271
271
|
private renderVersionDelta;
|
|
272
|
+
/**
|
|
273
|
+
* Render a TimePlot band — the referenced resources held by `source`
|
|
274
|
+
* plotted on a horizontal time axis (`orderBy` is the date property read
|
|
275
|
+
* on each), optionally split into lanes by `laneBy` (a path to a category
|
|
276
|
+
* value, e.g. a strength) and colored per lane. Each point carries a
|
|
277
|
+
* native hover tooltip from `labelPath`. Ontology-neutral: a generic
|
|
278
|
+
* "dated items × category" scatter.
|
|
279
|
+
*/
|
|
280
|
+
private renderTimePlot;
|
|
272
281
|
/**
|
|
273
282
|
* Render a PackageContents band — the default package listing. The page
|
|
274
283
|
* instance is a Package self-resource; this enumerates every other
|
package/dist/parsing/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as c,b as d,c as e,d as f}from"../chunk-
|
|
1
|
+
import{a as c,b as d,c as e,d as f}from"../chunk-NIJV5UYW.js";import{f as b}from"../chunk-FMYLEPMC.js";import"../chunk-W6T7MOKY.js";import{a}from"../chunk-7CUTGGH3.js";import"../chunk-HEMBMX7T.js";import"../chunk-FUUTGGJS.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
|
package/dist/reasoning/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j}from"../chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j}from"../chunk-IOJMTW4T.js";import"../chunk-FMYLEPMC.js";import"../chunk-W6T7MOKY.js";import"../chunk-7CUTGGH3.js";import"../chunk-HEMBMX7T.js";import"../chunk-FUUTGGJS.js";export{f as KanonakVocabulary,h as OWL_RL_CLASSIFICATION_RULES,g as RDFS_RULES,j as Reasoner,i as ReasoningResult,e as TripleStore,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
|
|
@@ -6,4 +6,19 @@ export interface ResourceResolutionResult {
|
|
|
6
6
|
definedInNamespace: string;
|
|
7
7
|
isImported: boolean;
|
|
8
8
|
importPath?: string;
|
|
9
|
+
/**
|
|
10
|
+
* `true` when the bare entity name is defined by more than one distinct
|
|
11
|
+
* imported package in the resolution closure. The resolver keeps the
|
|
12
|
+
* first match for `uri`/`entity` (declaration-order), but surfaces the
|
|
13
|
+
* collision here instead of silently swallowing it — a deterministic
|
|
14
|
+
* resolution cannot be guaranteed, so consumers should treat it as an
|
|
15
|
+
* error rather than trust the arbitrary first match.
|
|
16
|
+
*/
|
|
17
|
+
isAmbiguous?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The distinct `publisher/package@version` namespaces that each define
|
|
20
|
+
* this bare name, in the order encountered (the first is the one chosen
|
|
21
|
+
* for `uri`). Only populated when `isAmbiguous` is `true`.
|
|
22
|
+
*/
|
|
23
|
+
ambiguousNamespaces?: string[];
|
|
9
24
|
}
|
package/dist/resolution/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as l,b as m,c as n,d as o,e as q}from"../chunk-4TJZIM7A.js";import{a as p}from"../chunk-NIGFQYVA.js";import{a,b,c,d,e,f,g,h}from"../chunk-FQHALFRR.js";import{b as j,c as k}from"../chunk-
|
|
1
|
+
import{a as l,b as m,c as n,d as o,e as q}from"../chunk-4TJZIM7A.js";import{a as p}from"../chunk-NIGFQYVA.js";import{a,b,c,d,e,f,g,h}from"../chunk-FQHALFRR.js";import{b as j,c as k}from"../chunk-HEMBMX7T.js";import{a as i}from"../chunk-FUUTGGJS.js";export{i as KanonakUri,m as KanonakUriBuilder,p as KanonakUrlResolver,j as ResourceResolver,l as ResourceTypeClassifier,k as TypeResolver,a as compareVersions,d as createVersion,q as findInstancesByType,o as formatKanonakAddress,c as formatVersion,f as isCompatibleVersion,g as isMajorCompatible,n as parseKanonakAddress,e as parseVersionString,h as pickHighestDocument,b as versionsEqual};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as E,c as F,d as f,f as M}from"../chunk-2JQMUZWN.js";import{a as X,b as ye}from"../chunk-
|
|
1
|
+
import{b as E,c as F,d as f,f as M}from"../chunk-2JQMUZWN.js";import{a as X,b as ye}from"../chunk-O4GZ6W5Z.js";import{a as Oe}from"../chunk-BFZZ6YGX.js";import"../chunk-NIJV5UYW.js";import"../chunk-NIGFQYVA.js";import{a as Ue}from"../chunk-FJ35VIV6.js";import{a as C,c as Re,f as Ce}from"../chunk-FMYLEPMC.js";import{b as K,c as w,d as b,g as L,h as U,i as O,j,k as T,l as S}from"../chunk-W6T7MOKY.js";import{a as Le}from"../chunk-7CUTGGH3.js";import"../chunk-HEMBMX7T.js";import"../chunk-FUUTGGJS.js";var gt="kanonak.org",yt="document-ast",m=t=>({publisher:gt,package_:yt,name:t}),k={Document:m("Document"),Block:m("Block"),Inline:m("Inline"),StructuredValue:m("StructuredValue"),Heading:m("Heading"),Paragraph:m("Paragraph"),RawBlock:m("RawBlock"),Text:m("Text"),StructuredMap:m("StructuredMap"),StructuredEntry:m("StructuredEntry"),StructuredList:m("StructuredList"),StringScalar:m("StringScalar"),IntegerScalar:m("IntegerScalar"),EscapeHint:m("EscapeHint"),MediaType:m("MediaType"),metadata:m("metadata"),children:m("children"),level:m("level"),inlines:m("inlines"),text:m("text"),entries:m("entries"),key:m("key"),value:m("value"),escapeHint:m("escapeHint"),items:m("items"),stringValue:m("stringValue"),integerValue:m("integerValue"),rawContent:m("rawContent"),mediaType:m("mediaType"),mimeType:m("mimeType"),ESC_RAW:m("esc-raw"),ESC_YAML_SAFE:m("esc-yaml-safe"),ESC_TOML_STRING:m("esc-toml-string"),ESC_TOML_MULTILINE:m("esc-toml-multiline"),ESC_JSON:m("esc-json"),ESC_DYNAMODB_BOOL:m("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:m("esc-dynamodb-number"),ESC_DYNAMODB_NULL:m("esc-dynamodb-null"),TEXT_PLAIN:m("text-plain"),TEXT_MARKDOWN:m("text-markdown"),TEXT_HTML:m("text-html"),TEXT_CSS:m("text-css"),APPLICATION_JSON:m("application-json"),TEXT_YAML:m("text-yaml"),IMAGE_SVG_XML:m("image-svg-xml"),ResourceLink:m("ResourceLink"),target:m("target"),linkLabel:m("linkLabel"),PropertyList:m("PropertyList"),propertyEntries:m("propertyEntries"),PropertyEntry:m("PropertyEntry"),propertyKey:m("propertyKey"),propertyValue:m("propertyValue"),Table:m("Table"),tableColumnLabels:m("tableColumnLabels"),tableRows:m("tableRows"),TableRow:m("TableRow"),tableCells:m("tableCells")};function Ne(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=kt(e.metadata,n),a=wt(e.children),u=["---",...r,"---","",a].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
4
|
`)),u}};function kt(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ue(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ue(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ue),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let p=r.get(c),y=ue(p??c),h=Ie(l.value,l.escapeHint);h!==void 0&&u.push(`${y}: ${h}`)}return u}function ue(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Ie(t,e){switch(t.kind){case"StringScalar":return ht(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Ie(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function ht(t,e){return!e||Ne(e,k.ESC_RAW)?t:Ne(e,k.ESC_YAML_SAFE)?bt(t):t}function bt(t){return t.includes(`
|
|
@@ -8,4 +8,4 @@ export { KanonakObjectValidator } from './KanonakObjectValidator.js';
|
|
|
8
8
|
export type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
|
|
9
9
|
export type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
|
|
10
10
|
export { NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule } from './rules/document/index.js';
|
|
11
|
-
export { ImportExistenceRule, UnresolvedReferenceRule,
|
|
11
|
+
export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule } from './rules/repository/index.js';
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,
|
|
1
|
+
import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-SKTXJV4T.js";import"../chunk-FJ35VIV6.js";import"../chunk-FMYLEPMC.js";import"../chunk-W6T7MOKY.js";import"../chunk-7CUTGGH3.js";import"../chunk-FQHALFRR.js";import"../chunk-HEMBMX7T.js";import"../chunk-FUUTGGJS.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,j as EmbeddedKanonakTypeRule,k as ImportExistenceRule,s as InstancePropertyReferenceRule,D as KanonakObjectValidator,C as MarkdownLinkRule,r as NamespaceImportCycleRule,f as NamespacePrefixRule,x as ObjectPropertyImportRule,y as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,z as PropertyDomainRule,n as PropertyHierarchyCycleRule,w as PropertyRangeReferenceRule,o as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,g as ResourceNamingRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
|
|
2
2
|
export { ImportExistenceRule } from './ImportExistenceRule.js';
|
|
3
3
|
export { UnresolvedReferenceRule } from './UnresolvedReferenceRule.js';
|
|
4
|
-
export { TypeAmbiguityRule } from './TypeAmbiguityRule.js';
|
|
5
4
|
export { ClassHierarchyCycleRule } from './ClassHierarchyCycleRule.js';
|
|
6
5
|
export { PropertyHierarchyCycleRule } from './PropertyHierarchyCycleRule.js';
|
|
7
6
|
export { PropertyRangeRequiredRule } from './PropertyRangeRequiredRule.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.42.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"yaml-parser"
|
|
114
114
|
],
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"@kanonak-protocol/types": "^3.
|
|
116
|
+
"@kanonak-protocol/types": "^3.42.0",
|
|
117
117
|
"ignore": "^7.0.5",
|
|
118
118
|
"js-yaml": "^4.1.0",
|
|
119
119
|
"yaml": "^2.7.0"
|
package/dist/chunk-5ILSX24H.js
DELETED
|
@@ -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 R=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 i=n.get(e);if(i)return i}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],i=n[1],l=await this.findDocumentForAlias(t,r);return l?await this.resolveAllEntitiesAsync(i,l):[]}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 i=s.length===0?r:`${s} \u2192 ${r}`;for(let[l,o]of Object.entries(e.body))if(!l.includes(".")&&o&&typeof o=="object"&&!Array.isArray(o)){let a=e.metadata.namespace_?.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.push({entityName:l,uri:new y(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,l,a),entity:o,definedInNamespace:r,isImported:s.length>0,importPath:i})}if(this.logger?.debug?.(`Collected ${n.length} entities from ${r}`),e.metadata?.imports){let l=Object.values(e.metadata.imports).reduce((o,a)=>o+a.length,0);this.logger?.debug?.(`Processing ${l} import(s) for ${r}`);for(let[o,a]of Object.entries(e.metadata.imports))for(let g of a)try{this.logger?.debug?.(`Resolving import: ${o}/${g.packageName}`);let c=await this.repository.getHighestCompatibleVersionAsync(o,g);if(c){this.logger?.debug?.(`Successfully loaded import: ${c.metadata?.namespace_?.toString()}`);let u=await this.buildAllEntitiesIndexAsync(c,t,i);n.push(...u),this.logger?.debug?.(`Added ${u.length} entities from import ${c.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${o}/${g.packageName}`)}catch(c){let u=c;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:c})}}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 i=s.length===0?r:`${s} \u2192 ${r}`,l=0;for(let[o,a]of Object.entries(e.body))if(!o.includes(".")&&a&&typeof a=="object"&&!Array.isArray(a)&&!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:a,definedInNamespace:r,isImported:s.length>0,importPath:i}),l++}if(this.logger?.debug?.(`Indexed ${l} entities from ${r}`),e.metadata?.imports){let o=Object.values(e.metadata.imports).reduce((a,g)=>a+g.length,0);this.logger?.debug?.(`Processing ${o} import(s) for ${r}`);for(let[a,g]of Object.entries(e.metadata.imports))for(let c of g)try{this.logger?.debug?.(`Resolving import: ${a}/${c.packageName}`);let u=await this.repository.getHighestCompatibleVersionAsync(a,c);if(u){this.logger?.debug?.(`Successfully loaded import: ${u.metadata?.namespace_?.toString()}`);let d=await this.buildEntityIndexAsyncInternal(u,t,i),f=0;for(let[m,b]of d.entries())if(n.has(m)||(n.set(m,b),f++),c.alias&&!m.includes(".")){let k=`${c.alias}.${m}`;n.has(k)||(n.set(k,b),f++)}this.logger?.debug?.(`Merged ${f} entities from import ${u.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${a}/${c.packageName}`)}catch(u){let d=u;throw this.logger?.error?.(`Failed to process import ${a}/${c.packageName} for namespace ${r}. Error: ${d.message}`,d),new Error(`Failed to process import ${a}/${c.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 i=r.entity.subClassOf;if(i){let l=h(i);for(let o of l)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 i=r.entity.subPropertyOf;if(i){let l=h(i);for(let o of l)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}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!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,R as b,A as c};
|