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
|
@@ -1,603 +0,0 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
* This file was generated by langium-cli 0.4.0.
|
|
3
|
-
* DO NOT EDIT MANUALLY!
|
|
4
|
-
******************************************************************************/
|
|
5
|
-
|
|
6
|
-
/* eslint-disable @typescript-eslint/array-type */
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
8
|
-
import { AstNode, AstReflection, Reference, isAstNode, TypeMetaData } from 'langium';
|
|
9
|
-
|
|
10
|
-
export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | Function;
|
|
11
|
-
|
|
12
|
-
export const AbstractDeclaration = 'AbstractDeclaration';
|
|
13
|
-
|
|
14
|
-
export function isAbstractDeclaration(item: unknown): item is AbstractDeclaration {
|
|
15
|
-
return reflection.isInstance(item, AbstractDeclaration);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type Expression = ArrayExpr | BinaryExpr | InvocationExpr | LiteralExpr | MemberAccessExpr | NullExpr | ReferenceExpr | ThisExpr | UnaryExpr;
|
|
19
|
-
|
|
20
|
-
export const Expression = 'Expression';
|
|
21
|
-
|
|
22
|
-
export function isExpression(item: unknown): item is Expression {
|
|
23
|
-
return reflection.isInstance(item, Expression);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type ReferenceTarget = DataModelField | EnumField | FunctionParam;
|
|
27
|
-
|
|
28
|
-
export const ReferenceTarget = 'ReferenceTarget';
|
|
29
|
-
|
|
30
|
-
export function isReferenceTarget(item: unknown): item is ReferenceTarget {
|
|
31
|
-
return reflection.isInstance(item, ReferenceTarget);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type TypeDeclaration = DataModel | Enum;
|
|
35
|
-
|
|
36
|
-
export const TypeDeclaration = 'TypeDeclaration';
|
|
37
|
-
|
|
38
|
-
export function isTypeDeclaration(item: unknown): item is TypeDeclaration {
|
|
39
|
-
return reflection.isInstance(item, TypeDeclaration);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface Argument extends AstNode {
|
|
43
|
-
readonly $container: InvocationExpr;
|
|
44
|
-
name?: string
|
|
45
|
-
value: Expression
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const Argument = 'Argument';
|
|
49
|
-
|
|
50
|
-
export function isArgument(item: unknown): item is Argument {
|
|
51
|
-
return reflection.isInstance(item, Argument);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface ArrayExpr extends AstNode {
|
|
55
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
56
|
-
items: Array<Expression>
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const ArrayExpr = 'ArrayExpr';
|
|
60
|
-
|
|
61
|
-
export function isArrayExpr(item: unknown): item is ArrayExpr {
|
|
62
|
-
return reflection.isInstance(item, ArrayExpr);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface Attribute extends AstNode {
|
|
66
|
-
readonly $container: Model;
|
|
67
|
-
name: string
|
|
68
|
-
params: Array<AttributeParam>
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const Attribute = 'Attribute';
|
|
72
|
-
|
|
73
|
-
export function isAttribute(item: unknown): item is Attribute {
|
|
74
|
-
return reflection.isInstance(item, Attribute);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface AttributeArg extends AstNode {
|
|
78
|
-
readonly $container: DataModelAttribute | DataModelFieldAttribute;
|
|
79
|
-
name?: string
|
|
80
|
-
value: Expression
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const AttributeArg = 'AttributeArg';
|
|
84
|
-
|
|
85
|
-
export function isAttributeArg(item: unknown): item is AttributeArg {
|
|
86
|
-
return reflection.isInstance(item, AttributeArg);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface AttributeParam extends AstNode {
|
|
90
|
-
readonly $container: Attribute;
|
|
91
|
-
name: string
|
|
92
|
-
positional: boolean
|
|
93
|
-
type: AttributeParamType
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const AttributeParam = 'AttributeParam';
|
|
97
|
-
|
|
98
|
-
export function isAttributeParam(item: unknown): item is AttributeParam {
|
|
99
|
-
return reflection.isInstance(item, AttributeParam);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface AttributeParamType extends AstNode {
|
|
103
|
-
readonly $container: AttributeParam;
|
|
104
|
-
array: boolean
|
|
105
|
-
optional: boolean
|
|
106
|
-
type: 'Boolean' | 'DateTime' | 'FieldReference' | 'Int' | 'JSON' | 'String'
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const AttributeParamType = 'AttributeParamType';
|
|
110
|
-
|
|
111
|
-
export function isAttributeParamType(item: unknown): item is AttributeParamType {
|
|
112
|
-
return reflection.isInstance(item, AttributeParamType);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface BinaryExpr extends AstNode {
|
|
116
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
117
|
-
left: Expression
|
|
118
|
-
operator: '!' | '!=' | '&&' | '<' | '<=' | '==' | '>' | '>=' | '?' | '^' | '||'
|
|
119
|
-
right: Expression
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export const BinaryExpr = 'BinaryExpr';
|
|
123
|
-
|
|
124
|
-
export function isBinaryExpr(item: unknown): item is BinaryExpr {
|
|
125
|
-
return reflection.isInstance(item, BinaryExpr);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface DataModel extends AstNode {
|
|
129
|
-
readonly $container: Model;
|
|
130
|
-
attributes: Array<DataModelAttribute>
|
|
131
|
-
fields: Array<DataModelField>
|
|
132
|
-
name: string
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const DataModel = 'DataModel';
|
|
136
|
-
|
|
137
|
-
export function isDataModel(item: unknown): item is DataModel {
|
|
138
|
-
return reflection.isInstance(item, DataModel);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface DataModelAttribute extends AstNode {
|
|
142
|
-
readonly $container: DataModel;
|
|
143
|
-
args: Array<AttributeArg>
|
|
144
|
-
decl: Reference<Attribute>
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export const DataModelAttribute = 'DataModelAttribute';
|
|
148
|
-
|
|
149
|
-
export function isDataModelAttribute(item: unknown): item is DataModelAttribute {
|
|
150
|
-
return reflection.isInstance(item, DataModelAttribute);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface DataModelField extends AstNode {
|
|
154
|
-
readonly $container: DataModel;
|
|
155
|
-
attributes: Array<DataModelFieldAttribute>
|
|
156
|
-
name: string
|
|
157
|
-
type: DataModelFieldType
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export const DataModelField = 'DataModelField';
|
|
161
|
-
|
|
162
|
-
export function isDataModelField(item: unknown): item is DataModelField {
|
|
163
|
-
return reflection.isInstance(item, DataModelField);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export interface DataModelFieldAttribute extends AstNode {
|
|
167
|
-
readonly $container: DataModelField;
|
|
168
|
-
args: Array<AttributeArg>
|
|
169
|
-
decl: Reference<Attribute>
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export const DataModelFieldAttribute = 'DataModelFieldAttribute';
|
|
173
|
-
|
|
174
|
-
export function isDataModelFieldAttribute(item: unknown): item is DataModelFieldAttribute {
|
|
175
|
-
return reflection.isInstance(item, DataModelFieldAttribute);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export interface DataModelFieldType extends AstNode {
|
|
179
|
-
readonly $container: DataModelField;
|
|
180
|
-
array: boolean
|
|
181
|
-
optional: boolean
|
|
182
|
-
reference?: Reference<TypeDeclaration>
|
|
183
|
-
type?: 'Boolean' | 'DateTime' | 'Int' | 'JSON' | 'String'
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export const DataModelFieldType = 'DataModelFieldType';
|
|
187
|
-
|
|
188
|
-
export function isDataModelFieldType(item: unknown): item is DataModelFieldType {
|
|
189
|
-
return reflection.isInstance(item, DataModelFieldType);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export interface DataSource extends AstNode {
|
|
193
|
-
readonly $container: Model;
|
|
194
|
-
fields: Array<DataSourceField>
|
|
195
|
-
name: string
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export const DataSource = 'DataSource';
|
|
199
|
-
|
|
200
|
-
export function isDataSource(item: unknown): item is DataSource {
|
|
201
|
-
return reflection.isInstance(item, DataSource);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export interface DataSourceField extends AstNode {
|
|
205
|
-
readonly $container: DataSource;
|
|
206
|
-
name: string
|
|
207
|
-
value: InvocationExpr | LiteralExpr
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export const DataSourceField = 'DataSourceField';
|
|
211
|
-
|
|
212
|
-
export function isDataSourceField(item: unknown): item is DataSourceField {
|
|
213
|
-
return reflection.isInstance(item, DataSourceField);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export interface Enum extends AstNode {
|
|
217
|
-
readonly $container: Model;
|
|
218
|
-
fields: Array<EnumField>
|
|
219
|
-
name: string
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export const Enum = 'Enum';
|
|
223
|
-
|
|
224
|
-
export function isEnum(item: unknown): item is Enum {
|
|
225
|
-
return reflection.isInstance(item, Enum);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export interface EnumField extends AstNode {
|
|
229
|
-
readonly $container: Enum;
|
|
230
|
-
name: string
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export const EnumField = 'EnumField';
|
|
234
|
-
|
|
235
|
-
export function isEnumField(item: unknown): item is EnumField {
|
|
236
|
-
return reflection.isInstance(item, EnumField);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export interface Function extends AstNode {
|
|
240
|
-
readonly $container: Model;
|
|
241
|
-
expression?: Expression
|
|
242
|
-
name: string
|
|
243
|
-
params: Array<FunctionParam>
|
|
244
|
-
returnType: FunctionParamType
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export const Function = 'Function';
|
|
248
|
-
|
|
249
|
-
export function isFunction(item: unknown): item is Function {
|
|
250
|
-
return reflection.isInstance(item, Function);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export interface FunctionParam extends AstNode {
|
|
254
|
-
readonly $container: Function;
|
|
255
|
-
name: string
|
|
256
|
-
type: FunctionParamType
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export const FunctionParam = 'FunctionParam';
|
|
260
|
-
|
|
261
|
-
export function isFunctionParam(item: unknown): item is FunctionParam {
|
|
262
|
-
return reflection.isInstance(item, FunctionParam);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export interface FunctionParamType extends AstNode {
|
|
266
|
-
readonly $container: Function | FunctionParam;
|
|
267
|
-
array: boolean
|
|
268
|
-
reference?: Reference<TypeDeclaration>
|
|
269
|
-
type?: 'Boolean' | 'DateTime' | 'Int' | 'JSON' | 'String'
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export const FunctionParamType = 'FunctionParamType';
|
|
273
|
-
|
|
274
|
-
export function isFunctionParamType(item: unknown): item is FunctionParamType {
|
|
275
|
-
return reflection.isInstance(item, FunctionParamType);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export interface InvocationExpr extends AstNode {
|
|
279
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
280
|
-
args: Array<Argument>
|
|
281
|
-
function: Reference<Function>
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export const InvocationExpr = 'InvocationExpr';
|
|
285
|
-
|
|
286
|
-
export function isInvocationExpr(item: unknown): item is InvocationExpr {
|
|
287
|
-
return reflection.isInstance(item, InvocationExpr);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export interface LiteralExpr extends AstNode {
|
|
291
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
292
|
-
value: boolean | number | string
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export const LiteralExpr = 'LiteralExpr';
|
|
296
|
-
|
|
297
|
-
export function isLiteralExpr(item: unknown): item is LiteralExpr {
|
|
298
|
-
return reflection.isInstance(item, LiteralExpr);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
export interface MemberAccessExpr extends AstNode {
|
|
302
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
303
|
-
member: Reference<DataModelField>
|
|
304
|
-
operand: Expression
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export const MemberAccessExpr = 'MemberAccessExpr';
|
|
308
|
-
|
|
309
|
-
export function isMemberAccessExpr(item: unknown): item is MemberAccessExpr {
|
|
310
|
-
return reflection.isInstance(item, MemberAccessExpr);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export interface Model extends AstNode {
|
|
314
|
-
declarations: Array<AbstractDeclaration>
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export const Model = 'Model';
|
|
318
|
-
|
|
319
|
-
export function isModel(item: unknown): item is Model {
|
|
320
|
-
return reflection.isInstance(item, Model);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export interface NullExpr extends AstNode {
|
|
324
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
325
|
-
value: string
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export const NullExpr = 'NullExpr';
|
|
329
|
-
|
|
330
|
-
export function isNullExpr(item: unknown): item is NullExpr {
|
|
331
|
-
return reflection.isInstance(item, NullExpr);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export interface ReferenceArg extends AstNode {
|
|
335
|
-
readonly $container: ReferenceExpr;
|
|
336
|
-
name: 'sort'
|
|
337
|
-
value: 'Asc' | 'Desc'
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export const ReferenceArg = 'ReferenceArg';
|
|
341
|
-
|
|
342
|
-
export function isReferenceArg(item: unknown): item is ReferenceArg {
|
|
343
|
-
return reflection.isInstance(item, ReferenceArg);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export interface ReferenceExpr extends AstNode {
|
|
347
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
348
|
-
args: Array<ReferenceArg>
|
|
349
|
-
target: Reference<ReferenceTarget>
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export const ReferenceExpr = 'ReferenceExpr';
|
|
353
|
-
|
|
354
|
-
export function isReferenceExpr(item: unknown): item is ReferenceExpr {
|
|
355
|
-
return reflection.isInstance(item, ReferenceExpr);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export interface ThisExpr extends AstNode {
|
|
359
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
360
|
-
value: string
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export const ThisExpr = 'ThisExpr';
|
|
364
|
-
|
|
365
|
-
export function isThisExpr(item: unknown): item is ThisExpr {
|
|
366
|
-
return reflection.isInstance(item, ThisExpr);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
export interface UnaryExpr extends AstNode {
|
|
370
|
-
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | Function | MemberAccessExpr | UnaryExpr;
|
|
371
|
-
operand: Expression
|
|
372
|
-
operator: '!'
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
export const UnaryExpr = 'UnaryExpr';
|
|
376
|
-
|
|
377
|
-
export function isUnaryExpr(item: unknown): item is UnaryExpr {
|
|
378
|
-
return reflection.isInstance(item, UnaryExpr);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export type ZModelAstType = 'AbstractDeclaration' | 'Argument' | 'ArrayExpr' | 'Attribute' | 'AttributeArg' | 'AttributeParam' | 'AttributeParamType' | 'BinaryExpr' | 'DataModel' | 'DataModelAttribute' | 'DataModelField' | 'DataModelFieldAttribute' | 'DataModelFieldType' | 'DataSource' | 'DataSourceField' | 'Enum' | 'EnumField' | 'Expression' | 'Function' | 'FunctionParam' | 'FunctionParamType' | 'InvocationExpr' | 'LiteralExpr' | 'MemberAccessExpr' | 'Model' | 'NullExpr' | 'ReferenceArg' | 'ReferenceExpr' | 'ReferenceTarget' | 'ThisExpr' | 'TypeDeclaration' | 'UnaryExpr';
|
|
382
|
-
|
|
383
|
-
export type ZModelAstReference = 'DataModelAttribute:decl' | 'DataModelFieldAttribute:decl' | 'DataModelFieldType:reference' | 'FunctionParamType:reference' | 'InvocationExpr:function' | 'MemberAccessExpr:member' | 'ReferenceExpr:target';
|
|
384
|
-
|
|
385
|
-
export class ZModelAstReflection implements AstReflection {
|
|
386
|
-
|
|
387
|
-
getAllTypes(): string[] {
|
|
388
|
-
return ['AbstractDeclaration', 'Argument', 'ArrayExpr', 'Attribute', 'AttributeArg', 'AttributeParam', 'AttributeParamType', 'BinaryExpr', 'DataModel', 'DataModelAttribute', 'DataModelField', 'DataModelFieldAttribute', 'DataModelFieldType', 'DataSource', 'DataSourceField', 'Enum', 'EnumField', 'Expression', 'Function', 'FunctionParam', 'FunctionParamType', 'InvocationExpr', 'LiteralExpr', 'MemberAccessExpr', 'Model', 'NullExpr', 'ReferenceArg', 'ReferenceExpr', 'ReferenceTarget', 'ThisExpr', 'TypeDeclaration', 'UnaryExpr'];
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
isInstance(node: unknown, type: string): boolean {
|
|
392
|
-
return isAstNode(node) && this.isSubtype(node.$type, type);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
isSubtype(subtype: string, supertype: string): boolean {
|
|
396
|
-
if (subtype === supertype) {
|
|
397
|
-
return true;
|
|
398
|
-
}
|
|
399
|
-
switch (subtype) {
|
|
400
|
-
case ArrayExpr:
|
|
401
|
-
case BinaryExpr:
|
|
402
|
-
case InvocationExpr:
|
|
403
|
-
case LiteralExpr:
|
|
404
|
-
case MemberAccessExpr:
|
|
405
|
-
case NullExpr:
|
|
406
|
-
case ReferenceExpr:
|
|
407
|
-
case ThisExpr:
|
|
408
|
-
case UnaryExpr: {
|
|
409
|
-
return this.isSubtype(Expression, supertype);
|
|
410
|
-
}
|
|
411
|
-
case Attribute:
|
|
412
|
-
case DataSource:
|
|
413
|
-
case Function: {
|
|
414
|
-
return this.isSubtype(AbstractDeclaration, supertype);
|
|
415
|
-
}
|
|
416
|
-
case DataModel:
|
|
417
|
-
case Enum: {
|
|
418
|
-
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
|
|
419
|
-
}
|
|
420
|
-
case DataModelField:
|
|
421
|
-
case EnumField:
|
|
422
|
-
case FunctionParam: {
|
|
423
|
-
return this.isSubtype(ReferenceTarget, supertype);
|
|
424
|
-
}
|
|
425
|
-
default: {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
getReferenceType(referenceId: ZModelAstReference): string {
|
|
432
|
-
switch (referenceId) {
|
|
433
|
-
case 'DataModelAttribute:decl': {
|
|
434
|
-
return Attribute;
|
|
435
|
-
}
|
|
436
|
-
case 'DataModelFieldAttribute:decl': {
|
|
437
|
-
return Attribute;
|
|
438
|
-
}
|
|
439
|
-
case 'DataModelFieldType:reference': {
|
|
440
|
-
return TypeDeclaration;
|
|
441
|
-
}
|
|
442
|
-
case 'FunctionParamType:reference': {
|
|
443
|
-
return TypeDeclaration;
|
|
444
|
-
}
|
|
445
|
-
case 'InvocationExpr:function': {
|
|
446
|
-
return Function;
|
|
447
|
-
}
|
|
448
|
-
case 'MemberAccessExpr:member': {
|
|
449
|
-
return DataModelField;
|
|
450
|
-
}
|
|
451
|
-
case 'ReferenceExpr:target': {
|
|
452
|
-
return ReferenceTarget;
|
|
453
|
-
}
|
|
454
|
-
default: {
|
|
455
|
-
throw new Error(`${referenceId} is not a valid reference id.`);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
getTypeMetaData(type: string): TypeMetaData {
|
|
461
|
-
switch (type) {
|
|
462
|
-
case 'ArrayExpr': {
|
|
463
|
-
return {
|
|
464
|
-
name: 'ArrayExpr',
|
|
465
|
-
mandatory: [
|
|
466
|
-
{ name: 'items', type: 'array' }
|
|
467
|
-
]
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
case 'Attribute': {
|
|
471
|
-
return {
|
|
472
|
-
name: 'Attribute',
|
|
473
|
-
mandatory: [
|
|
474
|
-
{ name: 'params', type: 'array' }
|
|
475
|
-
]
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
case 'AttributeParam': {
|
|
479
|
-
return {
|
|
480
|
-
name: 'AttributeParam',
|
|
481
|
-
mandatory: [
|
|
482
|
-
{ name: 'positional', type: 'boolean' }
|
|
483
|
-
]
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
case 'AttributeParamType': {
|
|
487
|
-
return {
|
|
488
|
-
name: 'AttributeParamType',
|
|
489
|
-
mandatory: [
|
|
490
|
-
{ name: 'array', type: 'boolean' },
|
|
491
|
-
{ name: 'optional', type: 'boolean' }
|
|
492
|
-
]
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
case 'DataModel': {
|
|
496
|
-
return {
|
|
497
|
-
name: 'DataModel',
|
|
498
|
-
mandatory: [
|
|
499
|
-
{ name: 'attributes', type: 'array' },
|
|
500
|
-
{ name: 'fields', type: 'array' }
|
|
501
|
-
]
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
case 'DataModelAttribute': {
|
|
505
|
-
return {
|
|
506
|
-
name: 'DataModelAttribute',
|
|
507
|
-
mandatory: [
|
|
508
|
-
{ name: 'args', type: 'array' }
|
|
509
|
-
]
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
case 'DataModelField': {
|
|
513
|
-
return {
|
|
514
|
-
name: 'DataModelField',
|
|
515
|
-
mandatory: [
|
|
516
|
-
{ name: 'attributes', type: 'array' }
|
|
517
|
-
]
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
case 'DataModelFieldAttribute': {
|
|
521
|
-
return {
|
|
522
|
-
name: 'DataModelFieldAttribute',
|
|
523
|
-
mandatory: [
|
|
524
|
-
{ name: 'args', type: 'array' }
|
|
525
|
-
]
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
case 'DataModelFieldType': {
|
|
529
|
-
return {
|
|
530
|
-
name: 'DataModelFieldType',
|
|
531
|
-
mandatory: [
|
|
532
|
-
{ name: 'array', type: 'boolean' },
|
|
533
|
-
{ name: 'optional', type: 'boolean' }
|
|
534
|
-
]
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
case 'DataSource': {
|
|
538
|
-
return {
|
|
539
|
-
name: 'DataSource',
|
|
540
|
-
mandatory: [
|
|
541
|
-
{ name: 'fields', type: 'array' }
|
|
542
|
-
]
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
case 'Enum': {
|
|
546
|
-
return {
|
|
547
|
-
name: 'Enum',
|
|
548
|
-
mandatory: [
|
|
549
|
-
{ name: 'fields', type: 'array' }
|
|
550
|
-
]
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
case 'Function': {
|
|
554
|
-
return {
|
|
555
|
-
name: 'Function',
|
|
556
|
-
mandatory: [
|
|
557
|
-
{ name: 'params', type: 'array' }
|
|
558
|
-
]
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
case 'FunctionParamType': {
|
|
562
|
-
return {
|
|
563
|
-
name: 'FunctionParamType',
|
|
564
|
-
mandatory: [
|
|
565
|
-
{ name: 'array', type: 'boolean' }
|
|
566
|
-
]
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
case 'InvocationExpr': {
|
|
570
|
-
return {
|
|
571
|
-
name: 'InvocationExpr',
|
|
572
|
-
mandatory: [
|
|
573
|
-
{ name: 'args', type: 'array' }
|
|
574
|
-
]
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
case 'Model': {
|
|
578
|
-
return {
|
|
579
|
-
name: 'Model',
|
|
580
|
-
mandatory: [
|
|
581
|
-
{ name: 'declarations', type: 'array' }
|
|
582
|
-
]
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
case 'ReferenceExpr': {
|
|
586
|
-
return {
|
|
587
|
-
name: 'ReferenceExpr',
|
|
588
|
-
mandatory: [
|
|
589
|
-
{ name: 'args', type: 'array' }
|
|
590
|
-
]
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
default: {
|
|
594
|
-
return {
|
|
595
|
-
name: type,
|
|
596
|
-
mandatory: []
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
export const reflection = new ZModelAstReflection();
|