@kanonak-protocol/sdk 3.17.0 → 3.19.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.
@@ -156,8 +156,27 @@ export interface DocAstStructuredList {
156
156
  export interface DocAstStringScalar {
157
157
  kind: 'StringScalar';
158
158
  stringValue: string;
159
+ /**
160
+ * Optional per-scalar serialization hint (document-ast 1.3.0).
161
+ *
162
+ * `StructuredEntry.escapeHint` covers a scalar that sits directly
163
+ * under a map key, but a scalar *inside a `StructuredList`* has no
164
+ * enclosing entry to carry a hint. This field lets list-item
165
+ * scalars carry their own hint — e.g. a `StringScalar "true"` in a
166
+ * list that the dynamodb-json backend should emit as `{ "BOOL":
167
+ * true }`. Same `EntityUri` shape and URI-comparison rule as
168
+ * `StructuredEntry.escapeHint`. When a scalar is the value of a
169
+ * `StructuredEntry`, the entry-level hint takes precedence.
170
+ */
171
+ escapeHint?: EntityUri;
159
172
  }
160
173
  export interface DocAstIntegerScalar {
161
174
  kind: 'IntegerScalar';
162
175
  integerValue: number;
176
+ /**
177
+ * Optional per-scalar serialization hint (document-ast 1.3.0).
178
+ * See `DocAstStringScalar.escapeHint` — same rationale and
179
+ * precedence rule (entry-level hint wins when both are present).
180
+ */
181
+ escapeHint?: EntityUri;
163
182
  }
@@ -48,6 +48,9 @@ export declare const DOCAST: {
48
48
  readonly ESC_TOML_STRING: EntityUri;
49
49
  readonly ESC_TOML_MULTILINE: EntityUri;
50
50
  readonly ESC_JSON: EntityUri;
51
+ readonly ESC_DYNAMODB_BOOL: EntityUri;
52
+ readonly ESC_DYNAMODB_NUMBER: EntityUri;
53
+ readonly ESC_DYNAMODB_NULL: EntityUri;
51
54
  readonly TEXT_PLAIN: EntityUri;
52
55
  readonly TEXT_MARKDOWN: EntityUri;
53
56
  readonly TEXT_HTML: EntityUri;
@@ -0,0 +1,25 @@
1
+ import type { DocAstDocument } from '../DocAst.js';
2
+ import type { BackendFormatOverride } from '../FormatOverride.js';
3
+ import type { IDocumentAstBackend } from './IDocumentAstBackend.js';
4
+ /**
5
+ * The DynamoDB attribute-value JSON shape this backend emits. A
6
+ * subset of the full wire format — only the types representable by
7
+ * docast's `StructuredValue` set (no `SS` / `NS` / `BS` / `B`).
8
+ */
9
+ export type DynamoDbAttributeValue = {
10
+ S: string;
11
+ } | {
12
+ N: string;
13
+ } | {
14
+ BOOL: boolean;
15
+ } | {
16
+ NULL: true;
17
+ } | {
18
+ L: DynamoDbAttributeValue[];
19
+ } | {
20
+ M: Record<string, DynamoDbAttributeValue>;
21
+ };
22
+ export declare class DynamoDbBackend implements IDocumentAstBackend {
23
+ readonly backendUri = "kanonak.org/transformations/dynamodb-json";
24
+ render(document: DocAstDocument, override?: BackendFormatOverride): string;
25
+ }
@@ -17,4 +17,6 @@ export { SvgBackend } from './backends/SvgBackend.js';
17
17
  export { TomlBackend } from './backends/TomlBackend.js';
18
18
  export { CssBackend } from './backends/CssBackend.js';
19
19
  export { YamlBackend } from './backends/YamlBackend.js';
20
+ export { DynamoDbBackend } from './backends/DynamoDbBackend.js';
21
+ export type { DynamoDbAttributeValue } from './backends/DynamoDbBackend.js';
20
22
  export { renderMarkdownToHtml } from './backends/SimpleMarkdownRenderer.js';
@@ -1,53 +1,53 @@
1
- import{b,c as I,d,f as F}from"../chunk-2JQMUZWN.js";import{a as Ce}from"../chunk-C2WWLKWE.js";import"../chunk-CQLO62JP.js";import{a as Be}from"../chunk-FJ35VIV6.js";import{a as P,c as Re,d as Le}from"../chunk-Z72IKY6C.js";import{b as D,c as S,d as h,g as R,h as L,i as B,j as V,k as T,l as w}from"../chunk-W6T7MOKY.js";import{a as De}from"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";var pt="kanonak.org",gt="document-ast",p=t=>({publisher:pt,package_:gt,name:t}),E={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"),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 Ue(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var J=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=yt(e.metadata,n),i=wt(e.children),u=["---",...r,"---","",i].join(`
1
+ import{b as S,c as M,d as f,f as F}from"../chunk-2JQMUZWN.js";import{a as Oe}from"../chunk-C2WWLKWE.js";import"../chunk-CQLO62JP.js";import{a as Ce}from"../chunk-FJ35VIV6.js";import{a as O,c as Re,d as Ue}from"../chunk-Z72IKY6C.js";import{b as T,c as E,d as b,g as B,h as L,i as R,j as V,k as K,l as w}from"../chunk-W6T7MOKY.js";import{a as Le}from"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";var ht="kanonak.org",bt="document-ast",p=t=>({publisher:ht,package_:bt,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 Ne(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var X=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=wt(e.metadata,n),a=$t(e.children),u=["---",...r,"---","",a].join(`
2
2
  `);return n?.trailingNewline&&(u.endsWith(`
3
3
  `)||(u+=`
4
- `)),u}};function yt(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(oe(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(oe(c),l);let a=(e?.metadataKeys??t.entries.map(c=>c.key)).map(oe),u=[];for(let c of a){let l=n.get(c);if(!l)continue;let m=r.get(c),g=oe(m??c),k=Pe(l.value,l.escapeHint);k!==void 0&&u.push(`${g}: ${k}`)}return u}function oe(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Pe(t,e){switch(t.kind){case"StringScalar":return kt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let i=Pe(r,e);i!==void 0&&n.push(i)}return n.join(", ")}case"StructuredMap":return;default:return}}function kt(t,e){return!e||Ue(e,E.ESC_RAW)?t:Ue(e,E.ESC_YAML_SAFE)?ht(t):t}function ht(t){return t.includes(`
4
+ `)),u}};function wt(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ue(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ue(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ue),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let m=r.get(c),g=ue(m??c),k=_e(l.value,l.escapeHint);k!==void 0&&u.push(`${g}: ${k}`)}return u}function ue(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function _e(t,e){switch(t.kind){case"StringScalar":return St(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=_e(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function St(t,e){return!e||Ne(e,h.ESC_RAW)?t:Ne(e,h.ESC_YAML_SAFE)?Et(t):t}function Et(t){return t.includes(`
5
5
  `)?`|-
6
6
  ${t.replace(/\n/g,`
7
- `).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(t)?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function wt(t){let e=[];for(let n of t){let r=ge(n);r&&e.push(r)}return e.join(`
7
+ `).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(t)?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function $t(t){let e=[];for(let n of t){let r=ke(n);r&&e.push(r)}return e.join(`
8
8
 
9
- `)}function ge(t){switch(t.kind){case"Heading":return`${"#".repeat(t.level)} ${se(t.inlines)}`;case"Paragraph":return se(t.inlines);case"RawBlock":return t.rawContent;case"PropertyList":return Oe(t);case"Table":return bt(t);default:return""}}function bt(t){let e=t.tableColumnLabels??[],n=t.tableRows??[];if(e.length===0&&n.length===0)return"";let r=`| ${e.map(pe).join(" | ")} |`,i=`| ${e.map(()=>"---").join(" | ")} |`,a=n.map(u=>`| ${(u.tableCells??[]).map(St).join(" | ")} |`);return[r,i,...a].join(`
10
- `)}function St(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?pe(se([e])):pe(ge(e).replace(/\n+/g," "))}function pe(t){return t==null?"":String(t).replace(/\|/g,"\\|")}function Oe(t,e=0){if(!t.propertyEntries||t.propertyEntries.length===0)return"";let n=" ".repeat(e),r=[];for(let i of t.propertyEntries){let a=`${n}**${i.propertyKey}:**`,u=$t(i.propertyValue,e+1);u.includes(`
11
- `)?r.push(`${a}
12
- ${u}`):r.push(`${a} ${u}`)}return r.join(`
9
+ `)}function ke(t){switch(t.kind){case"Heading":return`${"#".repeat(t.level)} ${ce(t.inlines)}`;case"Paragraph":return ce(t.inlines);case"RawBlock":return t.rawContent;case"PropertyList":return Me(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(ye).join(" | ")} |`,a=`| ${e.map(()=>"---").join(" | ")} |`,i=n.map(u=>`| ${(u.tableCells??[]).map(jt).join(" | ")} |`);return[r,a,...i].join(`
10
+ `)}function jt(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?ye(ce([e])):ye(ke(e).replace(/\n+/g," "))}function ye(t){return t==null?"":String(t).replace(/\|/g,"\\|")}function Me(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=Vt(a.propertyValue,e+1);u.includes(`
11
+ `)?r.push(`${i}
12
+ ${u}`):r.push(`${i} ${u}`)}return r.join(`
13
13
 
14
- `)}function $t(t,e){if(!t||t.length===0)return"";let n=[],r=[];for(let i of t){let a=i;!a||typeof a!="object"||!a.kind||(a.kind==="Text"||a.kind==="ResourceLink"||a.kind==="Badge"?n.push(se([a])):a.kind==="PropertyList"?r.push(Oe(a,e)):r.push(ge(a)))}return r.length===0?n.join(""):n.length===0?r.join(`
14
+ `)}function Vt(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(ce([i])):i.kind==="PropertyList"?r.push(Me(i,e)):r.push(ke(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 se(t){let e=[];for(let n of t)n.kind==="Text"?e.push(n.text):n.kind==="ResourceLink"?e.push(Et(n)):n.kind==="Badge"&&e.push(vt(n));return e.join("")}function Et(t){let e=Ie(t.target);if(!e)return t.linkLabel??"[unresolved link]";let n=I(e),r=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,i=t.linkTooltip?` "${_e(t.linkTooltip)}"`:"";return`[${r}](${n}${i})`}function vt(t){if(!t.badgeTarget)return`*${t.badgeLabel}*`;let e=Ie(t.badgeTarget);if(!e)return`*${t.badgeLabel}*`;let n=I(e),r=t.badgeTooltip?` "${_e(t.badgeTooltip)}"`:"";return`*[${t.badgeLabel}](${n}${r})*`}function _e(t){return t==null?"":String(t).replace(/"/g,'\\"')}function Ie(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 jt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/toml";render(e,n){let i=Vt(e.metadata,n).join(`
21
- `);return n?.trailingNewline&&(i.endsWith(`
22
- `)||(i+=`
23
- `)),i}};function Vt(t,e){if(!t)return[];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,l=Me(u.value,u.escapeHint);l!==void 0&&i.push(`${c} = ${l}`)}return i}function Me(t,e){switch(t.kind){case"StringScalar":return At(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let i=Me(r,e);i!==void 0&&n.push(i)}return`[${n.join(", ")}]`}case"StructuredMap":return;default:return}}function At(t,e){return e&&jt(e,E.ESC_TOML_MULTILINE)?Tt(t):Kt(t)}function Kt(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function Tt(t){return`"""
20
+ `)}`}function ce(t){let e=[];for(let n of t)n.kind==="Text"?e.push(n.text):n.kind==="ResourceLink"?e.push(At(n)):n.kind==="Badge"&&e.push(Dt(n));return e.join("")}function At(t){let e=Ie(t.target);if(!e)return t.linkLabel??"[unresolved link]";let n=M(e),r=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,a=t.linkTooltip?` "${Pe(t.linkTooltip)}"`:"";return`[${r}](${n}${a})`}function Dt(t){if(!t.badgeTarget)return`*${t.badgeLabel}*`;let e=Ie(t.badgeTarget);if(!e)return`*${t.badgeLabel}*`;let n=M(e),r=t.badgeTooltip?` "${Pe(t.badgeTooltip)}"`:"";return`*[${t.badgeLabel}](${n}${r})*`}function Pe(t){return t==null?"":String(t).replace(/"/g,'\\"')}function Ie(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 Kt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/toml";render(e,n){let a=Tt(e.metadata,n).join(`
21
+ `);return n?.trailingNewline&&(a.endsWith(`
22
+ `)||(a+=`
23
+ `)),a}};function Tt(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=Fe(u.value,u.escapeHint);l!==void 0&&a.push(`${c} = ${l}`)}return a}function Fe(t,e){switch(t.kind){case"StringScalar":return Bt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Fe(r,e);a!==void 0&&n.push(a)}return`[${n.join(", ")}]`}case"StructuredMap":return;default:return}}function Bt(t,e){return e&&Kt(e,h.ESC_TOML_MULTILINE)?Rt(t):Lt(t)}function Lt(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function Rt(t){return`"""
24
24
  ${t.replace(/"""/g,'\\"\\"\\"')}
25
- """`}var Z=class{backendUri="kanonak.org/transformations/json";render(e,n){let r=JSON.stringify(e,null,2);return n?.trailingNewline&&!r.endsWith(`
25
+ """`}var x=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
- `:r}};function Q(t){let e=t.replace(/\r\n/g,`
27
+ `:r}};function Z(t){let e=t.replace(/\r\n/g,`
28
28
  `).split(`
29
- `),n=[],r=0;for(;r<e.length;){let i=e[r];if(i.trim()===""){r++;continue}let a=/^(\s*)```(\S*)\s*$/.exec(i);if(a){let l=a[2],m=[];for(r++;r<e.length&&!/^(\s*)```\s*$/.test(e[r]);)m.push(e[r]),r++;r++;let g=Fe(m.join(`
30
- `)),k=l?` class="language-${qe(l)}"`:"";n.push(`<pre><code${k}>${g}</code></pre>`);continue}let u=/^(#{1,6})\s+(.*)$/.exec(i);if(u){let l=u[1].length,m=W(u[2].trim());n.push(`<h${l}>${m}</h${l}>`),r++;continue}if(i.includes("|")&&r+1<e.length&&Ne(e[r+1])){let l=ye(i),m=Dt(e[r+1]);r+=2;let g=[];for(;r<e.length&&e[r].trim()!==""&&e[r].includes("|");)g.push(ye(e[r])),r++;n.push(Rt(l,m,g));continue}if(/^\s*[-*]\s+/.test(i)){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>${W(m.join(" ").trim())}</li>`)}n.push(`<ul>
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=We(m.join(`
30
+ `)),k=l?` class="language-${He(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=W(u[2].trim());n.push(`<h${l}>${m}</h${l}>`),r++;continue}if(a.includes("|")&&r+1<e.length&&qe(e[r+1])){let l=he(a),m=Ut(e[r+1]);r+=2;let g=[];for(;r<e.length&&e[r].trim()!==""&&e[r].includes("|");)g.push(he(e[r])),r++;n.push(Ct(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>${W(m.join(" ").trim())}</li>`)}n.push(`<ul>
31
31
  ${l.join(`
32
32
  `)}
33
- </ul>`);continue}if(/^\s*\d+\.\s+/.test(i)){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>${W(m.join(" ").trim())}</li>`)}n.push(`<ol>
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>${W(m.join(" ").trim())}</li>`)}n.push(`<ol>
34
34
  ${l.join(`
35
35
  `)}
36
- </ol>`);continue}let c=[i];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&&Ne(e[r+1]));)c.push(e[r]),r++;n.push(`<p>${W(c.join(" "))}</p>`)}return n.join(`
37
- `)}function Ne(t){return t.includes("-")?/^[\s|:-]+$/.test(t):!1}function ye(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 Dt(t){return ye(t).map(e=>{let n=e.startsWith(":"),r=e.endsWith(":");return n&&r?"center":r?"right":n?"left":null})}function Rt(t,e,n){let r=u=>{let c=e[u];return c?` style="text-align:${c}"`:""},i=t.map((u,c)=>`<th${r(c)}>${W(u)}</th>`).join(""),a=n.map(u=>`<tr>${u.map((l,m)=>`<td${r(m)}>${W(l)}</td>`).join("")}</tr>`).join(`
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&&qe(e[r+1]));)c.push(e[r]),r++;n.push(`<p>${W(c.join(" "))}</p>`)}return n.join(`
37
+ `)}function qe(t){return t.includes("-")?/^[\s|:-]+$/.test(t):!1}function he(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 Ut(t){return he(t).map(e=>{let n=e.startsWith(":"),r=e.endsWith(":");return n&&r?"center":r?"right":n?"left":null})}function Ct(t,e,n){let r=u=>{let c=e[u];return c?` style="text-align:${c}"`:""},a=t.map((u,c)=>`<th${r(c)}>${W(u)}</th>`).join(""),i=n.map(u=>`<tr>${u.map((l,m)=>`<td${r(m)}>${W(l)}</td>`).join("")}</tr>`).join(`
38
38
  `);return`<table>
39
- <thead><tr>${i}</tr></thead>
39
+ <thead><tr>${a}</tr></thead>
40
40
  <tbody>
41
- ${a}
41
+ ${i}
42
42
  </tbody>
43
- </table>`}function W(t){let e=Fe(t);return e=e.replace(/`([^`\n]+)`/g,(n,r)=>`<code>${r}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(n,r,i)=>`<a href="${qe(i)}">${r}</a>`),e=e.replace(/\*\*([^*\n]+)\*\*/g,(n,r)=>`<strong>${r}</strong>`),e=e.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g,(n,r,i)=>`${r}<em>${i}</em>`),e=e.replace(/(^|[\s(])_([^_\n]+)_(?=[\s).,;:!?]|$)/g,(n,r,i)=>`${r}<em>${i}</em>`),e}function Fe(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function qe(t){return t.replace(/"/g,"&quot;").replace(/&/g,"&amp;")}function ke(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var x=class{backendUri="kanonak.org/transformations/html";render(e,n){let r=Ct(e.children);if(n?.omitWrapper){let c=r.endsWith(`
43
+ </table>`}function W(t){let e=We(t);return e=e.replace(/`([^`\n]+)`/g,(n,r)=>`<code>${r}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(n,r,a)=>`<a href="${He(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 We(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function He(t){return t.replace(/"/g,"&quot;").replace(/&/g,"&amp;")}function be(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Q=class{backendUri="kanonak.org/transformations/html";render(e,n){let r=_t(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 i=Lt(e.metadata)??"Untitled",a=Bt(e.metadata,n),u=`<!DOCTYPE html>
46
+ `)?c.slice(0,-1):c}let a=Ot(e.metadata)??"Untitled",i=Nt(e.metadata,n),u=`<!DOCTYPE html>
47
47
  <html lang="en">
48
48
  <head>
49
49
  <meta charset="utf-8">
50
- <title>${C(i)}</title>
50
+ <title>${U(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,37 +69,39 @@ figure.svg-figure svg { max-width: 100%; height: auto; }
69
69
  </style>
70
70
  </head>
71
71
  <body>
72
- ${a}${r}
72
+ ${i}${r}
73
73
  </body>
74
74
  </html>
75
75
  `;return n?.trailingNewline===!1&&u.endsWith(`
76
- `)?u.slice(0,-1):u}};function Lt(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 Bt(t,e){if(!t||t.entries.length===0)return"";let n=e?.metadataKeys??t.entries.map(a=>a.key),r=new Map(t.entries.map(a=>[a.key,a])),i=[];for(let a of n){let u=r.get(a);if(!u)continue;let c=e?.metadataRenames.get(a)??a,l=We(u.value);l!==void 0&&i.push(` <dt>${C(c)}</dt>
77
- <dd>${l}</dd>`)}return i.length===0?"":`<dl class="metadata">
78
- ${i.join(`
76
+ `)?u.slice(0,-1):u}};function Ot(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 Nt(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=ze(u.value);l!==void 0&&a.push(` <dt>${U(c)}</dt>
77
+ <dd>${l}</dd>`)}return a.length===0?"":`<dl class="metadata">
78
+ ${a.join(`
79
79
  `)}
80
80
  </dl>
81
- `}function We(t){switch(t.kind){case"StringScalar":return C(t.stringValue);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let e=[];for(let n of t.items){let r=We(n);r!==void 0&&e.push(`<code>${r}</code>`)}return e.join(", ")}case"StructuredMap":return;default:return}}function Ct(t){let e=[];for(let n of t){let r=he(n);r&&e.push(r)}return e.join(`
82
- `)}function he(t){switch(t.kind){case"Heading":{let e=Math.max(1,Math.min(6,t.level));return`<h${e}>${ue(t.inlines)}</h${e}>`}case"Paragraph":return`<p>${ue(t.inlines)}</p>`;case"RawBlock":return Mt(t);case"PropertyList":return _t(t);case"Table":return Ut(t);default:return""}}function Ut(t){let e=t.tableColumnLabels??[],n=t.tableRows??[],r=e.length>0?`<thead>
83
- <tr>${e.map(a=>`<th>${C(a)}</th>`).join("")}</tr>
81
+ `}function ze(t){switch(t.kind){case"StringScalar":return U(t.stringValue);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let e=[];for(let n of t.items){let r=ze(n);r!==void 0&&e.push(`<code>${r}</code>`)}return e.join(", ")}case"StructuredMap":return;default:return}}function _t(t){let e=[];for(let n of t){let r=we(n);r&&e.push(r)}return e.join(`
82
+ `)}function we(t){switch(t.kind){case"Heading":{let e=Math.max(1,Math.min(6,t.level));return`<h${e}>${le(t.inlines)}</h${e}>`}case"Paragraph":return`<p>${le(t.inlines)}</p>`;case"RawBlock":return Wt(t);case"PropertyList":return Ft(t);case"Table":return Mt(t);default:return""}}function Mt(t){let e=t.tableColumnLabels??[],n=t.tableRows??[],r=e.length>0?`<thead>
83
+ <tr>${e.map(i=>`<th>${U(i)}</th>`).join("")}</tr>
84
84
  </thead>
85
- `:"",i=n.length>0?`<tbody>
85
+ `:"",a=n.length>0?`<tbody>
86
86
  ${n.map(Pt).join(`
87
87
  `)}
88
88
  </tbody>
89
89
  `:"";return`<table class="property-table">
90
- ${r}${i}</table>`}function Pt(t){return` <tr>${(t.tableCells??[]).map(r=>`<td>${Ot(r)}</td>`).join("")}</tr>`}function Ot(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?ue([e]):he(e)}function _t(t){if(!t.propertyEntries||t.propertyEntries.length===0)return"";let e=[];for(let n of t.propertyEntries){let i=`<dt${n.propertyTooltip?` title="${H(n.propertyTooltip)}"`:""}>${C(n.propertyKey)}</dt>`,a=`<dd>${It(n.propertyValue)}</dd>`;e.push(i,a)}return`<dl class="property-list">
90
+ ${r}${a}</table>`}function Pt(t){return` <tr>${(t.tableCells??[]).map(r=>`<td>${It(r)}</td>`).join("")}</tr>`}function It(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?le([e]):we(e)}function Ft(t){if(!t.propertyEntries||t.propertyEntries.length===0)return"";let e=[];for(let n of t.propertyEntries){let a=`<dt${n.propertyTooltip?` title="${H(n.propertyTooltip)}"`:""}>${U(n.propertyKey)}</dt>`,i=`<dd>${qt(n.propertyValue)}</dd>`;e.push(a,i)}return`<dl class="property-list">
91
91
  ${e.join(`
92
92
  `)}
93
- </dl>`}function It(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(ue([r])):e.push(he(r)))}return e.join("")}function Mt(t){let e=t.mediaType;return e&&ke(e,E.TEXT_MARKDOWN)?Q(t.rawContent):e&&ke(e,E.TEXT_HTML)?t.rawContent:e&&ke(e,E.IMAGE_SVG_XML)?`<figure class="svg-figure">
93
+ </dl>`}function qt(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(le([r])):e.push(we(r)))}return e.join("")}function Wt(t){let e=t.mediaType;return e&&be(e,h.TEXT_MARKDOWN)?Z(t.rawContent):e&&be(e,h.TEXT_HTML)?t.rawContent:e&&be(e,h.IMAGE_SVG_XML)?`<figure class="svg-figure">
94
94
  ${t.rawContent}
95
- </figure>`:`<pre${e?` class="media-${H(e.name)}"`:""}><code>${C(t.rawContent)}</code></pre>`}function ue(t){let e=[];for(let n of t)n.kind==="Text"?e.push(C(n.text)):n.kind==="ResourceLink"?e.push(Nt(n)):n.kind==="Badge"&&e.push(Ft(n));return e.join("")}function Nt(t){let e=He(t.target);if(!e)return C(t.linkLabel??"[unresolved link]");let n=I(e),r=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,i=t.linkTooltip?` title="${H(t.linkTooltip)}"`:"";return`<a class="kan-link" href="${H(n)}"${i}>${C(r)}</a>`}function Ft(t){let e=t.badgeTooltip?` title="${H(t.badgeTooltip)}"`:"",n=C(t.badgeLabel);if(!t.badgeTarget)return`<span class="kan-badge"${e}>${n}</span>`;let r=He(t.badgeTarget);if(!r)return`<span class="kan-badge"${e}>${n}</span>`;let i=I(r);return`<a class="kan-badge" href="${H(i)}"${e}>${n}</a>`}function He(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 C(t){return t==null?"":String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function H(t){return t==null?"":String(t).replace(/"/g,"&quot;").replace(/&/g,"&amp;")}function qt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ee=class{backendUri="kanonak.org/transformations/svg";render(e,n){for(let r of e.children)if(r.kind==="RawBlock"&&r.mediaType&&qt(r.mediaType,E.IMAGE_SVG_XML)){let i=r.rawContent;return n?.trailingNewline&&!i.endsWith(`
96
- `)&&(i+=`
97
- `),i}return'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'}};function Wt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var te=class{backendUri="kanonak.org/transformations/stylesheet";render(e,n){let r=[];for(let a of e.children)a.kind==="RawBlock"&&a.mediaType&&Wt(a.mediaType,E.TEXT_CSS)&&r.push(a.rawContent);let i=r.join(`
95
+ </figure>`:`<pre${e?` class="media-${H(e.name)}"`:""}><code>${U(t.rawContent)}</code></pre>`}function le(t){let e=[];for(let n of t)n.kind==="Text"?e.push(U(n.text)):n.kind==="ResourceLink"?e.push(Ht(n)):n.kind==="Badge"&&e.push(zt(n));return e.join("")}function Ht(t){let e=Ge(t.target);if(!e)return U(t.linkLabel??"[unresolved link]");let n=M(e),r=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,a=t.linkTooltip?` title="${H(t.linkTooltip)}"`:"";return`<a class="kan-link" href="${H(n)}"${a}>${U(r)}</a>`}function zt(t){let e=t.badgeTooltip?` title="${H(t.badgeTooltip)}"`:"",n=U(t.badgeLabel);if(!t.badgeTarget)return`<span class="kan-badge"${e}>${n}</span>`;let r=Ge(t.badgeTarget);if(!r)return`<span class="kan-badge"${e}>${n}</span>`;let a=M(r);return`<a class="kan-badge" href="${H(a)}"${e}>${n}</a>`}function Ge(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 U(t){return t==null?"":String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function H(t){return t==null?"":String(t).replace(/"/g,"&quot;").replace(/&/g,"&amp;")}function Gt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ee=class{backendUri="kanonak.org/transformations/svg";render(e,n){for(let r of e.children)if(r.kind==="RawBlock"&&r.mediaType&&Gt(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 Jt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var te=class{backendUri="kanonak.org/transformations/stylesheet";render(e,n){let r=[];for(let i of e.children)i.kind==="RawBlock"&&i.mediaType&&Jt(i.mediaType,h.TEXT_CSS)&&r.push(i.rawContent);let a=r.join(`
98
98
 
99
- `);return n?.trailingNewline&&i.length>0&&!i.endsWith(`
100
- `)&&(i+=`
101
- `),i}};function Ht(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ne=class{backendUri="kanonak.org/transformations/yaml";render(e,n){let r=[];for(let a of e.children)a.kind==="RawBlock"&&a.mediaType&&Ht(a.mediaType,E.TEXT_YAML)&&r.push(a.rawContent);let i=r.join(`
99
+ `);return n?.trailingNewline&&a.length>0&&!a.endsWith(`
100
+ `)&&(a+=`
101
+ `),a}};function Xt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ne=class{backendUri="kanonak.org/transformations/yaml";render(e,n){let r=[];for(let i of e.children)i.kind==="RawBlock"&&i.mediaType&&Xt(i.mediaType,h.TEXT_YAML)&&r.push(i.rawContent);let a=r.join(`
102
102
 
103
- `);return n?.trailingNewline&&i.length>0&&!i.endsWith(`
104
- `)&&(i+=`
105
- `),i}};var re=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=F(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(K=>{let v=K.metadata?.namespace_?.version;return v&&v.major===i.major&&v.minor===i.minor&&v.patch===i.patch})??m[0]:m[0],k=new Be(g,this.repository);c=await this.objectParser.parseKanonaks(k),this.cache.set(u,c)}let l=F(c,e);if(l)return l;for(let m of c)if(m instanceof S&&m.name===e.name)return m}};var zt="kanonak.org",Gt="transformations",Gn=3,s=t=>({publisher:zt,package_:Gt,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"),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 le(t,e){let n=t.name,r=an(e),i={catalog:e,depth:0};if(d(t,o.InstanceTransformation))return Xt(t,n,i,r);if(d(t,o.SetTransformation))return Jt(t,n,i,r);throw new y("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function Xt(t,e,n,r){return{kind:"instance",name:t.name,inputPattern:Ze(t,e),rule:ce(t,o.rule,`${e}.rule`,n),artifactName:ce(t,o.artifactName,`${e}.artifactName`,n),outputs:Qe(t,`${e}.outputs`),overrides:xe(t,`${e}.formatOverrides`,n),fragments:r}}function Jt(t,e,n,r){let i=O(t,o.partitionBy);return{kind:"set",name:t.name,inputPattern:Ze(t,e),rule:ce(t,o.rule,`${e}.rule`,n),artifactName:ce(t,o.artifactName,`${e}.artifactName`,n),outputs:Qe(t,`${e}.outputs`),overrides:xe(t,`${e}.formatOverrides`,n),partitionBy:i,fragments:r}}function Ze(t,e){let n=ie(t,o.inputPattern);if(!n)throw new y("inputPattern is required",e);return Yt(n,`${e}.inputPattern`)}function Yt(t,e){let n=O(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(Se(u.object.subject));else if(u instanceof w)for(let c of u.object)c instanceof h&&r.push(Se(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 P&&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=O(t,o.byProperty);if(!n)throw new y("SortKey.byProperty is required",e);let r=O(t,o.order);if(!r)throw new y("SortKey.order is required",e);if(b(r,o.ascending))return{byProperty:n,order:"ascending"};if(b(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 ce(t,e,n,r){let i=ie(t,e);if(!i)throw new y("expression is required",n);return G(i,n,r)}function G(t,e,n){if(d(t,o.StringLiteral))return{kind:"string-literal",value:j(t,o.stringLiteral,e)};if(d(t,o.IntegerLiteral))return{kind:"integer-literal",value:Ye(t,o.integerLiteral,e)};if(d(t,o.DecimalLiteral))return{kind:"decimal-literal",value:Ye(t,o.decimalLiteral,e)};if(d(t,o.BooleanLiteral))return{kind:"boolean-literal",value:un(t,o.booleanLiteral,e)};if(d(t,o.VarRef))return{kind:"var-ref",varName:j(t,o.varName,e)};if(d(t,o.PropertyRead))return{kind:"property-read",source:f(t,o.readSource,`${e}.readSource`,n),readProp:M(t,o.readProp,e,"readProp")};if(d(t,o.Traverse))return{kind:"traverse",source:f(t,o.traverseSource,`${e}.traverseSource`,n),through:M(t,o.through,e,"through"),step:f(t,o.step,`${e}.step`,n)};if(d(t,o.BuildAstNode))return{kind:"build-ast-node",astClass:M(t,o.astClass,e,"astClass"),set:Qt(t,`${e}.set`,n)};if(d(t,o.When))return{kind:"when",condition:f(t,o.condition,`${e}.condition`,n),thenBuild:f(t,o.thenBuild,`${e}.thenBuild`,n),elseBuild:Zt(t,o.elseBuild,`${e}.elseBuild`,n)};if(d(t,o.Concat))return{kind:"concat",parts:we(t,o.parts,`${e}.parts`,n)};if(d(t,o.Fallback))return{kind:"fallback",primary:f(t,o.primary,`${e}.primary`,n),alternate:f(t,o.alternate,`${e}.alternate`,n)};if(d(t,o.UriName))return{kind:"uri-name",source:f(t,o.uriNameOf,`${e}.uriNameOf`,n)};if(d(t,o.UriPublisher))return{kind:"uri-publisher",source:f(t,o.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(d(t,o.UriPackage))return{kind:"uri-package",source:f(t,o.uriPackageOf,`${e}.uriPackageOf`,n)};if(d(t,o.UriVersion))return{kind:"uri-version",source:f(t,o.uriVersionOf,`${e}.uriVersionOf`,n)};if(d(t,o.SubjectUri))return{kind:"subject-uri",source:f(t,o.subjectOf,`${e}.subjectOf`,n)};if(d(t,o.UriLiteral))return{kind:"uri-literal",refTo:M(t,o.refTo,e,"refTo")};if(d(t,o.DisplayLabel))return{kind:"display-label",labelTarget:M(t,o.labelTarget,e,"labelTarget"),labelSource:M(t,o.labelSource,e,"labelSource")};if(d(t,o.ResolveRef))return{kind:"resolve-ref",source:f(t,o.resolveSource,`${e}.resolveSource`,n)};if(d(t,o.Normalize))return{kind:"normalize",source:f(t,o.normSource,`${e}.normSource`,n),normKind:xt(t,e)};if(d(t,o.RenderMarkdown))return{kind:"render-markdown",source:f(t,o.renderSource,`${e}.renderSource`,n),readProp:M(t,o.renderProp,e,"renderProp"),format:en(t,e)};if(d(t,o.IsSet))return{kind:"is-set",check:f(t,o.checkExpr,`${e}.checkExpr`,n)};if(d(t,o.CallFragment))return nn(t,e,n);if(d(t,o.Join))return{kind:"join",source:f(t,o.source,`${e}.source`,n),separator:j(t,o.separator,e)};if(d(t,o.Count))return{kind:"count",source:f(t,o.source,`${e}.source`,n)};if(d(t,o.Sum))return{kind:"sum",source:f(t,o.source,`${e}.source`,n)};if(d(t,o.Min))return{kind:"min",source:f(t,o.source,`${e}.source`,n)};if(d(t,o.Max))return{kind:"max",source:f(t,o.source,`${e}.source`,n)};if(d(t,o.Average))return{kind:"average",source:f(t,o.source,`${e}.source`,n)};if(d(t,o.ForEach))return{kind:"for-each",source:f(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),emit:f(t,o.emit,`${e}.emit`,n)};if(d(t,o.ListMap))return{kind:"list-map",source:f(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),mapBody:f(t,o.mapBody,`${e}.mapBody`,n)};if(d(t,o.Filter))return{kind:"filter",source:f(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),predicate:f(t,o.predicate,`${e}.predicate`,n)};if(d(t,o.PartitionBy))return{kind:"partition-by",source:f(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),partitionKey:f(t,o.partitionKey,`${e}.partitionKey`,n)};if(d(t,o.DistinctBy))return{kind:"distinct-by",source:f(t,o.source,`${e}.source`,n),loopVar:j(t,o.loopVar,e),distinctKey:f(t,o.distinctKey,`${e}.distinctKey`,n)};if(d(t,o.AllStatements))return{kind:"all-statements",source:f(t,o.statementsOf,`${e}.statementsOf`,n)};if(d(t,o.StatementPredicate))return{kind:"statement-predicate",source:f(t,o.predicateOf,`${e}.predicateOf`,n)};if(d(t,o.StatementValue))return{kind:"statement-value",source:f(t,o.valueOf,`${e}.valueOf`,n)};if(d(t,o.DateFormat))return{kind:"date-format",source:f(t,o.dateSource,`${e}.dateSource`,n),format:tn(t,e)};if(d(t,o.Add))return{kind:"add",left:f(t,o.arithLeft,`${e}.arithLeft`,n),right:f(t,o.arithRight,`${e}.arithRight`,n)};if(d(t,o.Subtract))return{kind:"subtract",left:f(t,o.arithLeft,`${e}.arithLeft`,n),right:f(t,o.arithRight,`${e}.arithRight`,n)};if(d(t,o.Multiply))return{kind:"multiply",left:f(t,o.arithLeft,`${e}.arithLeft`,n),right:f(t,o.arithRight,`${e}.arithRight`,n)};if(d(t,o.Divide))return{kind:"divide",left:f(t,o.arithLeft,`${e}.arithLeft`,n),right:f(t,o.arithRight,`${e}.arithRight`,n)};if(d(t,o.Reverse))return{kind:"reverse",source:f(t,o.source,`${e}.source`,n)};if(d(t,o.WindowedMap)){let r=et(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:f(t,o.source,`${e}.source`,n),windowSize:r,windowVar:j(t,o.windowVar,e),windowBody:f(t,o.windowBody,`${e}.windowBody`,n)}}if(d(t,o.PairwiseMap))return{kind:"pairwise-map",source:f(t,o.source,`${e}.source`,n),firstVar:j(t,o.firstVar,e),secondVar:j(t,o.secondVar,e),pairBody:f(t,o.pairBody,`${e}.pairBody`,n)};if(d(t,o.Scan))return{kind:"scan",source:f(t,o.source,`${e}.source`,n),initialState:f(t,o.initialState,`${e}.initialState`,n),stateVar:j(t,o.stateVar,e),elementVar:j(t,o.elementVar,e),accumulate:f(t,o.accumulate,`${e}.accumulate`,n)};if(d(t,o.ListItemAt))return{kind:"list-item-at",source:f(t,o.source,`${e}.source`,n),itemIndex:f(t,o.itemIndex,`${e}.itemIndex`,n)};if(d(t,o.Equals))return{kind:"equals",left:f(t,o.compareLeft,`${e}.compareLeft`,n),right:f(t,o.compareRight,`${e}.compareRight`,n)};if(d(t,o.GreaterThan))return{kind:"greater-than",left:f(t,o.compareLeft,`${e}.compareLeft`,n),right:f(t,o.compareRight,`${e}.compareRight`,n)};if(d(t,o.LessThan))return{kind:"less-than",left:f(t,o.compareLeft,`${e}.compareLeft`,n),right:f(t,o.compareRight,`${e}.compareRight`,n)};if(d(t,o.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:f(t,o.compareLeft,`${e}.compareLeft`,n),right:f(t,o.compareRight,`${e}.compareRight`,n)};if(d(t,o.LessThanOrEqual))return{kind:"less-than-or-equal",left:f(t,o.compareLeft,`${e}.compareLeft`,n),right:f(t,o.compareRight,`${e}.compareRight`,n)};if(d(t,o.Not))return{kind:"not",operand:f(t,o.operand,`${e}.operand`,n)};if(d(t,o.And))return{kind:"and",operands:we(t,o.operands,`${e}.operands`,n)};if(d(t,o.Or))return{kind:"or",operands:we(t,o.operands,`${e}.operands`,n)};if(d(t,o.Contains))return{kind:"contains",haystack:f(t,o.haystack,`${e}.haystack`,n),needle:f(t,o.needle,`${e}.needle`,n)};if(d(t,o.Abs))return{kind:"abs",value:f(t,o.value,`${e}.value`,n)};if(d(t,o.Negate))return{kind:"negate",value:f(t,o.value,`${e}.value`,n)};if(d(t,o.IsReference))return{kind:"is-reference",check:f(t,o.kindCheck,`${e}.kindCheck`,n)};if(d(t,o.IsEmbedded))return{kind:"is-embedded",check:f(t,o.kindCheck,`${e}.kindCheck`,n)};if(d(t,o.IsList))return{kind:"is-list",check:f(t,o.kindCheck,`${e}.kindCheck`,n)};if(d(t,o.StatementObject))return{kind:"statement-object",source:f(t,o.statementSource,`${e}.statementSource`,n)};if(d(t,o.Let))return{kind:"let",bindName:j(t,o.letName,e),bindValue:f(t,o.letValue,`${e}.letValue`,n),body:f(t,o.letBody,`${e}.letBody`,n)};if(d(t,o.GetStatementByName))return{kind:"get-statement-by-name",inSubject:f(t,o.inSubject,`${e}.inSubject`,n),byName:f(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 f(t,e,n,r){let i=ie(t,e);if(!i)throw new y("child expression is required",n);return G(i,n,r)}function Zt(t,e,n,r){let i=ie(t,e);if(i)return G(i,n,r)}function we(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 P&&i.push(G(c,`${n}[${a++}]`,r));else u instanceof T&&i.push(G(u.object,`${n}[${a++}]`,r));return i}function Qt(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 P&&r.push(Ge(u,`${e}[${i++}]`,n));else a instanceof T&&r.push(Ge(a.object,`${e}[${i++}]`,n));return r}function Ge(t,e,n){return{field:M(t,o.field,e,"field"),value:f(t,o.bindValue,`${e}.bindValue`,n)}}function xt(t,e){let n=O(t,o.normKind);if(!n)throw new y("normKind is required",e);if(b(n,o.NORM_TRIM_END))return"trim-end";throw new y(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}function en(t,e){let n=O(t,o.renderFormat);if(!n)throw new y("renderFormat is required",e);if(b(n,o.RENDER_HTML))return"html";if(b(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 tn(t,e){let n=z(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 nn(t,e,n){let r=O(t,o.fragmentRef);if(!r)throw new y("fragmentRef is required",e);if(!on(n.catalog,r))throw new y(`ExpressionFragment not found: ${r.publisher}/${r.package_}/${r.name}`,e);return{kind:"call-fragment",fragmentKey:rn(r)}}function rn(t){return`${t.publisher}/${t.package_}/${t.name}`}function an(t){let e=new Map,n=[];for(let r of t){if(!(r instanceof S)||!d(r,o.ExpressionFragment))continue;let i=ie(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=G(r.bodyEmb,`fragment(${r.pubPkgName})`,{catalog:t,depth:0});e.set(r.key,i)}return e}function on(t,e){for(let n of t)if(!(!(n instanceof S)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&d(n,o.ExpressionFragment))return n}function Qe(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 h&&n.add(i.subject.name);if(n.size===0)throw new y("outputs is required (at least one OutputFormat)",e);return n}function xe(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 P){let[c,l]=Je(u,`${e}[${i++}]`);r.set(c,l)}}else if(a instanceof T){let[u,c]=Je(a.object,`${e}[${i++}]`);r.set(u,c)}return r}function Je(t,e){let n=O(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 R)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 P){let m=z(l,o.fromKey),g=z(l,o.toKey);m&&g&&i.set(m,g)}}else if(c instanceof T){let l=c.object,m=z(l,o.fromKey),g=z(l,o.toKey);m&&g&&i.set(m,g)}let a=be(t,o.trailingNewline),u=be(t,o.omitWrapper);return[n.name,{metadataKeys:r.length>0?r:void 0,metadataRenames:i,trailingNewline:a,omitWrapper:u}]}function sn(t){return t.predicate?.subject}function A(t,e){let n=[];for(let r of t.statement){let i=sn(r);i&&b(i,e)&&n.push(r)}return n}function ie(t,e){for(let n of A(t,e))if(n instanceof T)return n.object}function O(t,e){for(let n of A(t,e))if(n instanceof V)return Se(n.object.subject)}function z(t,e){for(let n of A(t,e))if(n instanceof R)return n.object}function et(t,e){for(let n of A(t,e))if(n instanceof L)return n.object}function be(t,e){for(let n of A(t,e))if(n instanceof B)return n.object}function j(t,e,n){let r=z(t,e);if(r===void 0)throw new y(`${e.name} (string) is required`,n);return r}function Ye(t,e,n){let r=et(t,e);if(r===void 0)throw new y(`${e.name} (number) is required`,n);return r}function un(t,e,n){let r=be(t,e);if(r===void 0)throw new y(`${e.name} (boolean) is required`,n);return r}function M(t,e,n,r){let i=O(t,e);if(!i)throw new y(`${r} (URI reference) is required`,n);return i}function Se(t){return{publisher:t.publisher,package_:t.package_,name:t.name}}var cn={publisher:"kanonak.org",package_:"core-rdf",name:"label"},U=class extends Error{},de=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 U(`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 tt(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 tt(r)}case"property-read":{let r=await this.evaluate(e.source,n);return fe(r,e.readProp)}case"traverse":{let r=await this.evaluate(e.source,n);if(!(r instanceof D))return;let i=fn(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(ae(m))}return a.join("")}case"uri-name":{let r=await this.evaluate(e.source,n);return X(r)?r.name:r instanceof h?r.subject.name:r instanceof S?r.name:r instanceof P?r.name??"":void 0}case"uri-publisher":{let r=await this.evaluate(e.source,n);return $e(r)?.publisher}case"uri-package":{let r=await this.evaluate(e.source,n);return $e(r)?.package_}case"uri-version":{let r=await this.evaluate(e.source,n);return $e(r)?.version}case"subject-uri":{let r=await this.evaluate(e.source,n);if(r instanceof S){let i=r.namespace??"",a=r.name??"";return!i||!a?void 0:`${i}/${a}`}if(r instanceof h){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?fe(r,e.labelSource):void 0}case"resolve-ref":{let r=await this.evaluate(e.source,n);return r instanceof S?r:r instanceof h?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?"":ae(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 D))return;let i;for(let u of r.statement){let c=ve(u);if(c&&b(c,e.readProp)){i=u;break}}if(!(i instanceof Re)){let u=fe(r,e.readProp);return u==null?void 0:ae(u)}let a=await this.renderMarkdownLinks(i);return e.format==="html"?Q(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;mn.has(u)&&(Array.isArray(a)&&a.every(c=>nt(c))?a=a.map(c=>String(c)).join(""):nt(a)&&(a=String(a))),r[u]=a}return r}case"call-fragment":{let r=this.fragments.get(e.fragmentKey);if(!r)throw new U(`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?"":ae(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 U("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 U("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 U("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,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,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,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,u);let l=await this.evaluate(e.partitionKey,c),m=at(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,u);let l=await this.evaluate(e.distinctKey,c),m=at(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 D?r.statement:[]}case"statement-predicate":{let r=await this.evaluate(e.source,n);if(Ee(r)){let i=r.predicate;if(i instanceof h)return i}return}case"statement-value":{let r=await this.evaluate(e.source,n);return Ee(r)?yn(r):void 0}case"date-format":{let r=await this.evaluate(e.source,n),i=r==null?"":ae(r);return i?gn(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 U("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,r[a]),u.set(e.secondVar,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,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 rt(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(rt(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 h||r instanceof S}case"is-embedded":return await this.evaluate(e.check,n)instanceof P;case"is-list":{let r=await this.evaluate(e.check,n);return Array.isArray(r)}case"statement-object":{let r=await this.evaluate(e.source,n);if(!Ee(r))return;let i=r;return i instanceof R||i instanceof L||i instanceof B||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 D)||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 U("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=fe(n,cn);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,r[a-1]),u.set(e.secondVar,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,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,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 fe(t,e){if(t instanceof D)return ln(t,e);if(dn(t))return b(e,o.key)?t.key:b(e,o.members)?t.members:void 0}function ln(t,e){for(let n of t.statement){let r=ve(n);if(!(!r||!b(r,e))&&(n instanceof R||n instanceof L||n instanceof B||n instanceof V||n instanceof T||n instanceof w))return n.object}}function fn(t,e){let n=[];for(let r of t.statement){let i=ve(r);if(!(!i||!b(i,e))){if(r instanceof V)n.push(r.object.subject);else if(r instanceof w)for(let a of r.object)a instanceof h&&n.push(a.subject)}}return n}function ve(t){return t.predicate?.subject}function ae(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(t instanceof D)return t.name??"";if(t instanceof h)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 tt(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 dn(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 U(`${e} requires numeric elements; got ${pn(t)}`)}function $e(t){if(t instanceof S){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 h){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 mn=new Set(["stringValue","text","rawContent","key","propertyKey","linkLabel"]);function nt(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function pn(t){return t===void 0?"undefined":t===null?"null":Array.isArray(t)?`array(${t.length})`:typeof t}function gn(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 rt(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=it(t),c=it(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 it(t){if(t instanceof h){let e=t.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}if(t instanceof S){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 Ee(t){return t instanceof R||t instanceof L||t instanceof B||t instanceof V||t instanceof T||t instanceof w}function yn(t){return t instanceof R||t instanceof L||t instanceof B?String(t.object??""):t instanceof V?t.object?.subject?.name??"":t instanceof T?"[embedded]":t instanceof w?(t.object??[]).map(n=>{if(n instanceof h)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 at(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 h){let e=t.subject;return`r:${e.publisher}/${e.package_}/${e.name}`}if(t instanceof D){let e=t.name??"";return`k:${t.namespace??""}/${e}`}return X(t)?`u:${t.publisher}/${t.package_}/${t.name}`:`o:${JSON.stringify(t)}`}var kn={"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"}},N=class extends Error{},me=class{backends=new Map;constructor(){this.register(new J),this.register(new Y),this.register(new Z),this.register(new x),this.register(new ee),this.register(new te),this.register(new ne)}register(e){this.backends.set(e.backendUri,e)}async run(e){let n=e.transformationKanonaks??e.allKanonaks,r=le(e.transformation,n);if(!r.outputs.has(e.outputFormat))throw new N(`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 N(`No backend registered for OutputFormat "${e.outputFormat}".`);let a=new re(e.repository,e.parser,e.objectParser),u=new de(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=ot(n.instances,e.inputPattern.requires),u=st(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);je(g,e.name,`input "${l.name}"`);let k=Ve(await i.evaluate(e.artifactName,m),e.name,`input "${l.name}"`),K=Ae(e.overrides.get(n.outputFormat),n.runtimeOverride),v=r.render(g,K);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=ot(n.instances,e.inputPattern.requires),u=st(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);je(c,e.name,"set");let l=Ve(await a.evaluate(e.artifactName,u),e.name,"set"),m=Ae(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=bn(g,u);if(k==null)continue;let K=Sn(k),v=c.get(K);v||(v={keyValue:k,keyDisplay:$n(k),members:[]},c.set(K,v),l.push(K)),v.members.push(g)}let m=[];for(let g of l){let k=c.get(g),K=new Map;K.set("inputs",k.members),K.set("key",k.keyValue);let v=await a.evaluate(e.rule,K);je(v,e.name,`partition "${k.keyDisplay}"`);let ft=Ve(await a.evaluate(e.artifactName,K),e.name,`partition "${k.keyDisplay}"`),dt=Ae(e.overrides.get(r.outputFormat),r.runtimeOverride),mt=i.render(v,dt);m.push({fileName:ft,format:r.outputFormat,content:mt,source:{kind:"set",memberCount:k.members.length,partitionKey:k.keyDisplay}})}return m}findBackend(e){let n=kn[e];if(n)return this.backends.get(n.formatUri)}};function ot(t,e){return e.length===0?t:t.filter(n=>{for(let r of e)if(!wn(n,r))return!1;return!0})}function st(t,e){if(e.length===0)return t;let n=[...t];return n.sort((r,i)=>{for(let a of e){let u=ut(r,a.byProperty),c=ut(i,a.byProperty),l=hn(u,c,a.order);if(l!==0)return l}return 0}),n}function ut(t,e){for(let n of t.statement){let r=Ke(n);if(!(!r||!b(r,e))){if(n instanceof R||n instanceof L||n instanceof B)return n.object;if(n instanceof w)throw new N(`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 N(`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 hn(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 wn(t,e){for(let n of t.statement){let r=Ke(n);if(!r||!b(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 bn(t,e){for(let n of t.statement){let r=Ke(n);if(!(!r||!b(r,e))&&(n instanceof R||n instanceof L||n instanceof B||n instanceof V||n instanceof w))return n.object}}function Ke(t){return t.predicate?.subject}function Sn(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 h){let e=t.subject;return`r:${e.publisher}/${e.package_}/${e.name}`}if(t instanceof D){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 $n(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):t instanceof h?t.subject.name:t instanceof D?t.name??"":typeof t=="object"&&t!==null&&typeof t.name=="string"?t.name:""}function je(t,e,n){if(typeof t!="object"||t===null||t.kind!=="Document")throw new N(`Transformation "${e}" rule did not yield a Document for ${n}. Got: ${ct(t)}`)}function Ve(t,e,n){if(typeof t=="string")return t;if(Array.isArray(t)&&t.every(En))return t.map(r=>String(r)).join("");throw new N(`Transformation "${e}" artifactName did not yield a string for ${n}. Got: ${ct(t)}`)}function En(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function ct(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 Ae(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 _=class extends Error{constructor(n,r){super(n);this.cause=r;this.name="RenderError"}cause},lt={publisher:"kanonak.org",package_:"derivation",name:"default"},Te=class{constructor(e,n=new De,r=new Le){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;runner=new me;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async findDerivation(e){let n=await this.getCatalog(),r=F(n,e.resource);if(!(r instanceof S))return;let i=e.variant??lt;return Ce(r,e.format,i,n)}async render(e){let n=await this.findDerivation(e);if(!n)throw new _(`No derivation found for ${q(e.resource)} \u2192 format ${q(e.format)}`+(e.variant?` variant ${q(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=F(n,e.transformation);if(!(r instanceof S))throw new _(`Transformation not found: ${q(e.transformation)}`);let i=F(n,e.input);if(!(i instanceof S))throw new _(`Input resource not found: ${q(e.input)}`);let a=le(r,n),u=vn(a.outputs,e.format);if(!u)throw new _(`Transformation ${q(e.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${q(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 _(`Transformation execution failed: ${l.message}`,l)}if(c.length===0)throw new _("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 q(t){return`${t.publisher}/${t.package_}/${t.name}`}function vn(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{te as CssBackend,lt as DEFAULT_VARIANT,E as DOCAST,gt as DOCAST_PKG,pt as DOCAST_PUB,de as ExpressionEngineV3,U as ExpressionEvalErrorV3,x as HtmlBackend,Z as JsonBackend,J as MarkdownFrontmatterBackend,re as ReferenceResolver,_ as RenderError,kn as SUPPORTED_FORMATS_V3,ee as SvgBackend,o as TX_V3,Gt as TX_V3_PKG,zt as TX_V3_PUB,Gn as TX_V3_VERSION_MAJOR,Y as TomlBackend,Te as TransformationEngine,y as TransformationLoadErrorV3,N as TransformationRunnerErrorV3,me as TransformationRunnerV3,ne as YamlBackend,le as compileTransformationV3,Q as renderMarkdownToHtml};
103
+ `);return n?.trailingNewline&&a.length>0&&!a.endsWith(`
104
+ `)&&(a+=`
105
+ `),a}};function re(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var ae=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=Je(e.metadata,n),a=JSON.stringify(r,null,2);return n?.trailingNewline&&!a.endsWith(`
106
+ `)&&(a+=`
107
+ `),a}};function Je(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]=Xe(u.value,u.escapeHint)}return{M:a}}function Xe(t,e){switch(t.kind){case"StructuredMap":return Je(t);case"StructuredList":return{L:t.items.map(n=>Xe(n,void 0))};case"StringScalar":return Yt(t.stringValue,e??t.escapeHint);case"IntegerScalar":return xt(t.integerValue,e??t.escapeHint)}}function Yt(t,e){if(e&&re(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&&re(e,h.ESC_DYNAMODB_NULL))return{NULL:!0};if(e&&re(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&&re(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&&re(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 ie=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=F(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 Ce(g,this.repository);c=await this.objectParser.parseKanonaks(k),this.cache.set(u,c)}let l=F(c,e);if(l)return l;for(let m of c)if(m instanceof E&&m.name===e.name)return m}};var Zt="kanonak.org",Qt="transformations",tr=3,s=t=>({publisher:Zt,package_:Qt,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"),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 fe(t,e){let n=t.name,r=dn(e),a={catalog:e,depth:0};if(f(t,o.InstanceTransformation))return en(t,n,a,r);if(f(t,o.SetTransformation))return tn(t,n,a,r);throw new y("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function en(t,e,n,r){return{kind:"instance",name:t.name,inputPattern:tt(t,e),rule:de(t,o.rule,`${e}.rule`,n),artifactName:de(t,o.artifactName,`${e}.artifactName`,n),outputs:nt(t,`${e}.outputs`),overrides:rt(t,`${e}.formatOverrides`,n),fragments:r}}function tn(t,e,n,r){let a=N(t,o.partitionBy);return{kind:"set",name:t.name,inputPattern:tt(t,e),rule:de(t,o.rule,`${e}.rule`,n),artifactName:de(t,o.artifactName,`${e}.artifactName`,n),outputs:nt(t,`${e}.outputs`),overrides:rt(t,`${e}.formatOverrides`,n),partitionBy:a,fragments:r}}function tt(t,e){let n=oe(t,o.inputPattern);if(!n)throw new y("inputPattern is required",e);return nn(n,`${e}.inputPattern`)}function nn(t,e){let n=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($e(u.object.subject));else if(u instanceof w)for(let c of u.object)c instanceof b&&r.push($e(c.subject));let a=[],i=0;for(let u of A(t,o.sortBy))if(u instanceof w)for(let c of u.object)c instanceof O&&a.push(Ye(c,`${e}.sortBy[${i++}]`));else u instanceof K&&a.push(Ye(u.object,`${e}.sortBy[${i++}]`));return{matchesClass:n,requires:r,sortBy:a}}function Ye(t,e){let n=N(t,o.byProperty);if(!n)throw new y("SortKey.byProperty is required",e);let r=N(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 de(t,e,n,r){let a=oe(t,e);if(!a)throw new y("expression is required",n);return G(a,n,r)}function G(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:et(t,o.integerLiteral,e)};if(f(t,o.DecimalLiteral))return{kind:"decimal-literal",value:et(t,o.decimalLiteral,e)};if(f(t,o.BooleanLiteral))return{kind:"boolean-literal",value:pn(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:an(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:rn(t,o.elseBuild,`${e}.elseBuild`,n)};if(f(t,o.Concat))return{kind:"concat",parts:Se(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:on(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:sn(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 cn(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:un(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:Se(t,o.operands,`${e}.operands`,n)};if(f(t,o.Or))return{kind:"or",operands:Se(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.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=oe(t,e);if(!a)throw new y("child expression is required",n);return G(a,n,r)}function rn(t,e,n,r){let a=oe(t,e);if(a)return G(a,n,r)}function Se(t,e,n,r){let a=[],i=0;for(let u of A(t,e))if(u instanceof w)for(let c of u.object)c instanceof O&&a.push(G(c,`${n}[${i++}]`,r));else u instanceof K&&a.push(G(u.object,`${n}[${i++}]`,r));return a}function an(t,e,n){let r=[],a=0;for(let i of A(t,o.set))if(i instanceof w)for(let u of i.object)u instanceof O&&r.push(xe(u,`${e}[${a++}]`,n));else i instanceof K&&r.push(xe(i.object,`${e}[${a++}]`,n));return r}function xe(t,e,n){return{field:P(t,o.field,e,"field"),value:d(t,o.bindValue,`${e}.bindValue`,n)}}function on(t,e){let n=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 sn(t,e){let n=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 Ze=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function un(t,e){let n=z(t,o.dateFormat);if(!n)throw new y("dateFormat is required",e);if(!Ze.has(n))throw new y(`Unknown dateFormat "${n}"; supported: ${[...Ze].join(", ")}`,e);return n}function cn(t,e,n){let r=N(t,o.fragmentRef);if(!r)throw new y("fragmentRef is required",e);if(!fn(n.catalog,r))throw new y(`ExpressionFragment not found: ${r.publisher}/${r.package_}/${r.name}`,e);return{kind:"call-fragment",fragmentKey:ln(r)}}function ln(t){return`${t.publisher}/${t.package_}/${t.name}`}function dn(t){let e=new Map,n=[];for(let r of t){if(!(r instanceof E)||!f(r,o.ExpressionFragment))continue;let a=oe(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=G(r.bodyEmb,`fragment(${r.pubPkgName})`,{catalog:t,depth:0});e.set(r.key,a)}return e}function fn(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 nt(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 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 rt(t,e,n){let r=new Map,a=0;for(let i of A(t,o.formatOverrides))if(i instanceof w){for(let u of i.object)if(u instanceof O){let[c,l]=Qe(u,`${e}[${a++}]`);r.set(c,l)}}else if(i instanceof K){let[u,c]=Qe(i.object,`${e}[${a++}]`);r.set(u,c)}return r}function Qe(t,e){let n=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 B)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 a=new Map;for(let c of A(t,o.metadataRenames))if(c instanceof w){for(let l of c.object)if(l instanceof O){let m=z(l,o.fromKey),g=z(l,o.toKey);m&&g&&a.set(m,g)}}else if(c instanceof K){let l=c.object,m=z(l,o.fromKey),g=z(l,o.toKey);m&&g&&a.set(m,g)}let i=Ee(t,o.trailingNewline),u=Ee(t,o.omitWrapper);return[n.name,{metadataKeys:r.length>0?r:void 0,metadataRenames:a,trailingNewline:i,omitWrapper:u}]}function mn(t){return t.predicate?.subject}function A(t,e){let n=[];for(let r of t.statement){let a=mn(r);a&&S(a,e)&&n.push(r)}return n}function oe(t,e){for(let n of A(t,e))if(n instanceof K)return n.object}function N(t,e){for(let n of A(t,e))if(n instanceof V)return $e(n.object.subject)}function z(t,e){for(let n of A(t,e))if(n instanceof B)return n.object}function at(t,e){for(let n of A(t,e))if(n instanceof L)return n.object}function Ee(t,e){for(let n of A(t,e))if(n instanceof R)return n.object}function j(t,e,n){let r=z(t,e);if(r===void 0)throw new y(`${e.name} (string) is required`,n);return r}function et(t,e,n){let r=at(t,e);if(r===void 0)throw new y(`${e.name} (number) is required`,n);return r}function pn(t,e,n){let r=Ee(t,e);if(r===void 0)throw new y(`${e.name} (boolean) is required`,n);return r}function P(t,e,n,r){let a=N(t,e);if(!a)throw new y(`${r} (URI reference) is required`,n);return a}function $e(t){return{publisher:t.publisher,package_:t.package_,name:t.name}}var gn={publisher:"kanonak.org",package_:"core-rdf",name:"label"},C=class extends Error{},pe=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 C(`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 it(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 it(r)}case"property-read":{let r=await this.evaluate(e.source,n);return me(r,e.readProp)}case"traverse":{let r=await this.evaluate(e.source,n);if(!(r instanceof T))return;let a=kn(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(se(m))}return i.join("")}case"uri-name":{let r=await this.evaluate(e.source,n);return J(r)?r.name:r instanceof b?r.subject.name:r instanceof E?r.name:r instanceof O?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 E){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?me(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):J(r)?await this.resolver.resolveSubject(r,this.catalog):void 0}case"normalize":{let r=await this.evaluate(e.source,n),a=r==null?"":se(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 T))return;let a;for(let u of r.statement){let c=Ve(u);if(c&&S(c,e.readProp)){a=u;break}}if(!(a instanceof Re)){let u=me(r,e.readProp);return u==null?void 0:se(u)}let i=await this.renderMarkdownLinks(a);return e.format==="html"?Z(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;bn.has(u)&&(Array.isArray(i)&&i.every(c=>ot(c))?i=i.map(c=>String(c)).join(""):ot(i)&&(i=String(i))),r[u]=i}return r}case"call-fragment":{let r=this.fragments.get(e.fragmentKey);if(!r)throw new C(`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?"":se(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 C("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 C("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 C("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,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,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,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,u);let l=await this.evaluate(e.partitionKey,c),m=ct(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,u);let l=await this.evaluate(e.distinctKey,c),m=ct(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 T?r.statement:[]}case"statement-predicate":{let r=await this.evaluate(e.source,n);if(je(r)){let a=r.predicate;if(a instanceof b)return a}return}case"statement-value":{let r=await this.evaluate(e.source,n);return je(r)?En(r):void 0}case"date-format":{let r=await this.evaluate(e.source,n),a=r==null?"":se(r);return a?Sn(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 C("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,r[i]),u.set(e.secondVar,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,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 st(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(st(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 E}case"is-embedded":return await this.evaluate(e.check,n)instanceof O;case"is-list":{let r=await this.evaluate(e.check,n);return Array.isArray(r)}case"statement-object":{let r=await this.evaluate(e.source,n);if(!je(r))return;let a=r;return a instanceof B||a instanceof L||a instanceof R||a instanceof V||a instanceof K||a instanceof w?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 T)||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 C("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}](${M(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=me(n,gn);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,r[i-1]),u.set(e.secondVar,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,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,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 me(t,e){if(t instanceof T)return yn(t,e);if(hn(t))return S(e,o.key)?t.key:S(e,o.members)?t.members:void 0}function yn(t,e){for(let n of t.statement){let r=Ve(n);if(!(!r||!S(r,e))&&(n instanceof B||n instanceof L||n instanceof R||n instanceof V||n instanceof K||n instanceof w))return n.object}}function kn(t,e){let n=[];for(let r of t.statement){let a=Ve(r);if(!(!a||!S(a,e))){if(r instanceof V)n.push(r.object.subject);else if(r instanceof w)for(let i of r.object)i instanceof b&&n.push(i.subject)}}return n}function Ve(t){return t.predicate?.subject}function se(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(t instanceof T)return t.name??"";if(t instanceof b)return t.subject.name;if(J(t))return t.name;let e=t.value;return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function it(t){return t==null?!1:typeof t=="string"||Array.isArray(t)?t.length>0:typeof t=="boolean"?t===!0:!0}function J(t){return typeof t=="object"&&t!==null&&typeof t.publisher=="string"&&typeof t.package_=="string"&&typeof t.name=="string"}function hn(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 C(`${e} requires numeric elements; got ${wn(t)}`)}function ve(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(J(t))return{publisher:t.publisher,package_:t.package_,version:"",name:t.name}}var bn=new Set(["stringValue","text","rawContent","key","propertyKey","linkLabel"]);function ot(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function wn(t){return t===void 0?"undefined":t===null?"null":Array.isArray(t)?`array(${t.length})`:typeof t}function Sn(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 st(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=ut(t),c=ut(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 ut(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 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(J(t))return{publisher:t.publisher,package_:t.package_,name:t.name}}function je(t){return t instanceof B||t instanceof L||t instanceof R||t instanceof V||t instanceof K||t instanceof w}function En(t){return t instanceof B||t instanceof L||t instanceof R?String(t.object??""):t instanceof V?t.object?.subject?.name??"":t instanceof K?"[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 a=n.value;return typeof a=="string"||typeof a=="number"||typeof a=="boolean"?String(a):"[embedded]"}).join(", "):""}function ct(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 T){let e=t.name??"";return`k:${t.namespace??""}/${e}`}return J(t)?`u:${t.publisher}/${t.package_}/${t.name}`:`o:${JSON.stringify(t)}`}var $n={"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"}},I=class extends Error{},ge=class{backends=new Map;constructor(){this.register(new X),this.register(new Y),this.register(new x),this.register(new Q),this.register(new ee),this.register(new te),this.register(new ne),this.register(new ae)}register(e){this.backends.set(e.backendUri,e)}async run(e){let n=e.transformationKanonaks??e.allKanonaks,r=fe(e.transformation,n);if(!r.outputs.has(e.outputFormat))throw new I(`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 I(`No backend registered for OutputFormat "${e.outputFormat}".`);let i=new ie(e.repository,e.parser,e.objectParser),u=new pe(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=lt(n.instances,e.inputPattern.requires),u=dt(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);Ae(g,e.name,`input "${l.name}"`);let k=De(await a.evaluate(e.artifactName,m),e.name,`input "${l.name}"`),D=Ke(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=lt(n.instances,e.inputPattern.requires),u=dt(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);Ae(c,e.name,"set");let l=De(await i.evaluate(e.artifactName,u),e.name,"set"),m=Ke(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=Vn(g,u);if(k==null)continue;let D=An(k),v=c.get(D);v||(v={keyValue:k,keyDisplay:Dn(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);Ae(v,e.name,`partition "${k.keyDisplay}"`);let gt=De(await i.evaluate(e.artifactName,D),e.name,`partition "${k.keyDisplay}"`),yt=Ke(e.overrides.get(r.outputFormat),r.runtimeOverride),kt=a.render(v,yt);m.push({fileName:gt,format:r.outputFormat,content:kt,source:{kind:"set",memberCount:k.members.length,partitionKey:k.keyDisplay}})}return m}findBackend(e){let n=$n[e];if(n)return this.backends.get(n.formatUri)}};function lt(t,e){return e.length===0?t:t.filter(n=>{for(let r of e)if(!jn(n,r))return!1;return!0})}function dt(t,e){if(e.length===0)return t;let n=[...t];return n.sort((r,a)=>{for(let i of e){let u=ft(r,i.byProperty),c=ft(a,i.byProperty),l=vn(u,c,i.order);if(l!==0)return l}return 0}),n}function ft(t,e){for(let n of t.statement){let r=Te(n);if(!(!r||!S(r,e))){if(n instanceof B||n instanceof L||n instanceof R)return n.object;if(n instanceof w)throw new I(`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 I(`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 jn(t,e){for(let n of t.statement){let r=Te(n);if(!r||!S(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 Vn(t,e){for(let n of t.statement){let r=Te(n);if(!(!r||!S(r,e))&&(n instanceof B||n instanceof L||n instanceof R||n instanceof V||n instanceof w))return n.object}}function Te(t){return t.predicate?.subject}function An(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 T){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 Dn(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):t instanceof b?t.subject.name:t instanceof T?t.name??"":typeof t=="object"&&t!==null&&typeof t.name=="string"?t.name:""}function Ae(t,e,n){if(typeof t!="object"||t===null||t.kind!=="Document")throw new I(`Transformation "${e}" rule did not yield a Document for ${n}. Got: ${mt(t)}`)}function De(t,e,n){if(typeof t=="string")return t;if(Array.isArray(t)&&t.every(Kn))return t.map(r=>String(r)).join("");throw new I(`Transformation "${e}" artifactName did not yield a string for ${n}. Got: ${mt(t)}`)}function Kn(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function mt(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 Ke(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 _=class extends Error{constructor(n,r){super(n);this.cause=r;this.name="RenderError"}cause},pt={publisher:"kanonak.org",package_:"derivation",name:"default"},Be=class{constructor(e,n=new Le,r=new Ue){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;runner=new ge;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async findDerivation(e){let n=await this.getCatalog(),r=F(n,e.resource);if(!(r instanceof E))return;let a=e.variant??pt;return Oe(r,e.format,a,n)}async render(e){let n=await this.findDerivation(e);if(!n)throw new _(`No derivation found for ${q(e.resource)} \u2192 format ${q(e.format)}`+(e.variant?` variant ${q(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=F(n,e.transformation);if(!(r instanceof E))throw new _(`Transformation not found: ${q(e.transformation)}`);let a=F(n,e.input);if(!(a instanceof E))throw new _(`Input resource not found: ${q(e.input)}`);let i=fe(r,n),u=Tn(i.outputs,e.format);if(!u)throw new _(`Transformation ${q(e.transformation)} declares outputs [${[...i.outputs].join(", ")}], none of which corresponds to format ${q(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 _(`Transformation execution failed: ${l.message}`,l)}if(c.length===0)throw new _("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 q(t){return`${t.publisher}/${t.package_}/${t.name}`}function Tn(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{te as CssBackend,pt as DEFAULT_VARIANT,h as DOCAST,bt as DOCAST_PKG,ht as DOCAST_PUB,ae as DynamoDbBackend,pe as ExpressionEngineV3,C as ExpressionEvalErrorV3,Q as HtmlBackend,x as JsonBackend,X as MarkdownFrontmatterBackend,ie as ReferenceResolver,_ as RenderError,$n as SUPPORTED_FORMATS_V3,ee as SvgBackend,o as TX_V3,Qt as TX_V3_PKG,Zt as TX_V3_PUB,tr as TX_V3_VERSION_MAJOR,Y as TomlBackend,Be as TransformationEngine,y as TransformationLoadErrorV3,I as TransformationRunnerErrorV3,ge as TransformationRunnerV3,ne as YamlBackend,fe as compileTransformationV3,Z as renderMarkdownToHtml};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.17.0",
3
+ "version": "3.19.0",
4
4
  "description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -113,7 +113,7 @@
113
113
  "yaml-parser"
114
114
  ],
115
115
  "dependencies": {
116
- "@kanonak-protocol/types": "^3.17.0",
116
+ "@kanonak-protocol/types": "^3.19.0",
117
117
  "ignore": "^7.0.5",
118
118
  "js-yaml": "^4.1.0",
119
119
  "yaml": "^2.7.0"