@almadar/core 8.5.0 → 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,5 +1,5 @@
1
1
  import { d as Expression, S as SExpr } from './expression-BVRFm0sV.js';
2
- import { bj as TraitConfig, bk as TraitConfigObject, aW as ServiceRef, y as Entity, B as EntityField, H as EntityPersistence, bx as TraitRef, R as EventPayloadField, n as ConfigFieldDeclaration, aS as ServiceDefinition, bg as Trait } from './trait-BV1DyJ2A.js';
2
+ import { bj as TraitConfig, bk as TraitConfigObject, aW as ServiceRef, y as Entity, B as EntityField, H as EntityPersistence, bx as TraitRef, R as EventPayloadField, n as ConfigFieldDeclaration, aS as ServiceDefinition, bg as Trait } from './trait-CvzQvW-e.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  /**
@@ -96,42 +96,77 @@ declare const RelationConfigSchema: z.ZodEffects<z.ZodObject<{
96
96
  type FieldFormat = 'email' | 'url' | 'phone' | 'date' | 'datetime' | 'uuid';
97
97
  declare const FieldFormatSchema: z.ZodEnum<["email", "url", "phone", "date", "datetime", "uuid"]>;
98
98
  /**
99
- * Entity field definition.
99
+ * Field-type tags that don't carry a type-dependent payload. The base
100
+ * `EntityField` shape applies as-is.
100
101
  */
101
- interface EntityField {
102
+ type ScalarFieldType = 'string' | 'number' | 'boolean' | 'date' | 'timestamp' | 'datetime' | 'object' | 'trait' | 'slot' | 'pattern';
103
+ /** Fields shared across every variant. */
104
+ interface EntityFieldBase {
102
105
  /**
103
106
  * Field name (camelCase). Optional for nested item/property descriptors
104
107
  * where the name is implied by the parent (`items`, `properties[k]`).
105
108
  * Mirrors Rust's `FieldDefinition.name: Option<String>`.
106
109
  */
107
110
  name?: string;
108
- /** Data type */
109
- type: FieldType;
110
111
  /** Whether the field is required */
111
112
  required?: boolean;
112
113
  /** Default value */
113
114
  default?: unknown;
114
- /** Allowed values for enum types */
115
- values?: string[];
116
- /** @deprecated Use 'values' instead */
117
- enum?: string[];
118
115
  /** Validation format */
119
116
  format?: FieldFormat;
120
117
  /** Minimum value (for number) or length (for string) */
121
118
  min?: number;
122
119
  /** Maximum value or length */
123
120
  max?: number;
124
- /** Array item schema (for array type) */
125
- items?: EntityField;
126
121
  /** Object property schemas keyed by property name (for object type).
127
122
  * Mirrors Rust's `FieldDefinition.properties: Option<HashMap<String,
128
123
  * FieldDefinition>>`. Populated by the lolo lowerer when a field /
129
124
  * config slot's type expression resolves to a struct shape
130
125
  * (`TypeExpr::Object`), including named-type aliases like `[MetricSpec]`. */
131
126
  properties?: Record<string, EntityField>;
132
- /** Relation configuration (required when type is 'relation') */
133
- relation?: RelationConfig;
134
127
  }
128
+ /** Scalar / structural fields — no type-dependent payload required. */
129
+ interface ScalarEntityField extends EntityFieldBase {
130
+ type: ScalarFieldType;
131
+ }
132
+ /** `type: 'enum'` REQUIRES the closed vocabulary in `values`. */
133
+ interface EnumEntityField extends EntityFieldBase {
134
+ type: 'enum';
135
+ /** Closed string vocabulary the field accepts. */
136
+ values: string[];
137
+ }
138
+ /** `type: 'relation'` REQUIRES the relation target binding. */
139
+ interface RelationEntityField extends EntityFieldBase {
140
+ type: 'relation';
141
+ /** Relation target binding (entity + cardinality). */
142
+ relation: RelationConfig;
143
+ }
144
+ /** `type: 'array'` REQUIRES the element schema in `items`. */
145
+ interface ArrayEntityField extends EntityFieldBase {
146
+ type: 'array';
147
+ /** Element schema for the array. */
148
+ items: EntityField;
149
+ }
150
+ /**
151
+ * Entity field definition — discriminated union by `type`. Each variant
152
+ * statically enforces its dependent payload (`values` for enum,
153
+ * `relation` for relation, `items` for array) so TS / Zod / JSON Schema
154
+ * consumers all agree on the dependency, not just the Rust validator.
155
+ *
156
+ * @example
157
+ * { name: 'status', type: 'enum', values: ['draft', 'published'] }
158
+ * { name: 'authorId', type: 'relation', relation: { entity: 'User', cardinality: 'one' } }
159
+ * { name: 'tags', type: 'array', items: { type: 'string' } }
160
+ */
161
+ type EntityField = ScalarEntityField | EnumEntityField | RelationEntityField | ArrayEntityField;
162
+ /**
163
+ * Zod schema for `EntityField`. Preprocess normalizes:
164
+ * - legacy `type` aliases (text → string, int → number, etc.)
165
+ * - legacy `enum: string[]` alias → `values: string[]`
166
+ *
167
+ * Branches on `type` so TS narrows the parsed output to the matching
168
+ * discriminated-union variant.
169
+ */
135
170
  declare const EntityFieldSchema: z.ZodType<EntityField, z.ZodTypeDef, unknown>;
136
171
  type EntityFieldInput = z.input<typeof EntityFieldSchema>;
137
172
  /** Alias for EntityField - preferred name */
@@ -1,7 +1,7 @@
1
- import { a3 as OrbitalSchema, T as Orbital, aa as Page, u as DomainContext } from '../schema-Dp98Xt5i.js';
2
- export { A as AGENT_DOMAIN_CATEGORIES, a as ALLOWED_CUSTOM_COMPONENTS, b as AgentDomainCategory, c as AgentDomainCategorySchema, d as AllowedCustomComponent, C as ComputedEventContract, e as ComputedEventContractSchema, f as ComputedEventListener, g as ComputedEventListenerSchema, h as CustomPatternDefinition, i as CustomPatternDefinitionInput, j as CustomPatternDefinitionSchema, k as CustomPatternMap, l as CustomPatternMapInput, m as CustomPatternMapSchema, D as DesignPreferences, n as DesignPreferencesInput, o as DesignPreferencesSchema, p as DesignTokens, q as DesignTokensInput, r as DesignTokensSchema, s as DomainCategory, t as DomainCategorySchema, v as DomainContextInput, w as DomainContextSchema, x as DomainVocabulary, y as DomainVocabularySchema, E as EntityCall, z as EntityCallSchema, B as EntityRef, F as EntityRefSchema, G as EntityRefStringSchema, H as EntitySemanticRole, I as EntitySemanticRoleSchema, J as EventListener, K as EventListenerSchema, L as EventSemanticRole, M as EventSemanticRoleSchema, N as EventSource, O as EventSourceSchema, P as GameSubCategory, Q as GameSubCategorySchema, R as NodeClassification, S as NodeClassificationSchema, U as OrbitalConfig, V as OrbitalConfigInput, W as OrbitalConfigSchema, X as OrbitalDefinition, Y as OrbitalDefinitionSchema, Z as OrbitalInput, _ as OrbitalPage, $ as OrbitalPageInput, a0 as OrbitalPageSchema, a1 as OrbitalPageStrictInput, a2 as OrbitalPageStrictSchema, a5 as OrbitalSchemaInput, a6 as OrbitalSchemaSchema, a7 as OrbitalSchemaWithTraits, a8 as OrbitalUnit, a9 as OrbitalUnitSchema, a4 as OrbitalZodSchema, ab as PageRef, ac as PageRefObject, ad as PageRefObjectSchema, ae as PageRefSchema, af as PageRefStringSchema, ag as PageSchema, ah as PageTraitRef, ai as PageTraitRefSchema, aj as RelatedLink, ak as RelatedLinkSchema, al as StateSemanticRole, am as StateSemanticRoleSchema, an as SuggestedGuard, ao as SuggestedGuardSchema, ap as ThemeDefinition, aq as ThemeDefinitionSchema, ar as ThemeRef, as as ThemeRefSchema, at as ThemeRefStringSchema, au as ThemeTokens, av as ThemeTokensSchema, aw as ThemeVariant, ax as ThemeVariantSchema, ay as UXHints, az as UXHintsSchema, aA as UseDeclaration, aB as UseDeclarationSchema, aC as UserPersona, aD as UserPersonaInput, aE as UserPersonaSchema, aF as ViewType, aG as ViewTypeSchema, aH as isEntityCall, aI as isEntityReference, aJ as isEntityReferenceAny, aK as isImportedTraitRef, aL as isOrbitalDefinition, aM as isPageReference, aN as isPageReferenceObject, aO as isPageReferenceString, aP as isThemeReference, aQ as parseEntityRef, aR as parseImportedTraitRef, aS as parseOrbitalSchema, aT as parsePageRef, aU as safeParseOrbitalSchema } from '../schema-Dp98Xt5i.js';
3
- import { aU as ServiceParams, bg as Trait, y as Entity, L as EntityRow, a3 as FieldValue, D as DeclaredTraitConfig, bj as TraitConfig } from '../trait-BV1DyJ2A.js';
4
- export { A as AgentEffect, a as AnimationDef, b as AnimationDefInput, c as AnimationDefSchema, d as AssetMap, e as AssetMapInput, f as AssetMapSchema, g as AssetMapping, h as AssetMappingInput, i as AssetMappingSchema, j as AtomicEffect, C as CallServiceConfig, k as CallServiceEffect, l as CheckpointLoadEffect, m as CheckpointSaveEffect, n as ConfigFieldDeclaration, o as ConfigFieldDeclarationSchema, p as DeclaredTraitConfigSchema, q as DerefEffect, r as DespawnEffect, s as DoEffect, E as ENTITY_ROLES, t as Effect, u as EffectInput, v as EffectSchema, w as EmitConfig, x as EmitEffect, z as EntityData, B as EntityField, F as EntityFieldInput, G as EntityFieldSchema, H as EntityPersistence, I as EntityPersistenceSchema, J as EntityRole, K as EntityRoleSchema, M as EntitySchema, N as EvaluateConfig, O as EvaluateEffect, P as Event, Q as EventInput, R as EventPayloadField, S as EventPayloadFieldSchema, T as EventSchema, U as EventScope, V as EventScopeSchema, W as FetchEffect, X as FetchOptions, Y as FetchResult, Z as Field, _ as FieldFormat, $ as FieldFormatSchema, a0 as FieldSchema, a1 as FieldType, a2 as FieldTypeSchema, a4 as ForwardConfig, a5 as ForwardEffect, a6 as GAME_TYPES, a7 as GameType, a8 as GameTypeSchema, a9 as Guard, aa as GuardInput, ab as GuardSchema, ac as ListenSource, ad as ListenSourceSchema, ae as LogEffect, af as McpServiceDef, ag as McpServiceDefSchema, ah as NavigateEffect, ai as NnConfig, aj as NnLayer, ak as NotifyEffect, al as OrbitalEntity, am as OrbitalEntityInput, an as OrbitalEntitySchema, ao as OrbitalTraitRef, ap as OrbitalTraitRefSchema, aq as OsEffect, ar as PayloadField, as as PayloadFieldSchema, at as PersistData, au as PersistEffect, av as PersistEmitConfig, aw as PresentationType, ax as RefEffect, ay as RelationConfig, az as RelationConfigSchema, aA as RenderItemLambda, aB as RenderUIConfig, aC as RenderUIEffect, aD as RenderUINode, aE as RequiredField, aF as RequiredFieldSchema, aG as ResolvedAsset, aH as ResolvedAssetInput, aI as ResolvedAssetSchema, aJ as ResolvedPatternProps, aK as RestAuthConfig, aL as RestAuthConfigSchema, aM as RestServiceDef, aN as RestServiceDefSchema, aO as SERVICE_TYPES, aP as SemanticAssetRef, aQ as SemanticAssetRefInput, aR as SemanticAssetRefSchema, aS as ServiceDefinition, aT as ServiceDefinitionSchema, aV as ServiceParamsValue, aW as ServiceRef, aX as ServiceRefObject, aY as ServiceRefObjectSchema, aZ as ServiceRefSchema, a_ as ServiceRefStringSchema, a$ as ServiceType, b0 as ServiceTypeSchema, b1 as SetEffect, b2 as SocketEvents, b3 as SocketEventsSchema, b4 as SocketServiceDef, b5 as SocketServiceDefSchema, b6 as SpawnEffect, b7 as State, b8 as StateInput, b9 as StateMachine, ba as StateMachineInput, bb as StateMachineSchema, bc as StateSchema, bd as SwapEffect, be as TrainConfig, bf as TrainEffect, bh as TraitCategory, bi as TraitCategorySchema, bk as TraitConfigObject, bl as TraitConfigSchema, bm as TraitConfigValue, bn as TraitConfigValueSchema, bo as TraitDataEntity, bp as TraitDataEntitySchema, bq as TraitEntityField, br as TraitEntityFieldSchema, bs as TraitEventContract, bt as TraitEventContractSchema, bu as TraitEventListener, bv as TraitEventListenerSchema, bw as TraitInput, bx as TraitRef, by as TraitRefSchema, bz as TraitReference, bA as TraitReferenceInput, bB as TraitReferenceSchema, bC as TraitSchema, bD as TraitTick, bE as TraitTickSchema, bF as TraitUIBinding, bG as Transition, bH as TransitionInput, bI as TransitionSchema, bJ as TypedEffect, bK as UISlot, bL as UISlotSchema, bM as UI_SLOTS, bN as VISUAL_STYLES, bO as VisualStyle, bP as VisualStyleSchema, bQ as WatchEffect, bR as WatchOptions, bS as atomic, bT as callService, bU as createAssetKey, bV as deref, bW as deriveCollection, bX as despawn, bY as doEffects, bZ as emit, b_ as findService, b$ as getDefaultAnimationsForRole, c0 as getServiceNames, c1 as getTraitConfig, c2 as getTraitName, c3 as hasService, c4 as isCircuitEvent, c5 as isEffect, c6 as isInlineTrait, c7 as isMcpService, c8 as isRestService, c9 as isRuntimeEntity, ca as isSExprEffect, cb as isServiceReference, cc as isServiceReferenceObject, cd as isSingletonEntity, ce as isSocketService, cf as navigate, cg as normalizeTraitRef, ch as notify, ci as parseAssetKey, cj as parseServiceRef, ck as persist, cl as ref, cm as renderUI, cn as set, co as spawn, cp as swap, cq as validateAssetAnimations, cr as watch } from '../trait-BV1DyJ2A.js';
1
+ import { a3 as OrbitalSchema, T as Orbital, aa as Page, u as DomainContext } from '../schema-TBowD2oF.js';
2
+ export { A as AGENT_DOMAIN_CATEGORIES, a as ALLOWED_CUSTOM_COMPONENTS, b as AgentDomainCategory, c as AgentDomainCategorySchema, d as AllowedCustomComponent, C as ComputedEventContract, e as ComputedEventContractSchema, f as ComputedEventListener, g as ComputedEventListenerSchema, h as CustomPatternDefinition, i as CustomPatternDefinitionInput, j as CustomPatternDefinitionSchema, k as CustomPatternMap, l as CustomPatternMapInput, m as CustomPatternMapSchema, D as DesignPreferences, n as DesignPreferencesInput, o as DesignPreferencesSchema, p as DesignTokens, q as DesignTokensInput, r as DesignTokensSchema, s as DomainCategory, t as DomainCategorySchema, v as DomainContextInput, w as DomainContextSchema, x as DomainVocabulary, y as DomainVocabularySchema, E as EntityCall, z as EntityCallSchema, B as EntityRef, F as EntityRefSchema, G as EntityRefStringSchema, H as EntitySemanticRole, I as EntitySemanticRoleSchema, J as EventListener, K as EventListenerSchema, L as EventSemanticRole, M as EventSemanticRoleSchema, N as EventSource, O as EventSourceSchema, P as GameSubCategory, Q as GameSubCategorySchema, R as NodeClassification, S as NodeClassificationSchema, U as OrbitalConfig, V as OrbitalConfigInput, W as OrbitalConfigSchema, X as OrbitalDefinition, Y as OrbitalDefinitionSchema, Z as OrbitalInput, _ as OrbitalPage, $ as OrbitalPageInput, a0 as OrbitalPageSchema, a1 as OrbitalPageStrictInput, a2 as OrbitalPageStrictSchema, a5 as OrbitalSchemaInput, a6 as OrbitalSchemaSchema, a7 as OrbitalSchemaWithTraits, a8 as OrbitalUnit, a9 as OrbitalUnitSchema, a4 as OrbitalZodSchema, ab as PageRef, ac as PageRefObject, ad as PageRefObjectSchema, ae as PageRefSchema, af as PageRefStringSchema, ag as PageSchema, ah as PageTraitRef, ai as PageTraitRefSchema, aj as RelatedLink, ak as RelatedLinkSchema, al as StateSemanticRole, am as StateSemanticRoleSchema, an as SuggestedGuard, ao as SuggestedGuardSchema, ap as ThemeDefinition, aq as ThemeDefinitionSchema, ar as ThemeRef, as as ThemeRefSchema, at as ThemeRefStringSchema, au as ThemeTokens, av as ThemeTokensSchema, aw as ThemeVariant, ax as ThemeVariantSchema, ay as UXHints, az as UXHintsSchema, aA as UseDeclaration, aB as UseDeclarationSchema, aC as UserPersona, aD as UserPersonaInput, aE as UserPersonaSchema, aF as ViewType, aG as ViewTypeSchema, aH as isEntityCall, aI as isEntityReference, aJ as isEntityReferenceAny, aK as isImportedTraitRef, aL as isOrbitalDefinition, aM as isPageReference, aN as isPageReferenceObject, aO as isPageReferenceString, aP as isThemeReference, aQ as parseEntityRef, aR as parseImportedTraitRef, aS as parseOrbitalSchema, aT as parsePageRef, aU as safeParseOrbitalSchema } from '../schema-TBowD2oF.js';
3
+ import { aU as ServiceParams, bg as Trait, y as Entity, L as EntityRow, a3 as FieldValue, D as DeclaredTraitConfig, bj as TraitConfig } from '../trait-CvzQvW-e.js';
4
+ export { A as AgentEffect, a as AnimationDef, b as AnimationDefInput, c as AnimationDefSchema, d as AssetMap, e as AssetMapInput, f as AssetMapSchema, g as AssetMapping, h as AssetMappingInput, i as AssetMappingSchema, j as AtomicEffect, C as CallServiceConfig, k as CallServiceEffect, l as CheckpointLoadEffect, m as CheckpointSaveEffect, n as ConfigFieldDeclaration, o as ConfigFieldDeclarationSchema, p as DeclaredTraitConfigSchema, q as DerefEffect, r as DespawnEffect, s as DoEffect, E as ENTITY_ROLES, t as Effect, u as EffectInput, v as EffectSchema, w as EmitConfig, x as EmitEffect, z as EntityData, B as EntityField, F as EntityFieldInput, G as EntityFieldSchema, H as EntityPersistence, I as EntityPersistenceSchema, J as EntityRole, K as EntityRoleSchema, M as EntitySchema, N as EvaluateConfig, O as EvaluateEffect, P as Event, Q as EventInput, R as EventPayloadField, S as EventPayloadFieldSchema, T as EventSchema, U as EventScope, V as EventScopeSchema, W as FetchEffect, X as FetchOptions, Y as FetchResult, Z as Field, _ as FieldFormat, $ as FieldFormatSchema, a0 as FieldSchema, a1 as FieldType, a2 as FieldTypeSchema, a4 as ForwardConfig, a5 as ForwardEffect, a6 as GAME_TYPES, a7 as GameType, a8 as GameTypeSchema, a9 as Guard, aa as GuardInput, ab as GuardSchema, ac as ListenSource, ad as ListenSourceSchema, ae as LogEffect, af as McpServiceDef, ag as McpServiceDefSchema, ah as NavigateEffect, ai as NnConfig, aj as NnLayer, ak as NotifyEffect, al as OrbitalEntity, am as OrbitalEntityInput, an as OrbitalEntitySchema, ao as OrbitalTraitRef, ap as OrbitalTraitRefSchema, aq as OsEffect, ar as PayloadField, as as PayloadFieldSchema, at as PersistData, au as PersistEffect, av as PersistEmitConfig, aw as PresentationType, ax as RefEffect, ay as RelationConfig, az as RelationConfigSchema, aA as RenderItemLambda, aB as RenderUIConfig, aC as RenderUIEffect, aD as RenderUINode, aE as RequiredField, aF as RequiredFieldSchema, aG as ResolvedAsset, aH as ResolvedAssetInput, aI as ResolvedAssetSchema, aJ as ResolvedPatternProps, aK as RestAuthConfig, aL as RestAuthConfigSchema, aM as RestServiceDef, aN as RestServiceDefSchema, aO as SERVICE_TYPES, aP as SemanticAssetRef, aQ as SemanticAssetRefInput, aR as SemanticAssetRefSchema, aS as ServiceDefinition, aT as ServiceDefinitionSchema, aV as ServiceParamsValue, aW as ServiceRef, aX as ServiceRefObject, aY as ServiceRefObjectSchema, aZ as ServiceRefSchema, a_ as ServiceRefStringSchema, a$ as ServiceType, b0 as ServiceTypeSchema, b1 as SetEffect, b2 as SocketEvents, b3 as SocketEventsSchema, b4 as SocketServiceDef, b5 as SocketServiceDefSchema, b6 as SpawnEffect, b7 as State, b8 as StateInput, b9 as StateMachine, ba as StateMachineInput, bb as StateMachineSchema, bc as StateSchema, bd as SwapEffect, be as TrainConfig, bf as TrainEffect, bh as TraitCategory, bi as TraitCategorySchema, bk as TraitConfigObject, bl as TraitConfigSchema, bm as TraitConfigValue, bn as TraitConfigValueSchema, bo as TraitDataEntity, bp as TraitDataEntitySchema, bq as TraitEntityField, br as TraitEntityFieldSchema, bs as TraitEventContract, bt as TraitEventContractSchema, bu as TraitEventListener, bv as TraitEventListenerSchema, bw as TraitInput, bx as TraitRef, by as TraitRefSchema, bz as TraitReference, bA as TraitReferenceInput, bB as TraitReferenceSchema, bC as TraitSchema, bD as TraitTick, bE as TraitTickSchema, bF as TraitUIBinding, bG as Transition, bH as TransitionInput, bI as TransitionSchema, bJ as TypedEffect, bK as UISlot, bL as UISlotSchema, bM as UI_SLOTS, bN as VISUAL_STYLES, bO as VisualStyle, bP as VisualStyleSchema, bQ as WatchEffect, bR as WatchOptions, bS as atomic, bT as callService, bU as createAssetKey, bV as deref, bW as deriveCollection, bX as despawn, bY as doEffects, bZ as emit, b_ as findService, b$ as getDefaultAnimationsForRole, c0 as getServiceNames, c1 as getTraitConfig, c2 as getTraitName, c3 as hasService, c4 as isCircuitEvent, c5 as isEffect, c6 as isInlineTrait, c7 as isMcpService, c8 as isRestService, c9 as isRuntimeEntity, ca as isSExprEffect, cb as isServiceReference, cc as isServiceReferenceObject, cd as isSingletonEntity, ce as isSocketService, cf as navigate, cg as normalizeTraitRef, ch as notify, ci as parseAssetKey, cj as parseServiceRef, ck as persist, cl as ref, cm as renderUI, cn as set, co as spawn, cp as swap, cq as validateAssetAnimations, cr as watch } from '../trait-CvzQvW-e.js';
5
5
  import { c as EventPayloadValue, b as EventPayload, L as LogMeta, S as SExpr } from '../expression-BVRFm0sV.js';
6
6
  export { C as CORE_BINDINGS, a as CoreBinding, E as EvalContext, d as Expression, e as ExpressionInput, f as ExpressionSchema, P as ParsedBinding, g as SExprAtom, h as SExprAtomSchema, i as SExprInput, j as SExprSchema, k as collectBindings, l as getArgs, m as getOperator, n as isBinding, o as isSExpr, p as isSExprAtom, q as isSExprCall, r as isValidBinding, s as parseBinding, t as sexpr, w as walkSExpr } from '../expression-BVRFm0sV.js';
7
7
  import { z } from 'zod';
@@ -57,58 +57,66 @@ var FIELD_TYPE_ALIASES = {
57
57
  float: "number",
58
58
  ts: "timestamp"
59
59
  };
60
- var EntityFieldSchema = z.lazy(
61
- () => z.preprocess(
60
+ var EntityFieldSchema = z.lazy(() => {
61
+ const baseFieldShape = {
62
+ name: z.string().min(1, "Field name is required").optional(),
63
+ required: z.boolean().optional(),
64
+ default: z.unknown().optional(),
65
+ format: FieldFormatSchema.optional(),
66
+ min: z.number().optional(),
67
+ max: z.number().optional(),
68
+ properties: z.record(EntityFieldSchema).optional()
69
+ };
70
+ function scalarVariant(t) {
71
+ return z.object({ ...baseFieldShape, type: z.literal(t) });
72
+ }
73
+ return z.preprocess(
62
74
  (input) => {
63
- if (input !== null && typeof input === "object" && "type" in input && typeof input.type === "string") {
64
- const raw = input.type;
65
- const canonical = FIELD_TYPE_ALIASES[raw];
66
- if (canonical !== void 0) {
67
- return { ...input, type: canonical };
68
- }
75
+ if (input === null || typeof input !== "object" || !("type" in input) || typeof input.type !== "string") {
76
+ return input;
69
77
  }
70
- return input;
78
+ const obj = input;
79
+ const next = { ...obj };
80
+ const aliased = FIELD_TYPE_ALIASES[obj.type];
81
+ if (aliased !== void 0) next["type"] = aliased;
82
+ if (next["enum"] !== void 0 && next["values"] === void 0) {
83
+ next["values"] = next["enum"];
84
+ }
85
+ delete next["enum"];
86
+ return next;
71
87
  },
72
- z.object({
73
- name: z.string().min(1, "Field name is required").optional(),
74
- type: FieldTypeSchema,
75
- required: z.boolean().optional(),
76
- default: z.unknown().optional(),
77
- values: z.array(z.string()).optional(),
78
- enum: z.array(z.string()).optional(),
79
- format: FieldFormatSchema.optional(),
80
- min: z.number().optional(),
81
- max: z.number().optional(),
82
- items: EntityFieldSchema.optional(),
83
- properties: z.record(EntityFieldSchema).optional(),
84
- relation: RelationConfigSchema.optional()
85
- }).refine(
86
- (field) => field.type !== "relation" || field.relation !== void 0,
87
- { message: 'Relation config is required when type is "relation"', path: ["relation"] }
88
- ).refine(
89
- // Enum fields must carry their allowed values. Without this refine,
90
- // the type was lying about what's valid — bare `type: 'enum'` without
91
- // `values` passed zod but failed `orb validate` downstream with
92
- // ORB_E_EMPTY_ENUM_VALUES, stalling the agent pipeline for 20 minutes.
93
- // `enum` is the legacy field-name alias; accept either.
94
- (field) => {
95
- if (field.type !== "enum") return true;
96
- const vals = field.values ?? field.enum;
97
- return Array.isArray(vals) && vals.length > 0;
98
- },
99
- { message: "Enum field requires a non-empty `values` array", path: ["values"] }
100
- ).refine(
101
- // Array fields must describe their element shape. Bare `type: 'array'`
102
- // with no `items` forces downstream consumers (builders, UI renderers,
103
- // persistence) to guess, so reject it at the schema boundary.
104
- (field) => {
105
- if (field.type !== "array") return true;
106
- return field.items !== void 0;
107
- },
108
- { message: "Array field requires an `items` schema describing each element", path: ["items"] }
109
- )
110
- )
111
- );
88
+ z.discriminatedUnion("type", [
89
+ scalarVariant("string"),
90
+ scalarVariant("number"),
91
+ scalarVariant("boolean"),
92
+ scalarVariant("date"),
93
+ scalarVariant("timestamp"),
94
+ scalarVariant("datetime"),
95
+ scalarVariant("object"),
96
+ scalarVariant("trait"),
97
+ scalarVariant("slot"),
98
+ scalarVariant("pattern"),
99
+ // Enum variant — REQUIRES non-empty values.
100
+ z.object({
101
+ ...baseFieldShape,
102
+ type: z.literal("enum"),
103
+ values: z.array(z.string()).min(1, "Enum field requires a non-empty `values` array")
104
+ }),
105
+ // Relation variant REQUIRES relation config.
106
+ z.object({
107
+ ...baseFieldShape,
108
+ type: z.literal("relation"),
109
+ relation: RelationConfigSchema
110
+ }),
111
+ // Array variant REQUIRES items schema.
112
+ z.object({
113
+ ...baseFieldShape,
114
+ type: z.literal("array"),
115
+ items: EntityFieldSchema
116
+ })
117
+ ])
118
+ );
119
+ });
112
120
  var FieldSchema = EntityFieldSchema;
113
121
  var ENTITY_ROLES = [
114
122
  "player",