zenstack 0.1.41 → 1.0.0

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 (215) hide show
  1. package/.vscode/extensions.json +7 -0
  2. package/.vscode/launch.json +49 -0
  3. package/.vscode/settings.json +4 -0
  4. package/README.md +1 -0
  5. package/package.json +8 -90
  6. package/packages/internal/jest.config.ts +32 -0
  7. package/packages/internal/package.json +42 -0
  8. package/packages/internal/src/constants.ts +1 -0
  9. package/packages/internal/src/handler/data/guard-utils.ts +7 -0
  10. package/packages/internal/src/handler/data/handler.ts +415 -0
  11. package/packages/internal/src/handler/data/query-processor.ts +504 -0
  12. package/packages/internal/src/handler/index.ts +1 -0
  13. package/packages/internal/src/handler/types.ts +20 -0
  14. package/packages/internal/src/index.ts +3 -0
  15. package/packages/internal/src/request-handler.ts +27 -0
  16. package/packages/internal/src/request.ts +101 -0
  17. package/packages/internal/src/types.ts +40 -0
  18. package/packages/internal/tests/query-processor.test.ts +172 -0
  19. package/{out/cli/tsconfig.template.json → packages/internal/tsconfig.json} +7 -3
  20. package/packages/runtime/auth.d.ts +1 -0
  21. package/packages/runtime/auth.js +3 -0
  22. package/packages/runtime/hooks.d.ts +10 -0
  23. package/packages/runtime/hooks.js +3 -0
  24. package/packages/runtime/index.d.ts +3 -0
  25. package/packages/runtime/index.js +1 -0
  26. package/packages/runtime/package-lock.json +512 -0
  27. package/packages/runtime/package.json +16 -0
  28. package/packages/runtime/server.d.ts +1 -0
  29. package/packages/runtime/server.js +3 -0
  30. package/packages/runtime/types.d.ts +1 -0
  31. package/packages/runtime/types.js +3 -0
  32. package/packages/schema/.eslintrc.json +13 -0
  33. package/packages/schema/.vscodeignore +4 -0
  34. package/packages/schema/asset/logo-dark.png +0 -0
  35. package/packages/schema/asset/logo-light.png +0 -0
  36. package/{bin → packages/schema/bin}/cli +0 -0
  37. package/packages/schema/jest.config.ts +32 -0
  38. package/packages/schema/langium-config.json +14 -0
  39. package/packages/schema/langium-quickstart.md +41 -0
  40. package/packages/schema/language-configuration.json +30 -0
  41. package/packages/schema/package.json +96 -0
  42. package/packages/schema/src/cli/cli-util.ts +80 -0
  43. package/packages/schema/src/cli/index.ts +64 -0
  44. package/packages/schema/src/extension.ts +76 -0
  45. package/packages/schema/src/generator/constants.ts +5 -0
  46. package/packages/schema/src/generator/index.ts +92 -0
  47. package/{out/generator/next-auth/index.js → packages/schema/src/generator/next-auth/index.ts} +46 -58
  48. package/{out → packages/schema/src}/generator/package.template.json +0 -0
  49. package/packages/schema/src/generator/prisma/expression-writer.ts +352 -0
  50. package/packages/schema/src/generator/prisma/index.ts +32 -0
  51. package/packages/schema/src/generator/prisma/plain-expression-builder.ts +91 -0
  52. package/packages/schema/src/generator/prisma/prisma-builder.ts +366 -0
  53. package/packages/schema/src/generator/prisma/query-gard-generator.ts +208 -0
  54. package/packages/schema/src/generator/prisma/schema-generator.ts +300 -0
  55. package/packages/schema/src/generator/react-hooks/index.ts +181 -0
  56. package/packages/schema/src/generator/service/index.ts +107 -0
  57. package/{out → packages/schema/src}/generator/tsconfig.template.json +0 -0
  58. package/packages/schema/src/generator/types.ts +17 -0
  59. package/packages/schema/src/generator/utils.ts +9 -0
  60. package/packages/schema/src/language-server/generated/ast.ts +603 -0
  61. package/{out/language-server/generated/grammar.js → packages/schema/src/language-server/generated/grammar.ts} +5 -8
  62. package/packages/schema/src/language-server/generated/module.ts +24 -0
  63. package/packages/schema/src/language-server/main.ts +12 -0
  64. package/{out → packages/schema/src}/language-server/stdlib.zmodel +0 -0
  65. package/packages/schema/src/language-server/types.ts +9 -0
  66. package/packages/schema/src/language-server/zmodel-index.ts +33 -0
  67. package/packages/schema/src/language-server/zmodel-linker.ts +409 -0
  68. package/packages/schema/src/language-server/zmodel-module.ts +90 -0
  69. package/packages/schema/src/language-server/zmodel-scope.ts +21 -0
  70. package/packages/schema/src/language-server/zmodel-validator.ts +35 -0
  71. package/packages/schema/src/language-server/zmodel.langium +186 -0
  72. package/packages/schema/src/utils/exec-utils.ts +5 -0
  73. package/packages/schema/src/utils/indent-string.ts +6 -0
  74. package/packages/schema/syntaxes/zmodel.json +57 -0
  75. package/packages/schema/syntaxes/zmodel.tmLanguage.json +57 -0
  76. package/packages/schema/tests/generator/expression-writer.test.ts +676 -0
  77. package/packages/schema/tests/generator/prisma-builder.test.ts +138 -0
  78. package/packages/schema/tests/schema/parser.test.ts +423 -0
  79. package/packages/schema/tests/schema/sample-todo.test.ts +14 -0
  80. package/packages/schema/tests/utils.ts +38 -0
  81. package/packages/schema/tsconfig.json +23 -0
  82. package/pnpm-workspace.yaml +3 -0
  83. package/samples/todo/.env +2 -0
  84. package/samples/todo/.eslintrc.json +3 -0
  85. package/samples/todo/.vscode/launch.json +11 -0
  86. package/samples/todo/README.md +34 -0
  87. package/samples/todo/components/AuthGuard.tsx +17 -0
  88. package/samples/todo/components/Avatar.tsx +22 -0
  89. package/samples/todo/components/BreadCrumb.tsx +44 -0
  90. package/samples/todo/components/ManageMembers.tsx +134 -0
  91. package/samples/todo/components/NavBar.tsx +57 -0
  92. package/samples/todo/components/SpaceMembers.tsx +76 -0
  93. package/samples/todo/components/Spaces.tsx +28 -0
  94. package/samples/todo/components/TimeInfo.tsx +17 -0
  95. package/samples/todo/components/Todo.tsx +72 -0
  96. package/samples/todo/components/TodoList.tsx +77 -0
  97. package/samples/todo/lib/context.ts +31 -0
  98. package/samples/todo/next.config.js +10 -0
  99. package/samples/todo/package-lock.json +7527 -0
  100. package/samples/todo/package.json +45 -0
  101. package/samples/todo/pages/_app.tsx +50 -0
  102. package/samples/todo/pages/api/auth/[...nextauth].ts +83 -0
  103. package/samples/todo/pages/api/zenstack/[...path].ts +16 -0
  104. package/samples/todo/pages/create-space.tsx +114 -0
  105. package/samples/todo/pages/index.tsx +32 -0
  106. package/samples/todo/pages/space/[slug]/[listId]/index.tsx +88 -0
  107. package/samples/todo/pages/space/[slug]/index.tsx +169 -0
  108. package/samples/todo/postcss.config.js +6 -0
  109. package/samples/todo/public/avatar.jpg +0 -0
  110. package/samples/todo/public/favicon.ico +0 -0
  111. package/samples/todo/public/logo.png +0 -0
  112. package/samples/todo/public/vercel.svg +4 -0
  113. package/samples/todo/styles/globals.css +7 -0
  114. package/samples/todo/tailwind.config.js +11 -0
  115. package/samples/todo/tsconfig.json +28 -0
  116. package/samples/todo/types/next-auth.d.ts +14 -0
  117. package/samples/todo/types/next.d.ts +16 -0
  118. package/samples/todo/zenstack/migrations/20221014084317_init/migration.sql +153 -0
  119. package/samples/todo/zenstack/migrations/20221020094651_upate_cli/migration.sql +23 -0
  120. package/samples/todo/zenstack/migrations/migration_lock.toml +3 -0
  121. package/samples/todo/zenstack/schema.prisma +126 -0
  122. package/samples/todo/zenstack/schema.zmodel +161 -0
  123. package/tests/integration/jest.config.ts +16 -0
  124. package/tests/integration/package-lock.json +1081 -0
  125. package/tests/integration/package.json +27 -0
  126. package/tests/integration/tests/operation-coverate.test.ts +563 -0
  127. package/tests/integration/tests/operations.zmodel +69 -0
  128. package/tests/integration/tests/todo-e2e.test.ts +577 -0
  129. package/tests/integration/tests/todo.zmodel +123 -0
  130. package/tests/integration/tests/tsconfig.template.json +10 -0
  131. package/tests/integration/tests/utils.ts +133 -0
  132. package/tests/integration/tsconfig.json +10 -0
  133. package/out/cli/cli-util.js +0 -64
  134. package/out/cli/cli-util.js.map +0 -1
  135. package/out/cli/generator.js +0 -1
  136. package/out/cli/generator.js.map +0 -1
  137. package/out/cli/index.js +0 -46
  138. package/out/cli/index.js.map +0 -1
  139. package/out/cli/package.template.json +0 -10
  140. package/out/extension.js +0 -81
  141. package/out/extension.js.map +0 -1
  142. package/out/generator/constants.js +0 -9
  143. package/out/generator/constants.js.map +0 -1
  144. package/out/generator/data-server/index.js +0 -1
  145. package/out/generator/data-server/index.js.map +0 -1
  146. package/out/generator/index.js +0 -98
  147. package/out/generator/index.js.map +0 -1
  148. package/out/generator/next-auth/index.js.map +0 -1
  149. package/out/generator/prisma/expression-writer.js +0 -287
  150. package/out/generator/prisma/expression-writer.js.map +0 -1
  151. package/out/generator/prisma/index.js +0 -38
  152. package/out/generator/prisma/index.js.map +0 -1
  153. package/out/generator/prisma/plain-expression-builder.js +0 -69
  154. package/out/generator/prisma/plain-expression-builder.js.map +0 -1
  155. package/out/generator/prisma/prisma-builder.js +0 -307
  156. package/out/generator/prisma/prisma-builder.js.map +0 -1
  157. package/out/generator/prisma/query-gard-generator.js +0 -159
  158. package/out/generator/prisma/query-gard-generator.js.map +0 -1
  159. package/out/generator/prisma/schema-generator.js +0 -201
  160. package/out/generator/prisma/schema-generator.js.map +0 -1
  161. package/out/generator/query-guard/index.js +0 -2
  162. package/out/generator/query-guard/index.js.map +0 -1
  163. package/out/generator/react-hooks/index.js +0 -179
  164. package/out/generator/react-hooks/index.js.map +0 -1
  165. package/out/generator/server/data/data-generator.js +0 -376
  166. package/out/generator/server/data/data-generator.js.map +0 -1
  167. package/out/generator/server/data/expression-writer.js +0 -287
  168. package/out/generator/server/data/expression-writer.js.map +0 -1
  169. package/out/generator/server/data/plain-expression-builder.js +0 -69
  170. package/out/generator/server/data/plain-expression-builder.js.map +0 -1
  171. package/out/generator/server/data-generator.js +0 -82
  172. package/out/generator/server/data-generator.js.map +0 -1
  173. package/out/generator/server/expression-writer.js +0 -1
  174. package/out/generator/server/expression-writer.js.map +0 -1
  175. package/out/generator/server/function/function-generator.js +0 -50
  176. package/out/generator/server/function/function-generator.js.map +0 -1
  177. package/out/generator/server/function-generator.js +0 -13
  178. package/out/generator/server/function-generator.js.map +0 -1
  179. package/out/generator/server/index.js +0 -88
  180. package/out/generator/server/index.js.map +0 -1
  181. package/out/generator/server/js-expression-builder.js +0 -1
  182. package/out/generator/server/js-expression-builder.js.map +0 -1
  183. package/out/generator/server/plain-expression-builder.js +0 -1
  184. package/out/generator/server/plain-expression-builder.js.map +0 -1
  185. package/out/generator/server/server-code-generator.js +0 -3
  186. package/out/generator/server/server-code-generator.js.map +0 -1
  187. package/out/generator/server/server-code-writer.js +0 -1
  188. package/out/generator/server/server-code-writer.js.map +0 -1
  189. package/out/generator/service/index.js +0 -133
  190. package/out/generator/service/index.js.map +0 -1
  191. package/out/generator/types.js +0 -10
  192. package/out/generator/types.js.map +0 -1
  193. package/out/generator/utils.js +0 -10
  194. package/out/generator/utils.js.map +0 -1
  195. package/out/language-server/generated/ast.js +0 -386
  196. package/out/language-server/generated/ast.js.map +0 -1
  197. package/out/language-server/generated/grammar.js.map +0 -1
  198. package/out/language-server/generated/module.js +0 -23
  199. package/out/language-server/generated/module.js.map +0 -1
  200. package/out/language-server/main.js +0 -12
  201. package/out/language-server/main.js.map +0 -1
  202. package/out/language-server/types.js +0 -3
  203. package/out/language-server/types.js.map +0 -1
  204. package/out/language-server/zmodel-index.js +0 -38
  205. package/out/language-server/zmodel-index.js.map +0 -1
  206. package/out/language-server/zmodel-linker.js +0 -241
  207. package/out/language-server/zmodel-linker.js.map +0 -1
  208. package/out/language-server/zmodel-module.js +0 -51
  209. package/out/language-server/zmodel-module.js.map +0 -1
  210. package/out/language-server/zmodel-scope.js +0 -30
  211. package/out/language-server/zmodel-scope.js.map +0 -1
  212. package/out/language-server/zmodel-validator.js +0 -25
  213. package/out/language-server/zmodel-validator.js.map +0 -1
  214. package/out/utils/indent-string.js +0 -9
  215. package/out/utils/indent-string.js.map +0 -1
@@ -0,0 +1,603 @@
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();
@@ -1,13 +1,12 @@
1
- "use strict";
2
1
  /******************************************************************************
3
2
  * This file was generated by langium-cli 0.4.0.
4
3
  * DO NOT EDIT MANUALLY!
5
4
  ******************************************************************************/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ZModelGrammar = void 0;
8
- const langium_1 = require("langium");
9
- let loadedZModelGrammar;
10
- const ZModelGrammar = () => loadedZModelGrammar || (loadedZModelGrammar = (0, langium_1.loadGrammar)(`{
5
+
6
+ import { loadGrammar, Grammar } from 'langium';
7
+
8
+ let loadedZModelGrammar: Grammar | undefined;
9
+ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ||(loadedZModelGrammar = loadGrammar(`{
11
10
  "$type": "Grammar",
12
11
  "isDeclared": true,
13
12
  "name": "ZModel",
@@ -2189,5 +2188,3 @@ const ZModelGrammar = () => loadedZModelGrammar || (loadedZModelGrammar = (0, la
2189
2188
  "interfaces": [],
2190
2189
  "usedGrammars": []
2191
2190
  }`));
2192
- exports.ZModelGrammar = ZModelGrammar;
2193
- //# sourceMappingURL=grammar.js.map
@@ -0,0 +1,24 @@
1
+ /******************************************************************************
2
+ * This file was generated by langium-cli 0.4.0.
3
+ * DO NOT EDIT MANUALLY!
4
+ ******************************************************************************/
5
+
6
+ import { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices, LanguageMetaData, Module } from 'langium';
7
+ import { ZModelAstReflection } from './ast';
8
+ import { ZModelGrammar } from './grammar';
9
+
10
+ export const ZModelLanguageMetaData: LanguageMetaData = {
11
+ languageId: 'zmodel',
12
+ fileExtensions: ['.zmodel'],
13
+ caseInsensitive: false
14
+ };
15
+
16
+ export const ZModelGeneratedSharedModule: Module<LangiumSharedServices, LangiumGeneratedSharedServices> = {
17
+ AstReflection: () => new ZModelAstReflection()
18
+ };
19
+
20
+ export const ZModelGeneratedModule: Module<LangiumServices, LangiumGeneratedServices> = {
21
+ Grammar: () => ZModelGrammar(),
22
+ LanguageMetaData: () => ZModelLanguageMetaData,
23
+ parser: {}
24
+ };
@@ -0,0 +1,12 @@
1
+ import { startLanguageServer } from 'langium';
2
+ import { createConnection, ProposedFeatures } from 'vscode-languageserver/node';
3
+ import { createZModelServices } from './zmodel-module';
4
+
5
+ // Create a connection to the client
6
+ const connection = createConnection(ProposedFeatures.all);
7
+
8
+ // Inject the shared services and language-specific services
9
+ const { shared } = createZModelServices({ connection });
10
+
11
+ // Start the language server with the shared services
12
+ startLanguageServer(shared);
@@ -0,0 +1,9 @@
1
+ import { AstNode } from 'langium';
2
+ import { AbstractDeclaration } from './generated/ast';
3
+
4
+ export type TypedNode = AstNode & {
5
+ $resolvedType?: {
6
+ decl?: string | AbstractDeclaration;
7
+ array?: boolean;
8
+ };
9
+ };