@almadar/core 8.0.0 → 8.1.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.
@@ -1,833 +0,0 @@
1
- import { e as DomainEntity, J as ParseResult, l as DomainPage, D as DomainBehavior, j as DomainGuard, H as GuardCondition, c as DomainDocument, Q as SectionMapping, P as ParseError, k as DomainMutation } from '../diff-factory-calls-DlBcMWPM.js';
2
- export { A as ASTNode, C as CallSiteDiff, a as ComparisonCondition, b as ComparisonOperator, d as DomainEffect, f as DomainField, g as DomainFieldDefault, h as DomainFieldItems, i as DomainFieldType, m as DomainPageAction, n as DomainPageSection, o as DomainRelationship, p as DomainRuleOverlayEntry, q as DomainTick, r as DomainTransition, E as EffectType, F as FactoryCallSite, s as FactoryCallSiteParams, t as FactoryEntitySignature, u as FactoryPageSignature, v as FactoryParamValue, w as FactorySignature, x as FactorySignatureCatalog, y as FactorySignatureEntityField, z as FactoryTraitSignature, B as FieldCheckCondition, G as FieldReference, L as LogicalCondition, I as LogicalOperator, O as OwnershipOverlayEntry, K as PresentationNavItem, M as PresentationOverlay, R as RelationshipType, N as RuleOverlay, S as SchemaFieldType, T as SourceLocation, U as SourceRange, V as TraitOverlay, W as TraitOverlayEntry, X as TraitOverlayListener, Y as TranslationBinding, Z as TranslationResult, _ as TranslationWarning, $ as UserCheckCondition, a0 as diffFactoryCalls, a1 as translateDomainToParams } from '../diff-factory-calls-DlBcMWPM.js';
3
- import { S as SExpr } from '../expression-BVRFm0sV.js';
4
- import { y as Entity, bg as Trait } from '../trait-BPe356_9.js';
5
- export { H as EntityPersistence, bD as TraitScope } from '../trait-BPe356_9.js';
6
- import { aa as Page, a3 as OrbitalSchema } from '../schema-Bg4qX43l.js';
7
- import 'zod';
8
- import '@almadar/patterns';
9
-
10
- /**
11
- * Domain Language Tokens
12
- *
13
- * Token definitions for the domain language lexer.
14
- */
15
- declare enum TokenType {
16
- NEWLINE = "NEWLINE",
17
- INDENT = "INDENT",
18
- DEDENT = "DEDENT",
19
- TEMPLATE_VAR = "TEMPLATE_VAR",
20
- A = "A",
21
- AN = "AN",
22
- IS = "IS",
23
- IT = "IT",
24
- HAS = "HAS",
25
- BELONGS = "BELONGS",
26
- TO = "TO",
27
- MANY = "MANY",
28
- ONE = "ONE",
29
- AS = "AS",
30
- CAN = "CAN",
31
- BE = "BE",
32
- STARTS = "STARTS",
33
- THE = "THE",
34
- SHOWS = "SHOWS",
35
- ENTITY = "ENTITY",// Explicit entity reference for pages
36
- PURPOSE = "PURPOSE",
37
- URL = "URL",
38
- DISPLAYS = "DISPLAYS",
39
- USERS = "USERS",
40
- WHEN = "WHEN",
41
- ACCESSED = "ACCESSED",
42
- LIFECYCLE = "LIFECYCLE",
43
- BEHAVIOR = "BEHAVIOR",
44
- STATES = "STATES",
45
- INITIAL = "INITIAL",
46
- TRANSITIONS = "TRANSITIONS",
47
- FROM = "FROM",
48
- IF = "IF",
49
- THEN = "THEN",
50
- RULES = "RULES",
51
- EVERY = "EVERY",
52
- CHECK = "CHECK",
53
- AND = "AND",
54
- OR = "OR",
55
- NOT = "NOT",
56
- PROVIDED = "PROVIDED",
57
- EMPTY = "EMPTY",
58
- USER = "USER",
59
- OWNS = "OWNS",
60
- THIS = "THIS",
61
- TEXT = "TEXT",
62
- LONG_TEXT = "LONG_TEXT",
63
- NUMBER = "NUMBER",
64
- CURRENCY = "CURRENCY",
65
- DATE = "DATE",
66
- TIMESTAMP = "TIMESTAMP",
67
- YES_NO = "YES_NO",
68
- ENUM = "ENUM",
69
- LIST = "LIST",
70
- REQUIRED = "REQUIRED",
71
- UNIQUE = "UNIQUE",
72
- AUTO = "AUTO",
73
- DEFAULT = "DEFAULT",
74
- COLON = "COLON",
75
- COMMA = "COMMA",
76
- PIPE = "PIPE",
77
- DOT = "DOT",
78
- DASH = "DASH",
79
- LBRACKET = "LBRACKET",
80
- RBRACKET = "RBRACKET",
81
- LPAREN = "LPAREN",
82
- RPAREN = "RPAREN",
83
- GREATER_THAN = "GREATER_THAN",
84
- LESS_THAN = "LESS_THAN",
85
- GREATER_EQUAL = "GREATER_EQUAL",
86
- LESS_EQUAL = "LESS_EQUAL",
87
- EQUALS = "EQUALS",
88
- NOT_EQUALS = "NOT_EQUALS",
89
- IDENTIFIER = "IDENTIFIER",
90
- STRING = "STRING",
91
- NUMBER_LITERAL = "NUMBER_LITERAL",
92
- BOOLEAN = "BOOLEAN",
93
- EOF = "EOF",
94
- ERROR = "ERROR"
95
- }
96
- interface Token {
97
- type: TokenType;
98
- value: string;
99
- line: number;
100
- column: number;
101
- offset: number;
102
- }
103
- declare const KEYWORDS: Record<string, TokenType>;
104
- declare const MULTI_WORD_KEYWORDS: Record<string, TokenType>;
105
-
106
- /**
107
- * Domain Language Lexer
108
- *
109
- * Tokenizes domain language text into tokens for parsing.
110
- */
111
-
112
- declare class Lexer {
113
- private input;
114
- private pos;
115
- private line;
116
- private column;
117
- private indentStack;
118
- constructor(input: string);
119
- /**
120
- * Tokenize the entire input
121
- */
122
- tokenize(): Token[];
123
- private nextToken;
124
- private consumeTemplateVar;
125
- private handleIndentation;
126
- private consumeNewline;
127
- private consumeString;
128
- private consumeNumber;
129
- private consumeIdentifier;
130
- private consumeChar;
131
- private consumeChars;
132
- private skipWhitespace;
133
- private skipToEndOfLine;
134
- private makeToken;
135
- private peek;
136
- private peekNext;
137
- private advance;
138
- private isAtEnd;
139
- private isDigit;
140
- private isAlpha;
141
- private isAlphaNumeric;
142
- }
143
- /**
144
- * Convenience function to tokenize a string
145
- */
146
- declare function tokenize(input: string): Token[];
147
-
148
- /**
149
- * Entity Parser
150
- *
151
- * Parses entity definitions from domain language.
152
- * All entity references are explicit (e.g., Order, User, Task).
153
- */
154
-
155
- /**
156
- * Parse an entity definition from domain text
157
- *
158
- * @example
159
- * parseEntity(`
160
- * A Order is a customer purchase request
161
- * It has:
162
- * - order number: text, required, unique
163
- * - amount: currency
164
- * - status: Pending | Confirmed | Shipped
165
- * It belongs to User
166
- * It can be: Pending, Confirmed, Shipped, Delivered, Cancelled
167
- * It starts as Pending
168
- * `)
169
- */
170
- declare function parseEntity(text: string): ParseResult<DomainEntity>;
171
- /**
172
- * Format an entity AST back to domain text
173
- */
174
- declare function formatEntityToDomain(entity: DomainEntity): string;
175
- /**
176
- * Format entity AST to KFlow schema
177
- */
178
- declare function formatEntityToSchema(entity: DomainEntity): Record<string, unknown>;
179
-
180
- /**
181
- * Page Parser
182
- *
183
- * Parses page definitions from domain language.
184
- */
185
-
186
- /**
187
- * Parse a page definition from domain text
188
- *
189
- * @example
190
- * parsePage(`
191
- * The Dashboard shows an overview of system activity
192
- * Purpose: Help users monitor their tasks and orders
193
- * URL: /dashboard
194
- *
195
- * It displays:
196
- * - Summary statistics for today
197
- * - Recent orders list
198
- * - Pending tasks requiring attention
199
- *
200
- * Users can:
201
- * - Click a task to view details
202
- * - Filter orders by status
203
- * `)
204
- */
205
- declare function parsePage(text: string): ParseResult<DomainPage>;
206
- /**
207
- * Format a page AST back to domain text
208
- */
209
- declare function formatPageToDomain(page: DomainPage): string;
210
- /**
211
- * Format page AST to KFlow schema
212
- */
213
- declare function formatPageToSchema(page: DomainPage): Record<string, unknown>;
214
-
215
- /**
216
- * Behavior Parser
217
- *
218
- * Parses behavior/trait definitions from domain language.
219
- * Behaviors define state machines with transitions, guards, and effects.
220
- * All entity references are explicit (e.g., Order.status, CurrentUser.role).
221
- */
222
-
223
- /**
224
- * Parse a behavior definition from domain text
225
- *
226
- * @example
227
- * parseBehavior(`
228
- * Order Lifecycle
229
- *
230
- * States: Pending, Confirmed, Shipped, Delivered, Cancelled
231
- *
232
- * Transitions:
233
- * - From Pending to Confirmed when CONFIRM
234
- * if Order.amount > 0
235
- * then notify customer
236
- * - From Confirmed to Shipped when SHIP
237
- * - From Shipped to Delivered when DELIVER
238
- * - From any to Cancelled when CANCEL
239
- * if Order.status is not Delivered
240
- *
241
- * Rules:
242
- * - Orders over $1000 require manager approval
243
- * - Cancelled orders cannot be reactivated
244
- * `, "Order")
245
- */
246
- declare function parseBehavior(text: string, entityName: string): ParseResult<DomainBehavior>;
247
- /**
248
- * Format a behavior AST back to domain text
249
- */
250
- declare function formatBehaviorToDomain(behavior: DomainBehavior): string;
251
- /**
252
- * Format behavior AST to KFlow schema trait
253
- */
254
- declare function formatBehaviorToSchema(behavior: DomainBehavior): Record<string, unknown>;
255
-
256
- /**
257
- * Guard Expression Parser
258
- *
259
- * Parses guard expressions deterministically from domain language.
260
- * All entity references are explicit (e.g., Order.amount, CurrentUser.role).
261
- */
262
-
263
- /**
264
- * Parse a guard expression from domain text
265
- *
266
- * @example
267
- * parseGuard("if amount > 1000", "Order")
268
- * // Returns: { field: { entityName: "Order", fieldName: "amount" }, operator: ">", value: 1000 }
269
- */
270
- declare function parseGuard(text: string, entityName: string): ParseResult<DomainGuard>;
271
- /**
272
- * Format a guard condition back to KFlow schema guard string
273
- */
274
- declare function formatGuardToSchema(guard: DomainGuard): string;
275
- /**
276
- * Format a guard condition back to domain language
277
- */
278
- declare function formatGuardToDomain(guard: DomainGuard): string;
279
-
280
- /**
281
- * S-Expression Parser
282
- *
283
- * Parses domain language text (guards/effects) back to S-Expression arrays.
284
- * This is the reverse of what sexpr-formatter.ts does.
285
- *
286
- * @example
287
- * parseDomainGuard("health is at least 0") → [">=", "@entity.health", 0]
288
- * parseDomainEffect("update status to 'done'") → ["set", "@entity.status", "done"]
289
- *
290
- * @packageDocumentation
291
- */
292
-
293
- /**
294
- * Parse a domain guard expression to S-Expression.
295
- *
296
- * @param text - Domain language guard (e.g., "health is at least 0", "status is 'active'")
297
- * @param entityName - The entity context for unqualified field references
298
- * @returns S-Expression array
299
- *
300
- * @example
301
- * parseDomainGuard("health is at least 0") → [">=", "@entity.health", 0]
302
- * parseDomainGuard("status is 'active'") → ["=", "@entity.status", "active"]
303
- * parseDomainGuard("x > 0 and y < 100") → ["and", [">", "@entity.x", 0], ["<", "@entity.y", 100]]
304
- */
305
- declare function parseDomainGuard(text: string, entityName?: string): SExpr;
306
- /**
307
- * Parse a domain effect expression to S-Expression.
308
- *
309
- * @param text - Domain language effect (e.g., "update status to 'done'", "emit ORDER_PLACED")
310
- * @param entityName - The entity context for unqualified field references
311
- * @returns S-Expression array
312
- *
313
- * @example
314
- * parseDomainEffect("update status to 'done'") → ["set", "@entity.status", "done"]
315
- * parseDomainEffect("emit ORDER_PLACED") → ["emit", "ORDER_PLACED"]
316
- * parseDomainEffect("render entity-table to main") → ["render-ui", "main", { type: "entity-table" }]
317
- */
318
- declare function parseDomainEffect(text: string, entityName?: string): SExpr;
319
- /**
320
- * Parse multiple domain effects (comma or "then" separated).
321
- *
322
- * @param text - Domain language effects
323
- * @param entityName - The entity context
324
- * @returns Array of S-Expressions (wrapped in ["do", ...] if multiple)
325
- */
326
- declare function parseDomainEffects(text: string, entityName?: string): SExpr[];
327
-
328
- /**
329
- * Entity Formatter
330
- *
331
- * Converts KFlow DataEntity schema to domain language text.
332
- */
333
-
334
- /**
335
- * Convert a KFlow DataEntity to domain language text
336
- */
337
- declare function formatSchemaEntityToDomain(entity: Record<string, unknown>): string;
338
- /**
339
- * Convert KFlow DataEntity to DomainEntity AST
340
- */
341
- declare function schemaEntityToDomainEntity(entity: Record<string, unknown>): DomainEntity;
342
-
343
- /**
344
- * Page Formatter
345
- *
346
- * Converts KFlow Page schema to domain language text.
347
- */
348
-
349
- /**
350
- * Convert a KFlow Page schema to domain language text
351
- */
352
- declare function formatSchemaPageToDomain(page: Record<string, unknown>): string;
353
- /**
354
- * Convert KFlow Page schema to DomainPage AST
355
- */
356
- declare function schemaPageToDomainPage(page: Record<string, unknown>): DomainPage;
357
-
358
- /**
359
- * Behavior Formatter
360
- *
361
- * Converts KFlow Trait schema to domain language text.
362
- * Supports both legacy typed effects and S-expression format.
363
- */
364
-
365
- /**
366
- * Convert a KFlow Trait schema to domain language text
367
- */
368
- declare function formatSchemaTraitToDomain(trait: Record<string, unknown>, entityName?: string): string;
369
- /**
370
- * Convert KFlow Trait schema to DomainBehavior AST
371
- */
372
- declare function schemaTraitToDomainBehavior(trait: Record<string, unknown>, entityName?: string): DomainBehavior;
373
-
374
- /**
375
- * Guard Formatter
376
- *
377
- * Converts KFlow guard conditions to domain language and vice versa.
378
- * All entity references are explicit (e.g., Order.amount, CurrentUser.role).
379
- *
380
- * Supports both legacy string-based conditions and S-expression format.
381
- */
382
-
383
- /**
384
- * Convert a KFlow schema guard to domain language text.
385
- * Handles both legacy string conditions and S-expression format.
386
- */
387
- declare function formatSchemaGuardToDomain(guard: Record<string, unknown> | unknown[], entityName: string): string;
388
- /**
389
- * Convert a DomainGuard to KFlow schema guard format
390
- */
391
- declare function formatDomainGuardToSchema(guard: DomainGuard): string;
392
- /**
393
- * Format a guard condition AST to domain-friendly text
394
- */
395
- declare function formatGuardConditionToDomain(condition: GuardCondition): string;
396
-
397
- /**
398
- * Schema to Domain Converter
399
- *
400
- * Converts a complete OrbitalSchema to domain language text.
401
- * Generates three sections: Entities, Pages, and Behaviors.
402
- *
403
- * Updated to read from OrbitalSchema where entities, pages, and traits
404
- * are grouped into Orbital units. Also supports legacy KFlowSchema format
405
- * for backward compatibility.
406
- */
407
-
408
- interface SchemaToDomainResult {
409
- /** The complete domain text document */
410
- domainText: string;
411
- /** Parsed AST representation */
412
- document: DomainDocument;
413
- /** Mapping of sections to schema paths */
414
- mappings: SectionMapping[];
415
- /** Separate section texts for individual editing */
416
- sections: {
417
- entities: string[];
418
- pages: string[];
419
- behaviors: string[];
420
- };
421
- }
422
- /**
423
- * Legacy KFlowSchema format (for backward compatibility)
424
- */
425
- interface LegacyKFlowSchema {
426
- name?: string;
427
- dataEntities?: Array<Record<string, unknown>>;
428
- ui?: {
429
- pages?: Array<Record<string, unknown>>;
430
- };
431
- traits?: Array<Record<string, unknown>>;
432
- ticks?: Array<Record<string, unknown>>;
433
- }
434
- /**
435
- * Combined input type for the converter
436
- */
437
- type SchemaInput = OrbitalSchema | LegacyKFlowSchema;
438
- /**
439
- * Convert a complete OrbitalSchema or legacy KFlowSchema to domain language
440
- */
441
- declare function convertSchemaToDomain(schema: SchemaInput): SchemaToDomainResult;
442
- /**
443
- * Convert just the entities section
444
- */
445
- declare function convertEntitiesToDomain(entities: Entity[]): string;
446
- /**
447
- * Convert just the pages section
448
- */
449
- declare function convertPagesToDomain(pages: Page[]): string;
450
- /**
451
- * Convert just the traits/behaviors section
452
- */
453
- declare function convertTraitsToDomain(traits: Trait[]): string;
454
-
455
- /**
456
- * Domain to Schema Converter
457
- *
458
- * Applies domain language text changes to an OrbitalSchema.
459
- * Supports incremental updates (single section) and full replacement.
460
- *
461
- * Updated to use OrbitalSchema where entities, pages, and traits
462
- * are grouped into Orbital units instead of flat arrays.
463
- */
464
-
465
- interface DomainToSchemaResult {
466
- /** Whether the conversion was successful */
467
- success: boolean;
468
- /** The updated schema */
469
- schema: OrbitalSchema;
470
- /** Any parse errors encountered */
471
- errors: ParseError[];
472
- /** Warnings (non-fatal issues) */
473
- warnings: ParseError[];
474
- /** Updated section mappings */
475
- mappings: SectionMapping[];
476
- }
477
- /**
478
- * Parse a complete domain document and convert to OrbitalSchema
479
- */
480
- declare function convertDomainToSchema(domainText: string, baseSchema?: OrbitalSchema): DomainToSchemaResult;
481
- /**
482
- * Apply a single section update to an OrbitalSchema
483
- */
484
- declare function applySectionUpdate(schema: OrbitalSchema, sectionType: 'entity' | 'page' | 'behavior' | 'tick', sectionId: string, newDomainText: string): DomainToSchemaResult;
485
- /**
486
- * Delete a section from the schema
487
- */
488
- declare function deleteSection(schema: OrbitalSchema, sectionType: 'entity' | 'page' | 'behavior' | 'tick', sectionId: string): OrbitalSchema;
489
-
490
- /**
491
- * Section Mapping
492
- *
493
- * Tracks the relationship between domain language sections and KFlow schema paths.
494
- * Enables bidirectional sync and conflict detection.
495
- */
496
-
497
- interface MappingStore {
498
- /** All tracked mappings */
499
- mappings: SectionMapping[];
500
- /** Last sync timestamp */
501
- lastSync: number;
502
- /** Schema version hash for change detection */
503
- schemaHash?: string;
504
- }
505
- /**
506
- * Create a new mapping store
507
- */
508
- declare function createMappingStore(mappings?: SectionMapping[]): MappingStore;
509
- /**
510
- * Find a mapping by section ID
511
- */
512
- declare function findMapping(store: MappingStore, sectionId: string): SectionMapping | undefined;
513
- /**
514
- * Find a mapping by schema path
515
- */
516
- declare function findMappingByPath(store: MappingStore, schemaPath: string): SectionMapping | undefined;
517
- /**
518
- * Find all mappings of a specific type
519
- */
520
- declare function findMappingsByType(store: MappingStore, sectionType: 'entity' | 'page' | 'behavior' | 'tick'): SectionMapping[];
521
- /**
522
- * Update or add a mapping
523
- */
524
- declare function upsertMapping(store: MappingStore, mapping: SectionMapping): MappingStore;
525
- /**
526
- * Remove a mapping
527
- */
528
- declare function removeMapping(store: MappingStore, sectionId: string): MappingStore;
529
- /**
530
- * Detect changes between old and new mappings
531
- */
532
- declare function detectChanges(oldMappings: SectionMapping[], newMappings: SectionMapping[]): {
533
- added: SectionMapping[];
534
- removed: SectionMapping[];
535
- modified: SectionMapping[];
536
- };
537
- /**
538
- * Generate a unique section ID
539
- */
540
- declare function generateSectionId(sectionType: 'entity' | 'page' | 'behavior' | 'tick', name: string): string;
541
- /**
542
- * Extract section type and name from a section ID
543
- */
544
- declare function parseSectionId(sectionId: string): {
545
- sectionType: 'entity' | 'page' | 'behavior' | 'tick';
546
- name: string;
547
- } | null;
548
- /**
549
- * Get the schema path for a section
550
- */
551
- declare function getSchemaPath(sectionType: 'entity' | 'page' | 'behavior' | 'tick', index: number): string;
552
- /**
553
- * Update range information for a mapping based on text position
554
- */
555
- declare function updateMappingRange(mapping: SectionMapping, fullText: string): SectionMapping;
556
- /**
557
- * Resolve conflicts between domain changes and schema changes
558
- */
559
- declare function resolveConflict(domainMapping: SectionMapping, schemaMapping: SectionMapping, preference: 'domain' | 'schema' | 'newest'): SectionMapping;
560
- /**
561
- * Compute a simple hash of a schema for change detection
562
- */
563
- declare function computeSchemaHash(schema: Record<string, unknown>): string;
564
- /**
565
- * Check if schema has changed since last sync
566
- */
567
- declare function hasSchemaChanged(store: MappingStore, schema: Record<string, unknown>): boolean;
568
- /**
569
- * Update the schema hash in the store
570
- */
571
- declare function updateSchemaHash(store: MappingStore, schema: Record<string, unknown>): MappingStore;
572
-
573
- /**
574
- * Domain Language Chunk Merging
575
- *
576
- * Utilities for merging multiple domain language chunks into a single document.
577
- * Used by the lean skill to generate orbitals incrementally.
578
- *
579
- * @packageDocumentation
580
- */
581
- interface DomainChunk {
582
- /** The domain language text for this orbital */
583
- text: string;
584
- /** Optional name for this orbital (for debugging) */
585
- name?: string;
586
- }
587
- interface MergeResult {
588
- /** The merged domain language text */
589
- text: string;
590
- /** Number of entities merged */
591
- entityCount: number;
592
- /** Number of pages merged */
593
- pageCount: number;
594
- /** Number of behaviors merged */
595
- behaviorCount: number;
596
- }
597
- /**
598
- * Merge multiple domain language chunks into a single document.
599
- *
600
- * Each chunk can contain:
601
- * - `# Entities` section with entity definitions
602
- * - `# Pages` section with page definitions
603
- * - `# Behaviors` section with behavior/trait definitions
604
- *
605
- * The merge combines all sections, maintaining the standard order:
606
- * 1. Entities
607
- * 2. Pages
608
- * 3. Behaviors
609
- *
610
- * @example
611
- * ```typescript
612
- * const chunks = [
613
- * { text: '# Entities\n\nA Task is...', name: 'Task' },
614
- * { text: '# Entities\n\nA User is...', name: 'User' },
615
- * ];
616
- * const result = mergeDomainChunks(chunks);
617
- * // result.text contains both entities merged
618
- * ```
619
- */
620
- declare function mergeDomainChunks(chunks: DomainChunk[]): MergeResult;
621
- /**
622
- * Validate that a domain chunk has the expected structure.
623
- * Returns errors if the chunk is malformed.
624
- */
625
- declare function validateDomainChunk(chunk: DomainChunk): string[];
626
- /**
627
- * Format a merged result as a summary string
628
- */
629
- declare function formatMergeSummary(result: MergeResult): string;
630
-
631
- /**
632
- * Phase 5 — `mergeDocuments(base, overlay)` overlay reducer.
633
- *
634
- * The studio questionnaire renders `mergeDocuments(factoryBase,
635
- * userOverlay)` as its surface — the user edits the overlay; the base
636
- * never mutates. Server-side, the planner reads the user's persisted
637
- * overlay and merges it on top of the catalog's `baseDocument` to
638
- * derive the final `DomainDocument` fed to `translateDomainToParams`.
639
- *
640
- * Semantics:
641
- * - `entities[]`, `pages[]`, `behaviors[]` matched by `name`. The
642
- * overlay's entry replaces the base's; missing names from one side
643
- * are kept verbatim from the other.
644
- * - Within a matched entity / page / behavior, overlay fields win
645
- * (overlay-replace, not deep-merge). This means a user clearing
646
- * `fields: []` is honoured rather than silently re-inflating from
647
- * the base. The questionnaire UI emits partial overlays only for
648
- * the slots the user touched, so this is the right granularity.
649
- * - Arrays inside matched entries (`entities[i].fields[]`,
650
- * `pages[i].sections[]`) are NOT field-level merged — the overlay
651
- * replaces the base array verbatim when present. For granular
652
- * additions ("add a field"), the UI authors a `DomainMutation`
653
- * and applies via `applyMutation` instead of going through
654
- * `mergeDocuments`.
655
- * - Top-level `type` is always `'document'`.
656
- *
657
- * Pure function — no I/O, no mutation of inputs. Returns a new
658
- * `DomainDocument`.
659
- *
660
- * @packageDocumentation
661
- */
662
-
663
- /**
664
- * Compose a base `DomainDocument` (factory catalog baseline) with a
665
- * user-authored overlay (questionnaire answers + edits). Entities,
666
- * pages, and behaviors are matched by `name`; the overlay replaces
667
- * any base entry with the same name. Unmatched entries on either side
668
- * survive unchanged.
669
- *
670
- * Idempotent: `mergeDocuments(d, emptyDocument)` returns a deep-copy
671
- * of `d`. `mergeDocuments(emptyDocument, d)` likewise.
672
- *
673
- * @param base The starting document (factory `baseDocument` or
674
- * organism-level union).
675
- * @param overlay The user-authored overlay carrying edits.
676
- * @returns A new merged document; neither input is mutated.
677
- */
678
- declare function mergeDocuments(base: DomainDocument, overlay: DomainDocument): DomainDocument;
679
-
680
- /**
681
- * Domain Language Registry
682
- *
683
- * Central registry for OrbitalSchema <-> Domain Language mappings.
684
- * This is the single source of truth for type conversions.
685
- *
686
- * When adding a new OrbitalSchema feature:
687
- * 1. Add type mapping here
688
- * 2. Formatters/parsers automatically use these mappings
689
- * 3. Build-time validation ensures coverage
690
- *
691
- * @packageDocumentation
692
- */
693
-
694
- /**
695
- * Field type mapping entry with format/parse functions
696
- */
697
- interface FieldTypeMapping {
698
- /** OrbitalSchema type name */
699
- schemaType: string;
700
- /** Domain Language keyword(s) - can be array for aliases */
701
- domainKeywords: string[];
702
- /** Format schema field to domain text */
703
- format: (field: {
704
- type: string;
705
- values?: string[];
706
- relation?: {
707
- entity: string;
708
- };
709
- }) => string;
710
- /** Parse domain keyword to schema type */
711
- parse: (keyword: string) => string;
712
- }
713
- /**
714
- * Effect operator mapping entry
715
- */
716
- interface EffectMapping {
717
- /** S-Expression operator name */
718
- operator: string;
719
- /** Human-readable domain pattern templates */
720
- domainPatterns: string[];
721
- /** Description for documentation */
722
- description: string;
723
- }
724
- /**
725
- * Guard operator mapping entry
726
- */
727
- interface GuardMapping {
728
- /** S-Expression operator */
729
- operator: string;
730
- /** Human-readable domain patterns */
731
- domainPatterns: string[];
732
- /** Description */
733
- description: string;
734
- }
735
- /**
736
- * Complete field type registry with format/parse functions
737
- */
738
- declare const FIELD_TYPE_REGISTRY: Record<string, FieldTypeMapping>;
739
- /**
740
- * Effect operator registry with human-readable patterns
741
- */
742
- declare const EFFECT_REGISTRY: Record<string, EffectMapping>;
743
- /**
744
- * Guard operator registry with human-readable patterns
745
- */
746
- declare const GUARD_REGISTRY: Record<string, GuardMapping>;
747
- /**
748
- * Get all registered field types
749
- */
750
- declare function getRegisteredFieldTypes(): string[];
751
- /**
752
- * Get all registered effect operators
753
- */
754
- declare function getRegisteredEffects(): string[];
755
- /**
756
- * Get all registered guard operators
757
- */
758
- declare function getRegisteredGuards(): string[];
759
- /**
760
- * Check if a field type is registered
761
- */
762
- declare function isFieldTypeRegistered(type: string): boolean;
763
- /**
764
- * Check if an effect operator is registered
765
- */
766
- declare function isEffectRegistered(operator: string): boolean;
767
- /**
768
- * Check if a guard operator is registered
769
- */
770
- declare function isGuardRegistered(operator: string): boolean;
771
- /**
772
- * Get field type mapping
773
- */
774
- declare function getFieldTypeMapping(type: string): FieldTypeMapping | undefined;
775
- /**
776
- * Get effect mapping
777
- */
778
- declare function getEffectMapping(operator: string): EffectMapping | undefined;
779
- /**
780
- * Get guard mapping
781
- */
782
- declare function getGuardMapping(operator: string): GuardMapping | undefined;
783
- /**
784
- * Lookup domain keyword and return schema type
785
- */
786
- declare function domainKeywordToSchemaType(keyword: string): string | undefined;
787
- /**
788
- * Lookup schema type and return primary domain keyword
789
- */
790
- declare function schemaTypeToDomainKeyword(type: string): string | undefined;
791
- /**
792
- * Get registry statistics for validation/documentation
793
- */
794
- declare function getRegistryStats(): {
795
- fieldTypes: number;
796
- effects: number;
797
- guards: number;
798
- uiSlots: number;
799
- };
800
-
801
- /**
802
- * Domain Language Reference — pure function that generates reference docs from the type registry.
803
- *
804
- * Separated from generate-docs.ts (CLI script) so it can be compiled and exported.
805
- */
806
- /**
807
- * Generate the complete Domain Language reference document as a string.
808
- */
809
- declare function generateDomainLanguageReference(): string;
810
-
811
- /**
812
- * Pure reducer for `DomainMutation` over `DomainDocument`.
813
- *
814
- * No I/O. No randomness. Returns a new typed `DomainDocument`
815
- * (immutable update) so callers can preserve prior state for
816
- * cross-turn stability. One total switch over the discriminated
817
- * union — the compiler enforces exhaustiveness via the `never`
818
- * default branch.
819
- *
820
- * Companion to `translateDomainToParams`: the UI/agent emits typed
821
- * `DomainMutation[]`, the reducer applies them, the translator
822
- * lowers the result onto factory call sites.
823
- */
824
-
825
- /**
826
- * Apply one mutation to the document. The original is not modified.
827
- * Mutations targeting missing entities/pages/behaviors/fields are
828
- * silently no-ops — callers that care should validate via
829
- * `findEntity`-style helpers before applying.
830
- */
831
- declare function applyMutation(doc: DomainDocument, mut: DomainMutation): DomainDocument;
832
-
833
- export { DomainBehavior, type DomainChunk, DomainDocument, DomainEntity, DomainGuard, DomainMutation, DomainPage, type DomainToSchemaResult, EFFECT_REGISTRY, type EffectMapping, FIELD_TYPE_REGISTRY, type FieldTypeMapping, GUARD_REGISTRY, GuardCondition, type GuardMapping, KEYWORDS, Lexer, MULTI_WORD_KEYWORDS, type MappingStore, type MergeResult, ParseError, ParseResult, type SchemaToDomainResult, SectionMapping, type Token, TokenType, applyMutation, applySectionUpdate, computeSchemaHash, convertDomainToSchema, convertEntitiesToDomain, convertPagesToDomain, convertSchemaToDomain, convertTraitsToDomain, createMappingStore, deleteSection, detectChanges, domainKeywordToSchemaType, findMapping, findMappingByPath, findMappingsByType, formatBehaviorToDomain, formatBehaviorToSchema, formatDomainGuardToSchema, formatEntityToDomain, formatEntityToSchema, formatGuardConditionToDomain, formatGuardToDomain, formatGuardToSchema, formatMergeSummary, formatPageToDomain, formatPageToSchema, formatSchemaEntityToDomain, formatSchemaGuardToDomain, formatSchemaPageToDomain, formatSchemaTraitToDomain, generateDomainLanguageReference, generateSectionId, getEffectMapping, getFieldTypeMapping, getGuardMapping, getRegisteredEffects, getRegisteredFieldTypes, getRegisteredGuards, getRegistryStats, getSchemaPath, hasSchemaChanged, isEffectRegistered, isFieldTypeRegistered, isGuardRegistered, mergeDocuments, mergeDomainChunks, parseBehavior, parseDomainEffect, parseDomainEffects, parseDomainGuard, parseEntity, parseGuard, parsePage, parseSectionId, removeMapping, resolveConflict, schemaEntityToDomainEntity, schemaPageToDomainPage, schemaTraitToDomainBehavior, schemaTypeToDomainKeyword, tokenize, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };