@kanonak-protocol/sdk 5.13.0 → 5.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +1 -1
- package/dist/{chunk-IHB7UVEH.js → chunk-4PY3JJH3.js} +4 -4
- package/dist/{chunk-S6VSAKXB.js → chunk-5NH5XDGO.js} +1 -1
- package/dist/{chunk-EZSHR3CB.js → chunk-LYSCTQC2.js} +1 -1
- package/dist/chunk-MK6UVFOJ.js +2 -0
- package/dist/chunk-Q6XQ5IXW.js +63 -0
- package/dist/chunk-SVUMCLK5.js +1 -0
- package/dist/chunk-V3IPBWWU.js +1 -0
- package/dist/chunk-V6KIDED2.js +1 -0
- package/dist/chunk-YW6P24RF.js +1 -0
- package/dist/index.js +1 -1
- package/dist/kanonaks/walkDefinedKanonaks.d.ts +22 -0
- package/dist/parsing/KanonakObjectParser.d.ts +22 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/ReasoningResult.d.ts +19 -0
- package/dist/reasoning/index.js +1 -1
- package/dist/resolution/ResourceTypeClassifier.d.ts +24 -0
- package/dist/resolution/TypeDirectedResolver.d.ts +37 -0
- package/dist/resolution/index.d.ts +3 -2
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/transformations/expressionRuntimeTree.d.ts +40 -0
- package/dist/transformations/index.d.ts +2 -0
- package/dist/transformations/index.js +22 -22
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/documentModel.d.ts +2 -15
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/PropertyRangeRequiredRule.d.ts +4 -0
- package/dist/validation/rules/repository/SubPropertyOfReferenceRule.d.ts +4 -2
- package/package.json +2 -2
- package/dist/chunk-4SQZBFJJ.js +0 -2
- package/dist/chunk-6U26UASC.js +0 -1
- package/dist/chunk-7BHDZHJY.js +0 -1
- package/dist/chunk-7K5TAJ44.js +0 -63
- package/dist/chunk-GZPLWII7.js +0 -1
- package/dist/chunk-MX3DEXMV.js +0 -1
- package/dist/chunk-TVSHIXLA.js +0 -1
- package/dist/chunk-ZP6P7HNU.js +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import{a as lt}from"./chunk-ITKOKDBG.js";import{a as I,b as Fe,c as at,d as G,h as M,k as pt,m as S}from"./chunk-V6KIDED2.js";import{a as nt}from"./chunk-NJ3AZYQD.js";import{j as We,k as it,o as v,p as w,q as z,r as H,s as W,v as st,w as L,x as ct}from"./chunk-SVUMCLK5.js";import{c as f,d as D,j as He,k as Q,l as Y,m as R,n as X,p as P,r as k,t as ee,u as x,v as F,w as y,x as $,y as b,z as q}from"./chunk-YW6P24RF.js";import{a as rt}from"./chunk-FUUTGGJS.js";import{e as U}from"./chunk-2ACBWC7K.js";var te=class{isValid=!1;errors=[];warnings=[];infos=[];get totalIssues(){return this.errors.length+this.warnings.length+this.infos.length}get allDiagnostics(){return[...this.errors,...this.warnings,...this.infos]}};var g=(o=>(o.Info="Info",o.Warning="Warning",o.Error="Error",o))(g||{});var u=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 Xe=class c{resolvedDocuments=[];currentEntityPath;withPath(e){let t=new c;return t.resolvedDocuments=this.resolvedDocuments,t.currentEntityPath=e,t}};var oe=class{constructor(e){this.underlying=e;this.repository=new Ze(e)}underlying;repository;parsePromise=null;getKanonaks(){return this.parseOnce().then(e=>e.merged)}getAuthoredKanonaks(){return this.parseOnce().then(e=>e.authored)}parseOnce(){return this.parsePromise||(this.parsePromise=(async()=>{let e=await this.underlying.getAllDocumentsAsync();await lt(e,this.repository);let t={};return{merged:await new S().parseKanonaks(this.underlying,t),authored:t.authored??[]}})()),this.parsePromise}},Ze=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,t){let o=`${e}/${t}`,n=this.byNamespaceCache.get(o);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,t),this.byNamespaceCache.set(o,n),n)}getHighestCompatibleVersionAsync(e,t){let o=t.version,n=o?`${o.major}.${o.minor}.${o.patch}`:"",r=`${e}/${t.packageName}@${t.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,t),this.highestVersionCache.set(r,a),a)}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)}};async function E(c,e,t){return t?t.getKanonaks():new S().parseKanonaks(new ne(c,e))}async function C(c,e,t){let o=await E(c,e,t),n=Ge(c);return n?o.filter(r=>r instanceof f&&r.namespace===n):[]}async function re(c,e,t){let o=Ge(c);if(!o)return[];let n;if(t)n=await t.getAuthoredKanonaks();else{let r={};await new S().parseKanonaks(new ne(c,e),r),n=r.authored??[]}return n.filter(r=>r instanceof f&&r.sourceDoc===o)}function Ge(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var ne=class{constructor(e,t){this.document=e;this.broader=t}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),t=(await this.broader.getAllDocumentsAsync()).filter(o=>o.metadata.namespace_?.toString()!==e);return[this.document,...t]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){return this.broader.getDocumentsByNamespaceAsync(e,t)}getHighestCompatibleVersionAsync(e,t){return this.broader.getHighestCompatibleVersionAsync(e,t)}getAllDocumentReferencesAsync(){return this.broader.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}saveDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}deleteDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}clearNamespaceAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}};var ae=class c{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 t=[];for(let[o,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(o,n,t);return t}validateEntity(e,t,o){for(let[n,r]of Object.entries(t)){let a=r?.toString()??"";if(a&&c.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),s=e.split(".")[0],p=new u;p.ruleType=this.ruleName,p.severity="Error",p.entityName=s,p.propertyName=e,p.actualValue=n,p.expectedValue=i,p.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,p.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",o.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,o)}}getSuggestionForPrefixedValue(e){let t=e.toLowerCase();if(t==="rdfs:class"||t==="owl:class")return"Class";if(t==="rdfs:property"||t==="rdf:property")return"DatatypeProperty or ObjectProperty";if(t.startsWith("xsd:"))return e.substring(4);let o=e.indexOf(":");return o>=0?e.substring(o+1):e}};var ie=class c{static RESERVED_WORDS=new Set(["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 t=[],o=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=c.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!o&&c.RESERVED_WORDS.has(n.toLowerCase())){let i=new u;i.ruleType=this.ruleName,i.severity="Error",i.entityName=n,i.message=`Entity name '${n}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",t.push(i);continue}if(!a&&!c.VALID_NAME_PATTERN.test(n)){let i;/^\d/.test(n)?i="Entity names must start with a letter, not a number.":n.includes(" ")?i="Entity names cannot contain spaces. Use camelCase or underscores instead.":i="Entity names must start with a letter and contain only letters, numbers, and underscores.";let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=n,s.message=`Invalid entity name '${n}'. ${i}`,s.suggestion=i,t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,t)}return t}validatePropertyNames(e,t,o){for(let n of Object.keys(t))if(!c.VALID_PROPERTIES.has(n)&&!c.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new u;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",o.push(r)}}};var se=class c{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 t=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return t;let o=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let s=[];if(Array.isArray(i))for(let p of i){let l=p?.toString();l&&l==="Property"&&!o&&s.push(l)}else{let p=i?.toString();p&&p==="Property"&&!o&&s.push(p)}for(let p of s){let l=this.getPropertyValue(a,"range"),m=this.determinePropertyType(l),d=new u;d.ruleType=this.ruleName,d.severity="Error",d.entityName=n,d.propertyName="type",d.actualValue=p,d.expectedValue=m,d.message=`Invalid property type '${p}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",t.push(d)}}}return t}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":c.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,t){let o=e[t];return o?o.toString():null}isPropertyDefinedAsClass(e){let t=e.body.Property;if(t&&typeof t=="object"&&!Array.isArray(t)){let n=t.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var ce=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let t=[];for(let[o,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||o.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=o,s.propertyName="type",s.message=`Subject Kanonak '${o}' must have a 'type' property.`,s.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.`,s.expectedValue="A valid class name (Scene, Character, Story, etc.)",t.push(s)}}return t}};var $t=new Set(["EphemeralPackage"]),pe=class{get ruleName(){return"PackageHeader"}validate(e){let t=e.metadata;if(!t.type_)return[];let o=[],n=this.packageKey(e,t.type_);return t.namespace_?(!$t.has(t.type_)&&!t.namespace_.version&&o.push(this.error(n,"version",`Package resource '${n}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
|
|
5
|
+
version: 1.0.0`)),o):(o.push(this.error(n,"publisher",`Package resource '${n}' requires a 'publisher' property.`,`Add a publisher, e.g.:
|
|
6
|
+
publisher: example.org`)),o)}packageKey(e,t){for(let[o,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.type===t)return o;return t}error(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.message=o,r.suggestion=n,r}};var Ut={publisher:"kanonak.org",package_:"core-rdf",name:"type"},wt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},At={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},xt={publisher:"kanonak.org",package_:"core-rdf",name:"Class"},le=class{ruleName="EmbeddedKanonakType";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await re(e,t,o);for(let i of a)i instanceof f&&this.walk(r,i,i.name,n);return n}walk(e,t,o,n){for(let r of t.statement)if(r instanceof Q){let a=r.predicate?.subject,i=`${o}.${a?.name??"<embedded>"}`;this.check(e,a,r.object,o,i,n),this.walk(e,r.object,i,n)}else if(r instanceof Y){let a=r.predicate?.subject,i=0;for(let s of r.object){if(s instanceof I){let p=`${o}.${a?.name??"<embedded>"}[${i}]`;this.check(e,a,s,o,p,n),this.walk(e,s,p,n)}i++}}}check(e,t,o,n,r,a){if(!t)return;let i=y(o,Ut);if(!i)return;let s=k(e,t);if(!s)return;let p=y(s,wt);if(p&&!(X(p,At)||X(p,xt))){if(R(i)===R(p)){a.push(this.redundant(n,r,i,p));return}z(e,i).some(l=>R(l)===R(p))||a.push(this.notSubclass(n,r,i,p))}}redundant(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=t,r.actualValue=o.name,r.expectedValue=n.name,r.message=`Embedded object at '${t}' declares 'type: ${o.name}', which equals the parent property's range '${n.name}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,r.suggestion=`Remove the 'type: ${o.name}' line, or keep it if explicitness is preferred over concision.`,r}notSubclass(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=o.name,r.expectedValue=n.name,r.message=`Embedded object at '${t}' has 'type: ${o.name}', which is not a subclass of the parent property's range '${n.name}'.`,r.suggestion=`Either remove the 'type: ${o.name}' line (so the type is inferred from the property's range '${n.name}'), or add 'subClassOf: ${n.name}' to the '${o.name}' class definition so the relationship holds.`,r}};import{VersionOperator as Ye}from"@kanonak-protocol/types/document/models/enums";var me=class{ruleName="ImportExistence";async validateAsync(e,t){let o=[];if(!e.metadata?.imports)return o;let n=await t.getAllDocumentsAsync();for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a)if(!await t.getHighestCompatibleVersionAsync(r,i)){let p=await this.determineImportErrorAsync(t,r,i,n),l=new u;l.ruleType=this.ruleName,l.severity="Error",l.message=p.message,l.suggestion=p.suggestion,l.entityName=`Import: ${r}/${i.packageName}`,l.actualValue=i.toString(),l.expectedValue=p.expectedValue,o.push(l)}return o}async determineImportErrorAsync(e,t,o,n){let r=await e.getDocumentsByNamespaceAsync(t,o.packageName);if(r.length===0){let p=n.filter(h=>h.metadata.namespace_?.publisher===t).map(h=>h.metadata.namespace_.package_).filter((h,V,T)=>T.indexOf(h)===V),l=this.findSimilarPackages(o.packageName,p),m=`Import '${t}/${o.package_}' not found - package does not exist`,d=l.length>0?`Did you mean: ${l.slice(0,3).join(", ")}?`:p.length>0?`Available packages in ${t}: ${p.slice(0,5).join(", ")}`:`No packages found for publisher '${t}'. Verify the publisher name is correct.`;return{message:m,suggestion:d,expectedValue:"Existing package"}}let i=r.filter(p=>p.metadata.namespace_?.version).map(p=>p.metadata.namespace_.version.toString()).sort().join(", "),s=this.getAcceptableVersionRange(o);return{message:`Import '${t}/${o.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${s}`,expectedValue:s}}getAcceptableVersionRange(e){switch(e.versionOperator){case Ye.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Ye.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Ye.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Ye.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,t){if(t.length===0)return[];let o=t.filter(a=>a.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(a.toLowerCase()));if(o.length>0)return o.sort((a,i)=>a.length-i.length);let n=t.map(a=>({package:a,distance:this.levenshteinDistance(e.toLowerCase(),a.toLowerCase())})).sort((a,i)=>a.distance-i.distance),r=Math.max(3,Math.floor(e.length*.4));return n.filter(a=>a.distance<=r).map(a=>a.package)}levenshteinDistance(e,t){if(!e||e.length===0)return t?.length??0;if(!t||t.length===0)return e.length;let o=e.length,n=t.length,r=Array(o+1).fill(null).map(()=>Array(n+1).fill(0));for(let a=0;a<=o;a++)r[a][0]=a;for(let a=0;a<=n;a++)r[0][a]=a;for(let a=1;a<=o;a++)for(let i=1;i<=n;i++){let s=e[a-1]===t[i-1]?0:1;r[a][i]=Math.min(Math.min(r[a-1][i]+1,r[a][i-1]+1),r[a-1][i-1]+s)}return r[o][n]}};var Nt="kanonak.org",Tt="core-rdf",_t=new Set(["type","subClassOf","subPropertyOf","domain","range"].map(c=>R({publisher:Nt,package_:Tt,name:c}))),ue=class{ruleName="UnresolvedReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);return G(a,({kanonak:i,path:s})=>{for(let p of i.statement){let l=Lt(p);if(!(!l||_t.has(R(l)))){if(p instanceof He)this.check(r,s,l,p.object,n);else if(p instanceof Y)for(let m of p.object)m instanceof D&&this.check(r,s,l,m,n)}}}),n}check(e,t,o,n,r){k(e,n.subject)||r.push(this.unresolvedError(t,o.name,n.subject))}unresolvedError(e,t,o){let n=`${o.publisher}/${o.package_}/${o.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=n,r.expectedValue="A reference that resolves to a defined or imported resource",r.message=`Reference to '${o.name}' in '${t}' could not be resolved`,r.suggestion=`The entity '${n}' is not defined in this namespace or any imported namespace.
|
|
7
|
+
\u2022 Import the package that defines it, or check for a typo in '${o.name}'
|
|
8
|
+
\u2022 If it lives in an imported namespace, alias-qualify the reference`,r}};function Lt(c){return c.predicate?.subject}var mt={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},ut={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"};function Mt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of b(c,e))n instanceof D&&o.push(n.subject);return o}function qe(c,e,t){let o=[],n=new Set,r=new Set,a=i=>{let s=k(c,i),p=s?`${s.namespace}/${s.name}`:R(i);if(n.has(p)){let l=o.findIndex(d=>d.key===p),m=o.slice(l);return m.length<=1?null:[...m.map(d=>d.uri),i]}if(r.has(p))return null;if(n.add(p),o.push({key:p,uri:i}),s)for(let l of Mt(s,t)){let m=a(l);if(m)return m}return o.pop(),n.delete(p),r.add(p),null};return a(e)}var dt=c=>c,de=class{ruleName="ClassHierarchyCycle";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!(v.isClassType(dt(i))||v.isDatatypeType(dt(i))))continue;let s=w(i);if(!s)continue;let p=qe(r,s,mt);if(p){let l=p.map(d=>d.name).join(" \u2192 "),m=new u;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular class hierarchy detected: ${l}`,m.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",m.entityName=i.name,m.propertyName="subClassOf",m.actualValue=l,n.push(m);break}}return n}};var fe=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!W(r,i))continue;let s=w(i);if(!s)continue;let p=qe(r,s,ut);if(p){let l=p.map(d=>d.name).join(" \u2192 "),m=new u;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${l}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=i.name,m.propertyName="subPropertyOf",m.actualValue=l,n.push(m);break}}return n}};var Bt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},ye=class{ruleName="PropertyRangeRequired";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f))continue;let s=H(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let p=s==="ObjectProperty";ee(i,Bt)||n.push(this.error(i.name,p))}return n}error(e,t){let o=new u;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName="range",o.message=`Property '${e}' must have a 'range' defined.`,o.suggestion=t?"Add a range like: range: ClassName (the class this property expects)":"Add a range like: range: string (or integer, boolean, etc.)",o.expectedValue=t?"A class name (Character, Scene, Story, etc.)":"A datatype (string, integer, boolean, decimal, etc.)",o}};var Ft={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},ft=c=>c,ge=class{ruleName="SubClassOfReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!yt(ft(i)))continue;let s=Ht(i,Ft);for(let p=0;p<s.length;p++)this.resolvesToClassLike(r,s[p])||n.push(this.error(i.name,s[p],s.length>1?`[${p}]`:""))}return n}resolvesToClassLike(e,t){let o=k(e,t);return o?yt(ft(o)):!1}error(e,t,o){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="subClassOf",r.actualValue=n,r.expectedValue="Defined or imported class",r.message=`Class '${t.name}' referenced in subClassOf${o} is not defined or imported`,r.suggestion=`Define '${t.name}' as a Class, or import a namespace that contains it`,r}};function yt(c){return v.isClassType(c)||v.isDatatypeType(c)}function Ht(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of b(c,e))n instanceof D&&o.push(n.subject);return o}var Wt={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"},ke=class{ruleName="SubPropertyOfReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!W(r,i))continue;let s=Gt(i,Wt);for(let p=0;p<s.length;p++)this.resolvesToProperty(r,s[p])||n.push(this.error(i.name,s[p],s.length>1?`[${p}]`:""))}return n}resolvesToProperty(e,t){let o=k(e,t);return o?W(e,o):!1}error(e,t,o){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="subPropertyOf",r.actualValue=n,r.expectedValue="Defined or imported property",r.message=`Property '${t.name}' referenced in subPropertyOf${o} is not defined or imported`,r.suggestion=`Define '${t.name}' as a property, or import a namespace that contains it`,r}};function Gt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of b(c,e))n instanceof D&&o.push(n.subject);return o}var he=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,t){let o=[],n=e.metadata.namespace_?.toString();if(!n)return o;let r=new Map,a=new Set;await this.buildImportGraph(e,t,r,a);let i=this.detectCycle(n,r);if(i){let s=i.join(" \u2192 "),p=new u;p.ruleType=this.ruleName,p.severity="Error",p.message=`Circular namespace import detected: ${s}`,p.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",p.entityName="imports",p.propertyName="imports",p.actualValue=s,o.push(p)}return o}async buildImportGraph(e,t,o,n){let r=e.metadata.namespace_?.toString()??"";if(!(!r||n.has(r))&&(n.add(r),e.metadata.imports)){let a=[];for(let[i,s]of Object.entries(e.metadata.imports))for(let p of s){let l=`${i}/${p.packageName}@${p.version}`;a.push(l);let m=await t.getHighestCompatibleVersionAsync(i,p);m&&await this.buildImportGraph(m,t,o,n)}a.length>0&&o.set(r,a)}}detectCycle(e,t){let o=[],n=new Set;return this.detectCycleRecursive(e,t,o,n)}detectCycleRecursive(e,t,o,n){let r=o.indexOf(e);if(r>=0){let i=o.slice(r);return i.push(e),i}if(n.has(e))return null;o.push(e),n.add(e);let a=t.get(e);if(a)for(let i of a){let s=this.detectCycleRecursive(i,t,o,n);if(s)return s}return o.pop(),null}};var Re=class{ruleName="UnresolvedPredicate";async validateAsync(e,t,o){let n=[],r=Ge(e);if(!r)return n;let a=await E(e,t,o);return G(a,({kanonak:i,path:s})=>{for(let p of i.unresolvedPredicates)p.sourceDoc===r&&n.push(this.unresolvedPredicateError(s,p.key))}),n}unresolvedPredicateError(e,t){let o=t.lastIndexOf("."),n=o>0?t.slice(0,o):null,r=o>0?t.slice(o+1):t,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.actualValue=t,a.expectedValue="A defined or imported property",a.message=`Property '${t}' is not defined or imported`,a.suggestion=n?`The property '${r}' was not found in the namespace imported as '${n}'.
|
|
9
|
+
1. Check '${r}' is spelled correctly
|
|
10
|
+
2. Verify '${n}' is imported with the right alias and version
|
|
11
|
+
3. Ensure that namespace version actually defines '${r}'`:`The property '${t}' is not defined in this namespace or any imported namespace.
|
|
12
|
+
1. Define '${t}' as an ObjectProperty or DatatypeProperty here, OR
|
|
13
|
+
2. Import the namespace that defines it, OR
|
|
14
|
+
3. Alias-qualify it if it lives in an imported namespace ('alias.${t}')`,a}};var Ke=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,t){let o=[],{entitySources:n,importPaths:r}=await this.buildEntitySourceMapAsync(e,t),a=await this.buildDatatypePropertyNamesAsync(e,t);for(let[i,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.validateEntityReferences(i,s,n,r,a,e,o);return o}async buildEntitySourceMapAsync(e,t){let o=new Map,n=new Set,r=new Map;for(let a of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";o.has(a)||o.set(a,[]),o.get(a).push(`(local:${i})`)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let s of i){let p=await t.getHighestCompatibleVersionAsync(a,s);if(p){let l=p.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(p,o,n,r,[l],t)}}return{entitySources:o,importPaths:r}}async collectEntitiesRecursivelyAsync(e,t,o,n,r,a){let i=e.metadata.namespace_?.toString()??"";if(!o.has(i)){o.add(i),n.has(i)||n.set(i,r);for(let s of Object.keys(e.body)){t.has(s)||t.set(s,[]);let p=t.get(s);p.includes(i)||p.push(i)}if(e.metadata.imports)for(let[s,p]of Object.entries(e.metadata.imports))for(let l of p){let m=await a.getHighestCompatibleVersionAsync(s,l);if(m){let d=m.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(m,t,o,n,[...r,d],a)}}}}async buildDatatypePropertyNamesAsync(e,t){let o=new Set,n=new Set;if(await this.collectDatatypePropertiesAsync(e,o,n,t),e.metadata.imports)for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a){let s=await t.getHighestCompatibleVersionAsync(r,i);s&&await this.collectDatatypePropertiesAsync(s,o,n,t)}return o}async collectDatatypePropertiesAsync(e,t,o,n){let r=e.metadata.namespace_?.toString()??"";if(!o.has(r)){o.add(r);for(let[a,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let s=i.type;if(typeof s!="string")continue;(s.includes(".")?s.substring(s.lastIndexOf(".")+1):s)==="DatatypeProperty"&&t.add(a)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let s of i){let p=await n.getHighestCompatibleVersionAsync(a,s);p&&await this.collectDatatypePropertiesAsync(p,t,o,n)}}}validateEntityReferences(e,t,o,n,r,a,i){for(let[s,p]of Object.entries(t)){let l=s;if(l&&!l.includes(".")){let m=o.get(l);if(m&&m.length>1&&!m.some(h=>h.startsWith("(local:"))){let h=m.filter(V=>!V.startsWith("(local:"));h.length>1&&i.push(this.createAmbiguityError(e,l,`Property '${l}'`,h,n,a,!0,l))}}this.validatePropertyValue(e,l,p,o,n,r,a,i)}}validatePropertyValue(e,t,o,n,r,a,i,s){if(o==null)return;let p=t&&t.includes(".")?t.substring(t.lastIndexOf(".")+1):t,l=!!p&&a.has(p);if(typeof o=="string"&&!o.includes(".")&&!l){let m=n.get(o);if(m&&m.length>1&&!m.some(h=>h.startsWith("(local:"))){let h=m.filter(V=>!V.startsWith("(local:"));h.length>1&&s.push(this.createAmbiguityError(e,t,`Reference '${o}'`,h,r,i,!1,o))}}else if(Array.isArray(o))for(let m=0;m<o.length;m++){let d=`${e}.${t}[${m}]`;this.validatePropertyValue(d,t,o[m],n,r,a,i,s)}else if(typeof o=="object"&&!Array.isArray(o)){let m=t?`${e}.${t}`:e;this.validateEntityReferences(m,o,n,r,a,i,s)}}createAmbiguityError(e,t,o,n,r,a,i,s){let p=[];for(let j of n){let O=this.findAliasForNamespace(a,j);if(O){let B=t?.split(".").pop()??t;p.push(`${O}.${B}`)}}let l=p.length>0?`Use one of: ${p.map(j=>`'${j}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${t}')`,m=n.map(j=>{let O=r.get(j);return!O||O.length===0?` \u2022 ${j}`:O.length===1?` \u2022 ${j} (direct import)`:` \u2022 ${j}
|
|
15
|
+
imported via: ${O.join(" \u2192 ")}`}).join(`
|
|
16
|
+
`),d=e.split(".")[0],h=e.includes(".")?e:t,V=new u;V.ruleType=this.ruleName,V.severity="Error",V.entityName=d,h&&(V.propertyName=h);let T=s??t;return T&&(V.actualValue=T),V.message=`${o} is ambiguous - defined in multiple imported namespaces`,V.suggestion=`${l}
|
|
17
|
+
|
|
18
|
+
Defined in:
|
|
19
|
+
${m}`,V.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",V}findAliasForNamespace(e,t){if(!e.metadata.imports)return null;for(let[o,n]of Object.entries(e.metadata.imports))for(let r of n)if(`${o}/${r.packageName}@${r.version}`===t&&r.alias)return r.alias;return null}};var Yt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},gt=c=>c,be=class{ruleName="PropertyRangeReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f))continue;let s=H(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let p=s==="ObjectProperty";for(let l of qt(i,Yt))this.resolvesToClassLike(r,l)||n.push(this.error(i.name,l,p))}return n}resolvesToClassLike(e,t){let o=k(e,t);return o?v.isClassType(gt(o))||v.isDatatypeType(gt(o)):!1}error(e,t,o){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="range",r.actualValue=n,r.expectedValue=o?"A defined or imported class":"A datatype or defined class",r.message=`Property '${e}' has range '${t.name}' which is not defined or imported`,r.suggestion=o?`Define '${t.name}' as a Class here, or import the namespace that contains it (alias-qualify it if imported under an alias).`:`Use a datatype (xsd type, rdfs.Literal, or a datatype-derived type), or \u2014 if '${t.name}' is a class \u2014 make this an ObjectProperty.`,r}};function qt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of b(c,e))n instanceof D&&o.push(n.subject);return o}var zt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},Ve="kanonak.org",Je="core-rdf",Qe="core-owl",et=c=>c,Xt=[{uri:{publisher:Ve,package_:Je,name:"Class"},ok:(c,e)=>v.isClassType(et(e))||v.isDatatypeType(et(e))},{uri:{publisher:Ve,package_:Je,name:"Datatype"},ok:(c,e)=>v.isDatatypeType(et(e))},{uri:{publisher:Ve,package_:Je,name:"Property"},ok:(c,e)=>W(c,e)},{uri:{publisher:Ve,package_:Qe,name:"ObjectProperty"},ok:(c,e)=>H(c,e)==="ObjectProperty"},{uri:{publisher:Ve,package_:Qe,name:"DatatypeProperty"},ok:(c,e)=>H(c,e)==="DatatypeProperty"},{uri:{publisher:Ve,package_:Qe,name:"AnnotationProperty"},ok:(c,e)=>H(c,e)==="AnnotationProperty"}],Ee=class{ruleName="ObjectPropertyValue";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await re(e,t,o);for(let i of a)i instanceof f&&this.walk(r,i,i.name,n);return n}walk(e,t,o,n){for(let r of t.statement)if(r instanceof He)this.check(e,r.predicate?.subject,r.object.subject,o,n);else if(r instanceof Q)this.walk(e,r.object,kt(o,r.predicate?.subject),n);else if(r instanceof Y){let a=r.predicate?.subject;for(let i of r.object)i instanceof D?this.check(e,a,i.subject,o,n):i instanceof I&&this.walk(e,i,kt(o,a),n)}}check(e,t,o,n,r){if(!t)return;let a=k(e,t);if(!a)return;let i=y(a,zt);if(!i)return;let s=Xt.find(l=>X(i,l.uri));if(!s)return;let p=k(e,o);p&&(s.ok(e,p)||r.push(this.warn(n,t,i,o)))}warn(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e.split(".")[0],r.propertyName=e,r.actualValue=n.name,r.expectedValue=o.name,r.message=`Property '${t.name}' expects a ${o.name}, but '${n.name}' is not a ${o.name}`,r.suggestion=`Reference a resource that is a ${o.name}, or correct the type of '${n.name}'.`,r}};function kt(c,e){return`${c}.${e?.name??"<embedded>"}`}var Zt={publisher:"kanonak.org",package_:"core-rdf",name:"type"},Jt={publisher:"kanonak.org",package_:"core-rdf",name:"domain"},Qt={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},ve=class{ruleName="PropertyDomain";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await re(e,t,o);for(let i of a)i instanceof f&&this.walk(r,i,i.name,n);return n}walk(e,t,o,n){this.checkNode(e,t,o,n);for(let r of t.statement)if(r instanceof Q)this.walk(e,r.object,Rt(o,r.predicate?.subject),n);else if(r instanceof Y)for(let a of r.object)a instanceof I&&this.walk(e,a,Rt(o,r.predicate?.subject),n)}checkNode(e,t,o,n){let r=ht(t,Zt);if(r.length===0)return;let a,i=()=>{if(!a){a=new Set([R(Qt)]);for(let p of r)for(let l of z(e,p))a.add(R(l))}return a},s=new Set;for(let p of t.statement){let l=eo(p);if(!l||We(l.name)||s.has(R(l)))continue;s.add(R(l));let m=k(e,l);if(!m)continue;let d=ht(m,Jt);d.length!==0&&(d.some(h=>i().has(R(h)))||n.push(this.error(o,l,d,r[0])))}}error(e,t,o,n){let r=o.map(i=>i.name).join(" | "),a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e.split(".")[0],a.propertyName=e,a.actualValue=t.name,a.expectedValue=`Property used on ${r} or its subclasses`,a.message=`Property '${t.name}' has domain '${r}' but is used on '${n.name}' at '${e}'`,a.suggestion=`Either:
|
|
20
|
+
1. Use '${t.name}' only on '${r}' (or a subclass) instances
|
|
21
|
+
2. Widen the property's domain to include '${n.name}'
|
|
22
|
+
3. Use a different property for '${n.name}'`,a}};function eo(c){return c.predicate?.subject}function ht(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of b(c,e))n instanceof D&&o.push(n.subject);return o}function Rt(c,e){return`${c}.${e?.name??"<embedded>"}`}var to={publisher:"kanonak.org",package_:"core-rdf",name:"range"},oo={publisher:"kanonak.org",package_:"core-rdf",name:"Literal"},no=c=>c,De=class{ruleName="PropertyKindRangeConsistency";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f))continue;let s=H(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let p=s==="ObjectProperty",l=s==="DatatypeProperty",m=y(i,to);if(!m||!k(r,m))continue;let d=ro(r,m);l&&!d?n.push(this.error(i.name,m,"datatype")):p&&d&&n.push(this.error(i.name,m,"object"))}return n}error(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName="range",n.actualValue=t.name,o==="datatype"?(n.expectedValue="A datatype (xsd type, rdfs.Literal, or a datatype-derived class)",n.message=`DatatypeProperty '${e}' has range '${t.name}', which is a class, not a datatype. A datatype property's values are literals.`,n.suggestion=`Use a datatype range (e.g. xsd.string, rdfs.Literal, or a datatype-derived class), or \u2014 if '${t.name}' is the intended target \u2014 declare '${e}' an ObjectProperty.`):(n.expectedValue="A plain class (not datatype-derived)",n.message=`ObjectProperty '${e}' has range '${t.name}', which is a datatype, not a class. An object property's values are references to resources.`,n.suggestion=`Declare '${e}' a DatatypeProperty (its values are literals of '${t.name}'), or change the range to a plain class.`),n}};function ro(c,e){for(let t of z(c,e)){if(X(t,oo))return!0;let o=k(c,t);if(o&&v.isDatatypeType(no(o)))return!0}return!1}var Ie=class{ruleName="ReservedNameShadow";async validateAsync(e,t,o){let n=[],r=await C(e,t,o);for(let a of r){if(!(a instanceof f))continue;let i=it(a.name);if(!i)continue;let s=w(a);s&&(i.publisher===s.publisher&&i.package_===s.package_||n.push(this.info(a.name,s,i)))}return n}info(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Info",n.entityName=e,n.propertyName=e,n.actualValue=`${t.publisher}/${t.package_}/${e}`,n.expectedValue=`${o.publisher}/${o.package_}/${e}`,n.message=`'${e}' is also the reserved built-in '${o.publisher}/${o.package_}/${e}'. This local definition shadows it \u2014 a bare '${e}' reference in this package resolves to the local entity, not the built-in.`,n.suggestion=`If this is intentional, qualify bare references to '${e}' explicitly (this local one vs. the built-in '${o.publisher}/${o.package_}/${e}') so the choice is unambiguous to readers and tools \u2014 e.g. a self-referential 'subClassOf: ${e}' silently resolves to this local entity.`,n}};var ao={publisher:"kanonak.org",package_:"core-rdf",name:"type"},Kt=c=>c,Ce=class{ruleName="ClassDefinition";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);return G(a,({kanonak:i,path:s})=>{for(let p of io(i,ao))this.resolvesToClassLike(r,p)||n.push(this.error(s,p))}),n}resolvesToClassLike(e,t){if(We(t.name))return!0;let o=k(e,t);return o?v.isClassType(Kt(o))||v.isDatatypeType(Kt(o)):!1}error(e,t){let o=`${t.publisher}/${t.package_}/${t.name}`,n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName="type",n.actualValue=o,n.expectedValue="Defined or imported class",n.message=`Class '${t.name}' is not defined or imported`,n.suggestion=`Define '${t.name}' as a Class in this document, or import a namespace that contains it`,n}};function io(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of b(c,e))n instanceof D&&o.push(n.subject);return o}var Se=class{ruleName="MarkdownLink";async validateAsync(e,t,o){let n=[],r=await C(e,t,o);return G(r,({kanonak:a,path:i})=>{this.checkNode(a,i,n)}),n}checkNode(e,t,o){for(let n of e.statement){if(!(n instanceof at))continue;let r=n.predicate.subject?.name??"(unknown)";for(let a of n.links)a.target||o.push(this.unresolvedLinkError(t,r,a.reference));for(let a of pt(n.object))o.push(this.malformedLinkError(t,r,a.snippet))}}unresolvedLinkError(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=t,n.actualValue=o,n.message=`Embedded link [[${o}]] in '${t}' could not be resolved`,n.expectedValue="A reference resolvable through the document's import closure",n.suggestion=`The reference '${o}' inside a markdown value cannot be found in the current document or any imported namespace.
|
|
23
|
+
|
|
24
|
+
Possible solutions:
|
|
25
|
+
\u2022 Import the package that defines '${o}' so the link can resolve
|
|
26
|
+
\u2022 Check for typos in the reference name
|
|
27
|
+
\u2022 If the name collides across imports, alias-qualify it: [[alias.${o}]]`,n}malformedLinkError(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=t,n.actualValue=o,n.message=`Malformed embedded reference near '${o}' in '${t}'`,n.expectedValue="A single-line [[reference]] with no internal line break",n.suggestion=`A '[[' in '${t}' does not form a complete [[reference]] link.
|
|
28
|
+
|
|
29
|
+
A reference may not span a line break \u2014 the most common cause is wrapping a
|
|
30
|
+
long reference across two lines in a block scalar, e.g.:
|
|
31
|
+
... read for [[persistent-energy-
|
|
32
|
+
shock]] held ...
|
|
33
|
+
which is parsed as literal text, not a link. Keep each [[reference]] on one
|
|
34
|
+
line (let the line run long), or check for an unterminated [[.`,n}};var bt="kanonak.org",Vt="look",so={publisher:bt,package_:Vt,name:"displayLabel"},co={publisher:bt,package_:Vt,name:"displaySummary"},Pe=class{ruleName="DisplayLensScope";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new q(e,t));let a=po(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&(this.checkLens(r,i,so,"displayLabel",n),this.checkLens(r,i,co,"displaySummary",n));return n}checkLens(e,t,o,n,r){let a=y(t,o);if(!a)return;let i=[],s=w(t);if(s&&i.push(s),i.push(...ct(t)),i.length===0)return;i.some(l=>L(e,l,a).ok)||r.push(this.scopeError(t.name,n,a.name))}scopeError(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=t,n.actualValue=o,n.message=`${t} points at '${o}', which is not a property in scope for '${e}'`,n.expectedValue="A property whose domain is this resource's class, an ancestor, or rdfs.Resource",n.suggestion=`'${o}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
|
|
35
|
+
|
|
36
|
+
Possible solutions:
|
|
37
|
+
\u2022 Point ${t} at a property declared on this class (or an ancestor / rdfs.Resource)
|
|
38
|
+
\u2022 Set the property's domain to this class if it should apply here
|
|
39
|
+
\u2022 Use rdfs.label / rdfs.comment for the universal default`,n}};function po(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}function Z(c,e,t){let o=[];return _e(c,t,{input:e},o),o}function _e(c,e,t,o){if(P(e,M.VarRef)){let a=F(e,M.varName);return a?t[a]:void 0}if(P(e,M.PropertyRead)){let a=$(e,M.readSource),i=a?_e(c,a,t,o):void 0,s=y(e,M.readProp);if(!i||!s)return;let p=L(c,i,s);if(!p.ok){o.push({contextClass:i,propertyUri:s,via:"PropertyRead"});return}return p.descriptor?.range}if(P(e,M.Traverse)){let a=$(e,M.traverseSource),i=a?_e(c,a,t,o):void 0,s=y(e,M.through),p;if(i&&s){let m=L(c,i,s);m.ok?p=m.descriptor?.range:o.push({contextClass:i,propertyUri:s,via:"Traverse"})}let l=$(e,M.step);return l?_e(c,l,{...t,input:p},o):void 0}let n=F(e,M.loopVar),r=n?{...t,[n]:void 0}:t;for(let a of lo(e))_e(c,a,r,o)}function lo(c){let e=[];for(let t of c.statement){let o=t.object;if(o instanceof I)e.push(o);else if(Array.isArray(o))for(let n of o)n instanceof I&&e.push(n)}return e}var Le="kanonak.org",Me="look",mo={publisher:Le,package_:Me,name:"semanticSvg"},uo={publisher:Le,package_:Me,name:"tierChip"},fo={publisher:Le,package_:Me,name:"tierIcon"},yo={publisher:Le,package_:Me,name:"tierCard"},go={publisher:Le,package_:Me,name:"tierFull"},ko=[uo,fo,yo,go],je=class{ruleName="LookSemanticSvgPath";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new q(e,t));let a=ho(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&this.checkSemanticSvg(r,i,n);return n}checkSemanticSvg(e,t,o){let n=$(t,mo);if(!n)return;let r=w(t);if(r)for(let a of ko){let i=$(n,a);if(i)for(let s of Z(e,r,i))o.push(this.toError(t.name,a.name,s))}}toError(e,t,o){let n=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,a=r===e?`'${e}' (the class this SemanticSvg is declared on)`:`'${r}', reached by traversal from '${e}' (the class this SemanticSvg is declared on)`,i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=`look.semanticSvg.${t}`,i.actualValue=n,i.message=`tx.${o.via} reads property '${o.propertyUri.name}' off the rendered instance, but its domain is not in scope for ${a}. The read would silently return undefined at render time.`,i.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,i.suggestion=`Property '${n}' is not in scope for '${r}'.
|
|
40
|
+
|
|
41
|
+
Possible solutions:
|
|
42
|
+
\u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
|
|
43
|
+
\u2022 If the property should apply to '${r}', adjust its domain
|
|
44
|
+
\u2022 If the value comes from a pre-computed env binding, use tx.VarRef instead of PropertyRead`,i}};function ho(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var Ro="kanonak.org",K=(c,e)=>({publisher:Ro,package_:c,name:e}),Ko=K("derivation","look"),bo=K("look","bands"),Vo=K("look","Distribution"),Eo=K("look","StatRow"),vo=K("look","VersionDelta"),Do=K("look","Timeline"),Io=K("look","VersionDiff"),Co=K("look","TimePlot"),So=K("look","ReferenceList"),Po=K("look","Diagram"),jo=K("look","alphaPath"),Oo=K("look","betaPath"),tt=K("look","metricPath"),Et=K("look","lowerPath"),vt=K("look","upperPath"),Dt=K("look","hueBy"),$o=K("look","statPath"),Uo=K("look","laneBy"),It=K("look","labelPath"),wo=K("look","badgePath"),Ao=K("look","mapPath"),xo=K("look","nodeNote"),No=K("look","edgeValue"),To=K("look","stats"),_o=K("look","facets"),Lo=K("look","channels"),Mo=K("look","track"),Bo=K("look","source"),Fo=K("look","relation"),Ho=K("look","entries"),Be=class{ruleName="LookBandPath";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new q(e,t));let a=Go(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&this.checkDeclaration(r,i,n);return n}checkDeclaration(e,t,o){let n=$(t,Ko);if(!n)return;let r=w(t);if(!r)return;let a=b(n,bo).filter(i=>i instanceof I);for(let i of a)for(let s of this.carriersOf(e,i,r))for(let p of Z(e,s.context,s.expr))o.push(this.toError(t.name,s.slot,p))}carriersOf(e,t,o){let n=[],r=(a,i)=>{let s=$(t,a);s&&n.push({slot:`look.${a.name}`,context:i,expr:s})};if(P(t,Vo))for(let a of[jo,Oo,tt,Et,vt,Dt])r(a,o);if(P(t,vo)&&r(tt,o),P(t,Eo)){let a=b(t,To).filter(i=>i instanceof I);for(let i of a){let s=$(i,$o);s&&n.push({slot:"look.stats[].statPath",context:o,expr:s})}}if(P(t,Do)||P(t,Io)){let a=this.rangeOf(e,o,y(t,Mo));if(a)for(let i of[tt,Et,vt,Dt])r(i,a)}if(P(t,Co)){let a=this.rangeOf(e,o,y(t,Bo));if(a)for(let i of[Uo,It])r(i,a)}if(P(t,So))for(let a of b(t,Ho)){let i=a instanceof I?void 0:Wo(a),s=this.rangeOf(e,o,i);if(s)for(let p of[It,wo])r(p,s)}if(P(t,Po)){let a=b(t,_o).filter(i=>i instanceof I);for(let i of a){let s=this.rangeOf(e,o,y(i,Fo));if(!s)continue;let p=$(i,xo);p&&n.push({slot:"look.facets[].nodeNote",context:s,expr:p});let l=$(i,No);l&&n.push({slot:"look.facets[].edgeValue",context:s,expr:l});let m=b(i,Lo).filter(d=>d instanceof I);for(let d of m){let h=$(d,Ao);h&&n.push({slot:"look.facets[].channels[].mapPath",context:s,expr:h})}}}return n}rangeOf(e,t,o){if(!o)return;let n=L(e,t,o);return n.ok?n.descriptor?.range:void 0}toError(e,t,o){let n=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.actualValue=n,a.message=`tx.${o.via} reads property '${o.propertyUri.name}', but its domain is not in scope for '${r}' (the class this band carrier is evaluated against). The read would silently return undefined at render time and the band would render empty.`,a.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${n}' is not in scope for '${r}'.
|
|
45
|
+
|
|
46
|
+
Possible solutions:
|
|
47
|
+
\u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
|
|
48
|
+
\u2022 If the property should apply to '${r}', adjust its domain
|
|
49
|
+
\u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,a}};function Wo(c){let e=c.subject;return e&&typeof e.name=="string"?e:void 0}function Go(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var $e="kanonak.org",Ue="view",Yo={publisher:$e,package_:Ue,name:"bind"},qo={publisher:$e,package_:Ue,name:"produces"},zo={publisher:$e,package_:Ue,name:"projections"},Xo={publisher:$e,package_:Ue,name:"where"},Zo={publisher:$e,package_:Ue,name:"value"},Jo={publisher:$e,package_:Ue,name:"as"},Oe=class{ruleName="TxExpressionPath";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new q(e,t));let a=tn(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&this.checkView(r,i,n);return n}checkView(e,t,o){let n=y(t,Yo);if(!n)return;let r=y(t,qo),a=0;for(let s of en(e,b(t,zo))){let p=$(s,Zo);if(p)for(let m of Z(e,n,p))o.push(this.toError(t.name,`view.projections[${a}].value`,n,m));let l=y(s,Jo);l&&r&&(L(e,r,l).ok||o.push(this.asError(t.name,a,r,l))),a+=1}let i=0;for(let s of Qo(t,Xo)){for(let p of Z(e,n,s))o.push(this.toError(t.name,`view.where[${i}]`,n,p));i+=1}}asError(e,t,o,n){let r=`${n.publisher}/${n.package_}/${n.name}`,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=`view.projections[${t}].as`,a.actualValue=r,a.message=`Projection stores its value under property '${n.name}', but that property's domain is not in scope for the view's produces class '${o.name}'. The materialized result instance could not carry this value.`,a.expectedValue=`A property whose domain is '${o.name}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${r}' is not in scope for produces class '${o.name}'.
|
|
50
|
+
|
|
51
|
+
Possible solutions:
|
|
52
|
+
\u2022 Use an output property whose domain covers '${o.name}'
|
|
53
|
+
\u2022 Define a new property in the ViewPackage with domain '${o.name}' and the right range
|
|
54
|
+
\u2022 If the value belongs on a different output class, adjust the view's produces`,a}toError(e,t,o,n){let r=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,i=a===o.name?`the view's bound class '${o.name}'`:`'${a}', reached by traversal from the view's bound class '${o.name}'`,s=new u;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=t,s.actualValue=r,s.message=`tx.${n.via} reads property '${n.propertyUri.name}', but its domain is not in scope for ${i}. The read would silently return undefined when the view materializes.`,s.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,s.suggestion=`Property '${r}' is not in scope for '${a}'.
|
|
55
|
+
|
|
56
|
+
Possible solutions:
|
|
57
|
+
\u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
|
|
58
|
+
\u2022 If the property should apply to '${a}', adjust its domain
|
|
59
|
+
\u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,s}};function Qo(c,e){let t=$(c,e);return t?[t]:b(c,e).filter(o=>o instanceof I)}function en(c,e){let t=[];for(let o of e)if(o instanceof I)t.push(o);else if(o instanceof D){let n=k(c,o.subject);n&&t.push(n)}return t}function tn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var ze="kanonak.org",on="core-shacl",A=c=>({publisher:ze,package_:on,name:c}),nn=A("NodeShape"),rn=A("PropertyShape"),an=A("targetClass"),sn=A("property"),cn=A("path"),pn=A("minCount"),ln=A("maxCount"),mn=A("datatype"),un=A("class"),Ct=A("in"),dn=A("pattern"),fn=A("flags"),yn=A("minLength"),gn=A("maxLength"),kn=A("minInclusive"),hn=A("maxInclusive"),Rn=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),St=c=>c,Ae=class{ruleName="ShaclShape";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(t),a=Kn(e);if(!a)return n;let i=new Set;for(let s of r){if(!(s instanceof f)||s.namespace!==a||!P(s,nn))continue;let p=y(s,an);p?this.resolvesToClass(r,p)||n.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' sh:targetClass '${p.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(p))):n.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' has no sh:targetClass; it constrains nothing.`,"Add sh:targetClass naming the class this shape applies to."));for(let l of b(s,sn)){let m;if(l instanceof I)m=l;else if(l instanceof D){let d=k(r,l.subject);d&&(m=d,i.add(R(l.subject)))}m&&this.checkPropertyShape(r,s.name,m,p??void 0,n)}}for(let s of r){if(!(s instanceof f)||s.namespace!==a||!P(s,rn))continue;let p=w(s);p&&i.has(R(p))||this.checkPropertyShape(r,s.name,s,void 0,n)}return n}checkPropertyShape(e,t,o,n,r){let a=y(o,cn);if(!a){r.push(this.err(t,"property.path","Error",`A PropertyShape on '${t}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=k(e,a),s=i?W(e,i):!1;s?n&&(L(e,n,a).ok||r.push(this.err(t,"property.path","Warning",`sh:path '${a.name}' is not in scope for sh:targetClass '${n.name}'; the constraint would never bind a value.`,`Constrain a property whose domain is '${n.name}', an ancestor, or rdfs.Resource.`,J(a)))):r.push(this.err(t,"property.path","Error",`sh:path '${a.name}' on '${t}' does not resolve to a property.`,"Reference a defined or imported property.",J(a)));let p=y(o,mn),l=y(o,un);p&&l&&r.push(this.err(t,"property","Error",`A PropertyShape on '${t}' sets both sh:datatype and sh:class; a value is a literal or a node, not both.`,"Keep sh:datatype (literal values) or sh:class (node values), not both.")),p&&!this.resolvesToDatatype(e,p)&&r.push(this.err(t,"datatype","Error",`sh:datatype '${p.name}' on '${t}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",J(p))),l&&!this.resolvesToClass(e,l)&&r.push(this.err(t,"class","Error",`sh:class '${l.name}' on '${t}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(l)));let m=we(x(o,pn)),d=we(x(o,ln));this.checkOrder(t,"minCount",m,"maxCount",d,r);let h=we(x(o,yn)),V=we(x(o,gn));this.checkOrder(t,"minLength",h,"maxLength",V,r);let T=we(x(o,kn)),j=we(x(o,hn));this.checkOrder(t,"minInclusive",T,"maxInclusive",j,r);let O=F(o,dn);if(O!==void 0){let B=F(o,fn);try{new RegExp(O,B)}catch{r.push(this.err(t,"pattern","Error",`sh:pattern on '${t}' is not a valid regular expression`+(B!==void 0?` (with flags '${B}')`:"")+`: ${O}`,"Provide a valid regular expression and flags.",O))}}if(ee(o,Ct)&&b(o,Ct).length===0&&r.push(this.err(t,"in","Error",`sh:in on '${t}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),s&&n){let _=L(e,n,a).descriptor;_&&((O!==void 0||h!==void 0||V!==void 0)&&_.kind==="object"&&r.push(this.err(t,"pattern/minLength/maxLength","Warning",`String facets on '${t}' apply to '${a.name}', which is an object property; string facets constrain literal values.`,"Apply string facets to a datatype property, or use sh:class for node values.",J(a))),(T!==void 0||j!==void 0)&&!this.isNumericDatatypeRange(_.range)&&r.push(this.err(t,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${t}' apply to '${a.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",J(a))))}}checkOrder(e,t,o,n,r,a){o!==void 0&&r!==void 0&&o>r&&a.push(this.err(e,`${t}/${n}`,"Error",`${t} (${o}) exceeds ${n} (${r}) on '${e}'.`,`Set ${t} <= ${n}.`))}resolvesToClass(e,t){let o=k(e,t);return o?v.isClassType(St(o)):!1}resolvesToDatatype(e,t){if(t.publisher===ze&&t.package_==="core-rdf"&&t.name==="Literal")return!0;let o=k(e,t);return o?v.isDatatypeType(St(o)):!1}isNumericDatatypeRange(e){return!e||e.publisher===ze&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===ze&&e.package_==="core-xsd"&&Rn.has(e.name)}err(e,t,o,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=o,i.entityName=e,i.propertyName=t,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function we(c){return typeof c=="number"?c:void 0}function J(c){return`${c.publisher}/${c.package_}/${c.name}`}function Kn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var Pt={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},bn=c=>c,xe=class{ruleName="OwlOneOf";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(t),a=Vn(e);if(!a)return n;for(let i of r){if(!(i instanceof f)||i.namespace!==a||!ee(i,Pt))continue;let s=b(i,Pt);if(s.length===0){n.push(this.err(i.name,"Warning",`owl:oneOf on '${i.name}' is empty; a closed enumeration must list at least one individual.`,"List the individuals that make up the enumeration, or remove owl:oneOf."));continue}for(let p of s)if(p instanceof Fe)n.push(this.err(i.name,"Error",`owl:oneOf member '${String(p.value)}' on '${i.name}' is not a named individual; a class enumeration is of individuals (a misspelled or unimported individual reads as a literal). For a closed set of literal VALUES, constrain a property with sh:in instead.`,"Reference a defined or imported individual, or move literal value sets to a property sh:in.",String(p.value)));else if(p instanceof D){let l=k(r,p.subject);l&&v.isSchemaDefinitionType(bn(l))&&n.push(this.err(i.name,"Error",`owl:oneOf member '${p.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${p.subject.publisher}/${p.subject.package_}/${p.subject.name}`))}}return n}err(e,t,o,n,r){let a=new u;return a.ruleType=this.ruleName,a.severity=t,a.entityName=e,a.propertyName="oneOf",a.message=o,a.suggestion=n,r!==void 0&&(a.actualValue=r),a}};function Vn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var En="kanonak.org",vn="core-shacl",N=c=>({publisher:En,package_:vn,name:c}),Dn=N("NodeShape"),In=N("targetClass"),Cn=N("property"),Sn=N("path"),Pn=N("minCount"),jn=N("maxCount"),On=N("in"),$n=N("pattern"),Un=N("flags"),wn=N("minLength"),An=N("maxLength"),xn=N("minInclusive"),Nn=N("maxInclusive"),Tn=N("message");function Ne(c){return typeof c=="number"?c:void 0}function _n(c){let e={},t=Ne(x(c,Pn)),o=Ne(x(c,jn));t!==void 0&&(e.minCount=t),o!==void 0&&(e.maxCount=o);let n=Ne(x(c,wn)),r=Ne(x(c,An));n!==void 0&&(e.minLength=n),r!==void 0&&(e.maxLength=r);let a=Ne(x(c,xn)),i=Ne(x(c,Nn));a!==void 0&&(e.minInclusive=a),i!==void 0&&(e.maxInclusive=i);let s=F(c,$n);if(s!==void 0){let m=F(c,Un);e.pattern=m!==void 0?{regex:s,flags:m}:{regex:s}}let p=b(c,On).filter(m=>m instanceof Fe).map(m=>m.value);p.length>0&&(e.enumValues=p);let l=F(c,Tn);return l!==void 0&&(e.message=l),e}function Ln(c,e){let t=[];for(let o of b(e,Cn))if(o instanceof I)t.push(o);else if(o instanceof D){let n=k(c,o.subject);n&&t.push(n)}return t}function jt(c){let e=new Map;for(let t of c){if(!(t instanceof f)||!P(t,Dn))continue;let o=y(t,In);if(!o)continue;let n=R(o);for(let r of Ln(c,t)){let a=y(r,Sn);if(!a)continue;let i={pathKey:R(a),constraints:_n(r)},s=e.get(n);s?s.push(i):e.set(n,[i])}}return e}function Mn(c,e){e.minCount!==void 0&&(c.minCount=e.minCount),e.maxCount!==void 0&&(c.maxCount=e.maxCount),e.minLength!==void 0&&(c.minLength=e.minLength),e.maxLength!==void 0&&(c.maxLength=e.maxLength),e.minInclusive!==void 0&&(c.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(c.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(c.pattern=e.pattern),e.enumValues!==void 0&&(c.enumValues=e.enumValues),e.message!==void 0&&(c.message=e.message)}function Ot(c,e,t){let o=R(t),n=!1,r={};for(let a=e.length-1;a>=0;a--){let i=c.get(R(e[a]));if(i)for(let s of i)s.pathKey===o&&(n=!0,Mn(r,s.constraints))}if(n)return r.cardinality=r.maxCount===1?"single":"list",r.required=(r.minCount??0)>=1,r}var Bn=c=>c,Fn=new rt("kanonak.org","core-rdf","Resource"),Te=class{ruleName="DiamondNameClash";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(t),a=Hn(e);if(!a)return n;let i=jt(r);for(let s of r){if(!(s instanceof f)||s.namespace!==a||!v.isClassType(Bn(s)))continue;let p=w(s);if(!p)continue;let l=z(r,p),m=R(p),d=new Set(l.map(V=>R(V)));d.delete(m),d.delete(R(Fn));let h=new Map;for(let V of st(r,p)){if(!V.domains.some(O=>d.has(R(O))))continue;let j=h.get(V.uri.name);j?j.push(V):h.set(V.uri.name,[V])}for(let[V,T]of h){if(T.length<2)continue;let j=_=>Ot(i,l,_.uri)?.cardinality,O=new Set(T.map(_=>_.range?R(_.range):void 0).filter(_=>_!==void 0)),B=new Set(T.map(j).filter(_=>_!==void 0));O.size<=1&&B.size<=1||n.push(this.toError(s.name,V,T,j))}}return n}toError(e,t,o,n){let r=s=>{let p=`${s.uri.publisher}/${s.uri.package_}/${s.uri.name}`,l=s.range?`${s.range.publisher}/${s.range.package_}/${s.range.name}`:"no range",m=n(s);return`${p} (range ${l}${m?`, ${m}`:""})`},a=o.map(r).join("; "),i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=t,i.actualValue=a,i.message=`Class '${e}' inherits ${o.length} distinct properties named '${t}' with incompatible range or cardinality: ${a}. The generated interface would multiply-inherit '${t}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${t}':
|
|
60
|
+
\u2022 rename one of the properties, or
|
|
61
|
+
\u2022 re-domain one so it is not inherited by '${e}', or
|
|
62
|
+
\u2022 restructure the hierarchy so '${e}' inherits only one '${t}', or
|
|
63
|
+
\u2022 make the ranges/cardinalities compatible (identical) if they are meant to be the same property.`,i}};function Hn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${U(e.version)}`}var ot=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new nt,this.documentRules=[new ae,new ie,new se,new ce,new pe],this.repositoryRules=[new le,new me,new ue,new de,new fe,new ye,new ge,new ke,new he,new Re,new Ke,new be,new Ee,new ve,new De,new Ie,new Ce,new Se,new Pe,new je,new Be,new Oe,new Ae,new xe,new Te]}async validateAsync(e,t,o){let n=new te;for(let r of this.documentRules)try{let a=r.validate(e);this.addErrorsToResult(n,a)}catch(a){let i=new u;i.ruleType=r.ruleName,i.severity="Error",i.message=`Validation rule '${r.ruleName}' failed: ${a instanceof Error?a.message:String(a)}`,n.errors.push(i)}if(t){let r=[],a=o??new oe(new ne(e,t)),i=a.repository;for(let s of this.repositoryRules)try{let p=await s.validateAsync(e,i,a);this.addErrorsToResult(n,p)}catch(p){let l=p instanceof Error?p.message:String(p);r.push({ruleName:s.ruleName,cause:l})}if(r.length>0){let s=new Map;for(let{ruleName:p,cause:l}of r){let m=s.get(l);m?m.push(p):s.set(l,[p])}for(let[p,l]of s){let m=new u;m.ruleType=l[0],m.severity="Error",l.length===1?m.message=`Validation rule '${l[0]}' failed: ${p}`:m.message=`${p} (affects ${l.length} rules: ${l.join(", ")})`,n.errors.push(m)}}}return n.isValid=n.errors.length===0,n}async validateDocumentsAsync(e,t){let o=new oe(t),n=[];for(let r of e){let a=await this.validateAsync(r,o.repository,o);n.push({document:r,result:a})}return n}async validateYamlAsync(e,t,o){let n=this.parser.parseWithErrors(e);if(!n.isValid){let r=new te;r.isValid=!1;for(let a of n.errors){let i=new u;i.ruleType="ParseError",i.severity="Error",i.lineNumber=a.line,i.column=a.column,i.message=a.message,a.keyName&&(i.entityName=a.keyName),a.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),r.errors.push(i)}return r}return await this.validateAsync(n.document,t,o)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let t=this.documentRules.findIndex(o=>o instanceof e);t>=0&&this.documentRules.splice(t,1)}removeRepositoryRule(e){let t=this.repositoryRules.findIndex(o=>o instanceof e);t>=0&&this.repositoryRules.splice(t,1)}addErrorsToResult(e,t){for(let o of t)o.severity==="Error"?e.errors.push(o):o.severity==="Info"?this.includeWarnings&&e.infos.push(o):this.includeWarnings&&e.warnings.push(o)}};export{te as a,g as b,u as c,Xe as d,oe as e,ae as f,ie as g,se as h,ce as i,pe as j,le as k,me as l,ue as m,de as n,fe as o,ye as p,ge as q,ke as r,he as s,Re as t,Ke as u,be as v,Ee as w,ve as x,De as y,Ie as z,Ce as A,Se as B,Pe as C,je as D,Oe as E,Ae as F,xe as G,jt as H,Ot as I,Te as J,ot as K};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as M,d as L,m as k,r as V,s as E,v as x,w as C,y as F}from"./chunk-YW6P24RF.js";import{a as P}from"./chunk-FUUTGGJS.js";var B=class{cache=new Map;repository;logger;constructor(e,n){this.repository=e,this.logger=n}async resolveEntityAsync(e,n){let r=n.metadata?.namespace_?.toString()??"unknown",a=this.cache.get(r);if(a){let i=a.get(e);if(i)return i}let o=await this.buildEntityIndexAsyncInternal(n,new Set,"",new Map);return this.cache.set(r,o),o.get(e)??null}async resolveAllEntitiesAsync(e,n){let r=await this.buildAllEntitiesIndexAsync(n,new Set,"");if(e.includes(".")){let a=e.split("."),o=a[0],i=a[1],l=await this.findDocumentForAlias(n,o);return l?await this.resolveAllEntitiesAsync(i,l):[]}return r.filter(a=>a.entityName===e)}async buildAllEntitiesIndexAsync(e,n,r){let a=[],o=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${o}`),n.has(o))return this.logger?.debug?.(`Skipping ${o} - already visited (circular import prevention)`),a;n.add(o);let i=r.length===0?o:`${r} \u2192 ${o}`;for(let[l,p]of Object.entries(e.body))if(!l.includes(".")&&p&&typeof p=="object"&&!Array.isArray(p)){if(!e.metadata.namespace_)continue;let d=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};a.push({entityName:l,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,l,d),entity:p,definedInNamespace:o,isImported:r.length>0,importPath:i})}if(this.logger?.debug?.(`Collected ${a.length} entities from ${o}`),e.metadata?.imports){let l=Object.values(e.metadata.imports).reduce((p,d)=>p+d.length,0);this.logger?.debug?.(`Processing ${l} import(s) for ${o}`);for(let[p,d]of Object.entries(e.metadata.imports))for(let g of d)try{this.logger?.debug?.(`Resolving import: ${p}/${g.packageName}`);let y=await this.repository.getHighestCompatibleVersionAsync(p,g);if(y){this.logger?.debug?.(`Successfully loaded import: ${y.metadata?.namespace_?.toString()}`);let f=await this.buildAllEntitiesIndexAsync(y,n,i);a.push(...f),this.logger?.debug?.(`Added ${f.length} entities from import ${y.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${p}/${g.packageName}`)}catch(y){let f=y;throw this.logger?.error?.(`Failed to process import ${p}/${g.packageName} for namespace ${o}. Error: ${f.message}`,f),new Error(`Failed to process import ${p}/${g.packageName} for namespace ${o}. See inner exception for details.`,{cause:y})}}return a}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,n,r,a){let o=new Map,i=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${i}`),n.has(i))return this.logger?.debug?.(`Skipping ${i} - circular import in progress`),o;let l=a.get(i);if(l)return l;n.add(i);let p=r.length===0?i:`${r} \u2192 ${i}`,d=0;for(let[g,y]of Object.entries(e.body))if(!g.includes(".")&&y&&typeof y=="object"&&!Array.isArray(y)){if(!e.metadata.namespace_)continue;if(!o.has(g)){let f=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};o.set(g,{entityName:g,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,g,f),entity:y,definedInNamespace:i,isImported:r.length>0,importPath:p}),d++}}if(this.logger?.debug?.(`Indexed ${d} entities from ${i}`),e.metadata?.imports){let g=Object.values(e.metadata.imports).reduce((y,f)=>y+f.length,0);this.logger?.debug?.(`Processing ${g} import(s) for ${i}`);for(let[y,f]of Object.entries(e.metadata.imports))for(let S of f)try{this.logger?.debug?.(`Resolving import: ${y}/${S.packageName}`);let $=await this.repository.getHighestCompatibleVersionAsync(y,S);if($){this.logger?.debug?.(`Successfully loaded import: ${$.metadata?.namespace_?.toString()}`);let j=await this.buildEntityIndexAsyncInternal($,n,p,a),D=0;for(let[U,_]of j.entries()){let K=o.get(U);if(!K)o.set(U,_),D++;else if(K.isImported&&_.isImported&&(K.uri.publisher!==_.uri.publisher||K.uri.package_!==_.uri.package_)){let R=K.isAmbiguous?K:{...K,isAmbiguous:!0,ambiguousNamespaces:[K.definedInNamespace]};R.ambiguousNamespaces.includes(_.definedInNamespace)||R.ambiguousNamespaces.push(_.definedInNamespace),o.set(U,R),this.logger?.warn?.(`Ambiguous reference '${U}': defined in ${R.ambiguousNamespaces.join(", ")}`)}if(S.alias&&!U.includes(".")){let R=`${S.alias}.${U}`;o.has(R)||(o.set(R,_),D++)}}this.logger?.debug?.(`Merged ${D} entities from import ${$.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${y}/${S.packageName}`)}catch($){let j=$;throw this.logger?.error?.(`Failed to process import ${y}/${S.packageName} for namespace ${i}. Error: ${j.message}`,j),new Error(`Failed to process import ${y}/${S.packageName} for namespace ${i}. See inner exception for details.`,{cause:$})}}return n.delete(i),a.set(i,o),o}async findDocumentForAlias(e,n){if(!e.metadata?.imports)return null;for(let[r,a]of Object.entries(e.metadata.imports))for(let o of a){if(o.alias===n)return await this.repository.getHighestCompatibleVersionAsync(r,o);if(!o.alias&&o.packageName===n)return await this.repository.getHighestCompatibleVersionAsync(r,o)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}};var H=class t{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","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"&&t.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 n=e.includes(".")?e.split(".")[1]:e;return t.KNOWN_XSD_DATATYPES.has(n.toLowerCase())}async isClassTypeAsync(e,n){if(this.isKnownXsdDatatypeName(e))return!1;let r=await this.resourceResolver.resolveEntityAsync(e,n);if(r){let a=r.entity.type;if(a){let o=String(a);return o==="Class"||o==="rdfs.Class"||o.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,n){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(n)||e==="Property"&&this.isLiteralType(n))}isEffectiveObjectProperty(e,n){return!!(e==="ObjectProperty"||e==="Property"&&n&&!this.isXsdDatatype(n)&&!this.isLiteralType(n))}};function q(t){if(!t||t.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let e=t.trim(),n=e.split("/");if(n.length===1){let r=n[0];if(!r)throw new Error(`Invalid Kanonak address: "${t}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(r.includes("@"))throw new Error(`Invalid Kanonak address: "${t}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:r}}if(n.length===2){let[r,a]=n;if(!r||!a)throw new Error(`Invalid Kanonak address: "${t}". Expected publisher/package[@version].`);let o=a.indexOf("@");if(o===-1)return{kind:"package",publisher:r,package_:a};let i=a.substring(0,o),l=a.substring(o+1);if(!i||!l)throw new Error(`Invalid Kanonak address: "${t}". Expected publisher/package[@version].`);let p=J(l);return{kind:"package",publisher:r,package_:i,version:p}}return{kind:"resource",uri:P.parse(e)}}function Ke(t){switch(t.kind){case"publisher":return t.publisher;case"package":return t.version?`${t.publisher}/${t.package_}@${t.version.major}.${t.version.minor}.${t.version.patch}`:`${t.publisher}/${t.package_}`;case"resource":return t.uri.toString()}}function J(t){let e=t.split(".").map(Number);return Q(e[0]||0,e[1]||0,e[2]||0)}function Q(t,e,n){return{major:t,minor:e,patch:n,toString:()=>`${t}.${e}.${n}`,equals:r=>!r||typeof r!="object"?!1:r.major===t&&r.minor===e&&r.patch===n,getHashCode:()=>t<<20|e<<10|n,compareTo:r=>t!==r.major?t-r.major:e!==r.minor?e-r.minor:n-r.patch}}function Se(t){return`${t.publisher}/${t.package_}/${t.name}`}function u(t,e,n){return`${t}/${e}/${n}`}function $e(t){return`${t.s}|${t.p}|${Z(t.o)}`}function Z(t){switch(t.kind){case"uri":return`u:${t.key}`;case"literal":return`l:${t.datatype}:${t.lexical}`;case"blank":return`b:${t.id}`}}function _e(t,e,n){return{s:t,p:e,o:{kind:"uri",key:n}}}var c="kanonak.org",s="core-rdf",m="core-owl",W="core-kanonak",O=new Map([["type",s],["subClassOf",s],["subPropertyOf",s],["domain",s],["range",s],["label",s],["comment",s],["seeAlso",s],["isDefinedBy",s],["member",s],["Resource",s],["Class",s],["Property",s],["Datatype",s],["Literal",s],["List",s],["ObjectProperty",m],["DatatypeProperty",m],["AnnotationProperty",m],["Thing",m],["Nothing",m],["Package",W]]),ee=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function Ae(t){return O.has(t)}function Ue(t){let e=O.get(t);return e?{publisher:c,package_:e}:void 0}function I(t,e,n){if(!t||!t.name)return;let r=O.get(t.name);if(!r)return;let a=()=>{t.publisher=c,t.package_=r,n&&(t.version=n.get(r))};if(ee.has(t.name)){let o=t.publisher===c&&t.package_===r;t.publisher=c,t.package_=r,!o&&n&&(t.version=n.get(r));return}t.publisher===c&&t.package_===r||t.publisher&&t.publisher.length>0&&(!e||e(t))||a()}var X=class{type=u(c,s,"type");subClassOf=u(c,s,"subClassOf");subPropertyOf=u(c,s,"subPropertyOf");domain=u(c,s,"domain");range=u(c,s,"range");label=u(c,s,"label");comment=u(c,s,"comment");resource=u(c,s,"Resource");class_=u(c,s,"Class");datatype=u(c,s,"Datatype");literal=u(c,s,"Literal");equivalentClass=u(c,m,"equivalentClass");equivalentProperty=u(c,m,"equivalentProperty");inverseOf=u(c,m,"inverseOf");sameAs=u(c,m,"sameAs");transitiveProperty=u(c,m,"TransitiveProperty");symmetricProperty=u(c,m,"SymmetricProperty");objectProperty=u(c,m,"ObjectProperty");datatypeProperty=u(c,m,"DatatypeProperty");annotationProperty=u(c,m,"AnnotationProperty");package_=u(c,W,"Package")};var ne=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function b(t){let e=t;if(e.entity&&typeof e.entity=="object"){let n=e.entity.type;if(typeof n=="string"){let a={publisher:"",package_:"",name:n.includes(".")?n.substring(n.lastIndexOf(".")+1):n};return I(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}if(e.statement&&Array.isArray(e.statement)){for(let n of e.statement)if(n.predicate?.subject?.name==="type"&&n.object?.subject){let r=n.object.subject,a={publisher:r.publisher??"",package_:r.package_??"",name:r.name};return I(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}return null}function h(t,e){return ne.has(`${t}/${e}`)}var te=new Set(["Property","ObjectProperty","DatatypeProperty","AnnotationProperty"]);function N(t){if(h(t.publisher,t.package_))return te.has(t.name)?t.name:void 0}var Y=class t{static getTypeUri(e){return b(e)}static isCoreOntologyType(e){return h(e.publisher,e.package_)}static isClassType(e){let n=b(e);return n?h(n.publisher,n.package_)&&n.name==="Class":!1}static isDatatypeType(e){let n=b(e);return n?h(n.publisher,n.package_)&&n.name==="Datatype":!1}static isDatatypePropertyType(e){let n=b(e);return n?h(n.publisher,n.package_)&&n.name==="DatatypeProperty":!1}static isObjectPropertyType(e){let n=b(e);return n?h(n.publisher,n.package_)&&n.name==="ObjectProperty":!1}static isAnnotationPropertyType(e){let n=b(e);return n?h(n.publisher,n.package_)&&n.name==="AnnotationProperty":!1}static isGenericPropertyType(e){let n=b(e);return n?h(n.publisher,n.package_)&&n.name==="Property":!1}static isAnyPropertyType(e){let n=b(e);return!n||!h(n.publisher,n.package_)?!1:n.name==="Property"||n.name==="DatatypeProperty"||n.name==="ObjectProperty"||n.name==="AnnotationProperty"}static isSchemaDefinitionType(e){let n=b(e);return!n||!h(n.publisher,n.package_)?!1:n.name==="Class"||n.name==="Property"||n.name==="DatatypeProperty"||n.name==="ObjectProperty"||n.name==="AnnotationProperty"||n.name==="Datatype"}static isInstanceOfKnownClass(e,n){if(t.isSchemaDefinitionType(e))return!1;let r=b(e);return r?n.has(r.name):!1}};var v="kanonak.org",A="core-rdf",re={publisher:v,package_:A,name:"domain"},ae={publisher:v,package_:A,name:"range"},oe={publisher:v,package_:A,name:"subClassOf"},ie={publisher:v,package_:A,name:"type"},se={publisher:v,package_:A,name:"label"},pe={publisher:v,package_:A,name:"comment"},ce=new P(v,A,"Resource");function le(t){try{let e=q(`${t.namespace}/${t.name}`);return e.kind==="resource"?e.uri:void 0}catch{return}}function T(t,e){let n=C(t,e);if(n)return[n];let r=[];for(let a of F(t,e))a instanceof L&&r.push(a.subject);return r}function G(t,e){let n=[],r=new Set,a="version"in e?e.version:void 0,o=[new P(e.publisher,e.package_,e.name,a??void 0)];for(;o.length>0;){let i=o.shift(),l=k(i);if(r.has(l))continue;r.add(l),n.push(i);let p=ue(t,i);p&&o.push(...T(p,oe))}return n}function ue(t,e){return e.version&&typeof e.version.major=="number"?V(t,e)??E(t,e)[0]:E(t,e)[0]}function w(t,e){let n;for(let r of me(e)){let a=ye(t,r);if(a){if(a!=="Property")return a;n??=a}}return n}function ye(t,e){let n=N(e);if(n)return n;let r=z.get(t);r||(r=new Map,z.set(t,r));let a=e.version,o=a&&typeof a.major=="number"?`${k(e)}@${a.major}.${a.minor}.${a.patch}`:k(e),i=r.get(o);if(i!==void 0)return i??void 0;let l;for(let p of G(t,e)){let d=N(p);if(d){if(d!=="Property"){l=d;break}l??="Property"}}return r.set(o,l??null),l}var z=new WeakMap;function Te(t,e){return w(t,e)!==void 0}function Me(t,e){return w(t,e)==="ObjectProperty"}function Le(t,e){return w(t,e)==="DatatypeProperty"}function de(t,e){let n=new Set([k(ce)]);for(let r of G(t,e))n.add(k(r));return n}function ge(t,e){let n=de(t,e),r=[],a=new Set;for(let o of t){if(!(o instanceof M))continue;let i=w(t,o);if(!i)continue;let l=T(o,re);if(!l.some(g=>n.has(k(g))))continue;let p=le(o);if(!p)continue;let d=k(p);a.has(d)||(a.add(d),r.push({uri:p,label:x(o,se),comment:x(o,pe),kind:i==="ObjectProperty"?"object":i==="DatatypeProperty"?"datatype":"other",range:C(o,ae),domains:l}))}return r}function Ve(t,e,n){let r=ge(t,e).find(a=>k(a.uri)===k(n));return r?{ok:!0,descriptor:r}:{ok:!1,message:`Property ${n.publisher}/${n.package_}/${n.name} is not in scope for ${e.publisher}/${e.package_}/${e.name}.`}}function me(t){return T(t,ie)}export{B as a,H as b,q as c,Ke as d,Se as e,u as f,$e as g,Z as h,_e as i,Ae as j,Ue as k,I as l,X as m,N as n,Y as o,le as p,G as q,w as r,Te as s,Me as t,Le as u,ge as v,Ve as w,me as x};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as j,b as x,m as $}from"./chunk-V6KIDED2.js";import{e as l,f as u,g as b,h as C,i as a,m as U}from"./chunk-SVUMCLK5.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-YW6P24RF.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let r=b(e);return this.all.has(r)?!1:(this.all.add(r),this.tripleList.push(e),h(this.byPIdx,e.p,e),h(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&h(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let r=this.byPIdx.get(e);return r?r.slice():[]}bySubjectPredicate(e,r){let t=this.bySPIdx.get(`${e}|${r}`);return t?t.slice():[]}byPredicateObject(e,r){let t=this.byPOIdx.get(`${e}|${r}`);return t?t.slice():[]}subjectsWithPredicateObject(e,r){let t=this.byPOIdx.get(`${e}|${r}`);if(!t)return[];let s=new Set;for(let n of t)s.add(n.s);return Array.from(s)}uriObjectsOf(e,r){let t=this.bySPIdx.get(`${e}|${r}`);if(!t)return[];let s=new Set;for(let n of t)n.o.kind==="uri"&&s.add(n.o.key);return Array.from(s)}hasUri(e,r,t){return this.all.has(`${e}|${r}|u:${t}`)}hasTriple(e,r,t){return this.all.has(`${e}|${r}|${C(t)}`)}};function h(o,e,r){let t=o.get(e);t?t.push(r):o.set(e,[r])}var _={name:"rdfs2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.domain)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},E={name:"rdfs3",apply(o,e){let r=!1;for(let t of o.byPredicate(e.range)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))i.o.kind==="uri"&&o.add(a(i.o.key,e.type,n))&&(r=!0)}return r}},A={name:"rdfs5",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subPropertyOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.bySubjectPredicate(n,e.subPropertyOf))i.o.kind==="uri"&&o.add(a(s,e.subPropertyOf,i.o.key))&&(r=!0)}return r}},V={name:"rdfs7",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subPropertyOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(s)){let p={s:i.s,p:n,o:i.o};o.add(p)&&(r=!0)}}return r}},W={name:"rdfs9",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subClassOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},F={name:"rdfs11",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subClassOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.bySubjectPredicate(n,e.subClassOf))i.o.kind==="uri"&&o.add(a(s,e.subClassOf,i.o.key))&&(r=!0)}return r}},k=[_,E,A,V,W,F];var N={name:"prp-trp",apply(o,e){let r=!1,t=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let s of t){let n=o.byPredicate(s);for(let i of n){if(i.o.kind!=="uri")continue;let p=i.o.key;for(let c of o.bySubjectPredicate(p,s))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(a(i.s,s,c.o.key))&&(r=!0)}}return r}},D={name:"prp-symp",apply(o,e){let r=!1,t=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let s of t)for(let n of o.byPredicate(s))n.o.kind==="uri"&&o.add(a(n.o.key,s,n.s))&&(r=!0);return r}},M={name:"prp-inv1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.inverseOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))i.o.kind==="uri"&&o.add(a(i.o.key,n,i.s))&&(r=!0)}return r}},z={name:"prp-inv2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.inverseOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(a(i.o.key,s,i.s))&&(r=!0)}return r}},B={name:"prp-eqp1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentProperty)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(s))o.add({s:i.s,p:n,o:i.o})&&(r=!0)}return r}},G={name:"prp-eqp2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentProperty)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(n))o.add({s:i.s,p:s,o:i.o})&&(r=!0)}return r}},H={name:"cax-eqc1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentClass)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},J={name:"cax-eqc2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentClass)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,n))o.add(a(i.s,e.type,s))&&(r=!0)}return r}},Q={name:"eq-rep-s",apply(o,e){let r=!1;for(let t of o.byPredicate(e.sameAs)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n){for(let i of o.snapshot())i.s===s&&o.add({s:n,p:i.p,o:i.o})&&(r=!0);for(let i of o.snapshot())i.s===n&&o.add({s,p:i.p,o:i.o})&&(r=!0)}}return r}},X={name:"eq-rep-o",apply(o,e){let r=!1;for(let t of o.byPredicate(e.sameAs)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===s?o.add(a(i.s,i.p,n))&&(r=!0):i.o.key===n&&o.add(a(i.s,i.p,s))&&(r=!0))}return r}},K=[N,D,M,z,B,G,H,J,Q,X];var y=class{constructor(e,r){this.store=e;this.vocabulary=r}store;vocabulary;getInstancesOfClass(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,r)}getSubclasses(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,r).filter(s=>s!==r)}getSuperclasses(e){let r=f(e);return this.store.uriObjectsOf(r,this.vocabulary.subClassOf).filter(t=>t!==r)}getTypesOfIndividual(e){return this.store.uriObjectsOf(f(e),this.vocabulary.type)}isInstanceOf(e,r){return this.store.hasUri(f(e),this.vocabulary.type,f(r))}getPropertyClosure(e){let r=f(e),t={},s=new Map;for(let n of this.store.byPredicate(r)){if(n.o.kind!=="uri")continue;let i=s.get(n.s);i||(i=new Set,s.set(n.s,i),t[n.s]=[]),i.has(n.o.key)||(i.add(n.o.key),t[n.s].push(n.o.key))}return t}getPropertyClosures(e){let r={};for(let t of e)r[f(t)]=this.getPropertyClosure(t);return r}triples(){return this.store.snapshot()}size(){return this.store.size()}};function f(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new U,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let r=new d,s=await new $().parseKanonaks(e),n=new P;for(let c of s)if(c instanceof S){let m=Y(c);if(!m)continue;for(let w of c.statement)this.emitStatement(m,w,r,n)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let p=0;for(;p<this.maxIterations;){let c=!1;for(let m of i)m.apply(r,this.vocabulary)&&(c=!0);if(!c)break;p++}return new y(r,this.vocabulary)}emitStatement(e,r,t,s){let n=Z(r);if(n){if(r instanceof I){t.add({s:e,p:n,o:{kind:"literal",lexical:r.object,datatype:"string"}});return}if(r instanceof T){t.add({s:e,p:n,o:{kind:"literal",lexical:String(r.object),datatype:"number"}});return}if(r instanceof g){t.add({s:e,p:n,o:{kind:"literal",lexical:String(r.object),datatype:"boolean"}});return}if(r instanceof v){let i=l(r.object.subject);t.add(a(e,n,i));return}if(r instanceof L){let i=s.next();t.add({s:e,p:n,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r.object,t,s);return}if(r instanceof q){for(let i of r.object??[])this.emitListItem(e,n,i,t,s);return}}}emitListItem(e,r,t,s,n){if(t instanceof O)s.add(a(e,r,l(t.subject)));else if(t instanceof j){let i=n.next();s.add({s:e,p:r,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t,s,n)}else if(t instanceof x){let i=typeof t.value=="number"?"number":typeof t.value=="boolean"?"boolean":"string";s.add({s:e,p:r,o:{kind:"literal",lexical:String(t.value),datatype:i}})}}emitEmbedded(e,r,t,s){let n=`_:${e}`;for(let i of r.statement)this.emitStatement(n,i,t,s)}},P=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",r=e.indexOf("@"),t=r===-1?e:e.substring(0,r),s=t.indexOf("/");if(s===-1)return null;let n=t.substring(0,s),i=t.substring(s+1);return!n||!i||!o.name?null:u(n,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,R as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as F}from"./chunk-NJ3AZYQD.js";import{a as W,b as G,j as X,l as T,r as J}from"./chunk-SVUMCLK5.js";import{a as $,b as z,c as S,d as g,g as P,h as I,i as L,j,k as w,l as K,m as E,n as q,r as H}from"./chunk-YW6P24RF.js";import{a as D}from"./chunk-FUUTGGJS.js";import{j as U}from"./chunk-2ACBWC7K.js";var b=class extends z{name};var R=class extends ${value;carrier;lexical};var v=class extends P{links=[]};var ne="kanonak.org",re="transformations",ge=3,e=m=>({publisher:ne,package_:re,name:m}),M={Transformation:e("Transformation"),InstanceTransformation:e("InstanceTransformation"),SetTransformation:e("SetTransformation"),inputPattern:e("inputPattern"),rule:e("rule"),artifactName:e("artifactName"),outputs:e("outputs"),formatOverrides:e("formatOverrides"),partitionBy:e("partitionBy"),InputPattern:e("InputPattern"),matchesClass:e("matchesClass"),requires:e("requires"),sortBy:e("sortBy"),SortKey:e("SortKey"),byProperty:e("byProperty"),order:e("order"),SortOrder:e("SortOrder"),ascending:e("ascending"),descending:e("descending"),OutputFormat:e("OutputFormat"),backendUri:e("backendUri"),FormatOverride:e("FormatOverride"),formatTarget:e("formatTarget"),metadataKeys:e("metadataKeys"),metadataRenames:e("metadataRenames"),trailingNewline:e("trailingNewline"),omitWrapper:e("omitWrapper"),RenameEntry:e("RenameEntry"),fromKey:e("fromKey"),toKey:e("toKey"),FMT_MARKDOWN_FRONTMATTER:e("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:e("plain-markdown"),FMT_TOML:e("toml"),FMT_JSON:e("json"),FMT_HTML:e("html"),FMT_SVG:e("svg"),Expression:e("Expression"),ListSourcedExpression:e("ListSourcedExpression"),ListAggregate:e("ListAggregate"),IteratingExpression:e("IteratingExpression"),BuildAstNode:e("BuildAstNode"),astClass:e("astClass"),set:e("set"),AstFieldBinding:e("AstFieldBinding"),field:e("field"),bindValue:e("bindValue"),When:e("When"),condition:e("condition"),thenBuild:e("thenBuild"),elseBuild:e("elseBuild"),Concat:e("Concat"),parts:e("parts"),Fallback:e("Fallback"),primary:e("primary"),alternate:e("alternate"),StringLiteral:e("StringLiteral"),stringLiteral:e("stringLiteral"),IntegerLiteral:e("IntegerLiteral"),integerLiteral:e("integerLiteral"),DecimalLiteral:e("DecimalLiteral"),decimalLiteral:e("decimalLiteral"),BooleanLiteral:e("BooleanLiteral"),booleanLiteral:e("booleanLiteral"),VarRef:e("VarRef"),varName:e("varName"),PropertyRead:e("PropertyRead"),readSource:e("readSource"),readProp:e("readProp"),Traverse:e("Traverse"),traverseSource:e("traverseSource"),through:e("through"),step:e("step"),UriName:e("UriName"),uriNameOf:e("uriNameOf"),UriPublisher:e("UriPublisher"),uriPublisherOf:e("uriPublisherOf"),UriPackage:e("UriPackage"),uriPackageOf:e("uriPackageOf"),UriVersion:e("UriVersion"),uriVersionOf:e("uriVersionOf"),SubjectUri:e("SubjectUri"),subjectOf:e("subjectOf"),UriLiteral:e("UriLiteral"),refTo:e("refTo"),DisplayLabel:e("DisplayLabel"),labelTarget:e("labelTarget"),labelSource:e("labelSource"),ResolveRef:e("ResolveRef"),resolveSource:e("resolveSource"),Normalize:e("Normalize"),normSource:e("normSource"),normKind:e("normKind"),NormalizeKind:e("NormalizeKind"),NORM_TRIM_END:e("trim-end"),NORM_TO_UPPER:e("to-upper"),NORM_TO_LOWER:e("to-lower"),NORM_FIRST_CHAR:e("first-char"),UnescapedString:e("UnescapedString"),unescapedSource:e("unescapedSource"),IsSet:e("IsSet"),checkExpr:e("checkExpr"),ExpressionFragment:e("ExpressionFragment"),body:e("body"),CallFragment:e("CallFragment"),fragmentRef:e("fragmentRef"),source:e("source"),Join:e("Join"),separator:e("separator"),Count:e("Count"),Sum:e("Sum"),Min:e("Min"),Max:e("Max"),Average:e("Average"),loopVar:e("loopVar"),ForEach:e("ForEach"),emit:e("emit"),ListMap:e("ListMap"),mapBody:e("mapBody"),Filter:e("Filter"),predicate:e("predicate"),PartitionBy:e("PartitionBy"),partitionKey:e("partitionKey"),DistinctBy:e("DistinctBy"),distinctKey:e("distinctKey"),Partition:e("Partition"),key:e("key"),members:e("members"),AllStatements:e("AllStatements"),statementsOf:e("statementsOf"),StatementPredicate:e("StatementPredicate"),predicateOf:e("predicateOf"),StatementValue:e("StatementValue"),valueOf:e("valueOf"),DateFormat:e("DateFormat"),dateSource:e("dateSource"),dateFormat:e("dateFormat"),BinaryArithmetic:e("BinaryArithmetic"),arithLeft:e("arithLeft"),arithRight:e("arithRight"),Add:e("Add"),Subtract:e("Subtract"),Multiply:e("Multiply"),Divide:e("Divide"),Reverse:e("Reverse"),WindowedMap:e("WindowedMap"),windowSize:e("windowSize"),windowVar:e("windowVar"),windowBody:e("windowBody"),PairwiseMap:e("PairwiseMap"),firstVar:e("firstVar"),secondVar:e("secondVar"),pairBody:e("pairBody"),Scan:e("Scan"),initialState:e("initialState"),stateVar:e("stateVar"),elementVar:e("elementVar"),accumulate:e("accumulate"),ListItemAt:e("ListItemAt"),itemIndex:e("itemIndex"),BinaryComparison:e("BinaryComparison"),compareLeft:e("compareLeft"),compareRight:e("compareRight"),Equals:e("Equals"),GreaterThan:e("GreaterThan"),LessThan:e("LessThan"),GreaterThanOrEqual:e("GreaterThanOrEqual"),LessThanOrEqual:e("LessThanOrEqual"),Not:e("Not"),operand:e("operand"),BooleanLogic:e("BooleanLogic"),operands:e("operands"),And:e("And"),Or:e("Or"),Contains:e("Contains"),haystack:e("haystack"),needle:e("needle"),UnaryNumericOp:e("UnaryNumericOp"),value:e("value"),Abs:e("Abs"),Negate:e("Negate"),KindPredicate:e("KindPredicate"),IsReference:e("IsReference"),IsEmbedded:e("IsEmbedded"),IsList:e("IsList"),kindCheck:e("kindCheck"),IsString:e("IsString"),IsNumber:e("IsNumber"),IsBoolean:e("IsBoolean"),StatementObject:e("StatementObject"),statementSource:e("statementSource"),Let:e("Let"),letName:e("letName"),letValue:e("letValue"),letBody:e("letBody"),GetStatementByName:e("GetStatementByName"),inSubject:e("inSubject"),byName:e("byName"),RenderMarkdown:e("RenderMarkdown"),renderSource:e("renderSource"),renderProp:e("renderProp"),renderFormat:e("renderFormat"),RenderFormat:e("RenderFormat"),RENDER_HTML:e("render-html"),RENDER_MARKDOWN:e("render-markdown")};import{Carrier as h,carrierOf as ae}from"@kanonak-protocol/canonical";function N(m){return ae(`${m.publisher}/${m.package_}/${m.name}`)}var oe=/\[\[([^\[\]\n]+)\]\]/g,se=/\[\[/g,Y=/```[\s\S]*?```|`[^`\n]*`/g;function ie(m){let t=[];for(let n of m.matchAll(Y))t.push([n.index,n.index+n[0].length]);return t}function Se(m){if(!m||!m.includes("[["))return[];let t=ie(m),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(x(m).map(s=>s.startOffset)),a=[];for(let s of m.matchAll(se)){let o=s.index;if(n(o)||r.has(o))continue;let c=m.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function x(m){if(!m||!m.includes("[["))return[];let t=[];for(let a of m.matchAll(Y))t.push([a.index,a.index+a[0].length]);let n=a=>t.some(([s,o])=>a>=s&&a<o),r=[];for(let a of m.matchAll(oe)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),p=(c===-1?o:o.slice(0,c)).trim();if(p.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),l={reference:p,startOffset:s,endOffset:s+a[0].length};i.length>0&&(l.displayText=i),r.push(l)}return r}function Z(m,t){for(let n of m)n instanceof S&&_(n,n.name,t)}function _(m,t,n){n({kanonak:m,path:t});for(let r of m.statement)if(r instanceof w)_(r.object,Q(t,r.object),n);else if(r instanceof K)for(let a of r.object)a instanceof b&&_(a,Q(t,a),n)}function Q(m,t){let n=t instanceof b&&t.name?t.name:"<embedded>";return`${m}/${n}`}var ee=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new W(t),s=new G(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let p of n){let i=p.metadata.namespace_?.toString();i&&a.set(i,p)}let s=[],o=new Set;Z(t,({kanonak:p})=>{for(let i of p.unresolvedPredicates){let l=`${i.sourceDoc}::${i.key}`;o.has(l)||(o.add(l),s.push(i))}});let c=!1;for(let p of s){let i=a.get(p.sourceDoc);if(!i)continue;let l=await r.resolveEntityAsync(p.key,i);if(!l)continue;let u=E(l.uri);if(this.knownPropertyClasses.has(u))continue;let f=H(t,l.uri);if(!f)continue;let d=J(t,f);d&&(this.knownPropertyClasses.set(u,d),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[p,i]of Object.entries(o.body)){let l=new S,u=this.resolveCanonicalEntity(p,o,c);l.namespace=u.namespace,l.name=u.name,l.statement=[];let f=await this.parseStatements(i,o,n,r,a);l.statement.push(...f.statements),l.unresolvedPredicates=f.unresolved,B(l,c),s.push(l)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof S){let l=`${i.namespace}/${i.name}`,u=r.get(l);if(u){let f=a.get(l);for(let d of i.statement){let y=C(d);f.has(y)||(f.add(y),u.statement.push(d))}for(let d of i.unresolvedPredicates)u.unresolvedPredicates.some(y=>y.key===d.key&&y.sourceDoc===d.sourceDoc)||u.unresolvedPredicates.push(d)}else{let f=new S;f.namespace=i.namespace,f.name=i.name,f.sourceDoc=i.sourceDoc;let d=new Set;for(let y of i.statement){let k=C(y);d.has(k)||(d.add(k),f.statement.push(y))}f.unresolvedPredicates=[...i.unresolvedPredicates],a.set(l,d),r.set(l,f),s.push(f)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof S){let l=i.namespace||"",u=l.indexOf("/"),f=u>=0?l.slice(0,u):"",d=u>=0?l.slice(u+1):"",y=d.indexOf("@"),k=y>=0?d.slice(0,y):d;o.add(`${f}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),p=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let l=await n.getDocumentsByNamespaceAsync("kanonak.org",i);p.set(i,U(l).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof S&&this.canonicalizeStatementBuiltins(i.statement,c,p);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(T(s,n,r),a instanceof j)a.object instanceof g&&T(a.object.subject,n,r);else if(a instanceof w)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof K)for(let o of a.object??[])o instanceof g?T(o.subject,n,r):o instanceof b&&this.canonicalizeStatementBuiltins(o.statement,n,r)}}resolveCanonicalEntity(t,n,r){if(!t.includes(".")||!n.metadata?.imports)return{namespace:r,name:t};let a=t.indexOf("."),s=t.substring(0,a),o=t.substring(a+1);for(let[c,p]of Object.entries(n.metadata.imports))for(let i of p)if((i.alias??i.packageName)===s){let u=i.version;return{namespace:`${c}/${i.packageName}@${u.major}.${u.minor}.${u.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let p=n.metadata.namespace_?.toString()??"";for(let[i,l]of Object.entries(t))try{let u=await this.getPropertyMetadata(i,n,r,s,a);if(!u){let d=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;X(d)||c.push({key:i,sourceDoc:p});continue}let f=await this.parsePropertyValue(i,l,u,n,r,a,s);f&&o.push(f)}catch(u){throw new Error(`Failed to parse property '${i}': ${u.message}`,{cause:u})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,p=c.type?.toString()??"",i=p.includes(".")?p.substring(p.lastIndexOf(".")+1):p,l=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),u=this.knownPropertyClasses.get(E(o.uri));if(!l.has(i)&&!u)return;let f=u??s.getPropertyTypeClassification(p),d=c.range?.toString(),y;if(f==="ObjectProperty")y="ObjectProperty";else if(f==="DatatypeProperty")y="DatatypeProperty";else{let O=d&&d.includes(".")?d.substring(d.lastIndexOf(".")+1):d??"";(d?s.isKnownXsdDatatypeName(d):!1)||O==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let k;if(d){let O=n;if(o.isImported&&o.definedInNamespace){if(typeof a.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${t}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let A=await a.getDocumentAsync(o.definedInNamespace);if(!A)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);O=A}k=(await r.resolveEntityAsync(d,O))?.uri}return{propertyUri:o.uri.toString(),propertyType:y,range:d,rangeUri:k,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async parsePropertyValue(t,n,r,a,s,o,c){let p=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(p,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(p,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(p,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?N(r.rangeUri):void 0;if(s===h.Boolean){let c=new L;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===h.Integer||s===h.Decimal||s===h.Double||s===h.Float){let c=new I;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=P.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new R,a=n.rangeUri?N(n.rangeUri):void 0;return a===h.Boolean?r.value=t==="true"||t==="1":a===h.Integer||a===h.Decimal||a===h.Double||a===h.Float?r.value=Number(t):r.value=t,a&&(r.carrier=a,r.lexical=t),r}async parseSubstitutableValue(t,n,r,a){let s=new v;s.predicate=g.parse(t),s.object=n;for(let o of x(n)){let c=await a.resolveEntityAsync(o.reference,r),p;c&&(p=new g,p.subject=c.uri);let i={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(i.displayText=o.displayText),p!==void 0&&(i.target=p),s.links.push(i)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&q(r.rangeUri,M.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let p=await this.resolveReference(n,a,s);if(!p)return;let i=new j;return i.predicate=g.parse(t),i.object=p,i}if(typeof n=="object"&&!Array.isArray(n)){let p=await this.parseStatements(n,a,s,o,c);if(p.statements.length>0){let u=new b;u.statement=p.statements,u.unresolvedPredicates=p.unresolved;let f=new w;return f.predicate=g.parse(t),f.object=u,f}let i=[];for(let[u,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=new b;d.name=u;let y=await this.parseStatements(f,a,s,o,c);d.statement=y.statements,d.unresolvedPredicates=y.unresolved,i.push(d)}else if(typeof f=="string"){let d=await this.resolveReference(f,a,s);d&&i.push(d)}if(i.length>0){let u=new K;return u.predicate=g.parse(t),u.object=i,u}let l=new w;return l.predicate=g.parse(t),l.object=new b,l}}coerceExpressionLiteral(t,n,r){let a=new b,s=new j,o=new g;o.subject=new D("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new D(r.publisher,r.package_,M.StringLiteral.name,r.version),s.object=c;let p=new P,i=new g;i.subject=new D(r.publisher,r.package_,M.stringLiteral.name,r.version),p.predicate=i,p.object=n,a.statement=[s,p];let l=new w;return l.predicate=g.parse(t),l.object=a,l}async parseListValue(t,n,r,a,s,o,c){let p=[],i=r.propertyType==="DatatypeProperty",l=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let f of n){let d=typeof f=="string"||typeof f=="number"||typeof f=="boolean";if(i&&d){let y=typeof f=="string"?f:String(f);p.push(this.typedListLiteral(y,r));continue}if(l&&d){if(typeof f=="string"){let y=await s.resolveEntityAsync(f,a);if(y){let k=new g;k.subject=y.uri,p.push(k)}else{let k=new R;k.value=f,p.push(k)}}else{let y=new R;y.value=f,p.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&p.push(y)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let y=new b,k=await this.parseStatements(f,a,s,o,c);y.statement=k.statements,y.unresolvedPredicates=k.unresolved,p.push(y)}}let u=new K;return u.predicate=g.parse(t),u.object=p,u}async resolveReference(t,n,r){let a=await r.resolveEntityAsync(t,n);if(a){let o=new g;return o.subject=a.uri,o}let s=n.metadata?.namespace_;if(s){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let p=t.indexOf("."),i=t.substring(0,p),l=t.substring(p+1);if(n.metadata?.imports){for(let[u,f]of Object.entries(n.metadata.imports))for(let d of f)if((d.alias??d.packageName)===i){let k=new g;return k.subject=new o(u,d.packageName,l,d.version),k}}}let c=new g;return c.subject=new o(s.publisher,s.package_,t,s.version??void 0),c}return null}async saveKanonaks(t,n){let r=new Map;for(let a of t)a instanceof S&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,s]of r){let o=await this.convertKanonaksToDocument(a,s),c=`${a.split("@")[0]}.yml`;await n.saveDocumentAsync(o,c)}}async serializeToYaml(t,n){let r=t.filter(o=>o instanceof S&&o.namespace===n);if(r.length===0)throw new Error(`No kanonaks found with namespace '${n}'`);let a=await this.convertKanonaksToDocument(n,r);return new F().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let p of o.statement){let[i,l]=this.convertStatementToProperty(p);i&&l!==null&&l!==void 0&&(c[i]=l),this.collectImportsFromStatement(p,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof P)return[t.predicate.subject.name,t.object];if(t instanceof I)return[t.predicate.subject.name,t.object];if(t instanceof L)return[t.predicate.subject.name,t.object];if(t instanceof j)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof K){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof w){let n=this.convertEmbeddedKanonakToValue(t.object);return[t.predicate.subject.name,n]}return[null,null]}convertKanonakListToValue(t){let n=[];for(let r of t)r instanceof g?n.push(r.subject.name):r instanceof b&&n.push(this.convertEmbeddedKanonakToValue(r));return n}convertEmbeddedKanonakToValue(t){let n={};for(let r of t.statement){let[a,s]=this.convertStatementToProperty(r);a&&s!==null&&s!==void 0&&(n[a]=s)}return n}collectImportsFromStatement(t,n,r){}};function B(m,t){m.sourceDoc=t;for(let n of m.statement)if(n instanceof w)B(n.object,t);else if(n instanceof K)for(let r of n.object)r instanceof b&&B(r,t)}function C(m){let t=m.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+ce(m)}function ce(m){return m instanceof v?"m:"+String(m.object):m instanceof P?"s:"+String(m.object):m instanceof I?"n:"+String(m.object):m instanceof L?"b:"+String(m.object):m instanceof j?"r:"+V(m.object):m instanceof w?"e:"+V(m.object):m instanceof K?"l:["+(m.object??[]).map(V).join("|")+"]":"x"}function V(m){if(!m)return"";if(m instanceof g){let t=m.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return m instanceof b?"E("+(m.statement??[]).map(C).join(";")+")":m instanceof R?"L("+String(m.value)+")":"N"}export{b as a,R as b,v as c,Z as d,ne as e,re as f,ge as g,M as h,h as i,N as j,Se as k,x as l,ee as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as D}from"./chunk-FUUTGGJS.js";import{c as h,g as S}from"./chunk-2ACBWC7K.js";var c=class{};var m=class extends c{statement=[];unresolvedPredicates=[];sourceDoc=""};var p=class extends m{namespace;name;icon};var a=class{predicate;object};var i=class extends a{carrier;lexical};var s=class n extends c{subject;static parse(e){let t=new n;return t.subject=D.parse(e),t}};var l=class n extends i{static parse(e,t){let r=new n;return r.predicate=s.parse(e),r.object=t,r}};var y=class n extends i{static parse(e,t){let r=new n;return r.predicate=s.parse(e),r.object=t,r}};var k=class extends i{};var f=class n extends a{static parse(e,t){let r=new n;return r.predicate=s.parse(e),r.object=s.parse(t),r}};var g=class extends a{};var b=class extends a{};function E(n){return`${n.publisher}/${n.package_}/${n.name}`}function x(n,e){return n.publisher===e.publisher&&n.package_===e.package_&&n.name===e.name}function $(n){let e=n.version;return e&&typeof e.major=="number"?`https://${n.publisher}/${n.package_}/${e.major}.${e.minor}.${e.patch}/${n.name}`:`https://${n.publisher}/${n.package_}/${n.name}`}function U(n,e){if(!(n instanceof m))return!1;for(let t of n.statement)if(t.predicate?.subject?.name==="type"&&t instanceof f){let o=t.object;if(x(o.subject,e))return!0}return!1}function A(n,e){let t=[];for(let r of n)r instanceof p&&U(r,e)&&t.push(r);return t}function P(n,e){let t=e.version,r=t&&typeof t.major=="number"?`${e.publisher}/${e.package_}@${t.major}.${t.minor}.${t.patch}`:void 0;for(let o of n){if(!(o instanceof p)||o.name!==e.name)continue;let u=o.namespace||"";if(r!==void 0){if(u===r)return o}else if(u.startsWith(`${e.publisher}/${e.package_}@`))return o}}function v(n,e){let t=[];for(let r of n){if(!(r instanceof p)||r.name!==e.name)continue;(r.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&t.push(r)}return t.sort((r,o)=>{let u=S((r.namespace||"").split("@")[1]??""),K=S((o.namespace||"").split("@")[1]??"");return u?K?h(K,u):-1:K?1:0}),t}function d(n,e){for(let t of n.statement){let r=t.predicate;if(r?.subject&&x(r.subject,e))return t}}function I(n,e){return d(n,e)!==void 0}function R(n,e){let t=d(n,e);if(t&&(t instanceof l||t instanceof y||t instanceof k))return t.object}function V(n,e){let t=R(n,e);return typeof t=="string"?t:void 0}function w(n,e){let t=d(n,e);if(t instanceof f)return t.object.subject}function C(n,e){let t=d(n,e);if(t instanceof g)return t.object}function B(n,e){let t=d(n,e);return t instanceof b?t.object??[]:[]}var j=class{constructor(e,t){this.doc=e;this.broader=t}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(e){return this.broader.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){return this.broader.getDocumentsByNamespaceAsync(e,t)}async getHighestCompatibleVersionAsync(e,t){return this.broader.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}async getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}};export{c as a,m as b,p as c,s as d,a as e,i as f,l as g,y as h,k as i,f as j,g as k,b as l,E as m,x as n,$ as o,U as p,A as q,P as r,v as s,I as t,R as u,V as v,w,C as x,B as y,j as z};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as br,b as Rr,c as wr,d as Er,e as N}from"./chunk-TVSHIXLA.js";import{a as Y,b as ee,c as re}from"./chunk-L2KE7B3K.js";import{a as bn,c as B,e as ne,h as te,i as oe,j as Rn}from"./chunk-IHB7UVEH.js";import{a as gr,b as hr,c as Pr,d as mn,e as yn,f as fn,g as kn,h as gn,i as hn,j as wn,k as F,l as En,m as xn}from"./chunk-4SQZBFJJ.js";import{a as Pn}from"./chunk-EZSHR3CB.js";import"./chunk-QHABFCRC.js";import{a as Ve,b as je,c as Ae,d as Ce,e as Se,f as Te,g as ze,h as He,i as We}from"./chunk-CC44JAOT.js";import{a as De,b as Ue,c as Oe,d as _e,e as Me,f as $e,h as Ne,j as Le,k as Fe}from"./chunk-UXYCUGSF.js";import{a as ve}from"./chunk-4NO7MHS7.js";import{a as Kr,b as Ir,c as vr,d as Vr}from"./chunk-S6VSAKXB.js";import{a as jr,b as _r}from"./chunk-PEUTCG3B.js";import{a as Cr}from"./chunk-PEJALHXK.js";import{a as Be}from"./chunk-SC5M74NM.js";import{A as un,B as ln,K as dn,a as Mr,b as $r,c as Nr,d as Lr,e as Br,f as Fr,g as Tr,h as zr,i as Hr,j as Wr,k as qr,l as Gr,m as Jr,n as Zr,o as Qr,p as Xr,q as Yr,r as en,s as rn,t as nn,u as tn,v as on,w as an,x as sn,y as cn,z as pn}from"./chunk-7K5TAJ44.js";import"./chunk-ITKOKDBG.js";import{a as k,b as Ze,c as ar,h as cr,i as pr,j as yr,k as fr,l as E}from"./chunk-MX3DEXMV.js";import{a as P}from"./chunk-NJ3AZYQD.js";import{a as kr,b as L,c as Ar,d as m,e as Sr,f as Dr,g as Ur,h as Or}from"./chunk-ZP6P7HNU.js";import{a as X}from"./chunk-6U26UASC.js";import{a as ir,b as sr,c as w,d as ur,e as lr,g as dr,k as mr}from"./chunk-GZPLWII7.js";import{a as qe,b as Ge,c as f,d as b,e as Qe,f as Xe,g as Ye,h as er,i as rr,j as nr,k as tr,l as or,r as j,w as R,x as M,y as $}from"./chunk-7BHDZHJY.js";import{a as Je}from"./chunk-FUUTGGJS.js";import{a as be,b as _,c as V,d as Re,e as y,f as we,g as Ee,h as xe,i as Ke,j as Ie}from"./chunk-2ACBWC7K.js";import{a as xr}from"./chunk-ODIECDN7.js";import{VersionOperator as _t}from"@kanonak-protocol/types/document/models/enums";import*as T from"js-yaml";import{VersionOperator as ae}from"@kanonak-protocol/types/document/models/enums";var Kn="0.0.0",g=class{constructor(e,r=new P,n){this.repository=e;this.parser=r;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new x}serializeValue(e,r){return ce(e,r)}async buildContentAddressed(e){let r=e.book.toImports(),n=await this.hashBody(e.publisher,r,e.body),t=z(n),a={type:"EphemeralPackage",publisher:e.publisher,imports:r};e.contentHashProperty&&(a[e.contentHashProperty]=n),Object.assign(a,e.header??{}),a.imports=r;let i={[t]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:se(s),contentHash:n,packageName:t,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let r=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:r},t;e.contentHashProperty&&(t=await this.hashBody(e.publisher,r,e.body),n[e.contentHashProperty]=t),Object.assign(n,e.header??{}),n.imports=r;let a={[e.name]:n,...e.body},i=this.dump(a),s={yaml:i,byteCount:se(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return t!==void 0&&(s.contentHash=t),s}dump(e){return T.dump(e,{lineWidth:-1})}async hashBody(e,r,n){let t={[ie]:{type:"EphemeralPackage",publisher:e,imports:r},...n},a=this.parser.parse(T.dump(t,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new X(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==ie);for(let u of c)u.namespace="ephemeral";return F(c)}},ie="__pkgbuilder_probe__";function se(o){return new TextEncoder().encode(o).length}function z(o){let e="sha256:",r=o.startsWith(e)?e.length:0;return`q-${o.slice(r,r+16)}`}var x=class{byKey=new Map;aliases=new Set;ensure(e,r,n,t,a=ae.Major){let i=`${e}/${r}@${n}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(t);return this.byKey.set(i,{publisher:e,package_:r,version:n,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,y(e.version),e.package_)}.${e.name}`}refLatest(e,r,n,t){return`${this.ensure(e,r,Kn,t??r,ae.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let t=e.get(n.publisher)??[];t.push(n),e.set(n.publisher,t)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((t,a)=>t.package_<a.package_?-1:1).map(t=>({package:t.package_,match:_(t.match),version:t.version,alias:t.alias}))}))}uniqueAlias(e){let r=K(e)||"pkg",n=r,t=2;for(;this.aliases.has(n);)n=`${r}${t++}`;return this.aliases.add(n),n}};function ce(o,e){if(o!=null){if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o;if(o instanceof b)return e.ref(o.subject);if(Array.isArray(o)){let r=o.map(n=>ce(n,e)).filter(n=>n!==void 0);return r.length>0?r:void 0}if(o instanceof k)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(In(o))throw new Error(`Value produced a bare URI without a version (${o.publisher}/${o.package_}/${o.name}); cannot serialize it as a reference.`)}}function K(o){return o.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function In(o){return typeof o=="object"&&o!==null&&typeof o.publisher=="string"&&typeof o.package_=="string"&&typeof o.name=="string"}var A=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,r){return this.producers.find(n=>n.canProduce(e,r))}async produceCached(e,r,n,t){let a=`${r}/${n}@${y(t)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(r,n,t);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,r){let n=this.producerFor(e,r.packageName);if(!n)return null;let t={operator:r.versionOperator,version:r.version},a=await n.resolveVersion(e,r.packageName,t);return a?this.produceCached(n,e,r.packageName,a):null}async getDocumentAsync(e){let r;try{r=L(e)}catch{return null}if(r.kind!=="package"||!r.version)return null;let n=this.producerFor(r.publisher,r.package_);return n?this.produceCached(n,r.publisher,r.package_,r.version):null}async getDocumentsByNamespaceAsync(e,r){return Array.from(this.produced.values()).filter(n=>{let t=n.metadata.namespace_;return t!=null&&t.publisher===e&&t.package_===r})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var H={async authorize(){return{allowed:!0}}},W={async record(){}},I=class extends Error{constructor(r,n){let t=`${r.publisher}/${r.package_}${r.version?`@${r.version.major}.${r.version.minor}.${r.version.patch}`:""}`;super(`Not entitled to produce ${t}${n?`: ${n}`:""}`);this.address=r;this.reason=n;this.name="EntitlementDeniedError"}address;reason},C=class{inner;ctx;policy;meter;constructor(e,r,n=H,t=W){this.inner=e,this.ctx=r,this.policy=n,this.meter=t}canProduce(e,r){return this.inner.canProduce(e,r)}async resolveVersion(e,r,n){return await this.assertAllowed({publisher:e,package_:r,version:n.version}),this.inner.resolveVersion(e,r,n)}async produce(e,r,n){let t={publisher:e,package_:r,version:n};await this.assertAllowed(t);let a=await this.inner.produce(e,r,n);return await this.meter.record(this.ctx,t,a),a}async assertAllowed(e){let r=await this.policy.authorize(this.ctx,e);if(!r.allowed)throw new I(e,r.reason)}};var p="kanonak.org",d="view",pe="core-kanonak",vn={publisher:p,package_:d,name:"rootView"},Vn={publisher:p,package_:d,name:"bind"},jn={publisher:p,package_:d,name:"produces"},An={publisher:p,package_:d,name:"projections"},Cn={publisher:p,package_:d,name:"where"},Sn={publisher:p,package_:d,name:"value"},Dn={publisher:p,package_:d,name:"as"},S=class{constructor(e,r=new P){this.repository=e;this.parser=r;this.objectParser=new E(this.parser),this.builder=new g(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,r={}){let n=await this.objectParser.parseKanonaks(this.repository),t=this.resolveView(n,e),a=R(t,Vn);if(!a)throw new Error(`View ${t.namespace}/${t.name} declares no view.bind; cannot materialize.`);let i=R(t,jn);if(!i)throw new Error(`View ${t.namespace}/${t.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let s=Un(t),c=ue(n,p,pe),u=ue(n,p,d),l=this.builder.imports(),D=l.ensure(p,pe,c,"ck"),de=l.ensure(p,d,u,"v"),me=l.ref(i),ye=new oe(this.repository,this.parser,this.objectParser),q=new ne(ye,n),fe=this.readProjections(n,t),ke=Mn(t,Cn),ge=this.findInstances(n,a,await this.reason(r)),G={},he=new Set;for(let v of ge){if(!await this.passesWhere(q,n,ke,v))continue;let O={type:me};for(let Z of fe){let Pe=await this.evaluateValue(q,n,Z.value,v),Q=this.builder.serializeValue(le(Pe),l);Q!==void 0&&(O[l.ref(Z.as)]=Q)}let J=m(v);J&&(O[`${de}.derivedFrom`]=l.ref(J)),G[this.rowName(v,he)]=O}let U={};r.resolvedAt&&(U[`${D}.resolvedAt`]=r.resolvedAt),r.invocationId&&(U[`${D}.id`]=r.invocationId);let h=await this.builder.buildContentAddressed({publisher:s,book:l,body:G,contentHashProperty:`${D}.contentHash`,header:U});return{yaml:h.yaml,contentHash:h.contentHash,packageName:h.packageName,publisher:h.publisher,rowCount:h.resourceCount}}resolveView(e,r){let n=j(e,r);if(!n)throw new Error(`View ${r.publisher}/${r.package_}/${r.name} not found in the catalog.`);let t=R(n,vn);if(t){let a=j(e,t);if(!a)throw new Error(`ViewPackage ${r.name} names rootView ${t.name}, which is not in the catalog.`);return a}return n}readProjections(e,r){let n=[];for(let t of $(r,An)){let a=t instanceof k?t:t instanceof b?j(e,t.subject):void 0;if(!a)continue;let i=M(a,Sn),s=R(a,Dn);i&&s&&n.push({value:i,as:s})}return n}async reason(e){return new N({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,r,n){let t=_n(e),a=[],i=new Set;for(let s of n.getInstancesOfClass(r)){if(i.has(s))continue;i.add(s);let c=t.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=w(m(s)),l=w(m(c));return u<l?-1:u>l?1:0}),a}async passesWhere(e,r,n,t){for(let a of n){let i=await this.evaluateValue(e,r,a,t);if(!$n(i))return!1}return!0}async evaluateValue(e,r,n,t){let a=te(n,"view-projection",{catalog:r,depth:0}),i=new Map([["input",t]]);return e.evaluate(a,i)}rowName(e,r){let n=K(e.name)||"row",t=n,a=2;for(;r.has(t);)t=`${n}-${a++}`;return r.add(t),t}};function le(o){return B(o)?o.value:Array.isArray(o)?o.map(le):o}function Un(o){let e=m(o);if(!e)throw new Error(`Could not derive a publisher from view ${o.namespace}/${o.name}.`);return e.publisher}function ue(o,e,r){let n=On(o,e,r);if(!n)throw new Error(`Package ${e}/${r} is not in the catalog; it must be importable to materialize a view.`);return n}function On(o,e,r){let n;for(let t of o){if(!(t instanceof f))continue;let a=m(t);!a||a.publisher!==e||a.package_!==r||!a.version||(!n||V(a.version,n)>0)&&(n=a.version)}return n?y(n):void 0}function _n(o){let e=new Map,r=new Map;for(let n of o){if(!(n instanceof f))continue;let t=m(n);if(!t||!t.version)continue;let a=w(t),i=r.get(a);(!i||V(t.version,i)>0)&&(r.set(a,t.version),e.set(a,n))}return e}function Mn(o,e){let r=M(o,e);return r?[r]:$(o,e).filter(n=>n instanceof k)}function $n(o){return o===!0?!0:o===!1||o===void 0||o===null?!1:typeof o=="string"?o.length>0:typeof o=="number"?o!==0:B(o)?o.value.length>0:Array.isArray(o)?o.length>0:!!o}export{tn as AmbiguousReferenceRule,rr as BooleanStatement,En as CANONICAL_FORM_VERSION,cr as Carrier,un as ClassDefinitionRule,Zr as ClassHierarchyCycleRule,Ae as CompositeKanonakDocumentRepository,yn as DEFAULT_CONSENT_BINDING_PARAM,Ge as DefinedKanonak,je as DocumentLocation,hr as EdgeType,k as EmbeddedKanonak,qr as EmbeddedKanonakTypeRule,tr as EmbeddedStatement,I as EntitlementDeniedError,C as EntitlementProducer,Ve as FileSystemKanonakDocumentRepository,xr as GitIgnoreFilter,Pr as GraphBuilder,Fe as HttpKanonakDocumentRepository,x as ImportBook,Gr as ImportExistenceRule,ve as InMemoryKanonakDocumentRepository,De as KANONAK_USER_AGENT,qe as Kanonak,Ir as KanonakDocumentPositions,E as KanonakObjectParser,dn as KanonakObjectValidator,P as KanonakParser,Je as KanonakUri,jr as KanonakUriBuilder,Cr as KanonakUrlResolver,mr as KanonakVocabulary,or as ListStatement,Ze as LiteralKanonak,Te as LocalFirstRepository,ze as LockAwareRepository,Rn as LookRenderer,ln as MarkdownLinkRule,ar as MarkdownStatement,rn as NamespaceImportCycleRule,Fr as NamespacePrefixRule,gr as NodeType,er as NumberStatement,fn as OAuthDiscovery,wr as OWL_RL_CLASSIFICATION_RULES,an as ObjectPropertyValueValidationRule,Nr as OntologyValidationError,Mr as OntologyValidationResult,g as PackageBuilder,Wr as PackageHeaderRule,A as ProducerRepository,sn as PropertyDomainRule,Qr as PropertyHierarchyCycleRule,cn as PropertyKindRangeConsistencyRule,Kr as PropertyMetadata,on as PropertyRangeReferenceRule,Xr as PropertyRangeRequiredRule,zr as PropertyTypeSpecificityRule,Ne as PublisherConfigResolver,Le as PublisherIndex,Rr as RDFS_RULES,N as Reasoner,Er as ReasoningResult,b as ReferenceKanonak,nr as ReferenceStatement,Se as RepositoryFactory,pn as ReservedNameShadowRule,Tr as ResourceNamingRule,ir as ResourceResolver,kr as ResourceTypeClassifier,Xe as ScalarStatement,Qe as Statement,Ye as StringStatement,Yr as SubClassOfReferenceRule,en as SubPropertyOfReferenceRule,f as SubjectKanonak,Hr as SubjectKanonakTypeRequiredRule,hn as TokenCredentialProvider,br as TripleStore,sr as TypeResolver,nn as UnresolvedPredicateRule,Jr as UnresolvedReferenceRule,Br as ValidationCache,Lr as ValidationContext,$r as ValidationSeverity,_t as VersionOperator,S as ViewMaterializer,H as allowAllPolicy,_e as assertHttpsUrl,Be as assertPackageIdentity,We as buildLocalFirstRepository,xn as buildOntologyModel,wn as canonicalForm,F as canonicalHash,pr as carrierOf,He as collectKanonakFiles,V as compareVersions,re as computeIntegrity,z as contentAddressedName,Or as contextTypesOf,gn as createCredentialedFetch,we as createVersion,fr as extractMarkdownLinks,Pn as findDerivation,_r as findInstancesByType,yr as findMalformedReferences,Vr as findMarkdownLinkAt,Ar as formatKanonakAddress,y as formatVersion,Ce as getGlobalCachePath,Oe as getKanonakUserAgent,xe as isCompatibleVersion,Ke as isMajorCompatible,Me as kanonakFetch,Y as loadLockFile,ur as makeUriKey,W as noopMeter,mn as normalizeHost,kn as parseAuthChallenge,L as parseKanonakAddress,Ee as parseVersionString,vr as parseWithPositions,Ie as pickHighestDocument,Dr as propertiesInScope,bn as resolveDisplayValue,Ur as resolvePropertyStep,K as sanitizeName,ee as saveLockFile,$e as setKanonakFetchRetries,Ue as setKanonakUserAgent,m as subjectUri,Sr as superClassChain,lr as tripleKey,w as uriKey,dr as uriTriple,be as versionOperatorFromChar,_ as versionOperatorToChar,Re as versionsEqual};
|
|
1
|
+
import{a as Kr,b as Ir,c as vr,d as Vr,e as L}from"./chunk-V3IPBWWU.js";import{a as Y,b as ee,c as re}from"./chunk-L2KE7B3K.js";import{a as bn,c as B,e as ne,h as te,i as oe,j as Rn}from"./chunk-4PY3JJH3.js";import{a as wr,b as Er,c as xr,d as mn,e as yn,f as fn,g as kn,h as gn,i as hn,j as wn,k as F,l as En,m as xn}from"./chunk-MK6UVFOJ.js";import{a as Pn}from"./chunk-LYSCTQC2.js";import"./chunk-QHABFCRC.js";import{a as Ve,b as je,c as Ae,d as Ce,e as Se,f as Te,g as ze,h as He,i as We}from"./chunk-CC44JAOT.js";import{a as De,b as Ue,c as Oe,d as _e,e as Me,f as $e,h as Ne,j as Le,k as Fe}from"./chunk-UXYCUGSF.js";import{a as ve}from"./chunk-4NO7MHS7.js";import{a as Ar,b as Cr,c as Sr,d as Dr}from"./chunk-5NH5XDGO.js";import{a as Ur,b as _r}from"./chunk-PEUTCG3B.js";import{a as Or}from"./chunk-PEJALHXK.js";import{a as Be}from"./chunk-SC5M74NM.js";import{A as un,B as ln,K as dn,a as Mr,b as $r,c as Nr,d as Lr,e as Br,f as Fr,g as Tr,h as zr,i as Hr,j as Wr,k as qr,l as Gr,m as Jr,n as Zr,o as Qr,p as Xr,q as Yr,r as en,s as rn,t as nn,u as tn,v as on,w as an,x as sn,y as cn,z as pn}from"./chunk-Q6XQ5IXW.js";import"./chunk-ITKOKDBG.js";import{a as k,b as Ze,c as ar,i as hr,j as Pr,k as br,l as Rr,m as E}from"./chunk-V6KIDED2.js";import{a as P}from"./chunk-NJ3AZYQD.js";import{a as ir,b as sr,c as M,d as cr,e as R,f as pr,g as ur,i as lr,m as dr,o as mr,p as m,q as yr,v as fr,w as kr,x as gr}from"./chunk-SVUMCLK5.js";import{a as qe,b as Ge,c as f,d as b,e as Qe,f as Xe,g as Ye,h as er,i as rr,j as nr,k as tr,l as or,r as j,w,x as $,y as N,z as X}from"./chunk-YW6P24RF.js";import{a as Je}from"./chunk-FUUTGGJS.js";import{a as be,b as _,c as V,d as Re,e as y,f as we,g as Ee,h as xe,i as Ke,j as Ie}from"./chunk-2ACBWC7K.js";import{a as jr}from"./chunk-ODIECDN7.js";import{VersionOperator as _t}from"@kanonak-protocol/types/document/models/enums";import*as T from"js-yaml";import{VersionOperator as ae}from"@kanonak-protocol/types/document/models/enums";var Kn="0.0.0",g=class{constructor(e,r=new P,n){this.repository=e;this.parser=r;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new x}serializeValue(e,r){return ce(e,r)}async buildContentAddressed(e){let r=e.book.toImports(),n=await this.hashBody(e.publisher,r,e.body),t=z(n),a={type:"EphemeralPackage",publisher:e.publisher,imports:r};e.contentHashProperty&&(a[e.contentHashProperty]=n),Object.assign(a,e.header??{}),a.imports=r;let i={[t]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:se(s),contentHash:n,packageName:t,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let r=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:r},t;e.contentHashProperty&&(t=await this.hashBody(e.publisher,r,e.body),n[e.contentHashProperty]=t),Object.assign(n,e.header??{}),n.imports=r;let a={[e.name]:n,...e.body},i=this.dump(a),s={yaml:i,byteCount:se(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return t!==void 0&&(s.contentHash=t),s}dump(e){return T.dump(e,{lineWidth:-1})}async hashBody(e,r,n){let t={[ie]:{type:"EphemeralPackage",publisher:e,imports:r},...n},a=this.parser.parse(T.dump(t,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new X(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==ie);for(let u of c)u.namespace="ephemeral";return F(c)}},ie="__pkgbuilder_probe__";function se(o){return new TextEncoder().encode(o).length}function z(o){let e="sha256:",r=o.startsWith(e)?e.length:0;return`q-${o.slice(r,r+16)}`}var x=class{byKey=new Map;aliases=new Set;ensure(e,r,n,t,a=ae.Major){let i=`${e}/${r}@${n}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(t);return this.byKey.set(i,{publisher:e,package_:r,version:n,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,y(e.version),e.package_)}.${e.name}`}refLatest(e,r,n,t){return`${this.ensure(e,r,Kn,t??r,ae.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let t=e.get(n.publisher)??[];t.push(n),e.set(n.publisher,t)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((t,a)=>t.package_<a.package_?-1:1).map(t=>({package:t.package_,match:_(t.match),version:t.version,alias:t.alias}))}))}uniqueAlias(e){let r=K(e)||"pkg",n=r,t=2;for(;this.aliases.has(n);)n=`${r}${t++}`;return this.aliases.add(n),n}};function ce(o,e){if(o!=null){if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o;if(o instanceof b)return e.ref(o.subject);if(Array.isArray(o)){let r=o.map(n=>ce(n,e)).filter(n=>n!==void 0);return r.length>0?r:void 0}if(o instanceof k)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(In(o))throw new Error(`Value produced a bare URI without a version (${o.publisher}/${o.package_}/${o.name}); cannot serialize it as a reference.`)}}function K(o){return o.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function In(o){return typeof o=="object"&&o!==null&&typeof o.publisher=="string"&&typeof o.package_=="string"&&typeof o.name=="string"}var A=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,r){return this.producers.find(n=>n.canProduce(e,r))}async produceCached(e,r,n,t){let a=`${r}/${n}@${y(t)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(r,n,t);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,r){let n=this.producerFor(e,r.packageName);if(!n)return null;let t={operator:r.versionOperator,version:r.version},a=await n.resolveVersion(e,r.packageName,t);return a?this.produceCached(n,e,r.packageName,a):null}async getDocumentAsync(e){let r;try{r=M(e)}catch{return null}if(r.kind!=="package"||!r.version)return null;let n=this.producerFor(r.publisher,r.package_);return n?this.produceCached(n,r.publisher,r.package_,r.version):null}async getDocumentsByNamespaceAsync(e,r){return Array.from(this.produced.values()).filter(n=>{let t=n.metadata.namespace_;return t!=null&&t.publisher===e&&t.package_===r})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var H={async authorize(){return{allowed:!0}}},W={async record(){}},I=class extends Error{constructor(r,n){let t=`${r.publisher}/${r.package_}${r.version?`@${r.version.major}.${r.version.minor}.${r.version.patch}`:""}`;super(`Not entitled to produce ${t}${n?`: ${n}`:""}`);this.address=r;this.reason=n;this.name="EntitlementDeniedError"}address;reason},C=class{inner;ctx;policy;meter;constructor(e,r,n=H,t=W){this.inner=e,this.ctx=r,this.policy=n,this.meter=t}canProduce(e,r){return this.inner.canProduce(e,r)}async resolveVersion(e,r,n){return await this.assertAllowed({publisher:e,package_:r,version:n.version}),this.inner.resolveVersion(e,r,n)}async produce(e,r,n){let t={publisher:e,package_:r,version:n};await this.assertAllowed(t);let a=await this.inner.produce(e,r,n);return await this.meter.record(this.ctx,t,a),a}async assertAllowed(e){let r=await this.policy.authorize(this.ctx,e);if(!r.allowed)throw new I(e,r.reason)}};var p="kanonak.org",d="view",pe="core-kanonak",vn={publisher:p,package_:d,name:"rootView"},Vn={publisher:p,package_:d,name:"bind"},jn={publisher:p,package_:d,name:"produces"},An={publisher:p,package_:d,name:"projections"},Cn={publisher:p,package_:d,name:"where"},Sn={publisher:p,package_:d,name:"value"},Dn={publisher:p,package_:d,name:"as"},S=class{constructor(e,r=new P){this.repository=e;this.parser=r;this.objectParser=new E(this.parser),this.builder=new g(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,r={}){let n=await this.objectParser.parseKanonaks(this.repository),t=this.resolveView(n,e),a=w(t,Vn);if(!a)throw new Error(`View ${t.namespace}/${t.name} declares no view.bind; cannot materialize.`);let i=w(t,jn);if(!i)throw new Error(`View ${t.namespace}/${t.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let s=Un(t),c=ue(n,p,pe),u=ue(n,p,d),l=this.builder.imports(),D=l.ensure(p,pe,c,"ck"),de=l.ensure(p,d,u,"v"),me=l.ref(i),ye=new oe(this.repository,this.parser,this.objectParser),q=new ne(ye,n),fe=this.readProjections(n,t),ke=Mn(t,Cn),ge=this.findInstances(n,a,await this.reason(r)),G={},he=new Set;for(let v of ge){if(!await this.passesWhere(q,n,ke,v))continue;let O={type:me};for(let Z of fe){let Pe=await this.evaluateValue(q,n,Z.value,v),Q=this.builder.serializeValue(le(Pe),l);Q!==void 0&&(O[l.ref(Z.as)]=Q)}let J=m(v);J&&(O[`${de}.derivedFrom`]=l.ref(J)),G[this.rowName(v,he)]=O}let U={};r.resolvedAt&&(U[`${D}.resolvedAt`]=r.resolvedAt),r.invocationId&&(U[`${D}.id`]=r.invocationId);let h=await this.builder.buildContentAddressed({publisher:s,book:l,body:G,contentHashProperty:`${D}.contentHash`,header:U});return{yaml:h.yaml,contentHash:h.contentHash,packageName:h.packageName,publisher:h.publisher,rowCount:h.resourceCount}}resolveView(e,r){let n=j(e,r);if(!n)throw new Error(`View ${r.publisher}/${r.package_}/${r.name} not found in the catalog.`);let t=w(n,vn);if(t){let a=j(e,t);if(!a)throw new Error(`ViewPackage ${r.name} names rootView ${t.name}, which is not in the catalog.`);return a}return n}readProjections(e,r){let n=[];for(let t of N(r,An)){let a=t instanceof k?t:t instanceof b?j(e,t.subject):void 0;if(!a)continue;let i=$(a,Sn),s=w(a,Dn);i&&s&&n.push({value:i,as:s})}return n}async reason(e){return new L({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,r,n){let t=_n(e),a=[],i=new Set;for(let s of n.getInstancesOfClass(r)){if(i.has(s))continue;i.add(s);let c=t.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=R(m(s)),l=R(m(c));return u<l?-1:u>l?1:0}),a}async passesWhere(e,r,n,t){for(let a of n){let i=await this.evaluateValue(e,r,a,t);if(!$n(i))return!1}return!0}async evaluateValue(e,r,n,t){let a=te(n,"view-projection",{catalog:r,depth:0}),i=new Map([["input",t]]);return e.evaluate(a,i)}rowName(e,r){let n=K(e.name)||"row",t=n,a=2;for(;r.has(t);)t=`${n}-${a++}`;return r.add(t),t}};function le(o){return B(o)?o.value:Array.isArray(o)?o.map(le):o}function Un(o){let e=m(o);if(!e)throw new Error(`Could not derive a publisher from view ${o.namespace}/${o.name}.`);return e.publisher}function ue(o,e,r){let n=On(o,e,r);if(!n)throw new Error(`Package ${e}/${r} is not in the catalog; it must be importable to materialize a view.`);return n}function On(o,e,r){let n;for(let t of o){if(!(t instanceof f))continue;let a=m(t);!a||a.publisher!==e||a.package_!==r||!a.version||(!n||V(a.version,n)>0)&&(n=a.version)}return n?y(n):void 0}function _n(o){let e=new Map,r=new Map;for(let n of o){if(!(n instanceof f))continue;let t=m(n);if(!t||!t.version)continue;let a=R(t),i=r.get(a);(!i||V(t.version,i)>0)&&(r.set(a,t.version),e.set(a,n))}return e}function Mn(o,e){let r=$(o,e);return r?[r]:N(o,e).filter(n=>n instanceof k)}function $n(o){return o===!0?!0:o===!1||o===void 0||o===null?!1:typeof o=="string"?o.length>0:typeof o=="number"?o!==0:B(o)?o.value.length>0:Array.isArray(o)?o.length>0:!!o}export{tn as AmbiguousReferenceRule,rr as BooleanStatement,En as CANONICAL_FORM_VERSION,hr as Carrier,un as ClassDefinitionRule,Zr as ClassHierarchyCycleRule,Ae as CompositeKanonakDocumentRepository,yn as DEFAULT_CONSENT_BINDING_PARAM,Ge as DefinedKanonak,je as DocumentLocation,Er as EdgeType,k as EmbeddedKanonak,qr as EmbeddedKanonakTypeRule,tr as EmbeddedStatement,I as EntitlementDeniedError,C as EntitlementProducer,Ve as FileSystemKanonakDocumentRepository,jr as GitIgnoreFilter,xr as GraphBuilder,Fe as HttpKanonakDocumentRepository,x as ImportBook,Gr as ImportExistenceRule,ve as InMemoryKanonakDocumentRepository,De as KANONAK_USER_AGENT,qe as Kanonak,Cr as KanonakDocumentPositions,E as KanonakObjectParser,dn as KanonakObjectValidator,P as KanonakParser,Je as KanonakUri,Ur as KanonakUriBuilder,Or as KanonakUrlResolver,dr as KanonakVocabulary,or as ListStatement,Ze as LiteralKanonak,Te as LocalFirstRepository,ze as LockAwareRepository,Rn as LookRenderer,ln as MarkdownLinkRule,ar as MarkdownStatement,rn as NamespaceImportCycleRule,Fr as NamespacePrefixRule,wr as NodeType,er as NumberStatement,fn as OAuthDiscovery,vr as OWL_RL_CLASSIFICATION_RULES,an as ObjectPropertyValueValidationRule,Nr as OntologyValidationError,Mr as OntologyValidationResult,g as PackageBuilder,Wr as PackageHeaderRule,A as ProducerRepository,sn as PropertyDomainRule,Qr as PropertyHierarchyCycleRule,cn as PropertyKindRangeConsistencyRule,Ar as PropertyMetadata,on as PropertyRangeReferenceRule,Xr as PropertyRangeRequiredRule,zr as PropertyTypeSpecificityRule,Ne as PublisherConfigResolver,Le as PublisherIndex,Ir as RDFS_RULES,L as Reasoner,Vr as ReasoningResult,b as ReferenceKanonak,nr as ReferenceStatement,Se as RepositoryFactory,pn as ReservedNameShadowRule,Tr as ResourceNamingRule,ir as ResourceResolver,mr as ResourceTypeClassifier,Xe as ScalarStatement,Qe as Statement,Ye as StringStatement,Yr as SubClassOfReferenceRule,en as SubPropertyOfReferenceRule,f as SubjectKanonak,Hr as SubjectKanonakTypeRequiredRule,hn as TokenCredentialProvider,Kr as TripleStore,sr as TypeResolver,nn as UnresolvedPredicateRule,Jr as UnresolvedReferenceRule,Br as ValidationCache,Lr as ValidationContext,$r as ValidationSeverity,_t as VersionOperator,S as ViewMaterializer,H as allowAllPolicy,_e as assertHttpsUrl,Be as assertPackageIdentity,We as buildLocalFirstRepository,xn as buildOntologyModel,wn as canonicalForm,F as canonicalHash,Pr as carrierOf,He as collectKanonakFiles,V as compareVersions,re as computeIntegrity,z as contentAddressedName,gr as contextTypesOf,gn as createCredentialedFetch,we as createVersion,Rr as extractMarkdownLinks,Pn as findDerivation,_r as findInstancesByType,br as findMalformedReferences,Dr as findMarkdownLinkAt,cr as formatKanonakAddress,y as formatVersion,Ce as getGlobalCachePath,Oe as getKanonakUserAgent,xe as isCompatibleVersion,Ke as isMajorCompatible,Me as kanonakFetch,Y as loadLockFile,pr as makeUriKey,W as noopMeter,mn as normalizeHost,kn as parseAuthChallenge,M as parseKanonakAddress,Ee as parseVersionString,Sr as parseWithPositions,Ie as pickHighestDocument,fr as propertiesInScope,bn as resolveDisplayValue,kr as resolvePropertyStep,K as sanitizeName,ee as saveLockFile,$e as setKanonakFetchRetries,Ue as setKanonakUserAgent,m as subjectUri,yr as superClassChain,ur as tripleKey,R as uriKey,lr as uriTriple,be as versionOperatorFromChar,_ as versionOperatorToChar,Re as versionsEqual};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Kanonak } from './Kanonak.js';
|
|
2
|
+
import type { DefinedKanonak } from './DefinedKanonak.js';
|
|
3
|
+
/** A DefinedKanonak visited during a walk, with a human-facing locator path. */
|
|
4
|
+
export interface WalkNode {
|
|
5
|
+
readonly kanonak: DefinedKanonak;
|
|
6
|
+
/** `subjectName` for a subject, `subjectName/childName/...` for embeddeds. */
|
|
7
|
+
readonly path: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Depth-first visit of every DefinedKanonak reachable from `roots`: each
|
|
11
|
+
* subject, then every embedded kanonak nested in its statements (single
|
|
12
|
+
* embeddeds and embedded list items), at any depth. The visitor sees one node
|
|
13
|
+
* at a time and should inspect only that node's OWN statements — the walk
|
|
14
|
+
* handles the recursion.
|
|
15
|
+
*
|
|
16
|
+
* Lives here rather than beside the validation helpers that first used it
|
|
17
|
+
* because it is a pure object-model traversal with no validation dependency,
|
|
18
|
+
* and the parser needs it too (its second-chance property pass scans
|
|
19
|
+
* `unresolvedPredicates` at every depth). `validation/documentModel` re-exports
|
|
20
|
+
* it, so this stays the single walk.
|
|
21
|
+
*/
|
|
22
|
+
export declare function walkDefinedKanonaks(roots: Kanonak[], visit: (node: WalkNode) => void): void;
|
|
@@ -7,6 +7,28 @@ export declare class KanonakObjectParser implements IKanonakObjectParser {
|
|
|
7
7
|
parseKanonaks(documentRepository: IKanonakDocumentRepository, out?: {
|
|
8
8
|
authored?: Kanonak[];
|
|
9
9
|
}): Promise<Kanonak[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Property classes discovered after the first pass, keyed by the
|
|
12
|
+
* property's canonical `uriKey`. Consulted by
|
|
13
|
+
* {@link getPropertyMetadata} when the declared-type name test fails.
|
|
14
|
+
* Parse-scoped — {@link parseKanonaks} clears it on entry.
|
|
15
|
+
*/
|
|
16
|
+
private readonly knownPropertyClasses;
|
|
17
|
+
/**
|
|
18
|
+
* Record every predicate that the first pass could not place but that the
|
|
19
|
+
* catalog now shows IS a property. Returns true when anything new was
|
|
20
|
+
* learned, i.e. when a re-parse would produce more statements.
|
|
21
|
+
*/
|
|
22
|
+
private learnPropertyClassesAsync;
|
|
23
|
+
/** Parse every entity in every document into a pre-merge SubjectKanonak. */
|
|
24
|
+
private parseAllDocumentsAsync;
|
|
25
|
+
/**
|
|
26
|
+
* Fold the pre-merge subjects onto one subject per canonical URI, then
|
|
27
|
+
* stamp built-in URIs across both views. Split out so the parse can be
|
|
28
|
+
* re-run and re-folded when {@link learnPropertyClassesAsync} discovers a
|
|
29
|
+
* property the first pass could not place.
|
|
30
|
+
*/
|
|
31
|
+
private mergeAndCanonicalizeAsync;
|
|
10
32
|
/**
|
|
11
33
|
* Walk a statement list, canonicalizing built-in URIs on every
|
|
12
34
|
* predicate and reference target (recursing into embeddeds and list
|
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-5NH5XDGO.js";import{m as b}from"../chunk-V6KIDED2.js";import{a}from"../chunk-NJ3AZYQD.js";import"../chunk-SVUMCLK5.js";import"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
|
|
@@ -49,6 +49,25 @@ export declare class ReasoningResult {
|
|
|
49
49
|
* reasoning?
|
|
50
50
|
*/
|
|
51
51
|
isInstanceOf(individual: UriKey | KanonakUri, classUri: UriKey | KanonakUri): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The saturated edge set of one property, as flat reachability data:
|
|
54
|
+
* `from → every member it reaches`. Because the store is saturated,
|
|
55
|
+
* the transitive closure is already materialised — for an
|
|
56
|
+
* `owl:TransitiveProperty` this is `prp-trp`'s output, and this method
|
|
57
|
+
* is a pure projection (no walking, no re-reasoning).
|
|
58
|
+
*/
|
|
59
|
+
getPropertyClosure(propertyUri: UriKey | KanonakUri): Record<UriKey, UriKey[]>;
|
|
60
|
+
/**
|
|
61
|
+
* The closure table the expression runtime's ordered comparisons
|
|
62
|
+
* (`tx.IsAtLeast` / `tx.Dominates`) consume as caller-supplied
|
|
63
|
+
* evaluation context: `property → member → reachable members`, keyed
|
|
64
|
+
* by canonical versionless URI. THE producer half of the
|
|
65
|
+
* runtime#16 design — reason once (typically at code-generation or
|
|
66
|
+
* publish time), emit this table, and evaluators never resolve a
|
|
67
|
+
* package or compute a closure at evaluation time. Shape matches
|
|
68
|
+
* `@kanonak-protocol/expression`'s `ClosureTable` exactly.
|
|
69
|
+
*/
|
|
70
|
+
getPropertyClosures(propertyUris: ReadonlyArray<UriKey | KanonakUri>): Record<UriKey, Record<UriKey, UriKey[]>>;
|
|
52
71
|
/**
|
|
53
72
|
* The full set of saturated triples. Useful for debugging and tests.
|
|
54
73
|
*/
|
package/dist/reasoning/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-
|
|
1
|
+
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-V3IPBWWU.js";import"../chunk-V6KIDED2.js";import"../chunk-NJ3AZYQD.js";import{e as a,f as b,g as c,i as d,l as e,m as f}from"../chunk-SVUMCLK5.js";import"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import type { SubjectKanonak } from '@kanonak-protocol/types/object/kanonaks/types';
|
|
2
|
+
/**
|
|
3
|
+
* The canonical RDF/OWL property classes — the roots of the property
|
|
4
|
+
* tree. A type is a property type when it IS one of these or descends
|
|
5
|
+
* from one; every OWL property characteristic
|
|
6
|
+
* (`TransitiveProperty`, `SymmetricProperty`, `FunctionalProperty`, …)
|
|
7
|
+
* does, per `core-owl`.
|
|
8
|
+
*/
|
|
9
|
+
export type PropertyClassKind = 'ObjectProperty' | 'DatatypeProperty' | 'AnnotationProperty' | 'Property';
|
|
10
|
+
/**
|
|
11
|
+
* Which canonical property class a resolved type URI names, or
|
|
12
|
+
* `undefined` if it names none.
|
|
13
|
+
*
|
|
14
|
+
* This is a URI-identity test on the FOUR roots, not a list of every
|
|
15
|
+
* property type — the caller that admits the characteristics and any
|
|
16
|
+
* publisher-defined property class is `propertyClassOf`, which walks
|
|
17
|
+
* `subClassOf` over the catalog and asks this of each node. THE single
|
|
18
|
+
* definition of "this URI is a property root"
|
|
19
|
+
* (kanonak-protocol/typescript#83).
|
|
20
|
+
*/
|
|
21
|
+
export declare function corePropertyClassOf(uri: {
|
|
22
|
+
publisher: string;
|
|
23
|
+
package_: string;
|
|
24
|
+
name: string;
|
|
25
|
+
}): PropertyClassKind | undefined;
|
|
2
26
|
export declare class ResourceTypeClassifier {
|
|
3
27
|
static getTypeUri(resource: SubjectKanonak): {
|
|
4
28
|
publisher: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Kanonak } from '../kanonaks/Kanonak.js';
|
|
2
2
|
import { SubjectKanonak } from '../kanonaks/SubjectKanonak.js';
|
|
3
3
|
import { KanonakUri } from './KanonakUri.js';
|
|
4
|
+
import { type PropertyClassKind } from './ResourceTypeClassifier.js';
|
|
4
5
|
import { type EntityUri } from '../uri-helpers/index.js';
|
|
5
6
|
export type PropertyKind = 'object' | 'datatype' | 'other';
|
|
6
7
|
export interface PropertyDescriptor {
|
|
@@ -26,6 +27,42 @@ export declare function subjectUri(subject: SubjectKanonak): KanonakUri | undefi
|
|
|
26
27
|
* inheritance) elsewhere, so there is one `subClassOf` traversal in the SDK.
|
|
27
28
|
*/
|
|
28
29
|
export declare function superClassChain(catalog: Kanonak[], classUri: KanonakUri | EntityUri): KanonakUri[];
|
|
30
|
+
/**
|
|
31
|
+
* The canonical property class a subject's declared type(s) descend
|
|
32
|
+
* from, or `undefined` when the subject is not a property at all.
|
|
33
|
+
*
|
|
34
|
+
* Decides by SUBSUMPTION, over `superClassChain` — the SDK's one
|
|
35
|
+
* `subClassOf` traversal — with `corePropertyClassOf` supplying the
|
|
36
|
+
* definition of a property root. `KanonakObjectParser` calls this too:
|
|
37
|
+
* its declared-type name test cannot settle a characteristic during the
|
|
38
|
+
* parse, so it re-asks here once the catalog exists (see the
|
|
39
|
+
* second-chance pass in `parseKanonaks`). One traversal, one answer.
|
|
40
|
+
*
|
|
41
|
+
* Consulting the chain rather than the declared type's own URI is what
|
|
42
|
+
* makes an OWL property characteristic visible as the property it is:
|
|
43
|
+
* `core-owl` says `TransitiveProperty ⊑ ObjectProperty ⊑ Property`, so a
|
|
44
|
+
* transitive property is an object property and is returned as one. A
|
|
45
|
+
* name-matching test saw none of them, which kept every characteristic
|
|
46
|
+
* out of `propertiesInScope` — and therefore out of path validation,
|
|
47
|
+
* completion, and the property-shaped validation rules
|
|
48
|
+
* (kanonak-protocol/typescript#83).
|
|
49
|
+
*
|
|
50
|
+
* The most specific kind wins, so a `FunctionalProperty` (which
|
|
51
|
+
* `core-owl` places directly under `Property`) yields `'Property'` while
|
|
52
|
+
* a `TransitiveProperty` yields `'ObjectProperty'`. A multi-valued
|
|
53
|
+
* `type:` is read in declaration order.
|
|
54
|
+
*/
|
|
55
|
+
export declare function propertyClassOf(catalog: Kanonak[], subject: SubjectKanonak): PropertyClassKind | undefined;
|
|
56
|
+
/** True when the subject is a property of any kind. */
|
|
57
|
+
export declare function isPropertySubject(catalog: Kanonak[], subject: SubjectKanonak): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* True when the subject is an object property — declared
|
|
60
|
+
* `owl.ObjectProperty` or any subclass of it, every OWL characteristic
|
|
61
|
+
* under `ObjectProperty` included.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isObjectPropertySubject(catalog: Kanonak[], subject: SubjectKanonak): boolean;
|
|
64
|
+
/** True when the subject is a datatype property, by the same subsumption test. */
|
|
65
|
+
export declare function isDatatypePropertySubject(catalog: Kanonak[], subject: SubjectKanonak): boolean;
|
|
29
66
|
/**
|
|
30
67
|
* Every property in scope for a class — those whose `domain` is the
|
|
31
68
|
* class, an ancestor, or rdfs.Resource. Scans the catalog once. Powers
|