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.
Files changed (264) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +126 -1
  3. package/bin/cli +3 -0
  4. package/bin/post-install.js +24 -0
  5. package/cli/cli-error.d.ts +5 -0
  6. package/cli/cli-error.js +10 -0
  7. package/cli/cli-error.js.map +1 -0
  8. package/cli/cli-util.d.ts +18 -0
  9. package/cli/cli-util.js +143 -0
  10. package/cli/cli-util.js.map +1 -0
  11. package/cli/index.d.ts +15 -0
  12. package/cli/index.js +121 -0
  13. package/cli/index.js.map +1 -0
  14. package/cli/plugin-runner.d.ts +14 -0
  15. package/cli/plugin-runner.js +145 -0
  16. package/cli/plugin-runner.js.map +1 -0
  17. package/constants.d.ts +1 -0
  18. package/constants.js +6 -0
  19. package/constants.js.map +1 -0
  20. package/language-server/constants.d.ts +15 -0
  21. package/language-server/constants.js +20 -0
  22. package/language-server/constants.js.map +1 -0
  23. package/language-server/main.d.ts +1 -0
  24. package/language-server/main.js +13 -0
  25. package/language-server/main.js.map +1 -0
  26. package/language-server/types.d.ts +10 -0
  27. package/language-server/types.js +3 -0
  28. package/language-server/types.js.map +1 -0
  29. package/language-server/utils.d.ts +18 -0
  30. package/language-server/utils.js +58 -0
  31. package/language-server/utils.js.map +1 -0
  32. package/language-server/validator/attribute-validator.d.ts +9 -0
  33. package/language-server/validator/attribute-validator.js +11 -0
  34. package/language-server/validator/attribute-validator.js.map +1 -0
  35. package/language-server/validator/datamodel-validator.d.ts +15 -0
  36. package/language-server/validator/datamodel-validator.js +278 -0
  37. package/language-server/validator/datamodel-validator.js.map +1 -0
  38. package/language-server/validator/datasource-validator.d.ts +12 -0
  39. package/language-server/validator/datasource-validator.js +66 -0
  40. package/language-server/validator/datasource-validator.js.map +1 -0
  41. package/language-server/validator/enum-validator.d.ts +11 -0
  42. package/language-server/validator/enum-validator.js +28 -0
  43. package/language-server/validator/enum-validator.js.map +1 -0
  44. package/language-server/validator/expression-validator.d.ts +10 -0
  45. package/language-server/validator/expression-validator.js +30 -0
  46. package/language-server/validator/expression-validator.js.map +1 -0
  47. package/language-server/validator/schema-validator.d.ts +10 -0
  48. package/language-server/validator/schema-validator.js +28 -0
  49. package/language-server/validator/schema-validator.js.map +1 -0
  50. package/language-server/validator/utils.d.ts +25 -0
  51. package/language-server/validator/utils.js +257 -0
  52. package/language-server/validator/utils.js.map +1 -0
  53. package/language-server/validator/zmodel-validator.d.ts +21 -0
  54. package/language-server/validator/zmodel-validator.js +69 -0
  55. package/language-server/validator/zmodel-validator.js.map +1 -0
  56. package/language-server/zmodel-code-action.d.ts +14 -0
  57. package/language-server/zmodel-code-action.js +93 -0
  58. package/language-server/zmodel-code-action.js.map +1 -0
  59. package/language-server/zmodel-formatter.d.ts +9 -0
  60. package/language-server/zmodel-formatter.js +76 -0
  61. package/language-server/zmodel-formatter.js.map +1 -0
  62. package/language-server/zmodel-linker.d.ts +29 -0
  63. package/language-server/zmodel-linker.js +366 -0
  64. package/language-server/zmodel-linker.js.map +1 -0
  65. package/language-server/zmodel-module.d.ts +41 -0
  66. package/language-server/zmodel-module.js +80 -0
  67. package/language-server/zmodel-module.js.map +1 -0
  68. package/language-server/zmodel-scope.d.ts +10 -0
  69. package/language-server/zmodel-scope.js +44 -0
  70. package/language-server/zmodel-scope.js.map +1 -0
  71. package/language-server/zmodel-workspace-manager.d.ts +8 -0
  72. package/language-server/zmodel-workspace-manager.js +37 -0
  73. package/language-server/zmodel-workspace-manager.js.map +1 -0
  74. package/package.json +133 -8
  75. package/plugins/access-policy/expression-writer.d.ts +39 -0
  76. package/plugins/access-policy/expression-writer.js +361 -0
  77. package/plugins/access-policy/expression-writer.js.map +1 -0
  78. package/plugins/access-policy/index.d.ts +4 -0
  79. package/plugins/access-policy/index.js +24 -0
  80. package/plugins/access-policy/index.js.map +1 -0
  81. package/plugins/access-policy/policy-guard-generator.d.ts +15 -0
  82. package/plugins/access-policy/policy-guard-generator.js +349 -0
  83. package/plugins/access-policy/policy-guard-generator.js.map +1 -0
  84. package/plugins/access-policy/typescript-expression-transformer.d.ts +26 -0
  85. package/plugins/access-policy/typescript-expression-transformer.js +111 -0
  86. package/plugins/access-policy/typescript-expression-transformer.js.map +1 -0
  87. package/plugins/access-policy/utils.d.ts +5 -0
  88. package/plugins/access-policy/utils.js +14 -0
  89. package/plugins/access-policy/utils.js.map +1 -0
  90. package/plugins/access-policy/zod-schema-generator.d.ts +12 -0
  91. package/plugins/access-policy/zod-schema-generator.js +158 -0
  92. package/plugins/access-policy/zod-schema-generator.js.map +1 -0
  93. package/plugins/model-meta/index.d.ts +4 -0
  94. package/plugins/model-meta/index.js +168 -0
  95. package/plugins/model-meta/index.js.map +1 -0
  96. package/plugins/plugin-utils.d.ts +16 -0
  97. package/plugins/plugin-utils.js +54 -0
  98. package/plugins/plugin-utils.js.map +1 -0
  99. package/plugins/prisma/indent-string.d.ts +4 -0
  100. package/plugins/prisma/indent-string.js +12 -0
  101. package/plugins/prisma/indent-string.js.map +1 -0
  102. package/plugins/prisma/index.d.ts +4 -0
  103. package/plugins/prisma/index.js +24 -0
  104. package/plugins/prisma/index.js.map +1 -0
  105. package/plugins/prisma/prisma-builder.d.ts +152 -0
  106. package/plugins/prisma/prisma-builder.js +363 -0
  107. package/plugins/prisma/prisma-builder.js.map +1 -0
  108. package/plugins/prisma/schema-generator.d.ts +25 -0
  109. package/plugins/prisma/schema-generator.js +292 -0
  110. package/plugins/prisma/schema-generator.js.map +1 -0
  111. package/plugins/prisma/zmodel-code-generator.d.ts +28 -0
  112. package/plugins/prisma/zmodel-code-generator.js +114 -0
  113. package/plugins/prisma/zmodel-code-generator.js.map +1 -0
  114. package/res/prism-zmodel.js +20 -0
  115. package/res/starter.zmodel +51 -0
  116. package/res/stdlib.zmodel +346 -0
  117. package/telemetry.d.ts +20 -0
  118. package/telemetry.js +119 -0
  119. package/telemetry.js.map +1 -0
  120. package/types.d.ts +12 -0
  121. package/types.js +3 -0
  122. package/types.js.map +1 -0
  123. package/utils/ast-utils.d.ts +16 -0
  124. package/utils/ast-utils.js +85 -0
  125. package/utils/ast-utils.js.map +1 -0
  126. package/utils/exec-utils.d.ts +6 -0
  127. package/utils/exec-utils.js +13 -0
  128. package/utils/exec-utils.js.map +1 -0
  129. package/utils/pkg-utils.d.ts +3 -0
  130. package/utils/pkg-utils.js +46 -0
  131. package/utils/pkg-utils.js.map +1 -0
  132. package/utils/version-utils.d.ts +1 -0
  133. package/utils/version-utils.js +14 -0
  134. package/utils/version-utils.js.map +1 -0
  135. package/.vscode/extensions.json +0 -7
  136. package/.vscode/launch.json +0 -49
  137. package/.vscode/settings.json +0 -4
  138. package/packages/internal/jest.config.ts +0 -32
  139. package/packages/internal/package.json +0 -42
  140. package/packages/internal/src/constants.ts +0 -1
  141. package/packages/internal/src/handler/data/guard-utils.ts +0 -7
  142. package/packages/internal/src/handler/data/handler.ts +0 -415
  143. package/packages/internal/src/handler/data/query-processor.ts +0 -504
  144. package/packages/internal/src/handler/index.ts +0 -1
  145. package/packages/internal/src/handler/types.ts +0 -20
  146. package/packages/internal/src/index.ts +0 -3
  147. package/packages/internal/src/request-handler.ts +0 -27
  148. package/packages/internal/src/request.ts +0 -101
  149. package/packages/internal/src/types.ts +0 -40
  150. package/packages/internal/tests/query-processor.test.ts +0 -172
  151. package/packages/internal/tsconfig.json +0 -21
  152. package/packages/runtime/auth.d.ts +0 -1
  153. package/packages/runtime/auth.js +0 -3
  154. package/packages/runtime/hooks.d.ts +0 -10
  155. package/packages/runtime/hooks.js +0 -3
  156. package/packages/runtime/index.d.ts +0 -3
  157. package/packages/runtime/index.js +0 -1
  158. package/packages/runtime/package-lock.json +0 -512
  159. package/packages/runtime/package.json +0 -16
  160. package/packages/runtime/server.d.ts +0 -1
  161. package/packages/runtime/server.js +0 -3
  162. package/packages/runtime/types.d.ts +0 -1
  163. package/packages/runtime/types.js +0 -3
  164. package/packages/schema/.eslintrc.json +0 -13
  165. package/packages/schema/.vscodeignore +0 -4
  166. package/packages/schema/asset/logo-dark.png +0 -0
  167. package/packages/schema/asset/logo-light.png +0 -0
  168. package/packages/schema/bin/cli +0 -3
  169. package/packages/schema/jest.config.ts +0 -32
  170. package/packages/schema/langium-config.json +0 -14
  171. package/packages/schema/langium-quickstart.md +0 -41
  172. package/packages/schema/language-configuration.json +0 -30
  173. package/packages/schema/package.json +0 -96
  174. package/packages/schema/src/cli/cli-util.ts +0 -80
  175. package/packages/schema/src/cli/index.ts +0 -64
  176. package/packages/schema/src/extension.ts +0 -76
  177. package/packages/schema/src/generator/constants.ts +0 -5
  178. package/packages/schema/src/generator/index.ts +0 -92
  179. package/packages/schema/src/generator/next-auth/index.ts +0 -197
  180. package/packages/schema/src/generator/package.template.json +0 -9
  181. package/packages/schema/src/generator/prisma/expression-writer.ts +0 -352
  182. package/packages/schema/src/generator/prisma/index.ts +0 -32
  183. package/packages/schema/src/generator/prisma/plain-expression-builder.ts +0 -91
  184. package/packages/schema/src/generator/prisma/prisma-builder.ts +0 -366
  185. package/packages/schema/src/generator/prisma/query-gard-generator.ts +0 -208
  186. package/packages/schema/src/generator/prisma/schema-generator.ts +0 -300
  187. package/packages/schema/src/generator/react-hooks/index.ts +0 -181
  188. package/packages/schema/src/generator/service/index.ts +0 -107
  189. package/packages/schema/src/generator/tsconfig.template.json +0 -17
  190. package/packages/schema/src/generator/types.ts +0 -17
  191. package/packages/schema/src/generator/utils.ts +0 -9
  192. package/packages/schema/src/language-server/generated/ast.ts +0 -603
  193. package/packages/schema/src/language-server/generated/grammar.ts +0 -2190
  194. package/packages/schema/src/language-server/generated/module.ts +0 -24
  195. package/packages/schema/src/language-server/main.ts +0 -12
  196. package/packages/schema/src/language-server/stdlib.zmodel +0 -22
  197. package/packages/schema/src/language-server/types.ts +0 -9
  198. package/packages/schema/src/language-server/zmodel-index.ts +0 -33
  199. package/packages/schema/src/language-server/zmodel-linker.ts +0 -409
  200. package/packages/schema/src/language-server/zmodel-module.ts +0 -90
  201. package/packages/schema/src/language-server/zmodel-scope.ts +0 -21
  202. package/packages/schema/src/language-server/zmodel-validator.ts +0 -35
  203. package/packages/schema/src/language-server/zmodel.langium +0 -186
  204. package/packages/schema/src/utils/exec-utils.ts +0 -5
  205. package/packages/schema/src/utils/indent-string.ts +0 -6
  206. package/packages/schema/syntaxes/zmodel.json +0 -57
  207. package/packages/schema/syntaxes/zmodel.tmLanguage.json +0 -57
  208. package/packages/schema/tests/generator/expression-writer.test.ts +0 -676
  209. package/packages/schema/tests/generator/prisma-builder.test.ts +0 -138
  210. package/packages/schema/tests/schema/parser.test.ts +0 -423
  211. package/packages/schema/tests/schema/sample-todo.test.ts +0 -14
  212. package/packages/schema/tests/utils.ts +0 -38
  213. package/packages/schema/tsconfig.json +0 -23
  214. package/pnpm-workspace.yaml +0 -3
  215. package/samples/todo/.env +0 -2
  216. package/samples/todo/.eslintrc.json +0 -3
  217. package/samples/todo/.vscode/launch.json +0 -11
  218. package/samples/todo/README.md +0 -34
  219. package/samples/todo/components/AuthGuard.tsx +0 -17
  220. package/samples/todo/components/Avatar.tsx +0 -22
  221. package/samples/todo/components/BreadCrumb.tsx +0 -44
  222. package/samples/todo/components/ManageMembers.tsx +0 -134
  223. package/samples/todo/components/NavBar.tsx +0 -57
  224. package/samples/todo/components/SpaceMembers.tsx +0 -76
  225. package/samples/todo/components/Spaces.tsx +0 -28
  226. package/samples/todo/components/TimeInfo.tsx +0 -17
  227. package/samples/todo/components/Todo.tsx +0 -72
  228. package/samples/todo/components/TodoList.tsx +0 -77
  229. package/samples/todo/lib/context.ts +0 -31
  230. package/samples/todo/next.config.js +0 -10
  231. package/samples/todo/package-lock.json +0 -7527
  232. package/samples/todo/package.json +0 -45
  233. package/samples/todo/pages/_app.tsx +0 -50
  234. package/samples/todo/pages/api/auth/[...nextauth].ts +0 -83
  235. package/samples/todo/pages/api/zenstack/[...path].ts +0 -16
  236. package/samples/todo/pages/create-space.tsx +0 -114
  237. package/samples/todo/pages/index.tsx +0 -32
  238. package/samples/todo/pages/space/[slug]/[listId]/index.tsx +0 -88
  239. package/samples/todo/pages/space/[slug]/index.tsx +0 -169
  240. package/samples/todo/postcss.config.js +0 -6
  241. package/samples/todo/public/avatar.jpg +0 -0
  242. package/samples/todo/public/favicon.ico +0 -0
  243. package/samples/todo/public/logo.png +0 -0
  244. package/samples/todo/public/vercel.svg +0 -4
  245. package/samples/todo/styles/globals.css +0 -7
  246. package/samples/todo/tailwind.config.js +0 -11
  247. package/samples/todo/tsconfig.json +0 -28
  248. package/samples/todo/types/next-auth.d.ts +0 -14
  249. package/samples/todo/types/next.d.ts +0 -16
  250. package/samples/todo/zenstack/migrations/20221014084317_init/migration.sql +0 -153
  251. package/samples/todo/zenstack/migrations/20221020094651_upate_cli/migration.sql +0 -23
  252. package/samples/todo/zenstack/migrations/migration_lock.toml +0 -3
  253. package/samples/todo/zenstack/schema.prisma +0 -126
  254. package/samples/todo/zenstack/schema.zmodel +0 -161
  255. package/tests/integration/jest.config.ts +0 -16
  256. package/tests/integration/package-lock.json +0 -1081
  257. package/tests/integration/package.json +0 -27
  258. package/tests/integration/tests/operation-coverate.test.ts +0 -563
  259. package/tests/integration/tests/operations.zmodel +0 -69
  260. package/tests/integration/tests/todo-e2e.test.ts +0 -577
  261. package/tests/integration/tests/todo.zmodel +0 -123
  262. package/tests/integration/tests/tsconfig.template.json +0 -10
  263. package/tests/integration/tests/utils.ts +0 -133
  264. 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();