@@ -4,7 +4,14 @@ import { lowerCaseFirst } from 'lower-case-first';
44 * Runtime information of a data model or field attribute 
55 */ 
66export  type  RuntimeAttribute  =  { 
7+     /** 
8+      * Attribute name 
9+      */ 
710    name : string ; 
11+ 
12+     /** 
13+      * Attribute arguments 
14+      */ 
815    args : Array < {  name ?: string ;  value : unknown  } > ; 
916} ; 
1017
@@ -72,6 +79,11 @@ export type FieldInfo = {
7279     */ 
7380    foreignKeyMapping ?: Record < string ,  string > ; 
7481
82+     /** 
83+      * Model from which the field is inherited 
84+      */ 
85+     inheritedFrom ?: string ; 
86+ 
7587    /** 
7688     * A function that provides a default value for the field 
7789     */ 
@@ -90,23 +102,53 @@ export type FieldInfo = {
90102export  type  UniqueConstraint  =  {  name : string ;  fields : string [ ]  } ; 
91103
92104/** 
93-  * ZModel  data model metadata  
105+  * Metadata for a  data model 
94106 */ 
95- export  type  ModelMeta  =  { 
107+ export  type  ModelInfo  =  { 
108+     /** 
109+      * Model name 
110+      */ 
111+     name : string ; 
112+ 
113+     /** 
114+      * Base types 
115+      */ 
116+     baseTypes ?: string [ ] ; 
117+ 
118+     /** 
119+      * Fields 
120+      */ 
121+     fields : Record < string ,  FieldInfo > ; 
122+ 
123+     /** 
124+      * Unique constraints 
125+      */ 
126+     uniqueConstraints ?: Record < string ,  UniqueConstraint > ; 
127+ 
128+     /** 
129+      * Attributes on the model 
130+      */ 
131+     attributes ?: RuntimeAttribute [ ] ; 
132+ 
96133    /** 
97-      * Model fields  
134+      * Discriminator field name  
98135     */ 
99-     fields : Record < string ,  Record < string ,  FieldInfo > > ; 
136+     discriminator ?: string ; 
137+ } ; 
100138
139+ /** 
140+  * ZModel data model metadata 
141+  */ 
142+ export  type  ModelMeta  =  { 
101143    /** 
102-      * Model unique constraints  
144+      * Data models  
103145     */ 
104-     uniqueConstraints : Record < string ,  Record < string ,   UniqueConstraint > > ; 
146+     models : Record < string ,  ModelInfo > ; 
105147
106148    /** 
107-      * Information for cascading  delete 
149+      * Mapping from model name to models that will be deleted because of it due to cascade  delete 
108150     */ 
109-     deleteCascade : Record < string ,  string [ ] > ; 
151+     deleteCascade ? : Record < string ,  string [ ] > ; 
110152
111153    /** 
112154     * Name of model that backs the `auth()` function 
@@ -117,8 +159,8 @@ export type ModelMeta = {
117159/** 
118160 * Resolves a model field to its metadata. Returns undefined if not found. 
119161 */ 
120- export  function  resolveField ( modelMeta : ModelMeta ,  model : string ,  field : string )  { 
121-     return  modelMeta . fields [ lowerCaseFirst ( model ) ] ?. [ field ] ; 
162+ export  function  resolveField ( modelMeta : ModelMeta ,  model : string ,  field : string ) :  FieldInfo   |   undefined  { 
163+     return  modelMeta . models [ lowerCaseFirst ( model ) ] ?. fields ?. [ field ] ; 
122164} 
123165
124166/** 
@@ -136,5 +178,12 @@ export function requireField(modelMeta: ModelMeta, model: string, field: string)
136178 * Gets all fields of a model. 
137179 */ 
138180export  function  getFields ( modelMeta : ModelMeta ,  model : string )  { 
139-     return  modelMeta . fields [ lowerCaseFirst ( model ) ] ; 
181+     return  modelMeta . models [ lowerCaseFirst ( model ) ] ?. fields ; 
182+ } 
183+ 
184+ /** 
185+  * Gets unique constraints of a model. 
186+  */ 
187+ export  function  getUniqueConstraints ( modelMeta : ModelMeta ,  model : string )  { 
188+     return  modelMeta . models [ lowerCaseFirst ( model ) ] ?. uniqueConstraints ; 
140189} 
0 commit comments