@contember/client-content-generator 2.2.0-alpha.2 → 2.2.0-alpha.20

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 (75) hide show
  1. package/dist/development/generate.cjs +2 -54
  2. package/dist/development/generate.cjs.map +1 -1
  3. package/dist/development/generate.js +2 -37
  4. package/dist/development/generate.js.map +1 -1
  5. package/dist/development/src/ContemberClientGenerator.cjs +4 -5
  6. package/dist/development/src/ContemberClientGenerator.cjs.map +1 -1
  7. package/dist/development/src/ContemberClientGenerator.js +4 -5
  8. package/dist/development/src/ContemberClientGenerator.js.map +1 -1
  9. package/dist/development/src/EntityTypeSchemaGenerator.cjs +40 -16
  10. package/dist/development/src/EntityTypeSchemaGenerator.cjs.map +1 -1
  11. package/dist/development/src/EntityTypeSchemaGenerator.js +41 -17
  12. package/dist/development/src/EntityTypeSchemaGenerator.js.map +1 -1
  13. package/dist/development/src/GenerateContentClient.cjs +72 -0
  14. package/dist/development/src/GenerateContentClient.cjs.map +1 -0
  15. package/dist/development/src/GenerateContentClient.js +55 -0
  16. package/dist/development/src/GenerateContentClient.js.map +1 -0
  17. package/dist/development/src/NameSchemaGenerator.cjs +12 -2
  18. package/dist/development/src/NameSchemaGenerator.cjs.map +1 -1
  19. package/dist/development/src/NameSchemaGenerator.js +12 -2
  20. package/dist/development/src/NameSchemaGenerator.js.map +1 -1
  21. package/dist/development/src/utils.cjs +21 -0
  22. package/dist/development/src/utils.cjs.map +1 -1
  23. package/dist/development/src/utils.js +22 -1
  24. package/dist/development/src/utils.js.map +1 -1
  25. package/dist/production/generate.cjs +2 -54
  26. package/dist/production/generate.cjs.map +1 -1
  27. package/dist/production/generate.js +2 -37
  28. package/dist/production/generate.js.map +1 -1
  29. package/dist/production/src/ContemberClientGenerator.cjs +4 -5
  30. package/dist/production/src/ContemberClientGenerator.cjs.map +1 -1
  31. package/dist/production/src/ContemberClientGenerator.js +4 -5
  32. package/dist/production/src/ContemberClientGenerator.js.map +1 -1
  33. package/dist/production/src/EntityTypeSchemaGenerator.cjs +40 -16
  34. package/dist/production/src/EntityTypeSchemaGenerator.cjs.map +1 -1
  35. package/dist/production/src/EntityTypeSchemaGenerator.js +41 -17
  36. package/dist/production/src/EntityTypeSchemaGenerator.js.map +1 -1
  37. package/dist/production/src/GenerateContentClient.cjs +72 -0
  38. package/dist/production/src/GenerateContentClient.cjs.map +1 -0
  39. package/dist/production/src/GenerateContentClient.js +55 -0
  40. package/dist/production/src/GenerateContentClient.js.map +1 -0
  41. package/dist/production/src/NameSchemaGenerator.cjs +12 -2
  42. package/dist/production/src/NameSchemaGenerator.cjs.map +1 -1
  43. package/dist/production/src/NameSchemaGenerator.js +12 -2
  44. package/dist/production/src/NameSchemaGenerator.js.map +1 -1
  45. package/dist/production/src/utils.cjs +21 -0
  46. package/dist/production/src/utils.cjs.map +1 -1
  47. package/dist/production/src/utils.js +22 -1
  48. package/dist/production/src/utils.js.map +1 -1
  49. package/dist/types/ContemberClientGenerator.d.ts +2 -1
  50. package/dist/types/ContemberClientGenerator.d.ts.map +1 -1
  51. package/dist/types/EntityTypeSchemaGenerator.d.ts +2 -1
  52. package/dist/types/EntityTypeSchemaGenerator.d.ts.map +1 -1
  53. package/dist/types/EnumTypeSchemaGenerator.d.ts.map +1 -1
  54. package/dist/types/GenerateContentClient.d.ts +14 -0
  55. package/dist/types/GenerateContentClient.d.ts.map +1 -0
  56. package/dist/types/NameSchemaGenerator.d.ts +2 -1
  57. package/dist/types/NameSchemaGenerator.d.ts.map +1 -1
  58. package/dist/types/index.d.ts +1 -0
  59. package/dist/types/index.d.ts.map +1 -1
  60. package/dist/types/tsconfig.tsbuildinfo +1 -1
  61. package/dist/types/utils.d.ts +13 -0
  62. package/dist/types/utils.d.ts.map +1 -1
  63. package/package.json +6 -5
  64. package/src/ContemberClientGenerator.ts +5 -5
  65. package/src/EntityTypeSchemaGenerator.ts +43 -16
  66. package/src/GenerateContentClient.ts +72 -0
  67. package/src/NameSchemaGenerator.ts +12 -2
  68. package/src/generate.ts +2 -41
  69. package/src/index.ts +1 -0
  70. package/src/tsconfig.json +1 -0
  71. package/src/utils.ts +29 -0
  72. package/tests/__snapshots__/generateEnittyTypes.test.ts.snap +559 -1
  73. package/tests/generateEnittyTypes.test.ts +40 -0
  74. package/tests/schemas.ts +93 -20
  75. package/tests/typecheckGeneratedClient.test.ts +53 -0
@@ -7,6 +7,78 @@ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
7
7
  export type JSONObject = { readonly [K in string]?: JSONValue }
8
8
  export type JSONArray = readonly JSONValue[]
9
9
 
10
+ export type Foo <OverRelation extends string | never = never> = {
11
+ name: 'Foo'
12
+ unique:
13
+ | Omit<{ id: string}, OverRelation>
14
+ columns: {
15
+ id: string
16
+ stringCol: string | null
17
+ intCol: number | null
18
+ doubleCol: number | null
19
+ dateCol: string | null
20
+ datetimeCol: string | null
21
+ booleanCol: boolean | null
22
+ jsonCol: JSONValue | null
23
+ uuidCol: string | null
24
+ /**
25
+ * @deprecated Field is deprecated
26
+ */
27
+ deprecatedStringCol: string | null
28
+ /**
29
+ * @deprecated Field is deprecated
30
+ */
31
+ deprecatedIntCol: number | null
32
+ /**
33
+ * @deprecated Field is deprecated
34
+ */
35
+ deprecatedDoubleCol: number | null
36
+ /**
37
+ * @deprecated Field is deprecated
38
+ */
39
+ deprecatedDateCol: string | null
40
+ /**
41
+ * @deprecated Field is deprecated
42
+ */
43
+ deprecatedDatetimeCol: string | null
44
+ /**
45
+ * @deprecated Field is deprecated
46
+ */
47
+ deprecatedBooleanCol: boolean | null
48
+ /**
49
+ * @deprecated Field is deprecated
50
+ */
51
+ deprecatedJsonCol: JSONValue | null
52
+ /**
53
+ * @deprecated Field is deprecated
54
+ */
55
+ deprecatedUuidCol: string | null
56
+ }
57
+ hasOne: {
58
+ }
59
+ hasMany: {
60
+ }
61
+ hasManyBy: {
62
+ }
63
+ }
64
+
65
+ export type ContemberClientEntities = {
66
+ Foo: Foo
67
+ }
68
+
69
+ export type ContemberClientSchema = {
70
+ entities: ContemberClientEntities
71
+ }
72
+ "
73
+ `;
74
+
75
+ exports[`generate entities generate for scalars excluding deprecated 1`] = `
76
+ "
77
+ export type JSONPrimitive = string | number | boolean | null
78
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
79
+ export type JSONObject = { readonly [K in string]?: JSONValue }
80
+ export type JSONArray = readonly JSONValue[]
81
+
10
82
  export type Foo <OverRelation extends string | never = never> = {
11
83
  name: 'Foo'
12
84
  unique:
@@ -42,6 +114,76 @@ export type ContemberClientSchema = {
42
114
 
43
115
  exports[`generate entities generate for has enum 1`] = `
44
116
  "import type { FooEnumCol } from './enums'
117
+ import type { FooDeprecatedEnumCol } from './enums'
118
+ import type { DeprecatedFooEnumCol } from './enums'
119
+ import type { DeprecatedFooDeprecatedEnumCol } from './enums'
120
+
121
+ export type JSONPrimitive = string | number | boolean | null
122
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
123
+ export type JSONObject = { readonly [K in string]?: JSONValue }
124
+ export type JSONArray = readonly JSONValue[]
125
+
126
+ export type Foo <OverRelation extends string | never = never> = {
127
+ name: 'Foo'
128
+ unique:
129
+ | Omit<{ id: string}, OverRelation>
130
+ columns: {
131
+ id: string
132
+ enumCol: FooEnumCol | null
133
+ /**
134
+ * @deprecated Field is deprecated
135
+ */
136
+ deprecatedEnumCol: FooDeprecatedEnumCol | null
137
+ }
138
+ hasOne: {
139
+ }
140
+ hasMany: {
141
+ }
142
+ hasManyBy: {
143
+ }
144
+ }
145
+ /**
146
+ * @deprecated Entity is deprecated
147
+ */
148
+ export type DeprecatedFoo <OverRelation extends string | never = never> = {
149
+ name: 'DeprecatedFoo'
150
+ unique:
151
+ | Omit<{ id: string}, OverRelation>
152
+ columns: {
153
+ id: string
154
+ enumCol: DeprecatedFooEnumCol | null
155
+ /**
156
+ * @deprecated Field is deprecated
157
+ */
158
+ deprecatedEnumCol: DeprecatedFooDeprecatedEnumCol | null
159
+ }
160
+ hasOne: {
161
+ }
162
+ hasMany: {
163
+ }
164
+ hasManyBy: {
165
+ }
166
+ }
167
+
168
+ export type ContemberClientEntities = {
169
+ Foo: Foo
170
+ /**
171
+ * @deprecated Entity is deprecated
172
+ */
173
+ DeprecatedFoo: DeprecatedFoo
174
+ }
175
+
176
+ export type ContemberClientSchema = {
177
+ entities: ContemberClientEntities
178
+ }
179
+ "
180
+ `;
181
+
182
+ exports[`generate entities generate for has enum excluding deprecated 1`] = `
183
+ "import type { FooEnumCol } from './enums'
184
+ import type { FooDeprecatedEnumCol } from './enums'
185
+ import type { DeprecatedFooEnumCol } from './enums'
186
+ import type { DeprecatedFooDeprecatedEnumCol } from './enums'
45
187
 
46
188
  export type JSONPrimitive = string | number | boolean | null
47
189
  export type JSONValue = JSONPrimitive | JSONObject | JSONArray
@@ -81,6 +223,109 @@ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
81
223
  export type JSONObject = { readonly [K in string]?: JSONValue }
82
224
  export type JSONArray = readonly JSONValue[]
83
225
 
226
+ export type Foo <OverRelation extends string | never = never> = {
227
+ name: 'Foo'
228
+ unique:
229
+ | Omit<{ id: string}, OverRelation>
230
+ | Omit<{ oneHasOneInverseRel: Bar['unique']}, OverRelation>
231
+ columns: {
232
+ id: string
233
+ }
234
+ hasOne: {
235
+ oneHasOneInverseRel: Bar
236
+ }
237
+ hasMany: {
238
+ }
239
+ hasManyBy: {
240
+ }
241
+ }
242
+ export type Bar <OverRelation extends string | never = never> = {
243
+ name: 'Bar'
244
+ unique:
245
+ | Omit<{ id: string}, OverRelation>
246
+ | Omit<{ oneHasOneOwningRel: Foo['unique']}, OverRelation>
247
+ columns: {
248
+ id: string
249
+ }
250
+ hasOne: {
251
+ oneHasOneOwningRel: Foo
252
+ }
253
+ hasMany: {
254
+ }
255
+ hasManyBy: {
256
+ }
257
+ }
258
+ /**
259
+ * @deprecated Entity is deprecated
260
+ */
261
+ export type DeprecatedFoo <OverRelation extends string | never = never> = {
262
+ name: 'DeprecatedFoo'
263
+ unique:
264
+ | Omit<{ id: string}, OverRelation>
265
+ | Omit<{ deprecatedOneHasOneInverseRel: DeprecatedBar['unique']}, OverRelation>
266
+ columns: {
267
+ id: string
268
+ }
269
+ hasOne: {
270
+ /**
271
+ * @deprecated Field is deprecated
272
+ */
273
+ deprecatedOneHasOneInverseRel: DeprecatedBar
274
+ }
275
+ hasMany: {
276
+ }
277
+ hasManyBy: {
278
+ }
279
+ }
280
+ /**
281
+ * @deprecated Entity is deprecated
282
+ */
283
+ export type DeprecatedBar <OverRelation extends string | never = never> = {
284
+ name: 'DeprecatedBar'
285
+ unique:
286
+ | Omit<{ id: string}, OverRelation>
287
+ | Omit<{ deprecatedOneHasOneOwningRel: DeprecatedFoo['unique']}, OverRelation>
288
+ columns: {
289
+ id: string
290
+ }
291
+ hasOne: {
292
+ /**
293
+ * @deprecated Field is deprecated
294
+ */
295
+ deprecatedOneHasOneOwningRel: DeprecatedFoo
296
+ }
297
+ hasMany: {
298
+ }
299
+ hasManyBy: {
300
+ }
301
+ }
302
+
303
+ export type ContemberClientEntities = {
304
+ Foo: Foo
305
+ Bar: Bar
306
+ /**
307
+ * @deprecated Entity is deprecated
308
+ */
309
+ DeprecatedFoo: DeprecatedFoo
310
+ /**
311
+ * @deprecated Entity is deprecated
312
+ */
313
+ DeprecatedBar: DeprecatedBar
314
+ }
315
+
316
+ export type ContemberClientSchema = {
317
+ entities: ContemberClientEntities
318
+ }
319
+ "
320
+ `;
321
+
322
+ exports[`generate entities generate one has one excluding deprecated 1`] = `
323
+ "
324
+ export type JSONPrimitive = string | number | boolean | null
325
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
326
+ export type JSONObject = { readonly [K in string]?: JSONValue }
327
+ export type JSONArray = readonly JSONValue[]
328
+
84
329
  export type Foo <OverRelation extends string | never = never> = {
85
330
  name: 'Foo'
86
331
  unique:
@@ -132,6 +377,107 @@ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
132
377
  export type JSONObject = { readonly [K in string]?: JSONValue }
133
378
  export type JSONArray = readonly JSONValue[]
134
379
 
380
+ export type Foo <OverRelation extends string | never = never> = {
381
+ name: 'Foo'
382
+ unique:
383
+ | Omit<{ id: string}, OverRelation>
384
+ | Omit<{ oneHasManyRel: Bar['unique']}, OverRelation>
385
+ columns: {
386
+ id: string
387
+ }
388
+ hasOne: {
389
+ }
390
+ hasMany: {
391
+ oneHasManyRel: Bar<'manyHasOneRel'>
392
+ }
393
+ hasManyBy: {
394
+ }
395
+ }
396
+ export type Bar <OverRelation extends string | never = never> = {
397
+ name: 'Bar'
398
+ unique:
399
+ | Omit<{ id: string}, OverRelation>
400
+ columns: {
401
+ id: string
402
+ }
403
+ hasOne: {
404
+ manyHasOneRel: Foo
405
+ }
406
+ hasMany: {
407
+ }
408
+ hasManyBy: {
409
+ }
410
+ }
411
+ /**
412
+ * @deprecated Entity is deprecated
413
+ */
414
+ export type DeprecatedFoo <OverRelation extends string | never = never> = {
415
+ name: 'DeprecatedFoo'
416
+ unique:
417
+ | Omit<{ id: string}, OverRelation>
418
+ | Omit<{ deprecatedOneHasManyRel: DeprecatedBar['unique']}, OverRelation>
419
+ columns: {
420
+ id: string
421
+ }
422
+ hasOne: {
423
+ }
424
+ hasMany: {
425
+ /**
426
+ * @deprecated Field is deprecated
427
+ */
428
+ deprecatedOneHasManyRel: DeprecatedBar<'deprecatedManyHasOneRel'>
429
+ }
430
+ hasManyBy: {
431
+ }
432
+ }
433
+ /**
434
+ * @deprecated Entity is deprecated
435
+ */
436
+ export type DeprecatedBar <OverRelation extends string | never = never> = {
437
+ name: 'DeprecatedBar'
438
+ unique:
439
+ | Omit<{ id: string}, OverRelation>
440
+ columns: {
441
+ id: string
442
+ }
443
+ hasOne: {
444
+ /**
445
+ * @deprecated Field is deprecated
446
+ */
447
+ deprecatedManyHasOneRel: DeprecatedFoo
448
+ }
449
+ hasMany: {
450
+ }
451
+ hasManyBy: {
452
+ }
453
+ }
454
+
455
+ export type ContemberClientEntities = {
456
+ Foo: Foo
457
+ Bar: Bar
458
+ /**
459
+ * @deprecated Entity is deprecated
460
+ */
461
+ DeprecatedFoo: DeprecatedFoo
462
+ /**
463
+ * @deprecated Entity is deprecated
464
+ */
465
+ DeprecatedBar: DeprecatedBar
466
+ }
467
+
468
+ export type ContemberClientSchema = {
469
+ entities: ContemberClientEntities
470
+ }
471
+ "
472
+ `;
473
+
474
+ exports[`generate entities generate one has many excluding deprecated 1`] = `
475
+ "
476
+ export type JSONPrimitive = string | number | boolean | null
477
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
478
+ export type JSONObject = { readonly [K in string]?: JSONValue }
479
+ export type JSONArray = readonly JSONValue[]
480
+
135
481
  export type Foo <OverRelation extends string | never = never> = {
136
482
  name: 'Foo'
137
483
  unique:
@@ -182,6 +528,105 @@ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
182
528
  export type JSONObject = { readonly [K in string]?: JSONValue }
183
529
  export type JSONArray = readonly JSONValue[]
184
530
 
531
+ export type Foo <OverRelation extends string | never = never> = {
532
+ name: 'Foo'
533
+ unique:
534
+ | Omit<{ id: string}, OverRelation>
535
+ columns: {
536
+ id: string
537
+ }
538
+ hasOne: {
539
+ }
540
+ hasMany: {
541
+ manyHasManyRel: Bar
542
+ }
543
+ hasManyBy: {
544
+ }
545
+ }
546
+ export type Bar <OverRelation extends string | never = never> = {
547
+ name: 'Bar'
548
+ unique:
549
+ | Omit<{ id: string}, OverRelation>
550
+ columns: {
551
+ id: string
552
+ }
553
+ hasOne: {
554
+ }
555
+ hasMany: {
556
+ manyHasManyInverseRel: Foo
557
+ }
558
+ hasManyBy: {
559
+ }
560
+ }
561
+ /**
562
+ * @deprecated Entity is deprecated
563
+ */
564
+ export type DeprecatedFoo <OverRelation extends string | never = never> = {
565
+ name: 'DeprecatedFoo'
566
+ unique:
567
+ | Omit<{ id: string}, OverRelation>
568
+ columns: {
569
+ id: string
570
+ }
571
+ hasOne: {
572
+ }
573
+ hasMany: {
574
+ /**
575
+ * @deprecated Field is deprecated
576
+ */
577
+ deprecatedManyHasManyRel: DeprecatedBar
578
+ }
579
+ hasManyBy: {
580
+ }
581
+ }
582
+ /**
583
+ * @deprecated Entity is deprecated
584
+ */
585
+ export type DeprecatedBar <OverRelation extends string | never = never> = {
586
+ name: 'DeprecatedBar'
587
+ unique:
588
+ | Omit<{ id: string}, OverRelation>
589
+ columns: {
590
+ id: string
591
+ }
592
+ hasOne: {
593
+ }
594
+ hasMany: {
595
+ /**
596
+ * @deprecated Field is deprecated
597
+ */
598
+ deeprecatedManyHasManyInverseRel: DeprecatedFoo
599
+ }
600
+ hasManyBy: {
601
+ }
602
+ }
603
+
604
+ export type ContemberClientEntities = {
605
+ Foo: Foo
606
+ Bar: Bar
607
+ /**
608
+ * @deprecated Entity is deprecated
609
+ */
610
+ DeprecatedFoo: DeprecatedFoo
611
+ /**
612
+ * @deprecated Entity is deprecated
613
+ */
614
+ DeprecatedBar: DeprecatedBar
615
+ }
616
+
617
+ export type ContemberClientSchema = {
618
+ entities: ContemberClientEntities
619
+ }
620
+ "
621
+ `;
622
+
623
+ exports[`generate entities generate many has many excluding deprecated 1`] = `
624
+ "
625
+ export type JSONPrimitive = string | number | boolean | null
626
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
627
+ export type JSONObject = { readonly [K in string]?: JSONValue }
628
+ export type JSONArray = readonly JSONValue[]
629
+
185
630
  export type Foo <OverRelation extends string | never = never> = {
186
631
  name: 'Foo'
187
632
  unique:
@@ -252,7 +697,120 @@ export type FooLocale <OverRelation extends string | never = never> = {
252
697
  name: 'FooLocale'
253
698
  unique:
254
699
  | Omit<{ id: string}, OverRelation>
255
- | Omit<{ locale: string, foo: Foo['unique']}, OverRelation>
700
+ | Omit<{ locale: string; foo: Foo['unique']}, OverRelation>
701
+ columns: {
702
+ id: string
703
+ locale: string
704
+ }
705
+ hasOne: {
706
+ foo: Foo
707
+ }
708
+ hasMany: {
709
+ }
710
+ hasManyBy: {
711
+ }
712
+ }
713
+ /**
714
+ * @deprecated Entity is deprecated
715
+ */
716
+ export type DeprecatedFoo <OverRelation extends string | never = never> = {
717
+ name: 'DeprecatedFoo'
718
+ unique:
719
+ | Omit<{ id: string}, OverRelation>
720
+ | Omit<{ deprecatedLocales: DeprecatedFooLocale['unique']}, OverRelation>
721
+ columns: {
722
+ id: string
723
+ }
724
+ hasOne: {
725
+ }
726
+ hasMany: {
727
+ /**
728
+ * @deprecated Field is deprecated
729
+ */
730
+ deprecatedLocales: DeprecatedFooLocale<'deprecatedFoo'>
731
+ }
732
+ hasManyBy: {
733
+ /**
734
+ * @deprecated Field is deprecated
735
+ */
736
+ deprecatedLocalesByDeprecatedLocale: { entity: DeprecatedFooLocale; by: {deprecatedLocale: string} }
737
+ }
738
+ }
739
+ /**
740
+ * @deprecated Entity is deprecated
741
+ */
742
+ export type DeprecatedFooLocale <OverRelation extends string | never = never> = {
743
+ name: 'DeprecatedFooLocale'
744
+ unique:
745
+ | Omit<{ id: string}, OverRelation>
746
+ | Omit<{ deprecatedLocale: string; deprecatedFoo: DeprecatedFoo['unique']}, OverRelation>
747
+ columns: {
748
+ id: string
749
+ /**
750
+ * @deprecated Field is deprecated
751
+ */
752
+ deprecatedLocale: string
753
+ }
754
+ hasOne: {
755
+ /**
756
+ * @deprecated Field is deprecated
757
+ */
758
+ deprecatedFoo: DeprecatedFoo
759
+ }
760
+ hasMany: {
761
+ }
762
+ hasManyBy: {
763
+ }
764
+ }
765
+
766
+ export type ContemberClientEntities = {
767
+ Foo: Foo
768
+ FooLocale: FooLocale
769
+ /**
770
+ * @deprecated Entity is deprecated
771
+ */
772
+ DeprecatedFoo: DeprecatedFoo
773
+ /**
774
+ * @deprecated Entity is deprecated
775
+ */
776
+ DeprecatedFooLocale: DeprecatedFooLocale
777
+ }
778
+
779
+ export type ContemberClientSchema = {
780
+ entities: ContemberClientEntities
781
+ }
782
+ "
783
+ `;
784
+
785
+ exports[`generate entities generate reduced has by excluding deprecated 1`] = `
786
+ "
787
+ export type JSONPrimitive = string | number | boolean | null
788
+ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
789
+ export type JSONObject = { readonly [K in string]?: JSONValue }
790
+ export type JSONArray = readonly JSONValue[]
791
+
792
+ export type Foo <OverRelation extends string | never = never> = {
793
+ name: 'Foo'
794
+ unique:
795
+ | Omit<{ id: string}, OverRelation>
796
+ | Omit<{ locales: FooLocale['unique']}, OverRelation>
797
+ columns: {
798
+ id: string
799
+ }
800
+ hasOne: {
801
+ }
802
+ hasMany: {
803
+ locales: FooLocale<'foo'>
804
+ }
805
+ hasManyBy: {
806
+ localesByLocale: { entity: FooLocale; by: {locale: string} }
807
+ }
808
+ }
809
+ export type FooLocale <OverRelation extends string | never = never> = {
810
+ name: 'FooLocale'
811
+ unique:
812
+ | Omit<{ id: string}, OverRelation>
813
+ | Omit<{ locale: string; foo: Foo['unique']}, OverRelation>
256
814
  columns: {
257
815
  id: string
258
816
  locale: string
@@ -8,21 +8,42 @@ describe('generate entities', () => {
8
8
  expect(entityGenerator.generate(schemas.scalarsSchema.model)).toMatchSnapshot()
9
9
  })
10
10
 
11
+ test('generate for scalars excluding deprecated', () => {
12
+ expect(entityGenerator.generate(schemas.scalarsSchema.model, { excludeDeprecated: true })).toMatchSnapshot()
13
+ })
14
+
11
15
  test('generate for has enum', () => {
12
16
  expect(entityGenerator.generate(schemas.enumSchema.model)).toMatchSnapshot()
13
17
  })
18
+
19
+ test('generate for has enum excluding deprecated', () => {
20
+ expect(entityGenerator.generate(schemas.enumSchema.model, { excludeDeprecated: true })).toMatchSnapshot()
21
+ })
22
+
14
23
  test('generate one has one', () => {
15
24
  expect(entityGenerator.generate(schemas.oneHasOneSchema.model)).toMatchSnapshot()
16
25
  })
17
26
 
27
+ test('generate one has one excluding deprecated', () => {
28
+ expect(entityGenerator.generate(schemas.oneHasOneSchema.model, { excludeDeprecated: true })).toMatchSnapshot()
29
+ })
30
+
18
31
  test('generate one has many', () => {
19
32
  expect(entityGenerator.generate(schemas.oneHasManySchema.model)).toMatchSnapshot()
20
33
  })
21
34
 
35
+ test('generate one has many excluding deprecated', () => {
36
+ expect(entityGenerator.generate(schemas.oneHasManySchema.model, { excludeDeprecated: true })).toMatchSnapshot()
37
+ })
38
+
22
39
  test('generate many has many', () => {
23
40
  expect(entityGenerator.generate(schemas.manyHasManySchema.model)).toMatchSnapshot()
24
41
  })
25
42
 
43
+ test('generate many has many excluding deprecated', () => {
44
+ expect(entityGenerator.generate(schemas.manyHasManySchema.model, { excludeDeprecated: true })).toMatchSnapshot()
45
+ })
46
+
26
47
  test('generate reduced has by', () => {
27
48
  expect(entityGenerator.generate(schemas.reducedHasManySchema.model)).toMatchSnapshot()
28
49
  })
@@ -34,4 +55,23 @@ describe('generate entities', () => {
34
55
  // json column with a schema gets the derived object type
35
56
  expect(output).toContain('structured: { name: string; age?: number; tags?: readonly (string)[] } | null')
36
57
  })
58
+
59
+ test('generate reduced has by excluding deprecated', () => {
60
+ expect(entityGenerator.generate(schemas.reducedHasManySchema.model, { excludeDeprecated: true })).toMatchSnapshot()
61
+ })
62
+
63
+ test('non-deprecated relation to a deprecated entity is dropped when excluding deprecated', () => {
64
+ const output = entityGenerator.generate(schemas.danglingDeprecatedRefSchema.model, { excludeDeprecated: true })
65
+ // the deprecated entity itself is excluded
66
+ expect(output).not.toContain('DeprecatedTarget')
67
+ // and the relation pointing to it must be dropped, otherwise the generated code references a missing type
68
+ expect(output).not.toContain('target:')
69
+ })
70
+
71
+ test('deprecated entities and fields are kept and marked by default', () => {
72
+ const output = entityGenerator.generate(schemas.danglingDeprecatedRefSchema.model)
73
+ expect(output).toContain('export type DeprecatedTarget')
74
+ expect(output).toContain('target: DeprecatedTarget')
75
+ expect(output).toContain('@deprecated')
76
+ })
37
77
  })