@zenstackhq/sdk 3.0.0-beta.9 → 3.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.
- package/dist/{schema.cjs → ast.cjs} +10 -4
- package/dist/ast.cjs.map +1 -0
- package/dist/ast.d.cts +1 -0
- package/dist/ast.d.ts +1 -0
- package/dist/ast.js +3 -0
- package/dist/ast.js.map +1 -0
- package/dist/index.cjs +222 -958
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -182
- package/dist/index.d.ts +18 -182
- package/dist/index.js +225 -958
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/dist/expression-Ce_oulwU.d.cts +0 -44
- package/dist/expression-Ce_oulwU.d.ts +0 -44
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.cts +0 -125
- package/dist/schema.d.ts +0 -125
- package/dist/schema.js +0 -1
- package/dist/schema.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -90,7 +90,7 @@ __name(resolved, "resolved");
|
|
|
90
90
|
function getAuthDecl(model) {
|
|
91
91
|
let found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
92
92
|
if (!found) {
|
|
93
|
-
found = model.declarations.find((d) => isDataModel(d) && d.name === "User");
|
|
93
|
+
found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.name === "User");
|
|
94
94
|
}
|
|
95
95
|
return found;
|
|
96
96
|
}
|
|
@@ -101,365 +101,13 @@ function getIdFields(dm) {
|
|
|
101
101
|
__name(getIdFields, "getIdFields");
|
|
102
102
|
var DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
|
|
103
103
|
|
|
104
|
-
// src/expression-utils.ts
|
|
105
|
-
import { match } from "ts-pattern";
|
|
106
|
-
var ExpressionVisitor = class {
|
|
107
|
-
static {
|
|
108
|
-
__name(this, "ExpressionVisitor");
|
|
109
|
-
}
|
|
110
|
-
visit(expr) {
|
|
111
|
-
match(expr).with({
|
|
112
|
-
kind: "literal"
|
|
113
|
-
}, (e) => this.visitLiteral(e)).with({
|
|
114
|
-
kind: "array"
|
|
115
|
-
}, (e) => this.visitArray(e)).with({
|
|
116
|
-
kind: "field"
|
|
117
|
-
}, (e) => this.visitField(e)).with({
|
|
118
|
-
kind: "member"
|
|
119
|
-
}, (e) => this.visitMember(e)).with({
|
|
120
|
-
kind: "binary"
|
|
121
|
-
}, (e) => this.visitBinary(e)).with({
|
|
122
|
-
kind: "unary"
|
|
123
|
-
}, (e) => this.visitUnary(e)).with({
|
|
124
|
-
kind: "call"
|
|
125
|
-
}, (e) => this.visitCall(e)).with({
|
|
126
|
-
kind: "this"
|
|
127
|
-
}, (e) => this.visitThis(e)).with({
|
|
128
|
-
kind: "null"
|
|
129
|
-
}, (e) => this.visitNull(e)).exhaustive();
|
|
130
|
-
}
|
|
131
|
-
visitLiteral(_e) {
|
|
132
|
-
}
|
|
133
|
-
visitArray(e) {
|
|
134
|
-
e.items.forEach((item) => this.visit(item));
|
|
135
|
-
}
|
|
136
|
-
visitField(_e) {
|
|
137
|
-
}
|
|
138
|
-
visitMember(e) {
|
|
139
|
-
this.visit(e.receiver);
|
|
140
|
-
}
|
|
141
|
-
visitBinary(e) {
|
|
142
|
-
this.visit(e.left);
|
|
143
|
-
this.visit(e.right);
|
|
144
|
-
}
|
|
145
|
-
visitUnary(e) {
|
|
146
|
-
this.visit(e.operand);
|
|
147
|
-
}
|
|
148
|
-
visitCall(e) {
|
|
149
|
-
e.args?.forEach((arg) => this.visit(arg));
|
|
150
|
-
}
|
|
151
|
-
visitThis(_e) {
|
|
152
|
-
}
|
|
153
|
-
visitNull(_e) {
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// src/default-operation-node-visitor.ts
|
|
158
|
-
import { OperationNodeVisitor } from "kysely";
|
|
159
|
-
var DefaultOperationNodeVisitor = class extends OperationNodeVisitor {
|
|
160
|
-
static {
|
|
161
|
-
__name(this, "DefaultOperationNodeVisitor");
|
|
162
|
-
}
|
|
163
|
-
defaultVisit(node) {
|
|
164
|
-
Object.values(node).forEach((value) => {
|
|
165
|
-
if (!value) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (Array.isArray(value)) {
|
|
169
|
-
value.forEach((el) => this.defaultVisit(el));
|
|
170
|
-
}
|
|
171
|
-
if (typeof value === "object" && "kind" in value && typeof value.kind === "string") {
|
|
172
|
-
this.visitNode(value);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
visitSelectQuery(node) {
|
|
177
|
-
this.defaultVisit(node);
|
|
178
|
-
}
|
|
179
|
-
visitSelection(node) {
|
|
180
|
-
this.defaultVisit(node);
|
|
181
|
-
}
|
|
182
|
-
visitColumn(node) {
|
|
183
|
-
this.defaultVisit(node);
|
|
184
|
-
}
|
|
185
|
-
visitAlias(node) {
|
|
186
|
-
this.defaultVisit(node);
|
|
187
|
-
}
|
|
188
|
-
visitTable(node) {
|
|
189
|
-
this.defaultVisit(node);
|
|
190
|
-
}
|
|
191
|
-
visitFrom(node) {
|
|
192
|
-
this.defaultVisit(node);
|
|
193
|
-
}
|
|
194
|
-
visitReference(node) {
|
|
195
|
-
this.defaultVisit(node);
|
|
196
|
-
}
|
|
197
|
-
visitAnd(node) {
|
|
198
|
-
this.defaultVisit(node);
|
|
199
|
-
}
|
|
200
|
-
visitOr(node) {
|
|
201
|
-
this.defaultVisit(node);
|
|
202
|
-
}
|
|
203
|
-
visitValueList(node) {
|
|
204
|
-
this.defaultVisit(node);
|
|
205
|
-
}
|
|
206
|
-
visitParens(node) {
|
|
207
|
-
this.defaultVisit(node);
|
|
208
|
-
}
|
|
209
|
-
visitJoin(node) {
|
|
210
|
-
this.defaultVisit(node);
|
|
211
|
-
}
|
|
212
|
-
visitRaw(node) {
|
|
213
|
-
this.defaultVisit(node);
|
|
214
|
-
}
|
|
215
|
-
visitWhere(node) {
|
|
216
|
-
this.defaultVisit(node);
|
|
217
|
-
}
|
|
218
|
-
visitInsertQuery(node) {
|
|
219
|
-
this.defaultVisit(node);
|
|
220
|
-
}
|
|
221
|
-
visitDeleteQuery(node) {
|
|
222
|
-
this.defaultVisit(node);
|
|
223
|
-
}
|
|
224
|
-
visitReturning(node) {
|
|
225
|
-
this.defaultVisit(node);
|
|
226
|
-
}
|
|
227
|
-
visitCreateTable(node) {
|
|
228
|
-
this.defaultVisit(node);
|
|
229
|
-
}
|
|
230
|
-
visitAddColumn(node) {
|
|
231
|
-
this.defaultVisit(node);
|
|
232
|
-
}
|
|
233
|
-
visitColumnDefinition(node) {
|
|
234
|
-
this.defaultVisit(node);
|
|
235
|
-
}
|
|
236
|
-
visitDropTable(node) {
|
|
237
|
-
this.defaultVisit(node);
|
|
238
|
-
}
|
|
239
|
-
visitOrderBy(node) {
|
|
240
|
-
this.defaultVisit(node);
|
|
241
|
-
}
|
|
242
|
-
visitOrderByItem(node) {
|
|
243
|
-
this.defaultVisit(node);
|
|
244
|
-
}
|
|
245
|
-
visitGroupBy(node) {
|
|
246
|
-
this.defaultVisit(node);
|
|
247
|
-
}
|
|
248
|
-
visitGroupByItem(node) {
|
|
249
|
-
this.defaultVisit(node);
|
|
250
|
-
}
|
|
251
|
-
visitUpdateQuery(node) {
|
|
252
|
-
this.defaultVisit(node);
|
|
253
|
-
}
|
|
254
|
-
visitColumnUpdate(node) {
|
|
255
|
-
this.defaultVisit(node);
|
|
256
|
-
}
|
|
257
|
-
visitLimit(node) {
|
|
258
|
-
this.defaultVisit(node);
|
|
259
|
-
}
|
|
260
|
-
visitOffset(node) {
|
|
261
|
-
this.defaultVisit(node);
|
|
262
|
-
}
|
|
263
|
-
visitOnConflict(node) {
|
|
264
|
-
this.defaultVisit(node);
|
|
265
|
-
}
|
|
266
|
-
visitOnDuplicateKey(node) {
|
|
267
|
-
this.defaultVisit(node);
|
|
268
|
-
}
|
|
269
|
-
visitCheckConstraint(node) {
|
|
270
|
-
this.defaultVisit(node);
|
|
271
|
-
}
|
|
272
|
-
visitDataType(node) {
|
|
273
|
-
this.defaultVisit(node);
|
|
274
|
-
}
|
|
275
|
-
visitSelectAll(node) {
|
|
276
|
-
this.defaultVisit(node);
|
|
277
|
-
}
|
|
278
|
-
visitIdentifier(node) {
|
|
279
|
-
this.defaultVisit(node);
|
|
280
|
-
}
|
|
281
|
-
visitSchemableIdentifier(node) {
|
|
282
|
-
this.defaultVisit(node);
|
|
283
|
-
}
|
|
284
|
-
visitValue(node) {
|
|
285
|
-
this.defaultVisit(node);
|
|
286
|
-
}
|
|
287
|
-
visitPrimitiveValueList(node) {
|
|
288
|
-
this.defaultVisit(node);
|
|
289
|
-
}
|
|
290
|
-
visitOperator(node) {
|
|
291
|
-
this.defaultVisit(node);
|
|
292
|
-
}
|
|
293
|
-
visitCreateIndex(node) {
|
|
294
|
-
this.defaultVisit(node);
|
|
295
|
-
}
|
|
296
|
-
visitDropIndex(node) {
|
|
297
|
-
this.defaultVisit(node);
|
|
298
|
-
}
|
|
299
|
-
visitList(node) {
|
|
300
|
-
this.defaultVisit(node);
|
|
301
|
-
}
|
|
302
|
-
visitPrimaryKeyConstraint(node) {
|
|
303
|
-
this.defaultVisit(node);
|
|
304
|
-
}
|
|
305
|
-
visitUniqueConstraint(node) {
|
|
306
|
-
this.defaultVisit(node);
|
|
307
|
-
}
|
|
308
|
-
visitReferences(node) {
|
|
309
|
-
this.defaultVisit(node);
|
|
310
|
-
}
|
|
311
|
-
visitWith(node) {
|
|
312
|
-
this.defaultVisit(node);
|
|
313
|
-
}
|
|
314
|
-
visitCommonTableExpression(node) {
|
|
315
|
-
this.defaultVisit(node);
|
|
316
|
-
}
|
|
317
|
-
visitCommonTableExpressionName(node) {
|
|
318
|
-
this.defaultVisit(node);
|
|
319
|
-
}
|
|
320
|
-
visitHaving(node) {
|
|
321
|
-
this.defaultVisit(node);
|
|
322
|
-
}
|
|
323
|
-
visitCreateSchema(node) {
|
|
324
|
-
this.defaultVisit(node);
|
|
325
|
-
}
|
|
326
|
-
visitDropSchema(node) {
|
|
327
|
-
this.defaultVisit(node);
|
|
328
|
-
}
|
|
329
|
-
visitAlterTable(node) {
|
|
330
|
-
this.defaultVisit(node);
|
|
331
|
-
}
|
|
332
|
-
visitDropColumn(node) {
|
|
333
|
-
this.defaultVisit(node);
|
|
334
|
-
}
|
|
335
|
-
visitRenameColumn(node) {
|
|
336
|
-
this.defaultVisit(node);
|
|
337
|
-
}
|
|
338
|
-
visitAlterColumn(node) {
|
|
339
|
-
this.defaultVisit(node);
|
|
340
|
-
}
|
|
341
|
-
visitModifyColumn(node) {
|
|
342
|
-
this.defaultVisit(node);
|
|
343
|
-
}
|
|
344
|
-
visitAddConstraint(node) {
|
|
345
|
-
this.defaultVisit(node);
|
|
346
|
-
}
|
|
347
|
-
visitDropConstraint(node) {
|
|
348
|
-
this.defaultVisit(node);
|
|
349
|
-
}
|
|
350
|
-
visitForeignKeyConstraint(node) {
|
|
351
|
-
this.defaultVisit(node);
|
|
352
|
-
}
|
|
353
|
-
visitCreateView(node) {
|
|
354
|
-
this.defaultVisit(node);
|
|
355
|
-
}
|
|
356
|
-
visitDropView(node) {
|
|
357
|
-
this.defaultVisit(node);
|
|
358
|
-
}
|
|
359
|
-
visitGenerated(node) {
|
|
360
|
-
this.defaultVisit(node);
|
|
361
|
-
}
|
|
362
|
-
visitDefaultValue(node) {
|
|
363
|
-
this.defaultVisit(node);
|
|
364
|
-
}
|
|
365
|
-
visitOn(node) {
|
|
366
|
-
this.defaultVisit(node);
|
|
367
|
-
}
|
|
368
|
-
visitValues(node) {
|
|
369
|
-
this.defaultVisit(node);
|
|
370
|
-
}
|
|
371
|
-
visitSelectModifier(node) {
|
|
372
|
-
this.defaultVisit(node);
|
|
373
|
-
}
|
|
374
|
-
visitCreateType(node) {
|
|
375
|
-
this.defaultVisit(node);
|
|
376
|
-
}
|
|
377
|
-
visitDropType(node) {
|
|
378
|
-
this.defaultVisit(node);
|
|
379
|
-
}
|
|
380
|
-
visitExplain(node) {
|
|
381
|
-
this.defaultVisit(node);
|
|
382
|
-
}
|
|
383
|
-
visitDefaultInsertValue(node) {
|
|
384
|
-
this.defaultVisit(node);
|
|
385
|
-
}
|
|
386
|
-
visitAggregateFunction(node) {
|
|
387
|
-
this.defaultVisit(node);
|
|
388
|
-
}
|
|
389
|
-
visitOver(node) {
|
|
390
|
-
this.defaultVisit(node);
|
|
391
|
-
}
|
|
392
|
-
visitPartitionBy(node) {
|
|
393
|
-
this.defaultVisit(node);
|
|
394
|
-
}
|
|
395
|
-
visitPartitionByItem(node) {
|
|
396
|
-
this.defaultVisit(node);
|
|
397
|
-
}
|
|
398
|
-
visitSetOperation(node) {
|
|
399
|
-
this.defaultVisit(node);
|
|
400
|
-
}
|
|
401
|
-
visitBinaryOperation(node) {
|
|
402
|
-
this.defaultVisit(node);
|
|
403
|
-
}
|
|
404
|
-
visitUnaryOperation(node) {
|
|
405
|
-
this.defaultVisit(node);
|
|
406
|
-
}
|
|
407
|
-
visitUsing(node) {
|
|
408
|
-
this.defaultVisit(node);
|
|
409
|
-
}
|
|
410
|
-
visitFunction(node) {
|
|
411
|
-
this.defaultVisit(node);
|
|
412
|
-
}
|
|
413
|
-
visitCase(node) {
|
|
414
|
-
this.defaultVisit(node);
|
|
415
|
-
}
|
|
416
|
-
visitWhen(node) {
|
|
417
|
-
this.defaultVisit(node);
|
|
418
|
-
}
|
|
419
|
-
visitJSONReference(node) {
|
|
420
|
-
this.defaultVisit(node);
|
|
421
|
-
}
|
|
422
|
-
visitJSONPath(node) {
|
|
423
|
-
this.defaultVisit(node);
|
|
424
|
-
}
|
|
425
|
-
visitJSONPathLeg(node) {
|
|
426
|
-
this.defaultVisit(node);
|
|
427
|
-
}
|
|
428
|
-
visitJSONOperatorChain(node) {
|
|
429
|
-
this.defaultVisit(node);
|
|
430
|
-
}
|
|
431
|
-
visitTuple(node) {
|
|
432
|
-
this.defaultVisit(node);
|
|
433
|
-
}
|
|
434
|
-
visitMergeQuery(node) {
|
|
435
|
-
this.defaultVisit(node);
|
|
436
|
-
}
|
|
437
|
-
visitMatched(node) {
|
|
438
|
-
this.defaultVisit(node);
|
|
439
|
-
}
|
|
440
|
-
visitAddIndex(node) {
|
|
441
|
-
this.defaultVisit(node);
|
|
442
|
-
}
|
|
443
|
-
visitCast(node) {
|
|
444
|
-
this.defaultVisit(node);
|
|
445
|
-
}
|
|
446
|
-
visitFetch(node) {
|
|
447
|
-
this.defaultVisit(node);
|
|
448
|
-
}
|
|
449
|
-
visitTop(node) {
|
|
450
|
-
this.defaultVisit(node);
|
|
451
|
-
}
|
|
452
|
-
visitOutput(node) {
|
|
453
|
-
this.defaultVisit(node);
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
|
|
457
104
|
// src/prisma/prisma-schema-generator.ts
|
|
458
105
|
import { lowerCaseFirst } from "@zenstackhq/common-helpers";
|
|
459
|
-
import {
|
|
460
|
-
import {
|
|
106
|
+
import { ZModelCodeGenerator } from "@zenstackhq/language";
|
|
107
|
+
import { BooleanLiteral, DataModel, DataSource as DataSource2, Enum as Enum2, GeneratorDecl, isArrayExpr, isDataModel as isDataModel2, isDataSource, isGeneratorDecl, isInvocationExpr, isLiteralExpr as isLiteralExpr2, isNullExpr, isReferenceExpr, isStringLiteral, isTypeDef as isTypeDef2, NumberLiteral, StringLiteral } from "@zenstackhq/language/ast";
|
|
108
|
+
import { getAllAttributes, getAllFields as getAllFields2, getStringLiteral, isAuthInvocation, isDelegateModel as isDelegateModel2 } from "@zenstackhq/language/utils";
|
|
461
109
|
import { AstUtils } from "langium";
|
|
462
|
-
import { match
|
|
110
|
+
import { match } from "ts-pattern";
|
|
463
111
|
|
|
464
112
|
// src/prisma/indent-string.ts
|
|
465
113
|
function indentString(string, count = 4) {
|
|
@@ -853,6 +501,9 @@ var EnumField = class extends DeclarationBase {
|
|
|
853
501
|
|
|
854
502
|
// src/prisma/prisma-schema-generator.ts
|
|
855
503
|
var IDENTIFIER_NAME_MAX_LENGTH = 50 - DELEGATE_AUX_RELATION_PREFIX.length;
|
|
504
|
+
var NON_PRISMA_DATASOURCE_FIELDS = [
|
|
505
|
+
"defaultSchema"
|
|
506
|
+
];
|
|
856
507
|
var PrismaSchemaGenerator = class {
|
|
857
508
|
static {
|
|
858
509
|
__name(this, "PrismaSchemaGenerator");
|
|
@@ -887,10 +538,13 @@ var PrismaSchemaGenerator = class {
|
|
|
887
538
|
break;
|
|
888
539
|
}
|
|
889
540
|
}
|
|
541
|
+
if (!this.zmodel.declarations.some(isGeneratorDecl)) {
|
|
542
|
+
this.generateDefaultGenerator(prisma);
|
|
543
|
+
}
|
|
890
544
|
return this.PRELUDE + prisma.toString();
|
|
891
545
|
}
|
|
892
546
|
generateDataSource(prisma, dataSource) {
|
|
893
|
-
const fields = dataSource.fields.map((f) => ({
|
|
547
|
+
const fields = dataSource.fields.filter((f) => !NON_PRISMA_DATASOURCE_FIELDS.includes(f.name)).map((f) => ({
|
|
894
548
|
name: f.name,
|
|
895
549
|
text: this.configExprToText(f.value)
|
|
896
550
|
}));
|
|
@@ -927,6 +581,21 @@ var PrismaSchemaGenerator = class {
|
|
|
927
581
|
text: this.configExprToText(f.value)
|
|
928
582
|
})));
|
|
929
583
|
}
|
|
584
|
+
generateDefaultGenerator(prisma) {
|
|
585
|
+
const gen = prisma.addGenerator("client", [
|
|
586
|
+
{
|
|
587
|
+
name: "provider",
|
|
588
|
+
text: '"prisma-client-js"'
|
|
589
|
+
}
|
|
590
|
+
]);
|
|
591
|
+
const dataSource = this.zmodel.declarations.find(isDataSource);
|
|
592
|
+
if (dataSource?.fields.some((f) => f.name === "extensions")) {
|
|
593
|
+
gen.fields.push({
|
|
594
|
+
name: "previewFeatures",
|
|
595
|
+
text: '["postgresqlExtensions"]'
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
930
599
|
generateModel(prisma, decl) {
|
|
931
600
|
const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
|
|
932
601
|
const allFields = getAllFields2(decl, true);
|
|
@@ -938,20 +607,29 @@ var PrismaSchemaGenerator = class {
|
|
|
938
607
|
this.generateModelField(model, field, decl);
|
|
939
608
|
}
|
|
940
609
|
}
|
|
941
|
-
const allAttributes = getAllAttributes(decl);
|
|
942
|
-
for (const attr of allAttributes
|
|
610
|
+
const allAttributes = getAllAttributes(decl).filter((attr) => this.isPrismaAttribute(attr));
|
|
611
|
+
for (const attr of allAttributes) {
|
|
943
612
|
this.generateContainerAttribute(model, attr);
|
|
944
613
|
}
|
|
614
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
615
|
+
model.addAttribute("@@schema", [
|
|
616
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
617
|
+
]);
|
|
618
|
+
}
|
|
945
619
|
decl.comments.forEach((c) => model.addComment(c));
|
|
946
620
|
this.generateDelegateRelationForBase(model, decl);
|
|
947
621
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
948
622
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
return
|
|
623
|
+
getDatasourceField(zmodel, fieldName) {
|
|
624
|
+
const dataSource = zmodel.declarations.find(isDataSource);
|
|
625
|
+
return dataSource?.fields.find((f) => f.name === fieldName);
|
|
626
|
+
}
|
|
627
|
+
datasourceHasSchemasSetting(zmodel) {
|
|
628
|
+
return !!this.getDatasourceField(zmodel, "schemas");
|
|
629
|
+
}
|
|
630
|
+
getDefaultPostgresSchemaName(zmodel) {
|
|
631
|
+
const defaultSchemaField = this.getDatasourceField(zmodel, "defaultSchema");
|
|
632
|
+
return getStringLiteral(defaultSchemaField?.value) ?? "public";
|
|
955
633
|
}
|
|
956
634
|
isPrismaAttribute(attr) {
|
|
957
635
|
if (!attr.decl.ref) {
|
|
@@ -961,7 +639,7 @@ var PrismaSchemaGenerator = class {
|
|
|
961
639
|
}
|
|
962
640
|
getUnsupportedFieldType(fieldType) {
|
|
963
641
|
if (fieldType.unsupported) {
|
|
964
|
-
const value =
|
|
642
|
+
const value = getStringLiteral(fieldType.unsupported.value);
|
|
965
643
|
if (value) {
|
|
966
644
|
return `Unsupported("${value}")`;
|
|
967
645
|
} else {
|
|
@@ -971,9 +649,6 @@ var PrismaSchemaGenerator = class {
|
|
|
971
649
|
return void 0;
|
|
972
650
|
}
|
|
973
651
|
}
|
|
974
|
-
getStringLiteral(node) {
|
|
975
|
-
return isStringLiteral(node) ? node.value : void 0;
|
|
976
|
-
}
|
|
977
652
|
generateModelField(model, field, contextModel, addToFront = false) {
|
|
978
653
|
let fieldType;
|
|
979
654
|
if (field.type.type) {
|
|
@@ -1030,7 +705,7 @@ var PrismaSchemaGenerator = class {
|
|
|
1030
705
|
}
|
|
1031
706
|
makeAttributeArgValue(node) {
|
|
1032
707
|
if (isLiteralExpr2(node)) {
|
|
1033
|
-
const argType =
|
|
708
|
+
const argType = match(node.$type).with(StringLiteral, () => "String").with(NumberLiteral, () => "Number").with(BooleanLiteral, () => "Boolean").exhaustive();
|
|
1034
709
|
return new AttributeArgValue(argType, node.value);
|
|
1035
710
|
} else if (isArrayExpr(node)) {
|
|
1036
711
|
return new AttributeArgValue("Array", new Array(...node.items.map((item) => this.makeAttributeArgValue(item))));
|
|
@@ -1049,7 +724,7 @@ var PrismaSchemaGenerator = class {
|
|
|
1049
724
|
}
|
|
1050
725
|
makeFunctionCall(node) {
|
|
1051
726
|
return new FunctionCall(node.function.ref.name, node.args.map((arg) => {
|
|
1052
|
-
const val =
|
|
727
|
+
const val = match(arg.value).when(isStringLiteral, (v) => `"${v.value}"`).when(isLiteralExpr2, (v) => v.value.toString()).when(isNullExpr, () => "null").otherwise(() => {
|
|
1053
728
|
throw new Error("Function call argument must be literal or null");
|
|
1054
729
|
});
|
|
1055
730
|
return new FunctionCallArg(val);
|
|
@@ -1064,9 +739,15 @@ var PrismaSchemaGenerator = class {
|
|
|
1064
739
|
for (const field of decl.fields) {
|
|
1065
740
|
this.generateEnumField(_enum, field);
|
|
1066
741
|
}
|
|
1067
|
-
|
|
742
|
+
const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
|
|
743
|
+
for (const attr of allAttributes) {
|
|
1068
744
|
this.generateContainerAttribute(_enum, attr);
|
|
1069
745
|
}
|
|
746
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
747
|
+
_enum.addAttribute("@@schema", [
|
|
748
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
749
|
+
]);
|
|
750
|
+
}
|
|
1070
751
|
decl.comments.forEach((c) => _enum.addComment(c));
|
|
1071
752
|
}
|
|
1072
753
|
generateEnumField(_enum, field) {
|
|
@@ -1134,40 +815,55 @@ var PrismaSchemaGenerator = class {
|
|
|
1134
815
|
|
|
1135
816
|
// src/ts-schema-generator.ts
|
|
1136
817
|
import { invariant } from "@zenstackhq/common-helpers";
|
|
1137
|
-
import { isArrayExpr as isArrayExpr2, isBinaryExpr, isDataField, isDataModel as isDataModel3, isDataSource, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as isTypeDef3, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
1138
|
-
import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, isDataFieldReference } from "@zenstackhq/language/utils";
|
|
818
|
+
import { isArrayExpr as isArrayExpr2, isBinaryExpr, isDataField, isDataModel as isDataModel3, isDataSource as isDataSource2, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as isTypeDef3, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
819
|
+
import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, getAttributeArg, isDataFieldReference } from "@zenstackhq/language/utils";
|
|
1139
820
|
import fs from "fs";
|
|
1140
821
|
import path from "path";
|
|
1141
|
-
import { match as
|
|
822
|
+
import { match as match2 } from "ts-pattern";
|
|
1142
823
|
import * as ts from "typescript";
|
|
1143
824
|
var TsSchemaGenerator = class {
|
|
1144
825
|
static {
|
|
1145
826
|
__name(this, "TsSchemaGenerator");
|
|
1146
827
|
}
|
|
1147
828
|
usedExpressionUtils = false;
|
|
1148
|
-
async generate(model,
|
|
1149
|
-
fs.mkdirSync(
|
|
829
|
+
async generate(model, options) {
|
|
830
|
+
fs.mkdirSync(options.outDir, {
|
|
1150
831
|
recursive: true
|
|
1151
832
|
});
|
|
1152
833
|
this.usedExpressionUtils = false;
|
|
1153
|
-
this.generateSchema(model,
|
|
1154
|
-
this.generateModelsAndTypeDefs(model,
|
|
1155
|
-
this.generateInputTypes(model,
|
|
1156
|
-
}
|
|
1157
|
-
generateSchema(model,
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
834
|
+
this.generateSchema(model, options);
|
|
835
|
+
this.generateModelsAndTypeDefs(model, options);
|
|
836
|
+
this.generateInputTypes(model, options);
|
|
837
|
+
}
|
|
838
|
+
generateSchema(model, options) {
|
|
839
|
+
const targets = [];
|
|
840
|
+
if (!options.liteOnly) {
|
|
841
|
+
targets.push({
|
|
842
|
+
lite: false,
|
|
843
|
+
file: "schema.ts"
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
if (options.lite || options.liteOnly) {
|
|
847
|
+
targets.push({
|
|
848
|
+
lite: true,
|
|
849
|
+
file: "schema-lite.ts"
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
for (const { lite, file } of targets) {
|
|
853
|
+
const statements = [];
|
|
854
|
+
this.generateSchemaStatements(model, statements, lite);
|
|
855
|
+
this.generateBannerComments(statements);
|
|
856
|
+
const schemaOutputFile = path.join(options.outDir, file);
|
|
857
|
+
const sourceFile = ts.createSourceFile(schemaOutputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
858
|
+
const printer = ts.createPrinter();
|
|
859
|
+
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
860
|
+
fs.writeFileSync(schemaOutputFile, result);
|
|
861
|
+
}
|
|
1166
862
|
}
|
|
1167
|
-
generateSchemaStatements(model, statements) {
|
|
863
|
+
generateSchemaStatements(model, statements, lite) {
|
|
1168
864
|
const hasComputedFields = model.declarations.some((d) => isDataModel3(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
1169
|
-
const
|
|
1170
|
-
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(
|
|
865
|
+
const schemaClass = this.createSchemaClass(model, lite);
|
|
866
|
+
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
|
|
1171
867
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
1172
868
|
...hasComputedFields ? [
|
|
1173
869
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
@@ -1175,64 +871,81 @@ var TsSchemaGenerator = class {
|
|
|
1175
871
|
...this.usedExpressionUtils ? [
|
|
1176
872
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
|
|
1177
873
|
] : []
|
|
1178
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
874
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
1179
875
|
statements.push(runtimeImportDecl);
|
|
1180
|
-
|
|
876
|
+
statements.push(schemaClass);
|
|
877
|
+
const schemaDecl = ts.factory.createVariableStatement([
|
|
1181
878
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1182
879
|
], ts.factory.createVariableDeclarationList([
|
|
1183
|
-
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.
|
|
880
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))
|
|
1184
881
|
], ts.NodeFlags.Const));
|
|
1185
|
-
statements.push(
|
|
1186
|
-
const typeDeclaration = ts.factory.createTypeAliasDeclaration([
|
|
1187
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1188
|
-
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("typeof schema"));
|
|
1189
|
-
statements.push(typeDeclaration);
|
|
882
|
+
statements.push(schemaDecl);
|
|
1190
883
|
}
|
|
1191
884
|
createExpressionUtilsCall(method, args) {
|
|
1192
885
|
this.usedExpressionUtils = true;
|
|
1193
886
|
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
1194
887
|
}
|
|
1195
|
-
|
|
1196
|
-
const
|
|
888
|
+
createSchemaClass(model, lite) {
|
|
889
|
+
const members = [
|
|
1197
890
|
// provider
|
|
1198
|
-
ts.factory.
|
|
891
|
+
ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
|
|
1199
892
|
// models
|
|
1200
|
-
ts.factory.
|
|
893
|
+
ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
|
|
1201
894
|
// typeDefs
|
|
1202
895
|
...model.declarations.some(isTypeDef3) ? [
|
|
1203
|
-
ts.factory.
|
|
896
|
+
ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))
|
|
1204
897
|
] : []
|
|
1205
898
|
];
|
|
1206
899
|
const enums = model.declarations.filter(isEnum);
|
|
1207
900
|
if (enums.length > 0) {
|
|
1208
|
-
|
|
901
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "enums", void 0, void 0, this.createAsConst(ts.factory.createObjectLiteralExpression(enums.map((e) => ts.factory.createPropertyAssignment(e.name, this.createEnumObject(e))), true))));
|
|
1209
902
|
}
|
|
1210
903
|
const authType = getAuthDecl(model);
|
|
1211
904
|
if (authType) {
|
|
1212
|
-
|
|
905
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
|
|
1213
906
|
}
|
|
1214
907
|
const procedures = model.declarations.filter(isProcedure);
|
|
1215
908
|
if (procedures.length > 0) {
|
|
1216
|
-
|
|
909
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
|
|
1217
910
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
911
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
|
|
912
|
+
const schemaClass = ts.factory.createClassDeclaration([
|
|
913
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
914
|
+
], "SchemaType", void 0, [
|
|
915
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
|
|
916
|
+
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)
|
|
917
|
+
])
|
|
918
|
+
], members);
|
|
919
|
+
return schemaClass;
|
|
920
|
+
}
|
|
921
|
+
createAsConst(expr) {
|
|
922
|
+
return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
|
|
1220
923
|
}
|
|
1221
924
|
createProviderObject(model) {
|
|
1222
925
|
const dsProvider = this.getDataSourceProvider(model);
|
|
926
|
+
const defaultSchema = this.getDataSourceDefaultSchema(model);
|
|
1223
927
|
return ts.factory.createObjectLiteralExpression([
|
|
1224
|
-
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider
|
|
928
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider)),
|
|
929
|
+
...defaultSchema ? [
|
|
930
|
+
ts.factory.createPropertyAssignment("defaultSchema", ts.factory.createStringLiteral(defaultSchema))
|
|
931
|
+
] : []
|
|
1225
932
|
], true);
|
|
1226
933
|
}
|
|
1227
|
-
createModelsObject(model) {
|
|
1228
|
-
return ts.factory.createObjectLiteralExpression(
|
|
934
|
+
createModelsObject(model, lite) {
|
|
935
|
+
return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
|
|
936
|
+
}
|
|
937
|
+
getAllDataModels(model) {
|
|
938
|
+
return model.declarations.filter((d) => isDataModel3(d) && !hasAttribute(d, "@@ignore"));
|
|
1229
939
|
}
|
|
1230
|
-
|
|
1231
|
-
return
|
|
940
|
+
getAllTypeDefs(model) {
|
|
941
|
+
return model.declarations.filter((d) => isTypeDef3(d) && !hasAttribute(d, "@@ignore"));
|
|
1232
942
|
}
|
|
1233
|
-
|
|
943
|
+
createTypeDefsObject(model, lite) {
|
|
944
|
+
return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
|
|
945
|
+
}
|
|
946
|
+
createDataModelObject(dm, lite) {
|
|
1234
947
|
const allFields = getAllFields3(dm);
|
|
1235
|
-
const allAttributes = getAllAttributes2(dm).filter((attr) => {
|
|
948
|
+
const allAttributes = lite ? [] : getAllAttributes2(dm).filter((attr) => {
|
|
1236
949
|
if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) {
|
|
1237
950
|
return false;
|
|
1238
951
|
}
|
|
@@ -1247,7 +960,7 @@ var TsSchemaGenerator = class {
|
|
|
1247
960
|
ts.factory.createPropertyAssignment("baseModel", ts.factory.createStringLiteral(dm.baseModel.$refText))
|
|
1248
961
|
] : [],
|
|
1249
962
|
// fields
|
|
1250
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm))), true)),
|
|
963
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm, lite))), true)),
|
|
1251
964
|
// attributes
|
|
1252
965
|
...allAttributes.length > 0 ? [
|
|
1253
966
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -1277,14 +990,14 @@ var TsSchemaGenerator = class {
|
|
|
1277
990
|
getSubModels(dm) {
|
|
1278
991
|
return dm.$container.declarations.filter(isDataModel3).filter((d) => d.baseModel?.ref === dm).map((d) => d.name);
|
|
1279
992
|
}
|
|
1280
|
-
createTypeDefObject(td) {
|
|
993
|
+
createTypeDefObject(td, lite) {
|
|
1281
994
|
const allFields = getAllFields3(td);
|
|
1282
995
|
const allAttributes = getAllAttributes2(td);
|
|
1283
996
|
const fields = [
|
|
1284
997
|
// name
|
|
1285
998
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
|
|
1286
999
|
// fields
|
|
1287
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0))), true)),
|
|
1000
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
|
|
1288
1001
|
// attributes
|
|
1289
1002
|
...allAttributes.length > 0 ? [
|
|
1290
1003
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -1307,7 +1020,7 @@ var TsSchemaGenerator = class {
|
|
|
1307
1020
|
], true))), true);
|
|
1308
1021
|
}
|
|
1309
1022
|
mapFieldTypeToTSType(type) {
|
|
1310
|
-
let result =
|
|
1023
|
+
let result = match2(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").otherwise(() => "unknown");
|
|
1311
1024
|
if (type.array) {
|
|
1312
1025
|
result = `${result}[]`;
|
|
1313
1026
|
}
|
|
@@ -1316,7 +1029,7 @@ var TsSchemaGenerator = class {
|
|
|
1316
1029
|
}
|
|
1317
1030
|
return result;
|
|
1318
1031
|
}
|
|
1319
|
-
createDataFieldObject(field, contextModel) {
|
|
1032
|
+
createDataFieldObject(field, contextModel, lite) {
|
|
1320
1033
|
const objectFields = [
|
|
1321
1034
|
// name
|
|
1322
1035
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
@@ -1338,6 +1051,9 @@ var TsSchemaGenerator = class {
|
|
|
1338
1051
|
if (hasAttribute(field, "@updatedAt")) {
|
|
1339
1052
|
objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
|
|
1340
1053
|
}
|
|
1054
|
+
if (hasAttribute(field, "@omit")) {
|
|
1055
|
+
objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
|
|
1056
|
+
}
|
|
1341
1057
|
if (contextModel && // id fields are duplicated in inherited models
|
|
1342
1058
|
!isIdField(field, contextModel) && field.$container !== contextModel && isDelegateModel(field.$container)) {
|
|
1343
1059
|
objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(field.$container.name)));
|
|
@@ -1345,7 +1061,7 @@ var TsSchemaGenerator = class {
|
|
|
1345
1061
|
if (this.isDiscriminatorField(field)) {
|
|
1346
1062
|
objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
|
|
1347
1063
|
}
|
|
1348
|
-
if (field.attributes.length > 0) {
|
|
1064
|
+
if (!lite && field.attributes.length > 0) {
|
|
1349
1065
|
objectFields.push(ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr)))));
|
|
1350
1066
|
}
|
|
1351
1067
|
const defaultValue = this.getFieldMappedDefault(field);
|
|
@@ -1395,14 +1111,21 @@ var TsSchemaGenerator = class {
|
|
|
1395
1111
|
return getAttribute(origin, "@@delegate")?.args.some((arg) => arg.$resolvedParam.name === "discriminator" && isDataFieldReference(arg.value) && arg.value.target.ref === field);
|
|
1396
1112
|
}
|
|
1397
1113
|
getDataSourceProvider(model) {
|
|
1398
|
-
const dataSource = model.declarations.find(
|
|
1114
|
+
const dataSource = model.declarations.find(isDataSource2);
|
|
1399
1115
|
invariant(dataSource, "No data source found in the model");
|
|
1400
1116
|
const providerExpr = dataSource.fields.find((f) => f.name === "provider")?.value;
|
|
1401
|
-
invariant(isLiteralExpr3(providerExpr), "Provider must be a literal");
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1117
|
+
invariant(isLiteralExpr3(providerExpr) && typeof providerExpr.value === "string", "Provider must be a string literal");
|
|
1118
|
+
return providerExpr.value;
|
|
1119
|
+
}
|
|
1120
|
+
getDataSourceDefaultSchema(model) {
|
|
1121
|
+
const dataSource = model.declarations.find(isDataSource2);
|
|
1122
|
+
invariant(dataSource, "No data source found in the model");
|
|
1123
|
+
const defaultSchemaExpr = dataSource.fields.find((f) => f.name === "defaultSchema")?.value;
|
|
1124
|
+
if (!defaultSchemaExpr) {
|
|
1125
|
+
return void 0;
|
|
1126
|
+
}
|
|
1127
|
+
invariant(isLiteralExpr3(defaultSchemaExpr) && typeof defaultSchemaExpr.value === "string", "Default schema must be a string literal");
|
|
1128
|
+
return defaultSchemaExpr.value;
|
|
1406
1129
|
}
|
|
1407
1130
|
getFieldMappedDefault(field) {
|
|
1408
1131
|
const defaultAttr = getAttribute(field, "@default");
|
|
@@ -1472,12 +1195,16 @@ var TsSchemaGenerator = class {
|
|
|
1472
1195
|
relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
|
|
1473
1196
|
}
|
|
1474
1197
|
const relation = getAttribute(field, "@relation");
|
|
1198
|
+
const fkFields = [];
|
|
1475
1199
|
if (relation) {
|
|
1476
1200
|
for (const arg of relation.args) {
|
|
1477
1201
|
const param = arg.$resolvedParam.name;
|
|
1478
1202
|
if (param === "fields" || param === "references") {
|
|
1479
1203
|
const fieldNames = this.getReferenceNames(arg.value);
|
|
1480
1204
|
if (fieldNames) {
|
|
1205
|
+
if (param === "fields") {
|
|
1206
|
+
fkFields.push(...fieldNames);
|
|
1207
|
+
}
|
|
1481
1208
|
relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
|
|
1482
1209
|
}
|
|
1483
1210
|
}
|
|
@@ -1487,6 +1214,15 @@ var TsSchemaGenerator = class {
|
|
|
1487
1214
|
}
|
|
1488
1215
|
}
|
|
1489
1216
|
}
|
|
1217
|
+
if (fkFields.length > 0) {
|
|
1218
|
+
const allHaveDefault = fkFields.every((fieldName) => {
|
|
1219
|
+
const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
|
|
1220
|
+
return fieldDef && hasAttribute(fieldDef, "@default");
|
|
1221
|
+
});
|
|
1222
|
+
if (allHaveDefault) {
|
|
1223
|
+
relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1490
1226
|
return ts.factory.createObjectLiteralExpression(relationFields);
|
|
1491
1227
|
}
|
|
1492
1228
|
getReferenceNames(expr) {
|
|
@@ -1555,7 +1291,11 @@ var TsSchemaGenerator = class {
|
|
|
1555
1291
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1556
1292
|
for (const attr of allAttributes) {
|
|
1557
1293
|
if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
|
|
1558
|
-
const
|
|
1294
|
+
const fieldsArg = getAttributeArg(attr, "fields");
|
|
1295
|
+
if (!fieldsArg) {
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
const fieldNames = this.getReferenceNames(fieldsArg);
|
|
1559
1299
|
if (!fieldNames) {
|
|
1560
1300
|
continue;
|
|
1561
1301
|
}
|
|
@@ -1594,7 +1334,21 @@ var TsSchemaGenerator = class {
|
|
|
1594
1334
|
return field.type.type ? ts.factory.createStringLiteral(field.type.type) : field.type.reference ? ts.factory.createStringLiteral(field.type.reference.$refText) : ts.factory.createStringLiteral("Unsupported");
|
|
1595
1335
|
}
|
|
1596
1336
|
createEnumObject(e) {
|
|
1597
|
-
return ts.factory.createObjectLiteralExpression(
|
|
1337
|
+
return ts.factory.createObjectLiteralExpression([
|
|
1338
|
+
ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
|
|
1339
|
+
// only generate `fields` if there are attributes on the fields
|
|
1340
|
+
...e.fields.some((f) => f.attributes.length > 0) ? [
|
|
1341
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([
|
|
1342
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
1343
|
+
...field.attributes.length > 0 ? [
|
|
1344
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes?.map((attr) => this.createAttributeObject(attr)) ?? [], true))
|
|
1345
|
+
] : []
|
|
1346
|
+
], true))), true))
|
|
1347
|
+
] : [],
|
|
1348
|
+
...e.attributes.length > 0 ? [
|
|
1349
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(e.attributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
1350
|
+
] : []
|
|
1351
|
+
], true);
|
|
1598
1352
|
}
|
|
1599
1353
|
getLiteral(expr) {
|
|
1600
1354
|
if (!isLiteralExpr3(expr)) {
|
|
@@ -1611,7 +1365,10 @@ var TsSchemaGenerator = class {
|
|
|
1611
1365
|
}
|
|
1612
1366
|
}
|
|
1613
1367
|
createLiteralNode(arg) {
|
|
1614
|
-
return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ?
|
|
1368
|
+
return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ? this.createNumberLiteral(arg) : arg === true ? ts.factory.createTrue() : arg === false ? ts.factory.createFalse() : void 0;
|
|
1369
|
+
}
|
|
1370
|
+
createNumberLiteral(arg) {
|
|
1371
|
+
return arg < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-arg)) : ts.factory.createNumericLiteral(arg);
|
|
1615
1372
|
}
|
|
1616
1373
|
createProceduresObject(procedures) {
|
|
1617
1374
|
return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
|
|
@@ -1671,7 +1428,7 @@ var TsSchemaGenerator = class {
|
|
|
1671
1428
|
]);
|
|
1672
1429
|
}
|
|
1673
1430
|
createExpression(value) {
|
|
1674
|
-
return
|
|
1431
|
+
return match2(value).when(isLiteralExpr3, (expr) => this.createLiteralExpression(expr.$type, expr.value)).when(isInvocationExpr2, (expr) => this.createCallExpression(expr)).when(isReferenceExpr2, (expr) => this.createRefExpression(expr)).when(isArrayExpr2, (expr) => this.createArrayExpression(expr)).when(isUnaryExpr, (expr) => this.createUnaryExpression(expr)).when(isBinaryExpr, (expr) => this.createBinaryExpression(expr)).when(isMemberAccessExpr, (expr) => this.createMemberExpression(expr)).when(isNullExpr2, () => this.createNullExpression()).when(isThisExpr, () => this.createThisExpression()).otherwise(() => {
|
|
1675
1432
|
throw new Error(`Unsupported attribute arg value: ${value.$type}`);
|
|
1676
1433
|
});
|
|
1677
1434
|
}
|
|
@@ -1733,7 +1490,7 @@ var TsSchemaGenerator = class {
|
|
|
1733
1490
|
]);
|
|
1734
1491
|
}
|
|
1735
1492
|
createLiteralExpression(type, value) {
|
|
1736
|
-
return
|
|
1493
|
+
return match2(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1737
1494
|
this.createLiteralNode(value)
|
|
1738
1495
|
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1739
1496
|
ts.factory.createIdentifier(value)
|
|
@@ -1743,16 +1500,16 @@ var TsSchemaGenerator = class {
|
|
|
1743
1500
|
throw new Error(`Unsupported literal type: ${type}`);
|
|
1744
1501
|
});
|
|
1745
1502
|
}
|
|
1746
|
-
generateModelsAndTypeDefs(model,
|
|
1503
|
+
generateModelsAndTypeDefs(model, options) {
|
|
1747
1504
|
const statements = [];
|
|
1748
|
-
statements.push(this.generateSchemaImport(model, true, true));
|
|
1505
|
+
statements.push(this.generateSchemaImport(model, true, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1749
1506
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
1750
1507
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)),
|
|
1751
1508
|
...model.declarations.some(isTypeDef3) ? [
|
|
1752
1509
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1753
1510
|
] : []
|
|
1754
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1755
|
-
const dataModels =
|
|
1511
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1512
|
+
const dataModels = this.getAllDataModels(model);
|
|
1756
1513
|
for (const dm of dataModels) {
|
|
1757
1514
|
let modelType = ts.factory.createTypeAliasDeclaration([
|
|
1758
1515
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1765,7 +1522,7 @@ var TsSchemaGenerator = class {
|
|
|
1765
1522
|
}
|
|
1766
1523
|
statements.push(modelType);
|
|
1767
1524
|
}
|
|
1768
|
-
const typeDefs =
|
|
1525
|
+
const typeDefs = this.getAllTypeDefs(model);
|
|
1769
1526
|
for (const td of typeDefs) {
|
|
1770
1527
|
let typeDef = ts.factory.createTypeAliasDeclaration([
|
|
1771
1528
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1783,7 +1540,7 @@ var TsSchemaGenerator = class {
|
|
|
1783
1540
|
let enumDecl = ts.factory.createVariableStatement([
|
|
1784
1541
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1785
1542
|
], ts.factory.createVariableDeclarationList([
|
|
1786
|
-
ts.factory.createVariableDeclaration(e.name, void 0, void 0, ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("$schema"), ts.factory.createIdentifier("enums")), ts.factory.createIdentifier(e.name)))
|
|
1543
|
+
ts.factory.createVariableDeclaration(e.name, void 0, void 0, ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("$schema"), ts.factory.createIdentifier("enums")), ts.factory.createIdentifier(e.name)), ts.factory.createIdentifier("values")))
|
|
1787
1544
|
], ts.NodeFlags.Const));
|
|
1788
1545
|
if (e.comments.length > 0) {
|
|
1789
1546
|
enumDecl = this.generateDocs(enumDecl, e);
|
|
@@ -1798,13 +1555,13 @@ var TsSchemaGenerator = class {
|
|
|
1798
1555
|
statements.push(typeAlias);
|
|
1799
1556
|
}
|
|
1800
1557
|
this.generateBannerComments(statements);
|
|
1801
|
-
const outputFile = path.join(
|
|
1558
|
+
const outputFile = path.join(options.outDir, "models.ts");
|
|
1802
1559
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1803
1560
|
const printer = ts.createPrinter();
|
|
1804
1561
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1805
1562
|
fs.writeFileSync(outputFile, result);
|
|
1806
1563
|
}
|
|
1807
|
-
generateSchemaImport(model, schemaObject, schemaType) {
|
|
1564
|
+
generateSchemaImport(model, schemaObject, schemaType, useLite, importWithFileExtension) {
|
|
1808
1565
|
const importSpecifiers = [];
|
|
1809
1566
|
if (schemaObject) {
|
|
1810
1567
|
if (model.declarations.some(isEnum)) {
|
|
@@ -1814,17 +1571,21 @@ var TsSchemaGenerator = class {
|
|
|
1814
1571
|
if (schemaType) {
|
|
1815
1572
|
importSpecifiers.push(ts.factory.createImportSpecifier(true, ts.factory.createIdentifier("SchemaType"), ts.factory.createIdentifier("$Schema")));
|
|
1816
1573
|
}
|
|
1817
|
-
|
|
1574
|
+
let importFrom = useLite ? "./schema-lite" : "./schema";
|
|
1575
|
+
if (importWithFileExtension) {
|
|
1576
|
+
importFrom += importWithFileExtension.startsWith(".") ? importWithFileExtension : `.${importWithFileExtension}`;
|
|
1577
|
+
}
|
|
1578
|
+
return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral(importFrom));
|
|
1818
1579
|
}
|
|
1819
1580
|
generateDocs(tsDecl, decl) {
|
|
1820
1581
|
return ts.addSyntheticLeadingComment(tsDecl, ts.SyntaxKind.MultiLineCommentTrivia, `*
|
|
1821
1582
|
* ${decl.comments.map((c) => c.replace(/^\s*\/*\s*/, "")).join("\n * ")}
|
|
1822
1583
|
`, true);
|
|
1823
1584
|
}
|
|
1824
|
-
generateInputTypes(model,
|
|
1825
|
-
const dataModels =
|
|
1585
|
+
generateInputTypes(model, options) {
|
|
1586
|
+
const dataModels = this.getAllDataModels(model);
|
|
1826
1587
|
const statements = [];
|
|
1827
|
-
statements.push(this.generateSchemaImport(model, false, true));
|
|
1588
|
+
statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1828
1589
|
const inputTypes = [
|
|
1829
1590
|
"FindManyArgs",
|
|
1830
1591
|
"FindUniqueArgs",
|
|
@@ -1851,11 +1612,14 @@ var TsSchemaGenerator = class {
|
|
|
1851
1612
|
IncludeInput: "Include",
|
|
1852
1613
|
OmitInput: "Omit"
|
|
1853
1614
|
};
|
|
1854
|
-
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports(inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))))), ts.factory.createStringLiteral("@zenstackhq/runtime")));
|
|
1855
1615
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1856
|
-
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(
|
|
1616
|
+
...inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))),
|
|
1617
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("QueryOptions as $QueryOptions"))
|
|
1618
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1619
|
+
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1620
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedPlainResult as $Result")),
|
|
1857
1621
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
|
|
1858
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1622
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1859
1623
|
for (const dm of dataModels) {
|
|
1860
1624
|
for (const inputType of inputTypes) {
|
|
1861
1625
|
const exportName = inputTypeNameFixes[inputType] ? `${dm.name}${inputTypeNameFixes[inputType]}` : `${dm.name}${inputType}`;
|
|
@@ -1873,527 +1637,30 @@ var TsSchemaGenerator = class {
|
|
|
1873
1637
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1874
1638
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1875
1639
|
ts.factory.createLiteralTypeNode(ts.factory.createTrue())
|
|
1640
|
+
])),
|
|
1641
|
+
ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1642
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1643
|
+
]), ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1644
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1876
1645
|
]))
|
|
1877
|
-
], ts.factory.createTypeReferenceNode("$
|
|
1646
|
+
], ts.factory.createTypeReferenceNode("$Result", [
|
|
1878
1647
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1879
1648
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1880
|
-
ts.factory.createTypeReferenceNode("Args")
|
|
1649
|
+
ts.factory.createTypeReferenceNode("Args"),
|
|
1650
|
+
ts.factory.createTypeReferenceNode("Options")
|
|
1881
1651
|
])));
|
|
1882
1652
|
}
|
|
1883
1653
|
this.generateBannerComments(statements);
|
|
1884
|
-
const outputFile = path.join(
|
|
1654
|
+
const outputFile = path.join(options.outDir, "input.ts");
|
|
1885
1655
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1886
1656
|
const printer = ts.createPrinter();
|
|
1887
1657
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1888
1658
|
fs.writeFileSync(outputFile, result);
|
|
1889
1659
|
}
|
|
1890
1660
|
};
|
|
1891
|
-
|
|
1892
|
-
// src/zmodel-code-generator.ts
|
|
1893
|
-
import { ArrayExpr, Attribute, AttributeArg as AttributeArg2, AttributeParam, AttributeParamType, BinaryExpr, BinaryExprOperatorPriority, BooleanLiteral as BooleanLiteral2, ConfigArrayExpr, ConfigField, ConfigInvocationExpr, DataField, DataFieldAttribute, DataModel as DataModel2, DataModelAttribute, DataSource as DataSource3, Enum as Enum3, EnumField as EnumField2, FunctionDecl, FunctionParam, FunctionParamType, GeneratorDecl as GeneratorDecl2, InvocationExpr, LiteralExpr, MemberAccessExpr, Model as Model2, NullExpr, NumberLiteral as NumberLiteral2, ObjectExpr, Plugin, PluginField, ReferenceArg, ReferenceExpr, StringLiteral as StringLiteral2, ThisExpr, TypeDef, UnaryExpr } from "@zenstackhq/language/ast";
|
|
1894
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
1895
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1896
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1897
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1898
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1899
|
-
}
|
|
1900
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
1901
|
-
function _ts_metadata(k, v) {
|
|
1902
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1903
|
-
}
|
|
1904
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
1905
|
-
var generationHandlers = /* @__PURE__ */ new Map();
|
|
1906
|
-
function gen(name) {
|
|
1907
|
-
return function(_target, _propertyKey, descriptor) {
|
|
1908
|
-
if (!generationHandlers.get(name)) {
|
|
1909
|
-
generationHandlers.set(name, descriptor);
|
|
1910
|
-
}
|
|
1911
|
-
return descriptor;
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
__name(gen, "gen");
|
|
1915
|
-
var ZModelCodeGenerator = class {
|
|
1916
|
-
static {
|
|
1917
|
-
__name(this, "ZModelCodeGenerator");
|
|
1918
|
-
}
|
|
1919
|
-
options;
|
|
1920
|
-
constructor(options) {
|
|
1921
|
-
this.options = {
|
|
1922
|
-
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
1923
|
-
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
1924
|
-
indent: options?.indent ?? 4,
|
|
1925
|
-
quote: options?.quote ?? "single"
|
|
1926
|
-
};
|
|
1927
|
-
}
|
|
1928
|
-
/**
|
|
1929
|
-
* Generates ZModel source code from AST.
|
|
1930
|
-
*/
|
|
1931
|
-
generate(ast) {
|
|
1932
|
-
const handler = generationHandlers.get(ast.$type);
|
|
1933
|
-
if (!handler) {
|
|
1934
|
-
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
1935
|
-
}
|
|
1936
|
-
return handler.value.call(this, ast);
|
|
1937
|
-
}
|
|
1938
|
-
_generateModel(ast) {
|
|
1939
|
-
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
1940
|
-
}
|
|
1941
|
-
_generateDataSource(ast) {
|
|
1942
|
-
return `datasource ${ast.name} {
|
|
1943
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1944
|
-
}`;
|
|
1945
|
-
}
|
|
1946
|
-
_generateEnum(ast) {
|
|
1947
|
-
return `enum ${ast.name} {
|
|
1948
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1949
|
-
}`;
|
|
1950
|
-
}
|
|
1951
|
-
_generateEnumField(ast) {
|
|
1952
|
-
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1953
|
-
}
|
|
1954
|
-
_generateGenerator(ast) {
|
|
1955
|
-
return `generator ${ast.name} {
|
|
1956
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1957
|
-
}`;
|
|
1958
|
-
}
|
|
1959
|
-
_generateConfigField(ast) {
|
|
1960
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1961
|
-
}
|
|
1962
|
-
_generateConfigArrayExpr(ast) {
|
|
1963
|
-
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
1964
|
-
}
|
|
1965
|
-
_generateConfigInvocationExpr(ast) {
|
|
1966
|
-
if (ast.args.length === 0) {
|
|
1967
|
-
return ast.name;
|
|
1968
|
-
} else {
|
|
1969
|
-
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
1970
|
-
}
|
|
1971
|
-
}
|
|
1972
|
-
_generatePlugin(ast) {
|
|
1973
|
-
return `plugin ${ast.name} {
|
|
1974
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1975
|
-
}`;
|
|
1976
|
-
}
|
|
1977
|
-
_generatePluginField(ast) {
|
|
1978
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1979
|
-
}
|
|
1980
|
-
_generateDataModel(ast) {
|
|
1981
|
-
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.ref?.name).join(", ") : ""} {
|
|
1982
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
1983
|
-
}`;
|
|
1984
|
-
}
|
|
1985
|
-
_generateDataField(ast) {
|
|
1986
|
-
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1987
|
-
}
|
|
1988
|
-
fieldType(type) {
|
|
1989
|
-
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
1990
|
-
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
1991
|
-
}
|
|
1992
|
-
_generateDataModelAttribute(ast) {
|
|
1993
|
-
return this.attribute(ast);
|
|
1994
|
-
}
|
|
1995
|
-
_generateDataFieldAttribute(ast) {
|
|
1996
|
-
return this.attribute(ast);
|
|
1997
|
-
}
|
|
1998
|
-
attribute(ast) {
|
|
1999
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
2000
|
-
return `${resolved(ast.decl).name}${args}`;
|
|
2001
|
-
}
|
|
2002
|
-
_generateAttributeArg(ast) {
|
|
2003
|
-
if (ast.name) {
|
|
2004
|
-
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
2005
|
-
} else {
|
|
2006
|
-
return this.generate(ast.value);
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
_generateObjectExpr(ast) {
|
|
2010
|
-
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
2011
|
-
}
|
|
2012
|
-
objectField(field) {
|
|
2013
|
-
return `${field.name}: ${this.generate(field.value)}`;
|
|
2014
|
-
}
|
|
2015
|
-
_generateArrayExpr(ast) {
|
|
2016
|
-
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
2017
|
-
}
|
|
2018
|
-
_generateLiteralExpr(ast) {
|
|
2019
|
-
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
2020
|
-
}
|
|
2021
|
-
_generateNumberLiteral(ast) {
|
|
2022
|
-
return ast.value.toString();
|
|
2023
|
-
}
|
|
2024
|
-
_generateBooleanLiteral(ast) {
|
|
2025
|
-
return ast.value.toString();
|
|
2026
|
-
}
|
|
2027
|
-
_generateUnaryExpr(ast) {
|
|
2028
|
-
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
2029
|
-
}
|
|
2030
|
-
_generateBinaryExpr(ast) {
|
|
2031
|
-
const operator = ast.operator;
|
|
2032
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
2033
|
-
const rightExpr = this.generate(ast.right);
|
|
2034
|
-
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
2035
|
-
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
2036
|
-
}
|
|
2037
|
-
_generateReferenceExpr(ast) {
|
|
2038
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
2039
|
-
return `${ast.target.ref?.name}${args}`;
|
|
2040
|
-
}
|
|
2041
|
-
_generateReferenceArg(ast) {
|
|
2042
|
-
return `${ast.name}:${this.generate(ast.value)}`;
|
|
2043
|
-
}
|
|
2044
|
-
_generateMemberExpr(ast) {
|
|
2045
|
-
return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
|
|
2046
|
-
}
|
|
2047
|
-
_generateInvocationExpr(ast) {
|
|
2048
|
-
return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
2049
|
-
}
|
|
2050
|
-
_generateNullExpr() {
|
|
2051
|
-
return "null";
|
|
2052
|
-
}
|
|
2053
|
-
_generateThisExpr() {
|
|
2054
|
-
return "this";
|
|
2055
|
-
}
|
|
2056
|
-
_generateAttribute(ast) {
|
|
2057
|
-
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
2058
|
-
}
|
|
2059
|
-
_generateAttributeParam(ast) {
|
|
2060
|
-
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
2061
|
-
}
|
|
2062
|
-
_generateAttributeParamType(ast) {
|
|
2063
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
2064
|
-
}
|
|
2065
|
-
_generateFunctionDecl(ast) {
|
|
2066
|
-
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
2067
|
-
}
|
|
2068
|
-
_generateFunctionParam(ast) {
|
|
2069
|
-
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
2070
|
-
}
|
|
2071
|
-
_generateFunctionParamType(ast) {
|
|
2072
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
2073
|
-
}
|
|
2074
|
-
_generateTypeDef(ast) {
|
|
2075
|
-
return `type ${ast.name} {
|
|
2076
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
2077
|
-
}`;
|
|
2078
|
-
}
|
|
2079
|
-
argument(ast) {
|
|
2080
|
-
return this.generate(ast.value);
|
|
2081
|
-
}
|
|
2082
|
-
get binaryExprSpace() {
|
|
2083
|
-
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
2084
|
-
}
|
|
2085
|
-
get unaryExprSpace() {
|
|
2086
|
-
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
2087
|
-
}
|
|
2088
|
-
get indent() {
|
|
2089
|
-
return " ".repeat(this.options.indent);
|
|
2090
|
-
}
|
|
2091
|
-
isParenthesesNeededForBinaryExpr(ast) {
|
|
2092
|
-
const result = {
|
|
2093
|
-
left: false,
|
|
2094
|
-
right: false
|
|
2095
|
-
};
|
|
2096
|
-
const operator = ast.operator;
|
|
2097
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
2098
|
-
const currentPriority = BinaryExprOperatorPriority[operator];
|
|
2099
|
-
if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
2100
|
-
result.left = true;
|
|
2101
|
-
}
|
|
2102
|
-
if (!isCollectionPredicate && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
2103
|
-
result.right = true;
|
|
2104
|
-
}
|
|
2105
|
-
return result;
|
|
2106
|
-
}
|
|
2107
|
-
isCollectionPredicateOperator(op) {
|
|
2108
|
-
return [
|
|
2109
|
-
"?",
|
|
2110
|
-
"!",
|
|
2111
|
-
"^"
|
|
2112
|
-
].includes(op);
|
|
2113
|
-
}
|
|
2114
|
-
};
|
|
2115
|
-
_ts_decorate([
|
|
2116
|
-
gen(Model2),
|
|
2117
|
-
_ts_metadata("design:type", Function),
|
|
2118
|
-
_ts_metadata("design:paramtypes", [
|
|
2119
|
-
typeof Model2 === "undefined" ? Object : Model2
|
|
2120
|
-
]),
|
|
2121
|
-
_ts_metadata("design:returntype", void 0)
|
|
2122
|
-
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
2123
|
-
_ts_decorate([
|
|
2124
|
-
gen(DataSource3),
|
|
2125
|
-
_ts_metadata("design:type", Function),
|
|
2126
|
-
_ts_metadata("design:paramtypes", [
|
|
2127
|
-
typeof DataSource3 === "undefined" ? Object : DataSource3
|
|
2128
|
-
]),
|
|
2129
|
-
_ts_metadata("design:returntype", void 0)
|
|
2130
|
-
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
2131
|
-
_ts_decorate([
|
|
2132
|
-
gen(Enum3),
|
|
2133
|
-
_ts_metadata("design:type", Function),
|
|
2134
|
-
_ts_metadata("design:paramtypes", [
|
|
2135
|
-
typeof Enum3 === "undefined" ? Object : Enum3
|
|
2136
|
-
]),
|
|
2137
|
-
_ts_metadata("design:returntype", void 0)
|
|
2138
|
-
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
2139
|
-
_ts_decorate([
|
|
2140
|
-
gen(EnumField2),
|
|
2141
|
-
_ts_metadata("design:type", Function),
|
|
2142
|
-
_ts_metadata("design:paramtypes", [
|
|
2143
|
-
typeof EnumField2 === "undefined" ? Object : EnumField2
|
|
2144
|
-
]),
|
|
2145
|
-
_ts_metadata("design:returntype", void 0)
|
|
2146
|
-
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
2147
|
-
_ts_decorate([
|
|
2148
|
-
gen(GeneratorDecl2),
|
|
2149
|
-
_ts_metadata("design:type", Function),
|
|
2150
|
-
_ts_metadata("design:paramtypes", [
|
|
2151
|
-
typeof GeneratorDecl2 === "undefined" ? Object : GeneratorDecl2
|
|
2152
|
-
]),
|
|
2153
|
-
_ts_metadata("design:returntype", void 0)
|
|
2154
|
-
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
2155
|
-
_ts_decorate([
|
|
2156
|
-
gen(ConfigField),
|
|
2157
|
-
_ts_metadata("design:type", Function),
|
|
2158
|
-
_ts_metadata("design:paramtypes", [
|
|
2159
|
-
typeof ConfigField === "undefined" ? Object : ConfigField
|
|
2160
|
-
]),
|
|
2161
|
-
_ts_metadata("design:returntype", void 0)
|
|
2162
|
-
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
2163
|
-
_ts_decorate([
|
|
2164
|
-
gen(ConfigArrayExpr),
|
|
2165
|
-
_ts_metadata("design:type", Function),
|
|
2166
|
-
_ts_metadata("design:paramtypes", [
|
|
2167
|
-
typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
|
|
2168
|
-
]),
|
|
2169
|
-
_ts_metadata("design:returntype", void 0)
|
|
2170
|
-
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
2171
|
-
_ts_decorate([
|
|
2172
|
-
gen(ConfigInvocationExpr),
|
|
2173
|
-
_ts_metadata("design:type", Function),
|
|
2174
|
-
_ts_metadata("design:paramtypes", [
|
|
2175
|
-
typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
|
|
2176
|
-
]),
|
|
2177
|
-
_ts_metadata("design:returntype", void 0)
|
|
2178
|
-
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
2179
|
-
_ts_decorate([
|
|
2180
|
-
gen(Plugin),
|
|
2181
|
-
_ts_metadata("design:type", Function),
|
|
2182
|
-
_ts_metadata("design:paramtypes", [
|
|
2183
|
-
typeof Plugin === "undefined" ? Object : Plugin
|
|
2184
|
-
]),
|
|
2185
|
-
_ts_metadata("design:returntype", void 0)
|
|
2186
|
-
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
2187
|
-
_ts_decorate([
|
|
2188
|
-
gen(PluginField),
|
|
2189
|
-
_ts_metadata("design:type", Function),
|
|
2190
|
-
_ts_metadata("design:paramtypes", [
|
|
2191
|
-
typeof PluginField === "undefined" ? Object : PluginField
|
|
2192
|
-
]),
|
|
2193
|
-
_ts_metadata("design:returntype", void 0)
|
|
2194
|
-
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
2195
|
-
_ts_decorate([
|
|
2196
|
-
gen(DataModel2),
|
|
2197
|
-
_ts_metadata("design:type", Function),
|
|
2198
|
-
_ts_metadata("design:paramtypes", [
|
|
2199
|
-
typeof DataModel2 === "undefined" ? Object : DataModel2
|
|
2200
|
-
]),
|
|
2201
|
-
_ts_metadata("design:returntype", void 0)
|
|
2202
|
-
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
2203
|
-
_ts_decorate([
|
|
2204
|
-
gen(DataField),
|
|
2205
|
-
_ts_metadata("design:type", Function),
|
|
2206
|
-
_ts_metadata("design:paramtypes", [
|
|
2207
|
-
typeof DataField === "undefined" ? Object : DataField
|
|
2208
|
-
]),
|
|
2209
|
-
_ts_metadata("design:returntype", void 0)
|
|
2210
|
-
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
2211
|
-
_ts_decorate([
|
|
2212
|
-
gen(DataModelAttribute),
|
|
2213
|
-
_ts_metadata("design:type", Function),
|
|
2214
|
-
_ts_metadata("design:paramtypes", [
|
|
2215
|
-
typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
|
|
2216
|
-
]),
|
|
2217
|
-
_ts_metadata("design:returntype", void 0)
|
|
2218
|
-
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
2219
|
-
_ts_decorate([
|
|
2220
|
-
gen(DataFieldAttribute),
|
|
2221
|
-
_ts_metadata("design:type", Function),
|
|
2222
|
-
_ts_metadata("design:paramtypes", [
|
|
2223
|
-
typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
|
|
2224
|
-
]),
|
|
2225
|
-
_ts_metadata("design:returntype", void 0)
|
|
2226
|
-
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
2227
|
-
_ts_decorate([
|
|
2228
|
-
gen(AttributeArg2),
|
|
2229
|
-
_ts_metadata("design:type", Function),
|
|
2230
|
-
_ts_metadata("design:paramtypes", [
|
|
2231
|
-
typeof AttributeArg2 === "undefined" ? Object : AttributeArg2
|
|
2232
|
-
]),
|
|
2233
|
-
_ts_metadata("design:returntype", void 0)
|
|
2234
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
2235
|
-
_ts_decorate([
|
|
2236
|
-
gen(ObjectExpr),
|
|
2237
|
-
_ts_metadata("design:type", Function),
|
|
2238
|
-
_ts_metadata("design:paramtypes", [
|
|
2239
|
-
typeof ObjectExpr === "undefined" ? Object : ObjectExpr
|
|
2240
|
-
]),
|
|
2241
|
-
_ts_metadata("design:returntype", void 0)
|
|
2242
|
-
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
2243
|
-
_ts_decorate([
|
|
2244
|
-
gen(ArrayExpr),
|
|
2245
|
-
_ts_metadata("design:type", Function),
|
|
2246
|
-
_ts_metadata("design:paramtypes", [
|
|
2247
|
-
typeof ArrayExpr === "undefined" ? Object : ArrayExpr
|
|
2248
|
-
]),
|
|
2249
|
-
_ts_metadata("design:returntype", void 0)
|
|
2250
|
-
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
2251
|
-
_ts_decorate([
|
|
2252
|
-
gen(StringLiteral2),
|
|
2253
|
-
_ts_metadata("design:type", Function),
|
|
2254
|
-
_ts_metadata("design:paramtypes", [
|
|
2255
|
-
typeof LiteralExpr === "undefined" ? Object : LiteralExpr
|
|
2256
|
-
]),
|
|
2257
|
-
_ts_metadata("design:returntype", void 0)
|
|
2258
|
-
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
2259
|
-
_ts_decorate([
|
|
2260
|
-
gen(NumberLiteral2),
|
|
2261
|
-
_ts_metadata("design:type", Function),
|
|
2262
|
-
_ts_metadata("design:paramtypes", [
|
|
2263
|
-
typeof NumberLiteral2 === "undefined" ? Object : NumberLiteral2
|
|
2264
|
-
]),
|
|
2265
|
-
_ts_metadata("design:returntype", void 0)
|
|
2266
|
-
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
2267
|
-
_ts_decorate([
|
|
2268
|
-
gen(BooleanLiteral2),
|
|
2269
|
-
_ts_metadata("design:type", Function),
|
|
2270
|
-
_ts_metadata("design:paramtypes", [
|
|
2271
|
-
typeof BooleanLiteral2 === "undefined" ? Object : BooleanLiteral2
|
|
2272
|
-
]),
|
|
2273
|
-
_ts_metadata("design:returntype", void 0)
|
|
2274
|
-
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
2275
|
-
_ts_decorate([
|
|
2276
|
-
gen(UnaryExpr),
|
|
2277
|
-
_ts_metadata("design:type", Function),
|
|
2278
|
-
_ts_metadata("design:paramtypes", [
|
|
2279
|
-
typeof UnaryExpr === "undefined" ? Object : UnaryExpr
|
|
2280
|
-
]),
|
|
2281
|
-
_ts_metadata("design:returntype", void 0)
|
|
2282
|
-
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
2283
|
-
_ts_decorate([
|
|
2284
|
-
gen(BinaryExpr),
|
|
2285
|
-
_ts_metadata("design:type", Function),
|
|
2286
|
-
_ts_metadata("design:paramtypes", [
|
|
2287
|
-
typeof BinaryExpr === "undefined" ? Object : BinaryExpr
|
|
2288
|
-
]),
|
|
2289
|
-
_ts_metadata("design:returntype", void 0)
|
|
2290
|
-
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
2291
|
-
_ts_decorate([
|
|
2292
|
-
gen(ReferenceExpr),
|
|
2293
|
-
_ts_metadata("design:type", Function),
|
|
2294
|
-
_ts_metadata("design:paramtypes", [
|
|
2295
|
-
typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
|
|
2296
|
-
]),
|
|
2297
|
-
_ts_metadata("design:returntype", void 0)
|
|
2298
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
2299
|
-
_ts_decorate([
|
|
2300
|
-
gen(ReferenceArg),
|
|
2301
|
-
_ts_metadata("design:type", Function),
|
|
2302
|
-
_ts_metadata("design:paramtypes", [
|
|
2303
|
-
typeof ReferenceArg === "undefined" ? Object : ReferenceArg
|
|
2304
|
-
]),
|
|
2305
|
-
_ts_metadata("design:returntype", void 0)
|
|
2306
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
2307
|
-
_ts_decorate([
|
|
2308
|
-
gen(MemberAccessExpr),
|
|
2309
|
-
_ts_metadata("design:type", Function),
|
|
2310
|
-
_ts_metadata("design:paramtypes", [
|
|
2311
|
-
typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
|
|
2312
|
-
]),
|
|
2313
|
-
_ts_metadata("design:returntype", void 0)
|
|
2314
|
-
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
2315
|
-
_ts_decorate([
|
|
2316
|
-
gen(InvocationExpr),
|
|
2317
|
-
_ts_metadata("design:type", Function),
|
|
2318
|
-
_ts_metadata("design:paramtypes", [
|
|
2319
|
-
typeof InvocationExpr === "undefined" ? Object : InvocationExpr
|
|
2320
|
-
]),
|
|
2321
|
-
_ts_metadata("design:returntype", void 0)
|
|
2322
|
-
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
2323
|
-
_ts_decorate([
|
|
2324
|
-
gen(NullExpr),
|
|
2325
|
-
_ts_metadata("design:type", Function),
|
|
2326
|
-
_ts_metadata("design:paramtypes", []),
|
|
2327
|
-
_ts_metadata("design:returntype", void 0)
|
|
2328
|
-
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
2329
|
-
_ts_decorate([
|
|
2330
|
-
gen(ThisExpr),
|
|
2331
|
-
_ts_metadata("design:type", Function),
|
|
2332
|
-
_ts_metadata("design:paramtypes", []),
|
|
2333
|
-
_ts_metadata("design:returntype", void 0)
|
|
2334
|
-
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
2335
|
-
_ts_decorate([
|
|
2336
|
-
gen(Attribute),
|
|
2337
|
-
_ts_metadata("design:type", Function),
|
|
2338
|
-
_ts_metadata("design:paramtypes", [
|
|
2339
|
-
typeof Attribute === "undefined" ? Object : Attribute
|
|
2340
|
-
]),
|
|
2341
|
-
_ts_metadata("design:returntype", void 0)
|
|
2342
|
-
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
2343
|
-
_ts_decorate([
|
|
2344
|
-
gen(AttributeParam),
|
|
2345
|
-
_ts_metadata("design:type", Function),
|
|
2346
|
-
_ts_metadata("design:paramtypes", [
|
|
2347
|
-
typeof AttributeParam === "undefined" ? Object : AttributeParam
|
|
2348
|
-
]),
|
|
2349
|
-
_ts_metadata("design:returntype", void 0)
|
|
2350
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
2351
|
-
_ts_decorate([
|
|
2352
|
-
gen(AttributeParamType),
|
|
2353
|
-
_ts_metadata("design:type", Function),
|
|
2354
|
-
_ts_metadata("design:paramtypes", [
|
|
2355
|
-
typeof AttributeParamType === "undefined" ? Object : AttributeParamType
|
|
2356
|
-
]),
|
|
2357
|
-
_ts_metadata("design:returntype", void 0)
|
|
2358
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
2359
|
-
_ts_decorate([
|
|
2360
|
-
gen(FunctionDecl),
|
|
2361
|
-
_ts_metadata("design:type", Function),
|
|
2362
|
-
_ts_metadata("design:paramtypes", [
|
|
2363
|
-
typeof FunctionDecl === "undefined" ? Object : FunctionDecl
|
|
2364
|
-
]),
|
|
2365
|
-
_ts_metadata("design:returntype", void 0)
|
|
2366
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
2367
|
-
_ts_decorate([
|
|
2368
|
-
gen(FunctionParam),
|
|
2369
|
-
_ts_metadata("design:type", Function),
|
|
2370
|
-
_ts_metadata("design:paramtypes", [
|
|
2371
|
-
typeof FunctionParam === "undefined" ? Object : FunctionParam
|
|
2372
|
-
]),
|
|
2373
|
-
_ts_metadata("design:returntype", void 0)
|
|
2374
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
2375
|
-
_ts_decorate([
|
|
2376
|
-
gen(FunctionParamType),
|
|
2377
|
-
_ts_metadata("design:type", Function),
|
|
2378
|
-
_ts_metadata("design:paramtypes", [
|
|
2379
|
-
typeof FunctionParamType === "undefined" ? Object : FunctionParamType
|
|
2380
|
-
]),
|
|
2381
|
-
_ts_metadata("design:returntype", void 0)
|
|
2382
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
2383
|
-
_ts_decorate([
|
|
2384
|
-
gen(TypeDef),
|
|
2385
|
-
_ts_metadata("design:type", Function),
|
|
2386
|
-
_ts_metadata("design:paramtypes", [
|
|
2387
|
-
typeof TypeDef === "undefined" ? Object : TypeDef
|
|
2388
|
-
]),
|
|
2389
|
-
_ts_metadata("design:returntype", void 0)
|
|
2390
|
-
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
2391
1661
|
export {
|
|
2392
|
-
DefaultOperationNodeVisitor,
|
|
2393
|
-
ExpressionVisitor,
|
|
2394
1662
|
model_utils_exports as ModelUtils,
|
|
2395
1663
|
PrismaSchemaGenerator,
|
|
2396
|
-
TsSchemaGenerator
|
|
2397
|
-
ZModelCodeGenerator
|
|
1664
|
+
TsSchemaGenerator
|
|
2398
1665
|
};
|
|
2399
1666
|
//# sourceMappingURL=index.js.map
|