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