@zenstackhq/language 3.0.0-beta.8 → 3.0.0
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/dist/index.cjs +1607 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -19
- package/dist/index.d.ts +89 -19
- package/dist/index.js +1553 -188
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +106 -9
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -5
- package/dist/utils.d.ts +7 -5
- package/dist/utils.js +100 -6
- package/dist/utils.js.map +1 -1
- package/package.json +10 -11
- package/res/stdlib.zmodel +42 -108
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
|
/**
|
|
@@ -125,11 +126,11 @@ function dbgenerated(expr: String?): Any {
|
|
|
125
126
|
function contains(field: String, search: String, caseInSensitive: Boolean?): Boolean {
|
|
126
127
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
127
128
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
function search(field: String, search: String): Boolean {
|
|
132
|
-
} @@@expressionContext([AccessPolicy])
|
|
129
|
+
// /**
|
|
130
|
+
// * 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.
|
|
131
|
+
// */
|
|
132
|
+
// function search(field: String, search: String): Boolean {
|
|
133
|
+
// } @@@expressionContext([AccessPolicy])
|
|
133
134
|
|
|
134
135
|
/**
|
|
135
136
|
* Checks the field value starts with the search string. By default, the search is case-sensitive, and
|
|
@@ -150,52 +151,29 @@ function endsWith(field: String, search: String, caseInSensitive: Boolean?): Boo
|
|
|
150
151
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
151
152
|
|
|
152
153
|
/**
|
|
153
|
-
*
|
|
154
|
+
* Checks if the list field has the given search value
|
|
154
155
|
*/
|
|
155
156
|
function has(field: Any[], search: Any): Boolean {
|
|
156
157
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
157
158
|
|
|
158
159
|
/**
|
|
159
|
-
*
|
|
160
|
+
* Checks if the list field has at least one element of the search list
|
|
160
161
|
*/
|
|
161
|
-
function
|
|
162
|
+
function hasSome(field: Any[], search: Any[]): Boolean {
|
|
162
163
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
163
164
|
|
|
164
165
|
/**
|
|
165
|
-
*
|
|
166
|
+
* Checks if the list field has every element of the search list
|
|
166
167
|
*/
|
|
167
|
-
function
|
|
168
|
+
function hasEvery(field: Any[], search: Any[]): Boolean {
|
|
168
169
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
169
170
|
|
|
170
171
|
/**
|
|
171
|
-
*
|
|
172
|
+
* Checks if the list field is empty
|
|
172
173
|
*/
|
|
173
174
|
function isEmpty(field: Any[]): Boolean {
|
|
174
175
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
175
176
|
|
|
176
|
-
/**
|
|
177
|
-
* The name of the model for which the policy rule is defined. If the rule is
|
|
178
|
-
* inherited to a sub model, this function returns the name of the sub model.
|
|
179
|
-
*
|
|
180
|
-
* @param optional parameter to control the casing of the returned value. Valid
|
|
181
|
-
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
|
|
182
|
-
* to "original".
|
|
183
|
-
*/
|
|
184
|
-
function currentModel(casing: String?): String {
|
|
185
|
-
} @@@expressionContext([AccessPolicy])
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The operation for which the policy rule is defined for. Note that a rule with
|
|
189
|
-
* "all" operation is expanded to "create", "read", "update", and "delete" rules,
|
|
190
|
-
* and the function returns corresponding value for each expanded version.
|
|
191
|
-
*
|
|
192
|
-
* @param optional parameter to control the casing of the returned value. Valid
|
|
193
|
-
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
|
|
194
|
-
* to "original".
|
|
195
|
-
*/
|
|
196
|
-
function currentOperation(casing: String?): String {
|
|
197
|
-
} @@@expressionContext([AccessPolicy])
|
|
198
|
-
|
|
199
177
|
/**
|
|
200
178
|
* Marks an attribute to be only applicable to certain field types.
|
|
201
179
|
*/
|
|
@@ -404,15 +382,24 @@ attribute @map(_ name: String) @@@prisma
|
|
|
404
382
|
attribute @@map(_ name: String) @@@prisma
|
|
405
383
|
|
|
406
384
|
/**
|
|
407
|
-
* Exclude a field from the
|
|
385
|
+
* Exclude a field from the ORM Client (for example, a field that you do not want Prisma users to update).
|
|
386
|
+
* The field is still recognized by database schema migrations.
|
|
408
387
|
*/
|
|
409
388
|
attribute @ignore() @@@prisma
|
|
410
389
|
|
|
411
390
|
/**
|
|
412
|
-
* Exclude a model from the
|
|
391
|
+
* Exclude a model from the ORM Client (for example, a model that you do not want Prisma users to update).
|
|
392
|
+
* The model is still recognized by database schema migrations.
|
|
413
393
|
*/
|
|
414
394
|
attribute @@ignore() @@@prisma
|
|
415
395
|
|
|
396
|
+
/**
|
|
397
|
+
* Indicates that the field should be omitted by default when read with an ORM client. The omission can be
|
|
398
|
+
* overridden in options passed to create `ZenStackClient`, or at query time by explicitly passing in an
|
|
399
|
+
* `omit` clause. The attribute is only effective for ORM query APIs, not for query-builder APIs.
|
|
400
|
+
*/
|
|
401
|
+
attribute @omit()
|
|
402
|
+
|
|
416
403
|
/**
|
|
417
404
|
* Automatically stores the time when a record was last updated.
|
|
418
405
|
*/
|
|
@@ -474,21 +461,21 @@ attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
|
|
|
474
461
|
|
|
475
462
|
attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
|
|
476
463
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
464
|
+
/**
|
|
465
|
+
* Specifies the schema to use in a multi-schema PostgreSQL database.
|
|
466
|
+
*
|
|
467
|
+
* @param map: The name of the database schema.
|
|
468
|
+
*/
|
|
469
|
+
attribute @@schema(_ map: String) @@@prisma
|
|
483
470
|
|
|
484
471
|
//////////////////////////////////////////////
|
|
485
472
|
// Begin validation attributes and functions
|
|
486
473
|
//////////////////////////////////////////////
|
|
487
474
|
|
|
488
475
|
/**
|
|
489
|
-
* Validates length of a string field.
|
|
476
|
+
* Validates length of a string field or list field.
|
|
490
477
|
*/
|
|
491
|
-
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
478
|
+
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation
|
|
492
479
|
|
|
493
480
|
/**
|
|
494
481
|
* Validates a string field value starts with the given text.
|
|
@@ -543,22 +530,22 @@ attribute @upper() @@@targetField([StringField]) @@@validation
|
|
|
543
530
|
/**
|
|
544
531
|
* Validates a number field is greater than the given value.
|
|
545
532
|
*/
|
|
546
|
-
attribute @gt(_ value:
|
|
533
|
+
attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
547
534
|
|
|
548
535
|
/**
|
|
549
536
|
* Validates a number field is greater than or equal to the given value.
|
|
550
537
|
*/
|
|
551
|
-
attribute @gte(_ value:
|
|
538
|
+
attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
552
539
|
|
|
553
540
|
/**
|
|
554
541
|
* Validates a number field is less than the given value.
|
|
555
542
|
*/
|
|
556
|
-
attribute @lt(_ value:
|
|
543
|
+
attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
557
544
|
|
|
558
545
|
/**
|
|
559
546
|
* Validates a number field is less than or equal to the given value.
|
|
560
547
|
*/
|
|
561
|
-
attribute @lte(_ value:
|
|
548
|
+
attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
562
549
|
|
|
563
550
|
/**
|
|
564
551
|
* Validates the entity with a complex condition.
|
|
@@ -566,34 +553,34 @@ attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, Float
|
|
|
566
553
|
attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
|
|
567
554
|
|
|
568
555
|
/**
|
|
569
|
-
*
|
|
556
|
+
* Returns the length of a string field or a list field.
|
|
570
557
|
*/
|
|
571
|
-
function length(field:
|
|
558
|
+
function length(field: Any): Int {
|
|
572
559
|
} @@@expressionContext([ValidationRule])
|
|
573
560
|
|
|
574
561
|
|
|
575
562
|
/**
|
|
576
|
-
* Validates a string field value matches a regex.
|
|
563
|
+
* Validates a string field value matches a regex pattern.
|
|
577
564
|
*/
|
|
578
|
-
function regex(field: String,
|
|
565
|
+
function regex(field: String, pattern: String): Boolean {
|
|
579
566
|
} @@@expressionContext([ValidationRule])
|
|
580
567
|
|
|
581
568
|
/**
|
|
582
569
|
* Validates a string field value is a valid email address.
|
|
583
570
|
*/
|
|
584
|
-
function
|
|
571
|
+
function isEmail(field: String): Boolean {
|
|
585
572
|
} @@@expressionContext([ValidationRule])
|
|
586
573
|
|
|
587
574
|
/**
|
|
588
575
|
* Validates a string field value is a valid ISO datetime.
|
|
589
576
|
*/
|
|
590
|
-
function
|
|
577
|
+
function isDateTime(field: String): Boolean {
|
|
591
578
|
} @@@expressionContext([ValidationRule])
|
|
592
579
|
|
|
593
580
|
/**
|
|
594
581
|
* Validates a string field value is a valid url.
|
|
595
582
|
*/
|
|
596
|
-
function
|
|
583
|
+
function isUrl(field: String): Boolean {
|
|
597
584
|
} @@@expressionContext([ValidationRule])
|
|
598
585
|
|
|
599
586
|
//////////////////////////////////////////////
|
|
@@ -657,56 +644,3 @@ attribute @meta(_ name: String, _ value: Any)
|
|
|
657
644
|
* Marks an attribute as deprecated.
|
|
658
645
|
*/
|
|
659
646
|
attribute @@@deprecated(_ message: String)
|
|
660
|
-
|
|
661
|
-
/* --- Policy Plugin --- */
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Defines an access policy that allows a set of operations when the given condition is true.
|
|
665
|
-
*
|
|
666
|
-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
|
|
667
|
-
* @param condition: a boolean expression that controls if the operation should be allowed.
|
|
668
|
-
*/
|
|
669
|
-
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'","'delete'", "'all'"]), _ condition: Boolean)
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
* Defines an access policy that allows the annotated field to be read or updated.
|
|
673
|
-
* You can pass a third argument as `true` to make it override the model-level policies.
|
|
674
|
-
*
|
|
675
|
-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
|
|
676
|
-
* @param condition: a boolean expression that controls if the operation should be allowed.
|
|
677
|
-
* @param override: a boolean value that controls if the field-level policy should override the model-level policy.
|
|
678
|
-
*/
|
|
679
|
-
attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean, _ override: Boolean?)
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Defines an access policy that denies a set of operations when the given condition is true.
|
|
683
|
-
*
|
|
684
|
-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
|
|
685
|
-
* @param condition: a boolean expression that controls if the operation should be denied.
|
|
686
|
-
*/
|
|
687
|
-
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'","'delete'", "'all'"]), _ condition: Boolean)
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* Defines an access policy that denies the annotated field to be read or updated.
|
|
691
|
-
*
|
|
692
|
-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
|
|
693
|
-
* @param condition: a boolean expression that controls if the operation should be denied.
|
|
694
|
-
*/
|
|
695
|
-
attribute @deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* Checks if the current user can perform the given operation on the given field.
|
|
699
|
-
*
|
|
700
|
-
* @param field: The field to check access for
|
|
701
|
-
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
|
|
702
|
-
* it defaults the operation of the containing policy rule.
|
|
703
|
-
*/
|
|
704
|
-
function check(field: Any, operation: String?): Boolean {
|
|
705
|
-
} @@@expressionContext([AccessPolicy])
|
|
706
|
-
|
|
707
|
-
/**
|
|
708
|
-
* Gets entity's value before an update. Only valid when used in a "post-update" policy rule.
|
|
709
|
-
*/
|
|
710
|
-
function before(): Any {
|
|
711
|
-
} @@@expressionContext([AccessPolicy])
|
|
712
|
-
|