@kanonak-protocol/sdk 5.30.0 → 5.32.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.
@@ -1,11 +1,11 @@
1
- import{a as Do}from"./chunk-KIBR3HAT.js";import{c as So,e as Io,f as oo,g as to,h as $o,i as jo,j as Oo,q as no,r as wo,s as Co}from"./chunk-Z5Y4MCW5.js";import{a as S,b as go,c as Ge,d as L,h as F,k as vo,m as j}from"./chunk-PVUBHIU2.js";import{a as fo}from"./chunk-HF5FJBS2.js";import{aa as ze,b as ko,ba as Ko,fa as $,ga as T,ha as H,ia as B,ja as Y,ma as Eo,na as W,oa as Vo}from"./chunk-7UYXTYXC.js";import{A as P,B as v,C as _,c as g,d as O,j as ee,k as G,l as M,m as b,n as q,p as ho,q as Ro,r as A,t as V,u as bo,w as oe,x as X,y as z,z as h}from"./chunk-CJMVIOZX.js";import{a as yo}from"./chunk-FUUTGGJS.js";import{b as Q,c as uo}from"./chunk-F67UH4FD.js";import{e as C}from"./chunk-QILEJIFU.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 R=(t=>(t.Info="Info",t.Warning="Warning",t.Error="Error",t))(R||{});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 ro=class p{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new p;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};var ne=class{constructor(e){this.underlying=e;this.repository=new ao(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 Do(e,this.repository);let o={};return{merged:await new j().parseKanonaks(this.underlying,o),authored:o.authored??[]}})()),this.parsePromise}},ao=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,o){let t=`${e}/${o}`,n=this.byNamespaceCache.get(t);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,o),this.byNamespaceCache.set(t,n),n)}getHighestCompatibleVersionAsync(e,o){let t=o.version,n=t?`${t.major}.${t.minor}.${t.patch}`:"",r=`${e}/${o.packageName}@${o.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,o),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 I(p,e,o){return o?o.getKanonaks():new j().parseKanonaks(new re(p,e))}async function w(p,e,o){let t=await I(p,e,o),n=Xe(p);return n?t.filter(r=>r instanceof g&&r.namespace===n):[]}async function ae(p,e,o){let t=Xe(p);if(!t)return[];let n;if(o)n=await o.getAuthoredKanonaks();else{let r={};await new j().parseKanonaks(new re(p,e),r),n=r.authored??[]}return n.filter(r=>r instanceof g&&r.sourceDoc===t)}function Xe(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var re=class{constructor(e,o){this.document=e;this.broader=o}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),o=(await this.broader.getAllDocumentsAsync()).filter(t=>t.metadata.namespace_?.toString()!==e);return[this.document,...o]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){return this.broader.getDocumentsByNamespaceAsync(e,o)}getHighestCompatibleVersionAsync(e,o){return this.broader.getHighestCompatibleVersionAsync(e,o)}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 ie=class{constructor(e={}){this.options=e}options;ruleName="LinkTarget";async validateAsync(e,o,t){let n=[],r=new Map;for(let[s,l]of Object.entries(e.metadata?.imports??{}))for(let m of l)Q(m)&&r.set(`${s}/${m.packageName}`,{publisher:s,import_:m});if(r.size===0)return n;let a=new Map,i=(s,l,m)=>{let d=`${s.publisher}/${s.package_}`;if(!r.has(d))return;let f=a.get(d)??[];f.push({uri:s,where:l,predicate:m}),a.set(d,f)},c=await w(e,o,t);L(c,({kanonak:s,path:l})=>{for(let m of s.statement){let d=m.predicate?.subject?.name??"(unknown)";if(m instanceof ee)i(m.object.subject,l,d);else if(m instanceof M)for(let f of m.object)f instanceof O&&i(f.subject,l,d);else if(m instanceof Ge)for(let f of m.links)f.target&&i(f.target.subject,l,d)}});for(let[s,l]of a){let{publisher:m,import_:d}=r.get(s),f=null,y;try{f=await o.getHighestCompatibleVersionAsync(m,d)}catch(k){y=k instanceof Error?k.message:String(k)}if(!f){let k=l[0],K=`${l.length} reference${l.length===1?"":"s"}, first at '${k.where}.${k.predicate}'`;this.options.offline?n.push(this.finding("Warning",k.where,k.predicate,s,`Link target package '${s}' could not be resolved offline (${K}); the link is UNVERIFIED, not known to be broken.`,"Run without --offline to verify the link over HTTP, or add the package to the workspace or cache.")):n.push(this.finding("Error",k.where,k.predicate,s,`Link target package '${s}' could not be resolved${y?` (${y})`:""} \u2014 ${K}.`,"Check the publisher and package name of the link import; a link must dereference even though it is not a dependency. Use --offline to validate without the network (the link is then reported as unverified)."));continue}for(let{uri:k,where:K,predicate:E}of l)Object.prototype.hasOwnProperty.call(f.body,k.name)||n.push(this.finding("Error",K,E,`${s}/${k.name}`,`Link to '${k.name}' in '${E}' at '${K}' does not dereference: package '${s}' (resolved to ${f.metadata.namespace_?.toString()??s}) defines no resource named '${k.name}'.`,`Check for a typo, or a resource renamed or removed in '${s}'; a link addresses a resource by name in its package's current version unless the import is pinned with '='.`))}return n}finding(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.actualValue=n,i.expectedValue="A link that dereferences to a resource its target package defines",i.message=r,i.suggestion=a,i}};var se=class p{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(t,n,o);return o}validateEntity(e,o,t){for(let[n,r]of Object.entries(o)){let a=r?.toString()??"";if(a&&p.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),c=e.split(".")[0],s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,s.propertyName=e,s.actualValue=n,s.expectedValue=i,s.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var ce=class p{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 o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=p.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!t&&p.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.",o.push(i);continue}if(!a&&!p.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 c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=n,c.message=`Invalid entity name '${n}'. ${i}`,c.suggestion=i,o.push(c)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,o)}return o}validatePropertyNames(e,o,t){for(let n of Object.keys(o))if(!p.VALID_PROPERTIES.has(n)&&!p.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.",t.push(r)}}};var pe=class p{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let c=[];if(Array.isArray(i))for(let s of i){let l=s?.toString();l&&l==="Property"&&!t&&c.push(l)}else{let s=i?.toString();s&&s==="Property"&&!t&&c.push(s)}for(let s of c){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=s,d.expectedValue=m,d.message=`Invalid property type '${s}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(d)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":p.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let n=o.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var le=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||t.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=t,c.propertyName="type",c.message=`Subject Kanonak '${t}' must have a 'type' property.`,c.suggestion=`Add a type statement like:
1
+ import{a as Do}from"./chunk-KIBR3HAT.js";import{c as So,e as Io,f as oo,g as to,h as $o,i as jo,j as Oo,q as no,r as wo,s as Co}from"./chunk-DD3TCFBT.js";import{a as S,b as go,c as Ge,d as L,h as F,k as vo,m as j}from"./chunk-PVUBHIU2.js";import{a as fo}from"./chunk-HF5FJBS2.js";import{aa as ze,b as ko,ba as Ko,fa as $,ga as T,ha as H,ia as B,ja as Y,ma as Eo,na as W,oa as Vo}from"./chunk-7UYXTYXC.js";import{A as P,B as v,C as _,c as g,d as O,j as ee,k as G,l as M,m as b,n as q,p as ho,q as Ro,r as A,t as V,u as bo,w as oe,x as Z,y as z,z as h}from"./chunk-CJMVIOZX.js";import{a as yo}from"./chunk-FUUTGGJS.js";import{b as Q,c as uo}from"./chunk-F67UH4FD.js";import{e as C}from"./chunk-QILEJIFU.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 R=(t=>(t.Info="Info",t.Warning="Warning",t.Error="Error",t))(R||{});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 ro=class p{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new p;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};var ne=class{constructor(e){this.underlying=e;this.repository=new ao(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 Do(e,this.repository);let o={};return{merged:await new j().parseKanonaks(this.underlying,o),authored:o.authored??[]}})()),this.parsePromise}},ao=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,o){let t=`${e}/${o}`,n=this.byNamespaceCache.get(t);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,o),this.byNamespaceCache.set(t,n),n)}getHighestCompatibleVersionAsync(e,o){let t=o.version,n=t?`${t.major}.${t.minor}.${t.patch}`:"",r=`${e}/${o.packageName}@${o.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,o),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 I(p,e,o){return o?o.getKanonaks():new j().parseKanonaks(new re(p,e))}async function w(p,e,o){let t=await I(p,e,o),n=Ze(p);return n?t.filter(r=>r instanceof g&&r.namespace===n):[]}async function ae(p,e,o){let t=Ze(p);if(!t)return[];let n;if(o)n=await o.getAuthoredKanonaks();else{let r={};await new j().parseKanonaks(new re(p,e),r),n=r.authored??[]}return n.filter(r=>r instanceof g&&r.sourceDoc===t)}function Ze(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var re=class{constructor(e,o){this.document=e;this.broader=o}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),o=(await this.broader.getAllDocumentsAsync()).filter(t=>t.metadata.namespace_?.toString()!==e);return[this.document,...o]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){return this.broader.getDocumentsByNamespaceAsync(e,o)}getHighestCompatibleVersionAsync(e,o){return this.broader.getHighestCompatibleVersionAsync(e,o)}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 ie=class{constructor(e={}){this.options=e}options;ruleName="LinkTarget";async validateAsync(e,o,t){let n=[],r=new Map;for(let[s,l]of Object.entries(e.metadata?.imports??{}))for(let m of l)Q(m)&&r.set(`${s}/${m.packageName}`,{publisher:s,import_:m});if(r.size===0)return n;let a=new Map,i=(s,l,m)=>{let d=`${s.publisher}/${s.package_}`;if(!r.has(d))return;let f=a.get(d)??[];f.push({uri:s,where:l,predicate:m}),a.set(d,f)},c=await w(e,o,t);L(c,({kanonak:s,path:l})=>{for(let m of s.statement){let d=m.predicate?.subject?.name??"(unknown)";if(m instanceof ee)i(m.object.subject,l,d);else if(m instanceof M)for(let f of m.object)f instanceof O&&i(f.subject,l,d);else if(m instanceof Ge)for(let f of m.links)f.target&&i(f.target.subject,l,d)}});for(let[s,l]of a){let{publisher:m,import_:d}=r.get(s),f=null,y;try{f=await o.getHighestCompatibleVersionAsync(m,d)}catch(k){y=k instanceof Error?k.message:String(k)}if(!f){let k=l[0],K=`${l.length} reference${l.length===1?"":"s"}, first at '${k.where}.${k.predicate}'`;this.options.offline?n.push(this.finding("Warning",k.where,k.predicate,s,`Link target package '${s}' could not be resolved offline (${K}); the link is UNVERIFIED, not known to be broken.`,"Run without --offline to verify the link over HTTP, or add the package to the workspace or cache.")):n.push(this.finding("Error",k.where,k.predicate,s,`Link target package '${s}' could not be resolved${y?` (${y})`:""} \u2014 ${K}.`,"Check the publisher and package name of the link import; a link must dereference even though it is not a dependency. Use --offline to validate without the network (the link is then reported as unverified)."));continue}for(let{uri:k,where:K,predicate:E}of l)Object.prototype.hasOwnProperty.call(f.body,k.name)||n.push(this.finding("Error",K,E,`${s}/${k.name}`,`Link to '${k.name}' in '${E}' at '${K}' does not dereference: package '${s}' (resolved to ${f.metadata.namespace_?.toString()??s}) defines no resource named '${k.name}'.`,`Check for a typo, or a resource renamed or removed in '${s}'; a link addresses a resource by name in its package's current version unless the import is pinned with '='.`))}return n}finding(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.actualValue=n,i.expectedValue="A link that dereferences to a resource its target package defines",i.message=r,i.suggestion=a,i}};var se=class p{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):[A-Za-z_][A-Za-z0-9_.-]*$/i;ruleName="NamespacePrefix";validate(e){let o=[];for(let[t,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(t,n,o);return o}validateEntity(e,o,t){for(let[n,r]of Object.entries(o)){let a=r?.toString()??"";if(a&&p.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),c=e.split(".")[0],s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=c,s.propertyName=e,s.actualValue=n,s.expectedValue=i,s.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,s.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var ce=class p{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 o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=p.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!t&&p.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.",o.push(i);continue}if(!a&&!p.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 c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=n,c.message=`Invalid entity name '${n}'. ${i}`,c.suggestion=i,o.push(c)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,o)}return o}validatePropertyNames(e,o,t){for(let n of Object.keys(o))if(!p.VALID_PROPERTIES.has(n)&&!p.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.",t.push(r)}}};var pe=class p{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let c=[];if(Array.isArray(i))for(let s of i){let l=s?.toString();l&&l==="Property"&&!t&&c.push(l)}else{let s=i?.toString();s&&s==="Property"&&!t&&c.push(s)}for(let s of c){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=s,d.expectedValue=m,d.message=`Invalid property type '${s}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(d)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":p.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let n=o.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var le=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||t.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=t,c.propertyName="type",c.message=`Subject Kanonak '${t}' must have a 'type' property.`,c.suggestion=`Add a type statement like:
2
2
  type: Scene
3
3
 
4
4
  Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,c.expectedValue="A valid class name (Scene, Character, Story, etc.)",o.push(c)}}return o}};var ot=new Set(["EphemeralPackage"]),me=class{get ruleName(){return"PackageHeader"}validate(e){let o=e.metadata;if(!o.type_)return[];let t=[],n=this.packageKey(e,o.type_);return o.namespace_?(!ot.has(o.type_)&&!o.namespace_.version&&t.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
5
  version: 1.0.0`)),t):(t.push(this.error(n,"publisher",`Package resource '${n}' requires a 'publisher' property.`,`Add a publisher, e.g.:
6
- publisher: example.org`)),t)}packageKey(e,o){for(let[t,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.type===o)return t;return o}error(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.message=t,r.suggestion=n,r}};var tt={publisher:"kanonak.org",package_:"core-rdf",name:"type"},nt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},rt={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},at={publisher:"kanonak.org",package_:"core-rdf",name:"Class"},ue=class{ruleName="EmbeddedKanonakType";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await ae(e,o,t);for(let i of a)i instanceof g&&this.walk(r,i,i.name,n);return n}walk(e,o,t,n){for(let r of o.statement)if(r instanceof G){let a=r.predicate?.subject,i=`${t}.${a?.name??"<embedded>"}`;this.check(e,a,r.object,t,i,n),this.walk(e,r.object,i,n)}else if(r instanceof M){let a=r.predicate?.subject,i=0;for(let c of r.object){if(c instanceof S){let s=`${t}.${a?.name??"<embedded>"}[${i}]`;this.check(e,a,c,t,s,n),this.walk(e,c,s,n)}i++}}}check(e,o,t,n,r,a){if(!o)return;let i=h(t,tt);if(!i)return;let c=V(e,o);if(!c)return;let s=h(c,nt);if(s&&!(q(s,rt)||q(s,at))){if(b(i)===b(s)){a.push(this.redundant(n,r,i,s));return}H(e,i).some(l=>b(l)===b(s))||a.push(this.notSubclass(n,r,i,s))}}redundant(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t.name,r.expectedValue=n.name,r.message=`Embedded object at '${o}' declares 'type: ${t.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: ${t.name}' line, or keep it if explicitness is preferred over concision.`,r}notSubclass(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=t.name,r.expectedValue=n.name,r.message=`Embedded object at '${o}' has 'type: ${t.name}', which is not a subclass of the parent property's range '${n.name}'.`,r.suggestion=`Either remove the 'type: ${t.name}' line (so the type is inferred from the property's range '${n.name}'), or add 'subClassOf: ${n.name}' to the '${t.name}' class definition so the relationship holds.`,r}};import{VersionOperator as Ze}from"@kanonak-protocol/types/document/models/enums";var de=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let n=await o.getAllDocumentsAsync();for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a){if(Q(i))continue;if(!await o.getHighestCompatibleVersionAsync(r,i)){let s=await this.determineImportErrorAsync(o,r,i,n),l=new u;l.ruleType=this.ruleName,l.severity="Error",l.message=s.message,l.suggestion=s.suggestion,l.entityName=`Import: ${r}/${i.packageName}`,l.actualValue=i.toString(),l.expectedValue=s.expectedValue,t.push(l)}}return t}async determineImportErrorAsync(e,o,t,n){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=n.filter(f=>f.metadata.namespace_?.publisher===o).map(f=>f.metadata.namespace_.package_).filter((f,y,k)=>k.indexOf(f)===y),l=this.findSimilarPackages(t.packageName,s),m=`Import '${o}/${t.package_}' not found - package does not exist`,d=l.length>0?`Did you mean: ${l.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${o}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:m,suggestion:d,expectedValue:"Existing package"}}let i=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),c=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${c}`,expectedValue:c}}getAcceptableVersionRange(e){switch(e.versionOperator){case Ze.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Ze.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Ze.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Ze.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(a=>a.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(a.toLowerCase()));if(t.length>0)return t.sort((a,i)=>a.length-i.length);let n=o.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,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,n=o.length,r=Array(t+1).fill(null).map(()=>Array(n+1).fill(0));for(let a=0;a<=t;a++)r[a][0]=a;for(let a=0;a<=n;a++)r[0][a]=a;for(let a=1;a<=t;a++)for(let i=1;i<=n;i++){let c=e[a-1]===o[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]+c)}return r[t][n]}};var it="kanonak.org",st="core-rdf",ct=new Set(["type","subClassOf","subPropertyOf","domain","range"].map(p=>b({publisher:it,package_:st,name:p}))),fe=class{ruleName="UnresolvedReference";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t),i=uo(e),c=s=>i.has(`${s.subject.publisher}/${s.subject.package_}`);return L(a,({kanonak:s,path:l})=>{for(let m of s.statement){let d=pt(m);if(!(!d||ct.has(b(d)))){if(m instanceof ee)c(m.object)||this.check(r,l,d,m.object,n);else if(m instanceof M)for(let f of m.object)f instanceof O&&!c(f)&&this.check(r,l,d,f,n)}}}),n}check(e,o,t,n,r){V(e,n.subject)||r.push(this.unresolvedError(o,t.name,n.subject))}unresolvedError(e,o,t){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=n,r.expectedValue="A reference that resolves to a defined or imported resource",r.message=`Reference to '${t.name}' in '${o}' could not be resolved`,r.suggestion=`The entity '${n}' is not defined in this namespace or any imported namespace.
6
+ publisher: example.org`)),t)}packageKey(e,o){for(let[t,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.type===o)return t;return o}error(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.message=t,r.suggestion=n,r}};var tt={publisher:"kanonak.org",package_:"core-rdf",name:"type"},nt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},rt={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},at={publisher:"kanonak.org",package_:"core-rdf",name:"Class"},ue=class{ruleName="EmbeddedKanonakType";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await ae(e,o,t);for(let i of a)i instanceof g&&this.walk(r,i,i.name,n);return n}walk(e,o,t,n){for(let r of o.statement)if(r instanceof G){let a=r.predicate?.subject,i=`${t}.${a?.name??"<embedded>"}`;this.check(e,a,r.object,t,i,n),this.walk(e,r.object,i,n)}else if(r instanceof M){let a=r.predicate?.subject,i=0;for(let c of r.object){if(c instanceof S){let s=`${t}.${a?.name??"<embedded>"}[${i}]`;this.check(e,a,c,t,s,n),this.walk(e,c,s,n)}i++}}}check(e,o,t,n,r,a){if(!o)return;let i=h(t,tt);if(!i)return;let c=V(e,o);if(!c)return;let s=h(c,nt);if(s&&!(q(s,rt)||q(s,at))){if(b(i)===b(s)){a.push(this.redundant(n,r,i,s));return}H(e,i).some(l=>b(l)===b(s))||a.push(this.notSubclass(n,r,i,s))}}redundant(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t.name,r.expectedValue=n.name,r.message=`Embedded object at '${o}' declares 'type: ${t.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: ${t.name}' line, or keep it if explicitness is preferred over concision.`,r}notSubclass(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=t.name,r.expectedValue=n.name,r.message=`Embedded object at '${o}' has 'type: ${t.name}', which is not a subclass of the parent property's range '${n.name}'.`,r.suggestion=`Either remove the 'type: ${t.name}' line (so the type is inferred from the property's range '${n.name}'), or add 'subClassOf: ${n.name}' to the '${t.name}' class definition so the relationship holds.`,r}};import{VersionOperator as Xe}from"@kanonak-protocol/types/document/models/enums";var de=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let n=await o.getAllDocumentsAsync();for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a){if(Q(i))continue;if(!await o.getHighestCompatibleVersionAsync(r,i)){let s=await this.determineImportErrorAsync(o,r,i,n),l=new u;l.ruleType=this.ruleName,l.severity="Error",l.message=s.message,l.suggestion=s.suggestion,l.entityName=`Import: ${r}/${i.packageName}`,l.actualValue=i.toString(),l.expectedValue=s.expectedValue,t.push(l)}}return t}async determineImportErrorAsync(e,o,t,n){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let s=n.filter(f=>f.metadata.namespace_?.publisher===o).map(f=>f.metadata.namespace_.package_).filter((f,y,k)=>k.indexOf(f)===y),l=this.findSimilarPackages(t.packageName,s),m=`Import '${o}/${t.package_}' not found - package does not exist`,d=l.length>0?`Did you mean: ${l.slice(0,3).join(", ")}?`:s.length>0?`Available packages in ${o}: ${s.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:m,suggestion:d,expectedValue:"Existing package"}}let i=r.filter(s=>s.metadata.namespace_?.version).map(s=>s.metadata.namespace_.version.toString()).sort().join(", "),c=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${c}`,expectedValue:c}}getAcceptableVersionRange(e){switch(e.versionOperator){case Xe.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Xe.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Xe.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Xe.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(a=>a.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(a.toLowerCase()));if(t.length>0)return t.sort((a,i)=>a.length-i.length);let n=o.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,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,n=o.length,r=Array(t+1).fill(null).map(()=>Array(n+1).fill(0));for(let a=0;a<=t;a++)r[a][0]=a;for(let a=0;a<=n;a++)r[0][a]=a;for(let a=1;a<=t;a++)for(let i=1;i<=n;i++){let c=e[a-1]===o[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]+c)}return r[t][n]}};var it="kanonak.org",st="core-rdf",ct=new Set(["type","subClassOf","subPropertyOf","domain","range"].map(p=>b({publisher:it,package_:st,name:p}))),fe=class{ruleName="UnresolvedReference";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t),i=uo(e),c=s=>i.has(`${s.subject.publisher}/${s.subject.package_}`);return L(a,({kanonak:s,path:l})=>{for(let m of s.statement){let d=pt(m);if(!(!d||ct.has(b(d)))){if(m instanceof ee)c(m.object)||this.check(r,l,d,m.object,n);else if(m instanceof M)for(let f of m.object)f instanceof O&&!c(f)&&this.check(r,l,d,f,n)}}}),n}check(e,o,t,n,r){V(e,n.subject)||r.push(this.unresolvedError(o,t.name,n.subject))}unresolvedError(e,o,t){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=n,r.expectedValue="A reference that resolves to a defined or imported resource",r.message=`Reference to '${t.name}' in '${o}' could not be resolved`,r.suggestion=`The entity '${n}' is not defined in this namespace or any imported namespace.
7
7
  \u2022 Import the package that defines it, or check for a typo in '${t.name}'
8
- \u2022 If it lives in an imported namespace, alias-qualify the reference`,r}};function pt(p){return p.predicate?.subject}var Po={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},Uo={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"};function lt(p,e){let o=h(p,e);if(o)return[o];let t=[];for(let n of v(p,e))n instanceof O&&t.push(n.subject);return t}function Je(p,e,o){let t=[],n=new Set,r=new Set,a=i=>{let c=V(p,i),s=c?`${c.namespace}/${c.name}`:b(i);if(n.has(s)){let l=t.findIndex(d=>d.key===s),m=t.slice(l);return m.length<=1?null:[...m.map(d=>d.uri),i]}if(r.has(s))return null;if(n.add(s),t.push({key:s,uri:i}),c)for(let l of lt(c,o)){let m=a(l);if(m)return m}return t.pop(),n.delete(s),r.add(s),null};return a(e)}var Ao=p=>p,ye=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!($.isClassType(Ao(i))||$.isDatatypeType(Ao(i))))continue;let c=T(i);if(!c)continue;let s=Je(r,c,Po);if(s){let l=s.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 ge=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!Y(r,i))continue;let c=T(i);if(!c)continue;let s=Je(r,c,Uo);if(s){let l=s.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 mt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},ke=class{ruleName="PropertyRangeRequired";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g))continue;let c=B(r,i);if(c!=="ObjectProperty"&&c!=="DatatypeProperty")continue;let s=c==="ObjectProperty";oe(i,mt)||n.push(this.error(i.name,s))}return n}error(e,o){let t=new u;return t.ruleType=this.ruleName,t.severity="Error",t.entityName=e,t.propertyName="range",t.message=`Property '${e}' must have a 'range' defined.`,t.suggestion=o?"Add a range like: range: ClassName (the class this property expects)":"Add a range like: range: string (or integer, boolean, etc.)",t.expectedValue=o?"A class name (Character, Scene, Story, etc.)":"A datatype (string, integer, boolean, decimal, etc.)",t}};var ut={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},No=p=>p,he=class{ruleName="SubClassOfReference";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!To(No(i)))continue;let c=dt(i,ut);for(let s=0;s<c.length;s++)this.resolvesToClassLike(r,c[s])||n.push(this.error(i.name,c[s],c.length>1?`[${s}]`:""))}return n}resolvesToClassLike(e,o){let t=V(e,o);return t?To(No(t)):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.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 '${o.name}' referenced in subClassOf${t} is not defined or imported`,r.suggestion=`Define '${o.name}' as a Class, or import a namespace that contains it`,r}};function To(p){return $.isClassType(p)||$.isDatatypeType(p)}function dt(p,e){let o=h(p,e);if(o)return[o];let t=[];for(let n of v(p,e))n instanceof O&&t.push(n.subject);return t}var ft={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"},Re=class{ruleName="SubPropertyOfReference";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!Y(r,i))continue;let c=yt(i,ft);for(let s=0;s<c.length;s++)this.resolvesToProperty(r,c[s])||n.push(this.error(i.name,c[s],c.length>1?`[${s}]`:""))}return n}resolvesToProperty(e,o){let t=V(e,o);return t?Y(e,t):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.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 '${o.name}' referenced in subPropertyOf${t} is not defined or imported`,r.suggestion=`Define '${o.name}' as a property, or import a namespace that contains it`,r}};function yt(p,e){let o=h(p,e);if(o)return[o];let t=[];for(let n of v(p,e))n instanceof O&&t.push(n.subject);return t}var be=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],n=e.metadata.namespace_?.toString();if(!n)return t;let r=new Map,a=new Set;await this.buildImportGraph(e,o,r,a);let i=this.detectCycle(n,r);if(i){let c=i.join(" \u2192 "),s=new u;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${c}`,s.suggestion="Remove one of the imports to break the circular dependency, or \u2014 if one direction is a DATA reference rather than a schema dependency (an object-property value naming a resource in the other package) \u2014 mark that import `mode: link`: links are dereferenced on demand, are not in the closure, and are exempt from this rule. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=c,t.push(s)}return t}async buildImportGraph(e,o,t,n){let r=e.metadata.namespace_?.toString()??"";if(!(!r||n.has(r))&&(n.add(r),e.metadata.imports)){let a=[];for(let[i,c]of Object.entries(e.metadata.imports))for(let s of c){if(Q(s))continue;let l=`${i}/${s.packageName}@${s.version}`;a.push(l);let m=await o.getHighestCompatibleVersionAsync(i,s);m&&await this.buildImportGraph(m,o,t,n)}a.length>0&&t.set(r,a)}}detectCycle(e,o){let t=[],n=new Set;return this.detectCycleRecursive(e,o,t,n)}detectCycleRecursive(e,o,t,n){let r=t.indexOf(e);if(r>=0){let i=t.slice(r);return i.push(e),i}if(n.has(e))return null;t.push(e),n.add(e);let a=o.get(e);if(a)for(let i of a){let c=this.detectCycleRecursive(i,o,t,n);if(c)return c}return t.pop(),null}};var Ke=class{ruleName="UnresolvedPredicate";async validateAsync(e,o,t){let n=[],r=Xe(e);if(!r)return n;let a=await I(e,o,t);return L(a,({kanonak:i,path:c})=>{for(let s of i.unresolvedPredicates)s.sourceDoc===r&&n.push(this.unresolvedPredicateError(c,s.key))}),n}unresolvedPredicateError(e,o){let t=o.lastIndexOf("."),n=t>0?o.slice(0,t):null,r=t>0?o.slice(t+1):o,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=o,a.actualValue=o,a.expectedValue="A defined or imported property",a.message=`Property '${o}' is not defined or imported`,a.suggestion=n?`The property '${r}' was not found in the namespace imported as '${n}'.
8
+ \u2022 If it lives in an imported namespace, alias-qualify the reference`,r}};function pt(p){return p.predicate?.subject}var Po={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},Uo={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"};function lt(p,e){let o=h(p,e);if(o)return[o];let t=[];for(let n of v(p,e))n instanceof O&&t.push(n.subject);return t}function Je(p,e,o){let t=[],n=new Set,r=new Set,a=i=>{let c=V(p,i),s=c?`${c.namespace}/${c.name}`:b(i);if(n.has(s)){let l=t.findIndex(d=>d.key===s),m=t.slice(l);return m.length<=1?null:[...m.map(d=>d.uri),i]}if(r.has(s))return null;if(n.add(s),t.push({key:s,uri:i}),c)for(let l of lt(c,o)){let m=a(l);if(m)return m}return t.pop(),n.delete(s),r.add(s),null};return a(e)}var Ao=p=>p,ye=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!($.isClassType(Ao(i))||$.isDatatypeType(Ao(i))))continue;let c=T(i);if(!c)continue;let s=Je(r,c,Po);if(s){let l=s.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 ge=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!Y(r,i))continue;let c=T(i);if(!c)continue;let s=Je(r,c,Uo);if(s){let l=s.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 mt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},ke=class{ruleName="PropertyRangeRequired";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g))continue;let c=B(r,i);if(c!=="ObjectProperty"&&c!=="DatatypeProperty")continue;let s=c==="ObjectProperty";oe(i,mt)||n.push(this.error(i.name,s))}return n}error(e,o){let t=new u;return t.ruleType=this.ruleName,t.severity="Error",t.entityName=e,t.propertyName="range",t.message=`Property '${e}' must have a 'range' defined.`,t.suggestion=o?"Add a range like: range: ClassName (the class this property expects)":"Add a range like: range: string (or integer, boolean, etc.)",t.expectedValue=o?"A class name (Character, Scene, Story, etc.)":"A datatype (string, integer, boolean, decimal, etc.)",t}};var ut={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},No=p=>p,he=class{ruleName="SubClassOfReference";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!To(No(i)))continue;let c=dt(i,ut);for(let s=0;s<c.length;s++)this.resolvesToClassLike(r,c[s])||n.push(this.error(i.name,c[s],c.length>1?`[${s}]`:""))}return n}resolvesToClassLike(e,o){let t=V(e,o);return t?To(No(t)):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.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 '${o.name}' referenced in subClassOf${t} is not defined or imported`,r.suggestion=`Define '${o.name}' as a Class, or import a namespace that contains it`,r}};function To(p){return $.isClassType(p)||$.isDatatypeType(p)}function dt(p,e){let o=h(p,e);if(o)return[o];let t=[];for(let n of v(p,e))n instanceof O&&t.push(n.subject);return t}var ft={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"},Re=class{ruleName="SubPropertyOfReference";async validateAsync(e,o,t){let n=[],r=await I(e,o,t),a=await w(e,o,t);for(let i of a){if(!(i instanceof g)||!Y(r,i))continue;let c=yt(i,ft);for(let s=0;s<c.length;s++)this.resolvesToProperty(r,c[s])||n.push(this.error(i.name,c[s],c.length>1?`[${s}]`:""))}return n}resolvesToProperty(e,o){let t=V(e,o);return t?Y(e,t):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.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 '${o.name}' referenced in subPropertyOf${t} is not defined or imported`,r.suggestion=`Define '${o.name}' as a property, or import a namespace that contains it`,r}};function yt(p,e){let o=h(p,e);if(o)return[o];let t=[];for(let n of v(p,e))n instanceof O&&t.push(n.subject);return t}var be=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],n=e.metadata.namespace_?.toString();if(!n)return t;let r=new Map,a=new Set;await this.buildImportGraph(e,o,r,a);let i=this.detectCycle(n,r);if(i){let c=i.join(" \u2192 "),s=new u;s.ruleType=this.ruleName,s.severity="Error",s.message=`Circular namespace import detected: ${c}`,s.suggestion="Remove one of the imports to break the circular dependency, or \u2014 if one direction is a DATA reference rather than a schema dependency (an object-property value naming a resource in the other package) \u2014 mark that import `mode: link`: links are dereferenced on demand, are not in the closure, and are exempt from this rule. Circular dependencies prevent proper package resolution.",s.entityName="imports",s.propertyName="imports",s.actualValue=c,t.push(s)}return t}async buildImportGraph(e,o,t,n){let r=e.metadata.namespace_?.toString()??"";if(!(!r||n.has(r))&&(n.add(r),e.metadata.imports)){let a=[];for(let[i,c]of Object.entries(e.metadata.imports))for(let s of c){if(Q(s))continue;let l=`${i}/${s.packageName}@${s.version}`;a.push(l);let m=await o.getHighestCompatibleVersionAsync(i,s);m&&await this.buildImportGraph(m,o,t,n)}a.length>0&&t.set(r,a)}}detectCycle(e,o){let t=[],n=new Set;return this.detectCycleRecursive(e,o,t,n)}detectCycleRecursive(e,o,t,n){let r=t.indexOf(e);if(r>=0){let i=t.slice(r);return i.push(e),i}if(n.has(e))return null;t.push(e),n.add(e);let a=o.get(e);if(a)for(let i of a){let c=this.detectCycleRecursive(i,o,t,n);if(c)return c}return t.pop(),null}};var Ke=class{ruleName="UnresolvedPredicate";async validateAsync(e,o,t){let n=[],r=Ze(e);if(!r)return n;let a=await I(e,o,t);return L(a,({kanonak:i,path:c})=>{for(let s of i.unresolvedPredicates)s.sourceDoc===r&&n.push(this.unresolvedPredicateError(c,s.key))}),n}unresolvedPredicateError(e,o){let t=o.lastIndexOf("."),n=t>0?o.slice(0,t):null,r=t>0?o.slice(t+1):o,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=o,a.actualValue=o,a.expectedValue="A defined or imported property",a.message=`Property '${o}' is not defined or imported`,a.suggestion=n?`The property '${r}' was not found in the namespace imported as '${n}'.
9
9
  1. Check '${r}' is spelled correctly
10
10
  2. Verify '${n}' is imported with the right alias and version
11
11
  3. Ensure that namespace version actually defines '${r}'`:`The property '${o}' is not defined in this namespace or any imported namespace.
@@ -36,7 +36,7 @@ line (let the line run long), or check for an unterminated [[.`,n}};var Wo="kano
36
36
  Possible solutions:
37
37
  \u2022 Point ${o} at a property declared on this class (or an ancestor / rdfs.Resource)
38
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 Ct(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}function Z(p,e,o){let t=[];return We(p,o,{input:e},t),t}function We(p,e,o,t){if(A(e,F.VarRef)){let a=z(e,F.varName);return a?o[a]:void 0}if(A(e,F.PropertyRead)){let a=P(e,F.readSource),i=a?We(p,a,o,t):void 0,c=h(e,F.readProp);if(!i||!c)return;let s=W(p,i,c);if(!s.ok){t.push({contextClass:i,propertyUri:c,via:"PropertyRead"});return}return s.descriptor?.range}if(A(e,F.Traverse)){let a=P(e,F.traverseSource),i=a?We(p,a,o,t):void 0,c=h(e,F.through),s;if(i&&c){let m=W(p,i,c);m.ok?s=m.descriptor?.range:t.push({contextClass:i,propertyUri:c,via:"Traverse"})}let l=P(e,F.step);return l?We(p,l,{...o,input:s},t):void 0}let n=z(e,F.loopVar),r=n?{...o,[n]:void 0}:o;for(let a of Pt(e))We(p,a,r,t)}function Pt(p){let e=[];for(let o of p.statement){let t=o.object;if(t instanceof S)e.push(t);else if(Array.isArray(t))for(let n of t)n instanceof S&&e.push(n)}return e}var Fe="kanonak.org",qe="look",Ut={publisher:Fe,package_:qe,name:"semanticSvg"},At={publisher:Fe,package_:qe,name:"tierChip"},Nt={publisher:Fe,package_:qe,name:"tierIcon"},Tt={publisher:Fe,package_:qe,name:"tierCard"},xt={publisher:Fe,package_:qe,name:"tierFull"},_t=[At,Nt,Tt,xt],Ce=class{ruleName="LookSemanticSvgPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=Lt(e);if(!a)return n;for(let i of r)i instanceof g&&i.namespace===a&&this.checkSemanticSvg(r,i,n);return n}checkSemanticSvg(e,o,t){let n=P(o,Ut);if(!n)return;let r=T(o);if(r)for(let a of _t){let i=P(n,a);if(i)for(let c of Z(e,r,i))t.push(this.toError(o.name,a.name,c))}}toError(e,o,t){let n=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,r=t.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.${o}`,i.actualValue=n,i.message=`tx.${t.via} reads property '${t.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}'.
39
+ \u2022 Use rdfs.label / rdfs.comment for the universal default`,n}};function Ct(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}function X(p,e,o){let t=[];return We(p,o,{input:e},t),t}function We(p,e,o,t){if(A(e,F.VarRef)){let a=z(e,F.varName);return a?o[a]:void 0}if(A(e,F.PropertyRead)){let a=P(e,F.readSource),i=a?We(p,a,o,t):void 0,c=h(e,F.readProp);if(!i||!c)return;let s=W(p,i,c);if(!s.ok){t.push({contextClass:i,propertyUri:c,via:"PropertyRead"});return}return s.descriptor?.range}if(A(e,F.Traverse)){let a=P(e,F.traverseSource),i=a?We(p,a,o,t):void 0,c=h(e,F.through),s;if(i&&c){let m=W(p,i,c);m.ok?s=m.descriptor?.range:t.push({contextClass:i,propertyUri:c,via:"Traverse"})}let l=P(e,F.step);return l?We(p,l,{...o,input:s},t):void 0}let n=z(e,F.loopVar),r=n?{...o,[n]:void 0}:o;for(let a of Pt(e))We(p,a,r,t)}function Pt(p){let e=[];for(let o of p.statement){let t=o.object;if(t instanceof S)e.push(t);else if(Array.isArray(t))for(let n of t)n instanceof S&&e.push(n)}return e}var Fe="kanonak.org",qe="look",Ut={publisher:Fe,package_:qe,name:"semanticSvg"},At={publisher:Fe,package_:qe,name:"tierChip"},Nt={publisher:Fe,package_:qe,name:"tierIcon"},Tt={publisher:Fe,package_:qe,name:"tierCard"},xt={publisher:Fe,package_:qe,name:"tierFull"},_t=[At,Nt,Tt,xt],Ce=class{ruleName="LookSemanticSvgPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=Lt(e);if(!a)return n;for(let i of r)i instanceof g&&i.namespace===a&&this.checkSemanticSvg(r,i,n);return n}checkSemanticSvg(e,o,t){let n=P(o,Ut);if(!n)return;let r=T(o);if(r)for(let a of _t){let i=P(n,a);if(i)for(let c of X(e,r,i))t.push(this.toError(o.name,a.name,c))}}toError(e,o,t){let n=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,r=t.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.${o}`,i.actualValue=n,i.message=`tx.${t.via} reads property '${t.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
40
 
41
41
  Possible solutions:
42
42
  \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
@@ -46,12 +46,12 @@ Possible solutions:
46
46
  Possible solutions:
47
47
  \u2022 Rebuild the expression from tx primitives this SDK supports
48
48
  \u2022 For numeric presentation (rounding, percentages, fixed precision), use tx.NumberFormat \u2014 it scales internally, so no arithmetic is needed
49
- \u2022 If the node class should be supported, implement it in the runner first`,r}};function Wt(p){let e=[];for(let o of p.statement){let t=o.predicate?.subject;if(o instanceof G)e.push({child:o.object,predicate:t});else if(o instanceof M)for(let n of o.object)n instanceof S&&e.push({child:n,predicate:t})}return e}function Ft(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var qt="kanonak.org",He=(p,e)=>({publisher:qt,package_:p,name:e}),Ht=He("derivation","look"),Ho=He("look","bands"),Yo=He("look","Sequence"),Yt=He("core-rdf","range"),Gt=He("look","nodeTier"),Ue=class{ruleName="SequenceNarrative";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=zt(e);if(!a)return n;let i=r.filter(s=>s instanceof g&&s.namespace===a);if(i.length===0)return n;for(let s of i){let l=P(s,Ht);l&&v(l,Ho).forEach((m,d)=>{!(m instanceof S)||!A(m,Yo)||n.push(...this.checkBand(r,s,m,`${s.name}.look.bands[${d}]`))})}let c=new wo(r);for(let s of i){let l=c.findCascadedLook(s);if(l)for(let m of v(l.declaration,Ho))!(m instanceof S)||!A(m,Yo)||this.checkBand(r,s,m,"").length>0||n.push(...this.checkInstance(r,s,m,$o(r,s,m)))}return n}checkBand(e,o,t,n){let r=[],a=(l,m,d)=>r.push(this.toError("Error",o.name,n,l,m,d)),i=oo(t);if(!i)a("A look.Sequence band declares no look.source. The order of a sequence comes from the [[references]] in a prose property, so without one nothing can be sequenced.","Set look.source to a property of this class whose rdfs.range is prose.Markdown (or prose.SubstitutableString), and render the same property with a look.Markdown band so the narrative and the diagram cannot drift.");else{let l=bo(e,i)[0],m=l?Ro(l,Yt):[];l&&!m.some(d=>ko.isSubstitutableDatatypeUri(d))&&a(`look.source names '${i.name}', whose rdfs.range is ${m.map(d=>b(d)).join(", ")||"undeclared"} \u2014 not prose.Markdown. A Sequence orders its participants by the [[references]] in prose, so a value of this property carries no order.`,"Point look.source at a prose.Markdown-ranged property, or give this property that range if its values are narrative.",b(i))}let c=to(e,t);c.length===0&&a("A look.Sequence band declares no look.connectors, so no property counts as a message and every narrative renders empty.","List the object properties that constitute messages: look.connectors: [{ look.relation: calls }, ...]. The domain ontology declares nothing about sequences; the look layer says which of its relations are interactions.");for(let l of c)(!l.subject||B(e,l.subject)===void 0)&&a(`look.connectors names '${l.relation.name}' as a relation, but it is not a property${l.subject?"":" in the closure"}. A message is a triple, so its relation must be an object property whose values are the participants.`,"Use an owl.ObjectProperty (or a subclass such as owl.SymmetricProperty) for look.relation.",b(l.relation)),l.invalidStyle!==void 0&&a(`look.lineStyle '${l.invalidStyle}' on connector '${l.relation.name}' is not a supported value. Supported: ${[...Io].join(", ")}.`,"Use one of the supported values, or omit look.lineStyle: a reply is derived from owl.inverseOf and an undirected edge from owl.SymmetricProperty, so the overlay is only needed for what the ontology cannot say.",l.invalidStyle);let s=z(t,Gt);return s!==void 0&&no[s]===void 0&&a(`look.nodeTier '${s}' is not a tier. Supported: ${Object.keys(no).join(", ")}.`,"Use one of the semantic-zoom tiers \u2014 chip (56), icon (120, the default), card (240), full (420) \u2014 or omit look.nodeTier to take the participants' class-level look.diagramTier.",s),r}checkInstance(e,o,t,n){let r=[],a=oo(t),i=`${o.name}.${a.name}`,c=to(e,t).map(s=>s.relation.name).join(", ");if(n.problem)return r.push(this.toError("Error",o.name,i,`The look.Sequence band cannot walk this instance: ${n.problem}.`,"Check the value authored for the source property.")),r;if(n.sourceAbsent)return r.push(this.toError("Warning",o.name,i,`'${o.name}' carries no value for '${a.name}', so its look.Sequence band renders nothing.`,`Author the narrative in '${a.name}' with [[references]] to the participants, or leave it if the band is meant to be empty here.`)),r;for(let s of n.strayPropertyRefs)r.push(this.toError("Error",o.name,i,`The narrative references property '${s.name}', which is not a declared connector of the look.Sequence band (declared: ${c}). A property reference between two participants selects the edge for that pair; one the band does not declare selects nothing, and the sentence draws no message.`,`Add { look.relation: ${s.name} } to look.connectors on the band, or reference one of the declared connectors instead.`,b(s)));if(n.mentions>=2&&n.messages.length===0)return r.push(this.toError("Error",o.name,i,`The narrative mentions ${n.mentions} participant references but joins nothing: no declared connector (${c}) holds between any consecutive pair, so the look.Sequence band renders no message.`,"Either the graph is missing the triples the prose describes (declare them on the participants), the band is missing the relation the prose relies on (add it to look.connectors), or the prose orders participants no relation joins (reorder it).")),r;for(let s of n.gaps){let l=s.selected?`'${s.selected.name}' does not hold`:`no declared connector (${c}) holds`;r.push(this.toError("Warning",o.name,i,`The narrative orders '${s.prev.name}' then '${s.next.name}', but ${l} between them in the graph, so no message is drawn for that pair.`,`If the prose is right, declare the relation on '${s.prev.name}' or '${s.next.name}' (or add it to look.connectors); if the graph is right, reorder the prose so consecutive references are joined. A mention that is meant to connect to nothing is fine \u2014 it simply gets no lifeline.`,`${s.prev.name} \u2192 ${s.next.name}`))}return r}toError(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function zt(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Xt="kanonak.org",D=(p,e)=>({publisher:Xt,package_:p,name:e}),Zt=D("derivation","look"),Jt=D("look","bands"),Qt=D("look","Distribution"),en=D("look","StatRow"),on=D("look","VersionDelta"),tn=D("look","Timeline"),nn=D("look","VersionDiff"),rn=D("look","TimePlot"),an=D("look","ReferenceList"),sn=D("look","Diagram"),cn=D("look","alphaPath"),pn=D("look","betaPath"),po=D("look","metricPath"),Go=D("look","lowerPath"),zo=D("look","upperPath"),Xo=D("look","hueBy"),ln=D("look","statPath"),mn=D("look","laneBy"),Zo=D("look","labelPath"),un=D("look","badgePath"),dn=D("look","mapPath"),fn=D("look","nodeNote"),yn=D("look","edgeValue"),gn=D("look","stats"),kn=D("look","facets"),hn=D("look","channels"),Rn=D("look","track"),bn=D("look","source"),Kn=D("look","relation"),En=D("look","entries"),Ae=class{ruleName="LookBandPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=vn(e);if(!a)return n;for(let i of r)i instanceof g&&i.namespace===a&&this.checkDeclaration(r,i,n);return n}checkDeclaration(e,o,t){let n=P(o,Zt);if(!n)return;let r=T(o);if(!r)return;let a=v(n,Jt).filter(i=>i instanceof S);for(let i of a)for(let c of this.carriersOf(e,i,r))for(let s of Z(e,c.context,c.expr))t.push(this.toError(o.name,c.slot,s))}carriersOf(e,o,t){let n=[],r=(a,i)=>{let c=P(o,a);c&&n.push({slot:`look.${a.name}`,context:i,expr:c})};if(A(o,Qt))for(let a of[cn,pn,po,Go,zo,Xo])r(a,t);if(A(o,on)&&r(po,t),A(o,en)){let a=v(o,gn).filter(i=>i instanceof S);for(let i of a){let c=P(i,ln);c&&n.push({slot:"look.stats[].statPath",context:t,expr:c})}}if(A(o,tn)||A(o,nn)){let a=this.rangeOf(e,t,h(o,Rn));if(a)for(let i of[po,Go,zo,Xo])r(i,a)}if(A(o,rn)){let a=this.rangeOf(e,t,h(o,bn));if(a)for(let i of[mn,Zo])r(i,a)}if(A(o,an))for(let a of v(o,En)){let i=a instanceof S?void 0:Vn(a),c=this.rangeOf(e,t,i);if(c)for(let s of[Zo,un])r(s,c)}if(A(o,sn)){let a=v(o,kn).filter(i=>i instanceof S);for(let i of a){let c=this.rangeOf(e,t,h(i,Kn));if(!c)continue;let s=P(i,fn);s&&n.push({slot:"look.facets[].nodeNote",context:c,expr:s});let l=P(i,yn);l&&n.push({slot:"look.facets[].edgeValue",context:c,expr:l});let m=v(i,hn).filter(d=>d instanceof S);for(let d of m){let f=P(d,dn);f&&n.push({slot:"look.facets[].channels[].mapPath",context:c,expr:f})}}}return n}rangeOf(e,o,t){if(!t)return;let n=W(e,o,t);return n.ok?n.descriptor?.range:void 0}toError(e,o,t){let n=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,r=t.contextClass.name,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=o,a.actualValue=n,a.message=`tx.${t.via} reads property '${t.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}'.
49
+ \u2022 If the node class should be supported, implement it in the runner first`,r}};function Wt(p){let e=[];for(let o of p.statement){let t=o.predicate?.subject;if(o instanceof G)e.push({child:o.object,predicate:t});else if(o instanceof M)for(let n of o.object)n instanceof S&&e.push({child:n,predicate:t})}return e}function Ft(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var qt="kanonak.org",He=(p,e)=>({publisher:qt,package_:p,name:e}),Ht=He("derivation","look"),Ho=He("look","bands"),Yo=He("look","Sequence"),Yt=He("core-rdf","range"),Gt=He("look","nodeTier"),Ue=class{ruleName="SequenceNarrative";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=zt(e);if(!a)return n;let i=r.filter(s=>s instanceof g&&s.namespace===a);if(i.length===0)return n;for(let s of i){let l=P(s,Ht);l&&v(l,Ho).forEach((m,d)=>{!(m instanceof S)||!A(m,Yo)||n.push(...this.checkBand(r,s,m,`${s.name}.look.bands[${d}]`))})}let c=new wo(r);for(let s of i){let l=c.findCascadedLook(s);if(l)for(let m of v(l.declaration,Ho))!(m instanceof S)||!A(m,Yo)||this.checkBand(r,s,m,"").length>0||n.push(...this.checkInstance(r,s,m,$o(r,s,m)))}return n}checkBand(e,o,t,n){let r=[],a=(l,m,d)=>r.push(this.toError("Error",o.name,n,l,m,d)),i=oo(t);if(!i)a("A look.Sequence band declares no look.source. The order of a sequence comes from the [[references]] in a prose property, so without one nothing can be sequenced.","Set look.source to a property of this class whose rdfs.range is prose.Markdown (or prose.SubstitutableString), and render the same property with a look.Markdown band so the narrative and the diagram cannot drift.");else{let l=bo(e,i)[0],m=l?Ro(l,Yt):[];l&&!m.some(d=>ko.isSubstitutableDatatypeUri(d))&&a(`look.source names '${i.name}', whose rdfs.range is ${m.map(d=>b(d)).join(", ")||"undeclared"} \u2014 not prose.Markdown. A Sequence orders its participants by the [[references]] in prose, so a value of this property carries no order.`,"Point look.source at a prose.Markdown-ranged property, or give this property that range if its values are narrative.",b(i))}let c=to(e,t);c.length===0&&a("A look.Sequence band declares no look.connectors, so no property counts as a message and every narrative renders empty.","List the object properties that constitute messages: look.connectors: [{ look.relation: calls }, ...]. The domain ontology declares nothing about sequences; the look layer says which of its relations are interactions.");for(let l of c)(!l.subject||B(e,l.subject)===void 0)&&a(`look.connectors names '${l.relation.name}' as a relation, but it is not a property${l.subject?"":" in the closure"}. A message is a triple, so its relation must be an object property whose values are the participants.`,"Use an owl.ObjectProperty (or a subclass such as owl.SymmetricProperty) for look.relation.",b(l.relation)),l.invalidStyle!==void 0&&a(`look.lineStyle '${l.invalidStyle}' on connector '${l.relation.name}' is not a supported value. Supported: ${[...Io].join(", ")}.`,"Use one of the supported values, or omit look.lineStyle: a reply is derived from owl.inverseOf and an undirected edge from owl.SymmetricProperty, so the overlay is only needed for what the ontology cannot say.",l.invalidStyle);let s=z(t,Gt);return s!==void 0&&no[s]===void 0&&a(`look.nodeTier '${s}' is not a tier. Supported: ${Object.keys(no).join(", ")}.`,"Use one of the semantic-zoom tiers \u2014 chip (56), icon (120, the default), card (240), full (420) \u2014 or omit look.nodeTier to take the participants' class-level look.diagramTier.",s),r}checkInstance(e,o,t,n){let r=[],a=oo(t),i=`${o.name}.${a.name}`,c=to(e,t).map(s=>s.relation.name).join(", ");if(n.problem)return r.push(this.toError("Error",o.name,i,`The look.Sequence band cannot walk this instance: ${n.problem}.`,"Check the value authored for the source property.")),r;if(n.sourceAbsent)return r.push(this.toError("Warning",o.name,i,`'${o.name}' carries no value for '${a.name}', so its look.Sequence band renders nothing.`,`Author the narrative in '${a.name}' with [[references]] to the participants, or leave it if the band is meant to be empty here.`)),r;for(let s of n.strayPropertyRefs)r.push(this.toError("Error",o.name,i,`The narrative references property '${s.name}', which is not a declared connector of the look.Sequence band (declared: ${c}). A property reference between two participants selects the edge for that pair; one the band does not declare selects nothing, and the sentence draws no message.`,`Add { look.relation: ${s.name} } to look.connectors on the band, or reference one of the declared connectors instead.`,b(s)));if(n.mentions>=2&&n.messages.length===0)return r.push(this.toError("Error",o.name,i,`The narrative mentions ${n.mentions} participant references but joins nothing: no declared connector (${c}) holds between any consecutive pair, so the look.Sequence band renders no message.`,"Either the graph is missing the triples the prose describes (declare them on the participants), the band is missing the relation the prose relies on (add it to look.connectors), or the prose orders participants no relation joins (reorder it).")),r;for(let s of n.gaps){let l=s.selected?`'${s.selected.name}' does not hold`:`no declared connector (${c}) holds`;r.push(this.toError("Warning",o.name,i,`The narrative orders '${s.prev.name}' then '${s.next.name}', but ${l} between them in the graph, so no message is drawn for that pair.`,`If the prose is right, declare the relation on '${s.prev.name}' or '${s.next.name}' (or add it to look.connectors); if the graph is right, reorder the prose so consecutive references are joined. A mention that is meant to connect to nothing is fine \u2014 it simply gets no lifeline.`,`${s.prev.name} \u2192 ${s.next.name}`))}return r}toError(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function zt(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Zt="kanonak.org",D=(p,e)=>({publisher:Zt,package_:p,name:e}),Xt=D("derivation","look"),Jt=D("look","bands"),Qt=D("look","Distribution"),en=D("look","StatRow"),on=D("look","VersionDelta"),tn=D("look","Timeline"),nn=D("look","VersionDiff"),rn=D("look","TimePlot"),an=D("look","ReferenceList"),sn=D("look","Diagram"),cn=D("look","alphaPath"),pn=D("look","betaPath"),po=D("look","metricPath"),Go=D("look","lowerPath"),zo=D("look","upperPath"),Zo=D("look","hueBy"),ln=D("look","statPath"),mn=D("look","laneBy"),Xo=D("look","labelPath"),un=D("look","badgePath"),dn=D("look","mapPath"),fn=D("look","nodeNote"),yn=D("look","edgeValue"),gn=D("look","stats"),kn=D("look","facets"),hn=D("look","channels"),Rn=D("look","track"),bn=D("look","source"),Kn=D("look","relation"),En=D("look","entries"),Ae=class{ruleName="LookBandPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=vn(e);if(!a)return n;for(let i of r)i instanceof g&&i.namespace===a&&this.checkDeclaration(r,i,n);return n}checkDeclaration(e,o,t){let n=P(o,Xt);if(!n)return;let r=T(o);if(!r)return;let a=v(n,Jt).filter(i=>i instanceof S);for(let i of a)for(let c of this.carriersOf(e,i,r))for(let s of X(e,c.context,c.expr))t.push(this.toError(o.name,c.slot,s))}carriersOf(e,o,t){let n=[],r=(a,i)=>{let c=P(o,a);c&&n.push({slot:`look.${a.name}`,context:i,expr:c})};if(A(o,Qt))for(let a of[cn,pn,po,Go,zo,Zo])r(a,t);if(A(o,on)&&r(po,t),A(o,en)){let a=v(o,gn).filter(i=>i instanceof S);for(let i of a){let c=P(i,ln);c&&n.push({slot:"look.stats[].statPath",context:t,expr:c})}}if(A(o,tn)||A(o,nn)){let a=this.rangeOf(e,t,h(o,Rn));if(a)for(let i of[po,Go,zo,Zo])r(i,a)}if(A(o,rn)){let a=this.rangeOf(e,t,h(o,bn));if(a)for(let i of[mn,Xo])r(i,a)}if(A(o,an))for(let a of v(o,En)){let i=a instanceof S?void 0:Vn(a),c=this.rangeOf(e,t,i);if(c)for(let s of[Xo,un])r(s,c)}if(A(o,sn)){let a=v(o,kn).filter(i=>i instanceof S);for(let i of a){let c=this.rangeOf(e,t,h(i,Kn));if(!c)continue;let s=P(i,fn);s&&n.push({slot:"look.facets[].nodeNote",context:c,expr:s});let l=P(i,yn);l&&n.push({slot:"look.facets[].edgeValue",context:c,expr:l});let m=v(i,hn).filter(d=>d instanceof S);for(let d of m){let f=P(d,dn);f&&n.push({slot:"look.facets[].channels[].mapPath",context:c,expr:f})}}}return n}rangeOf(e,o,t){if(!t)return;let n=W(e,o,t);return n.ok?n.descriptor?.range:void 0}toError(e,o,t){let n=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,r=t.contextClass.name,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=o,a.actualValue=n,a.message=`tx.${t.via} reads property '${t.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}'.
50
50
 
51
51
  Possible solutions:
52
52
  \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
53
53
  \u2022 If the property should apply to '${r}', adjust its domain
54
- \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,a}};function Vn(p){let e=p.subject;return e&&typeof e.name=="string"?e:void 0}function vn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Dn="kanonak.org",lo=(p,e)=>({publisher:Dn,package_:p,name:e}),Sn=lo("derivation","look"),In=lo("look","bands"),$n=lo("core-rdf","type"),Ye=class{ruleName="UnrenderableBand";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=jn(e);if(!a)return n;let i=Co();for(let c of r){if(!(c instanceof g)||c.namespace!==a)continue;let s=P(c,Sn);if(!s)continue;let l=v(s,In).filter(m=>m instanceof S);for(let m of l){let d=this.typeOf(m);if(!d)continue;let f=`${d.publisher}/${d.package_}/${d.name}`;if(i.has(f))continue;let y=new u;y.ruleType=this.ruleName,y.severity="Warning",y.entityName=c.name,y.propertyName="derivation.look",y.actualValue=f,y.message=`Band '${d.name}' has no renderer, so this region of the page will be empty. The declaration is valid against the look vocabulary, but the renderer emits only an HTML comment for it \u2014 which a browser does not display, so the loss is silent. Use a band the renderer implements, or remove it until it is supported.`,n.push(y)}}return n}typeOf(e){let o=h(e,$n);if(o)return{publisher:o.publisher,package_:o.package_,name:o.name}}};function jn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Te="kanonak.org",xe="view",On={publisher:Te,package_:xe,name:"bind"},wn={publisher:Te,package_:xe,name:"produces"},Cn={publisher:Te,package_:xe,name:"projections"},Pn={publisher:Te,package_:xe,name:"where"},Un={publisher:Te,package_:xe,name:"value"},An={publisher:Te,package_:xe,name:"as"},Ne=class{ruleName="TxExpressionPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=xn(e);if(!a)return n;for(let i of r)i instanceof g&&i.namespace===a&&this.checkView(r,i,n);return n}checkView(e,o,t){let n=h(o,On);if(!n)return;let r=h(o,wn),a=0;for(let c of Tn(e,v(o,Cn))){let s=P(c,Un);if(s)for(let m of Z(e,n,s))t.push(this.toError(o.name,`view.projections[${a}].value`,n,m));let l=h(c,An);l&&r&&(W(e,r,l).ok||t.push(this.asError(o.name,a,r,l))),a+=1}let i=0;for(let c of Nn(o,Pn)){for(let s of Z(e,n,c))t.push(this.toError(o.name,`view.where[${i}]`,n,s));i+=1}}asError(e,o,t,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[${o}].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 '${t.name}'. The materialized result instance could not carry this value.`,a.expectedValue=`A property whose domain is '${t.name}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${r}' is not in scope for produces class '${t.name}'.
54
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,a}};function Vn(p){let e=p.subject;return e&&typeof e.name=="string"?e:void 0}function vn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Dn="kanonak.org",lo=(p,e)=>({publisher:Dn,package_:p,name:e}),Sn=lo("derivation","look"),In=lo("look","bands"),$n=lo("core-rdf","type"),Ye=class{ruleName="UnrenderableBand";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=jn(e);if(!a)return n;let i=Co();for(let c of r){if(!(c instanceof g)||c.namespace!==a)continue;let s=P(c,Sn);if(!s)continue;let l=v(s,In).filter(m=>m instanceof S);for(let m of l){let d=this.typeOf(m);if(!d)continue;let f=`${d.publisher}/${d.package_}/${d.name}`;if(i.has(f))continue;let y=new u;y.ruleType=this.ruleName,y.severity="Warning",y.entityName=c.name,y.propertyName="derivation.look",y.actualValue=f,y.message=`Band '${d.name}' has no renderer, so this region of the page will be empty. The declaration is valid against the look vocabulary, but the renderer emits only an HTML comment for it \u2014 which a browser does not display, so the loss is silent. Use a band the renderer implements, or remove it until it is supported.`,n.push(y)}}return n}typeOf(e){let o=h(e,$n);if(o)return{publisher:o.publisher,package_:o.package_,name:o.name}}};function jn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Te="kanonak.org",xe="view",On={publisher:Te,package_:xe,name:"bind"},wn={publisher:Te,package_:xe,name:"produces"},Cn={publisher:Te,package_:xe,name:"projections"},Pn={publisher:Te,package_:xe,name:"where"},Un={publisher:Te,package_:xe,name:"value"},An={publisher:Te,package_:xe,name:"as"},Ne=class{ruleName="TxExpressionPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=xn(e);if(!a)return n;for(let i of r)i instanceof g&&i.namespace===a&&this.checkView(r,i,n);return n}checkView(e,o,t){let n=h(o,On);if(!n)return;let r=h(o,wn),a=0;for(let c of Tn(e,v(o,Cn))){let s=P(c,Un);if(s)for(let m of X(e,n,s))t.push(this.toError(o.name,`view.projections[${a}].value`,n,m));let l=h(c,An);l&&r&&(W(e,r,l).ok||t.push(this.asError(o.name,a,r,l))),a+=1}let i=0;for(let c of Nn(o,Pn)){for(let s of X(e,n,c))t.push(this.toError(o.name,`view.where[${i}]`,n,s));i+=1}}asError(e,o,t,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[${o}].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 '${t.name}'. The materialized result instance could not carry this value.`,a.expectedValue=`A property whose domain is '${t.name}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${r}' is not in scope for produces class '${t.name}'.
55
55
 
56
56
  Possible solutions:
57
57
  \u2022 Use an output property whose domain covers '${t.name}'
@@ -61,7 +61,7 @@ Possible solutions:
61
61
  Possible solutions:
62
62
  \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
63
63
  \u2022 If the property should apply to '${a}', adjust its domain
64
- \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,c}};function Nn(p,e){let o=P(p,e);return o?[o]:v(p,e).filter(t=>t instanceof S)}function Tn(p,e){let o=[];for(let t of e)if(t instanceof S)o.push(t);else if(t instanceof O){let n=V(p,t.subject);n&&o.push(n)}return o}function xn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Qe="kanonak.org",_n="core-shacl",x=p=>({publisher:Qe,package_:_n,name:p}),Ln=x("NodeShape"),Mn=x("PropertyShape"),Bn=x("targetClass"),Wn=x("property"),Fn=x("path"),qn=x("minCount"),Hn=x("maxCount"),Yn=x("datatype"),Gn=x("class"),Jo=x("in"),zn=x("pattern"),Xn=x("flags"),Zn=x("minLength"),Jn=x("maxLength"),Qn=x("minInclusive"),er=x("maxInclusive"),or=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),Qo=p=>p,Le=class{ruleName="ShaclShape";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=tr(e);if(!a)return n;let i=new Set;for(let c of r){if(!(c instanceof g)||c.namespace!==a||!A(c,Ln))continue;let s=h(c,Bn);s?this.resolvesToClass(r,s)||n.push(this.err(c.name,"targetClass","Error",`NodeShape '${c.name}' sh:targetClass '${s.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(s))):n.push(this.err(c.name,"targetClass","Error",`NodeShape '${c.name}' has no sh:targetClass; it constrains nothing.`,"Add sh:targetClass naming the class this shape applies to."));for(let l of v(c,Wn)){let m;if(l instanceof S)m=l;else if(l instanceof O){let d=V(r,l.subject);d&&(m=d,i.add(b(l.subject)))}m&&this.checkPropertyShape(r,c.name,m,s??void 0,n)}}for(let c of r){if(!(c instanceof g)||c.namespace!==a||!A(c,Mn))continue;let s=T(c);s&&i.has(b(s))||this.checkPropertyShape(r,c.name,c,void 0,n)}return n}checkPropertyShape(e,o,t,n,r){let a=h(t,Fn);if(!a){r.push(this.err(o,"property.path","Error",`A PropertyShape on '${o}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=V(e,a),c=i?Y(e,i):!1;c?n&&(W(e,n,a).ok||r.push(this.err(o,"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(o,"property.path","Error",`sh:path '${a.name}' on '${o}' does not resolve to a property.`,"Reference a defined or imported property.",J(a)));let s=h(t,Yn),l=h(t,Gn);s&&l&&r.push(this.err(o,"property","Error",`A PropertyShape on '${o}' 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.")),s&&!this.resolvesToDatatype(e,s)&&r.push(this.err(o,"datatype","Error",`sh:datatype '${s.name}' on '${o}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",J(s))),l&&!this.resolvesToClass(e,l)&&r.push(this.err(o,"class","Error",`sh:class '${l.name}' on '${o}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(l)));let m=_e(X(t,qn)),d=_e(X(t,Hn));this.checkOrder(o,"minCount",m,"maxCount",d,r);let f=_e(X(t,Zn)),y=_e(X(t,Jn));this.checkOrder(o,"minLength",f,"maxLength",y,r);let k=_e(X(t,Qn)),K=_e(X(t,er));this.checkOrder(o,"minInclusive",k,"maxInclusive",K,r);let E=z(t,zn);if(E!==void 0){let U=z(t,Xn);try{new RegExp(E,U)}catch{r.push(this.err(o,"pattern","Error",`sh:pattern on '${o}' is not a valid regular expression`+(U!==void 0?` (with flags '${U}')`:"")+`: ${E}`,"Provide a valid regular expression and flags.",E))}}if(oe(t,Jo)&&v(t,Jo).length===0&&r.push(this.err(o,"in","Error",`sh:in on '${o}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),c&&n){let N=W(e,n,a).descriptor;N&&((E!==void 0||f!==void 0||y!==void 0)&&N.kind==="object"&&r.push(this.err(o,"pattern/minLength/maxLength","Warning",`String facets on '${o}' 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))),(k!==void 0||K!==void 0)&&!this.isNumericDatatypeRange(N.range)&&r.push(this.err(o,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${o}' apply to '${a.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",J(a))))}}checkOrder(e,o,t,n,r,a){t!==void 0&&r!==void 0&&t>r&&a.push(this.err(e,`${o}/${n}`,"Error",`${o} (${t}) exceeds ${n} (${r}) on '${e}'.`,`Set ${o} <= ${n}.`))}resolvesToClass(e,o){let t=V(e,o);return t?$.isClassType(Qo(t)):!1}resolvesToDatatype(e,o){if(o.publisher===Qe&&o.package_==="core-rdf"&&o.name==="Literal")return!0;let t=V(e,o);return t?$.isDatatypeType(Qo(t)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Qe&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Qe&&e.package_==="core-xsd"&&or.has(e.name)}err(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=t,i.entityName=e,i.propertyName=o,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function _e(p){return typeof p=="number"?p:void 0}function J(p){return`${p.publisher}/${p.package_}/${p.name}`}function tr(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var et={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},nr=p=>p,Me=class{ruleName="OwlOneOf";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=rr(e);if(!a)return n;for(let i of r){if(!(i instanceof g)||i.namespace!==a||!oe(i,et))continue;let c=v(i,et);if(c.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 s of c)if(s instanceof go)n.push(this.err(i.name,"Error",`owl:oneOf member '${String(s.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(s.value)));else if(s instanceof O){let l=V(r,s.subject);l&&$.isSchemaDefinitionType(nr(l))&&n.push(this.err(i.name,"Error",`owl:oneOf member '${s.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${s.subject.publisher}/${s.subject.package_}/${s.subject.name}`))}}return n}err(e,o,t,n,r){let a=new u;return a.ruleType=this.ruleName,a.severity=o,a.entityName=e,a.propertyName="oneOf",a.message=t,a.suggestion=n,r!==void 0&&(a.actualValue=r),a}};function rr(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var ar=p=>p,ir=new yo("kanonak.org","core-rdf","Resource"),Be=class{ruleName="DiamondNameClash";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=sr(e);if(!a)return n;let i=jo(r);for(let c of r){if(!(c instanceof g)||c.namespace!==a||!$.isClassType(ar(c)))continue;let s=T(c);if(!s)continue;let l=H(r,s),m=b(s),d=new Set(l.map(y=>b(y)));d.delete(m),d.delete(b(ir));let f=new Map;for(let y of Eo(r,s)){if(!y.domains.some(E=>d.has(b(E))))continue;let K=f.get(y.uri.name);K?K.push(y):f.set(y.uri.name,[y])}for(let[y,k]of f){if(k.length<2)continue;let K=N=>Oo(i,l,N.uri)?.cardinality,E=new Set(k.map(N=>N.range?b(N.range):void 0).filter(N=>N!==void 0)),U=new Set(k.map(K).filter(N=>N!==void 0));E.size<=1&&U.size<=1||n.push(this.toError(c.name,y,k,K))}}return n}toError(e,o,t,n){let r=c=>{let s=`${c.uri.publisher}/${c.uri.package_}/${c.uri.name}`,l=c.range?`${c.range.publisher}/${c.range.package_}/${c.range.name}`:"no range",m=n(c);return`${s} (range ${l}${m?`, ${m}`:""})`},a=t.map(r).join("; "),i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=o,i.actualValue=a,i.message=`Class '${e}' inherits ${t.length} distinct properties named '${o}' with incompatible range or cardinality: ${a}. The generated interface would multiply-inherit '${o}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${o}':
64
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,c}};function Nn(p,e){let o=P(p,e);return o?[o]:v(p,e).filter(t=>t instanceof S)}function Tn(p,e){let o=[];for(let t of e)if(t instanceof S)o.push(t);else if(t instanceof O){let n=V(p,t.subject);n&&o.push(n)}return o}function xn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var Qe="kanonak.org",_n="core-shacl",x=p=>({publisher:Qe,package_:_n,name:p}),Ln=x("NodeShape"),Mn=x("PropertyShape"),Bn=x("targetClass"),Wn=x("property"),Fn=x("path"),qn=x("minCount"),Hn=x("maxCount"),Yn=x("datatype"),Gn=x("class"),Jo=x("in"),zn=x("pattern"),Zn=x("flags"),Xn=x("minLength"),Jn=x("maxLength"),Qn=x("minInclusive"),er=x("maxInclusive"),or=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),Qo=p=>p,Le=class{ruleName="ShaclShape";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=tr(e);if(!a)return n;let i=new Set;for(let c of r){if(!(c instanceof g)||c.namespace!==a||!A(c,Ln))continue;let s=h(c,Bn);s?this.resolvesToClass(r,s)||n.push(this.err(c.name,"targetClass","Error",`NodeShape '${c.name}' sh:targetClass '${s.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(s))):n.push(this.err(c.name,"targetClass","Error",`NodeShape '${c.name}' has no sh:targetClass; it constrains nothing.`,"Add sh:targetClass naming the class this shape applies to."));for(let l of v(c,Wn)){let m;if(l instanceof S)m=l;else if(l instanceof O){let d=V(r,l.subject);d&&(m=d,i.add(b(l.subject)))}m&&this.checkPropertyShape(r,c.name,m,s??void 0,n)}}for(let c of r){if(!(c instanceof g)||c.namespace!==a||!A(c,Mn))continue;let s=T(c);s&&i.has(b(s))||this.checkPropertyShape(r,c.name,c,void 0,n)}return n}checkPropertyShape(e,o,t,n,r){let a=h(t,Fn);if(!a){r.push(this.err(o,"property.path","Error",`A PropertyShape on '${o}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=V(e,a),c=i?Y(e,i):!1;c?n&&(W(e,n,a).ok||r.push(this.err(o,"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(o,"property.path","Error",`sh:path '${a.name}' on '${o}' does not resolve to a property.`,"Reference a defined or imported property.",J(a)));let s=h(t,Yn),l=h(t,Gn);s&&l&&r.push(this.err(o,"property","Error",`A PropertyShape on '${o}' 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.")),s&&!this.resolvesToDatatype(e,s)&&r.push(this.err(o,"datatype","Error",`sh:datatype '${s.name}' on '${o}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",J(s))),l&&!this.resolvesToClass(e,l)&&r.push(this.err(o,"class","Error",`sh:class '${l.name}' on '${o}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(l)));let m=_e(Z(t,qn)),d=_e(Z(t,Hn));this.checkOrder(o,"minCount",m,"maxCount",d,r);let f=_e(Z(t,Xn)),y=_e(Z(t,Jn));this.checkOrder(o,"minLength",f,"maxLength",y,r);let k=_e(Z(t,Qn)),K=_e(Z(t,er));this.checkOrder(o,"minInclusive",k,"maxInclusive",K,r);let E=z(t,zn);if(E!==void 0){let U=z(t,Zn);try{new RegExp(E,U)}catch{r.push(this.err(o,"pattern","Error",`sh:pattern on '${o}' is not a valid regular expression`+(U!==void 0?` (with flags '${U}')`:"")+`: ${E}`,"Provide a valid regular expression and flags.",E))}}if(oe(t,Jo)&&v(t,Jo).length===0&&r.push(this.err(o,"in","Error",`sh:in on '${o}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),c&&n){let N=W(e,n,a).descriptor;N&&((E!==void 0||f!==void 0||y!==void 0)&&N.kind==="object"&&r.push(this.err(o,"pattern/minLength/maxLength","Warning",`String facets on '${o}' 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))),(k!==void 0||K!==void 0)&&!this.isNumericDatatypeRange(N.range)&&r.push(this.err(o,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${o}' apply to '${a.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",J(a))))}}checkOrder(e,o,t,n,r,a){t!==void 0&&r!==void 0&&t>r&&a.push(this.err(e,`${o}/${n}`,"Error",`${o} (${t}) exceeds ${n} (${r}) on '${e}'.`,`Set ${o} <= ${n}.`))}resolvesToClass(e,o){let t=V(e,o);return t?$.isClassType(Qo(t)):!1}resolvesToDatatype(e,o){if(o.publisher===Qe&&o.package_==="core-rdf"&&o.name==="Literal")return!0;let t=V(e,o);return t?$.isDatatypeType(Qo(t)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Qe&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Qe&&e.package_==="core-xsd"&&or.has(e.name)}err(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=t,i.entityName=e,i.propertyName=o,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function _e(p){return typeof p=="number"?p:void 0}function J(p){return`${p.publisher}/${p.package_}/${p.name}`}function tr(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var et={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},nr=p=>p,Me=class{ruleName="OwlOneOf";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=rr(e);if(!a)return n;for(let i of r){if(!(i instanceof g)||i.namespace!==a||!oe(i,et))continue;let c=v(i,et);if(c.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 s of c)if(s instanceof go)n.push(this.err(i.name,"Error",`owl:oneOf member '${String(s.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(s.value)));else if(s instanceof O){let l=V(r,s.subject);l&&$.isSchemaDefinitionType(nr(l))&&n.push(this.err(i.name,"Error",`owl:oneOf member '${s.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${s.subject.publisher}/${s.subject.package_}/${s.subject.name}`))}}return n}err(e,o,t,n,r){let a=new u;return a.ruleType=this.ruleName,a.severity=o,a.entityName=e,a.propertyName="oneOf",a.message=t,a.suggestion=n,r!==void 0&&(a.actualValue=r),a}};function rr(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${C(e.version)}`}var ar=p=>p,ir=new yo("kanonak.org","core-rdf","Resource"),Be=class{ruleName="DiamondNameClash";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=sr(e);if(!a)return n;let i=jo(r);for(let c of r){if(!(c instanceof g)||c.namespace!==a||!$.isClassType(ar(c)))continue;let s=T(c);if(!s)continue;let l=H(r,s),m=b(s),d=new Set(l.map(y=>b(y)));d.delete(m),d.delete(b(ir));let f=new Map;for(let y of Eo(r,s)){if(!y.domains.some(E=>d.has(b(E))))continue;let K=f.get(y.uri.name);K?K.push(y):f.set(y.uri.name,[y])}for(let[y,k]of f){if(k.length<2)continue;let K=N=>Oo(i,l,N.uri)?.cardinality,E=new Set(k.map(N=>N.range?b(N.range):void 0).filter(N=>N!==void 0)),U=new Set(k.map(K).filter(N=>N!==void 0));E.size<=1&&U.size<=1||n.push(this.toError(c.name,y,k,K))}}return n}toError(e,o,t,n){let r=c=>{let s=`${c.uri.publisher}/${c.uri.package_}/${c.uri.name}`,l=c.range?`${c.range.publisher}/${c.range.package_}/${c.range.name}`:"no range",m=n(c);return`${s} (range ${l}${m?`, ${m}`:""})`},a=t.map(r).join("; "),i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=o,i.actualValue=a,i.message=`Class '${e}' inherits ${t.length} distinct properties named '${o}' with incompatible range or cardinality: ${a}. The generated interface would multiply-inherit '${o}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${o}':
65
65
  \u2022 rename one of the properties, or
66
66
  \u2022 re-domain one so it is not inherited by '${e}', or
67
67
  \u2022 restructure the hierarchy so '${e}' inherits only one '${o}', or
@@ -0,0 +1 @@
1
+ import{a as m,b as E,i as U,m as B}from"./chunk-PVUBHIU2.js";import{a as K}from"./chunk-HF5FJBS2.js";import{ba as _,c as D}from"./chunk-7UYXTYXC.js";import{C as N,b as j,c as d,d as p,f as R,g as $,h as A,i as v,j as S,k as V,l as g}from"./chunk-CJMVIOZX.js";import{b as C,e as l}from"./chunk-QILEJIFU.js";import*as P from"js-yaml";import{canonicalForm as Y,canonicalHash as ee}from"@kanonak-protocol/canonical";function k(n){return typeof n=="object"&&n!==null&&Array.isArray(n.subjects)}import{CANONICAL_FORM_VERSION as Pe}from"@kanonak-protocol/canonical";function ke(n){return Y(k(n)?n:F(n))}function O(n){return ee(k(n)?n:F(n))}function F(n){let e=[];for(let t of n)t instanceof d&&e.push({uri:se(t),statements:h(t.statement)});return{subjects:e}}function h(n){let e=[];for(let t of n){let r=ie(t);if(!r)continue;if(t instanceof g&&ne(t.predicate.subject)){e.push(...re(t,r));continue}let o=oe(t);o&&e.push({predicate:r,value:o})}return e}function ne(n){let e=_("type");return e!==void 0&&n.name==="type"&&n.publisher===e.publisher&&n.package_===e.package_}var H=new TextEncoder;function te(n,e){let t=H.encode(n),r=H.encode(e),o=Math.min(t.length,r.length);for(let a=0;a<o;a++)if(t[a]!==r[a])return t[a]-r[a];return t.length-r.length}function re(n,e){let t=[];for(let r of n.object){if(!(r instanceof p))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(b(r))}t.sort(te);for(let r=1;r<t.length;r++)if(t[r-1]===t[r])throw new Error(`canonicalForm: duplicate type ${t[r]} in a multi-valued type statement`);return t.map(r=>({predicate:e,value:{ref:r}}))}function oe(n){if(n instanceof R&&n.carrier)return{lit:n.lexical??String(n.object),datatype:z(n.carrier)};if(n instanceof $)return{raw:n.object};if(n instanceof A)return{raw:n.lexical??String(n.object)};if(n instanceof v)return{raw:n.lexical??String(n.object)};if(n instanceof S)return{ref:b(n.object)};if(n instanceof V)return M(n.object);if(n instanceof g)return{list:n.object.map(ae)}}function M(n){let e=h(n.statement);return n.name&&n.name.length>0?{embed:{name:n.name,statements:e}}:{embed:{statements:e}}}function ae(n){if(n instanceof p)return{ref:b(n)};if(n instanceof m)return M(n);if(n instanceof E){if(n.carrier)return{lit:n.lexical??String(n.value),datatype:z(n.carrier)};let e=n.value;if(typeof e=="string")return{raw:e};if(typeof e=="number")return{raw:String(e)};if(typeof e=="boolean")return{raw:String(e)}}if(n instanceof j)return{embed:{statements:h(n.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${n.constructor?.name??typeof n}); add canonicalization support before hashing data that contains it`)}function z(n){return n===U.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${n}`}function ie(n){let e=n.predicate;if(e)return L(e.subject)}function se(n){let e=n.namespace??"",t=n.name??"";return`${e}/${t}`}function b(n){return L(n.subject)}function L(n){let e=n.version;return e&&typeof e.major=="number"?`${n.publisher}/${n.package_}@${e.major}.${e.minor}.${e.patch}/${n.name}`:`${n.publisher}/${n.package_}/${n.name}`}import{VersionOperator as T}from"@kanonak-protocol/types/document/models/enums";var ce="0.0.0",w=class{constructor(e,t=new K,r){this.repository=e;this.parser=t;this.objectParser=r??new B(this.parser)}repository;parser;objectParser;imports(){return new f}serializeValue(e,t){return G(e,t)}async buildContentAddressed(e){let t=e.book.toImports(),r=await this.hashBody(e.publisher,t,e.body),o=Z(r),a={type:"EphemeralPackage",publisher:e.publisher,imports:t};e.contentHashProperty&&(a[e.contentHashProperty]=r),Object.assign(a,e.header??{}),a.imports=t;let i={[o]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:W(s),contentHash:r,packageName:o,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let t=e.book.toImports(),r={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:t},o;e.contentHashProperty&&(o=await this.hashBody(e.publisher,t,e.body),r[e.contentHashProperty]=o),Object.assign(r,e.header??{}),r.imports=t;let a={[e.name]:r,...e.body},i=this.dump(a),s={yaml:i,byteCount:W(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return o!==void 0&&(s.contentHash=o),s}dump(e){return P.dump(e,{lineWidth:-1})}async hashBody(e,t,r){let o={[q]:{type:"EphemeralPackage",publisher:e,imports:t},...r},a=this.parser.parse(P.dump(o,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new N(a,this.repository))).filter(u=>u instanceof d&&u.namespace===i&&u.name!==q);for(let u of c)u.namespace="ephemeral";return O(c)}},q="__pkgbuilder_probe__";function W(n){return new TextEncoder().encode(n).length}function Z(n){let e="sha256:",t=n.startsWith(e)?e.length:0;return`q-${n.slice(t,t+16)}`}var f=class{byKey=new Map;aliases=new Set;ensure(e,t,r,o,a=T.Major){let i=`${e}/${t}@${r}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(o);return this.byKey.set(i,{publisher:e,package_:t,version:r,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_,l(e.version),e.package_)}.${e.name}`}refLatest(e,t,r,o){return`${this.ensure(e,t,ce,o??t,T.Any)}.${r}`}toImports(){let e=new Map;for(let r of this.byKey.values()){let o=e.get(r.publisher)??[];o.push(r),e.set(r.publisher,o)}return[...e.keys()].sort().map(r=>({publisher:r,packages:e.get(r).sort((o,a)=>o.package_<a.package_?-1:1).map(o=>({package:o.package_,match:C(o.match),version:o.version,alias:o.alias}))}))}uniqueAlias(e){let t=J(e)||"pkg",r=t,o=2;for(;this.aliases.has(r);)r=`${t}${o++}`;return this.aliases.add(r),r}};function G(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof p)return e.ref(n.subject);if(Array.isArray(n)){let t=n.map(r=>G(r,e)).filter(r=>r!==void 0);return t.length>0?t:void 0}if(n instanceof m)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(ue(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function J(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function ue(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var I=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,t){return this.producers.find(r=>r.canProduce(e,t))}async produceCached(e,t,r,o){let a=`${t}/${r}@${l(o)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(t,r,o);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,t){let r=this.producerFor(e,t.packageName);if(!r)return null;let o={operator:t.versionOperator,version:t.version},a=await r.resolveVersion(e,t.packageName,o);return a?this.produceCached(r,e,t.packageName,a):null}async getDocumentAsync(e){let t;try{t=D(e)}catch{return null}if(t.kind!=="package"||!t.version)return null;let r=this.producerFor(t.publisher,t.package_);return r?this.produceCached(r,t.publisher,t.package_,t.version):null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.produced.values()).filter(r=>{let o=r.metadata.namespace_;return o!=null&&o.publisher===e&&o.package_===t})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,t){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,t){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 Q={async authorize(){return{allowed:!0}}},X={async record(){}},y=class extends Error{constructor(t,r){let o=`${t.publisher}/${t.package_}${t.version?`@${t.version.major}.${t.version.minor}.${t.version.patch}`:""}`;super(`Not entitled to produce ${o}${r?`: ${r}`:""}`);this.address=t;this.reason=r;this.name="EntitlementDeniedError"}address;reason},x=class{inner;ctx;policy;meter;constructor(e,t,r=Q,o=X){this.inner=e,this.ctx=t,this.policy=r,this.meter=o}canProduce(e,t){return this.inner.canProduce(e,t)}async resolveVersion(e,t,r){return await this.assertAllowed({publisher:e,package_:t,version:r.version}),this.inner.resolveVersion(e,t,r)}async produce(e,t,r){let o={publisher:e,package_:t,version:r};await this.assertAllowed(o);let a=await this.inner.produce(e,t,r);return await this.meter.record(this.ctx,o,a),a}async assertAllowed(e){let t=await this.policy.authorize(this.ctx,e);if(!t.allowed)throw new y(e,t.reason)}};export{ke as a,O as b,Pe as c,w as d,Z as e,f,J as g,I as h,Q as i,X as j,y as k,x as l};
@@ -0,0 +1,2 @@
1
+ import{e as R}from"./chunk-BZ3YTI3C.js";import{c as F,m as G}from"./chunk-PVUBHIU2.js";import{fa as S,ia as j}from"./chunk-7UYXTYXC.js";import{c as N}from"./chunk-CJMVIOZX.js";var z=(r=>(r.Class="Class",r.DatatypeProperty="DatatypeProperty",r.ObjectProperty="ObjectProperty",r.AnnotationProperty="AnnotationProperty",r.Instance="Instance",r.Datatype="Datatype",r.Shape="Shape",r.Unknown="Unknown",r))(z||{}),L=(r=>(r.InstanceOf="instanceOf",r.SubClassOf="subClassOf",r.Domain="domain",r.Range="range",r.ObjectRelationship="objectRelationship",r.SubPropertyOf="subPropertyOf",r.PropertyValue="propertyValue",r.EmbeddedLink="embeddedLink",r))(L||{}),$=class{static async buildFromRepository(e,n){let i=await new G().parseKanonaks(e),s=await e.getAllDocumentsAsync(),p=[],a=[],r=new Set,d=new Set,y=new Map;for(let f of i){let c=f;if(c.name&&(S.isClassType(c)&&r.add(c.name),f instanceof N)){let l=j(i,f);(l==="ObjectProperty"||l==="Property")&&d.add(c.name)}}for(let f of s)for(let[c,l]of Object.entries(f.body))d.has(c)&&l?.range&&typeof l.range=="string"&&y.set(c,l.range);let g=new Map;for(let f of i){let c=f;c.name&&g.set(c.name,c)}for(let f of s){let c=f.metadata.namespace_,l=c?`${c.publisher}/${c.package_}`:"",m=c?.version?`${c.version.major}.${c.version.minor}.${c.version.patch}`:"",O=U(f);for(let[h,u]of Object.entries(f.body)){if(!u||typeof u!="object")continue;let b=g.get(h),k="Unknown";if(b){let T=b,A=b instanceof N?j(i,b):void 0;S.isClassType(T)?k="Class":A==="ObjectProperty"?k="ObjectProperty":A==="DatatypeProperty"?k="DatatypeProperty":A==="AnnotationProperty"?k="AnnotationProperty":S.isDatatypeType(T)?k="Datatype":A==="Property"?k="ObjectProperty":S.isShapeType(T)?k="Shape":S.isInstanceOfKnownClass(T,r)&&(k="Instance")}let P=l&&m?`${l}/${h}@${m}`:h,I={};for(let[T,A]of Object.entries(u))T!=="type"&&(typeof A!="object"||A===null)&&(I[T]=A);p.push({id:P,label:u.label??h,type:k,namespace:l,properties:I}),K(P,u,k,r,d,a,l,m,O,n),D(P,u,d,y,p,a,l,m,O),Q(P,b,a)}}return{nodes:p,edges:a}}static buildFromDocument(e,n){let o=[],i=[],s=e.metadata.namespace_,p=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",a=s?`${s.publisher}/${s.package_}`:"",r=new Set,d=new Set,y=new Map,g=U(e);for(let[l,m]of Object.entries(e.body)){let O=m?.type;O&&(Y(O,g)&&r.add(l),J(O,g)&&(d.add(l),m.range&&typeof m.range=="string"&&y.set(l,m.range)))}for(let[l,m]of Object.entries(e.body)){if(!m||typeof m!="object")continue;let O=m.type,h=X(O,l,r,g),u=a&&p?`${a}/${l}@${p}`:l,b={};for(let[k,P]of Object.entries(m))k!=="type"&&(typeof P!="object"||P===null)&&(b[k]=P);o.push({id:u,label:m.label??l,type:h,namespace:a,properties:b}),K(u,m,h,r,d,i,a,p,g,n),D(u,m,d,y,o,i,a,p,g)}let f=new Set(o.map(l=>l.id)),c=i.filter(l=>f.has(l.source)&&f.has(l.target));return{nodes:o,edges:c}}};function U(t,e){let n=new Map;if(t.metadata?.imports)for(let[o,i]of Object.entries(t.metadata.imports))for(let s of i){let p=s.alias??s.packageName,a=s.version,r=`${a.major}.${a.minor}.${a.patch}`;n.set(p,{publisher:o,package_:s.packageName,version:r})}return n}var B={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},W=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function M(t,e){if(t.includes(".")){let n=t.indexOf("."),o=t.substring(0,n),i=t.substring(n+1),s=e.get(o);if(s)return`${s.publisher}/${s.package_}/${i}`}return null}function Y(t,e){let n=M(t,e);return n?B[n]==="Class":!1}function J(t,e){let n=M(t,e);return n?W.has(n):!1}function X(t,e,n,o){if(!t||t==="Package")return"Unknown";let i=M(t,o);if(i){let p=B[i];if(p)return p;let a=i.split("/").pop()?.split("@")[0]??"";return n.has(a)?"Instance":"Unknown"}let s=t.split(".").pop()??t;return n.has(s)?"Instance":"Unknown"}var V=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function K(t,e,n,o,i,s,p,a,r,d){let y=e.type,g=e.subClassOf;if(g){let h=Array.isArray(g)?g:[g];for(let u of h)typeof u=="string"&&s.push({source:t,target:v(u,p,a,r),type:"subClassOf",label:"subClassOf"})}let f=e.subPropertyOf;if(f){let h=Array.isArray(f)?f:[f];for(let u of h)typeof u=="string"&&s.push({source:t,target:v(u,p,a,r),type:"subPropertyOf",label:"subPropertyOf"})}let c=e.domain,l=e.range;if(d?.includePropertyEdges){let h=[[c,"domain","domain"],[l,"range","range"]];for(let[u,b,k]of h)if(u!=null)for(let P of Array.isArray(u)?u:[u])typeof P=="string"&&s.push({source:t,target:v(P,p,a,r),type:b,label:k})}if(n==="Instance"&&y){let h=y.split(".").pop()??y;s.push({source:t,target:v(h,p,a,r),type:"instanceOf",label:"type"})}if(n==="Instance")for(let[h,u]of Object.entries(e)){if(V.has(h)||!i.has(h))continue;let b=Array.isArray(u)?u:[u];for(let k of b)typeof k=="string"&&Z(k)&&s.push({source:t,target:v(k,p,a,r),type:"propertyValue",label:h,propertyId:v(h,p,a,r)})}if((n==="ObjectProperty"||n==="DatatypeProperty"||c&&l)&&c&&l){let h=typeof c=="string"?c:null,u=typeof l=="string"?l:null;h&&u&&s.push({source:v(h,p,a,r),target:v(u,p,a,r),type:"objectRelationship",label:e.label??t.split("/").pop()??"",propertyId:t})}}function D(t,e,n,o,i,s,p,a,r){for(let[d,y]of Object.entries(e)){if(V.has(d)||typeof y!="object"||y===null||Array.isArray(y))continue;let g=y,f=`${t}/${d}`,c=o.get(d),l=c?c.split(".").pop()??c:"Unknown",m={};for(let[h,u]of Object.entries(g))(typeof u!="object"||u===null)&&(m[h]=u);i.push({id:f,label:`${l} (embedded)`,type:"Instance",namespace:p,properties:m});let O=p&&a?`${p}/${d}@${a}`:d;s.push({source:t,target:f,type:"propertyValue",label:d,propertyId:n.has(d)?O:void 0}),c&&s.push({source:f,target:v(l,p,a,r),type:"instanceOf",label:"type (inferred)"}),D(f,g,n,o,i,s,p,a,r)}}function Q(t,e,n){let o=e?.statement;if(Array.isArray(o))for(let i of o){if(!(i instanceof F))continue;let s=i.predicate?.subject?.name??"";for(let p of i.links){let a=p.target?.subject;if(!a)continue;let r=a.version,d=r&&typeof r.major=="number"?`@${r.major}.${r.minor}.${r.patch}`:"";n.push({source:t,target:`${a.publisher}/${a.package_}/${a.name}${d}`,type:"embeddedLink",label:s})}}}function Z(t){return!(!t||t.includes(" ")||t.includes(`
2
+ `)||t.startsWith("http://")||t.startsWith("https://")||/^\d{4}-\d{2}/.test(t)||/^\d+(\.\d+)?$/.test(t))}function v(t,e,n,o){if(t.includes("@")&&t.includes("/"))return t;if(t.includes(".")){let i=t.indexOf("."),s=t.substring(0,i),p=t.substring(i+1);if(o){let a=o.get(s);if(a)return`${a.publisher}/${a.package_}/${p}@${a.version}`}return e&&n?`${e}/${p}@${n}`:p}return e&&n?`${e}/${t}@${n}`:t}function _(t){let e=t.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!e)throw new Error("Publisher host cannot be empty");return e}var ee="key_thumbprint",E=class{cache=new Map;prCache=new Map;async discoverProtectedResource(e){let n=_(e);if(this.prCache.has(n))return this.prCache.get(n);let o=`https://${n}/.well-known/oauth-protected-resource`,i=await te(o),s=i&&Array.isArray(i.authorization_servers)?i.authorization_servers.filter(a=>typeof a=="string"):[],p=s.length>0?s:null;return this.prCache.set(n,p),p}async discover(e){let n=_(e);if(this.cache.has(n))return this.cache.get(n);let o=`https://${n}/.well-known/oauth-authorization-server`,i=await this.tryEndpoint(o);if(!i){let s=`https://${n}/.well-known/openid-configuration`;i=await this.tryEndpoint(s)}return this.cache.set(n,i),i}async supportsOAuth(e){return await this.discover(e)!==null}static supportsPkceS256(e){return e.codeChallengeMethodsSupported?.some(n=>n.toUpperCase()==="S256")??!1}static supportsDynamicRegistration(e){return!!e.registrationEndpoint}static supportsAuthorizationCode(e){return e.responseTypesSupported?.some(n=>n.toLowerCase()==="code")??!1}static supportsEnrollment(e){return!!e.enrollmentEndpoint}static supportsSession(e){return!!e.sessionEndpoint}async tryEndpoint(e){let n;try{n=await fetch(e)}catch(i){let s=i instanceof Error?i.message:String(i);return s.includes("ENOTFOUND")||s.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${e} \u2014 host unreachable (${s})`),console.error(" If the server is behind a VPN, ensure you are connected.")):s.includes("CERT")||s.includes("SSL")||s.includes("TLS")?(console.error(` OAuth discovery: ${e} \u2014 TLS error (${s})`),console.error(" If using a custom CA certificate, set NODE_EXTRA_CA_CERTS=/path/to/ca.pem")):console.error(` OAuth discovery: ${e} \u2014 network error: ${s}`),null}if(!n.ok)return n.status===404||(n.status===403?(console.error(` OAuth discovery: ${e} \u2014 HTTP 403 Forbidden`),console.error(" Access may be blocked by a firewall, proxy, or WAF.")):n.status>=500&&(console.error(` OAuth discovery: ${e} \u2014 HTTP ${n.status} server error`),console.error(" The authorization server returned an internal error. Contact your IDP administrator."))),null;let o;try{o=await n.json()}catch{return console.error(` OAuth discovery: ${e} \u2014 response is not valid JSON`),console.error(" The endpoint may be returning HTML instead of JSON. Check IDP configuration."),null}return{issuer:C(o.issuer),authorizationEndpoint:C(o.authorization_endpoint),tokenEndpoint:C(o.token_endpoint),registrationEndpoint:C(o.registration_endpoint),revocationEndpoint:C(o.revocation_endpoint),scopesSupported:w(o.scopes_supported),responseTypesSupported:w(o.response_types_supported),grantTypesSupported:w(o.grant_types_supported),codeChallengeMethodsSupported:w(o.code_challenge_methods_supported),tokenEndpointAuthMethodsSupported:w(o.token_endpoint_auth_methods_supported),dpopSigningAlgValuesSupported:w(o.dpop_signing_alg_values_supported),enrollmentEndpoint:C(o.enrollment_endpoint),enrollmentIssuanceProtocols:w(o.enrollment_issuance_protocols),enrollmentKeyTypes:w(o.enrollment_key_types),enrollmentScopesSupported:w(o.enrollment_scopes_supported),enrollmentConsentBindingParam:C(o.enrollment_consent_binding_param),sessionEndpoint:C(o.session_endpoint),sessionEndpointAuthMethod:C(o.session_endpoint_auth_method)}}};async function te(t){try{let e=await fetch(t);return e.ok?await e.json():null}catch{return null}}function C(t){return typeof t=="string"?t:null}function w(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"):null}function H(t){let e=t.headers.get("WWW-Authenticate")??void 0,n=t.headers.get("DPoP-Nonce")??void 0;if(!e&&!n)return;let o={wwwAuthenticate:e??""};if(n&&(o.nonce=n),e){let i=e.match(/acr_values\s*=\s*"([^"]*)"/i);i&&(o.acrValues=i[1])}return o}function ne(t){try{return new URL(t).host}catch{return null}}function re(t,e={}){let n=e.discovery??new E,o=new Map,i=new Map,s=async r=>{let d=o.get(r);if(d!==void 0)return d;let y=null,g=await n.discoverProtectedResource(r).catch(()=>null);return g&&g.length>0&&(y=ne(g[0])),o.set(r,y),y},p=async(r,d)=>{if(!t)return null;if(!(d.forceRefresh||d.challenge)&&i.has(r))return i.get(r);let g=await t.resolve(r,d).catch(()=>null);return i.set(r,g),g},a=async(r,d,y,g)=>{let f=await s(d);if(!f)return{res:await R(r,{method:y,redirect:"manual"}),authed:!1};let c=await p(f,{method:y,url:r,...g}),l=c?.headers??{};return{res:await R(r,{method:y,redirect:"manual",headers:l}),authed:!!c}};return async(r,d,y="GET")=>{let g=await a(r,d,y,{});if((g.res.status===401||g.res.status===403)&&g.authed){let f=H(g.res),c={forceRefresh:f===void 0};return f&&(c.challenge=f),(await a(r,d,y,c)).res}return g.res}}var q="KANONAK_TOKEN";function oe(){return typeof process<"u"&&process.env?process.env:{}}function se(t){return`${q}_${t.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}var x=class{tokens;env;constructor(e={}){this.tokens=e.tokens??{},this.env=e.env??oe()}async resolve(e,n){let o=_(e),i=this.tokens[o]??this.env[se(o)]??this.env[q];return i?{headers:{Authorization:`Bearer ${i}`}}:null}};export{z as a,L as b,$ as c,_ as d,ee as e,E as f,H as g,re as h,x as i};
File without changes
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as Zt,b as Qt,c as eo,d as no,e as H}from"./chunk-EVMSO7HJ.js";import{a as Vn,b as Nn,c as On}from"./chunk-V3DH67P3.js";import{a as Xt,b as Yt,c as Jt,d as tr,e as we,f as or,g as rr,h as ar,i as ir,j as sr,k as cr,l as ur}from"./chunk-J4ZD6IF6.js";import{a as lr}from"./chunk-L2J7WD7E.js";import{a as mt,b as ft,c as kt,d as yt,e as ht,f as vt,g as It,h as _t,i as Lt}from"./chunk-IS3AQKB4.js";import{a as gt,b as St,c as bt,d as Pt,e as Rt,f as Et,h as Kt,i as De,j as Me,k as He,l as Te,m as xt,n as Ct}from"./chunk-BZ3YTI3C.js";import{a as oo,b as ro,c as ao,d as io}from"./chunk-BS7RRG7D.js";import{a as so}from"./chunk-XK24CN3C.js";import{a as wt}from"./chunk-SC5M74NM.js";import{A as Oo,B as $o,C as Uo,D as Do,E as Mo,F as Ho,G as Xo,H as Yo,I as Jo,J as Zo,K as Qo,L as er,M as nr,a as uo,b as lo,c as po,d as mo,e as fo,f as ko,g as yo,h as ho,i as go,j as So,k as bo,l as Po,m as Ro,n as Eo,o as Ko,p as xo,q as wo,r as Co,s as vo,t as Io,u as _o,v as Lo,w as Ao,x as jo,y as Vo,z as No}from"./chunk-CR5QY3LJ.js";import"./chunk-KIBR3HAT.js";import{c as Ln,d as To,e as Fo,g as Bo,h as Wo,k as zo,m as xe,o as An,p as jn,r as Go,s as qo}from"./chunk-Z5Y4MCW5.js";import{a as me}from"./chunk-6VIUXP4N.js";import{a as E,b as D,c as ge,i as V,j as Ke,k as Gt,l as qt,m as L}from"./chunk-PVUBHIU2.js";import{a as j}from"./chunk-HF5FJBS2.js";import{a as co}from"./chunk-PEJALHXK.js";import{$ as Ee,A as rn,B as an,C as sn,D as cn,E as un,F as ln,G as pn,H as dn,I as mn,J as fn,K as kn,L as yn,M as Re,N as hn,O as gn,P as Sn,Q as bn,R as Pn,S as Rn,T as En,U as Kn,V as xn,W as wn,X as Cn,Y as vn,Z as In,_ as _n,a as $t,b as Ut,c as Se,d as Dt,da as Ft,e as M,f as Mt,fa as Bt,g as Ht,ga as h,ha as ee,i as Tt,j as Y,k as J,l as We,m as Z,ma as Wt,n as ze,na as zt,o as Ge,oa as ne,p as qe,q as Xe,r as Ye,s as Je,t as Ze,u as Qe,v as Pe,w as en,x as nn,y as tn,z as on}from"./chunk-7UYXTYXC.js";import{A as be,B as _,C as Q,a as At,b as jt,c as g,d as k,e as Nt,f as Ot,g as fe,h as ke,i as ye,j as G,k as he,l as q,m as u,r as Fe,t as K,w as Be,x as I,y as X,z as y}from"./chunk-CJMVIOZX.js";import{a as Vt}from"./chunk-FUUTGGJS.js";import"./chunk-F67UH4FD.js";import{a as at,b as de,c as z,d as it,e as w,f as st,g as ct,h as ut,i as lt,j as pt,k as dt}from"./chunk-QILEJIFU.js";import{a as to}from"./chunk-ODIECDN7.js";async function $n(n){let e=await new L().parseKanonaks(n),o=await new H().reason(n);return{kind:"merged",catalog:e,reasoning:o}}function Un(n,e){return{kind:"merged",catalog:n,reasoning:e}}async function Dn(n,e){let o=e??new me(new j);return{kind:"standalone",catalog:await new L().parseKanonaks(new Q(n,o))}}function $(n){return typeof n=="number"?n:void 0}function pr(n){if(!n)return;let e=u(n);if(e===u(fn))return"IRI";if(e===u(kn))return"BlankNode";if(e===u(yn))return"Literal"}function Mn(n){if(!n)return;let e=u(n);if(e===u(hn))return"Violation";if(e===u(gn))return"Warning";if(e===u(Sn))return"Info"}function Ce(n,e){let o=y(n,e);if(o)return[o];let t=[];for(let r of _(n,e))r instanceof k&&t.push(r.subject);return t}function dr(n,e){let o=y(n,Xe);if(!o)return;let t={path:o},r=$(I(n,Ye)),a=$(I(n,Je));r!==void 0&&(t.minCount=r),a!==void 0&&(t.maxCount=a);let s=$(I(n,tn)),i=$(I(n,on));s!==void 0&&(t.minLength=s),i!==void 0&&(t.maxLength=i);let c=$(I(n,rn)),p=$(I(n,an));c!==void 0&&(t.minInclusive=c),p!==void 0&&(t.maxInclusive=p);let d=X(n,en);if(d!==void 0){let P=X(n,nn);t.pattern=P!==void 0?{regex:d,flags:P}:{regex:d}}if(Be(n,Pe)){let P=[],N=[];for(let O of _(n,Pe))O instanceof D?P.push(O.value):O instanceof k&&N.push(O.subject);P.length>0&&(t.inValues=P),N.length>0&&(t.inRefs=N)}let S=y(n,Ze);S&&(t.datatype=S);let b=y(n,Qe);b&&(t.classRef=b);let l=pr(y(n,mn));l&&(t.nodeKind=l);let m=X(n,sn);m!==void 0&&(t.message=m);let f=Mn(y(n,Re))??e;return f&&(t.severity=f),t}function te(n){let e=[];for(let o of n){if(!(o instanceof g)||!Fe(o,Z))continue;let t=Mn(y(o,Re)),r={name:o.name,uri:h(o),targetClass:y(o,Ge),targetNodes:Ce(o,cn),targetSubjectsOf:Ce(o,un),targetObjectsOf:Ce(o,ln),closed:I(o,pn)===!0,ignoredProperties:[],severity:t,properties:[]};for(let a of _(o,dn))a instanceof k&&r.ignoredProperties.push(a.subject);for(let a of _(o,qe)){let s;if(a instanceof E?s=a:a instanceof k&&(s=K(n,a.subject)),!s)continue;let i=dr(s,t);i&&r.properties.push(i)}e.push(r)}return e}var x="kanonak.org/transformations",oe="values";var re="allowed",C=n=>({type:`${x}/VarRef`,varName:n}),ve=n=>({type:`${x}/IntegerLiteral`,integerLiteral:n}),mr=n=>({type:`${x}/DecimalLiteral`,decimalLiteral:n}),Hn=n=>Number.isInteger(n)?ve(n):mr(n),Tn=n=>({type:`${x}/Count`,source:n}),Fn=(n,e)=>({type:`${x}/GreaterThanOrEqual`,compareLeft:n,compareRight:e}),Bn=(n,e)=>({type:`${x}/LessThanOrEqual`,compareLeft:n,compareRight:e});function Ie(n,e){if(!e||e.length===0)return n;let o=new Set(["i","m","s"]),t=[...new Set(e.split(""))];if(t.filter(a=>!o.has(a)).length>0)throw new Error(`sh:flags '${e}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${t.sort().join("")})${n}`}function ae(n){let e=[];return n.minCount!==void 0&&e.push({component:"minCount",per:"node",expr:Fn(Tn(C(oe)),ve(n.minCount))}),n.maxCount!==void 0&&e.push({component:"maxCount",per:"node",expr:Bn(Tn(C(oe)),ve(n.maxCount))}),(n.inValues!==void 0||n.inRefs!==void 0)&&e.push({component:"in",per:"value",expr:{type:`${x}/Contains`,haystack:C(re),needle:C("v")}}),n.pattern!==void 0&&e.push({component:"pattern",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:Ie(n.pattern.regex,n.pattern.flags)}}),n.minLength!==void 0&&e.push({component:"minLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{${n.minLength},}$`}}),n.maxLength!==void 0&&e.push({component:"maxLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{0,${n.maxLength}}$`}}),n.minInclusive!==void 0&&e.push({component:"minInclusive",per:"value",expr:Fn(C("v"),Hn(n.minInclusive))}),n.maxInclusive!==void 0&&e.push({component:"maxInclusive",per:"value",expr:Bn(C("v"),Hn(n.maxInclusive))}),e}import{evaluate as kr,ExpressionError as yr}from"@kanonak-protocol/expression";function Gn(n,e){let o=hr(e)?e:te(e),t=[];for(let r of o)for(let a of gr(n,r))Pr(n,r,a,t);return{conforms:!t.some(r=>r.severity==="Violation"),results:t}}function hr(n){return n.length>0&&!(n[0]instanceof Object&&"statement"in n[0])&&typeof n[0].name=="string"&&"properties"in n[0]}function ie(n){let e=n.predicate;return e instanceof k?e:void 0}function gr(n,e){let o=new Map,t=n.catalog.filter(a=>a instanceof g),r=a=>{let s=h(a);o.set(s?u(s):`${a.namespace}/${a.name}`,a)};if(e.targetClass){let a=u(e.targetClass);if(n.reasoning){let s=new Set(n.reasoning.getInstancesOfClass(e.targetClass));for(let i of t){let c=h(i);c&&s.has(u(c))&&r(i)}}else for(let s of t)ne(s).some(c=>u(c)===a||ee(n.catalog,c).some(p=>u(p)===a))&&r(s)}for(let a of e.targetNodes){let s=K(n.catalog,a);s instanceof g&&r(s)}for(let a of e.targetSubjectsOf){let s=u(a);for(let i of t)i.statement.some(c=>{let p=ie(c);return p&&u(p.subject)===s})&&r(i)}for(let a of e.targetObjectsOf){let s=u(a);for(let i of t)for(let c of i.statement){let p=ie(c);if(!(!p||u(p.subject)!==s))for(let d of Sr(c)){let S=K(n.catalog,d);S instanceof g&&r(S)}}}return[...o.values()]}function Sr(n){return n instanceof G?[n.object.subject]:n instanceof q?(n.object??[]).filter(e=>e instanceof k).map(e=>e.subject):[]}function br(n,e,o){let t=[];for(let r of n.statement){let a=ie(r);if(!(!a||u(a.subject)!==e)){if(r instanceof fe||r instanceof ge)t.push({kernel:r.object,kind:"string",literal:r.object});else if(r instanceof ke)t.push({kernel:r.object,kind:"number",literal:r.object});else if(r instanceof ye)t.push({kernel:r.object?1:0,kind:"boolean",literal:r.object});else if(r instanceof G)t.push({kernel:{ref:u(r.object.subject)},kind:"reference",ref:r.object.subject});else if(r instanceof he)t.push(Wn(r.object,o,t.length));else if(r instanceof q){for(let s of r.object??[])if(s instanceof k)t.push({kernel:{ref:u(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof E)t.push(Wn(s,o,t.length));else if(s instanceof D){let i=s.value;typeof i=="boolean"?t.push({kernel:i?1:0,kind:"boolean",literal:i}):t.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return t}function Wn(n,e,o){let t=n.name&&n.name.length>0?n.name:String(o);return{kernel:{ref:`${e}#${t}`},kind:"embedded"}}function Pr(n,e,o,t){let r=h(o),a=r?u(r):`${o.namespace}/${o.name}`;for(let s of e.properties)Er(n,e,o,a,r,s,t);e.closed&&vr(e,o,a,r,t)}function _e(n,e,o,t,r,a={},s){return{focusNode:e,focusUri:o,constraintComponent:t,severity:s??qn(n),message:r,sourceShape:n.name,sourceShapeUri:n.uri,...a}}function qn(n){return n.severity??"Violation"}var Rr={minCount:bn,maxCount:Pn,in:Kn,pattern:xn,minLength:wn,maxLength:Cn,minInclusive:vn,maxInclusive:In};function Er(n,e,o,t,r,a,s){let i=u(a.path),c=br(o,i,t),p=a.severity??qn(e),d=a.path.name,S=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:u(l)}))],b=(l,m,f)=>{s.push(_e(e,t,r,l,a.message??m,{resultPath:a.path,value:f?.literal,valueRef:f?.ref},p))};for(let l of ae(a)){let m=Rr[l.component];if(l.per==="node"){zn(l,{[oe]:c.map(P=>P.kernel),[re]:S})||b(m,l.component==="minCount"?`'${d}' has ${c.length} value(s); minCount is ${a.minCount}.`:`'${d}' has ${c.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let f of c){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&f.kind!=="string"){b(m,`'${d}' value is not a string; ${l.component} applies to string values.`,f);continue}zn(l,{v:f.kernel,[re]:S})||b(m,Kr(l,d,a,f),f)}}if(a.nodeKind)for(let l of c)xr(a.nodeKind,l)||b(_n,`'${d}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of c){let m=wr(a.datatype,l);m&&b(Rn,`'${d}' ${m}`,l)}if(a.classRef)for(let l of c){let m=Cr(n,a.classRef,l);m&&b(En,`'${d}' ${m}`,l)}}function Kr(n,e,o,t){let r=t.ref?u(t.ref):JSON.stringify(t.literal);switch(n.component){case"in":return`'${e}' value ${r} is not in the permitted set.`;case"pattern":return`'${e}' value ${r} does not match pattern ${o.pattern?.regex}.`;case"minLength":return`'${e}' value ${r} is shorter than minLength ${o.minLength}.`;case"maxLength":return`'${e}' value ${r} is longer than maxLength ${o.maxLength}.`;case"minInclusive":return`'${e}' value ${r} is below minInclusive ${o.minInclusive} (or not numeric).`;case"maxInclusive":return`'${e}' value ${r} is above maxInclusive ${o.maxInclusive} (or not numeric).`;default:return`'${e}' value ${r} violates ${n.component}.`}}function zn(n,e){let o=t=>{let r=t.varName;if(t.type==="kanonak.org/transformations/VarRef"&&typeof r=="string"&&r in e)return e[r];throw new yr(`Conformance lowering produced an unexpected leaf '${t.type}'`)};return kr(n.expr,void 0,o)===1}function xr(n,e){switch(n){case"IRI":return e.kind==="reference";case"BlankNode":return e.kind==="embedded";case"Literal":return e.kind==="string"||e.kind==="number"||e.kind==="boolean"}}function wr(n,e){if(e.kind==="reference"||e.kind==="embedded")return`value is a ${e.kind}; sh:datatype requires a literal of ${n.name}.`;let o=Ke(n);if(o!==void 0)switch(o){case V.Boolean:return e.kind==="boolean"?void 0:`value is not a boolean (${n.name}).`;case V.Integer:return e.kind!=="number"?`value is not a number (${n.name}).`:Number.isInteger(e.literal)?void 0:`value is not an integer (${n.name}).`;case V.Decimal:case V.Double:case V.Float:return e.kind==="number"?void 0:`value is not a number (${n.name}).`;default:return e.kind==="string"?void 0:`value is not a string-carried literal (${n.name}).`}}function Cr(n,e,o){if(o.kind!=="reference"||!o.ref)return`value is not a reference; sh:class requires an instance of ${e.name}.`;let t=u(e);if(n.reasoning)return n.reasoning.isInstanceOf(o.ref,e)?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`;let r=K(n.catalog,o.ref);return r instanceof g?ne(r).some(s=>u(s)===t||ee(n.catalog,s).some(i=>u(i)===t))?void 0:`value ${u(o.ref)} is not an instance of ${e.name}.`:`value ${u(o.ref)} does not resolve in this scope (sh:class ${e.name}).`}function vr(n,e,o,t,r){let a=new Set([...n.properties.map(i=>u(i.path)),...n.ignoredProperties.map(i=>u(i))]),s=new Set;for(let i of e.statement){let c=ie(i);if(!c)continue;let p=u(c.subject);a.has(p)||s.has(p)||(s.add(p),r.push(_e(n,o,t,Ee,`'${e.name}' carries undeclared property '${c.subject.name}' (closed shape).`,{resultPath:c.subject})))}for(let i of e.unresolvedPredicates)s.has(i.key)||(s.add(i.key),r.push(_e(n,o,t,Ee,`'${e.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}import*as Le from"js-yaml";import{VersionOperator as Xn}from"@kanonak-protocol/types/document/models/enums";var Ir="0.0.0",A=class{constructor(e,o=new j,t){this.repository=e;this.parser=o;this.objectParser=t??new L(this.parser)}repository;parser;objectParser;imports(){return new T}serializeValue(e,o){return Zn(e,o)}async buildContentAddressed(e){let o=e.book.toImports(),t=await this.hashBody(e.publisher,o,e.body),r=Ae(t),a={type:"EphemeralPackage",publisher:e.publisher,imports:o};e.contentHashProperty&&(a[e.contentHashProperty]=t),Object.assign(a,e.header??{}),a.imports=o;let s={[r]:a,...e.body},i=this.dump(s);return{yaml:i,byteCount:Jn(i),contentHash:t,packageName:r,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let o=e.book.toImports(),t={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:o},r;e.contentHashProperty&&(r=await this.hashBody(e.publisher,o,e.body),t[e.contentHashProperty]=r),Object.assign(t,e.header??{}),t.imports=o;let a={[e.name]:t,...e.body},s=this.dump(a),i={yaml:s,byteCount:Jn(s),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return r!==void 0&&(i.contentHash=r),i}dump(e){return Le.dump(e,{lineWidth:-1})}async hashBody(e,o,t){let r={[Yn]:{type:"EphemeralPackage",publisher:e,imports:o},...t},a=this.parser.parse(Le.dump(r,{lineWidth:-1})),s=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new Q(a,this.repository))).filter(p=>p instanceof g&&p.namespace===s&&p.name!==Yn);for(let p of c)p.namespace="ephemeral";return we(c)}},Yn="__pkgbuilder_probe__";function Jn(n){return new TextEncoder().encode(n).length}function Ae(n){let e="sha256:",o=n.startsWith(e)?e.length:0;return`q-${n.slice(o,o+16)}`}var T=class{byKey=new Map;aliases=new Set;ensure(e,o,t,r,a=Xn.Major){let s=`${e}/${o}@${t}`,i=this.byKey.get(s);if(i)return i.alias;let c=this.uniqueAlias(r);return this.byKey.set(s,{publisher:e,package_:o,version:t,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_,w(e.version),e.package_)}.${e.name}`}refLatest(e,o,t,r){return`${this.ensure(e,o,Ir,r??o,Xn.Any)}.${t}`}toImports(){let e=new Map;for(let t of this.byKey.values()){let r=e.get(t.publisher)??[];r.push(t),e.set(t.publisher,r)}return[...e.keys()].sort().map(t=>({publisher:t,packages:e.get(t).sort((r,a)=>r.package_<a.package_?-1:1).map(r=>({package:r.package_,match:de(r.match),version:r.version,alias:r.alias}))}))}uniqueAlias(e){let o=F(e)||"pkg",t=o,r=2;for(;this.aliases.has(t);)t=`${o}${r++}`;return this.aliases.add(t),t}};function Zn(n,e){if(n!=null){if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(n instanceof k)return e.ref(n.subject);if(Array.isArray(n)){let o=n.map(t=>Zn(t,e)).filter(t=>t!==void 0);return o.length>0?o:void 0}if(n instanceof E)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(_r(n))throw new Error(`Value produced a bare URI without a version (${n.publisher}/${n.package_}/${n.name}); cannot serialize it as a reference.`)}}function F(n){return n.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function _r(n){return typeof n=="object"&&n!==null&&typeof n.publisher=="string"&&typeof n.package_=="string"&&typeof n.name=="string"}var Lr="1.1.0";async function Qn(n){let e=new A(n.repository),o=e.imports(),t=o.ensure(Y,J,Lr,"sh"),r=(i,c)=>i&&i.version&&typeof i.version.major=="number"?`${o.ensure(i.publisher,i.package_,w(i.version),i.package_)}.${i.name}`:c,a={},s=[];return n.result.results.forEach((i,c)=>{let p=`result-${c+1}`;s.push(p);let d={type:`${t}.ValidationResult`,[`${t}.focusNode`]:r(i.focusUri,i.focusNode),[`${t}.resultMessage`]:i.message,[`${t}.resultSeverity`]:`${t}.${i.severity}`,[`${t}.sourceConstraintComponent`]:`${t}.${i.constraintComponent.name}`};i.resultPath&&(d[`${t}.resultPath`]=r(i.resultPath,u(i.resultPath))),i.sourceShapeUri&&(d[`${t}.sourceShape`]=r(i.sourceShapeUri,i.sourceShape)),i.valueRef?d[`${t}.value`]=r(i.valueRef,u(i.valueRef)):i.value!==void 0&&(d[`${t}.value`]=i.value),a[p]=d}),a.report={type:`${t}.ValidationReport`,[`${t}.conforms`]:n.result.conforms,...s.length>0?{[`${t}.result`]:s}:{}},e.buildContentAddressed({publisher:n.publisher,book:o,body:a,...n.header!==void 0?{header:n.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as ji}from"@kanonak-protocol/types/document/models/enums";var se=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,o){return this.producers.find(t=>t.canProduce(e,o))}async produceCached(e,o,t,r){let a=`${o}/${t}@${w(r)}`,s=this.produced.get(a);if(s)return s;let{document:i}=await e.produce(o,t,r);return this.produced.set(a,i),i}async getHighestCompatibleVersionAsync(e,o){let t=this.producerFor(e,o.packageName);if(!t)return null;let r={operator:o.versionOperator,version:o.version},a=await t.resolveVersion(e,o.packageName,r);return a?this.produceCached(t,e,o.packageName,a):null}async getDocumentAsync(e){let o;try{o=Se(e)}catch{return null}if(o.kind!=="package"||!o.version)return null;let t=this.producerFor(o.publisher,o.package_);return t?this.produceCached(t,o.publisher,o.package_,o.version):null}async getDocumentsByNamespaceAsync(e,o){return Array.from(this.produced.values()).filter(t=>{let r=t.metadata.namespace_;return r!=null&&r.publisher===e&&r.package_===o})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,o){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,o){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 je={async authorize(){return{allowed:!0}}},Ve={async record(){}},B=class extends Error{constructor(o,t){let r=`${o.publisher}/${o.package_}${o.version?`@${o.version.major}.${o.version.minor}.${o.version.patch}`:""}`;super(`Not entitled to produce ${r}${t?`: ${t}`:""}`);this.address=o;this.reason=t;this.name="EntitlementDeniedError"}address;reason},ce=class{inner;ctx;policy;meter;constructor(e,o,t=je,r=Ve){this.inner=e,this.ctx=o,this.policy=t,this.meter=r}canProduce(e,o){return this.inner.canProduce(e,o)}async resolveVersion(e,o,t){return await this.assertAllowed({publisher:e,package_:o,version:t.version}),this.inner.resolveVersion(e,o,t)}async produce(e,o,t){let r={publisher:e,package_:o,version:t};await this.assertAllowed(r);let a=await this.inner.produce(e,o,t);return await this.meter.record(this.ctx,r,a),a}async assertAllowed(e){let o=await this.policy.authorize(this.ctx,e);if(!o.allowed)throw new B(e,o.reason)}};var R="kanonak.org",v="view",et="core-kanonak",Ar={publisher:R,package_:v,name:"rootView"},jr={publisher:R,package_:v,name:"bind"},Vr={publisher:R,package_:v,name:"produces"},Nr={publisher:R,package_:v,name:"projections"},Or={publisher:R,package_:v,name:"where"},$r={publisher:R,package_:v,name:"value"},Ur={publisher:R,package_:v,name:"as"},ue=class{constructor(e,o=new j){this.repository=e;this.parser=o;this.objectParser=new L(this.parser),this.builder=new A(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,o={}){let t=await this.objectParser.parseKanonaks(this.repository),r=this.resolveView(t,e),a=y(r,jr);if(!a)throw new Error(`View ${r.namespace}/${r.name} declares no view.bind; cannot materialize.`);let s=y(r,Vr);if(!s)throw new Error(`View ${r.namespace}/${r.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 i=Dr(r),c=nt(t,R,et),p=nt(t,R,v),d=this.builder.imports(),S=d.ensure(R,et,c,"ck"),b=d.ensure(R,v,p,"v"),l=d.ref(s),m=new jn(this.repository,this.parser,this.objectParser),f=new An(m,t),P=this.readProjections(t,r),N=Tr(r,Or),O=this.findInstances(t,a,await this.reason(o)),Ne={},ot=new Set;for(let W of O){if(!await this.passesWhere(f,t,N,W))continue;let pe={type:l};for(let $e of P){let rt=await this.evaluateValue(f,t,$e.value,W),Ue=this.builder.serializeValue(tt(rt),d);Ue!==void 0&&(pe[d.ref($e.as)]=Ue)}let Oe=h(W);Oe&&(pe[`${b}.derivedFrom`]=d.ref(Oe)),Ne[this.rowName(W,ot)]=pe}let le={};o.resolvedAt&&(le[`${S}.resolvedAt`]=o.resolvedAt),o.invocationId&&(le[`${S}.id`]=o.invocationId);let U=await this.builder.buildContentAddressed({publisher:i,book:d,body:Ne,contentHashProperty:`${S}.contentHash`,header:le});return{yaml:U.yaml,contentHash:U.contentHash,packageName:U.packageName,publisher:U.publisher,rowCount:U.resourceCount}}resolveView(e,o){let t=K(e,o);if(!t)throw new Error(`View ${o.publisher}/${o.package_}/${o.name} not found in the catalog.`);let r=y(t,Ar);if(r){let a=K(e,r);if(!a)throw new Error(`ViewPackage ${o.name} names rootView ${r.name}, which is not in the catalog.`);return a}return t}readProjections(e,o){let t=[];for(let r of _(o,Nr)){let a=r instanceof E?r:r instanceof k?K(e,r.subject):void 0;if(!a)continue;let s=be(a,$r),i=y(a,Ur);s&&i&&t.push({value:s,as:i})}return t}async reason(e){return new H({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,o,t){let r=Hr(e),a=[],s=new Set;for(let i of t.getInstancesOfClass(o)){if(s.has(i))continue;s.add(i);let c=r.get(i);c&&a.push(c)}return a.sort((i,c)=>{let p=M(h(i)),d=M(h(c));return p<d?-1:p>d?1:0}),a}async passesWhere(e,o,t,r){for(let a of t){let s=await this.evaluateValue(e,o,a,r);if(!Fr(s))return!1}return!0}async evaluateValue(e,o,t,r){let a=Ln(t,"view-projection",{catalog:o,depth:0}),s=new Map([["input",r]]);return e.evaluate(a,s)}rowName(e,o){let t=F(e.name)||"row",r=t,a=2;for(;o.has(r);)r=`${t}-${a++}`;return o.add(r),r}};function tt(n){return xe(n)?n.value:Array.isArray(n)?n.map(tt):n}function Dr(n){let e=h(n);if(!e)throw new Error(`Could not derive a publisher from view ${n.namespace}/${n.name}.`);return e.publisher}function nt(n,e,o){let t=Mr(n,e,o);if(!t)throw new Error(`Package ${e}/${o} is not in the catalog; it must be importable to materialize a view.`);return t}function Mr(n,e,o){let t;for(let r of n){if(!(r instanceof g))continue;let a=h(r);!a||a.publisher!==e||a.package_!==o||!a.version||(!t||z(a.version,t)>0)&&(t=a.version)}return t?w(t):void 0}function Hr(n){let e=new Map,o=new Map;for(let t of n){if(!(t instanceof g))continue;let r=h(t);if(!r||!r.version)continue;let a=M(r),s=o.get(a);(!s||z(r.version,s)>0)&&(o.set(a,r.version),e.set(a,t))}return e}function Tr(n,e){let o=be(n,e);return o?[o]:_(n,e).filter(t=>t instanceof E)}function Fr(n){return n===!0?!0:n===!1||n===void 0||n===null?!1:typeof n=="string"?n.length>0:typeof n=="number"?n!==0:xe(n)?n.value.length>0:Array.isArray(n)?n.length>0:!!n}export{Lo as AmbiguousReferenceRule,ye as BooleanStatement,or as CANONICAL_FORM_VERSION,V as Carrier,$o as ClassDefinitionRule,Ko as ClassHierarchyCycleRule,kt as CompositeKanonakDocumentRepository,ar as DEFAULT_CONSENT_BINDING_PARAM,jt as DefinedKanonak,er as DiamondNameClashRule,Do as DisplayLensScopeRule,ft as DocumentLocation,Yt as EdgeType,E as EmbeddedKanonak,Po as EmbeddedKanonakTypeRule,he as EmbeddedStatement,B as EntitlementDeniedError,ce as EntitlementProducer,mt as FileSystemKanonakDocumentRepository,to as GitIgnoreFilter,Jt as GraphBuilder,Ct as HttpKanonakDocumentRepository,De as INTEGRITY_PREFIX,T as ImportBook,Ro as ImportExistenceRule,me as InMemoryKanonakDocumentRepository,gt as KANONAK_USER_AGENT,At as Kanonak,ro as KanonakDocumentPositions,L as KanonakObjectParser,nr as KanonakObjectValidator,j as KanonakParser,Vt as KanonakUri,so as KanonakUriBuilder,co as KanonakUrlResolver,Ft as KanonakVocabulary,Fo as LINE_STYLES,ko as LinkTargetRule,q as ListStatement,D as LiteralKanonak,vt as LocalFirstRepository,It as LockAwareRepository,Yo as LookBandPathRule,Go as LookRenderer,Mo as LookSemanticSvgPathRule,Uo as MarkdownLinkRule,ge as MarkdownStatement,Io as NamespaceImportCycleRule,yo as NamespacePrefixRule,Xt as NodeType,ke as NumberStatement,ir as OAuthDiscovery,eo as OWL_RL_CLASSIFICATION_RULES,jo as ObjectPropertyValueValidationRule,po as OntologyValidationError,uo as OntologyValidationResult,Qo as OwlOneOfRule,A as PackageBuilder,bo as PackageHeaderRule,se as ProducerRepository,Vo as PropertyDomainRule,xo as PropertyHierarchyCycleRule,No as PropertyKindRangeConsistencyRule,oo as PropertyMetadata,Ao as PropertyRangeReferenceRule,wo as PropertyRangeRequiredRule,go as PropertyTypeSpecificityRule,Kt as PublisherConfigResolver,xt as PublisherIndex,Qt as RDFS_RULES,H as Reasoner,no as ReasoningResult,k as ReferenceKanonak,G as ReferenceStatement,ht as RepositoryFactory,Oo as ReservedNameShadowRule,ho as ResourceNamingRule,$t as ResourceResolver,Bt as ResourceTypeClassifier,J as SHACL_PACKAGE,Y as SHACL_PUBLISHER,Z as SH_NODE_SHAPE,ze as SH_PROPERTY_SHAPE,We as SH_SHAPE,Ot as ScalarStatement,Xo as SequenceNarrativeRule,Zo as ShaclShapeRule,Nt as Statement,fe as StringStatement,Co as SubClassOfReferenceRule,vo as SubPropertyOfReferenceRule,g as SubjectKanonak,So as SubjectKanonakTypeRequiredRule,ur as TokenCredentialProvider,Zt as TripleStore,Ho as TxExpressionCompilesRule,Jo as TxExpressionPathRule,Ut as TypeResolver,_o as UnresolvedPredicateRule,Eo as UnresolvedReferenceRule,fo as ValidationCache,mo as ValidationContext,lo as ValidationSeverity,ji as VersionOperator,ue as ViewMaterializer,je as allowAllPolicy,Pt as assertHttpsUrl,wt as assertPackageIdentity,Lt as buildLocalFirstRepository,zo as buildOntologyModel,Qn as buildReportPackageAsync,te as buildShapesModel,tr as canonicalForm,we as canonicalHash,Ke as carrierOf,_t as collectKanonakFiles,z as compareVersions,On as computeIntegrity,Te as computeIntegrityAsync,Ae as contentAddressedName,ne as contextTypesOf,cr as createCredentialedFetch,st as createVersion,Gn as evaluateConformance,qt as extractMarkdownLinks,lr as findDerivation,Gt as findMalformedReferences,io as findMarkdownLinkAt,Ie as foldFlagsIntoPattern,Dt as formatKanonakAddress,w as formatVersion,yt as getGlobalCachePath,bt as getKanonakUserAgent,ut as isCompatibleVersion,lt as isMajorCompatible,Rt as kanonakFetch,Vn as loadLockFile,ae as lowerConstraint,Mt as makeUriKey,Ve as noopMeter,rr as normalizeHost,sr as parseAuthChallenge,Se as parseKanonakAddress,Me as parseLockFile,ct as parseVersionString,ao as parseWithPositions,dt as pickHighestDocument,Wt as propertiesInScope,Bo as readSequenceConnectors,To as resolveDisplayValue,zt as resolvePropertyStep,F as sanitizeName,pt as satisfiesVersionOperator,Nn as saveLockFile,Un as scopeFromCatalog,Dn as scopeFromDocumentAsync,$n as scopeFromRepositoryAsync,He as serializeLockFile,Et as setKanonakFetchRetries,St as setKanonakUserAgent,h as subjectUri,ee as superClassChain,qo as supportedBandKeys,Ht as tripleKey,M as uriKey,Tt as uriTriple,at as versionOperatorFromChar,de as versionOperatorToChar,it as versionsEqual,Wo as walkSequence};
1
+ import{a as Do,b as Ho,c as To,d as Fo,e as D}from"./chunk-EVMSO7HJ.js";import{a as Kn,b as xn,c as Cn}from"./chunk-V3DH67P3.js";import{a as Ao,b as $o,c as Mo,d as qt,e as Xt,f as Yt,g as Jt,h as Qt,i as Zt}from"./chunk-PXS6XZ3V.js";import{a as er}from"./chunk-L2J7WD7E.js";import{a as Ft,b as Bt,c as Wt,d as H,e as Gt,f as zt,g as ge,h as nr,i as or,j as tr,k as rr,l as ar}from"./chunk-PRXC2HZ3.js";import{a as Zn,b as eo,c as no,d as oo,e as to,f as ko,g as ho,h as So,i as go}from"./chunk-IS3AQKB4.js";import{a as ro,b as ao,c as io,d as so,e as co,f as uo,h as lo,i as ve,j as Le,k as _e,l as Ie,m as po,n as mo}from"./chunk-BZ3YTI3C.js";import{a as Wo,b as Go,c as zo,d as qo}from"./chunk-BS7RRG7D.js";import{a as Xo}from"./chunk-XK24CN3C.js";import{a as fo}from"./chunk-SC5M74NM.js";import{A as Kt,B as xt,C as Ct,D as Pt,E as vt,F as Lt,G as Ut,H as At,I as $t,J as Mt,K as Dt,L as Ht,M as Tt,a as Jo,b as Qo,c as Zo,d as et,e as nt,f as ot,g as tt,h as rt,i as at,j as it,k as st,l as ct,m as ut,n as lt,o as pt,p as dt,q as ft,r as mt,s as kt,t as ht,u as St,v as gt,w as yt,x as bt,y as Rt,z as Et}from"./chunk-LRVOGQI5.js";import"./chunk-KIBR3HAT.js";import{c as bn,d as _t,e as It,g as wt,h as Vt,k as Nt,m as Se,o as Rn,p as En,r as jt,s as Ot}from"./chunk-DD3TCFBT.js";import"./chunk-QHABFCRC.js";import{a as ie}from"./chunk-6VIUXP4N.js";import{a as v,b as $,c as pe,i as I,j as he,k as Oo,l as Uo,m as N}from"./chunk-PVUBHIU2.js";import{a as A}from"./chunk-HF5FJBS2.js";import{a as Yo}from"./chunk-PEJALHXK.js";import{$ as ke,A as Ge,B as ze,C as qe,D as Xe,E as Ye,F as Je,G as Qe,H as Ze,I as en,J as nn,K as on,L as tn,M as me,N as rn,O as an,P as sn,Q as cn,R as un,S as ln,T as pn,U as dn,V as fn,W as mn,X as kn,Y as hn,Z as Sn,_ as gn,a as xo,b as Co,c as Po,d as vo,da as wo,e as M,f as Lo,fa as Vo,g as _o,ga as h,ha as Y,i as Io,j as z,k as q,l as Ne,m as X,ma as No,n as je,na as jo,o as Oe,oa as J,p as Ue,q as Ae,r as $e,s as Me,t as De,u as He,v as fe,w as Te,x as Fe,y as Be,z as We}from"./chunk-7UYXTYXC.js";import{A as de,B as _,C as yn,a as yo,b as bo,c as R,d as g,e as Eo,f as Ko,g as se,h as ce,i as ue,j as B,k as le,l as W,m as c,r as we,t as K,w as Ve,x as L,y as G,z as k}from"./chunk-CJMVIOZX.js";import{a as Ro}from"./chunk-FUUTGGJS.js";import"./chunk-F67UH4FD.js";import{a as Bn,b as Wn,c as F,d as Gn,e as U,f as zn,g as qn,h as Xn,i as Yn,j as Jn,k as Qn}from"./chunk-QILEJIFU.js";import{a as Bo}from"./chunk-ODIECDN7.js";async function Pn(e){let n=await new N().parseKanonaks(e),r=await new D().reason(e);return{kind:"merged",catalog:n,reasoning:r}}function vn(e,n){return{kind:"merged",catalog:e,reasoning:n}}async function Ln(e,n){let r=n??new ie(new A);return{kind:"standalone",catalog:await new N().parseKanonaks(new yn(e,r))}}function j(e){return typeof e=="number"?e:void 0}function ir(e){if(!e)return;let n=c(e);if(n===c(nn))return"IRI";if(n===c(on))return"BlankNode";if(n===c(tn))return"Literal"}function _n(e){if(!e)return;let n=c(e);if(n===c(rn))return"Violation";if(n===c(an))return"Warning";if(n===c(sn))return"Info"}function ye(e,n){let r=k(e,n);if(r)return[r];let o=[];for(let t of _(e,n))t instanceof g&&o.push(t.subject);return o}function sr(e,n){let r=k(e,Ae);if(!r)return;let o={path:r},t=j(L(e,$e)),a=j(L(e,Me));t!==void 0&&(o.minCount=t),a!==void 0&&(o.maxCount=a);let s=j(L(e,Be)),i=j(L(e,We));s!==void 0&&(o.minLength=s),i!==void 0&&(o.maxLength=i);let u=j(L(e,Ge)),d=j(L(e,ze));u!==void 0&&(o.minInclusive=u),d!==void 0&&(o.maxInclusive=d);let p=G(e,Te);if(p!==void 0){let b=G(e,Fe);o.pattern=b!==void 0?{regex:p,flags:b}:{regex:p}}if(Ve(e,fe)){let b=[],w=[];for(let V of _(e,fe))V instanceof $?b.push(V.value):V instanceof g&&w.push(V.subject);b.length>0&&(o.inValues=b),w.length>0&&(o.inRefs=w)}let S=k(e,De);S&&(o.datatype=S);let y=k(e,He);y&&(o.classRef=y);let l=ir(k(e,en));l&&(o.nodeKind=l);let f=G(e,qe);f!==void 0&&(o.message=f);let m=_n(k(e,me))??n;return m&&(o.severity=m),o}function Q(e){let n=[];for(let r of e){if(!(r instanceof R)||!we(r,X))continue;let o=_n(k(r,me)),t={name:r.name,uri:h(r),targetClass:k(r,Oe),targetNodes:ye(r,Xe),targetSubjectsOf:ye(r,Ye),targetObjectsOf:ye(r,Je),closed:L(r,Qe)===!0,ignoredProperties:[],severity:o,properties:[]};for(let a of _(r,Ze))a instanceof g&&t.ignoredProperties.push(a.subject);for(let a of _(r,Ue)){let s;if(a instanceof v?s=a:a instanceof g&&(s=K(e,a.subject)),!s)continue;let i=sr(s,o);i&&t.properties.push(i)}n.push(t)}return n}var x="kanonak.org/transformations",Z="values";var ee="allowed",C=e=>({type:`${x}/VarRef`,varName:e}),be=e=>({type:`${x}/IntegerLiteral`,integerLiteral:e}),cr=e=>({type:`${x}/DecimalLiteral`,decimalLiteral:e}),In=e=>Number.isInteger(e)?be(e):cr(e),wn=e=>({type:`${x}/Count`,source:e}),Vn=(e,n)=>({type:`${x}/GreaterThanOrEqual`,compareLeft:e,compareRight:n}),Nn=(e,n)=>({type:`${x}/LessThanOrEqual`,compareLeft:e,compareRight:n});function Re(e,n){if(!n||n.length===0)return e;let r=new Set(["i","m","s"]),o=[...new Set(n.split(""))];if(o.filter(a=>!r.has(a)).length>0)throw new Error(`sh:flags '${n}' is outside the pinned regex subset (supported: i, m, s)`);return`(?${o.sort().join("")})${e}`}function ne(e){let n=[];return e.minCount!==void 0&&n.push({component:"minCount",per:"node",expr:Vn(wn(C(Z)),be(e.minCount))}),e.maxCount!==void 0&&n.push({component:"maxCount",per:"node",expr:Nn(wn(C(Z)),be(e.maxCount))}),(e.inValues!==void 0||e.inRefs!==void 0)&&n.push({component:"in",per:"value",expr:{type:`${x}/Contains`,haystack:C(ee),needle:C("v")}}),e.pattern!==void 0&&n.push({component:"pattern",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:Re(e.pattern.regex,e.pattern.flags)}}),e.minLength!==void 0&&n.push({component:"minLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{${e.minLength},}$`}}),e.maxLength!==void 0&&n.push({component:"maxLength",per:"value",expr:{type:`${x}/Matches`,matchSource:C("v"),pattern:`(?s)^.{0,${e.maxLength}}$`}}),e.minInclusive!==void 0&&n.push({component:"minInclusive",per:"value",expr:Vn(C("v"),In(e.minInclusive))}),e.maxInclusive!==void 0&&n.push({component:"maxInclusive",per:"value",expr:Nn(C("v"),In(e.maxInclusive))}),n}import{evaluate as lr,ExpressionError as pr}from"@kanonak-protocol/expression";function Un(e,n){let r=dr(n)?n:Q(n),o=[];for(let t of r)for(let a of fr(e,t))hr(e,t,a,o);return{conforms:!o.some(t=>t.severity==="Violation"),results:o}}function dr(e){return e.length>0&&!(e[0]instanceof Object&&"statement"in e[0])&&typeof e[0].name=="string"&&"properties"in e[0]}function oe(e){let n=e.predicate;return n instanceof g?n:void 0}function fr(e,n){let r=new Map,o=e.catalog.filter(a=>a instanceof R),t=a=>{let s=h(a);r.set(s?c(s):`${a.namespace}/${a.name}`,a)};if(n.targetClass){let a=c(n.targetClass);if(e.reasoning){let s=new Set(e.reasoning.getInstancesOfClass(n.targetClass));for(let i of o){let u=h(i);u&&s.has(c(u))&&t(i)}}else for(let s of o)J(s).some(u=>c(u)===a||Y(e.catalog,u).some(d=>c(d)===a))&&t(s)}for(let a of n.targetNodes){let s=K(e.catalog,a);s instanceof R&&t(s)}for(let a of n.targetSubjectsOf){let s=c(a);for(let i of o)i.statement.some(u=>{let d=oe(u);return d&&c(d.subject)===s})&&t(i)}for(let a of n.targetObjectsOf){let s=c(a);for(let i of o)for(let u of i.statement){let d=oe(u);if(!(!d||c(d.subject)!==s))for(let p of mr(u)){let S=K(e.catalog,p);S instanceof R&&t(S)}}}return[...r.values()]}function mr(e){return e instanceof B?[e.object.subject]:e instanceof W?(e.object??[]).filter(n=>n instanceof g).map(n=>n.subject):[]}function kr(e,n,r){let o=[];for(let t of e.statement){let a=oe(t);if(!(!a||c(a.subject)!==n)){if(t instanceof se||t instanceof pe)o.push({kernel:t.object,kind:"string",literal:t.object});else if(t instanceof ce)o.push({kernel:t.object,kind:"number",literal:t.object});else if(t instanceof ue)o.push({kernel:t.object?1:0,kind:"boolean",literal:t.object});else if(t instanceof B)o.push({kernel:{ref:c(t.object.subject)},kind:"reference",ref:t.object.subject});else if(t instanceof le)o.push(jn(t.object,r,o.length));else if(t instanceof W){for(let s of t.object??[])if(s instanceof g)o.push({kernel:{ref:c(s.subject)},kind:"reference",ref:s.subject});else if(s instanceof v)o.push(jn(s,r,o.length));else if(s instanceof $){let i=s.value;typeof i=="boolean"?o.push({kernel:i?1:0,kind:"boolean",literal:i}):o.push({kernel:i,kind:typeof i=="number"?"number":"string",literal:i})}}}}return o}function jn(e,n,r){let o=e.name&&e.name.length>0?e.name:String(r);return{kernel:{ref:`${n}#${o}`},kind:"embedded"}}function hr(e,n,r,o){let t=h(r),a=t?c(t):`${r.namespace}/${r.name}`;for(let s of n.properties)gr(e,n,r,a,t,s,o);n.closed&&Kr(n,r,a,t,o)}function Ee(e,n,r,o,t,a={},s){return{focusNode:n,focusUri:r,constraintComponent:o,severity:s??An(e),message:t,sourceShape:e.name,sourceShapeUri:e.uri,...a}}function An(e){return e.severity??"Violation"}var Sr={minCount:cn,maxCount:un,in:dn,pattern:fn,minLength:mn,maxLength:kn,minInclusive:hn,maxInclusive:Sn};function gr(e,n,r,o,t,a,s){let i=c(a.path),u=kr(r,i,o),d=a.severity??An(n),p=a.path.name,S=[...(a.inValues??[]).map(l=>typeof l=="boolean"?l?1:0:l),...(a.inRefs??[]).map(l=>({ref:c(l)}))],y=(l,f,m)=>{s.push(Ee(n,o,t,l,a.message??f,{resultPath:a.path,value:m?.literal,valueRef:m?.ref},d))};for(let l of ne(a)){let f=Sr[l.component];if(l.per==="node"){On(l,{[Z]:u.map(b=>b.kernel),[ee]:S})||y(f,l.component==="minCount"?`'${p}' has ${u.length} value(s); minCount is ${a.minCount}.`:`'${p}' has ${u.length} value(s); maxCount is ${a.maxCount}.`);continue}for(let m of u){if((l.component==="pattern"||l.component==="minLength"||l.component==="maxLength")&&m.kind!=="string"){y(f,`'${p}' value is not a string; ${l.component} applies to string values.`,m);continue}On(l,{v:m.kernel,[ee]:S})||y(f,yr(l,p,a,m),m)}}if(a.nodeKind)for(let l of u)br(a.nodeKind,l)||y(gn,`'${p}' value is ${l.kind}; nodeKind requires ${a.nodeKind}.`,l);if(a.datatype)for(let l of u){let f=Rr(a.datatype,l);f&&y(ln,`'${p}' ${f}`,l)}if(a.classRef)for(let l of u){let f=Er(e,a.classRef,l);f&&y(pn,`'${p}' ${f}`,l)}}function yr(e,n,r,o){let t=o.ref?c(o.ref):JSON.stringify(o.literal);switch(e.component){case"in":return`'${n}' value ${t} is not in the permitted set.`;case"pattern":return`'${n}' value ${t} does not match pattern ${r.pattern?.regex}.`;case"minLength":return`'${n}' value ${t} is shorter than minLength ${r.minLength}.`;case"maxLength":return`'${n}' value ${t} is longer than maxLength ${r.maxLength}.`;case"minInclusive":return`'${n}' value ${t} is below minInclusive ${r.minInclusive} (or not numeric).`;case"maxInclusive":return`'${n}' value ${t} is above maxInclusive ${r.maxInclusive} (or not numeric).`;default:return`'${n}' value ${t} violates ${e.component}.`}}function On(e,n){let r=o=>{let t=o.varName;if(o.type==="kanonak.org/transformations/VarRef"&&typeof t=="string"&&t in n)return n[t];throw new pr(`Conformance lowering produced an unexpected leaf '${o.type}'`)};return lr(e.expr,void 0,r)===1}function br(e,n){switch(e){case"IRI":return n.kind==="reference";case"BlankNode":return n.kind==="embedded";case"Literal":return n.kind==="string"||n.kind==="number"||n.kind==="boolean"}}function Rr(e,n){if(n.kind==="reference"||n.kind==="embedded")return`value is a ${n.kind}; sh:datatype requires a literal of ${e.name}.`;let r=he(e);if(r!==void 0)switch(r){case I.Boolean:return n.kind==="boolean"?void 0:`value is not a boolean (${e.name}).`;case I.Integer:return n.kind!=="number"?`value is not a number (${e.name}).`:Number.isInteger(n.literal)?void 0:`value is not an integer (${e.name}).`;case I.Decimal:case I.Double:case I.Float:return n.kind==="number"?void 0:`value is not a number (${e.name}).`;default:return n.kind==="string"?void 0:`value is not a string-carried literal (${e.name}).`}}function Er(e,n,r){if(r.kind!=="reference"||!r.ref)return`value is not a reference; sh:class requires an instance of ${n.name}.`;let o=c(n);if(e.reasoning)return e.reasoning.isInstanceOf(r.ref,n)?void 0:`value ${c(r.ref)} is not an instance of ${n.name}.`;let t=K(e.catalog,r.ref);return t instanceof R?J(t).some(s=>c(s)===o||Y(e.catalog,s).some(i=>c(i)===o))?void 0:`value ${c(r.ref)} is not an instance of ${n.name}.`:`value ${c(r.ref)} does not resolve in this scope (sh:class ${n.name}).`}function Kr(e,n,r,o,t){let a=new Set([...e.properties.map(i=>c(i.path)),...e.ignoredProperties.map(i=>c(i))]),s=new Set;for(let i of n.statement){let u=oe(i);if(!u)continue;let d=c(u.subject);a.has(d)||s.has(d)||(s.add(d),t.push(Ee(e,r,o,ke,`'${n.name}' carries undeclared property '${u.subject.name}' (closed shape).`,{resultPath:u.subject})))}for(let i of n.unresolvedPredicates)s.has(i.key)||(s.add(i.key),t.push(Ee(e,r,o,ke,`'${n.name}' carries unresolvable property '${i.key}' (closed shape).`,{value:i.key})))}var xr="1.1.0";async function $n(e){let n=new H(e.repository),r=n.imports(),o=r.ensure(z,q,xr,"sh"),t=(i,u)=>i&&i.version&&typeof i.version.major=="number"?`${r.ensure(i.publisher,i.package_,U(i.version),i.package_)}.${i.name}`:u,a={},s=[];return e.result.results.forEach((i,u)=>{let d=`result-${u+1}`;s.push(d);let p={type:`${o}.ValidationResult`,[`${o}.focusNode`]:t(i.focusUri,i.focusNode),[`${o}.resultMessage`]:i.message,[`${o}.resultSeverity`]:`${o}.${i.severity}`,[`${o}.sourceConstraintComponent`]:`${o}.${i.constraintComponent.name}`};i.resultPath&&(p[`${o}.resultPath`]=t(i.resultPath,c(i.resultPath))),i.sourceShapeUri&&(p[`${o}.sourceShape`]=t(i.sourceShapeUri,i.sourceShape)),i.valueRef?p[`${o}.value`]=t(i.valueRef,c(i.valueRef)):i.value!==void 0&&(p[`${o}.value`]=i.value),a[d]=p}),a.report={type:`${o}.ValidationReport`,[`${o}.conforms`]:e.result.conforms,...s.length>0?{[`${o}.result`]:s}:{}},n.buildContentAddressed({publisher:e.publisher,book:r,body:a,...e.header!==void 0?{header:e.header}:{},contentHashProperty:"contentHash"})}import{VersionOperator as ci}from"@kanonak-protocol/types/document/models/enums";var E="kanonak.org",P="view",Mn="core-kanonak",Cr={publisher:E,package_:P,name:"rootView"},Pr={publisher:E,package_:P,name:"bind"},vr={publisher:E,package_:P,name:"produces"},Lr={publisher:E,package_:P,name:"projections"},_r={publisher:E,package_:P,name:"where"},Ir={publisher:E,package_:P,name:"value"},wr={publisher:E,package_:P,name:"as"},te=class{constructor(n,r=new A){this.repository=n;this.parser=r;this.objectParser=new N(this.parser),this.builder=new H(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(n,r={}){let o=await this.objectParser.parseKanonaks(this.repository),t=this.resolveView(o,n),a=k(t,Pr);if(!a)throw new Error(`View ${t.namespace}/${t.name} declares no view.bind; cannot materialize.`);let s=k(t,vr);if(!s)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 i=Vr(t),u=Dn(o,E,Mn),d=Dn(o,E,P),p=this.builder.imports(),S=p.ensure(E,Mn,u,"ck"),y=p.ensure(E,P,d,"v"),l=p.ref(s),f=new En(this.repository,this.parser,this.objectParser),m=new Rn(f,o),b=this.readProjections(o,t),w=Or(t,_r),V=this.findInstances(o,a,await this.reason(r)),Ke={},Tn=new Set;for(let T of V){if(!await this.passesWhere(m,o,w,T))continue;let ae={type:l};for(let Ce of b){let Fn=await this.evaluateValue(m,o,Ce.value,T),Pe=this.builder.serializeValue(Hn(Fn),p);Pe!==void 0&&(ae[p.ref(Ce.as)]=Pe)}let xe=h(T);xe&&(ae[`${y}.derivedFrom`]=p.ref(xe)),Ke[this.rowName(T,Tn)]=ae}let re={};r.resolvedAt&&(re[`${S}.resolvedAt`]=r.resolvedAt),r.invocationId&&(re[`${S}.id`]=r.invocationId);let O=await this.builder.buildContentAddressed({publisher:i,book:p,body:Ke,contentHashProperty:`${S}.contentHash`,header:re});return{yaml:O.yaml,contentHash:O.contentHash,packageName:O.packageName,publisher:O.publisher,rowCount:O.resourceCount}}resolveView(n,r){let o=K(n,r);if(!o)throw new Error(`View ${r.publisher}/${r.package_}/${r.name} not found in the catalog.`);let t=k(o,Cr);if(t){let a=K(n,t);if(!a)throw new Error(`ViewPackage ${r.name} names rootView ${t.name}, which is not in the catalog.`);return a}return o}readProjections(n,r){let o=[];for(let t of _(r,Lr)){let a=t instanceof v?t:t instanceof g?K(n,t.subject):void 0;if(!a)continue;let s=de(a,Ir),i=k(a,wr);s&&i&&o.push({value:s,as:i})}return o}async reason(n){return new D({profile:n.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(n,r,o){let t=jr(n),a=[],s=new Set;for(let i of o.getInstancesOfClass(r)){if(s.has(i))continue;s.add(i);let u=t.get(i);u&&a.push(u)}return a.sort((i,u)=>{let d=M(h(i)),p=M(h(u));return d<p?-1:d>p?1:0}),a}async passesWhere(n,r,o,t){for(let a of o){let s=await this.evaluateValue(n,r,a,t);if(!Ur(s))return!1}return!0}async evaluateValue(n,r,o,t){let a=bn(o,"view-projection",{catalog:r,depth:0}),s=new Map([["input",t]]);return n.evaluate(a,s)}rowName(n,r){let o=ge(n.name)||"row",t=o,a=2;for(;r.has(t);)t=`${o}-${a++}`;return r.add(t),t}};function Hn(e){return Se(e)?e.value:Array.isArray(e)?e.map(Hn):e}function Vr(e){let n=h(e);if(!n)throw new Error(`Could not derive a publisher from view ${e.namespace}/${e.name}.`);return n.publisher}function Dn(e,n,r){let o=Nr(e,n,r);if(!o)throw new Error(`Package ${n}/${r} is not in the catalog; it must be importable to materialize a view.`);return o}function Nr(e,n,r){let o;for(let t of e){if(!(t instanceof R))continue;let a=h(t);!a||a.publisher!==n||a.package_!==r||!a.version||(!o||F(a.version,o)>0)&&(o=a.version)}return o?U(o):void 0}function jr(e){let n=new Map,r=new Map;for(let o of e){if(!(o instanceof R))continue;let t=h(o);if(!t||!t.version)continue;let a=M(t),s=r.get(a);(!s||F(t.version,s)>0)&&(r.set(a,t.version),n.set(a,o))}return n}function Or(e,n){let r=de(e,n);return r?[r]:_(e,n).filter(o=>o instanceof v)}function Ur(e){return e===!0?!0:e===!1||e===void 0||e===null?!1:typeof e=="string"?e.length>0:typeof e=="number"?e!==0:Se(e)?e.value.length>0:Array.isArray(e)?e.length>0:!!e}export{gt as AmbiguousReferenceRule,ue as BooleanStatement,Wt as CANONICAL_FORM_VERSION,I as Carrier,xt as ClassDefinitionRule,pt as ClassHierarchyCycleRule,no as CompositeKanonakDocumentRepository,Xt as DEFAULT_CONSENT_BINDING_PARAM,bo as DefinedKanonak,Ht as DiamondNameClashRule,Pt as DisplayLensScopeRule,eo as DocumentLocation,$o as EdgeType,v as EmbeddedKanonak,ct as EmbeddedKanonakTypeRule,le as EmbeddedStatement,rr as EntitlementDeniedError,ar as EntitlementProducer,Zn as FileSystemKanonakDocumentRepository,Bo as GitIgnoreFilter,Mo as GraphBuilder,mo as HttpKanonakDocumentRepository,ve as INTEGRITY_PREFIX,zt as ImportBook,ut as ImportExistenceRule,ie as InMemoryKanonakDocumentRepository,ro as KANONAK_USER_AGENT,yo as Kanonak,Go as KanonakDocumentPositions,N as KanonakObjectParser,Tt as KanonakObjectValidator,A as KanonakParser,Ro as KanonakUri,Xo as KanonakUriBuilder,Yo as KanonakUrlResolver,wo as KanonakVocabulary,It as LINE_STYLES,ot as LinkTargetRule,W as ListStatement,$ as LiteralKanonak,ko as LocalFirstRepository,ho as LockAwareRepository,At as LookBandPathRule,jt as LookRenderer,vt as LookSemanticSvgPathRule,Ct as MarkdownLinkRule,pe as MarkdownStatement,ht as NamespaceImportCycleRule,tt as NamespacePrefixRule,Ao as NodeType,ce as NumberStatement,Yt as OAuthDiscovery,To as OWL_RL_CLASSIFICATION_RULES,bt as ObjectPropertyValueValidationRule,Zo as OntologyValidationError,Jo as OntologyValidationResult,Dt as OwlOneOfRule,H as PackageBuilder,st as PackageHeaderRule,nr as ProducerRepository,Rt as PropertyDomainRule,dt as PropertyHierarchyCycleRule,Et as PropertyKindRangeConsistencyRule,Wo as PropertyMetadata,yt as PropertyRangeReferenceRule,ft as PropertyRangeRequiredRule,at as PropertyTypeSpecificityRule,lo as PublisherConfigResolver,po as PublisherIndex,Ho as RDFS_RULES,D as Reasoner,Fo as ReasoningResult,g as ReferenceKanonak,B as ReferenceStatement,to as RepositoryFactory,Kt as ReservedNameShadowRule,rt as ResourceNamingRule,xo as ResourceResolver,Vo as ResourceTypeClassifier,q as SHACL_PACKAGE,z as SHACL_PUBLISHER,X as SH_NODE_SHAPE,je as SH_PROPERTY_SHAPE,Ne as SH_SHAPE,Ko as ScalarStatement,Ut as SequenceNarrativeRule,Mt as ShaclShapeRule,Eo as Statement,se as StringStatement,mt as SubClassOfReferenceRule,kt as SubPropertyOfReferenceRule,R as SubjectKanonak,it as SubjectKanonakTypeRequiredRule,Zt as TokenCredentialProvider,Do as TripleStore,Lt as TxExpressionCompilesRule,$t as TxExpressionPathRule,Co as TypeResolver,St as UnresolvedPredicateRule,lt as UnresolvedReferenceRule,nt as ValidationCache,et as ValidationContext,Qo as ValidationSeverity,ci as VersionOperator,te as ViewMaterializer,or as allowAllPolicy,so as assertHttpsUrl,fo as assertPackageIdentity,go as buildLocalFirstRepository,Nt as buildOntologyModel,$n as buildReportPackageAsync,Q as buildShapesModel,Ft as canonicalForm,Bt as canonicalHash,he as carrierOf,So as collectKanonakFiles,F as compareVersions,Cn as computeIntegrity,Ie as computeIntegrityAsync,Gt as contentAddressedName,J as contextTypesOf,Qt as createCredentialedFetch,zn as createVersion,Un as evaluateConformance,Uo as extractMarkdownLinks,er as findDerivation,Oo as findMalformedReferences,qo as findMarkdownLinkAt,Re as foldFlagsIntoPattern,vo as formatKanonakAddress,U as formatVersion,oo as getGlobalCachePath,io as getKanonakUserAgent,Xn as isCompatibleVersion,Yn as isMajorCompatible,co as kanonakFetch,Kn as loadLockFile,ne as lowerConstraint,Lo as makeUriKey,tr as noopMeter,qt as normalizeHost,Jt as parseAuthChallenge,Po as parseKanonakAddress,Le as parseLockFile,qn as parseVersionString,zo as parseWithPositions,Qn as pickHighestDocument,No as propertiesInScope,wt as readSequenceConnectors,_t as resolveDisplayValue,jo as resolvePropertyStep,ge as sanitizeName,Jn as satisfiesVersionOperator,xn as saveLockFile,vn as scopeFromCatalog,Ln as scopeFromDocumentAsync,Pn as scopeFromRepositoryAsync,_e as serializeLockFile,uo as setKanonakFetchRetries,ao as setKanonakUserAgent,h as subjectUri,Y as superClassChain,Ot as supportedBandKeys,_o as tripleKey,M as uriKey,Io as uriTriple,Bn as versionOperatorFromChar,Wn as versionOperatorToChar,Gn as versionsEqual,Vt as walkSequence};
@@ -0,0 +1 @@
1
+ import{d as a,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i}from"../chunk-PRXC2HZ3.js";import"../chunk-QHABFCRC.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{h as EntitlementDeniedError,i as EntitlementProducer,c as ImportBook,a as PackageBuilder,e as ProducerRepository,f as allowAllPolicy,b as contentAddressedName,g as noopMeter,d as sanitizeName};
@@ -1,4 +1,4 @@
1
- import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{d as g}from"../chunk-Z5Y4MCW5.js";import"../chunk-6VIUXP4N.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import{ga as m,oa as S}from"../chunk-7UYXTYXC.js";import{c as v,m as p,t as E}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as x}from"../chunk-QILEJIFU.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
1
+ import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{d as g}from"../chunk-DD3TCFBT.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import{ga as m,oa as S}from"../chunk-7UYXTYXC.js";import{c as v,m as p,t as E}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as x}from"../chunk-QILEJIFU.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
2
2
  Install it with:
3
3
  npm install @huggingface/transformers
4
4
  (underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`