MCPcopy
hub / github.com/blitz-js/blitz / constructor

Method constructor

packages/generator/src/prisma/field.ts:179–201  ·  view source on GitHub ↗
(name: string, options: FieldArgs)

Source from the content-addressed store, hash-verified

177 }
178
179 constructor(name: string, options: FieldArgs) {
180 if (!name) throw new MissingFieldNameError("[PrismaField]: A field name is required")
181 if (!options.type) {
182 console.warn(`No field type specified for field ${name}, falling back to "String".`)
183 options.type = FieldType.String
184 }
185 this.name = name
186 this.isList = fallbackIfUndef(false, options.isList)
187 this.isRequired = fallbackIfUndef(true, options.isRequired)
188 this.isUnique = fallbackIfUndef(false, options.isUnique)
189 this.isId = fallbackIfUndef(false, options.isId)
190 this.type = options.type
191 this.default = options.default
192 this.isUpdatedAt = fallbackIfUndef(false, options.isUpdatedAt)
193 this.relationFromFields = options.relationFromFields
194 this.relationToFields = options.relationToFields
195 if (!this.isRequired && this.isList) {
196 throw new Error("[PrismaField]: a type cannot be both optional and a list")
197 }
198 if (this.isId && this.default === undefined) {
199 throw new Error("[PrismaField]: ID fields must have a default value")
200 }
201 }
202
203 appendTo(model: ast.Model) {
204 if (model.properties.some((prop) => prop.type === "field" && prop.name === this.name)) return

Callers

nothing calls this directly

Calls 2

fallbackIfUndefFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected