@zenstackhq/language 3.0.0-alpha.3 → 3.0.0-alpha.31

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
@@ -25,7 +25,7 @@ enum ReferentialAction {
25
25
  * Used with "onUpdate": when updating the identifier of a referenced object, the scalar fields of the referencing objects will be set to NULL.
26
26
  */
27
27
  SetNull
28
-
28
+
29
29
  /**
30
30
  * Used with "onDelete": the scalar field of the referencing object will be set to the fields default value.
31
31
  * Used with "onUpdate": the scalar field of the referencing object will be set to the fields default value.
@@ -104,7 +104,7 @@ function ulid(): String {
104
104
  } @@@expressionContext([DefaultValue])
105
105
 
106
106
  /**
107
- * Creates a sequence of integers in the underlying database and assign the incremented
107
+ * Creates a sequence of integers in the underlying database and assign the incremented
108
108
  * values to the ID values of the created records based on the sequence.
109
109
  */
110
110
  function autoincrement(): Int {
@@ -174,9 +174,9 @@ function isEmpty(field: Any[]): Boolean {
174
174
  /**
175
175
  * The name of the model for which the policy rule is defined. If the rule is
176
176
  * inherited to a sub model, this function returns the name of the sub model.
177
- *
177
+ *
178
178
  * @param optional parameter to control the casing of the returned value. Valid
179
- * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
179
+ * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
180
180
  * to "original".
181
181
  */
182
182
  function currentModel(casing: String?): String {
@@ -186,7 +186,7 @@ function currentModel(casing: String?): String {
186
186
  * The operation for which the policy rule is defined for. Note that a rule with
187
187
  * "all" operation is expanded to "create", "read", "update", and "delete" rules,
188
188
  * and the function returns corresponding value for each expanded version.
189
- *
189
+ *
190
190
  * @param optional parameter to control the casing of the returned value. Valid
191
191
  * values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
192
192
  * to "original".
@@ -199,11 +199,6 @@ function currentOperation(casing: String?): String {
199
199
  */
200
200
  attribute @@@targetField(_ targetField: AttributeTargetField[])
201
201
 
202
- /**
203
- * Marks an attribute to be applicable to type defs and fields.
204
- */
205
- attribute @@@supportTypeDef()
206
-
207
202
  /**
208
203
  * Marks an attribute to be used for data validation.
209
204
  */
@@ -224,6 +219,11 @@ attribute @@@prisma()
224
219
  */
225
220
  attribute @@@completionHint(_ values: String[])
226
221
 
222
+ /**
223
+ * Indicates that the attribute can only be applied once to a declaration.
224
+ */
225
+ attribute @@@once()
226
+
227
227
  /**
228
228
  * Defines a single-field ID on the model.
229
229
  *
@@ -232,13 +232,13 @@ attribute @@@completionHint(_ values: String[])
232
232
  * @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
233
  * @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true.
234
234
  */
235
- attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@supportTypeDef
235
+ attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
236
236
 
237
237
  /**
238
238
  * Defines a default value for a field.
239
239
  * @param value: An expression (e.g. 5, true, now(), auth()).
240
240
  */
241
- attribute @default(_ value: ContextType, map: String?) @@@prisma @@@supportTypeDef
241
+ attribute @default(_ value: ContextType, map: String?) @@@prisma
242
242
 
243
243
  /**
244
244
  * Defines a unique constraint for this field.
@@ -247,7 +247,7 @@ attribute @default(_ value: ContextType, map: String?) @@@prisma @@@supportTypeD
247
247
  * @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
248
  * @param clustered: Boolean Defines whether the constraint is clustered or non-clustered. Defaults to false.
249
249
  */
250
- attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma
250
+ attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
251
251
 
252
252
  /**
253
253
  * Defines a multi-field ID (composite ID) on the model.
@@ -259,7 +259,7 @@ attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boole
259
259
  * @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
260
  * @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true.
261
261
  */
262
- attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma
262
+ attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma @@@once
263
263
 
264
264
  /**
265
265
  * Defines a compound unique constraint for the specified fields.
@@ -424,25 +424,12 @@ attribute @@fulltext(_ fields: FieldReference[], map: String?) @@@prisma
424
424
 
425
425
  // String type modifiers
426
426
 
427
- enum MSSQLServerTypes {
428
- Max
429
- }
430
-
431
- attribute @db.String(_ x: Int?) @@@targetField([StringField]) @@@prisma
432
427
  attribute @db.Text() @@@targetField([StringField]) @@@prisma
433
- attribute @db.NText() @@@targetField([StringField]) @@@prisma
434
428
  attribute @db.Char(_ x: Int?) @@@targetField([StringField]) @@@prisma
435
- attribute @db.NChar(_ x: Int?) @@@targetField([StringField]) @@@prisma
436
429
  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
430
  attribute @db.Bit(_ x: Int?) @@@targetField([StringField, BooleanField, BytesField]) @@@prisma
443
431
  attribute @db.VarBit(_ x: Int?) @@@targetField([StringField]) @@@prisma
444
432
  attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
445
- attribute @db.UniqueIdentifier() @@@targetField([StringField]) @@@prisma
446
433
  attribute @db.Xml() @@@targetField([StringField]) @@@prisma
447
434
  attribute @db.Inet() @@@targetField([StringField]) @@@prisma
448
435
  attribute @db.Citext() @@@targetField([StringField]) @@@prisma
@@ -450,8 +437,6 @@ attribute @db.Citext() @@@targetField([StringField]) @@@prisma
450
437
  // Boolean type modifiers
451
438
 
452
439
  attribute @db.Boolean() @@@targetField([BooleanField]) @@@prisma
453
- attribute @db.TinyInt(_ x: Int?) @@@targetField([BooleanField, IntField]) @@@prisma
454
- attribute @db.Bool() @@@targetField([BooleanField]) @@@prisma
455
440
 
456
441
  // Int type modifiers
457
442
 
@@ -459,38 +444,19 @@ attribute @db.Int() @@@targetField([IntField]) @@@prisma
459
444
  attribute @db.Integer() @@@targetField([IntField]) @@@prisma
460
445
  attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
461
446
  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
447
 
471
448
  // BigInt type modifiers
472
449
 
473
450
  attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
474
- attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma
475
- attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
476
451
 
477
452
  // Float/Decimal type modifiers
478
453
  attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
479
454
  attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
480
- attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
481
455
  attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
482
- attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
483
456
  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
457
 
488
458
  // DateTime type modifiers
489
459
 
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
460
  attribute @db.Timestamp(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
495
461
  attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
496
462
  attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
@@ -504,49 +470,14 @@ attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
504
470
 
505
471
  // Bytes type modifiers
506
472
 
507
- attribute @db.Bytes() @@@targetField([BytesField]) @@@prisma
508
473
  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
-
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
474
 
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()
475
+ // /**
476
+ // * Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
477
+ // *
478
+ // * @param: The name of the database schema.
479
+ // */
480
+ // attribute @@schema(_ name: String) @@@prisma
550
481
 
551
482
  //////////////////////////////////////////////
552
483
  // Begin validation attributes and functions
@@ -555,82 +486,82 @@ attribute @omit()
555
486
  /**
556
487
  * Validates length of a string field.
557
488
  */
558
- attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
489
+ attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
559
490
 
560
491
  /**
561
492
  * Validates a string field value starts with the given text.
562
493
  */
563
- attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
494
+ attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
564
495
 
565
496
  /**
566
497
  * Validates a string field value ends with the given text.
567
498
  */
568
- attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
499
+ attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
569
500
 
570
501
  /**
571
502
  * Validates a string field value contains the given text.
572
503
  */
573
- attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
504
+ attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
574
505
 
575
506
  /**
576
507
  * Validates a string field value matches a regex.
577
508
  */
578
- attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
509
+ attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation
579
510
 
580
511
  /**
581
512
  * Validates a string field value is a valid email address.
582
513
  */
583
- attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
514
+ attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation
584
515
 
585
516
  /**
586
517
  * Validates a string field value is a valid ISO datetime.
587
518
  */
588
- attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
519
+ attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation
589
520
 
590
521
  /**
591
522
  * Validates a string field value is a valid url.
592
523
  */
593
- attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef
524
+ attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation
594
525
 
595
526
  /**
596
527
  * Trims whitespaces from the start and end of the string.
597
528
  */
598
- attribute @trim() @@@targetField([StringField]) @@@validation @@@supportTypeDef
529
+ attribute @trim() @@@targetField([StringField]) @@@validation
599
530
 
600
531
  /**
601
532
  * Transform entire string toLowerCase.
602
533
  */
603
- attribute @lower() @@@targetField([StringField]) @@@validation @@@supportTypeDef
534
+ attribute @lower() @@@targetField([StringField]) @@@validation
604
535
 
605
536
  /**
606
537
  * Transform entire string toUpperCase.
607
538
  */
608
- attribute @upper() @@@targetField([StringField]) @@@validation @@@supportTypeDef
539
+ attribute @upper() @@@targetField([StringField]) @@@validation
609
540
 
610
541
  /**
611
542
  * Validates a number field is greater than the given value.
612
543
  */
613
- attribute @gt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
544
+ attribute @gt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
614
545
 
615
546
  /**
616
547
  * Validates a number field is greater than or equal to the given value.
617
548
  */
618
- attribute @gte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
549
+ attribute @gte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
619
550
 
620
551
  /**
621
552
  * Validates a number field is less than the given value.
622
553
  */
623
- attribute @lt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
554
+ attribute @lt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
624
555
 
625
556
  /**
626
557
  * Validates a number field is less than or equal to the given value.
627
558
  */
628
- attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation @@@supportTypeDef
559
+ attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
629
560
 
630
561
  /**
631
562
  * Validates the entity with a complex condition.
632
563
  */
633
- attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation @@@supportTypeDef
564
+ attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
634
565
 
635
566
  /**
636
567
  * Validates length of a string field.
@@ -665,9 +596,9 @@ function url(field: String): Boolean {
665
596
 
666
597
  /**
667
598
  * Checks if the current user can perform the given operation on the given field.
668
- *
599
+ *
669
600
  * @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,
601
+ * @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
671
602
  * it defaults the operation of the containing policy rule.
672
603
  */
673
604
  function check(field: Any, operation: String?): Boolean {
@@ -718,4 +649,19 @@ function auth(): Any {
718
649
  * Used to specify the model for resolving `auth()` function call in access policies. A Zmodel
719
650
  * can have at most one model with this attribute. By default, the model named "User" is used.
720
651
  */
721
- attribute @@auth() @@@supportTypeDef
652
+ attribute @@auth()
653
+
654
+ /**
655
+ * Attaches arbitrary metadata to a model or type def.
656
+ */
657
+ attribute @@meta(_ name: String, _ value: Any)
658
+
659
+ /**
660
+ * Attaches arbitrary metadata to a field.
661
+ */
662
+ attribute @meta(_ name: String, _ value: Any)
663
+
664
+ /**
665
+ * Marks an attribute as deprecated.
666
+ */
667
+ attribute @@@deprecated(_ message: String)