@almadar/core 8.5.1 → 8.6.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,7 +1,7 @@
1
- import { bK as UISlot, t as Effect, bg as Trait, aC as RenderUIEffect, bs as TraitEventContract, y as Entity, bu as TraitEventListener, bj as TraitConfig, B as EntityField, H as EntityPersistence, L as EntityRow, bx as TraitRef, bz as TraitReference } from './trait-BV1DyJ2A.js';
2
- import { aA as UseDeclaration, B as EntityRef, ab as PageRef, X as OrbitalDefinition, a3 as OrbitalSchema, aa as Page, ac as PageRefObject } from './schema-Dp98Xt5i.js';
1
+ import { bK as UISlot, t as Effect, bg as Trait, aC as RenderUIEffect, bs as TraitEventContract, y as Entity, bu as TraitEventListener, bj as TraitConfig, B as EntityField, H as EntityPersistence, L as EntityRow, bx as TraitRef, bz as TraitReference } from './trait-CvzQvW-e.js';
2
+ import { aA as UseDeclaration, B as EntityRef, ab as PageRef, X as OrbitalDefinition, a3 as OrbitalSchema, aa as Page, ac as PageRefObject } from './schema-TBowD2oF.js';
3
3
  import { S as SExpr } from './expression-BVRFm0sV.js';
4
- export { C as ComposeBehaviorsInput, a as ComposeBehaviorsResult, E as EventWiringEntry, L as LayoutStrategy, b as applyEventWiring, c as composeBehaviors, d as detectLayoutStrategy } from './compose-behaviors-TSp2c_dn.js';
4
+ export { C as ComposeBehaviorsInput, a as ComposeBehaviorsResult, E as EventWiringEntry, L as LayoutStrategy, b as applyEventWiring, c as composeBehaviors, d as detectLayoutStrategy } from './compose-behaviors-DUv4yYRF.js';
5
5
  import { AnyPatternConfig } from '@almadar/patterns';
6
6
  import 'zod';
7
7
 
package/dist/builders.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  // src/types/orbital.ts
4
- var FieldTypeSchema = z.enum([
4
+ z.enum([
5
5
  "string",
6
6
  "number",
7
7
  "boolean",
@@ -55,58 +55,66 @@ var FIELD_TYPE_ALIASES = {
55
55
  float: "number",
56
56
  ts: "timestamp"
57
57
  };
58
- var EntityFieldSchema = z.lazy(
59
- () => z.preprocess(
58
+ var EntityFieldSchema = z.lazy(() => {
59
+ const baseFieldShape = {
60
+ name: z.string().min(1, "Field name is required").optional(),
61
+ required: z.boolean().optional(),
62
+ default: z.unknown().optional(),
63
+ format: FieldFormatSchema.optional(),
64
+ min: z.number().optional(),
65
+ max: z.number().optional(),
66
+ properties: z.record(EntityFieldSchema).optional()
67
+ };
68
+ function scalarVariant(t) {
69
+ return z.object({ ...baseFieldShape, type: z.literal(t) });
70
+ }
71
+ return z.preprocess(
60
72
  (input) => {
61
- if (input !== null && typeof input === "object" && "type" in input && typeof input.type === "string") {
62
- const raw = input.type;
63
- const canonical = FIELD_TYPE_ALIASES[raw];
64
- if (canonical !== void 0) {
65
- return { ...input, type: canonical };
66
- }
73
+ if (input === null || typeof input !== "object" || !("type" in input) || typeof input.type !== "string") {
74
+ return input;
75
+ }
76
+ const obj = input;
77
+ const next = { ...obj };
78
+ const aliased = FIELD_TYPE_ALIASES[obj.type];
79
+ if (aliased !== void 0) next["type"] = aliased;
80
+ if (next["enum"] !== void 0 && next["values"] === void 0) {
81
+ next["values"] = next["enum"];
67
82
  }
68
- return input;
83
+ delete next["enum"];
84
+ return next;
69
85
  },
70
- z.object({
71
- name: z.string().min(1, "Field name is required").optional(),
72
- type: FieldTypeSchema,
73
- required: z.boolean().optional(),
74
- default: z.unknown().optional(),
75
- values: z.array(z.string()).optional(),
76
- enum: z.array(z.string()).optional(),
77
- format: FieldFormatSchema.optional(),
78
- min: z.number().optional(),
79
- max: z.number().optional(),
80
- items: EntityFieldSchema.optional(),
81
- properties: z.record(EntityFieldSchema).optional(),
82
- relation: RelationConfigSchema.optional()
83
- }).refine(
84
- (field) => field.type !== "relation" || field.relation !== void 0,
85
- { message: 'Relation config is required when type is "relation"', path: ["relation"] }
86
- ).refine(
87
- // Enum fields must carry their allowed values. Without this refine,
88
- // the type was lying about what's valid — bare `type: 'enum'` without
89
- // `values` passed zod but failed `orb validate` downstream with
90
- // ORB_E_EMPTY_ENUM_VALUES, stalling the agent pipeline for 20 minutes.
91
- // `enum` is the legacy field-name alias; accept either.
92
- (field) => {
93
- if (field.type !== "enum") return true;
94
- const vals = field.values ?? field.enum;
95
- return Array.isArray(vals) && vals.length > 0;
96
- },
97
- { message: "Enum field requires a non-empty `values` array", path: ["values"] }
98
- ).refine(
99
- // Array fields must describe their element shape. Bare `type: 'array'`
100
- // with no `items` forces downstream consumers (builders, UI renderers,
101
- // persistence) to guess, so reject it at the schema boundary.
102
- (field) => {
103
- if (field.type !== "array") return true;
104
- return field.items !== void 0;
105
- },
106
- { message: "Array field requires an `items` schema describing each element", path: ["items"] }
107
- )
108
- )
109
- );
86
+ z.discriminatedUnion("type", [
87
+ scalarVariant("string"),
88
+ scalarVariant("number"),
89
+ scalarVariant("boolean"),
90
+ scalarVariant("date"),
91
+ scalarVariant("timestamp"),
92
+ scalarVariant("datetime"),
93
+ scalarVariant("object"),
94
+ scalarVariant("trait"),
95
+ scalarVariant("slot"),
96
+ scalarVariant("pattern"),
97
+ // Enum variant — REQUIRES non-empty values.
98
+ z.object({
99
+ ...baseFieldShape,
100
+ type: z.literal("enum"),
101
+ values: z.array(z.string()).min(1, "Enum field requires a non-empty `values` array")
102
+ }),
103
+ // Relation variant REQUIRES relation config.
104
+ z.object({
105
+ ...baseFieldShape,
106
+ type: z.literal("relation"),
107
+ relation: RelationConfigSchema
108
+ }),
109
+ // Array variant REQUIRES items schema.
110
+ z.object({
111
+ ...baseFieldShape,
112
+ type: z.literal("array"),
113
+ items: EntityFieldSchema
114
+ })
115
+ ])
116
+ );
117
+ });
110
118
  var ENTITY_ROLES = [
111
119
  "player",
112
120
  "enemy",