@zenstackhq/language 3.0.0-alpha.9 → 3.0.0-beta.10

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.
package/res/stdlib.zmodel CHANGED
@@ -48,6 +48,7 @@ enum AttributeTargetField {
48
48
  BytesField
49
49
  ModelField
50
50
  TypeDefField
51
+ ListField
51
52
  }
52
53
 
53
54
  /**
@@ -117,14 +118,10 @@ function dbgenerated(expr: String?): Any {
117
118
  } @@@expressionContext([DefaultValue])
118
119
 
119
120
  /**
120
- * Gets entities value before an update. Only valid when used in a "update" policy rule.
121
- */
122
- function future(): Any {
123
- } @@@expressionContext([AccessPolicy])
124
-
125
- /**
126
- * If the field value contains the search string. By default, the search is case-sensitive,
127
- * but you can override the behavior with the "caseInSensitive" argument.
121
+ * Checks if the field value contains the search string. By default, the search is case-sensitive, and
122
+ * "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
123
+ * supported, otherwise it still falls back to "LIKE" and delivers whatever the database's
124
+ * behavior is.
128
125
  */
129
126
  function contains(field: String, search: String, caseInSensitive: Boolean?): Boolean {
130
127
  } @@@expressionContext([AccessPolicy, ValidationRule])
@@ -136,15 +133,21 @@ function search(field: String, search: String): Boolean {
136
133
  } @@@expressionContext([AccessPolicy])
137
134
 
138
135
  /**
139
- * If the field value starts with the search string
136
+ * Checks the field value starts with the search string. By default, the search is case-sensitive, and
137
+ * "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
138
+ * supported, otherwise it still falls back to "LIKE" and delivers whatever the database's
139
+ * behavior is.
140
140
  */
141
- function startsWith(field: String, search: String): Boolean {
141
+ function startsWith(field: String, search: String, caseInSensitive: Boolean?): Boolean {
142
142
  } @@@expressionContext([AccessPolicy, ValidationRule])
143
143
 
144
144
  /**
145
- * If the field value ends with the search string
145
+ * Checks if the field value ends with the search string. By default, the search is case-sensitive, and
146
+ * "LIKE" operator is used to match. If `caseInSensitive` is true, "ILIKE" operator is used if
147
+ * supported, otherwise it still falls back to "LIKE" and delivers whatever the database's
148
+ * behavior is.
146
149
  */
147
- function endsWith(field: String, search: String): Boolean {
150
+ function endsWith(field: String, search: String, caseInSensitive: Boolean?): Boolean {
148
151
  } @@@expressionContext([AccessPolicy, ValidationRule])
149
152
 
150
153
  /**
@@ -171,39 +174,11 @@ function hasSome(field: Any[], search: Any[]): Boolean {
171
174
  function isEmpty(field: Any[]): Boolean {
172
175
  } @@@expressionContext([AccessPolicy, ValidationRule])
173
176
 
174
- /**
175
- * The name of the model for which the policy rule is defined. If the rule is
176
- * inherited to a sub model, this function returns the name of the sub model.
177
- *
178
- * @param optional parameter to control the casing of the returned value. Valid
179
- * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
180
- * to "original".
181
- */
182
- function currentModel(casing: String?): String {
183
- } @@@expressionContext([AccessPolicy])
184
-
185
- /**
186
- * The operation for which the policy rule is defined for. Note that a rule with
187
- * "all" operation is expanded to "create", "read", "update", and "delete" rules,
188
- * and the function returns corresponding value for each expanded version.
189
- *
190
- * @param optional parameter to control the casing of the returned value. Valid
191
- * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
192
- * to "original".
193
- */
194
- function currentOperation(casing: String?): String {
195
- } @@@expressionContext([AccessPolicy])
196
-
197
177
  /**
198
178
  * Marks an attribute to be only applicable to certain field types.
199
179
  */
200
180
  attribute @@@targetField(_ targetField: AttributeTargetField[])
201
181
 
202
- /**
203
- * Marks an attribute to be applicable to type defs and fields.
204
- */
205
- attribute @@@supportTypeDef()
206
-
207
182
  /**
208
183
  * Marks an attribute to be used for data validation.
209
184
  */
@@ -224,6 +199,11 @@ attribute @@@prisma()
224
199
  */
225
200
  attribute @@@completionHint(_ values: String[])
226
201
 
202
+ /**
203
+ * Indicates that the attribute can only be applied once to a declaration.
204
+ */
205
+ attribute @@@once()
206
+
227
207
  /**
228
208
  * Defines a single-field ID on the model.
229
209
  *
@@ -232,13 +212,13 @@ attribute @@@completionHint(_ values: String[])
232
212
  * @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.
233
213
  * @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true.
234
214
  */
235
- attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@supportTypeDef
215
+ attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
236
216
 
237
217
  /**
238
218
  * Defines a default value for a field.
239
219
  * @param value: An expression (e.g. 5, true, now(), auth()).
240
220
  */
241
- attribute @default(_ value: ContextType, map: String?) @@@prisma @@@supportTypeDef
221
+ attribute @default(_ value: ContextType, map: String?) @@@prisma
242
222
 
243
223
  /**
244
224
  * Defines a unique constraint for this field.
@@ -247,7 +227,7 @@ attribute @default(_ value: ContextType, map: String?) @@@prisma @@@supportTypeD
247
227
  * @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.
248
228
  * @param clustered: Boolean Defines whether the constraint is clustered or non-clustered. Defaults to false.
249
229
  */
250
- attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma
230
+ attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
251
231
 
252
232
  /**
253
233
  * Defines a multi-field ID (composite ID) on the model.
@@ -259,7 +239,7 @@ attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boole
259
239
  * @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.
260
240
  * @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true.
261
241
  */
262
- attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma
242
+ attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
263
243
 
264
244
  /**
265
245
  * Defines a compound unique constraint for the specified fields.
@@ -424,25 +404,12 @@ attribute @@fulltext(_ fields: FieldReference[], map: String?) @@@prisma
424
404
 
425
405
  // String type modifiers
426
406
 
427
- enum MSSQLServerTypes {
428
- Max
429
- }
430
-
431
- attribute @db.String(_ x: Int?) @@@targetField([StringField]) @@@prisma
432
407
  attribute @db.Text() @@@targetField([StringField]) @@@prisma
433
- attribute @db.NText() @@@targetField([StringField]) @@@prisma
434
408
  attribute @db.Char(_ x: Int?) @@@targetField([StringField]) @@@prisma
435
- attribute @db.NChar(_ x: Int?) @@@targetField([StringField]) @@@prisma
436
409
  attribute @db.VarChar(_ x: Any?) @@@targetField([StringField]) @@@prisma
437
- attribute @db.NVarChar(_ x: Any?) @@@targetField([StringField]) @@@prisma
438
- attribute @db.CatalogSingleChar() @@@targetField([StringField]) @@@prisma
439
- attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
440
- attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
441
- attribute @db.LongText() @@@targetField([StringField]) @@@prisma
442
410
  attribute @db.Bit(_ x: Int?) @@@targetField([StringField, BooleanField, BytesField]) @@@prisma
443
411
  attribute @db.VarBit(_ x: Int?) @@@targetField([StringField]) @@@prisma
444
412
  attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
445
- attribute @db.UniqueIdentifier() @@@targetField([StringField]) @@@prisma
446
413
  attribute @db.Xml() @@@targetField([StringField]) @@@prisma
447
414
  attribute @db.Inet() @@@targetField([StringField]) @@@prisma
448
415
  attribute @db.Citext() @@@targetField([StringField]) @@@prisma
@@ -450,8 +417,6 @@ attribute @db.Citext() @@@targetField([StringField]) @@@prisma
450
417
  // Boolean type modifiers
451
418
 
452
419
  attribute @db.Boolean() @@@targetField([BooleanField]) @@@prisma
453
- attribute @db.TinyInt(_ x: Int?) @@@targetField([BooleanField, IntField]) @@@prisma
454
- attribute @db.Bool() @@@targetField([BooleanField]) @@@prisma
455
420
 
456
421
  // Int type modifiers
457
422
 
@@ -459,38 +424,19 @@ attribute @db.Int() @@@targetField([IntField]) @@@prisma
459
424
  attribute @db.Integer() @@@targetField([IntField]) @@@prisma
460
425
  attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
461
426
  attribute @db.Oid() @@@targetField([IntField]) @@@prisma
462
- attribute @db.UnsignedInt() @@@targetField([IntField]) @@@prisma
463
- attribute @db.UnsignedSmallInt() @@@targetField([IntField]) @@@prisma
464
- attribute @db.MediumInt() @@@targetField([IntField]) @@@prisma
465
- attribute @db.UnsignedMediumInt() @@@targetField([IntField]) @@@prisma
466
- attribute @db.UnsignedTinyInt() @@@targetField([IntField]) @@@prisma
467
- attribute @db.Year() @@@targetField([IntField]) @@@prisma
468
- attribute @db.Int4() @@@targetField([IntField]) @@@prisma
469
- attribute @db.Int2() @@@targetField([IntField]) @@@prisma
470
427
 
471
428
  // BigInt type modifiers
472
429
 
473
430
  attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
474
- attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma
475
- attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
476
431
 
477
432
  // Float/Decimal type modifiers
478
433
  attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
479
434
  attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
480
- attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
481
435
  attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
482
- attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
483
436
  attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
484
- attribute @db.SmallMoney() @@@targetField([FloatField, DecimalField]) @@@prisma
485
- attribute @db.Float8() @@@targetField([FloatField, DecimalField]) @@@prisma
486
- attribute @db.Float4() @@@targetField([FloatField, DecimalField]) @@@prisma
487
437
 
488
438
  // DateTime type modifiers
489
439
 
490
- attribute @db.DateTime(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
491
- attribute @db.DateTime2() @@@targetField([DateTimeField]) @@@prisma
492
- attribute @db.SmallDateTime() @@@targetField([DateTimeField]) @@@prisma
493
- attribute @db.DateTimeOffset() @@@targetField([DateTimeField]) @@@prisma
494
440
  attribute @db.Timestamp(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
495
441
  attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
496
442
  attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
@@ -504,138 +450,103 @@ attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
504
450
 
505
451
  // Bytes type modifiers
506
452
 
507
- attribute @db.Bytes() @@@targetField([BytesField]) @@@prisma
508
453
  attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
509
- attribute @db.LongBlob() @@@targetField([BytesField]) @@@prisma
510
- attribute @db.Binary() @@@targetField([BytesField]) @@@prisma
511
- attribute @db.VarBinary(_ x: Int?) @@@targetField([BytesField]) @@@prisma
512
- attribute @db.TinyBlob() @@@targetField([BytesField]) @@@prisma
513
- attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
514
- attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
515
- attribute @db.Image() @@@targetField([BytesField]) @@@prisma
516
454
 
517
- /**
518
- * Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
519
- *
520
- * @param: The name of the database schema.
521
- */
522
- attribute @@schema(_ name: String) @@@prisma
523
-
524
- /**
525
- * Indicates that the field is a password field and needs to be hashed before persistence.
526
- *
527
- * ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
528
- * to configure the cost of hashing, or use `salt` parameter to provide an explicit salt.
529
- * By default, salt length of 12 is used.
530
- *
531
- * @see https://www.npmjs.com/package/bcryptjs for details
532
- *
533
- * @param saltLength: length of salt to use (cost factor for the hash function)
534
- * @param salt: salt to use (a pregenerated valid salt)
535
- */
536
- attribute @password(saltLength: Int?, salt: String?) @@@targetField([StringField])
537
-
538
-
539
- /**
540
- * Indicates that the field is encrypted when storing in the DB and should be decrypted when read
541
- *
542
- * ZenStack uses the Web Crypto API to encrypt and decrypt the field.
543
- */
544
- attribute @encrypted() @@@targetField([StringField])
545
-
546
- /**
547
- * Indicates that the field should be omitted when read from the generated services.
548
- */
549
- attribute @omit()
455
+ // /**
456
+ // * Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
457
+ // *
458
+ // * @param: The name of the database schema.
459
+ // */
460
+ // attribute @@schema(_ name: String) @@@prisma
550
461
 
551
462
  //////////////////////////////////////////////
552
463
  // Begin validation attributes and functions
553
464
  //////////////////////////////////////////////
554
465
 
555
466
  /**
556
- * Validates length of a string field.
467
+ * Validates length of a string field or list field.
557
468
  */
558
- attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
469
+ attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation
559
470
 
560
471
  /**
561
472
  * Validates a string field value starts with the given text.
562
473
  */
563
- attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
474
+ attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
564
475
 
565
476
  /**
566
477
  * Validates a string field value ends with the given text.
567
478
  */
568
- attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
479
+ attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
569
480
 
570
481
  /**
571
482
  * Validates a string field value contains the given text.
572
483
  */
573
- attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
484
+ attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
574
485
 
575
486
  /**
576
487
  * Validates a string field value matches a regex.
577
488
  */
578
- attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
489
+ attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation
579
490
 
580
491
  /**
581
492
  * Validates a string field value is a valid email address.
582
493
  */
583
- attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
494
+ attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation
584
495
 
585
496
  /**
586
497
  * Validates a string field value is a valid ISO datetime.
587
498
  */
588
- attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
499
+ attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation
589
500
 
590
501
  /**
591
502
  * Validates a string field value is a valid url.
592
503
  */
593
- attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
504
+ attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation
594
505
 
595
506
  /**
596
507
  * Trims whitespaces from the start and end of the string.
597
508
  */
598
- attribute @trim() @@@targetField([StringField]) @@@validation @@@supportTypeDef
509
+ attribute @trim() @@@targetField([StringField]) @@@validation
599
510
 
600
511
  /**
601
512
  * Transform entire string toLowerCase.
602
513
  */
603
- attribute @lower() @@@targetField([StringField]) @@@validation @@@supportTypeDef
514
+ attribute @lower() @@@targetField([StringField]) @@@validation
604
515
 
605
516
  /**
606
517
  * Transform entire string toUpperCase.
607
518
  */
608
- attribute @upper() @@@targetField([StringField]) @@@validation @@@supportTypeDef
519
+ attribute @upper() @@@targetField([StringField]) @@@validation
609
520
 
610
521
  /**
611
522
  * Validates a number field is greater than the given value.
612
523
  */
613
- attribute @gt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
524
+ attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
614
525
 
615
526
  /**
616
527
  * Validates a number field is greater than or equal to the given value.
617
528
  */
618
- attribute @gte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
529
+ attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
619
530
 
620
531
  /**
621
532
  * Validates a number field is less than the given value.
622
533
  */
623
- attribute @lt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
534
+ attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
624
535
 
625
536
  /**
626
537
  * Validates a number field is less than or equal to the given value.
627
538
  */
628
- attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
539
+ attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
629
540
 
630
541
  /**
631
542
  * Validates the entity with a complex condition.
632
543
  */
633
- attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation @@@supportTypeDef
544
+ attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
634
545
 
635
546
  /**
636
- * Validates length of a string field.
547
+ * Returns the length of a string field or a list field.
637
548
  */
638
- function length(field: String, min: Int, max: Int?): Boolean {
549
+ function length(field: Any): Int {
639
550
  } @@@expressionContext([ValidationRule])
640
551
 
641
552
 
@@ -648,31 +559,21 @@ function regex(field: String, regex: String): Boolean {
648
559
  /**
649
560
  * Validates a string field value is a valid email address.
650
561
  */
651
- function email(field: String): Boolean {
562
+ function isEmail(field: String): Boolean {
652
563
  } @@@expressionContext([ValidationRule])
653
564
 
654
565
  /**
655
566
  * Validates a string field value is a valid ISO datetime.
656
567
  */
657
- function datetime(field: String): Boolean {
568
+ function isDateTime(field: String): Boolean {
658
569
  } @@@expressionContext([ValidationRule])
659
570
 
660
571
  /**
661
572
  * Validates a string field value is a valid url.
662
573
  */
663
- function url(field: String): Boolean {
574
+ function isUrl(field: String): Boolean {
664
575
  } @@@expressionContext([ValidationRule])
665
576
 
666
- /**
667
- * Checks if the current user can perform the given operation on the given field.
668
- *
669
- * @param field: The field to check access for
670
- * @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
671
- * it defaults the operation of the containing policy rule.
672
- */
673
- function check(field: Any, operation: String?): Boolean {
674
- } @@@expressionContext([AccessPolicy])
675
-
676
577
  //////////////////////////////////////////////
677
578
  // End validation attributes and functions
678
579
  //////////////////////////////////////////////
@@ -718,4 +619,19 @@ function auth(): Any {
718
619
  * Used to specify the model for resolving `auth()` function call in access policies. A Zmodel
719
620
  * can have at most one model with this attribute. By default, the model named "User" is used.
720
621
  */
721
- attribute @@auth() @@@supportTypeDef
622
+ attribute @@auth()
623
+
624
+ /**
625
+ * Attaches arbitrary metadata to a model or type def.
626
+ */
627
+ attribute @@meta(_ name: String, _ value: Any)
628
+
629
+ /**
630
+ * Attaches arbitrary metadata to a field.
631
+ */
632
+ attribute @meta(_ name: String, _ value: Any)
633
+
634
+ /**
635
+ * Marks an attribute as deprecated.
636
+ */
637
+ attribute @@@deprecated(_ message: String)