zenstack 1.0.0-alpha.99 → 1.0.0-beta.10
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/README.md +65 -24
- package/cli/cli-util.d.ts +4 -1
- package/cli/cli-util.js +63 -9
- package/cli/cli-util.js.map +1 -1
- package/cli/config.js +39 -13
- package/cli/config.js.map +1 -1
- package/cli/index.js +1 -6
- package/cli/index.js.map +1 -1
- package/cli/plugin-runner.d.ts +2 -1
- package/cli/plugin-runner.js +106 -48
- package/cli/plugin-runner.js.map +1 -1
- package/language-server/constants.d.ts +0 -4
- package/language-server/constants.js +1 -14
- package/language-server/constants.js.map +1 -1
- package/language-server/utils.d.ts +1 -5
- package/language-server/utils.js +3 -20
- package/language-server/utils.js.map +1 -1
- package/language-server/validator/datamodel-validator.d.ts +7 -0
- package/language-server/validator/datamodel-validator.js +71 -21
- package/language-server/validator/datamodel-validator.js.map +1 -1
- package/language-server/validator/expression-validator.js +44 -7
- package/language-server/validator/expression-validator.js.map +1 -1
- package/language-server/validator/function-decl-validator.d.ts +9 -0
- package/language-server/validator/function-decl-validator.js +15 -0
- package/language-server/validator/function-decl-validator.js.map +1 -0
- package/language-server/validator/function-invocation-validator.js +31 -5
- package/language-server/validator/function-invocation-validator.js.map +1 -1
- package/language-server/validator/schema-validator.d.ts +4 -1
- package/language-server/validator/schema-validator.js +25 -5
- package/language-server/validator/schema-validator.js.map +1 -1
- package/language-server/validator/utils.d.ts +4 -4
- package/language-server/validator/utils.js +10 -1
- package/language-server/validator/utils.js.map +1 -1
- package/language-server/validator/zmodel-validator.d.ts +4 -1
- package/language-server/validator/zmodel-validator.js +13 -4
- package/language-server/validator/zmodel-validator.js.map +1 -1
- package/language-server/zmodel-code-action.d.ts +2 -1
- package/language-server/zmodel-code-action.js +19 -10
- package/language-server/zmodel-code-action.js.map +1 -1
- package/language-server/zmodel-definition.d.ts +7 -0
- package/language-server/zmodel-definition.js +31 -0
- package/language-server/zmodel-definition.js.map +1 -0
- package/language-server/zmodel-formatter.js +2 -2
- package/language-server/zmodel-formatter.js.map +1 -1
- package/language-server/zmodel-linker.d.ts +2 -0
- package/language-server/zmodel-linker.js +71 -7
- package/language-server/zmodel-linker.js.map +1 -1
- package/language-server/zmodel-module.js +4 -1
- package/language-server/zmodel-module.js.map +1 -1
- package/language-server/zmodel-scope.d.ts +7 -1
- package/language-server/zmodel-scope.js +57 -1
- package/language-server/zmodel-scope.js.map +1 -1
- package/package.json +19 -21
- package/plugins/access-policy/expression-writer.js +71 -25
- package/plugins/access-policy/expression-writer.js.map +1 -1
- package/plugins/access-policy/policy-guard-generator.js +107 -73
- package/plugins/access-policy/policy-guard-generator.js.map +1 -1
- package/plugins/access-policy/utils.d.ts +2 -2
- package/plugins/access-policy/utils.js +2 -2
- package/plugins/access-policy/utils.js.map +1 -1
- package/plugins/model-meta/index.js +35 -31
- package/plugins/model-meta/index.js.map +1 -1
- package/plugins/plugin-utils.d.ts +4 -4
- package/plugins/plugin-utils.js +28 -18
- package/plugins/plugin-utils.js.map +1 -1
- package/plugins/prisma/index.d.ts +1 -1
- package/plugins/prisma/prisma-builder.d.ts +6 -3
- package/plugins/prisma/prisma-builder.js +29 -8
- package/plugins/prisma/prisma-builder.js.map +1 -1
- package/plugins/prisma/schema-generator.d.ts +4 -1
- package/plugins/prisma/schema-generator.js +149 -32
- package/plugins/prisma/schema-generator.js.map +1 -1
- package/plugins/zod/generator.js +171 -22
- package/plugins/zod/generator.js.map +1 -1
- package/plugins/zod/index.d.ts +1 -1
- package/plugins/zod/transformer.d.ts +6 -6
- package/plugins/zod/transformer.js +168 -108
- package/plugins/zod/transformer.js.map +1 -1
- package/plugins/zod/types.d.ts +2 -0
- package/plugins/zod/utils/schema-gen.d.ts +3 -0
- package/plugins/zod/utils/schema-gen.js +178 -0
- package/plugins/zod/utils/schema-gen.js.map +1 -0
- package/res/starter.zmodel +4 -4
- package/res/stdlib.zmodel +176 -90
- package/telemetry.d.ts +2 -1
- package/telemetry.js +5 -3
- package/telemetry.js.map +1 -1
- package/utils/ast-utils.d.ts +10 -3
- package/utils/ast-utils.js +91 -8
- package/utils/ast-utils.js.map +1 -1
- package/utils/pkg-utils.js +1 -1
- package/utils/pkg-utils.js.map +1 -1
- package/utils/typescript-expression-transformer.d.ts +53 -0
- package/utils/typescript-expression-transformer.js +295 -0
- package/utils/typescript-expression-transformer.js.map +1 -0
- package/utils/version-utils.js +1 -0
- package/utils/version-utils.js.map +1 -1
- package/plugins/access-policy/typescript-expression-transformer.d.ts +0 -28
- package/plugins/access-policy/typescript-expression-transformer.js +0 -121
- package/plugins/access-policy/typescript-expression-transformer.js.map +0 -1
- package/plugins/access-policy/zod-schema-generator.d.ts +0 -12
- package/plugins/access-policy/zod-schema-generator.js +0 -157
- package/plugins/access-policy/zod-schema-generator.js.map +0 -1
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,169 +49,206 @@ 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])
|
|
100
114
|
|
|
101
|
-
|
|
102
|
-
* If the field value contains the search string
|
|
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.
|
|
103
118
|
*/
|
|
104
|
-
function contains(field: String, search: String,
|
|
105
|
-
}
|
|
119
|
+
function contains(field: String, search: String, caseInSensitive: Boolean?): Boolean {
|
|
120
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
106
121
|
|
|
107
|
-
|
|
122
|
+
/**
|
|
108
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.
|
|
109
124
|
*/
|
|
110
125
|
function search(field: String, search: String): Boolean {
|
|
111
|
-
}
|
|
126
|
+
} @@@expressionContext([AccessPolicy])
|
|
112
127
|
|
|
113
|
-
|
|
128
|
+
/**
|
|
114
129
|
* If the field value starts with the search string
|
|
115
130
|
*/
|
|
116
131
|
function startsWith(field: String, search: String): Boolean {
|
|
117
|
-
}
|
|
132
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
118
133
|
|
|
119
|
-
|
|
134
|
+
/**
|
|
120
135
|
* If the field value ends with the search string
|
|
121
136
|
*/
|
|
122
137
|
function endsWith(field: String, search: String): Boolean {
|
|
123
|
-
}
|
|
138
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
124
139
|
|
|
125
|
-
|
|
140
|
+
/**
|
|
126
141
|
* If the field value (a list) has the given search value
|
|
127
142
|
*/
|
|
128
143
|
function has(field: Any[], search: Any): Boolean {
|
|
129
|
-
}
|
|
144
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
130
145
|
|
|
131
|
-
|
|
146
|
+
/**
|
|
132
147
|
* If the field value (a list) has every element of the search list
|
|
133
148
|
*/
|
|
134
149
|
function hasEvery(field: Any[], search: Any[]): Boolean {
|
|
135
|
-
}
|
|
150
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
/**
|
|
138
153
|
* If the field value (a list) has at least one element of the search list
|
|
139
154
|
*/
|
|
140
155
|
function hasSome(field: Any[], search: Any[]): Boolean {
|
|
141
|
-
}
|
|
156
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
142
157
|
|
|
143
|
-
|
|
158
|
+
/**
|
|
144
159
|
* If the field value (a list) is empty
|
|
145
160
|
*/
|
|
146
161
|
function isEmpty(field: Any[]): Boolean {
|
|
147
|
-
}
|
|
162
|
+
} @@@expressionContext([AccessPolicy, ValidationRule])
|
|
148
163
|
|
|
149
164
|
/**
|
|
150
165
|
* Marks an attribute to be only applicable to certain field types.
|
|
151
166
|
*/
|
|
152
167
|
attribute @@@targetField(targetField: AttributeTargetField[])
|
|
153
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[])
|
|
178
|
+
|
|
154
179
|
/**
|
|
155
180
|
* Indicates an attribute is directly supported by the Prisma schema.
|
|
156
181
|
*/
|
|
157
182
|
attribute @@@prisma()
|
|
158
183
|
|
|
159
|
-
|
|
184
|
+
/**
|
|
160
185
|
* Defines an ID on the model.
|
|
161
186
|
*/
|
|
162
|
-
attribute @id(map: String?) @@@prisma
|
|
187
|
+
attribute @id(map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma
|
|
163
188
|
|
|
164
|
-
|
|
189
|
+
/**
|
|
165
190
|
* Defines a default value for a field.
|
|
166
191
|
*/
|
|
167
192
|
attribute @default(_ value: ContextType) @@@prisma
|
|
168
193
|
|
|
169
|
-
|
|
194
|
+
/**
|
|
170
195
|
* Defines a unique constraint for this field.
|
|
171
196
|
*/
|
|
172
|
-
attribute @unique(map: String?) @@@prisma
|
|
197
|
+
attribute @unique(map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma
|
|
173
198
|
|
|
174
|
-
|
|
199
|
+
/**
|
|
175
200
|
* Defines a multi-field ID (composite ID) on the model.
|
|
176
201
|
*/
|
|
177
|
-
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
|
|
178
203
|
|
|
179
|
-
|
|
204
|
+
/**
|
|
180
205
|
* Defines a compound unique constraint for the specified fields.
|
|
181
206
|
*/
|
|
182
|
-
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
|
|
183
208
|
|
|
184
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Index types
|
|
211
|
+
*/
|
|
212
|
+
enum IndexType {
|
|
213
|
+
BTree
|
|
214
|
+
Hash
|
|
215
|
+
Gist
|
|
216
|
+
Gin
|
|
217
|
+
SpGist
|
|
218
|
+
Brin
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
185
222
|
* Defines an index in the database.
|
|
186
223
|
*/
|
|
187
|
-
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
|
|
188
225
|
|
|
189
|
-
|
|
226
|
+
/**
|
|
190
227
|
* Defines meta information about the relation.
|
|
191
228
|
*/
|
|
192
229
|
attribute @relation(_ name: String?, fields: FieldReference[]?, references: TransitiveFieldReference[]?, onDelete: ReferentialAction?, onUpdate: ReferentialAction?, map: String?) @@@prisma
|
|
193
230
|
|
|
194
|
-
|
|
231
|
+
/**
|
|
195
232
|
* Maps a field name or enum value from the schema to a column with a different name in the database.
|
|
196
233
|
*/
|
|
197
234
|
attribute @map(_ name: String) @@@prisma
|
|
198
235
|
|
|
199
|
-
|
|
236
|
+
/**
|
|
200
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.
|
|
201
238
|
*/
|
|
202
239
|
attribute @@map(_ name: String) @@@prisma
|
|
203
240
|
|
|
204
|
-
|
|
241
|
+
/**
|
|
205
242
|
* Exclude a field from the Prisma Client (for example, a field that you do not want Prisma users to update).
|
|
206
243
|
*/
|
|
207
244
|
attribute @ignore() @@@prisma
|
|
208
245
|
|
|
209
|
-
|
|
246
|
+
/**
|
|
210
247
|
* Exclude a model from the Prisma Client (for example, a model that you do not want Prisma users to update).
|
|
211
248
|
*/
|
|
212
249
|
attribute @@ignore() @@@prisma
|
|
213
250
|
|
|
214
|
-
|
|
251
|
+
/**
|
|
215
252
|
* Automatically stores the time when a record was last updated.
|
|
216
253
|
*/
|
|
217
254
|
attribute @updatedAt() @@@targetField([DateTimeField]) @@@prisma
|
|
@@ -268,7 +305,7 @@ attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
|
|
|
268
305
|
attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
269
306
|
attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
270
307
|
attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
271
|
-
attribute @db.Decimal() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
308
|
+
attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
272
309
|
attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
273
310
|
attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
274
311
|
attribute @db.SmallMoney() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
@@ -277,7 +314,7 @@ attribute @db.Float4() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
|
277
314
|
|
|
278
315
|
// DateTime type modifiers
|
|
279
316
|
|
|
280
|
-
attribute @db.DateTime(x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
317
|
+
attribute @db.DateTime(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
281
318
|
attribute @db.DateTime2() @@@targetField([DateTimeField]) @@@prisma
|
|
282
319
|
attribute @db.SmallDateTime() @@@targetField([DateTimeField]) @@@prisma
|
|
283
320
|
attribute @db.DateTimeOffset() @@@targetField([DateTimeField]) @@@prisma
|
|
@@ -304,22 +341,22 @@ attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
|
|
|
304
341
|
attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
|
|
305
342
|
attribute @db.Image() @@@targetField([BytesField]) @@@prisma
|
|
306
343
|
|
|
307
|
-
|
|
344
|
+
/**
|
|
308
345
|
* Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
|
|
309
346
|
*/
|
|
310
347
|
attribute @@schema(_ name: String) @@@prisma
|
|
311
348
|
|
|
312
|
-
|
|
349
|
+
/**
|
|
313
350
|
* Defines an access policy that allows a set of operations when the given condition is true.
|
|
314
351
|
*/
|
|
315
352
|
attribute @@allow(_ operation: String, _ condition: Boolean)
|
|
316
353
|
|
|
317
|
-
|
|
354
|
+
/**
|
|
318
355
|
* Defines an access policy that denies a set of operations when the given condition is true.
|
|
319
356
|
*/
|
|
320
357
|
attribute @@deny(_ operation: String, _ condition: Boolean)
|
|
321
358
|
|
|
322
|
-
|
|
359
|
+
/**
|
|
323
360
|
* Indicates that the field is a password field and needs to be hashed before persistence.
|
|
324
361
|
*
|
|
325
362
|
* ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
|
|
@@ -333,72 +370,121 @@ attribute @@deny(_ operation: String, _ condition: Boolean)
|
|
|
333
370
|
*/
|
|
334
371
|
attribute @password(saltLength: Int?, salt: String?) @@@targetField([StringField])
|
|
335
372
|
|
|
336
|
-
|
|
373
|
+
/**
|
|
337
374
|
* Indicates that the field should be omitted when read from the generated services.
|
|
338
375
|
*/
|
|
339
376
|
attribute @omit()
|
|
340
377
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
attribute @length(_ min: Int?, _ max: Int?) @@@targetField([StringField])
|
|
378
|
+
//////////////////////////////////////////////
|
|
379
|
+
// Begin validation attributes and functions
|
|
380
|
+
//////////////////////////////////////////////
|
|
345
381
|
|
|
346
|
-
|
|
347
|
-
* Validates a string field
|
|
382
|
+
/**
|
|
383
|
+
* Validates length of a string field.
|
|
348
384
|
*/
|
|
349
|
-
attribute @
|
|
385
|
+
attribute @length(_ min: Int?, _ max: Int?, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
350
386
|
|
|
351
|
-
|
|
387
|
+
/**
|
|
352
388
|
* Validates a string field value starts with the given text.
|
|
353
389
|
*/
|
|
354
|
-
attribute @startsWith(_ text: String) @@@targetField([StringField])
|
|
390
|
+
attribute @startsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
355
391
|
|
|
356
|
-
|
|
392
|
+
/**
|
|
357
393
|
* Validates a string field value ends with the given text.
|
|
358
394
|
*/
|
|
359
|
-
attribute @endsWith(_ text: String) @@@targetField([StringField])
|
|
395
|
+
attribute @endsWith(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Validates a string field value contains the given text.
|
|
399
|
+
*/
|
|
400
|
+
attribute @contains(_ text: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Validates a string field value matches a regex.
|
|
404
|
+
*/
|
|
405
|
+
attribute @regex(_ regex: String, _ message: String?) @@@targetField([StringField]) @@@validation
|
|
360
406
|
|
|
361
|
-
|
|
407
|
+
/**
|
|
362
408
|
* Validates a string field value is a valid email address.
|
|
363
409
|
*/
|
|
364
|
-
attribute @email() @@@targetField([StringField])
|
|
410
|
+
attribute @email(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
365
411
|
|
|
366
|
-
|
|
412
|
+
/**
|
|
367
413
|
* Validates a string field value is a valid ISO datetime.
|
|
368
414
|
*/
|
|
369
|
-
attribute @datetime() @@@targetField([StringField])
|
|
415
|
+
attribute @datetime(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
370
416
|
|
|
371
|
-
|
|
417
|
+
/**
|
|
372
418
|
* Validates a string field value is a valid url.
|
|
373
419
|
*/
|
|
374
|
-
attribute @url() @@@targetField([StringField])
|
|
420
|
+
attribute @url(_ message: String?) @@@targetField([StringField]) @@@validation
|
|
375
421
|
|
|
376
|
-
|
|
422
|
+
/**
|
|
377
423
|
* Validates a number field is greater than the given value.
|
|
378
424
|
*/
|
|
379
|
-
attribute @gt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
425
|
+
attribute @gt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
|
|
380
426
|
|
|
381
|
-
|
|
427
|
+
/**
|
|
382
428
|
* Validates a number field is greater than or equal to the given value.
|
|
383
429
|
*/
|
|
384
|
-
attribute @gte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
430
|
+
attribute @gte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
|
|
385
431
|
|
|
386
|
-
|
|
432
|
+
/**
|
|
387
433
|
* Validates a number field is less than the given value.
|
|
388
434
|
*/
|
|
389
|
-
attribute @lt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
435
|
+
attribute @lt(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
|
|
390
436
|
|
|
391
|
-
|
|
437
|
+
/**
|
|
392
438
|
* Validates a number field is less than or equal to the given value.
|
|
393
439
|
*/
|
|
394
|
-
attribute @lte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
440
|
+
attribute @lte(_ value: Int, _ message: String?) @@@targetField([IntField, FloatField, DecimalField]) @@@validation
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Validates the entity with a complex condition.
|
|
444
|
+
*/
|
|
445
|
+
attribute @@validate(_ value: Boolean, _ message: String?) @@@validation
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Validates length of a string field.
|
|
449
|
+
*/
|
|
450
|
+
function length(field: String, min: Int, max: Int?): Boolean {
|
|
451
|
+
} @@@expressionContext([ValidationRule])
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Validates a string field value matches a regex.
|
|
456
|
+
*/
|
|
457
|
+
function regex(field: String, regex: String): Boolean {
|
|
458
|
+
} @@@expressionContext([ValidationRule])
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Validates a string field value is a valid email address.
|
|
462
|
+
*/
|
|
463
|
+
function email(field: String): Boolean {
|
|
464
|
+
} @@@expressionContext([ValidationRule])
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Validates a string field value is a valid ISO datetime.
|
|
468
|
+
*/
|
|
469
|
+
function datetime(field: String): Boolean {
|
|
470
|
+
} @@@expressionContext([ValidationRule])
|
|
395
471
|
|
|
396
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Validates a string field value is a valid url.
|
|
474
|
+
*/
|
|
475
|
+
function url(field: String): Boolean {
|
|
476
|
+
} @@@expressionContext([ValidationRule])
|
|
477
|
+
|
|
478
|
+
//////////////////////////////////////////////
|
|
479
|
+
// End validation attributes and functions
|
|
480
|
+
//////////////////////////////////////////////
|
|
481
|
+
|
|
482
|
+
/**
|
|
397
483
|
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
398
484
|
*/
|
|
399
485
|
attribute @prisma.passthrough(_ text: String)
|
|
400
486
|
|
|
401
|
-
|
|
487
|
+
/**
|
|
402
488
|
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
403
489
|
*/
|
|
404
490
|
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:crash' | '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,9 @@ 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");
|
|
39
40
|
const async_exit_hook_1 = __importDefault(require("async-exit-hook"));
|
|
40
41
|
const commander_1 = require("commander");
|
|
41
|
-
const cuid_1 = __importDefault(require("cuid"));
|
|
42
42
|
const mixpanel_1 = require("mixpanel");
|
|
43
43
|
const node_machine_id_1 = require("node-machine-id");
|
|
44
44
|
const os = __importStar(require("os"));
|
|
@@ -46,15 +46,17 @@ const sleep_promise_1 = __importDefault(require("sleep-promise"));
|
|
|
46
46
|
const cli_error_1 = require("./cli/cli-error");
|
|
47
47
|
const constants_1 = require("./constants");
|
|
48
48
|
const version_utils_1 = require("./utils/version-utils");
|
|
49
|
+
const sdk_1 = require("@zenstackhq/sdk");
|
|
49
50
|
/**
|
|
50
51
|
* Utility class for sending telemetry
|
|
51
52
|
*/
|
|
52
53
|
class Telemetry {
|
|
53
54
|
constructor() {
|
|
54
55
|
this.hostId = (0, node_machine_id_1.machineIdSync)();
|
|
55
|
-
this.sessionid = (0,
|
|
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, {
|
|
@@ -98,7 +100,7 @@ class Telemetry {
|
|
|
98
100
|
}
|
|
99
101
|
track(event, properties = {}) {
|
|
100
102
|
if (this.mixpanel) {
|
|
101
|
-
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);
|
|
102
104
|
this.mixpanel.track(event, payload);
|
|
103
105
|
}
|
|
104
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,
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAgD;AAChD,sEAAuC;AACvC,yCAA2C;AAC3C,uCAA0C;AAC1C,qDAAgD;AAChD,uCAAyB;AACzB,kEAAkC;AAClC,+CAA2C;AAC3C,2CAAuD;AACvD,yDAAmD;AACnD,yCAAmD;AAkBnD;;GAEG;AACH,MAAa,SAAS;IASlB;QAPiB,WAAM,GAAG,IAAA,+BAAa,GAAE,CAAC;QACzB,cAAS,GAAG,IAAA,gBAAQ,GAAE,CA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BACH,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"}
|
package/utils/ast-utils.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { DataModel, DataModelField, Expression } from '@zenstackhq/language/ast';
|
|
1
|
+
import { DataModel, DataModelField, Expression, Model, ModelImport } from '@zenstackhq/language/ast';
|
|
2
|
+
import { AstNode, LangiumDocuments } from 'langium';
|
|
3
|
+
import { URI } from 'vscode-uri';
|
|
4
|
+
export declare function extractDataModelsWithAllowRules(model: Model): DataModel[];
|
|
5
|
+
export declare function mergeBaseModel(model: Model): void;
|
|
2
6
|
export declare function getIdFields(dataModel: DataModel): DataModelField[];
|
|
3
|
-
export declare function isAuthInvocation(
|
|
4
|
-
export declare function isEnumFieldReference(expr: Expression): boolean;
|
|
7
|
+
export declare function isAuthInvocation(node: AstNode): boolean;
|
|
5
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[];
|