@almadar/core 7.25.0 → 7.26.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.
@@ -322,6 +322,20 @@ interface FactorySignature {
322
322
  emittedEvents: ReadonlyArray<string>;
323
323
  /** Union of all `traits[].listenedEvents`. */
324
324
  listenedEvents: ReadonlyArray<string>;
325
+ /**
326
+ * Phase 5 — canonical starting `DomainDocument` fragment the studio
327
+ * questionnaire renders before any user input. Lifted verbatim from
328
+ * the factory's resolved `.orb` by `almadar-pattern-sync`. Users
329
+ * append / override via `DomainMutation` from the questionnaire UI;
330
+ * the base itself is never edited in place (consumers compose with
331
+ * `mergeDocuments(base, overlay)`).
332
+ *
333
+ * Optional during the 7.26.x transition — older catalog snapshots
334
+ * predating the sync regeneration omit it. Consumers should fall
335
+ * back to building a minimal document from `entities` + `pages`
336
+ * when this is missing.
337
+ */
338
+ baseDocument?: DomainDocument;
325
339
  }
326
340
  /**
327
341
  * Aggregate catalog written to
@@ -1255,6 +1269,55 @@ declare function validateDomainChunk(chunk: DomainChunk): string[];
1255
1269
  */
1256
1270
  declare function formatMergeSummary(result: MergeResult): string;
1257
1271
 
1272
+ /**
1273
+ * Phase 5 — `mergeDocuments(base, overlay)` overlay reducer.
1274
+ *
1275
+ * The studio questionnaire renders `mergeDocuments(factoryBase,
1276
+ * userOverlay)` as its surface — the user edits the overlay; the base
1277
+ * never mutates. Server-side, the planner reads the user's persisted
1278
+ * overlay and merges it on top of the catalog's `baseDocument` to
1279
+ * derive the final `DomainDocument` fed to `translateDomainToParams`.
1280
+ *
1281
+ * Semantics:
1282
+ * - `entities[]`, `pages[]`, `behaviors[]` matched by `name`. The
1283
+ * overlay's entry replaces the base's; missing names from one side
1284
+ * are kept verbatim from the other.
1285
+ * - Within a matched entity / page / behavior, overlay fields win
1286
+ * (overlay-replace, not deep-merge). This means a user clearing
1287
+ * `fields: []` is honoured rather than silently re-inflating from
1288
+ * the base. The questionnaire UI emits partial overlays only for
1289
+ * the slots the user touched, so this is the right granularity.
1290
+ * - Arrays inside matched entries (`entities[i].fields[]`,
1291
+ * `pages[i].sections[]`) are NOT field-level merged — the overlay
1292
+ * replaces the base array verbatim when present. For granular
1293
+ * additions ("add a field"), the UI authors a `DomainMutation`
1294
+ * and applies via `applyMutation` instead of going through
1295
+ * `mergeDocuments`.
1296
+ * - Top-level `type` is always `'document'`.
1297
+ *
1298
+ * Pure function — no I/O, no mutation of inputs. Returns a new
1299
+ * `DomainDocument`.
1300
+ *
1301
+ * @packageDocumentation
1302
+ */
1303
+
1304
+ /**
1305
+ * Compose a base `DomainDocument` (factory catalog baseline) with a
1306
+ * user-authored overlay (questionnaire answers + edits). Entities,
1307
+ * pages, and behaviors are matched by `name`; the overlay replaces
1308
+ * any base entry with the same name. Unmatched entries on either side
1309
+ * survive unchanged.
1310
+ *
1311
+ * Idempotent: `mergeDocuments(d, emptyDocument)` returns a deep-copy
1312
+ * of `d`. `mergeDocuments(emptyDocument, d)` likewise.
1313
+ *
1314
+ * @param base The starting document (factory `baseDocument` or
1315
+ * organism-level union).
1316
+ * @param overlay The user-authored overlay carrying edits.
1317
+ * @returns A new merged document; neither input is mutated.
1318
+ */
1319
+ declare function mergeDocuments(base: DomainDocument, overlay: DomainDocument): DomainDocument;
1320
+
1258
1321
  /**
1259
1322
  * Domain Language Registry
1260
1323
  *
@@ -1408,4 +1471,4 @@ declare function generateDomainLanguageReference(): string;
1408
1471
  */
1409
1472
  declare function applyMutation(doc: DomainDocument, mut: DomainMutation): DomainDocument;
1410
1473
 
1411
- export { type ASTNode, type CallSiteDiff, type ComparisonCondition, type ComparisonOperator, type DomainBehavior, type DomainChunk, type DomainDocument, type DomainEffect, type DomainEntity, type DomainField, type DomainFieldDefault, type DomainFieldItems, type DomainFieldType, type DomainGuard, type DomainMutation, type DomainPage, type DomainPageAction, type DomainPageSection, type DomainRelationship, type DomainRuleOverlayEntry, type DomainTick, type DomainToSchemaResult, type DomainTransition, EFFECT_REGISTRY, type EffectMapping, type EffectType, EntityPersistence, FIELD_TYPE_REGISTRY, type FactoryCallSite, type FactoryCallSiteParams, type FactoryEntitySignature, type FactoryPageSignature, type FactoryParamValue, type FactorySignature, type FactorySignatureCatalog, type FactorySignatureEntityField, type FactoryTraitSignature, type FieldCheckCondition, type FieldReference, type FieldTypeMapping, GUARD_REGISTRY, type GuardCondition, type GuardMapping, KEYWORDS, Lexer, type LogicalCondition, type LogicalOperator, MULTI_WORD_KEYWORDS, type MappingStore, type MergeResult, type OwnershipOverlayEntry, type ParseError, type ParseResult, type PresentationNavItem, type PresentationOverlay, type RelationshipType, type RuleOverlay, type SchemaFieldType, type SchemaToDomainResult, type SectionMapping, type SourceLocation, type SourceRange, type Token, TokenType, type TraitOverlay, type TraitOverlayEntry, type TraitOverlayListener, TraitScope, type TranslationBinding, type TranslationResult, type TranslationWarning, type UserCheckCondition, applyMutation, applySectionUpdate, computeSchemaHash, convertDomainToSchema, convertEntitiesToDomain, convertPagesToDomain, convertSchemaToDomain, convertTraitsToDomain, createMappingStore, deleteSection, detectChanges, diffFactoryCalls, 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, mergeDomainChunks, parseBehavior, parseDomainEffect, parseDomainEffects, parseDomainGuard, parseEntity, parseGuard, parsePage, parseSectionId, removeMapping, resolveConflict, schemaEntityToDomainEntity, schemaPageToDomainPage, schemaTraitToDomainBehavior, schemaTypeToDomainKeyword, tokenize, translateDomainToParams, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };
1474
+ export { type ASTNode, type CallSiteDiff, type ComparisonCondition, type ComparisonOperator, type DomainBehavior, type DomainChunk, type DomainDocument, type DomainEffect, type DomainEntity, type DomainField, type DomainFieldDefault, type DomainFieldItems, type DomainFieldType, type DomainGuard, type DomainMutation, type DomainPage, type DomainPageAction, type DomainPageSection, type DomainRelationship, type DomainRuleOverlayEntry, type DomainTick, type DomainToSchemaResult, type DomainTransition, EFFECT_REGISTRY, type EffectMapping, type EffectType, EntityPersistence, FIELD_TYPE_REGISTRY, type FactoryCallSite, type FactoryCallSiteParams, type FactoryEntitySignature, type FactoryPageSignature, type FactoryParamValue, type FactorySignature, type FactorySignatureCatalog, type FactorySignatureEntityField, type FactoryTraitSignature, type FieldCheckCondition, type FieldReference, type FieldTypeMapping, GUARD_REGISTRY, type GuardCondition, type GuardMapping, KEYWORDS, Lexer, type LogicalCondition, type LogicalOperator, MULTI_WORD_KEYWORDS, type MappingStore, type MergeResult, type OwnershipOverlayEntry, type ParseError, type ParseResult, type PresentationNavItem, type PresentationOverlay, type RelationshipType, type RuleOverlay, type SchemaFieldType, type SchemaToDomainResult, type SectionMapping, type SourceLocation, type SourceRange, type Token, TokenType, type TraitOverlay, type TraitOverlayEntry, type TraitOverlayListener, TraitScope, type TranslationBinding, type TranslationResult, type TranslationWarning, type UserCheckCondition, applyMutation, applySectionUpdate, computeSchemaHash, convertDomainToSchema, convertEntitiesToDomain, convertPagesToDomain, convertSchemaToDomain, convertTraitsToDomain, createMappingStore, deleteSection, detectChanges, diffFactoryCalls, 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, translateDomainToParams, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };
@@ -7031,6 +7031,37 @@ function formatMergeSummary(result) {
7031
7031
  return parts.join(", ") || "empty";
7032
7032
  }
7033
7033
 
7034
+ // src/domain-language/sync/merge-documents.ts
7035
+ function mergeDocuments(base, overlay) {
7036
+ return {
7037
+ type: "document",
7038
+ entities: mergeByName(base.entities, overlay.entities),
7039
+ pages: mergeByName(base.pages, overlay.pages),
7040
+ behaviors: mergeByName(base.behaviors, overlay.behaviors)
7041
+ };
7042
+ }
7043
+ function mergeByName(baseItems, overlayItems) {
7044
+ const overlayByName = /* @__PURE__ */ new Map();
7045
+ for (const item of overlayItems) overlayByName.set(item.name, item);
7046
+ const result = [];
7047
+ const seen = /* @__PURE__ */ new Set();
7048
+ for (const item of baseItems) {
7049
+ const replacement = overlayByName.get(item.name);
7050
+ if (replacement) {
7051
+ result.push(replacement);
7052
+ } else {
7053
+ result.push(item);
7054
+ }
7055
+ seen.add(item.name);
7056
+ }
7057
+ for (const item of overlayItems) {
7058
+ if (!seen.has(item.name)) {
7059
+ result.push(item);
7060
+ }
7061
+ }
7062
+ return result;
7063
+ }
7064
+
7034
7065
  // src/domain-language/registry.ts
7035
7066
  var FIELD_TYPE_REGISTRY = {
7036
7067
  string: {
@@ -7603,6 +7634,6 @@ function matchesRelationship(r, targetEntity, relationshipType) {
7603
7634
  return r.targetEntity === targetEntity && r.relationshipType === relationshipType;
7604
7635
  }
7605
7636
 
7606
- export { EFFECT_REGISTRY, FIELD_TYPE_REGISTRY, GUARD_REGISTRY, KEYWORDS, Lexer, MULTI_WORD_KEYWORDS, TokenType, applyMutation, applySectionUpdate, computeSchemaHash, convertDomainToSchema, convertEntitiesToDomain, convertPagesToDomain, convertSchemaToDomain, convertTraitsToDomain, createMappingStore, deleteSection, detectChanges, diffFactoryCalls, 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, mergeDomainChunks, parseBehavior, parseDomainEffect, parseDomainEffects, parseDomainGuard, parseEntity, parseGuard, parsePage, parseSectionId, removeMapping, resolveConflict, schemaEntityToDomainEntity, schemaPageToDomainPage, schemaTraitToDomainBehavior, schemaTypeToDomainKeyword, tokenize, translateDomainToParams, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };
7637
+ export { EFFECT_REGISTRY, FIELD_TYPE_REGISTRY, GUARD_REGISTRY, KEYWORDS, Lexer, MULTI_WORD_KEYWORDS, TokenType, applyMutation, applySectionUpdate, computeSchemaHash, convertDomainToSchema, convertEntitiesToDomain, convertPagesToDomain, convertSchemaToDomain, convertTraitsToDomain, createMappingStore, deleteSection, detectChanges, diffFactoryCalls, 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, translateDomainToParams, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };
7607
7638
  //# sourceMappingURL=index.js.map
7608
7639
  //# sourceMappingURL=index.js.map