@kanonak-protocol/sdk 3.12.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/transformations/DocAst.d.ts +46 -3
- package/dist/transformations/DocAstUriConstants.d.ts +6 -0
- package/dist/transformations/TransformationEngine.d.ts +11 -0
- package/dist/transformations/backends/CssBackend.d.ts +7 -0
- package/dist/transformations/index.d.ts +1 -0
- package/dist/transformations/index.js +43 -30
- package/dist/transformations/v3/CompiledTransformationV3.d.ts +37 -3
- package/dist/transformations/v3/ExpressionEngineV3.d.ts +15 -1
- package/dist/transformations/v3/TransformationRunnerV3.d.ts +10 -0
- package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +7 -0
- package/package.json +2 -2
|
@@ -22,7 +22,7 @@ export interface DocAstDocument {
|
|
|
22
22
|
metadata?: DocAstStructuredMap;
|
|
23
23
|
children: DocAstBlock[];
|
|
24
24
|
}
|
|
25
|
-
export type DocAstBlock = DocAstHeading | DocAstParagraph | DocAstRawBlock | DocAstPropertyList;
|
|
25
|
+
export type DocAstBlock = DocAstHeading | DocAstParagraph | DocAstRawBlock | DocAstPropertyList | DocAstTable;
|
|
26
26
|
export interface DocAstHeading {
|
|
27
27
|
kind: 'Heading';
|
|
28
28
|
level: number;
|
|
@@ -48,7 +48,7 @@ export interface DocAstRawBlock {
|
|
|
48
48
|
mediaType?: EntityUri;
|
|
49
49
|
rawContent: string;
|
|
50
50
|
}
|
|
51
|
-
export type DocAstInline = DocAstText | DocAstResourceLink;
|
|
51
|
+
export type DocAstInline = DocAstText | DocAstResourceLink | DocAstBadge;
|
|
52
52
|
export interface DocAstText {
|
|
53
53
|
kind: 'Text';
|
|
54
54
|
text: string;
|
|
@@ -61,12 +61,31 @@ export interface DocAstText {
|
|
|
61
61
|
* rdfs.Resource` to it. Backends serialize the target's canonical
|
|
62
62
|
* URI via the reference's `subject` field. `linkLabel` is optional;
|
|
63
63
|
* when absent backends derive a label from the target's
|
|
64
|
-
* `rdfs.label` / `rdfs.comment` / local name.
|
|
64
|
+
* `rdfs.label` / `rdfs.comment` / local name. `linkTooltip` (1.2.0)
|
|
65
|
+
* populates the hover tooltip — `title=` in HTML, link-title in
|
|
66
|
+
* Markdown — typically the target's `rdfs.comment`.
|
|
65
67
|
*/
|
|
66
68
|
export interface DocAstResourceLink {
|
|
67
69
|
kind: 'ResourceLink';
|
|
68
70
|
target: unknown;
|
|
69
71
|
linkLabel?: string | undefined;
|
|
72
|
+
linkTooltip?: string | undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Small styled inline annotation (docast 1.2.0). Renders next to its
|
|
76
|
+
* surrounding inline content as a chip — the natural shape for type
|
|
77
|
+
* tags next to a resource heading, status pills, etc. `badgeTarget`
|
|
78
|
+
* is optional; when set, the badge is clickable (same target shape
|
|
79
|
+
* as `ResourceLink.target`). HTML backends render as
|
|
80
|
+
* `<span class="kan-badge">` (with an inner anchor when targeted);
|
|
81
|
+
* Markdown backends render as the link form, or the bare label when
|
|
82
|
+
* untargeted, so the text round-trips through plaintext readers.
|
|
83
|
+
*/
|
|
84
|
+
export interface DocAstBadge {
|
|
85
|
+
kind: 'Badge';
|
|
86
|
+
badgeLabel: string;
|
|
87
|
+
badgeTarget?: unknown;
|
|
88
|
+
badgeTooltip?: string | undefined;
|
|
70
89
|
}
|
|
71
90
|
/**
|
|
72
91
|
* Definition-list block: ordered (key, value) rows where each value
|
|
@@ -88,6 +107,30 @@ export interface DocAstPropertyEntry {
|
|
|
88
107
|
* dispatch on each item's `kind`.
|
|
89
108
|
*/
|
|
90
109
|
propertyValue: Array<DocAstInline | DocAstBlock>;
|
|
110
|
+
/**
|
|
111
|
+
* Optional hover-text for the property key (docast 1.2.0).
|
|
112
|
+
* HTML backends emit on the `<dt>` as `title=`. Conventionally
|
|
113
|
+
* populated by the universal renderer with the predicate's
|
|
114
|
+
* `rdfs.comment`.
|
|
115
|
+
*/
|
|
116
|
+
propertyTooltip?: string | undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Tabular layout (docast 1.2.0). Used by the universal renderer
|
|
120
|
+
* for lists of dict-keyed embeddeds with a consistent shape — the
|
|
121
|
+
* natural rendering for `hasFitnessScore: { fit-quiet: {…},
|
|
122
|
+
* fit-bull: {…} }` style data. The renderer that produces a Table
|
|
123
|
+
* is responsible for keeping the cell count aligned with the
|
|
124
|
+
* column count; backends iterate positionally and don't pad/trim.
|
|
125
|
+
*/
|
|
126
|
+
export interface DocAstTable {
|
|
127
|
+
kind: 'Table';
|
|
128
|
+
tableColumnLabels: string[];
|
|
129
|
+
tableRows: DocAstTableRow[];
|
|
130
|
+
}
|
|
131
|
+
export interface DocAstTableRow {
|
|
132
|
+
kind: 'TableRow';
|
|
133
|
+
tableCells: Array<DocAstInline | DocAstBlock>;
|
|
91
134
|
}
|
|
92
135
|
export type DocAstStructuredValue = DocAstStructuredMap | DocAstStructuredList | DocAstStringScalar | DocAstIntegerScalar;
|
|
93
136
|
export interface DocAstStructuredMap {
|
|
@@ -51,6 +51,7 @@ export declare const DOCAST: {
|
|
|
51
51
|
readonly TEXT_PLAIN: EntityUri;
|
|
52
52
|
readonly TEXT_MARKDOWN: EntityUri;
|
|
53
53
|
readonly TEXT_HTML: EntityUri;
|
|
54
|
+
readonly TEXT_CSS: EntityUri;
|
|
54
55
|
readonly APPLICATION_JSON: EntityUri;
|
|
55
56
|
readonly TEXT_YAML: EntityUri;
|
|
56
57
|
readonly IMAGE_SVG_XML: EntityUri;
|
|
@@ -62,4 +63,9 @@ export declare const DOCAST: {
|
|
|
62
63
|
readonly PropertyEntry: EntityUri;
|
|
63
64
|
readonly propertyKey: EntityUri;
|
|
64
65
|
readonly propertyValue: EntityUri;
|
|
66
|
+
readonly Table: EntityUri;
|
|
67
|
+
readonly tableColumnLabels: EntityUri;
|
|
68
|
+
readonly tableRows: EntityUri;
|
|
69
|
+
readonly TableRow: EntityUri;
|
|
70
|
+
readonly tableCells: EntityUri;
|
|
65
71
|
};
|
|
@@ -57,6 +57,15 @@ export declare class TransformationEngine {
|
|
|
57
57
|
resource: EntityUri;
|
|
58
58
|
format: EntityUri;
|
|
59
59
|
variant?: EntityUri;
|
|
60
|
+
/**
|
|
61
|
+
* Suppress the backend's default chrome (e.g. the HTML backend's
|
|
62
|
+
* `<!DOCTYPE html>...<style>...</style>` wrapper). Useful when
|
|
63
|
+
* embedding the rendered content inside a host that already has
|
|
64
|
+
* its own document shell — the VS Code Browser's webview being
|
|
65
|
+
* the canonical case. Backends without chrome (JSON, plain
|
|
66
|
+
* Markdown) ignore the flag.
|
|
67
|
+
*/
|
|
68
|
+
omitWrapper?: boolean;
|
|
60
69
|
}): Promise<RenderedArtifact>;
|
|
61
70
|
/**
|
|
62
71
|
* Run a specific transformation against a resource. Use when the
|
|
@@ -67,6 +76,8 @@ export declare class TransformationEngine {
|
|
|
67
76
|
transformation: EntityUri;
|
|
68
77
|
input: EntityUri;
|
|
69
78
|
format: EntityUri;
|
|
79
|
+
/** Suppress backend default chrome. See render's omitWrapper. */
|
|
80
|
+
omitWrapper?: boolean;
|
|
70
81
|
}): Promise<RenderedArtifact>;
|
|
71
82
|
private getCatalog;
|
|
72
83
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DocAstDocument } from '../DocAst.js';
|
|
2
|
+
import type { BackendFormatOverride } from '../FormatOverride.js';
|
|
3
|
+
import type { IDocumentAstBackend } from './IDocumentAstBackend.js';
|
|
4
|
+
export declare class CssBackend implements IDocumentAstBackend {
|
|
5
|
+
readonly backendUri = "kanonak.org/transformations/stylesheet";
|
|
6
|
+
render(document: DocAstDocument, override?: BackendFormatOverride): string;
|
|
7
|
+
}
|
|
@@ -15,4 +15,5 @@ export { JsonBackend } from './backends/JsonBackend.js';
|
|
|
15
15
|
export { MarkdownFrontmatterBackend } from './backends/MarkdownFrontmatterBackend.js';
|
|
16
16
|
export { SvgBackend } from './backends/SvgBackend.js';
|
|
17
17
|
export { TomlBackend } from './backends/TomlBackend.js';
|
|
18
|
+
export { CssBackend } from './backends/CssBackend.js';
|
|
18
19
|
export { renderMarkdownToHtml } from './backends/SimpleMarkdownRenderer.js';
|
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as v,c as d,e as N,k as Te}from"../chunk-NPWF35XZ.js";import{a as Ke}from"../chunk-GKQVJITL.js";import"../chunk-7M7XXZOV.js";import{a as P,c as Ae}from"../chunk-CRR4BQKR.js";import{b as L,c as w,d as h,g as D,h as C,i as B,j,k as T,l as b}from"../chunk-W6T7MOKY.js";import{a as Ve}from"../chunk-MYITGTGJ.js";import"../chunk-RGMZAKJV.js";import"../chunk-FUUTGGJS.js";var lt="kanonak.org",ft="document-ast",p=t=>({publisher:lt,package_:ft,name:t}),V={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 De(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=dt(e.metadata,n),i=gt(e.children),u=["---",...r,"---","",i].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
|
-
`)),u}};function
|
|
4
|
+
`)),u}};function dt(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ne(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ne(c),l);let a=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ne),u=[];for(let c of a){let l=n.get(c);if(!l)continue;let m=r.get(c),g=ne(m??c),k=Le(l.value,l.escapeHint);k!==void 0&&u.push(`${g}: ${k}`)}return u}function ne(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Le(t,e){switch(t.kind){case"StringScalar":return mt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let i=Le(r,e);i!==void 0&&n.push(i)}return n.join(", ")}case"StructuredMap":return;default:return}}function mt(t,e){return!e||De(e,V.ESC_RAW)?t:De(e,V.ESC_YAML_SAFE)?pt(t):t}function pt(t){return t.includes(`
|
|
5
5
|
`)?`|-
|
|
6
6
|
${t.replace(/\n/g,`
|
|
7
|
-
`).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(t)?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function
|
|
7
|
+
`).trimEnd()}`:/[:#\[\]{}&*!|>'"%@`,]/.test(t)?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function gt(t){let e=[];for(let n of t){let r=fe(n);r&&e.push(r)}return e.join(`
|
|
8
8
|
|
|
9
|
-
`)}function
|
|
10
|
-
`)?
|
|
11
|
-
|
|
12
|
-
`)
|
|
9
|
+
`)}function fe(t){switch(t.kind){case"Heading":return`${"#".repeat(t.level)} ${re(t.inlines)}`;case"Paragraph":return re(t.inlines);case"RawBlock":return t.rawContent;case"PropertyList":return Ce(t);case"Table":return yt(t);default:return""}}function yt(t){let e=t.tableColumnLabels??[],n=t.tableRows??[];if(e.length===0&&n.length===0)return"";let r=`| ${e.map(le).join(" | ")} |`,i=`| ${e.map(()=>"---").join(" | ")} |`,a=n.map(u=>`| ${(u.tableCells??[]).map(kt).join(" | ")} |`);return[r,i,...a].join(`
|
|
10
|
+
`)}function kt(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?le(re([e])):le(fe(e).replace(/\n+/g," "))}function le(t){return t.replace(/\|/g,"\\|")}function Ce(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=ht(i.propertyValue,e+1);u.includes(`
|
|
11
|
+
`)?r.push(`${a}
|
|
12
|
+
${u}`):r.push(`${a} ${u}`)}return r.join(`
|
|
13
|
+
`)}function ht(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(re([a])):a.kind==="PropertyList"?r.push(Ce(a,e)):r.push(fe(a)))}return r.length===0?n.join(""):n.length===0?r.join(`
|
|
13
14
|
`):`${n.join("")}
|
|
14
15
|
${r.join(`
|
|
15
|
-
`)}`}function
|
|
16
|
+
`)}`}function re(t){let e=[];for(let n of t)n.kind==="Text"?e.push(n.text):n.kind==="ResourceLink"?e.push(bt(n)):n.kind==="Badge"&&e.push(wt(n));return e.join("")}function bt(t){let e=Re(t.target);if(!e)return t.linkLabel??"[unresolved link]";let n=e.version,r=n?`https://${e.publisher}/${e.package_}/${n.major}.${n.minor}.${n.patch}/${e.name}`:`https://${e.publisher}/${e.package_}/${e.name}`,i=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,a=t.linkTooltip?` "${Be(t.linkTooltip)}"`:"";return`[${i}](${r}${a})`}function wt(t){if(!t.badgeTarget)return`*${t.badgeLabel}*`;let e=Re(t.badgeTarget);if(!e)return`*${t.badgeLabel}*`;let n=e.version,r=n?`https://${e.publisher}/${e.package_}/${n.major}.${n.minor}.${n.patch}/${e.name}`:`https://${e.publisher}/${e.package_}/${e.name}`,i=t.badgeTooltip?` "${Be(t.badgeTooltip)}"`:"";return`*[${t.badgeLabel}](${r}${i})*`}function Be(t){return t.replace(/"/g,'\\"')}function Re(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 $t(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var J=class{backendUri="kanonak.org/transformations/toml";render(e,n){let i=St(e.metadata,n).join(`
|
|
16
17
|
`);return n?.trailingNewline&&(i.endsWith(`
|
|
17
18
|
`)||(i+=`
|
|
18
|
-
`)),i}};function
|
|
19
|
+
`)),i}};function St(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=Ue(u.value,u.escapeHint);l!==void 0&&i.push(`${c} = ${l}`)}return i}function Ue(t,e){switch(t.kind){case"StringScalar":return vt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let i=Ue(r,e);i!==void 0&&n.push(i)}return`[${n.join(", ")}]`}case"StructuredMap":return;default:return}}function vt(t,e){return e&&$t(e,V.ESC_TOML_MULTILINE)?jt(t):Et(t)}function Et(t){return`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`}function jt(t){return`"""
|
|
19
20
|
${t.replace(/"""/g,'\\"\\"\\"')}
|
|
20
|
-
"""`}var
|
|
21
|
+
"""`}var Y=class{backendUri="kanonak.org/transformations/json";render(e,n){let r=JSON.stringify(e,null,2);return n?.trailingNewline&&!r.endsWith(`
|
|
21
22
|
`)?r+`
|
|
22
|
-
`:r}};function
|
|
23
|
+
`:r}};function me(t){let e=t.replace(/\r\n/g,`
|
|
23
24
|
`).split(`
|
|
24
|
-
`),n=[],r=0;for(;r<e.length;){let i=e[r];if(i.trim()===""){r++;continue}let
|
|
25
|
-
`)),k=
|
|
26
|
-
${
|
|
25
|
+
`),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=Oe(m.join(`
|
|
26
|
+
`)),k=l?` class="language-${_e(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=q(u[2].trim());n.push(`<h${l}>${m}</h${l}>`),r++;continue}if(i.includes("|")&&r+1<e.length&&Pe(e[r+1])){let l=de(i),m=Vt(e[r+1]);r+=2;let g=[];for(;r<e.length&&e[r].trim()!==""&&e[r].includes("|");)g.push(de(e[r])),r++;n.push(At(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>${q(m.join(" ").trim())}</li>`)}n.push(`<ul>
|
|
27
|
+
${l.join(`
|
|
27
28
|
`)}
|
|
28
|
-
</ul>`);continue}if(/^\s*\d+\.\s+/.test(i)){let
|
|
29
|
-
${
|
|
29
|
+
</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>${q(m.join(" ").trim())}</li>`)}n.push(`<ol>
|
|
30
|
+
${l.join(`
|
|
30
31
|
`)}
|
|
31
|
-
</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&&
|
|
32
|
-
`)}function
|
|
32
|
+
</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&&Pe(e[r+1]));)c.push(e[r]),r++;n.push(`<p>${q(c.join(" "))}</p>`)}return n.join(`
|
|
33
|
+
`)}function Pe(t){return t.includes("-")?/^[\s|:-]+$/.test(t):!1}function de(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 Vt(t){return de(t).map(e=>{let n=e.startsWith(":"),r=e.endsWith(":");return n&&r?"center":r?"right":n?"left":null})}function At(t,e,n){let r=u=>{let c=e[u];return c?` style="text-align:${c}"`:""},i=t.map((u,c)=>`<th${r(c)}>${q(u)}</th>`).join(""),a=n.map(u=>`<tr>${u.map((l,m)=>`<td${r(m)}>${q(l)}</td>`).join("")}</tr>`).join(`
|
|
33
34
|
`);return`<table>
|
|
34
35
|
<thead><tr>${i}</tr></thead>
|
|
35
36
|
<tbody>
|
|
36
|
-
${
|
|
37
|
+
${a}
|
|
37
38
|
</tbody>
|
|
38
|
-
</table>`}function q(t){let e=
|
|
39
|
+
</table>`}function q(t){let e=Oe(t);return e=e.replace(/`([^`\n]+)`/g,(n,r)=>`<code>${r}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(n,r,i)=>`<a href="${_e(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 Oe(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function _e(t){return t.replace(/"/g,""").replace(/&/g,"&")}function pe(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Z=class{backendUri="kanonak.org/transformations/html";render(e,n){let r=Dt(e.children);if(n?.omitWrapper){let c=r.endsWith(`
|
|
39
40
|
`)?r:`${r}
|
|
40
41
|
`;return n.trailingNewline===!1&&c.endsWith(`
|
|
41
|
-
`)?c.slice(0,-1):c}let i=
|
|
42
|
+
`)?c.slice(0,-1):c}let i=Kt(e.metadata)??"Untitled",a=Tt(e.metadata,n),u=`<!DOCTYPE html>
|
|
42
43
|
<html lang="en">
|
|
43
44
|
<head>
|
|
44
45
|
<meta charset="utf-8">
|
|
45
|
-
<title>${
|
|
46
|
+
<title>${R(i)}</title>
|
|
46
47
|
<style>
|
|
47
48
|
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; }
|
|
48
49
|
h1, h2, h3, h4 { line-height: 1.2; }
|
|
@@ -64,21 +65,33 @@ figure.svg-figure svg { max-width: 100%; height: auto; }
|
|
|
64
65
|
</style>
|
|
65
66
|
</head>
|
|
66
67
|
<body>
|
|
67
|
-
${
|
|
68
|
+
${a}${r}
|
|
68
69
|
</body>
|
|
69
70
|
</html>
|
|
70
71
|
`;return n?.trailingNewline===!1&&u.endsWith(`
|
|
71
|
-
`)?u.slice(0,-1):u}};function
|
|
72
|
-
<dd>${
|
|
72
|
+
`)?u.slice(0,-1):u}};function Kt(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 Tt(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=Ie(u.value);l!==void 0&&i.push(` <dt>${R(c)}</dt>
|
|
73
|
+
<dd>${l}</dd>`)}return i.length===0?"":`<dl class="metadata">
|
|
73
74
|
${i.join(`
|
|
74
75
|
`)}
|
|
75
76
|
</dl>
|
|
76
|
-
`}function
|
|
77
|
-
`)}function
|
|
77
|
+
`}function Ie(t){switch(t.kind){case"StringScalar":return R(t.stringValue);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let e=[];for(let n of t.items){let r=Ie(n);r!==void 0&&e.push(`<code>${r}</code>`)}return e.join(", ")}case"StructuredMap":return;default:return}}function Dt(t){let e=[];for(let n of t){let r=ge(n);r&&e.push(r)}return e.join(`
|
|
78
|
+
`)}function ge(t){switch(t.kind){case"Heading":{let e=Math.max(1,Math.min(6,t.level));return`<h${e}>${ie(t.inlines)}</h${e}>`}case"Paragraph":return`<p>${ie(t.inlines)}</p>`;case"RawBlock":return Pt(t);case"PropertyList":return Rt(t);case"Table":return Lt(t);default:return""}}function Lt(t){let e=t.tableColumnLabels??[],n=t.tableRows??[],r=e.length>0?`<thead>
|
|
79
|
+
<tr>${e.map(a=>`<th>${R(a)}</th>`).join("")}</tr>
|
|
80
|
+
</thead>
|
|
81
|
+
`:"",i=n.length>0?`<tbody>
|
|
82
|
+
${n.map(Ct).join(`
|
|
83
|
+
`)}
|
|
84
|
+
</tbody>
|
|
85
|
+
`:"";return`<table class="property-table">
|
|
86
|
+
${r}${i}</table>`}function Ct(t){return` <tr>${(t.tableCells??[]).map(r=>`<td>${Bt(r)}</td>`).join("")}</tr>`}function Bt(t){let e=t;return!e||typeof e!="object"||!e.kind?"":e.kind==="Text"||e.kind==="ResourceLink"||e.kind==="Badge"?ie([e]):ge(e)}function Rt(t){if(!t.propertyEntries||t.propertyEntries.length===0)return"";let e=[];for(let n of t.propertyEntries){let i=`<dt${n.propertyTooltip?` title="${W(n.propertyTooltip)}"`:""}>${R(n.propertyKey)}</dt>`,a=`<dd>${Ut(n.propertyValue)}</dd>`;e.push(i,a)}return`<dl class="property-list">
|
|
78
87
|
${e.join(`
|
|
79
88
|
`)}
|
|
80
|
-
</dl>`}function
|
|
89
|
+
</dl>`}function Ut(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(ie([r])):e.push(ge(r)))}return e.join("")}function Pt(t){let e=t.mediaType;return e&&pe(e,V.TEXT_MARKDOWN)?me(t.rawContent):e&&pe(e,V.TEXT_HTML)?t.rawContent:e&&pe(e,V.IMAGE_SVG_XML)?`<figure class="svg-figure">
|
|
81
90
|
${t.rawContent}
|
|
82
|
-
</figure>`:`<pre${e?` class="media-${
|
|
91
|
+
</figure>`:`<pre${e?` class="media-${W(e.name)}"`:""}><code>${R(t.rawContent)}</code></pre>`}function ie(t){let e=[];for(let n of t)n.kind==="Text"?e.push(R(n.text)):n.kind==="ResourceLink"?e.push(Ot(n)):n.kind==="Badge"&&e.push(_t(n));return e.join("")}function Ot(t){let e=Ne(t.target);if(!e)return R(t.linkLabel??"[unresolved link]");let n=e.version,r=n?`https://${e.publisher}/${e.package_}/${n.major}.${n.minor}.${n.patch}/${e.name}`:`https://${e.publisher}/${e.package_}/${e.name}`,i=t.linkLabel&&t.linkLabel.length>0?t.linkLabel:e.name,a=t.linkTooltip?` title="${W(t.linkTooltip)}"`:"";return`<a class="kan-link" href="${W(r)}"${a}>${R(i)}</a>`}function _t(t){let e=t.badgeTooltip?` title="${W(t.badgeTooltip)}"`:"",n=R(t.badgeLabel);if(!t.badgeTarget)return`<span class="kan-badge"${e}>${n}</span>`;let r=Ne(t.badgeTarget);if(!r)return`<span class="kan-badge"${e}>${n}</span>`;let i=r.version,a=i?`https://${r.publisher}/${r.package_}/${i.major}.${i.minor}.${i.patch}/${r.name}`:`https://${r.publisher}/${r.package_}/${r.name}`;return`<a class="kan-badge" href="${W(a)}"${e}>${n}</a>`}function Ne(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 R(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function W(t){return t.replace(/"/g,""").replace(/&/g,"&")}function It(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Q=class{backendUri="kanonak.org/transformations/svg";render(e,n){for(let r of e.children)if(r.kind==="RawBlock"&&r.mediaType&&It(r.mediaType,V.IMAGE_SVG_XML)){let i=r.rawContent;return n?.trailingNewline&&!i.endsWith(`
|
|
92
|
+
`)&&(i+=`
|
|
93
|
+
`),i}return'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'}};function Nt(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var x=class{backendUri="kanonak.org/transformations/stylesheet";render(e,n){let r=[];for(let a of e.children)a.kind==="RawBlock"&&a.mediaType&&Nt(a.mediaType,V.TEXT_CSS)&&r.push(a.rawContent);let i=r.join(`
|
|
94
|
+
|
|
95
|
+
`);return n?.trailingNewline&&i.length>0&&!i.endsWith(`
|
|
83
96
|
`)&&(i+=`
|
|
84
|
-
`),i}return'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'}};var Q=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=_(n,e);if(r)return r;let i=e.version,o=i&&typeof i.major=="number"?`@${i.major}.${i.minor}.${i.patch}`:"",u=`${e.publisher}/${e.package_}${o}`,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(A=>{let b=A.metadata?.namespace_?.version;return b&&b.major===i.major&&b.minor===i.minor&&b.patch===i.patch})??m[0]:m[0],k=new Ee(g,this.repository);c=await this.objectParser.parseKanonaks(k),this.cache.set(u,c)}let f=_(c,e);if(f)return f;for(let m of c)if(m instanceof E&&m.name===e.name)return m}};var Kt="kanonak.org",Dt="transformations",Sn=3,s=t=>({publisher:Kt,package_:Dt,name:t}),a={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")};var y=class extends Error{constructor(n,r){super(`${n} (at ${r})`);this.path=r}path},Re=16;function ne(t,e){let n=t.name,r={catalog:e,depth:0};if(d(t,a.InstanceTransformation))return Tt(t,n,r);if(d(t,a.SetTransformation))return Lt(t,n,r);throw new y("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function Tt(t,e,n){return{kind:"instance",name:t.name,inputPattern:Fe(t,e),rule:te(t,a.rule,`${e}.rule`,n),artifactName:te(t,a.artifactName,`${e}.artifactName`,n),outputs:Ne(t,`${e}.outputs`),overrides:qe(t,`${e}.formatOverrides`,n)}}function Lt(t,e,n){let r=M(t,a.partitionBy);return{kind:"set",name:t.name,inputPattern:Fe(t,e),rule:te(t,a.rule,`${e}.rule`,n),artifactName:te(t,a.artifactName,`${e}.artifactName`,n),outputs:Ne(t,`${e}.outputs`),overrides:qe(t,`${e}.formatOverrides`,n),partitionBy:r}}function Fe(t,e){let n=x(t,a.inputPattern);if(!n)throw new y("inputPattern is required",e);return Ct(n,`${e}.inputPattern`)}function Ct(t,e){let n=M(t,a.matchesClass);if(!n)throw new y("matchesClass is required",e);let r=[];for(let u of j(t,a.requires))if(u instanceof v)r.push(me(u.object.subject));else if(u instanceof w)for(let c of u.object)c instanceof h&&r.push(me(c.subject));let i=[],o=0;for(let u of j(t,a.sortBy))if(u instanceof w)for(let c of u.object)c instanceof B&&i.push(Pe(c,`${e}.sortBy[${o++}]`));else u instanceof K&&i.push(Pe(u.object,`${e}.sortBy[${o++}]`));return{matchesClass:n,requires:r,sortBy:i}}function Pe(t,e){let n=M(t,a.byProperty);if(!n)throw new y("SortKey.byProperty is required",e);let r=M(t,a.order);if(!r)throw new y("SortKey.order is required",e);if($(r,a.ascending))return{byProperty:n,order:"ascending"};if($(r,a.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 te(t,e,n,r){let i=x(t,e);if(!i)throw new y("expression is required",n);return z(i,n,r)}function z(t,e,n){if(d(t,a.StringLiteral))return{kind:"string-literal",value:V(t,a.stringLiteral,e)};if(d(t,a.IntegerLiteral))return{kind:"integer-literal",value:_e(t,a.integerLiteral,e)};if(d(t,a.DecimalLiteral))return{kind:"decimal-literal",value:_e(t,a.decimalLiteral,e)};if(d(t,a.BooleanLiteral))return{kind:"boolean-literal",value:_t(t,a.booleanLiteral,e)};if(d(t,a.VarRef))return{kind:"var-ref",varName:V(t,a.varName,e)};if(d(t,a.PropertyRead))return{kind:"property-read",source:l(t,a.readSource,`${e}.readSource`,n),readProp:F(t,a.readProp,e,"readProp")};if(d(t,a.Traverse))return{kind:"traverse",source:l(t,a.traverseSource,`${e}.traverseSource`,n),through:F(t,a.through,e,"through"),step:l(t,a.step,`${e}.step`,n)};if(d(t,a.BuildAstNode))return{kind:"build-ast-node",astClass:F(t,a.astClass,e,"astClass"),set:Bt(t,`${e}.set`,n)};if(d(t,a.When))return{kind:"when",condition:l(t,a.condition,`${e}.condition`,n),thenBuild:l(t,a.thenBuild,`${e}.thenBuild`,n),elseBuild:Ut(t,a.elseBuild,`${e}.elseBuild`,n)};if(d(t,a.Concat))return{kind:"concat",parts:le(t,a.parts,`${e}.parts`,n)};if(d(t,a.Fallback))return{kind:"fallback",primary:l(t,a.primary,`${e}.primary`,n),alternate:l(t,a.alternate,`${e}.alternate`,n)};if(d(t,a.UriName))return{kind:"uri-name",source:l(t,a.uriNameOf,`${e}.uriNameOf`,n)};if(d(t,a.UriPublisher))return{kind:"uri-publisher",source:l(t,a.uriPublisherOf,`${e}.uriPublisherOf`,n)};if(d(t,a.UriPackage))return{kind:"uri-package",source:l(t,a.uriPackageOf,`${e}.uriPackageOf`,n)};if(d(t,a.UriVersion))return{kind:"uri-version",source:l(t,a.uriVersionOf,`${e}.uriVersionOf`,n)};if(d(t,a.SubjectUri))return{kind:"subject-uri",source:l(t,a.subjectOf,`${e}.subjectOf`,n)};if(d(t,a.UriLiteral))return{kind:"uri-literal",refTo:F(t,a.refTo,e,"refTo")};if(d(t,a.DisplayLabel))return{kind:"display-label",labelTarget:F(t,a.labelTarget,e,"labelTarget"),labelSource:F(t,a.labelSource,e,"labelSource")};if(d(t,a.ResolveRef))return{kind:"resolve-ref",source:l(t,a.resolveSource,`${e}.resolveSource`,n)};if(d(t,a.Normalize))return{kind:"normalize",source:l(t,a.normSource,`${e}.normSource`,n),normKind:Rt(t,e)};if(d(t,a.IsSet))return{kind:"is-set",check:l(t,a.checkExpr,`${e}.checkExpr`,n)};if(d(t,a.CallFragment))return It(t,e,n);if(d(t,a.Join))return{kind:"join",source:l(t,a.source,`${e}.source`,n),separator:V(t,a.separator,e)};if(d(t,a.Count))return{kind:"count",source:l(t,a.source,`${e}.source`,n)};if(d(t,a.Sum))return{kind:"sum",source:l(t,a.source,`${e}.source`,n)};if(d(t,a.Min))return{kind:"min",source:l(t,a.source,`${e}.source`,n)};if(d(t,a.Max))return{kind:"max",source:l(t,a.source,`${e}.source`,n)};if(d(t,a.Average))return{kind:"average",source:l(t,a.source,`${e}.source`,n)};if(d(t,a.ForEach))return{kind:"for-each",source:l(t,a.source,`${e}.source`,n),loopVar:V(t,a.loopVar,e),emit:l(t,a.emit,`${e}.emit`,n)};if(d(t,a.ListMap))return{kind:"list-map",source:l(t,a.source,`${e}.source`,n),loopVar:V(t,a.loopVar,e),mapBody:l(t,a.mapBody,`${e}.mapBody`,n)};if(d(t,a.Filter))return{kind:"filter",source:l(t,a.source,`${e}.source`,n),loopVar:V(t,a.loopVar,e),predicate:l(t,a.predicate,`${e}.predicate`,n)};if(d(t,a.PartitionBy))return{kind:"partition-by",source:l(t,a.source,`${e}.source`,n),loopVar:V(t,a.loopVar,e),partitionKey:l(t,a.partitionKey,`${e}.partitionKey`,n)};if(d(t,a.DistinctBy))return{kind:"distinct-by",source:l(t,a.source,`${e}.source`,n),loopVar:V(t,a.loopVar,e),distinctKey:l(t,a.distinctKey,`${e}.distinctKey`,n)};if(d(t,a.AllStatements))return{kind:"all-statements",source:l(t,a.statementsOf,`${e}.statementsOf`,n)};if(d(t,a.StatementPredicate))return{kind:"statement-predicate",source:l(t,a.predicateOf,`${e}.predicateOf`,n)};if(d(t,a.StatementValue))return{kind:"statement-value",source:l(t,a.valueOf,`${e}.valueOf`,n)};if(d(t,a.DateFormat))return{kind:"date-format",source:l(t,a.dateSource,`${e}.dateSource`,n),format:Pt(t,e)};if(d(t,a.Add))return{kind:"add",left:l(t,a.arithLeft,`${e}.arithLeft`,n),right:l(t,a.arithRight,`${e}.arithRight`,n)};if(d(t,a.Subtract))return{kind:"subtract",left:l(t,a.arithLeft,`${e}.arithLeft`,n),right:l(t,a.arithRight,`${e}.arithRight`,n)};if(d(t,a.Multiply))return{kind:"multiply",left:l(t,a.arithLeft,`${e}.arithLeft`,n),right:l(t,a.arithRight,`${e}.arithRight`,n)};if(d(t,a.Divide))return{kind:"divide",left:l(t,a.arithLeft,`${e}.arithLeft`,n),right:l(t,a.arithRight,`${e}.arithRight`,n)};if(d(t,a.Reverse))return{kind:"reverse",source:l(t,a.source,`${e}.source`,n)};if(d(t,a.WindowedMap)){let r=We(t,a.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:l(t,a.source,`${e}.source`,n),windowSize:r,windowVar:V(t,a.windowVar,e),windowBody:l(t,a.windowBody,`${e}.windowBody`,n)}}if(d(t,a.PairwiseMap))return{kind:"pairwise-map",source:l(t,a.source,`${e}.source`,n),firstVar:V(t,a.firstVar,e),secondVar:V(t,a.secondVar,e),pairBody:l(t,a.pairBody,`${e}.pairBody`,n)};if(d(t,a.Scan))return{kind:"scan",source:l(t,a.source,`${e}.source`,n),initialState:l(t,a.initialState,`${e}.initialState`,n),stateVar:V(t,a.stateVar,e),elementVar:V(t,a.elementVar,e),accumulate:l(t,a.accumulate,`${e}.accumulate`,n)};if(d(t,a.ListItemAt))return{kind:"list-item-at",source:l(t,a.source,`${e}.source`,n),itemIndex:l(t,a.itemIndex,`${e}.itemIndex`,n)};if(d(t,a.Equals))return{kind:"equals",left:l(t,a.compareLeft,`${e}.compareLeft`,n),right:l(t,a.compareRight,`${e}.compareRight`,n)};if(d(t,a.GreaterThan))return{kind:"greater-than",left:l(t,a.compareLeft,`${e}.compareLeft`,n),right:l(t,a.compareRight,`${e}.compareRight`,n)};if(d(t,a.LessThan))return{kind:"less-than",left:l(t,a.compareLeft,`${e}.compareLeft`,n),right:l(t,a.compareRight,`${e}.compareRight`,n)};if(d(t,a.GreaterThanOrEqual))return{kind:"greater-than-or-equal",left:l(t,a.compareLeft,`${e}.compareLeft`,n),right:l(t,a.compareRight,`${e}.compareRight`,n)};if(d(t,a.LessThanOrEqual))return{kind:"less-than-or-equal",left:l(t,a.compareLeft,`${e}.compareLeft`,n),right:l(t,a.compareRight,`${e}.compareRight`,n)};if(d(t,a.Not))return{kind:"not",operand:l(t,a.operand,`${e}.operand`,n)};if(d(t,a.And))return{kind:"and",operands:le(t,a.operands,`${e}.operands`,n)};if(d(t,a.Or))return{kind:"or",operands:le(t,a.operands,`${e}.operands`,n)};if(d(t,a.Contains))return{kind:"contains",haystack:l(t,a.haystack,`${e}.haystack`,n),needle:l(t,a.needle,`${e}.needle`,n)};if(d(t,a.Abs))return{kind:"abs",value:l(t,a.value,`${e}.value`,n)};if(d(t,a.Negate))return{kind:"negate",value:l(t,a.value,`${e}.value`,n)};if(d(t,a.IsReference))return{kind:"is-reference",check:l(t,a.kindCheck,`${e}.kindCheck`,n)};if(d(t,a.IsEmbedded))return{kind:"is-embedded",check:l(t,a.kindCheck,`${e}.kindCheck`,n)};if(d(t,a.IsList))return{kind:"is-list",check:l(t,a.kindCheck,`${e}.kindCheck`,n)};if(d(t,a.StatementObject))return{kind:"statement-object",source:l(t,a.statementSource,`${e}.statementSource`,n)};throw new y("Expression is not of a recognized v3 type \u2014 embedded has no matching subclass of tx.Expression",e)}function l(t,e,n,r){let i=x(t,e);if(!i)throw new y("child expression is required",n);return z(i,n,r)}function Ut(t,e,n,r){let i=x(t,e);if(i)return z(i,n,r)}function le(t,e,n,r){let i=[],o=0;for(let u of j(t,e))if(u instanceof w)for(let c of u.object)c instanceof B&&i.push(z(c,`${n}[${o++}]`,r));else u instanceof K&&i.push(z(u.object,`${n}[${o++}]`,r));return i}function Bt(t,e,n){let r=[],i=0;for(let o of j(t,a.set))if(o instanceof w)for(let u of o.object)u instanceof B&&r.push(Ie(u,`${e}[${i++}]`,n));else o instanceof K&&r.push(Ie(o.object,`${e}[${i++}]`,n));return r}function Ie(t,e,n){return{field:F(t,a.field,e,"field"),value:l(t,a.bindValue,`${e}.bindValue`,n)}}function Rt(t,e){let n=M(t,a.normKind);if(!n)throw new y("normKind is required",e);if($(n,a.NORM_TRIM_END))return"trim-end";throw new y(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}var Me=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function Pt(t,e){let n=W(t,a.dateFormat);if(!n)throw new y("dateFormat is required",e);if(!Me.has(n))throw new y(`Unknown dateFormat "${n}"; supported: ${[...Me].join(", ")}`,e);return n}function It(t,e,n){if(n.depth>=Re)throw new y(`Fragment recursion exceeded MAX_FRAGMENT_DEPTH (${Re})`,e);let r=M(t,a.fragmentRef);if(!r)throw new y("fragmentRef is required",e);let i=Mt(n.catalog,r);if(!i)throw new y(`ExpressionFragment not found: ${r.publisher}/${r.package_}/${r.name}`,e);let o=x(i,a.body);if(!o)throw new y(`ExpressionFragment ${r.name} has no body`,e);return{kind:"call-fragment",body:z(o,`${e}.fragment(${r.name})`,{catalog:n.catalog,depth:n.depth+1})}}function Mt(t,e){for(let n of t)if(!(!(n instanceof E)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&d(n,a.ExpressionFragment))return n}function Ne(t,e){let n=new Set;for(let r of j(t,a.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 qe(t,e,n){let r=new Map,i=0;for(let o of j(t,a.formatOverrides))if(o instanceof w){for(let u of o.object)if(u instanceof B){let[c,f]=Oe(u,`${e}[${i++}]`);r.set(c,f)}}else if(o instanceof K){let[u,c]=Oe(o.object,`${e}[${i++}]`);r.set(u,c)}return r}function Oe(t,e){let n=M(t,a.formatTarget);if(!n)throw new y("formatTarget is required",e);let r=[];for(let c of j(t,a.metadataKeys))if(c instanceof D)r.push(c.object);else if(c instanceof w)for(let f of c.object){let m=f.value;typeof m=="string"&&r.push(m)}let i=new Map;for(let c of j(t,a.metadataRenames))if(c instanceof w){for(let f of c.object)if(f instanceof B){let m=W(f,a.fromKey),g=W(f,a.toKey);m&&g&&i.set(m,g)}}else if(c instanceof K){let f=c.object,m=W(f,a.fromKey),g=W(f,a.toKey);m&&g&&i.set(m,g)}let o=de(t,a.trailingNewline),u=de(t,a.omitWrapper);return[n.name,{metadataKeys:r.length>0?r:void 0,metadataRenames:i,trailingNewline:o,omitWrapper:u}]}function Ot(t){return t.predicate?.subject}function j(t,e){let n=[];for(let r of t.statement){let i=Ot(r);i&&$(i,e)&&n.push(r)}return n}function x(t,e){for(let n of j(t,e))if(n instanceof K)return n.object}function M(t,e){for(let n of j(t,e))if(n instanceof v)return me(n.object.subject)}function W(t,e){for(let n of j(t,e))if(n instanceof D)return n.object}function We(t,e){for(let n of j(t,e))if(n instanceof L)return n.object}function de(t,e){for(let n of j(t,e))if(n instanceof C)return n.object}function V(t,e,n){let r=W(t,e);if(r===void 0)throw new y(`${e.name} (string) is required`,n);return r}function _e(t,e,n){let r=We(t,e);if(r===void 0)throw new y(`${e.name} (number) is required`,n);return r}function _t(t,e,n){let r=de(t,e);if(r===void 0)throw new y(`${e.name} (boolean) is required`,n);return r}function F(t,e,n,r){let i=M(t,e);if(!i)throw new y(`${r} (URI reference) is required`,n);return i}function me(t){return{publisher:t.publisher,package_:t.package_,name:t.name}}var R=class extends Error{},ie=class{constructor(e,n){this.resolver=e;this.catalog=n}resolver;catalog;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 R(`Unbound variable "${e.varName}"`);return n.get(e.varName)}case"concat":{let r=[];for(let i of e.parts){let o=await this.evaluate(i,n);if(o!=null)if(Array.isArray(o))for(let u of o)r.push(u);else r.push(o)}return r}case"fallback":{let r=await this.evaluate(e.primary,n);return He(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 He(r)}case"property-read":{let r=await this.evaluate(e.source,n);return ze(r,e.readProp)}case"traverse":{let r=await this.evaluate(e.source,n);if(!(r instanceof U))return;let i=Nt(r,e.through),o=[];for(let u of i){let c=await this.resolver.resolveSubject(u,this.catalog);if(!c)continue;let f=new Map(n);f.set("input",c);let m=await this.evaluate(e.step,f);m!=null&&o.push(re(m))}return o.join("")}case"uri-name":{let r=await this.evaluate(e.source,n);return H(r)?r.name:r instanceof h?r.subject.name:r instanceof E?r.name:r instanceof B?r.name??"":void 0}case"uri-publisher":{let r=await this.evaluate(e.source,n);return pe(r)?.publisher}case"uri-package":{let r=await this.evaluate(e.source,n);return pe(r)?.package_}case"uri-version":{let r=await this.evaluate(e.source,n);return pe(r)?.version}case"subject-uri":{let r=await this.evaluate(e.source,n);if(r instanceof E){let i=r.namespace??"",o=r.name??"";return!i||!o?void 0:`${i}/${o}`}if(r instanceof h){let i=r.subject,o=i.version;return o&&typeof o.major=="number"?`${i.publisher}/${i.package_}@${o.major}.${o.minor}.${o.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?ze(r,e.labelSource):void 0}case"resolve-ref":{let r=await this.evaluate(e.source,n);return r instanceof h?await this.resolver.resolveSubject(r.subject,this.catalog):H(r)?await this.resolver.resolveSubject(r,this.catalog):void 0}case"normalize":{let r=await this.evaluate(e.source,n),i=r==null?"":re(r);return e.normKind==="trim-end"?i.replace(/[\s\r\n]+$/u,""):i}case"build-ast-node":{let r={kind:e.astClass.name};for(let i of e.set){let o=await this.evaluate(i.value,n);if(o==null||Array.isArray(o)&&o.length===0)continue;let u=i.field.name;Array.isArray(o)&&Wt.has(u)&&o.every(c=>zt(c))&&(o=o.map(c=>String(c)).join("")),r[u]=o}return r}case"call-fragment":return this.evaluate(e.body,n);case"join":return(await this.evaluateList(e.source,n)).map(i=>i==null?"":re(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 o of r)i+=S(o,"Sum");return i}case"min":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new R("Min on an empty list is undefined; guard with IsSet");let i=S(r[0],"Min");for(let o=1;o<r.length;o++){let u=S(r[o],"Min");u<i&&(i=u)}return i}case"max":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new R("Max on an empty list is undefined; guard with IsSet");let i=S(r[0],"Max");for(let o=1;o<r.length;o++){let u=S(r[o],"Max");u>i&&(i=u)}return i}case"average":{let r=await this.evaluateList(e.source,n);if(r.length===0)throw new R("Average on an empty list is undefined; guard with IsSet");let i=0;for(let o of r)i+=S(o,"Average");return i/r.length}case"for-each":{let r=await this.evaluateList(e.source,n),i=[];for(let o of r){let u=new Map(n);u.set(e.loopVar,o);let c=await this.evaluate(e.emit,u);if(c!=null)if(Array.isArray(c))for(let f of c)i.push(f);else i.push(c)}return i}case"list-map":{let r=await this.evaluateList(e.source,n),i=[];for(let o of r){let u=new Map(n);u.set(e.loopVar,o),i.push(await this.evaluate(e.mapBody,u))}return i}case"filter":{let r=await this.evaluateList(e.source,n),i=[];for(let o of r){let u=new Map(n);u.set(e.loopVar,o),await this.evaluate(e.predicate,u)===!0&&i.push(o)}return i}case"partition-by":{let r=await this.evaluateList(e.source,n),i=new Map,o=[];for(let u of r){let c=new Map(n);c.set(e.loopVar,u);let f=await this.evaluate(e.partitionKey,c),m=Xe(f),g=i.get(m);g||(g={kind:"Partition",key:f,members:[]},i.set(m,g),o.push(m)),g.members.push(u)}return o.map(u=>i.get(u))}case"distinct-by":{let r=await this.evaluateList(e.source,n),i=new Set,o=[];for(let u of r){let c=new Map(n);c.set(e.loopVar,u);let f=await this.evaluate(e.distinctKey,c),m=Xe(f);i.has(m)||(i.add(m),o.push(u))}return o}case"all-statements":{let r=await this.evaluate(e.source,n);return r instanceof U?r.statement:[]}case"statement-predicate":{let r=await this.evaluate(e.source,n);if(ge(r)){let i=r.predicate;if(i instanceof h)return i}return}case"statement-value":{let r=await this.evaluate(e.source,n);return ge(r)?Jt(r):void 0}case"date-format":{let r=await this.evaluate(e.source,n),i=r==null?"":re(r);return i?Gt(i,e.format):""}case"add":{let r=S(await this.evaluate(e.left,n),"Add"),i=S(await this.evaluate(e.right,n),"Add");return r+i}case"subtract":{let r=S(await this.evaluate(e.left,n),"Subtract"),i=S(await this.evaluate(e.right,n),"Subtract");return r-i}case"multiply":{let r=S(await this.evaluate(e.left,n),"Multiply"),i=S(await this.evaluate(e.right,n),"Multiply");return r*i}case"divide":{let r=S(await this.evaluate(e.left,n),"Divide"),i=S(await this.evaluate(e.right,n),"Divide");if(i===0)throw new R("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 o=0;o+e.windowSize<=r.length;o++){let u=r.slice(o,o+e.windowSize),c=new Map(n);c.set(e.windowVar,u);let f=await this.evaluate(e.windowBody,c);if(f!=null)if(Array.isArray(f))for(let m of f)i.push(m);else i.push(f)}return i}case"pairwise-map":{let r=await this.evaluateList(e.source,n);if(r.length<2)return[];let i=[];for(let o=0;o+1<r.length;o++){let u=new Map(n);u.set(e.firstVar,r[o]),u.set(e.secondVar,r[o+1]);let c=await this.evaluate(e.pairBody,u);if(c!=null)if(Array.isArray(c))for(let f of c)i.push(f);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),o=[];for(let u of r){let c=new Map(n);c.set(e.stateVar,i),c.set(e.elementVar,u);let f=await this.evaluate(e.accumulate,c);o.push(f),i=f}return o}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 Ge(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 o of r)if(Ge(o,i))return!0;return!1}case"abs":{let r=S(await this.evaluate(e.value,n),"Abs");return Math.abs(r)}case"negate":return-S(await this.evaluate(e.value,n),"Negate");case"is-reference":return await this.evaluate(e.check,n)instanceof h;case"is-embedded":return await this.evaluate(e.check,n)instanceof B;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(!ge(r))return;let i=r;return i instanceof D||i instanceof L||i instanceof C||i instanceof v||i instanceof K||i instanceof w?i.object:void 0}default:{let r=e;throw new R("Unknown expression kind")}}}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 o=r.length-1;o>=1;o--){let u=new Map(n);u.set(e.firstVar,r[o-1]),u.set(e.secondVar,r[o]);let c=await this.evaluate(e.pairBody,u);if(c!=null)if(Array.isArray(c))for(let f of c)i.push(f);else i.push(c)}return i}if(e.kind==="for-each"){let r=await this.evaluateList(e.source,n),i=[];for(let o=r.length-1;o>=0;o--){let u=new Map(n);u.set(e.loopVar,r[o]);let c=await this.evaluate(e.emit,u);if(c!=null)if(Array.isArray(c))for(let f of c)i.push(f);else i.push(c)}return i}if(e.kind==="list-map"){let r=await this.evaluateList(e.source,n),i=[];for(let o=r.length-1;o>=0;o--){let u=new Map(n);u.set(e.loopVar,r[o]),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 o=r.length-e.windowSize;o>=0;o--){let u=r.slice(o,o+e.windowSize),c=new Map(n);c.set(e.windowVar,u);let f=await this.evaluate(e.windowBody,c);if(f!=null)if(Array.isArray(f))for(let m of f)i.push(m);else i.push(f)}return i}}};function ze(t,e){if(t instanceof U)return Ft(t,e);if(qt(t))return $(e,a.key)?t.key:$(e,a.members)?t.members:void 0}function Ft(t,e){for(let n of t.statement){let r=Ye(n);if(!(!r||!$(r,e))&&(n instanceof D||n instanceof L||n instanceof C||n instanceof v||n instanceof K||n instanceof w))return n.object}}function Nt(t,e){let n=[];for(let r of t.statement){let i=Ye(r);if(!(!i||!$(i,e))){if(r instanceof v)n.push(r.object.subject);else if(r instanceof w)for(let o of r.object)o instanceof h&&n.push(o.subject)}}return n}function Ye(t){return t.predicate?.subject}function re(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(t instanceof U)return t.name??"";if(t instanceof h)return t.subject.name;if(H(t))return t.name;let e=t.value;return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function He(t){return t==null?!1:typeof t=="string"||Array.isArray(t)?t.length>0:typeof t=="boolean"?t===!0:!0}function H(t){return typeof t=="object"&&t!==null&&typeof t.publisher=="string"&&typeof t.package_=="string"&&typeof t.name=="string"}function qt(t){return typeof t=="object"&&t!==null&&t.kind==="Partition"&&Array.isArray(t.members)}function S(t,e){if(typeof t=="number"&&Number.isFinite(t))return t;throw new R(`${e} requires numeric elements; got ${Ht(t)}`)}function pe(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 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(H(t))return{publisher:t.publisher,package_:t.package_,version:"",name:t.name}}var Wt=new Set(["stringValue","text","rawContent","key","propertyKey","linkLabel"]);function zt(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function Ht(t){return t===void 0?"undefined":t===null?"null":Array.isArray(t)?`array(${t.length})`:typeof t}function Gt(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()],o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getUTCMonth()],u=n.getUTCDate(),c=(f,m=2)=>String(f).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`${o} ${u}`;case"long-date":return`${i} ${u}, ${r}`;case"year":return String(r);case"month-year":return`${i} ${r}`}}function Ge(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,o=r??e,u=Je(t),c=Je(e);return u&&c?u.publisher===c.publisher&&u.package_===c.package_&&u.name===c.name:typeof i=="string"&&typeof o=="string"||typeof i=="number"&&typeof o=="number"||typeof i=="boolean"&&typeof o=="boolean"?i===o:!1}function Je(t){if(t instanceof h){let e=t.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}if(t instanceof E){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);if(n<0)return;let i=e.substring(0,n),o=r>=0?e.substring(n+1,r):e.substring(n+1);return{publisher:i,package_:o,name:t.name??""}}if(H(t))return{publisher:t.publisher,package_:t.package_,name:t.name}}function ge(t){return t instanceof D||t instanceof L||t instanceof C||t instanceof v||t instanceof K||t instanceof w}function Jt(t){return t instanceof D||t instanceof L||t instanceof C?String(t.object??""):t instanceof v?t.object?.subject?.name??"":t instanceof K?"[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 Xe(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 U){let e=t.name??"";return`k:${t.namespace??""}/${e}`}return H(t)?`u:${t.publisher}/${t.package_}/${t.name}`:`o:${JSON.stringify(t)}`}var Xt={"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"}},O=class extends Error{},ae=class{backends=new Map;constructor(){this.register(new G),this.register(new J),this.register(new X),this.register(new Y),this.register(new Z)}register(e){this.backends.set(e.backendUri,e)}async run(e){let n=e.transformationKanonaks??e.allKanonaks,r=ne(e.transformation,n);if(!r.outputs.has(e.outputFormat))throw new O(`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 O(`No backend registered for OutputFormat "${e.outputFormat}".`);let o=new Q(e.repository,e.parser,e.objectParser),u=new ie(o,e.allKanonaks);return r.kind==="instance"?this.runInstance(r,e,i,u):this.runSet(r,e,i,u)}async runInstance(e,n,r,i){let o=Ze(n.instances,e.inputPattern.requires),u=Qe(o,e.inputPattern.sortBy),c=[];for(let f of u){let m=new Map;m.set("input",f);let g=await i.evaluate(e.rule,m);ye(g,e.name,`input "${f.name}"`);let k=ke(await i.evaluate(e.artifactName,m),e.name,`input "${f.name}"`),A=e.overrides.get(n.outputFormat),b=r.render(g,A);c.push({fileName:k,format:n.outputFormat,content:b,source:{kind:"instance",sourceName:f.name}})}return c}async runSet(e,n,r,i){let o=Ze(n.instances,e.inputPattern.requires),u=Qe(o,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,o){let u=new Map;u.set("inputs",n);let c=await o.evaluate(e.rule,u);ye(c,e.name,"set");let f=ke(await o.evaluate(e.artifactName,u),e.name,"set"),m=e.overrides.get(r.outputFormat),g=i.render(c,m);return[{fileName:f,format:r.outputFormat,content:g,source:{kind:"set",memberCount:n.length}}]}async runSetWithPartition(e,n,r,i,o){let u=e.partitionBy,c=new Map,f=[];for(let g of n){let k=Qt(g,u);if(k==null)continue;let A=xt(k),b=c.get(A);b||(b={keyValue:k,keyDisplay:en(k),members:[]},c.set(A,b),f.push(A)),b.members.push(g)}let m=[];for(let g of f){let k=c.get(g),A=new Map;A.set("inputs",k.members),A.set("key",k.keyValue);let b=await o.evaluate(e.rule,A);ye(b,e.name,`partition "${k.keyDisplay}"`);let nt=ke(await o.evaluate(e.artifactName,A),e.name,`partition "${k.keyDisplay}"`),rt=e.overrides.get(r.outputFormat),it=i.render(b,rt);m.push({fileName:nt,format:r.outputFormat,content:it,source:{kind:"set",memberCount:k.members.length,partitionKey:k.keyDisplay}})}return m}findBackend(e){let n=Xt[e];if(n)return this.backends.get(n.formatUri)}};function Ze(t,e){return e.length===0?t:t.filter(n=>{for(let r of e)if(!Zt(n,r))return!1;return!0})}function Qe(t,e){if(e.length===0)return t;let n=[...t];return n.sort((r,i)=>{for(let o of e){let u=xe(r,o.byProperty),c=xe(i,o.byProperty),f=Yt(u,c,o.order);if(f!==0)return f}return 0}),n}function xe(t,e){for(let n of t.statement){let r=he(n);if(!(!r||!$(r,e))){if(n instanceof D||n instanceof L||n instanceof C)return n.object;if(n instanceof w)throw new O(`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 O(`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 Yt(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 Zt(t,e){for(let n of t.statement){let r=he(n);if(!r||!$(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 Qt(t,e){for(let n of t.statement){let r=he(n);if(!(!r||!$(r,e))&&(n instanceof D||n instanceof L||n instanceof C||n instanceof v||n instanceof w))return n.object}}function he(t){return t.predicate?.subject}function xt(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 U){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 en(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):t instanceof h?t.subject.name:t instanceof U?t.name??"":typeof t=="object"&&t!==null&&typeof t.name=="string"?t.name:""}function ye(t,e,n){if(typeof t!="object"||t===null||t.kind!=="Document")throw new O(`Transformation "${e}" rule did not yield a Document for ${n}. Got: ${et(t)}`)}function ke(t,e,n){if(typeof t=="string")return t;if(Array.isArray(t)&&t.every(tn))return t.map(r=>String(r)).join("");throw new O(`Transformation "${e}" artifactName did not yield a string for ${n}. Got: ${et(t)}`)}function tn(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function et(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}var P=class extends Error{constructor(n,r){super(n);this.cause=r;this.name="RenderError"}cause},tt={publisher:"kanonak.org",package_:"derivation",name:"default"},we=class{constructor(e,n=new Se,r=new be){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;runner=new ae;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async findDerivation(e){let n=await this.getCatalog(),r=_(n,e.resource);if(!(r instanceof E))return;let i=e.variant??tt;return $e(r,e.format,i,n)}async render(e){let n=await this.findDerivation(e);if(!n)throw new P(`No derivation found for ${N(e.resource)} \u2192 format ${N(e.format)}`+(e.variant?` variant ${N(e.variant)}`:""));return this.runTransformation({transformation:{publisher:n.transformation.publisher,package_:n.transformation.package_,name:n.transformation.name},input:e.resource,format:e.format})}async runTransformation(e){let n=await this.getCatalog(),r=_(n,e.transformation);if(!(r instanceof E))throw new P(`Transformation not found: ${N(e.transformation)}`);let i=_(n,e.input);if(!(i instanceof E))throw new P(`Input resource not found: ${N(e.input)}`);let o=ne(r,n),u=nn(o.outputs,e.format);if(!u)throw new P(`Transformation ${N(e.transformation)} declares outputs [${[...o.outputs].join(", ")}], none of which corresponds to format ${N(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})}catch(f){throw new P(`Transformation execution failed: ${f.message}`,f)}if(c.length===0)throw new P("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 N(t){return`${t.publisher}/${t.package_}/${t.name}`}function nn(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{tt as DEFAULT_VARIANT,T as DOCAST,ot as DOCAST_PKG,at as DOCAST_PUB,ie as ExpressionEngineV3,R as ExpressionEvalErrorV3,Y as HtmlBackend,X as JsonBackend,G as MarkdownFrontmatterBackend,Q as ReferenceResolver,P as RenderError,Xt as SUPPORTED_FORMATS_V3,Z as SvgBackend,a as TX_V3,Dt as TX_V3_PKG,Kt as TX_V3_PUB,Sn as TX_V3_VERSION_MAJOR,J as TomlBackend,we as TransformationEngine,y as TransformationLoadErrorV3,O as TransformationRunnerErrorV3,ae as TransformationRunnerV3,ne as compileTransformationV3,ue as renderMarkdownToHtml};
|
|
97
|
+
`),i}};var ee=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=N(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 S=K.metadata?.namespace_?.version;return S&&S.major===i.major&&S.minor===i.minor&&S.patch===i.patch})??m[0]:m[0],k=new Te(g,this.repository);c=await this.objectParser.parseKanonaks(k),this.cache.set(u,c)}let l=N(c,e);if(l)return l;for(let m of c)if(m instanceof w&&m.name===e.name)return m}};var Mt="kanonak.org",Ft="transformations",On=3,s=t=>({publisher:Mt,package_:Ft,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")};var y=class extends Error{constructor(n,r){super(`${n} (at ${r})`);this.path=r}path};function oe(t,e){let n=t.name,r=Qt(e),i={catalog:e,depth:0};if(d(t,o.InstanceTransformation))return qt(t,n,i,r);if(d(t,o.SetTransformation))return Wt(t,n,i,r);throw new y("Subject is not a recognized v3 transformation type \u2014 expected InstanceTransformation or SetTransformation",n)}function qt(t,e,n,r){return{kind:"instance",name:t.name,inputPattern:He(t,e),rule:ae(t,o.rule,`${e}.rule`,n),artifactName:ae(t,o.artifactName,`${e}.artifactName`,n),outputs:Ge(t,`${e}.outputs`),overrides:Xe(t,`${e}.formatOverrides`,n),fragments:r}}function Wt(t,e,n,r){let i=_(t,o.partitionBy);return{kind:"set",name:t.name,inputPattern:He(t,e),rule:ae(t,o.rule,`${e}.rule`,n),artifactName:ae(t,o.artifactName,`${e}.artifactName`,n),outputs:Ge(t,`${e}.outputs`),overrides:Xe(t,`${e}.formatOverrides`,n),partitionBy:i,fragments:r}}function He(t,e){let n=te(t,o.inputPattern);if(!n)throw new y("inputPattern is required",e);return zt(n,`${e}.inputPattern`)}function zt(t,e){let n=_(t,o.matchesClass);if(!n)throw new y("matchesClass is required",e);let r=[];for(let u of A(t,o.requires))if(u instanceof j)r.push(he(u.object.subject));else if(u instanceof b)for(let c of u.object)c instanceof h&&r.push(he(c.subject));let i=[],a=0;for(let u of A(t,o.sortBy))if(u instanceof b)for(let c of u.object)c instanceof P&&i.push(Me(c,`${e}.sortBy[${a++}]`));else u instanceof T&&i.push(Me(u.object,`${e}.sortBy[${a++}]`));return{matchesClass:n,requires:r,sortBy:i}}function Me(t,e){let n=_(t,o.byProperty);if(!n)throw new y("SortKey.byProperty is required",e);let r=_(t,o.order);if(!r)throw new y("SortKey.order is required",e);if(v(r,o.ascending))return{byProperty:n,order:"ascending"};if(v(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 ae(t,e,n,r){let i=te(t,e);if(!i)throw new y("expression is required",n);return H(i,n,r)}function H(t,e,n){if(d(t,o.StringLiteral))return{kind:"string-literal",value:E(t,o.stringLiteral,e)};if(d(t,o.IntegerLiteral))return{kind:"integer-literal",value:ze(t,o.integerLiteral,e)};if(d(t,o.DecimalLiteral))return{kind:"decimal-literal",value:ze(t,o.decimalLiteral,e)};if(d(t,o.BooleanLiteral))return{kind:"boolean-literal",value:tn(t,o.booleanLiteral,e)};if(d(t,o.VarRef))return{kind:"var-ref",varName:E(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:Gt(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:Ht(t,o.elseBuild,`${e}.elseBuild`,n)};if(d(t,o.Concat))return{kind:"concat",parts:ye(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.IsSet))return{kind:"is-set",check:f(t,o.checkExpr,`${e}.checkExpr`,n)};if(d(t,o.CallFragment))return Yt(t,e,n);if(d(t,o.Join))return{kind:"join",source:f(t,o.source,`${e}.source`,n),separator:E(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:E(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:E(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:E(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:E(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:E(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:Jt(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=Je(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:E(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:E(t,o.firstVar,e),secondVar:E(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:E(t,o.stateVar,e),elementVar:E(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:ye(t,o.operands,`${e}.operands`,n)};if(d(t,o.Or))return{kind:"or",operands:ye(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:E(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=te(t,e);if(!i)throw new y("child expression is required",n);return H(i,n,r)}function Ht(t,e,n,r){let i=te(t,e);if(i)return H(i,n,r)}function ye(t,e,n,r){let i=[],a=0;for(let u of A(t,e))if(u instanceof b)for(let c of u.object)c instanceof P&&i.push(H(c,`${n}[${a++}]`,r));else u instanceof T&&i.push(H(u.object,`${n}[${a++}]`,r));return i}function Gt(t,e,n){let r=[],i=0;for(let a of A(t,o.set))if(a instanceof b)for(let u of a.object)u instanceof P&&r.push(Fe(u,`${e}[${i++}]`,n));else a instanceof T&&r.push(Fe(a.object,`${e}[${i++}]`,n));return r}function Fe(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=_(t,o.normKind);if(!n)throw new y("normKind is required",e);if(v(n,o.NORM_TRIM_END))return"trim-end";throw new y(`Unknown NormalizeKind: ${n.publisher}/${n.package_}/${n.name}`,e)}var qe=new Set(["iso-date","iso-datetime","short-date","long-date","year","month-year"]);function Jt(t,e){let n=z(t,o.dateFormat);if(!n)throw new y("dateFormat is required",e);if(!qe.has(n))throw new y(`Unknown dateFormat "${n}"; supported: ${[...qe].join(", ")}`,e);return n}function Yt(t,e,n){let r=_(t,o.fragmentRef);if(!r)throw new y("fragmentRef is required",e);if(!xt(n.catalog,r))throw new y(`ExpressionFragment not found: ${r.publisher}/${r.package_}/${r.name}`,e);return{kind:"call-fragment",fragmentKey:Zt(r)}}function Zt(t){return`${t.publisher}/${t.package_}/${t.name}`}function Qt(t){let e=new Map,n=[];for(let r of t){if(!(r instanceof w)||!d(r,o.ExpressionFragment))continue;let i=te(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=H(r.bodyEmb,`fragment(${r.pubPkgName})`,{catalog:t,depth:0});e.set(r.key,i)}return e}function xt(t,e){for(let n of t)if(!(!(n instanceof w)||n.name!==e.name||!(n.namespace||"").startsWith(`${e.publisher}/${e.package_}@`))&&d(n,o.ExpressionFragment))return n}function Ge(t,e){let n=new Set;for(let r of A(t,o.outputs))if(r instanceof j)n.add(r.object.subject.name);else if(r instanceof b)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 b){for(let u of a.object)if(u instanceof P){let[c,l]=We(u,`${e}[${i++}]`);r.set(c,l)}}else if(a instanceof T){let[u,c]=We(a.object,`${e}[${i++}]`);r.set(u,c)}return r}function We(t,e){let n=_(t,o.formatTarget);if(!n)throw new y("formatTarget is required",e);let r=[];for(let c of A(t,o.metadataKeys))if(c instanceof D)r.push(c.object);else if(c instanceof b)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 b){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=ke(t,o.trailingNewline),u=ke(t,o.omitWrapper);return[n.name,{metadataKeys:r.length>0?r:void 0,metadataRenames:i,trailingNewline:a,omitWrapper:u}]}function en(t){return t.predicate?.subject}function A(t,e){let n=[];for(let r of t.statement){let i=en(r);i&&v(i,e)&&n.push(r)}return n}function te(t,e){for(let n of A(t,e))if(n instanceof T)return n.object}function _(t,e){for(let n of A(t,e))if(n instanceof j)return he(n.object.subject)}function z(t,e){for(let n of A(t,e))if(n instanceof D)return n.object}function Je(t,e){for(let n of A(t,e))if(n instanceof C)return n.object}function ke(t,e){for(let n of A(t,e))if(n instanceof B)return n.object}function E(t,e,n){let r=z(t,e);if(r===void 0)throw new y(`${e.name} (string) is required`,n);return r}function ze(t,e,n){let r=Je(t,e);if(r===void 0)throw new y(`${e.name} (number) is required`,n);return r}function tn(t,e,n){let r=ke(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=_(t,e);if(!i)throw new y(`${r} (URI reference) is required`,n);return i}function he(t){return{publisher:t.publisher,package_:t.package_,name:t.name}}var U=class extends Error{},ue=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 Ze(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 Ze(r)}case"property-read":{let r=await this.evaluate(e.source,n);return Ye(r,e.readProp)}case"traverse":{let r=await this.evaluate(e.source,n);if(!(r instanceof L))return;let i=rn(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(se(m))}return a.join("")}case"uri-name":{let r=await this.evaluate(e.source,n);return G(r)?r.name:r instanceof h?r.subject.name:r instanceof w?r.name:r instanceof P?r.name??"":void 0}case"uri-publisher":{let r=await this.evaluate(e.source,n);return be(r)?.publisher}case"uri-package":{let r=await this.evaluate(e.source,n);return be(r)?.package_}case"uri-version":{let r=await this.evaluate(e.source,n);return be(r)?.version}case"subject-uri":{let r=await this.evaluate(e.source,n);if(r instanceof w){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?Ye(r,e.labelSource):void 0}case"resolve-ref":{let r=await this.evaluate(e.source,n);return r instanceof w?r:r instanceof h?await this.resolver.resolveSubject(r.subject,this.catalog):G(r)?await this.resolver.resolveSubject(r,this.catalog):void 0}case"normalize":{let r=await this.evaluate(e.source,n),i=r==null?"":se(r);return e.normKind==="trim-end"?i.replace(/[\s\r\n]+$/u,""):i}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;Array.isArray(a)&&on.has(u)&&a.every(c=>sn(c))&&(a=a.map(c=>String(c)).join("")),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?"":se(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=et(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=et(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 L?r.statement:[]}case"statement-predicate":{let r=await this.evaluate(e.source,n);if(we(r)){let i=r.predicate;if(i instanceof h)return i}return}case"statement-value":{let r=await this.evaluate(e.source,n);return we(r)?ln(r):void 0}case"date-format":{let r=await this.evaluate(e.source,n),i=r==null?"":se(r);return i?cn(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 Qe(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(Qe(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 w}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(!we(r))return;let i=r;return i instanceof D||i instanceof C||i instanceof B||i instanceof j||i instanceof T||i instanceof b?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 L)||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 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 Ye(t,e){if(t instanceof L)return nn(t,e);if(an(t))return v(e,o.key)?t.key:v(e,o.members)?t.members:void 0}function nn(t,e){for(let n of t.statement){let r=tt(n);if(!(!r||!v(r,e))&&(n instanceof D||n instanceof C||n instanceof B||n instanceof j||n instanceof T||n instanceof b))return n.object}}function rn(t,e){let n=[];for(let r of t.statement){let i=tt(r);if(!(!i||!v(i,e))){if(r instanceof j)n.push(r.object.subject);else if(r instanceof b)for(let a of r.object)a instanceof h&&n.push(a.subject)}}return n}function tt(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 L)return t.name??"";if(t instanceof h)return t.subject.name;if(G(t))return t.name;let e=t.value;return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function Ze(t){return t==null?!1:typeof t=="string"||Array.isArray(t)?t.length>0:typeof t=="boolean"?t===!0:!0}function G(t){return typeof t=="object"&&t!==null&&typeof t.publisher=="string"&&typeof t.package_=="string"&&typeof t.name=="string"}function an(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 ${un(t)}`)}function be(t){if(t instanceof w){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);return n<0||r<0?void 0:{publisher:e.substring(0,n),package_:e.substring(n+1,r),version:e.substring(r+1),name:t.name??""}}if(t instanceof 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(G(t))return{publisher:t.publisher,package_:t.package_,version:"",name:t.name}}var on=new Set(["stringValue","text","rawContent","key","propertyKey","linkLabel"]);function sn(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function un(t){return t===void 0?"undefined":t===null?"null":Array.isArray(t)?`array(${t.length})`:typeof t}function cn(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 Qe(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=xe(t),c=xe(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 xe(t){if(t instanceof h){let e=t.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}if(t instanceof w){let e=t.namespace??"",n=e.indexOf("/"),r=e.indexOf("@",n+1);if(n<0)return;let 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(G(t))return{publisher:t.publisher,package_:t.package_,name:t.name}}function we(t){return t instanceof D||t instanceof C||t instanceof B||t instanceof j||t instanceof T||t instanceof b}function ln(t){return t instanceof D||t instanceof C||t instanceof B?String(t.object??""):t instanceof j?t.object?.subject?.name??"":t instanceof T?"[embedded]":t instanceof b?(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 et(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 L){let e=t.name??"";return`k:${t.namespace??""}/${e}`}return G(t)?`u:${t.publisher}/${t.package_}/${t.name}`:`o:${JSON.stringify(t)}`}var fn={"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"}},I=class extends Error{},ce=class{backends=new Map;constructor(){this.register(new X),this.register(new J),this.register(new Y),this.register(new Z),this.register(new Q),this.register(new x)}register(e){this.backends.set(e.backendUri,e)}async run(e){let n=e.transformationKanonaks??e.allKanonaks,r=oe(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 i=this.findBackend(e.outputFormat);if(!i)throw new I(`No backend registered for OutputFormat "${e.outputFormat}".`);let a=new ee(e.repository,e.parser,e.objectParser),u=new ue(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=nt(n.instances,e.inputPattern.requires),u=rt(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);$e(g,e.name,`input "${l.name}"`);let k=Se(await i.evaluate(e.artifactName,m),e.name,`input "${l.name}"`),K=ve(e.overrides.get(n.outputFormat),n.runtimeOverride),S=r.render(g,K);c.push({fileName:k,format:n.outputFormat,content:S,source:{kind:"instance",sourceName:l.name}})}return c}async runSet(e,n,r,i){let a=nt(n.instances,e.inputPattern.requires),u=rt(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);$e(c,e.name,"set");let l=Se(await a.evaluate(e.artifactName,u),e.name,"set"),m=ve(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=pn(g,u);if(k==null)continue;let K=gn(k),S=c.get(K);S||(S={keyValue:k,keyDisplay:yn(k),members:[]},c.set(K,S),l.push(K)),S.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 S=await a.evaluate(e.rule,K);$e(S,e.name,`partition "${k.keyDisplay}"`);let st=Se(await a.evaluate(e.artifactName,K),e.name,`partition "${k.keyDisplay}"`),ut=ve(e.overrides.get(r.outputFormat),r.runtimeOverride),ct=i.render(S,ut);m.push({fileName:st,format:r.outputFormat,content:ct,source:{kind:"set",memberCount:k.members.length,partitionKey:k.keyDisplay}})}return m}findBackend(e){let n=fn[e];if(n)return this.backends.get(n.formatUri)}};function nt(t,e){return e.length===0?t:t.filter(n=>{for(let r of e)if(!mn(n,r))return!1;return!0})}function rt(t,e){if(e.length===0)return t;let n=[...t];return n.sort((r,i)=>{for(let a of e){let u=it(r,a.byProperty),c=it(i,a.byProperty),l=dn(u,c,a.order);if(l!==0)return l}return 0}),n}function it(t,e){for(let n of t.statement){let r=Ee(n);if(!(!r||!v(r,e))){if(n instanceof D||n instanceof C||n instanceof B)return n.object;if(n instanceof b)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 j)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 dn(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 mn(t,e){for(let n of t.statement){let r=Ee(n);if(!r||!v(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 pn(t,e){for(let n of t.statement){let r=Ee(n);if(!(!r||!v(r,e))&&(n instanceof D||n instanceof C||n instanceof B||n instanceof j||n instanceof b))return n.object}}function Ee(t){return t.predicate?.subject}function gn(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 L){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 yn(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):t instanceof h?t.subject.name:t instanceof L?t.name??"":typeof t=="object"&&t!==null&&typeof t.name=="string"?t.name:""}function $e(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: ${at(t)}`)}function Se(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: ${at(t)}`)}function kn(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"}function at(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 ve(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 O=class extends Error{constructor(n,r){super(n);this.cause=r;this.name="RenderError"}cause},ot={publisher:"kanonak.org",package_:"derivation",name:"default"},je=class{constructor(e,n=new Ve,r=new Ae){this.repository=e;this.parser=n;this.objectParser=r}repository;parser;objectParser;runner=new ce;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async findDerivation(e){let n=await this.getCatalog(),r=N(n,e.resource);if(!(r instanceof w))return;let i=e.variant??ot;return Ke(r,e.format,i,n)}async render(e){let n=await this.findDerivation(e);if(!n)throw new O(`No derivation found for ${F(e.resource)} \u2192 format ${F(e.format)}`+(e.variant?` variant ${F(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=N(n,e.transformation);if(!(r instanceof w))throw new O(`Transformation not found: ${F(e.transformation)}`);let i=N(n,e.input);if(!(i instanceof w))throw new O(`Input resource not found: ${F(e.input)}`);let a=oe(r,n),u=hn(a.outputs,e.format);if(!u)throw new O(`Transformation ${F(e.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${F(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 O(`Transformation execution failed: ${l.message}`,l)}if(c.length===0)throw new O("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 F(t){return`${t.publisher}/${t.package_}/${t.name}`}function hn(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{x as CssBackend,ot as DEFAULT_VARIANT,V as DOCAST,ft as DOCAST_PKG,lt as DOCAST_PUB,ue as ExpressionEngineV3,U as ExpressionEvalErrorV3,Z as HtmlBackend,Y as JsonBackend,X as MarkdownFrontmatterBackend,ee as ReferenceResolver,O as RenderError,fn as SUPPORTED_FORMATS_V3,Q as SvgBackend,o as TX_V3,Ft as TX_V3_PKG,Mt as TX_V3_PUB,On as TX_V3_VERSION_MAJOR,J as TomlBackend,je as TransformationEngine,y as TransformationLoadErrorV3,I as TransformationRunnerErrorV3,ce as TransformationRunnerV3,oe as compileTransformationV3,me as renderMarkdownToHtml};
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import type { EntityUri } from '../../uri-helpers/UriHelpers.js';
|
|
23
23
|
export type CompiledTransformationV3 = CompiledInstanceTransformationV3 | CompiledSetTransformationV3;
|
|
24
|
+
/**
|
|
25
|
+
* Fragments are pre-compiled at top-level transformation compilation
|
|
26
|
+
* and held in this map so call-fragment evaluations dispatch at
|
|
27
|
+
* runtime — supporting recursive fragments without compile-time
|
|
28
|
+
* inlining (which has bounded depth).
|
|
29
|
+
*
|
|
30
|
+
* Key: canonical versionless key "publisher/package/name". Matches
|
|
31
|
+
* the EntityUri shape that CallFragment.fragmentRef carries.
|
|
32
|
+
*/
|
|
33
|
+
export type CompiledFragmentRegistryV3 = Map<string, CompiledExpressionV3>;
|
|
24
34
|
export interface CompiledTransformationV3Base {
|
|
25
35
|
/** Local name of the transformation entity, for diagnostics. */
|
|
26
36
|
name: string;
|
|
@@ -35,6 +45,13 @@ export interface CompiledTransformationV3Base {
|
|
|
35
45
|
outputs: Set<string>;
|
|
36
46
|
/** Per-output-format overrides keyed by the OutputFormat's local name. */
|
|
37
47
|
overrides: Map<string, CompiledFormatOverrideV3>;
|
|
48
|
+
/**
|
|
49
|
+
* Pre-compiled ExpressionFragments from the catalog, keyed by
|
|
50
|
+
* canonical versionless URI ("publisher/package/name"). The engine
|
|
51
|
+
* uses this map for runtime call-fragment dispatch — fragments
|
|
52
|
+
* recurse cleanly without bounded compile-time inlining.
|
|
53
|
+
*/
|
|
54
|
+
fragments: CompiledFragmentRegistryV3;
|
|
38
55
|
}
|
|
39
56
|
export interface CompiledInstanceTransformationV3 extends CompiledTransformationV3Base {
|
|
40
57
|
kind: 'instance';
|
|
@@ -73,7 +90,7 @@ export interface CompiledFormatOverrideV3 {
|
|
|
73
90
|
* doctype + style + metadata <dl>; analogous in other backends). */
|
|
74
91
|
omitWrapper?: boolean | undefined;
|
|
75
92
|
}
|
|
76
|
-
export type CompiledExpressionV3 = CompiledStringLiteralV3 | CompiledIntegerLiteralV3 | CompiledDecimalLiteralV3 | CompiledBooleanLiteralV3 | CompiledVarRefV3 | CompiledPropertyReadV3 | CompiledTraverseV3 | CompiledBuildAstNodeV3 | CompiledWhenV3 | CompiledConcatV3 | CompiledFallbackV3 | CompiledUriNameV3 | CompiledUriPublisherV3 | CompiledUriPackageV3 | CompiledUriVersionV3 | CompiledSubjectUriV3 | CompiledUriLiteralV3 | CompiledDisplayLabelV3 | CompiledResolveRefV3 | CompiledNormalizeV3 | CompiledIsSetV3 | CompiledCallFragmentV3 | CompiledJoinV3 | CompiledCountV3 | CompiledSumV3 | CompiledMinV3 | CompiledMaxV3 | CompiledAverageV3 | CompiledForEachV3 | CompiledListMapV3 | CompiledFilterV3 | CompiledPartitionByV3 | CompiledDistinctByV3 | CompiledAllStatementsV3 | CompiledStatementPredicateV3 | CompiledStatementValueV3 | CompiledDateFormatV3 | CompiledAddV3 | CompiledSubtractV3 | CompiledMultiplyV3 | CompiledDivideV3 | CompiledReverseV3 | CompiledWindowedMapV3 | CompiledPairwiseMapV3 | CompiledScanV3 | CompiledListItemAtV3 | CompiledEqualsV3 | CompiledGreaterThanV3 | CompiledLessThanV3 | CompiledGreaterThanOrEqualV3 | CompiledLessThanOrEqualV3 | CompiledNotV3 | CompiledAndV3 | CompiledOrV3 | CompiledContainsV3 | CompiledAbsV3 | CompiledNegateV3 | CompiledIsReferenceV3 | CompiledIsEmbeddedV3 | CompiledIsListV3 | CompiledStatementObjectV3;
|
|
93
|
+
export type CompiledExpressionV3 = CompiledStringLiteralV3 | CompiledIntegerLiteralV3 | CompiledDecimalLiteralV3 | CompiledBooleanLiteralV3 | CompiledVarRefV3 | CompiledPropertyReadV3 | CompiledTraverseV3 | CompiledBuildAstNodeV3 | CompiledWhenV3 | CompiledConcatV3 | CompiledFallbackV3 | CompiledUriNameV3 | CompiledUriPublisherV3 | CompiledUriPackageV3 | CompiledUriVersionV3 | CompiledSubjectUriV3 | CompiledUriLiteralV3 | CompiledDisplayLabelV3 | CompiledResolveRefV3 | CompiledNormalizeV3 | CompiledIsSetV3 | CompiledCallFragmentV3 | CompiledJoinV3 | CompiledCountV3 | CompiledSumV3 | CompiledMinV3 | CompiledMaxV3 | CompiledAverageV3 | CompiledForEachV3 | CompiledListMapV3 | CompiledFilterV3 | CompiledPartitionByV3 | CompiledDistinctByV3 | CompiledAllStatementsV3 | CompiledStatementPredicateV3 | CompiledStatementValueV3 | CompiledDateFormatV3 | CompiledAddV3 | CompiledSubtractV3 | CompiledMultiplyV3 | CompiledDivideV3 | CompiledReverseV3 | CompiledWindowedMapV3 | CompiledPairwiseMapV3 | CompiledScanV3 | CompiledListItemAtV3 | CompiledEqualsV3 | CompiledGreaterThanV3 | CompiledLessThanV3 | CompiledGreaterThanOrEqualV3 | CompiledLessThanOrEqualV3 | CompiledNotV3 | CompiledAndV3 | CompiledOrV3 | CompiledContainsV3 | CompiledAbsV3 | CompiledNegateV3 | CompiledIsReferenceV3 | CompiledIsEmbeddedV3 | CompiledIsListV3 | CompiledStatementObjectV3 | CompiledLetV3 | CompiledGetStatementByNameV3;
|
|
77
94
|
export interface CompiledStringLiteralV3 {
|
|
78
95
|
kind: 'string-literal';
|
|
79
96
|
value: string;
|
|
@@ -298,6 +315,17 @@ export interface CompiledStatementObjectV3 {
|
|
|
298
315
|
kind: 'statement-object';
|
|
299
316
|
source: CompiledExpressionV3;
|
|
300
317
|
}
|
|
318
|
+
export interface CompiledLetV3 {
|
|
319
|
+
kind: 'let';
|
|
320
|
+
bindName: string;
|
|
321
|
+
bindValue: CompiledExpressionV3;
|
|
322
|
+
body: CompiledExpressionV3;
|
|
323
|
+
}
|
|
324
|
+
export interface CompiledGetStatementByNameV3 {
|
|
325
|
+
kind: 'get-statement-by-name';
|
|
326
|
+
inSubject: CompiledExpressionV3;
|
|
327
|
+
byName: CompiledExpressionV3;
|
|
328
|
+
}
|
|
301
329
|
export type NormalizeKindV3 = 'trim-end';
|
|
302
330
|
export interface CompiledNormalizeV3 {
|
|
303
331
|
kind: 'normalize';
|
|
@@ -310,8 +338,14 @@ export interface CompiledIsSetV3 {
|
|
|
310
338
|
}
|
|
311
339
|
export interface CompiledCallFragmentV3 {
|
|
312
340
|
kind: 'call-fragment';
|
|
313
|
-
/**
|
|
314
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Versionless canonical key ("publisher/package/name") of the
|
|
343
|
+
* fragment to invoke. The engine looks the key up in the
|
|
344
|
+
* compiled-transformation's fragments registry at runtime,
|
|
345
|
+
* which lets fragments recurse without compile-time inlining
|
|
346
|
+
* blowing past MAX_FRAGMENT_DEPTH.
|
|
347
|
+
*/
|
|
348
|
+
fragmentKey: string;
|
|
315
349
|
}
|
|
316
350
|
export interface CompiledJoinV3 {
|
|
317
351
|
kind: 'join';
|
|
@@ -36,7 +36,21 @@ export declare class ExpressionEvalErrorV3 extends Error {
|
|
|
36
36
|
export declare class ExpressionEngineV3 {
|
|
37
37
|
private readonly resolver;
|
|
38
38
|
private readonly catalog;
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Pre-compiled ExpressionFragments keyed by canonical versionless
|
|
41
|
+
* URI ("publisher/package/name"). Empty when not provided
|
|
42
|
+
* (the call-fragment case errors visibly if invoked without
|
|
43
|
+
* a registry — never silently no-ops).
|
|
44
|
+
*/
|
|
45
|
+
private readonly fragments;
|
|
46
|
+
constructor(resolver: ReferenceResolver, catalog: Kanonak[],
|
|
47
|
+
/**
|
|
48
|
+
* Pre-compiled ExpressionFragments keyed by canonical versionless
|
|
49
|
+
* URI ("publisher/package/name"). Empty when not provided
|
|
50
|
+
* (the call-fragment case errors visibly if invoked without
|
|
51
|
+
* a registry — never silently no-ops).
|
|
52
|
+
*/
|
|
53
|
+
fragments?: Map<string, CompiledExpressionV3>);
|
|
40
54
|
evaluate(expr: CompiledExpressionV3, env: Env): Promise<EnvValue>;
|
|
41
55
|
/**
|
|
42
56
|
* Evaluate a source expression and coerce its result into a list.
|
|
@@ -32,6 +32,7 @@ import { SubjectKanonak, type Kanonak } from '../../kanonaks/index.js';
|
|
|
32
32
|
import { KanonakParser, KanonakObjectParser } from '../../parsing/index.js';
|
|
33
33
|
import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
|
|
34
34
|
import type { IDocumentAstBackend } from '../backends/IDocumentAstBackend.js';
|
|
35
|
+
import type { BackendFormatOverride } from '../FormatOverride.js';
|
|
35
36
|
import { TransformationLoadErrorV3 } from './TransformationLoaderV3.js';
|
|
36
37
|
import type { CompiledTransformationV3 } from './CompiledTransformationV3.js';
|
|
37
38
|
export interface ArtifactV3 {
|
|
@@ -74,6 +75,15 @@ export interface RunInputV3 {
|
|
|
74
75
|
objectParser: KanonakObjectParser;
|
|
75
76
|
/** OutputFormat local name (e.g. `'markdown-with-frontmatter'`). */
|
|
76
77
|
outputFormat: string;
|
|
78
|
+
/**
|
|
79
|
+
* Optional runtime override merged into the backend FormatOverride
|
|
80
|
+
* for this run. Lets a consumer (e.g. the VS Code Browser embedding
|
|
81
|
+
* HTML inside its own webview shell) pass `omitWrapper: true`
|
|
82
|
+
* without needing to mutate the transformation source. Merges
|
|
83
|
+
* field-by-field with any compiled override declared on the
|
|
84
|
+
* transformation; runtime fields win when both are set.
|
|
85
|
+
*/
|
|
86
|
+
runtimeOverride?: BackendFormatOverride;
|
|
77
87
|
}
|
|
78
88
|
export declare class TransformationRunnerErrorV3 extends Error {
|
|
79
89
|
}
|
|
@@ -197,4 +197,11 @@ export declare const TX_V3: {
|
|
|
197
197
|
readonly kindCheck: EntityUri;
|
|
198
198
|
readonly StatementObject: EntityUri;
|
|
199
199
|
readonly statementSource: EntityUri;
|
|
200
|
+
readonly Let: EntityUri;
|
|
201
|
+
readonly letName: EntityUri;
|
|
202
|
+
readonly letValue: EntityUri;
|
|
203
|
+
readonly letBody: EntityUri;
|
|
204
|
+
readonly GetStatementByName: EntityUri;
|
|
205
|
+
readonly inSubject: EntityUri;
|
|
206
|
+
readonly byName: EntityUri;
|
|
200
207
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"yaml-parser"
|
|
122
122
|
],
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@kanonak-protocol/types": "^3.
|
|
124
|
+
"@kanonak-protocol/types": "^3.13.0",
|
|
125
125
|
"ignore": "^7.0.5",
|
|
126
126
|
"js-yaml": "^4.1.0",
|
|
127
127
|
"yaml": "^2.7.0"
|