@kanonak-protocol/sdk 3.22.0 → 3.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +1 -1
- package/dist/{chunk-VRZUCZEF.js → chunk-4TJZIM7A.js} +1 -1
- package/dist/chunk-7U6IOH7G.js +165 -0
- package/dist/{chunk-CNM3SY5S.js → chunk-AV4AVTI6.js} +1 -1
- package/dist/{chunk-3JRHG2JH.js → chunk-AZSZXLEH.js} +1 -1
- package/dist/chunk-NIGFQYVA.js +1 -0
- package/dist/chunk-PB2RWBJN.js +47 -0
- package/dist/{chunk-GD4SYMXW.js → chunk-VLBP5CHO.js} +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +17 -17
- package/dist/look/LookRenderer.d.ts +141 -0
- package/dist/look/index.d.ts +1 -0
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/KanonakUrlResolver.d.ts +114 -0
- package/dist/resolution/index.d.ts +2 -0
- package/dist/resolution/index.js +1 -1
- package/dist/transformations/TransformationEngine.d.ts +33 -0
- package/dist/transformations/index.js +44 -44
- package/dist/validation/IKanonakObjectValidator.d.ts +3 -2
- package/dist/validation/KanonakObjectValidator.d.ts +3 -2
- package/dist/validation/ValidationCache.d.ts +94 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/IRepositoryValidationRule.d.ts +2 -1
- package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +23 -1
- package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +2 -1
- package/dist/validation/rules/repository/PropertyDomainRule.d.ts +11 -1
- package/package.json +2 -2
- package/dist/chunk-3JV5IPKZ.js +0 -47
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as E,c as F,d as f,f as M}from"../chunk-2JQMUZWN.js";import{a as ke}from"../chunk-7U6IOH7G.js";import{a as _e}from"../chunk-ROCCA4BY.js";import"../chunk-63NJ25ZX.js";import"../chunk-NIGFQYVA.js";import{a as Ne}from"../chunk-FJ35VIV6.js";import{a as C,c as Ue,e as Oe}from"../chunk-R2V7IXWN.js";import{b as K,c as w,d as b,g as B,h as U,i as O,j as V,k as T,l as S}from"../chunk-W6T7MOKY.js";import{a as Ce}from"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";var wt="kanonak.org",St="document-ast",p=t=>({publisher:wt,package_:St,name:t}),h={Document:p("Document"),Block:p("Block"),Inline:p("Inline"),StructuredValue:p("StructuredValue"),Heading:p("Heading"),Paragraph:p("Paragraph"),RawBlock:p("RawBlock"),Text:p("Text"),StructuredMap:p("StructuredMap"),StructuredEntry:p("StructuredEntry"),StructuredList:p("StructuredList"),StringScalar:p("StringScalar"),IntegerScalar:p("IntegerScalar"),EscapeHint:p("EscapeHint"),MediaType:p("MediaType"),metadata:p("metadata"),children:p("children"),level:p("level"),inlines:p("inlines"),text:p("text"),entries:p("entries"),key:p("key"),value:p("value"),escapeHint:p("escapeHint"),items:p("items"),stringValue:p("stringValue"),integerValue:p("integerValue"),rawContent:p("rawContent"),mediaType:p("mediaType"),mimeType:p("mimeType"),ESC_RAW:p("esc-raw"),ESC_YAML_SAFE:p("esc-yaml-safe"),ESC_TOML_STRING:p("esc-toml-string"),ESC_TOML_MULTILINE:p("esc-toml-multiline"),ESC_JSON:p("esc-json"),ESC_DYNAMODB_BOOL:p("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:p("esc-dynamodb-number"),ESC_DYNAMODB_NULL:p("esc-dynamodb-null"),TEXT_PLAIN:p("text-plain"),TEXT_MARKDOWN:p("text-markdown"),TEXT_HTML:p("text-html"),TEXT_CSS:p("text-css"),APPLICATION_JSON:p("application-json"),TEXT_YAML:p("text-yaml"),IMAGE_SVG_XML:p("image-svg-xml"),ResourceLink:p("ResourceLink"),target:p("target"),linkLabel:p("linkLabel"),PropertyList:p("PropertyList"),propertyEntries:p("propertyEntries"),PropertyEntry:p("PropertyEntry"),propertyKey:p("propertyKey"),propertyValue:p("propertyValue"),Table:p("Table"),tableColumnLabels:p("tableColumnLabels"),tableRows:p("tableRows"),TableRow:p("TableRow"),tableCells:p("tableCells")};function Me(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=Et(e.metadata,n),a=jt(e.children),u=["---",...r,"---","",a].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
|
-
`)),u}};function
|
|
4
|
+
`)),u}};function Et(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ce(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ce(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ce),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let m=r.get(c),g=ce(m??c),k=Ie(l.value,l.escapeHint);k!==void 0&&u.push(`${g}: ${k}`)}return u}function ce(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Ie(t,e){switch(t.kind){case"StringScalar":return $t(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Ie(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function $t(t,e){return!e||Me(e,h.ESC_RAW)?t:Me(e,h.ESC_YAML_SAFE)?vt(t):t}function vt(t){return t.includes(`
|
|
5
5
|
`)?`|-
|
|
6
6
|
${t.replace(/\n/g,`
|
|
7
|
-
`).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(t)?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function
|
|
7
|
+
`).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(t)?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function jt(t){let e=[];for(let n of t){let r=be(n);r&&e.push(r)}return e.join(`
|
|
8
8
|
|
|
9
|
-
`)}function
|
|
10
|
-
`)}function
|
|
11
|
-
`)?r.push(`${
|
|
12
|
-
${u}`):r.push(`${
|
|
9
|
+
`)}function be(t){switch(t.kind){case"Heading":return`${"#".repeat(t.level)} ${le(t.inlines)}`;case"Paragraph":return le(t.inlines);case"RawBlock":return t.rawContent;case"PropertyList":return Pe(t);case"Table":return Vt(t);default:return""}}function Vt(t){let e=t.tableColumnLabels??[],n=t.tableRows??[];if(e.length===0&&n.length===0)return"";let r=`| ${e.map(he).join(" | ")} |`,a=`| ${e.map(()=>"---").join(" | ")} |`,i=n.map(u=>`| ${(u.tableCells??[]).map(At).join(" | ")} |`);return[r,a,...i].join(`
|
|
10
|
+
`)}function At(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?he(le([e])):he(be(e).replace(/\n+/g," "))}function he(t){return t==null?"":String(t).replace(/\|/g,"\\|")}function Pe(t,e=0){if(!t.propertyEntries||t.propertyEntries.length===0)return"";let n=" ".repeat(e),r=[];for(let a of t.propertyEntries){let i=`${n}**${a.propertyKey}:**`,u=Dt(a.propertyValue,e+1);u.includes(`
|
|
11
|
+
`)?r.push(`${i}
|
|
12
|
+
${u}`):r.push(`${i} ${u}`)}return r.join(`
|
|
13
13
|
|
|
14
|
-
`)}function
|
|
14
|
+
`)}function Dt(t,e){if(!t||t.length===0)return"";let n=[],r=[];for(let a of t){let i=a;!i||typeof i!="object"||!i.kind||(i.kind==="Text"||i.kind==="ResourceLink"||i.kind==="Badge"?n.push(le([i])):i.kind==="PropertyList"?r.push(Pe(i,e)):r.push(be(i)))}return r.length===0?n.join(""):n.length===0?r.join(`
|
|
15
15
|
|
|
16
16
|
`):`${n.join("")}
|
|
17
17
|
|
|
18
18
|
${r.join(`
|
|
19
19
|
|
|
20
|
-
`)}`}function le(t){let e=[];for(let n of t)n.kind==="Text"?e.push(n.text):n.kind==="ResourceLink"?e.push(
|
|
21
|
-
`);return n?.trailingNewline&&(
|
|
22
|
-
`)||(
|
|
23
|
-
`)),
|
|
20
|
+
`)}`}function le(t){let e=[];for(let n of t)n.kind==="Text"?e.push(n.text):n.kind==="ResourceLink"?e.push(Kt(n)):n.kind==="Badge"&&e.push(Tt(n));return e.join("")}function Kt(t){let e=qe(t.target);if(!e)return t.linkLabel??"[unresolved link]";let n=F(e),r=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,a=t.linkTooltip?` "${Fe(t.linkTooltip)}"`:"";return`[${r}](${n}${a})`}function Tt(t){if(!t.badgeTarget)return`*${t.badgeLabel}*`;let e=qe(t.badgeTarget);if(!e)return`*${t.badgeLabel}*`;let n=F(e),r=t.badgeTooltip?` "${Fe(t.badgeTooltip)}"`:"";return`*[${t.badgeLabel}](${n}${r})*`}function Fe(t){return t==null?"":String(t).replace(/"/g,'\\"')}function qe(t){if(!t||typeof t!="object")return;let e=t;if(e.subject&&e.subject.publisher&&e.subject.package_&&e.subject.name){let r={publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name};return e.subject.version&&(r.version=e.subject.version),r}let n=t;if(typeof n.namespace=="string"&&typeof n.name=="string"&&n.name.length>0){let r=/^([^/]+)\/([^@]+)@(\d+)\.(\d+)\.(\d+)$/.exec(n.namespace);if(r)return{publisher:r[1],package_:r[2],name:n.name,version:{major:Number(r[3]),minor:Number(r[4]),patch:Number(r[5])}}}}function Lt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Z=class{backendUri="kanonak.org/transformations/toml";render(e,n){let a=Bt(e.metadata,n).join(`
|
|
21
|
+
`);return n?.trailingNewline&&(a.endsWith(`
|
|
22
|
+
`)||(a+=`
|
|
23
|
+
`)),a}};function Bt(t,e){if(!t)return[];let n=new Map;for(let i of t.entries)n.set(i.key,i);let r=e?.metadataKeys??t.entries.map(i=>i.key),a=[];for(let i of r){let u=n.get(i);if(!u)continue;let c=e?.metadataRenames.get(i)??i,l=We(u.value,u.escapeHint);l!==void 0&&a.push(`${c} = ${l}`)}return a}function We(t,e){switch(t.kind){case"StringScalar":return Rt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=We(r,e);a!==void 0&&n.push(a)}return`[${n.join(", ")}]`}case"StructuredMap":return;default:return}}function Rt(t,e){return e&&Lt(e,h.ESC_TOML_MULTILINE)?Ut(t):Ct(t)}function Ct(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function Ut(t){return`"""
|
|
24
24
|
${t.replace(/"""/g,'\\"\\"\\"')}
|
|
25
25
|
"""`}var Q=class{backendUri="kanonak.org/transformations/json";render(e,n){let r=JSON.stringify(e,null,2);return n?.trailingNewline&&!r.endsWith(`
|
|
26
26
|
`)?r+`
|
|
27
27
|
`:r}};function x(t){let e=t.replace(/\r\n/g,`
|
|
28
28
|
`).split(`
|
|
29
|
-
`),n=[],r=0;for(;r<e.length;){let
|
|
30
|
-
`)),k=l?` class="language-${
|
|
29
|
+
`),n=[],r=0;for(;r<e.length;){let a=e[r];if(a.trim()===""){r++;continue}let i=/^(\s*)```(\S*)\s*$/.exec(a);if(i){let l=i[2],m=[];for(r++;r<e.length&&!/^(\s*)```\s*$/.test(e[r]);)m.push(e[r]),r++;r++;let g=ze(m.join(`
|
|
30
|
+
`)),k=l?` class="language-${Ge(l)}"`:"";n.push(`<pre><code${k}>${g}</code></pre>`);continue}let u=/^(#{1,6})\s+(.*)$/.exec(a);if(u){let l=u[1].length,m=H(u[2].trim());n.push(`<h${l}>${m}</h${l}>`),r++;continue}if(a.includes("|")&&r+1<e.length&&He(e[r+1])){let l=we(a),m=Ot(e[r+1]);r+=2;let g=[];for(;r<e.length&&e[r].trim()!==""&&e[r].includes("|");)g.push(we(e[r])),r++;n.push(Nt(l,m,g));continue}if(/^\s*[-*]\s+/.test(a)){let l=[];for(;r<e.length&&/^\s*[-*]\s+/.test(e[r]);){let m=[e[r].replace(/^\s*[-*]\s+/,"")];for(r++;r<e.length&&e[r].trim()!==""&&!/^\s*[-*]\s+/.test(e[r])&&!/^\s*\d+\.\s+/.test(e[r]);)m.push(e[r]),r++;r<e.length&&e[r].trim()===""&&r++,l.push(`<li>${H(m.join(" ").trim())}</li>`)}n.push(`<ul>
|
|
31
31
|
${l.join(`
|
|
32
32
|
`)}
|
|
33
|
-
</ul>`);continue}if(/^\s*\d+\.\s+/.test(
|
|
33
|
+
</ul>`);continue}if(/^\s*\d+\.\s+/.test(a)){let l=[];for(;r<e.length&&/^\s*\d+\.\s+/.test(e[r]);){let m=[e[r].replace(/^\s*\d+\.\s+/,"")];for(r++;r<e.length&&e[r].trim()!==""&&!/^\s*\d+\.\s+/.test(e[r])&&!/^\s*[-*]\s+/.test(e[r]);)m.push(e[r]),r++;r<e.length&&e[r].trim()===""&&r++,l.push(`<li>${H(m.join(" ").trim())}</li>`)}n.push(`<ol>
|
|
34
34
|
${l.join(`
|
|
35
35
|
`)}
|
|
36
|
-
</ol>`);continue}let c=[
|
|
37
|
-
`)}function
|
|
36
|
+
</ol>`);continue}let c=[a];for(r++;r<e.length&&e[r].trim()!==""&&!/^(#{1,6})\s+/.test(e[r])&&!/^(\s*)```/.test(e[r])&&!/^\s*[-*]\s+/.test(e[r])&&!/^\s*\d+\.\s+/.test(e[r])&&!(e[r].includes("|")&&r+1<e.length&&He(e[r+1]));)c.push(e[r]),r++;n.push(`<p>${H(c.join(" "))}</p>`)}return n.join(`
|
|
37
|
+
`)}function He(t){return t.includes("-")?/^[\s|:-]+$/.test(t):!1}function we(t){let e=t.trim();return e.startsWith("|")&&(e=e.slice(1)),e.endsWith("|")&&(e=e.slice(0,-1)),e.split("|").map(n=>n.trim())}function Ot(t){return we(t).map(e=>{let n=e.startsWith(":"),r=e.endsWith(":");return n&&r?"center":r?"right":n?"left":null})}function Nt(t,e,n){let r=u=>{let c=e[u];return c?` style="text-align:${c}"`:""},a=t.map((u,c)=>`<th${r(c)}>${H(u)}</th>`).join(""),i=n.map(u=>`<tr>${u.map((l,m)=>`<td${r(m)}>${H(l)}</td>`).join("")}</tr>`).join(`
|
|
38
38
|
`);return`<table>
|
|
39
|
-
<thead><tr>${
|
|
39
|
+
<thead><tr>${a}</tr></thead>
|
|
40
40
|
<tbody>
|
|
41
|
-
${
|
|
41
|
+
${i}
|
|
42
42
|
</tbody>
|
|
43
|
-
</table>`}function H(t){let e=
|
|
43
|
+
</table>`}function H(t){let e=ze(t);return e=e.replace(/`([^`\n]+)`/g,(n,r)=>`<code>${r}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(n,r,a)=>`<a href="${Ge(a)}">${r}</a>`),e=e.replace(/\*\*([^*\n]+)\*\*/g,(n,r)=>`<strong>${r}</strong>`),e=e.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g,(n,r,a)=>`${r}<em>${a}</em>`),e=e.replace(/(^|[\s(])_([^_\n]+)_(?=[\s).,;:!?]|$)/g,(n,r,a)=>`${r}<em>${a}</em>`),e}function ze(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ge(t){return t.replace(/"/g,""").replace(/&/g,"&")}function Se(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ee=class{backendUri="kanonak.org/transformations/html";render(e,n){let r=It(e.children);if(n?.omitWrapper){let c=r.endsWith(`
|
|
44
44
|
`)?r:`${r}
|
|
45
45
|
`;return n.trailingNewline===!1&&c.endsWith(`
|
|
46
|
-
`)?c.slice(0,-1):c}let
|
|
46
|
+
`)?c.slice(0,-1):c}let a=_t(e.metadata)??"Untitled",i=Mt(e.metadata,n),u=`<!DOCTYPE html>
|
|
47
47
|
<html lang="en">
|
|
48
48
|
<head>
|
|
49
49
|
<meta charset="utf-8">
|
|
50
|
-
<title>${
|
|
50
|
+
<title>${N(a)}</title>
|
|
51
51
|
<style>
|
|
52
52
|
body { font-family: -apple-system, Segoe UI, Helvetica, Arial, sans-serif; max-width: 860px; margin: 2rem auto; padding: 0 1rem; color: #222; line-height: 1.55; }
|
|
53
53
|
h1, h2, h3, h4 { line-height: 1.2; }
|
|
@@ -69,39 +69,39 @@ figure.svg-figure svg { max-width: 100%; height: auto; }
|
|
|
69
69
|
</style>
|
|
70
70
|
</head>
|
|
71
71
|
<body>
|
|
72
|
-
${
|
|
72
|
+
${i}${r}
|
|
73
73
|
</body>
|
|
74
74
|
</html>
|
|
75
75
|
`;return n?.trailingNewline===!1&&u.endsWith(`
|
|
76
|
-
`)?u.slice(0,-1):u}};function
|
|
77
|
-
<dd>${l}</dd>`)}return
|
|
78
|
-
${
|
|
76
|
+
`)?u.slice(0,-1):u}};function _t(t){if(t){for(let e of t.entries)if((e.key==="title"||e.key==="name")&&e.value.kind==="StringScalar")return e.value.stringValue}}function Mt(t,e){if(!t||t.entries.length===0)return"";let n=e?.metadataKeys??t.entries.map(i=>i.key),r=new Map(t.entries.map(i=>[i.key,i])),a=[];for(let i of n){let u=r.get(i);if(!u)continue;let c=e?.metadataRenames.get(i)??i,l=Je(u.value);l!==void 0&&a.push(` <dt>${N(c)}</dt>
|
|
77
|
+
<dd>${l}</dd>`)}return a.length===0?"":`<dl class="metadata">
|
|
78
|
+
${a.join(`
|
|
79
79
|
`)}
|
|
80
80
|
</dl>
|
|
81
|
-
`}function
|
|
82
|
-
`)}function
|
|
83
|
-
<tr>${e.map(
|
|
81
|
+
`}function Je(t){switch(t.kind){case"StringScalar":return N(t.stringValue);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let e=[];for(let n of t.items){let r=Je(n);r!==void 0&&e.push(`<code>${r}</code>`)}return e.join(", ")}case"StructuredMap":return;default:return}}function It(t){let e=[];for(let n of t){let r=Ee(n);r&&e.push(r)}return e.join(`
|
|
82
|
+
`)}function Ee(t){switch(t.kind){case"Heading":{let e=Math.max(1,Math.min(6,t.level));return`<h${e}>${de(t.inlines)}</h${e}>`}case"Paragraph":return`<p>${de(t.inlines)}</p>`;case"RawBlock":return zt(t);case"PropertyList":return Wt(t);case"Table":return Pt(t);default:return""}}function Pt(t){let e=t.tableColumnLabels??[],n=t.tableRows??[],r=e.length>0?`<thead>
|
|
83
|
+
<tr>${e.map(i=>`<th>${N(i)}</th>`).join("")}</tr>
|
|
84
84
|
</thead>
|
|
85
|
-
`:"",
|
|
86
|
-
${n.map(
|
|
85
|
+
`:"",a=n.length>0?`<tbody>
|
|
86
|
+
${n.map(Ft).join(`
|
|
87
87
|
`)}
|
|
88
88
|
</tbody>
|
|
89
89
|
`:"";return`<table class="property-table">
|
|
90
|
-
${r}${
|
|
90
|
+
${r}${a}</table>`}function Ft(t){return` <tr>${(t.tableCells??[]).map(r=>`<td>${qt(r)}</td>`).join("")}</tr>`}function qt(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?de([e]):Ee(e)}function Wt(t){if(!t.propertyEntries||t.propertyEntries.length===0)return"";let e=[];for(let n of t.propertyEntries){let a=`<dt${n.propertyTooltip?` title="${z(n.propertyTooltip)}"`:""}>${N(n.propertyKey)}</dt>`,i=`<dd>${Ht(n.propertyValue)}</dd>`;e.push(a,i)}return`<dl class="property-list">
|
|
91
91
|
${e.join(`
|
|
92
92
|
`)}
|
|
93
|
-
</dl>`}function
|
|
93
|
+
</dl>`}function Ht(t){if(!t||t.length===0)return"";let e=[];for(let n of t){let r=n;!r||typeof r!="object"||!r.kind||(r.kind==="Text"||r.kind==="ResourceLink"||r.kind==="Badge"?e.push(de([r])):e.push(Ee(r)))}return e.join("")}function zt(t){let e=t.mediaType;return e&&Se(e,h.TEXT_MARKDOWN)?x(t.rawContent):e&&Se(e,h.TEXT_HTML)?t.rawContent:e&&Se(e,h.IMAGE_SVG_XML)?`<figure class="svg-figure">
|
|
94
94
|
${t.rawContent}
|
|
95
|
-
</figure>`:`<pre${e?` class="media-${z(e.name)}"`:""}><code>${
|
|
96
|
-
`)&&(
|
|
97
|
-
`),
|
|
95
|
+
</figure>`:`<pre${e?` class="media-${z(e.name)}"`:""}><code>${N(t.rawContent)}</code></pre>`}function de(t){let e=[];for(let n of t)n.kind==="Text"?e.push(N(n.text)):n.kind==="ResourceLink"?e.push(Gt(n)):n.kind==="Badge"&&e.push(Jt(n));return e.join("")}function Gt(t){let e=Xe(t.target);if(!e)return N(t.linkLabel??"[unresolved link]");let n=F(e),r=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,a=t.linkTooltip?` title="${z(t.linkTooltip)}"`:"";return`<a class="kan-link" href="${z(n)}"${a}>${N(r)}</a>`}function Jt(t){let e=t.badgeTooltip?` title="${z(t.badgeTooltip)}"`:"",n=N(t.badgeLabel);if(!t.badgeTarget)return`<span class="kan-badge"${e}>${n}</span>`;let r=Xe(t.badgeTarget);if(!r)return`<span class="kan-badge"${e}>${n}</span>`;let a=F(r);return`<a class="kan-badge" href="${z(a)}"${e}>${n}</a>`}function Xe(t){if(!t||typeof t!="object")return;let e=t;if(e.subject&&e.subject.publisher&&e.subject.package_&&e.subject.name){let r={publisher:e.subject.publisher,package_:e.subject.package_,name:e.subject.name};return e.subject.version&&(r.version=e.subject.version),r}let n=t;if(typeof n.namespace=="string"&&typeof n.name=="string"&&n.name.length>0){let r=/^([^/]+)\/([^@]+)@(\d+)\.(\d+)\.(\d+)$/.exec(n.namespace);if(r)return{publisher:r[1],package_:r[2],name:n.name,version:{major:Number(r[3]),minor:Number(r[4]),patch:Number(r[5])}}}}function N(t){return t==null?"":String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function z(t){return t==null?"":String(t).replace(/"/g,""").replace(/&/g,"&")}function Xt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var te=class{backendUri="kanonak.org/transformations/svg";render(e,n){for(let r of e.children)if(r.kind==="RawBlock"&&r.mediaType&&Xt(r.mediaType,h.IMAGE_SVG_XML)){let a=r.rawContent;return n?.trailingNewline&&!a.endsWith(`
|
|
96
|
+
`)&&(a+=`
|
|
97
|
+
`),a}return'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'}};function Yt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ne=class{backendUri="kanonak.org/transformations/stylesheet";render(e,n){let r=[];for(let i of e.children)i.kind==="RawBlock"&&i.mediaType&&Yt(i.mediaType,h.TEXT_CSS)&&r.push(i.rawContent);let a=r.join(`
|
|
98
98
|
|
|
99
|
-
`);return n?.trailingNewline&&
|
|
100
|
-
`)&&(
|
|
101
|
-
`),
|
|
99
|
+
`);return n?.trailingNewline&&a.length>0&&!a.endsWith(`
|
|
100
|
+
`)&&(a+=`
|
|
101
|
+
`),a}};function Zt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var re=class{backendUri="kanonak.org/transformations/yaml";render(e,n){let r=[];for(let i of e.children)i.kind==="RawBlock"&&i.mediaType&&Zt(i.mediaType,h.TEXT_YAML)&&r.push(i.rawContent);let a=r.join(`
|
|
102
102
|
|
|
103
|
-
`);return n?.trailingNewline&&
|
|
104
|
-
`)&&(
|
|
105
|
-
`),
|
|
106
|
-
`)&&(
|
|
107
|
-
`),i}};function Xe(t,e){let n=new Map;for(let a of t.entries)n.set(a.key,a);let r=e?.metadataKeys??t.entries.map(a=>a.key),i={};for(let a of r){let u=n.get(a);if(!u)continue;let c=e?.metadataRenames.get(a)??a;i[c]=Ye(u.value,u.escapeHint)}return{M:i}}function Ye(t,e){switch(t.kind){case"StructuredMap":return Xe(t);case"StructuredList":return{L:t.items.map(n=>Ye(n,void 0))};case"StringScalar":return Zt(t.stringValue,e??t.escapeHint);case"IntegerScalar":return Qt(t.integerValue,e??t.escapeHint)}}function Zt(t,e){if(e&&ie(e,h.ESC_DYNAMODB_BOOL)){if(t==="true")return{BOOL:!0};if(t==="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(t)}.`)}if(e&&ie(e,h.ESC_DYNAMODB_NULL))return{NULL:!0};if(e&&ie(e,h.ESC_DYNAMODB_NUMBER)){if(t.trim()===""||Number.isNaN(Number(t)))throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-number must hold a numeric literal; got ${JSON.stringify(t)}.`);return{N:t}}return{S:t}}function Qt(t,e){if(e&&ie(e,h.ESC_DYNAMODB_BOOL))throw new Error(`dynamodb-json backend: esc-dynamodb-bool cannot apply to an IntegerScalar (value ${t}). Use a StringScalar "true"/"false".`);if(e&&ie(e,h.ESC_DYNAMODB_NULL))throw new Error(`dynamodb-json backend: esc-dynamodb-null cannot apply to an IntegerScalar (value ${t}). Use a StringScalar hinted esc-dynamodb-null.`);return{N:String(t)}}var oe=class{constructor(e,n,r){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;cache=new Map;async resolveSubject(e,n){let r=q(n,e);if(r)return r;let i=e.version,a=i&&typeof i.major=="number"?`@${i.major}.${i.minor}.${i.patch}`:"",u=`${e.publisher}/${e.package_}${a}`,c=this.cache.get(u);if(!c){let m=await this.repository.getDocumentsByNamespaceAsync(e.publisher,e.package_);if(m.length===0)return;let g=i&&typeof i.major=="number"?m.find(D=>{let v=D.metadata?.namespace_?.version;return v&&v.major===i.major&&v.minor===i.minor&&v.patch===i.patch})??m[0]:m[0],k=new Oe(g,this.repository);c=await this.objectParser.parseKanonaks(k),this.cache.set(u,c)}let l=q(c,e);if(l)return l;for(let m of c)if(m instanceof E&&m.name===e.name)return m}};var xt="kanonak.org",en="transformations",nr=3,s=t=>({publisher:xt,package_:en,name:t}),o={Transformation:s("Transformation"),InstanceTransformation:s("InstanceTransformation"),SetTransformation:s("SetTransformation"),inputPattern:s("inputPattern"),rule:s("rule"),artifactName:s("artifactName"),outputs:s("outputs"),formatOverrides:s("formatOverrides"),partitionBy:s("partitionBy"),InputPattern:s("InputPattern"),matchesClass:s("matchesClass"),requires:s("requires"),sortBy:s("sortBy"),SortKey:s("SortKey"),byProperty:s("byProperty"),order:s("order"),SortOrder:s("SortOrder"),ascending:s("ascending"),descending:s("descending"),OutputFormat:s("OutputFormat"),backendUri:s("backendUri"),FormatOverride:s("FormatOverride"),formatTarget:s("formatTarget"),metadataKeys:s("metadataKeys"),metadataRenames:s("metadataRenames"),trailingNewline:s("trailingNewline"),omitWrapper:s("omitWrapper"),RenameEntry:s("RenameEntry"),fromKey:s("fromKey"),toKey:s("toKey"),FMT_MARKDOWN_FRONTMATTER:s("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:s("plain-markdown"),FMT_TOML:s("toml"),FMT_JSON:s("json"),FMT_HTML:s("html"),FMT_SVG:s("svg"),Expression:s("Expression"),ListSourcedExpression:s("ListSourcedExpression"),ListAggregate:s("ListAggregate"),IteratingExpression:s("IteratingExpression"),BuildAstNode:s("BuildAstNode"),astClass:s("astClass"),set:s("set"),AstFieldBinding:s("AstFieldBinding"),field:s("field"),bindValue:s("bindValue"),When:s("When"),condition:s("condition"),thenBuild:s("thenBuild"),elseBuild:s("elseBuild"),Concat:s("Concat"),parts:s("parts"),Fallback:s("Fallback"),primary:s("primary"),alternate:s("alternate"),StringLiteral:s("StringLiteral"),stringLiteral:s("stringLiteral"),IntegerLiteral:s("IntegerLiteral"),integerLiteral:s("integerLiteral"),DecimalLiteral:s("DecimalLiteral"),decimalLiteral:s("decimalLiteral"),BooleanLiteral:s("BooleanLiteral"),booleanLiteral:s("booleanLiteral"),VarRef:s("VarRef"),varName:s("varName"),PropertyRead:s("PropertyRead"),readSource:s("readSource"),readProp:s("readProp"),Traverse:s("Traverse"),traverseSource:s("traverseSource"),through:s("through"),step:s("step"),UriName:s("UriName"),uriNameOf:s("uriNameOf"),UriPublisher:s("UriPublisher"),uriPublisherOf:s("uriPublisherOf"),UriPackage:s("UriPackage"),uriPackageOf:s("uriPackageOf"),UriVersion:s("UriVersion"),uriVersionOf:s("uriVersionOf"),SubjectUri:s("SubjectUri"),subjectOf:s("subjectOf"),UriLiteral:s("UriLiteral"),refTo:s("refTo"),DisplayLabel:s("DisplayLabel"),labelTarget:s("labelTarget"),labelSource:s("labelSource"),ResolveRef:s("ResolveRef"),resolveSource:s("resolveSource"),Normalize:s("Normalize"),normSource:s("normSource"),normKind:s("normKind"),NormalizeKind:s("NormalizeKind"),NORM_TRIM_END:s("trim-end"),IsSet:s("IsSet"),checkExpr:s("checkExpr"),ExpressionFragment:s("ExpressionFragment"),body:s("body"),CallFragment:s("CallFragment"),fragmentRef:s("fragmentRef"),source:s("source"),Join:s("Join"),separator:s("separator"),Count:s("Count"),Sum:s("Sum"),Min:s("Min"),Max:s("Max"),Average:s("Average"),loopVar:s("loopVar"),ForEach:s("ForEach"),emit:s("emit"),ListMap:s("ListMap"),mapBody:s("mapBody"),Filter:s("Filter"),predicate:s("predicate"),PartitionBy:s("PartitionBy"),partitionKey:s("partitionKey"),DistinctBy:s("DistinctBy"),distinctKey:s("distinctKey"),Partition:s("Partition"),key:s("key"),members:s("members"),AllStatements:s("AllStatements"),statementsOf:s("statementsOf"),StatementPredicate:s("StatementPredicate"),predicateOf:s("predicateOf"),StatementValue:s("StatementValue"),valueOf:s("valueOf"),DateFormat:s("DateFormat"),dateSource:s("dateSource"),dateFormat:s("dateFormat"),BinaryArithmetic:s("BinaryArithmetic"),arithLeft:s("arithLeft"),arithRight:s("arithRight"),Add:s("Add"),Subtract:s("Subtract"),Multiply:s("Multiply"),Divide:s("Divide"),Reverse:s("Reverse"),WindowedMap:s("WindowedMap"),windowSize:s("windowSize"),windowVar:s("windowVar"),windowBody:s("windowBody"),PairwiseMap:s("PairwiseMap"),firstVar:s("firstVar"),secondVar:s("secondVar"),pairBody:s("pairBody"),Scan:s("Scan"),initialState:s("initialState"),stateVar:s("stateVar"),elementVar:s("elementVar"),accumulate:s("accumulate"),ListItemAt:s("ListItemAt"),itemIndex:s("itemIndex"),BinaryComparison:s("BinaryComparison"),compareLeft:s("compareLeft"),compareRight:s("compareRight"),Equals:s("Equals"),GreaterThan:s("GreaterThan"),LessThan:s("LessThan"),GreaterThanOrEqual:s("GreaterThanOrEqual"),LessThanOrEqual:s("LessThanOrEqual"),Not:s("Not"),operand:s("operand"),BooleanLogic:s("BooleanLogic"),operands:s("operands"),And:s("And"),Or:s("Or"),Contains:s("Contains"),haystack:s("haystack"),needle:s("needle"),UnaryNumericOp:s("UnaryNumericOp"),value:s("value"),Abs:s("Abs"),Negate:s("Negate"),KindPredicate:s("KindPredicate"),IsReference:s("IsReference"),IsEmbedded:s("IsEmbedded"),IsList:s("IsList"),kindCheck:s("kindCheck"),IsString:s("IsString"),IsNumber:s("IsNumber"),IsBoolean:s("IsBoolean"),StatementObject:s("StatementObject"),statementSource:s("statementSource"),Let:s("Let"),letName:s("letName"),letValue:s("letValue"),letBody:s("letBody"),GetStatementByName:s("GetStatementByName"),inSubject:s("inSubject"),byName:s("byName"),RenderMarkdown:s("RenderMarkdown"),renderSource:s("renderSource"),renderProp:s("renderProp"),renderFormat:s("renderFormat"),RenderFormat:s("RenderFormat"),RENDER_HTML:s("render-html"),RENDER_MARKDOWN:s("render-markdown")};var y=class extends Error{constructor(n,r){super(`${n} (at ${r})`);this.path=r}path};function me(t,e){let n=t.name,r=fn(e),i={catalog:e,depth:0};if(f(t,o.InstanceTransformation))return tn(t,n,i,r);if(f(t,o.SetTransformation))return nn(t,n,i,r);throw new y("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function tn(t,e,n,r){return{kind:"instance",name:t.name,inputPattern:nt(t,e),rule:fe(t,o.rule,`${e}.rule`,n),artifactName:fe(t,o.artifactName,`${e}.artifactName`,n),outputs:rt(t,`${e}.outputs`),overrides:it(t,`${e}.formatOverrides`,n),fragments:r}}function nn(t,e,n,r){let i=_(t,o.partitionBy);return{kind:"set",name:t.name,inputPattern:nt(t,e),rule:fe(t,o.rule,`${e}.rule`,n),artifactName:fe(t,o.artifactName,`${e}.artifactName`,n),outputs:rt(t,`${e}.outputs`),overrides:it(t,`${e}.formatOverrides`,n),partitionBy:i,fragments:r}}function nt(t,e){let n=se(t,o.inputPattern);if(!n)throw new y("inputPattern is required",e);return rn(n,`${e}.inputPattern`)}function rn(t,e){let n=_(t,o.matchesClass);if(!n)throw new y("matchesClass is required",e);let r=[];for(let u of A(t,o.requires))if(u instanceof V)r.push(ve(u.object.subject));else if(u instanceof w)for(let c of u.object)c instanceof b&&r.push(ve(c.subject));let i=[],a=0;for(let u of A(t,o.sortBy))if(u instanceof w)for(let c of u.object)c instanceof R&&i.push(Ze(c,`${e}.sortBy[${a++}]`));else u instanceof T&&i.push(Ze(u.object,`${e}.sortBy[${a++}]`));return{matchesClass:n,requires:r,sortBy:i}}function Ze(t,e){let n=_(t,o.byProperty);if(!n)throw new y("SortKey.byProperty is required",e);let r=_(t,o.order);if(!r)throw new y("SortKey.order is required",e);if(S(r,o.ascending))return{byProperty:n,order:"ascending"};if(S(r,o.descending))return{byProperty:n,order:"descending"};throw new y(`SortKey.order must reference tx.ascending or tx.descending; got ${r.publisher}/${r.package_}/${r.name}`,e)}function fe(t,e,n,r){let i=se(t,e);if(!i)throw new y("expression is required",n);return J(i,n,r)}function J(t,e,n){if(f(t,o.StringLiteral))return{kind:"string-literal",value:j(t,o.stringLiteral,e)};if(f(t,o.IntegerLiteral))return{kind:"integer-literal",value:tt(t,o.integerLiteral,e)};if(f(t,o.DecimalLiteral))return{kind:"decimal-literal",value:tt(t,o.decimalLiteral,e)};if(f(t,o.BooleanLiteral))return{kind:"boolean-literal",value:gn(t,o.booleanLiteral,e)};if(f(t,o.VarRef))return{kind:"var-ref",varName:j(t,o.varName,e)};if(f(t,o.PropertyRead))return{kind:"property-read",source:d(t,o.readSource,`${e}.readSource`,n),readProp:P(t,o.readProp,e,"readProp")};if(f(t,o.Traverse))return{kind:"traverse",source:d(t,o.traverseSource,`${e}.traverseSource`,n),through:P(t,o.through,e,"through"),step:d(t,o.step,`${e}.step`,n)};if(f(t,o.BuildAstNode))return{kind:"build-ast-node",astClass:P(t,o.astClass,e,"astClass"),set:on(t,`${e}.set`,n)};if(f(t,o.When))return{kind:"when",condition:d(t,o.condition,`${e}.condition`,n),thenBuild:d(t,o.thenBuild,`${e}.thenBuild`,n),elseBuild:an(t,o.elseBuild,`${e}.elseBuild`,n)};if(f(t,o.Concat))return{kind:"concat",parts:Ee(t,o.parts,`${e}.parts`,n)};if(f(t,o.Fallback))return{kind:"fallback",primary:d(t,o.primary,`${e}.primary`,n),alternate:d(t,o.alternate,`${e}.alternate`,n)};if(f(t,o.UriName))return{kind:"uri-name",source:d(t,o.uriNameOf,`${e}.uriNameOf`,n)};if(f(t,o.UriPublisher))return{kind:"uri-publisher",source:d(t,o.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(f(t,o.UriPackage))return{kind:"uri-package",source:d(t,o.uriPackageOf,`${e}.uriPackageOf`,n)};if(f(t,o.UriVersion))return{kind:"uri-version",source:d(t,o.uriVersionOf,`${e}.uriVersionOf`,n)};if(f(t,o.SubjectUri))return{kind:"subject-uri",source:d(t,o.subjectOf,`${e}.subjectOf`,n)};if(f(t,o.UriLiteral))return{kind:"uri-literal",refTo:P(t,o.refTo,e,"refTo")};if(f(t,o.DisplayLabel))return{kind:"display-label",labelTarget:P(t,o.labelTarget,e,"labelTarget"),labelSource:P(t,o.labelSource,e,"labelSource")};if(f(t,o.ResolveRef))return{kind:"resolve-ref",source:d(t,o.resolveSource,`${e}.resolveSource`,n)};if(f(t,o.Normalize))return{kind:"normalize",source:d(t,o.normSource,`${e}.normSource`,n),normKind:sn(t,e)};if(f(t,o.RenderMarkdown))return{kind:"render-markdown",source:d(t,o.renderSource,`${e}.renderSource`,n),readProp:P(t,o.renderProp,e,"renderProp"),format:un(t,e)};if(f(t,o.IsSet))return{kind:"is-set",check:d(t,o.checkExpr,`${e}.checkExpr`,n)};if(f(t,o.CallFragment))return ln(t,e,n);if(f(t,o.Join))return{kind:"join",source:d(t,o.source,`${e}.source`,n),separator:j(t,o.separator,e)};if(f(t,o.Count))return{kind:"count",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Sum))return{kind:"sum",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Min))return{kind:"min",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Max))return{kind:"max",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Average))return{kind:"average",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.ForEach))return{kind:"for-each",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),emit:d(t,o.emit,`${e}.emit`,n)};if(f(t,o.ListMap))return{kind:"list-map",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),mapBody:d(t,o.mapBody,`${e}.mapBody`,n)};if(f(t,o.Filter))return{kind:"filter",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),predicate:d(t,o.predicate,`${e}.predicate`,n)};if(f(t,o.PartitionBy))return{kind:"partition-by",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),partitionKey:d(t,o.partitionKey,`${e}.partitionKey`,n)};if(f(t,o.DistinctBy))return{kind:"distinct-by",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),distinctKey:d(t,o.distinctKey,`${e}.distinctKey`,n)};if(f(t,o.AllStatements))return{kind:"all-statements",source:d(t,o.statementsOf,`${e}.statementsOf`,n)};if(f(t,o.StatementPredicate))return{kind:"statement-predicate",source:d(t,o.predicateOf,`${e}.predicateOf`,n)};if(f(t,o.StatementValue))return{kind:"statement-value",source:d(t,o.valueOf,`${e}.valueOf`,n)};if(f(t,o.DateFormat))return{kind:"date-format",source:d(t,o.dateSource,`${e}.dateSource`,n),format:cn(t,e)};if(f(t,o.Add))return{kind:"add",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Subtract))return{kind:"subtract",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Multiply))return{kind:"multiply",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Divide))return{kind:"divide",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Reverse))return{kind:"reverse",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.WindowedMap)){let r=at(t,o.windowSize);if(r===void 0||!Number.isInteger(r)||r<1)throw new y("windowSize must be a positive integer",`${e}.windowSize`);return{kind:"windowed-map",source:d(t,o.source,`${e}.source`,n),windowSize:r,windowVar:j(t,o.windowVar,e),windowBody:d(t,o.windowBody,`${e}.windowBody`,n)}}if(f(t,o.PairwiseMap))return{kind:"pairwise-map",source:d(t,o.source,`${e}.source`,n),firstVar:j(t,o.firstVar,e),secondVar:j(t,o.secondVar,e),pairBody:d(t,o.pairBody,`${e}.pairBody`,n)};if(f(t,o.Scan))return{kind:"scan",source:d(t,o.source,`${e}.source`,n),initialState:d(t,o.initialState,`${e}.initialState`,n),stateVar:j(t,o.stateVar,e),elementVar:j(t,o.elementVar,e),accumulate:d(t,o.accumulate,`${e}.accumulate`,n)};if(f(t,o.ListItemAt))return{kind:"list-item-at",source:d(t,o.source,`${e}.source`,n),itemIndex:d(t,o.itemIndex,`${e}.itemIndex`,n)};if(f(t,o.Equals))return{kind:"equals",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.GreaterThan))return{kind:"greater-than",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.LessThan))return{kind:"less-than",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.LessThanOrEqual))return{kind:"less-than-or-equal",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.Not))return{kind:"not",operand:d(t,o.operand,`${e}.operand`,n)};if(f(t,o.And))return{kind:"and",operands:Ee(t,o.operands,`${e}.operands`,n)};if(f(t,o.Or))return{kind:"or",operands:Ee(t,o.operands,`${e}.operands`,n)};if(f(t,o.Contains))return{kind:"contains",haystack:d(t,o.haystack,`${e}.haystack`,n),needle:d(t,o.needle,`${e}.needle`,n)};if(f(t,o.Abs))return{kind:"abs",value:d(t,o.value,`${e}.value`,n)};if(f(t,o.Negate))return{kind:"negate",value:d(t,o.value,`${e}.value`,n)};if(f(t,o.IsReference))return{kind:"is-reference",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsEmbedded))return{kind:"is-embedded",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsList))return{kind:"is-list",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsString))return{kind:"is-string",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsNumber))return{kind:"is-number",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsBoolean))return{kind:"is-boolean",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.StatementObject))return{kind:"statement-object",source:d(t,o.statementSource,`${e}.statementSource`,n)};if(f(t,o.Let))return{kind:"let",bindName:j(t,o.letName,e),bindValue:d(t,o.letValue,`${e}.letValue`,n),body:d(t,o.letBody,`${e}.letBody`,n)};if(f(t,o.GetStatementByName))return{kind:"get-statement-by-name",inSubject:d(t,o.inSubject,`${e}.inSubject`,n),byName:d(t,o.byName,`${e}.byName`,n)};throw new y("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}function d(t,e,n,r){let i=se(t,e);if(!i)throw new y("child expression is required",n);return J(i,n,r)}function an(t,e,n,r){let i=se(t,e);if(i)return J(i,n,r)}function Ee(t,e,n,r){let i=[],a=0;for(let u of A(t,e))if(u instanceof w)for(let c of u.object)c instanceof R&&i.push(J(c,`${n}[${a++}]`,r));else u instanceof T&&i.push(J(u.object,`${n}[${a++}]`,r));return i}function on(t,e,n){let r=[],i=0;for(let a of A(t,o.set))if(a instanceof w)for(let u of a.object)u instanceof R&&r.push(Qe(u,`${e}[${i++}]`,n));else a instanceof T&&r.push(Qe(a.object,`${e}[${i++}]`,n));return r}function Qe(t,e,n){return{field:P(t,o.field,e,"field"),value:d(t,o.bindValue,`${e}.bindValue`,n)}}function sn(t,e){let n=_(t,o.normKind);if(!n)throw new y("normKind is required",e);if(S(n,o.NORM_TRIM_END))return"trim-end";throw new y(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function un(t,e){let n=_(t,o.renderFormat);if(!n)throw new y("renderFormat is required",e);if(S(n,o.RENDER_HTML))return"html";if(S(n,o.RENDER_MARKDOWN))return"markdown";throw new y(`Unknown RenderFormat: ${n.publisher}/${n.package_}/${n.name}`,e)}var xe=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function cn(t,e){let n=G(t,o.dateFormat);if(!n)throw new y("dateFormat is required",e);if(!xe.has(n))throw new y(`Unknown dateFormat "${n}"; supported: ${[...xe].join(", ")}`,e);return n}function ln(t,e,n){let r=_(t,o.fragmentRef);if(!r)throw new y("fragmentRef is required",e);if(!mn(n.catalog,r))throw new y(`ExpressionFragment not found: ${r.publisher}/${r.package_}/${r.name}`,e);return{kind:"call-fragment",fragmentKey:dn(r)}}function dn(t){return`${t.publisher}/${t.package_}/${t.name}`}function fn(t){let e=new Map,n=[];for(let r of t){if(!(r instanceof E)||!f(r,o.ExpressionFragment))continue;let i=se(r,o.body);if(!i)continue;let a=(r.namespace||"").split("@")[0]||"",u=a.indexOf("/");if(u<0)continue;let c=a.substring(0,u),l=a.substring(u+1),m=`${c}/${l}/${r.name}`;n.push({key:m,subject:r,bodyEmb:i,pubPkgName:`${a}/${r.name}`})}for(let r of n){let i=J(r.bodyEmb,`fragment(${r.pubPkgName})`,{catalog:t,depth:0});e.set(r.key,i)}return e}function mn(t,e){for(let n of t)if(!(!(n instanceof E)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&f(n,o.ExpressionFragment))return n}function rt(t,e){let n=new Set;for(let r of A(t,o.outputs))if(r instanceof V)n.add(r.object.subject.name);else if(r instanceof w)for(let i of r.object)i instanceof b&&n.add(i.subject.name);if(n.size===0)throw new y("outputs is required (at least one OutputFormat)",e);return n}function it(t,e,n){let r=new Map,i=0;for(let a of A(t,o.formatOverrides))if(a instanceof w){for(let u of a.object)if(u instanceof R){let[c,l]=et(u,`${e}[${i++}]`);r.set(c,l)}}else if(a instanceof T){let[u,c]=et(a.object,`${e}[${i++}]`);r.set(u,c)}return r}function et(t,e){let n=_(t,o.formatTarget);if(!n)throw new y("formatTarget is required",e);let r=[];for(let c of A(t,o.metadataKeys))if(c instanceof L)r.push(c.object);else if(c instanceof w)for(let l of c.object){let m=l.value;typeof m=="string"&&r.push(m)}let i=new Map;for(let c of A(t,o.metadataRenames))if(c instanceof w){for(let l of c.object)if(l instanceof R){let m=G(l,o.fromKey),g=G(l,o.toKey);m&&g&&i.set(m,g)}}else if(c instanceof T){let l=c.object,m=G(l,o.fromKey),g=G(l,o.toKey);m&&g&&i.set(m,g)}let a=$e(t,o.trailingNewline),u=$e(t,o.omitWrapper);return[n.name,{metadataKeys:r.length>0?r:void 0,metadataRenames:i,trailingNewline:a,omitWrapper:u}]}function pn(t){return t.predicate?.subject}function A(t,e){let n=[];for(let r of t.statement){let i=pn(r);i&&S(i,e)&&n.push(r)}return n}function se(t,e){for(let n of A(t,e))if(n instanceof T)return n.object}function _(t,e){for(let n of A(t,e))if(n instanceof V)return ve(n.object.subject)}function G(t,e){for(let n of A(t,e))if(n instanceof L)return n.object}function at(t,e){for(let n of A(t,e))if(n instanceof C)return n.object}function $e(t,e){for(let n of A(t,e))if(n instanceof U)return n.object}function j(t,e,n){let r=G(t,e);if(r===void 0)throw new y(`${e.name} (string) is required`,n);return r}function tt(t,e,n){let r=at(t,e);if(r===void 0)throw new y(`${e.name} (number) is required`,n);return r}function gn(t,e,n){let r=$e(t,e);if(r===void 0)throw new y(`${e.name} (boolean) is required`,n);return r}function P(t,e,n,r){let i=_(t,e);if(!i)throw new y(`${r} (URI reference) is required`,n);return i}function ve(t){return{publisher:t.publisher,package_:t.package_,name:t.name}}var yn={publisher:"kanonak.org",package_:"core-rdf",name:"label"},N=class extends Error{},ge=class{constructor(e,n,r=new Map){this.resolver=e;this.catalog=n;this.fragments=r}resolver;catalog;fragments;async evaluate(e,n){switch(e.kind){case"string-literal":return e.value;case"integer-literal":return e.value;case"decimal-literal":return e.value;case"boolean-literal":return e.value;case"uri-literal":return{...e.refTo};case"var-ref":{if(!n.has(e.varName))throw new N(`Unbound variable "${e.varName}"`);return n.get(e.varName)}case"concat":{let r=[];for(let i of e.parts){let a=await this.evaluate(i,n);if(a!=null)if(Array.isArray(a))for(let u of a)r.push(u);else r.push(a)}return r}case"fallback":{let r=await this.evaluate(e.primary,n);return ot(r)?r:this.evaluate(e.alternate,n)}case"when":return await this.evaluate(e.condition,n)===!0?this.evaluate(e.thenBuild,n):e.elseBuild?this.evaluate(e.elseBuild,n):void 0;case"is-set":{let r=await this.evaluate(e.check,n);return ot(r)}case"property-read":{let r=await this.evaluate(e.source,n);return pe(r,e.readProp)}case"traverse":{let r=await this.evaluate(e.source,n);if(!(r instanceof K))return;let i=hn(r,e.through),a=[];for(let u of i){let c=await this.resolver.resolveSubject(u,this.catalog);if(!c)continue;let l=new Map(n);l.set("input",c);let m=await this.evaluate(e.step,l);m!=null&&a.push(ue(m))}return a.join("")}case"uri-name":{let r=await this.evaluate(e.source,n);return X(r)?r.name:r instanceof b?r.subject.name:r instanceof E?r.name:r instanceof R?r.name??"":void 0}case"uri-publisher":{let r=await this.evaluate(e.source,n);return je(r)?.publisher}case"uri-package":{let r=await this.evaluate(e.source,n);return je(r)?.package_}case"uri-version":{let r=await this.evaluate(e.source,n);return je(r)?.version}case"subject-uri":{let r=await this.evaluate(e.source,n);if(r instanceof E){let i=r.namespace??"",a=r.name??"";return!i||!a?void 0:`${i}/${a}`}if(r instanceof b){let i=r.subject,a=i.version;return a&&typeof a.major=="number"?`${i.publisher}/${i.package_}@${a.major}.${a.minor}.${a.patch}/${i.name}`:`${i.publisher}/${i.package_}/${i.name}`}return}case"display-label":{let r=await this.resolver.resolveSubject({...e.labelTarget},this.catalog);return r?pe(r,e.labelSource):void 0}case"resolve-ref":{let r=await this.evaluate(e.source,n);return r instanceof E?r:r instanceof b?await this.resolver.resolveSubject(r.subject,this.catalog):X(r)?await this.resolver.resolveSubject(r,this.catalog):void 0}case"normalize":{let r=await this.evaluate(e.source,n),i=r==null?"":ue(r);return e.normKind==="trim-end"?i.replace(/[\s\r\n]+$/u,""):i}case"render-markdown":{let r=await this.evaluate(e.source,n);if(!(r instanceof K))return;let i;for(let u of r.statement){let c=Ae(u);if(c&&S(c,e.readProp)){i=u;break}}if(!(i instanceof Ce)){let u=pe(r,e.readProp);return u==null?void 0:ue(u)}let a=await this.renderMarkdownLinks(i);return e.format==="html"?x(a):a}case"build-ast-node":{let r={kind:e.astClass.name};for(let i of e.set){let a=await this.evaluate(i.value,n);if(a==null||Array.isArray(a)&&a.length===0)continue;let u=i.field.name;wn.has(u)&&(Array.isArray(a)&&a.every(c=>st(c))?a=a.map(c=>String(c)).join(""):st(a)&&(a=String(a))),r[u]=a}return r}case"call-fragment":{let r=this.fragments.get(e.fragmentKey);if(!r)throw new N(`ExpressionFragment ${e.fragmentKey} not found in registry`);return this.evaluate(r,n)}case"join":return(await this.evaluateList(e.source,n)).map(i=>i==null?"":ue(i)).join(e.separator);case"count":return(await this.evaluateList(e.source,n)).length;case"sum":{let r=await this.evaluateList(e.source,n),i=0;for(let a of r)i+=$(a,"Sum");return i}case"min":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new N("Min on an empty list is undefined; guard with IsSet");let i=$(r[0],"Min");for(let a=1;a<r.length;a++){let u=$(r[a],"Min");u<i&&(i=u)}return i}case"max":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new N("Max on an empty list is undefined; guard with IsSet");let i=$(r[0],"Max");for(let a=1;a<r.length;a++){let u=$(r[a],"Max");u>i&&(i=u)}return i}case"average":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new N("Average on an empty list is undefined; guard with IsSet");let i=0;for(let a of r)i+=$(a,"Average");return i/r.length}case"for-each":{let r=await this.evaluateList(e.source,n),i=[];for(let a of r){let u=new Map(n);u.set(e.loopVar,B(a));let c=await this.evaluate(e.emit,u);if(c!=null)if(Array.isArray(c))for(let l of c)i.push(l);else i.push(c)}return i}case"list-map":{let r=await this.evaluateList(e.source,n),i=[];for(let a of r){let u=new Map(n);u.set(e.loopVar,B(a)),i.push(await this.evaluate(e.mapBody,u))}return i}case"filter":{let r=await this.evaluateList(e.source,n),i=[];for(let a of r){let u=new Map(n);u.set(e.loopVar,B(a)),await this.evaluate(e.predicate,u)===!0&&i.push(a)}return i}case"partition-by":{let r=await this.evaluateList(e.source,n),i=new Map,a=[];for(let u of r){let c=new Map(n);c.set(e.loopVar,B(u));let l=await this.evaluate(e.partitionKey,c),m=lt(l),g=i.get(m);g||(g={kind:"Partition",key:l,members:[]},i.set(m,g),a.push(m)),g.members.push(u)}return a.map(u=>i.get(u))}case"distinct-by":{let r=await this.evaluateList(e.source,n),i=new Set,a=[];for(let u of r){let c=new Map(n);c.set(e.loopVar,B(u));let l=await this.evaluate(e.distinctKey,c),m=lt(l);i.has(m)||(i.add(m),a.push(u))}return a}case"all-statements":{let r=await this.evaluate(e.source,n);return r instanceof K?r.statement:[]}case"statement-predicate":{let r=await this.evaluate(e.source,n);if(Ve(r)){let i=r.predicate;if(i instanceof b)return i}return}case"statement-value":{let r=await this.evaluate(e.source,n);return Ve(r)?$n(r):void 0}case"date-format":{let r=await this.evaluate(e.source,n),i=r==null?"":ue(r);return i?En(i,e.format):""}case"add":{let r=$(await this.evaluate(e.left,n),"Add"),i=$(await this.evaluate(e.right,n),"Add");return r+i}case"subtract":{let r=$(await this.evaluate(e.left,n),"Subtract"),i=$(await this.evaluate(e.right,n),"Subtract");return r-i}case"multiply":{let r=$(await this.evaluate(e.left,n),"Multiply"),i=$(await this.evaluate(e.right,n),"Multiply");return r*i}case"divide":{let r=$(await this.evaluate(e.left,n),"Divide"),i=$(await this.evaluate(e.right,n),"Divide");if(i===0)throw new N("Divide by zero; guard with When");return r/i}case"reverse":{if(e.source.kind==="reverse")return this.evaluate(e.source.source,n);let r=await this.evaluateReverseIterator(e.source,n);return r!==void 0?r:[...await this.evaluateList(e.source,n)].reverse()}case"windowed-map":{let r=await this.evaluateList(e.source,n);if(r.length<e.windowSize)return[];let i=[];for(let a=0;a+e.windowSize<=r.length;a++){let u=r.slice(a,a+e.windowSize),c=new Map(n);c.set(e.windowVar,u);let l=await this.evaluate(e.windowBody,c);if(l!=null)if(Array.isArray(l))for(let m of l)i.push(m);else i.push(l)}return i}case"pairwise-map":{let r=await this.evaluateList(e.source,n);if(r.length<2)return[];let i=[];for(let a=0;a+1<r.length;a++){let u=new Map(n);u.set(e.firstVar,B(r[a])),u.set(e.secondVar,B(r[a+1]));let c=await this.evaluate(e.pairBody,u);if(c!=null)if(Array.isArray(c))for(let l of c)i.push(l);else i.push(c)}return i}case"scan":{let r=await this.evaluateList(e.source,n);if(r.length===0)return[];let i=await this.evaluate(e.initialState,n),a=[];for(let u of r){let c=new Map(n);c.set(e.stateVar,i),c.set(e.elementVar,B(u));let l=await this.evaluate(e.accumulate,c);a.push(l),i=l}return a}case"list-item-at":{let r=await this.evaluateList(e.source,n),i=await this.evaluate(e.itemIndex,n);return typeof i!="number"||!Number.isInteger(i)||i<0||i>=r.length?void 0:r[i]}case"equals":{let r=await this.evaluate(e.left,n),i=await this.evaluate(e.right,n);return ut(r,i)}case"greater-than":{let r=await this.evaluate(e.left,n),i=await this.evaluate(e.right,n);return typeof r!="number"||typeof i!="number"?!1:r>i}case"less-than":{let r=await this.evaluate(e.left,n),i=await this.evaluate(e.right,n);return typeof r!="number"||typeof i!="number"?!1:r<i}case"greater-than-or-equal":{let r=await this.evaluate(e.left,n),i=await this.evaluate(e.right,n);return typeof r!="number"||typeof i!="number"?!1:r>=i}case"less-than-or-equal":{let r=await this.evaluate(e.left,n),i=await this.evaluate(e.right,n);return typeof r!="number"||typeof i!="number"?!1:r<=i}case"not":{let r=await this.evaluate(e.operand,n);return r===!0?!1:r===!1?!0:void 0}case"and":{for(let r of e.operands)if(await this.evaluate(r,n)!==!0)return!1;return!0}case"or":{for(let r of e.operands)if(await this.evaluate(r,n)===!0)return!0;return!1}case"contains":{let r=await this.evaluateList(e.haystack,n),i=await this.evaluate(e.needle,n);for(let a of r)if(ut(a,i))return!0;return!1}case"abs":{let r=$(await this.evaluate(e.value,n),"Abs");return Math.abs(r)}case"negate":return-$(await this.evaluate(e.value,n),"Negate");case"is-reference":{let r=await this.evaluate(e.check,n);return r instanceof b||r instanceof E}case"is-embedded":return await this.evaluate(e.check,n)instanceof R;case"is-list":{let r=await this.evaluate(e.check,n);return Array.isArray(r)}case"is-string":return typeof await this.evaluate(e.check,n)=="string";case"is-number":return typeof await this.evaluate(e.check,n)=="number";case"is-boolean":return typeof await this.evaluate(e.check,n)=="boolean";case"statement-object":{let r=await this.evaluate(e.source,n);if(!Ve(r))return;let i=r;return i instanceof L||i instanceof C||i instanceof U||i instanceof V||i instanceof T||i instanceof w?i.object:void 0}case"let":{let r=await this.evaluate(e.bindValue,n),i=new Map(n);return i.set(e.bindName,r),this.evaluate(e.body,i)}case"get-statement-by-name":{let r=await this.evaluate(e.inSubject,n),i=await this.evaluate(e.byName,n);if(!(r instanceof K)||typeof i!="string")return;for(let a of r.statement)if(a.predicate?.subject?.name===i)return a;return}default:{let r=e;throw new N("Unknown expression kind")}}}async renderMarkdownLinks(e){let n=e.object,r="",i=0;for(let a of e.links){if(r+=n.slice(i,a.startOffset),a.target){let u=a.target.subject,c=a.displayText??await this.resolveLabel(u)??u.name;r+=`[${c}](${I(u)})`}else r+=a.displayText??a.reference;i=a.endOffset}return r+=n.slice(i),r}async resolveLabel(e){let n=await this.resolver.resolveSubject(e,this.catalog);if(!n)return;let r=pe(n,yn);return typeof r=="string"?r:void 0}async evaluateList(e,n){let r=await this.evaluate(e,n);return r==null?[]:Array.isArray(r)?r:[r]}async evaluateReverseIterator(e,n){if(e.kind==="pairwise-map"){let r=await this.evaluateList(e.source,n);if(r.length<2)return[];let i=[];for(let a=r.length-1;a>=1;a--){let u=new Map(n);u.set(e.firstVar,B(r[a-1])),u.set(e.secondVar,B(r[a]));let c=await this.evaluate(e.pairBody,u);if(c!=null)if(Array.isArray(c))for(let l of c)i.push(l);else i.push(c)}return i}if(e.kind==="for-each"){let r=await this.evaluateList(e.source,n),i=[];for(let a=r.length-1;a>=0;a--){let u=new Map(n);u.set(e.loopVar,B(r[a]));let c=await this.evaluate(e.emit,u);if(c!=null)if(Array.isArray(c))for(let l of c)i.push(l);else i.push(c)}return i}if(e.kind==="list-map"){let r=await this.evaluateList(e.source,n),i=[];for(let a=r.length-1;a>=0;a--){let u=new Map(n);u.set(e.loopVar,B(r[a])),i.push(await this.evaluate(e.mapBody,u))}return i}if(e.kind==="windowed-map"){let r=await this.evaluateList(e.source,n);if(r.length<e.windowSize)return[];let i=[];for(let a=r.length-e.windowSize;a>=0;a--){let u=r.slice(a,a+e.windowSize),c=new Map(n);c.set(e.windowVar,u);let l=await this.evaluate(e.windowBody,c);if(l!=null)if(Array.isArray(l))for(let m of l)i.push(m);else i.push(l)}return i}}};function pe(t,e){if(t instanceof K)return kn(t,e);if(bn(t))return S(e,o.key)?t.key:S(e,o.members)?t.members:void 0}function kn(t,e){for(let n of t.statement){let r=Ae(n);if(!(!r||!S(r,e))&&(n instanceof L||n instanceof C||n instanceof U||n instanceof V||n instanceof T||n instanceof w))return n.object}}function hn(t,e){let n=[];for(let r of t.statement){let i=Ae(r);if(!(!i||!S(i,e))){if(r instanceof V)n.push(r.object.subject);else if(r instanceof w)for(let a of r.object)a instanceof b&&n.push(a.subject)}}return n}function Ae(t){return t.predicate?.subject}function ue(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(t instanceof K)return t.name??"";if(t instanceof b)return t.subject.name;if(X(t))return t.name;let e=t.value;return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function B(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof K)&&!(t instanceof b)&&!(t instanceof R)&&"value"in t?t.value:t}function ot(t){return t==null?!1:typeof t=="string"||Array.isArray(t)?t.length>0:typeof t=="boolean"?t===!0:!0}function X(t){return typeof t=="object"&&t!==null&&typeof t.publisher=="string"&&typeof t.package_=="string"&&typeof t.name=="string"}function bn(t){return typeof t=="object"&&t!==null&&t.kind==="Partition"&&Array.isArray(t.members)}function $(t,e){if(typeof t=="number"&&Number.isFinite(t))return t;throw new N(`${e} requires numeric elements; got ${Sn(t)}`)}function je(t){if(t instanceof E){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);return n<0||r<0?void 0:{publisher:e.substring(0,n),package_:e.substring(n+1,r),version:e.substring(r+1),name:t.name??""}}if(t instanceof b){let e=t.subject,n=e.version;return{publisher:e.publisher,package_:e.package_,version:n&&typeof n.major=="number"?`${n.major}.${n.minor}.${n.patch}`:"",name:e.name}}if(X(t))return{publisher:t.publisher,package_:t.package_,version:"",name:t.name}}var wn=new Set(["stringValue","text","rawContent","key","propertyKey","linkLabel"]);function st(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function Sn(t){return t===void 0?"undefined":t===null?"null":Array.isArray(t)?`array(${t.length})`:typeof t}function En(t,e){let n=new Date(t);if(isNaN(n.getTime()))return"";let r=n.getUTCFullYear(),i=["January","February","March","April","May","June","July","August","September","October","November","December"][n.getUTCMonth()],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getUTCMonth()],u=n.getUTCDate(),c=(l,m=2)=>String(l).padStart(m,"0");switch(e){case"iso-date":return`${r}-${c(n.getUTCMonth()+1)}-${c(u)}`;case"iso-datetime":return`${r}-${c(n.getUTCMonth()+1)}-${c(u)}T${c(n.getUTCHours())}:${c(n.getUTCMinutes())}:${c(n.getUTCSeconds())}Z`;case"short-date":return`${a} ${u}`;case"long-date":return`${i} ${u}, ${r}`;case"year":return String(r);case"month-year":return`${i} ${r}`}}function ut(t,e){if(t==null||e===void 0||e===null)return!1;if(t===e)return!0;let n=typeof t=="object"&&"value"in t?t.value:void 0,r=typeof e=="object"&&"value"in e?e.value:void 0,i=n??t,a=r??e,u=ct(t),c=ct(e);return u&&c?u.publisher===c.publisher&&u.package_===c.package_&&u.name===c.name:typeof i=="string"&&typeof a=="string"||typeof i=="number"&&typeof a=="number"||typeof i=="boolean"&&typeof a=="boolean"?i===a:!1}function ct(t){if(t instanceof b){let e=t.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}if(t instanceof E){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);if(n<0)return;let i=e.substring(0,n),a=r>=0?e.substring(n+1,r):e.substring(n+1);return{publisher:i,package_:a,name:t.name??""}}if(X(t))return{publisher:t.publisher,package_:t.package_,name:t.name}}function Ve(t){return t instanceof L||t instanceof C||t instanceof U||t instanceof V||t instanceof T||t instanceof w}function $n(t){return t instanceof L||t instanceof C||t instanceof U?String(t.object??""):t instanceof V?t.object?.subject?.name??"":t instanceof T?"[embedded]":t instanceof w?(t.object??[]).map(n=>{if(n instanceof b)return n.subject.name;let r=n.name;if(r&&r.length>0)return r;let i=n.value;return typeof i=="string"||typeof i=="number"||typeof i=="boolean"?String(i):"[embedded]"}).join(", "):""}function lt(t){if(t===void 0)return"\0undef";if(t===null)return"\0null";if(typeof t=="string")return`s:${t}`;if(typeof t=="number")return`n:${t}`;if(typeof t=="boolean")return`b:${t}`;if(t instanceof b){let e=t.subject;return`r:${e.publisher}/${e.package_}/${e.name}`}if(t instanceof K){let e=t.name??"";return`k:${t.namespace??""}/${e}`}return X(t)?`u:${t.publisher}/${t.package_}/${t.name}`:`o:${JSON.stringify(t)}`}var vn={"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"}},F=class extends Error{},ye=class{backends=new Map;constructor(){this.register(new Y),this.register(new Z),this.register(new Q),this.register(new ee),this.register(new te),this.register(new ne),this.register(new re),this.register(new ae)}register(e){this.backends.set(e.backendUri,e)}async run(e){let n=e.transformationKanonaks??e.allKanonaks,r=me(e.transformation,n);if(!r.outputs.has(e.outputFormat))throw new F(`Transformation "${r.name}" does not declare output format "${e.outputFormat}". Declared: ${Array.from(r.outputs).join(", ")}`);let i=this.findBackend(e.outputFormat);if(!i)throw new F(`No backend registered for OutputFormat "${e.outputFormat}".`);let a=new oe(e.repository,e.parser,e.objectParser),u=new ge(a,e.allKanonaks,r.fragments);return r.kind==="instance"?this.runInstance(r,e,i,u):this.runSet(r,e,i,u)}async runInstance(e,n,r,i){let a=dt(n.instances,e.inputPattern.requires),u=ft(a,e.inputPattern.sortBy),c=[];for(let l of u){let m=new Map;m.set("input",l);let g=await i.evaluate(e.rule,m);De(g,e.name,`input "${l.name}"`);let k=Ke(await i.evaluate(e.artifactName,m),e.name,`input "${l.name}"`),D=Te(e.overrides.get(n.outputFormat),n.runtimeOverride),v=r.render(g,D);c.push({fileName:k,format:n.outputFormat,content:v,source:{kind:"instance",sourceName:l.name}})}return c}async runSet(e,n,r,i){let a=dt(n.instances,e.inputPattern.requires),u=ft(a,e.inputPattern.sortBy);return e.partitionBy?this.runSetWithPartition(e,u,n,r,i):this.runSetSingle(e,u,n,r,i)}async runSetSingle(e,n,r,i,a){let u=new Map;u.set("inputs",n);let c=await a.evaluate(e.rule,u);De(c,e.name,"set");let l=Ke(await a.evaluate(e.artifactName,u),e.name,"set"),m=Te(e.overrides.get(r.outputFormat),r.runtimeOverride),g=i.render(c,m);return[{fileName:l,format:r.outputFormat,content:g,source:{kind:"set",memberCount:n.length}}]}async runSetWithPartition(e,n,r,i,a){let u=e.partitionBy,c=new Map,l=[];for(let g of n){let k=An(g,u);if(k==null)continue;let D=Dn(k),v=c.get(D);v||(v={keyValue:k,keyDisplay:Kn(k),members:[]},c.set(D,v),l.push(D)),v.members.push(g)}let m=[];for(let g of l){let k=c.get(g),D=new Map;D.set("inputs",k.members),D.set("key",k.keyValue);let v=await a.evaluate(e.rule,D);De(v,e.name,`partition "${k.keyDisplay}"`);let yt=Ke(await a.evaluate(e.artifactName,D),e.name,`partition "${k.keyDisplay}"`),kt=Te(e.overrides.get(r.outputFormat),r.runtimeOverride),ht=i.render(v,kt);m.push({fileName:yt,format:r.outputFormat,content:ht,source:{kind:"set",memberCount:k.members.length,partitionKey:k.keyDisplay}})}return m}findBackend(e){let n=vn[e];if(n)return this.backends.get(n.formatUri)}};function dt(t,e){return e.length===0?t:t.filter(n=>{for(let r of e)if(!Vn(n,r))return!1;return!0})}function ft(t,e){if(e.length===0)return t;let n=[...t];return n.sort((r,i)=>{for(let a of e){let u=mt(r,a.byProperty),c=mt(i,a.byProperty),l=jn(u,c,a.order);if(l!==0)return l}return 0}),n}function mt(t,e){for(let n of t.statement){let r=Be(n);if(!(!r||!S(r,e))){if(n instanceof L||n instanceof C||n instanceof U)return n.object;if(n instanceof w)throw new F(`Sort property "${e.name}" on instance "${t.name??"?"}" resolves to a list \u2014 list-typed properties are not sortable. Use a scalar property.`);if(n instanceof V)throw new F(`Sort property "${e.name}" on instance "${t.name??"?"}" resolves to a reference \u2014 reference-typed properties don't have a natural total order. Use a scalar property.`)}}}function jn(t,e,n){if(t===void 0&&e===void 0)return 0;if(t===void 0)return n==="ascending"?1:-1;if(e===void 0)return n==="ascending"?-1:1;let r;return typeof t=="number"&&typeof e=="number"?r=t-e:r=String(t).localeCompare(String(e)),n==="ascending"?r:-r}function Vn(t,e){for(let n of t.statement){let r=Be(n);if(!r||!S(r,e))continue;let i=n.object;if(i!=null&&!(typeof i=="string"&&i.length===0)&&!(Array.isArray(i)&&i.length===0))return!0}return!1}function An(t,e){for(let n of t.statement){let r=Be(n);if(!(!r||!S(r,e))&&(n instanceof L||n instanceof C||n instanceof U||n instanceof V||n instanceof w))return n.object}}function Be(t){return t.predicate?.subject}function Dn(t){if(t===void 0)return" undef";if(t===null)return" null";if(typeof t=="string")return`s:${t}`;if(typeof t=="number")return`n:${t}`;if(typeof t=="boolean")return`b:${t}`;if(t instanceof b){let e=t.subject;return`r:${e.publisher}/${e.package_}/${e.name}`}if(t instanceof K){let e=t.name??"";return`k:${t.namespace??""}/${e}`}if(typeof t=="object"&&t!==null&&typeof t.name=="string"&&typeof t.publisher=="string"){let e=t;return`u:${e.publisher}/${e.package_}/${e.name}`}return`o:${JSON.stringify(t)}`}function Kn(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):t instanceof b?t.subject.name:t instanceof K?t.name??"":typeof t=="object"&&t!==null&&typeof t.name=="string"?t.name:""}function De(t,e,n){if(typeof t!="object"||t===null||t.kind!=="Document")throw new F(`Transformation "${e}" rule did not yield a Document for ${n}. Got: ${pt(t)}`)}function Ke(t,e,n){if(typeof t=="string")return t;if(Array.isArray(t)&&t.every(Tn))return t.map(r=>String(r)).join("");throw new F(`Transformation "${e}" artifactName did not yield a string for ${n}. Got: ${pt(t)}`)}function Tn(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function pt(t){if(t===void 0)return"undefined";if(t===null)return"null";if(Array.isArray(t))return`array(${t.length})`;if(typeof t=="object"){let e=t.kind;return e?`object(kind=${e})`:"object"}return typeof t}function Te(t,e){if(!t&&!e)return;let n={metadataRenames:e?.metadataRenames??t?.metadataRenames??new Map},r=e?.metadataKeys??t?.metadataKeys;r!==void 0&&(n.metadataKeys=r);let i=e?.trailingNewline??t?.trailingNewline;i!==void 0&&(n.trailingNewline=i);let a=e?.omitWrapper??t?.omitWrapper;return a!==void 0&&(n.omitWrapper=a),n}var M=class extends Error{constructor(n,r){super(n);this.cause=r;this.name="RenderError"}cause},gt={publisher:"kanonak.org",package_:"derivation",name:"default"},Le=class{constructor(e,n=new Re,r=new Ue){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;runner=new ye;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async findDerivation(e){let n=await this.getCatalog(),r=q(n,e.resource);if(!(r instanceof E))return;let i=e.variant??gt;return Ne(r,e.format,i,n)}async render(e){let n=await this.findDerivation(e);if(!n)throw new M(`No derivation found for ${W(e.resource)} \u2192 format ${W(e.format)}`+(e.variant?` variant ${W(e.variant)}`:""));let r={transformation:{publisher:n.transformation.publisher,package_:n.transformation.package_,name:n.transformation.name},input:e.resource,format:e.format};return e.omitWrapper!==void 0&&(r.omitWrapper=e.omitWrapper),this.runTransformation(r)}async runTransformation(e){let n=await this.getCatalog(),r=q(n,e.transformation);if(!(r instanceof E))throw new M(`Transformation not found: ${W(e.transformation)}`);let i=q(n,e.input);if(!(i instanceof E))throw new M(`Input resource not found: ${W(e.input)}`);let a=me(r,n),u=Bn(a.outputs,e.format);if(!u)throw new M(`Transformation ${W(e.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${W(e.format)}`);let c;try{c=await this.runner.run({transformation:r,instances:[i],allKanonaks:n,repository:this.repository,parser:this.parser,objectParser:this.objectParser,outputFormat:u,...e.omitWrapper!==void 0?{runtimeOverride:{metadataRenames:new Map,omitWrapper:e.omitWrapper}}:{}})}catch(l){throw new M(`Transformation execution failed: ${l.message}`,l)}if(c.length===0)throw new M("Transformation produced no artifacts");return{content:c[0].content,format:e.format,filename:c[0].fileName}}async getCatalog(){return this.cachedCatalog||(this.cachedCatalog=await this.objectParser.parseKanonaks(this.repository)),this.cachedCatalog}};function W(t){return`${t.publisher}/${t.package_}/${t.name}`}function Bn(t,e){let n=e.name;if(t.has(n))return n;for(let r of t)if(r.startsWith(n+"-")||r===n)return r}export{ne as CssBackend,gt as DEFAULT_VARIANT,h as DOCAST,wt as DOCAST_PKG,bt as DOCAST_PUB,ae as DynamoDbBackend,ge as ExpressionEngineV3,N as ExpressionEvalErrorV3,ee as HtmlBackend,Q as JsonBackend,Y as MarkdownFrontmatterBackend,oe as ReferenceResolver,M as RenderError,vn as SUPPORTED_FORMATS_V3,te as SvgBackend,o as TX_V3,en as TX_V3_PKG,xt as TX_V3_PUB,nr as TX_V3_VERSION_MAJOR,Z as TomlBackend,Le as TransformationEngine,y as TransformationLoadErrorV3,F as TransformationRunnerErrorV3,ye as TransformationRunnerV3,re as YamlBackend,me as compileTransformationV3,x as renderMarkdownToHtml};
|
|
103
|
+
`);return n?.trailingNewline&&a.length>0&&!a.endsWith(`
|
|
104
|
+
`)&&(a+=`
|
|
105
|
+
`),a}};function ae(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ie=class{backendUri="kanonak.org/transformations/dynamodb-json";render(e,n){if(!e.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=Ye(e.metadata,n),a=JSON.stringify(r,null,2);return n?.trailingNewline&&!a.endsWith(`
|
|
106
|
+
`)&&(a+=`
|
|
107
|
+
`),a}};function Ye(t,e){let n=new Map;for(let i of t.entries)n.set(i.key,i);let r=e?.metadataKeys??t.entries.map(i=>i.key),a={};for(let i of r){let u=n.get(i);if(!u)continue;let c=e?.metadataRenames.get(i)??i;a[c]=Ze(u.value,u.escapeHint)}return{M:a}}function Ze(t,e){switch(t.kind){case"StructuredMap":return Ye(t);case"StructuredList":return{L:t.items.map(n=>Ze(n,void 0))};case"StringScalar":return Qt(t.stringValue,e??t.escapeHint);case"IntegerScalar":return xt(t.integerValue,e??t.escapeHint)}}function Qt(t,e){if(e&&ae(e,h.ESC_DYNAMODB_BOOL)){if(t==="true")return{BOOL:!0};if(t==="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(t)}.`)}if(e&&ae(e,h.ESC_DYNAMODB_NULL))return{NULL:!0};if(e&&ae(e,h.ESC_DYNAMODB_NUMBER)){if(t.trim()===""||Number.isNaN(Number(t)))throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-number must hold a numeric literal; got ${JSON.stringify(t)}.`);return{N:t}}return{S:t}}function xt(t,e){if(e&&ae(e,h.ESC_DYNAMODB_BOOL))throw new Error(`dynamodb-json backend: esc-dynamodb-bool cannot apply to an IntegerScalar (value ${t}). Use a StringScalar "true"/"false".`);if(e&&ae(e,h.ESC_DYNAMODB_NULL))throw new Error(`dynamodb-json backend: esc-dynamodb-null cannot apply to an IntegerScalar (value ${t}). Use a StringScalar hinted esc-dynamodb-null.`);return{N:String(t)}}var oe=class{constructor(e,n,r){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;cache=new Map;async resolveSubject(e,n){let r=M(n,e);if(r)return r;let a=e.version,i=a&&typeof a.major=="number"?`@${a.major}.${a.minor}.${a.patch}`:"",u=`${e.publisher}/${e.package_}${i}`,c=this.cache.get(u);if(!c){let m=await this.repository.getDocumentsByNamespaceAsync(e.publisher,e.package_);if(m.length===0)return;let g=a&&typeof a.major=="number"?m.find(D=>{let v=D.metadata?.namespace_?.version;return v&&v.major===a.major&&v.minor===a.minor&&v.patch===a.patch})??m[0]:m[0],k=new Ne(g,this.repository);c=await this.objectParser.parseKanonaks(k),this.cache.set(u,c)}let l=M(c,e);if(l)return l;for(let m of c)if(m instanceof w&&m.name===e.name)return m}};var en="kanonak.org",tn="transformations",ir=3,s=t=>({publisher:en,package_:tn,name:t}),o={Transformation:s("Transformation"),InstanceTransformation:s("InstanceTransformation"),SetTransformation:s("SetTransformation"),inputPattern:s("inputPattern"),rule:s("rule"),artifactName:s("artifactName"),outputs:s("outputs"),formatOverrides:s("formatOverrides"),partitionBy:s("partitionBy"),InputPattern:s("InputPattern"),matchesClass:s("matchesClass"),requires:s("requires"),sortBy:s("sortBy"),SortKey:s("SortKey"),byProperty:s("byProperty"),order:s("order"),SortOrder:s("SortOrder"),ascending:s("ascending"),descending:s("descending"),OutputFormat:s("OutputFormat"),backendUri:s("backendUri"),FormatOverride:s("FormatOverride"),formatTarget:s("formatTarget"),metadataKeys:s("metadataKeys"),metadataRenames:s("metadataRenames"),trailingNewline:s("trailingNewline"),omitWrapper:s("omitWrapper"),RenameEntry:s("RenameEntry"),fromKey:s("fromKey"),toKey:s("toKey"),FMT_MARKDOWN_FRONTMATTER:s("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:s("plain-markdown"),FMT_TOML:s("toml"),FMT_JSON:s("json"),FMT_HTML:s("html"),FMT_SVG:s("svg"),Expression:s("Expression"),ListSourcedExpression:s("ListSourcedExpression"),ListAggregate:s("ListAggregate"),IteratingExpression:s("IteratingExpression"),BuildAstNode:s("BuildAstNode"),astClass:s("astClass"),set:s("set"),AstFieldBinding:s("AstFieldBinding"),field:s("field"),bindValue:s("bindValue"),When:s("When"),condition:s("condition"),thenBuild:s("thenBuild"),elseBuild:s("elseBuild"),Concat:s("Concat"),parts:s("parts"),Fallback:s("Fallback"),primary:s("primary"),alternate:s("alternate"),StringLiteral:s("StringLiteral"),stringLiteral:s("stringLiteral"),IntegerLiteral:s("IntegerLiteral"),integerLiteral:s("integerLiteral"),DecimalLiteral:s("DecimalLiteral"),decimalLiteral:s("decimalLiteral"),BooleanLiteral:s("BooleanLiteral"),booleanLiteral:s("booleanLiteral"),VarRef:s("VarRef"),varName:s("varName"),PropertyRead:s("PropertyRead"),readSource:s("readSource"),readProp:s("readProp"),Traverse:s("Traverse"),traverseSource:s("traverseSource"),through:s("through"),step:s("step"),UriName:s("UriName"),uriNameOf:s("uriNameOf"),UriPublisher:s("UriPublisher"),uriPublisherOf:s("uriPublisherOf"),UriPackage:s("UriPackage"),uriPackageOf:s("uriPackageOf"),UriVersion:s("UriVersion"),uriVersionOf:s("uriVersionOf"),SubjectUri:s("SubjectUri"),subjectOf:s("subjectOf"),UriLiteral:s("UriLiteral"),refTo:s("refTo"),DisplayLabel:s("DisplayLabel"),labelTarget:s("labelTarget"),labelSource:s("labelSource"),ResolveRef:s("ResolveRef"),resolveSource:s("resolveSource"),Normalize:s("Normalize"),normSource:s("normSource"),normKind:s("normKind"),NormalizeKind:s("NormalizeKind"),NORM_TRIM_END:s("trim-end"),IsSet:s("IsSet"),checkExpr:s("checkExpr"),ExpressionFragment:s("ExpressionFragment"),body:s("body"),CallFragment:s("CallFragment"),fragmentRef:s("fragmentRef"),source:s("source"),Join:s("Join"),separator:s("separator"),Count:s("Count"),Sum:s("Sum"),Min:s("Min"),Max:s("Max"),Average:s("Average"),loopVar:s("loopVar"),ForEach:s("ForEach"),emit:s("emit"),ListMap:s("ListMap"),mapBody:s("mapBody"),Filter:s("Filter"),predicate:s("predicate"),PartitionBy:s("PartitionBy"),partitionKey:s("partitionKey"),DistinctBy:s("DistinctBy"),distinctKey:s("distinctKey"),Partition:s("Partition"),key:s("key"),members:s("members"),AllStatements:s("AllStatements"),statementsOf:s("statementsOf"),StatementPredicate:s("StatementPredicate"),predicateOf:s("predicateOf"),StatementValue:s("StatementValue"),valueOf:s("valueOf"),DateFormat:s("DateFormat"),dateSource:s("dateSource"),dateFormat:s("dateFormat"),BinaryArithmetic:s("BinaryArithmetic"),arithLeft:s("arithLeft"),arithRight:s("arithRight"),Add:s("Add"),Subtract:s("Subtract"),Multiply:s("Multiply"),Divide:s("Divide"),Reverse:s("Reverse"),WindowedMap:s("WindowedMap"),windowSize:s("windowSize"),windowVar:s("windowVar"),windowBody:s("windowBody"),PairwiseMap:s("PairwiseMap"),firstVar:s("firstVar"),secondVar:s("secondVar"),pairBody:s("pairBody"),Scan:s("Scan"),initialState:s("initialState"),stateVar:s("stateVar"),elementVar:s("elementVar"),accumulate:s("accumulate"),ListItemAt:s("ListItemAt"),itemIndex:s("itemIndex"),BinaryComparison:s("BinaryComparison"),compareLeft:s("compareLeft"),compareRight:s("compareRight"),Equals:s("Equals"),GreaterThan:s("GreaterThan"),LessThan:s("LessThan"),GreaterThanOrEqual:s("GreaterThanOrEqual"),LessThanOrEqual:s("LessThanOrEqual"),Not:s("Not"),operand:s("operand"),BooleanLogic:s("BooleanLogic"),operands:s("operands"),And:s("And"),Or:s("Or"),Contains:s("Contains"),haystack:s("haystack"),needle:s("needle"),UnaryNumericOp:s("UnaryNumericOp"),value:s("value"),Abs:s("Abs"),Negate:s("Negate"),KindPredicate:s("KindPredicate"),IsReference:s("IsReference"),IsEmbedded:s("IsEmbedded"),IsList:s("IsList"),kindCheck:s("kindCheck"),IsString:s("IsString"),IsNumber:s("IsNumber"),IsBoolean:s("IsBoolean"),StatementObject:s("StatementObject"),statementSource:s("statementSource"),Let:s("Let"),letName:s("letName"),letValue:s("letValue"),letBody:s("letBody"),GetStatementByName:s("GetStatementByName"),inSubject:s("inSubject"),byName:s("byName"),RenderMarkdown:s("RenderMarkdown"),renderSource:s("renderSource"),renderProp:s("renderProp"),renderFormat:s("renderFormat"),RenderFormat:s("RenderFormat"),RENDER_HTML:s("render-html"),RENDER_MARKDOWN:s("render-markdown")};var y=class extends Error{constructor(n,r){super(`${n} (at ${r})`);this.path=r}path};function me(t,e){let n=t.name,r=mn(e),a={catalog:e,depth:0};if(f(t,o.InstanceTransformation))return nn(t,n,a,r);if(f(t,o.SetTransformation))return rn(t,n,a,r);throw new y("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function nn(t,e,n,r){return{kind:"instance",name:t.name,inputPattern:rt(t,e),rule:fe(t,o.rule,`${e}.rule`,n),artifactName:fe(t,o.artifactName,`${e}.artifactName`,n),outputs:at(t,`${e}.outputs`),overrides:it(t,`${e}.formatOverrides`,n),fragments:r}}function rn(t,e,n,r){let a=I(t,o.partitionBy);return{kind:"set",name:t.name,inputPattern:rt(t,e),rule:fe(t,o.rule,`${e}.rule`,n),artifactName:fe(t,o.artifactName,`${e}.artifactName`,n),outputs:at(t,`${e}.outputs`),overrides:it(t,`${e}.formatOverrides`,n),partitionBy:a,fragments:r}}function rt(t,e){let n=se(t,o.inputPattern);if(!n)throw new y("inputPattern is required",e);return an(n,`${e}.inputPattern`)}function an(t,e){let n=I(t,o.matchesClass);if(!n)throw new y("matchesClass is required",e);let r=[];for(let u of A(t,o.requires))if(u instanceof V)r.push(je(u.object.subject));else if(u instanceof S)for(let c of u.object)c instanceof b&&r.push(je(c.subject));let a=[],i=0;for(let u of A(t,o.sortBy))if(u instanceof S)for(let c of u.object)c instanceof C&&a.push(Qe(c,`${e}.sortBy[${i++}]`));else u instanceof T&&a.push(Qe(u.object,`${e}.sortBy[${i++}]`));return{matchesClass:n,requires:r,sortBy:a}}function Qe(t,e){let n=I(t,o.byProperty);if(!n)throw new y("SortKey.byProperty is required",e);let r=I(t,o.order);if(!r)throw new y("SortKey.order is required",e);if(E(r,o.ascending))return{byProperty:n,order:"ascending"};if(E(r,o.descending))return{byProperty:n,order:"descending"};throw new y(`SortKey.order must reference tx.ascending or tx.descending; got ${r.publisher}/${r.package_}/${r.name}`,e)}function fe(t,e,n,r){let a=se(t,e);if(!a)throw new y("expression is required",n);return J(a,n,r)}function J(t,e,n){if(f(t,o.StringLiteral))return{kind:"string-literal",value:j(t,o.stringLiteral,e)};if(f(t,o.IntegerLiteral))return{kind:"integer-literal",value:nt(t,o.integerLiteral,e)};if(f(t,o.DecimalLiteral))return{kind:"decimal-literal",value:nt(t,o.decimalLiteral,e)};if(f(t,o.BooleanLiteral))return{kind:"boolean-literal",value:yn(t,o.booleanLiteral,e)};if(f(t,o.VarRef))return{kind:"var-ref",varName:j(t,o.varName,e)};if(f(t,o.PropertyRead))return{kind:"property-read",source:d(t,o.readSource,`${e}.readSource`,n),readProp:q(t,o.readProp,e,"readProp")};if(f(t,o.Traverse))return{kind:"traverse",source:d(t,o.traverseSource,`${e}.traverseSource`,n),through:q(t,o.through,e,"through"),step:d(t,o.step,`${e}.step`,n)};if(f(t,o.BuildAstNode))return{kind:"build-ast-node",astClass:q(t,o.astClass,e,"astClass"),set:sn(t,`${e}.set`,n)};if(f(t,o.When))return{kind:"when",condition:d(t,o.condition,`${e}.condition`,n),thenBuild:d(t,o.thenBuild,`${e}.thenBuild`,n),elseBuild:on(t,o.elseBuild,`${e}.elseBuild`,n)};if(f(t,o.Concat))return{kind:"concat",parts:$e(t,o.parts,`${e}.parts`,n)};if(f(t,o.Fallback))return{kind:"fallback",primary:d(t,o.primary,`${e}.primary`,n),alternate:d(t,o.alternate,`${e}.alternate`,n)};if(f(t,o.UriName))return{kind:"uri-name",source:d(t,o.uriNameOf,`${e}.uriNameOf`,n)};if(f(t,o.UriPublisher))return{kind:"uri-publisher",source:d(t,o.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(f(t,o.UriPackage))return{kind:"uri-package",source:d(t,o.uriPackageOf,`${e}.uriPackageOf`,n)};if(f(t,o.UriVersion))return{kind:"uri-version",source:d(t,o.uriVersionOf,`${e}.uriVersionOf`,n)};if(f(t,o.SubjectUri))return{kind:"subject-uri",source:d(t,o.subjectOf,`${e}.subjectOf`,n)};if(f(t,o.UriLiteral))return{kind:"uri-literal",refTo:q(t,o.refTo,e,"refTo")};if(f(t,o.DisplayLabel))return{kind:"display-label",labelTarget:q(t,o.labelTarget,e,"labelTarget"),labelSource:q(t,o.labelSource,e,"labelSource")};if(f(t,o.ResolveRef))return{kind:"resolve-ref",source:d(t,o.resolveSource,`${e}.resolveSource`,n)};if(f(t,o.Normalize))return{kind:"normalize",source:d(t,o.normSource,`${e}.normSource`,n),normKind:un(t,e)};if(f(t,o.RenderMarkdown))return{kind:"render-markdown",source:d(t,o.renderSource,`${e}.renderSource`,n),readProp:q(t,o.renderProp,e,"renderProp"),format:cn(t,e)};if(f(t,o.IsSet))return{kind:"is-set",check:d(t,o.checkExpr,`${e}.checkExpr`,n)};if(f(t,o.CallFragment))return dn(t,e,n);if(f(t,o.Join))return{kind:"join",source:d(t,o.source,`${e}.source`,n),separator:j(t,o.separator,e)};if(f(t,o.Count))return{kind:"count",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Sum))return{kind:"sum",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Min))return{kind:"min",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Max))return{kind:"max",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.Average))return{kind:"average",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.ForEach))return{kind:"for-each",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),emit:d(t,o.emit,`${e}.emit`,n)};if(f(t,o.ListMap))return{kind:"list-map",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),mapBody:d(t,o.mapBody,`${e}.mapBody`,n)};if(f(t,o.Filter))return{kind:"filter",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),predicate:d(t,o.predicate,`${e}.predicate`,n)};if(f(t,o.PartitionBy))return{kind:"partition-by",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),partitionKey:d(t,o.partitionKey,`${e}.partitionKey`,n)};if(f(t,o.DistinctBy))return{kind:"distinct-by",source:d(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),distinctKey:d(t,o.distinctKey,`${e}.distinctKey`,n)};if(f(t,o.AllStatements))return{kind:"all-statements",source:d(t,o.statementsOf,`${e}.statementsOf`,n)};if(f(t,o.StatementPredicate))return{kind:"statement-predicate",source:d(t,o.predicateOf,`${e}.predicateOf`,n)};if(f(t,o.StatementValue))return{kind:"statement-value",source:d(t,o.valueOf,`${e}.valueOf`,n)};if(f(t,o.DateFormat))return{kind:"date-format",source:d(t,o.dateSource,`${e}.dateSource`,n),format:ln(t,e)};if(f(t,o.Add))return{kind:"add",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Subtract))return{kind:"subtract",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Multiply))return{kind:"multiply",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Divide))return{kind:"divide",left:d(t,o.arithLeft,`${e}.arithLeft`,n),right:d(t,o.arithRight,`${e}.arithRight`,n)};if(f(t,o.Reverse))return{kind:"reverse",source:d(t,o.source,`${e}.source`,n)};if(f(t,o.WindowedMap)){let r=ot(t,o.windowSize);if(r===void 0||!Number.isInteger(r)||r<1)throw new y("windowSize must be a positive integer",`${e}.windowSize`);return{kind:"windowed-map",source:d(t,o.source,`${e}.source`,n),windowSize:r,windowVar:j(t,o.windowVar,e),windowBody:d(t,o.windowBody,`${e}.windowBody`,n)}}if(f(t,o.PairwiseMap))return{kind:"pairwise-map",source:d(t,o.source,`${e}.source`,n),firstVar:j(t,o.firstVar,e),secondVar:j(t,o.secondVar,e),pairBody:d(t,o.pairBody,`${e}.pairBody`,n)};if(f(t,o.Scan))return{kind:"scan",source:d(t,o.source,`${e}.source`,n),initialState:d(t,o.initialState,`${e}.initialState`,n),stateVar:j(t,o.stateVar,e),elementVar:j(t,o.elementVar,e),accumulate:d(t,o.accumulate,`${e}.accumulate`,n)};if(f(t,o.ListItemAt))return{kind:"list-item-at",source:d(t,o.source,`${e}.source`,n),itemIndex:d(t,o.itemIndex,`${e}.itemIndex`,n)};if(f(t,o.Equals))return{kind:"equals",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.GreaterThan))return{kind:"greater-than",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.LessThan))return{kind:"less-than",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.LessThanOrEqual))return{kind:"less-than-or-equal",left:d(t,o.compareLeft,`${e}.compareLeft`,n),right:d(t,o.compareRight,`${e}.compareRight`,n)};if(f(t,o.Not))return{kind:"not",operand:d(t,o.operand,`${e}.operand`,n)};if(f(t,o.And))return{kind:"and",operands:$e(t,o.operands,`${e}.operands`,n)};if(f(t,o.Or))return{kind:"or",operands:$e(t,o.operands,`${e}.operands`,n)};if(f(t,o.Contains))return{kind:"contains",haystack:d(t,o.haystack,`${e}.haystack`,n),needle:d(t,o.needle,`${e}.needle`,n)};if(f(t,o.Abs))return{kind:"abs",value:d(t,o.value,`${e}.value`,n)};if(f(t,o.Negate))return{kind:"negate",value:d(t,o.value,`${e}.value`,n)};if(f(t,o.IsReference))return{kind:"is-reference",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsEmbedded))return{kind:"is-embedded",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsList))return{kind:"is-list",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsString))return{kind:"is-string",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsNumber))return{kind:"is-number",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.IsBoolean))return{kind:"is-boolean",check:d(t,o.kindCheck,`${e}.kindCheck`,n)};if(f(t,o.StatementObject))return{kind:"statement-object",source:d(t,o.statementSource,`${e}.statementSource`,n)};if(f(t,o.Let))return{kind:"let",bindName:j(t,o.letName,e),bindValue:d(t,o.letValue,`${e}.letValue`,n),body:d(t,o.letBody,`${e}.letBody`,n)};if(f(t,o.GetStatementByName))return{kind:"get-statement-by-name",inSubject:d(t,o.inSubject,`${e}.inSubject`,n),byName:d(t,o.byName,`${e}.byName`,n)};throw new y("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}function d(t,e,n,r){let a=se(t,e);if(!a)throw new y("child expression is required",n);return J(a,n,r)}function on(t,e,n,r){let a=se(t,e);if(a)return J(a,n,r)}function $e(t,e,n,r){let a=[],i=0;for(let u of A(t,e))if(u instanceof S)for(let c of u.object)c instanceof C&&a.push(J(c,`${n}[${i++}]`,r));else u instanceof T&&a.push(J(u.object,`${n}[${i++}]`,r));return a}function sn(t,e,n){let r=[],a=0;for(let i of A(t,o.set))if(i instanceof S)for(let u of i.object)u instanceof C&&r.push(xe(u,`${e}[${a++}]`,n));else i instanceof T&&r.push(xe(i.object,`${e}[${a++}]`,n));return r}function xe(t,e,n){return{field:q(t,o.field,e,"field"),value:d(t,o.bindValue,`${e}.bindValue`,n)}}function un(t,e){let n=I(t,o.normKind);if(!n)throw new y("normKind is required",e);if(E(n,o.NORM_TRIM_END))return"trim-end";throw new y(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function cn(t,e){let n=I(t,o.renderFormat);if(!n)throw new y("renderFormat is required",e);if(E(n,o.RENDER_HTML))return"html";if(E(n,o.RENDER_MARKDOWN))return"markdown";throw new y(`Unknown RenderFormat: ${n.publisher}/${n.package_}/${n.name}`,e)}var et=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function ln(t,e){let n=G(t,o.dateFormat);if(!n)throw new y("dateFormat is required",e);if(!et.has(n))throw new y(`Unknown dateFormat "${n}"; supported: ${[...et].join(", ")}`,e);return n}function dn(t,e,n){let r=I(t,o.fragmentRef);if(!r)throw new y("fragmentRef is required",e);if(!pn(n.catalog,r))throw new y(`ExpressionFragment not found: ${r.publisher}/${r.package_}/${r.name}`,e);return{kind:"call-fragment",fragmentKey:fn(r)}}function fn(t){return`${t.publisher}/${t.package_}/${t.name}`}function mn(t){let e=new Map,n=[];for(let r of t){if(!(r instanceof w)||!f(r,o.ExpressionFragment))continue;let a=se(r,o.body);if(!a)continue;let i=(r.namespace||"").split("@")[0]||"",u=i.indexOf("/");if(u<0)continue;let c=i.substring(0,u),l=i.substring(u+1),m=`${c}/${l}/${r.name}`;n.push({key:m,subject:r,bodyEmb:a,pubPkgName:`${i}/${r.name}`})}for(let r of n){let a=J(r.bodyEmb,`fragment(${r.pubPkgName})`,{catalog:t,depth:0});e.set(r.key,a)}return e}function pn(t,e){for(let n of t)if(!(!(n instanceof w)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&f(n,o.ExpressionFragment))return n}function at(t,e){let n=new Set;for(let r of A(t,o.outputs))if(r instanceof V)n.add(r.object.subject.name);else if(r instanceof S)for(let a of r.object)a instanceof b&&n.add(a.subject.name);if(n.size===0)throw new y("outputs is required (at least one OutputFormat)",e);return n}function it(t,e,n){let r=new Map,a=0;for(let i of A(t,o.formatOverrides))if(i instanceof S){for(let u of i.object)if(u instanceof C){let[c,l]=tt(u,`${e}[${a++}]`);r.set(c,l)}}else if(i instanceof T){let[u,c]=tt(i.object,`${e}[${a++}]`);r.set(u,c)}return r}function tt(t,e){let n=I(t,o.formatTarget);if(!n)throw new y("formatTarget is required",e);let r=[];for(let c of A(t,o.metadataKeys))if(c instanceof B)r.push(c.object);else if(c instanceof S)for(let l of c.object){let m=l.value;typeof m=="string"&&r.push(m)}let a=new Map;for(let c of A(t,o.metadataRenames))if(c instanceof S){for(let l of c.object)if(l instanceof C){let m=G(l,o.fromKey),g=G(l,o.toKey);m&&g&&a.set(m,g)}}else if(c instanceof T){let l=c.object,m=G(l,o.fromKey),g=G(l,o.toKey);m&&g&&a.set(m,g)}let i=ve(t,o.trailingNewline),u=ve(t,o.omitWrapper);return[n.name,{metadataKeys:r.length>0?r:void 0,metadataRenames:a,trailingNewline:i,omitWrapper:u}]}function gn(t){return t.predicate?.subject}function A(t,e){let n=[];for(let r of t.statement){let a=gn(r);a&&E(a,e)&&n.push(r)}return n}function se(t,e){for(let n of A(t,e))if(n instanceof T)return n.object}function I(t,e){for(let n of A(t,e))if(n instanceof V)return je(n.object.subject)}function G(t,e){for(let n of A(t,e))if(n instanceof B)return n.object}function ot(t,e){for(let n of A(t,e))if(n instanceof U)return n.object}function ve(t,e){for(let n of A(t,e))if(n instanceof O)return n.object}function j(t,e,n){let r=G(t,e);if(r===void 0)throw new y(`${e.name} (string) is required`,n);return r}function nt(t,e,n){let r=ot(t,e);if(r===void 0)throw new y(`${e.name} (number) is required`,n);return r}function yn(t,e,n){let r=ve(t,e);if(r===void 0)throw new y(`${e.name} (boolean) is required`,n);return r}function q(t,e,n,r){let a=I(t,e);if(!a)throw new y(`${r} (URI reference) is required`,n);return a}function je(t){return{publisher:t.publisher,package_:t.package_,name:t.name}}var kn={publisher:"kanonak.org",package_:"core-rdf",name:"label"},_=class extends Error{},ge=class{constructor(e,n,r=new Map){this.resolver=e;this.catalog=n;this.fragments=r}resolver;catalog;fragments;async evaluate(e,n){switch(e.kind){case"string-literal":return e.value;case"integer-literal":return e.value;case"decimal-literal":return e.value;case"boolean-literal":return e.value;case"uri-literal":return{...e.refTo};case"var-ref":{if(!n.has(e.varName))throw new _(`Unbound variable "${e.varName}"`);return n.get(e.varName)}case"concat":{let r=[];for(let a of e.parts){let i=await this.evaluate(a,n);if(i!=null)if(Array.isArray(i))for(let u of i)r.push(u);else r.push(i)}return r}case"fallback":{let r=await this.evaluate(e.primary,n);return st(r)?r:this.evaluate(e.alternate,n)}case"when":return await this.evaluate(e.condition,n)===!0?this.evaluate(e.thenBuild,n):e.elseBuild?this.evaluate(e.elseBuild,n):void 0;case"is-set":{let r=await this.evaluate(e.check,n);return st(r)}case"property-read":{let r=await this.evaluate(e.source,n);return pe(r,e.readProp)}case"traverse":{let r=await this.evaluate(e.source,n);if(!(r instanceof K))return;let a=bn(r,e.through),i=[];for(let u of a){let c=await this.resolver.resolveSubject(u,this.catalog);if(!c)continue;let l=new Map(n);l.set("input",c);let m=await this.evaluate(e.step,l);m!=null&&i.push(ue(m))}return i.join("")}case"uri-name":{let r=await this.evaluate(e.source,n);return X(r)?r.name:r instanceof b?r.subject.name:r instanceof w?r.name:r instanceof C?r.name??"":void 0}case"uri-publisher":{let r=await this.evaluate(e.source,n);return Ve(r)?.publisher}case"uri-package":{let r=await this.evaluate(e.source,n);return Ve(r)?.package_}case"uri-version":{let r=await this.evaluate(e.source,n);return Ve(r)?.version}case"subject-uri":{let r=await this.evaluate(e.source,n);if(r instanceof w){let a=r.namespace??"",i=r.name??"";return!a||!i?void 0:`${a}/${i}`}if(r instanceof b){let a=r.subject,i=a.version;return i&&typeof i.major=="number"?`${a.publisher}/${a.package_}@${i.major}.${i.minor}.${i.patch}/${a.name}`:`${a.publisher}/${a.package_}/${a.name}`}return}case"display-label":{let r=await this.resolver.resolveSubject({...e.labelTarget},this.catalog);return r?pe(r,e.labelSource):void 0}case"resolve-ref":{let r=await this.evaluate(e.source,n);return r instanceof w?r:r instanceof b?await this.resolver.resolveSubject(r.subject,this.catalog):X(r)?await this.resolver.resolveSubject(r,this.catalog):void 0}case"normalize":{let r=await this.evaluate(e.source,n),a=r==null?"":ue(r);return e.normKind==="trim-end"?a.replace(/[\s\r\n]+$/u,""):a}case"render-markdown":{let r=await this.evaluate(e.source,n);if(!(r instanceof K))return;let a;for(let u of r.statement){let c=De(u);if(c&&E(c,e.readProp)){a=u;break}}if(!(a instanceof Ue)){let u=pe(r,e.readProp);return u==null?void 0:ue(u)}let i=await this.renderMarkdownLinks(a);return e.format==="html"?x(i):i}case"build-ast-node":{let r={kind:e.astClass.name};for(let a of e.set){let i=await this.evaluate(a.value,n);if(i==null||Array.isArray(i)&&i.length===0)continue;let u=a.field.name;Sn.has(u)&&(Array.isArray(i)&&i.every(c=>ut(c))?i=i.map(c=>String(c)).join(""):ut(i)&&(i=String(i))),r[u]=i}return r}case"call-fragment":{let r=this.fragments.get(e.fragmentKey);if(!r)throw new _(`ExpressionFragment ${e.fragmentKey} not found in registry`);return this.evaluate(r,n)}case"join":return(await this.evaluateList(e.source,n)).map(a=>a==null?"":ue(a)).join(e.separator);case"count":return(await this.evaluateList(e.source,n)).length;case"sum":{let r=await this.evaluateList(e.source,n),a=0;for(let i of r)a+=$(i,"Sum");return a}case"min":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new _("Min on an empty list is undefined; guard with IsSet");let a=$(r[0],"Min");for(let i=1;i<r.length;i++){let u=$(r[i],"Min");u<a&&(a=u)}return a}case"max":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new _("Max on an empty list is undefined; guard with IsSet");let a=$(r[0],"Max");for(let i=1;i<r.length;i++){let u=$(r[i],"Max");u>a&&(a=u)}return a}case"average":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new _("Average on an empty list is undefined; guard with IsSet");let a=0;for(let i of r)a+=$(i,"Average");return a/r.length}case"for-each":{let r=await this.evaluateList(e.source,n),a=[];for(let i of r){let u=new Map(n);u.set(e.loopVar,L(i));let c=await this.evaluate(e.emit,u);if(c!=null)if(Array.isArray(c))for(let l of c)a.push(l);else a.push(c)}return a}case"list-map":{let r=await this.evaluateList(e.source,n),a=[];for(let i of r){let u=new Map(n);u.set(e.loopVar,L(i)),a.push(await this.evaluate(e.mapBody,u))}return a}case"filter":{let r=await this.evaluateList(e.source,n),a=[];for(let i of r){let u=new Map(n);u.set(e.loopVar,L(i)),await this.evaluate(e.predicate,u)===!0&&a.push(i)}return a}case"partition-by":{let r=await this.evaluateList(e.source,n),a=new Map,i=[];for(let u of r){let c=new Map(n);c.set(e.loopVar,L(u));let l=await this.evaluate(e.partitionKey,c),m=dt(l),g=a.get(m);g||(g={kind:"Partition",key:l,members:[]},a.set(m,g),i.push(m)),g.members.push(u)}return i.map(u=>a.get(u))}case"distinct-by":{let r=await this.evaluateList(e.source,n),a=new Set,i=[];for(let u of r){let c=new Map(n);c.set(e.loopVar,L(u));let l=await this.evaluate(e.distinctKey,c),m=dt(l);a.has(m)||(a.add(m),i.push(u))}return i}case"all-statements":{let r=await this.evaluate(e.source,n);return r instanceof K?r.statement:[]}case"statement-predicate":{let r=await this.evaluate(e.source,n);if(Ae(r)){let a=r.predicate;if(a instanceof b)return a}return}case"statement-value":{let r=await this.evaluate(e.source,n);return Ae(r)?vn(r):void 0}case"date-format":{let r=await this.evaluate(e.source,n),a=r==null?"":ue(r);return a?$n(a,e.format):""}case"add":{let r=$(await this.evaluate(e.left,n),"Add"),a=$(await this.evaluate(e.right,n),"Add");return r+a}case"subtract":{let r=$(await this.evaluate(e.left,n),"Subtract"),a=$(await this.evaluate(e.right,n),"Subtract");return r-a}case"multiply":{let r=$(await this.evaluate(e.left,n),"Multiply"),a=$(await this.evaluate(e.right,n),"Multiply");return r*a}case"divide":{let r=$(await this.evaluate(e.left,n),"Divide"),a=$(await this.evaluate(e.right,n),"Divide");if(a===0)throw new _("Divide by zero; guard with When");return r/a}case"reverse":{if(e.source.kind==="reverse")return this.evaluate(e.source.source,n);let r=await this.evaluateReverseIterator(e.source,n);return r!==void 0?r:[...await this.evaluateList(e.source,n)].reverse()}case"windowed-map":{let r=await this.evaluateList(e.source,n);if(r.length<e.windowSize)return[];let a=[];for(let i=0;i+e.windowSize<=r.length;i++){let u=r.slice(i,i+e.windowSize),c=new Map(n);c.set(e.windowVar,u);let l=await this.evaluate(e.windowBody,c);if(l!=null)if(Array.isArray(l))for(let m of l)a.push(m);else a.push(l)}return a}case"pairwise-map":{let r=await this.evaluateList(e.source,n);if(r.length<2)return[];let a=[];for(let i=0;i+1<r.length;i++){let u=new Map(n);u.set(e.firstVar,L(r[i])),u.set(e.secondVar,L(r[i+1]));let c=await this.evaluate(e.pairBody,u);if(c!=null)if(Array.isArray(c))for(let l of c)a.push(l);else a.push(c)}return a}case"scan":{let r=await this.evaluateList(e.source,n);if(r.length===0)return[];let a=await this.evaluate(e.initialState,n),i=[];for(let u of r){let c=new Map(n);c.set(e.stateVar,a),c.set(e.elementVar,L(u));let l=await this.evaluate(e.accumulate,c);i.push(l),a=l}return i}case"list-item-at":{let r=await this.evaluateList(e.source,n),a=await this.evaluate(e.itemIndex,n);return typeof a!="number"||!Number.isInteger(a)||a<0||a>=r.length?void 0:r[a]}case"equals":{let r=await this.evaluate(e.left,n),a=await this.evaluate(e.right,n);return ct(r,a)}case"greater-than":{let r=await this.evaluate(e.left,n),a=await this.evaluate(e.right,n);return typeof r!="number"||typeof a!="number"?!1:r>a}case"less-than":{let r=await this.evaluate(e.left,n),a=await this.evaluate(e.right,n);return typeof r!="number"||typeof a!="number"?!1:r<a}case"greater-than-or-equal":{let r=await this.evaluate(e.left,n),a=await this.evaluate(e.right,n);return typeof r!="number"||typeof a!="number"?!1:r>=a}case"less-than-or-equal":{let r=await this.evaluate(e.left,n),a=await this.evaluate(e.right,n);return typeof r!="number"||typeof a!="number"?!1:r<=a}case"not":{let r=await this.evaluate(e.operand,n);return r===!0?!1:r===!1?!0:void 0}case"and":{for(let r of e.operands)if(await this.evaluate(r,n)!==!0)return!1;return!0}case"or":{for(let r of e.operands)if(await this.evaluate(r,n)===!0)return!0;return!1}case"contains":{let r=await this.evaluateList(e.haystack,n),a=await this.evaluate(e.needle,n);for(let i of r)if(ct(i,a))return!0;return!1}case"abs":{let r=$(await this.evaluate(e.value,n),"Abs");return Math.abs(r)}case"negate":return-$(await this.evaluate(e.value,n),"Negate");case"is-reference":{let r=await this.evaluate(e.check,n);return r instanceof b||r instanceof w}case"is-embedded":return await this.evaluate(e.check,n)instanceof C;case"is-list":{let r=await this.evaluate(e.check,n);return Array.isArray(r)}case"is-string":return typeof await this.evaluate(e.check,n)=="string";case"is-number":return typeof await this.evaluate(e.check,n)=="number";case"is-boolean":return typeof await this.evaluate(e.check,n)=="boolean";case"statement-object":{let r=await this.evaluate(e.source,n);if(!Ae(r))return;let a=r;return a instanceof B||a instanceof U||a instanceof O||a instanceof V||a instanceof T||a instanceof S?a.object:void 0}case"let":{let r=await this.evaluate(e.bindValue,n),a=new Map(n);return a.set(e.bindName,r),this.evaluate(e.body,a)}case"get-statement-by-name":{let r=await this.evaluate(e.inSubject,n),a=await this.evaluate(e.byName,n);if(!(r instanceof K)||typeof a!="string")return;for(let i of r.statement)if(i.predicate?.subject?.name===a)return i;return}default:{let r=e;throw new _("Unknown expression kind")}}}async renderMarkdownLinks(e){let n=e.object,r="",a=0;for(let i of e.links){if(r+=n.slice(a,i.startOffset),i.target){let u=i.target.subject,c=i.displayText??await this.resolveLabel(u)??u.name;r+=`[${c}](${F(u)})`}else r+=i.displayText??i.reference;a=i.endOffset}return r+=n.slice(a),r}async resolveLabel(e){let n=await this.resolver.resolveSubject(e,this.catalog);if(!n)return;let r=pe(n,kn);return typeof r=="string"?r:void 0}async evaluateList(e,n){let r=await this.evaluate(e,n);return r==null?[]:Array.isArray(r)?r:[r]}async evaluateReverseIterator(e,n){if(e.kind==="pairwise-map"){let r=await this.evaluateList(e.source,n);if(r.length<2)return[];let a=[];for(let i=r.length-1;i>=1;i--){let u=new Map(n);u.set(e.firstVar,L(r[i-1])),u.set(e.secondVar,L(r[i]));let c=await this.evaluate(e.pairBody,u);if(c!=null)if(Array.isArray(c))for(let l of c)a.push(l);else a.push(c)}return a}if(e.kind==="for-each"){let r=await this.evaluateList(e.source,n),a=[];for(let i=r.length-1;i>=0;i--){let u=new Map(n);u.set(e.loopVar,L(r[i]));let c=await this.evaluate(e.emit,u);if(c!=null)if(Array.isArray(c))for(let l of c)a.push(l);else a.push(c)}return a}if(e.kind==="list-map"){let r=await this.evaluateList(e.source,n),a=[];for(let i=r.length-1;i>=0;i--){let u=new Map(n);u.set(e.loopVar,L(r[i])),a.push(await this.evaluate(e.mapBody,u))}return a}if(e.kind==="windowed-map"){let r=await this.evaluateList(e.source,n);if(r.length<e.windowSize)return[];let a=[];for(let i=r.length-e.windowSize;i>=0;i--){let u=r.slice(i,i+e.windowSize),c=new Map(n);c.set(e.windowVar,u);let l=await this.evaluate(e.windowBody,c);if(l!=null)if(Array.isArray(l))for(let m of l)a.push(m);else a.push(l)}return a}}};function pe(t,e){if(t instanceof K)return hn(t,e);if(wn(t))return E(e,o.key)?t.key:E(e,o.members)?t.members:void 0}function hn(t,e){for(let n of t.statement){let r=De(n);if(!(!r||!E(r,e))&&(n instanceof B||n instanceof U||n instanceof O||n instanceof V||n instanceof T||n instanceof S))return n.object}}function bn(t,e){let n=[];for(let r of t.statement){let a=De(r);if(!(!a||!E(a,e))){if(r instanceof V)n.push(r.object.subject);else if(r instanceof S)for(let i of r.object)i instanceof b&&n.push(i.subject)}}return n}function De(t){return t.predicate?.subject}function ue(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(t instanceof K)return t.name??"";if(t instanceof b)return t.subject.name;if(X(t))return t.name;let e=t.value;return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function L(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof K)&&!(t instanceof b)&&!(t instanceof C)&&"value"in t?t.value:t}function st(t){return t==null?!1:typeof t=="string"||Array.isArray(t)?t.length>0:typeof t=="boolean"?t===!0:!0}function X(t){return typeof t=="object"&&t!==null&&typeof t.publisher=="string"&&typeof t.package_=="string"&&typeof t.name=="string"}function wn(t){return typeof t=="object"&&t!==null&&t.kind==="Partition"&&Array.isArray(t.members)}function $(t,e){if(typeof t=="number"&&Number.isFinite(t))return t;throw new _(`${e} requires numeric elements; got ${En(t)}`)}function Ve(t){if(t instanceof w){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);return n<0||r<0?void 0:{publisher:e.substring(0,n),package_:e.substring(n+1,r),version:e.substring(r+1),name:t.name??""}}if(t instanceof b){let e=t.subject,n=e.version;return{publisher:e.publisher,package_:e.package_,version:n&&typeof n.major=="number"?`${n.major}.${n.minor}.${n.patch}`:"",name:e.name}}if(X(t))return{publisher:t.publisher,package_:t.package_,version:"",name:t.name}}var Sn=new Set(["stringValue","text","rawContent","key","propertyKey","linkLabel"]);function ut(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function En(t){return t===void 0?"undefined":t===null?"null":Array.isArray(t)?`array(${t.length})`:typeof t}function $n(t,e){let n=new Date(t);if(isNaN(n.getTime()))return"";let r=n.getUTCFullYear(),a=["January","February","March","April","May","June","July","August","September","October","November","December"][n.getUTCMonth()],i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getUTCMonth()],u=n.getUTCDate(),c=(l,m=2)=>String(l).padStart(m,"0");switch(e){case"iso-date":return`${r}-${c(n.getUTCMonth()+1)}-${c(u)}`;case"iso-datetime":return`${r}-${c(n.getUTCMonth()+1)}-${c(u)}T${c(n.getUTCHours())}:${c(n.getUTCMinutes())}:${c(n.getUTCSeconds())}Z`;case"short-date":return`${i} ${u}`;case"long-date":return`${a} ${u}, ${r}`;case"year":return String(r);case"month-year":return`${a} ${r}`}}function ct(t,e){if(t==null||e===void 0||e===null)return!1;if(t===e)return!0;let n=typeof t=="object"&&"value"in t?t.value:void 0,r=typeof e=="object"&&"value"in e?e.value:void 0,a=n??t,i=r??e,u=lt(t),c=lt(e);return u&&c?u.publisher===c.publisher&&u.package_===c.package_&&u.name===c.name:typeof a=="string"&&typeof i=="string"||typeof a=="number"&&typeof i=="number"||typeof a=="boolean"&&typeof i=="boolean"?a===i:!1}function lt(t){if(t instanceof b){let e=t.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}if(t instanceof w){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);if(n<0)return;let a=e.substring(0,n),i=r>=0?e.substring(n+1,r):e.substring(n+1);return{publisher:a,package_:i,name:t.name??""}}if(X(t))return{publisher:t.publisher,package_:t.package_,name:t.name}}function Ae(t){return t instanceof B||t instanceof U||t instanceof O||t instanceof V||t instanceof T||t instanceof S}function vn(t){return t instanceof B||t instanceof U||t instanceof O?String(t.object??""):t instanceof V?t.object?.subject?.name??"":t instanceof T?"[embedded]":t instanceof S?(t.object??[]).map(n=>{if(n instanceof b)return n.subject.name;let r=n.name;if(r&&r.length>0)return r;let a=n.value;return typeof a=="string"||typeof a=="number"||typeof a=="boolean"?String(a):"[embedded]"}).join(", "):""}function dt(t){if(t===void 0)return"\0undef";if(t===null)return"\0null";if(typeof t=="string")return`s:${t}`;if(typeof t=="number")return`n:${t}`;if(typeof t=="boolean")return`b:${t}`;if(t instanceof b){let e=t.subject;return`r:${e.publisher}/${e.package_}/${e.name}`}if(t instanceof K){let e=t.name??"";return`k:${t.namespace??""}/${e}`}return X(t)?`u:${t.publisher}/${t.package_}/${t.name}`:`o:${JSON.stringify(t)}`}var jn={"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"}},W=class extends Error{},ye=class{backends=new Map;constructor(){this.register(new Y),this.register(new Z),this.register(new Q),this.register(new ee),this.register(new te),this.register(new ne),this.register(new re),this.register(new ie)}register(e){this.backends.set(e.backendUri,e)}async run(e){let n=e.transformationKanonaks??e.allKanonaks,r=me(e.transformation,n);if(!r.outputs.has(e.outputFormat))throw new W(`Transformation "${r.name}" does not declare output format "${e.outputFormat}". Declared: ${Array.from(r.outputs).join(", ")}`);let a=this.findBackend(e.outputFormat);if(!a)throw new W(`No backend registered for OutputFormat "${e.outputFormat}".`);let i=new oe(e.repository,e.parser,e.objectParser),u=new ge(i,e.allKanonaks,r.fragments);return r.kind==="instance"?this.runInstance(r,e,a,u):this.runSet(r,e,a,u)}async runInstance(e,n,r,a){let i=ft(n.instances,e.inputPattern.requires),u=mt(i,e.inputPattern.sortBy),c=[];for(let l of u){let m=new Map;m.set("input",l);let g=await a.evaluate(e.rule,m);Ke(g,e.name,`input "${l.name}"`);let k=Te(await a.evaluate(e.artifactName,m),e.name,`input "${l.name}"`),D=Le(e.overrides.get(n.outputFormat),n.runtimeOverride),v=r.render(g,D);c.push({fileName:k,format:n.outputFormat,content:v,source:{kind:"instance",sourceName:l.name}})}return c}async runSet(e,n,r,a){let i=ft(n.instances,e.inputPattern.requires),u=mt(i,e.inputPattern.sortBy);return e.partitionBy?this.runSetWithPartition(e,u,n,r,a):this.runSetSingle(e,u,n,r,a)}async runSetSingle(e,n,r,a,i){let u=new Map;u.set("inputs",n);let c=await i.evaluate(e.rule,u);Ke(c,e.name,"set");let l=Te(await i.evaluate(e.artifactName,u),e.name,"set"),m=Le(e.overrides.get(r.outputFormat),r.runtimeOverride),g=a.render(c,m);return[{fileName:l,format:r.outputFormat,content:g,source:{kind:"set",memberCount:n.length}}]}async runSetWithPartition(e,n,r,a,i){let u=e.partitionBy,c=new Map,l=[];for(let g of n){let k=Dn(g,u);if(k==null)continue;let D=Kn(k),v=c.get(D);v||(v={keyValue:k,keyDisplay:Tn(k),members:[]},c.set(D,v),l.push(D)),v.members.push(g)}let m=[];for(let g of l){let k=c.get(g),D=new Map;D.set("inputs",k.members),D.set("key",k.keyValue);let v=await i.evaluate(e.rule,D);Ke(v,e.name,`partition "${k.keyDisplay}"`);let kt=Te(await i.evaluate(e.artifactName,D),e.name,`partition "${k.keyDisplay}"`),ht=Le(e.overrides.get(r.outputFormat),r.runtimeOverride),bt=a.render(v,ht);m.push({fileName:kt,format:r.outputFormat,content:bt,source:{kind:"set",memberCount:k.members.length,partitionKey:k.keyDisplay}})}return m}findBackend(e){let n=jn[e];if(n)return this.backends.get(n.formatUri)}};function ft(t,e){return e.length===0?t:t.filter(n=>{for(let r of e)if(!An(n,r))return!1;return!0})}function mt(t,e){if(e.length===0)return t;let n=[...t];return n.sort((r,a)=>{for(let i of e){let u=pt(r,i.byProperty),c=pt(a,i.byProperty),l=Vn(u,c,i.order);if(l!==0)return l}return 0}),n}function pt(t,e){for(let n of t.statement){let r=Be(n);if(!(!r||!E(r,e))){if(n instanceof B||n instanceof U||n instanceof O)return n.object;if(n instanceof S)throw new W(`Sort property "${e.name}" on instance "${t.name??"?"}" resolves to a list \u2014 list-typed properties are not sortable. Use a scalar property.`);if(n instanceof V)throw new W(`Sort property "${e.name}" on instance "${t.name??"?"}" resolves to a reference \u2014 reference-typed properties don't have a natural total order. Use a scalar property.`)}}}function Vn(t,e,n){if(t===void 0&&e===void 0)return 0;if(t===void 0)return n==="ascending"?1:-1;if(e===void 0)return n==="ascending"?-1:1;let r;return typeof t=="number"&&typeof e=="number"?r=t-e:r=String(t).localeCompare(String(e)),n==="ascending"?r:-r}function An(t,e){for(let n of t.statement){let r=Be(n);if(!r||!E(r,e))continue;let a=n.object;if(a!=null&&!(typeof a=="string"&&a.length===0)&&!(Array.isArray(a)&&a.length===0))return!0}return!1}function Dn(t,e){for(let n of t.statement){let r=Be(n);if(!(!r||!E(r,e))&&(n instanceof B||n instanceof U||n instanceof O||n instanceof V||n instanceof S))return n.object}}function Be(t){return t.predicate?.subject}function Kn(t){if(t===void 0)return" undef";if(t===null)return" null";if(typeof t=="string")return`s:${t}`;if(typeof t=="number")return`n:${t}`;if(typeof t=="boolean")return`b:${t}`;if(t instanceof b){let e=t.subject;return`r:${e.publisher}/${e.package_}/${e.name}`}if(t instanceof K){let e=t.name??"";return`k:${t.namespace??""}/${e}`}if(typeof t=="object"&&t!==null&&typeof t.name=="string"&&typeof t.publisher=="string"){let e=t;return`u:${e.publisher}/${e.package_}/${e.name}`}return`o:${JSON.stringify(t)}`}function Tn(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):t instanceof b?t.subject.name:t instanceof K?t.name??"":typeof t=="object"&&t!==null&&typeof t.name=="string"?t.name:""}function Ke(t,e,n){if(typeof t!="object"||t===null||t.kind!=="Document")throw new W(`Transformation "${e}" rule did not yield a Document for ${n}. Got: ${gt(t)}`)}function Te(t,e,n){if(typeof t=="string")return t;if(Array.isArray(t)&&t.every(Ln))return t.map(r=>String(r)).join("");throw new W(`Transformation "${e}" artifactName did not yield a string for ${n}. Got: ${gt(t)}`)}function Ln(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function gt(t){if(t===void 0)return"undefined";if(t===null)return"null";if(Array.isArray(t))return`array(${t.length})`;if(typeof t=="object"){let e=t.kind;return e?`object(kind=${e})`:"object"}return typeof t}function Le(t,e){if(!t&&!e)return;let n={metadataRenames:e?.metadataRenames??t?.metadataRenames??new Map},r=e?.metadataKeys??t?.metadataKeys;r!==void 0&&(n.metadataKeys=r);let a=e?.trailingNewline??t?.trailingNewline;a!==void 0&&(n.trailingNewline=a);let i=e?.omitWrapper??t?.omitWrapper;return i!==void 0&&(n.omitWrapper=i),n}var R=class extends Error{constructor(n,r){super(n);this.cause=r;this.name="RenderError"}cause},yt={publisher:"kanonak.org",package_:"derivation",name:"default"},Re=class{constructor(e,n=new Ce,r=new Oe){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;runner=new ye;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async renderViaLook(e){let n=await this.getCatalog(),r=M(n,e.resource);if(!(r instanceof w))throw new R(`Resource not found: ${P(e.resource)}`);let a=new ke(n),i;if(e.format.name==="html")i=a.renderHtml(r);else if(e.format.name==="stylesheet")i=a.renderStylesheet(r);else throw new R(`LookRenderer does not support format ${P(e.format)} \u2014 only formats.html and formats.stylesheet are implemented in v0.1.`);return{content:i,format:e.format,filename:r.name}}async findDerivation(e){let n=await this.getCatalog(),r=M(n,e.resource);if(!(r instanceof w))return;let a=e.variant??yt;return _e(r,e.format,a,n)}async render(e){if(e.format.name==="html"||e.format.name==="stylesheet"){let a=await this.getCatalog(),i=M(a,e.resource);if(i instanceof w){let c=new ke(a).findCascadedLook(i);if(c&&!Rn(c.sourceClass)){let l=await this.findDerivation(e);if(!l||Bn(l))return this.renderViaLook({resource:e.resource,format:e.format})}}}let n=await this.findDerivation(e);if(!n)throw new R(`No derivation found for ${P(e.resource)} \u2192 format ${P(e.format)}`+(e.variant?` variant ${P(e.variant)}`:""));let r={transformation:{publisher:n.transformation.publisher,package_:n.transformation.package_,name:n.transformation.name},input:e.resource,format:e.format};return e.omitWrapper!==void 0&&(r.omitWrapper=e.omitWrapper),this.runTransformation(r)}async runTransformation(e){let n=await this.getCatalog(),r=M(n,e.transformation);if(!(r instanceof w))throw new R(`Transformation not found: ${P(e.transformation)}`);let a=M(n,e.input);if(!(a instanceof w))throw new R(`Input resource not found: ${P(e.input)}`);let i=me(r,n),u=Cn(i.outputs,e.format);if(!u)throw new R(`Transformation ${P(e.transformation)} declares outputs [${[...i.outputs].join(", ")}], none of which corresponds to format ${P(e.format)}`);let c;try{c=await this.runner.run({transformation:r,instances:[a],allKanonaks:n,repository:this.repository,parser:this.parser,objectParser:this.objectParser,outputFormat:u,...e.omitWrapper!==void 0?{runtimeOverride:{metadataRenames:new Map,omitWrapper:e.omitWrapper}}:{}})}catch(l){throw new R(`Transformation execution failed: ${l.message}`,l)}if(c.length===0)throw new R("Transformation produced no artifacts");return{content:c[0].content,format:e.format,filename:c[0].fileName}}async getCatalog(){return this.cachedCatalog||(this.cachedCatalog=await this.objectParser.parseKanonaks(this.repository)),this.cachedCatalog}};function P(t){return`${t.publisher}/${t.package_}/${t.name}`}function Bn(t){return typeof t.source=="string"?!1:t.source.publisher==="kanonak.org"&&t.source.package_==="core-rdf"&&t.source.name==="Resource"}function Rn(t){return t.publisher==="kanonak.org"&&t.package_==="core-rdf"&&t.name==="Resource"}function Cn(t,e){let n=e.name;if(t.has(n))return n;for(let r of t)if(r.startsWith(n+"-")||r===n)return r}export{ne as CssBackend,yt as DEFAULT_VARIANT,h as DOCAST,St as DOCAST_PKG,wt as DOCAST_PUB,ie as DynamoDbBackend,ge as ExpressionEngineV3,_ as ExpressionEvalErrorV3,ee as HtmlBackend,Q as JsonBackend,Y as MarkdownFrontmatterBackend,oe as ReferenceResolver,R as RenderError,jn as SUPPORTED_FORMATS_V3,te as SvgBackend,o as TX_V3,tn as TX_V3_PKG,en as TX_V3_PUB,ir as TX_V3_VERSION_MAJOR,Z as TomlBackend,Re as TransformationEngine,y as TransformationLoadErrorV3,W as TransformationRunnerErrorV3,ye as TransformationRunnerV3,re as YamlBackend,me as compileTransformationV3,x as renderMarkdownToHtml};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
2
2
|
import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
|
|
3
3
|
import type { OntologyValidationResult } from './OntologyValidationResult.js';
|
|
4
|
+
import type { ValidationCache } from './ValidationCache.js';
|
|
4
5
|
export interface IKanonakObjectValidator {
|
|
5
|
-
validateAsync(document: KanonakDocument, repository?: IKanonakDocumentRepository | null): Promise<OntologyValidationResult>;
|
|
6
|
-
validateYamlAsync(yamlText: string, repository?: IKanonakDocumentRepository | null): Promise<OntologyValidationResult>;
|
|
6
|
+
validateAsync(document: KanonakDocument, repository?: IKanonakDocumentRepository | null, cache?: ValidationCache): Promise<OntologyValidationResult>;
|
|
7
|
+
validateYamlAsync(yamlText: string, repository?: IKanonakDocumentRepository | null, cache?: ValidationCache): Promise<OntologyValidationResult>;
|
|
7
8
|
}
|
|
@@ -5,14 +5,15 @@ import type { IKanonakObjectValidator } from './IKanonakObjectValidator.js';
|
|
|
5
5
|
import type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
|
|
6
6
|
import type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
|
|
7
7
|
import { OntologyValidationResult } from './OntologyValidationResult.js';
|
|
8
|
+
import type { ValidationCache } from './ValidationCache.js';
|
|
8
9
|
export declare class KanonakObjectValidator implements IKanonakObjectValidator {
|
|
9
10
|
private readonly parser;
|
|
10
11
|
private readonly documentRules;
|
|
11
12
|
private readonly repositoryRules;
|
|
12
13
|
includeWarnings: boolean;
|
|
13
14
|
constructor(parser?: IKanonakParser);
|
|
14
|
-
validateAsync(document: KanonakDocument, repository?: IKanonakDocumentRepository | null): Promise<OntologyValidationResult>;
|
|
15
|
-
validateYamlAsync(yamlText: string, repository?: IKanonakDocumentRepository | null): Promise<OntologyValidationResult>;
|
|
15
|
+
validateAsync(document: KanonakDocument, repository?: IKanonakDocumentRepository | null, cache?: ValidationCache): Promise<OntologyValidationResult>;
|
|
16
|
+
validateYamlAsync(yamlText: string, repository?: IKanonakDocumentRepository | null, cache?: ValidationCache): Promise<OntologyValidationResult>;
|
|
16
17
|
addDocumentRule(rule: IDocumentValidationRule): void;
|
|
17
18
|
addRepositoryRule(rule: IRepositoryValidationRule): void;
|
|
18
19
|
removeDocumentRule<T extends IDocumentValidationRule>(ruleType: new () => T): void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
2
|
+
import type { Kanonak } from '../kanonaks/Kanonak.js';
|
|
3
|
+
/**
|
|
4
|
+
* Per-validation-pass memoization shared across every repository rule
|
|
5
|
+
* applied to documents in the same repository.
|
|
6
|
+
*
|
|
7
|
+
* Today the validator's caller (CLI single-file validation, or the
|
|
8
|
+
* VS Code diagnostics provider validating every workspace document)
|
|
9
|
+
* runs `KanonakObjectValidator.validateAsync(doc, repo)` once per
|
|
10
|
+
* document. Each call re-executes 21 repository rules from scratch
|
|
11
|
+
* against the same repository, and several of those rules redo
|
|
12
|
+
* identical work for every document — walking the import closure
|
|
13
|
+
* to collect class declarations, looking up the same package via
|
|
14
|
+
* `getHighestCompatibleVersionAsync` over and over, or re-parsing
|
|
15
|
+
* the entire repo through `KanonakObjectParser`.
|
|
16
|
+
*
|
|
17
|
+
* `ValidationCache` is the seam that lets a multi-document caller
|
|
18
|
+
* share that work across calls. The cache's lifetime is one
|
|
19
|
+
* validation pass over one repository; the diagnostics provider
|
|
20
|
+
* constructs a fresh cache at the top of each refresh and passes
|
|
21
|
+
* it to every per-document `validateAsync`. Rules opt in by
|
|
22
|
+
* reading from the cache when present; without it they fall back
|
|
23
|
+
* to their original logic (used by single-document callers like
|
|
24
|
+
* the CLI's `kanonak validate <path>`).
|
|
25
|
+
*
|
|
26
|
+
* The cache also exposes a wrapped `repository` that memoizes
|
|
27
|
+
* `getHighestCompatibleVersionAsync` and
|
|
28
|
+
* `getDocumentsByNamespaceAsync` — both linear scans over the
|
|
29
|
+
* in-memory repo. Rules that don't know about the cache still
|
|
30
|
+
* benefit, because the validator passes `cache.repository` as the
|
|
31
|
+
* repo argument so their existing lookup calls hit the cache
|
|
32
|
+
* transparently.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ValidationCache {
|
|
35
|
+
private readonly underlying;
|
|
36
|
+
/**
|
|
37
|
+
* Repository wrapper that memoizes read-only lookups for the
|
|
38
|
+
* lifetime of this cache. Pass this to every rule (instead of
|
|
39
|
+
* the bare repository) so existing rule code that calls
|
|
40
|
+
* `repository.getHighestCompatibleVersionAsync(...)` benefits
|
|
41
|
+
* automatically without needing to know about the cache.
|
|
42
|
+
*/
|
|
43
|
+
readonly repository: IKanonakDocumentRepository;
|
|
44
|
+
private kanonaksPromise;
|
|
45
|
+
private importClosureCache;
|
|
46
|
+
private classDeclarationsCache;
|
|
47
|
+
private propertyNamesCache;
|
|
48
|
+
private allDocumentsPromise;
|
|
49
|
+
constructor(underlying: IKanonakDocumentRepository);
|
|
50
|
+
/**
|
|
51
|
+
* Full-repository `parseKanonaks` result, memoized for the cache's
|
|
52
|
+
* lifetime. Used by rules that want the resolved-URI object model
|
|
53
|
+
* (e.g. `MarkdownLinkRule`) instead of walking raw `document.body`.
|
|
54
|
+
* Filter by `subject.namespace` to scope to a specific document.
|
|
55
|
+
*/
|
|
56
|
+
getKanonaks(): Promise<Kanonak[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Identifier-keyed transitive-import closure for the given document.
|
|
59
|
+
* Returns the set of `publisher/package@version` strings reachable
|
|
60
|
+
* via `imports:` starting from `docId`, including `docId` itself.
|
|
61
|
+
*
|
|
62
|
+
* Rules that need to know "what does this document import,
|
|
63
|
+
* recursively?" should call this once instead of walking the
|
|
64
|
+
* imports graph themselves on every reference lookup. Per-doc
|
|
65
|
+
* memoized; same doc validated multiple times in the pass
|
|
66
|
+
* traverses the graph once.
|
|
67
|
+
*/
|
|
68
|
+
getImportClosure(docId: string): Promise<Set<string>>;
|
|
69
|
+
/**
|
|
70
|
+
* subClassOf relationships declared inside the given document's
|
|
71
|
+
* body (NOT in its imports). Map<className, parentClassName[]>.
|
|
72
|
+
* Composed across an import closure to build the effective class
|
|
73
|
+
* hierarchy a rule needs.
|
|
74
|
+
*
|
|
75
|
+
* Cached per-doc so two rules consulting the same document's
|
|
76
|
+
* declarations (or the same document validated multiple times)
|
|
77
|
+
* walk its body once.
|
|
78
|
+
*/
|
|
79
|
+
getClassDeclarations(docId: string): Promise<Map<string, string[]>>;
|
|
80
|
+
/**
|
|
81
|
+
* Names of property-typed entities (`ObjectProperty`,
|
|
82
|
+
* `DatatypeProperty`, `AnnotationProperty`, plain `Property`)
|
|
83
|
+
* declared inside the given document's body. Used by reference-
|
|
84
|
+
* resolution rules to answer "is property P defined here?" in O(1)
|
|
85
|
+
* after a one-time scan.
|
|
86
|
+
*/
|
|
87
|
+
getPropertyNames(docId: string): Promise<Set<string>>;
|
|
88
|
+
private getAllDocuments;
|
|
89
|
+
private computeImportClosure;
|
|
90
|
+
private buildDocsByIdIndex;
|
|
91
|
+
private computeClassDeclarations;
|
|
92
|
+
private computePropertyNames;
|
|
93
|
+
private findDocById;
|
|
94
|
+
}
|
|
@@ -2,6 +2,7 @@ export { OntologyValidationResult } from './OntologyValidationResult.js';
|
|
|
2
2
|
export { OntologyValidationError } from './OntologyValidationError.js';
|
|
3
3
|
export { ValidationSeverity } from './ValidationSeverity.js';
|
|
4
4
|
export { ValidationContext } from './ValidationContext.js';
|
|
5
|
+
export { ValidationCache } from './ValidationCache.js';
|
|
5
6
|
export type { IKanonakObjectValidator } from './IKanonakObjectValidator.js';
|
|
6
7
|
export { KanonakObjectValidator } from './KanonakObjectValidator.js';
|
|
7
8
|
export type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
|