zenstack 1.0.16 → 1.1.1

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.
Files changed (154) hide show
  1. package/README.md +93 -24
  2. package/bin/post-install.js +1 -1
  3. package/cli/actions/generate.d.ts +13 -0
  4. package/cli/actions/generate.js +71 -0
  5. package/cli/actions/generate.js.map +1 -0
  6. package/cli/actions/index.d.ts +3 -0
  7. package/cli/actions/index.js +20 -0
  8. package/cli/actions/index.js.map +1 -0
  9. package/cli/actions/info.d.ts +4 -0
  10. package/cli/actions/info.js +63 -0
  11. package/cli/actions/info.js.map +1 -0
  12. package/cli/actions/init.d.ts +12 -0
  13. package/cli/actions/init.js +83 -0
  14. package/cli/actions/init.js.map +1 -0
  15. package/cli/cli-util.d.ts +14 -11
  16. package/cli/cli-util.js +150 -82
  17. package/cli/cli-util.js.map +1 -1
  18. package/cli/config.d.ts +10 -0
  19. package/cli/config.js +62 -0
  20. package/cli/config.js.map +1 -0
  21. package/cli/index.d.ts +4 -12
  22. package/cli/index.js +36 -29
  23. package/cli/index.js.map +1 -1
  24. package/cli/plugin-runner.d.ts +13 -3
  25. package/cli/plugin-runner.js +165 -59
  26. package/cli/plugin-runner.js.map +1 -1
  27. package/constants.js +1 -1
  28. package/language-server/constants.d.ts +7 -0
  29. package/language-server/constants.js +8 -1
  30. package/language-server/constants.js.map +1 -1
  31. package/language-server/utils.d.ts +1 -14
  32. package/language-server/utils.js +2 -38
  33. package/language-server/utils.js.map +1 -1
  34. package/language-server/validator/attribute-application-validator.d.ts +15 -0
  35. package/language-server/validator/attribute-application-validator.js +246 -0
  36. package/language-server/validator/attribute-application-validator.js.map +1 -0
  37. package/language-server/validator/attribute-validator.d.ts +1 -1
  38. package/language-server/validator/attribute-validator.js +4 -1
  39. package/language-server/validator/attribute-validator.js.map +1 -1
  40. package/language-server/validator/datamodel-validator.d.ts +7 -0
  41. package/language-server/validator/datamodel-validator.js +84 -33
  42. package/language-server/validator/datamodel-validator.js.map +1 -1
  43. package/language-server/validator/enum-validator.js +3 -6
  44. package/language-server/validator/enum-validator.js.map +1 -1
  45. package/language-server/validator/expression-validator.d.ts +1 -1
  46. package/language-server/validator/expression-validator.js +108 -3
  47. package/language-server/validator/expression-validator.js.map +1 -1
  48. package/language-server/validator/function-decl-validator.d.ts +9 -0
  49. package/language-server/validator/function-decl-validator.js +13 -0
  50. package/language-server/validator/function-decl-validator.js.map +1 -0
  51. package/language-server/validator/function-invocation-validator.d.ts +11 -0
  52. package/language-server/validator/function-invocation-validator.js +135 -0
  53. package/language-server/validator/function-invocation-validator.js.map +1 -0
  54. package/language-server/validator/schema-validator.d.ts +4 -1
  55. package/language-server/validator/schema-validator.js +28 -7
  56. package/language-server/validator/schema-validator.js.map +1 -1
  57. package/language-server/validator/utils.d.ts +3 -4
  58. package/language-server/validator/utils.js +20 -123
  59. package/language-server/validator/utils.js.map +1 -1
  60. package/language-server/validator/zmodel-validator.d.ts +5 -1
  61. package/language-server/validator/zmodel-validator.js +18 -4
  62. package/language-server/validator/zmodel-validator.js.map +1 -1
  63. package/language-server/zmodel-code-action.d.ts +2 -1
  64. package/language-server/zmodel-code-action.js +46 -21
  65. package/language-server/zmodel-code-action.js.map +1 -1
  66. package/language-server/zmodel-definition.d.ts +7 -0
  67. package/language-server/zmodel-definition.js +31 -0
  68. package/language-server/zmodel-definition.js.map +1 -0
  69. package/language-server/zmodel-formatter.js +2 -2
  70. package/language-server/zmodel-formatter.js.map +1 -1
  71. package/language-server/zmodel-linker.d.ts +3 -0
  72. package/language-server/zmodel-linker.js +122 -41
  73. package/language-server/zmodel-linker.js.map +1 -1
  74. package/language-server/zmodel-module.js +4 -1
  75. package/language-server/zmodel-module.js.map +1 -1
  76. package/language-server/zmodel-scope.d.ts +7 -1
  77. package/language-server/zmodel-scope.js +57 -1
  78. package/language-server/zmodel-scope.js.map +1 -1
  79. package/language-server/zmodel-workspace-manager.d.ts +5 -1
  80. package/language-server/zmodel-workspace-manager.js +101 -0
  81. package/language-server/zmodel-workspace-manager.js.map +1 -1
  82. package/package.json +27 -20
  83. package/plugins/access-policy/expression-writer.d.ts +7 -0
  84. package/plugins/access-policy/expression-writer.js +325 -106
  85. package/plugins/access-policy/expression-writer.js.map +1 -1
  86. package/plugins/access-policy/index.d.ts +3 -3
  87. package/plugins/access-policy/index.js +3 -5
  88. package/plugins/access-policy/index.js.map +1 -1
  89. package/plugins/access-policy/policy-guard-generator.d.ts +10 -3
  90. package/plugins/access-policy/policy-guard-generator.js +406 -121
  91. package/plugins/access-policy/policy-guard-generator.js.map +1 -1
  92. package/plugins/model-meta/index.d.ts +3 -3
  93. package/plugins/model-meta/index.js +110 -46
  94. package/plugins/model-meta/index.js.map +1 -1
  95. package/plugins/plugin-utils.d.ts +8 -7
  96. package/plugins/plugin-utils.js +55 -21
  97. package/plugins/plugin-utils.js.map +1 -1
  98. package/plugins/prisma/index.d.ts +3 -3
  99. package/plugins/prisma/index.js +3 -5
  100. package/plugins/prisma/index.js.map +1 -1
  101. package/plugins/prisma/prisma-builder.d.ts +7 -14
  102. package/plugins/prisma/prisma-builder.js +29 -34
  103. package/plugins/prisma/prisma-builder.js.map +1 -1
  104. package/plugins/prisma/schema-generator.d.ts +7 -3
  105. package/plugins/prisma/schema-generator.js +146 -102
  106. package/plugins/prisma/schema-generator.js.map +1 -1
  107. package/plugins/prisma/zmodel-code-generator.d.ts +3 -1
  108. package/plugins/prisma/zmodel-code-generator.js +12 -2
  109. package/plugins/prisma/zmodel-code-generator.js.map +1 -1
  110. package/plugins/zod/generator.d.ts +4 -0
  111. package/plugins/zod/generator.js +298 -0
  112. package/plugins/zod/generator.js.map +1 -0
  113. package/plugins/zod/index.d.ts +4 -0
  114. package/plugins/zod/index.js +24 -0
  115. package/plugins/zod/index.js.map +1 -0
  116. package/plugins/zod/transformer.d.ts +68 -0
  117. package/plugins/zod/transformer.js +554 -0
  118. package/plugins/zod/transformer.js.map +1 -0
  119. package/plugins/zod/types.d.ts +25 -0
  120. package/plugins/zod/types.js.map +1 -0
  121. package/plugins/zod/utils/removeDir.d.ts +1 -0
  122. package/plugins/zod/utils/removeDir.js +30 -0
  123. package/plugins/zod/utils/removeDir.js.map +1 -0
  124. package/plugins/zod/utils/schema-gen.d.ts +3 -0
  125. package/plugins/zod/utils/schema-gen.js +188 -0
  126. package/plugins/zod/utils/schema-gen.js.map +1 -0
  127. package/res/starter.zmodel +6 -8
  128. package/res/stdlib.zmodel +238 -74
  129. package/telemetry.d.ts +2 -1
  130. package/telemetry.js +21 -11
  131. package/telemetry.js.map +1 -1
  132. package/utils/ast-utils.d.ts +12 -15
  133. package/utils/ast-utils.js +117 -66
  134. package/utils/ast-utils.js.map +1 -1
  135. package/utils/pkg-utils.d.ts +2 -2
  136. package/utils/pkg-utils.js +34 -16
  137. package/utils/pkg-utils.js.map +1 -1
  138. package/utils/typescript-expression-transformer.d.ts +54 -0
  139. package/utils/typescript-expression-transformer.js +326 -0
  140. package/utils/typescript-expression-transformer.js.map +1 -0
  141. package/utils/version-utils.js +7 -1
  142. package/utils/version-utils.js.map +1 -1
  143. package/plugins/access-policy/typescript-expression-transformer.d.ts +0 -26
  144. package/plugins/access-policy/typescript-expression-transformer.js +0 -111
  145. package/plugins/access-policy/typescript-expression-transformer.js.map +0 -1
  146. package/plugins/access-policy/utils.d.ts +0 -5
  147. package/plugins/access-policy/utils.js +0 -14
  148. package/plugins/access-policy/utils.js.map +0 -1
  149. package/plugins/access-policy/zod-schema-generator.d.ts +0 -12
  150. package/plugins/access-policy/zod-schema-generator.js +0 -158
  151. package/plugins/access-policy/zod-schema-generator.js.map +0 -1
  152. package/types.d.ts +0 -12
  153. package/types.js.map +0 -1
  154. /package/{types.js → plugins/zod/types.js} +0 -0
package/res/stdlib.zmodel CHANGED
@@ -1,39 +1,39 @@
1
- /*
1
+ /**
2
2
  * Enum representing referential integrity related actions
3
3
  */
4
4
  enum ReferentialAction {
5
- /*
5
+ /**
6
6
  * Used with "onDelete": deleting a referenced record will trigger the deletion of referencing record.
7
7
  * Used with "onUpdate": updates the relation scalar fields if the referenced scalar fields of the dependent record are updated.
8
8
  */
9
9
  Cascade
10
10
 
11
- /*
11
+ /**
12
12
  * Used with "onDelete": prevents the deletion if any referencing records exist.
13
13
  * Used with "onUpdate": prevents the identifier of a referenced record from being changed.
14
14
  */
15
15
  Restrict
16
16
 
17
- /*
17
+ /**
18
18
  * Similar to 'Restrict', the difference between the two is dependent on the database being used.
19
19
  * See details: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions#noaction
20
20
  */
21
21
  NoAction
22
22
 
23
- /*
23
+ /**
24
24
  * Used with "onDelete": the scalar field of the referencing object will be set to NULL.
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.
32
32
  */
33
33
  SetDefault
34
34
  }
35
35
 
36
- /*
36
+ /**
37
37
  * Enum representing all possible field types
38
38
  */
39
39
  enum AttributeTargetField {
@@ -49,124 +49,229 @@ enum AttributeTargetField {
49
49
  ModelField
50
50
  }
51
51
 
52
- /*
52
+ /**
53
+ * Indicates the expression context a function can be used.
54
+ */
55
+ enum ExpressionContext {
56
+ // used in @default
57
+ DefaultValue
58
+
59
+ // used in @@allow and @@deny
60
+ AccessPolicy
61
+
62
+ // used in @@validate
63
+ ValidationRule
64
+ }
65
+
66
+ /**
53
67
  * Reads value from an environment variable.
54
68
  */
55
69
  function env(name: String): String {
56
70
  }
57
71
 
58
- /*
72
+ /**
59
73
  * Gets the current login user.
60
74
  */
61
75
  function auth(): Any {
62
- }
76
+ } @@@expressionContext([AccessPolicy])
63
77
 
64
- /*
78
+ /**
65
79
  * Gets current date-time (as DateTime type).
66
80
  */
67
81
  function now(): DateTime {
68
- }
82
+ } @@@expressionContext([DefaultValue, AccessPolicy, ValidationRule])
69
83
 
70
- /*
84
+ /**
71
85
  * Generates a globally unique identifier based on the UUID specs.
72
86
  */
73
87
  function uuid(): String {
74
- }
88
+ } @@@expressionContext([DefaultValue])
75
89
 
76
- /*
90
+ /**
77
91
  * Generates a globally unique identifier based on the CUID spec.
78
92
  */
79
93
  function cuid(): String {
80
- }
94
+ } @@@expressionContext([DefaultValue])
81
95
 
82
- /*
96
+ /**
83
97
  * Creates a sequence of integers in the underlying database and assign the incremented
84
98
  * values to the ID values of the created records based on the sequence.
85
99
  */
86
100
  function autoincrement(): Int {
87
- }
101
+ } @@@expressionContext([DefaultValue])
88
102
 
89
- /*
103
+ /**
90
104
  * Represents default values that cannot be expressed in the Prisma schema (such as random()).
91
105
  */
92
106
  function dbgenerated(expr: String): Any {
93
- }
107
+ } @@@expressionContext([DefaultValue])
94
108
 
95
109
  /**
96
110
  * Gets entities value before an update. Only valid when used in a "update" policy rule.
97
111
  */
98
112
  function future(): Any {
99
- }
113
+ } @@@expressionContext([AccessPolicy])
114
+
115
+ /**
116
+ * If the field value contains the search string. By default, the search is case-sensitive,
117
+ * but you can override the behavior with the "caseInSensitive" argument.
118
+ */
119
+ function contains(field: String, search: String, caseInSensitive: Boolean?): Boolean {
120
+ } @@@expressionContext([AccessPolicy, ValidationRule])
121
+
122
+ /**
123
+ * 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.
124
+ */
125
+ function search(field: String, search: String): Boolean {
126
+ } @@@expressionContext([AccessPolicy])
127
+
128
+ /**
129
+ * If the field value starts with the search string
130
+ */
131
+ function startsWith(field: String, search: String): Boolean {
132
+ } @@@expressionContext([AccessPolicy, ValidationRule])
133
+
134
+ /**
135
+ * If the field value ends with the search string
136
+ */
137
+ function endsWith(field: String, search: String): Boolean {
138
+ } @@@expressionContext([AccessPolicy, ValidationRule])
139
+
140
+ /**
141
+ * If the field value (a list) has the given search value
142
+ */
143
+ function has(field: Any[], search: Any): Boolean {
144
+ } @@@expressionContext([AccessPolicy, ValidationRule])
145
+
146
+ /**
147
+ * If the field value (a list) has every element of the search list
148
+ */
149
+ function hasEvery(field: Any[], search: Any[]): Boolean {
150
+ } @@@expressionContext([AccessPolicy, ValidationRule])
151
+
152
+ /**
153
+ * If the field value (a list) has at least one element of the search list
154
+ */
155
+ function hasSome(field: Any[], search: Any[]): Boolean {
156
+ } @@@expressionContext([AccessPolicy, ValidationRule])
157
+
158
+ /**
159
+ * If the field value (a list) is empty
160
+ */
161
+ function isEmpty(field: Any[]): Boolean {
162
+ } @@@expressionContext([AccessPolicy, ValidationRule])
100
163
 
101
164
  /**
102
165
  * Marks an attribute to be only applicable to certain field types.
103
166
  */
104
- attribute @@@targetField(targetField: AttributeTargetField[])
167
+ attribute @@@targetField(_ targetField: AttributeTargetField[])
168
+
169
+ /**
170
+ * Marks an attribute to be used for data validation.
171
+ */
172
+ attribute @@@validation()
173
+
174
+ /**
175
+ * Indicates the expression context a function can be used.
176
+ */
177
+ attribute @@@expressionContext(_ context: ExpressionContext[])
105
178
 
106
179
  /**
107
180
  * Indicates an attribute is directly supported by the Prisma schema.
108
181
  */
109
182
  attribute @@@prisma()
110
183
 
111
- /*
184
+ /**
112
185
  * Defines an ID on the model.
113
186
  */
114
- attribute @id(map: String?) @@@prisma
187
+ attribute @id(map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma
115
188
 
116
- /*
189
+ /**
117
190
  * Defines a default value for a field.
118
191
  */
119
- attribute @default(_ value: ContextType) @@@prisma
192
+ attribute @default(_ value: ContextType, map: String?) @@@prisma
120
193
 
121
- /*
194
+ /**
122
195
  * Defines a unique constraint for this field.
123
196
  */
124
- attribute @unique(map: String?) @@@prisma
197
+ attribute @unique(map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma
125
198
 
126
- /*
199
+ /**
127
200
  * Defines a multi-field ID (composite ID) on the model.
128
201
  */
129
- attribute @@id(_ fields: FieldReference[], name: String?, map: String?) @@@prisma
202
+ attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma
130
203
 
131
- /*
204
+ /**
132
205
  * Defines a compound unique constraint for the specified fields.
133
206
  */
134
- attribute @@unique(_ fields: FieldReference[], name: String?, map: String?) @@@prisma
207
+ attribute @@unique(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma
208
+
209
+ /**
210
+ * Index types
211
+ */
212
+ enum IndexType {
213
+ BTree
214
+ Hash
215
+ Gist
216
+ Gin
217
+ SpGist
218
+ Brin
219
+ }
135
220
 
136
- /*
221
+ /**
137
222
  * Defines an index in the database.
138
223
  */
139
- attribute @@index(_ fields: FieldReference[], map: String?) @@@prisma
224
+ attribute @@index(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: String?, clustered: Boolean?, type: IndexType?) @@@prisma
140
225
 
141
- /*
226
+ /**
142
227
  * Defines meta information about the relation.
143
228
  */
144
229
  attribute @relation(_ name: String?, fields: FieldReference[]?, references: TransitiveFieldReference[]?, onDelete: ReferentialAction?, onUpdate: ReferentialAction?, map: String?) @@@prisma
145
230
 
146
- /*
231
+ /**
147
232
  * Maps a field name or enum value from the schema to a column with a different name in the database.
148
233
  */
149
234
  attribute @map(_ name: String) @@@prisma
150
235
 
151
- /*
236
+ /**
152
237
  * Maps the schema model name to a table with a different name, or an enum name to a different underlying enum in the database.
153
238
  */
154
239
  attribute @@map(_ name: String) @@@prisma
155
240
 
156
- /*
241
+ /**
242
+ * Exclude a field from the Prisma Client (for example, a field that you do not want Prisma users to update).
243
+ */
244
+ attribute @ignore() @@@prisma
245
+
246
+ /**
247
+ * Exclude a model from the Prisma Client (for example, a model that you do not want Prisma users to update).
248
+ */
249
+ attribute @@ignore() @@@prisma
250
+
251
+ /**
157
252
  * Automatically stores the time when a record was last updated.
158
253
  */
159
254
  attribute @updatedAt() @@@targetField([DateTimeField]) @@@prisma
160
255
 
256
+ /**
257
+ * Add full text index (MySQL only).
258
+ */
259
+ attribute @@fulltext(_ fields: FieldReference[]) @@@prisma
260
+
261
+
161
262
  // String type modifiers
162
263
 
264
+ enum MSSQLServerTypes {
265
+ Max
266
+ }
267
+
163
268
  attribute @db.String(_ x: Int?) @@@targetField([StringField]) @@@prisma
164
269
  attribute @db.Text() @@@targetField([StringField]) @@@prisma
165
270
  attribute @db.NText() @@@targetField([StringField]) @@@prisma
166
271
  attribute @db.Char(_ x: Int) @@@targetField([StringField]) @@@prisma
167
272
  attribute @db.NChar(_ x: Int) @@@targetField([StringField]) @@@prisma
168
- attribute @db.VarChar(_ x: Int) @@@targetField([StringField]) @@@prisma
169
- attribute @db.NVarChar(_ x: Int) @@@targetField([StringField]) @@@prisma
273
+ attribute @db.VarChar(_ x: Any) @@@targetField([StringField]) @@@prisma
274
+ attribute @db.NVarChar(_ x: Any) @@@targetField([StringField]) @@@prisma
170
275
  attribute @db.CatalogSingleChar() @@@targetField([StringField]) @@@prisma
171
276
  attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
172
277
  attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
@@ -210,7 +315,7 @@ attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
210
315
  attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
211
316
  attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
212
317
  attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
213
- attribute @db.Decimal() @@@targetField([FloatField, DecimalField]) @@@prisma
318
+ attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
214
319
  attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
215
320
  attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
216
321
  attribute @db.SmallMoney() @@@targetField([FloatField, DecimalField]) @@@prisma
@@ -219,7 +324,7 @@ attribute @db.Float4() @@@targetField([FloatField, DecimalField]) @@@prisma
219
324
 
220
325
  // DateTime type modifiers
221
326
 
222
- attribute @db.DateTime(x: Int?) @@@targetField([DateTimeField]) @@@prisma
327
+ attribute @db.DateTime(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
223
328
  attribute @db.DateTime2() @@@targetField([DateTimeField]) @@@prisma
224
329
  attribute @db.SmallDateTime() @@@targetField([DateTimeField]) @@@prisma
225
330
  attribute @db.DateTimeOffset() @@@targetField([DateTimeField]) @@@prisma
@@ -246,22 +351,32 @@ attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
246
351
  attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
247
352
  attribute @db.Image() @@@targetField([BytesField]) @@@prisma
248
353
 
249
- /*
354
+ /**
250
355
  * Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
251
356
  */
252
357
  attribute @@schema(_ name: String) @@@prisma
253
358
 
254
- /*
359
+ /**
255
360
  * Defines an access policy that allows a set of operations when the given condition is true.
256
361
  */
257
362
  attribute @@allow(_ operation: String, _ condition: Boolean)
258
363
 
259
- /*
364
+ /**
365
+ * Defines an access policy that allows the annotated field to be read or updated.
366
+ */
367
+ attribute @allow(_ operation: String, _ condition: Boolean)
368
+
369
+ /**
260
370
  * Defines an access policy that denies a set of operations when the given condition is true.
261
371
  */
262
372
  attribute @@deny(_ operation: String, _ condition: Boolean)
263
373
 
264
- /*
374
+ /**
375
+ * Defines an access policy that denies the annotated field to be read or updated.
376
+ */
377
+ attribute @deny(_ operation: String, _ condition: Boolean)
378
+
379
+ /**
265
380
  * Indicates that the field is a password field and needs to be hashed before persistence.
266
381
  *
267
382
  * ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
@@ -275,72 +390,121 @@ attribute @@deny(_ operation: String, _ condition: Boolean)
275
390
  */
276
391
  attribute @password(saltLength: Int?, salt: String?) @@@targetField([StringField])
277
392
 
278
- /*
393
+ /**
279
394
  * Indicates that the field should be omitted when read from the generated services.
280
395
  */
281
396
  attribute @omit()
282
397
 
283
- /*
284
- * Validates length of a string field.
285
- */
286
- attribute @length(_ min: Int?, _ max: Int?) @@@targetField([StringField])
398
+ //////////////////////////////////////////////
399
+ // Begin validation attributes and functions
400
+ //////////////////////////////////////////////
287
401
 
288
- /*
289
- * Validates a string field value matches a regex.
402
+ /**
403
+ * Validates length of a string field.
290
404
  */
291
- attribute @regex(_ regex: String) @@@targetField([StringField])
405
+ attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
292
406
 
293
- /*
407
+ /**
294
408
  * Validates a string field value starts with the given text.
295
409
  */
296
- attribute @startsWith(_ text: String) @@@targetField([StringField])
410
+ attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
297
411
 
298
- /*
412
+ /**
299
413
  * Validates a string field value ends with the given text.
300
414
  */
301
- attribute @endsWith(_ text: String) @@@targetField([StringField])
415
+ attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
416
+
417
+ /**
418
+ * Validates a string field value contains the given text.
419
+ */
420
+ attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
421
+
422
+ /**
423
+ * Validates a string field value matches a regex.
424
+ */
425
+ attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation
302
426
 
303
- /*
427
+ /**
304
428
  * Validates a string field value is a valid email address.
305
429
  */
306
- attribute @email() @@@targetField([StringField])
430
+ attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation
307
431
 
308
- /*
432
+ /**
309
433
  * Validates a string field value is a valid ISO datetime.
310
434
  */
311
- attribute @datetime() @@@targetField([StringField])
435
+ attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation
312
436
 
313
- /*
437
+ /**
314
438
  * Validates a string field value is a valid url.
315
439
  */
316
- attribute @url() @@@targetField([StringField])
440
+ attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation
317
441
 
318
- /*
442
+ /**
319
443
  * Validates a number field is greater than the given value.
320
444
  */
321
- attribute @gt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
445
+ attribute @gt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
322
446
 
323
- /*
447
+ /**
324
448
  * Validates a number field is greater than or equal to the given value.
325
449
  */
326
- attribute @gte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
450
+ attribute @gte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
327
451
 
328
- /*
452
+ /**
329
453
  * Validates a number field is less than the given value.
330
454
  */
331
- attribute @lt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
455
+ attribute @lt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
332
456
 
333
- /*
457
+ /**
334
458
  * Validates a number field is less than or equal to the given value.
335
459
  */
336
- attribute @lte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
460
+ attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
461
+
462
+ /**
463
+ * Validates the entity with a complex condition.
464
+ */
465
+ attribute @@validate(_ value: Boolean, _ message: String?) @@@validation
466
+
467
+ /**
468
+ * Validates length of a string field.
469
+ */
470
+ function length(field: String, min: Int, max: Int?): Boolean {
471
+ } @@@expressionContext([ValidationRule])
472
+
473
+
474
+ /**
475
+ * Validates a string field value matches a regex.
476
+ */
477
+ function regex(field: String, regex: String): Boolean {
478
+ } @@@expressionContext([ValidationRule])
337
479
 
338
- /*
480
+ /**
481
+ * Validates a string field value is a valid email address.
482
+ */
483
+ function email(field: String): Boolean {
484
+ } @@@expressionContext([ValidationRule])
485
+
486
+ /**
487
+ * Validates a string field value is a valid ISO datetime.
488
+ */
489
+ function datetime(field: String): Boolean {
490
+ } @@@expressionContext([ValidationRule])
491
+
492
+ /**
493
+ * Validates a string field value is a valid url.
494
+ */
495
+ function url(field: String): Boolean {
496
+ } @@@expressionContext([ValidationRule])
497
+
498
+ //////////////////////////////////////////////
499
+ // End validation attributes and functions
500
+ //////////////////////////////////////////////
501
+
502
+ /**
339
503
  * A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
340
504
  */
341
505
  attribute @prisma.passthrough(_ text: String)
342
506
 
343
- /*
507
+ /**
344
508
  * A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
345
509
  */
346
510
  attribute @@prisma.passthrough(_ text: String)
package/telemetry.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Telemetry events
3
3
  */
4
- export declare type TelemetryEvents = 'cli:start' | 'cli:complete' | 'cli:error' | 'cli:command:start' | 'cli:command:complete' | 'cli:command:error' | 'cli:plugin:start' | 'cli:plugin:complete' | 'cli:plugin:error';
4
+ export declare type TelemetryEvents = 'cli:start' | 'cli:complete' | 'cli:error' | 'cli:crash' | 'cli:command:start' | 'cli:command:complete' | 'cli:command:error' | 'cli:plugin:start' | 'cli:plugin:complete' | 'cli:plugin:error' | 'prisma:error';
5
5
  /**
6
6
  * Utility class for sending telemetry
7
7
  */
@@ -11,6 +11,7 @@ export declare class Telemetry {
11
11
  private readonly sessionid;
12
12
  private readonly _os;
13
13
  private readonly version;
14
+ private readonly prismaVersion;
14
15
  private exitWait;
15
16
  constructor();
16
17
  track(event: TelemetryEvents, properties?: Record<string, unknown>): void;
package/telemetry.js CHANGED
@@ -36,9 +36,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.Telemetry = void 0;
39
+ const cuid2_1 = require("@paralleldrive/cuid2");
40
+ const sdk_1 = require("@zenstackhq/sdk");
39
41
  const async_exit_hook_1 = __importDefault(require("async-exit-hook"));
40
42
  const commander_1 = require("commander");
41
- const cuid_1 = __importDefault(require("cuid"));
42
43
  const mixpanel_1 = require("mixpanel");
43
44
  const node_machine_id_1 = require("node-machine-id");
44
45
  const os = __importStar(require("os"));
@@ -52,9 +53,10 @@ const version_utils_1 = require("./utils/version-utils");
52
53
  class Telemetry {
53
54
  constructor() {
54
55
  this.hostId = (0, node_machine_id_1.machineIdSync)();
55
- this.sessionid = (0, cuid_1.default)();
56
+ this.sessionid = (0, cuid2_1.createId)();
56
57
  this._os = os.platform();
57
58
  this.version = (0, version_utils_1.getVersion)();
59
+ this.prismaVersion = (0, sdk_1.getPrismaVersion)();
58
60
  this.exitWait = 200;
59
61
  if (process.env.DO_NOT_TRACK !== '1' && constants_1.TELEMETRY_TRACKING_TOKEN) {
60
62
  this.mixpanel = (0, mixpanel_1.init)(constants_1.TELEMETRY_TRACKING_TOKEN, {
@@ -69,19 +71,27 @@ class Telemetry {
69
71
  callback();
70
72
  }));
71
73
  const errorHandler = (err) => __awaiter(this, void 0, void 0, function* () {
72
- this.track('cli:error', {
73
- message: err.message,
74
- stack: err.stack,
75
- });
76
- if (this.mixpanel) {
77
- // a small delay to ensure telemetry is sent
78
- yield (0, sleep_promise_1.default)(this.exitWait);
79
- }
80
74
  if (err instanceof cli_error_1.CliError || err instanceof commander_1.CommanderError) {
75
+ this.track('cli:error', {
76
+ message: err.message,
77
+ stack: err.stack,
78
+ });
79
+ if (this.mixpanel) {
80
+ // a small delay to ensure telemetry is sent
81
+ yield (0, sleep_promise_1.default)(this.exitWait);
82
+ }
81
83
  // error already logged
82
84
  }
83
85
  else {
84
86
  console.error('\nAn unexpected error occurred:\n', err);
87
+ this.track('cli:crash', {
88
+ message: err.message,
89
+ stack: err.stack,
90
+ });
91
+ if (this.mixpanel) {
92
+ // a small delay to ensure telemetry is sent
93
+ yield (0, sleep_promise_1.default)(this.exitWait);
94
+ }
85
95
  }
86
96
  process.exit(1);
87
97
  });
@@ -90,7 +100,7 @@ class Telemetry {
90
100
  }
91
101
  track(event, properties = {}) {
92
102
  if (this.mixpanel) {
93
- const payload = Object.assign({ distinct_id: this.hostId, session: this.sessionid, time: new Date(), $os: this._os, nodeVersion: process.version, version: this.version }, properties);
103
+ const payload = Object.assign({ distinct_id: this.hostId, session: this.sessionid, time: new Date(), $os: this._os, nodeVersion: process.version, version: this.version, prismaVersion: this.prismaVersion }, properties);
94
104
  this.mixpanel.track(event, payload);
95
105
  }
96
106
  }
package/telemetry.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAuC;AACvC,yCAA2C;AAC3C,gDAAwB;AACxB,uCAA0C;AAC1C,qDAAgD;AAChD,uCAAyB;AACzB,kEAAkC;AAClC,+CAA2C;AAC3C,2CAAuD;AACvD,yDAAmD;AAgBnD;;GAEG;AACH,MAAa,SAAS;IAQlB;QANiB,WAAM,GAAG,IAAA,+BAAa,GAAE,CAAC;QACzB,cAAS,GAAG,IAAA,cAAI,GAAE,CAAC;QACnB,QAAG,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACpB,YAAO,GAAG,IAAA,0BAAU,GAAE,CAAC;QAChC,aAAQ,GAAG,GAAG,CAAC;QAGnB,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG,IAAI,oCAAwB,EAAE;YAC9D,IAAI,CAAC,QAAQ,GAAG,IAAA,eAAI,EAAC,oCAAwB,EAAE;gBAC3C,SAAS,EAAE,IAAI;aAClB,CAAC,CAAC;SACN;QAED,IAAA,yBAAQ,EAAC,CAAO,QAAQ,EAAE,EAAE;YACxB,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACf,4CAA4C;gBAC5C,MAAM,IAAA,uBAAK,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC9B;YACD,QAAQ,EAAE,CAAC;QACf,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,CAAO,GAAU,EAAE,EAAE;YACtC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;gBACpB,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,KAAK,EAAE,GAAG,CAAC,KAAK;a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T,WAAW,EAAE,IAAI,CAAC,MAAM,EACxB,OAAO,EAAE,IAAI,CAAC,SAAS,EACvB,IAAI,EAAE,IAAI,IAAI,EAAE,EAChB,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,WAAW,EAAE,OAAO,CAAC,OAAO,EAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,aAAa,EAAE,IAAI,CAAC,aAAa,IAC9B,UAAU,CAChB,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SACvC;IACL,CAAC;IAEK,SAAS,CACX,UAA2B,EAC3B,aAA8B,EAC9B,UAA2B,EAC3B,UAAmC,EACnC,MAAqC;;YAErC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,OAAO,GAAG,IAAI,CAAC;YACnB,IAAI;gBACA,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;gBAChC,8DAA8D;aACjE;YAAC,OAAO,GAAQ,EAAE;gBACf,IAAI,CAAC,KAAK,CAAC,UAAU,kBACjB,OAAO,EAAE,GAAG,CAAC,OAAO,EACpB,KAAK,EAAE,GAAG,CAAC,KAAK,IACb,UAAU,EACf,CAAC;gBACH,OAAO,GAAG,KAAK,CAAC;gBAChB,MAAM,GAAG,CAAC;aACb;oBAAS;gBACN,IAAI,CAAC,KAAK,CAAC,aAAa,kBACpB,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAC5B,OAAO,IACJ,UAAU,EACf,CAAC;aACN;QACL,CAAC;KAAA;CACJ;AAnGD,8BAmGC;AAED,kBAAe,IAAI,SAAS,EAAE,CAAC"}
@@ -1,16 +1,13 @@
1
- import { DataModel, DataModelAttribute, Expression, Model } from '@zenstackhq/language/ast';
1
+ import { BinaryExpr, DataModel, DataModelField, Expression, Model, ModelImport } from '@zenstackhq/language/ast';
2
+ import { AstNode, LangiumDocuments } from 'langium';
3
+ import { URI } from 'vscode-uri';
2
4
  export declare function extractDataModelsWithAllowRules(model: Model): DataModel[];
3
- export declare function analyzePolicies(dataModel: DataModel): {
4
- allows: DataModelAttribute[];
5
- denies: DataModelAttribute[];
6
- create: boolean | undefined;
7
- read: boolean | undefined;
8
- update: boolean | undefined;
9
- delete: boolean | undefined;
10
- allowAll: boolean;
11
- denyAll: boolean;
12
- hasFieldValidation: boolean;
13
- };
14
- export declare const VALIDATION_ATTRIBUTES: string[];
15
- export declare function getIdField(dataModel: DataModel): import("@zenstackhq/language/ast").DataModelField | undefined;
16
- export declare function isAuthInvocation(expr: Expression): boolean;
5
+ export declare function mergeBaseModel(model: Model): void;
6
+ export declare function getIdFields(dataModel: DataModel): DataModelField[];
7
+ export declare function isAuthInvocation(node: AstNode): boolean;
8
+ export declare function getDataModelFieldReference(expr: Expression): DataModelField | undefined;
9
+ export declare function resolveImportUri(imp: ModelImport): URI | undefined;
10
+ export declare function resolveTransitiveImports(documents: LangiumDocuments, model: Model): Model[];
11
+ export declare function resolveImport(documents: LangiumDocuments, imp: ModelImport): Model | undefined;
12
+ export declare function getAllDeclarationsFromImports(documents: LangiumDocuments, model: Model): import("@zenstackhq/language/ast").AbstractDeclaration[];
13
+ export declare function isCollectionPredicate(expr: Expression): expr is BinaryExpr;