@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.cjs
CHANGED
|
@@ -31,12 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
|
-
DefaultOperationNodeVisitor: () => DefaultOperationNodeVisitor,
|
|
35
|
-
ExpressionVisitor: () => ExpressionVisitor,
|
|
36
34
|
ModelUtils: () => model_utils_exports,
|
|
37
35
|
PrismaSchemaGenerator: () => PrismaSchemaGenerator,
|
|
38
|
-
TsSchemaGenerator: () => TsSchemaGenerator
|
|
39
|
-
ZModelCodeGenerator: () => ZModelCodeGenerator
|
|
36
|
+
TsSchemaGenerator: () => TsSchemaGenerator
|
|
40
37
|
});
|
|
41
38
|
module.exports = __toCommonJS(src_exports);
|
|
42
39
|
|
|
@@ -125,7 +122,7 @@ __name(resolved, "resolved");
|
|
|
125
122
|
function getAuthDecl(model) {
|
|
126
123
|
let found = model.declarations.find((d) => ((0, import_ast.isDataModel)(d) || (0, import_ast.isTypeDef)(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
127
124
|
if (!found) {
|
|
128
|
-
found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.name === "User");
|
|
125
|
+
found = model.declarations.find((d) => ((0, import_ast.isDataModel)(d) || (0, import_ast.isTypeDef)(d)) && d.name === "User");
|
|
129
126
|
}
|
|
130
127
|
return found;
|
|
131
128
|
}
|
|
@@ -136,365 +133,13 @@ function getIdFields(dm) {
|
|
|
136
133
|
__name(getIdFields, "getIdFields");
|
|
137
134
|
var DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
|
|
138
135
|
|
|
139
|
-
// src/expression-utils.ts
|
|
140
|
-
var import_ts_pattern = require("ts-pattern");
|
|
141
|
-
var ExpressionVisitor = class {
|
|
142
|
-
static {
|
|
143
|
-
__name(this, "ExpressionVisitor");
|
|
144
|
-
}
|
|
145
|
-
visit(expr) {
|
|
146
|
-
(0, import_ts_pattern.match)(expr).with({
|
|
147
|
-
kind: "literal"
|
|
148
|
-
}, (e) => this.visitLiteral(e)).with({
|
|
149
|
-
kind: "array"
|
|
150
|
-
}, (e) => this.visitArray(e)).with({
|
|
151
|
-
kind: "field"
|
|
152
|
-
}, (e) => this.visitField(e)).with({
|
|
153
|
-
kind: "member"
|
|
154
|
-
}, (e) => this.visitMember(e)).with({
|
|
155
|
-
kind: "binary"
|
|
156
|
-
}, (e) => this.visitBinary(e)).with({
|
|
157
|
-
kind: "unary"
|
|
158
|
-
}, (e) => this.visitUnary(e)).with({
|
|
159
|
-
kind: "call"
|
|
160
|
-
}, (e) => this.visitCall(e)).with({
|
|
161
|
-
kind: "this"
|
|
162
|
-
}, (e) => this.visitThis(e)).with({
|
|
163
|
-
kind: "null"
|
|
164
|
-
}, (e) => this.visitNull(e)).exhaustive();
|
|
165
|
-
}
|
|
166
|
-
visitLiteral(_e) {
|
|
167
|
-
}
|
|
168
|
-
visitArray(e) {
|
|
169
|
-
e.items.forEach((item) => this.visit(item));
|
|
170
|
-
}
|
|
171
|
-
visitField(_e) {
|
|
172
|
-
}
|
|
173
|
-
visitMember(e) {
|
|
174
|
-
this.visit(e.receiver);
|
|
175
|
-
}
|
|
176
|
-
visitBinary(e) {
|
|
177
|
-
this.visit(e.left);
|
|
178
|
-
this.visit(e.right);
|
|
179
|
-
}
|
|
180
|
-
visitUnary(e) {
|
|
181
|
-
this.visit(e.operand);
|
|
182
|
-
}
|
|
183
|
-
visitCall(e) {
|
|
184
|
-
e.args?.forEach((arg) => this.visit(arg));
|
|
185
|
-
}
|
|
186
|
-
visitThis(_e) {
|
|
187
|
-
}
|
|
188
|
-
visitNull(_e) {
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// src/default-operation-node-visitor.ts
|
|
193
|
-
var import_kysely = require("kysely");
|
|
194
|
-
var DefaultOperationNodeVisitor = class extends import_kysely.OperationNodeVisitor {
|
|
195
|
-
static {
|
|
196
|
-
__name(this, "DefaultOperationNodeVisitor");
|
|
197
|
-
}
|
|
198
|
-
defaultVisit(node) {
|
|
199
|
-
Object.values(node).forEach((value) => {
|
|
200
|
-
if (!value) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (Array.isArray(value)) {
|
|
204
|
-
value.forEach((el) => this.defaultVisit(el));
|
|
205
|
-
}
|
|
206
|
-
if (typeof value === "object" && "kind" in value && typeof value.kind === "string") {
|
|
207
|
-
this.visitNode(value);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
visitSelectQuery(node) {
|
|
212
|
-
this.defaultVisit(node);
|
|
213
|
-
}
|
|
214
|
-
visitSelection(node) {
|
|
215
|
-
this.defaultVisit(node);
|
|
216
|
-
}
|
|
217
|
-
visitColumn(node) {
|
|
218
|
-
this.defaultVisit(node);
|
|
219
|
-
}
|
|
220
|
-
visitAlias(node) {
|
|
221
|
-
this.defaultVisit(node);
|
|
222
|
-
}
|
|
223
|
-
visitTable(node) {
|
|
224
|
-
this.defaultVisit(node);
|
|
225
|
-
}
|
|
226
|
-
visitFrom(node) {
|
|
227
|
-
this.defaultVisit(node);
|
|
228
|
-
}
|
|
229
|
-
visitReference(node) {
|
|
230
|
-
this.defaultVisit(node);
|
|
231
|
-
}
|
|
232
|
-
visitAnd(node) {
|
|
233
|
-
this.defaultVisit(node);
|
|
234
|
-
}
|
|
235
|
-
visitOr(node) {
|
|
236
|
-
this.defaultVisit(node);
|
|
237
|
-
}
|
|
238
|
-
visitValueList(node) {
|
|
239
|
-
this.defaultVisit(node);
|
|
240
|
-
}
|
|
241
|
-
visitParens(node) {
|
|
242
|
-
this.defaultVisit(node);
|
|
243
|
-
}
|
|
244
|
-
visitJoin(node) {
|
|
245
|
-
this.defaultVisit(node);
|
|
246
|
-
}
|
|
247
|
-
visitRaw(node) {
|
|
248
|
-
this.defaultVisit(node);
|
|
249
|
-
}
|
|
250
|
-
visitWhere(node) {
|
|
251
|
-
this.defaultVisit(node);
|
|
252
|
-
}
|
|
253
|
-
visitInsertQuery(node) {
|
|
254
|
-
this.defaultVisit(node);
|
|
255
|
-
}
|
|
256
|
-
visitDeleteQuery(node) {
|
|
257
|
-
this.defaultVisit(node);
|
|
258
|
-
}
|
|
259
|
-
visitReturning(node) {
|
|
260
|
-
this.defaultVisit(node);
|
|
261
|
-
}
|
|
262
|
-
visitCreateTable(node) {
|
|
263
|
-
this.defaultVisit(node);
|
|
264
|
-
}
|
|
265
|
-
visitAddColumn(node) {
|
|
266
|
-
this.defaultVisit(node);
|
|
267
|
-
}
|
|
268
|
-
visitColumnDefinition(node) {
|
|
269
|
-
this.defaultVisit(node);
|
|
270
|
-
}
|
|
271
|
-
visitDropTable(node) {
|
|
272
|
-
this.defaultVisit(node);
|
|
273
|
-
}
|
|
274
|
-
visitOrderBy(node) {
|
|
275
|
-
this.defaultVisit(node);
|
|
276
|
-
}
|
|
277
|
-
visitOrderByItem(node) {
|
|
278
|
-
this.defaultVisit(node);
|
|
279
|
-
}
|
|
280
|
-
visitGroupBy(node) {
|
|
281
|
-
this.defaultVisit(node);
|
|
282
|
-
}
|
|
283
|
-
visitGroupByItem(node) {
|
|
284
|
-
this.defaultVisit(node);
|
|
285
|
-
}
|
|
286
|
-
visitUpdateQuery(node) {
|
|
287
|
-
this.defaultVisit(node);
|
|
288
|
-
}
|
|
289
|
-
visitColumnUpdate(node) {
|
|
290
|
-
this.defaultVisit(node);
|
|
291
|
-
}
|
|
292
|
-
visitLimit(node) {
|
|
293
|
-
this.defaultVisit(node);
|
|
294
|
-
}
|
|
295
|
-
visitOffset(node) {
|
|
296
|
-
this.defaultVisit(node);
|
|
297
|
-
}
|
|
298
|
-
visitOnConflict(node) {
|
|
299
|
-
this.defaultVisit(node);
|
|
300
|
-
}
|
|
301
|
-
visitOnDuplicateKey(node) {
|
|
302
|
-
this.defaultVisit(node);
|
|
303
|
-
}
|
|
304
|
-
visitCheckConstraint(node) {
|
|
305
|
-
this.defaultVisit(node);
|
|
306
|
-
}
|
|
307
|
-
visitDataType(node) {
|
|
308
|
-
this.defaultVisit(node);
|
|
309
|
-
}
|
|
310
|
-
visitSelectAll(node) {
|
|
311
|
-
this.defaultVisit(node);
|
|
312
|
-
}
|
|
313
|
-
visitIdentifier(node) {
|
|
314
|
-
this.defaultVisit(node);
|
|
315
|
-
}
|
|
316
|
-
visitSchemableIdentifier(node) {
|
|
317
|
-
this.defaultVisit(node);
|
|
318
|
-
}
|
|
319
|
-
visitValue(node) {
|
|
320
|
-
this.defaultVisit(node);
|
|
321
|
-
}
|
|
322
|
-
visitPrimitiveValueList(node) {
|
|
323
|
-
this.defaultVisit(node);
|
|
324
|
-
}
|
|
325
|
-
visitOperator(node) {
|
|
326
|
-
this.defaultVisit(node);
|
|
327
|
-
}
|
|
328
|
-
visitCreateIndex(node) {
|
|
329
|
-
this.defaultVisit(node);
|
|
330
|
-
}
|
|
331
|
-
visitDropIndex(node) {
|
|
332
|
-
this.defaultVisit(node);
|
|
333
|
-
}
|
|
334
|
-
visitList(node) {
|
|
335
|
-
this.defaultVisit(node);
|
|
336
|
-
}
|
|
337
|
-
visitPrimaryKeyConstraint(node) {
|
|
338
|
-
this.defaultVisit(node);
|
|
339
|
-
}
|
|
340
|
-
visitUniqueConstraint(node) {
|
|
341
|
-
this.defaultVisit(node);
|
|
342
|
-
}
|
|
343
|
-
visitReferences(node) {
|
|
344
|
-
this.defaultVisit(node);
|
|
345
|
-
}
|
|
346
|
-
visitWith(node) {
|
|
347
|
-
this.defaultVisit(node);
|
|
348
|
-
}
|
|
349
|
-
visitCommonTableExpression(node) {
|
|
350
|
-
this.defaultVisit(node);
|
|
351
|
-
}
|
|
352
|
-
visitCommonTableExpressionName(node) {
|
|
353
|
-
this.defaultVisit(node);
|
|
354
|
-
}
|
|
355
|
-
visitHaving(node) {
|
|
356
|
-
this.defaultVisit(node);
|
|
357
|
-
}
|
|
358
|
-
visitCreateSchema(node) {
|
|
359
|
-
this.defaultVisit(node);
|
|
360
|
-
}
|
|
361
|
-
visitDropSchema(node) {
|
|
362
|
-
this.defaultVisit(node);
|
|
363
|
-
}
|
|
364
|
-
visitAlterTable(node) {
|
|
365
|
-
this.defaultVisit(node);
|
|
366
|
-
}
|
|
367
|
-
visitDropColumn(node) {
|
|
368
|
-
this.defaultVisit(node);
|
|
369
|
-
}
|
|
370
|
-
visitRenameColumn(node) {
|
|
371
|
-
this.defaultVisit(node);
|
|
372
|
-
}
|
|
373
|
-
visitAlterColumn(node) {
|
|
374
|
-
this.defaultVisit(node);
|
|
375
|
-
}
|
|
376
|
-
visitModifyColumn(node) {
|
|
377
|
-
this.defaultVisit(node);
|
|
378
|
-
}
|
|
379
|
-
visitAddConstraint(node) {
|
|
380
|
-
this.defaultVisit(node);
|
|
381
|
-
}
|
|
382
|
-
visitDropConstraint(node) {
|
|
383
|
-
this.defaultVisit(node);
|
|
384
|
-
}
|
|
385
|
-
visitForeignKeyConstraint(node) {
|
|
386
|
-
this.defaultVisit(node);
|
|
387
|
-
}
|
|
388
|
-
visitCreateView(node) {
|
|
389
|
-
this.defaultVisit(node);
|
|
390
|
-
}
|
|
391
|
-
visitDropView(node) {
|
|
392
|
-
this.defaultVisit(node);
|
|
393
|
-
}
|
|
394
|
-
visitGenerated(node) {
|
|
395
|
-
this.defaultVisit(node);
|
|
396
|
-
}
|
|
397
|
-
visitDefaultValue(node) {
|
|
398
|
-
this.defaultVisit(node);
|
|
399
|
-
}
|
|
400
|
-
visitOn(node) {
|
|
401
|
-
this.defaultVisit(node);
|
|
402
|
-
}
|
|
403
|
-
visitValues(node) {
|
|
404
|
-
this.defaultVisit(node);
|
|
405
|
-
}
|
|
406
|
-
visitSelectModifier(node) {
|
|
407
|
-
this.defaultVisit(node);
|
|
408
|
-
}
|
|
409
|
-
visitCreateType(node) {
|
|
410
|
-
this.defaultVisit(node);
|
|
411
|
-
}
|
|
412
|
-
visitDropType(node) {
|
|
413
|
-
this.defaultVisit(node);
|
|
414
|
-
}
|
|
415
|
-
visitExplain(node) {
|
|
416
|
-
this.defaultVisit(node);
|
|
417
|
-
}
|
|
418
|
-
visitDefaultInsertValue(node) {
|
|
419
|
-
this.defaultVisit(node);
|
|
420
|
-
}
|
|
421
|
-
visitAggregateFunction(node) {
|
|
422
|
-
this.defaultVisit(node);
|
|
423
|
-
}
|
|
424
|
-
visitOver(node) {
|
|
425
|
-
this.defaultVisit(node);
|
|
426
|
-
}
|
|
427
|
-
visitPartitionBy(node) {
|
|
428
|
-
this.defaultVisit(node);
|
|
429
|
-
}
|
|
430
|
-
visitPartitionByItem(node) {
|
|
431
|
-
this.defaultVisit(node);
|
|
432
|
-
}
|
|
433
|
-
visitSetOperation(node) {
|
|
434
|
-
this.defaultVisit(node);
|
|
435
|
-
}
|
|
436
|
-
visitBinaryOperation(node) {
|
|
437
|
-
this.defaultVisit(node);
|
|
438
|
-
}
|
|
439
|
-
visitUnaryOperation(node) {
|
|
440
|
-
this.defaultVisit(node);
|
|
441
|
-
}
|
|
442
|
-
visitUsing(node) {
|
|
443
|
-
this.defaultVisit(node);
|
|
444
|
-
}
|
|
445
|
-
visitFunction(node) {
|
|
446
|
-
this.defaultVisit(node);
|
|
447
|
-
}
|
|
448
|
-
visitCase(node) {
|
|
449
|
-
this.defaultVisit(node);
|
|
450
|
-
}
|
|
451
|
-
visitWhen(node) {
|
|
452
|
-
this.defaultVisit(node);
|
|
453
|
-
}
|
|
454
|
-
visitJSONReference(node) {
|
|
455
|
-
this.defaultVisit(node);
|
|
456
|
-
}
|
|
457
|
-
visitJSONPath(node) {
|
|
458
|
-
this.defaultVisit(node);
|
|
459
|
-
}
|
|
460
|
-
visitJSONPathLeg(node) {
|
|
461
|
-
this.defaultVisit(node);
|
|
462
|
-
}
|
|
463
|
-
visitJSONOperatorChain(node) {
|
|
464
|
-
this.defaultVisit(node);
|
|
465
|
-
}
|
|
466
|
-
visitTuple(node) {
|
|
467
|
-
this.defaultVisit(node);
|
|
468
|
-
}
|
|
469
|
-
visitMergeQuery(node) {
|
|
470
|
-
this.defaultVisit(node);
|
|
471
|
-
}
|
|
472
|
-
visitMatched(node) {
|
|
473
|
-
this.defaultVisit(node);
|
|
474
|
-
}
|
|
475
|
-
visitAddIndex(node) {
|
|
476
|
-
this.defaultVisit(node);
|
|
477
|
-
}
|
|
478
|
-
visitCast(node) {
|
|
479
|
-
this.defaultVisit(node);
|
|
480
|
-
}
|
|
481
|
-
visitFetch(node) {
|
|
482
|
-
this.defaultVisit(node);
|
|
483
|
-
}
|
|
484
|
-
visitTop(node) {
|
|
485
|
-
this.defaultVisit(node);
|
|
486
|
-
}
|
|
487
|
-
visitOutput(node) {
|
|
488
|
-
this.defaultVisit(node);
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
|
|
492
136
|
// src/prisma/prisma-schema-generator.ts
|
|
493
137
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
138
|
+
var import_language = require("@zenstackhq/language");
|
|
494
139
|
var import_ast2 = require("@zenstackhq/language/ast");
|
|
495
140
|
var import_utils2 = require("@zenstackhq/language/utils");
|
|
496
141
|
var import_langium = require("langium");
|
|
497
|
-
var
|
|
142
|
+
var import_ts_pattern = require("ts-pattern");
|
|
498
143
|
|
|
499
144
|
// src/prisma/indent-string.ts
|
|
500
145
|
function indentString(string, count = 4) {
|
|
@@ -888,6 +533,9 @@ var EnumField = class extends DeclarationBase {
|
|
|
888
533
|
|
|
889
534
|
// src/prisma/prisma-schema-generator.ts
|
|
890
535
|
var IDENTIFIER_NAME_MAX_LENGTH = 50 - DELEGATE_AUX_RELATION_PREFIX.length;
|
|
536
|
+
var NON_PRISMA_DATASOURCE_FIELDS = [
|
|
537
|
+
"defaultSchema"
|
|
538
|
+
];
|
|
891
539
|
var PrismaSchemaGenerator = class {
|
|
892
540
|
static {
|
|
893
541
|
__name(this, "PrismaSchemaGenerator");
|
|
@@ -922,10 +570,13 @@ var PrismaSchemaGenerator = class {
|
|
|
922
570
|
break;
|
|
923
571
|
}
|
|
924
572
|
}
|
|
573
|
+
if (!this.zmodel.declarations.some(import_ast2.isGeneratorDecl)) {
|
|
574
|
+
this.generateDefaultGenerator(prisma);
|
|
575
|
+
}
|
|
925
576
|
return this.PRELUDE + prisma.toString();
|
|
926
577
|
}
|
|
927
578
|
generateDataSource(prisma, dataSource) {
|
|
928
|
-
const fields = dataSource.fields.map((f) => ({
|
|
579
|
+
const fields = dataSource.fields.filter((f) => !NON_PRISMA_DATASOURCE_FIELDS.includes(f.name)).map((f) => ({
|
|
929
580
|
name: f.name,
|
|
930
581
|
text: this.configExprToText(f.value)
|
|
931
582
|
}));
|
|
@@ -962,6 +613,21 @@ var PrismaSchemaGenerator = class {
|
|
|
962
613
|
text: this.configExprToText(f.value)
|
|
963
614
|
})));
|
|
964
615
|
}
|
|
616
|
+
generateDefaultGenerator(prisma) {
|
|
617
|
+
const gen = prisma.addGenerator("client", [
|
|
618
|
+
{
|
|
619
|
+
name: "provider",
|
|
620
|
+
text: '"prisma-client-js"'
|
|
621
|
+
}
|
|
622
|
+
]);
|
|
623
|
+
const dataSource = this.zmodel.declarations.find(import_ast2.isDataSource);
|
|
624
|
+
if (dataSource?.fields.some((f) => f.name === "extensions")) {
|
|
625
|
+
gen.fields.push({
|
|
626
|
+
name: "previewFeatures",
|
|
627
|
+
text: '["postgresqlExtensions"]'
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
965
631
|
generateModel(prisma, decl) {
|
|
966
632
|
const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
|
|
967
633
|
const allFields = (0, import_utils2.getAllFields)(decl, true);
|
|
@@ -973,20 +639,29 @@ var PrismaSchemaGenerator = class {
|
|
|
973
639
|
this.generateModelField(model, field, decl);
|
|
974
640
|
}
|
|
975
641
|
}
|
|
976
|
-
const allAttributes = (0, import_utils2.getAllAttributes)(decl);
|
|
977
|
-
for (const attr of allAttributes
|
|
642
|
+
const allAttributes = (0, import_utils2.getAllAttributes)(decl).filter((attr) => this.isPrismaAttribute(attr));
|
|
643
|
+
for (const attr of allAttributes) {
|
|
978
644
|
this.generateContainerAttribute(model, attr);
|
|
979
645
|
}
|
|
646
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
647
|
+
model.addAttribute("@@schema", [
|
|
648
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
649
|
+
]);
|
|
650
|
+
}
|
|
980
651
|
decl.comments.forEach((c) => model.addComment(c));
|
|
981
652
|
this.generateDelegateRelationForBase(model, decl);
|
|
982
653
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
983
654
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
return
|
|
655
|
+
getDatasourceField(zmodel, fieldName) {
|
|
656
|
+
const dataSource = zmodel.declarations.find(import_ast2.isDataSource);
|
|
657
|
+
return dataSource?.fields.find((f) => f.name === fieldName);
|
|
658
|
+
}
|
|
659
|
+
datasourceHasSchemasSetting(zmodel) {
|
|
660
|
+
return !!this.getDatasourceField(zmodel, "schemas");
|
|
661
|
+
}
|
|
662
|
+
getDefaultPostgresSchemaName(zmodel) {
|
|
663
|
+
const defaultSchemaField = this.getDatasourceField(zmodel, "defaultSchema");
|
|
664
|
+
return (0, import_utils2.getStringLiteral)(defaultSchemaField?.value) ?? "public";
|
|
990
665
|
}
|
|
991
666
|
isPrismaAttribute(attr) {
|
|
992
667
|
if (!attr.decl.ref) {
|
|
@@ -996,7 +671,7 @@ var PrismaSchemaGenerator = class {
|
|
|
996
671
|
}
|
|
997
672
|
getUnsupportedFieldType(fieldType) {
|
|
998
673
|
if (fieldType.unsupported) {
|
|
999
|
-
const value =
|
|
674
|
+
const value = (0, import_utils2.getStringLiteral)(fieldType.unsupported.value);
|
|
1000
675
|
if (value) {
|
|
1001
676
|
return `Unsupported("${value}")`;
|
|
1002
677
|
} else {
|
|
@@ -1006,9 +681,6 @@ var PrismaSchemaGenerator = class {
|
|
|
1006
681
|
return void 0;
|
|
1007
682
|
}
|
|
1008
683
|
}
|
|
1009
|
-
getStringLiteral(node) {
|
|
1010
|
-
return (0, import_ast2.isStringLiteral)(node) ? node.value : void 0;
|
|
1011
|
-
}
|
|
1012
684
|
generateModelField(model, field, contextModel, addToFront = false) {
|
|
1013
685
|
let fieldType;
|
|
1014
686
|
if (field.type.type) {
|
|
@@ -1065,7 +737,7 @@ var PrismaSchemaGenerator = class {
|
|
|
1065
737
|
}
|
|
1066
738
|
makeAttributeArgValue(node) {
|
|
1067
739
|
if ((0, import_ast2.isLiteralExpr)(node)) {
|
|
1068
|
-
const argType = (0,
|
|
740
|
+
const argType = (0, import_ts_pattern.match)(node.$type).with(import_ast2.StringLiteral, () => "String").with(import_ast2.NumberLiteral, () => "Number").with(import_ast2.BooleanLiteral, () => "Boolean").exhaustive();
|
|
1069
741
|
return new AttributeArgValue(argType, node.value);
|
|
1070
742
|
} else if ((0, import_ast2.isArrayExpr)(node)) {
|
|
1071
743
|
return new AttributeArgValue("Array", new Array(...node.items.map((item) => this.makeAttributeArgValue(item))));
|
|
@@ -1078,13 +750,13 @@ var PrismaSchemaGenerator = class {
|
|
|
1078
750
|
}
|
|
1079
751
|
}
|
|
1080
752
|
exprToText(expr) {
|
|
1081
|
-
return new ZModelCodeGenerator({
|
|
753
|
+
return new import_language.ZModelCodeGenerator({
|
|
1082
754
|
quote: "double"
|
|
1083
755
|
}).generate(expr);
|
|
1084
756
|
}
|
|
1085
757
|
makeFunctionCall(node) {
|
|
1086
758
|
return new FunctionCall(node.function.ref.name, node.args.map((arg) => {
|
|
1087
|
-
const val = (0,
|
|
759
|
+
const val = (0, import_ts_pattern.match)(arg.value).when(import_ast2.isStringLiteral, (v) => `"${v.value}"`).when(import_ast2.isLiteralExpr, (v) => v.value.toString()).when(import_ast2.isNullExpr, () => "null").otherwise(() => {
|
|
1088
760
|
throw new Error("Function call argument must be literal or null");
|
|
1089
761
|
});
|
|
1090
762
|
return new FunctionCallArg(val);
|
|
@@ -1099,9 +771,15 @@ var PrismaSchemaGenerator = class {
|
|
|
1099
771
|
for (const field of decl.fields) {
|
|
1100
772
|
this.generateEnumField(_enum, field);
|
|
1101
773
|
}
|
|
1102
|
-
|
|
774
|
+
const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
|
|
775
|
+
for (const attr of allAttributes) {
|
|
1103
776
|
this.generateContainerAttribute(_enum, attr);
|
|
1104
777
|
}
|
|
778
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
779
|
+
_enum.addAttribute("@@schema", [
|
|
780
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
781
|
+
]);
|
|
782
|
+
}
|
|
1105
783
|
decl.comments.forEach((c) => _enum.addComment(c));
|
|
1106
784
|
}
|
|
1107
785
|
generateEnumField(_enum, field) {
|
|
@@ -1173,36 +851,51 @@ var import_ast3 = require("@zenstackhq/language/ast");
|
|
|
1173
851
|
var import_utils3 = require("@zenstackhq/language/utils");
|
|
1174
852
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
1175
853
|
var import_node_path = __toESM(require("path"), 1);
|
|
1176
|
-
var
|
|
854
|
+
var import_ts_pattern2 = require("ts-pattern");
|
|
1177
855
|
var ts = __toESM(require("typescript"), 1);
|
|
1178
856
|
var TsSchemaGenerator = class {
|
|
1179
857
|
static {
|
|
1180
858
|
__name(this, "TsSchemaGenerator");
|
|
1181
859
|
}
|
|
1182
860
|
usedExpressionUtils = false;
|
|
1183
|
-
async generate(model,
|
|
1184
|
-
import_node_fs.default.mkdirSync(
|
|
861
|
+
async generate(model, options) {
|
|
862
|
+
import_node_fs.default.mkdirSync(options.outDir, {
|
|
1185
863
|
recursive: true
|
|
1186
864
|
});
|
|
1187
865
|
this.usedExpressionUtils = false;
|
|
1188
|
-
this.generateSchema(model,
|
|
1189
|
-
this.generateModelsAndTypeDefs(model,
|
|
1190
|
-
this.generateInputTypes(model,
|
|
1191
|
-
}
|
|
1192
|
-
generateSchema(model,
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
866
|
+
this.generateSchema(model, options);
|
|
867
|
+
this.generateModelsAndTypeDefs(model, options);
|
|
868
|
+
this.generateInputTypes(model, options);
|
|
869
|
+
}
|
|
870
|
+
generateSchema(model, options) {
|
|
871
|
+
const targets = [];
|
|
872
|
+
if (!options.liteOnly) {
|
|
873
|
+
targets.push({
|
|
874
|
+
lite: false,
|
|
875
|
+
file: "schema.ts"
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
if (options.lite || options.liteOnly) {
|
|
879
|
+
targets.push({
|
|
880
|
+
lite: true,
|
|
881
|
+
file: "schema-lite.ts"
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
for (const { lite, file } of targets) {
|
|
885
|
+
const statements = [];
|
|
886
|
+
this.generateSchemaStatements(model, statements, lite);
|
|
887
|
+
this.generateBannerComments(statements);
|
|
888
|
+
const schemaOutputFile = import_node_path.default.join(options.outDir, file);
|
|
889
|
+
const sourceFile = ts.createSourceFile(schemaOutputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
890
|
+
const printer = ts.createPrinter();
|
|
891
|
+
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
892
|
+
import_node_fs.default.writeFileSync(schemaOutputFile, result);
|
|
893
|
+
}
|
|
1201
894
|
}
|
|
1202
|
-
generateSchemaStatements(model, statements) {
|
|
895
|
+
generateSchemaStatements(model, statements, lite) {
|
|
1203
896
|
const hasComputedFields = model.declarations.some((d) => (0, import_ast3.isDataModel)(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
1204
|
-
const
|
|
1205
|
-
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(
|
|
897
|
+
const schemaClass = this.createSchemaClass(model, lite);
|
|
898
|
+
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
|
|
1206
899
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
1207
900
|
...hasComputedFields ? [
|
|
1208
901
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
@@ -1210,64 +903,81 @@ var TsSchemaGenerator = class {
|
|
|
1210
903
|
...this.usedExpressionUtils ? [
|
|
1211
904
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
|
|
1212
905
|
] : []
|
|
1213
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
906
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
1214
907
|
statements.push(runtimeImportDecl);
|
|
1215
|
-
|
|
908
|
+
statements.push(schemaClass);
|
|
909
|
+
const schemaDecl = ts.factory.createVariableStatement([
|
|
1216
910
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1217
911
|
], ts.factory.createVariableDeclarationList([
|
|
1218
|
-
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.
|
|
912
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))
|
|
1219
913
|
], ts.NodeFlags.Const));
|
|
1220
|
-
statements.push(
|
|
1221
|
-
const typeDeclaration = ts.factory.createTypeAliasDeclaration([
|
|
1222
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1223
|
-
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("typeof schema"));
|
|
1224
|
-
statements.push(typeDeclaration);
|
|
914
|
+
statements.push(schemaDecl);
|
|
1225
915
|
}
|
|
1226
916
|
createExpressionUtilsCall(method, args) {
|
|
1227
917
|
this.usedExpressionUtils = true;
|
|
1228
918
|
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
1229
919
|
}
|
|
1230
|
-
|
|
1231
|
-
const
|
|
920
|
+
createSchemaClass(model, lite) {
|
|
921
|
+
const members = [
|
|
1232
922
|
// provider
|
|
1233
|
-
ts.factory.
|
|
923
|
+
ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
|
|
1234
924
|
// models
|
|
1235
|
-
ts.factory.
|
|
925
|
+
ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
|
|
1236
926
|
// typeDefs
|
|
1237
927
|
...model.declarations.some(import_ast3.isTypeDef) ? [
|
|
1238
|
-
ts.factory.
|
|
928
|
+
ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))
|
|
1239
929
|
] : []
|
|
1240
930
|
];
|
|
1241
931
|
const enums = model.declarations.filter(import_ast3.isEnum);
|
|
1242
932
|
if (enums.length > 0) {
|
|
1243
|
-
|
|
933
|
+
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))));
|
|
1244
934
|
}
|
|
1245
935
|
const authType = getAuthDecl(model);
|
|
1246
936
|
if (authType) {
|
|
1247
|
-
|
|
937
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
|
|
1248
938
|
}
|
|
1249
939
|
const procedures = model.declarations.filter(import_ast3.isProcedure);
|
|
1250
940
|
if (procedures.length > 0) {
|
|
1251
|
-
|
|
941
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
|
|
1252
942
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
943
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
|
|
944
|
+
const schemaClass = ts.factory.createClassDeclaration([
|
|
945
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
946
|
+
], "SchemaType", void 0, [
|
|
947
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
|
|
948
|
+
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)
|
|
949
|
+
])
|
|
950
|
+
], members);
|
|
951
|
+
return schemaClass;
|
|
952
|
+
}
|
|
953
|
+
createAsConst(expr) {
|
|
954
|
+
return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
|
|
1255
955
|
}
|
|
1256
956
|
createProviderObject(model) {
|
|
1257
957
|
const dsProvider = this.getDataSourceProvider(model);
|
|
958
|
+
const defaultSchema = this.getDataSourceDefaultSchema(model);
|
|
1258
959
|
return ts.factory.createObjectLiteralExpression([
|
|
1259
|
-
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider
|
|
960
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider)),
|
|
961
|
+
...defaultSchema ? [
|
|
962
|
+
ts.factory.createPropertyAssignment("defaultSchema", ts.factory.createStringLiteral(defaultSchema))
|
|
963
|
+
] : []
|
|
1260
964
|
], true);
|
|
1261
965
|
}
|
|
1262
|
-
createModelsObject(model) {
|
|
1263
|
-
return ts.factory.createObjectLiteralExpression(
|
|
966
|
+
createModelsObject(model, lite) {
|
|
967
|
+
return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
|
|
1264
968
|
}
|
|
1265
|
-
|
|
1266
|
-
return
|
|
969
|
+
getAllDataModels(model) {
|
|
970
|
+
return model.declarations.filter((d) => (0, import_ast3.isDataModel)(d) && !hasAttribute(d, "@@ignore"));
|
|
1267
971
|
}
|
|
1268
|
-
|
|
972
|
+
getAllTypeDefs(model) {
|
|
973
|
+
return model.declarations.filter((d) => (0, import_ast3.isTypeDef)(d) && !hasAttribute(d, "@@ignore"));
|
|
974
|
+
}
|
|
975
|
+
createTypeDefsObject(model, lite) {
|
|
976
|
+
return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
|
|
977
|
+
}
|
|
978
|
+
createDataModelObject(dm, lite) {
|
|
1269
979
|
const allFields = (0, import_utils3.getAllFields)(dm);
|
|
1270
|
-
const allAttributes = (0, import_utils3.getAllAttributes)(dm).filter((attr) => {
|
|
980
|
+
const allAttributes = lite ? [] : (0, import_utils3.getAllAttributes)(dm).filter((attr) => {
|
|
1271
981
|
if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) {
|
|
1272
982
|
return false;
|
|
1273
983
|
}
|
|
@@ -1282,7 +992,7 @@ var TsSchemaGenerator = class {
|
|
|
1282
992
|
ts.factory.createPropertyAssignment("baseModel", ts.factory.createStringLiteral(dm.baseModel.$refText))
|
|
1283
993
|
] : [],
|
|
1284
994
|
// fields
|
|
1285
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm))), true)),
|
|
995
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm, lite))), true)),
|
|
1286
996
|
// attributes
|
|
1287
997
|
...allAttributes.length > 0 ? [
|
|
1288
998
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -1312,14 +1022,14 @@ var TsSchemaGenerator = class {
|
|
|
1312
1022
|
getSubModels(dm) {
|
|
1313
1023
|
return dm.$container.declarations.filter(import_ast3.isDataModel).filter((d) => d.baseModel?.ref === dm).map((d) => d.name);
|
|
1314
1024
|
}
|
|
1315
|
-
createTypeDefObject(td) {
|
|
1025
|
+
createTypeDefObject(td, lite) {
|
|
1316
1026
|
const allFields = (0, import_utils3.getAllFields)(td);
|
|
1317
1027
|
const allAttributes = (0, import_utils3.getAllAttributes)(td);
|
|
1318
1028
|
const fields = [
|
|
1319
1029
|
// name
|
|
1320
1030
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
|
|
1321
1031
|
// fields
|
|
1322
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0))), true)),
|
|
1032
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
|
|
1323
1033
|
// attributes
|
|
1324
1034
|
...allAttributes.length > 0 ? [
|
|
1325
1035
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -1342,7 +1052,7 @@ var TsSchemaGenerator = class {
|
|
|
1342
1052
|
], true))), true);
|
|
1343
1053
|
}
|
|
1344
1054
|
mapFieldTypeToTSType(type) {
|
|
1345
|
-
let result = (0,
|
|
1055
|
+
let result = (0, import_ts_pattern2.match)(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").otherwise(() => "unknown");
|
|
1346
1056
|
if (type.array) {
|
|
1347
1057
|
result = `${result}[]`;
|
|
1348
1058
|
}
|
|
@@ -1351,7 +1061,7 @@ var TsSchemaGenerator = class {
|
|
|
1351
1061
|
}
|
|
1352
1062
|
return result;
|
|
1353
1063
|
}
|
|
1354
|
-
createDataFieldObject(field, contextModel) {
|
|
1064
|
+
createDataFieldObject(field, contextModel, lite) {
|
|
1355
1065
|
const objectFields = [
|
|
1356
1066
|
// name
|
|
1357
1067
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
@@ -1373,6 +1083,9 @@ var TsSchemaGenerator = class {
|
|
|
1373
1083
|
if (hasAttribute(field, "@updatedAt")) {
|
|
1374
1084
|
objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
|
|
1375
1085
|
}
|
|
1086
|
+
if (hasAttribute(field, "@omit")) {
|
|
1087
|
+
objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
|
|
1088
|
+
}
|
|
1376
1089
|
if (contextModel && // id fields are duplicated in inherited models
|
|
1377
1090
|
!isIdField(field, contextModel) && field.$container !== contextModel && isDelegateModel(field.$container)) {
|
|
1378
1091
|
objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(field.$container.name)));
|
|
@@ -1380,7 +1093,7 @@ var TsSchemaGenerator = class {
|
|
|
1380
1093
|
if (this.isDiscriminatorField(field)) {
|
|
1381
1094
|
objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
|
|
1382
1095
|
}
|
|
1383
|
-
if (field.attributes.length > 0) {
|
|
1096
|
+
if (!lite && field.attributes.length > 0) {
|
|
1384
1097
|
objectFields.push(ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr)))));
|
|
1385
1098
|
}
|
|
1386
1099
|
const defaultValue = this.getFieldMappedDefault(field);
|
|
@@ -1433,11 +1146,18 @@ var TsSchemaGenerator = class {
|
|
|
1433
1146
|
const dataSource = model.declarations.find(import_ast3.isDataSource);
|
|
1434
1147
|
(0, import_common_helpers2.invariant)(dataSource, "No data source found in the model");
|
|
1435
1148
|
const providerExpr = dataSource.fields.find((f) => f.name === "provider")?.value;
|
|
1436
|
-
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(providerExpr), "Provider must be a literal");
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1149
|
+
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(providerExpr) && typeof providerExpr.value === "string", "Provider must be a string literal");
|
|
1150
|
+
return providerExpr.value;
|
|
1151
|
+
}
|
|
1152
|
+
getDataSourceDefaultSchema(model) {
|
|
1153
|
+
const dataSource = model.declarations.find(import_ast3.isDataSource);
|
|
1154
|
+
(0, import_common_helpers2.invariant)(dataSource, "No data source found in the model");
|
|
1155
|
+
const defaultSchemaExpr = dataSource.fields.find((f) => f.name === "defaultSchema")?.value;
|
|
1156
|
+
if (!defaultSchemaExpr) {
|
|
1157
|
+
return void 0;
|
|
1158
|
+
}
|
|
1159
|
+
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(defaultSchemaExpr) && typeof defaultSchemaExpr.value === "string", "Default schema must be a string literal");
|
|
1160
|
+
return defaultSchemaExpr.value;
|
|
1441
1161
|
}
|
|
1442
1162
|
getFieldMappedDefault(field) {
|
|
1443
1163
|
const defaultAttr = getAttribute(field, "@default");
|
|
@@ -1507,12 +1227,16 @@ var TsSchemaGenerator = class {
|
|
|
1507
1227
|
relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
|
|
1508
1228
|
}
|
|
1509
1229
|
const relation = getAttribute(field, "@relation");
|
|
1230
|
+
const fkFields = [];
|
|
1510
1231
|
if (relation) {
|
|
1511
1232
|
for (const arg of relation.args) {
|
|
1512
1233
|
const param = arg.$resolvedParam.name;
|
|
1513
1234
|
if (param === "fields" || param === "references") {
|
|
1514
1235
|
const fieldNames = this.getReferenceNames(arg.value);
|
|
1515
1236
|
if (fieldNames) {
|
|
1237
|
+
if (param === "fields") {
|
|
1238
|
+
fkFields.push(...fieldNames);
|
|
1239
|
+
}
|
|
1516
1240
|
relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
|
|
1517
1241
|
}
|
|
1518
1242
|
}
|
|
@@ -1522,6 +1246,15 @@ var TsSchemaGenerator = class {
|
|
|
1522
1246
|
}
|
|
1523
1247
|
}
|
|
1524
1248
|
}
|
|
1249
|
+
if (fkFields.length > 0) {
|
|
1250
|
+
const allHaveDefault = fkFields.every((fieldName) => {
|
|
1251
|
+
const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
|
|
1252
|
+
return fieldDef && hasAttribute(fieldDef, "@default");
|
|
1253
|
+
});
|
|
1254
|
+
if (allHaveDefault) {
|
|
1255
|
+
relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1525
1258
|
return ts.factory.createObjectLiteralExpression(relationFields);
|
|
1526
1259
|
}
|
|
1527
1260
|
getReferenceNames(expr) {
|
|
@@ -1590,7 +1323,11 @@ var TsSchemaGenerator = class {
|
|
|
1590
1323
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1591
1324
|
for (const attr of allAttributes) {
|
|
1592
1325
|
if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
|
|
1593
|
-
const
|
|
1326
|
+
const fieldsArg = (0, import_utils3.getAttributeArg)(attr, "fields");
|
|
1327
|
+
if (!fieldsArg) {
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
const fieldNames = this.getReferenceNames(fieldsArg);
|
|
1594
1331
|
if (!fieldNames) {
|
|
1595
1332
|
continue;
|
|
1596
1333
|
}
|
|
@@ -1629,7 +1366,21 @@ var TsSchemaGenerator = class {
|
|
|
1629
1366
|
return field.type.type ? ts.factory.createStringLiteral(field.type.type) : field.type.reference ? ts.factory.createStringLiteral(field.type.reference.$refText) : ts.factory.createStringLiteral("Unsupported");
|
|
1630
1367
|
}
|
|
1631
1368
|
createEnumObject(e) {
|
|
1632
|
-
return ts.factory.createObjectLiteralExpression(
|
|
1369
|
+
return ts.factory.createObjectLiteralExpression([
|
|
1370
|
+
ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
|
|
1371
|
+
// only generate `fields` if there are attributes on the fields
|
|
1372
|
+
...e.fields.some((f) => f.attributes.length > 0) ? [
|
|
1373
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([
|
|
1374
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
1375
|
+
...field.attributes.length > 0 ? [
|
|
1376
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes?.map((attr) => this.createAttributeObject(attr)) ?? [], true))
|
|
1377
|
+
] : []
|
|
1378
|
+
], true))), true))
|
|
1379
|
+
] : [],
|
|
1380
|
+
...e.attributes.length > 0 ? [
|
|
1381
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(e.attributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
1382
|
+
] : []
|
|
1383
|
+
], true);
|
|
1633
1384
|
}
|
|
1634
1385
|
getLiteral(expr) {
|
|
1635
1386
|
if (!(0, import_ast3.isLiteralExpr)(expr)) {
|
|
@@ -1646,7 +1397,10 @@ var TsSchemaGenerator = class {
|
|
|
1646
1397
|
}
|
|
1647
1398
|
}
|
|
1648
1399
|
createLiteralNode(arg) {
|
|
1649
|
-
return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ?
|
|
1400
|
+
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;
|
|
1401
|
+
}
|
|
1402
|
+
createNumberLiteral(arg) {
|
|
1403
|
+
return arg < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-arg)) : ts.factory.createNumericLiteral(arg);
|
|
1650
1404
|
}
|
|
1651
1405
|
createProceduresObject(procedures) {
|
|
1652
1406
|
return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
|
|
@@ -1706,7 +1460,7 @@ var TsSchemaGenerator = class {
|
|
|
1706
1460
|
]);
|
|
1707
1461
|
}
|
|
1708
1462
|
createExpression(value) {
|
|
1709
|
-
return (0,
|
|
1463
|
+
return (0, import_ts_pattern2.match)(value).when(import_ast3.isLiteralExpr, (expr) => this.createLiteralExpression(expr.$type, expr.value)).when(import_ast3.isInvocationExpr, (expr) => this.createCallExpression(expr)).when(import_ast3.isReferenceExpr, (expr) => this.createRefExpression(expr)).when(import_ast3.isArrayExpr, (expr) => this.createArrayExpression(expr)).when(import_ast3.isUnaryExpr, (expr) => this.createUnaryExpression(expr)).when(import_ast3.isBinaryExpr, (expr) => this.createBinaryExpression(expr)).when(import_ast3.isMemberAccessExpr, (expr) => this.createMemberExpression(expr)).when(import_ast3.isNullExpr, () => this.createNullExpression()).when(import_ast3.isThisExpr, () => this.createThisExpression()).otherwise(() => {
|
|
1710
1464
|
throw new Error(`Unsupported attribute arg value: ${value.$type}`);
|
|
1711
1465
|
});
|
|
1712
1466
|
}
|
|
@@ -1768,7 +1522,7 @@ var TsSchemaGenerator = class {
|
|
|
1768
1522
|
]);
|
|
1769
1523
|
}
|
|
1770
1524
|
createLiteralExpression(type, value) {
|
|
1771
|
-
return (0,
|
|
1525
|
+
return (0, import_ts_pattern2.match)(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1772
1526
|
this.createLiteralNode(value)
|
|
1773
1527
|
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1774
1528
|
ts.factory.createIdentifier(value)
|
|
@@ -1778,16 +1532,16 @@ var TsSchemaGenerator = class {
|
|
|
1778
1532
|
throw new Error(`Unsupported literal type: ${type}`);
|
|
1779
1533
|
});
|
|
1780
1534
|
}
|
|
1781
|
-
generateModelsAndTypeDefs(model,
|
|
1535
|
+
generateModelsAndTypeDefs(model, options) {
|
|
1782
1536
|
const statements = [];
|
|
1783
|
-
statements.push(this.generateSchemaImport(model, true, true));
|
|
1537
|
+
statements.push(this.generateSchemaImport(model, true, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1784
1538
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
1785
1539
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)),
|
|
1786
1540
|
...model.declarations.some(import_ast3.isTypeDef) ? [
|
|
1787
1541
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1788
1542
|
] : []
|
|
1789
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1790
|
-
const dataModels =
|
|
1543
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1544
|
+
const dataModels = this.getAllDataModels(model);
|
|
1791
1545
|
for (const dm of dataModels) {
|
|
1792
1546
|
let modelType = ts.factory.createTypeAliasDeclaration([
|
|
1793
1547
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1800,7 +1554,7 @@ var TsSchemaGenerator = class {
|
|
|
1800
1554
|
}
|
|
1801
1555
|
statements.push(modelType);
|
|
1802
1556
|
}
|
|
1803
|
-
const typeDefs =
|
|
1557
|
+
const typeDefs = this.getAllTypeDefs(model);
|
|
1804
1558
|
for (const td of typeDefs) {
|
|
1805
1559
|
let typeDef = ts.factory.createTypeAliasDeclaration([
|
|
1806
1560
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1818,7 +1572,7 @@ var TsSchemaGenerator = class {
|
|
|
1818
1572
|
let enumDecl = ts.factory.createVariableStatement([
|
|
1819
1573
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1820
1574
|
], ts.factory.createVariableDeclarationList([
|
|
1821
|
-
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)))
|
|
1575
|
+
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")))
|
|
1822
1576
|
], ts.NodeFlags.Const));
|
|
1823
1577
|
if (e.comments.length > 0) {
|
|
1824
1578
|
enumDecl = this.generateDocs(enumDecl, e);
|
|
@@ -1833,13 +1587,13 @@ var TsSchemaGenerator = class {
|
|
|
1833
1587
|
statements.push(typeAlias);
|
|
1834
1588
|
}
|
|
1835
1589
|
this.generateBannerComments(statements);
|
|
1836
|
-
const outputFile = import_node_path.default.join(
|
|
1590
|
+
const outputFile = import_node_path.default.join(options.outDir, "models.ts");
|
|
1837
1591
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1838
1592
|
const printer = ts.createPrinter();
|
|
1839
1593
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1840
1594
|
import_node_fs.default.writeFileSync(outputFile, result);
|
|
1841
1595
|
}
|
|
1842
|
-
generateSchemaImport(model, schemaObject, schemaType) {
|
|
1596
|
+
generateSchemaImport(model, schemaObject, schemaType, useLite, importWithFileExtension) {
|
|
1843
1597
|
const importSpecifiers = [];
|
|
1844
1598
|
if (schemaObject) {
|
|
1845
1599
|
if (model.declarations.some(import_ast3.isEnum)) {
|
|
@@ -1849,17 +1603,21 @@ var TsSchemaGenerator = class {
|
|
|
1849
1603
|
if (schemaType) {
|
|
1850
1604
|
importSpecifiers.push(ts.factory.createImportSpecifier(true, ts.factory.createIdentifier("SchemaType"), ts.factory.createIdentifier("$Schema")));
|
|
1851
1605
|
}
|
|
1852
|
-
|
|
1606
|
+
let importFrom = useLite ? "./schema-lite" : "./schema";
|
|
1607
|
+
if (importWithFileExtension) {
|
|
1608
|
+
importFrom += importWithFileExtension.startsWith(".") ? importWithFileExtension : `.${importWithFileExtension}`;
|
|
1609
|
+
}
|
|
1610
|
+
return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral(importFrom));
|
|
1853
1611
|
}
|
|
1854
1612
|
generateDocs(tsDecl, decl) {
|
|
1855
1613
|
return ts.addSyntheticLeadingComment(tsDecl, ts.SyntaxKind.MultiLineCommentTrivia, `*
|
|
1856
1614
|
* ${decl.comments.map((c) => c.replace(/^\s*\/*\s*/, "")).join("\n * ")}
|
|
1857
1615
|
`, true);
|
|
1858
1616
|
}
|
|
1859
|
-
generateInputTypes(model,
|
|
1860
|
-
const dataModels =
|
|
1617
|
+
generateInputTypes(model, options) {
|
|
1618
|
+
const dataModels = this.getAllDataModels(model);
|
|
1861
1619
|
const statements = [];
|
|
1862
|
-
statements.push(this.generateSchemaImport(model, false, true));
|
|
1620
|
+
statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1863
1621
|
const inputTypes = [
|
|
1864
1622
|
"FindManyArgs",
|
|
1865
1623
|
"FindUniqueArgs",
|
|
@@ -1886,11 +1644,14 @@ var TsSchemaGenerator = class {
|
|
|
1886
1644
|
IncludeInput: "Include",
|
|
1887
1645
|
OmitInput: "Omit"
|
|
1888
1646
|
};
|
|
1889
|
-
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")));
|
|
1890
1647
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1891
|
-
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(
|
|
1648
|
+
...inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))),
|
|
1649
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("QueryOptions as $QueryOptions"))
|
|
1650
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1651
|
+
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1652
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedPlainResult as $Result")),
|
|
1892
1653
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
|
|
1893
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1654
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1894
1655
|
for (const dm of dataModels) {
|
|
1895
1656
|
for (const inputType of inputTypes) {
|
|
1896
1657
|
const exportName = inputTypeNameFixes[inputType] ? `${dm.name}${inputTypeNameFixes[inputType]}` : `${dm.name}${inputType}`;
|
|
@@ -1908,528 +1669,31 @@ var TsSchemaGenerator = class {
|
|
|
1908
1669
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1909
1670
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1910
1671
|
ts.factory.createLiteralTypeNode(ts.factory.createTrue())
|
|
1672
|
+
])),
|
|
1673
|
+
ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1674
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1675
|
+
]), ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1676
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1911
1677
|
]))
|
|
1912
|
-
], ts.factory.createTypeReferenceNode("$
|
|
1678
|
+
], ts.factory.createTypeReferenceNode("$Result", [
|
|
1913
1679
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1914
1680
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1915
|
-
ts.factory.createTypeReferenceNode("Args")
|
|
1681
|
+
ts.factory.createTypeReferenceNode("Args"),
|
|
1682
|
+
ts.factory.createTypeReferenceNode("Options")
|
|
1916
1683
|
])));
|
|
1917
1684
|
}
|
|
1918
1685
|
this.generateBannerComments(statements);
|
|
1919
|
-
const outputFile = import_node_path.default.join(
|
|
1686
|
+
const outputFile = import_node_path.default.join(options.outDir, "input.ts");
|
|
1920
1687
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1921
1688
|
const printer = ts.createPrinter();
|
|
1922
1689
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1923
1690
|
import_node_fs.default.writeFileSync(outputFile, result);
|
|
1924
1691
|
}
|
|
1925
1692
|
};
|
|
1926
|
-
|
|
1927
|
-
// src/zmodel-code-generator.ts
|
|
1928
|
-
var import_ast4 = require("@zenstackhq/language/ast");
|
|
1929
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
1930
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1931
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1932
|
-
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;
|
|
1933
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1934
|
-
}
|
|
1935
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
1936
|
-
function _ts_metadata(k, v) {
|
|
1937
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1938
|
-
}
|
|
1939
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
1940
|
-
var generationHandlers = /* @__PURE__ */ new Map();
|
|
1941
|
-
function gen(name) {
|
|
1942
|
-
return function(_target, _propertyKey, descriptor) {
|
|
1943
|
-
if (!generationHandlers.get(name)) {
|
|
1944
|
-
generationHandlers.set(name, descriptor);
|
|
1945
|
-
}
|
|
1946
|
-
return descriptor;
|
|
1947
|
-
};
|
|
1948
|
-
}
|
|
1949
|
-
__name(gen, "gen");
|
|
1950
|
-
var ZModelCodeGenerator = class {
|
|
1951
|
-
static {
|
|
1952
|
-
__name(this, "ZModelCodeGenerator");
|
|
1953
|
-
}
|
|
1954
|
-
options;
|
|
1955
|
-
constructor(options) {
|
|
1956
|
-
this.options = {
|
|
1957
|
-
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
1958
|
-
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
1959
|
-
indent: options?.indent ?? 4,
|
|
1960
|
-
quote: options?.quote ?? "single"
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
/**
|
|
1964
|
-
* Generates ZModel source code from AST.
|
|
1965
|
-
*/
|
|
1966
|
-
generate(ast) {
|
|
1967
|
-
const handler = generationHandlers.get(ast.$type);
|
|
1968
|
-
if (!handler) {
|
|
1969
|
-
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
1970
|
-
}
|
|
1971
|
-
return handler.value.call(this, ast);
|
|
1972
|
-
}
|
|
1973
|
-
_generateModel(ast) {
|
|
1974
|
-
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
1975
|
-
}
|
|
1976
|
-
_generateDataSource(ast) {
|
|
1977
|
-
return `datasource ${ast.name} {
|
|
1978
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1979
|
-
}`;
|
|
1980
|
-
}
|
|
1981
|
-
_generateEnum(ast) {
|
|
1982
|
-
return `enum ${ast.name} {
|
|
1983
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1984
|
-
}`;
|
|
1985
|
-
}
|
|
1986
|
-
_generateEnumField(ast) {
|
|
1987
|
-
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1988
|
-
}
|
|
1989
|
-
_generateGenerator(ast) {
|
|
1990
|
-
return `generator ${ast.name} {
|
|
1991
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1992
|
-
}`;
|
|
1993
|
-
}
|
|
1994
|
-
_generateConfigField(ast) {
|
|
1995
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1996
|
-
}
|
|
1997
|
-
_generateConfigArrayExpr(ast) {
|
|
1998
|
-
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
1999
|
-
}
|
|
2000
|
-
_generateConfigInvocationExpr(ast) {
|
|
2001
|
-
if (ast.args.length === 0) {
|
|
2002
|
-
return ast.name;
|
|
2003
|
-
} else {
|
|
2004
|
-
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
_generatePlugin(ast) {
|
|
2008
|
-
return `plugin ${ast.name} {
|
|
2009
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
2010
|
-
}`;
|
|
2011
|
-
}
|
|
2012
|
-
_generatePluginField(ast) {
|
|
2013
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
2014
|
-
}
|
|
2015
|
-
_generateDataModel(ast) {
|
|
2016
|
-
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.ref?.name).join(", ") : ""} {
|
|
2017
|
-
${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") : ""}
|
|
2018
|
-
}`;
|
|
2019
|
-
}
|
|
2020
|
-
_generateDataField(ast) {
|
|
2021
|
-
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
2022
|
-
}
|
|
2023
|
-
fieldType(type) {
|
|
2024
|
-
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
2025
|
-
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
2026
|
-
}
|
|
2027
|
-
_generateDataModelAttribute(ast) {
|
|
2028
|
-
return this.attribute(ast);
|
|
2029
|
-
}
|
|
2030
|
-
_generateDataFieldAttribute(ast) {
|
|
2031
|
-
return this.attribute(ast);
|
|
2032
|
-
}
|
|
2033
|
-
attribute(ast) {
|
|
2034
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
2035
|
-
return `${resolved(ast.decl).name}${args}`;
|
|
2036
|
-
}
|
|
2037
|
-
_generateAttributeArg(ast) {
|
|
2038
|
-
if (ast.name) {
|
|
2039
|
-
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
2040
|
-
} else {
|
|
2041
|
-
return this.generate(ast.value);
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
_generateObjectExpr(ast) {
|
|
2045
|
-
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
2046
|
-
}
|
|
2047
|
-
objectField(field) {
|
|
2048
|
-
return `${field.name}: ${this.generate(field.value)}`;
|
|
2049
|
-
}
|
|
2050
|
-
_generateArrayExpr(ast) {
|
|
2051
|
-
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
2052
|
-
}
|
|
2053
|
-
_generateLiteralExpr(ast) {
|
|
2054
|
-
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
2055
|
-
}
|
|
2056
|
-
_generateNumberLiteral(ast) {
|
|
2057
|
-
return ast.value.toString();
|
|
2058
|
-
}
|
|
2059
|
-
_generateBooleanLiteral(ast) {
|
|
2060
|
-
return ast.value.toString();
|
|
2061
|
-
}
|
|
2062
|
-
_generateUnaryExpr(ast) {
|
|
2063
|
-
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
2064
|
-
}
|
|
2065
|
-
_generateBinaryExpr(ast) {
|
|
2066
|
-
const operator = ast.operator;
|
|
2067
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
2068
|
-
const rightExpr = this.generate(ast.right);
|
|
2069
|
-
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
2070
|
-
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
2071
|
-
}
|
|
2072
|
-
_generateReferenceExpr(ast) {
|
|
2073
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
2074
|
-
return `${ast.target.ref?.name}${args}`;
|
|
2075
|
-
}
|
|
2076
|
-
_generateReferenceArg(ast) {
|
|
2077
|
-
return `${ast.name}:${this.generate(ast.value)}`;
|
|
2078
|
-
}
|
|
2079
|
-
_generateMemberExpr(ast) {
|
|
2080
|
-
return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
|
|
2081
|
-
}
|
|
2082
|
-
_generateInvocationExpr(ast) {
|
|
2083
|
-
return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
2084
|
-
}
|
|
2085
|
-
_generateNullExpr() {
|
|
2086
|
-
return "null";
|
|
2087
|
-
}
|
|
2088
|
-
_generateThisExpr() {
|
|
2089
|
-
return "this";
|
|
2090
|
-
}
|
|
2091
|
-
_generateAttribute(ast) {
|
|
2092
|
-
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
2093
|
-
}
|
|
2094
|
-
_generateAttributeParam(ast) {
|
|
2095
|
-
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
2096
|
-
}
|
|
2097
|
-
_generateAttributeParamType(ast) {
|
|
2098
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
2099
|
-
}
|
|
2100
|
-
_generateFunctionDecl(ast) {
|
|
2101
|
-
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
2102
|
-
}
|
|
2103
|
-
_generateFunctionParam(ast) {
|
|
2104
|
-
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
2105
|
-
}
|
|
2106
|
-
_generateFunctionParamType(ast) {
|
|
2107
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
2108
|
-
}
|
|
2109
|
-
_generateTypeDef(ast) {
|
|
2110
|
-
return `type ${ast.name} {
|
|
2111
|
-
${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") : ""}
|
|
2112
|
-
}`;
|
|
2113
|
-
}
|
|
2114
|
-
argument(ast) {
|
|
2115
|
-
return this.generate(ast.value);
|
|
2116
|
-
}
|
|
2117
|
-
get binaryExprSpace() {
|
|
2118
|
-
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
2119
|
-
}
|
|
2120
|
-
get unaryExprSpace() {
|
|
2121
|
-
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
2122
|
-
}
|
|
2123
|
-
get indent() {
|
|
2124
|
-
return " ".repeat(this.options.indent);
|
|
2125
|
-
}
|
|
2126
|
-
isParenthesesNeededForBinaryExpr(ast) {
|
|
2127
|
-
const result = {
|
|
2128
|
-
left: false,
|
|
2129
|
-
right: false
|
|
2130
|
-
};
|
|
2131
|
-
const operator = ast.operator;
|
|
2132
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
2133
|
-
const currentPriority = import_ast4.BinaryExprOperatorPriority[operator];
|
|
2134
|
-
if (ast.left.$type === import_ast4.BinaryExpr && import_ast4.BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
2135
|
-
result.left = true;
|
|
2136
|
-
}
|
|
2137
|
-
if (!isCollectionPredicate && ast.right.$type === import_ast4.BinaryExpr && import_ast4.BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
2138
|
-
result.right = true;
|
|
2139
|
-
}
|
|
2140
|
-
return result;
|
|
2141
|
-
}
|
|
2142
|
-
isCollectionPredicateOperator(op) {
|
|
2143
|
-
return [
|
|
2144
|
-
"?",
|
|
2145
|
-
"!",
|
|
2146
|
-
"^"
|
|
2147
|
-
].includes(op);
|
|
2148
|
-
}
|
|
2149
|
-
};
|
|
2150
|
-
_ts_decorate([
|
|
2151
|
-
gen(import_ast4.Model),
|
|
2152
|
-
_ts_metadata("design:type", Function),
|
|
2153
|
-
_ts_metadata("design:paramtypes", [
|
|
2154
|
-
typeof import_ast4.Model === "undefined" ? Object : import_ast4.Model
|
|
2155
|
-
]),
|
|
2156
|
-
_ts_metadata("design:returntype", void 0)
|
|
2157
|
-
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
2158
|
-
_ts_decorate([
|
|
2159
|
-
gen(import_ast4.DataSource),
|
|
2160
|
-
_ts_metadata("design:type", Function),
|
|
2161
|
-
_ts_metadata("design:paramtypes", [
|
|
2162
|
-
typeof import_ast4.DataSource === "undefined" ? Object : import_ast4.DataSource
|
|
2163
|
-
]),
|
|
2164
|
-
_ts_metadata("design:returntype", void 0)
|
|
2165
|
-
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
2166
|
-
_ts_decorate([
|
|
2167
|
-
gen(import_ast4.Enum),
|
|
2168
|
-
_ts_metadata("design:type", Function),
|
|
2169
|
-
_ts_metadata("design:paramtypes", [
|
|
2170
|
-
typeof import_ast4.Enum === "undefined" ? Object : import_ast4.Enum
|
|
2171
|
-
]),
|
|
2172
|
-
_ts_metadata("design:returntype", void 0)
|
|
2173
|
-
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
2174
|
-
_ts_decorate([
|
|
2175
|
-
gen(import_ast4.EnumField),
|
|
2176
|
-
_ts_metadata("design:type", Function),
|
|
2177
|
-
_ts_metadata("design:paramtypes", [
|
|
2178
|
-
typeof import_ast4.EnumField === "undefined" ? Object : import_ast4.EnumField
|
|
2179
|
-
]),
|
|
2180
|
-
_ts_metadata("design:returntype", void 0)
|
|
2181
|
-
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
2182
|
-
_ts_decorate([
|
|
2183
|
-
gen(import_ast4.GeneratorDecl),
|
|
2184
|
-
_ts_metadata("design:type", Function),
|
|
2185
|
-
_ts_metadata("design:paramtypes", [
|
|
2186
|
-
typeof import_ast4.GeneratorDecl === "undefined" ? Object : import_ast4.GeneratorDecl
|
|
2187
|
-
]),
|
|
2188
|
-
_ts_metadata("design:returntype", void 0)
|
|
2189
|
-
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
2190
|
-
_ts_decorate([
|
|
2191
|
-
gen(import_ast4.ConfigField),
|
|
2192
|
-
_ts_metadata("design:type", Function),
|
|
2193
|
-
_ts_metadata("design:paramtypes", [
|
|
2194
|
-
typeof import_ast4.ConfigField === "undefined" ? Object : import_ast4.ConfigField
|
|
2195
|
-
]),
|
|
2196
|
-
_ts_metadata("design:returntype", void 0)
|
|
2197
|
-
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
2198
|
-
_ts_decorate([
|
|
2199
|
-
gen(import_ast4.ConfigArrayExpr),
|
|
2200
|
-
_ts_metadata("design:type", Function),
|
|
2201
|
-
_ts_metadata("design:paramtypes", [
|
|
2202
|
-
typeof import_ast4.ConfigArrayExpr === "undefined" ? Object : import_ast4.ConfigArrayExpr
|
|
2203
|
-
]),
|
|
2204
|
-
_ts_metadata("design:returntype", void 0)
|
|
2205
|
-
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
2206
|
-
_ts_decorate([
|
|
2207
|
-
gen(import_ast4.ConfigInvocationExpr),
|
|
2208
|
-
_ts_metadata("design:type", Function),
|
|
2209
|
-
_ts_metadata("design:paramtypes", [
|
|
2210
|
-
typeof import_ast4.ConfigInvocationExpr === "undefined" ? Object : import_ast4.ConfigInvocationExpr
|
|
2211
|
-
]),
|
|
2212
|
-
_ts_metadata("design:returntype", void 0)
|
|
2213
|
-
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
2214
|
-
_ts_decorate([
|
|
2215
|
-
gen(import_ast4.Plugin),
|
|
2216
|
-
_ts_metadata("design:type", Function),
|
|
2217
|
-
_ts_metadata("design:paramtypes", [
|
|
2218
|
-
typeof import_ast4.Plugin === "undefined" ? Object : import_ast4.Plugin
|
|
2219
|
-
]),
|
|
2220
|
-
_ts_metadata("design:returntype", void 0)
|
|
2221
|
-
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
2222
|
-
_ts_decorate([
|
|
2223
|
-
gen(import_ast4.PluginField),
|
|
2224
|
-
_ts_metadata("design:type", Function),
|
|
2225
|
-
_ts_metadata("design:paramtypes", [
|
|
2226
|
-
typeof import_ast4.PluginField === "undefined" ? Object : import_ast4.PluginField
|
|
2227
|
-
]),
|
|
2228
|
-
_ts_metadata("design:returntype", void 0)
|
|
2229
|
-
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
2230
|
-
_ts_decorate([
|
|
2231
|
-
gen(import_ast4.DataModel),
|
|
2232
|
-
_ts_metadata("design:type", Function),
|
|
2233
|
-
_ts_metadata("design:paramtypes", [
|
|
2234
|
-
typeof import_ast4.DataModel === "undefined" ? Object : import_ast4.DataModel
|
|
2235
|
-
]),
|
|
2236
|
-
_ts_metadata("design:returntype", void 0)
|
|
2237
|
-
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
2238
|
-
_ts_decorate([
|
|
2239
|
-
gen(import_ast4.DataField),
|
|
2240
|
-
_ts_metadata("design:type", Function),
|
|
2241
|
-
_ts_metadata("design:paramtypes", [
|
|
2242
|
-
typeof import_ast4.DataField === "undefined" ? Object : import_ast4.DataField
|
|
2243
|
-
]),
|
|
2244
|
-
_ts_metadata("design:returntype", void 0)
|
|
2245
|
-
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
2246
|
-
_ts_decorate([
|
|
2247
|
-
gen(import_ast4.DataModelAttribute),
|
|
2248
|
-
_ts_metadata("design:type", Function),
|
|
2249
|
-
_ts_metadata("design:paramtypes", [
|
|
2250
|
-
typeof import_ast4.DataModelAttribute === "undefined" ? Object : import_ast4.DataModelAttribute
|
|
2251
|
-
]),
|
|
2252
|
-
_ts_metadata("design:returntype", void 0)
|
|
2253
|
-
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
2254
|
-
_ts_decorate([
|
|
2255
|
-
gen(import_ast4.DataFieldAttribute),
|
|
2256
|
-
_ts_metadata("design:type", Function),
|
|
2257
|
-
_ts_metadata("design:paramtypes", [
|
|
2258
|
-
typeof import_ast4.DataFieldAttribute === "undefined" ? Object : import_ast4.DataFieldAttribute
|
|
2259
|
-
]),
|
|
2260
|
-
_ts_metadata("design:returntype", void 0)
|
|
2261
|
-
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
2262
|
-
_ts_decorate([
|
|
2263
|
-
gen(import_ast4.AttributeArg),
|
|
2264
|
-
_ts_metadata("design:type", Function),
|
|
2265
|
-
_ts_metadata("design:paramtypes", [
|
|
2266
|
-
typeof import_ast4.AttributeArg === "undefined" ? Object : import_ast4.AttributeArg
|
|
2267
|
-
]),
|
|
2268
|
-
_ts_metadata("design:returntype", void 0)
|
|
2269
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
2270
|
-
_ts_decorate([
|
|
2271
|
-
gen(import_ast4.ObjectExpr),
|
|
2272
|
-
_ts_metadata("design:type", Function),
|
|
2273
|
-
_ts_metadata("design:paramtypes", [
|
|
2274
|
-
typeof import_ast4.ObjectExpr === "undefined" ? Object : import_ast4.ObjectExpr
|
|
2275
|
-
]),
|
|
2276
|
-
_ts_metadata("design:returntype", void 0)
|
|
2277
|
-
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
2278
|
-
_ts_decorate([
|
|
2279
|
-
gen(import_ast4.ArrayExpr),
|
|
2280
|
-
_ts_metadata("design:type", Function),
|
|
2281
|
-
_ts_metadata("design:paramtypes", [
|
|
2282
|
-
typeof import_ast4.ArrayExpr === "undefined" ? Object : import_ast4.ArrayExpr
|
|
2283
|
-
]),
|
|
2284
|
-
_ts_metadata("design:returntype", void 0)
|
|
2285
|
-
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
2286
|
-
_ts_decorate([
|
|
2287
|
-
gen(import_ast4.StringLiteral),
|
|
2288
|
-
_ts_metadata("design:type", Function),
|
|
2289
|
-
_ts_metadata("design:paramtypes", [
|
|
2290
|
-
typeof import_ast4.LiteralExpr === "undefined" ? Object : import_ast4.LiteralExpr
|
|
2291
|
-
]),
|
|
2292
|
-
_ts_metadata("design:returntype", void 0)
|
|
2293
|
-
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
2294
|
-
_ts_decorate([
|
|
2295
|
-
gen(import_ast4.NumberLiteral),
|
|
2296
|
-
_ts_metadata("design:type", Function),
|
|
2297
|
-
_ts_metadata("design:paramtypes", [
|
|
2298
|
-
typeof import_ast4.NumberLiteral === "undefined" ? Object : import_ast4.NumberLiteral
|
|
2299
|
-
]),
|
|
2300
|
-
_ts_metadata("design:returntype", void 0)
|
|
2301
|
-
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
2302
|
-
_ts_decorate([
|
|
2303
|
-
gen(import_ast4.BooleanLiteral),
|
|
2304
|
-
_ts_metadata("design:type", Function),
|
|
2305
|
-
_ts_metadata("design:paramtypes", [
|
|
2306
|
-
typeof import_ast4.BooleanLiteral === "undefined" ? Object : import_ast4.BooleanLiteral
|
|
2307
|
-
]),
|
|
2308
|
-
_ts_metadata("design:returntype", void 0)
|
|
2309
|
-
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
2310
|
-
_ts_decorate([
|
|
2311
|
-
gen(import_ast4.UnaryExpr),
|
|
2312
|
-
_ts_metadata("design:type", Function),
|
|
2313
|
-
_ts_metadata("design:paramtypes", [
|
|
2314
|
-
typeof import_ast4.UnaryExpr === "undefined" ? Object : import_ast4.UnaryExpr
|
|
2315
|
-
]),
|
|
2316
|
-
_ts_metadata("design:returntype", void 0)
|
|
2317
|
-
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
2318
|
-
_ts_decorate([
|
|
2319
|
-
gen(import_ast4.BinaryExpr),
|
|
2320
|
-
_ts_metadata("design:type", Function),
|
|
2321
|
-
_ts_metadata("design:paramtypes", [
|
|
2322
|
-
typeof import_ast4.BinaryExpr === "undefined" ? Object : import_ast4.BinaryExpr
|
|
2323
|
-
]),
|
|
2324
|
-
_ts_metadata("design:returntype", void 0)
|
|
2325
|
-
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
2326
|
-
_ts_decorate([
|
|
2327
|
-
gen(import_ast4.ReferenceExpr),
|
|
2328
|
-
_ts_metadata("design:type", Function),
|
|
2329
|
-
_ts_metadata("design:paramtypes", [
|
|
2330
|
-
typeof import_ast4.ReferenceExpr === "undefined" ? Object : import_ast4.ReferenceExpr
|
|
2331
|
-
]),
|
|
2332
|
-
_ts_metadata("design:returntype", void 0)
|
|
2333
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
2334
|
-
_ts_decorate([
|
|
2335
|
-
gen(import_ast4.ReferenceArg),
|
|
2336
|
-
_ts_metadata("design:type", Function),
|
|
2337
|
-
_ts_metadata("design:paramtypes", [
|
|
2338
|
-
typeof import_ast4.ReferenceArg === "undefined" ? Object : import_ast4.ReferenceArg
|
|
2339
|
-
]),
|
|
2340
|
-
_ts_metadata("design:returntype", void 0)
|
|
2341
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
2342
|
-
_ts_decorate([
|
|
2343
|
-
gen(import_ast4.MemberAccessExpr),
|
|
2344
|
-
_ts_metadata("design:type", Function),
|
|
2345
|
-
_ts_metadata("design:paramtypes", [
|
|
2346
|
-
typeof import_ast4.MemberAccessExpr === "undefined" ? Object : import_ast4.MemberAccessExpr
|
|
2347
|
-
]),
|
|
2348
|
-
_ts_metadata("design:returntype", void 0)
|
|
2349
|
-
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
2350
|
-
_ts_decorate([
|
|
2351
|
-
gen(import_ast4.InvocationExpr),
|
|
2352
|
-
_ts_metadata("design:type", Function),
|
|
2353
|
-
_ts_metadata("design:paramtypes", [
|
|
2354
|
-
typeof import_ast4.InvocationExpr === "undefined" ? Object : import_ast4.InvocationExpr
|
|
2355
|
-
]),
|
|
2356
|
-
_ts_metadata("design:returntype", void 0)
|
|
2357
|
-
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
2358
|
-
_ts_decorate([
|
|
2359
|
-
gen(import_ast4.NullExpr),
|
|
2360
|
-
_ts_metadata("design:type", Function),
|
|
2361
|
-
_ts_metadata("design:paramtypes", []),
|
|
2362
|
-
_ts_metadata("design:returntype", void 0)
|
|
2363
|
-
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
2364
|
-
_ts_decorate([
|
|
2365
|
-
gen(import_ast4.ThisExpr),
|
|
2366
|
-
_ts_metadata("design:type", Function),
|
|
2367
|
-
_ts_metadata("design:paramtypes", []),
|
|
2368
|
-
_ts_metadata("design:returntype", void 0)
|
|
2369
|
-
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
2370
|
-
_ts_decorate([
|
|
2371
|
-
gen(import_ast4.Attribute),
|
|
2372
|
-
_ts_metadata("design:type", Function),
|
|
2373
|
-
_ts_metadata("design:paramtypes", [
|
|
2374
|
-
typeof import_ast4.Attribute === "undefined" ? Object : import_ast4.Attribute
|
|
2375
|
-
]),
|
|
2376
|
-
_ts_metadata("design:returntype", void 0)
|
|
2377
|
-
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
2378
|
-
_ts_decorate([
|
|
2379
|
-
gen(import_ast4.AttributeParam),
|
|
2380
|
-
_ts_metadata("design:type", Function),
|
|
2381
|
-
_ts_metadata("design:paramtypes", [
|
|
2382
|
-
typeof import_ast4.AttributeParam === "undefined" ? Object : import_ast4.AttributeParam
|
|
2383
|
-
]),
|
|
2384
|
-
_ts_metadata("design:returntype", void 0)
|
|
2385
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
2386
|
-
_ts_decorate([
|
|
2387
|
-
gen(import_ast4.AttributeParamType),
|
|
2388
|
-
_ts_metadata("design:type", Function),
|
|
2389
|
-
_ts_metadata("design:paramtypes", [
|
|
2390
|
-
typeof import_ast4.AttributeParamType === "undefined" ? Object : import_ast4.AttributeParamType
|
|
2391
|
-
]),
|
|
2392
|
-
_ts_metadata("design:returntype", void 0)
|
|
2393
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
2394
|
-
_ts_decorate([
|
|
2395
|
-
gen(import_ast4.FunctionDecl),
|
|
2396
|
-
_ts_metadata("design:type", Function),
|
|
2397
|
-
_ts_metadata("design:paramtypes", [
|
|
2398
|
-
typeof import_ast4.FunctionDecl === "undefined" ? Object : import_ast4.FunctionDecl
|
|
2399
|
-
]),
|
|
2400
|
-
_ts_metadata("design:returntype", void 0)
|
|
2401
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
2402
|
-
_ts_decorate([
|
|
2403
|
-
gen(import_ast4.FunctionParam),
|
|
2404
|
-
_ts_metadata("design:type", Function),
|
|
2405
|
-
_ts_metadata("design:paramtypes", [
|
|
2406
|
-
typeof import_ast4.FunctionParam === "undefined" ? Object : import_ast4.FunctionParam
|
|
2407
|
-
]),
|
|
2408
|
-
_ts_metadata("design:returntype", void 0)
|
|
2409
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
2410
|
-
_ts_decorate([
|
|
2411
|
-
gen(import_ast4.FunctionParamType),
|
|
2412
|
-
_ts_metadata("design:type", Function),
|
|
2413
|
-
_ts_metadata("design:paramtypes", [
|
|
2414
|
-
typeof import_ast4.FunctionParamType === "undefined" ? Object : import_ast4.FunctionParamType
|
|
2415
|
-
]),
|
|
2416
|
-
_ts_metadata("design:returntype", void 0)
|
|
2417
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
2418
|
-
_ts_decorate([
|
|
2419
|
-
gen(import_ast4.TypeDef),
|
|
2420
|
-
_ts_metadata("design:type", Function),
|
|
2421
|
-
_ts_metadata("design:paramtypes", [
|
|
2422
|
-
typeof import_ast4.TypeDef === "undefined" ? Object : import_ast4.TypeDef
|
|
2423
|
-
]),
|
|
2424
|
-
_ts_metadata("design:returntype", void 0)
|
|
2425
|
-
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
2426
1693
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2427
1694
|
0 && (module.exports = {
|
|
2428
|
-
DefaultOperationNodeVisitor,
|
|
2429
|
-
ExpressionVisitor,
|
|
2430
1695
|
ModelUtils,
|
|
2431
1696
|
PrismaSchemaGenerator,
|
|
2432
|
-
TsSchemaGenerator
|
|
2433
|
-
ZModelCodeGenerator
|
|
1697
|
+
TsSchemaGenerator
|
|
2434
1698
|
});
|
|
2435
1699
|
//# sourceMappingURL=index.cjs.map
|