@kanonak-protocol/sdk 3.11.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.
Files changed (53) hide show
  1. package/dist/KanonakUri-4VJGV3FN.js +1 -0
  2. package/dist/browser.js +2 -48
  3. package/dist/chunk-3JRHG2JH.js +1 -0
  4. package/dist/chunk-7M7XXZOV.js +1 -0
  5. package/dist/chunk-AFF2TQ7Y.js +2 -0
  6. package/dist/chunk-C54LRL2A.js +42 -0
  7. package/dist/chunk-CNM3SY5S.js +2 -0
  8. package/dist/chunk-CRR4BQKR.js +1 -0
  9. package/dist/chunk-FQHALFRR.js +1 -0
  10. package/dist/chunk-FUUTGGJS.js +1 -0
  11. package/dist/chunk-GKQVJITL.js +1 -0
  12. package/dist/chunk-MYITGTGJ.js +1 -0
  13. package/dist/chunk-NPWF35XZ.js +1 -0
  14. package/dist/chunk-ODIECDN7.js +1 -0
  15. package/dist/chunk-QJ66UBDY.js +1 -0
  16. package/dist/chunk-RGMZAKJV.js +1 -0
  17. package/dist/chunk-USLG7UIM.js +4 -0
  18. package/dist/chunk-W6T7MOKY.js +1 -0
  19. package/dist/chunk-YENGFI2R.js +1 -0
  20. package/dist/ctl/index.js +1 -4
  21. package/dist/filtering/index.js +1 -1
  22. package/dist/index.js +26 -72
  23. package/dist/parsing/index.js +1 -1
  24. package/dist/reasoning/index.js +1 -1
  25. package/dist/repositories/browser.js +1 -2
  26. package/dist/repositories/index.js +1 -2
  27. package/dist/resolution/index.js +1 -1
  28. package/dist/transformations/DocAst.d.ts +163 -0
  29. package/dist/transformations/DocAstUriConstants.d.ts +71 -0
  30. package/dist/transformations/FormatOverride.d.ts +34 -0
  31. package/dist/transformations/ReferenceResolver.d.ts +23 -0
  32. package/dist/transformations/TransformationEngine.d.ts +83 -0
  33. package/dist/transformations/backends/CssBackend.d.ts +7 -0
  34. package/dist/transformations/backends/HtmlBackend.d.ts +7 -0
  35. package/dist/transformations/backends/IDocumentAstBackend.d.ts +16 -0
  36. package/dist/transformations/backends/JsonBackend.d.ts +12 -0
  37. package/dist/transformations/backends/MarkdownFrontmatterBackend.d.ts +7 -0
  38. package/dist/transformations/backends/SimpleMarkdownRenderer.d.ts +17 -0
  39. package/dist/transformations/backends/SvgBackend.d.ts +7 -0
  40. package/dist/transformations/backends/TomlBackend.d.ts +7 -0
  41. package/dist/transformations/index.d.ts +19 -0
  42. package/dist/transformations/index.js +97 -0
  43. package/dist/transformations/v3/CompiledTransformationV3.d.ts +404 -0
  44. package/dist/transformations/v3/ExpressionEngineV3.d.ts +89 -0
  45. package/dist/transformations/v3/TransformationLoaderV3.d.ts +22 -0
  46. package/dist/transformations/v3/TransformationRunnerV3.d.ts +102 -0
  47. package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +207 -0
  48. package/dist/uri-helpers/SingleDocumentRepository.d.ts +28 -0
  49. package/dist/uri-helpers/UriHelpers.d.ts +89 -0
  50. package/dist/uri-helpers/index.d.ts +3 -0
  51. package/dist/uri-helpers/index.js +1 -0
  52. package/dist/validation/index.js +1 -42
  53. package/package.json +18 -2
@@ -0,0 +1,404 @@
1
+ /**
2
+ * Typed, parsed-once representation of a transformations@3.0.0
3
+ * Transformation. Produced by `TransformationLoaderV3` from a
4
+ * `SubjectKanonak` whose RDF type is either `InstanceTransformation`
5
+ * or `SetTransformation`; consumed by `TransformationRunnerV3` and
6
+ * `ExpressionEngineV3`.
7
+ *
8
+ * The full Expression type union is declared here even though slice 1
9
+ * only implements a subset — declaring it upfront means later slices
10
+ * add behavior (loader cases, engine cases) rather than type members.
11
+ *
12
+ * V3 SHAPE NOTES (vs V2):
13
+ * - Top level is a discriminated union over `kind: 'instance' | 'set'`,
14
+ * mirroring the InstanceTransformation/SetTransformation split.
15
+ * - InputPattern carries `sortBy` (ordered list of SortKeys); the V2
16
+ * pattern had no sort.
17
+ * - SetTransformation may carry `partitionBy` for fan-out.
18
+ * - Expression nodes are tagged by their `kind` string here (the
19
+ * compiled form), but in the YAML they're dispatched by RDF type
20
+ * (real OWL hierarchy, not a discriminator instance).
21
+ */
22
+ import type { EntityUri } from '../../uri-helpers/UriHelpers.js';
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>;
34
+ export interface CompiledTransformationV3Base {
35
+ /** Local name of the transformation entity, for diagnostics. */
36
+ name: string;
37
+ inputPattern: CompiledInputPatternV3;
38
+ rule: CompiledExpressionV3;
39
+ artifactName: CompiledExpressionV3;
40
+ /**
41
+ * The set of OutputFormat URIs this transformation supports, keyed
42
+ * by the OutputFormat's local name. The runner rejects requests to
43
+ * render in a format not in this set.
44
+ */
45
+ outputs: Set<string>;
46
+ /** Per-output-format overrides keyed by the OutputFormat's local name. */
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;
55
+ }
56
+ export interface CompiledInstanceTransformationV3 extends CompiledTransformationV3Base {
57
+ kind: 'instance';
58
+ }
59
+ export interface CompiledSetTransformationV3 extends CompiledTransformationV3Base {
60
+ kind: 'set';
61
+ /**
62
+ * When set, the runner partitions the matched input set on this
63
+ * property and emits one Artifact per partition; `key` and `inputs`
64
+ * are bound for each evaluation. When undefined, the runner runs
65
+ * `rule` and `artifactName` once with `inputs` bound to the whole
66
+ * matched set, emitting a single Artifact.
67
+ */
68
+ partitionBy?: EntityUri | undefined;
69
+ }
70
+ export interface CompiledInputPatternV3 {
71
+ /** The class URI whose instances are eligible. */
72
+ matchesClass: EntityUri;
73
+ /** Property URIs that must each resolve to non-empty on each instance. */
74
+ requires: EntityUri[];
75
+ /**
76
+ * Ordered list of sort criteria (primary first, ties broken by
77
+ * subsequent keys). Empty for transformations that don't need order.
78
+ */
79
+ sortBy: CompiledSortKeyV3[];
80
+ }
81
+ export interface CompiledSortKeyV3 {
82
+ byProperty: EntityUri;
83
+ order: 'ascending' | 'descending';
84
+ }
85
+ export interface CompiledFormatOverrideV3 {
86
+ metadataKeys?: string[] | undefined;
87
+ metadataRenames: Map<string, string>;
88
+ trailingNewline?: boolean | undefined;
89
+ /** When true, backends suppress their default chrome (HTML's
90
+ * doctype + style + metadata <dl>; analogous in other backends). */
91
+ omitWrapper?: boolean | undefined;
92
+ }
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;
94
+ export interface CompiledStringLiteralV3 {
95
+ kind: 'string-literal';
96
+ value: string;
97
+ }
98
+ export interface CompiledIntegerLiteralV3 {
99
+ kind: 'integer-literal';
100
+ value: number;
101
+ }
102
+ export interface CompiledDecimalLiteralV3 {
103
+ kind: 'decimal-literal';
104
+ value: number;
105
+ }
106
+ export interface CompiledBooleanLiteralV3 {
107
+ kind: 'boolean-literal';
108
+ value: boolean;
109
+ }
110
+ export interface CompiledVarRefV3 {
111
+ kind: 'var-ref';
112
+ varName: string;
113
+ }
114
+ export interface CompiledPropertyReadV3 {
115
+ kind: 'property-read';
116
+ source: CompiledExpressionV3;
117
+ readProp: EntityUri;
118
+ }
119
+ export interface CompiledTraverseV3 {
120
+ kind: 'traverse';
121
+ source: CompiledExpressionV3;
122
+ through: EntityUri;
123
+ step: CompiledExpressionV3;
124
+ }
125
+ export interface CompiledBuildAstNodeV3 {
126
+ kind: 'build-ast-node';
127
+ astClass: EntityUri;
128
+ set: CompiledFieldBindingV3[];
129
+ }
130
+ export interface CompiledFieldBindingV3 {
131
+ field: EntityUri;
132
+ value: CompiledExpressionV3;
133
+ }
134
+ export interface CompiledWhenV3 {
135
+ kind: 'when';
136
+ condition: CompiledExpressionV3;
137
+ thenBuild: CompiledExpressionV3;
138
+ elseBuild?: CompiledExpressionV3 | undefined;
139
+ }
140
+ export interface CompiledConcatV3 {
141
+ kind: 'concat';
142
+ parts: CompiledExpressionV3[];
143
+ }
144
+ export interface CompiledFallbackV3 {
145
+ kind: 'fallback';
146
+ primary: CompiledExpressionV3;
147
+ alternate: CompiledExpressionV3;
148
+ }
149
+ export interface CompiledUriNameV3 {
150
+ kind: 'uri-name';
151
+ source: CompiledExpressionV3;
152
+ }
153
+ export interface CompiledUriPublisherV3 {
154
+ kind: 'uri-publisher';
155
+ source: CompiledExpressionV3;
156
+ }
157
+ export interface CompiledUriPackageV3 {
158
+ kind: 'uri-package';
159
+ source: CompiledExpressionV3;
160
+ }
161
+ export interface CompiledUriVersionV3 {
162
+ kind: 'uri-version';
163
+ source: CompiledExpressionV3;
164
+ }
165
+ export interface CompiledSubjectUriV3 {
166
+ kind: 'subject-uri';
167
+ source: CompiledExpressionV3;
168
+ }
169
+ export interface CompiledUriLiteralV3 {
170
+ kind: 'uri-literal';
171
+ refTo: EntityUri;
172
+ }
173
+ export interface CompiledDisplayLabelV3 {
174
+ kind: 'display-label';
175
+ labelTarget: EntityUri;
176
+ labelSource: EntityUri;
177
+ }
178
+ export interface CompiledResolveRefV3 {
179
+ kind: 'resolve-ref';
180
+ source: CompiledExpressionV3;
181
+ }
182
+ export interface CompiledAllStatementsV3 {
183
+ kind: 'all-statements';
184
+ source: CompiledExpressionV3;
185
+ }
186
+ export interface CompiledStatementPredicateV3 {
187
+ kind: 'statement-predicate';
188
+ source: CompiledExpressionV3;
189
+ }
190
+ export interface CompiledStatementValueV3 {
191
+ kind: 'statement-value';
192
+ source: CompiledExpressionV3;
193
+ }
194
+ /** Named output formats supported by the engine. */
195
+ export type DateFormatKindV3 = 'iso-date' | 'iso-datetime' | 'short-date' | 'long-date' | 'year' | 'month-year';
196
+ export interface CompiledDateFormatV3 {
197
+ kind: 'date-format';
198
+ source: CompiledExpressionV3;
199
+ format: DateFormatKindV3;
200
+ }
201
+ export interface CompiledAddV3 {
202
+ kind: 'add';
203
+ left: CompiledExpressionV3;
204
+ right: CompiledExpressionV3;
205
+ }
206
+ export interface CompiledSubtractV3 {
207
+ kind: 'subtract';
208
+ left: CompiledExpressionV3;
209
+ right: CompiledExpressionV3;
210
+ }
211
+ export interface CompiledMultiplyV3 {
212
+ kind: 'multiply';
213
+ left: CompiledExpressionV3;
214
+ right: CompiledExpressionV3;
215
+ }
216
+ export interface CompiledDivideV3 {
217
+ kind: 'divide';
218
+ left: CompiledExpressionV3;
219
+ right: CompiledExpressionV3;
220
+ }
221
+ export interface CompiledReverseV3 {
222
+ kind: 'reverse';
223
+ source: CompiledExpressionV3;
224
+ }
225
+ export interface CompiledWindowedMapV3 {
226
+ kind: 'windowed-map';
227
+ source: CompiledExpressionV3;
228
+ windowSize: number;
229
+ windowVar: string;
230
+ windowBody: CompiledExpressionV3;
231
+ }
232
+ export interface CompiledPairwiseMapV3 {
233
+ kind: 'pairwise-map';
234
+ source: CompiledExpressionV3;
235
+ firstVar: string;
236
+ secondVar: string;
237
+ pairBody: CompiledExpressionV3;
238
+ }
239
+ export interface CompiledScanV3 {
240
+ kind: 'scan';
241
+ source: CompiledExpressionV3;
242
+ initialState: CompiledExpressionV3;
243
+ stateVar: string;
244
+ elementVar: string;
245
+ accumulate: CompiledExpressionV3;
246
+ }
247
+ export interface CompiledListItemAtV3 {
248
+ kind: 'list-item-at';
249
+ source: CompiledExpressionV3;
250
+ itemIndex: CompiledExpressionV3;
251
+ }
252
+ export interface CompiledEqualsV3 {
253
+ kind: 'equals';
254
+ left: CompiledExpressionV3;
255
+ right: CompiledExpressionV3;
256
+ }
257
+ export interface CompiledGreaterThanV3 {
258
+ kind: 'greater-than';
259
+ left: CompiledExpressionV3;
260
+ right: CompiledExpressionV3;
261
+ }
262
+ export interface CompiledLessThanV3 {
263
+ kind: 'less-than';
264
+ left: CompiledExpressionV3;
265
+ right: CompiledExpressionV3;
266
+ }
267
+ export interface CompiledGreaterThanOrEqualV3 {
268
+ kind: 'greater-than-or-equal';
269
+ left: CompiledExpressionV3;
270
+ right: CompiledExpressionV3;
271
+ }
272
+ export interface CompiledLessThanOrEqualV3 {
273
+ kind: 'less-than-or-equal';
274
+ left: CompiledExpressionV3;
275
+ right: CompiledExpressionV3;
276
+ }
277
+ export interface CompiledNotV3 {
278
+ kind: 'not';
279
+ operand: CompiledExpressionV3;
280
+ }
281
+ export interface CompiledAndV3 {
282
+ kind: 'and';
283
+ operands: CompiledExpressionV3[];
284
+ }
285
+ export interface CompiledOrV3 {
286
+ kind: 'or';
287
+ operands: CompiledExpressionV3[];
288
+ }
289
+ export interface CompiledContainsV3 {
290
+ kind: 'contains';
291
+ haystack: CompiledExpressionV3;
292
+ needle: CompiledExpressionV3;
293
+ }
294
+ export interface CompiledAbsV3 {
295
+ kind: 'abs';
296
+ value: CompiledExpressionV3;
297
+ }
298
+ export interface CompiledNegateV3 {
299
+ kind: 'negate';
300
+ value: CompiledExpressionV3;
301
+ }
302
+ export interface CompiledIsReferenceV3 {
303
+ kind: 'is-reference';
304
+ check: CompiledExpressionV3;
305
+ }
306
+ export interface CompiledIsEmbeddedV3 {
307
+ kind: 'is-embedded';
308
+ check: CompiledExpressionV3;
309
+ }
310
+ export interface CompiledIsListV3 {
311
+ kind: 'is-list';
312
+ check: CompiledExpressionV3;
313
+ }
314
+ export interface CompiledStatementObjectV3 {
315
+ kind: 'statement-object';
316
+ source: CompiledExpressionV3;
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
+ }
329
+ export type NormalizeKindV3 = 'trim-end';
330
+ export interface CompiledNormalizeV3 {
331
+ kind: 'normalize';
332
+ source: CompiledExpressionV3;
333
+ normKind: NormalizeKindV3;
334
+ }
335
+ export interface CompiledIsSetV3 {
336
+ kind: 'is-set';
337
+ check: CompiledExpressionV3;
338
+ }
339
+ export interface CompiledCallFragmentV3 {
340
+ kind: 'call-fragment';
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;
349
+ }
350
+ export interface CompiledJoinV3 {
351
+ kind: 'join';
352
+ source: CompiledExpressionV3;
353
+ separator: string;
354
+ }
355
+ export interface CompiledCountV3 {
356
+ kind: 'count';
357
+ source: CompiledExpressionV3;
358
+ }
359
+ export interface CompiledSumV3 {
360
+ kind: 'sum';
361
+ source: CompiledExpressionV3;
362
+ }
363
+ export interface CompiledMinV3 {
364
+ kind: 'min';
365
+ source: CompiledExpressionV3;
366
+ }
367
+ export interface CompiledMaxV3 {
368
+ kind: 'max';
369
+ source: CompiledExpressionV3;
370
+ }
371
+ export interface CompiledAverageV3 {
372
+ kind: 'average';
373
+ source: CompiledExpressionV3;
374
+ }
375
+ export interface CompiledForEachV3 {
376
+ kind: 'for-each';
377
+ source: CompiledExpressionV3;
378
+ loopVar: string;
379
+ emit: CompiledExpressionV3;
380
+ }
381
+ export interface CompiledListMapV3 {
382
+ kind: 'list-map';
383
+ source: CompiledExpressionV3;
384
+ loopVar: string;
385
+ mapBody: CompiledExpressionV3;
386
+ }
387
+ export interface CompiledFilterV3 {
388
+ kind: 'filter';
389
+ source: CompiledExpressionV3;
390
+ loopVar: string;
391
+ predicate: CompiledExpressionV3;
392
+ }
393
+ export interface CompiledPartitionByV3 {
394
+ kind: 'partition-by';
395
+ source: CompiledExpressionV3;
396
+ loopVar: string;
397
+ partitionKey: CompiledExpressionV3;
398
+ }
399
+ export interface CompiledDistinctByV3 {
400
+ kind: 'distinct-by';
401
+ source: CompiledExpressionV3;
402
+ loopVar: string;
403
+ distinctKey: CompiledExpressionV3;
404
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Evaluates a `CompiledExpressionV3` tree against an environment.
3
+ *
4
+ * Covers the full v3 Expression hierarchy. Aggregations are strict
5
+ * about element types — non-numeric elements in a Sum/Min/Max/Average
6
+ * raise a runtime error. Min/Max/Average on an empty list also error
7
+ * (per the ontology contract); Sum on empty returns 0; Count works
8
+ * regardless of element type.
9
+ *
10
+ * Property reads walk `statement[]` by canonical predicate URI via
11
+ * `UriHelpers`. Reference resolution during traversal goes through
12
+ * the shared `ReferenceResolver`.
13
+ */
14
+ import { type Kanonak } from '../../kanonaks/index.js';
15
+ import { type EntityUri } from '../../uri-helpers/UriHelpers.js';
16
+ import { ReferenceResolver } from '../ReferenceResolver.js';
17
+ import type { CompiledExpressionV3 } from './CompiledTransformationV3.js';
18
+ /**
19
+ * Runtime representation of a Partition produced by the
20
+ * `PartitionBy` expression. Carries the partition key value plus
21
+ * the list of source elements that share that key.
22
+ *
23
+ * The engine surfaces Partitions as plain JS objects; PropertyRead
24
+ * special-cases this shape so authors can read `partition.key` and
25
+ * `partition.members` from inside a ForEach over the partition list.
26
+ */
27
+ export interface RuntimePartitionV3 {
28
+ kind: 'Partition';
29
+ key: EnvValue;
30
+ members: Kanonak[];
31
+ }
32
+ export type EnvValue = string | number | boolean | Kanonak | Kanonak[] | EnvValue[] | RuntimePartitionV3 | EntityUri | unknown | undefined | null;
33
+ export type Env = Map<string, EnvValue>;
34
+ export declare class ExpressionEvalErrorV3 extends Error {
35
+ }
36
+ export declare class ExpressionEngineV3 {
37
+ private readonly resolver;
38
+ private readonly catalog;
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>);
54
+ evaluate(expr: CompiledExpressionV3, env: Env): Promise<EnvValue>;
55
+ /**
56
+ * Evaluate a source expression and coerce its result into a list.
57
+ * Single-valued results are wrapped in a single-element list so
58
+ * downstream operations don't have to special-case scalar sources
59
+ * (e.g. an aggregation over a property that happens to be
60
+ * single-valued for one instance and multi-valued for another).
61
+ */
62
+ private evaluateList;
63
+ /**
64
+ * Re-run an iterator with reverse iteration order, preserving each
65
+ * iteration's body output as a logical group. Returns `undefined`
66
+ * for non-iterator sources so the caller falls back to flat-list
67
+ * reversal.
68
+ *
69
+ * Why this exists: iterators (PairwiseMap, ForEach, WindowedMap)
70
+ * flatten array body results into a single output list. Wrapping
71
+ * one in `tx.Reverse` then applies a flat-list reverse, which
72
+ * scrambles per-iteration contents (#18). Re-iterating with
73
+ * reversed source preserves per-iteration body output structure
74
+ * while delivering the iteration sequence in newest-first order.
75
+ *
76
+ * For PairwiseMap, `firstVar` and `secondVar` still bind in
77
+ * chronological order (earlier→later) so per-pair body semantics
78
+ * are unchanged — only the visit order of pairs reverses. This
79
+ * matches the canonical "ascending sortBy + Reverse for newest-
80
+ * first changelog" idiom from issue #14's worked example.
81
+ *
82
+ * ListMap is included even though ListMap doesn't flatten —
83
+ * Reverse over ListMap should still surface body output in
84
+ * reverse order, which falling back to flat reversal would do
85
+ * correctly already; including it here keeps the semantics
86
+ * consistent (re-iterate with reversed source).
87
+ */
88
+ private evaluateReverseIterator;
89
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Compiles a transformations@3.0.0 SubjectKanonak into a typed
3
+ * CompiledTransformationV3. Walks `statement[]` via the SDK's parsed
4
+ * object model — never re-parses YAML, never matches on alias
5
+ * prefixes. Property reads go through `UriHelpers`; type dispatch
6
+ * uses `hasType` against canonical `TX_V3` URIs.
7
+ *
8
+ * Throws `TransformationLoadErrorV3` with a breadcrumb path on the
9
+ * first shape violation.
10
+ */
11
+ import { SubjectKanonak, type Kanonak } from '../../kanonaks/index.js';
12
+ import type { CompiledTransformationV3 } from './CompiledTransformationV3.js';
13
+ export declare class TransformationLoadErrorV3 extends Error {
14
+ readonly path: string;
15
+ constructor(message: string, path: string);
16
+ }
17
+ /**
18
+ * Top-level entry point. Determines whether the SubjectKanonak is an
19
+ * InstanceTransformation or SetTransformation by RDF type, then
20
+ * dispatches to the appropriate compiler.
21
+ */
22
+ export declare function compileTransformationV3(transformation: SubjectKanonak, catalog: Kanonak[]): CompiledTransformationV3;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Runtime entry point for transformations@3.0.0.
3
+ *
4
+ * Two pipelines:
5
+ *
6
+ * - InstanceTransformation: 1 input → 1 artifact. The runner filters
7
+ * candidates by InputPattern, then evaluates `rule` and
8
+ * `artifactName` once per candidate with `input` bound. Sort
9
+ * order on the InputPattern affects the order of emitted
10
+ * artifacts but doesn't change the cardinality.
11
+ *
12
+ * - SetTransformation:
13
+ * Without partitionBy: N candidates → 1 artifact, with `inputs`
14
+ * bound to the entire matched (and optionally sorted) list.
15
+ * With partitionBy: candidates are partitioned by the property
16
+ * value; one artifact per partition, with `inputs` bound to
17
+ * that partition's members and `key` bound to the partition
18
+ * value. Candidates whose partition property is absent are
19
+ * dropped (no group is created).
20
+ *
21
+ * Sort behavior:
22
+ * - SortKey.byProperty is read off each candidate. Missing values
23
+ * sort last (ascending) or first (descending). Lists or
24
+ * references on the sort property are an authoring error caught
25
+ * here at runtime.
26
+ *
27
+ * The runner does NOT touch the filesystem — writing is the
28
+ * deployment handler / CLI's job. Backends are version-agnostic and
29
+ * shared with any other transformation runtime.
30
+ */
31
+ import { SubjectKanonak, type Kanonak } from '../../kanonaks/index.js';
32
+ import { KanonakParser, KanonakObjectParser } from '../../parsing/index.js';
33
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
34
+ import type { IDocumentAstBackend } from '../backends/IDocumentAstBackend.js';
35
+ import type { BackendFormatOverride } from '../FormatOverride.js';
36
+ import { TransformationLoadErrorV3 } from './TransformationLoaderV3.js';
37
+ import type { CompiledTransformationV3 } from './CompiledTransformationV3.js';
38
+ export interface ArtifactV3 {
39
+ /** Filename stem (no directory, no extension). */
40
+ fileName: string;
41
+ /** OutputFormat local name this was rendered as. */
42
+ format: string;
43
+ /** Serialized bytes. */
44
+ content: string;
45
+ /** Provenance — which subject(s) drove this artifact. */
46
+ source: ArtifactProvenanceV3;
47
+ }
48
+ export type ArtifactProvenanceV3 = {
49
+ kind: 'instance';
50
+ sourceName: string;
51
+ } | {
52
+ kind: 'set';
53
+ memberCount: number;
54
+ partitionKey?: string;
55
+ };
56
+ export interface FormatDescriptorV3 {
57
+ formatUri: string;
58
+ extension: string;
59
+ }
60
+ export declare const SUPPORTED_FORMATS_V3: Record<string, FormatDescriptorV3>;
61
+ export interface RunInputV3 {
62
+ transformation: SubjectKanonak;
63
+ /** Candidate input subjects. Caller is responsible for subclass-aware selection. */
64
+ instances: SubjectKanonak[];
65
+ /** All loaded kanonaks for fragment lookup + reference resolution. */
66
+ allKanonaks: Kanonak[];
67
+ /**
68
+ * Optional kanonaks of the transformation's own package (where any
69
+ * ExpressionFragments live). Falls back to allKanonaks.
70
+ */
71
+ transformationKanonaks?: Kanonak[];
72
+ /** Repository for cross-package reference resolution at evaluation time. */
73
+ repository: IKanonakDocumentRepository;
74
+ parser: KanonakParser;
75
+ objectParser: KanonakObjectParser;
76
+ /** OutputFormat local name (e.g. `'markdown-with-frontmatter'`). */
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;
87
+ }
88
+ export declare class TransformationRunnerErrorV3 extends Error {
89
+ }
90
+ export declare class TransformationRunnerV3 {
91
+ private readonly backends;
92
+ constructor();
93
+ register(backend: IDocumentAstBackend): void;
94
+ run(input: RunInputV3): Promise<ArtifactV3[]>;
95
+ private runInstance;
96
+ private runSet;
97
+ private runSetSingle;
98
+ private runSetWithPartition;
99
+ private findBackend;
100
+ }
101
+ export { TransformationLoadErrorV3 };
102
+ export type { CompiledTransformationV3 };