@zenstackhq/language 3.0.0-beta.1 → 3.0.0-beta.11
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 +442 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +394 -225
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +106 -28
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +5 -5
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +100 -23
- package/dist/utils.js.map +1 -1
- package/package.json +8 -6
- package/res/stdlib.zmodel +39 -69
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,83 +118,62 @@ function dbgenerated(expr: String?): Any {
|
|
|
117
118
|
} @@@expressionContext([DefaultValue])
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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])
|
|
131
128
|
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
function search(field: String, search: String): Boolean {
|
|
136
|
-
} @@@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])
|
|
137
134
|
|
|
138
135
|
/**
|
|
139
|
-
*
|
|
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
|
-
*
|
|
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
|
/**
|
|
151
|
-
*
|
|
154
|
+
* Checks if the list field has the given search value
|
|
152
155
|
*/
|
|
153
156
|
function has(field: Any[], search: Any): Boolean {
|
|
154
157
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
155
158
|
|
|
156
159
|
/**
|
|
157
|
-
*
|
|
160
|
+
* Checks if the list field has at least one element of the search list
|
|
158
161
|
*/
|
|
159
|
-
function
|
|
162
|
+
function hasSome(field: Any[], search: Any[]): Boolean {
|
|
160
163
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
161
164
|
|
|
162
165
|
/**
|
|
163
|
-
*
|
|
166
|
+
* Checks if the list field has every element of the search list
|
|
164
167
|
*/
|
|
165
|
-
function
|
|
168
|
+
function hasEvery(field: Any[], search: Any[]): Boolean {
|
|
166
169
|
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
167
170
|
|
|
168
171
|
/**
|
|
169
|
-
*
|
|
172
|
+
* Checks if the list field is empty
|
|
170
173
|
*/
|
|
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
|
*/
|
|
@@ -484,9 +464,9 @@ attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
|
|
|
484
464
|
//////////////////////////////////////////////
|
|
485
465
|
|
|
486
466
|
/**
|
|
487
|
-
* Validates length of a string field.
|
|
467
|
+
* Validates length of a string field or list field.
|
|
488
468
|
*/
|
|
489
|
-
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
469
|
+
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation
|
|
490
470
|
|
|
491
471
|
/**
|
|
492
472
|
* Validates a string field value starts with the given text.
|
|
@@ -541,22 +521,22 @@ attribute @upper() @@@targetField([StringField]) @@@validation
|
|
|
541
521
|
/**
|
|
542
522
|
* Validates a number field is greater than the given value.
|
|
543
523
|
*/
|
|
544
|
-
attribute @gt(_ value:
|
|
524
|
+
attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
545
525
|
|
|
546
526
|
/**
|
|
547
527
|
* Validates a number field is greater than or equal to the given value.
|
|
548
528
|
*/
|
|
549
|
-
attribute @gte(_ value:
|
|
529
|
+
attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
550
530
|
|
|
551
531
|
/**
|
|
552
532
|
* Validates a number field is less than the given value.
|
|
553
533
|
*/
|
|
554
|
-
attribute @lt(_ value:
|
|
534
|
+
attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
555
535
|
|
|
556
536
|
/**
|
|
557
537
|
* Validates a number field is less than or equal to the given value.
|
|
558
538
|
*/
|
|
559
|
-
attribute @lte(_ value:
|
|
539
|
+
attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
560
540
|
|
|
561
541
|
/**
|
|
562
542
|
* Validates the entity with a complex condition.
|
|
@@ -564,46 +544,36 @@ attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, Float
|
|
|
564
544
|
attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
|
|
565
545
|
|
|
566
546
|
/**
|
|
567
|
-
*
|
|
547
|
+
* Returns the length of a string field or a list field.
|
|
568
548
|
*/
|
|
569
|
-
function length(field:
|
|
549
|
+
function length(field: Any): Int {
|
|
570
550
|
} @@@expressionContext([ValidationRule])
|
|
571
551
|
|
|
572
552
|
|
|
573
553
|
/**
|
|
574
|
-
* Validates a string field value matches a regex.
|
|
554
|
+
* Validates a string field value matches a regex pattern.
|
|
575
555
|
*/
|
|
576
|
-
function regex(field: String,
|
|
556
|
+
function regex(field: String, pattern: String): Boolean {
|
|
577
557
|
} @@@expressionContext([ValidationRule])
|
|
578
558
|
|
|
579
559
|
/**
|
|
580
560
|
* Validates a string field value is a valid email address.
|
|
581
561
|
*/
|
|
582
|
-
function
|
|
562
|
+
function isEmail(field: String): Boolean {
|
|
583
563
|
} @@@expressionContext([ValidationRule])
|
|
584
564
|
|
|
585
565
|
/**
|
|
586
566
|
* Validates a string field value is a valid ISO datetime.
|
|
587
567
|
*/
|
|
588
|
-
function
|
|
568
|
+
function isDateTime(field: String): Boolean {
|
|
589
569
|
} @@@expressionContext([ValidationRule])
|
|
590
570
|
|
|
591
571
|
/**
|
|
592
572
|
* Validates a string field value is a valid url.
|
|
593
573
|
*/
|
|
594
|
-
function
|
|
574
|
+
function isUrl(field: String): Boolean {
|
|
595
575
|
} @@@expressionContext([ValidationRule])
|
|
596
576
|
|
|
597
|
-
/**
|
|
598
|
-
* Checks if the current user can perform the given operation on the given field.
|
|
599
|
-
*
|
|
600
|
-
* @param field: The field to check access for
|
|
601
|
-
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
|
|
602
|
-
* it defaults the operation of the containing policy rule.
|
|
603
|
-
*/
|
|
604
|
-
function check(field: Any, operation: String?): Boolean {
|
|
605
|
-
} @@@expressionContext([AccessPolicy])
|
|
606
|
-
|
|
607
577
|
//////////////////////////////////////////////
|
|
608
578
|
// End validation attributes and functions
|
|
609
579
|
//////////////////////////////////////////////
|