zenstack 0.6.0-pre.9 → 1.0.0-alpha.101
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 +111 -10
- package/cli/cli-error.d.ts +5 -0
- package/cli/cli-error.js +10 -0
- package/cli/cli-error.js.map +1 -0
- package/cli/cli-util.d.ts +21 -0
- package/cli/cli-util.js +239 -0
- package/cli/cli-util.js.map +1 -0
- package/cli/config.d.ts +19 -0
- package/cli/config.js +41 -0
- package/cli/config.js.map +1 -0
- package/cli/index.d.ts +16 -0
- package/cli/index.js +143 -6524
- package/cli/index.js.map +1 -0
- package/cli/plugin-runner.d.ts +14 -0
- package/cli/plugin-runner.js +146 -0
- package/cli/plugin-runner.js.map +1 -0
- package/constants.d.ts +1 -0
- package/constants.js +6 -0
- package/constants.js.map +1 -0
- package/language-server/constants.d.ts +26 -0
- package/language-server/constants.js +40 -0
- package/language-server/constants.js.map +1 -0
- package/language-server/main.d.ts +1 -0
- package/language-server/main.js +13 -6436
- package/language-server/main.js.map +1 -0
- package/language-server/types.d.ts +10 -0
- package/language-server/types.js +3 -0
- package/language-server/types.js.map +1 -0
- package/language-server/utils.d.ts +18 -0
- package/language-server/utils.js +58 -0
- package/language-server/utils.js.map +1 -0
- package/language-server/validator/attribute-validator.d.ts +9 -0
- package/language-server/validator/attribute-validator.js +11 -0
- package/language-server/validator/attribute-validator.js.map +1 -0
- package/language-server/validator/datamodel-validator.d.ts +15 -0
- package/language-server/validator/datamodel-validator.js +280 -0
- package/language-server/validator/datamodel-validator.js.map +1 -0
- package/language-server/validator/datasource-validator.d.ts +12 -0
- package/language-server/validator/datasource-validator.js +66 -0
- package/language-server/validator/datasource-validator.js.map +1 -0
- package/language-server/validator/enum-validator.d.ts +11 -0
- package/language-server/validator/enum-validator.js +28 -0
- package/language-server/validator/enum-validator.js.map +1 -0
- package/language-server/validator/expression-validator.d.ts +11 -0
- package/language-server/validator/expression-validator.js +57 -0
- package/language-server/validator/expression-validator.js.map +1 -0
- package/language-server/validator/function-invocation-validator.d.ts +11 -0
- package/language-server/validator/function-invocation-validator.js +110 -0
- package/language-server/validator/function-invocation-validator.js.map +1 -0
- package/language-server/validator/schema-validator.d.ts +10 -0
- package/language-server/validator/schema-validator.js +29 -0
- package/language-server/validator/schema-validator.js.map +1 -0
- package/language-server/validator/utils.d.ts +25 -0
- package/language-server/validator/utils.js +261 -0
- package/language-server/validator/utils.js.map +1 -0
- package/language-server/validator/zmodel-validator.d.ts +22 -0
- package/language-server/validator/zmodel-validator.js +74 -0
- package/language-server/validator/zmodel-validator.js.map +1 -0
- package/language-server/zmodel-code-action.d.ts +14 -0
- package/language-server/zmodel-code-action.js +109 -0
- package/language-server/zmodel-code-action.js.map +1 -0
- package/language-server/zmodel-formatter.d.ts +9 -0
- package/language-server/zmodel-formatter.js +76 -0
- package/language-server/zmodel-formatter.js.map +1 -0
- package/language-server/zmodel-linker.d.ts +30 -0
- package/language-server/zmodel-linker.js +375 -0
- package/language-server/zmodel-linker.js.map +1 -0
- package/language-server/zmodel-module.d.ts +41 -0
- package/language-server/zmodel-module.js +80 -0
- package/language-server/zmodel-module.js.map +1 -0
- package/language-server/zmodel-scope.d.ts +10 -0
- package/language-server/zmodel-scope.js +44 -0
- package/language-server/zmodel-scope.js.map +1 -0
- package/language-server/zmodel-workspace-manager.d.ts +12 -0
- package/language-server/zmodel-workspace-manager.js +138 -0
- package/language-server/zmodel-workspace-manager.js.map +1 -0
- package/package.json +31 -23
- package/plugins/access-policy/expression-writer.d.ts +41 -0
- package/plugins/access-policy/expression-writer.js +475 -0
- package/plugins/access-policy/expression-writer.js.map +1 -0
- package/plugins/access-policy/index.d.ts +4 -0
- package/plugins/access-policy/index.js +24 -0
- package/plugins/access-policy/index.js.map +1 -0
- package/plugins/access-policy/policy-guard-generator.d.ts +15 -0
- package/plugins/access-policy/policy-guard-generator.js +350 -0
- package/plugins/access-policy/policy-guard-generator.js.map +1 -0
- package/plugins/access-policy/typescript-expression-transformer.d.ts +28 -0
- package/plugins/access-policy/typescript-expression-transformer.js +121 -0
- package/plugins/access-policy/typescript-expression-transformer.js.map +1 -0
- package/plugins/access-policy/utils.d.ts +5 -0
- package/plugins/access-policy/utils.js +14 -0
- package/plugins/access-policy/utils.js.map +1 -0
- package/plugins/access-policy/zod-schema-generator.d.ts +12 -0
- package/plugins/access-policy/zod-schema-generator.js +157 -0
- package/plugins/access-policy/zod-schema-generator.js.map +1 -0
- package/plugins/model-meta/index.d.ts +4 -0
- package/plugins/model-meta/index.js +172 -0
- package/plugins/model-meta/index.js.map +1 -0
- package/plugins/plugin-utils.d.ts +15 -0
- package/plugins/plugin-utils.js +53 -0
- package/plugins/plugin-utils.js.map +1 -0
- package/plugins/prisma/indent-string.d.ts +4 -0
- package/plugins/prisma/indent-string.js +12 -0
- package/plugins/prisma/indent-string.js.map +1 -0
- package/plugins/prisma/index.d.ts +5 -0
- package/plugins/prisma/index.js +24 -3740
- package/plugins/prisma/index.js.map +1 -0
- package/plugins/prisma/prisma-builder.d.ts +152 -0
- package/plugins/prisma/prisma-builder.js +363 -0
- package/plugins/prisma/prisma-builder.js.map +1 -0
- package/plugins/prisma/schema-generator.d.ts +25 -0
- package/plugins/prisma/schema-generator.js +306 -0
- package/plugins/prisma/schema-generator.js.map +1 -0
- package/plugins/prisma/zmodel-code-generator.d.ts +30 -0
- package/plugins/prisma/zmodel-code-generator.js +122 -0
- package/plugins/prisma/zmodel-code-generator.js.map +1 -0
- package/plugins/zod/generator.d.ts +4 -0
- package/plugins/zod/generator.js +102 -0
- package/plugins/zod/generator.js.map +1 -0
- package/plugins/zod/index.d.ts +5 -0
- package/plugins/zod/index.js +21 -4808
- package/plugins/zod/index.js.map +1 -0
- package/plugins/zod/transformer.d.ts +67 -0
- package/plugins/zod/transformer.js +452 -0
- package/plugins/zod/transformer.js.map +1 -0
- package/plugins/zod/types.d.ts +22 -0
- package/plugins/zod/types.js +3 -0
- package/plugins/zod/types.js.map +1 -0
- package/plugins/zod/utils/removeDir.d.ts +1 -0
- package/plugins/zod/utils/removeDir.js +30 -0
- package/plugins/zod/utils/removeDir.js.map +1 -0
- package/res/prism-zmodel.js +2 -4
- package/res/starter.zmodel +51 -0
- package/res/stdlib.zmodel +194 -8
- package/telemetry.d.ts +20 -0
- package/telemetry.js +127 -0
- package/telemetry.js.map +1 -0
- package/types.d.ts +12 -0
- package/types.js +3 -0
- package/types.js.map +1 -0
- package/utils/ast-utils.d.ts +5 -0
- package/utils/ast-utils.js +49 -0
- package/utils/ast-utils.js.map +1 -0
- package/utils/exec-utils.d.ts +6 -0
- package/utils/exec-utils.js +13 -0
- package/utils/exec-utils.js.map +1 -0
- package/utils/pkg-utils.d.ts +3 -0
- package/utils/pkg-utils.js +64 -0
- package/utils/pkg-utils.js.map +1 -0
- package/utils/version-utils.d.ts +1 -0
- package/utils/version-utils.js +14 -0
- package/utils/version-utils.js.map +1 -0
- package/asset/logo-256-bg.png +0 -0
- package/asset/logo-dark-256.png +0 -0
- package/asset/logo-light-256.png +0 -0
- package/extension.js +0 -39
- package/plugins/policy-guard/index.js +0 -4289
- package/plugins/react-hooks/index.js +0 -4318
- package/plugins/trpc/index.js +0 -5386
- package/res/package.template.json +0 -9
- package/res/tsconfig.template.json +0 -17
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// This is a sample model to get you started.
|
|
2
|
+
// Learn how to model you app: https://zenstack.dev/#/modeling-your-app.
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* A sample data source using local sqlite db.
|
|
6
|
+
* See how to use a different db: https://zenstack.dev/#/zmodel-data-source.
|
|
7
|
+
*/
|
|
8
|
+
datasource db {
|
|
9
|
+
provider = 'sqlite'
|
|
10
|
+
url = 'file:./todo.db'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
generator client {
|
|
14
|
+
provider = "prisma-client-js"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* User model
|
|
19
|
+
*/
|
|
20
|
+
model User {
|
|
21
|
+
id String @id @default(cuid())
|
|
22
|
+
email String @unique @email
|
|
23
|
+
password String @password @omit @length(8, 16)
|
|
24
|
+
posts Post[]
|
|
25
|
+
|
|
26
|
+
// everybody can signup
|
|
27
|
+
@@allow('create', true)
|
|
28
|
+
|
|
29
|
+
// full access by self
|
|
30
|
+
@@allow('all', auth() == this)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* Post model
|
|
35
|
+
*/
|
|
36
|
+
model Post {
|
|
37
|
+
id String @id @default(cuid())
|
|
38
|
+
createdAt DateTime @default(now())
|
|
39
|
+
updatedAt DateTime @updatedAt
|
|
40
|
+
title String @length(1, 256)
|
|
41
|
+
content String
|
|
42
|
+
published Boolean @default(false)
|
|
43
|
+
author User? @relation(fields: [authorId], references: [id])
|
|
44
|
+
authorId String?
|
|
45
|
+
|
|
46
|
+
// allow read for all signin users
|
|
47
|
+
@@allow('read', auth() != null && published)
|
|
48
|
+
|
|
49
|
+
// full access by author
|
|
50
|
+
@@allow('all', author == auth())
|
|
51
|
+
}
|
package/res/stdlib.zmodel
CHANGED
|
@@ -39,6 +39,7 @@ enum ReferentialAction {
|
|
|
39
39
|
enum AttributeTargetField {
|
|
40
40
|
StringField
|
|
41
41
|
IntField
|
|
42
|
+
BigIntField
|
|
42
43
|
FloatField
|
|
43
44
|
DecimalField
|
|
44
45
|
BooleanField
|
|
@@ -51,41 +52,108 @@ enum AttributeTargetField {
|
|
|
51
52
|
/*
|
|
52
53
|
* Reads value from an environment variable.
|
|
53
54
|
*/
|
|
54
|
-
function env(name: String): String {
|
|
55
|
+
function env(name: String): String {
|
|
56
|
+
}
|
|
55
57
|
|
|
56
58
|
/*
|
|
57
59
|
* Gets the current login user.
|
|
58
60
|
*/
|
|
59
|
-
function auth(): Any {
|
|
61
|
+
function auth(): Any {
|
|
62
|
+
}
|
|
60
63
|
|
|
61
64
|
/*
|
|
62
65
|
* Gets current date-time (as DateTime type).
|
|
63
66
|
*/
|
|
64
|
-
function now(): DateTime {
|
|
67
|
+
function now(): DateTime {
|
|
68
|
+
}
|
|
65
69
|
|
|
66
70
|
/*
|
|
67
71
|
* Generates a globally unique identifier based on the UUID specs.
|
|
68
72
|
*/
|
|
69
|
-
function uuid(): String {
|
|
73
|
+
function uuid(): String {
|
|
74
|
+
}
|
|
70
75
|
|
|
71
76
|
/*
|
|
72
77
|
* Generates a globally unique identifier based on the CUID spec.
|
|
73
78
|
*/
|
|
74
|
-
function cuid(): String {
|
|
79
|
+
function cuid(): String {
|
|
80
|
+
}
|
|
75
81
|
|
|
76
82
|
/*
|
|
77
83
|
* Creates a sequence of integers in the underlying database and assign the incremented
|
|
78
84
|
* values to the ID values of the created records based on the sequence.
|
|
79
85
|
*/
|
|
80
|
-
function autoincrement(): Int {
|
|
86
|
+
function autoincrement(): Int {
|
|
87
|
+
}
|
|
81
88
|
|
|
82
89
|
/*
|
|
83
90
|
* Represents default values that cannot be expressed in the Prisma schema (such as random()).
|
|
84
91
|
*/
|
|
85
|
-
function dbgenerated(expr: String): Any {
|
|
92
|
+
function dbgenerated(expr: String): Any {
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets entities value before an update. Only valid when used in a "update" policy rule.
|
|
97
|
+
*/
|
|
98
|
+
function future(): Any {
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* If the field value contains the search string
|
|
103
|
+
*/
|
|
104
|
+
function contains(field: String, search: String, caseSensitive: Boolean?): Boolean {
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/*
|
|
108
|
+
* 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
|
+
*/
|
|
110
|
+
function search(field: String, search: String): Boolean {
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
* If the field value starts with the search string
|
|
115
|
+
*/
|
|
116
|
+
function startsWith(field: String, search: String): Boolean {
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* If the field value ends with the search string
|
|
121
|
+
*/
|
|
122
|
+
function endsWith(field: String, search: String): Boolean {
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/*
|
|
126
|
+
* If the field value (a list) has the given search value
|
|
127
|
+
*/
|
|
128
|
+
function has(field: Any[], search: Any): Boolean {
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* If the field value (a list) has every element of the search list
|
|
133
|
+
*/
|
|
134
|
+
function hasEvery(field: Any[], search: Any[]): Boolean {
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/*
|
|
138
|
+
* If the field value (a list) has at least one element of the search list
|
|
139
|
+
*/
|
|
140
|
+
function hasSome(field: Any[], search: Any[]): Boolean {
|
|
141
|
+
}
|
|
86
142
|
|
|
143
|
+
/*
|
|
144
|
+
* If the field value (a list) is empty
|
|
145
|
+
*/
|
|
146
|
+
function isEmpty(field: Any[]): Boolean {
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Marks an attribute to be only applicable to certain field types.
|
|
151
|
+
*/
|
|
87
152
|
attribute @@@targetField(targetField: AttributeTargetField[])
|
|
88
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Indicates an attribute is directly supported by the Prisma schema.
|
|
156
|
+
*/
|
|
89
157
|
attribute @@@prisma()
|
|
90
158
|
|
|
91
159
|
/*
|
|
@@ -103,6 +171,11 @@ attribute @default(_ value: ContextType) @@@prisma
|
|
|
103
171
|
*/
|
|
104
172
|
attribute @unique(map: String?) @@@prisma
|
|
105
173
|
|
|
174
|
+
/*
|
|
175
|
+
* Defines a multi-field ID (composite ID) on the model.
|
|
176
|
+
*/
|
|
177
|
+
attribute @@id(_ fields: FieldReference[], name: String?, map: String?) @@@prisma
|
|
178
|
+
|
|
106
179
|
/*
|
|
107
180
|
* Defines a compound unique constraint for the specified fields.
|
|
108
181
|
*/
|
|
@@ -116,7 +189,7 @@ attribute @@index(_ fields: FieldReference[], map: String?) @@@prisma
|
|
|
116
189
|
/*
|
|
117
190
|
* Defines meta information about the relation.
|
|
118
191
|
*/
|
|
119
|
-
attribute @relation(_ name: String?, fields: FieldReference[]?, references:
|
|
192
|
+
attribute @relation(_ name: String?, fields: FieldReference[]?, references: TransitiveFieldReference[]?, onDelete: ReferentialAction?, onUpdate: ReferentialAction?, map: String?) @@@prisma
|
|
120
193
|
|
|
121
194
|
/*
|
|
122
195
|
* Maps a field name or enum value from the schema to a column with a different name in the database.
|
|
@@ -128,11 +201,114 @@ attribute @map(_ name: String) @@@prisma
|
|
|
128
201
|
*/
|
|
129
202
|
attribute @@map(_ name: String) @@@prisma
|
|
130
203
|
|
|
204
|
+
/*
|
|
205
|
+
* Exclude a field from the Prisma Client (for example, a field that you do not want Prisma users to update).
|
|
206
|
+
*/
|
|
207
|
+
attribute @ignore() @@@prisma
|
|
208
|
+
|
|
209
|
+
/*
|
|
210
|
+
* Exclude a model from the Prisma Client (for example, a model that you do not want Prisma users to update).
|
|
211
|
+
*/
|
|
212
|
+
attribute @@ignore() @@@prisma
|
|
213
|
+
|
|
131
214
|
/*
|
|
132
215
|
* Automatically stores the time when a record was last updated.
|
|
133
216
|
*/
|
|
134
217
|
attribute @updatedAt() @@@targetField([DateTimeField]) @@@prisma
|
|
135
218
|
|
|
219
|
+
// String type modifiers
|
|
220
|
+
|
|
221
|
+
attribute @db.String(_ x: Int?) @@@targetField([StringField]) @@@prisma
|
|
222
|
+
attribute @db.Text() @@@targetField([StringField]) @@@prisma
|
|
223
|
+
attribute @db.NText() @@@targetField([StringField]) @@@prisma
|
|
224
|
+
attribute @db.Char(_ x: Int) @@@targetField([StringField]) @@@prisma
|
|
225
|
+
attribute @db.NChar(_ x: Int) @@@targetField([StringField]) @@@prisma
|
|
226
|
+
attribute @db.VarChar(_ x: Int) @@@targetField([StringField]) @@@prisma
|
|
227
|
+
attribute @db.NVarChar(_ x: Int) @@@targetField([StringField]) @@@prisma
|
|
228
|
+
attribute @db.CatalogSingleChar() @@@targetField([StringField]) @@@prisma
|
|
229
|
+
attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
|
|
230
|
+
attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
|
|
231
|
+
attribute @db.LongText() @@@targetField([StringField]) @@@prisma
|
|
232
|
+
attribute @db.Bit(_ x: Int?) @@@targetField([StringField, BooleanField, BytesField]) @@@prisma
|
|
233
|
+
attribute @db.VarBit(_ x: Int?) @@@targetField([StringField]) @@@prisma
|
|
234
|
+
attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
|
|
235
|
+
attribute @db.UniqueIdentifier() @@@targetField([StringField]) @@@prisma
|
|
236
|
+
attribute @db.Xml() @@@targetField([StringField]) @@@prisma
|
|
237
|
+
attribute @db.Inet() @@@targetField([StringField]) @@@prisma
|
|
238
|
+
attribute @db.Citext() @@@targetField([StringField]) @@@prisma
|
|
239
|
+
|
|
240
|
+
// Boolean type modifiers
|
|
241
|
+
|
|
242
|
+
attribute @db.Boolean() @@@targetField([BooleanField]) @@@prisma
|
|
243
|
+
attribute @db.TinyInt(_ x: Int?) @@@targetField([BooleanField]) @@@prisma
|
|
244
|
+
attribute @db.Bool() @@@targetField([BooleanField]) @@@prisma
|
|
245
|
+
|
|
246
|
+
// Int type modifiers
|
|
247
|
+
|
|
248
|
+
attribute @db.Int() @@@targetField([IntField]) @@@prisma
|
|
249
|
+
attribute @db.Integer() @@@targetField([IntField]) @@@prisma
|
|
250
|
+
attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
|
|
251
|
+
attribute @db.Oid() @@@targetField([IntField]) @@@prisma
|
|
252
|
+
attribute @db.UnsignedInt() @@@targetField([IntField]) @@@prisma
|
|
253
|
+
attribute @db.UnsignedSmallInt() @@@targetField([IntField]) @@@prisma
|
|
254
|
+
attribute @db.MediumInt() @@@targetField([IntField]) @@@prisma
|
|
255
|
+
attribute @db.UnsignedMediumInt() @@@targetField([IntField]) @@@prisma
|
|
256
|
+
attribute @db.UnsignedTinyInt() @@@targetField([IntField]) @@@prisma
|
|
257
|
+
attribute @db.Year() @@@targetField([IntField]) @@@prisma
|
|
258
|
+
attribute @db.Int4() @@@targetField([IntField]) @@@prisma
|
|
259
|
+
attribute @db.Int2() @@@targetField([IntField]) @@@prisma
|
|
260
|
+
|
|
261
|
+
// BigInt type modifiers
|
|
262
|
+
|
|
263
|
+
attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
|
|
264
|
+
attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma
|
|
265
|
+
attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
|
|
266
|
+
|
|
267
|
+
// Float/Decimal type modifiers
|
|
268
|
+
attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
269
|
+
attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
270
|
+
attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
271
|
+
attribute @db.Decimal() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
272
|
+
attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
273
|
+
attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
274
|
+
attribute @db.SmallMoney() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
275
|
+
attribute @db.Float8() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
276
|
+
attribute @db.Float4() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
277
|
+
|
|
278
|
+
// DateTime type modifiers
|
|
279
|
+
|
|
280
|
+
attribute @db.DateTime(x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
281
|
+
attribute @db.DateTime2() @@@targetField([DateTimeField]) @@@prisma
|
|
282
|
+
attribute @db.SmallDateTime() @@@targetField([DateTimeField]) @@@prisma
|
|
283
|
+
attribute @db.DateTimeOffset() @@@targetField([DateTimeField]) @@@prisma
|
|
284
|
+
attribute @db.Timestamp(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
285
|
+
attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
286
|
+
attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
|
|
287
|
+
attribute @db.Time(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
288
|
+
attribute @db.Timetz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
289
|
+
|
|
290
|
+
// Json type modifiers
|
|
291
|
+
|
|
292
|
+
attribute @db.Json() @@@targetField([JsonField]) @@@prisma
|
|
293
|
+
attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
|
|
294
|
+
|
|
295
|
+
// Bytes type modifiers
|
|
296
|
+
|
|
297
|
+
attribute @db.Bytes() @@@targetField([BytesField]) @@@prisma
|
|
298
|
+
attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
|
|
299
|
+
attribute @db.LongBlob() @@@targetField([BytesField]) @@@prisma
|
|
300
|
+
attribute @db.Binary() @@@targetField([BytesField]) @@@prisma
|
|
301
|
+
attribute @db.VarBinary() @@@targetField([BytesField]) @@@prisma
|
|
302
|
+
attribute @db.TinyBlob() @@@targetField([BytesField]) @@@prisma
|
|
303
|
+
attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
|
|
304
|
+
attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
|
|
305
|
+
attribute @db.Image() @@@targetField([BytesField]) @@@prisma
|
|
306
|
+
|
|
307
|
+
/*
|
|
308
|
+
* Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
|
|
309
|
+
*/
|
|
310
|
+
attribute @@schema(_ name: String) @@@prisma
|
|
311
|
+
|
|
136
312
|
/*
|
|
137
313
|
* Defines an access policy that allows a set of operations when the given condition is true.
|
|
138
314
|
*/
|
|
@@ -216,3 +392,13 @@ attribute @lt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
|
216
392
|
* Validates a number field is less than or equal to the given value.
|
|
217
393
|
*/
|
|
218
394
|
attribute @lte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
395
|
+
|
|
396
|
+
/*
|
|
397
|
+
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
398
|
+
*/
|
|
399
|
+
attribute @prisma.passthrough(_ text: String)
|
|
400
|
+
|
|
401
|
+
/*
|
|
402
|
+
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
403
|
+
*/
|
|
404
|
+
attribute @@prisma.passthrough(_ text: String)
|
package/telemetry.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telemetry events
|
|
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';
|
|
5
|
+
/**
|
|
6
|
+
* Utility class for sending telemetry
|
|
7
|
+
*/
|
|
8
|
+
export declare class Telemetry {
|
|
9
|
+
private readonly mixpanel;
|
|
10
|
+
private readonly hostId;
|
|
11
|
+
private readonly sessionid;
|
|
12
|
+
private readonly _os;
|
|
13
|
+
private readonly version;
|
|
14
|
+
private exitWait;
|
|
15
|
+
constructor();
|
|
16
|
+
track(event: TelemetryEvents, properties?: Record<string, unknown>): void;
|
|
17
|
+
trackSpan(startEvent: TelemetryEvents, completeEvent: TelemetryEvents, errorEvent: TelemetryEvents, properties: Record<string, unknown>, action: () => Promise<unknown> | void): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
declare const _default: Telemetry;
|
|
20
|
+
export default _default;
|
package/telemetry.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.Telemetry = void 0;
|
|
39
|
+
const async_exit_hook_1 = __importDefault(require("async-exit-hook"));
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const cuid_1 = __importDefault(require("cuid"));
|
|
42
|
+
const mixpanel_1 = require("mixpanel");
|
|
43
|
+
const node_machine_id_1 = require("node-machine-id");
|
|
44
|
+
const os = __importStar(require("os"));
|
|
45
|
+
const sleep_promise_1 = __importDefault(require("sleep-promise"));
|
|
46
|
+
const cli_error_1 = require("./cli/cli-error");
|
|
47
|
+
const constants_1 = require("./constants");
|
|
48
|
+
const version_utils_1 = require("./utils/version-utils");
|
|
49
|
+
/**
|
|
50
|
+
* Utility class for sending telemetry
|
|
51
|
+
*/
|
|
52
|
+
class Telemetry {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.hostId = (0, node_machine_id_1.machineIdSync)();
|
|
55
|
+
this.sessionid = (0, cuid_1.default)();
|
|
56
|
+
this._os = os.platform();
|
|
57
|
+
this.version = (0, version_utils_1.getVersion)();
|
|
58
|
+
this.exitWait = 200;
|
|
59
|
+
if (process.env.DO_NOT_TRACK !== '1' && constants_1.TELEMETRY_TRACKING_TOKEN) {
|
|
60
|
+
this.mixpanel = (0, mixpanel_1.init)(constants_1.TELEMETRY_TRACKING_TOKEN, {
|
|
61
|
+
geolocate: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
(0, async_exit_hook_1.default)((callback) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (this.mixpanel) {
|
|
66
|
+
// a small delay to ensure telemetry is sent
|
|
67
|
+
yield (0, sleep_promise_1.default)(this.exitWait);
|
|
68
|
+
}
|
|
69
|
+
callback();
|
|
70
|
+
}));
|
|
71
|
+
const errorHandler = (err) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
if (err instanceof cli_error_1.CliError || err instanceof commander_1.CommanderError) {
|
|
73
|
+
this.track('cli:error', {
|
|
74
|
+
message: err.message,
|
|
75
|
+
stack: err.stack,
|
|
76
|
+
});
|
|
77
|
+
if (this.mixpanel) {
|
|
78
|
+
// a small delay to ensure telemetry is sent
|
|
79
|
+
yield (0, sleep_promise_1.default)(this.exitWait);
|
|
80
|
+
}
|
|
81
|
+
// error already logged
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.error('\nAn unexpected error occurred:\n', err);
|
|
85
|
+
this.track('cli:crash', {
|
|
86
|
+
message: err.message,
|
|
87
|
+
stack: err.stack,
|
|
88
|
+
});
|
|
89
|
+
if (this.mixpanel) {
|
|
90
|
+
// a small delay to ensure telemetry is sent
|
|
91
|
+
yield (0, sleep_promise_1.default)(this.exitWait);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
process.exit(1);
|
|
95
|
+
});
|
|
96
|
+
async_exit_hook_1.default.unhandledRejectionHandler(errorHandler);
|
|
97
|
+
async_exit_hook_1.default.uncaughtExceptionHandler(errorHandler);
|
|
98
|
+
}
|
|
99
|
+
track(event, properties = {}) {
|
|
100
|
+
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);
|
|
102
|
+
this.mixpanel.track(event, payload);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
trackSpan(startEvent, completeEvent, errorEvent, properties, action) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
this.track(startEvent, properties);
|
|
108
|
+
const start = Date.now();
|
|
109
|
+
let success = true;
|
|
110
|
+
try {
|
|
111
|
+
yield Promise.resolve(action());
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
this.track(errorEvent, Object.assign({ message: err.message, stack: err.stack }, properties));
|
|
116
|
+
success = false;
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
this.track(completeEvent, Object.assign({ duration: Date.now() - start, success }, properties));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Telemetry = Telemetry;
|
|
126
|
+
exports.default = new Telemetry();
|
|
127
|
+
//# sourceMappingURL=telemetry.js.map
|
package/telemetry.js.map
ADDED
|
@@ -0,0 +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;AAiBnD;;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,MAA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B,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;AAjGD,8BAiGC;AAED,kBAAe,IAAI,SAAS,EAAE,CAAC"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Model } from '@zenstackhq/language/ast';
|
|
2
|
+
export interface Context {
|
|
3
|
+
schema: Model;
|
|
4
|
+
schemaPath: string;
|
|
5
|
+
outDir: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Generator {
|
|
8
|
+
get name(): string;
|
|
9
|
+
get startMessage(): string;
|
|
10
|
+
get successMessage(): string;
|
|
11
|
+
generate(context: Context): Promise<string[]>;
|
|
12
|
+
}
|
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DataModel, DataModelField, Expression } from '@zenstackhq/language/ast';
|
|
2
|
+
export declare function getIdFields(dataModel: DataModel): DataModelField[];
|
|
3
|
+
export declare function isAuthInvocation(expr: Expression): boolean;
|
|
4
|
+
export declare function isEnumFieldReference(expr: Expression): boolean;
|
|
5
|
+
export declare function getDataModelFieldReference(expr: Expression): DataModelField | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDataModelFieldReference = exports.isEnumFieldReference = exports.isAuthInvocation = exports.getIdFields = void 0;
|
|
4
|
+
const ast_1 = require("@zenstackhq/language/ast");
|
|
5
|
+
const utils_1 = require("../language-server/utils");
|
|
6
|
+
function getIdFields(dataModel) {
|
|
7
|
+
const fieldLevelId = dataModel.fields.find((f) => f.attributes.some((attr) => attr.decl.$refText === '@id'));
|
|
8
|
+
if (fieldLevelId) {
|
|
9
|
+
return [fieldLevelId];
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
// get model level @@id attribute
|
|
13
|
+
const modelIdAttr = dataModel.attributes.find((attr) => { var _a, _b; return ((_b = (_a = attr.decl) === null || _a === void 0 ? void 0 : _a.ref) === null || _b === void 0 ? void 0 : _b.name) === '@@id'; });
|
|
14
|
+
if (modelIdAttr) {
|
|
15
|
+
// get fields referenced in the attribute: @@id([field1, field2]])
|
|
16
|
+
if (!(0, ast_1.isArrayExpr)(modelIdAttr.args[0].value)) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const argValue = modelIdAttr.args[0].value;
|
|
20
|
+
return argValue.items
|
|
21
|
+
.filter((expr) => (0, ast_1.isReferenceExpr)(expr) && !!getDataModelFieldReference(expr))
|
|
22
|
+
.map((expr) => expr.target.ref);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
exports.getIdFields = getIdFields;
|
|
28
|
+
function isAuthInvocation(expr) {
|
|
29
|
+
var _a;
|
|
30
|
+
return (0, ast_1.isInvocationExpr)(expr) && ((_a = expr.function.ref) === null || _a === void 0 ? void 0 : _a.name) === 'auth' && (0, utils_1.isFromStdlib)(expr.function.ref);
|
|
31
|
+
}
|
|
32
|
+
exports.isAuthInvocation = isAuthInvocation;
|
|
33
|
+
function isEnumFieldReference(expr) {
|
|
34
|
+
return (0, ast_1.isReferenceExpr)(expr) && (0, ast_1.isEnumField)(expr.target.ref);
|
|
35
|
+
}
|
|
36
|
+
exports.isEnumFieldReference = isEnumFieldReference;
|
|
37
|
+
function getDataModelFieldReference(expr) {
|
|
38
|
+
if ((0, ast_1.isReferenceExpr)(expr) && (0, ast_1.isDataModelField)(expr.target.ref)) {
|
|
39
|
+
return expr.target.ref;
|
|
40
|
+
}
|
|
41
|
+
else if ((0, ast_1.isMemberAccessExpr)(expr) && (0, ast_1.isDataModelField)(expr.member.ref)) {
|
|
42
|
+
return expr.member.ref;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.getDataModelFieldReference = getDataModelFieldReference;
|
|
49
|
+
//# sourceMappingURL=ast-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../src/utils/ast-utils.ts"],"names":[],"mappings":";;;AAAA,kDAWkC;AAClC,oDAAwD;AAExD,SAAgB,WAAW,CAAC,SAAoB;IAC5C,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ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CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC;AAFD,oDAEC;AAED,SAAgB,0BAA0B,CAAC,IAAgB;IACvD,IAAI,IAAA,qBAAe,EAAC,IAAI,CAAC,IAAI,IAAA,sBAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;QAC5D,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;KAC1B;SAAM,IAAI,IAAA,wBAAkB,EAAC,IAAI,CAAC,IAAI,IAAA,sBAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;QACtE,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;KAC1B;SAAM;QACH,OAAO,SAAS,CAAC;KACpB;AACL,CAAC;AARD,gEAQC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { StdioOptions } from 'child_process';
|
|
3
|
+
/**
|
|
4
|
+
* Utility for executing command synchronously and prints outputs on current console
|
|
5
|
+
*/
|
|
6
|
+
export declare function execSync(cmd: string, stdio?: StdioOptions, env?: Record<string, string>): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execSync = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
/**
|
|
6
|
+
* Utility for executing command synchronously and prints outputs on current console
|
|
7
|
+
*/
|
|
8
|
+
function execSync(cmd, stdio = 'inherit', env) {
|
|
9
|
+
const mergedEnv = Object.assign(Object.assign({}, process.env), env);
|
|
10
|
+
(0, child_process_1.execSync)(cmd, { encoding: 'utf-8', stdio, env: mergedEnv });
|
|
11
|
+
}
|
|
12
|
+
exports.execSync = execSync;
|
|
13
|
+
//# sourceMappingURL=exec-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-utils.js","sourceRoot":"","sources":["../../src/utils/exec-utils.ts"],"names":[],"mappings":";;;AAAA,iDAAgE;AAEhE;;GAEG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,QAAsB,SAAS,EAAE,GAA4B;IAC/F,MAAM,SAAS,mCAAQ,OAAO,CAAC,GAAG,GAAK,GAAG,CAAE,CAAC;IAC7C,IAAA,wBAAK,EAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;AAC7D,CAAC;AAHD,4BAGC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare type PackageManagers = 'npm' | 'yarn' | 'pnpm';
|
|
2
|
+
export declare function installPackage(pkg: string, dev: boolean, pkgManager?: PackageManagers | undefined, tag?: string, projectPath?: string, exactVersion?: boolean): void;
|
|
3
|
+
export declare function ensurePackage(pkg: string, dev: boolean, pkgManager?: PackageManagers | undefined, tag?: string, projectPath?: string, exactVersion?: boolean): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensurePackage = exports.installPackage = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const exec_utils_1 = require("./exec-utils");
|
|
10
|
+
function findUp(names, cwd) {
|
|
11
|
+
let dir = cwd;
|
|
12
|
+
// eslint-disable-next-line no-constant-condition
|
|
13
|
+
while (true) {
|
|
14
|
+
const target = names.find((name) => fs_1.default.existsSync(path_1.default.join(dir, name)));
|
|
15
|
+
if (target)
|
|
16
|
+
return target;
|
|
17
|
+
const up = path_1.default.resolve(dir, '..');
|
|
18
|
+
if (up === dir)
|
|
19
|
+
return undefined; // it'll fail anyway
|
|
20
|
+
dir = up;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function getPackageManager(projectPath = '.') {
|
|
24
|
+
const lockFile = findUp(['yarn.lock', 'pnpm-lock.yaml', 'package-lock.json'], projectPath);
|
|
25
|
+
if (!lockFile) {
|
|
26
|
+
// default use npm
|
|
27
|
+
return 'npm';
|
|
28
|
+
}
|
|
29
|
+
switch (path_1.default.basename(lockFile)) {
|
|
30
|
+
case 'yarn.lock':
|
|
31
|
+
return 'yarn';
|
|
32
|
+
case 'pnpm-lock.yaml':
|
|
33
|
+
return 'pnpm';
|
|
34
|
+
default:
|
|
35
|
+
return 'npm';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function installPackage(pkg, dev, pkgManager = undefined, tag = 'latest', projectPath = '.', exactVersion = true) {
|
|
39
|
+
const manager = pkgManager !== null && pkgManager !== void 0 ? pkgManager : getPackageManager(projectPath);
|
|
40
|
+
console.log(`Installing package "${pkg}@${tag}" with ${manager}`);
|
|
41
|
+
switch (manager) {
|
|
42
|
+
case 'yarn':
|
|
43
|
+
(0, exec_utils_1.execSync)(`yarn --cwd "${projectPath}" add ${exactVersion ? '--exact' : ''} ${pkg}@${tag} ${dev ? ' --dev' : ''} --ignore-engines`);
|
|
44
|
+
break;
|
|
45
|
+
case 'pnpm':
|
|
46
|
+
(0, exec_utils_1.execSync)(`pnpm add -C "${projectPath}" ${exactVersion ? '--save-exact' : ''} ${dev ? ' --save-dev' : ''} ${pkg}@${tag}`);
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
(0, exec_utils_1.execSync)(`npm install --prefix "${projectPath}" ${exactVersion ? '--save-exact' : ''} ${dev ? ' --save-dev' : ''} ${pkg}@${tag}`);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.installPackage = installPackage;
|
|
54
|
+
function ensurePackage(pkg, dev, pkgManager = undefined, tag = 'latest', projectPath = '.', exactVersion = false) {
|
|
55
|
+
const resolvePath = path_1.default.resolve(projectPath);
|
|
56
|
+
try {
|
|
57
|
+
require.resolve(pkg, { paths: [resolvePath] });
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
installPackage(pkg, dev, pkgManager, tag, resolvePath, exactVersion);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ensurePackage = ensurePackage;
|
|
64
|
+
//# sourceMappingURL=pkg-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkg-utils.js","sourceRoot":"","sources":["../../src/utils/pkg-utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,6CAAwC;AAIxC,SAAS,MAAM,CAAC,KAAe,EAAE,GAAW;IACxC,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,iDAAiD;IACjD,OAAO,IAAI,EAAE;QACT,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACzE,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAE1B,MAAM,EAAE,GAAG,cAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACnC,IAAI,EAAE,KAAK,GAAG;YAAE,OAAO,SAAS,CAAC,CAAC,oBAAoB;QACtD,GAAG,GAAG,EAAE,CAAC;KACZ;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAW,GAAG,GAAG;IACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,CAAC,EAAE,WAAW,CAAC,CAAC;IAE3F,IAAI,CAAC,QAAQ,EAAE;QACX,kBAAkB;QAClB,OAAO,KAAK,CAAC;KAChB;IAED,QAAQ,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAC7B,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