mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
703 lines
24 KiB
Text
703 lines
24 KiB
Text
/**
|
|
* Enum representing referential integrity related actions
|
|
* @see https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/referential-actions
|
|
*/
|
|
enum ReferentialAction {
|
|
/**
|
|
* Used with "onDelete": deleting a referenced record will trigger the deletion of referencing record.
|
|
* Used with "onUpdate": updates the relation scalar fields if the referenced scalar fields of the dependent record are updated.
|
|
*/
|
|
Cascade
|
|
|
|
/**
|
|
* Used with "onDelete": prevents the deletion if any referencing records exist.
|
|
* Used with "onUpdate": prevents the identifier of a referenced record from being changed.
|
|
*/
|
|
Restrict
|
|
|
|
/**
|
|
* Similar to 'Restrict', the difference between the two is dependent on the database being used.
|
|
*/
|
|
NoAction
|
|
|
|
/**
|
|
* Used with "onDelete": the scalar field of the referencing object will be set to NULL.
|
|
* Used with "onUpdate": when updating the identifier of a referenced object, the scalar fields of the referencing objects will be set to NULL.
|
|
*/
|
|
SetNull
|
|
|
|
/**
|
|
* Used with "onDelete": the scalar field of the referencing object will be set to the fields default value.
|
|
* Used with "onUpdate": the scalar field of the referencing object will be set to the fields default value.
|
|
*/
|
|
SetDefault
|
|
}
|
|
|
|
/**
|
|
* Enum representing all possible field types
|
|
*/
|
|
enum AttributeTargetField {
|
|
StringField
|
|
IntField
|
|
BigIntField
|
|
FloatField
|
|
DecimalField
|
|
BooleanField
|
|
DateTimeField
|
|
JsonField
|
|
BytesField
|
|
ModelField
|
|
TypeDefField
|
|
ListField
|
|
}
|
|
|
|
/**
|
|
* Indicates the expression context a function can be used.
|
|
*/
|
|
enum ExpressionContext {
|
|
// used in @default
|
|
DefaultValue
|
|
|
|
// used in @@allow and @@deny
|
|
AccessPolicy
|
|
|
|
// used in @@validate
|
|
ValidationRule
|
|
|
|
// used in @@index
|
|
Index
|
|
}
|
|
|
|
/**
|
|
* Reads value from an environment variable.
|
|
*/
|
|
function env(name: String): String {
|
|
}
|
|
|
|
/**
|
|
* Gets current date-time (as DateTime type).
|
|
*/
|
|
function now(): DateTime {
|
|
} @@@expressionContext([DefaultValue, AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Generates a globally unique identifier based on the UUID specs.
|
|
*/
|
|
function uuid(version: Int?, format: String?): String {
|
|
} @@@expressionContext([DefaultValue])
|
|
|
|
/**
|
|
* Generates a globally unique identifier based on the CUID spec.
|
|
*/
|
|
function cuid(version: Int?, format: String?): String {
|
|
} @@@expressionContext([DefaultValue])
|
|
|
|
/**
|
|
* Generates an identifier based on the nanoid spec.
|
|
*/
|
|
function nanoid(length: Int?, format: String?): String {
|
|
} @@@expressionContext([DefaultValue])
|
|
|
|
/**
|
|
* Generates an identifier based on the ulid spec.
|
|
*/
|
|
function ulid(format: String?): String {
|
|
} @@@expressionContext([DefaultValue])
|
|
|
|
/**
|
|
* Creates a sequence of integers in the underlying database and assign the incremented
|
|
* values to the ID values of the created records based on the sequence.
|
|
*/
|
|
function autoincrement(): Int {
|
|
} @@@expressionContext([DefaultValue])
|
|
|
|
/**
|
|
* Represents default values that cannot be expressed in the Prisma schema (such as random()).
|
|
*/
|
|
function dbgenerated(expr: String?): Any {
|
|
} @@@expressionContext([DefaultValue])
|
|
|
|
/**
|
|
* Checks if the field value contains the search string. By default, the search is case-sensitive, and
|
|
* "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
|
|
* supported, otherwise it still falls back to "LIKE" and delivers whatever the database's
|
|
* behavior is.
|
|
*/
|
|
function contains(field: String, search: String, caseInSensitive: Boolean?): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
// /**
|
|
// * If the field value matches the search condition with [full-text-search](https://www.prisma.io/docs/concepts/components/prisma-client/full-text-search). Need to enable "fullTextSearch" preview feature to use.
|
|
// */
|
|
// function search(field: String, search: String): Boolean {
|
|
// } @@@expressionContext([AccessPolicy])
|
|
|
|
/**
|
|
* Checks the field value starts with the search string. By default, the search is case-sensitive, and
|
|
* "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
|
|
* supported, otherwise it still falls back to "LIKE" and delivers whatever the database's
|
|
* behavior is.
|
|
*/
|
|
function startsWith(field: String, search: String, caseInSensitive: Boolean?): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Checks if the field value ends with the search string. By default, the search is case-sensitive, and
|
|
* "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
|
|
* supported, otherwise it still falls back to "LIKE" and delivers whatever the database's
|
|
* behavior is.
|
|
*/
|
|
function endsWith(field: String, search: String, caseInSensitive: Boolean?): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Checks if the list field has the given search value
|
|
*/
|
|
function has(field: Any[], search: Any): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Checks if the list field has at least one element of the search list
|
|
*/
|
|
function hasSome(field: Any[], search: Any[]): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Checks if the list field has every element of the search list
|
|
*/
|
|
function hasEvery(field: Any[], search: Any[]): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Checks if the list field is empty
|
|
*/
|
|
function isEmpty(field: Any[]): Boolean {
|
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
|
|
/**
|
|
* Marks an attribute to be only applicable to certain field types.
|
|
*/
|
|
attribute @@@targetField(_ targetField: AttributeTargetField[])
|
|
|
|
/**
|
|
* Marks an attribute to be used for data validation.
|
|
*/
|
|
attribute @@@validation()
|
|
|
|
/**
|
|
* Indicates the expression context a function can be used.
|
|
*/
|
|
attribute @@@expressionContext(_ context: ExpressionContext[])
|
|
|
|
/**
|
|
* Indicates an attribute is directly supported by the Prisma schema.
|
|
*/
|
|
attribute @@@prisma()
|
|
|
|
/**
|
|
* Provides hint for auto-completion.
|
|
*/
|
|
attribute @@@completionHint(_ values: String[])
|
|
|
|
/**
|
|
* Indicates that the attribute can only be applied once to a declaration.
|
|
*/
|
|
attribute @@@once()
|
|
|
|
/**
|
|
* Defines a single-field ID on the model.
|
|
*
|
|
* @param map: The name of the underlying primary key constraint in the database.
|
|
* @param length: Allows you to specify a maximum length for the subpart of the value to be indexed.
|
|
* @param sort: Allows you to specify in what order the entries of the ID are stored in the database. The available options are Asc and Desc.
|
|
* @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true.
|
|
*/
|
|
attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
|
|
|
|
/**
|
|
* Defines a default value for a field.
|
|
* @param value: An expression (e.g. 5, true, now(), auth()).
|
|
*/
|
|
attribute @default(_ value: ContextType, map: String?) @@@prisma
|
|
|
|
/**
|
|
* Defines a unique constraint for this field.
|
|
*
|
|
* @param length: Allows you to specify a maximum length for the subpart of the value to be indexed.
|
|
* @param sort: Allows you to specify in what order the entries of the constraint are stored in the database. The available options are Asc and Desc.
|
|
* @param clustered: Boolean Defines whether the constraint is clustered or non-clustered. Defaults to false.
|
|
*/
|
|
attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
|
|
|
|
/**
|
|
* Defines a multi-field ID (composite ID) on the model.
|
|
*
|
|
* @param fields: A list of field names - for example, [firstname, lastname]
|
|
* @param name: The name that Prisma Client will expose for the argument covering all fields, e.g. fullName in fullName: { firstName: "First", lastName: "Last"}
|
|
* @param map: The name of the underlying primary key constraint in the database.
|
|
* @param length: Allows you to specify a maximum length for the subpart of the value to be indexed.
|
|
* @param sort: Allows you to specify in what order the entries of the ID are stored in the database. The available options are Asc and Desc.
|
|
* @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true.
|
|
*/
|
|
attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
|
|
|
|
/**
|
|
* Defines a compound unique constraint for the specified fields.
|
|
*
|
|
* @param fields: A list of field names - for example, [firstname, lastname]. Fields must be mandatory.
|
|
* @param name: The name of the unique combination of fields - defaults to fieldName1_fieldName2_fieldName3
|
|
* @param length: Allows you to specify a maximum length for the subpart of the value to be indexed.
|
|
* @param sort: Allows you to specify in what order the entries of the constraint are stored in the database. The available options are Asc and Desc.
|
|
* @param clustered: Boolean Defines whether the constraint is clustered or non-clustered. Defaults to false.
|
|
*/
|
|
attribute @@unique(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma
|
|
|
|
/**
|
|
* Index types
|
|
*/
|
|
enum IndexType {
|
|
BTree
|
|
Hash
|
|
Gist
|
|
Gin
|
|
SpGist
|
|
Brin
|
|
}
|
|
|
|
/**
|
|
* Operator class for index
|
|
*/
|
|
enum IndexOperatorClass {
|
|
// GIN
|
|
ArrayOps
|
|
JsonbOps
|
|
JsonbPathOps
|
|
|
|
// Gist
|
|
InetOps
|
|
|
|
// SpGist
|
|
TextOps
|
|
|
|
// BRIN
|
|
BitMinMaxOps
|
|
VarBitMinMaxOps
|
|
BpcharBloomOps
|
|
BpcharMinMaxOps
|
|
ByteaBloomOps
|
|
ByteaMinMaxOps
|
|
DateBloomOps
|
|
DateMinMaxOps
|
|
DateMinMaxMultiOps
|
|
Float4BloomOps
|
|
Float4MinMaxOps
|
|
Float4MinMaxMultiOps
|
|
Float8BloomOps
|
|
Float8MinMaxOps
|
|
Float8MinMaxMultiOps
|
|
InetInclusionOps
|
|
InetBloomOps
|
|
InetMinMaxOps
|
|
InetMinMaxMultiOps
|
|
Int2BloomOps
|
|
Int2MinMaxOps
|
|
Int2MinMaxMultiOps
|
|
Int4BloomOps
|
|
Int4MinMaxOps
|
|
Int4MinMaxMultiOps
|
|
Int8BloomOps
|
|
Int8MinMaxOps
|
|
Int8MinMaxMultiOps
|
|
NumericBloomOps
|
|
NumericMinMaxOps
|
|
NumericMinMaxMultiOps
|
|
OidBloomOps
|
|
OidMinMaxOps
|
|
OidMinMaxMultiOps
|
|
TextBloomOps
|
|
TextMinMaxOps
|
|
TextMinMaxMultiOps
|
|
TimestampBloomOps
|
|
TimestampMinMaxOps
|
|
TimestampMinMaxMultiOps
|
|
TimestampTzBloomOps
|
|
TimestampTzMinMaxOps
|
|
TimestampTzMinMaxMultiOps
|
|
TimeBloomOps
|
|
TimeMinMaxOps
|
|
TimeMinMaxMultiOps
|
|
TimeTzBloomOps
|
|
TimeTzMinMaxOps
|
|
TimeTzMinMaxMultiOps
|
|
UuidBloomOps
|
|
UuidMinMaxOps
|
|
UuidMinMaxMultiOps
|
|
}
|
|
|
|
/**
|
|
* Index sort order
|
|
*/
|
|
enum SortOrder {
|
|
Asc
|
|
Desc
|
|
}
|
|
|
|
/**
|
|
* Defines an index in the database.
|
|
*
|
|
* @params fields: A list of field names - for example, [firstname, lastname]
|
|
* @params name: The name that Prisma Client will expose for the argument covering all fields, e.g. fullName in fullName: { firstName: "First", lastName: "Last"}
|
|
* @params map: The name of the index in the underlying database (Prisma generates an index name that respects identifier length limits if you do not specify a name. Prisma uses the following naming convention: tablename.field1_field2_field3_unique)
|
|
* @params length: Allows you to specify a maximum length for the subpart of the value to be indexed.
|
|
* @params sort: Allows you to specify in what order the entries of the index or constraint are stored in the database. The available options are asc and desc.
|
|
* @params clustered: Defines whether the index is clustered or non-clustered. Defaults to false.
|
|
* @params type: Allows you to specify an index access method. Defaults to BTree.
|
|
*/
|
|
attribute @@index(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?, type: IndexType?) @@@prisma
|
|
|
|
/**
|
|
* Defines meta information about the relation.
|
|
*
|
|
* @param name: Sometimes (e.g. to disambiguate a relation) Defines the name of the relationship. In an m-n-relation, it also determines the name of the underlying relation table.
|
|
* @param fields: A list of fields of the current model
|
|
* @param references: A list of fields of the model on the other side of the relation
|
|
* @param map: Defines a custom name for the foreign key in the database.
|
|
* @param onUpdate: Defines the referential action to perform when a referenced entry in the referenced model is being updated.
|
|
* @param onDelete: Defines the referential action to perform when a referenced entry in the referenced model is being deleted.
|
|
*/
|
|
attribute @relation(_ name: String?, fields: FieldReference[]?, references: TransitiveFieldReference[]?, onDelete: ReferentialAction?, onUpdate: ReferentialAction?, map: String?) @@@prisma
|
|
|
|
/**
|
|
* Maps a field name or enum value from the schema to a column with a different name in the database.
|
|
*
|
|
* @param name: The database column name.
|
|
*/
|
|
attribute @map(_ name: String) @@@prisma
|
|
|
|
/**
|
|
* Maps the schema model name to a table with a different name, or an enum name to a different underlying enum in the database.
|
|
*
|
|
* @param name: The database column name.
|
|
*/
|
|
attribute @@map(_ name: String) @@@prisma
|
|
|
|
/**
|
|
* Exclude a field from the ORM Client (for example, a field that you do not want Prisma users to update).
|
|
* The field is still recognized by database schema migrations.
|
|
*/
|
|
attribute @ignore() @@@prisma
|
|
|
|
/**
|
|
* Exclude a model from the ORM Client (for example, a model that you do not want Prisma users to update).
|
|
* The model is still recognized by database schema migrations.
|
|
*/
|
|
attribute @@ignore() @@@prisma
|
|
|
|
/**
|
|
* Indicates that the field should be omitted by default when read with an ORM client. The omission can be
|
|
* overridden in options passed to create `ZenStackClient`, or at query time by explicitly passing in an
|
|
* `omit` clause. The attribute is only effective for ORM query APIs, not for query-builder APIs.
|
|
*/
|
|
attribute @omit()
|
|
|
|
/**
|
|
* Marks a `String` field as fuzzy-searchable. Fields with this attribute can be used with the
|
|
* `fuzzy` filter operator and the `_fuzzyRelevance` orderBy. Fuzzy search is currently
|
|
* supported only on the `postgresql` provider (requires `pg_trgm` extension).
|
|
*/
|
|
attribute @fuzzy() @@@targetField([StringField]) @@@once
|
|
|
|
/**
|
|
* Marks a `String` field as full-text-searchable. Fields with this attribute can be used with the
|
|
* `fts` filter operator and the `_ftsRelevance` orderBy. Full-text search is currently
|
|
* supported only on the `postgresql` provider (uses `to_tsvector` / `to_tsquery` / `ts_rank`).
|
|
*/
|
|
attribute @fullText() @@@targetField([StringField]) @@@once
|
|
|
|
/**
|
|
* Automatically stores the time when a record was last updated.
|
|
*
|
|
* @param ignore: A list of field names that are not considered when the ORM client is determining whether any
|
|
* updates have been made to a record. An update that only contains ignored fields does not change the
|
|
* timestamp.
|
|
*/
|
|
attribute @updatedAt(ignore: FieldReference[]?) @@@targetField([DateTimeField]) @@@prisma
|
|
|
|
/**
|
|
* Add full text index (MySQL only).
|
|
*/
|
|
attribute @@fulltext(_ fields: FieldReference[], map: String?) @@@prisma
|
|
|
|
|
|
// String type modifiers
|
|
|
|
attribute @db.Text() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.Char(_ x: Int?) @@@targetField([StringField]) @@@prisma
|
|
attribute @db.VarChar(_ x: Any?) @@@targetField([StringField]) @@@prisma
|
|
attribute @db.Bit(_ x: Int?) @@@targetField([StringField, BooleanField, BytesField]) @@@prisma
|
|
attribute @db.VarBit(_ x: Int?) @@@targetField([StringField]) @@@prisma
|
|
attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.Xml() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.Inet() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.Citext() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
|
|
attribute @db.LongText() @@@targetField([StringField]) @@@prisma
|
|
|
|
// Boolean type modifiers
|
|
|
|
attribute @db.Boolean() @@@targetField([BooleanField]) @@@prisma
|
|
|
|
// Int type modifiers
|
|
|
|
attribute @db.Int() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.Integer() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.Oid() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.UnsignedInt() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.UnsignedSmallInt() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.MediumInt() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.UnsignedMediumInt() @@@targetField([IntField]) @@@prisma
|
|
attribute @db.TinyInt(_ length: Int?) @@@targetField([IntField]) @@@prisma
|
|
attribute @db.UnsignedTinyInt(_ length: Int?) @@@targetField([IntField]) @@@prisma
|
|
attribute @db.Year() @@@targetField([IntField]) @@@prisma
|
|
|
|
// BigInt type modifiers
|
|
|
|
attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
|
|
attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma
|
|
|
|
// Float/Decimal type modifiers
|
|
attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
attribute @db.Float() @@@targetField([FloatField]) @@@prisma
|
|
attribute @db.Double() @@@targetField([FloatField]) @@@prisma
|
|
|
|
// DateTime type modifiers
|
|
|
|
attribute @db.Timestamp(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
|
|
attribute @db.Time(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
attribute @db.Timetz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
attribute @db.DateTime(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
|
|
|
|
// Json type modifiers
|
|
|
|
attribute @db.Json() @@@targetField([JsonField]) @@@prisma
|
|
attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
|
|
|
|
// Bytes type modifiers
|
|
|
|
attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
|
|
attribute @db.LongBlob() @@@targetField([BytesField]) @@@prisma
|
|
attribute @db.Binary(_ n: Int?) @@@targetField([BytesField]) @@@prisma
|
|
attribute @db.VarBinary(_ n: Int?) @@@targetField([BytesField]) @@@prisma
|
|
attribute @db.TinyBlob() @@@targetField([BytesField]) @@@prisma
|
|
attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
|
|
attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
|
|
|
|
/**
|
|
* Specifies the schema to use in a multi-schema PostgreSQL database.
|
|
*
|
|
* @param map: The name of the database schema.
|
|
*/
|
|
attribute @@schema(_ map: String) @@@prisma
|
|
|
|
//////////////////////////////////////////////
|
|
// Begin validation attributes and functions
|
|
//////////////////////////////////////////////
|
|
|
|
/**
|
|
* Validates length of a string field or list field.
|
|
*/
|
|
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value starts with the given text.
|
|
*/
|
|
attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value ends with the given text.
|
|
*/
|
|
attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value contains the given text.
|
|
*/
|
|
attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value matches a regex.
|
|
*/
|
|
attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value is a valid email address.
|
|
*/
|
|
attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value is a valid ISO datetime.
|
|
*/
|
|
attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value is a valid url.
|
|
*/
|
|
attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a string field value is a valid E.164 phone number.
|
|
*/
|
|
attribute @phone(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Trims whitespaces from the start and end of the string.
|
|
*/
|
|
attribute @trim() @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Transform entire string toLowerCase.
|
|
*/
|
|
attribute @lower() @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Transform entire string toUpperCase.
|
|
*/
|
|
attribute @upper() @@@targetField([StringField]) @@@validation
|
|
|
|
/**
|
|
* Validates a number field is greater than the given value.
|
|
*/
|
|
attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
|
|
/**
|
|
* Validates a number field is greater than or equal to the given value.
|
|
*/
|
|
attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
|
|
/**
|
|
* Validates a number field is less than the given value.
|
|
*/
|
|
attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
|
|
/**
|
|
* Validates a number field is less than or equal to the given value.
|
|
*/
|
|
attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
|
|
/**
|
|
* Validates the entity with a complex condition.
|
|
*/
|
|
attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
|
|
|
|
/**
|
|
* Returns the length of a string field or a list field.
|
|
*/
|
|
function length(field: Any): Int {
|
|
} @@@expressionContext([ValidationRule])
|
|
|
|
|
|
/**
|
|
* Validates a string field value matches a regex pattern.
|
|
*/
|
|
function regex(field: String, pattern: String): Boolean {
|
|
} @@@expressionContext([ValidationRule])
|
|
|
|
/**
|
|
* Validates a string field value is a valid email address.
|
|
*/
|
|
function isEmail(field: String): Boolean {
|
|
} @@@expressionContext([ValidationRule])
|
|
|
|
/**
|
|
* Validates a string field value is a valid ISO datetime.
|
|
*/
|
|
function isDateTime(field: String): Boolean {
|
|
} @@@expressionContext([ValidationRule])
|
|
|
|
/**
|
|
* Validates a string field value is a valid url.
|
|
*/
|
|
function isUrl(field: String): Boolean {
|
|
} @@@expressionContext([ValidationRule])
|
|
|
|
/**
|
|
* Validates a string field value is a valid E.164 phone number.
|
|
*/
|
|
function isPhone(field: String): Boolean {
|
|
} @@@expressionContext([ValidationRule])
|
|
|
|
//////////////////////////////////////////////
|
|
// End validation attributes and functions
|
|
//////////////////////////////////////////////
|
|
|
|
/**
|
|
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
*/
|
|
attribute @prisma.passthrough(_ text: String)
|
|
|
|
/**
|
|
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
*/
|
|
attribute @@prisma.passthrough(_ text: String)
|
|
|
|
/**
|
|
* Marks a model to be a delegate. Used for implementing polymorphism.
|
|
*/
|
|
attribute @@delegate(_ discriminator: FieldReference)
|
|
|
|
/**
|
|
* Maps a delegate sub-model to a specific discriminator value. If not set the sub-model name is used as the discriminator value by default.
|
|
*
|
|
* @param value: A string literal or enum member used as the discriminator.
|
|
*/
|
|
attribute @@delegateMap(_ value: Any)
|
|
|
|
/**
|
|
* Used for specifying operator classes for GIN index.
|
|
*/
|
|
function raw(value: String): Any {
|
|
} @@@expressionContext([Index])
|
|
|
|
/**
|
|
* Marks a field to be strong-typed JSON.
|
|
*/
|
|
attribute @json() @@@targetField([TypeDefField])
|
|
|
|
/**
|
|
* Marks a field to be computed.
|
|
*/
|
|
attribute @computed()
|
|
|
|
/**
|
|
* Gets the current login user.
|
|
*/
|
|
function auth(): Any {
|
|
} @@@expressionContext([DefaultValue, AccessPolicy])
|
|
|
|
/**
|
|
* Used to specify the model for resolving `auth()` function call in access policies. A Zmodel
|
|
* can have at most one model with this attribute. By default, the model named "User" is used.
|
|
*/
|
|
attribute @@auth()
|
|
|
|
/**
|
|
* Attaches arbitrary metadata to a model or type def.
|
|
*/
|
|
attribute @@meta(_ name: String, _ value: Any)
|
|
|
|
/**
|
|
* Attaches arbitrary metadata to a field.
|
|
*/
|
|
attribute @meta(_ name: String, _ value: Any)
|
|
|
|
/**
|
|
* Marks an attribute as deprecated.
|
|
*/
|
|
attribute @@@deprecated(_ message: String)
|