@zenstackhq/sdk 3.5.6 → 3.6.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/index.mjs ADDED
@@ -0,0 +1,1148 @@
1
+ import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
+ import { BooleanLiteral, DataModel, DataSource, Enum, GeneratorDecl, NumberLiteral, StringLiteral, isArrayExpr, isBinaryExpr, isCollectionPredicateBinding, isDataField, isDataModel, isDataSource, isEnum, isEnumField, isGeneratorDecl, isInvocationExpr, isLiteralExpr, isMemberAccessExpr, isModel, isNullExpr, isProcedure, isReferenceExpr, isStringLiteral, isThisExpr, isTypeDef, isUnaryExpr } from "@zenstackhq/language/ast";
3
+ import { getAllAttributes, getAllFields, getAttributeArg, getModelIdFields, getModelUniqueFields, getStringLiteral, isAuthInvocation, isDataFieldReference, isDelegateModel } from "@zenstackhq/language/utils";
4
+ import { invariant, lowerCaseFirst } from "@zenstackhq/common-helpers";
5
+ import { ZModelCodeGenerator } from "@zenstackhq/language";
6
+ import { AstUtils } from "langium";
7
+ import { match } from "ts-pattern";
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import * as ts from "typescript";
11
+ //#region src/model-utils.ts
12
+ var model_utils_exports = /* @__PURE__ */ __exportAll({
13
+ DELEGATE_AUX_RELATION_PREFIX: () => DELEGATE_AUX_RELATION_PREFIX,
14
+ getAttribute: () => getAttribute,
15
+ getAuthDecl: () => getAuthDecl,
16
+ getContainingModel: () => getContainingModel,
17
+ getDelegateOriginModel: () => getDelegateOriginModel,
18
+ getIdFields: () => getIdFields,
19
+ getOwnedFields: () => getOwnedFields,
20
+ hasAttribute: () => hasAttribute,
21
+ isDelegateModel: () => isDelegateModel$1,
22
+ isFromStdlib: () => isFromStdlib,
23
+ isIdField: () => isIdField,
24
+ isUniqueField: () => isUniqueField,
25
+ resolved: () => resolved
26
+ });
27
+ function isIdField(field, contextModel) {
28
+ if (hasAttribute(field, "@id")) return true;
29
+ const modelLevelIds = getModelIdFields(contextModel);
30
+ if (modelLevelIds.map((f) => f.name).includes(field.name)) return true;
31
+ const allFields = getAllFields(contextModel);
32
+ if (allFields.some((f) => hasAttribute(f, "@id")) || modelLevelIds.length > 0) return false;
33
+ const firstUniqueField = allFields.find((f) => hasAttribute(f, "@unique"));
34
+ if (firstUniqueField) return firstUniqueField.name === field.name;
35
+ if (getModelUniqueFields(contextModel).map((f) => f.name).includes(field.name)) return true;
36
+ return false;
37
+ }
38
+ function hasAttribute(decl, name) {
39
+ return !!getAttribute(decl, name);
40
+ }
41
+ function getAttribute(decl, name) {
42
+ return decl.attributes.find((attr) => attr.decl.$refText === name);
43
+ }
44
+ function isDelegateModel$1(node) {
45
+ return isDataModel(node) && hasAttribute(node, "@@delegate");
46
+ }
47
+ /**
48
+ * Returns all fields that physically belong to a model's table: its directly declared
49
+ * fields plus fields from its mixins (recursively).
50
+ */
51
+ function getOwnedFields(model) {
52
+ const fields = [...model.fields];
53
+ for (const mixin of model.mixins) if (mixin.ref) fields.push(...getOwnedFields(mixin.ref));
54
+ return fields;
55
+ }
56
+ /**
57
+ * Returns the name of the delegate base model that "owns" the given field in the context of
58
+ * `contextModel`. This handles both direct fields of delegate models and mixin fields that
59
+ * belong to a mixin used by a delegate base model.
60
+ */
61
+ function getDelegateOriginModel(field, contextModel) {
62
+ let base = contextModel.baseModel?.ref;
63
+ while (base) {
64
+ if (isDelegateModel$1(base) && getOwnedFields(base).some((f) => f.name === field.name)) return base.name;
65
+ base = base.baseModel?.ref;
66
+ }
67
+ }
68
+ function isUniqueField(field) {
69
+ if (hasAttribute(field, "@unique")) return true;
70
+ const modelIds = getAttribute(field.$container, "@@unique");
71
+ if (modelIds && modelIds.args.some((arg) => isLiteralExpr(arg.value) && arg.value.value === field.name)) return true;
72
+ return false;
73
+ }
74
+ function isFromStdlib(node) {
75
+ const model = getContainingModel(node);
76
+ return !!model && !!model.$document && model.$document.uri.path.endsWith("stdlib.zmodel");
77
+ }
78
+ function getContainingModel(node) {
79
+ if (!node) return null;
80
+ return isModel(node) ? node : getContainingModel(node.$container);
81
+ }
82
+ function resolved(ref) {
83
+ if (!ref.ref) throw new Error(`Reference not resolved: ${ref.$refText}`);
84
+ return ref.ref;
85
+ }
86
+ function getAuthDecl(model) {
87
+ let found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
88
+ if (!found) found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.name === "User");
89
+ return found;
90
+ }
91
+ function getIdFields(dm) {
92
+ return getAllFields(dm).filter((f) => isIdField(f, dm)).map((f) => f.name);
93
+ }
94
+ /**
95
+ * Prefix for auxiliary relation fields generated for delegated models
96
+ */
97
+ const DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
98
+ //#endregion
99
+ //#region src/prisma/indent-string.ts
100
+ /**
101
+ * Utility for indenting strings
102
+ */
103
+ function indentString(string, count = 4) {
104
+ return string.replace(/^(?!\s*$)/gm, " ".repeat(count));
105
+ }
106
+ //#endregion
107
+ //#region src/prisma/prisma-builder.ts
108
+ /**
109
+ * Prisma schema builder
110
+ */
111
+ var PrismaModel = class {
112
+ datasources = [];
113
+ generators = [];
114
+ models = [];
115
+ enums = [];
116
+ addDataSource(name, fields = []) {
117
+ const ds = new DataSource$1(name, fields);
118
+ this.datasources.push(ds);
119
+ return ds;
120
+ }
121
+ addGenerator(name, fields) {
122
+ const generator = new Generator(name, fields);
123
+ this.generators.push(generator);
124
+ return generator;
125
+ }
126
+ addModel(name) {
127
+ const model = new Model$1(name, false);
128
+ this.models.push(model);
129
+ return model;
130
+ }
131
+ addView(name) {
132
+ const model = new Model$1(name, true);
133
+ this.models.push(model);
134
+ return model;
135
+ }
136
+ addEnum(name) {
137
+ const e = new Enum$1(name);
138
+ this.enums.push(e);
139
+ return e;
140
+ }
141
+ toString() {
142
+ return [
143
+ ...this.datasources,
144
+ ...this.generators,
145
+ ...this.enums,
146
+ ...this.models
147
+ ].map((d) => d.toString()).join("\n\n");
148
+ }
149
+ };
150
+ var DataSource$1 = class {
151
+ constructor(name, fields = []) {
152
+ this.name = name;
153
+ this.fields = fields;
154
+ }
155
+ toString() {
156
+ return `datasource ${this.name} {\n` + this.fields.map((f) => indentString(`${f.name} = ${f.text}`)).join("\n") + `\n}`;
157
+ }
158
+ };
159
+ var Generator = class {
160
+ constructor(name, fields) {
161
+ this.name = name;
162
+ this.fields = fields;
163
+ }
164
+ toString() {
165
+ return `generator ${this.name} {\n` + this.fields.map((f) => indentString(`${f.name} = ${f.text}`)).join("\n") + `\n}`;
166
+ }
167
+ };
168
+ var DeclarationBase = class {
169
+ constructor(documentations = []) {
170
+ this.documentations = documentations;
171
+ }
172
+ addComment(name) {
173
+ this.documentations.push(name);
174
+ return name;
175
+ }
176
+ toString() {
177
+ return this.documentations.map((x) => `${x}\n`).join("");
178
+ }
179
+ };
180
+ var ContainerDeclaration = class extends DeclarationBase {
181
+ constructor(documentations = [], attributes = []) {
182
+ super(documentations);
183
+ this.attributes = attributes;
184
+ }
185
+ };
186
+ var FieldDeclaration = class extends DeclarationBase {
187
+ constructor(documentations = [], attributes = []) {
188
+ super(documentations);
189
+ this.attributes = attributes;
190
+ }
191
+ };
192
+ var Model$1 = class extends ContainerDeclaration {
193
+ fields = [];
194
+ constructor(name, isView, documentations = []) {
195
+ super(documentations);
196
+ this.name = name;
197
+ this.isView = isView;
198
+ }
199
+ addField(name, type, attributes = [], documentations = [], addToFront = false) {
200
+ const field = new ModelField(name, type, attributes, documentations);
201
+ if (addToFront) this.fields.unshift(field);
202
+ else this.fields.push(field);
203
+ return field;
204
+ }
205
+ addAttribute(name, args = []) {
206
+ const attr = new ContainerAttribute(name, args);
207
+ this.attributes.push(attr);
208
+ return attr;
209
+ }
210
+ toString() {
211
+ const result = [...this.fields];
212
+ if (this.attributes.length > 0) result.push("");
213
+ result.push(...this.attributes);
214
+ return super.toString() + `${this.isView ? "view" : "model"} ${this.name} {\n` + indentString(result.map((d) => d.toString()).join("\n")) + `\n}`;
215
+ }
216
+ };
217
+ var ModelFieldType = class {
218
+ constructor(type, array, optional) {
219
+ this.type = type;
220
+ this.array = array;
221
+ this.optional = optional;
222
+ }
223
+ toString() {
224
+ return `${this.type}${this.array ? "[]" : ""}${this.optional ? "?" : ""}`;
225
+ }
226
+ };
227
+ var ModelField = class extends FieldDeclaration {
228
+ constructor(name, type, attributes = [], documentations = []) {
229
+ super(documentations, attributes);
230
+ this.name = name;
231
+ this.type = type;
232
+ }
233
+ addAttribute(name, args = []) {
234
+ const attr = new FieldAttribute(name, args);
235
+ this.attributes.push(attr);
236
+ return attr;
237
+ }
238
+ toString() {
239
+ return super.toString() + `${this.name} ${this.type}` + (this.attributes.length > 0 ? " " + this.attributes.map((a) => a.toString()).join(" ") : "");
240
+ }
241
+ };
242
+ var FieldAttribute = class {
243
+ constructor(name, args = []) {
244
+ this.name = name;
245
+ this.args = args;
246
+ }
247
+ toString() {
248
+ return `${this.name}(` + this.args.map((a) => a.toString()).join(", ") + `)`;
249
+ }
250
+ };
251
+ var ContainerAttribute = class {
252
+ constructor(name, args = []) {
253
+ this.name = name;
254
+ this.args = args;
255
+ }
256
+ toString() {
257
+ return `${this.name}(` + this.args.map((a) => a.toString()).join(", ") + `)`;
258
+ }
259
+ };
260
+ var AttributeArg = class {
261
+ constructor(name, value) {
262
+ this.name = name;
263
+ this.value = value;
264
+ }
265
+ toString() {
266
+ return this.name ? `${this.name}: ${this.value}` : this.value.toString();
267
+ }
268
+ };
269
+ var AttributeArgValue = class {
270
+ constructor(type, value) {
271
+ this.type = type;
272
+ this.value = value;
273
+ switch (type) {
274
+ case "String":
275
+ if (typeof value !== "string") throw new Error("Value must be string");
276
+ break;
277
+ case "Number":
278
+ if (typeof value !== "number" && typeof value !== "string") throw new Error("Value must be number or string");
279
+ break;
280
+ case "Boolean":
281
+ if (typeof value !== "boolean") throw new Error("Value must be boolean");
282
+ break;
283
+ case "Array":
284
+ if (!Array.isArray(value)) throw new Error("Value must be array");
285
+ break;
286
+ case "FieldReference":
287
+ if (typeof value !== "string" && !(value instanceof FieldReference)) throw new Error("Value must be string or FieldReference");
288
+ break;
289
+ case "FunctionCall":
290
+ if (!(value instanceof FunctionCall)) throw new Error("Value must be FunctionCall");
291
+ break;
292
+ }
293
+ }
294
+ toString() {
295
+ switch (this.type) {
296
+ case "String": return JSON.stringify(this.value);
297
+ case "Number": return this.value.toString();
298
+ case "FieldReference": if (typeof this.value === "string") return this.value;
299
+ else {
300
+ const fr = this.value;
301
+ let r = fr.field;
302
+ if (fr.args.length > 0) r += "(" + fr.args.map((a) => a.toString()).join(",") + ")";
303
+ return r;
304
+ }
305
+ case "FunctionCall": return this.value.toString();
306
+ case "Boolean": return this.value ? "true" : "false";
307
+ case "Array": return "[" + this.value.map((v) => v.toString()).join(", ") + "]";
308
+ default: throw new Error(`Unknown attribute value type ${this.type}`);
309
+ }
310
+ }
311
+ };
312
+ var FieldReference = class {
313
+ constructor(field, args = []) {
314
+ this.field = field;
315
+ this.args = args;
316
+ }
317
+ };
318
+ var FieldReferenceArg = class {
319
+ constructor(name, value) {
320
+ this.name = name;
321
+ this.value = value;
322
+ }
323
+ toString() {
324
+ return `${this.name}: ${this.value}`;
325
+ }
326
+ };
327
+ var FunctionCall = class {
328
+ constructor(func, args = []) {
329
+ this.func = func;
330
+ this.args = args;
331
+ }
332
+ toString() {
333
+ return `${this.func}(` + this.args.map((a) => a.toString()).join(", ") + ")";
334
+ }
335
+ };
336
+ var FunctionCallArg = class {
337
+ constructor(value) {
338
+ this.value = value;
339
+ }
340
+ toString() {
341
+ return this.value;
342
+ }
343
+ };
344
+ var Enum$1 = class extends ContainerDeclaration {
345
+ fields = [];
346
+ constructor(name, documentations = []) {
347
+ super(documentations);
348
+ this.name = name;
349
+ }
350
+ addField(name, attributes = [], documentations = []) {
351
+ const field = new EnumField$1(name, attributes, documentations);
352
+ this.fields.push(field);
353
+ return field;
354
+ }
355
+ addAttribute(name, args = []) {
356
+ const attr = new ContainerAttribute(name, args);
357
+ this.attributes.push(attr);
358
+ return attr;
359
+ }
360
+ addComment(name) {
361
+ this.documentations.push(name);
362
+ return name;
363
+ }
364
+ toString() {
365
+ return super.toString() + `enum ${this.name} {\n` + indentString([...this.fields, ...this.attributes].map((d) => d.toString()).join("\n")) + "\n}";
366
+ }
367
+ };
368
+ var EnumField$1 = class extends DeclarationBase {
369
+ constructor(name, attributes = [], documentations = []) {
370
+ super(documentations);
371
+ this.name = name;
372
+ this.attributes = attributes;
373
+ }
374
+ addAttribute(name, args = []) {
375
+ const attr = new FieldAttribute(name, args);
376
+ this.attributes.push(attr);
377
+ return attr;
378
+ }
379
+ toString() {
380
+ return super.toString() + this.name + (this.attributes.length > 0 ? " " + this.attributes.map((a) => a.toString()).join(" ") : "");
381
+ }
382
+ };
383
+ //#endregion
384
+ //#region src/prisma/prisma-schema-generator.ts
385
+ const IDENTIFIER_NAME_MAX_LENGTH = 38;
386
+ const NON_PRISMA_DATASOURCE_FIELDS = ["defaultSchema"];
387
+ /**
388
+ * Generates Prisma schema file
389
+ */
390
+ var PrismaSchemaGenerator = class {
391
+ PRELUDE = `//////////////////////////////////////////////////////////////////////////////////////////////
392
+ // DO NOT MODIFY THIS FILE //
393
+ // This file is automatically generated by ZenStack CLI and should not be manually updated. //
394
+ //////////////////////////////////////////////////////////////////////////////////////////////
395
+
396
+ `;
397
+ shortNameMap = /* @__PURE__ */ new Map();
398
+ constructor(zmodel) {
399
+ this.zmodel = zmodel;
400
+ }
401
+ async generate() {
402
+ const prisma = new PrismaModel();
403
+ for (const decl of this.zmodel.declarations) switch (decl.$type) {
404
+ case DataSource:
405
+ this.generateDataSource(prisma, decl);
406
+ break;
407
+ case Enum:
408
+ this.generateEnum(prisma, decl);
409
+ break;
410
+ case DataModel:
411
+ this.generateModel(prisma, decl);
412
+ break;
413
+ case GeneratorDecl:
414
+ this.generateGenerator(prisma, decl);
415
+ break;
416
+ }
417
+ if (!this.zmodel.declarations.some(isGeneratorDecl)) this.generateDefaultGenerator(prisma);
418
+ return this.PRELUDE + prisma.toString();
419
+ }
420
+ generateDataSource(prisma, dataSource) {
421
+ const fields = dataSource.fields.filter((f) => !NON_PRISMA_DATASOURCE_FIELDS.includes(f.name)).map((f) => ({
422
+ name: f.name,
423
+ text: this.configExprToText(f.value)
424
+ }));
425
+ prisma.addDataSource(dataSource.name, fields);
426
+ }
427
+ configExprToText(expr) {
428
+ if (isLiteralExpr(expr)) return this.literalToText(expr);
429
+ else if (isInvocationExpr(expr)) return this.makeFunctionCall(expr).toString();
430
+ else return this.configArrayToText(expr);
431
+ }
432
+ configArrayToText(expr) {
433
+ return "[" + expr.items.map((item) => {
434
+ if (isLiteralExpr(item)) return this.literalToText(item);
435
+ else return item.name + (item.args.length > 0 ? "(" + item.args.map((arg) => this.configInvocationArgToText(arg)).join(", ") + ")" : "");
436
+ }).join(", ") + "]";
437
+ }
438
+ configInvocationArgToText(arg) {
439
+ return `${arg.name}: ${this.literalToText(arg.value)}`;
440
+ }
441
+ literalToText(expr) {
442
+ return JSON.stringify(expr.value);
443
+ }
444
+ generateGenerator(prisma, decl) {
445
+ prisma.addGenerator(decl.name, decl.fields.map((f) => ({
446
+ name: f.name,
447
+ text: this.configExprToText(f.value)
448
+ })));
449
+ }
450
+ generateDefaultGenerator(prisma) {
451
+ const gen = prisma.addGenerator("client", [{
452
+ name: "provider",
453
+ text: "\"prisma-client-js\""
454
+ }]);
455
+ const previewFeatures = [];
456
+ if (this.zmodel.declarations.find(isDataSource)?.fields.some((f) => f.name === "extensions")) previewFeatures.push("postgresqlExtensions");
457
+ if (this.zmodel.declarations.some((d) => isDataModel(d) && d.isView)) previewFeatures.push("views");
458
+ if (previewFeatures.length > 0) gen.fields.push({
459
+ name: "previewFeatures",
460
+ text: JSON.stringify(previewFeatures)
461
+ });
462
+ }
463
+ generateModel(prisma, decl) {
464
+ const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
465
+ const allFields = getAllFields(decl, true);
466
+ for (const field of allFields) {
467
+ if (hasAttribute(field, "@computed")) continue;
468
+ if (isIdField(field, decl) || !getDelegateOriginModel(field, decl)) this.generateModelField(model, field, decl);
469
+ }
470
+ const allAttributes = getAllAttributes(decl).filter((attr) => this.isPrismaAttribute(attr));
471
+ for (const attr of allAttributes) this.generateContainerAttribute(model, attr);
472
+ if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) model.addAttribute("@@schema", [new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))]);
473
+ decl.comments.forEach((c) => model.addComment(c));
474
+ this.generateDelegateRelationForBase(model, decl);
475
+ this.generateDelegateRelationForConcrete(model, decl);
476
+ }
477
+ getDatasourceField(zmodel, fieldName) {
478
+ return zmodel.declarations.find(isDataSource)?.fields.find((f) => f.name === fieldName);
479
+ }
480
+ datasourceHasSchemasSetting(zmodel) {
481
+ return !!this.getDatasourceField(zmodel, "schemas");
482
+ }
483
+ getDefaultPostgresSchemaName(zmodel) {
484
+ return getStringLiteral(this.getDatasourceField(zmodel, "defaultSchema")?.value) ?? "public";
485
+ }
486
+ isPrismaAttribute(attr) {
487
+ if (!attr.decl.ref) return false;
488
+ return attr.decl.ref.attributes.some((a) => a.decl.ref?.name === "@@@prisma");
489
+ }
490
+ getUnsupportedFieldType(fieldType) {
491
+ if (fieldType.unsupported) {
492
+ const value = getStringLiteral(fieldType.unsupported.value);
493
+ if (value) return `Unsupported("${value}")`;
494
+ else return;
495
+ } else return;
496
+ }
497
+ generateModelField(model, field, contextModel, addToFront = false) {
498
+ let fieldType;
499
+ if (field.type.type) fieldType = field.type.type;
500
+ else if (field.type.reference?.ref) if (isTypeDef(field.type.reference.ref)) fieldType = "Json";
501
+ else fieldType = field.type.reference.ref.name;
502
+ else {
503
+ const unsupported = this.getUnsupportedFieldType(field.type);
504
+ if (unsupported) fieldType = unsupported;
505
+ }
506
+ if (!fieldType) throw new Error(`Field type is not resolved: ${field.$container.name}.${field.name}`);
507
+ const isArray = isTypeDef(field.type.reference?.ref) ? false : field.type.array;
508
+ const type = new ModelFieldType(fieldType, isArray, field.type.optional);
509
+ const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.isDefaultWithAuthInvocation(attr)).filter((attr) => !(isIdField(field, contextModel) && getDelegateOriginModel(field, contextModel) && attr.decl.$refText === "@default")).map((attr) => this.makeFieldAttribute(attr));
510
+ const docs = [...field.comments];
511
+ return model.addField(field.name, type, attributes, docs, addToFront);
512
+ }
513
+ isDefaultWithAuthInvocation(attr) {
514
+ if (attr.decl.ref?.name !== "@default") return false;
515
+ const expr = attr.args[0]?.value;
516
+ if (!expr) return false;
517
+ return AstUtils.streamAst(expr).some(isAuthInvocation);
518
+ }
519
+ makeFieldAttribute(attr) {
520
+ const attrName = attr.decl.ref.name;
521
+ return new FieldAttribute(attrName, attr.args.map((arg) => this.makeAttributeArg(arg)));
522
+ }
523
+ makeAttributeArg(arg) {
524
+ return new AttributeArg(arg.name, this.makeAttributeArgValue(arg.value));
525
+ }
526
+ makeAttributeArgValue(node) {
527
+ if (isLiteralExpr(node)) return new AttributeArgValue(match(node.$type).with(StringLiteral, () => "String").with(NumberLiteral, () => "Number").with(BooleanLiteral, () => "Boolean").exhaustive(), node.value);
528
+ else if (isArrayExpr(node)) return new AttributeArgValue("Array", new Array(...node.items.map((item) => this.makeAttributeArgValue(item))));
529
+ else if (isReferenceExpr(node)) return new AttributeArgValue("FieldReference", new FieldReference(node.target.ref.name, node.args.map((arg) => new FieldReferenceArg(arg.name, this.exprToText(arg.value)))));
530
+ else if (isInvocationExpr(node)) return new AttributeArgValue("FunctionCall", this.makeFunctionCall(node));
531
+ else throw Error(`Unsupported attribute argument expression type: ${node.$type}`);
532
+ }
533
+ exprToText(expr) {
534
+ return new ZModelCodeGenerator({ quote: "double" }).generate(expr);
535
+ }
536
+ makeFunctionCall(node) {
537
+ return new FunctionCall(node.function.ref.name, node.args.map((arg) => {
538
+ return new FunctionCallArg(match(arg.value).when(isStringLiteral, (v) => `"${v.value}"`).when(isLiteralExpr, (v) => v.value.toString()).when(isNullExpr, () => "null").otherwise(() => {
539
+ throw new Error("Function call argument must be literal or null");
540
+ }));
541
+ }));
542
+ }
543
+ generateContainerAttribute(container, attr) {
544
+ const attrName = attr.decl.ref.name;
545
+ container.attributes.push(new ContainerAttribute(attrName, attr.args.map((arg) => this.makeAttributeArg(arg))));
546
+ }
547
+ generateEnum(prisma, decl) {
548
+ const _enum = prisma.addEnum(decl.name);
549
+ for (const field of decl.fields) this.generateEnumField(_enum, field);
550
+ const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
551
+ for (const attr of allAttributes) this.generateContainerAttribute(_enum, attr);
552
+ if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) _enum.addAttribute("@@schema", [new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))]);
553
+ decl.comments.forEach((c) => _enum.addComment(c));
554
+ }
555
+ generateEnumField(_enum, field) {
556
+ const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).map((attr) => this.makeFieldAttribute(attr));
557
+ const docs = [...field.comments];
558
+ _enum.addField(field.name, attributes, docs);
559
+ }
560
+ generateDelegateRelationForBase(model, decl) {
561
+ if (!isDelegateModel(decl)) return;
562
+ this.getConcreteModels(decl).forEach((concrete) => {
563
+ const auxName = this.truncate(`${DELEGATE_AUX_RELATION_PREFIX}_${lowerCaseFirst(concrete.name)}`);
564
+ model.addField(auxName, new ModelFieldType(concrete.name, false, true));
565
+ });
566
+ }
567
+ generateDelegateRelationForConcrete(model, concreteDecl) {
568
+ const base = concreteDecl.baseModel?.ref;
569
+ if (!base) return;
570
+ const idFields = getIdFields(base);
571
+ const relationField = this.truncate(`${DELEGATE_AUX_RELATION_PREFIX}_${lowerCaseFirst(base.name)}`);
572
+ model.addField(relationField, base.name, [new FieldAttribute("@relation", [
573
+ new AttributeArg("fields", new AttributeArgValue("Array", idFields.map((idField) => new AttributeArgValue("FieldReference", new FieldReference(idField))))),
574
+ new AttributeArg("references", new AttributeArgValue("Array", idFields.map((idField) => new AttributeArgValue("FieldReference", new FieldReference(idField))))),
575
+ new AttributeArg("onDelete", new AttributeArgValue("FieldReference", new FieldReference("Cascade"))),
576
+ new AttributeArg("onUpdate", new AttributeArgValue("FieldReference", new FieldReference("Cascade")))
577
+ ])]);
578
+ }
579
+ getConcreteModels(dataModel) {
580
+ if (!isDelegateModel(dataModel)) return [];
581
+ return dataModel.$container.declarations.filter((d) => isDataModel(d) && d !== dataModel && d.baseModel?.ref === dataModel);
582
+ }
583
+ truncate(name) {
584
+ if (name.length <= IDENTIFIER_NAME_MAX_LENGTH) return name;
585
+ const existing = this.shortNameMap.get(name);
586
+ if (existing) return existing;
587
+ const baseName = name.slice(0, IDENTIFIER_NAME_MAX_LENGTH);
588
+ let index = 0;
589
+ let shortName = `${baseName}_${index}`;
590
+ while (true) {
591
+ if (!Array.from(this.shortNameMap.values()).find((v) => v === shortName)) {
592
+ this.shortNameMap.set(name, shortName);
593
+ break;
594
+ }
595
+ index++;
596
+ shortName = `${baseName}_${index}`;
597
+ }
598
+ return shortName;
599
+ }
600
+ };
601
+ //#endregion
602
+ //#region src/ts-schema-generator.ts
603
+ var TsSchemaGenerator = class {
604
+ usedExpressionUtils = false;
605
+ usedAttributeApplication = false;
606
+ usedFieldDefault = false;
607
+ async generate(model, options) {
608
+ fs.mkdirSync(options.outDir, { recursive: true });
609
+ this.generateSchema(model, options);
610
+ if (options.generateModelTypes !== false) this.generateModelsAndTypeDefs(model, options);
611
+ if (options.generateInputTypes !== false) this.generateInputTypes(model, options);
612
+ }
613
+ generateSchema(model, options) {
614
+ const targets = [];
615
+ if (!options.liteOnly) targets.push({
616
+ lite: false,
617
+ file: "schema.ts"
618
+ });
619
+ if (options.lite || options.liteOnly) targets.push({
620
+ lite: true,
621
+ file: "schema-lite.ts"
622
+ });
623
+ for (const { lite, file } of targets) {
624
+ this.usedExpressionUtils = false;
625
+ this.usedAttributeApplication = false;
626
+ this.usedFieldDefault = false;
627
+ const statements = [];
628
+ this.generateSchemaStatements(model, statements, lite);
629
+ this.generateBannerComments(statements);
630
+ const schemaOutputFile = path.join(options.outDir, file);
631
+ const sourceFile = ts.createSourceFile(schemaOutputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
632
+ const result = ts.createPrinter().printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
633
+ fs.writeFileSync(schemaOutputFile, result);
634
+ }
635
+ }
636
+ generateSchemaStatements(model, statements, lite) {
637
+ const schemaClass = this.createSchemaClass(model, lite);
638
+ const schemaImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
639
+ ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
640
+ ...this.usedAttributeApplication ? [ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("AttributeApplication"))] : [],
641
+ ...this.usedFieldDefault ? [ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("FieldDefault"))] : [],
642
+ ...this.usedExpressionUtils ? [ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))] : []
643
+ ])), ts.factory.createStringLiteral("@zenstackhq/schema"));
644
+ statements.push(schemaImportDecl);
645
+ statements.push(schemaClass);
646
+ const schemaDecl = ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))], ts.NodeFlags.Const));
647
+ statements.push(schemaDecl);
648
+ }
649
+ createExpressionUtilsCall(method, args) {
650
+ this.usedExpressionUtils = true;
651
+ return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
652
+ }
653
+ createSchemaClass(model, lite) {
654
+ const members = [
655
+ ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
656
+ ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
657
+ ...model.declarations.some(isTypeDef) ? [ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))] : []
658
+ ];
659
+ const enums = model.declarations.filter(isEnum);
660
+ if (enums.length > 0) 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))));
661
+ const authType = getAuthDecl(model);
662
+ if (authType) members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
663
+ const procedures = model.declarations.filter(isProcedure);
664
+ if (procedures.length > 0) members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
665
+ members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
666
+ return ts.factory.createClassDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], "SchemaType", void 0, [ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)])], members);
667
+ }
668
+ createAsConst(expr) {
669
+ return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
670
+ }
671
+ createAttributesTypeAssertion(expr) {
672
+ this.usedAttributeApplication = true;
673
+ return ts.factory.createAsExpression(expr, ts.factory.createTypeOperatorNode(ts.SyntaxKind.ReadonlyKeyword, ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode("AttributeApplication"))));
674
+ }
675
+ createDefaultTypeAssertion(expr) {
676
+ this.usedFieldDefault = true;
677
+ return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("FieldDefault"));
678
+ }
679
+ createProviderObject(model) {
680
+ const dsProvider = this.getDataSourceProvider(model);
681
+ const defaultSchema = this.getDataSourceDefaultSchema(model);
682
+ return ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider)), ...defaultSchema ? [ts.factory.createPropertyAssignment("defaultSchema", ts.factory.createStringLiteral(defaultSchema))] : []], true);
683
+ }
684
+ createModelsObject(model, lite) {
685
+ return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
686
+ }
687
+ getAllDataModels(model) {
688
+ return model.declarations.filter((d) => isDataModel(d) && !hasAttribute(d, "@@ignore"));
689
+ }
690
+ getAllTypeDefs(model) {
691
+ return model.declarations.filter((d) => isTypeDef(d) && !hasAttribute(d, "@@ignore"));
692
+ }
693
+ createTypeDefsObject(model, lite) {
694
+ return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
695
+ }
696
+ createDataModelObject(dm, lite) {
697
+ const allFields = getAllFields(dm);
698
+ const allAttributes = lite ? [] : getAllAttributes(dm).filter((attr) => {
699
+ if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) return false;
700
+ return true;
701
+ });
702
+ const subModels = this.getSubModels(dm);
703
+ const fields = [
704
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(dm.name)),
705
+ ...dm.baseModel ? [ts.factory.createPropertyAssignment("baseModel", ts.factory.createStringLiteral(dm.baseModel.$refText))] : [],
706
+ ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm, lite))), true)),
707
+ ...allAttributes.length > 0 ? [ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true)))] : [],
708
+ ts.factory.createPropertyAssignment("idFields", ts.factory.createArrayLiteralExpression(getIdFields(dm).map((idField) => ts.factory.createStringLiteral(idField)))),
709
+ ts.factory.createPropertyAssignment("uniqueFields", this.createUniqueFieldsObject(dm)),
710
+ ...isDelegateModel$1(dm) ? [ts.factory.createPropertyAssignment("isDelegate", ts.factory.createTrue())] : [],
711
+ ...subModels.length > 0 ? [ts.factory.createPropertyAssignment("subModels", ts.factory.createArrayLiteralExpression(subModels.map((subModel) => ts.factory.createStringLiteral(subModel))))] : [],
712
+ ...dm.isView ? [ts.factory.createPropertyAssignment("isView", ts.factory.createTrue())] : []
713
+ ];
714
+ const computedFields = allFields.filter((f) => hasAttribute(f, "@computed") && !getDelegateOriginModel(f, dm));
715
+ if (computedFields.length > 0) fields.push(ts.factory.createPropertyAssignment("computedFields", this.createComputedFieldsObject(computedFields)));
716
+ return ts.factory.createObjectLiteralExpression(fields, true);
717
+ }
718
+ getSubModels(dm) {
719
+ return dm.$container.declarations.filter(isDataModel).filter((d) => d.baseModel?.ref === dm).map((d) => d.name);
720
+ }
721
+ createTypeDefObject(td, lite) {
722
+ const allFields = getAllFields(td);
723
+ const allAttributes = getAllAttributes(td);
724
+ const fields = [
725
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
726
+ ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
727
+ ...allAttributes.length > 0 ? [ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true)))] : []
728
+ ];
729
+ return ts.factory.createObjectLiteralExpression(fields, true);
730
+ }
731
+ createComputedFieldsObject(fields) {
732
+ return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [ts.factory.createParameterDeclaration(void 0, void 0, "_context", void 0, ts.factory.createTypeLiteralNode([ts.factory.createPropertySignature(void 0, "modelAlias", void 0, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))]), void 0)], ts.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type)), ts.factory.createBlock([ts.factory.createThrowStatement(ts.factory.createNewExpression(ts.factory.createIdentifier("Error"), void 0, [ts.factory.createStringLiteral("This is a stub for computed field")]))], true))), true);
733
+ }
734
+ createUpdatedAtObject(ignoreArg) {
735
+ return ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("ignore", ts.factory.createArrayLiteralExpression(ignoreArg.value.items.map((item) => ts.factory.createStringLiteral(item.target.$refText))))]);
736
+ }
737
+ mapFieldTypeToTSType(type) {
738
+ let result = match(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").otherwise(() => "unknown");
739
+ if (type.array) result = `${result}[]`;
740
+ if (type.optional) result = `${result} | null`;
741
+ return result;
742
+ }
743
+ createDataFieldObject(field, contextModel, lite) {
744
+ const objectFields = [ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)), ts.factory.createPropertyAssignment("type", this.generateFieldTypeLiteral(field))];
745
+ if (contextModel && isIdField(field, contextModel)) objectFields.push(ts.factory.createPropertyAssignment("id", ts.factory.createTrue()));
746
+ if (isUniqueField(field)) objectFields.push(ts.factory.createPropertyAssignment("unique", ts.factory.createTrue()));
747
+ if (field.type.optional) objectFields.push(ts.factory.createPropertyAssignment("optional", ts.factory.createTrue()));
748
+ if (field.type.array) objectFields.push(ts.factory.createPropertyAssignment("array", ts.factory.createTrue()));
749
+ const updatedAtAttrib = getAttribute(field, "@updatedAt");
750
+ if (updatedAtAttrib) {
751
+ const ignoreArg = updatedAtAttrib.args.find((arg) => arg.$resolvedParam?.name === "ignore");
752
+ objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ignoreArg ? this.createUpdatedAtObject(ignoreArg) : ts.factory.createTrue()));
753
+ }
754
+ if (hasAttribute(field, "@omit")) objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
755
+ if (contextModel && !isIdField(field, contextModel)) {
756
+ const delegateOrigin = getDelegateOriginModel(field, contextModel);
757
+ if (delegateOrigin) objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(delegateOrigin)));
758
+ }
759
+ if (this.isDiscriminatorField(field)) objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
760
+ if (!lite && field.attributes.length > 0) objectFields.push(ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr))))));
761
+ const defaultValue = this.getFieldMappedDefault(field);
762
+ if (defaultValue !== void 0) {
763
+ let defaultExpr;
764
+ if (defaultValue === null) defaultExpr = this.createExpressionUtilsCall("_null");
765
+ else if (typeof defaultValue === "object" && !Array.isArray(defaultValue)) if ("call" in defaultValue) defaultExpr = this.createExpressionUtilsCall("call", [ts.factory.createStringLiteral(defaultValue.call), ...defaultValue.args.length > 0 ? [ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createExpressionUtilsCall("literal", [this.createLiteralNode(arg)])))] : []]);
766
+ else if ("authMember" in defaultValue) defaultExpr = this.createExpressionUtilsCall("member", [this.createExpressionUtilsCall("call", [ts.factory.createStringLiteral("auth")]), ts.factory.createArrayLiteralExpression(defaultValue.authMember.map((m) => ts.factory.createStringLiteral(m)))]);
767
+ else throw new Error(`Unsupported default value type for field ${field.name}`);
768
+ else if (Array.isArray(defaultValue)) defaultExpr = ts.factory.createArrayLiteralExpression(defaultValue.map((item) => this.createLiteralNode(item)));
769
+ else defaultExpr = this.createLiteralNode(defaultValue);
770
+ objectFields.push(ts.factory.createPropertyAssignment("default", this.createDefaultTypeAssertion(defaultExpr)));
771
+ }
772
+ if (hasAttribute(field, "@computed")) objectFields.push(ts.factory.createPropertyAssignment("computed", ts.factory.createTrue()));
773
+ if (isDataModel(field.type.reference?.ref)) objectFields.push(ts.factory.createPropertyAssignment("relation", this.createRelationObject(field, contextModel)));
774
+ const fkFor = this.getForeignKeyFor(field, contextModel);
775
+ if (fkFor && fkFor.length > 0) objectFields.push(ts.factory.createPropertyAssignment("foreignKeyFor", ts.factory.createAsExpression(ts.factory.createArrayLiteralExpression(fkFor.map((fk) => ts.factory.createStringLiteral(fk)), true), ts.factory.createTypeOperatorNode(ts.SyntaxKind.ReadonlyKeyword, ts.factory.createArrayTypeNode(ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))))));
776
+ return ts.factory.createObjectLiteralExpression(objectFields, true);
777
+ }
778
+ isDiscriminatorField(field) {
779
+ const origin = field.$container;
780
+ return getAttribute(origin, "@@delegate")?.args.some((arg) => arg.$resolvedParam?.name === "discriminator" && isDataFieldReference(arg.value) && arg.value.target.ref === field);
781
+ }
782
+ getDataSourceProvider(model) {
783
+ const dataSource = model.declarations.find(isDataSource);
784
+ invariant(dataSource, "No data source found in the model");
785
+ const providerExpr = dataSource.fields.find((f) => f.name === "provider")?.value;
786
+ invariant(isLiteralExpr(providerExpr) && typeof providerExpr.value === "string", "Provider must be a string literal");
787
+ return providerExpr.value;
788
+ }
789
+ getDataSourceDefaultSchema(model) {
790
+ const dataSource = model.declarations.find(isDataSource);
791
+ invariant(dataSource, "No data source found in the model");
792
+ const defaultSchemaExpr = dataSource.fields.find((f) => f.name === "defaultSchema")?.value;
793
+ if (!defaultSchemaExpr) return;
794
+ invariant(isLiteralExpr(defaultSchemaExpr) && typeof defaultSchemaExpr.value === "string", "Default schema must be a string literal");
795
+ return defaultSchemaExpr.value;
796
+ }
797
+ getFieldMappedDefault(field) {
798
+ const defaultAttr = getAttribute(field, "@default");
799
+ if (!defaultAttr) return;
800
+ const defaultValue = defaultAttr.args[0]?.value;
801
+ invariant(defaultValue, "Expected a default value");
802
+ return this.getMappedValue(defaultValue, field.type);
803
+ }
804
+ getMappedValue(expr, fieldType) {
805
+ if (isLiteralExpr(expr)) {
806
+ const lit = expr.value;
807
+ return fieldType.type === "Boolean" ? lit : [
808
+ "Int",
809
+ "Float",
810
+ "Decimal",
811
+ "BigInt"
812
+ ].includes(fieldType.type) ? Number(lit) : lit;
813
+ } else if (isArrayExpr(expr)) return expr.items.map((item) => this.getMappedValue(item, fieldType));
814
+ else if (isReferenceExpr(expr) && isEnumField(expr.target.ref)) return expr.target.ref.name;
815
+ else if (isInvocationExpr(expr)) return {
816
+ call: expr.function.$refText,
817
+ args: expr.args.map((arg) => this.getLiteral(arg.value))
818
+ };
819
+ else if (this.isAuthMemberAccess(expr)) return { authMember: this.getMemberAccessChain(expr) };
820
+ else if (isNullExpr(expr)) return null;
821
+ else throw new Error(`Unsupported expression type: ${expr.$type}`);
822
+ }
823
+ getMemberAccessChain(expr) {
824
+ if (!isMemberAccessExpr(expr.operand)) return [expr.member.$refText];
825
+ else return [...this.getMemberAccessChain(expr.operand), expr.member.$refText];
826
+ }
827
+ isAuthMemberAccess(expr) {
828
+ if (isMemberAccessExpr(expr)) return this.isAuthInvocation(expr.operand) || this.isAuthMemberAccess(expr.operand);
829
+ else return false;
830
+ }
831
+ isAuthInvocation(expr) {
832
+ return isInvocationExpr(expr) && expr.function.$refText === "auth" && isFromStdlib(expr.function.ref);
833
+ }
834
+ createRelationObject(field, contextModel) {
835
+ const relationFields = [];
836
+ const oppositeRelation = this.getOppositeRelationField(field, contextModel);
837
+ if (oppositeRelation) relationFields.push(ts.factory.createPropertyAssignment("opposite", ts.factory.createStringLiteral(oppositeRelation.name)));
838
+ const relationName = this.getRelationName(field);
839
+ if (relationName) relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
840
+ const relation = getAttribute(field, "@relation");
841
+ const fkFields = [];
842
+ if (relation) for (const arg of relation.args) {
843
+ const param = arg.$resolvedParam?.name;
844
+ if (param === "fields" || param === "references") {
845
+ const fieldNames = this.getReferenceNames(arg.value);
846
+ if (fieldNames) {
847
+ if (param === "fields") fkFields.push(...fieldNames);
848
+ relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
849
+ }
850
+ }
851
+ if (param === "onDelete" || param === "onUpdate") {
852
+ const action = arg.value.target.$refText;
853
+ relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createStringLiteral(action)));
854
+ }
855
+ }
856
+ if (fkFields.length > 0) {
857
+ if (fkFields.every((fieldName) => {
858
+ const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
859
+ return fieldDef && hasAttribute(fieldDef, "@default");
860
+ })) relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
861
+ }
862
+ return ts.factory.createObjectLiteralExpression(relationFields);
863
+ }
864
+ getReferenceNames(expr) {
865
+ return isArrayExpr(expr) && expr.items.map((item) => item.target.$refText);
866
+ }
867
+ getForeignKeyFor(field, contextModel) {
868
+ if (!contextModel) return [];
869
+ const result = [];
870
+ for (const f of getAllFields(contextModel)) {
871
+ const relation = getAttribute(f, "@relation");
872
+ if (relation) {
873
+ for (const arg of relation.args) if (arg.name === "fields" && isArrayExpr(arg.value) && arg.value.items.some((el) => isReferenceExpr(el) && el.target.ref === field)) result.push(f.name);
874
+ }
875
+ }
876
+ return result;
877
+ }
878
+ getOppositeRelationField(field, contextModel) {
879
+ if (!field.type.reference?.ref || !isDataModel(field.type.reference?.ref) || !contextModel) return;
880
+ const sourceModel = isTypeDef(field.$container) ? contextModel : field.$container;
881
+ const targetModel = field.type.reference.ref;
882
+ const relationName = this.getRelationName(field);
883
+ for (const otherField of getAllFields(targetModel)) {
884
+ if (otherField === field) continue;
885
+ if (otherField.type.reference?.ref === sourceModel) if (relationName) {
886
+ if (this.getRelationName(otherField) === relationName) return otherField;
887
+ } else return otherField;
888
+ }
889
+ }
890
+ getRelationName(field) {
891
+ const relation = getAttribute(field, "@relation");
892
+ if (relation) {
893
+ const nameArg = relation.args.find((arg) => arg.$resolvedParam?.name === "name");
894
+ if (nameArg) {
895
+ invariant(isLiteralExpr(nameArg.value), "name must be a literal");
896
+ return nameArg.value.value;
897
+ }
898
+ }
899
+ }
900
+ createUniqueFieldsObject(dm) {
901
+ const properties = [];
902
+ const allFields = getAllFields(dm);
903
+ for (const field of allFields) if (hasAttribute(field, "@id") || hasAttribute(field, "@unique")) properties.push(ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("type", this.generateFieldTypeLiteral(field))])));
904
+ const allAttributes = getAllAttributes(dm);
905
+ const seenKeys = /* @__PURE__ */ new Set();
906
+ for (const attr of allAttributes) if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
907
+ const fieldsArg = getAttributeArg(attr, "fields");
908
+ if (!fieldsArg) continue;
909
+ const fieldNames = this.getReferenceNames(fieldsArg);
910
+ if (!fieldNames) continue;
911
+ if (fieldNames.length === 1) {
912
+ const fieldDef = allFields.find((f) => f.name === fieldNames[0]);
913
+ properties.push(ts.factory.createPropertyAssignment(fieldNames[0], ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("type", this.generateFieldTypeLiteral(fieldDef))])));
914
+ } else {
915
+ const key = this.getCompoundUniqueKey(attr, fieldNames);
916
+ if (seenKeys.has(key)) continue;
917
+ seenKeys.add(key);
918
+ properties.push(ts.factory.createPropertyAssignment(key, ts.factory.createObjectLiteralExpression(fieldNames.map((field) => {
919
+ const fieldDef = allFields.find((f) => f.name === field);
920
+ return ts.factory.createPropertyAssignment(field, ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("type", this.generateFieldTypeLiteral(fieldDef))]));
921
+ }))));
922
+ }
923
+ }
924
+ return ts.factory.createObjectLiteralExpression(properties, true);
925
+ }
926
+ getCompoundUniqueKey(attr, fieldNames) {
927
+ const nameArg = attr.args.find((arg) => arg.$resolvedParam?.name === "name");
928
+ if (nameArg && isLiteralExpr(nameArg.value)) return nameArg.value.value;
929
+ else return fieldNames.join("_");
930
+ }
931
+ generateFieldTypeLiteral(field) {
932
+ invariant(field.type.type || field.type.reference || field.type.unsupported, "Field type must be a primitive, reference, or Unsupported");
933
+ return field.type.type ? ts.factory.createStringLiteral(field.type.type) : field.type.reference ? ts.factory.createStringLiteral(field.type.reference.$refText) : ts.factory.createStringLiteral("Unsupported");
934
+ }
935
+ createEnumObject(e) {
936
+ return ts.factory.createObjectLiteralExpression([
937
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(e.name)),
938
+ ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
939
+ ...e.fields.some((f) => f.attributes.length > 0) ? [ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)), ...field.attributes.length > 0 ? [ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(field.attributes?.map((attr) => this.createAttributeObject(attr)) ?? [], true)))] : []], true))), true))] : [],
940
+ ...e.attributes.length > 0 ? [ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(e.attributes.map((attr) => this.createAttributeObject(attr)), true)))] : []
941
+ ], true);
942
+ }
943
+ getLiteral(expr) {
944
+ if (!isLiteralExpr(expr)) throw new Error("Expected a literal expression");
945
+ switch (expr?.$type) {
946
+ case "StringLiteral":
947
+ case "BooleanLiteral": return expr.value;
948
+ case "NumberLiteral": return parseFloat(expr.value);
949
+ default: throw new Error("Unsupported literal type");
950
+ }
951
+ }
952
+ createLiteralNode(arg) {
953
+ 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;
954
+ }
955
+ createNumberLiteral(arg) {
956
+ return arg < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-arg)) : ts.factory.createNumericLiteral(arg);
957
+ }
958
+ createProceduresObject(procedures) {
959
+ return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
960
+ }
961
+ createProcedureObject(proc) {
962
+ const params = ts.factory.createObjectLiteralExpression(proc.params.map((param) => ts.factory.createPropertyAssignment(param.name, ts.factory.createObjectLiteralExpression([
963
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(param.name)),
964
+ ...param.optional ? [ts.factory.createPropertyAssignment("optional", ts.factory.createTrue())] : [],
965
+ ...param.type.array ? [ts.factory.createPropertyAssignment("array", ts.factory.createTrue())] : [],
966
+ ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(param.type.type ?? param.type.reference.$refText))
967
+ ]))), true);
968
+ return ts.factory.createObjectLiteralExpression([
969
+ ts.factory.createPropertyAssignment("params", params),
970
+ ts.factory.createPropertyAssignment("returnType", ts.factory.createStringLiteral(proc.returnType.type ?? proc.returnType.reference.$refText)),
971
+ ...proc.returnType.array ? [ts.factory.createPropertyAssignment("returnArray", ts.factory.createTrue())] : [],
972
+ ...proc.mutation ? [ts.factory.createPropertyAssignment("mutation", ts.factory.createTrue())] : []
973
+ ], true);
974
+ }
975
+ generateBannerComments(statements) {
976
+ ts.addSyntheticLeadingComment(statements[0], ts.SyntaxKind.SingleLineCommentTrivia, `////////////////////////////////////////////////////////////////////////////////////////////
977
+ // DO NOT MODIFY THIS FILE //
978
+ // This file is automatically generated by ZenStack CLI and should not be manually updated. //
979
+ //////////////////////////////////////////////////////////////////////////////////////////////
980
+
981
+ /* eslint-disable */
982
+
983
+ `);
984
+ }
985
+ createAttributeObject(attr) {
986
+ return ts.factory.createObjectLiteralExpression([ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(attr.decl.$refText)), ...attr.args.length > 0 ? [ts.factory.createPropertyAssignment("args", ts.factory.createArrayLiteralExpression(attr.args.map((arg) => this.createAttributeArg(arg))))] : []]);
987
+ }
988
+ createAttributeArg(arg) {
989
+ return ts.factory.createObjectLiteralExpression([...arg.$resolvedParam?.name ? [ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(arg.$resolvedParam.name))] : [], ts.factory.createPropertyAssignment("value", this.createExpression(arg.value))]);
990
+ }
991
+ createExpression(value) {
992
+ return match(value).when(isLiteralExpr, (expr) => this.createLiteralExpression(expr.$type, expr.value)).when(isInvocationExpr, (expr) => this.createCallExpression(expr)).when(isReferenceExpr, (expr) => this.createRefExpression(expr)).when(isArrayExpr, (expr) => this.createArrayExpression(expr)).when(isUnaryExpr, (expr) => this.createUnaryExpression(expr)).when(isBinaryExpr, (expr) => this.createBinaryExpression(expr)).when(isMemberAccessExpr, (expr) => this.createMemberExpression(expr)).when(isNullExpr, () => this.createNullExpression()).when(isThisExpr, () => this.createThisExpression()).otherwise(() => {
993
+ throw new Error(`Unsupported attribute arg value: ${value.$type}`);
994
+ });
995
+ }
996
+ createThisExpression() {
997
+ return this.createExpressionUtilsCall("_this");
998
+ }
999
+ createMemberExpression(expr) {
1000
+ const members = [];
1001
+ let current = expr;
1002
+ while (isMemberAccessExpr(current)) {
1003
+ members.unshift(current.member.$refText);
1004
+ current = current.operand;
1005
+ }
1006
+ const receiver = current;
1007
+ const args = [this.createExpression(receiver), ts.factory.createArrayLiteralExpression(members.map((m) => ts.factory.createStringLiteral(m)))];
1008
+ return this.createExpressionUtilsCall("member", args);
1009
+ }
1010
+ createNullExpression() {
1011
+ return this.createExpressionUtilsCall("_null");
1012
+ }
1013
+ createBinaryExpression(expr) {
1014
+ const args = [
1015
+ this.createExpression(expr.left),
1016
+ this.createLiteralNode(expr.operator),
1017
+ this.createExpression(expr.right)
1018
+ ];
1019
+ if (expr.binding) args.push(this.createLiteralNode(expr.binding.name));
1020
+ return this.createExpressionUtilsCall("binary", args);
1021
+ }
1022
+ createUnaryExpression(expr) {
1023
+ return this.createExpressionUtilsCall("unary", [this.createLiteralNode(expr.operator), this.createExpression(expr.operand)]);
1024
+ }
1025
+ createArrayExpression(expr) {
1026
+ const arrayResolved = expr.$resolvedType?.decl;
1027
+ const arrayType = typeof arrayResolved === "string" ? arrayResolved : arrayResolved?.name;
1028
+ invariant(arrayType, "Array type must be resolved to a string or declaration");
1029
+ return this.createExpressionUtilsCall("array", [this.createLiteralNode(arrayType), ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))]);
1030
+ }
1031
+ createRefExpression(expr) {
1032
+ const target = expr.target.ref;
1033
+ return match(target).when(isDataField, () => this.createExpressionUtilsCall("field", [this.createLiteralNode(expr.target.$refText)])).when(isEnumField, () => this.createLiteralExpression("StringLiteral", expr.target.$refText)).when(isCollectionPredicateBinding, () => this.createExpressionUtilsCall("binding", [this.createLiteralNode(expr.target.$refText)])).otherwise(() => {
1034
+ throw Error(`Unsupported reference type: ${expr.target.$refText}`);
1035
+ });
1036
+ }
1037
+ createCallExpression(expr) {
1038
+ return this.createExpressionUtilsCall("call", [ts.factory.createStringLiteral(expr.function.$refText), ...expr.args.length > 0 ? [ts.factory.createArrayLiteralExpression(expr.args.map((arg) => this.createExpression(arg.value)))] : []]);
1039
+ }
1040
+ createLiteralExpression(type, value) {
1041
+ return match(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [this.createLiteralNode(value)])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [ts.factory.createIdentifier(value)])).with("StringLiteral", () => this.createExpressionUtilsCall("literal", [this.createLiteralNode(value)])).otherwise(() => {
1042
+ throw new Error(`Unsupported literal type: ${type}`);
1043
+ });
1044
+ }
1045
+ generateModelsAndTypeDefs(model, options) {
1046
+ const statements = [];
1047
+ statements.push(this.generateSchemaImport(model, true, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
1048
+ statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)), ...model.declarations.some(isTypeDef) ? [ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))] : []])), ts.factory.createStringLiteral("@zenstackhq/orm")));
1049
+ const dataModels = this.getAllDataModels(model);
1050
+ for (const dm of dataModels) {
1051
+ let modelType = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], dm.name, void 0, ts.factory.createTypeReferenceNode("$ModelResult", [ts.factory.createTypeReferenceNode("$Schema"), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name))]));
1052
+ if (dm.comments.length > 0) modelType = this.generateDocs(modelType, dm);
1053
+ statements.push(modelType);
1054
+ }
1055
+ const typeDefs = this.getAllTypeDefs(model);
1056
+ for (const td of typeDefs) {
1057
+ let typeDef = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], td.name, void 0, ts.factory.createTypeReferenceNode("$TypeDefResult", [ts.factory.createTypeReferenceNode("$Schema"), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(td.name))]));
1058
+ if (td.comments.length > 0) typeDef = this.generateDocs(typeDef, td);
1059
+ statements.push(typeDef);
1060
+ }
1061
+ const enums = model.declarations.filter(isEnum);
1062
+ for (const e of enums) {
1063
+ let enumDecl = ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([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")))], ts.NodeFlags.Const));
1064
+ if (e.comments.length > 0) enumDecl = this.generateDocs(enumDecl, e);
1065
+ statements.push(enumDecl);
1066
+ let typeAlias = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], e.name, void 0, ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeQueryNode(ts.factory.createIdentifier(e.name)), ts.factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, ts.factory.createTypeQueryNode(ts.factory.createIdentifier(e.name)))));
1067
+ if (e.comments.length > 0) typeAlias = this.generateDocs(typeAlias, e);
1068
+ statements.push(typeAlias);
1069
+ }
1070
+ this.generateBannerComments(statements);
1071
+ const outputFile = path.join(options.outDir, "models.ts");
1072
+ const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
1073
+ const result = ts.createPrinter().printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
1074
+ fs.writeFileSync(outputFile, result);
1075
+ }
1076
+ generateSchemaImport(model, schemaObject, schemaType, useLite, importWithFileExtension) {
1077
+ const importSpecifiers = [];
1078
+ if (schemaObject) {
1079
+ if (model.declarations.some(isEnum)) importSpecifiers.push(ts.factory.createImportSpecifier(false, ts.factory.createIdentifier("schema"), ts.factory.createIdentifier("$schema")));
1080
+ }
1081
+ if (schemaType) importSpecifiers.push(ts.factory.createImportSpecifier(true, ts.factory.createIdentifier("SchemaType"), ts.factory.createIdentifier("$Schema")));
1082
+ let importFrom = useLite ? "./schema-lite" : "./schema";
1083
+ if (importWithFileExtension) importFrom += importWithFileExtension.startsWith(".") ? importWithFileExtension : `.${importWithFileExtension}`;
1084
+ return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral(importFrom));
1085
+ }
1086
+ generateDocs(tsDecl, decl) {
1087
+ return ts.addSyntheticLeadingComment(tsDecl, ts.SyntaxKind.MultiLineCommentTrivia, `*\n * ${decl.comments.map((c) => c.replace(/^\s*\/*\s*/, "")).join("\n * ")}\n `, true);
1088
+ }
1089
+ generateInputTypes(model, options) {
1090
+ const dataModels = this.getAllDataModels(model);
1091
+ const statements = [];
1092
+ statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
1093
+ const inputTypes = [
1094
+ "FindManyArgs",
1095
+ "FindUniqueArgs",
1096
+ "FindFirstArgs",
1097
+ "ExistsArgs",
1098
+ "CreateArgs",
1099
+ "CreateManyArgs",
1100
+ "CreateManyAndReturnArgs",
1101
+ "UpdateArgs",
1102
+ "UpdateManyArgs",
1103
+ "UpdateManyAndReturnArgs",
1104
+ "UpsertArgs",
1105
+ "DeleteArgs",
1106
+ "DeleteManyArgs",
1107
+ "CountArgs",
1108
+ "AggregateArgs",
1109
+ "GroupByArgs",
1110
+ "WhereInput",
1111
+ "SelectInput",
1112
+ "IncludeInput",
1113
+ "OmitInput"
1114
+ ];
1115
+ const inputTypeNameFixes = {
1116
+ SelectInput: "Select",
1117
+ IncludeInput: "Include",
1118
+ OmitInput: "Omit"
1119
+ };
1120
+ 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.createImportSpecifier(false, void 0, ts.factory.createIdentifier("QueryOptions as $QueryOptions"))])), ts.factory.createStringLiteral("@zenstackhq/orm")));
1121
+ statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedPlainResult as $Result")), ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))])), ts.factory.createStringLiteral("@zenstackhq/orm")));
1122
+ for (const dm of dataModels) {
1123
+ for (const inputType of inputTypes) {
1124
+ const exportName = inputTypeNameFixes[inputType] ? `${dm.name}${inputTypeNameFixes[inputType]}` : `${dm.name}${inputType}`;
1125
+ statements.push(ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], exportName, void 0, ts.factory.createTypeReferenceNode(`$${inputType}`, [ts.factory.createTypeReferenceNode("$Schema"), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name))])));
1126
+ }
1127
+ statements.push(ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], `${dm.name}GetPayload`, [ts.factory.createTypeParameterDeclaration(void 0, "Args", ts.factory.createTypeReferenceNode("$SelectIncludeOmit", [
1128
+ ts.factory.createTypeReferenceNode("$Schema"),
1129
+ ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
1130
+ ts.factory.createLiteralTypeNode(ts.factory.createTrue())
1131
+ ])), ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$QueryOptions", [ts.factory.createTypeReferenceNode("$Schema")]), ts.factory.createTypeReferenceNode("$QueryOptions", [ts.factory.createTypeReferenceNode("$Schema")]))], ts.factory.createTypeReferenceNode("$Result", [
1132
+ ts.factory.createTypeReferenceNode("$Schema"),
1133
+ ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
1134
+ ts.factory.createTypeReferenceNode("Args"),
1135
+ ts.factory.createTypeReferenceNode("Options")
1136
+ ])));
1137
+ }
1138
+ this.generateBannerComments(statements);
1139
+ const outputFile = path.join(options.outDir, "input.ts");
1140
+ const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
1141
+ const result = ts.createPrinter().printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
1142
+ fs.writeFileSync(outputFile, result);
1143
+ }
1144
+ };
1145
+ //#endregion
1146
+ export { model_utils_exports as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator };
1147
+
1148
+ //# sourceMappingURL=index.mjs.map