@zenstackhq/language 3.0.0-beta.3 → 3.0.0-beta.30
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 +1701 -301
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -20
- package/dist/index.d.ts +89 -20
- package/dist/index.js +1652 -256
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +122 -28
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -6
- package/dist/utils.d.ts +7 -6
- package/dist/utils.js +115 -23
- package/dist/utils.js.map +1 -1
- package/package.json +11 -11
- package/res/stdlib.zmodel +56 -77
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
|
*/
|
|
@@ -402,15 +382,24 @@ attribute @map(_ name: String) @@@prisma
|
|
|
402
382
|
attribute @@map(_ name: String) @@@prisma
|
|
403
383
|
|
|
404
384
|
/**
|
|
405
|
-
* 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.
|
|
406
387
|
*/
|
|
407
388
|
attribute @ignore() @@@prisma
|
|
408
389
|
|
|
409
390
|
/**
|
|
410
|
-
* 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.
|
|
411
393
|
*/
|
|
412
394
|
attribute @@ignore() @@@prisma
|
|
413
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
|
+
|
|
414
403
|
/**
|
|
415
404
|
* Automatically stores the time when a record was last updated.
|
|
416
405
|
*/
|
|
@@ -472,21 +461,21 @@ attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
|
|
|
472
461
|
|
|
473
462
|
attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
|
|
474
463
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
|
481
470
|
|
|
482
471
|
//////////////////////////////////////////////
|
|
483
472
|
// Begin validation attributes and functions
|
|
484
473
|
//////////////////////////////////////////////
|
|
485
474
|
|
|
486
475
|
/**
|
|
487
|
-
* Validates length of a string field.
|
|
476
|
+
* Validates length of a string field or list field.
|
|
488
477
|
*/
|
|
489
|
-
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
478
|
+
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField, ListField]) @@@validation
|
|
490
479
|
|
|
491
480
|
/**
|
|
492
481
|
* Validates a string field value starts with the given text.
|
|
@@ -541,22 +530,22 @@ attribute @upper() @@@targetField([StringField]) @@@validation
|
|
|
541
530
|
/**
|
|
542
531
|
* Validates a number field is greater than the given value.
|
|
543
532
|
*/
|
|
544
|
-
attribute @gt(_ value:
|
|
533
|
+
attribute @gt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
545
534
|
|
|
546
535
|
/**
|
|
547
536
|
* Validates a number field is greater than or equal to the given value.
|
|
548
537
|
*/
|
|
549
|
-
attribute @gte(_ value:
|
|
538
|
+
attribute @gte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
550
539
|
|
|
551
540
|
/**
|
|
552
541
|
* Validates a number field is less than the given value.
|
|
553
542
|
*/
|
|
554
|
-
attribute @lt(_ value:
|
|
543
|
+
attribute @lt(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
555
544
|
|
|
556
545
|
/**
|
|
557
546
|
* Validates a number field is less than or equal to the given value.
|
|
558
547
|
*/
|
|
559
|
-
attribute @lte(_ value:
|
|
548
|
+
attribute @lte(_ value: Any, _ message: String?) @@@targetField([IntField, FloatField, DecimalField, BigIntField]) @@@validation
|
|
560
549
|
|
|
561
550
|
/**
|
|
562
551
|
* Validates the entity with a complex condition.
|
|
@@ -564,46 +553,36 @@ attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, Float
|
|
|
564
553
|
attribute @@validate(_ value: Boolean, _ message: String?, _ path: String[]?) @@@validation
|
|
565
554
|
|
|
566
555
|
/**
|
|
567
|
-
*
|
|
556
|
+
* Returns the length of a string field or a list field.
|
|
568
557
|
*/
|
|
569
|
-
function length(field:
|
|
558
|
+
function length(field: Any): Int {
|
|
570
559
|
} @@@expressionContext([ValidationRule])
|
|
571
560
|
|
|
572
561
|
|
|
573
562
|
/**
|
|
574
|
-
* Validates a string field value matches a regex.
|
|
563
|
+
* Validates a string field value matches a regex pattern.
|
|
575
564
|
*/
|
|
576
|
-
function regex(field: String,
|
|
565
|
+
function regex(field: String, pattern: String): Boolean {
|
|
577
566
|
} @@@expressionContext([ValidationRule])
|
|
578
567
|
|
|
579
568
|
/**
|
|
580
569
|
* Validates a string field value is a valid email address.
|
|
581
570
|
*/
|
|
582
|
-
function
|
|
571
|
+
function isEmail(field: String): Boolean {
|
|
583
572
|
} @@@expressionContext([ValidationRule])
|
|
584
573
|
|
|
585
574
|
/**
|
|
586
575
|
* Validates a string field value is a valid ISO datetime.
|
|
587
576
|
*/
|
|
588
|
-
function
|
|
577
|
+
function isDateTime(field: String): Boolean {
|
|
589
578
|
} @@@expressionContext([ValidationRule])
|
|
590
579
|
|
|
591
580
|
/**
|
|
592
581
|
* Validates a string field value is a valid url.
|
|
593
582
|
*/
|
|
594
|
-
function
|
|
583
|
+
function isUrl(field: String): Boolean {
|
|
595
584
|
} @@@expressionContext([ValidationRule])
|
|
596
585
|
|
|
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
586
|
//////////////////////////////////////////////
|
|
608
587
|
// End validation attributes and functions
|
|
609
588
|
//////////////////////////////////////////////
|