@bairock/lenz 0.0.16 → 0.0.17

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 (30) hide show
  1. package/README.md +107 -15
  2. package/dist/cli/commands/generate/crud.d.ts +3 -0
  3. package/dist/cli/commands/generate/crud.d.ts.map +1 -0
  4. package/dist/cli/commands/generate/crud.js +123 -0
  5. package/dist/cli/commands/generate/crud.js.map +1 -0
  6. package/dist/cli/commands/generate/index.d.ts +3 -0
  7. package/dist/cli/commands/generate/index.d.ts.map +1 -0
  8. package/dist/cli/commands/generate/index.js +8 -0
  9. package/dist/cli/commands/generate/index.js.map +1 -0
  10. package/dist/cli/commands/generate/orm.d.ts +3 -0
  11. package/dist/cli/commands/generate/orm.d.ts.map +1 -0
  12. package/dist/cli/commands/generate/orm.js +107 -0
  13. package/dist/cli/commands/generate/orm.js.map +1 -0
  14. package/dist/cli/index.js +1 -1
  15. package/dist/cli/index.js.map +1 -1
  16. package/dist/engine/CodeGenerator.d.ts +1 -0
  17. package/dist/engine/CodeGenerator.d.ts.map +1 -1
  18. package/dist/engine/CodeGenerator.js +3 -0
  19. package/dist/engine/CodeGenerator.js.map +1 -1
  20. package/dist/engine/generators/CrudModuleGenerator.d.ts +10 -0
  21. package/dist/engine/generators/CrudModuleGenerator.d.ts.map +1 -0
  22. package/dist/engine/generators/CrudModuleGenerator.js +141 -0
  23. package/dist/engine/generators/CrudModuleGenerator.js.map +1 -0
  24. package/dist/engine/generators/SDLInputTypesGenerator.d.ts +6 -0
  25. package/dist/engine/generators/SDLInputTypesGenerator.d.ts.map +1 -0
  26. package/dist/engine/generators/SDLInputTypesGenerator.js +763 -0
  27. package/dist/engine/generators/SDLInputTypesGenerator.js.map +1 -0
  28. package/dist/index.js +1 -1
  29. package/dist/index.js.map +1 -1
  30. package/package.json +9 -3
@@ -0,0 +1,763 @@
1
+ // ===== Helpers =====
2
+ function isEnum(type, enums) {
3
+ return enums.some(e => e.name === type);
4
+ }
5
+ function getFilterName(type, isRequired, enums) {
6
+ if (isEnum(type, enums))
7
+ return isRequired ? `Enum${type}Filter` : `Enum${type}NullableFilter`;
8
+ switch (type) {
9
+ case 'String': return isRequired ? 'StringFilter' : 'StringNullableFilter';
10
+ case 'Int': return isRequired ? 'IntFilter' : 'IntNullableFilter';
11
+ case 'Float': return isRequired ? 'FloatFilter' : 'FloatNullableFilter';
12
+ case 'Boolean': return isRequired ? 'BooleanFilter' : 'BooleanNullableFilter';
13
+ case 'DateTime':
14
+ case 'Date': return isRequired ? 'DateTimeFilter' : 'DateTimeNullableFilter';
15
+ case 'ID': return 'IDFilter';
16
+ case 'Json': return 'JsonFilter';
17
+ case 'BigInt': return isRequired ? 'BigIntFilter' : 'BigIntNullableFilter';
18
+ case 'Bytes': return isRequired ? 'BytesFilter' : 'BytesNullableFilter';
19
+ case 'ObjectId': return isRequired ? 'StringFilter' : 'StringNullableFilter';
20
+ default: return isRequired ? 'StringFilter' : 'StringNullableFilter';
21
+ }
22
+ }
23
+ function getWithAggregatesFilterName(type, isRequired, enums) {
24
+ if (isEnum(type, enums))
25
+ return isRequired ? `Enum${type}WithAggregatesFilter` : `Enum${type}NullableWithAggregatesFilter`;
26
+ switch (type) {
27
+ case 'String': return isRequired ? 'StringWithAggregatesFilter' : 'StringNullableWithAggregatesFilter';
28
+ case 'Int': return isRequired ? 'IntWithAggregatesFilter' : 'IntNullableWithAggregatesFilter';
29
+ case 'Float': return isRequired ? 'FloatWithAggregatesFilter' : 'FloatNullableWithAggregatesFilter';
30
+ case 'Boolean': return isRequired ? 'BooleanWithAggregatesFilter' : 'BooleanNullableWithAggregatesFilter';
31
+ case 'DateTime':
32
+ case 'Date': return isRequired ? 'DateTimeWithAggregatesFilter' : 'DateTimeNullableWithAggregatesFilter';
33
+ case 'ID': return 'IDFilter';
34
+ case 'Json': return 'JsonFilter';
35
+ case 'BigInt': return isRequired ? 'BigIntWithAggregatesFilter' : 'BigIntNullableWithAggregatesFilter';
36
+ case 'Bytes': return isRequired ? 'BytesWithAggregatesFilter' : 'BytesNullableWithAggregatesFilter';
37
+ case 'ObjectId': return isRequired ? 'StringWithAggregatesFilter' : 'StringNullableWithAggregatesFilter';
38
+ default: return isRequired ? 'StringWithAggregatesFilter' : 'StringNullableWithAggregatesFilter';
39
+ }
40
+ }
41
+ function getArrayFilterName(type) {
42
+ switch (type) {
43
+ case 'String': return 'StringArrayFilter';
44
+ case 'Int': return 'IntArrayFilter';
45
+ case 'Float': return 'FloatArrayFilter';
46
+ case 'Boolean': return 'BooleanArrayFilter';
47
+ case 'DateTime':
48
+ case 'Date': return 'DateTimeArrayFilter';
49
+ case 'BigInt': return 'BigIntArrayFilter';
50
+ case 'Bytes': return 'BytesArrayFilter';
51
+ default: return 'StringArrayFilter';
52
+ }
53
+ }
54
+ // ===== SDL Snippets =====
55
+ function sdlScalars() {
56
+ return 'scalar DateTime';
57
+ }
58
+ function sdlBatchPayload() {
59
+ return 'type BatchPayload {\n count: Int!\n}';
60
+ }
61
+ function sdlSortEnums() {
62
+ return `enum SortOrder {
63
+ asc
64
+ desc
65
+ }
66
+
67
+ enum QueryMode {
68
+ default
69
+ insensitive
70
+ }
71
+
72
+ enum NullsOrder {
73
+ first
74
+ last
75
+ }`;
76
+ }
77
+ function sdlSortOrderInput() {
78
+ return `input SortOrderInput {
79
+ sort: SortOrder!
80
+ nulls: NullsOrder
81
+ }`;
82
+ }
83
+ function sdlBaseFilters() {
84
+ return `input StringFilter {
85
+ equals: String
86
+ not: String
87
+ in: [String!]
88
+ notIn: [String!]
89
+ lt: String
90
+ lte: String
91
+ gt: String
92
+ gte: String
93
+ contains: String
94
+ startsWith: String
95
+ endsWith: String
96
+ mode: QueryMode
97
+ }
98
+
99
+ input StringNullableFilter {
100
+ equals: String
101
+ not: String
102
+ in: [String!]
103
+ notIn: [String!]
104
+ lt: String
105
+ lte: String
106
+ gt: String
107
+ gte: String
108
+ contains: String
109
+ startsWith: String
110
+ endsWith: String
111
+ mode: QueryMode
112
+ }
113
+
114
+ input IntFilter {
115
+ equals: Int
116
+ not: Int
117
+ in: [Int!]
118
+ notIn: [Int!]
119
+ lt: Int
120
+ lte: Int
121
+ gt: Int
122
+ gte: Int
123
+ }
124
+
125
+ input IntNullableFilter {
126
+ equals: Int
127
+ not: Int
128
+ in: [Int!]
129
+ notIn: [Int!]
130
+ lt: Int
131
+ lte: Int
132
+ gt: Int
133
+ gte: Int
134
+ }
135
+
136
+ input FloatFilter {
137
+ equals: Float
138
+ not: Float
139
+ in: [Float!]
140
+ notIn: [Float!]
141
+ lt: Float
142
+ lte: Float
143
+ gt: Float
144
+ gte: Float
145
+ }
146
+
147
+ input FloatNullableFilter {
148
+ equals: Float
149
+ not: Float
150
+ in: [Float!]
151
+ notIn: [Float!]
152
+ lt: Float
153
+ lte: Float
154
+ gt: Float
155
+ gte: Float
156
+ }
157
+
158
+ input BooleanFilter {
159
+ equals: Boolean
160
+ not: Boolean
161
+ }
162
+
163
+ input BooleanNullableFilter {
164
+ equals: Boolean
165
+ not: Boolean
166
+ }
167
+
168
+ input DateTimeFilter {
169
+ equals: DateTime
170
+ not: DateTime
171
+ in: [DateTime!]
172
+ notIn: [DateTime!]
173
+ lt: DateTime
174
+ lte: DateTime
175
+ gt: DateTime
176
+ gte: DateTime
177
+ }
178
+
179
+ input DateTimeNullableFilter {
180
+ equals: DateTime
181
+ not: DateTime
182
+ in: [DateTime!]
183
+ notIn: [DateTime!]
184
+ lt: DateTime
185
+ lte: DateTime
186
+ gt: DateTime
187
+ gte: DateTime
188
+ }
189
+
190
+ input IDFilter {
191
+ equals: String
192
+ not: String
193
+ in: [String!]
194
+ notIn: [String!]
195
+ }
196
+
197
+ input JsonFilter {
198
+ equals: JSON
199
+ not: JSON
200
+ path: [String!]
201
+ string_contains: String
202
+ string_starts_with: String
203
+ string_ends_with: String
204
+ array_contains: JSON
205
+ array_starts_with: JSON
206
+ array_ends_with: JSON
207
+ }
208
+
209
+ input BigIntFilter {
210
+ equals: BigInt
211
+ not: BigInt
212
+ in: [BigInt!]
213
+ notIn: [BigInt!]
214
+ lt: BigInt
215
+ lte: BigInt
216
+ gt: BigInt
217
+ gte: BigInt
218
+ }
219
+
220
+ input BigIntNullableFilter {
221
+ equals: BigInt
222
+ not: BigInt
223
+ in: [BigInt!]
224
+ notIn: [BigInt!]
225
+ lt: BigInt
226
+ lte: BigInt
227
+ gt: BigInt
228
+ gte: BigInt
229
+ }
230
+
231
+ input BytesFilter {
232
+ equals: Bytes
233
+ not: Bytes
234
+ in: [Bytes!]
235
+ notIn: [Bytes!]
236
+ }
237
+
238
+ input BytesNullableFilter {
239
+ equals: Bytes
240
+ not: Bytes
241
+ in: [Bytes!]
242
+ notIn: [Bytes!]
243
+ }`;
244
+ }
245
+ function sdlArrayFilters() {
246
+ return `input StringArrayFilter {
247
+ has: String
248
+ hasEvery: [String!]
249
+ hasSome: [String!]
250
+ isEmpty: Boolean
251
+ equals: [String!]
252
+ }
253
+
254
+ input IntArrayFilter {
255
+ has: Int
256
+ hasEvery: [Int!]
257
+ hasSome: [Int!]
258
+ isEmpty: Boolean
259
+ equals: [Int!]
260
+ }
261
+
262
+ input FloatArrayFilter {
263
+ has: Float
264
+ hasEvery: [Float!]
265
+ hasSome: [Float!]
266
+ isEmpty: Boolean
267
+ equals: [Float!]
268
+ }
269
+
270
+ input DateTimeArrayFilter {
271
+ has: DateTime
272
+ hasEvery: [DateTime!]
273
+ hasSome: [DateTime!]
274
+ isEmpty: Boolean
275
+ equals: [DateTime!]
276
+ }
277
+
278
+ input BigIntArrayFilter {
279
+ has: BigInt
280
+ hasEvery: [BigInt!]
281
+ hasSome: [BigInt!]
282
+ isEmpty: Boolean
283
+ equals: [BigInt!]
284
+ }
285
+
286
+ input BytesArrayFilter {
287
+ has: Bytes
288
+ hasEvery: [Bytes!]
289
+ hasSome: [Bytes!]
290
+ isEmpty: Boolean
291
+ equals: [Bytes!]
292
+ }`;
293
+ }
294
+ function sdlWithAggregatesFilters() {
295
+ return `input StringWithAggregatesFilter {
296
+ equals: String
297
+ not: String
298
+ in: [String!]
299
+ notIn: [String!]
300
+ lt: String
301
+ lte: String
302
+ gt: String
303
+ gte: String
304
+ contains: String
305
+ startsWith: String
306
+ endsWith: String
307
+ mode: QueryMode
308
+ _count: IntFilter
309
+ _min: StringFilter
310
+ _max: StringFilter
311
+ }
312
+
313
+ input StringNullableWithAggregatesFilter {
314
+ equals: String
315
+ not: String
316
+ in: [String!]
317
+ notIn: [String!]
318
+ lt: String
319
+ lte: String
320
+ gt: String
321
+ gte: String
322
+ contains: String
323
+ startsWith: String
324
+ endsWith: String
325
+ mode: QueryMode
326
+ _count: IntFilter
327
+ _min: StringFilter
328
+ _max: StringFilter
329
+ }
330
+
331
+ input IntWithAggregatesFilter {
332
+ equals: Int
333
+ not: Int
334
+ in: [Int!]
335
+ notIn: [Int!]
336
+ lt: Int
337
+ lte: Int
338
+ gt: Int
339
+ gte: Int
340
+ _count: IntFilter
341
+ _avg: FloatFilter
342
+ _sum: IntFilter
343
+ _min: IntFilter
344
+ _max: IntFilter
345
+ }
346
+
347
+ input IntNullableWithAggregatesFilter {
348
+ equals: Int
349
+ not: Int
350
+ in: [Int!]
351
+ notIn: [Int!]
352
+ lt: Int
353
+ lte: Int
354
+ gt: Int
355
+ gte: Int
356
+ _count: IntFilter
357
+ _avg: FloatFilter
358
+ _sum: IntFilter
359
+ _min: IntFilter
360
+ _max: IntFilter
361
+ }
362
+
363
+ input FloatWithAggregatesFilter {
364
+ equals: Float
365
+ not: Float
366
+ in: [Float!]
367
+ notIn: [Float!]
368
+ lt: Float
369
+ lte: Float
370
+ gt: Float
371
+ gte: Float
372
+ _count: IntFilter
373
+ _avg: FloatFilter
374
+ _sum: FloatFilter
375
+ _min: FloatFilter
376
+ _max: FloatFilter
377
+ }
378
+
379
+ input FloatNullableWithAggregatesFilter {
380
+ equals: Float
381
+ not: Float
382
+ in: [Float!]
383
+ notIn: [Float!]
384
+ lt: Float
385
+ lte: Float
386
+ gt: Float
387
+ gte: Float
388
+ _count: IntFilter
389
+ _avg: FloatFilter
390
+ _sum: FloatFilter
391
+ _min: FloatFilter
392
+ _max: FloatFilter
393
+ }
394
+
395
+ input BooleanWithAggregatesFilter {
396
+ equals: Boolean
397
+ not: Boolean
398
+ _count: IntFilter
399
+ _min: BooleanFilter
400
+ _max: BooleanFilter
401
+ }
402
+
403
+ input BooleanNullableWithAggregatesFilter {
404
+ equals: Boolean
405
+ not: Boolean
406
+ _count: IntFilter
407
+ _min: BooleanFilter
408
+ _max: BooleanFilter
409
+ }
410
+
411
+ input DateTimeWithAggregatesFilter {
412
+ equals: DateTime
413
+ not: DateTime
414
+ in: [DateTime!]
415
+ notIn: [DateTime!]
416
+ lt: DateTime
417
+ lte: DateTime
418
+ gt: DateTime
419
+ gte: DateTime
420
+ _count: IntFilter
421
+ _min: DateTimeFilter
422
+ _max: DateTimeFilter
423
+ }
424
+
425
+ input DateTimeNullableWithAggregatesFilter {
426
+ equals: DateTime
427
+ not: DateTime
428
+ in: [DateTime!]
429
+ notIn: [DateTime!]
430
+ lt: DateTime
431
+ lte: DateTime
432
+ gt: DateTime
433
+ gte: DateTime
434
+ _count: IntFilter
435
+ _min: DateTimeFilter
436
+ _max: DateTimeFilter
437
+ }
438
+
439
+ input BigIntWithAggregatesFilter {
440
+ equals: BigInt
441
+ not: BigInt
442
+ in: [BigInt!]
443
+ notIn: [BigInt!]
444
+ lt: BigInt
445
+ lte: BigInt
446
+ gt: BigInt
447
+ gte: BigInt
448
+ _count: IntFilter
449
+ _avg: FloatFilter
450
+ _sum: BigIntFilter
451
+ _min: BigIntFilter
452
+ _max: BigIntFilter
453
+ }
454
+
455
+ input BigIntNullableWithAggregatesFilter {
456
+ equals: BigInt
457
+ not: BigInt
458
+ in: [BigInt!]
459
+ notIn: [BigInt!]
460
+ lt: BigInt
461
+ lte: BigInt
462
+ gt: BigInt
463
+ gte: BigInt
464
+ _count: IntFilter
465
+ _avg: FloatFilter
466
+ _sum: BigIntFilter
467
+ _min: BigIntFilter
468
+ _max: BigIntFilter
469
+ }
470
+
471
+ input BytesWithAggregatesFilter {
472
+ equals: Bytes
473
+ not: Bytes
474
+ in: [Bytes!]
475
+ notIn: [Bytes!]
476
+ _count: IntFilter
477
+ _min: BytesFilter
478
+ _max: BytesFilter
479
+ }
480
+
481
+ input BytesNullableWithAggregatesFilter {
482
+ equals: Bytes
483
+ not: Bytes
484
+ in: [Bytes!]
485
+ notIn: [Bytes!]
486
+ _count: IntFilter
487
+ _min: BytesFilter
488
+ _max: BytesFilter
489
+ }`;
490
+ }
491
+ function sdlRelationFilters() {
492
+ return `input RelationFilter {
493
+ is: JSON
494
+ isNot: JSON
495
+ }
496
+
497
+ input ListRelationFilter {
498
+ every: JSON
499
+ some: JSON
500
+ none: JSON
501
+ }
502
+
503
+ input <Model>OrderByRelationAggregateInput {
504
+ _count: SortOrder
505
+ }`;
506
+ }
507
+ // ===== Per-model generators =====
508
+ function sdlModelScalarFieldEnum(model) {
509
+ const scalars = model.fields.filter(f => !f.isRelation && !f.isIgnored);
510
+ return `enum ${model.name}ScalarFieldEnum {\n${scalars.map(f => ` ${f.name}`).join('\n')}\n}`;
511
+ }
512
+ function sdlWhereInput(model, allModels, enums) {
513
+ const fields = [];
514
+ fields.push(' AND: [JSON]');
515
+ fields.push(' OR: [JSON]');
516
+ fields.push(' NOT: [JSON]');
517
+ fields.push(' id: IDFilter');
518
+ for (const field of model.fields) {
519
+ if (field.isId)
520
+ continue;
521
+ if (field.isIgnored)
522
+ continue;
523
+ // Skip cross-collection relation fields
524
+ const isCrossCollectionRelation = field.isRelation && !allModels.find(m => m.name === field.type && m.isEmbedded);
525
+ if (isCrossCollectionRelation)
526
+ continue;
527
+ // Embedded model fields
528
+ const embeddedModel = allModels.find(m => m.name === field.type && m.isEmbedded);
529
+ if (embeddedModel) {
530
+ if (field.isArray) {
531
+ fields.push(` ${field.name}: JSON`);
532
+ }
533
+ else {
534
+ fields.push(` ${field.name}: ${embeddedModel.name}WhereInput`);
535
+ }
536
+ continue;
537
+ }
538
+ // Array scalar fields
539
+ if (field.isArray && !field.isRelation) {
540
+ const filterType = getArrayFilterName(field.type);
541
+ fields.push(` ${field.name}: ${filterType}`);
542
+ continue;
543
+ }
544
+ // Regular scalar fields
545
+ const filterType = getFilterName(field.type, field.isRequired, enums);
546
+ fields.push(` ${field.name}: ${filterType}`);
547
+ }
548
+ // Relation filters
549
+ for (const rel of model.relations) {
550
+ const targetModel = allModels.find(m => m.name === rel.target);
551
+ if (targetModel && !targetModel.isEmbedded) {
552
+ if (rel.type === 'oneToMany' || rel.type === 'manyToMany') {
553
+ fields.push(` ${rel.field}: ListRelationFilter`);
554
+ }
555
+ else {
556
+ fields.push(` ${rel.field}: RelationFilter`);
557
+ }
558
+ }
559
+ }
560
+ // Fulltext search
561
+ if (model.fulltextFields && model.fulltextFields.length > 0) {
562
+ fields.push(' search: String');
563
+ }
564
+ return `input ${model.name}WhereInput {\n${fields.join('\n')}\n}`;
565
+ }
566
+ function sdlOrderByWithRelationInput(model, allModels) {
567
+ const fields = [];
568
+ // Sortable scalar fields (no Json, no Bytes — they can't be sorted by)
569
+ const sortableFields = model.fields.filter(f => !f.isRelation && !f.isIgnored && f.type !== 'Json' && f.type !== 'Bytes' && f.type !== 'BigInt');
570
+ for (const f of sortableFields) {
571
+ fields.push(` ${f.name}: SortOrder`);
572
+ }
573
+ // Relation order by
574
+ for (const rel of model.relations) {
575
+ const targetModel = allModels.find(m => m.name === rel.target);
576
+ if (targetModel && !targetModel.isEmbedded) {
577
+ fields.push(` ${rel.field}: ${rel.target}OrderByRelationAggregateInput`);
578
+ }
579
+ }
580
+ return `input ${model.name}OrderByWithRelationInput {\n${fields.join('\n')}\n}`;
581
+ }
582
+ function sdlWhereUniqueInput(model) {
583
+ const uniqueFields = model.fields.filter(f => !f.isIgnored && (f.isId || f.isUnique));
584
+ const fields = uniqueFields.map(f => ` ${f.name}: String`);
585
+ return `input ${model.name}WhereUniqueInput {\n${fields.join('\n')}\n}`;
586
+ }
587
+ function sdlOrderByWithAggregationInput(model) {
588
+ const fields = [];
589
+ const sortableFields = model.fields.filter(f => !f.isRelation && !f.isIgnored && f.type !== 'Json' && f.type !== 'Bytes');
590
+ for (const f of sortableFields) {
591
+ fields.push(` ${f.name}: SortOrder`);
592
+ }
593
+ fields.push(` _count: ${model.name}CountOrderByAggregateInput`);
594
+ fields.push(` _max: ${model.name}MaxOrderByAggregateInput`);
595
+ fields.push(` _min: ${model.name}MinOrderByAggregateInput`);
596
+ return `input ${model.name}OrderByWithAggregationInput {\n${fields.join('\n')}\n}`;
597
+ }
598
+ function sdlScalarWhereWithAggregatesInput(model, enums) {
599
+ const fields = [];
600
+ fields.push(' AND: [JSON]');
601
+ fields.push(' OR: [JSON]');
602
+ fields.push(' NOT: [JSON]');
603
+ for (const field of model.fields) {
604
+ if (field.isId)
605
+ continue;
606
+ if (field.isIgnored)
607
+ continue;
608
+ if (field.isRelation)
609
+ continue;
610
+ const embeddedModel = undefined; // embedded won't reach here
611
+ if (embeddedModel)
612
+ continue;
613
+ if (field.isArray) {
614
+ fields.push(` ${field.name}: JSON`);
615
+ continue;
616
+ }
617
+ const filterType = getWithAggregatesFilterName(field.type, field.isRequired, enums);
618
+ fields.push(` ${field.name}: ${filterType}`);
619
+ }
620
+ return `input ${model.name}ScalarWhereWithAggregatesInput {\n${fields.join('\n')}\n}`;
621
+ }
622
+ function sdlAggregateOrderByInputs(model) {
623
+ const sortableFields = model.fields.filter(f => !f.isRelation && !f.isIgnored && f.type !== 'Json' && f.type !== 'Bytes');
624
+ const countFields = sortableFields.map(f => ` ${f.name}: SortOrder`);
625
+ const maxFields = sortableFields.map(f => ` ${f.name}: SortOrder`);
626
+ const minFields = sortableFields.map(f => ` ${f.name}: SortOrder`);
627
+ return `input ${model.name}CountOrderByAggregateInput {\n${countFields.join('\n')}\n}
628
+
629
+ input ${model.name}MaxOrderByAggregateInput {\n${maxFields.join('\n')}\n}
630
+
631
+ input ${model.name}MinOrderByAggregateInput {\n${minFields.join('\n')}\n}
632
+
633
+ input ${model.name}OrderByRelationAggregateInput {
634
+ _count: SortOrder
635
+ }`;
636
+ }
637
+ // ===== Enum filters =====
638
+ function sdlEnumFilter(enumName) {
639
+ return `input Enum${enumName}Filter {
640
+ equals: ${enumName}
641
+ not: ${enumName}
642
+ in: [${enumName}!]
643
+ notIn: [${enumName}!]
644
+ }
645
+
646
+ input Enum${enumName}NullableFilter {
647
+ equals: ${enumName}
648
+ not: ${enumName}
649
+ in: [${enumName}!]
650
+ notIn: [${enumName}!]
651
+ }
652
+
653
+ input Enum${enumName}WithAggregatesFilter {
654
+ equals: ${enumName}
655
+ not: ${enumName}
656
+ in: [${enumName}!]
657
+ notIn: [${enumName}!]
658
+ _count: IntFilter
659
+ _min: Enum${enumName}Filter
660
+ _max: Enum${enumName}Filter
661
+ }
662
+
663
+ input Enum${enumName}NullableWithAggregatesFilter {
664
+ equals: ${enumName}
665
+ not: ${enumName}
666
+ in: [${enumName}!]
667
+ notIn: [${enumName}!]
668
+ _count: IntFilter
669
+ _min: Enum${enumName}Filter
670
+ _max: Enum${enumName}Filter
671
+ }`;
672
+ }
673
+ // ===== CreateInput / UpdateInput =====
674
+ function sdlFieldType(fieldType, isArray, isRequired) {
675
+ let t = fieldType;
676
+ if (isArray) {
677
+ t = `[${t}!]`;
678
+ }
679
+ return isRequired ? `${t}!` : t;
680
+ }
681
+ function sdlCreateInput(model) {
682
+ // Non-relation, non-id, non-ignored fields
683
+ const required = model.fields.filter(f => !f.isRelation && !f.isIgnored && !f.isId
684
+ && f.isRequired && f.defaultValue === undefined && !f.defaultGenerator);
685
+ const optional = model.fields.filter(f => !f.isRelation && !f.isIgnored && !f.isId
686
+ && (!f.isRequired || f.defaultValue !== undefined || !!f.defaultGenerator));
687
+ const fields = [
688
+ ...required.map(f => ` ${f.name}: ${sdlFieldType(f.type, f.isArray, true)}`),
689
+ ...optional.map(f => ` ${f.name}: ${sdlFieldType(f.type, f.isArray, false)}`),
690
+ ];
691
+ return `input ${model.name}CreateInput {\n${fields.join('\n')}\n}`;
692
+ }
693
+ function sdlUpdateInput(model) {
694
+ const fields = model.fields.filter(f => !f.isRelation && !f.isIgnored && !f.isId).map(f => ` ${f.name}: ${sdlFieldType(f.type, f.isArray, false)}`);
695
+ return `input ${model.name}UpdateInput {\n${fields.join('\n')}\n}`;
696
+ }
697
+ // ===== Main generator class =====
698
+ export class SDLInputTypesGenerator {
699
+ generateSDL(models, enums) {
700
+ const nonEmbedded = models.filter(m => !m.isEmbedded);
701
+ const parts = [];
702
+ const nl = '\n\n';
703
+ parts.push(sdlScalars());
704
+ parts.push(sdlBatchPayload());
705
+ parts.push(sdlSortEnums());
706
+ parts.push(sdlSortOrderInput());
707
+ // Base filters
708
+ parts.push(sdlBaseFilters());
709
+ parts.push(sdlArrayFilters());
710
+ parts.push(sdlWithAggregatesFilters());
711
+ parts.push(sdlRelationFilters().replace('<Model>', ''));
712
+ // Enum definitions + filters (per enum)
713
+ for (const enm of enums) {
714
+ parts.push(`enum ${enm.name} {\n${enm.values.map(v => ` ${v}`).join('\n')}\n}`);
715
+ }
716
+ for (const enm of enums) {
717
+ parts.push(sdlEnumFilter(enm.name));
718
+ }
719
+ // Per-model types
720
+ for (const model of nonEmbedded) {
721
+ parts.push(sdlModelScalarFieldEnum(model));
722
+ }
723
+ for (const model of nonEmbedded) {
724
+ parts.push(sdlWhereInput(model, models, enums));
725
+ }
726
+ for (const model of nonEmbedded) {
727
+ parts.push(sdlOrderByWithRelationInput(model, models));
728
+ }
729
+ for (const model of nonEmbedded) {
730
+ parts.push(sdlWhereUniqueInput(model));
731
+ }
732
+ for (const model of nonEmbedded) {
733
+ parts.push(sdlOrderByWithAggregationInput(model));
734
+ }
735
+ for (const model of nonEmbedded) {
736
+ parts.push(sdlScalarWhereWithAggregatesInput(model, enums));
737
+ }
738
+ for (const model of nonEmbedded) {
739
+ parts.push(sdlAggregateOrderByInputs(model));
740
+ }
741
+ // CreateInput / UpdateInput
742
+ for (const model of nonEmbedded) {
743
+ parts.push(sdlCreateInput(model));
744
+ }
745
+ for (const model of nonEmbedded) {
746
+ parts.push(sdlUpdateInput(model));
747
+ }
748
+ return parts.join(nl);
749
+ }
750
+ generateSDLOutput(models, enums) {
751
+ const sdl = this.generateSDL(models, enums);
752
+ return `// This file was auto-generated by Lenz. Do not edit manually.
753
+ // @generated
754
+
755
+ import { gql } from 'graphql-tag';
756
+
757
+ export const inputTypes = gql\`
758
+ ${sdl.trim()}
759
+ \`;
760
+ `;
761
+ }
762
+ }
763
+ //# sourceMappingURL=SDLInputTypesGenerator.js.map