@zenstackhq/sdk 2.16.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.cjs +1906 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +196 -0
  5. package/dist/index.d.ts +196 -0
  6. package/dist/index.js +1872 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/schema.cjs +19 -0
  9. package/dist/schema.cjs.map +1 -0
  10. package/dist/schema.d.cts +138 -0
  11. package/dist/schema.d.ts +138 -0
  12. package/dist/schema.js +1 -0
  13. package/dist/schema.js.map +1 -0
  14. package/package.json +43 -39
  15. package/README.md +0 -5
  16. package/ast.d.ts +0 -1
  17. package/ast.js +0 -18
  18. package/ast.js.map +0 -1
  19. package/code-gen.d.ts +0 -37
  20. package/code-gen.js +0 -114
  21. package/code-gen.js.map +0 -1
  22. package/constants.d.ts +0 -15
  23. package/constants.js +0 -21
  24. package/constants.js.map +0 -1
  25. package/dmmf-helpers/aggregate-helpers.d.ts +0 -5
  26. package/dmmf-helpers/aggregate-helpers.js +0 -65
  27. package/dmmf-helpers/aggregate-helpers.js.map +0 -1
  28. package/dmmf-helpers/include-helpers.d.ts +0 -2
  29. package/dmmf-helpers/include-helpers.js +0 -88
  30. package/dmmf-helpers/include-helpers.js.map +0 -1
  31. package/dmmf-helpers/index.d.ts +0 -7
  32. package/dmmf-helpers/index.js +0 -24
  33. package/dmmf-helpers/index.js.map +0 -1
  34. package/dmmf-helpers/missing-types-helper.d.ts +0 -2
  35. package/dmmf-helpers/missing-types-helper.js +0 -14
  36. package/dmmf-helpers/missing-types-helper.js.map +0 -1
  37. package/dmmf-helpers/model-helpers.d.ts +0 -16
  38. package/dmmf-helpers/model-helpers.js +0 -38
  39. package/dmmf-helpers/model-helpers.js.map +0 -1
  40. package/dmmf-helpers/modelArgs-helpers.d.ts +0 -2
  41. package/dmmf-helpers/modelArgs-helpers.js +0 -67
  42. package/dmmf-helpers/modelArgs-helpers.js.map +0 -1
  43. package/dmmf-helpers/select-helpers.d.ts +0 -2
  44. package/dmmf-helpers/select-helpers.js +0 -152
  45. package/dmmf-helpers/select-helpers.js.map +0 -1
  46. package/dmmf-helpers/types.d.ts +0 -20
  47. package/dmmf-helpers/types.js +0 -3
  48. package/dmmf-helpers/types.js.map +0 -1
  49. package/index.d.ts +0 -11
  50. package/index.js +0 -30
  51. package/index.js.map +0 -1
  52. package/model-meta-generator.d.ts +0 -24
  53. package/model-meta-generator.js +0 -458
  54. package/model-meta-generator.js.map +0 -1
  55. package/names.d.ts +0 -9
  56. package/names.js +0 -17
  57. package/names.js.map +0 -1
  58. package/path.d.ts +0 -4
  59. package/path.js +0 -15
  60. package/path.js.map +0 -1
  61. package/policy.d.ts +0 -13
  62. package/policy.js +0 -57
  63. package/policy.js.map +0 -1
  64. package/prisma.d.ts +0 -21
  65. package/prisma.js +0 -84
  66. package/prisma.js.map +0 -1
  67. package/types.d.ts +0 -97
  68. package/types.js +0 -14
  69. package/types.js.map +0 -1
  70. package/typescript-expression-transformer.d.ts +0 -64
  71. package/typescript-expression-transformer.js +0 -491
  72. package/typescript-expression-transformer.js.map +0 -1
  73. package/utils.d.ts +0 -103
  74. package/utils.js +0 -633
  75. package/utils.js.map +0 -1
  76. package/validation.d.ts +0 -7
  77. package/validation.js +0 -37
  78. package/validation.js.map +0 -1
  79. package/zmodel-code-generator.d.ts +0 -66
  80. package/zmodel-code-generator.js +0 -353
  81. package/zmodel-code-generator.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,1906 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ ModelUtils: () => model_utils_exports,
35
+ PrismaSchemaGenerator: () => PrismaSchemaGenerator,
36
+ TsSchemaGenerator: () => TsSchemaGenerator,
37
+ ZModelCodeGenerator: () => ZModelCodeGenerator
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+
41
+ // src/model-utils.ts
42
+ var model_utils_exports = {};
43
+ __export(model_utils_exports, {
44
+ getAttribute: () => getAttribute,
45
+ getAuthDecl: () => getAuthDecl,
46
+ getContainingModel: () => getContainingModel,
47
+ getModelIdFields: () => getModelIdFields,
48
+ getModelUniqueFields: () => getModelUniqueFields,
49
+ getRecursiveBases: () => getRecursiveBases,
50
+ hasAttribute: () => hasAttribute,
51
+ isDelegateModel: () => isDelegateModel,
52
+ isFromStdlib: () => isFromStdlib,
53
+ isIdField: () => isIdField,
54
+ isUniqueField: () => isUniqueField,
55
+ resolved: () => resolved
56
+ });
57
+ var import_ast = require("@zenstackhq/language/ast");
58
+ function isIdField(field) {
59
+ if (hasAttribute(field, "@id")) {
60
+ return true;
61
+ }
62
+ const model = field.$container;
63
+ const modelLevelIds = getModelIdFields(model);
64
+ if (modelLevelIds.map((f) => f.name).includes(field.name)) {
65
+ return true;
66
+ }
67
+ if (model.fields.some((f) => hasAttribute(f, "@id")) || modelLevelIds.length > 0) {
68
+ return false;
69
+ }
70
+ const firstUniqueField = model.fields.find((f) => hasAttribute(f, "@unique"));
71
+ if (firstUniqueField) {
72
+ return firstUniqueField.name === field.name;
73
+ }
74
+ const modelLevelUnique = getModelUniqueFields(model);
75
+ if (modelLevelUnique.map((f) => f.name).includes(field.name)) {
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ __name(isIdField, "isIdField");
81
+ function hasAttribute(decl, name) {
82
+ return !!getAttribute(decl, name);
83
+ }
84
+ __name(hasAttribute, "hasAttribute");
85
+ function getAttribute(decl, name) {
86
+ return decl.attributes.find((attr) => attr.decl.$refText === name);
87
+ }
88
+ __name(getAttribute, "getAttribute");
89
+ function getModelIdFields(model) {
90
+ const modelsToCheck = model.$baseMerged ? [
91
+ model
92
+ ] : [
93
+ model,
94
+ ...getRecursiveBases(model)
95
+ ];
96
+ for (const modelToCheck of modelsToCheck) {
97
+ const idAttr = modelToCheck.attributes.find((attr) => attr.decl.$refText === "@@id");
98
+ if (!idAttr) {
99
+ continue;
100
+ }
101
+ const fieldsArg = idAttr.args.find((a) => a.$resolvedParam?.name === "fields");
102
+ if (!fieldsArg || !(0, import_ast.isArrayExpr)(fieldsArg.value)) {
103
+ continue;
104
+ }
105
+ return fieldsArg.value.items.filter((item) => (0, import_ast.isReferenceExpr)(item)).map((item) => item.target.ref);
106
+ }
107
+ return [];
108
+ }
109
+ __name(getModelIdFields, "getModelIdFields");
110
+ function getModelUniqueFields(model) {
111
+ const modelsToCheck = model.$baseMerged ? [
112
+ model
113
+ ] : [
114
+ model,
115
+ ...getRecursiveBases(model)
116
+ ];
117
+ for (const modelToCheck of modelsToCheck) {
118
+ const uniqueAttr = modelToCheck.attributes.find((attr) => attr.decl.$refText === "@@unique");
119
+ if (!uniqueAttr) {
120
+ continue;
121
+ }
122
+ const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === "fields");
123
+ if (!fieldsArg || !(0, import_ast.isArrayExpr)(fieldsArg.value)) {
124
+ continue;
125
+ }
126
+ return fieldsArg.value.items.filter((item) => (0, import_ast.isReferenceExpr)(item)).map((item) => item.target.ref);
127
+ }
128
+ return [];
129
+ }
130
+ __name(getModelUniqueFields, "getModelUniqueFields");
131
+ function getRecursiveBases(dataModel, includeDelegate = true, seen = /* @__PURE__ */ new Set()) {
132
+ const result = [];
133
+ if (seen.has(dataModel)) {
134
+ return result;
135
+ }
136
+ seen.add(dataModel);
137
+ dataModel.superTypes.forEach((superType) => {
138
+ const baseDecl = superType.ref;
139
+ if (baseDecl) {
140
+ if (!includeDelegate && isDelegateModel(baseDecl)) {
141
+ return;
142
+ }
143
+ result.push(baseDecl);
144
+ result.push(...getRecursiveBases(baseDecl, includeDelegate, seen));
145
+ }
146
+ });
147
+ return result;
148
+ }
149
+ __name(getRecursiveBases, "getRecursiveBases");
150
+ function isDelegateModel(node) {
151
+ return (0, import_ast.isDataModel)(node) && hasAttribute(node, "@@delegate");
152
+ }
153
+ __name(isDelegateModel, "isDelegateModel");
154
+ function isUniqueField(field) {
155
+ if (hasAttribute(field, "@unique")) {
156
+ return true;
157
+ }
158
+ const modelIds = getAttribute(field.$container, "@@unique");
159
+ if (modelIds && modelIds.args.some((arg) => (0, import_ast.isLiteralExpr)(arg.value) && arg.value.value === field.name)) {
160
+ return true;
161
+ }
162
+ return false;
163
+ }
164
+ __name(isUniqueField, "isUniqueField");
165
+ function isFromStdlib(node) {
166
+ const model = getContainingModel(node);
167
+ return !!model && !!model.$document && model.$document.uri.path.endsWith("stdlib.zmodel");
168
+ }
169
+ __name(isFromStdlib, "isFromStdlib");
170
+ function getContainingModel(node) {
171
+ if (!node) {
172
+ return null;
173
+ }
174
+ return (0, import_ast.isModel)(node) ? node : getContainingModel(node.$container);
175
+ }
176
+ __name(getContainingModel, "getContainingModel");
177
+ function resolved(ref) {
178
+ if (!ref.ref) {
179
+ throw new Error(`Reference not resolved: ${ref.$refText}`);
180
+ }
181
+ return ref.ref;
182
+ }
183
+ __name(resolved, "resolved");
184
+ function getAuthDecl(model) {
185
+ let found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
186
+ if (!found) {
187
+ found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.name === "User");
188
+ }
189
+ return found;
190
+ }
191
+ __name(getAuthDecl, "getAuthDecl");
192
+
193
+ // src/prisma/prisma-schema-generator.ts
194
+ var import_ast2 = require("@zenstackhq/language/ast");
195
+ var import_langium = require("langium");
196
+ var import_ts_pattern = require("ts-pattern");
197
+
198
+ // src/prisma/indent-string.ts
199
+ function indentString(string, count = 4) {
200
+ const indent = " ";
201
+ return string.replace(/^(?!\s*$)/gm, indent.repeat(count));
202
+ }
203
+ __name(indentString, "indentString");
204
+
205
+ // src/prisma/prisma-builder.ts
206
+ var PrismaModel = class {
207
+ static {
208
+ __name(this, "PrismaModel");
209
+ }
210
+ datasources = [];
211
+ generators = [];
212
+ models = [];
213
+ enums = [];
214
+ addDataSource(name, fields = []) {
215
+ const ds = new DataSource(name, fields);
216
+ this.datasources.push(ds);
217
+ return ds;
218
+ }
219
+ addGenerator(name, fields) {
220
+ const generator = new Generator(name, fields);
221
+ this.generators.push(generator);
222
+ return generator;
223
+ }
224
+ addModel(name) {
225
+ const model = new Model(name, false);
226
+ this.models.push(model);
227
+ return model;
228
+ }
229
+ addView(name) {
230
+ const model = new Model(name, true);
231
+ this.models.push(model);
232
+ return model;
233
+ }
234
+ addEnum(name) {
235
+ const e = new Enum(name);
236
+ this.enums.push(e);
237
+ return e;
238
+ }
239
+ toString() {
240
+ return [
241
+ ...this.datasources,
242
+ ...this.generators,
243
+ ...this.enums,
244
+ ...this.models
245
+ ].map((d) => d.toString()).join("\n\n");
246
+ }
247
+ };
248
+ var DataSource = class {
249
+ static {
250
+ __name(this, "DataSource");
251
+ }
252
+ name;
253
+ fields;
254
+ constructor(name, fields = []) {
255
+ this.name = name;
256
+ this.fields = fields;
257
+ }
258
+ toString() {
259
+ return `datasource ${this.name} {
260
+ ` + this.fields.map((f) => indentString(`${f.name} = ${f.text}`)).join("\n") + `
261
+ }`;
262
+ }
263
+ };
264
+ var Generator = class {
265
+ static {
266
+ __name(this, "Generator");
267
+ }
268
+ name;
269
+ fields;
270
+ constructor(name, fields) {
271
+ this.name = name;
272
+ this.fields = fields;
273
+ }
274
+ toString() {
275
+ return `generator ${this.name} {
276
+ ` + this.fields.map((f) => indentString(`${f.name} = ${f.text}`)).join("\n") + `
277
+ }`;
278
+ }
279
+ };
280
+ var DeclarationBase = class {
281
+ static {
282
+ __name(this, "DeclarationBase");
283
+ }
284
+ documentations;
285
+ constructor(documentations = []) {
286
+ this.documentations = documentations;
287
+ }
288
+ addComment(name) {
289
+ this.documentations.push(name);
290
+ return name;
291
+ }
292
+ toString() {
293
+ return this.documentations.map((x) => `${x}
294
+ `).join("");
295
+ }
296
+ };
297
+ var ContainerDeclaration = class extends DeclarationBase {
298
+ static {
299
+ __name(this, "ContainerDeclaration");
300
+ }
301
+ attributes;
302
+ constructor(documentations = [], attributes = []) {
303
+ super(documentations), this.attributes = attributes;
304
+ }
305
+ };
306
+ var FieldDeclaration = class extends DeclarationBase {
307
+ static {
308
+ __name(this, "FieldDeclaration");
309
+ }
310
+ attributes;
311
+ constructor(documentations = [], attributes = []) {
312
+ super(documentations), this.attributes = attributes;
313
+ }
314
+ };
315
+ var Model = class extends ContainerDeclaration {
316
+ static {
317
+ __name(this, "Model");
318
+ }
319
+ name;
320
+ isView;
321
+ fields;
322
+ constructor(name, isView, documentations = []) {
323
+ super(documentations), this.name = name, this.isView = isView, this.fields = [];
324
+ }
325
+ addField(name, type, attributes = [], documentations = [], addToFront = false) {
326
+ const field = new ModelField(name, type, attributes, documentations);
327
+ if (addToFront) {
328
+ this.fields.unshift(field);
329
+ } else {
330
+ this.fields.push(field);
331
+ }
332
+ return field;
333
+ }
334
+ addAttribute(name, args = []) {
335
+ const attr = new ContainerAttribute(name, args);
336
+ this.attributes.push(attr);
337
+ return attr;
338
+ }
339
+ toString() {
340
+ const result = [
341
+ ...this.fields
342
+ ];
343
+ if (this.attributes.length > 0) {
344
+ result.push("");
345
+ }
346
+ result.push(...this.attributes);
347
+ return super.toString() + `${this.isView ? "view" : "model"} ${this.name} {
348
+ ` + indentString(result.map((d) => d.toString()).join("\n")) + `
349
+ }`;
350
+ }
351
+ };
352
+ var ModelFieldType = class {
353
+ static {
354
+ __name(this, "ModelFieldType");
355
+ }
356
+ type;
357
+ array;
358
+ optional;
359
+ constructor(type, array, optional) {
360
+ this.type = type;
361
+ this.array = array;
362
+ this.optional = optional;
363
+ }
364
+ toString() {
365
+ return `${this.type}${this.array ? "[]" : ""}${this.optional ? "?" : ""}`;
366
+ }
367
+ };
368
+ var ModelField = class extends FieldDeclaration {
369
+ static {
370
+ __name(this, "ModelField");
371
+ }
372
+ name;
373
+ type;
374
+ constructor(name, type, attributes = [], documentations = []) {
375
+ super(documentations, attributes), this.name = name, this.type = type;
376
+ }
377
+ addAttribute(name, args = []) {
378
+ const attr = new FieldAttribute(name, args);
379
+ this.attributes.push(attr);
380
+ return attr;
381
+ }
382
+ toString() {
383
+ return super.toString() + `${this.name} ${this.type}` + (this.attributes.length > 0 ? " " + this.attributes.map((a) => a.toString()).join(" ") : "");
384
+ }
385
+ };
386
+ var FieldAttribute = class {
387
+ static {
388
+ __name(this, "FieldAttribute");
389
+ }
390
+ name;
391
+ args;
392
+ constructor(name, args = []) {
393
+ this.name = name;
394
+ this.args = args;
395
+ }
396
+ toString() {
397
+ return `${this.name}(` + this.args.map((a) => a.toString()).join(", ") + `)`;
398
+ }
399
+ };
400
+ var ContainerAttribute = class {
401
+ static {
402
+ __name(this, "ContainerAttribute");
403
+ }
404
+ name;
405
+ args;
406
+ constructor(name, args = []) {
407
+ this.name = name;
408
+ this.args = args;
409
+ }
410
+ toString() {
411
+ return `${this.name}(` + this.args.map((a) => a.toString()).join(", ") + `)`;
412
+ }
413
+ };
414
+ var AttributeArg = class {
415
+ static {
416
+ __name(this, "AttributeArg");
417
+ }
418
+ name;
419
+ value;
420
+ constructor(name, value) {
421
+ this.name = name;
422
+ this.value = value;
423
+ }
424
+ toString() {
425
+ return this.name ? `${this.name}: ${this.value}` : this.value.toString();
426
+ }
427
+ };
428
+ var AttributeArgValue = class {
429
+ static {
430
+ __name(this, "AttributeArgValue");
431
+ }
432
+ type;
433
+ value;
434
+ constructor(type, value) {
435
+ this.type = type;
436
+ this.value = value;
437
+ switch (type) {
438
+ case "String":
439
+ if (typeof value !== "string") throw new Error("Value must be string");
440
+ break;
441
+ case "Number":
442
+ if (typeof value !== "number" && typeof value !== "string") throw new Error("Value must be number or string");
443
+ break;
444
+ case "Boolean":
445
+ if (typeof value !== "boolean") throw new Error("Value must be boolean");
446
+ break;
447
+ case "Array":
448
+ if (!Array.isArray(value)) throw new Error("Value must be array");
449
+ break;
450
+ case "FieldReference":
451
+ if (typeof value !== "string" && !(value instanceof FieldReference)) throw new Error("Value must be string or FieldReference");
452
+ break;
453
+ case "FunctionCall":
454
+ if (!(value instanceof FunctionCall)) throw new Error("Value must be FunctionCall");
455
+ break;
456
+ }
457
+ }
458
+ toString() {
459
+ switch (this.type) {
460
+ case "String":
461
+ return JSON.stringify(this.value);
462
+ case "Number":
463
+ return this.value.toString();
464
+ case "FieldReference": {
465
+ if (typeof this.value === "string") {
466
+ return this.value;
467
+ } else {
468
+ const fr = this.value;
469
+ let r = fr.field;
470
+ if (fr.args.length > 0) {
471
+ r += "(" + fr.args.map((a) => a.toString()).join(",") + ")";
472
+ }
473
+ return r;
474
+ }
475
+ }
476
+ case "FunctionCall":
477
+ return this.value.toString();
478
+ case "Boolean":
479
+ return this.value ? "true" : "false";
480
+ case "Array":
481
+ return "[" + this.value.map((v) => v.toString()).join(", ") + "]";
482
+ default:
483
+ throw new Error(`Unknown attribute value type ${this.type}`);
484
+ }
485
+ }
486
+ };
487
+ var FieldReference = class {
488
+ static {
489
+ __name(this, "FieldReference");
490
+ }
491
+ field;
492
+ args;
493
+ constructor(field, args = []) {
494
+ this.field = field;
495
+ this.args = args;
496
+ }
497
+ };
498
+ var FieldReferenceArg = class {
499
+ static {
500
+ __name(this, "FieldReferenceArg");
501
+ }
502
+ name;
503
+ value;
504
+ constructor(name, value) {
505
+ this.name = name;
506
+ this.value = value;
507
+ }
508
+ toString() {
509
+ return `${this.name}: ${this.value}`;
510
+ }
511
+ };
512
+ var FunctionCall = class {
513
+ static {
514
+ __name(this, "FunctionCall");
515
+ }
516
+ func;
517
+ args;
518
+ constructor(func, args = []) {
519
+ this.func = func;
520
+ this.args = args;
521
+ }
522
+ toString() {
523
+ return `${this.func}(` + this.args.map((a) => a.toString()).join(", ") + ")";
524
+ }
525
+ };
526
+ var FunctionCallArg = class {
527
+ static {
528
+ __name(this, "FunctionCallArg");
529
+ }
530
+ value;
531
+ constructor(value) {
532
+ this.value = value;
533
+ }
534
+ toString() {
535
+ return this.value;
536
+ }
537
+ };
538
+ var Enum = class extends ContainerDeclaration {
539
+ static {
540
+ __name(this, "Enum");
541
+ }
542
+ name;
543
+ fields;
544
+ constructor(name, documentations = []) {
545
+ super(documentations), this.name = name, this.fields = [];
546
+ }
547
+ addField(name, attributes = [], documentations = []) {
548
+ const field = new EnumField(name, attributes, documentations);
549
+ this.fields.push(field);
550
+ return field;
551
+ }
552
+ addAttribute(name, args = []) {
553
+ const attr = new ContainerAttribute(name, args);
554
+ this.attributes.push(attr);
555
+ return attr;
556
+ }
557
+ addComment(name) {
558
+ this.documentations.push(name);
559
+ return name;
560
+ }
561
+ toString() {
562
+ return super.toString() + `enum ${this.name} {
563
+ ` + indentString([
564
+ ...this.fields,
565
+ ...this.attributes
566
+ ].map((d) => d.toString()).join("\n")) + "\n}";
567
+ }
568
+ };
569
+ var EnumField = class extends DeclarationBase {
570
+ static {
571
+ __name(this, "EnumField");
572
+ }
573
+ name;
574
+ attributes;
575
+ constructor(name, attributes = [], documentations = []) {
576
+ super(documentations), this.name = name, this.attributes = attributes;
577
+ }
578
+ addAttribute(name, args = []) {
579
+ const attr = new FieldAttribute(name, args);
580
+ this.attributes.push(attr);
581
+ return attr;
582
+ }
583
+ toString() {
584
+ return super.toString() + this.name + (this.attributes.length > 0 ? " " + this.attributes.map((a) => a.toString()).join(" ") : "");
585
+ }
586
+ };
587
+
588
+ // src/prisma/prisma-schema-generator.ts
589
+ var PrismaSchemaGenerator = class {
590
+ static {
591
+ __name(this, "PrismaSchemaGenerator");
592
+ }
593
+ zmodel;
594
+ PRELUDE;
595
+ constructor(zmodel) {
596
+ this.zmodel = zmodel;
597
+ this.PRELUDE = `//////////////////////////////////////////////////////////////////////////////////////////////
598
+ // DO NOT MODIFY THIS FILE //
599
+ // This file is automatically generated by ZenStack CLI and should not be manually updated. //
600
+ //////////////////////////////////////////////////////////////////////////////////////////////
601
+
602
+ `;
603
+ }
604
+ async generate() {
605
+ const prisma = new PrismaModel();
606
+ for (const decl of this.zmodel.declarations) {
607
+ switch (decl.$type) {
608
+ case import_ast2.DataSource:
609
+ this.generateDataSource(prisma, decl);
610
+ break;
611
+ case import_ast2.Enum:
612
+ this.generateEnum(prisma, decl);
613
+ break;
614
+ case import_ast2.DataModel:
615
+ this.generateModel(prisma, decl);
616
+ break;
617
+ case import_ast2.GeneratorDecl:
618
+ this.generateGenerator(prisma, decl);
619
+ break;
620
+ }
621
+ }
622
+ return this.PRELUDE + prisma.toString();
623
+ }
624
+ generateDataSource(prisma, dataSource) {
625
+ const fields = dataSource.fields.map((f) => ({
626
+ name: f.name,
627
+ text: this.configExprToText(f.value)
628
+ }));
629
+ prisma.addDataSource(dataSource.name, fields);
630
+ }
631
+ configExprToText(expr) {
632
+ if ((0, import_ast2.isLiteralExpr)(expr)) {
633
+ return this.literalToText(expr);
634
+ } else if ((0, import_ast2.isInvocationExpr)(expr)) {
635
+ const fc = this.makeFunctionCall(expr);
636
+ return fc.toString();
637
+ } else {
638
+ return this.configArrayToText(expr);
639
+ }
640
+ }
641
+ configArrayToText(expr) {
642
+ return "[" + expr.items.map((item) => {
643
+ if ((0, import_ast2.isLiteralExpr)(item)) {
644
+ return this.literalToText(item);
645
+ } else {
646
+ return item.name + (item.args.length > 0 ? "(" + item.args.map((arg) => this.configInvocationArgToText(arg)).join(", ") + ")" : "");
647
+ }
648
+ }).join(", ") + "]";
649
+ }
650
+ configInvocationArgToText(arg) {
651
+ return `${arg.name}: ${this.literalToText(arg.value)}`;
652
+ }
653
+ literalToText(expr) {
654
+ return JSON.stringify(expr.value);
655
+ }
656
+ generateGenerator(prisma, decl) {
657
+ prisma.addGenerator(decl.name, decl.fields.map((f) => ({
658
+ name: f.name,
659
+ text: this.configExprToText(f.value)
660
+ })));
661
+ }
662
+ generateModel(prisma, decl) {
663
+ const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
664
+ for (const field of decl.fields) {
665
+ if (model_utils_exports.hasAttribute(field, "@computed")) {
666
+ continue;
667
+ }
668
+ this.generateModelField(model, field);
669
+ }
670
+ for (const attr of decl.attributes.filter((attr2) => this.isPrismaAttribute(attr2))) {
671
+ this.generateContainerAttribute(model, attr);
672
+ }
673
+ decl.comments.forEach((c) => model.addComment(c));
674
+ }
675
+ isPrismaAttribute(attr) {
676
+ if (!attr.decl.ref) {
677
+ return false;
678
+ }
679
+ return attr.decl.ref.attributes.some((a) => a.decl.ref?.name === "@@@prisma");
680
+ }
681
+ getUnsupportedFieldType(fieldType) {
682
+ if (fieldType.unsupported) {
683
+ const value = this.getStringLiteral(fieldType.unsupported.value);
684
+ if (value) {
685
+ return `Unsupported("${value}")`;
686
+ } else {
687
+ return void 0;
688
+ }
689
+ } else {
690
+ return void 0;
691
+ }
692
+ }
693
+ getStringLiteral(node) {
694
+ return (0, import_ast2.isStringLiteral)(node) ? node.value : void 0;
695
+ }
696
+ generateModelField(model, field, addToFront = false) {
697
+ let fieldType;
698
+ if (field.type.type) {
699
+ fieldType = field.type.type;
700
+ } else if (field.type.reference?.ref) {
701
+ if ((0, import_ast2.isTypeDef)(field.type.reference.ref)) {
702
+ fieldType = "Json";
703
+ } else {
704
+ fieldType = field.type.reference.ref.name;
705
+ }
706
+ } else {
707
+ const unsupported = this.getUnsupportedFieldType(field.type);
708
+ if (unsupported) {
709
+ fieldType = unsupported;
710
+ }
711
+ }
712
+ if (!fieldType) {
713
+ throw new Error(`Field type is not resolved: ${field.$container.name}.${field.name}`);
714
+ }
715
+ const isArray = (
716
+ // typed-JSON fields should be translated to scalar Json type
717
+ (0, import_ast2.isTypeDef)(field.type.reference?.ref) ? false : field.type.array
718
+ );
719
+ const type = new ModelFieldType(fieldType, isArray, field.type.optional);
720
+ const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.isDefaultWithPluginInvocation(attr)).filter((attr) => (
721
+ // when building physical schema, exclude `@default` for id fields inherited from delegate base
722
+ !(model_utils_exports.isIdField(field) && this.isInheritedFromDelegate(field) && attr.decl.$refText === "@default")
723
+ )).map((attr) => this.makeFieldAttribute(attr));
724
+ const docs = [
725
+ ...field.comments
726
+ ];
727
+ const result = model.addField(field.name, type, attributes, docs, addToFront);
728
+ return result;
729
+ }
730
+ isDefaultWithPluginInvocation(attr) {
731
+ if (attr.decl.ref?.name !== "@default") {
732
+ return false;
733
+ }
734
+ const expr = attr.args[0]?.value;
735
+ if (!expr) {
736
+ return false;
737
+ }
738
+ return import_langium.AstUtils.streamAst(expr).some((node) => (0, import_ast2.isInvocationExpr)(node) && this.isFromPlugin(node.function.ref));
739
+ }
740
+ isFromPlugin(node) {
741
+ const model = import_langium.AstUtils.getContainerOfType(node, import_ast2.isModel);
742
+ return !!model && !!model.$document && model.$document.uri.path.endsWith("plugin.zmodel");
743
+ }
744
+ setDummyDefault(result, field) {
745
+ const dummyDefaultValue = (0, import_ts_pattern.match)(field.type.type).with("String", () => new AttributeArgValue("String", "")).with(import_ts_pattern.P.union("Int", "BigInt", "Float", "Decimal"), () => new AttributeArgValue("Number", "0")).with("Boolean", () => new AttributeArgValue("Boolean", "false")).with("DateTime", () => new AttributeArgValue("FunctionCall", new FunctionCall("now"))).with("Json", () => new AttributeArgValue("String", "{}")).with("Bytes", () => new AttributeArgValue("String", "")).otherwise(() => {
746
+ throw new Error(`Unsupported field type with default value: ${field.type.type}`);
747
+ });
748
+ result.attributes.push(new FieldAttribute("@default", [
749
+ new AttributeArg(void 0, dummyDefaultValue)
750
+ ]));
751
+ }
752
+ isInheritedFromDelegate(field) {
753
+ return field.$inheritedFrom && model_utils_exports.isDelegateModel(field.$inheritedFrom);
754
+ }
755
+ makeFieldAttribute(attr) {
756
+ const attrName = attr.decl.ref.name;
757
+ return new FieldAttribute(attrName, attr.args.map((arg) => this.makeAttributeArg(arg)));
758
+ }
759
+ makeAttributeArg(arg) {
760
+ return new AttributeArg(arg.name, this.makeAttributeArgValue(arg.value));
761
+ }
762
+ makeAttributeArgValue(node) {
763
+ if ((0, import_ast2.isLiteralExpr)(node)) {
764
+ 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();
765
+ return new AttributeArgValue(argType, node.value);
766
+ } else if ((0, import_ast2.isArrayExpr)(node)) {
767
+ return new AttributeArgValue("Array", new Array(...node.items.map((item) => this.makeAttributeArgValue(item))));
768
+ } else if ((0, import_ast2.isReferenceExpr)(node)) {
769
+ return new AttributeArgValue("FieldReference", new FieldReference(node.target.ref.name, node.args.map((arg) => new FieldReferenceArg(arg.name, this.exprToText(arg.value)))));
770
+ } else if ((0, import_ast2.isInvocationExpr)(node)) {
771
+ return new AttributeArgValue("FunctionCall", this.makeFunctionCall(node));
772
+ } else {
773
+ throw Error(`Unsupported attribute argument expression type: ${node.$type}`);
774
+ }
775
+ }
776
+ exprToText(expr) {
777
+ return new ZModelCodeGenerator({
778
+ quote: "double"
779
+ }).generate(expr);
780
+ }
781
+ makeFunctionCall(node) {
782
+ return new FunctionCall(node.function.ref.name, node.args.map((arg) => {
783
+ 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(() => {
784
+ throw new Error("Function call argument must be literal or null");
785
+ });
786
+ return new FunctionCallArg(val);
787
+ }));
788
+ }
789
+ generateContainerAttribute(container, attr) {
790
+ const attrName = attr.decl.ref.name;
791
+ container.attributes.push(new ContainerAttribute(attrName, attr.args.map((arg) => this.makeAttributeArg(arg))));
792
+ }
793
+ generateEnum(prisma, decl) {
794
+ const _enum = prisma.addEnum(decl.name);
795
+ for (const field of decl.fields) {
796
+ this.generateEnumField(_enum, field);
797
+ }
798
+ for (const attr of decl.attributes.filter((attr2) => this.isPrismaAttribute(attr2))) {
799
+ this.generateContainerAttribute(_enum, attr);
800
+ }
801
+ decl.comments.forEach((c) => _enum.addComment(c));
802
+ }
803
+ generateEnumField(_enum, field) {
804
+ const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).map((attr) => this.makeFieldAttribute(attr));
805
+ const docs = [
806
+ ...field.comments
807
+ ];
808
+ _enum.addField(field.name, attributes, docs);
809
+ }
810
+ };
811
+
812
+ // src/ts-schema-generator.ts
813
+ var import_language = require("@zenstackhq/language");
814
+ var import_ast3 = require("@zenstackhq/language/ast");
815
+ var import_node_fs = __toESM(require("fs"), 1);
816
+ var import_node_path = __toESM(require("path"), 1);
817
+ var import_tiny_invariant = __toESM(require("tiny-invariant"), 1);
818
+ var import_ts_pattern2 = require("ts-pattern");
819
+ var ts = __toESM(require("typescript"), 1);
820
+ var TsSchemaGenerator = class {
821
+ static {
822
+ __name(this, "TsSchemaGenerator");
823
+ }
824
+ async generate(schemaFile, pluginModelFiles, outputFile) {
825
+ const loaded = await (0, import_language.loadDocument)(schemaFile, pluginModelFiles);
826
+ if (!loaded.success) {
827
+ throw new Error(`Error loading schema:${loaded.errors.join("\n")}`);
828
+ }
829
+ const { model, warnings } = loaded;
830
+ const statements = [];
831
+ this.generateSchemaStatements(model, statements);
832
+ this.generateBannerComments(statements);
833
+ const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
834
+ const printer = ts.createPrinter();
835
+ const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
836
+ import_node_fs.default.mkdirSync(import_node_path.default.dirname(outputFile), {
837
+ recursive: true
838
+ });
839
+ import_node_fs.default.writeFileSync(outputFile, result);
840
+ return {
841
+ model,
842
+ warnings
843
+ };
844
+ }
845
+ generateSchemaStatements(model, statements) {
846
+ const hasComputedFields = model.declarations.some((d) => (0, import_ast3.isDataModel)(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
847
+ const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
848
+ ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
849
+ ...hasComputedFields ? [
850
+ ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
851
+ ] : [],
852
+ ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
853
+ ])), ts.factory.createStringLiteral("@zenstackhq/runtime/schema"));
854
+ statements.push(runtimeImportDecl);
855
+ const { type: providerType } = this.getDataSourceProvider(model);
856
+ switch (providerType) {
857
+ case "sqlite": {
858
+ const pathImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, ts.factory.createIdentifier("path"), void 0), ts.factory.createStringLiteral("node:path"));
859
+ statements.push(pathImportDecl);
860
+ const urlImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, ts.factory.createIdentifier("url"), void 0), ts.factory.createStringLiteral("node:url"));
861
+ statements.push(urlImportDecl);
862
+ const dialectConfigImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
863
+ ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("toDialectConfig"))
864
+ ])), ts.factory.createStringLiteral("@zenstackhq/runtime/utils/sqlite-utils"));
865
+ statements.push(dialectConfigImportDecl);
866
+ break;
867
+ }
868
+ case "postgresql": {
869
+ const dialectConfigImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
870
+ ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("toDialectConfig"))
871
+ ])), ts.factory.createStringLiteral("@zenstackhq/runtime/utils/pg-utils"));
872
+ statements.push(dialectConfigImportDecl);
873
+ break;
874
+ }
875
+ }
876
+ const declaration = ts.factory.createVariableStatement([
877
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
878
+ ], ts.factory.createVariableDeclarationList([
879
+ ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(this.createSchemaObject(model), ts.factory.createTypeReferenceNode("const")), ts.factory.createTypeReferenceNode("SchemaDef")))
880
+ ], ts.NodeFlags.Const));
881
+ statements.push(declaration);
882
+ const typeDeclaration = ts.factory.createTypeAliasDeclaration([
883
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
884
+ ], "SchemaType", void 0, ts.factory.createTypeReferenceNode("typeof schema"));
885
+ statements.push(typeDeclaration);
886
+ }
887
+ createSchemaObject(model) {
888
+ const properties = [
889
+ // provider
890
+ ts.factory.createPropertyAssignment("provider", this.createProviderObject(model)),
891
+ // models
892
+ ts.factory.createPropertyAssignment("models", this.createModelsObject(model))
893
+ ];
894
+ const enums = model.declarations.filter(import_ast3.isEnum);
895
+ if (enums.length > 0) {
896
+ properties.push(ts.factory.createPropertyAssignment("enums", ts.factory.createObjectLiteralExpression(enums.map((e) => ts.factory.createPropertyAssignment(e.name, this.createEnumObject(e))), true)));
897
+ }
898
+ const authType = getAuthDecl(model);
899
+ if (authType) {
900
+ properties.push(ts.factory.createPropertyAssignment("authType", this.createLiteralNode(authType.name)));
901
+ }
902
+ const procedures = model.declarations.filter(import_ast3.isProcedure);
903
+ if (procedures.length > 0) {
904
+ properties.push(ts.factory.createPropertyAssignment("procedures", this.createProceduresObject(procedures)));
905
+ }
906
+ properties.push(ts.factory.createPropertyAssignment("plugins", ts.factory.createObjectLiteralExpression([], true)));
907
+ return ts.factory.createObjectLiteralExpression(properties, true);
908
+ }
909
+ createProviderObject(model) {
910
+ const dsProvider = this.getDataSourceProvider(model);
911
+ return ts.factory.createObjectLiteralExpression([
912
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider.type)),
913
+ ts.factory.createPropertyAssignment("dialectConfigProvider", this.createDialectConfigProvider(dsProvider))
914
+ ], true);
915
+ }
916
+ createModelsObject(model) {
917
+ return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => (0, import_ast3.isDataModel)(d) && !hasAttribute(d, "@@ignore")).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm))), true);
918
+ }
919
+ createDataModelObject(dm) {
920
+ const fields = [
921
+ // fields
922
+ ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(dm.fields.filter((field) => !hasAttribute(field, "@ignore")).map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataModelFieldObject(field))), true)),
923
+ // attributes
924
+ ...dm.attributes.length > 0 ? [
925
+ ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(dm.attributes.map((attr) => this.createAttributeObject(attr)), true))
926
+ ] : [],
927
+ // idFields
928
+ ts.factory.createPropertyAssignment("idFields", ts.factory.createArrayLiteralExpression(this.getIdFields(dm).map((idField) => ts.factory.createStringLiteral(idField)))),
929
+ // uniqueFields
930
+ ts.factory.createPropertyAssignment("uniqueFields", this.createUniqueFieldsObject(dm))
931
+ ];
932
+ const computedFields = dm.fields.filter((f) => hasAttribute(f, "@computed"));
933
+ if (computedFields.length > 0) {
934
+ fields.push(ts.factory.createPropertyAssignment("computedFields", this.createComputedFieldsObject(computedFields)));
935
+ }
936
+ return ts.factory.createObjectLiteralExpression(fields, true);
937
+ }
938
+ createComputedFieldsObject(fields) {
939
+ return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [], ts.factory.createTypeReferenceNode("OperandExpression", [
940
+ ts.factory.createKeywordTypeNode(this.mapTypeToTSSyntaxKeyword(field.type.type))
941
+ ]), ts.factory.createBlock([
942
+ ts.factory.createThrowStatement(ts.factory.createNewExpression(ts.factory.createIdentifier("Error"), void 0, [
943
+ ts.factory.createStringLiteral("This is a stub for computed field")
944
+ ]))
945
+ ], true))), true);
946
+ }
947
+ mapTypeToTSSyntaxKeyword(type) {
948
+ return (0, import_ts_pattern2.match)(type).with("String", () => ts.SyntaxKind.StringKeyword).with("Boolean", () => ts.SyntaxKind.BooleanKeyword).with("Int", () => ts.SyntaxKind.NumberKeyword).with("Float", () => ts.SyntaxKind.NumberKeyword).with("BigInt", () => ts.SyntaxKind.BigIntKeyword).with("Decimal", () => ts.SyntaxKind.NumberKeyword).otherwise(() => ts.SyntaxKind.UnknownKeyword);
949
+ }
950
+ createDataModelFieldObject(field) {
951
+ const objectFields = [
952
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(field.type.type ?? field.type.reference.$refText))
953
+ ];
954
+ if (isIdField(field)) {
955
+ objectFields.push(ts.factory.createPropertyAssignment("id", ts.factory.createTrue()));
956
+ }
957
+ if (isUniqueField(field)) {
958
+ objectFields.push(ts.factory.createPropertyAssignment("unique", ts.factory.createTrue()));
959
+ }
960
+ if (field.type.optional) {
961
+ objectFields.push(ts.factory.createPropertyAssignment("optional", ts.factory.createTrue()));
962
+ }
963
+ if (field.type.array) {
964
+ objectFields.push(ts.factory.createPropertyAssignment("array", ts.factory.createTrue()));
965
+ }
966
+ if (hasAttribute(field, "@updatedAt")) {
967
+ objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
968
+ }
969
+ if (field.attributes.length > 0) {
970
+ objectFields.push(ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr)))));
971
+ }
972
+ const defaultValue = this.getMappedDefault(field);
973
+ if (defaultValue !== void 0) {
974
+ if (typeof defaultValue === "object") {
975
+ if ("call" in defaultValue) {
976
+ objectFields.push(ts.factory.createPropertyAssignment("default", ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.call"), void 0, [
977
+ ts.factory.createStringLiteral(defaultValue.call),
978
+ ...defaultValue.args.length > 0 ? [
979
+ ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createLiteralNode(arg)))
980
+ ] : []
981
+ ])));
982
+ } else if ("authMember" in defaultValue) {
983
+ objectFields.push(ts.factory.createPropertyAssignment("default", ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.member"), void 0, [
984
+ ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.call"), void 0, [
985
+ ts.factory.createStringLiteral("auth")
986
+ ]),
987
+ ts.factory.createArrayLiteralExpression(defaultValue.authMember.map((m) => ts.factory.createStringLiteral(m)))
988
+ ])));
989
+ } else {
990
+ throw new Error(`Unsupported default value type for field ${field.name}`);
991
+ }
992
+ } else {
993
+ objectFields.push(ts.factory.createPropertyAssignment("default", typeof defaultValue === "string" ? ts.factory.createStringLiteral(defaultValue) : typeof defaultValue === "number" ? ts.factory.createNumericLiteral(defaultValue) : defaultValue === true ? ts.factory.createTrue() : ts.factory.createFalse()));
994
+ }
995
+ }
996
+ if (hasAttribute(field, "@computed")) {
997
+ objectFields.push(ts.factory.createPropertyAssignment("computed", ts.factory.createTrue()));
998
+ }
999
+ if ((0, import_ast3.isDataModel)(field.type.reference?.ref)) {
1000
+ objectFields.push(ts.factory.createPropertyAssignment("relation", this.createRelationObject(field)));
1001
+ }
1002
+ const fkFor = this.getForeignKeyFor(field);
1003
+ if (fkFor && fkFor.length > 0) {
1004
+ objectFields.push(ts.factory.createPropertyAssignment("foreignKeyFor", ts.factory.createArrayLiteralExpression(fkFor.map((fk) => ts.factory.createStringLiteral(fk)), true)));
1005
+ }
1006
+ return ts.factory.createObjectLiteralExpression(objectFields, true);
1007
+ }
1008
+ getDataSourceProvider(model) {
1009
+ const dataSource = model.declarations.find(import_ast3.isDataSource);
1010
+ (0, import_tiny_invariant.default)(dataSource, "No data source found in the model");
1011
+ const providerExpr = dataSource.fields.find((f) => f.name === "provider")?.value;
1012
+ (0, import_tiny_invariant.default)((0, import_ast3.isLiteralExpr)(providerExpr), "Provider must be a literal");
1013
+ const type = providerExpr.value;
1014
+ const urlExpr = dataSource.fields.find((f) => f.name === "url")?.value;
1015
+ (0, import_tiny_invariant.default)((0, import_ast3.isLiteralExpr)(urlExpr) || (0, import_ast3.isInvocationExpr)(urlExpr), "URL must be a literal or env function");
1016
+ if ((0, import_ast3.isLiteralExpr)(urlExpr)) {
1017
+ return {
1018
+ type,
1019
+ url: urlExpr.value,
1020
+ env: void 0
1021
+ };
1022
+ } else if ((0, import_ast3.isInvocationExpr)(urlExpr)) {
1023
+ (0, import_tiny_invariant.default)(urlExpr.function.$refText === "env", 'only "env" function is supported');
1024
+ (0, import_tiny_invariant.default)(urlExpr.args.length === 1, "env function must have one argument");
1025
+ return {
1026
+ type,
1027
+ env: urlExpr.args[0].value.value,
1028
+ url: void 0
1029
+ };
1030
+ } else {
1031
+ throw new Error("Unsupported URL type");
1032
+ }
1033
+ }
1034
+ getMappedDefault(field) {
1035
+ const defaultAttr = getAttribute(field, "@default");
1036
+ if (!defaultAttr) {
1037
+ return void 0;
1038
+ }
1039
+ const defaultValue = defaultAttr.args[0]?.value;
1040
+ (0, import_tiny_invariant.default)(defaultValue, "Expected a default value");
1041
+ if ((0, import_ast3.isLiteralExpr)(defaultValue)) {
1042
+ const lit = defaultValue.value;
1043
+ return field.type.type === "Boolean" ? lit : [
1044
+ "Int",
1045
+ "Float",
1046
+ "Decimal",
1047
+ "BigInt"
1048
+ ].includes(field.type.type) ? Number(lit) : lit;
1049
+ } else if ((0, import_ast3.isReferenceExpr)(defaultValue) && (0, import_ast3.isEnumField)(defaultValue.target.ref)) {
1050
+ return defaultValue.target.ref.name;
1051
+ } else if ((0, import_ast3.isInvocationExpr)(defaultValue)) {
1052
+ return {
1053
+ call: defaultValue.function.$refText,
1054
+ args: defaultValue.args.map((arg) => this.getLiteral(arg.value))
1055
+ };
1056
+ } else if (this.isAuthMemberAccess(defaultValue)) {
1057
+ return {
1058
+ authMember: this.getMemberAccessChain(defaultValue)
1059
+ };
1060
+ } else {
1061
+ throw new Error(`Unsupported default value type for field ${field.name}`);
1062
+ }
1063
+ }
1064
+ getMemberAccessChain(expr) {
1065
+ if (!(0, import_ast3.isMemberAccessExpr)(expr.operand)) {
1066
+ return [
1067
+ expr.member.$refText
1068
+ ];
1069
+ } else {
1070
+ return [
1071
+ ...this.getMemberAccessChain(expr.operand),
1072
+ expr.member.$refText
1073
+ ];
1074
+ }
1075
+ }
1076
+ isAuthMemberAccess(expr) {
1077
+ if ((0, import_ast3.isMemberAccessExpr)(expr)) {
1078
+ return this.isAuthInvocation(expr.operand) || this.isAuthMemberAccess(expr.operand);
1079
+ } else {
1080
+ return false;
1081
+ }
1082
+ }
1083
+ isAuthInvocation(expr) {
1084
+ return (0, import_ast3.isInvocationExpr)(expr) && expr.function.$refText === "auth" && model_utils_exports.isFromStdlib(expr.function.ref);
1085
+ }
1086
+ createRelationObject(field) {
1087
+ const relationFields = [];
1088
+ const oppositeRelation = this.getOppositeRelationField(field);
1089
+ if (oppositeRelation) {
1090
+ relationFields.push(ts.factory.createPropertyAssignment("opposite", ts.factory.createStringLiteral(oppositeRelation.name)));
1091
+ }
1092
+ const relationName = this.getRelationName(field);
1093
+ if (relationName) {
1094
+ relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
1095
+ }
1096
+ const relation = getAttribute(field, "@relation");
1097
+ if (relation) {
1098
+ for (const arg of relation.args) {
1099
+ const param = arg.$resolvedParam.name;
1100
+ if (param === "fields" || param === "references") {
1101
+ const fieldNames = this.getReferenceNames(arg.value);
1102
+ if (fieldNames) {
1103
+ relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
1104
+ }
1105
+ }
1106
+ if (param === "onDelete" || param === "onUpdate") {
1107
+ const action = arg.value.target.$refText;
1108
+ relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createStringLiteral(action)));
1109
+ }
1110
+ }
1111
+ }
1112
+ return ts.factory.createObjectLiteralExpression(relationFields);
1113
+ }
1114
+ getReferenceNames(expr) {
1115
+ return (0, import_ast3.isArrayExpr)(expr) && expr.items.map((item) => item.target.$refText);
1116
+ }
1117
+ getForeignKeyFor(field) {
1118
+ const result = [];
1119
+ for (const f of field.$container.fields) {
1120
+ const relation = getAttribute(f, "@relation");
1121
+ if (relation) {
1122
+ for (const arg of relation.args) {
1123
+ if (arg.name === "fields" && (0, import_ast3.isArrayExpr)(arg.value) && arg.value.items.some((el) => (0, import_ast3.isReferenceExpr)(el) && el.target.ref === field)) {
1124
+ result.push(f.name);
1125
+ }
1126
+ }
1127
+ }
1128
+ }
1129
+ return result;
1130
+ }
1131
+ getOppositeRelationField(field) {
1132
+ if (!field.type.reference?.ref || !(0, import_ast3.isDataModel)(field.type.reference?.ref)) {
1133
+ return void 0;
1134
+ }
1135
+ const sourceModel = field.$container;
1136
+ const targetModel = field.type.reference.ref;
1137
+ const relationName = this.getRelationName(field);
1138
+ for (const otherField of targetModel.fields) {
1139
+ if (otherField === field) {
1140
+ continue;
1141
+ }
1142
+ if (otherField.type.reference?.ref === sourceModel) {
1143
+ if (relationName) {
1144
+ const otherRelationName = this.getRelationName(otherField);
1145
+ if (otherRelationName === relationName) {
1146
+ return otherField;
1147
+ }
1148
+ } else {
1149
+ return otherField;
1150
+ }
1151
+ }
1152
+ }
1153
+ return void 0;
1154
+ }
1155
+ getRelationName(field) {
1156
+ const relation = getAttribute(field, "@relation");
1157
+ if (relation) {
1158
+ const nameArg = relation.args.find((arg) => arg.$resolvedParam.name === "name");
1159
+ if (nameArg) {
1160
+ (0, import_tiny_invariant.default)((0, import_ast3.isLiteralExpr)(nameArg.value), "name must be a literal");
1161
+ return nameArg.value.value;
1162
+ }
1163
+ }
1164
+ return void 0;
1165
+ }
1166
+ getIdFields(dm) {
1167
+ return dm.fields.filter(isIdField).map((f) => f.name);
1168
+ }
1169
+ createUniqueFieldsObject(dm) {
1170
+ const properties = [];
1171
+ for (const field of dm.fields) {
1172
+ if (hasAttribute(field, "@id") || hasAttribute(field, "@unique")) {
1173
+ properties.push(ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([
1174
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(field.type.type))
1175
+ ])));
1176
+ }
1177
+ }
1178
+ for (const attr of dm.attributes) {
1179
+ if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
1180
+ const fieldNames = this.getReferenceNames(attr.args[0].value);
1181
+ if (!fieldNames) {
1182
+ continue;
1183
+ }
1184
+ if (fieldNames.length === 1) {
1185
+ const fieldDef = dm.fields.find((f) => f.name === fieldNames[0]);
1186
+ properties.push(ts.factory.createPropertyAssignment(fieldNames[0], ts.factory.createObjectLiteralExpression([
1187
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(fieldDef.type.type))
1188
+ ])));
1189
+ } else {
1190
+ properties.push(ts.factory.createPropertyAssignment(fieldNames.join("_"), ts.factory.createObjectLiteralExpression(fieldNames.map((field) => {
1191
+ const fieldDef = dm.fields.find((f) => f.name === field);
1192
+ return ts.factory.createPropertyAssignment(field, ts.factory.createObjectLiteralExpression([
1193
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(fieldDef.type.type))
1194
+ ]));
1195
+ }))));
1196
+ }
1197
+ }
1198
+ }
1199
+ return ts.factory.createObjectLiteralExpression(properties, true);
1200
+ }
1201
+ createEnumObject(e) {
1202
+ return ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createStringLiteral(field.name))), true);
1203
+ }
1204
+ getLiteral(expr) {
1205
+ if (!(0, import_ast3.isLiteralExpr)(expr)) {
1206
+ throw new Error("Expected a literal expression");
1207
+ }
1208
+ switch (expr?.$type) {
1209
+ case "StringLiteral":
1210
+ case "BooleanLiteral":
1211
+ return expr.value;
1212
+ case "NumberLiteral":
1213
+ return parseFloat(expr.value);
1214
+ default:
1215
+ throw new Error("Unsupported literal type");
1216
+ }
1217
+ }
1218
+ createLiteralNode(arg) {
1219
+ return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ? ts.factory.createNumericLiteral(arg) : arg === true ? ts.factory.createTrue() : arg === false ? ts.factory.createFalse() : void 0;
1220
+ }
1221
+ createDialectConfigProvider(dsProvider) {
1222
+ const type = dsProvider.type;
1223
+ let urlExpr;
1224
+ if (dsProvider.env !== void 0) {
1225
+ urlExpr = ts.factory.createIdentifier(`process.env['${dsProvider.env}']`);
1226
+ } else {
1227
+ urlExpr = ts.factory.createStringLiteral(dsProvider.url);
1228
+ if (type === "sqlite") {
1229
+ let parsedUrl;
1230
+ try {
1231
+ parsedUrl = new URL(dsProvider.url);
1232
+ } catch {
1233
+ }
1234
+ if (parsedUrl) {
1235
+ if (parsedUrl.protocol !== "file:") {
1236
+ throw new Error("Invalid SQLite URL: only file protocol is supported");
1237
+ }
1238
+ urlExpr = ts.factory.createStringLiteral(dsProvider.url.replace(/^file:/, ""));
1239
+ }
1240
+ }
1241
+ }
1242
+ return (0, import_ts_pattern2.match)(type).with("sqlite", () => {
1243
+ return ts.factory.createFunctionExpression(void 0, void 0, void 0, void 0, void 0, void 0, ts.factory.createBlock([
1244
+ ts.factory.createReturnStatement(ts.factory.createCallExpression(ts.factory.createIdentifier("toDialectConfig"), void 0, [
1245
+ urlExpr,
1246
+ ts.factory.createIdentifier(`typeof __dirname !== 'undefined' ? __dirname : path.dirname(url.fileURLToPath(import.meta.url))`)
1247
+ ]))
1248
+ ], true));
1249
+ }).with("postgresql", () => {
1250
+ return ts.factory.createFunctionExpression(void 0, void 0, void 0, void 0, void 0, void 0, ts.factory.createBlock([
1251
+ ts.factory.createReturnStatement(ts.factory.createCallExpression(ts.factory.createIdentifier("toDialectConfig"), void 0, [
1252
+ urlExpr
1253
+ ]))
1254
+ ], true));
1255
+ }).otherwise(() => {
1256
+ throw new Error(`Unsupported provider: ${type}`);
1257
+ });
1258
+ }
1259
+ createProceduresObject(procedures) {
1260
+ return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
1261
+ }
1262
+ createProcedureObject(proc) {
1263
+ const params = ts.factory.createArrayLiteralExpression(proc.params.map((param) => ts.factory.createObjectLiteralExpression([
1264
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(param.name)),
1265
+ ...param.optional ? [
1266
+ ts.factory.createPropertyAssignment("optional", ts.factory.createTrue())
1267
+ ] : [],
1268
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(param.type.type ?? param.type.reference.$refText))
1269
+ ])), true);
1270
+ const paramsType = ts.factory.createTupleTypeNode([
1271
+ ...proc.params.map((param) => ts.factory.createNamedTupleMember(void 0, ts.factory.createIdentifier(param.name), void 0, ts.factory.createTypeLiteralNode([
1272
+ ts.factory.createPropertySignature(void 0, ts.factory.createStringLiteral("name"), void 0, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(param.name))),
1273
+ ts.factory.createPropertySignature(void 0, ts.factory.createStringLiteral("type"), void 0, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(param.type.type ?? param.type.reference.$refText))),
1274
+ ...param.optional ? [
1275
+ ts.factory.createPropertySignature(void 0, ts.factory.createStringLiteral("optional"), void 0, ts.factory.createLiteralTypeNode(ts.factory.createTrue()))
1276
+ ] : []
1277
+ ])))
1278
+ ]);
1279
+ return ts.factory.createObjectLiteralExpression([
1280
+ ts.factory.createPropertyAssignment("params", ts.factory.createAsExpression(params, paramsType)),
1281
+ ts.factory.createPropertyAssignment("returnType", ts.factory.createStringLiteral(proc.returnType.type ?? proc.returnType.reference.$refText)),
1282
+ ...proc.mutation ? [
1283
+ ts.factory.createPropertyAssignment("mutation", ts.factory.createTrue())
1284
+ ] : []
1285
+ ], true);
1286
+ }
1287
+ generateBannerComments(statements) {
1288
+ const banner = `////////////////////////////////////////////////////////////////////////////////////////////
1289
+ // DO NOT MODIFY THIS FILE //
1290
+ // This file is automatically generated by ZenStack CLI and should not be manually updated. //
1291
+ //////////////////////////////////////////////////////////////////////////////////////////////
1292
+
1293
+ `;
1294
+ ts.addSyntheticLeadingComment(statements[0], ts.SyntaxKind.SingleLineCommentTrivia, banner);
1295
+ }
1296
+ createAttributeObject(attr) {
1297
+ return ts.factory.createObjectLiteralExpression([
1298
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(attr.decl.$refText)),
1299
+ ...attr.args.length > 0 ? [
1300
+ ts.factory.createPropertyAssignment("args", ts.factory.createArrayLiteralExpression(attr.args.map((arg) => this.createAttributeArg(arg))))
1301
+ ] : []
1302
+ ]);
1303
+ }
1304
+ createAttributeArg(arg) {
1305
+ return ts.factory.createObjectLiteralExpression([
1306
+ // name
1307
+ ...arg.$resolvedParam?.name ? [
1308
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(arg.$resolvedParam.name))
1309
+ ] : [],
1310
+ // value
1311
+ ts.factory.createPropertyAssignment("value", this.createExpression(arg.value))
1312
+ ]);
1313
+ }
1314
+ createExpression(value) {
1315
+ 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(() => {
1316
+ throw new Error(`Unsupported attribute arg value: ${value.$type}`);
1317
+ });
1318
+ }
1319
+ createThisExpression() {
1320
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils._this"), void 0, []);
1321
+ }
1322
+ createMemberExpression(expr) {
1323
+ const members = [];
1324
+ let current = expr;
1325
+ while ((0, import_ast3.isMemberAccessExpr)(current)) {
1326
+ members.unshift(current.member.$refText);
1327
+ current = current.operand;
1328
+ }
1329
+ const receiver = current;
1330
+ const args = [
1331
+ this.createExpression(receiver),
1332
+ ts.factory.createArrayLiteralExpression(members.map((m) => ts.factory.createStringLiteral(m)))
1333
+ ];
1334
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.member"), void 0, args);
1335
+ }
1336
+ createNullExpression() {
1337
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils._null"), void 0, []);
1338
+ }
1339
+ createBinaryExpression(expr) {
1340
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.binary"), void 0, [
1341
+ this.createExpression(expr.left),
1342
+ this.createLiteralNode(expr.operator),
1343
+ this.createExpression(expr.right)
1344
+ ]);
1345
+ }
1346
+ createUnaryExpression(expr) {
1347
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.unary"), void 0, [
1348
+ this.createLiteralNode(expr.operator),
1349
+ this.createExpression(expr.operand)
1350
+ ]);
1351
+ }
1352
+ createArrayExpression(expr) {
1353
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.array"), void 0, [
1354
+ ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))
1355
+ ]);
1356
+ }
1357
+ createRefExpression(expr) {
1358
+ if ((0, import_ast3.isDataModelField)(expr.target.ref)) {
1359
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.field"), void 0, [
1360
+ this.createLiteralNode(expr.target.$refText)
1361
+ ]);
1362
+ } else if ((0, import_ast3.isEnumField)(expr.target.ref)) {
1363
+ return this.createLiteralExpression("StringLiteral", expr.target.$refText);
1364
+ } else {
1365
+ throw new Error(`Unsupported reference type: ${expr.target.$refText}`);
1366
+ }
1367
+ }
1368
+ createCallExpression(expr) {
1369
+ return ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.call"), void 0, [
1370
+ ts.factory.createStringLiteral(expr.function.$refText),
1371
+ ...expr.args.length > 0 ? [
1372
+ ts.factory.createArrayLiteralExpression(expr.args.map((arg) => this.createExpression(arg.value)))
1373
+ ] : []
1374
+ ]);
1375
+ }
1376
+ createLiteralExpression(type, value) {
1377
+ return (0, import_ts_pattern2.match)(type).with("BooleanLiteral", () => ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.literal"), void 0, [
1378
+ this.createLiteralNode(value)
1379
+ ])).with("NumberLiteral", () => ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.literal"), void 0, [
1380
+ ts.factory.createIdentifier(value)
1381
+ ])).with("StringLiteral", () => ts.factory.createCallExpression(ts.factory.createIdentifier("ExpressionUtils.literal"), void 0, [
1382
+ this.createLiteralNode(value)
1383
+ ])).otherwise(() => {
1384
+ throw new Error(`Unsupported literal type: ${type}`);
1385
+ });
1386
+ }
1387
+ };
1388
+
1389
+ // src/zmodel-code-generator.ts
1390
+ var import_ast4 = require("@zenstackhq/language/ast");
1391
+ function _ts_decorate(decorators, target, key, desc) {
1392
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1393
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1394
+ 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;
1395
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1396
+ }
1397
+ __name(_ts_decorate, "_ts_decorate");
1398
+ function _ts_metadata(k, v) {
1399
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1400
+ }
1401
+ __name(_ts_metadata, "_ts_metadata");
1402
+ var generationHandlers = /* @__PURE__ */ new Map();
1403
+ function gen(name) {
1404
+ return function(_target, _propertyKey, descriptor) {
1405
+ if (!generationHandlers.get(name)) {
1406
+ generationHandlers.set(name, descriptor);
1407
+ }
1408
+ return descriptor;
1409
+ };
1410
+ }
1411
+ __name(gen, "gen");
1412
+ var ZModelCodeGenerator = class {
1413
+ static {
1414
+ __name(this, "ZModelCodeGenerator");
1415
+ }
1416
+ options;
1417
+ constructor(options) {
1418
+ this.options = {
1419
+ binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
1420
+ unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
1421
+ indent: options?.indent ?? 4,
1422
+ quote: options?.quote ?? "single"
1423
+ };
1424
+ }
1425
+ /**
1426
+ * Generates ZModel source code from AST.
1427
+ */
1428
+ generate(ast) {
1429
+ const handler = generationHandlers.get(ast.$type);
1430
+ if (!handler) {
1431
+ throw new Error(`No generation handler found for ${ast.$type}`);
1432
+ }
1433
+ return handler.value.call(this, ast);
1434
+ }
1435
+ _generateModel(ast) {
1436
+ return ast.declarations.map((d) => this.generate(d)).join("\n\n");
1437
+ }
1438
+ _generateDataSource(ast) {
1439
+ return `datasource ${ast.name} {
1440
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
1441
+ }`;
1442
+ }
1443
+ _generateEnum(ast) {
1444
+ return `enum ${ast.name} {
1445
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
1446
+ }`;
1447
+ }
1448
+ _generateEnumField(ast) {
1449
+ return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
1450
+ }
1451
+ _generateGenerator(ast) {
1452
+ return `generator ${ast.name} {
1453
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
1454
+ }`;
1455
+ }
1456
+ _generateConfigField(ast) {
1457
+ return `${ast.name} = ${this.generate(ast.value)}`;
1458
+ }
1459
+ _generateConfigArrayExpr(ast) {
1460
+ return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
1461
+ }
1462
+ _generateConfigInvocationExpr(ast) {
1463
+ if (ast.args.length === 0) {
1464
+ return ast.name;
1465
+ } else {
1466
+ return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
1467
+ }
1468
+ }
1469
+ _generatePlugin(ast) {
1470
+ return `plugin ${ast.name} {
1471
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
1472
+ }`;
1473
+ }
1474
+ _generatePluginField(ast) {
1475
+ return `${ast.name} = ${this.generate(ast.value)}`;
1476
+ }
1477
+ _generateDataModel(ast) {
1478
+ return `${ast.isAbstract ? "abstract " : ""}${ast.isView ? "view" : "model"} ${ast.name}${ast.superTypes.length > 0 ? " extends " + ast.superTypes.map((x) => x.ref?.name).join(", ") : ""} {
1479
+ ${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") : ""}
1480
+ }`;
1481
+ }
1482
+ _generateDataModelField(ast) {
1483
+ return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
1484
+ }
1485
+ fieldType(type) {
1486
+ const baseType = type.type ? type.type : type.$type == "DataModelFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
1487
+ return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
1488
+ }
1489
+ _generateDataModelAttribute(ast) {
1490
+ return this.attribute(ast);
1491
+ }
1492
+ _generateDataModelFieldAttribute(ast) {
1493
+ return this.attribute(ast);
1494
+ }
1495
+ attribute(ast) {
1496
+ const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
1497
+ return `${resolved(ast.decl).name}${args}`;
1498
+ }
1499
+ _generateAttributeArg(ast) {
1500
+ if (ast.name) {
1501
+ return `${ast.name}: ${this.generate(ast.value)}`;
1502
+ } else {
1503
+ return this.generate(ast.value);
1504
+ }
1505
+ }
1506
+ _generateObjectExpr(ast) {
1507
+ return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
1508
+ }
1509
+ objectField(field) {
1510
+ return `${field.name}: ${this.generate(field.value)}`;
1511
+ }
1512
+ _generateArrayExpr(ast) {
1513
+ return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
1514
+ }
1515
+ _generateLiteralExpr(ast) {
1516
+ return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
1517
+ }
1518
+ _generateNumberLiteral(ast) {
1519
+ return ast.value.toString();
1520
+ }
1521
+ _generateBooleanLiteral(ast) {
1522
+ return ast.value.toString();
1523
+ }
1524
+ _generateUnaryExpr(ast) {
1525
+ return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
1526
+ }
1527
+ _generateBinaryExpr(ast) {
1528
+ const operator = ast.operator;
1529
+ const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
1530
+ const rightExpr = this.generate(ast.right);
1531
+ const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
1532
+ return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
1533
+ }
1534
+ _generateReferenceExpr(ast) {
1535
+ const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
1536
+ return `${ast.target.ref?.name}${args}`;
1537
+ }
1538
+ _generateReferenceArg(ast) {
1539
+ return `${ast.name}:${this.generate(ast.value)}`;
1540
+ }
1541
+ _generateMemberExpr(ast) {
1542
+ return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
1543
+ }
1544
+ _generateInvocationExpr(ast) {
1545
+ return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
1546
+ }
1547
+ _generateNullExpr() {
1548
+ return "null";
1549
+ }
1550
+ _generateThisExpr() {
1551
+ return "this";
1552
+ }
1553
+ _generateAttribute(ast) {
1554
+ return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
1555
+ }
1556
+ _generateAttributeParam(ast) {
1557
+ return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
1558
+ }
1559
+ _generateAttributeParamType(ast) {
1560
+ return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
1561
+ }
1562
+ _generateFunctionDecl(ast) {
1563
+ return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
1564
+ }
1565
+ _generateFunctionParam(ast) {
1566
+ return `${ast.name}: ${this.generate(ast.type)}`;
1567
+ }
1568
+ _generateFunctionParamType(ast) {
1569
+ return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
1570
+ }
1571
+ _generateTypeDef(ast) {
1572
+ return `type ${ast.name} {
1573
+ ${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") : ""}
1574
+ }`;
1575
+ }
1576
+ _generateTypeDefField(ast) {
1577
+ return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
1578
+ }
1579
+ argument(ast) {
1580
+ return this.generate(ast.value);
1581
+ }
1582
+ get binaryExprSpace() {
1583
+ return " ".repeat(this.options.binaryExprNumberOfSpaces);
1584
+ }
1585
+ get unaryExprSpace() {
1586
+ return " ".repeat(this.options.unaryExprNumberOfSpaces);
1587
+ }
1588
+ get indent() {
1589
+ return " ".repeat(this.options.indent);
1590
+ }
1591
+ isParenthesesNeededForBinaryExpr(ast) {
1592
+ const result = {
1593
+ left: false,
1594
+ right: false
1595
+ };
1596
+ const operator = ast.operator;
1597
+ const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
1598
+ const currentPriority = import_ast4.BinaryExprOperatorPriority[operator];
1599
+ if (ast.left.$type === import_ast4.BinaryExpr && import_ast4.BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
1600
+ result.left = true;
1601
+ }
1602
+ if (!isCollectionPredicate && ast.right.$type === import_ast4.BinaryExpr && import_ast4.BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
1603
+ result.right = true;
1604
+ }
1605
+ return result;
1606
+ }
1607
+ isCollectionPredicateOperator(op) {
1608
+ return [
1609
+ "?",
1610
+ "!",
1611
+ "^"
1612
+ ].includes(op);
1613
+ }
1614
+ };
1615
+ _ts_decorate([
1616
+ gen(import_ast4.Model),
1617
+ _ts_metadata("design:type", Function),
1618
+ _ts_metadata("design:paramtypes", [
1619
+ typeof import_ast4.Model === "undefined" ? Object : import_ast4.Model
1620
+ ]),
1621
+ _ts_metadata("design:returntype", void 0)
1622
+ ], ZModelCodeGenerator.prototype, "_generateModel", null);
1623
+ _ts_decorate([
1624
+ gen(import_ast4.DataSource),
1625
+ _ts_metadata("design:type", Function),
1626
+ _ts_metadata("design:paramtypes", [
1627
+ typeof import_ast4.DataSource === "undefined" ? Object : import_ast4.DataSource
1628
+ ]),
1629
+ _ts_metadata("design:returntype", void 0)
1630
+ ], ZModelCodeGenerator.prototype, "_generateDataSource", null);
1631
+ _ts_decorate([
1632
+ gen(import_ast4.Enum),
1633
+ _ts_metadata("design:type", Function),
1634
+ _ts_metadata("design:paramtypes", [
1635
+ typeof import_ast4.Enum === "undefined" ? Object : import_ast4.Enum
1636
+ ]),
1637
+ _ts_metadata("design:returntype", void 0)
1638
+ ], ZModelCodeGenerator.prototype, "_generateEnum", null);
1639
+ _ts_decorate([
1640
+ gen(import_ast4.EnumField),
1641
+ _ts_metadata("design:type", Function),
1642
+ _ts_metadata("design:paramtypes", [
1643
+ typeof import_ast4.EnumField === "undefined" ? Object : import_ast4.EnumField
1644
+ ]),
1645
+ _ts_metadata("design:returntype", void 0)
1646
+ ], ZModelCodeGenerator.prototype, "_generateEnumField", null);
1647
+ _ts_decorate([
1648
+ gen(import_ast4.GeneratorDecl),
1649
+ _ts_metadata("design:type", Function),
1650
+ _ts_metadata("design:paramtypes", [
1651
+ typeof import_ast4.GeneratorDecl === "undefined" ? Object : import_ast4.GeneratorDecl
1652
+ ]),
1653
+ _ts_metadata("design:returntype", void 0)
1654
+ ], ZModelCodeGenerator.prototype, "_generateGenerator", null);
1655
+ _ts_decorate([
1656
+ gen(import_ast4.ConfigField),
1657
+ _ts_metadata("design:type", Function),
1658
+ _ts_metadata("design:paramtypes", [
1659
+ typeof import_ast4.ConfigField === "undefined" ? Object : import_ast4.ConfigField
1660
+ ]),
1661
+ _ts_metadata("design:returntype", void 0)
1662
+ ], ZModelCodeGenerator.prototype, "_generateConfigField", null);
1663
+ _ts_decorate([
1664
+ gen(import_ast4.ConfigArrayExpr),
1665
+ _ts_metadata("design:type", Function),
1666
+ _ts_metadata("design:paramtypes", [
1667
+ typeof import_ast4.ConfigArrayExpr === "undefined" ? Object : import_ast4.ConfigArrayExpr
1668
+ ]),
1669
+ _ts_metadata("design:returntype", void 0)
1670
+ ], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
1671
+ _ts_decorate([
1672
+ gen(import_ast4.ConfigInvocationExpr),
1673
+ _ts_metadata("design:type", Function),
1674
+ _ts_metadata("design:paramtypes", [
1675
+ typeof import_ast4.ConfigInvocationExpr === "undefined" ? Object : import_ast4.ConfigInvocationExpr
1676
+ ]),
1677
+ _ts_metadata("design:returntype", void 0)
1678
+ ], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
1679
+ _ts_decorate([
1680
+ gen(import_ast4.Plugin),
1681
+ _ts_metadata("design:type", Function),
1682
+ _ts_metadata("design:paramtypes", [
1683
+ typeof import_ast4.Plugin === "undefined" ? Object : import_ast4.Plugin
1684
+ ]),
1685
+ _ts_metadata("design:returntype", void 0)
1686
+ ], ZModelCodeGenerator.prototype, "_generatePlugin", null);
1687
+ _ts_decorate([
1688
+ gen(import_ast4.PluginField),
1689
+ _ts_metadata("design:type", Function),
1690
+ _ts_metadata("design:paramtypes", [
1691
+ typeof import_ast4.PluginField === "undefined" ? Object : import_ast4.PluginField
1692
+ ]),
1693
+ _ts_metadata("design:returntype", void 0)
1694
+ ], ZModelCodeGenerator.prototype, "_generatePluginField", null);
1695
+ _ts_decorate([
1696
+ gen(import_ast4.DataModel),
1697
+ _ts_metadata("design:type", Function),
1698
+ _ts_metadata("design:paramtypes", [
1699
+ typeof import_ast4.DataModel === "undefined" ? Object : import_ast4.DataModel
1700
+ ]),
1701
+ _ts_metadata("design:returntype", void 0)
1702
+ ], ZModelCodeGenerator.prototype, "_generateDataModel", null);
1703
+ _ts_decorate([
1704
+ gen(import_ast4.DataModelField),
1705
+ _ts_metadata("design:type", Function),
1706
+ _ts_metadata("design:paramtypes", [
1707
+ typeof import_ast4.DataModelField === "undefined" ? Object : import_ast4.DataModelField
1708
+ ]),
1709
+ _ts_metadata("design:returntype", void 0)
1710
+ ], ZModelCodeGenerator.prototype, "_generateDataModelField", null);
1711
+ _ts_decorate([
1712
+ gen(import_ast4.DataModelAttribute),
1713
+ _ts_metadata("design:type", Function),
1714
+ _ts_metadata("design:paramtypes", [
1715
+ typeof import_ast4.DataModelAttribute === "undefined" ? Object : import_ast4.DataModelAttribute
1716
+ ]),
1717
+ _ts_metadata("design:returntype", void 0)
1718
+ ], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
1719
+ _ts_decorate([
1720
+ gen(import_ast4.DataModelFieldAttribute),
1721
+ _ts_metadata("design:type", Function),
1722
+ _ts_metadata("design:paramtypes", [
1723
+ typeof import_ast4.DataModelFieldAttribute === "undefined" ? Object : import_ast4.DataModelFieldAttribute
1724
+ ]),
1725
+ _ts_metadata("design:returntype", void 0)
1726
+ ], ZModelCodeGenerator.prototype, "_generateDataModelFieldAttribute", null);
1727
+ _ts_decorate([
1728
+ gen(import_ast4.AttributeArg),
1729
+ _ts_metadata("design:type", Function),
1730
+ _ts_metadata("design:paramtypes", [
1731
+ typeof import_ast4.AttributeArg === "undefined" ? Object : import_ast4.AttributeArg
1732
+ ]),
1733
+ _ts_metadata("design:returntype", void 0)
1734
+ ], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
1735
+ _ts_decorate([
1736
+ gen(import_ast4.ObjectExpr),
1737
+ _ts_metadata("design:type", Function),
1738
+ _ts_metadata("design:paramtypes", [
1739
+ typeof import_ast4.ObjectExpr === "undefined" ? Object : import_ast4.ObjectExpr
1740
+ ]),
1741
+ _ts_metadata("design:returntype", void 0)
1742
+ ], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
1743
+ _ts_decorate([
1744
+ gen(import_ast4.ArrayExpr),
1745
+ _ts_metadata("design:type", Function),
1746
+ _ts_metadata("design:paramtypes", [
1747
+ typeof import_ast4.ArrayExpr === "undefined" ? Object : import_ast4.ArrayExpr
1748
+ ]),
1749
+ _ts_metadata("design:returntype", void 0)
1750
+ ], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
1751
+ _ts_decorate([
1752
+ gen(import_ast4.StringLiteral),
1753
+ _ts_metadata("design:type", Function),
1754
+ _ts_metadata("design:paramtypes", [
1755
+ typeof import_ast4.LiteralExpr === "undefined" ? Object : import_ast4.LiteralExpr
1756
+ ]),
1757
+ _ts_metadata("design:returntype", void 0)
1758
+ ], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
1759
+ _ts_decorate([
1760
+ gen(import_ast4.NumberLiteral),
1761
+ _ts_metadata("design:type", Function),
1762
+ _ts_metadata("design:paramtypes", [
1763
+ typeof import_ast4.NumberLiteral === "undefined" ? Object : import_ast4.NumberLiteral
1764
+ ]),
1765
+ _ts_metadata("design:returntype", void 0)
1766
+ ], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
1767
+ _ts_decorate([
1768
+ gen(import_ast4.BooleanLiteral),
1769
+ _ts_metadata("design:type", Function),
1770
+ _ts_metadata("design:paramtypes", [
1771
+ typeof import_ast4.BooleanLiteral === "undefined" ? Object : import_ast4.BooleanLiteral
1772
+ ]),
1773
+ _ts_metadata("design:returntype", void 0)
1774
+ ], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
1775
+ _ts_decorate([
1776
+ gen(import_ast4.UnaryExpr),
1777
+ _ts_metadata("design:type", Function),
1778
+ _ts_metadata("design:paramtypes", [
1779
+ typeof import_ast4.UnaryExpr === "undefined" ? Object : import_ast4.UnaryExpr
1780
+ ]),
1781
+ _ts_metadata("design:returntype", void 0)
1782
+ ], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
1783
+ _ts_decorate([
1784
+ gen(import_ast4.BinaryExpr),
1785
+ _ts_metadata("design:type", Function),
1786
+ _ts_metadata("design:paramtypes", [
1787
+ typeof import_ast4.BinaryExpr === "undefined" ? Object : import_ast4.BinaryExpr
1788
+ ]),
1789
+ _ts_metadata("design:returntype", void 0)
1790
+ ], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
1791
+ _ts_decorate([
1792
+ gen(import_ast4.ReferenceExpr),
1793
+ _ts_metadata("design:type", Function),
1794
+ _ts_metadata("design:paramtypes", [
1795
+ typeof import_ast4.ReferenceExpr === "undefined" ? Object : import_ast4.ReferenceExpr
1796
+ ]),
1797
+ _ts_metadata("design:returntype", void 0)
1798
+ ], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
1799
+ _ts_decorate([
1800
+ gen(import_ast4.ReferenceArg),
1801
+ _ts_metadata("design:type", Function),
1802
+ _ts_metadata("design:paramtypes", [
1803
+ typeof import_ast4.ReferenceArg === "undefined" ? Object : import_ast4.ReferenceArg
1804
+ ]),
1805
+ _ts_metadata("design:returntype", void 0)
1806
+ ], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
1807
+ _ts_decorate([
1808
+ gen(import_ast4.MemberAccessExpr),
1809
+ _ts_metadata("design:type", Function),
1810
+ _ts_metadata("design:paramtypes", [
1811
+ typeof import_ast4.MemberAccessExpr === "undefined" ? Object : import_ast4.MemberAccessExpr
1812
+ ]),
1813
+ _ts_metadata("design:returntype", void 0)
1814
+ ], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
1815
+ _ts_decorate([
1816
+ gen(import_ast4.InvocationExpr),
1817
+ _ts_metadata("design:type", Function),
1818
+ _ts_metadata("design:paramtypes", [
1819
+ typeof import_ast4.InvocationExpr === "undefined" ? Object : import_ast4.InvocationExpr
1820
+ ]),
1821
+ _ts_metadata("design:returntype", void 0)
1822
+ ], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
1823
+ _ts_decorate([
1824
+ gen(import_ast4.NullExpr),
1825
+ _ts_metadata("design:type", Function),
1826
+ _ts_metadata("design:paramtypes", []),
1827
+ _ts_metadata("design:returntype", void 0)
1828
+ ], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
1829
+ _ts_decorate([
1830
+ gen(import_ast4.ThisExpr),
1831
+ _ts_metadata("design:type", Function),
1832
+ _ts_metadata("design:paramtypes", []),
1833
+ _ts_metadata("design:returntype", void 0)
1834
+ ], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
1835
+ _ts_decorate([
1836
+ gen(import_ast4.Attribute),
1837
+ _ts_metadata("design:type", Function),
1838
+ _ts_metadata("design:paramtypes", [
1839
+ typeof import_ast4.Attribute === "undefined" ? Object : import_ast4.Attribute
1840
+ ]),
1841
+ _ts_metadata("design:returntype", void 0)
1842
+ ], ZModelCodeGenerator.prototype, "_generateAttribute", null);
1843
+ _ts_decorate([
1844
+ gen(import_ast4.AttributeParam),
1845
+ _ts_metadata("design:type", Function),
1846
+ _ts_metadata("design:paramtypes", [
1847
+ typeof import_ast4.AttributeParam === "undefined" ? Object : import_ast4.AttributeParam
1848
+ ]),
1849
+ _ts_metadata("design:returntype", void 0)
1850
+ ], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
1851
+ _ts_decorate([
1852
+ gen(import_ast4.AttributeParamType),
1853
+ _ts_metadata("design:type", Function),
1854
+ _ts_metadata("design:paramtypes", [
1855
+ typeof import_ast4.AttributeParamType === "undefined" ? Object : import_ast4.AttributeParamType
1856
+ ]),
1857
+ _ts_metadata("design:returntype", void 0)
1858
+ ], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
1859
+ _ts_decorate([
1860
+ gen(import_ast4.FunctionDecl),
1861
+ _ts_metadata("design:type", Function),
1862
+ _ts_metadata("design:paramtypes", [
1863
+ typeof import_ast4.FunctionDecl === "undefined" ? Object : import_ast4.FunctionDecl
1864
+ ]),
1865
+ _ts_metadata("design:returntype", void 0)
1866
+ ], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
1867
+ _ts_decorate([
1868
+ gen(import_ast4.FunctionParam),
1869
+ _ts_metadata("design:type", Function),
1870
+ _ts_metadata("design:paramtypes", [
1871
+ typeof import_ast4.FunctionParam === "undefined" ? Object : import_ast4.FunctionParam
1872
+ ]),
1873
+ _ts_metadata("design:returntype", void 0)
1874
+ ], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
1875
+ _ts_decorate([
1876
+ gen(import_ast4.FunctionParamType),
1877
+ _ts_metadata("design:type", Function),
1878
+ _ts_metadata("design:paramtypes", [
1879
+ typeof import_ast4.FunctionParamType === "undefined" ? Object : import_ast4.FunctionParamType
1880
+ ]),
1881
+ _ts_metadata("design:returntype", void 0)
1882
+ ], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
1883
+ _ts_decorate([
1884
+ gen(import_ast4.TypeDef),
1885
+ _ts_metadata("design:type", Function),
1886
+ _ts_metadata("design:paramtypes", [
1887
+ typeof import_ast4.TypeDef === "undefined" ? Object : import_ast4.TypeDef
1888
+ ]),
1889
+ _ts_metadata("design:returntype", void 0)
1890
+ ], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
1891
+ _ts_decorate([
1892
+ gen(import_ast4.TypeDefField),
1893
+ _ts_metadata("design:type", Function),
1894
+ _ts_metadata("design:paramtypes", [
1895
+ typeof import_ast4.TypeDefField === "undefined" ? Object : import_ast4.TypeDefField
1896
+ ]),
1897
+ _ts_metadata("design:returntype", void 0)
1898
+ ], ZModelCodeGenerator.prototype, "_generateTypeDefField", null);
1899
+ // Annotate the CommonJS export names for ESM import in node:
1900
+ 0 && (module.exports = {
1901
+ ModelUtils,
1902
+ PrismaSchemaGenerator,
1903
+ TsSchemaGenerator,
1904
+ ZModelCodeGenerator
1905
+ });
1906
+ //# sourceMappingURL=index.cjs.map