zenstack 1.0.0 → 1.0.16
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/LICENSE +1 -1
- package/README.md +126 -1
- package/bin/cli +3 -0
- package/bin/post-install.js +24 -0
- 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 +18 -0
- package/cli/cli-util.js +143 -0
- package/cli/cli-util.js.map +1 -0
- package/cli/index.d.ts +15 -0
- package/cli/index.js +121 -0
- package/cli/index.js.map +1 -0
- package/cli/plugin-runner.d.ts +14 -0
- package/cli/plugin-runner.js +145 -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 +15 -0
- package/language-server/constants.js +20 -0
- package/language-server/constants.js.map +1 -0
- package/language-server/main.d.ts +1 -0
- package/language-server/main.js +13 -0
- 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 +278 -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 +10 -0
- package/language-server/validator/expression-validator.js +30 -0
- package/language-server/validator/expression-validator.js.map +1 -0
- package/language-server/validator/schema-validator.d.ts +10 -0
- package/language-server/validator/schema-validator.js +28 -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 +257 -0
- package/language-server/validator/utils.js.map +1 -0
- package/language-server/validator/zmodel-validator.d.ts +21 -0
- package/language-server/validator/zmodel-validator.js +69 -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 +93 -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 +29 -0
- package/language-server/zmodel-linker.js +366 -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 +8 -0
- package/language-server/zmodel-workspace-manager.js +37 -0
- package/language-server/zmodel-workspace-manager.js.map +1 -0
- package/package.json +133 -8
- package/plugins/access-policy/expression-writer.d.ts +39 -0
- package/plugins/access-policy/expression-writer.js +361 -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 +349 -0
- package/plugins/access-policy/policy-guard-generator.js.map +1 -0
- package/plugins/access-policy/typescript-expression-transformer.d.ts +26 -0
- package/plugins/access-policy/typescript-expression-transformer.js +111 -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 +158 -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 +168 -0
- package/plugins/model-meta/index.js.map +1 -0
- package/plugins/plugin-utils.d.ts +16 -0
- package/plugins/plugin-utils.js +54 -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 +4 -0
- package/plugins/prisma/index.js +24 -0
- 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 +292 -0
- package/plugins/prisma/schema-generator.js.map +1 -0
- package/plugins/prisma/zmodel-code-generator.d.ts +28 -0
- package/plugins/prisma/zmodel-code-generator.js +114 -0
- package/plugins/prisma/zmodel-code-generator.js.map +1 -0
- package/res/prism-zmodel.js +20 -0
- package/res/starter.zmodel +51 -0
- package/res/stdlib.zmodel +346 -0
- package/telemetry.d.ts +20 -0
- package/telemetry.js +119 -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 +16 -0
- package/utils/ast-utils.js +85 -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 +46 -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/.vscode/extensions.json +0 -7
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -4
- package/packages/internal/jest.config.ts +0 -32
- package/packages/internal/package.json +0 -42
- package/packages/internal/src/constants.ts +0 -1
- package/packages/internal/src/handler/data/guard-utils.ts +0 -7
- package/packages/internal/src/handler/data/handler.ts +0 -415
- package/packages/internal/src/handler/data/query-processor.ts +0 -504
- package/packages/internal/src/handler/index.ts +0 -1
- package/packages/internal/src/handler/types.ts +0 -20
- package/packages/internal/src/index.ts +0 -3
- package/packages/internal/src/request-handler.ts +0 -27
- package/packages/internal/src/request.ts +0 -101
- package/packages/internal/src/types.ts +0 -40
- package/packages/internal/tests/query-processor.test.ts +0 -172
- package/packages/internal/tsconfig.json +0 -21
- package/packages/runtime/auth.d.ts +0 -1
- package/packages/runtime/auth.js +0 -3
- package/packages/runtime/hooks.d.ts +0 -10
- package/packages/runtime/hooks.js +0 -3
- package/packages/runtime/index.d.ts +0 -3
- package/packages/runtime/index.js +0 -1
- package/packages/runtime/package-lock.json +0 -512
- package/packages/runtime/package.json +0 -16
- package/packages/runtime/server.d.ts +0 -1
- package/packages/runtime/server.js +0 -3
- package/packages/runtime/types.d.ts +0 -1
- package/packages/runtime/types.js +0 -3
- package/packages/schema/.eslintrc.json +0 -13
- package/packages/schema/.vscodeignore +0 -4
- package/packages/schema/asset/logo-dark.png +0 -0
- package/packages/schema/asset/logo-light.png +0 -0
- package/packages/schema/bin/cli +0 -3
- package/packages/schema/jest.config.ts +0 -32
- package/packages/schema/langium-config.json +0 -14
- package/packages/schema/langium-quickstart.md +0 -41
- package/packages/schema/language-configuration.json +0 -30
- package/packages/schema/package.json +0 -96
- package/packages/schema/src/cli/cli-util.ts +0 -80
- package/packages/schema/src/cli/index.ts +0 -64
- package/packages/schema/src/extension.ts +0 -76
- package/packages/schema/src/generator/constants.ts +0 -5
- package/packages/schema/src/generator/index.ts +0 -92
- package/packages/schema/src/generator/next-auth/index.ts +0 -197
- package/packages/schema/src/generator/package.template.json +0 -9
- package/packages/schema/src/generator/prisma/expression-writer.ts +0 -352
- package/packages/schema/src/generator/prisma/index.ts +0 -32
- package/packages/schema/src/generator/prisma/plain-expression-builder.ts +0 -91
- package/packages/schema/src/generator/prisma/prisma-builder.ts +0 -366
- package/packages/schema/src/generator/prisma/query-gard-generator.ts +0 -208
- package/packages/schema/src/generator/prisma/schema-generator.ts +0 -300
- package/packages/schema/src/generator/react-hooks/index.ts +0 -181
- package/packages/schema/src/generator/service/index.ts +0 -107
- package/packages/schema/src/generator/tsconfig.template.json +0 -17
- package/packages/schema/src/generator/types.ts +0 -17
- package/packages/schema/src/generator/utils.ts +0 -9
- package/packages/schema/src/language-server/generated/ast.ts +0 -603
- package/packages/schema/src/language-server/generated/grammar.ts +0 -2190
- package/packages/schema/src/language-server/generated/module.ts +0 -24
- package/packages/schema/src/language-server/main.ts +0 -12
- package/packages/schema/src/language-server/stdlib.zmodel +0 -22
- package/packages/schema/src/language-server/types.ts +0 -9
- package/packages/schema/src/language-server/zmodel-index.ts +0 -33
- package/packages/schema/src/language-server/zmodel-linker.ts +0 -409
- package/packages/schema/src/language-server/zmodel-module.ts +0 -90
- package/packages/schema/src/language-server/zmodel-scope.ts +0 -21
- package/packages/schema/src/language-server/zmodel-validator.ts +0 -35
- package/packages/schema/src/language-server/zmodel.langium +0 -186
- package/packages/schema/src/utils/exec-utils.ts +0 -5
- package/packages/schema/src/utils/indent-string.ts +0 -6
- package/packages/schema/syntaxes/zmodel.json +0 -57
- package/packages/schema/syntaxes/zmodel.tmLanguage.json +0 -57
- package/packages/schema/tests/generator/expression-writer.test.ts +0 -676
- package/packages/schema/tests/generator/prisma-builder.test.ts +0 -138
- package/packages/schema/tests/schema/parser.test.ts +0 -423
- package/packages/schema/tests/schema/sample-todo.test.ts +0 -14
- package/packages/schema/tests/utils.ts +0 -38
- package/packages/schema/tsconfig.json +0 -23
- package/pnpm-workspace.yaml +0 -3
- package/samples/todo/.env +0 -2
- package/samples/todo/.eslintrc.json +0 -3
- package/samples/todo/.vscode/launch.json +0 -11
- package/samples/todo/README.md +0 -34
- package/samples/todo/components/AuthGuard.tsx +0 -17
- package/samples/todo/components/Avatar.tsx +0 -22
- package/samples/todo/components/BreadCrumb.tsx +0 -44
- package/samples/todo/components/ManageMembers.tsx +0 -134
- package/samples/todo/components/NavBar.tsx +0 -57
- package/samples/todo/components/SpaceMembers.tsx +0 -76
- package/samples/todo/components/Spaces.tsx +0 -28
- package/samples/todo/components/TimeInfo.tsx +0 -17
- package/samples/todo/components/Todo.tsx +0 -72
- package/samples/todo/components/TodoList.tsx +0 -77
- package/samples/todo/lib/context.ts +0 -31
- package/samples/todo/next.config.js +0 -10
- package/samples/todo/package-lock.json +0 -7527
- package/samples/todo/package.json +0 -45
- package/samples/todo/pages/_app.tsx +0 -50
- package/samples/todo/pages/api/auth/[...nextauth].ts +0 -83
- package/samples/todo/pages/api/zenstack/[...path].ts +0 -16
- package/samples/todo/pages/create-space.tsx +0 -114
- package/samples/todo/pages/index.tsx +0 -32
- package/samples/todo/pages/space/[slug]/[listId]/index.tsx +0 -88
- package/samples/todo/pages/space/[slug]/index.tsx +0 -169
- package/samples/todo/postcss.config.js +0 -6
- package/samples/todo/public/avatar.jpg +0 -0
- package/samples/todo/public/favicon.ico +0 -0
- package/samples/todo/public/logo.png +0 -0
- package/samples/todo/public/vercel.svg +0 -4
- package/samples/todo/styles/globals.css +0 -7
- package/samples/todo/tailwind.config.js +0 -11
- package/samples/todo/tsconfig.json +0 -28
- package/samples/todo/types/next-auth.d.ts +0 -14
- package/samples/todo/types/next.d.ts +0 -16
- package/samples/todo/zenstack/migrations/20221014084317_init/migration.sql +0 -153
- package/samples/todo/zenstack/migrations/20221020094651_upate_cli/migration.sql +0 -23
- package/samples/todo/zenstack/migrations/migration_lock.toml +0 -3
- package/samples/todo/zenstack/schema.prisma +0 -126
- package/samples/todo/zenstack/schema.zmodel +0 -161
- package/tests/integration/jest.config.ts +0 -16
- package/tests/integration/package-lock.json +0 -1081
- package/tests/integration/package.json +0 -27
- package/tests/integration/tests/operation-coverate.test.ts +0 -563
- package/tests/integration/tests/operations.zmodel +0 -69
- package/tests/integration/tests/todo-e2e.test.ts +0 -577
- package/tests/integration/tests/todo.zmodel +0 -123
- package/tests/integration/tests/tsconfig.template.json +0 -10
- package/tests/integration/tests/utils.ts +0 -133
- package/tests/integration/tsconfig.json +0 -10
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Enum representing referential integrity related actions
|
|
3
|
+
*/
|
|
4
|
+
enum ReferentialAction {
|
|
5
|
+
/*
|
|
6
|
+
* Used with "onDelete": deleting a referenced record will trigger the deletion of referencing record.
|
|
7
|
+
* Used with "onUpdate": updates the relation scalar fields if the referenced scalar fields of the dependent record are updated.
|
|
8
|
+
*/
|
|
9
|
+
Cascade
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Used with "onDelete": prevents the deletion if any referencing records exist.
|
|
13
|
+
* Used with "onUpdate": prevents the identifier of a referenced record from being changed.
|
|
14
|
+
*/
|
|
15
|
+
Restrict
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Similar to 'Restrict', the difference between the two is dependent on the database being used.
|
|
19
|
+
* See details: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions#noaction
|
|
20
|
+
*/
|
|
21
|
+
NoAction
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* Used with "onDelete": the scalar field of the referencing object will be set to NULL.
|
|
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
|
+
*/
|
|
27
|
+
SetNull
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Used with "onDelete": the scalar field of the referencing object will be set to the fields default value.
|
|
31
|
+
* Used with "onUpdate": the scalar field of the referencing object will be set to the fields default value.
|
|
32
|
+
*/
|
|
33
|
+
SetDefault
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Enum representing all possible field types
|
|
38
|
+
*/
|
|
39
|
+
enum AttributeTargetField {
|
|
40
|
+
StringField
|
|
41
|
+
IntField
|
|
42
|
+
BigIntField
|
|
43
|
+
FloatField
|
|
44
|
+
DecimalField
|
|
45
|
+
BooleanField
|
|
46
|
+
DateTimeField
|
|
47
|
+
JsonField
|
|
48
|
+
BytesField
|
|
49
|
+
ModelField
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Reads value from an environment variable.
|
|
54
|
+
*/
|
|
55
|
+
function env(name: String): String {
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Gets the current login user.
|
|
60
|
+
*/
|
|
61
|
+
function auth(): Any {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* Gets current date-time (as DateTime type).
|
|
66
|
+
*/
|
|
67
|
+
function now(): DateTime {
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* Generates a globally unique identifier based on the UUID specs.
|
|
72
|
+
*/
|
|
73
|
+
function uuid(): String {
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* Generates a globally unique identifier based on the CUID spec.
|
|
78
|
+
*/
|
|
79
|
+
function cuid(): String {
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* Creates a sequence of integers in the underlying database and assign the incremented
|
|
84
|
+
* values to the ID values of the created records based on the sequence.
|
|
85
|
+
*/
|
|
86
|
+
function autoincrement(): Int {
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* Represents default values that cannot be expressed in the Prisma schema (such as random()).
|
|
91
|
+
*/
|
|
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
|
+
* Marks an attribute to be only applicable to certain field types.
|
|
103
|
+
*/
|
|
104
|
+
attribute @@@targetField(targetField: AttributeTargetField[])
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Indicates an attribute is directly supported by the Prisma schema.
|
|
108
|
+
*/
|
|
109
|
+
attribute @@@prisma()
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
* Defines an ID on the model.
|
|
113
|
+
*/
|
|
114
|
+
attribute @id(map: String?) @@@prisma
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
* Defines a default value for a field.
|
|
118
|
+
*/
|
|
119
|
+
attribute @default(_ value: ContextType) @@@prisma
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
* Defines a unique constraint for this field.
|
|
123
|
+
*/
|
|
124
|
+
attribute @unique(map: String?) @@@prisma
|
|
125
|
+
|
|
126
|
+
/*
|
|
127
|
+
* Defines a multi-field ID (composite ID) on the model.
|
|
128
|
+
*/
|
|
129
|
+
attribute @@id(_ fields: FieldReference[], name: String?, map: String?) @@@prisma
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Defines a compound unique constraint for the specified fields.
|
|
133
|
+
*/
|
|
134
|
+
attribute @@unique(_ fields: FieldReference[], name: String?, map: String?) @@@prisma
|
|
135
|
+
|
|
136
|
+
/*
|
|
137
|
+
* Defines an index in the database.
|
|
138
|
+
*/
|
|
139
|
+
attribute @@index(_ fields: FieldReference[], map: String?) @@@prisma
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* Defines meta information about the relation.
|
|
143
|
+
*/
|
|
144
|
+
attribute @relation(_ name: String?, fields: FieldReference[]?, references: TransitiveFieldReference[]?, onDelete: ReferentialAction?, onUpdate: ReferentialAction?, map: String?) @@@prisma
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
* Maps a field name or enum value from the schema to a column with a different name in the database.
|
|
148
|
+
*/
|
|
149
|
+
attribute @map(_ name: String) @@@prisma
|
|
150
|
+
|
|
151
|
+
/*
|
|
152
|
+
* 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
|
+
*/
|
|
154
|
+
attribute @@map(_ name: String) @@@prisma
|
|
155
|
+
|
|
156
|
+
/*
|
|
157
|
+
* Automatically stores the time when a record was last updated.
|
|
158
|
+
*/
|
|
159
|
+
attribute @updatedAt() @@@targetField([DateTimeField]) @@@prisma
|
|
160
|
+
|
|
161
|
+
// String type modifiers
|
|
162
|
+
|
|
163
|
+
attribute @db.String(_ x: Int?) @@@targetField([StringField]) @@@prisma
|
|
164
|
+
attribute @db.Text() @@@targetField([StringField]) @@@prisma
|
|
165
|
+
attribute @db.NText() @@@targetField([StringField]) @@@prisma
|
|
166
|
+
attribute @db.Char(_ x: Int) @@@targetField([StringField]) @@@prisma
|
|
167
|
+
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
|
|
170
|
+
attribute @db.CatalogSingleChar() @@@targetField([StringField]) @@@prisma
|
|
171
|
+
attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
|
|
172
|
+
attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
|
|
173
|
+
attribute @db.LongText() @@@targetField([StringField]) @@@prisma
|
|
174
|
+
attribute @db.Bit(_ x: Int?) @@@targetField([StringField, BooleanField, BytesField]) @@@prisma
|
|
175
|
+
attribute @db.VarBit(_ x: Int?) @@@targetField([StringField]) @@@prisma
|
|
176
|
+
attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
|
|
177
|
+
attribute @db.UniqueIdentifier() @@@targetField([StringField]) @@@prisma
|
|
178
|
+
attribute @db.Xml() @@@targetField([StringField]) @@@prisma
|
|
179
|
+
attribute @db.Inet() @@@targetField([StringField]) @@@prisma
|
|
180
|
+
attribute @db.Citext() @@@targetField([StringField]) @@@prisma
|
|
181
|
+
|
|
182
|
+
// Boolean type modifiers
|
|
183
|
+
|
|
184
|
+
attribute @db.Boolean() @@@targetField([BooleanField]) @@@prisma
|
|
185
|
+
attribute @db.TinyInt(_ x: Int?) @@@targetField([BooleanField]) @@@prisma
|
|
186
|
+
attribute @db.Bool() @@@targetField([BooleanField]) @@@prisma
|
|
187
|
+
|
|
188
|
+
// Int type modifiers
|
|
189
|
+
|
|
190
|
+
attribute @db.Int() @@@targetField([IntField]) @@@prisma
|
|
191
|
+
attribute @db.Integer() @@@targetField([IntField]) @@@prisma
|
|
192
|
+
attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
|
|
193
|
+
attribute @db.Oid() @@@targetField([IntField]) @@@prisma
|
|
194
|
+
attribute @db.UnsignedInt() @@@targetField([IntField]) @@@prisma
|
|
195
|
+
attribute @db.UnsignedSmallInt() @@@targetField([IntField]) @@@prisma
|
|
196
|
+
attribute @db.MediumInt() @@@targetField([IntField]) @@@prisma
|
|
197
|
+
attribute @db.UnsignedMediumInt() @@@targetField([IntField]) @@@prisma
|
|
198
|
+
attribute @db.UnsignedTinyInt() @@@targetField([IntField]) @@@prisma
|
|
199
|
+
attribute @db.Year() @@@targetField([IntField]) @@@prisma
|
|
200
|
+
attribute @db.Int4() @@@targetField([IntField]) @@@prisma
|
|
201
|
+
attribute @db.Int2() @@@targetField([IntField]) @@@prisma
|
|
202
|
+
|
|
203
|
+
// BigInt type modifiers
|
|
204
|
+
|
|
205
|
+
attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
|
|
206
|
+
attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma
|
|
207
|
+
attribute @db.Int8() @@@targetField([BigIntField]) @@@prisma
|
|
208
|
+
|
|
209
|
+
// Float/Decimal type modifiers
|
|
210
|
+
attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
211
|
+
attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
212
|
+
attribute @db.Float() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
213
|
+
attribute @db.Decimal() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
214
|
+
attribute @db.Double() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
215
|
+
attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
216
|
+
attribute @db.SmallMoney() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
217
|
+
attribute @db.Float8() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
218
|
+
attribute @db.Float4() @@@targetField([FloatField, DecimalField]) @@@prisma
|
|
219
|
+
|
|
220
|
+
// DateTime type modifiers
|
|
221
|
+
|
|
222
|
+
attribute @db.DateTime(x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
223
|
+
attribute @db.DateTime2() @@@targetField([DateTimeField]) @@@prisma
|
|
224
|
+
attribute @db.SmallDateTime() @@@targetField([DateTimeField]) @@@prisma
|
|
225
|
+
attribute @db.DateTimeOffset() @@@targetField([DateTimeField]) @@@prisma
|
|
226
|
+
attribute @db.Timestamp(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
227
|
+
attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
228
|
+
attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
|
|
229
|
+
attribute @db.Time(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
230
|
+
attribute @db.Timetz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
|
|
231
|
+
|
|
232
|
+
// Json type modifiers
|
|
233
|
+
|
|
234
|
+
attribute @db.Json() @@@targetField([JsonField]) @@@prisma
|
|
235
|
+
attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
|
|
236
|
+
|
|
237
|
+
// Bytes type modifiers
|
|
238
|
+
|
|
239
|
+
attribute @db.Bytes() @@@targetField([BytesField]) @@@prisma
|
|
240
|
+
attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
|
|
241
|
+
attribute @db.LongBlob() @@@targetField([BytesField]) @@@prisma
|
|
242
|
+
attribute @db.Binary() @@@targetField([BytesField]) @@@prisma
|
|
243
|
+
attribute @db.VarBinary() @@@targetField([BytesField]) @@@prisma
|
|
244
|
+
attribute @db.TinyBlob() @@@targetField([BytesField]) @@@prisma
|
|
245
|
+
attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
|
|
246
|
+
attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma
|
|
247
|
+
attribute @db.Image() @@@targetField([BytesField]) @@@prisma
|
|
248
|
+
|
|
249
|
+
/*
|
|
250
|
+
* Specifies the schema to use in a multi-schema database. https://www.prisma.io/docs/guides/database/multi-schema.
|
|
251
|
+
*/
|
|
252
|
+
attribute @@schema(_ name: String) @@@prisma
|
|
253
|
+
|
|
254
|
+
/*
|
|
255
|
+
* Defines an access policy that allows a set of operations when the given condition is true.
|
|
256
|
+
*/
|
|
257
|
+
attribute @@allow(_ operation: String, _ condition: Boolean)
|
|
258
|
+
|
|
259
|
+
/*
|
|
260
|
+
* Defines an access policy that denies a set of operations when the given condition is true.
|
|
261
|
+
*/
|
|
262
|
+
attribute @@deny(_ operation: String, _ condition: Boolean)
|
|
263
|
+
|
|
264
|
+
/*
|
|
265
|
+
* Indicates that the field is a password field and needs to be hashed before persistence.
|
|
266
|
+
*
|
|
267
|
+
* ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
|
|
268
|
+
* to configure the cost of hashing, or use `salt` parameter to provide an explicit salt.
|
|
269
|
+
* By default, salt length of 12 is used.
|
|
270
|
+
*
|
|
271
|
+
* @see https://www.npmjs.com/package/bcryptjs for details
|
|
272
|
+
*
|
|
273
|
+
* @saltLength: length of salt to use (cost factor for the hash function)
|
|
274
|
+
* @salt: salt to use (a pregenerated valid salt)
|
|
275
|
+
*/
|
|
276
|
+
attribute @password(saltLength: Int?, salt: String?) @@@targetField([StringField])
|
|
277
|
+
|
|
278
|
+
/*
|
|
279
|
+
* Indicates that the field should be omitted when read from the generated services.
|
|
280
|
+
*/
|
|
281
|
+
attribute @omit()
|
|
282
|
+
|
|
283
|
+
/*
|
|
284
|
+
* Validates length of a string field.
|
|
285
|
+
*/
|
|
286
|
+
attribute @length(_ min: Int?, _ max: Int?) @@@targetField([StringField])
|
|
287
|
+
|
|
288
|
+
/*
|
|
289
|
+
* Validates a string field value matches a regex.
|
|
290
|
+
*/
|
|
291
|
+
attribute @regex(_ regex: String) @@@targetField([StringField])
|
|
292
|
+
|
|
293
|
+
/*
|
|
294
|
+
* Validates a string field value starts with the given text.
|
|
295
|
+
*/
|
|
296
|
+
attribute @startsWith(_ text: String) @@@targetField([StringField])
|
|
297
|
+
|
|
298
|
+
/*
|
|
299
|
+
* Validates a string field value ends with the given text.
|
|
300
|
+
*/
|
|
301
|
+
attribute @endsWith(_ text: String) @@@targetField([StringField])
|
|
302
|
+
|
|
303
|
+
/*
|
|
304
|
+
* Validates a string field value is a valid email address.
|
|
305
|
+
*/
|
|
306
|
+
attribute @email() @@@targetField([StringField])
|
|
307
|
+
|
|
308
|
+
/*
|
|
309
|
+
* Validates a string field value is a valid ISO datetime.
|
|
310
|
+
*/
|
|
311
|
+
attribute @datetime() @@@targetField([StringField])
|
|
312
|
+
|
|
313
|
+
/*
|
|
314
|
+
* Validates a string field value is a valid url.
|
|
315
|
+
*/
|
|
316
|
+
attribute @url() @@@targetField([StringField])
|
|
317
|
+
|
|
318
|
+
/*
|
|
319
|
+
* Validates a number field is greater than the given value.
|
|
320
|
+
*/
|
|
321
|
+
attribute @gt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
322
|
+
|
|
323
|
+
/*
|
|
324
|
+
* Validates a number field is greater than or equal to the given value.
|
|
325
|
+
*/
|
|
326
|
+
attribute @gte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
327
|
+
|
|
328
|
+
/*
|
|
329
|
+
* Validates a number field is less than the given value.
|
|
330
|
+
*/
|
|
331
|
+
attribute @lt(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
332
|
+
|
|
333
|
+
/*
|
|
334
|
+
* Validates a number field is less than or equal to the given value.
|
|
335
|
+
*/
|
|
336
|
+
attribute @lte(_ value: Int) @@@targetField([IntField, FloatField, DecimalField])
|
|
337
|
+
|
|
338
|
+
/*
|
|
339
|
+
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
340
|
+
*/
|
|
341
|
+
attribute @prisma.passthrough(_ text: String)
|
|
342
|
+
|
|
343
|
+
/*
|
|
344
|
+
* A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema.
|
|
345
|
+
*/
|
|
346
|
+
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: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,119 @@
|
|
|
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
|
+
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
|
+
if (err instanceof cli_error_1.CliError || err instanceof commander_1.CommanderError) {
|
|
81
|
+
// error already logged
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.error('\nAn unexpected error occurred:\n', err);
|
|
85
|
+
}
|
|
86
|
+
process.exit(1);
|
|
87
|
+
});
|
|
88
|
+
async_exit_hook_1.default.unhandledRejectionHandler(errorHandler);
|
|
89
|
+
async_exit_hook_1.default.uncaughtExceptionHandler(errorHandler);
|
|
90
|
+
}
|
|
91
|
+
track(event, properties = {}) {
|
|
92
|
+
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);
|
|
94
|
+
this.mixpanel.track(event, payload);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
trackSpan(startEvent, completeEvent, errorEvent, properties, action) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
this.track(startEvent, properties);
|
|
100
|
+
const start = Date.now();
|
|
101
|
+
let success = true;
|
|
102
|
+
try {
|
|
103
|
+
yield Promise.resolve(action());
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
this.track(errorEvent, Object.assign({ message: err.message, stack: err.stack }, properties));
|
|
108
|
+
success = false;
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
this.track(completeEvent, Object.assign({ duration: Date.now() - start, success }, properties));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.Telemetry = Telemetry;
|
|
118
|
+
exports.default = new Telemetry();
|
|
119
|
+
//# 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;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,O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BACA,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;AA1FD,8BA0FC;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,16 @@
|
|
|
1
|
+
import { DataModel, DataModelAttribute, Expression, Model } from '@zenstackhq/language/ast';
|
|
2
|
+
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;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAuthInvocation = exports.getIdField = exports.VALIDATION_ATTRIBUTES = exports.analyzePolicies = exports.extractDataModelsWithAllowRules = void 0;
|
|
4
|
+
const ast_1 = require("@zenstackhq/language/ast");
|
|
5
|
+
const sdk_1 = require("@zenstackhq/sdk");
|
|
6
|
+
const utils_1 = require("../language-server/utils");
|
|
7
|
+
function extractDataModelsWithAllowRules(model) {
|
|
8
|
+
return model.declarations.filter((d) => (0, ast_1.isDataModel)(d) && d.attributes.some((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@@allow'; }));
|
|
9
|
+
}
|
|
10
|
+
exports.extractDataModelsWithAllowRules = extractDataModelsWithAllowRules;
|
|
11
|
+
function analyzePolicies(dataModel) {
|
|
12
|
+
const allows = dataModel.attributes.filter((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@@allow'; });
|
|
13
|
+
const denies = dataModel.attributes.filter((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@@deny'; });
|
|
14
|
+
const create = toStaticPolicy('create', allows, denies);
|
|
15
|
+
const read = toStaticPolicy('read', allows, denies);
|
|
16
|
+
const update = toStaticPolicy('update', allows, denies);
|
|
17
|
+
const del = toStaticPolicy('delete', allows, denies);
|
|
18
|
+
const hasFieldValidation = dataModel.fields.some((field) => field.attributes.some((attr) => exports.VALIDATION_ATTRIBUTES.includes(attr.decl.$refText)));
|
|
19
|
+
return {
|
|
20
|
+
allows,
|
|
21
|
+
denies,
|
|
22
|
+
create,
|
|
23
|
+
read,
|
|
24
|
+
update,
|
|
25
|
+
delete: del,
|
|
26
|
+
allowAll: create === true && read === true && update === true && del === true,
|
|
27
|
+
denyAll: create === false && read === false && update === false && del === false,
|
|
28
|
+
hasFieldValidation,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.analyzePolicies = analyzePolicies;
|
|
32
|
+
function toStaticPolicy(operation, allows, denies) {
|
|
33
|
+
const filteredDenies = forOperation(operation, denies);
|
|
34
|
+
if (filteredDenies.some((rule) => (0, sdk_1.getLiteral)(rule.args[1].value) === true)) {
|
|
35
|
+
// any constant true deny rule
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const filteredAllows = forOperation(operation, allows);
|
|
39
|
+
if (filteredAllows.length === 0) {
|
|
40
|
+
// no allow rule
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (filteredDenies.length === 0 &&
|
|
44
|
+
filteredAllows.some((rule) => (0, sdk_1.getLiteral)(rule.args[1].value) === true)) {
|
|
45
|
+
// any constant true allow rule
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
function forOperation(operation, rules) {
|
|
51
|
+
return rules.filter((rule) => {
|
|
52
|
+
const ops = (0, sdk_1.getLiteral)(rule.args[0].value);
|
|
53
|
+
if (!ops) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (ops === 'all') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
const splitOps = ops.split(',').map((p) => p.trim());
|
|
60
|
+
return splitOps.includes(operation);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.VALIDATION_ATTRIBUTES = [
|
|
64
|
+
'@length',
|
|
65
|
+
'@regex',
|
|
66
|
+
'@startsWith',
|
|
67
|
+
'@endsWith',
|
|
68
|
+
'@email',
|
|
69
|
+
'@url',
|
|
70
|
+
'@datetime',
|
|
71
|
+
'@gt',
|
|
72
|
+
'@gte',
|
|
73
|
+
'@lt',
|
|
74
|
+
'@lte',
|
|
75
|
+
];
|
|
76
|
+
function getIdField(dataModel) {
|
|
77
|
+
return dataModel.fields.find((f) => f.attributes.some((attr) => attr.decl.$refText === '@id'));
|
|
78
|
+
}
|
|
79
|
+
exports.getIdField = getIdField;
|
|
80
|
+
function isAuthInvocation(expr) {
|
|
81
|
+
var _a;
|
|
82
|
+
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);
|
|
83
|
+
}
|
|
84
|
+
exports.isAuthInvocation = isAuthInvocation;
|
|
85
|
+
//# 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,kDAOkC;AAElC,yCAA6C;AAC7C,oDAAwD;AAExD,SAAgB,+BAA+B,CAAC,KAAY;IACxD,OAAO,KAAK,CAAC,YAAY,CAAC,MAAM,CAC5B,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,iBAAW,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,GAAG,0CAAE,IAAI,MAAK,SAAS,CAAA,EAAA,CAAC,CAC3E,CAAC;AACrB,CAAC;AAJD,0EAIC;AAED,SAAgB,eAAe,CAAC,SAAoB;IAChD,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,CAA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AC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC;AAEY,QAAA,qBAAqB,GAAG;IACjC,SAAS;IACT,QAAQ;IACR,aAAa;IACb,WAAW;IACX,QAAQ;IACR,MAAM;IACN,WAAW;IACX,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;CACT,CAAC;AAEF,SAAgB,UAAU,CAAC,SAAoB;IAC3C,OAAO,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,KAAK,KAAK,CAAC,CAAC,CAAC;AACnG,CAAC;AAFD,gCAEC;AAED,SAAgB,gBAAgB,CAAC,IAAgB;;IAC7C,OAAO,IAAA,sBAAgB,EAAC,IAAI,CAAC,IAAI,CAAA,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,0CAAE,IAAI,MAAK,MAAM,IAAI,IAAA,oBAAY,EAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC3G,CAAC;AAFD,4CAEC"}
|
|
@@ -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): void;
|
|
3
|
+
export declare function ensurePackage(pkg: string, dev: boolean, pkgManager?: PackageManagers | undefined, tag?: string, projectPath?: string): void;
|