@almadar/core 2.14.3 → 4.0.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,4 +1,4 @@
1
- import { O as OrbitalDefinition, c as OrbitalSchema } from './schema-BFnZrBhm.js';
1
+ import { O as OrbitalDefinition, c as OrbitalSchema } from './schema-CDA_dJjH.js';
2
2
 
3
3
  /**
4
4
  * Event Wiring
@@ -1,4 +1,4 @@
1
- import { bE as SExpr, e as Entity, P as Page, c as OrbitalSchema, d as Trait } from '../schema-BFnZrBhm.js';
1
+ import { bG as SExpr, e as Entity, P as Page, c as OrbitalSchema, d as Trait } from '../schema-CDA_dJjH.js';
2
2
  import 'zod';
3
3
  import '@almadar/patterns';
4
4
 
@@ -3680,9 +3680,41 @@ var RequiredFieldSchema = z.object({
3680
3680
  z.object({
3681
3681
  ref: z.string().min(1),
3682
3682
  linkedEntity: z.string().optional(),
3683
+ name: z.string().optional(),
3684
+ events: z.record(
3685
+ z.string().min(1, "events key (atom event name) must be non-empty"),
3686
+ z.string().min(1, "events value (caller event name) must be non-empty")
3687
+ ).optional(),
3683
3688
  config: z.record(z.record(z.unknown())).optional(),
3684
- appliesTo: z.array(z.string()).optional()
3685
- });
3689
+ appliesTo: z.array(z.string()).optional(),
3690
+ // Phase F.7: zod accepts an array (the inliner validates element
3691
+ // shape). The full ListenDefinition shape isn't recursively encoded
3692
+ // here because TraitReference is the call-site form — listen entries
3693
+ // pasted in are already-resolved structured definitions, not nested
3694
+ // overrides.
3695
+ listens: z.array(z.unknown()).optional(),
3696
+ emitsScope: z.enum(["internal", "external"]).optional(),
3697
+ // Phase F.8: per-transition effects override. The keys are event
3698
+ // names (the transition triggers AFTER renames). Values are arrays
3699
+ // of SExpression-shaped data; the inliner validates the SExpression
3700
+ // shape during application, so the schema accepts loose `unknown[]`.
3701
+ effects: z.record(
3702
+ z.string().min(1, "effects override key (event name) must be non-empty"),
3703
+ z.array(z.unknown())
3704
+ ).optional()
3705
+ }).refine(
3706
+ (ref2) => {
3707
+ if (!ref2.events) return true;
3708
+ for (const [from, to] of Object.entries(ref2.events)) {
3709
+ if (from.length === 0 || to.length === 0) return false;
3710
+ }
3711
+ return true;
3712
+ },
3713
+ {
3714
+ message: 'TraitReference "events" entries must have non-empty atom and caller event names',
3715
+ path: ["events"]
3716
+ }
3717
+ );
3686
3718
  var TraitSchema = z.object({
3687
3719
  name: z.string().min(1),
3688
3720
  description: z.string().optional(),
@@ -3703,7 +3735,15 @@ var TraitRefSchema = z.union([
3703
3735
  z.object({
3704
3736
  ref: z.string().min(1),
3705
3737
  config: z.record(z.unknown()).optional(),
3706
- linkedEntity: z.string().optional()
3738
+ linkedEntity: z.string().optional(),
3739
+ name: z.string().optional(),
3740
+ // Phase F.4: same non-empty refine as TraitReferenceSchema.events.
3741
+ // Both schemas accept the same call-site argument shape, so the
3742
+ // validators should agree.
3743
+ events: z.record(
3744
+ z.string().min(1, "events key (atom event name) must be non-empty"),
3745
+ z.string().min(1, "events value (caller event name) must be non-empty")
3746
+ ).optional()
3707
3747
  }),
3708
3748
  TraitSchema
3709
3749
  // Allow inline trait definitions
@@ -3946,8 +3986,17 @@ var ServiceRefStringSchema = z.string().regex(
3946
3986
  /^[A-Z][a-zA-Z0-9]*\.services\.[a-zA-Z][a-zA-Z0-9]*$/,
3947
3987
  'Service reference must be in format "Alias.services.ServiceName" (e.g., "Weather.services.openweather")'
3948
3988
  );
3989
+ var ServiceRefObjectSchema = z.object({
3990
+ ref: ServiceRefStringSchema,
3991
+ description: z.string().optional(),
3992
+ baseUrl: z.string().url("baseUrl override must be a valid URL").optional(),
3993
+ headers: z.record(z.string()).optional(),
3994
+ url: z.string().url("url override must be a valid URL").optional(),
3995
+ serverPath: z.string().optional()
3996
+ });
3949
3997
  var ServiceRefSchema = z.union([
3950
3998
  ServiceDefinitionSchema,
3999
+ ServiceRefObjectSchema,
3951
4000
  ServiceRefStringSchema
3952
4001
  ]);
3953
4002
 
@@ -3962,11 +4011,42 @@ var UseDeclarationSchema = z.object({
3962
4011
  function isEntityReference(entity) {
3963
4012
  return typeof entity === "string";
3964
4013
  }
4014
+ function isEntityCall(entity) {
4015
+ return typeof entity === "object" && entity !== null && "extends" in entity;
4016
+ }
3965
4017
  var EntityRefStringSchema = z.string().regex(
3966
4018
  /^[A-Z][a-zA-Z0-9]*\.entity$/,
3967
4019
  'Entity reference must be in format "Alias.entity" (e.g., "Goblin.entity")'
3968
4020
  );
3969
- var EntityRefSchema = z.union([EntitySchema, EntityRefStringSchema]);
4021
+ var EntityCallSchema = z.object({
4022
+ extends: z.string().regex(
4023
+ /^[A-Z][a-zA-Z0-9]*\.entity$/,
4024
+ 'EntityCall "extends" must be in format "Alias.entity"'
4025
+ ),
4026
+ name: z.string().optional(),
4027
+ fields: z.array(EntityFieldSchema).optional(),
4028
+ persistence: EntityPersistenceSchema.optional(),
4029
+ collection: z.string().optional()
4030
+ }).refine(
4031
+ (call) => {
4032
+ if (!call.fields) return true;
4033
+ const seen = /* @__PURE__ */ new Set();
4034
+ for (const field of call.fields) {
4035
+ if (seen.has(field.name)) return false;
4036
+ seen.add(field.name);
4037
+ }
4038
+ return true;
4039
+ },
4040
+ {
4041
+ message: 'EntityCall "fields" override list must not contain duplicate field names',
4042
+ path: ["fields"]
4043
+ }
4044
+ );
4045
+ var EntityRefSchema = z.union([
4046
+ EntitySchema,
4047
+ EntityRefStringSchema,
4048
+ EntityCallSchema
4049
+ ]);
3970
4050
  function isPageReferenceString(page) {
3971
4051
  return typeof page === "string";
3972
4052
  }
@@ -3979,7 +4059,9 @@ var PageRefStringSchema = z.string().regex(
3979
4059
  );
3980
4060
  var PageRefObjectSchema = z.object({
3981
4061
  ref: PageRefStringSchema,
3982
- path: z.string().startsWith("/").optional()
4062
+ path: z.string().startsWith("/").optional(),
4063
+ linkedEntity: z.string().optional(),
4064
+ traits: z.array(TraitRefSchema).optional()
3983
4065
  });
3984
4066
  var PageRefSchema = z.union([
3985
4067
  PageSchema,
@@ -5258,10 +5340,13 @@ function getEntityName(entity) {
5258
5340
  if (isEntityReference(entity)) {
5259
5341
  return entity.replace(".entity", "");
5260
5342
  }
5343
+ if (isEntityCall(entity)) {
5344
+ return entity.name ?? entity.extends.replace(".entity", "");
5345
+ }
5261
5346
  return entity.name;
5262
5347
  }
5263
5348
  function isInlineEntity(entity) {
5264
- return !isEntityReference(entity);
5349
+ return !isEntityReference(entity) && !isEntityCall(entity);
5265
5350
  }
5266
5351
  function isInlinePage(page) {
5267
5352
  return !isPageReferenceString(page) && !isPageReferenceObject(page);
@@ -5556,6 +5641,9 @@ function getEntityName2(entity) {
5556
5641
  if (isEntityReference(entity)) {
5557
5642
  return entity.replace(".entity", "");
5558
5643
  }
5644
+ if (isEntityCall(entity)) {
5645
+ return entity.name ?? entity.extends.replace(".entity", "");
5646
+ }
5559
5647
  return entity.name;
5560
5648
  }
5561
5649
  function getPageName(page) {