@almadar/core 7.19.1 → 7.21.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.
@@ -3410,7 +3410,9 @@ var FieldTypeSchema = z.enum([
3410
3410
  "object",
3411
3411
  "enum",
3412
3412
  "relation",
3413
- "trait"
3413
+ "trait",
3414
+ "slot",
3415
+ "pattern"
3414
3416
  ]);
3415
3417
  var RelationCardinalitySchema = z.enum([
3416
3418
  "one",
@@ -6397,6 +6399,251 @@ function parseEffectFromText(text) {
6397
6399
  }
6398
6400
  }
6399
6401
 
6402
+ // src/domain-language/types.ts
6403
+ var DOMAIN_TO_SCHEMA_FIELD_TYPE = {
6404
+ "text": "string",
6405
+ "long text": "string",
6406
+ "number": "number",
6407
+ "currency": "number",
6408
+ "yes/no": "boolean",
6409
+ "date": "date",
6410
+ "timestamp": "timestamp",
6411
+ "datetime": "datetime",
6412
+ "list": "array",
6413
+ "object": "object",
6414
+ "enum": "enum",
6415
+ "relation": "relation"
6416
+ };
6417
+ var UI_SLOTS2 = [
6418
+ "main",
6419
+ "sidebar",
6420
+ "modal",
6421
+ "drawer",
6422
+ "overlay",
6423
+ "center",
6424
+ "toast",
6425
+ "hud-top",
6426
+ "hud-bottom",
6427
+ "floating",
6428
+ "system"
6429
+ ];
6430
+
6431
+ // src/domain-language/sync/translate-domain-to-params.ts
6432
+ function translateDomainToParams(binding, signature, presentation) {
6433
+ const warnings = [];
6434
+ const params = {};
6435
+ applyEntityName(binding.entity, signature, params);
6436
+ applyEntityFields(binding.entity, signature, params, warnings);
6437
+ applyPersistence(binding.entity, signature, params, warnings);
6438
+ applyPagePaths(binding.pages ?? [], signature, params, warnings);
6439
+ applyPresentation(presentation, signature, params, warnings);
6440
+ return {
6441
+ callSite: {
6442
+ organism: signature.organism,
6443
+ orbital: signature.orbital,
6444
+ factoryPath: signature.factoryPath,
6445
+ params
6446
+ },
6447
+ warnings
6448
+ };
6449
+ }
6450
+ function applyEntityName(entity, signature, params) {
6451
+ if (signature.entities.length === 0) return;
6452
+ if (entity.name === signature.entities[0].name) return;
6453
+ params.entityName = entity.name;
6454
+ }
6455
+ function applyEntityFields(entity, signature, params, warnings) {
6456
+ if (signature.entities.length === 0) {
6457
+ if (entity.fields.length > 0) {
6458
+ warnings.push({
6459
+ field: `entity.${entity.name}.fields`,
6460
+ reason: "factory signature does not advertise an entity surface"
6461
+ });
6462
+ }
6463
+ return;
6464
+ }
6465
+ const canonical = new Set(signature.entities[0].fields.map((f) => f.name));
6466
+ const extras = [];
6467
+ for (const f of entity.fields) {
6468
+ if (canonical.has(f.name)) continue;
6469
+ const lowered = lowerField(f);
6470
+ if (lowered) extras.push(lowered);
6471
+ }
6472
+ if (extras.length > 0) params.entityFields = extras;
6473
+ }
6474
+ function applyPersistence(entity, signature, params, warnings) {
6475
+ if (!entity.persistence) return;
6476
+ if (signature.entities.length === 0) {
6477
+ warnings.push({
6478
+ field: `entity.${entity.name}.persistence`,
6479
+ reason: "factory signature has no entity to apply persistence to"
6480
+ });
6481
+ return;
6482
+ }
6483
+ if (entity.persistence === signature.entities[0].persistence) return;
6484
+ params.persistence = entity.persistence;
6485
+ }
6486
+ function applyPagePaths(pages, signature, params, warnings) {
6487
+ if (pages.length === 0) return;
6488
+ const sigPages = new Map(signature.pages.map((p) => [p.name, p]));
6489
+ const overrides = {};
6490
+ for (const p of pages) {
6491
+ const sig = sigPages.get(p.name);
6492
+ if (!sig) {
6493
+ warnings.push({
6494
+ field: `page.${p.name}.url`,
6495
+ reason: `factory signature has no page named "${p.name}"`
6496
+ });
6497
+ continue;
6498
+ }
6499
+ if (sig.defaultPath !== p.url) overrides[p.name] = p.url;
6500
+ }
6501
+ if (Object.keys(overrides).length > 0) params.pagePaths = overrides;
6502
+ }
6503
+ function applyPresentation(overlay, signature, params, warnings) {
6504
+ if (!overlay?.navAdditions || overlay.navAdditions.length === 0) return;
6505
+ const target = signature.traits.find(
6506
+ (t) => t.overridableConfigKeys.includes("navItems")
6507
+ );
6508
+ if (!target) {
6509
+ warnings.push({
6510
+ field: "presentation.navAdditions",
6511
+ reason: "factory signature has no trait advertising a `navItems` config key"
6512
+ });
6513
+ return;
6514
+ }
6515
+ const existing = params.traitOverrides?.[target.name] ?? {};
6516
+ const existingConfig = existing.config ?? {};
6517
+ const items = overlay.navAdditions.map(
6518
+ navItemToParamValue
6519
+ );
6520
+ params.traitOverrides = {
6521
+ ...params.traitOverrides,
6522
+ [target.name]: {
6523
+ ...existing,
6524
+ config: { ...existingConfig, navItems: items }
6525
+ }
6526
+ };
6527
+ }
6528
+ function lowerField(f) {
6529
+ const schemaType = DOMAIN_TO_SCHEMA_FIELD_TYPE[f.fieldType];
6530
+ if (!schemaType) return void 0;
6531
+ const out = {
6532
+ name: f.name,
6533
+ type: schemaType
6534
+ };
6535
+ if (f.required === true) out.required = true;
6536
+ if (f.enumValues && f.enumValues.length > 0) out.values = [...f.enumValues];
6537
+ if (f.default !== void 0) out.default = lowerDefault(f.default);
6538
+ if (f.items) {
6539
+ const itemSchema = DOMAIN_TO_SCHEMA_FIELD_TYPE[f.items.type];
6540
+ if (itemSchema) out.items = { type: itemSchema };
6541
+ }
6542
+ return out;
6543
+ }
6544
+ function lowerDefault(d) {
6545
+ if (d === void 0 || d === null) return d;
6546
+ if (typeof d === "string" || typeof d === "number" || typeof d === "boolean") {
6547
+ return d;
6548
+ }
6549
+ if (Array.isArray(d)) {
6550
+ return d.map(lowerDefault);
6551
+ }
6552
+ if (typeof d === "object") {
6553
+ const out = {};
6554
+ for (const [k, v] of Object.entries(d)) out[k] = lowerDefault(v);
6555
+ return out;
6556
+ }
6557
+ return void 0;
6558
+ }
6559
+ function navItemToParamValue(item) {
6560
+ const out = {
6561
+ label: item.label,
6562
+ path: item.path
6563
+ };
6564
+ if (item.icon) out.icon = item.icon;
6565
+ return out;
6566
+ }
6567
+
6568
+ // src/domain-language/sync/diff-factory-calls.ts
6569
+ function diffFactoryCalls(prior, next) {
6570
+ const out = [];
6571
+ const priorByKey = new Map(prior.map((c) => [callKey(c), c]));
6572
+ const nextByKey = new Map(next.map((c) => [callKey(c), c]));
6573
+ for (const [key, p] of priorByKey) {
6574
+ const n = nextByKey.get(key);
6575
+ if (!n) {
6576
+ out.push({ kind: "delete", orbitalName: p.orbital, prior: p });
6577
+ continue;
6578
+ }
6579
+ if (paramsEqual(p.params, n.params)) {
6580
+ out.push({ kind: "keep", orbitalName: p.orbital, call: n });
6581
+ } else {
6582
+ out.push({ kind: "edit", orbitalName: p.orbital, prior: p, next: n });
6583
+ }
6584
+ }
6585
+ for (const [key, n] of nextByKey) {
6586
+ if (!priorByKey.has(key)) {
6587
+ out.push({ kind: "add", orbitalName: n.orbital, next: n });
6588
+ }
6589
+ }
6590
+ return out;
6591
+ }
6592
+ function callKey(c) {
6593
+ return `${c.organism}::${c.orbital}`;
6594
+ }
6595
+ function paramsEqual(a, b) {
6596
+ return canonicalParams(a) === canonicalParams(b);
6597
+ }
6598
+ function canonicalParams(p) {
6599
+ const keys = [
6600
+ "entityFields",
6601
+ "entityName",
6602
+ "extraTraits",
6603
+ "pagePaths",
6604
+ "persistence",
6605
+ "traitOverrides"
6606
+ ];
6607
+ const parts = [];
6608
+ for (const k of keys) {
6609
+ const v = p[k];
6610
+ if (v === void 0) continue;
6611
+ parts.push(`${k}:${canonicalNode(v)}`);
6612
+ }
6613
+ return `{${parts.join(",")}}`;
6614
+ }
6615
+ function canonicalNode(v) {
6616
+ if (v === void 0) return "u";
6617
+ if (typeof v === "string") return JSON.stringify(v);
6618
+ if (Array.isArray(v)) {
6619
+ return `[${v.map((x) => canonicalParamValue(x)).join(",")}]`;
6620
+ }
6621
+ const keys = Object.keys(v).sort();
6622
+ const parts = [];
6623
+ for (const k of keys) {
6624
+ const child = v[k];
6625
+ parts.push(`${JSON.stringify(k)}:${canonicalParamValue(child)}`);
6626
+ }
6627
+ return `{${parts.join(",")}}`;
6628
+ }
6629
+ function canonicalParamValue(v) {
6630
+ if (v === null || v === void 0) return "u";
6631
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
6632
+ return JSON.stringify(v);
6633
+ }
6634
+ if (Array.isArray(v)) {
6635
+ return `[${v.map(canonicalParamValue).join(",")}]`;
6636
+ }
6637
+ const keys = Object.keys(v).sort();
6638
+ const parts = [];
6639
+ for (const k of keys) {
6640
+ const child = v[k];
6641
+ if (child === void 0) continue;
6642
+ parts.push(`${JSON.stringify(k)}:${canonicalParamValue(child)}`);
6643
+ }
6644
+ return `{${parts.join(",")}}`;
6645
+ }
6646
+
6400
6647
  // src/domain-language/sync/section-mapping.ts
6401
6648
  function createMappingStore(mappings = []) {
6402
6649
  return {
@@ -6617,21 +6864,6 @@ function formatMergeSummary(result) {
6617
6864
  return parts.join(", ") || "empty";
6618
6865
  }
6619
6866
 
6620
- // src/domain-language/types.ts
6621
- var UI_SLOTS2 = [
6622
- "main",
6623
- "sidebar",
6624
- "modal",
6625
- "drawer",
6626
- "overlay",
6627
- "center",
6628
- "toast",
6629
- "hud-top",
6630
- "hud-bottom",
6631
- "floating",
6632
- "system"
6633
- ];
6634
-
6635
6867
  // src/domain-language/registry.ts
6636
6868
  var FIELD_TYPE_REGISTRY = {
6637
6869
  string: {
@@ -7069,6 +7301,141 @@ function generateDomainLanguageReference() {
7069
7301
  return lines.join("\n");
7070
7302
  }
7071
7303
 
7072
- export { EFFECT_REGISTRY, FIELD_TYPE_REGISTRY, GUARD_REGISTRY, KEYWORDS, Lexer, MULTI_WORD_KEYWORDS, TokenType, 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, mergeDomainChunks, parseBehavior, parseDomainEffect, parseDomainEffects, parseDomainGuard, parseEntity, parseGuard, parsePage, parseSectionId, removeMapping, resolveConflict, schemaEntityToDomainEntity, schemaPageToDomainPage, schemaTraitToDomainBehavior, schemaTypeToDomainKeyword, tokenize, updateMappingRange, updateSchemaHash, upsertMapping, validateDomainChunk };
7304
+ // src/domain-language/applyMutation.ts
7305
+ function applyMutation(doc, mut) {
7306
+ switch (mut.kind) {
7307
+ case "add-entity":
7308
+ return { ...doc, entities: [...doc.entities, mut.entity] };
7309
+ case "remove-entity":
7310
+ return {
7311
+ ...doc,
7312
+ entities: doc.entities.filter((e) => e.name !== mut.entityName)
7313
+ };
7314
+ case "rename-entity":
7315
+ return {
7316
+ ...doc,
7317
+ entities: replaceEntity(doc.entities, mut.from, (e) => ({
7318
+ ...e,
7319
+ name: mut.to
7320
+ }))
7321
+ };
7322
+ case "update-entity":
7323
+ return {
7324
+ ...doc,
7325
+ entities: replaceEntity(doc.entities, mut.entityName, () => mut.entity)
7326
+ };
7327
+ case "add-field":
7328
+ return {
7329
+ ...doc,
7330
+ entities: replaceEntity(doc.entities, mut.entityName, (e) => ({
7331
+ ...e,
7332
+ fields: [...e.fields, mut.field]
7333
+ }))
7334
+ };
7335
+ case "remove-field":
7336
+ return {
7337
+ ...doc,
7338
+ entities: replaceEntity(doc.entities, mut.entityName, (e) => ({
7339
+ ...e,
7340
+ fields: e.fields.filter((f) => f.name !== mut.fieldName)
7341
+ }))
7342
+ };
7343
+ case "update-field":
7344
+ return {
7345
+ ...doc,
7346
+ entities: replaceEntity(doc.entities, mut.entityName, (e) => ({
7347
+ ...e,
7348
+ fields: replaceField(e.fields, mut.field)
7349
+ }))
7350
+ };
7351
+ case "add-page":
7352
+ return { ...doc, pages: [...doc.pages, mut.page] };
7353
+ case "remove-page":
7354
+ return {
7355
+ ...doc,
7356
+ pages: doc.pages.filter((p) => p.name !== mut.pageName)
7357
+ };
7358
+ case "update-page":
7359
+ return {
7360
+ ...doc,
7361
+ pages: replacePage(doc.pages, mut.pageName, () => mut.page)
7362
+ };
7363
+ case "add-behavior":
7364
+ return { ...doc, behaviors: [...doc.behaviors, mut.behavior] };
7365
+ case "remove-behavior":
7366
+ return {
7367
+ ...doc,
7368
+ behaviors: doc.behaviors.filter((b) => b.name !== mut.behaviorName)
7369
+ };
7370
+ case "update-behavior":
7371
+ return {
7372
+ ...doc,
7373
+ behaviors: replaceBehavior(
7374
+ doc.behaviors,
7375
+ mut.behaviorName,
7376
+ () => mut.behavior
7377
+ )
7378
+ };
7379
+ case "add-transition":
7380
+ return {
7381
+ ...doc,
7382
+ behaviors: replaceBehavior(doc.behaviors, mut.behaviorName, (b) => ({
7383
+ ...b,
7384
+ transitions: [...b.transitions, mut.transition]
7385
+ }))
7386
+ };
7387
+ case "remove-transition":
7388
+ return {
7389
+ ...doc,
7390
+ behaviors: replaceBehavior(doc.behaviors, mut.behaviorName, (b) => ({
7391
+ ...b,
7392
+ transitions: b.transitions.filter(
7393
+ (t) => !matchesTransition(t, mut.from, mut.to, mut.event)
7394
+ )
7395
+ }))
7396
+ };
7397
+ case "add-relationship":
7398
+ return {
7399
+ ...doc,
7400
+ entities: replaceEntity(doc.entities, mut.entityName, (e) => ({
7401
+ ...e,
7402
+ relationships: [...e.relationships, mut.relationship]
7403
+ }))
7404
+ };
7405
+ case "remove-relationship":
7406
+ return {
7407
+ ...doc,
7408
+ entities: replaceEntity(doc.entities, mut.entityName, (e) => ({
7409
+ ...e,
7410
+ relationships: e.relationships.filter(
7411
+ (r) => !matchesRelationship(r, mut.targetEntity, mut.relationshipType)
7412
+ )
7413
+ }))
7414
+ };
7415
+ default: {
7416
+ return doc;
7417
+ }
7418
+ }
7419
+ }
7420
+ function replaceEntity(entities, name, update) {
7421
+ return entities.map((e) => e.name === name ? update(e) : e);
7422
+ }
7423
+ function replaceField(fields, next) {
7424
+ return fields.map((f) => f.name === next.name ? next : f);
7425
+ }
7426
+ function replacePage(pages, name, update) {
7427
+ return pages.map((p) => p.name === name ? update(p) : p);
7428
+ }
7429
+ function replaceBehavior(behaviors, name, update) {
7430
+ return behaviors.map((b) => b.name === name ? update(b) : b);
7431
+ }
7432
+ function matchesTransition(t, from, to, event) {
7433
+ return t.fromState === from && t.toState === to && t.event === event;
7434
+ }
7435
+ function matchesRelationship(r, targetEntity, relationshipType) {
7436
+ return r.targetEntity === targetEntity && r.relationshipType === relationshipType;
7437
+ }
7438
+
7439
+ 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 };
7073
7440
  //# sourceMappingURL=index.js.map
7074
7441
  //# sourceMappingURL=index.js.map