@zenstackhq/language 3.3.2 → 3.4.0-beta.1

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.
@@ -0,0 +1,284 @@
1
+ import { ThisExpr, NullExpr, NumberLiteral, StringLiteral, BooleanLiteral, ArrayExpr, Expression, BinaryExpr, InvocationExpr, Argument, FunctionDecl, MemberAccessExpr, MemberAccessTarget, ObjectExpr, FieldInitializer, RegularID, ReferenceExpr, ReferenceTarget, ReferenceArg, UnaryExpr, Attribute, InternalAttribute, AttributeArg, AttributeParam, AttributeParamType, TypeDeclaration, DataModelAttribute, DataFieldAttribute, DataModel, DataField, DataFieldType, BuiltinType, UnsupportedFieldType, LiteralExpr, TypeDef, Enum, EnumField, RegularIDWithTypeNames, AbstractDeclaration, Model, ModelImport } from './ast.js';
2
+ import { AstNode, Reference } from 'langium';
3
+
4
+ type ContainerProps<T extends AstNode | undefined> = {
5
+ $container: T;
6
+ $containerProperty?: string;
7
+ $containerIndex?: number;
8
+ };
9
+ type NodeFactoriesFor<N> = {
10
+ [K in keyof N as {} extends Pick<N, K> ? never : K]: N[K] extends (infer U)[] ? (AstFactory<U extends AstNode ? U : AstNode> | U)[] : AstFactory<N[K] extends AstNode ? N[K] : AstNode> | N[K];
11
+ } & {
12
+ [K in keyof N as {} extends Pick<N, K> ? K : never]?: N[K] extends (infer U)[] ? (AstFactory<U extends AstNode ? U : AstNode> | U)[] : AstFactory<N[K] extends AstNode ? N[K] : AstNode> | N[K];
13
+ };
14
+ declare abstract class AstFactory<T extends AstNode = AstNode> {
15
+ node: T;
16
+ constructor({ type, node }: {
17
+ type: T['$type'];
18
+ node?: Partial<T>;
19
+ });
20
+ setContainer(container: T['$container']): this;
21
+ get(params?: ContainerProps<T['$container']>): T;
22
+ update(nodeArg: Partial<T | NodeFactoriesFor<T>>): T;
23
+ }
24
+
25
+ declare class ThisExprFactory extends AstFactory<ThisExpr> {
26
+ constructor();
27
+ }
28
+ declare class NullExprFactory extends AstFactory<NullExpr> {
29
+ constructor();
30
+ }
31
+ declare class NumberLiteralFactory extends AstFactory<NumberLiteral> {
32
+ value?: number | string;
33
+ constructor();
34
+ setValue(value: number | string): this;
35
+ }
36
+ declare class StringLiteralFactory extends AstFactory<StringLiteral> {
37
+ value?: string;
38
+ constructor();
39
+ setValue(value: string): this;
40
+ }
41
+ declare class BooleanLiteralFactory extends AstFactory<BooleanLiteral> {
42
+ value?: boolean;
43
+ constructor();
44
+ setValue(value: boolean): this;
45
+ }
46
+
47
+ type ExpressionFactoryMap = ReturnType<typeof ExpressionBuilder>;
48
+ declare const ExpressionBuilder: () => {
49
+ readonly ArrayExpr: ArrayExprFactory;
50
+ readonly BinaryExpr: BinaryExprFactory;
51
+ readonly BooleanLiteral: BooleanLiteralFactory;
52
+ readonly InvocationExpr: InvocationExprFactory;
53
+ readonly MemberAccessExpr: MemberAccessExprFactory;
54
+ readonly NullExpr: NullExprFactory;
55
+ readonly NumberLiteral: NumberLiteralFactory;
56
+ readonly ObjectExpr: ObjectExprFactory;
57
+ readonly ReferenceExpr: ReferenceExprFactory;
58
+ readonly StringLiteral: StringLiteralFactory;
59
+ readonly ThisExpr: ThisExprFactory;
60
+ readonly UnaryExpr: UnaryExprFactory;
61
+ };
62
+ type ExpressionBuilder<T extends Expression = Expression> = Pick<ExpressionFactoryMap, Extract<T['$type'], keyof ExpressionFactoryMap>>;
63
+ declare class UnaryExprFactory extends AstFactory<UnaryExpr> {
64
+ operand?: AstFactory<Expression>;
65
+ constructor();
66
+ setOperand(builder: (a: ExpressionBuilder) => AstFactory<Expression>): this;
67
+ }
68
+ declare class ReferenceExprFactory extends AstFactory<ReferenceExpr> {
69
+ target?: Reference<ReferenceTarget>;
70
+ args: ReferenceArgFactory[];
71
+ constructor();
72
+ setTarget(target: ReferenceTarget): this;
73
+ addArg(builder: (a: ExpressionBuilder) => AstFactory<Expression>, name?: string): this;
74
+ }
75
+ declare class ReferenceArgFactory extends AstFactory<ReferenceArg> {
76
+ name?: string;
77
+ value?: AstFactory<Expression>;
78
+ constructor();
79
+ setName(name: string): this;
80
+ setValue(builder: (a: ExpressionBuilder) => AstFactory<Expression>): this;
81
+ }
82
+ declare class MemberAccessExprFactory extends AstFactory<MemberAccessExpr> {
83
+ member?: Reference<MemberAccessTarget>;
84
+ operand?: AstFactory<Expression>;
85
+ constructor();
86
+ setMember(target: Reference<MemberAccessTarget>): this;
87
+ setOperand(builder: (b: ExpressionBuilder) => AstFactory<Expression>): this;
88
+ }
89
+ declare class ObjectExprFactory extends AstFactory<ObjectExpr> {
90
+ fields: FieldInitializerFactory[];
91
+ constructor();
92
+ addField(builder: (b: FieldInitializerFactory) => FieldInitializerFactory): this;
93
+ }
94
+ declare class FieldInitializerFactory extends AstFactory<FieldInitializer> {
95
+ name?: RegularID;
96
+ value?: AstFactory<Expression>;
97
+ constructor();
98
+ setName(name: RegularID): this;
99
+ setValue(builder: (a: ExpressionBuilder) => AstFactory<Expression>): this;
100
+ }
101
+ declare class InvocationExprFactory extends AstFactory<InvocationExpr> {
102
+ args: ArgumentFactory[];
103
+ function?: Reference<FunctionDecl>;
104
+ constructor();
105
+ addArg(builder: (arg: ArgumentFactory) => ArgumentFactory): this;
106
+ setFunction(value: FunctionDecl): this;
107
+ }
108
+ declare class ArgumentFactory extends AstFactory<Argument> {
109
+ value?: AstFactory<Expression>;
110
+ constructor();
111
+ setValue(builder: (a: ExpressionBuilder) => AstFactory<Expression>): this;
112
+ }
113
+ declare class ArrayExprFactory extends AstFactory<ArrayExpr> {
114
+ items: AstFactory<Expression>[];
115
+ constructor();
116
+ addItem(builder: (a: ExpressionBuilder) => AstFactory<Expression>): this;
117
+ }
118
+ declare class BinaryExprFactory extends AstFactory<BinaryExpr> {
119
+ operator?: BinaryExpr['operator'];
120
+ right?: AstFactory<Expression>;
121
+ left?: AstFactory<Expression>;
122
+ constructor();
123
+ setOperator(operator: BinaryExpr['operator']): this;
124
+ setRight(builder: (arg: ExpressionBuilder) => AstFactory<Expression>): this;
125
+ setLeft(builder: (arg: ExpressionBuilder) => AstFactory<Expression>): this;
126
+ }
127
+
128
+ declare class DataFieldAttributeFactory extends AstFactory<DataFieldAttribute> {
129
+ args: AttributeArgFactory[];
130
+ decl?: Reference<Attribute>;
131
+ constructor();
132
+ setDecl(decl: Attribute): this;
133
+ addArg(builder: (b: ExpressionBuilder) => AstFactory<Expression>, name?: string): this;
134
+ }
135
+ declare class DataModelAttributeFactory extends AstFactory<DataModelAttribute> {
136
+ args: AttributeArgFactory[];
137
+ decl?: Reference<Attribute>;
138
+ constructor();
139
+ setDecl(decl: Attribute): this;
140
+ addArg(builder: (b: ExpressionBuilder) => AstFactory<Expression>, name?: string): this;
141
+ }
142
+ declare class AttributeArgFactory extends AstFactory<AttributeArg> {
143
+ name?: RegularID;
144
+ value?: AstFactory<Expression>;
145
+ constructor();
146
+ setName(name: RegularID): this;
147
+ setValue(builder: (b: ExpressionBuilder) => AstFactory<Expression>): this;
148
+ }
149
+ declare class InternalAttributeFactory extends AstFactory<InternalAttribute> {
150
+ decl?: Reference<Attribute>;
151
+ args: AttributeArgFactory[];
152
+ constructor();
153
+ setDecl(decl: Attribute): this;
154
+ addArg(builder: (b: ExpressionBuilder) => AstFactory<Expression>, name?: string): this;
155
+ }
156
+ declare class AttributeParamFactory extends AstFactory<AttributeParam> {
157
+ attributes: InternalAttributeFactory[];
158
+ comments: string[];
159
+ default?: boolean;
160
+ name?: RegularID;
161
+ type?: AttributeParamTypeFactory;
162
+ constructor();
163
+ addAttribute(builder: (b: InternalAttributeFactory) => InternalAttributeFactory): this;
164
+ setComments(comments: string[]): this;
165
+ setDefault(defaultValue: boolean): this;
166
+ setName(name: string): this;
167
+ setType(builder: (b: AttributeParamTypeFactory) => AttributeParamTypeFactory): this;
168
+ }
169
+ declare class AttributeParamTypeFactory extends AstFactory<AttributeParamType> {
170
+ array?: boolean;
171
+ optional?: boolean;
172
+ reference?: Reference<TypeDeclaration>;
173
+ type?: AttributeParamType['type'];
174
+ constructor();
175
+ setArray(array: boolean): this;
176
+ setOptional(optional: boolean): this;
177
+ setReference(reference: TypeDeclaration): this;
178
+ setType(type: AttributeParamType['type']): this;
179
+ }
180
+ declare class AttributeFactory extends AstFactory<Attribute> {
181
+ name?: string;
182
+ comments: string[];
183
+ attributes: InternalAttributeFactory[];
184
+ params: AttributeParamFactory[];
185
+ constructor();
186
+ setName(name: string): this;
187
+ setComments(comments: string[]): this;
188
+ addAttribute(builder: (b: InternalAttributeFactory) => InternalAttributeFactory): this;
189
+ addParam(builder: (b: AttributeParamFactory) => AttributeParamFactory): this;
190
+ }
191
+
192
+ type DeclarationBuilderMap = ReturnType<typeof DeclarationBuilder>;
193
+ declare const DeclarationBuilder: () => {
194
+ readonly Attribute: AttributeFactory;
195
+ readonly DataModel: DataModelFactory;
196
+ readonly DataSource: any;
197
+ readonly Enum: EnumFactory;
198
+ readonly FunctionDecl: any;
199
+ readonly GeneratorDecl: any;
200
+ readonly Plugin: any;
201
+ readonly Procedure: any;
202
+ readonly TypeDef: any;
203
+ };
204
+ type DeclarationBuilder<T extends AbstractDeclaration = AbstractDeclaration> = Pick<DeclarationBuilderMap, Extract<T['$type'], keyof DeclarationBuilderMap>>;
205
+ declare class DataModelFactory extends AstFactory<DataModel> {
206
+ attributes: DataModelAttributeFactory[];
207
+ baseModel?: Reference<DataModel>;
208
+ comments: string[];
209
+ fields: DataFieldFactory[];
210
+ isView?: boolean;
211
+ mixins: Reference<TypeDef>[];
212
+ name?: RegularID;
213
+ constructor();
214
+ addAttribute(builder: (attr: DataModelAttributeFactory) => DataModelAttributeFactory): this;
215
+ setBaseModel(model: Reference<DataModel>): this;
216
+ setComments(comments: string[]): this;
217
+ addComment(comment: string): this;
218
+ addField(builder: (field: DataFieldFactory) => DataFieldFactory): this;
219
+ setIsView(isView: boolean): this;
220
+ addMixin(mixin: Reference<TypeDef>): this;
221
+ setName(name: string): this;
222
+ }
223
+ declare class DataFieldFactory extends AstFactory<DataField> {
224
+ attributes: DataFieldAttributeFactory[];
225
+ comments: string[];
226
+ name?: string;
227
+ type?: DataFieldTypeFactory;
228
+ constructor();
229
+ addAttribute(builder: ((attr: DataFieldAttributeFactory) => DataFieldAttributeFactory) | DataFieldAttributeFactory): this;
230
+ setComments(comments: string[]): this;
231
+ setName(name: string): this;
232
+ setType(builder: (type: DataFieldTypeFactory) => DataFieldTypeFactory): this;
233
+ }
234
+ declare class DataFieldTypeFactory extends AstFactory<DataFieldType> {
235
+ array?: boolean;
236
+ optional?: boolean;
237
+ reference?: Reference<TypeDeclaration>;
238
+ type?: BuiltinType;
239
+ unsupported?: UnsupportedFieldTypeFactory;
240
+ constructor();
241
+ setArray(array: boolean): this;
242
+ setOptional(optional: boolean): this;
243
+ setReference(reference: TypeDeclaration): this;
244
+ setType(type: BuiltinType): this;
245
+ setUnsupported(builder: (a: UnsupportedFieldTypeFactory) => UnsupportedFieldTypeFactory): this;
246
+ }
247
+ declare class UnsupportedFieldTypeFactory extends AstFactory<UnsupportedFieldType> {
248
+ value?: AstFactory<LiteralExpr>;
249
+ constructor();
250
+ setValue(builder: (value: ExpressionBuilder<LiteralExpr>) => AstFactory<LiteralExpr>): this;
251
+ }
252
+ declare class ModelFactory extends AstFactory<Model> {
253
+ declarations: AstFactory<AbstractDeclaration>[];
254
+ imports: ModelImportFactory[];
255
+ constructor();
256
+ addImport(builder: (b: ModelImportFactory) => ModelImportFactory): this;
257
+ addDeclaration(builder: (b: DeclarationBuilder) => AstFactory<AbstractDeclaration>): this;
258
+ }
259
+ declare class ModelImportFactory extends AstFactory<ModelImport> {
260
+ path?: string | undefined;
261
+ constructor();
262
+ setPath(path: string): this;
263
+ }
264
+ declare class EnumFactory extends AstFactory<Enum> {
265
+ name?: string;
266
+ comments: string[];
267
+ fields: EnumFieldFactory[];
268
+ attributes: DataModelAttributeFactory[];
269
+ constructor();
270
+ addField(builder: (b: EnumFieldFactory) => EnumFieldFactory): this;
271
+ addAttribute(builder: (b: DataModelAttributeFactory) => DataModelAttributeFactory): this;
272
+ setName(name: string): this;
273
+ }
274
+ declare class EnumFieldFactory extends AstFactory<EnumField> {
275
+ name?: RegularIDWithTypeNames;
276
+ comments: string[];
277
+ attributes: DataFieldAttributeFactory[];
278
+ constructor();
279
+ setName(name: RegularIDWithTypeNames): this;
280
+ addAttribute(builder: (b: DataFieldAttributeFactory) => DataFieldAttributeFactory): this;
281
+ addComment(comment: string): this;
282
+ }
283
+
284
+ export { ArgumentFactory, ArrayExprFactory, AstFactory, AttributeArgFactory, AttributeFactory, AttributeParamFactory, AttributeParamTypeFactory, BinaryExprFactory, BooleanLiteralFactory, type ContainerProps, DataFieldAttributeFactory, DataFieldFactory, DataFieldTypeFactory, DataModelAttributeFactory, DataModelFactory, DeclarationBuilder, EnumFactory, EnumFieldFactory, ExpressionBuilder, FieldInitializerFactory, InternalAttributeFactory, InvocationExprFactory, MemberAccessExprFactory, ModelFactory, ModelImportFactory, NullExprFactory, NumberLiteralFactory, ObjectExprFactory, ReferenceArgFactory, ReferenceExprFactory, StringLiteralFactory, ThisExprFactory, UnaryExprFactory, UnsupportedFieldTypeFactory };