@kanonak-protocol/sdk 5.14.0 → 5.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-V3IPBWWU.js +1 -0
- package/dist/index.js +1 -1
- package/dist/reasoning/ReasoningResult.d.ts +19 -0
- package/dist/reasoning/index.js +1 -1
- package/dist/transformations/expressionRuntimeTree.d.ts +40 -0
- package/dist/transformations/index.d.ts +2 -0
- package/dist/transformations/index.js +22 -22
- package/package.json +2 -2
- package/dist/chunk-ZQAAF3GB.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as j,b as x,m as $}from"./chunk-V6KIDED2.js";import{e as l,f as u,g as b,h as C,i as a,m as U}from"./chunk-SVUMCLK5.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-YW6P24RF.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let r=b(e);return this.all.has(r)?!1:(this.all.add(r),this.tripleList.push(e),h(this.byPIdx,e.p,e),h(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&h(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let r=this.byPIdx.get(e);return r?r.slice():[]}bySubjectPredicate(e,r){let t=this.bySPIdx.get(`${e}|${r}`);return t?t.slice():[]}byPredicateObject(e,r){let t=this.byPOIdx.get(`${e}|${r}`);return t?t.slice():[]}subjectsWithPredicateObject(e,r){let t=this.byPOIdx.get(`${e}|${r}`);if(!t)return[];let s=new Set;for(let n of t)s.add(n.s);return Array.from(s)}uriObjectsOf(e,r){let t=this.bySPIdx.get(`${e}|${r}`);if(!t)return[];let s=new Set;for(let n of t)n.o.kind==="uri"&&s.add(n.o.key);return Array.from(s)}hasUri(e,r,t){return this.all.has(`${e}|${r}|u:${t}`)}hasTriple(e,r,t){return this.all.has(`${e}|${r}|${C(t)}`)}};function h(o,e,r){let t=o.get(e);t?t.push(r):o.set(e,[r])}var _={name:"rdfs2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.domain)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},E={name:"rdfs3",apply(o,e){let r=!1;for(let t of o.byPredicate(e.range)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))i.o.kind==="uri"&&o.add(a(i.o.key,e.type,n))&&(r=!0)}return r}},A={name:"rdfs5",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subPropertyOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.bySubjectPredicate(n,e.subPropertyOf))i.o.kind==="uri"&&o.add(a(s,e.subPropertyOf,i.o.key))&&(r=!0)}return r}},V={name:"rdfs7",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subPropertyOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(s)){let p={s:i.s,p:n,o:i.o};o.add(p)&&(r=!0)}}return r}},W={name:"rdfs9",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subClassOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},F={name:"rdfs11",apply(o,e){let r=!1;for(let t of o.byPredicate(e.subClassOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.bySubjectPredicate(n,e.subClassOf))i.o.kind==="uri"&&o.add(a(s,e.subClassOf,i.o.key))&&(r=!0)}return r}},k=[_,E,A,V,W,F];var N={name:"prp-trp",apply(o,e){let r=!1,t=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let s of t){let n=o.byPredicate(s);for(let i of n){if(i.o.kind!=="uri")continue;let p=i.o.key;for(let c of o.bySubjectPredicate(p,s))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(a(i.s,s,c.o.key))&&(r=!0)}}return r}},D={name:"prp-symp",apply(o,e){let r=!1,t=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let s of t)for(let n of o.byPredicate(s))n.o.kind==="uri"&&o.add(a(n.o.key,s,n.s))&&(r=!0);return r}},M={name:"prp-inv1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.inverseOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(s))i.o.kind==="uri"&&o.add(a(i.o.key,n,i.s))&&(r=!0)}return r}},z={name:"prp-inv2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.inverseOf)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(a(i.o.key,s,i.s))&&(r=!0)}return r}},B={name:"prp-eqp1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentProperty)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(s))o.add({s:i.s,p:n,o:i.o})&&(r=!0)}return r}},G={name:"prp-eqp2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentProperty)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicate(n))o.add({s:i.s,p:s,o:i.o})&&(r=!0)}return r}},H={name:"cax-eqc1",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentClass)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,s))o.add(a(i.s,e.type,n))&&(r=!0)}return r}},J={name:"cax-eqc2",apply(o,e){let r=!1;for(let t of o.byPredicate(e.equivalentClass)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.byPredicateObject(e.type,n))o.add(a(i.s,e.type,s))&&(r=!0)}return r}},Q={name:"eq-rep-s",apply(o,e){let r=!1;for(let t of o.byPredicate(e.sameAs)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n){for(let i of o.snapshot())i.s===s&&o.add({s:n,p:i.p,o:i.o})&&(r=!0);for(let i of o.snapshot())i.s===n&&o.add({s,p:i.p,o:i.o})&&(r=!0)}}return r}},X={name:"eq-rep-o",apply(o,e){let r=!1;for(let t of o.byPredicate(e.sameAs)){if(t.o.kind!=="uri")continue;let s=t.s,n=t.o.key;if(s!==n)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===s?o.add(a(i.s,i.p,n))&&(r=!0):i.o.key===n&&o.add(a(i.s,i.p,s))&&(r=!0))}return r}},K=[N,D,M,z,B,G,H,J,Q,X];var y=class{constructor(e,r){this.store=e;this.vocabulary=r}store;vocabulary;getInstancesOfClass(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,r)}getSubclasses(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,r).filter(s=>s!==r)}getSuperclasses(e){let r=f(e);return this.store.uriObjectsOf(r,this.vocabulary.subClassOf).filter(t=>t!==r)}getTypesOfIndividual(e){return this.store.uriObjectsOf(f(e),this.vocabulary.type)}isInstanceOf(e,r){return this.store.hasUri(f(e),this.vocabulary.type,f(r))}getPropertyClosure(e){let r=f(e),t={},s=new Map;for(let n of this.store.byPredicate(r)){if(n.o.kind!=="uri")continue;let i=s.get(n.s);i||(i=new Set,s.set(n.s,i),t[n.s]=[]),i.has(n.o.key)||(i.add(n.o.key),t[n.s].push(n.o.key))}return t}getPropertyClosures(e){let r={};for(let t of e)r[f(t)]=this.getPropertyClosure(t);return r}triples(){return this.store.snapshot()}size(){return this.store.size()}};function f(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new U,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let r=new d,s=await new $().parseKanonaks(e),n=new P;for(let c of s)if(c instanceof S){let m=Y(c);if(!m)continue;for(let w of c.statement)this.emitStatement(m,w,r,n)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let p=0;for(;p<this.maxIterations;){let c=!1;for(let m of i)m.apply(r,this.vocabulary)&&(c=!0);if(!c)break;p++}return new y(r,this.vocabulary)}emitStatement(e,r,t,s){let n=Z(r);if(n){if(r instanceof I){t.add({s:e,p:n,o:{kind:"literal",lexical:r.object,datatype:"string"}});return}if(r instanceof T){t.add({s:e,p:n,o:{kind:"literal",lexical:String(r.object),datatype:"number"}});return}if(r instanceof g){t.add({s:e,p:n,o:{kind:"literal",lexical:String(r.object),datatype:"boolean"}});return}if(r instanceof v){let i=l(r.object.subject);t.add(a(e,n,i));return}if(r instanceof L){let i=s.next();t.add({s:e,p:n,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r.object,t,s);return}if(r instanceof q){for(let i of r.object??[])this.emitListItem(e,n,i,t,s);return}}}emitListItem(e,r,t,s,n){if(t instanceof O)s.add(a(e,r,l(t.subject)));else if(t instanceof j){let i=n.next();s.add({s:e,p:r,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t,s,n)}else if(t instanceof x){let i=typeof t.value=="number"?"number":typeof t.value=="boolean"?"boolean":"string";s.add({s:e,p:r,o:{kind:"literal",lexical:String(t.value),datatype:i}})}}emitEmbedded(e,r,t,s){let n=`_:${e}`;for(let i of r.statement)this.emitStatement(n,i,t,s)}},P=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",r=e.indexOf("@"),t=r===-1?e:e.substring(0,r),s=t.indexOf("/");if(s===-1)return null;let n=t.substring(0,s),i=t.substring(s+1);return!n||!i||!o.name?null:u(n,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,R as e};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Kr,b as Ir,c as vr,d as Vr,e as L}from"./chunk-ZQAAF3GB.js";import{a as Y,b as ee,c as re}from"./chunk-L2KE7B3K.js";import{a as bn,c as B,e as ne,h as te,i as oe,j as Rn}from"./chunk-4PY3JJH3.js";import{a as wr,b as Er,c as xr,d as mn,e as yn,f as fn,g as kn,h as gn,i as hn,j as wn,k as F,l as En,m as xn}from"./chunk-MK6UVFOJ.js";import{a as Pn}from"./chunk-LYSCTQC2.js";import"./chunk-QHABFCRC.js";import{a as Ve,b as je,c as Ae,d as Ce,e as Se,f as Te,g as ze,h as He,i as We}from"./chunk-CC44JAOT.js";import{a as De,b as Ue,c as Oe,d as _e,e as Me,f as $e,h as Ne,j as Le,k as Fe}from"./chunk-UXYCUGSF.js";import{a as ve}from"./chunk-4NO7MHS7.js";import{a as Ar,b as Cr,c as Sr,d as Dr}from"./chunk-5NH5XDGO.js";import{a as Ur,b as _r}from"./chunk-PEUTCG3B.js";import{a as Or}from"./chunk-PEJALHXK.js";import{a as Be}from"./chunk-SC5M74NM.js";import{A as un,B as ln,K as dn,a as Mr,b as $r,c as Nr,d as Lr,e as Br,f as Fr,g as Tr,h as zr,i as Hr,j as Wr,k as qr,l as Gr,m as Jr,n as Zr,o as Qr,p as Xr,q as Yr,r as en,s as rn,t as nn,u as tn,v as on,w as an,x as sn,y as cn,z as pn}from"./chunk-Q6XQ5IXW.js";import"./chunk-ITKOKDBG.js";import{a as k,b as Ze,c as ar,i as hr,j as Pr,k as br,l as Rr,m as E}from"./chunk-V6KIDED2.js";import{a as P}from"./chunk-NJ3AZYQD.js";import{a as ir,b as sr,c as M,d as cr,e as R,f as pr,g as ur,i as lr,m as dr,o as mr,p as m,q as yr,v as fr,w as kr,x as gr}from"./chunk-SVUMCLK5.js";import{a as qe,b as Ge,c as f,d as b,e as Qe,f as Xe,g as Ye,h as er,i as rr,j as nr,k as tr,l as or,r as j,w,x as $,y as N,z as X}from"./chunk-YW6P24RF.js";import{a as Je}from"./chunk-FUUTGGJS.js";import{a as be,b as _,c as V,d as Re,e as y,f as we,g as Ee,h as xe,i as Ke,j as Ie}from"./chunk-2ACBWC7K.js";import{a as jr}from"./chunk-ODIECDN7.js";import{VersionOperator as _t}from"@kanonak-protocol/types/document/models/enums";import*as T from"js-yaml";import{VersionOperator as ae}from"@kanonak-protocol/types/document/models/enums";var Kn="0.0.0",g=class{constructor(e,r=new P,n){this.repository=e;this.parser=r;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new x}serializeValue(e,r){return ce(e,r)}async buildContentAddressed(e){let r=e.book.toImports(),n=await this.hashBody(e.publisher,r,e.body),t=z(n),a={type:"EphemeralPackage",publisher:e.publisher,imports:r};e.contentHashProperty&&(a[e.contentHashProperty]=n),Object.assign(a,e.header??{}),a.imports=r;let i={[t]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:se(s),contentHash:n,packageName:t,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let r=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:r},t;e.contentHashProperty&&(t=await this.hashBody(e.publisher,r,e.body),n[e.contentHashProperty]=t),Object.assign(n,e.header??{}),n.imports=r;let a={[e.name]:n,...e.body},i=this.dump(a),s={yaml:i,byteCount:se(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return t!==void 0&&(s.contentHash=t),s}dump(e){return T.dump(e,{lineWidth:-1})}async hashBody(e,r,n){let t={[ie]:{type:"EphemeralPackage",publisher:e,imports:r},...n},a=this.parser.parse(T.dump(t,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new X(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==ie);for(let u of c)u.namespace="ephemeral";return F(c)}},ie="__pkgbuilder_probe__";function se(o){return new TextEncoder().encode(o).length}function z(o){let e="sha256:",r=o.startsWith(e)?e.length:0;return`q-${o.slice(r,r+16)}`}var x=class{byKey=new Map;aliases=new Set;ensure(e,r,n,t,a=ae.Major){let i=`${e}/${r}@${n}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(t);return this.byKey.set(i,{publisher:e,package_:r,version:n,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,y(e.version),e.package_)}.${e.name}`}refLatest(e,r,n,t){return`${this.ensure(e,r,Kn,t??r,ae.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let t=e.get(n.publisher)??[];t.push(n),e.set(n.publisher,t)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((t,a)=>t.package_<a.package_?-1:1).map(t=>({package:t.package_,match:_(t.match),version:t.version,alias:t.alias}))}))}uniqueAlias(e){let r=K(e)||"pkg",n=r,t=2;for(;this.aliases.has(n);)n=`${r}${t++}`;return this.aliases.add(n),n}};function ce(o,e){if(o!=null){if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o;if(o instanceof b)return e.ref(o.subject);if(Array.isArray(o)){let r=o.map(n=>ce(n,e)).filter(n=>n!==void 0);return r.length>0?r:void 0}if(o instanceof k)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(In(o))throw new Error(`Value produced a bare URI without a version (${o.publisher}/${o.package_}/${o.name}); cannot serialize it as a reference.`)}}function K(o){return o.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function In(o){return typeof o=="object"&&o!==null&&typeof o.publisher=="string"&&typeof o.package_=="string"&&typeof o.name=="string"}var A=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,r){return this.producers.find(n=>n.canProduce(e,r))}async produceCached(e,r,n,t){let a=`${r}/${n}@${y(t)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(r,n,t);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,r){let n=this.producerFor(e,r.packageName);if(!n)return null;let t={operator:r.versionOperator,version:r.version},a=await n.resolveVersion(e,r.packageName,t);return a?this.produceCached(n,e,r.packageName,a):null}async getDocumentAsync(e){let r;try{r=M(e)}catch{return null}if(r.kind!=="package"||!r.version)return null;let n=this.producerFor(r.publisher,r.package_);return n?this.produceCached(n,r.publisher,r.package_,r.version):null}async getDocumentsByNamespaceAsync(e,r){return Array.from(this.produced.values()).filter(n=>{let t=n.metadata.namespace_;return t!=null&&t.publisher===e&&t.package_===r})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var H={async authorize(){return{allowed:!0}}},W={async record(){}},I=class extends Error{constructor(r,n){let t=`${r.publisher}/${r.package_}${r.version?`@${r.version.major}.${r.version.minor}.${r.version.patch}`:""}`;super(`Not entitled to produce ${t}${n?`: ${n}`:""}`);this.address=r;this.reason=n;this.name="EntitlementDeniedError"}address;reason},C=class{inner;ctx;policy;meter;constructor(e,r,n=H,t=W){this.inner=e,this.ctx=r,this.policy=n,this.meter=t}canProduce(e,r){return this.inner.canProduce(e,r)}async resolveVersion(e,r,n){return await this.assertAllowed({publisher:e,package_:r,version:n.version}),this.inner.resolveVersion(e,r,n)}async produce(e,r,n){let t={publisher:e,package_:r,version:n};await this.assertAllowed(t);let a=await this.inner.produce(e,r,n);return await this.meter.record(this.ctx,t,a),a}async assertAllowed(e){let r=await this.policy.authorize(this.ctx,e);if(!r.allowed)throw new I(e,r.reason)}};var p="kanonak.org",d="view",pe="core-kanonak",vn={publisher:p,package_:d,name:"rootView"},Vn={publisher:p,package_:d,name:"bind"},jn={publisher:p,package_:d,name:"produces"},An={publisher:p,package_:d,name:"projections"},Cn={publisher:p,package_:d,name:"where"},Sn={publisher:p,package_:d,name:"value"},Dn={publisher:p,package_:d,name:"as"},S=class{constructor(e,r=new P){this.repository=e;this.parser=r;this.objectParser=new E(this.parser),this.builder=new g(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,r={}){let n=await this.objectParser.parseKanonaks(this.repository),t=this.resolveView(n,e),a=w(t,Vn);if(!a)throw new Error(`View ${t.namespace}/${t.name} declares no view.bind; cannot materialize.`);let i=w(t,jn);if(!i)throw new Error(`View ${t.namespace}/${t.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let s=Un(t),c=ue(n,p,pe),u=ue(n,p,d),l=this.builder.imports(),D=l.ensure(p,pe,c,"ck"),de=l.ensure(p,d,u,"v"),me=l.ref(i),ye=new oe(this.repository,this.parser,this.objectParser),q=new ne(ye,n),fe=this.readProjections(n,t),ke=Mn(t,Cn),ge=this.findInstances(n,a,await this.reason(r)),G={},he=new Set;for(let v of ge){if(!await this.passesWhere(q,n,ke,v))continue;let O={type:me};for(let Z of fe){let Pe=await this.evaluateValue(q,n,Z.value,v),Q=this.builder.serializeValue(le(Pe),l);Q!==void 0&&(O[l.ref(Z.as)]=Q)}let J=m(v);J&&(O[`${de}.derivedFrom`]=l.ref(J)),G[this.rowName(v,he)]=O}let U={};r.resolvedAt&&(U[`${D}.resolvedAt`]=r.resolvedAt),r.invocationId&&(U[`${D}.id`]=r.invocationId);let h=await this.builder.buildContentAddressed({publisher:s,book:l,body:G,contentHashProperty:`${D}.contentHash`,header:U});return{yaml:h.yaml,contentHash:h.contentHash,packageName:h.packageName,publisher:h.publisher,rowCount:h.resourceCount}}resolveView(e,r){let n=j(e,r);if(!n)throw new Error(`View ${r.publisher}/${r.package_}/${r.name} not found in the catalog.`);let t=w(n,vn);if(t){let a=j(e,t);if(!a)throw new Error(`ViewPackage ${r.name} names rootView ${t.name}, which is not in the catalog.`);return a}return n}readProjections(e,r){let n=[];for(let t of N(r,An)){let a=t instanceof k?t:t instanceof b?j(e,t.subject):void 0;if(!a)continue;let i=$(a,Sn),s=w(a,Dn);i&&s&&n.push({value:i,as:s})}return n}async reason(e){return new L({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,r,n){let t=_n(e),a=[],i=new Set;for(let s of n.getInstancesOfClass(r)){if(i.has(s))continue;i.add(s);let c=t.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=R(m(s)),l=R(m(c));return u<l?-1:u>l?1:0}),a}async passesWhere(e,r,n,t){for(let a of n){let i=await this.evaluateValue(e,r,a,t);if(!$n(i))return!1}return!0}async evaluateValue(e,r,n,t){let a=te(n,"view-projection",{catalog:r,depth:0}),i=new Map([["input",t]]);return e.evaluate(a,i)}rowName(e,r){let n=K(e.name)||"row",t=n,a=2;for(;r.has(t);)t=`${n}-${a++}`;return r.add(t),t}};function le(o){return B(o)?o.value:Array.isArray(o)?o.map(le):o}function Un(o){let e=m(o);if(!e)throw new Error(`Could not derive a publisher from view ${o.namespace}/${o.name}.`);return e.publisher}function ue(o,e,r){let n=On(o,e,r);if(!n)throw new Error(`Package ${e}/${r} is not in the catalog; it must be importable to materialize a view.`);return n}function On(o,e,r){let n;for(let t of o){if(!(t instanceof f))continue;let a=m(t);!a||a.publisher!==e||a.package_!==r||!a.version||(!n||V(a.version,n)>0)&&(n=a.version)}return n?y(n):void 0}function _n(o){let e=new Map,r=new Map;for(let n of o){if(!(n instanceof f))continue;let t=m(n);if(!t||!t.version)continue;let a=R(t),i=r.get(a);(!i||V(t.version,i)>0)&&(r.set(a,t.version),e.set(a,n))}return e}function Mn(o,e){let r=$(o,e);return r?[r]:N(o,e).filter(n=>n instanceof k)}function $n(o){return o===!0?!0:o===!1||o===void 0||o===null?!1:typeof o=="string"?o.length>0:typeof o=="number"?o!==0:B(o)?o.value.length>0:Array.isArray(o)?o.length>0:!!o}export{tn as AmbiguousReferenceRule,rr as BooleanStatement,En as CANONICAL_FORM_VERSION,hr as Carrier,un as ClassDefinitionRule,Zr as ClassHierarchyCycleRule,Ae as CompositeKanonakDocumentRepository,yn as DEFAULT_CONSENT_BINDING_PARAM,Ge as DefinedKanonak,je as DocumentLocation,Er as EdgeType,k as EmbeddedKanonak,qr as EmbeddedKanonakTypeRule,tr as EmbeddedStatement,I as EntitlementDeniedError,C as EntitlementProducer,Ve as FileSystemKanonakDocumentRepository,jr as GitIgnoreFilter,xr as GraphBuilder,Fe as HttpKanonakDocumentRepository,x as ImportBook,Gr as ImportExistenceRule,ve as InMemoryKanonakDocumentRepository,De as KANONAK_USER_AGENT,qe as Kanonak,Cr as KanonakDocumentPositions,E as KanonakObjectParser,dn as KanonakObjectValidator,P as KanonakParser,Je as KanonakUri,Ur as KanonakUriBuilder,Or as KanonakUrlResolver,dr as KanonakVocabulary,or as ListStatement,Ze as LiteralKanonak,Te as LocalFirstRepository,ze as LockAwareRepository,Rn as LookRenderer,ln as MarkdownLinkRule,ar as MarkdownStatement,rn as NamespaceImportCycleRule,Fr as NamespacePrefixRule,wr as NodeType,er as NumberStatement,fn as OAuthDiscovery,vr as OWL_RL_CLASSIFICATION_RULES,an as ObjectPropertyValueValidationRule,Nr as OntologyValidationError,Mr as OntologyValidationResult,g as PackageBuilder,Wr as PackageHeaderRule,A as ProducerRepository,sn as PropertyDomainRule,Qr as PropertyHierarchyCycleRule,cn as PropertyKindRangeConsistencyRule,Ar as PropertyMetadata,on as PropertyRangeReferenceRule,Xr as PropertyRangeRequiredRule,zr as PropertyTypeSpecificityRule,Ne as PublisherConfigResolver,Le as PublisherIndex,Ir as RDFS_RULES,L as Reasoner,Vr as ReasoningResult,b as ReferenceKanonak,nr as ReferenceStatement,Se as RepositoryFactory,pn as ReservedNameShadowRule,Tr as ResourceNamingRule,ir as ResourceResolver,mr as ResourceTypeClassifier,Xe as ScalarStatement,Qe as Statement,Ye as StringStatement,Yr as SubClassOfReferenceRule,en as SubPropertyOfReferenceRule,f as SubjectKanonak,Hr as SubjectKanonakTypeRequiredRule,hn as TokenCredentialProvider,Kr as TripleStore,sr as TypeResolver,nn as UnresolvedPredicateRule,Jr as UnresolvedReferenceRule,Br as ValidationCache,Lr as ValidationContext,$r as ValidationSeverity,_t as VersionOperator,S as ViewMaterializer,H as allowAllPolicy,_e as assertHttpsUrl,Be as assertPackageIdentity,We as buildLocalFirstRepository,xn as buildOntologyModel,wn as canonicalForm,F as canonicalHash,Pr as carrierOf,He as collectKanonakFiles,V as compareVersions,re as computeIntegrity,z as contentAddressedName,gr as contextTypesOf,gn as createCredentialedFetch,we as createVersion,Rr as extractMarkdownLinks,Pn as findDerivation,_r as findInstancesByType,br as findMalformedReferences,Dr as findMarkdownLinkAt,cr as formatKanonakAddress,y as formatVersion,Ce as getGlobalCachePath,Oe as getKanonakUserAgent,xe as isCompatibleVersion,Ke as isMajorCompatible,Me as kanonakFetch,Y as loadLockFile,pr as makeUriKey,W as noopMeter,mn as normalizeHost,kn as parseAuthChallenge,M as parseKanonakAddress,Ee as parseVersionString,Sr as parseWithPositions,Ie as pickHighestDocument,fr as propertiesInScope,bn as resolveDisplayValue,kr as resolvePropertyStep,K as sanitizeName,ee as saveLockFile,$e as setKanonakFetchRetries,Ue as setKanonakUserAgent,m as subjectUri,yr as superClassChain,ur as tripleKey,R as uriKey,lr as uriTriple,be as versionOperatorFromChar,_ as versionOperatorToChar,Re as versionsEqual};
|
|
1
|
+
import{a as Kr,b as Ir,c as vr,d as Vr,e as L}from"./chunk-V3IPBWWU.js";import{a as Y,b as ee,c as re}from"./chunk-L2KE7B3K.js";import{a as bn,c as B,e as ne,h as te,i as oe,j as Rn}from"./chunk-4PY3JJH3.js";import{a as wr,b as Er,c as xr,d as mn,e as yn,f as fn,g as kn,h as gn,i as hn,j as wn,k as F,l as En,m as xn}from"./chunk-MK6UVFOJ.js";import{a as Pn}from"./chunk-LYSCTQC2.js";import"./chunk-QHABFCRC.js";import{a as Ve,b as je,c as Ae,d as Ce,e as Se,f as Te,g as ze,h as He,i as We}from"./chunk-CC44JAOT.js";import{a as De,b as Ue,c as Oe,d as _e,e as Me,f as $e,h as Ne,j as Le,k as Fe}from"./chunk-UXYCUGSF.js";import{a as ve}from"./chunk-4NO7MHS7.js";import{a as Ar,b as Cr,c as Sr,d as Dr}from"./chunk-5NH5XDGO.js";import{a as Ur,b as _r}from"./chunk-PEUTCG3B.js";import{a as Or}from"./chunk-PEJALHXK.js";import{a as Be}from"./chunk-SC5M74NM.js";import{A as un,B as ln,K as dn,a as Mr,b as $r,c as Nr,d as Lr,e as Br,f as Fr,g as Tr,h as zr,i as Hr,j as Wr,k as qr,l as Gr,m as Jr,n as Zr,o as Qr,p as Xr,q as Yr,r as en,s as rn,t as nn,u as tn,v as on,w as an,x as sn,y as cn,z as pn}from"./chunk-Q6XQ5IXW.js";import"./chunk-ITKOKDBG.js";import{a as k,b as Ze,c as ar,i as hr,j as Pr,k as br,l as Rr,m as E}from"./chunk-V6KIDED2.js";import{a as P}from"./chunk-NJ3AZYQD.js";import{a as ir,b as sr,c as M,d as cr,e as R,f as pr,g as ur,i as lr,m as dr,o as mr,p as m,q as yr,v as fr,w as kr,x as gr}from"./chunk-SVUMCLK5.js";import{a as qe,b as Ge,c as f,d as b,e as Qe,f as Xe,g as Ye,h as er,i as rr,j as nr,k as tr,l as or,r as j,w,x as $,y as N,z as X}from"./chunk-YW6P24RF.js";import{a as Je}from"./chunk-FUUTGGJS.js";import{a as be,b as _,c as V,d as Re,e as y,f as we,g as Ee,h as xe,i as Ke,j as Ie}from"./chunk-2ACBWC7K.js";import{a as jr}from"./chunk-ODIECDN7.js";import{VersionOperator as _t}from"@kanonak-protocol/types/document/models/enums";import*as T from"js-yaml";import{VersionOperator as ae}from"@kanonak-protocol/types/document/models/enums";var Kn="0.0.0",g=class{constructor(e,r=new P,n){this.repository=e;this.parser=r;this.objectParser=n??new E(this.parser)}repository;parser;objectParser;imports(){return new x}serializeValue(e,r){return ce(e,r)}async buildContentAddressed(e){let r=e.book.toImports(),n=await this.hashBody(e.publisher,r,e.body),t=z(n),a={type:"EphemeralPackage",publisher:e.publisher,imports:r};e.contentHashProperty&&(a[e.contentHashProperty]=n),Object.assign(a,e.header??{}),a.imports=r;let i={[t]:a,...e.body},s=this.dump(i);return{yaml:s,byteCount:se(s),contentHash:n,packageName:t,publisher:e.publisher,resourceCount:Object.keys(e.body).length}}async buildNamed(e){let r=e.book.toImports(),n={type:e.type??"Package",publisher:e.publisher,version:e.version,imports:r},t;e.contentHashProperty&&(t=await this.hashBody(e.publisher,r,e.body),n[e.contentHashProperty]=t),Object.assign(n,e.header??{}),n.imports=r;let a={[e.name]:n,...e.body},i=this.dump(a),s={yaml:i,byteCount:se(i),packageName:e.name,publisher:e.publisher,resourceCount:Object.keys(e.body).length};return t!==void 0&&(s.contentHash=t),s}dump(e){return T.dump(e,{lineWidth:-1})}async hashBody(e,r,n){let t={[ie]:{type:"EphemeralPackage",publisher:e,imports:r},...n},a=this.parser.parse(T.dump(t,{lineWidth:-1})),i=a.metadata.namespace_?.toString(),c=(await this.objectParser.parseKanonaks(new X(a,this.repository))).filter(u=>u instanceof f&&u.namespace===i&&u.name!==ie);for(let u of c)u.namespace="ephemeral";return F(c)}},ie="__pkgbuilder_probe__";function se(o){return new TextEncoder().encode(o).length}function z(o){let e="sha256:",r=o.startsWith(e)?e.length:0;return`q-${o.slice(r,r+16)}`}var x=class{byKey=new Map;aliases=new Set;ensure(e,r,n,t,a=ae.Major){let i=`${e}/${r}@${n}`,s=this.byKey.get(i);if(s)return s.alias;let c=this.uniqueAlias(t);return this.byKey.set(i,{publisher:e,package_:r,version:n,alias:c,match:a}),c}ref(e){if(!e.version||typeof e.version.major!="number")throw new Error(`Cannot serialize a reference to ${e.publisher}/${e.package_}/${e.name} without a version.`);return`${this.ensure(e.publisher,e.package_,y(e.version),e.package_)}.${e.name}`}refLatest(e,r,n,t){return`${this.ensure(e,r,Kn,t??r,ae.Any)}.${n}`}toImports(){let e=new Map;for(let n of this.byKey.values()){let t=e.get(n.publisher)??[];t.push(n),e.set(n.publisher,t)}return[...e.keys()].sort().map(n=>({publisher:n,packages:e.get(n).sort((t,a)=>t.package_<a.package_?-1:1).map(t=>({package:t.package_,match:_(t.match),version:t.version,alias:t.alias}))}))}uniqueAlias(e){let r=K(e)||"pkg",n=r,t=2;for(;this.aliases.has(n);)n=`${r}${t++}`;return this.aliases.add(n),n}};function ce(o,e){if(o!=null){if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o;if(o instanceof b)return e.ref(o.subject);if(Array.isArray(o)){let r=o.map(n=>ce(n,e)).filter(n=>n!==void 0);return r.length>0?r:void 0}if(o instanceof k)throw new Error("Embedded values are not yet supported by PackageBuilder. Produce a literal or a reference, or compose the embedded shape into the output class.");if(In(o))throw new Error(`Value produced a bare URI without a version (${o.publisher}/${o.package_}/${o.name}); cannot serialize it as a reference.`)}}function K(o){return o.replace(/[^A-Za-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function In(o){return typeof o=="object"&&o!==null&&typeof o.publisher=="string"&&typeof o.package_=="string"&&typeof o.name=="string"}var A=class{constructor(e){this.producers=e}producers;produced=new Map;producerFor(e,r){return this.producers.find(n=>n.canProduce(e,r))}async produceCached(e,r,n,t){let a=`${r}/${n}@${y(t)}`,i=this.produced.get(a);if(i)return i;let{document:s}=await e.produce(r,n,t);return this.produced.set(a,s),s}async getHighestCompatibleVersionAsync(e,r){let n=this.producerFor(e,r.packageName);if(!n)return null;let t={operator:r.versionOperator,version:r.version},a=await n.resolveVersion(e,r.packageName,t);return a?this.produceCached(n,e,r.packageName,a):null}async getDocumentAsync(e){let r;try{r=M(e)}catch{return null}if(r.kind!=="package"||!r.version)return null;let n=this.producerFor(r.publisher,r.package_);return n?this.produceCached(n,r.publisher,r.package_,r.version):null}async getDocumentsByNamespaceAsync(e,r){return Array.from(this.produced.values()).filter(n=>{let t=n.metadata.namespace_;return t!=null&&t.publisher===e&&t.package_===r})}async getAllDocumentsAsync(){return Array.from(this.produced.values())}async saveDocumentAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async deleteDocumentAsync(e){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async clearNamespaceAsync(e,r){throw new Error("ProducerRepository is read-only: a producer is a source, not a store.")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return null}async getDocumentUriAsync(e){return null}};var H={async authorize(){return{allowed:!0}}},W={async record(){}},I=class extends Error{constructor(r,n){let t=`${r.publisher}/${r.package_}${r.version?`@${r.version.major}.${r.version.minor}.${r.version.patch}`:""}`;super(`Not entitled to produce ${t}${n?`: ${n}`:""}`);this.address=r;this.reason=n;this.name="EntitlementDeniedError"}address;reason},C=class{inner;ctx;policy;meter;constructor(e,r,n=H,t=W){this.inner=e,this.ctx=r,this.policy=n,this.meter=t}canProduce(e,r){return this.inner.canProduce(e,r)}async resolveVersion(e,r,n){return await this.assertAllowed({publisher:e,package_:r,version:n.version}),this.inner.resolveVersion(e,r,n)}async produce(e,r,n){let t={publisher:e,package_:r,version:n};await this.assertAllowed(t);let a=await this.inner.produce(e,r,n);return await this.meter.record(this.ctx,t,a),a}async assertAllowed(e){let r=await this.policy.authorize(this.ctx,e);if(!r.allowed)throw new I(e,r.reason)}};var p="kanonak.org",d="view",pe="core-kanonak",vn={publisher:p,package_:d,name:"rootView"},Vn={publisher:p,package_:d,name:"bind"},jn={publisher:p,package_:d,name:"produces"},An={publisher:p,package_:d,name:"projections"},Cn={publisher:p,package_:d,name:"where"},Sn={publisher:p,package_:d,name:"value"},Dn={publisher:p,package_:d,name:"as"},S=class{constructor(e,r=new P){this.repository=e;this.parser=r;this.objectParser=new E(this.parser),this.builder=new g(this.repository,this.parser,this.objectParser)}repository;parser;objectParser;builder;async materialize(e,r={}){let n=await this.objectParser.parseKanonaks(this.repository),t=this.resolveView(n,e),a=w(t,Vn);if(!a)throw new Error(`View ${t.namespace}/${t.name} declares no view.bind; cannot materialize.`);let i=w(t,jn);if(!i)throw new Error(`View ${t.namespace}/${t.name} is a selection view (no view.produces). In-graph materialization of selection views is not yet supported \u2014 declare a view.produces output class to reshape the result.`);let s=Un(t),c=ue(n,p,pe),u=ue(n,p,d),l=this.builder.imports(),D=l.ensure(p,pe,c,"ck"),de=l.ensure(p,d,u,"v"),me=l.ref(i),ye=new oe(this.repository,this.parser,this.objectParser),q=new ne(ye,n),fe=this.readProjections(n,t),ke=Mn(t,Cn),ge=this.findInstances(n,a,await this.reason(r)),G={},he=new Set;for(let v of ge){if(!await this.passesWhere(q,n,ke,v))continue;let O={type:me};for(let Z of fe){let Pe=await this.evaluateValue(q,n,Z.value,v),Q=this.builder.serializeValue(le(Pe),l);Q!==void 0&&(O[l.ref(Z.as)]=Q)}let J=m(v);J&&(O[`${de}.derivedFrom`]=l.ref(J)),G[this.rowName(v,he)]=O}let U={};r.resolvedAt&&(U[`${D}.resolvedAt`]=r.resolvedAt),r.invocationId&&(U[`${D}.id`]=r.invocationId);let h=await this.builder.buildContentAddressed({publisher:s,book:l,body:G,contentHashProperty:`${D}.contentHash`,header:U});return{yaml:h.yaml,contentHash:h.contentHash,packageName:h.packageName,publisher:h.publisher,rowCount:h.resourceCount}}resolveView(e,r){let n=j(e,r);if(!n)throw new Error(`View ${r.publisher}/${r.package_}/${r.name} not found in the catalog.`);let t=w(n,vn);if(t){let a=j(e,t);if(!a)throw new Error(`ViewPackage ${r.name} names rootView ${t.name}, which is not in the catalog.`);return a}return n}readProjections(e,r){let n=[];for(let t of N(r,An)){let a=t instanceof k?t:t instanceof b?j(e,t.subject):void 0;if(!a)continue;let i=$(a,Sn),s=w(a,Dn);i&&s&&n.push({value:i,as:s})}return n}async reason(e){return new L({profile:e.reasoningProfile??"owl-rl-classification"}).reason(this.repository)}findInstances(e,r,n){let t=_n(e),a=[],i=new Set;for(let s of n.getInstancesOfClass(r)){if(i.has(s))continue;i.add(s);let c=t.get(s);c&&a.push(c)}return a.sort((s,c)=>{let u=R(m(s)),l=R(m(c));return u<l?-1:u>l?1:0}),a}async passesWhere(e,r,n,t){for(let a of n){let i=await this.evaluateValue(e,r,a,t);if(!$n(i))return!1}return!0}async evaluateValue(e,r,n,t){let a=te(n,"view-projection",{catalog:r,depth:0}),i=new Map([["input",t]]);return e.evaluate(a,i)}rowName(e,r){let n=K(e.name)||"row",t=n,a=2;for(;r.has(t);)t=`${n}-${a++}`;return r.add(t),t}};function le(o){return B(o)?o.value:Array.isArray(o)?o.map(le):o}function Un(o){let e=m(o);if(!e)throw new Error(`Could not derive a publisher from view ${o.namespace}/${o.name}.`);return e.publisher}function ue(o,e,r){let n=On(o,e,r);if(!n)throw new Error(`Package ${e}/${r} is not in the catalog; it must be importable to materialize a view.`);return n}function On(o,e,r){let n;for(let t of o){if(!(t instanceof f))continue;let a=m(t);!a||a.publisher!==e||a.package_!==r||!a.version||(!n||V(a.version,n)>0)&&(n=a.version)}return n?y(n):void 0}function _n(o){let e=new Map,r=new Map;for(let n of o){if(!(n instanceof f))continue;let t=m(n);if(!t||!t.version)continue;let a=R(t),i=r.get(a);(!i||V(t.version,i)>0)&&(r.set(a,t.version),e.set(a,n))}return e}function Mn(o,e){let r=$(o,e);return r?[r]:N(o,e).filter(n=>n instanceof k)}function $n(o){return o===!0?!0:o===!1||o===void 0||o===null?!1:typeof o=="string"?o.length>0:typeof o=="number"?o!==0:B(o)?o.value.length>0:Array.isArray(o)?o.length>0:!!o}export{tn as AmbiguousReferenceRule,rr as BooleanStatement,En as CANONICAL_FORM_VERSION,hr as Carrier,un as ClassDefinitionRule,Zr as ClassHierarchyCycleRule,Ae as CompositeKanonakDocumentRepository,yn as DEFAULT_CONSENT_BINDING_PARAM,Ge as DefinedKanonak,je as DocumentLocation,Er as EdgeType,k as EmbeddedKanonak,qr as EmbeddedKanonakTypeRule,tr as EmbeddedStatement,I as EntitlementDeniedError,C as EntitlementProducer,Ve as FileSystemKanonakDocumentRepository,jr as GitIgnoreFilter,xr as GraphBuilder,Fe as HttpKanonakDocumentRepository,x as ImportBook,Gr as ImportExistenceRule,ve as InMemoryKanonakDocumentRepository,De as KANONAK_USER_AGENT,qe as Kanonak,Cr as KanonakDocumentPositions,E as KanonakObjectParser,dn as KanonakObjectValidator,P as KanonakParser,Je as KanonakUri,Ur as KanonakUriBuilder,Or as KanonakUrlResolver,dr as KanonakVocabulary,or as ListStatement,Ze as LiteralKanonak,Te as LocalFirstRepository,ze as LockAwareRepository,Rn as LookRenderer,ln as MarkdownLinkRule,ar as MarkdownStatement,rn as NamespaceImportCycleRule,Fr as NamespacePrefixRule,wr as NodeType,er as NumberStatement,fn as OAuthDiscovery,vr as OWL_RL_CLASSIFICATION_RULES,an as ObjectPropertyValueValidationRule,Nr as OntologyValidationError,Mr as OntologyValidationResult,g as PackageBuilder,Wr as PackageHeaderRule,A as ProducerRepository,sn as PropertyDomainRule,Qr as PropertyHierarchyCycleRule,cn as PropertyKindRangeConsistencyRule,Ar as PropertyMetadata,on as PropertyRangeReferenceRule,Xr as PropertyRangeRequiredRule,zr as PropertyTypeSpecificityRule,Ne as PublisherConfigResolver,Le as PublisherIndex,Ir as RDFS_RULES,L as Reasoner,Vr as ReasoningResult,b as ReferenceKanonak,nr as ReferenceStatement,Se as RepositoryFactory,pn as ReservedNameShadowRule,Tr as ResourceNamingRule,ir as ResourceResolver,mr as ResourceTypeClassifier,Xe as ScalarStatement,Qe as Statement,Ye as StringStatement,Yr as SubClassOfReferenceRule,en as SubPropertyOfReferenceRule,f as SubjectKanonak,Hr as SubjectKanonakTypeRequiredRule,hn as TokenCredentialProvider,Kr as TripleStore,sr as TypeResolver,nn as UnresolvedPredicateRule,Jr as UnresolvedReferenceRule,Br as ValidationCache,Lr as ValidationContext,$r as ValidationSeverity,_t as VersionOperator,S as ViewMaterializer,H as allowAllPolicy,_e as assertHttpsUrl,Be as assertPackageIdentity,We as buildLocalFirstRepository,xn as buildOntologyModel,wn as canonicalForm,F as canonicalHash,Pr as carrierOf,He as collectKanonakFiles,V as compareVersions,re as computeIntegrity,z as contentAddressedName,gr as contextTypesOf,gn as createCredentialedFetch,we as createVersion,Rr as extractMarkdownLinks,Pn as findDerivation,_r as findInstancesByType,br as findMalformedReferences,Dr as findMarkdownLinkAt,cr as formatKanonakAddress,y as formatVersion,Ce as getGlobalCachePath,Oe as getKanonakUserAgent,xe as isCompatibleVersion,Ke as isMajorCompatible,Me as kanonakFetch,Y as loadLockFile,pr as makeUriKey,W as noopMeter,mn as normalizeHost,kn as parseAuthChallenge,M as parseKanonakAddress,Ee as parseVersionString,Sr as parseWithPositions,Ie as pickHighestDocument,fr as propertiesInScope,bn as resolveDisplayValue,kr as resolvePropertyStep,K as sanitizeName,ee as saveLockFile,$e as setKanonakFetchRetries,Ue as setKanonakUserAgent,m as subjectUri,yr as superClassChain,ur as tripleKey,R as uriKey,lr as uriTriple,be as versionOperatorFromChar,_ as versionOperatorToChar,Re as versionsEqual};
|
|
@@ -49,6 +49,25 @@ export declare class ReasoningResult {
|
|
|
49
49
|
* reasoning?
|
|
50
50
|
*/
|
|
51
51
|
isInstanceOf(individual: UriKey | KanonakUri, classUri: UriKey | KanonakUri): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The saturated edge set of one property, as flat reachability data:
|
|
54
|
+
* `from → every member it reaches`. Because the store is saturated,
|
|
55
|
+
* the transitive closure is already materialised — for an
|
|
56
|
+
* `owl:TransitiveProperty` this is `prp-trp`'s output, and this method
|
|
57
|
+
* is a pure projection (no walking, no re-reasoning).
|
|
58
|
+
*/
|
|
59
|
+
getPropertyClosure(propertyUri: UriKey | KanonakUri): Record<UriKey, UriKey[]>;
|
|
60
|
+
/**
|
|
61
|
+
* The closure table the expression runtime's ordered comparisons
|
|
62
|
+
* (`tx.IsAtLeast` / `tx.Dominates`) consume as caller-supplied
|
|
63
|
+
* evaluation context: `property → member → reachable members`, keyed
|
|
64
|
+
* by canonical versionless URI. THE producer half of the
|
|
65
|
+
* runtime#16 design — reason once (typically at code-generation or
|
|
66
|
+
* publish time), emit this table, and evaluators never resolve a
|
|
67
|
+
* package or compute a closure at evaluation time. Shape matches
|
|
68
|
+
* `@kanonak-protocol/expression`'s `ClosureTable` exactly.
|
|
69
|
+
*/
|
|
70
|
+
getPropertyClosures(propertyUris: ReadonlyArray<UriKey | KanonakUri>): Record<UriKey, Record<UriKey, UriKey[]>>;
|
|
52
71
|
/**
|
|
53
72
|
* The full set of saturated triples. Useful for debugging and tests.
|
|
54
73
|
*/
|
package/dist/reasoning/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-
|
|
1
|
+
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-V3IPBWWU.js";import"../chunk-V6KIDED2.js";import"../chunk-NJ3AZYQD.js";import{e as a,f as b,g as c,i as d,l as e,m as f}from"../chunk-SVUMCLK5.js";import"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import"../chunk-2ACBWC7K.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DefinedKanonak } from '../kanonaks/DefinedKanonak.js';
|
|
2
|
+
/**
|
|
3
|
+
* A node in the expression RUNTIME's tree format — the JSON contract
|
|
4
|
+
* `@kanonak-protocol/expression` evaluates (its `ExprNode`): `type` is the
|
|
5
|
+
* node class's canonical versionless URI, operand keys are the frozen `tx`
|
|
6
|
+
* operand property local names, references are canonical versionless URI
|
|
7
|
+
* strings. Declared here so the SDK does not depend on the runtime package;
|
|
8
|
+
* the shape is pinned by the runtime's shared conformance vectors.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExpressionRuntimeNode {
|
|
11
|
+
type: string;
|
|
12
|
+
[operandOrValue: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Serialize a parsed `tx` expression (a `SubjectKanonak` or
|
|
16
|
+
* `EmbeddedKanonak` from `KanonakObjectParser`) into the expression
|
|
17
|
+
* runtime's tree format, so an authored rule can be EVALUATED through
|
|
18
|
+
* `@kanonak-protocol/expression` — the adapter owed since runtime#71,
|
|
19
|
+
* and the second half (with `ReasoningResult.getPropertyClosures`) of
|
|
20
|
+
* the runtime#16 pipeline: parse → reason → adapt → evaluate.
|
|
21
|
+
*
|
|
22
|
+
* Purely mechanical, driven by the resolved object model:
|
|
23
|
+
*
|
|
24
|
+
* - the node's `type` statement (matched by canonical URI, never by
|
|
25
|
+
* local name) becomes the runtime `type` — its target's versionless
|
|
26
|
+
* canonical URI;
|
|
27
|
+
* - every other statement becomes a field keyed by the predicate's
|
|
28
|
+
* LOCAL name — which is exact here, not a heuristic: the runtime's
|
|
29
|
+
* operand keys ARE the frozen `tx` property local names, and the
|
|
30
|
+
* predicate arrives already resolved to its canonical URI;
|
|
31
|
+
* - embeddeds recurse; references serialize as versionless canonical
|
|
32
|
+
* URI strings (so `tx.UriLiteral.refTo` and `tx.viaProperty` carry
|
|
33
|
+
* exactly the identity the runtime's ordered comparisons and the
|
|
34
|
+
* reasoner's closure tables share); scalars pass through.
|
|
35
|
+
*
|
|
36
|
+
* Fails loudly on shapes the runtime cannot evaluate — a node with no
|
|
37
|
+
* (or more than one) declared type, or a duplicated operand — rather
|
|
38
|
+
* than emitting a tree that would misevaluate.
|
|
39
|
+
*/
|
|
40
|
+
export declare function toExpressionRuntimeTree(node: DefinedKanonak): ExpressionRuntimeNode;
|
|
@@ -9,6 +9,8 @@ export * from './DocAst.js';
|
|
|
9
9
|
export * from './DocAstUriConstants.js';
|
|
10
10
|
export * from './FormatOverride.js';
|
|
11
11
|
export { ReferenceResolver } from './ReferenceResolver.js';
|
|
12
|
+
export { toExpressionRuntimeTree } from './expressionRuntimeTree.js';
|
|
13
|
+
export type { ExpressionRuntimeNode } from './expressionRuntimeTree.js';
|
|
12
14
|
export type { IDocumentAstBackend } from './backends/IDocumentAstBackend.js';
|
|
13
15
|
export { HtmlBackend } from './backends/HtmlBackend.js';
|
|
14
16
|
export { JsonBackend } from './backends/JsonBackend.js';
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as X,c as Un,d as Vn,e as pe,f as ve,g as M,h as Rn,i as q,j as G}from"../chunk-4PY3JJH3.js";import{a as le}from"../chunk-LYSCTQC2.js";import"../chunk-QHABFCRC.js";import"../chunk-4NO7MHS7.js";import"../chunk-5NH5XDGO.js";import"../chunk-PEJALHXK.js";import{a as ce,b as ue,c as de,e as $n,f as Tn,g as Bn,h as xn,m as fe}from"../chunk-V6KIDED2.js";import{a as se}from"../chunk-NJ3AZYQD.js";import{e as U}from"../chunk-SVUMCLK5.js";import{b as Y,c as D,d as E,g as $,h as T,i as B,j as w,k as me,l as x,n as N,o as S,r as A}from"../chunk-YW6P24RF.js";import"../chunk-FUUTGGJS.js";import{g as ie}from"../chunk-2ACBWC7K.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
|
|
2
2
|
`);return t?.trailingNewline&&(s.endsWith(`
|
|
3
3
|
`)||(s+=`
|
|
4
|
-
`)),s}};function
|
|
4
|
+
`)),s}};function Ie(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(P(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(P(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(P),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=P(f??c),d=ye(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function P(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function ye(e,n){switch(e.kind){case"StringScalar":return _e(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=ye(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function _e(e,n){return!n||ge(n,m.ESC_RAW)?e:ge(n,m.ESC_YAML_SAFE)?Ce(e):e}function Ce(e){return e.includes(`
|
|
5
5
|
`)?`|-
|
|
6
6
|
${e.replace(/\n/g,`
|
|
7
|
-
`).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(e)?`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:e}function
|
|
7
|
+
`).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(e)?`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:e}function Ke(e){let n=[];for(let t of e){let r=z(t);r&&n.push(r)}return n.join(`
|
|
8
8
|
|
|
9
|
-
`)}function
|
|
10
|
-
`)}function
|
|
9
|
+
`)}function z(e){switch(e.kind){case"Heading":return`${"#".repeat(e.level)} ${F(e.inlines)}`;case"Paragraph":return F(e.inlines);case"RawBlock":return e.rawContent;case"PropertyList":return ke(e);case"Table":return Ne(e);default:return""}}function Ne(e){let n=e.tableColumnLabels??[],t=e.tableRows??[];if(n.length===0&&t.length===0)return"";let r=`| ${n.map(J).join(" | ")} |`,o=`| ${n.map(()=>"---").join(" | ")} |`,a=t.map(s=>`| ${(s.tableCells??[]).map(Me).join(" | ")} |`);return[r,o,...a].join(`
|
|
10
|
+
`)}function Me(e){let n=e;return!n||typeof n!="object"||!n.kind?"":n.kind==="Text"||n.kind==="ResourceLink"||n.kind==="Badge"?J(F([n])):J(z(n).replace(/\n+/g," "))}function J(e){return e==null?"":String(e).replace(/\|/g,"\\|")}function ke(e,n=0){if(!e.propertyEntries||e.propertyEntries.length===0)return"";let t=" ".repeat(n),r=[];for(let o of e.propertyEntries){let a=`${t}**${o.propertyKey}:**`,s=Pe(o.propertyValue,n+1);s.includes(`
|
|
11
11
|
`)?r.push(`${a}
|
|
12
12
|
${s}`):r.push(`${a} ${s}`)}return r.join(`
|
|
13
13
|
|
|
14
|
-
`)}function
|
|
14
|
+
`)}function Pe(e,n){if(!e||e.length===0)return"";let t=[],r=[];for(let o of e){let a=o;!a||typeof a!="object"||!a.kind||(a.kind==="Text"||a.kind==="ResourceLink"||a.kind==="Badge"?t.push(F([a])):a.kind==="PropertyList"?r.push(ke(a,n)):r.push(z(a)))}return r.length===0?t.join(""):t.length===0?r.join(`
|
|
15
15
|
|
|
16
16
|
`):`${t.join("")}
|
|
17
17
|
|
|
18
18
|
${r.join(`
|
|
19
19
|
|
|
20
|
-
`)}`}function
|
|
20
|
+
`)}`}function F(e){let n=[];for(let t of e)t.kind==="Text"?n.push(t.text):t.kind==="ResourceLink"?n.push(Fe(t)):t.kind==="Badge"&&n.push(We(t));return n.join("")}function Fe(e){let n=he(e.target);if(!n)return e.linkLabel??"[unresolved link]";let t=S(n),r=e.linkLabel&&e.linkLabel.length>0?e.linkLabel:n.name,o=e.linkTooltip?` "${be(e.linkTooltip)}"`:"";return`[${r}](${t}${o})`}function We(e){if(!e.badgeTarget)return`*${e.badgeLabel}*`;let n=he(e.badgeTarget);if(!n)return`*${e.badgeLabel}*`;let t=S(n),r=e.badgeTooltip?` "${be(e.badgeTooltip)}"`:"";return`*[${e.badgeLabel}](${t}${r})*`}function be(e){return e==null?"":String(e).replace(/"/g,'\\"')}function he(e){if(!e||typeof e!="object")return;let n=e;if(n.subject&&n.subject.publisher&&n.subject.package_&&n.subject.name){let r={publisher:n.subject.publisher,package_:n.subject.package_,name:n.subject.name};return n.subject.version&&(r.version=n.subject.version),r}let t=e;if(typeof t.namespace=="string"&&typeof t.name=="string"&&t.name.length>0){let r=/^([^/]+)\/([^@]+)@(\d+)\.(\d+)\.(\d+)$/.exec(t.namespace);if(r)return{publisher:r[1],package_:r[2],name:t.name,version:{major:Number(r[3]),minor:Number(r[4]),patch:Number(r[5])}}}}function He(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var R=class{backendUri="kanonak.org/transformations/toml";render(n,t){let o=Ye(n.metadata,t).join(`
|
|
21
21
|
`);return t?.trailingNewline&&(o.endsWith(`
|
|
22
22
|
`)||(o+=`
|
|
23
|
-
`)),o}};function
|
|
23
|
+
`)),o}};function Ye(e,n){if(!e)return[];let t=new Map;for(let a of e.entries)t.set(a.key,a);let r=n?.metadataKeys??e.entries.map(a=>a.key),o=[];for(let a of r){let s=t.get(a);if(!s)continue;let c=n?.metadataRenames.get(a)??a,u=De(s.value,s.escapeHint);u!==void 0&&o.push(`${c} = ${u}`)}return o}function De(e,n){switch(e.kind){case"StringScalar":return Xe(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=De(r,n);o!==void 0&&t.push(o)}return`[${t.join(", ")}]`}case"StructuredMap":return;default:return}}function Xe(e,n){return n&&He(n,m.ESC_TOML_MULTILINE)?Ge(e):qe(e)}function qe(e){return`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function Ge(e){return`"""
|
|
24
24
|
${e.replace(/"""/g,'\\"\\"\\"')}
|
|
25
|
-
"""`}var
|
|
25
|
+
"""`}var v=class{backendUri="kanonak.org/transformations/json";render(n,t){let r=JSON.stringify(n,null,2);return t?.trailingNewline&&!r.endsWith(`
|
|
26
26
|
`)?r+`
|
|
27
|
-
`:r}};function
|
|
27
|
+
`:r}};function Q(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var L=class{backendUri="kanonak.org/transformations/html";render(n,t){let r=Qe(n.children);if(t?.omitWrapper){let c=r.endsWith(`
|
|
28
28
|
`)?r:`${r}
|
|
29
29
|
`;return t.trailingNewline===!1&&c.endsWith(`
|
|
30
|
-
`)?c.slice(0,-1):c}let o=
|
|
30
|
+
`)?c.slice(0,-1):c}let o=Je(n.metadata)??"Untitled",a=ze(n.metadata,t),s=`<!DOCTYPE html>
|
|
31
31
|
<html lang="en">
|
|
32
32
|
<head>
|
|
33
33
|
<meta charset="utf-8">
|
|
@@ -57,35 +57,35 @@ ${a}${r}
|
|
|
57
57
|
</body>
|
|
58
58
|
</html>
|
|
59
59
|
`;return t?.trailingNewline===!1&&s.endsWith(`
|
|
60
|
-
`)?s.slice(0,-1):s}};function
|
|
60
|
+
`)?s.slice(0,-1):s}};function Je(e){if(e){for(let n of e.entries)if((n.key==="title"||n.key==="name")&&n.value.kind==="StringScalar")return n.value.stringValue}}function ze(e,n){if(!e||e.entries.length===0)return"";let t=n?.metadataKeys??e.entries.map(a=>a.key),r=new Map(e.entries.map(a=>[a.key,a])),o=[];for(let a of t){let s=r.get(a);if(!s)continue;let c=n?.metadataRenames.get(a)??a,u=we(s.value);u!==void 0&&o.push(` <dt>${y(c)}</dt>
|
|
61
61
|
<dd>${u}</dd>`)}return o.length===0?"":`<dl class="metadata">
|
|
62
62
|
${o.join(`
|
|
63
63
|
`)}
|
|
64
64
|
</dl>
|
|
65
|
-
`}function
|
|
66
|
-
`)}function
|
|
65
|
+
`}function we(e){switch(e.kind){case"StringScalar":return y(e.stringValue);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let n=[];for(let t of e.items){let r=we(t);r!==void 0&&n.push(`<code>${r}</code>`)}return n.join(", ")}case"StructuredMap":return;default:return}}function Qe(e){let n=[];for(let t of e){let r=Z(t);r&&n.push(r)}return n.join(`
|
|
66
|
+
`)}function Z(e){switch(e.kind){case"Heading":{let n=Math.max(1,Math.min(6,e.level));return`<h${n}>${W(e.inlines)}</h${n}>`}case"Paragraph":return`<p>${W(e.inlines)}</p>`;case"RawBlock":return on(e);case"PropertyList":return tn(e);case"Table":return Ze(e);default:return""}}function Ze(e){let n=e.tableColumnLabels??[],t=e.tableRows??[],r=n.length>0?`<thead>
|
|
67
67
|
<tr>${n.map(a=>`<th>${y(a)}</th>`).join("")}</tr>
|
|
68
68
|
</thead>
|
|
69
69
|
`:"",o=t.length>0?`<tbody>
|
|
70
|
-
${t.map(
|
|
70
|
+
${t.map(en).join(`
|
|
71
71
|
`)}
|
|
72
72
|
</tbody>
|
|
73
73
|
`:"";return`<table class="property-table">
|
|
74
|
-
${r}${o}</table>`}function
|
|
74
|
+
${r}${o}</table>`}function en(e){return` <tr>${(e.tableCells??[]).map(r=>`<td>${nn(r)}</td>`).join("")}</tr>`}function nn(e){let n=e;return!n||typeof n!="object"||!n.kind?"":n.kind==="Text"||n.kind==="ResourceLink"||n.kind==="Badge"?W([n]):Z(n)}function tn(e){if(!e.propertyEntries||e.propertyEntries.length===0)return"";let n=[];for(let t of e.propertyEntries){let o=`<dt${t.propertyTooltip?` title="${j(t.propertyTooltip)}"`:""}>${y(t.propertyKey)}</dt>`,a=`<dd>${rn(t.propertyValue)}</dd>`;n.push(o,a)}return`<dl class="property-list">
|
|
75
75
|
${n.join(`
|
|
76
76
|
`)}
|
|
77
|
-
</dl>`}function
|
|
77
|
+
</dl>`}function rn(e){if(!e||e.length===0)return"";let n=[];for(let t of e){let r=t;!r||typeof r!="object"||!r.kind||(r.kind==="Text"||r.kind==="ResourceLink"||r.kind==="Badge"?n.push(W([r])):n.push(Z(r)))}return n.join("")}function on(e){let n=e.mediaType;return n&&Q(n,m.TEXT_MARKDOWN)?X(e.rawContent):n&&Q(n,m.TEXT_HTML)?e.rawContent:n&&Q(n,m.IMAGE_SVG_XML)?`<figure class="svg-figure">
|
|
78
78
|
${e.rawContent}
|
|
79
|
-
</figure>`:`<pre${n?` class="media-${
|
|
79
|
+
</figure>`:`<pre${n?` class="media-${j(n.name)}"`:""}><code>${y(e.rawContent)}</code></pre>`}function W(e){let n=[];for(let t of e)t.kind==="Text"?n.push(y(t.text)):t.kind==="ResourceLink"?n.push(an(t)):t.kind==="Badge"&&n.push(sn(t));return n.join("")}function an(e){let n=Se(e.target);if(!n)return y(e.linkLabel??"[unresolved link]");let t=S(n),r=e.linkLabel&&e.linkLabel.length>0?e.linkLabel:n.name,o=e.linkTooltip?` title="${j(e.linkTooltip)}"`:"";return`<a class="kan-link" href="${j(t)}"${o}>${y(r)}</a>`}function sn(e){let n=e.badgeTooltip?` title="${j(e.badgeTooltip)}"`:"",t=y(e.badgeLabel);if(!e.badgeTarget)return`<span class="kan-badge"${n}>${t}</span>`;let r=Se(e.badgeTarget);if(!r)return`<span class="kan-badge"${n}>${t}</span>`;let o=S(r);return`<a class="kan-badge" href="${j(o)}"${n}>${t}</a>`}function Se(e){if(!e||typeof e!="object")return;let n=e;if(n.subject&&n.subject.publisher&&n.subject.package_&&n.subject.name){let r={publisher:n.subject.publisher,package_:n.subject.package_,name:n.subject.name};return n.subject.version&&(r.version=n.subject.version),r}let t=e;if(typeof t.namespace=="string"&&typeof t.name=="string"&&t.name.length>0){let r=/^([^/]+)\/([^@]+)@(\d+)\.(\d+)\.(\d+)$/.exec(t.namespace);if(r)return{publisher:r[1],package_:r[2],name:t.name,version:{major:Number(r[3]),minor:Number(r[4]),patch:Number(r[5])}}}}function y(e){return e==null?"":String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function j(e){return e==null?"":String(e).replace(/"/g,""").replace(/&/g,"&")}function cn(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var O=class{backendUri="kanonak.org/transformations/svg";render(n,t){for(let r of n.children)if(r.kind==="RawBlock"&&r.mediaType&&cn(r.mediaType,m.IMAGE_SVG_XML)){let o=r.rawContent;return t?.trailingNewline&&!o.endsWith(`
|
|
80
80
|
`)&&(o+=`
|
|
81
|
-
`),o}return'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'}};function
|
|
81
|
+
`),o}return'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'}};function un(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var I=class{backendUri="kanonak.org/transformations/stylesheet";render(n,t){let r=[];for(let a of n.children)a.kind==="RawBlock"&&a.mediaType&&un(a.mediaType,m.TEXT_CSS)&&r.push(a.rawContent);let o=r.join(`
|
|
82
82
|
|
|
83
83
|
`);return t?.trailingNewline&&o.length>0&&!o.endsWith(`
|
|
84
84
|
`)&&(o+=`
|
|
85
|
-
`),o}};function
|
|
85
|
+
`),o}};function mn(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var _=class{backendUri="kanonak.org/transformations/yaml";render(n,t){let r=[];for(let a of n.children)a.kind==="RawBlock"&&a.mediaType&&mn(a.mediaType,m.TEXT_YAML)&&r.push(a.rawContent);let o=r.join(`
|
|
86
86
|
|
|
87
87
|
`);return t?.trailingNewline&&o.length>0&&!o.endsWith(`
|
|
88
88
|
`)&&(o+=`
|
|
89
|
-
`),o}};function
|
|
89
|
+
`),o}};function C(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var K=class{backendUri="kanonak.org/transformations/dynamodb-json";render(n,t){if(!n.metadata)throw new Error("dynamodb-json backend: Document has no `metadata` channel. This backend serializes Document.metadata into DynamoDB attribute-value JSON \u2014 the transformation must populate that channel. (No silent empty artifact.)");let r=Ae(n.metadata,t),o=JSON.stringify(r,null,2);return t?.trailingNewline&&!o.endsWith(`
|
|
90
90
|
`)&&(o+=`
|
|
91
|
-
`),o}};function ke(e,n){let t=new Map;for(let a of e.entries)t.set(a.key,a);let r=n?.metadataKeys??e.entries.map(a=>a.key),o={};for(let a of r){let s=t.get(a);if(!s)continue;let c=n?.metadataRenames.get(a)??a;o[c]=be(s.value,s.escapeHint)}return{M:o}}function be(e,n){switch(e.kind){case"StructuredMap":return ke(e);case"StructuredList":return{L:e.items.map(t=>be(t,void 0))};case"StringScalar":return on(e.stringValue,n??e.escapeHint);case"IntegerScalar":return an(e.integerValue,n??e.escapeHint)}}function on(e,n){if(n&&V(n,m.ESC_DYNAMODB_BOOL)){if(e==="true")return{BOOL:!0};if(e==="false")return{BOOL:!1};throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-bool must have the value "true" or "false"; got ${JSON.stringify(e)}.`)}if(n&&V(n,m.ESC_DYNAMODB_NULL))return{NULL:!0};if(n&&V(n,m.ESC_DYNAMODB_NUMBER)){if(e.trim()===""||Number.isNaN(Number(e)))throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-number must hold a numeric literal; got ${JSON.stringify(e)}.`);return{N:e}}return{S:e}}function an(e,n){if(n&&V(n,m.ESC_DYNAMODB_BOOL))throw new Error(`dynamodb-json backend: esc-dynamodb-bool cannot apply to an IntegerScalar (value ${e}). Use a StringScalar "true"/"false".`);if(n&&V(n,m.ESC_DYNAMODB_NULL))throw new Error(`dynamodb-json backend: esc-dynamodb-null cannot apply to an IntegerScalar (value ${e}). Use a StringScalar hinted esc-dynamodb-null.`);return{N:String(e)}}var sn={"markdown-with-frontmatter":{formatUri:"kanonak.org/transformations/markdown-with-frontmatter",extension:".md"},"plain-markdown":{formatUri:"kanonak.org/transformations/plain-markdown",extension:".md"},toml:{formatUri:"kanonak.org/transformations/toml",extension:".toml"},json:{formatUri:"kanonak.org/transformations/json",extension:".json"},html:{formatUri:"kanonak.org/transformations/html",extension:".html"},svg:{formatUri:"kanonak.org/transformations/svg",extension:".svg"},stylesheet:{formatUri:"kanonak.org/transformations/stylesheet",extension:".css"},yaml:{formatUri:"kanonak.org/transformations/yaml",extension:".yaml"},"dynamodb-json":{formatUri:"kanonak.org/transformations/dynamodb-json",extension:".json"}},h=class extends Error{},C=class{backends=new Map;constructor(){this.register(new j),this.register(new E),this.register(new B),this.register(new T),this.register(new $),this.register(new U),this.register(new x),this.register(new v)}register(n){this.backends.set(n.backendUri,n)}async run(n){let t=n.transformationKanonaks??n.allKanonaks,r=O(n.transformation,t);if(!r.outputs.has(n.outputFormat))throw new h(`Transformation "${r.name}" does not declare output format "${n.outputFormat}". Declared: ${Array.from(r.outputs).join(", ")}`);let o=this.findBackend(n.outputFormat);if(!o)throw new h(`No backend registered for OutputFormat "${n.outputFormat}".`);let a=new X(n.repository,n.parser,n.objectParser),s=new ce(a,n.allKanonaks,r.fragments);return r.kind==="instance"?this.runInstance(r,n,o,s):this.runSet(r,n,o,s)}async runInstance(n,t,r,o){let a=he(t.instances,n.inputPattern.requires),s=De(a,n.inputPattern.sortBy),c=[];for(let u of s){let f=new Map;f.set("input",u);let l=await o.evaluate(n.rule,f);Z(l,n.name,`input "${u.name}"`);let d=ee(await o.evaluate(n.artifactName,f),n.name,`input "${u.name}"`),g=ne(n.overrides.get(t.outputFormat),t.runtimeOverride),k=r.render(l,g);c.push({fileName:d,format:t.outputFormat,content:k,source:{kind:"instance",sourceName:u.name}})}return c}async runSet(n,t,r,o){let a=he(t.instances,n.inputPattern.requires),s=De(a,n.inputPattern.sortBy);return n.partitionBy?this.runSetWithPartition(n,s,t,r,o):this.runSetSingle(n,s,t,r,o)}async runSetSingle(n,t,r,o,a){let s=new Map;s.set("inputs",t);let c=await a.evaluate(n.rule,s);Z(c,n.name,"set");let u=ee(await a.evaluate(n.artifactName,s),n.name,"set"),f=ne(n.overrides.get(r.outputFormat),r.runtimeOverride),l=o.render(c,f);return[{fileName:u,format:r.outputFormat,content:l,source:{kind:"set",memberCount:t.length}}]}async runSetWithPartition(n,t,r,o,a){let s=n.partitionBy,c=new Map,u=[];for(let l of t){let d=mn(l,s);if(d==null)continue;let g=dn(d),k=c.get(g);k||(k={keyValue:d,keyDisplay:fn(d),members:[]},c.set(g,k),u.push(g)),k.members.push(l)}let f=[];for(let l of u){let d=c.get(l),g=new Map;g.set("inputs",d.members),g.set("key",d.keyValue);let k=await a.evaluate(n.rule,g);Z(k,n.name,`partition "${d.keyDisplay}"`);let je=ee(await a.evaluate(n.artifactName,g),n.name,`partition "${d.keyDisplay}"`),Ee=ne(n.overrides.get(r.outputFormat),r.runtimeOverride),Be=o.render(k,Ee);f.push({fileName:je,format:r.outputFormat,content:Be,source:{kind:"set",memberCount:d.members.length,partitionKey:d.keyDisplay}})}return f}findBackend(n){let t=sn[n];if(t)return this.backends.get(t.formatUri)}};function he(e,n){return n.length===0?e:e.filter(t=>{for(let r of n)if(!un(t,r))return!1;return!0})}function De(e,n){if(n.length===0)return e;let t=[...e];return t.sort((r,o)=>{for(let a of n){let s=Ae(r,a.byProperty),c=Ae(o,a.byProperty),u=cn(s,c,a.order);if(u!==0)return u}return 0}),t}function Ae(e,n){for(let t of e.statement){let r=te(t);if(!(!r||!L(r,n))){if(t instanceof M||t instanceof P||t instanceof F)return t.object;if(t instanceof H)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a list \u2014 list-typed properties are not sortable. Use a scalar property.`);if(t instanceof W)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a reference \u2014 reference-typed properties don't have a natural total order. Use a scalar property.`)}}}function cn(e,n,t){if(e===void 0&&n===void 0)return 0;if(e===void 0)return t==="ascending"?1:-1;if(n===void 0)return t==="ascending"?-1:1;let r;return typeof e=="number"&&typeof n=="number"?r=e-n:r=String(e).localeCompare(String(n)),t==="ascending"?r:-r}function un(e,n){for(let t of e.statement){let r=te(t);if(!r||!L(r,n))continue;let o=t.object;if(o!=null&&!(typeof o=="string"&&o.length===0)&&!(Array.isArray(o)&&o.length===0))return!0}return!1}function mn(e,n){for(let t of e.statement){let r=te(t);if(!(!r||!L(r,n))&&(t instanceof M||t instanceof P||t instanceof F||t instanceof W||t instanceof H))return t.object}}function te(e){return e.predicate?.subject}function dn(e){if(e===void 0)return" undef";if(e===null)return" null";if(typeof e=="string")return`s:${e}`;if(typeof e=="number")return`n:${e}`;if(typeof e=="boolean")return`b:${e}`;if(e instanceof K){let n=e.subject;return`r:${n.publisher}/${n.package_}/${n.name}`}if(e instanceof N){let n=e.name??"";return`k:${e.namespace??""}/${n}`}if(typeof e=="object"&&e!==null&&typeof e.name=="string"&&typeof e.publisher=="string"){let n=e;return`u:${n.publisher}/${n.package_}/${n.name}`}return`o:${JSON.stringify(e)}`}function fn(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):e instanceof K?e.subject.name:e instanceof N?e.name??"":typeof e=="object"&&e!==null&&typeof e.name=="string"?e.name:""}function Z(e,n,t){if(typeof e!="object"||e===null||e.kind!=="Document")throw new h(`Transformation "${n}" rule did not yield a Document for ${t}. Got: ${Se(e)}`)}function ee(e,n,t){if(typeof e=="string")return e;if(Array.isArray(e)&&e.every(ln))return e.map(r=>String(r)).join("");throw new h(`Transformation "${n}" artifactName did not yield a string for ${t}. Got: ${Se(e)}`)}function ln(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Se(e){if(e===void 0)return"undefined";if(e===null)return"null";if(Array.isArray(e))return`array(${e.length})`;if(typeof e=="object"){let n=e.kind;return n?`object(kind=${n})`:"object"}return typeof e}function ne(e,n){if(!e&&!n)return;let t={metadataRenames:n?.metadataRenames??e?.metadataRenames??new Map},r=n?.metadataKeys??e?.metadataKeys;r!==void 0&&(t.metadataKeys=r);let o=n?.trailingNewline??e?.trailingNewline;o!==void 0&&(t.trailingNewline=o);let a=n?.omitWrapper??e?.omitWrapper;return a!==void 0&&(t.omitWrapper=a),t}var p=class extends Error{constructor(t,r){super(t);this.cause=r;this.name="RenderError"}cause},we={publisher:"kanonak.org",package_:"derivation",name:"default"},re=class{constructor(n,t=new ae,r=new ie){this.repository=n;this.parser=t;this.objectParser=r}repository;parser;objectParser;runner=new C;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async renderViaLook(n){let t=await this.getCatalog(),r=S(t,n.resource);if(!(r instanceof D))throw new p(`Resource not found: ${b(n.resource)}`);let o=new q(t),a;if(n.format.name==="html")a=await o.renderHtml(r);else if(n.format.name==="stylesheet")a=o.renderStylesheet(r);else throw new p(`LookRenderer does not support format ${b(n.format)} \u2014 only formats.html and formats.stylesheet are implemented in v0.1.`);return{content:a,format:n.format,filename:r.name}}async findDerivation(n){let t=await this.getCatalog(),r=S(t,n.resource);if(!(r instanceof D))return;let o=n.variant??we;return se(r,n.format,o,t)}async render(n){if(n.format.name==="html"||n.format.name==="stylesheet"){let a=await this.getCatalog(),s=S(a,n.resource);if(s instanceof D){let u=new q(a).findCascadedLook(s);if(u&&!gn(u.sourceClass)){let f=await this.findDerivation(n);if(!f||pn(f))return this.renderViaLook({resource:n.resource,format:n.format})}}}let t=await this.findDerivation(n);if(!t)throw new p(`No derivation found for ${b(n.resource)} \u2192 format ${b(n.format)}`+(n.variant?` variant ${b(n.variant)}`:""));let r=oe(t.transformation.version),o={transformation:{publisher:t.transformation.publisher,package_:t.transformation.package_,name:t.transformation.name,...r?{version:r}:{}},input:n.resource,format:n.format};return n.omitWrapper!==void 0&&(o.omitWrapper=n.omitWrapper),this.runTransformation(o)}async runTransformation(n){let t=await this.getCatalog(),r=S(t,n.transformation);if(!(r instanceof D))throw new p(`Transformation not found: ${b(n.transformation)}`);let o=S(t,n.input);if(!(o instanceof D))throw new p(`Input resource not found: ${b(n.input)}`);let a=O(r,t),s=yn(a.outputs,n.format);if(!s)throw new p(`Transformation ${b(n.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${b(n.format)}`);let c;try{c=await this.runner.run({transformation:r,instances:[o],allKanonaks:t,repository:this.repository,parser:this.parser,objectParser:this.objectParser,outputFormat:s,...n.omitWrapper!==void 0?{runtimeOverride:{metadataRenames:new Map,omitWrapper:n.omitWrapper}}:{}})}catch(u){throw new p(`Transformation execution failed: ${u.message}`,u)}if(c.length===0)throw new p("Transformation produced no artifacts");return{content:c[0].content,format:n.format,filename:c[0].fileName}}async getCatalog(){return this.cachedCatalog||(this.cachedCatalog=await this.objectParser.parseKanonaks(this.repository)),this.cachedCatalog}};function b(e){return`${e.publisher}/${e.package_}/${e.name}`}function pn(e){return typeof e.source=="string"?!1:e.source.publisher==="kanonak.org"&&e.source.package_==="core-rdf"&&e.source.name==="Resource"}function gn(e){return e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Resource"}function yn(e,n){let t=n.name;if(e.has(t))return t;for(let r of e)if(r.startsWith(t+"-")||r===t)return r}export{U as CssBackend,we as DEFAULT_VARIANT,m as DOCAST,Ue as DOCAST_PKG,$e as DOCAST_PUB,v as DynamoDbBackend,ce as ExpressionEngineV3,Sn as ExpressionEvalErrorV3,T as HtmlBackend,B as JsonBackend,j as MarkdownFrontmatterBackend,X as ReferenceResolver,p as RenderError,sn as SUPPORTED_FORMATS_V3,$ as SvgBackend,Dn as TX_V3,bn as TX_V3_PKG,kn as TX_V3_PUB,hn as TX_V3_VERSION_MAJOR,E as TomlBackend,re as TransformationEngine,Te as TransformationLoadErrorV3,h as TransformationRunnerErrorV3,C as TransformationRunnerV3,x as YamlBackend,wn as compileExpression,O as compileTransformationV3,An as isRawStringV3,Y as renderMarkdownToHtml};
|
|
91
|
+
`),o}};function Ae(e,n){let t=new Map;for(let a of e.entries)t.set(a.key,a);let r=n?.metadataKeys??e.entries.map(a=>a.key),o={};for(let a of r){let s=t.get(a);if(!s)continue;let c=n?.metadataRenames.get(a)??a;o[c]=je(s.value,s.escapeHint)}return{M:o}}function je(e,n){switch(e.kind){case"StructuredMap":return Ae(e);case"StructuredList":return{L:e.items.map(t=>je(t,void 0))};case"StringScalar":return dn(e.stringValue,n??e.escapeHint);case"IntegerScalar":return fn(e.integerValue,n??e.escapeHint)}}function dn(e,n){if(n&&C(n,m.ESC_DYNAMODB_BOOL)){if(e==="true")return{BOOL:!0};if(e==="false")return{BOOL:!1};throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-bool must have the value "true" or "false"; got ${JSON.stringify(e)}.`)}if(n&&C(n,m.ESC_DYNAMODB_NULL))return{NULL:!0};if(n&&C(n,m.ESC_DYNAMODB_NUMBER)){if(e.trim()===""||Number.isNaN(Number(e)))throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-number must hold a numeric literal; got ${JSON.stringify(e)}.`);return{N:e}}return{S:e}}function fn(e,n){if(n&&C(n,m.ESC_DYNAMODB_BOOL))throw new Error(`dynamodb-json backend: esc-dynamodb-bool cannot apply to an IntegerScalar (value ${e}). Use a StringScalar "true"/"false".`);if(n&&C(n,m.ESC_DYNAMODB_NULL))throw new Error(`dynamodb-json backend: esc-dynamodb-null cannot apply to an IntegerScalar (value ${e}). Use a StringScalar hinted esc-dynamodb-null.`);return{N:String(e)}}var ln={"markdown-with-frontmatter":{formatUri:"kanonak.org/transformations/markdown-with-frontmatter",extension:".md"},"plain-markdown":{formatUri:"kanonak.org/transformations/plain-markdown",extension:".md"},toml:{formatUri:"kanonak.org/transformations/toml",extension:".toml"},json:{formatUri:"kanonak.org/transformations/json",extension:".json"},html:{formatUri:"kanonak.org/transformations/html",extension:".html"},svg:{formatUri:"kanonak.org/transformations/svg",extension:".svg"},stylesheet:{formatUri:"kanonak.org/transformations/stylesheet",extension:".css"},yaml:{formatUri:"kanonak.org/transformations/yaml",extension:".yaml"},"dynamodb-json":{formatUri:"kanonak.org/transformations/dynamodb-json",extension:".json"}},h=class extends Error{},H=class{backends=new Map;constructor(){this.register(new V),this.register(new R),this.register(new v),this.register(new L),this.register(new O),this.register(new I),this.register(new _),this.register(new K)}register(n){this.backends.set(n.backendUri,n)}async run(n){let t=n.transformationKanonaks??n.allKanonaks,r=M(n.transformation,t);if(!r.outputs.has(n.outputFormat))throw new h(`Transformation "${r.name}" does not declare output format "${n.outputFormat}". Declared: ${Array.from(r.outputs).join(", ")}`);let o=this.findBackend(n.outputFormat);if(!o)throw new h(`No backend registered for OutputFormat "${n.outputFormat}".`);let a=new q(n.repository,n.parser,n.objectParser),s=new pe(a,n.allKanonaks,r.fragments);return r.kind==="instance"?this.runInstance(r,n,o,s):this.runSet(r,n,o,s)}async runInstance(n,t,r,o){let a=Ee(t.instances,n.inputPattern.requires),s=$e(a,n.inputPattern.sortBy),c=[];for(let u of s){let f=new Map;f.set("input",u);let l=await o.evaluate(n.rule,f);ee(l,n.name,`input "${u.name}"`);let d=ne(await o.evaluate(n.artifactName,f),n.name,`input "${u.name}"`),g=te(n.overrides.get(t.outputFormat),t.runtimeOverride),k=r.render(l,g);c.push({fileName:d,format:t.outputFormat,content:k,source:{kind:"instance",sourceName:u.name}})}return c}async runSet(n,t,r,o){let a=Ee(t.instances,n.inputPattern.requires),s=$e(a,n.inputPattern.sortBy);return n.partitionBy?this.runSetWithPartition(n,s,t,r,o):this.runSetSingle(n,s,t,r,o)}async runSetSingle(n,t,r,o,a){let s=new Map;s.set("inputs",t);let c=await a.evaluate(n.rule,s);ee(c,n.name,"set");let u=ne(await a.evaluate(n.artifactName,s),n.name,"set"),f=te(n.overrides.get(r.outputFormat),r.runtimeOverride),l=o.render(c,f);return[{fileName:u,format:r.outputFormat,content:l,source:{kind:"set",memberCount:t.length}}]}async runSetWithPartition(n,t,r,o,a){let s=n.partitionBy,c=new Map,u=[];for(let l of t){let d=yn(l,s);if(d==null)continue;let g=kn(d),k=c.get(g);k||(k={keyValue:d,keyDisplay:bn(d),members:[]},c.set(g,k),u.push(g)),k.members.push(l)}let f=[];for(let l of u){let d=c.get(l),g=new Map;g.set("inputs",d.members),g.set("key",d.keyValue);let k=await a.evaluate(n.rule,g);ee(k,n.name,`partition "${d.keyDisplay}"`);let Ue=ne(await a.evaluate(n.artifactName,g),n.name,`partition "${d.keyDisplay}"`),Ve=te(n.overrides.get(r.outputFormat),r.runtimeOverride),Re=o.render(k,Ve);f.push({fileName:Ue,format:r.outputFormat,content:Re,source:{kind:"set",memberCount:d.members.length,partitionKey:d.keyDisplay}})}return f}findBackend(n){let t=ln[n];if(t)return this.backends.get(t.formatUri)}};function Ee(e,n){return n.length===0?e:e.filter(t=>{for(let r of n)if(!gn(t,r))return!1;return!0})}function $e(e,n){if(n.length===0)return e;let t=[...e];return t.sort((r,o)=>{for(let a of n){let s=Te(r,a.byProperty),c=Te(o,a.byProperty),u=pn(s,c,a.order);if(u!==0)return u}return 0}),t}function Te(e,n){for(let t of e.statement){let r=re(t);if(!(!r||!N(r,n))){if(t instanceof $||t instanceof T||t instanceof B)return t.object;if(t instanceof x)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a list \u2014 list-typed properties are not sortable. Use a scalar property.`);if(t instanceof w)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a reference \u2014 reference-typed properties don't have a natural total order. Use a scalar property.`)}}}function pn(e,n,t){if(e===void 0&&n===void 0)return 0;if(e===void 0)return t==="ascending"?1:-1;if(n===void 0)return t==="ascending"?-1:1;let r;return typeof e=="number"&&typeof n=="number"?r=e-n:r=String(e).localeCompare(String(n)),t==="ascending"?r:-r}function gn(e,n){for(let t of e.statement){let r=re(t);if(!r||!N(r,n))continue;let o=t.object;if(o!=null&&!(typeof o=="string"&&o.length===0)&&!(Array.isArray(o)&&o.length===0))return!0}return!1}function yn(e,n){for(let t of e.statement){let r=re(t);if(!(!r||!N(r,n))&&(t instanceof $||t instanceof T||t instanceof B||t instanceof w||t instanceof x))return t.object}}function re(e){return e.predicate?.subject}function kn(e){if(e===void 0)return" undef";if(e===null)return" null";if(typeof e=="string")return`s:${e}`;if(typeof e=="number")return`n:${e}`;if(typeof e=="boolean")return`b:${e}`;if(e instanceof E){let n=e.subject;return`r:${n.publisher}/${n.package_}/${n.name}`}if(e instanceof Y){let n=e.name??"";return`k:${e.namespace??""}/${n}`}if(typeof e=="object"&&e!==null&&typeof e.name=="string"&&typeof e.publisher=="string"){let n=e;return`u:${n.publisher}/${n.package_}/${n.name}`}return`o:${JSON.stringify(e)}`}function bn(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):e instanceof E?e.subject.name:e instanceof Y?e.name??"":typeof e=="object"&&e!==null&&typeof e.name=="string"?e.name:""}function ee(e,n,t){if(typeof e!="object"||e===null||e.kind!=="Document")throw new h(`Transformation "${n}" rule did not yield a Document for ${t}. Got: ${Be(e)}`)}function ne(e,n,t){if(typeof e=="string")return e;if(Array.isArray(e)&&e.every(hn))return e.map(r=>String(r)).join("");throw new h(`Transformation "${n}" artifactName did not yield a string for ${t}. Got: ${Be(e)}`)}function hn(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Be(e){if(e===void 0)return"undefined";if(e===null)return"null";if(Array.isArray(e))return`array(${e.length})`;if(typeof e=="object"){let n=e.kind;return n?`object(kind=${n})`:"object"}return typeof e}function te(e,n){if(!e&&!n)return;let t={metadataRenames:n?.metadataRenames??e?.metadataRenames??new Map},r=n?.metadataKeys??e?.metadataKeys;r!==void 0&&(t.metadataKeys=r);let o=n?.trailingNewline??e?.trailingNewline;o!==void 0&&(t.trailingNewline=o);let a=n?.omitWrapper??e?.omitWrapper;return a!==void 0&&(t.omitWrapper=a),t}var p=class extends Error{constructor(t,r){super(t);this.cause=r;this.name="RenderError"}cause},xe={publisher:"kanonak.org",package_:"derivation",name:"default"},oe=class{constructor(n,t=new se,r=new fe){this.repository=n;this.parser=t;this.objectParser=r}repository;parser;objectParser;runner=new H;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async renderViaLook(n){let t=await this.getCatalog(),r=A(t,n.resource);if(!(r instanceof D))throw new p(`Resource not found: ${b(n.resource)}`);let o=new G(t),a;if(n.format.name==="html")a=await o.renderHtml(r);else if(n.format.name==="stylesheet")a=o.renderStylesheet(r);else throw new p(`LookRenderer does not support format ${b(n.format)} \u2014 only formats.html and formats.stylesheet are implemented in v0.1.`);return{content:a,format:n.format,filename:r.name}}async findDerivation(n){let t=await this.getCatalog(),r=A(t,n.resource);if(!(r instanceof D))return;let o=n.variant??xe;return le(r,n.format,o,t)}async render(n){if(n.format.name==="html"||n.format.name==="stylesheet"){let a=await this.getCatalog(),s=A(a,n.resource);if(s instanceof D){let u=new G(a).findCascadedLook(s);if(u&&!wn(u.sourceClass)){let f=await this.findDerivation(n);if(!f||Dn(f))return this.renderViaLook({resource:n.resource,format:n.format})}}}let t=await this.findDerivation(n);if(!t)throw new p(`No derivation found for ${b(n.resource)} \u2192 format ${b(n.format)}`+(n.variant?` variant ${b(n.variant)}`:""));let r=ie(t.transformation.version),o={transformation:{publisher:t.transformation.publisher,package_:t.transformation.package_,name:t.transformation.name,...r?{version:r}:{}},input:n.resource,format:n.format};return n.omitWrapper!==void 0&&(o.omitWrapper=n.omitWrapper),this.runTransformation(o)}async runTransformation(n){let t=await this.getCatalog(),r=A(t,n.transformation);if(!(r instanceof D))throw new p(`Transformation not found: ${b(n.transformation)}`);let o=A(t,n.input);if(!(o instanceof D))throw new p(`Input resource not found: ${b(n.input)}`);let a=M(r,t),s=Sn(a.outputs,n.format);if(!s)throw new p(`Transformation ${b(n.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${b(n.format)}`);let c;try{c=await this.runner.run({transformation:r,instances:[o],allKanonaks:t,repository:this.repository,parser:this.parser,objectParser:this.objectParser,outputFormat:s,...n.omitWrapper!==void 0?{runtimeOverride:{metadataRenames:new Map,omitWrapper:n.omitWrapper}}:{}})}catch(u){throw new p(`Transformation execution failed: ${u.message}`,u)}if(c.length===0)throw new p("Transformation produced no artifacts");return{content:c[0].content,format:n.format,filename:c[0].fileName}}async getCatalog(){return this.cachedCatalog||(this.cachedCatalog=await this.objectParser.parseKanonaks(this.repository)),this.cachedCatalog}};function b(e){return`${e.publisher}/${e.package_}/${e.name}`}function Dn(e){return typeof e.source=="string"?!1:e.source.publisher==="kanonak.org"&&e.source.package_==="core-rdf"&&e.source.name==="Resource"}function wn(e){return e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Resource"}function Sn(e,n){let t=n.name;if(e.has(t))return t;for(let r of e)if(r.startsWith(t+"-")||r===t)return r}var An="kanonak.org/core-rdf/type";function ae(e){let n=En(e),t,r={type:""};for(let o of e.statement){let a=o.predicate?.subject;if(!a)throw new Error(`Expression node ${n} has a statement with no resolved predicate`);if(U(a)===An){if(!(o instanceof w))throw new Error(`Expression node ${n} has a non-reference 'type' statement`);if(t!==void 0)throw new Error(`Expression node ${n} declares more than one type \u2014 a runtime tree node is exactly one operator/literal/leaf class`);t=U(o.object.subject);continue}let s=a.name;if(s in r)throw new Error(`Expression node ${n} declares operand '${s}' more than once`);r[s]=jn(o,n,s)}if(t===void 0)throw new Error(`Expression node ${n} declares no type \u2014 the runtime dispatches on it`);return r.type=t,r}function jn(e,n,t){if(e instanceof $||e instanceof de||e instanceof T||e instanceof B)return e.object;if(e instanceof w)return U(e.object.subject);if(e instanceof me)return ae(e.object);if(e instanceof x)return(e.object??[]).map((r,o)=>{if(r instanceof E)return U(r.subject);if(r instanceof ce)return ae(r);if(r instanceof ue)return r.value;throw new Error(`Expression node ${n}: '${t}'[${o}] is not a serializable list item`)});throw new Error(`Expression node ${n}: operand '${t}' has an unserializable statement kind`)}function En(e){let n=e;return n.name?`'${n.name}'`:"(embedded)"}export{I as CssBackend,xe as DEFAULT_VARIANT,m as DOCAST,Oe as DOCAST_PKG,Le as DOCAST_PUB,K as DynamoDbBackend,pe as ExpressionEngineV3,Vn as ExpressionEvalErrorV3,L as HtmlBackend,v as JsonBackend,V as MarkdownFrontmatterBackend,q as ReferenceResolver,p as RenderError,ln as SUPPORTED_FORMATS_V3,O as SvgBackend,xn as TX_V3,Tn as TX_V3_PKG,$n as TX_V3_PUB,Bn as TX_V3_VERSION_MAJOR,R as TomlBackend,oe as TransformationEngine,ve as TransformationLoadErrorV3,h as TransformationRunnerErrorV3,H as TransformationRunnerV3,_ as YamlBackend,Rn as compileExpression,M as compileTransformationV3,Un as isRawStringV3,X as renderMarkdownToHtml,ae as toExpressionRuntimeTree};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.15.0",
|
|
4
4
|
"description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
],
|
|
127
127
|
"dependencies": {
|
|
128
128
|
"@kanonak-protocol/canonical": "^0.1.3",
|
|
129
|
-
"@kanonak-protocol/types": "^5.
|
|
129
|
+
"@kanonak-protocol/types": "^5.15.0",
|
|
130
130
|
"ignore": "^7.0.5",
|
|
131
131
|
"js-yaml": "^4.1.0",
|
|
132
132
|
"yaml": "^2.7.0"
|
package/dist/chunk-ZQAAF3GB.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as j,b as x,m as _}from"./chunk-V6KIDED2.js";import{e as l,f as u,g as b,h as $,i as s,m as h}from"./chunk-SVUMCLK5.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-YW6P24RF.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let t=b(e);return this.all.has(t)?!1:(this.all.add(t),this.tripleList.push(e),P(this.byPIdx,e.p,e),P(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&P(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let t=this.byPIdx.get(e);return t?t.slice():[]}bySubjectPredicate(e,t){let r=this.bySPIdx.get(`${e}|${t}`);return r?r.slice():[]}byPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);return r?r.slice():[]}subjectsWithPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)n.add(a.s);return Array.from(n)}uriObjectsOf(e,t){let r=this.bySPIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)a.o.kind==="uri"&&n.add(a.o.key);return Array.from(n)}hasUri(e,t,r){return this.all.has(`${e}|${t}|u:${r}`)}hasTriple(e,t,r){return this.all.has(`${e}|${t}|${$(r)}`)}};function P(o,e,t){let r=o.get(e);r?r.push(t):o.set(e,[t])}var w={name:"rdfs2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.domain)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},C={name:"rdfs3",apply(o,e){let t=!1;for(let r of o.byPredicate(e.range)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,e.type,a))&&(t=!0)}return t}},A={name:"rdfs5",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subPropertyOf))i.o.kind==="uri"&&o.add(s(n,e.subPropertyOf,i.o.key))&&(t=!0)}return t}},V={name:"rdfs7",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n)){let f={s:i.s,p:a,o:i.o};o.add(f)&&(t=!0)}}return t}},W={name:"rdfs9",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},F={name:"rdfs11",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subClassOf))i.o.kind==="uri"&&o.add(s(n,e.subClassOf,i.o.key))&&(t=!0)}return t}},k=[w,C,A,V,W,F];var N={name:"prp-trp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let n of r){let a=o.byPredicate(n);for(let i of a){if(i.o.kind!=="uri")continue;let f=i.o.key;for(let c of o.bySubjectPredicate(f,n))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(s(i.s,n,c.o.key))&&(t=!0)}}return t}},D={name:"prp-symp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let n of r)for(let a of o.byPredicate(n))a.o.kind==="uri"&&o.add(s(a.o.key,n,a.s))&&(t=!0);return t}},z={name:"prp-inv1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,a,i.s))&&(t=!0)}return t}},B={name:"prp-inv2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(a))i.o.kind==="uri"&&o.add(s(i.o.key,n,i.s))&&(t=!0)}return t}},M={name:"prp-eqp1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n))o.add({s:i.s,p:a,o:i.o})&&(t=!0)}return t}},G={name:"prp-eqp2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(a))o.add({s:i.s,p:n,o:i.o})&&(t=!0)}return t}},H={name:"cax-eqc1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},J={name:"cax-eqc2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,a))o.add(s(i.s,e.type,n))&&(t=!0)}return t}},Q={name:"eq-rep-s",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a){for(let i of o.snapshot())i.s===n&&o.add({s:a,p:i.p,o:i.o})&&(t=!0);for(let i of o.snapshot())i.s===a&&o.add({s:n,p:i.p,o:i.o})&&(t=!0)}}return t}},X={name:"eq-rep-o",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===n?o.add(s(i.s,i.p,a))&&(t=!0):i.o.key===a&&o.add(s(i.s,i.p,n))&&(t=!0))}return t}},K=[N,D,z,B,M,G,H,J,Q,X];var y=class{constructor(e,t){this.store=e;this.vocabulary=t}store;vocabulary;getInstancesOfClass(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,t)}getSubclasses(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,t).filter(n=>n!==t)}getSuperclasses(e){let t=p(e);return this.store.uriObjectsOf(t,this.vocabulary.subClassOf).filter(r=>r!==t)}getTypesOfIndividual(e){return this.store.uriObjectsOf(p(e),this.vocabulary.type)}isInstanceOf(e,t){return this.store.hasUri(p(e),this.vocabulary.type,p(t))}triples(){return this.store.snapshot()}size(){return this.store.size()}};function p(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new h,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let t=new d,n=await new _().parseKanonaks(e),a=new U;for(let c of n)if(c instanceof S){let m=Y(c);if(!m)continue;for(let E of c.statement)this.emitStatement(m,E,t,a)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let f=0;for(;f<this.maxIterations;){let c=!1;for(let m of i)m.apply(t,this.vocabulary)&&(c=!0);if(!c)break;f++}return new y(t,this.vocabulary)}emitStatement(e,t,r,n){let a=Z(t);if(a){if(t instanceof I){r.add({s:e,p:a,o:{kind:"literal",lexical:t.object,datatype:"string"}});return}if(t instanceof T){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"number"}});return}if(t instanceof g){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"boolean"}});return}if(t instanceof v){let i=l(t.object.subject);r.add(s(e,a,i));return}if(t instanceof L){let i=n.next();r.add({s:e,p:a,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t.object,r,n);return}if(t instanceof q){for(let i of t.object??[])this.emitListItem(e,a,i,r,n);return}}}emitListItem(e,t,r,n,a){if(r instanceof O)n.add(s(e,t,l(r.subject)));else if(r instanceof j){let i=a.next();n.add({s:e,p:t,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r,n,a)}else if(r instanceof x){let i=typeof r.value=="number"?"number":typeof r.value=="boolean"?"boolean":"string";n.add({s:e,p:t,o:{kind:"literal",lexical:String(r.value),datatype:i}})}}emitEmbedded(e,t,r,n){let a=`_:${e}`;for(let i of t.statement)this.emitStatement(a,i,r,n)}},U=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",t=e.indexOf("@"),r=t===-1?e:e.substring(0,t),n=r.indexOf("/");if(n===-1)return null;let a=r.substring(0,n),i=r.substring(n+1);return!a||!i||!o.name?null:u(a,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,R as e};
|