@nest-boot/eslint-plugin 7.0.6 → 7.0.7
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/rules/mikro-orm/entity-property-config-from-types.js +51 -17
- package/dist/rules/mikro-orm/entity-property-config-from-types.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +8 -0
- package/src/rules/graphql/graphql-field-config-from-types.spec.ts +249 -0
- package/src/rules/graphql/graphql-field-definite-assignment.spec.ts +17 -0
- package/src/rules/index.spec.ts +15 -0
- package/src/rules/mikro-orm/entity-field-definite-assignment.spec.ts +17 -0
- package/src/rules/mikro-orm/entity-property-config-from-types.spec.ts +678 -1
- package/src/rules/mikro-orm/entity-property-config-from-types.ts +94 -17
- package/src/utils/decorators.spec.ts +52 -0
|
@@ -128,6 +128,125 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
128
128
|
description!: string;
|
|
129
129
|
}
|
|
130
130
|
`,
|
|
131
|
+
// Decimal and BigInt string storage are valid string configurations
|
|
132
|
+
/* typescript */ `
|
|
133
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
134
|
+
|
|
135
|
+
@Entity()
|
|
136
|
+
class User {
|
|
137
|
+
@Property({ type: new BigIntType('string') })
|
|
138
|
+
externalId!: string;
|
|
139
|
+
}
|
|
140
|
+
`,
|
|
141
|
+
// Decimal and BigInt number storage are valid number configurations
|
|
142
|
+
/* typescript */ `
|
|
143
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
144
|
+
|
|
145
|
+
@Entity()
|
|
146
|
+
class User {
|
|
147
|
+
@Property({ type: new DecimalType('number') })
|
|
148
|
+
score!: number;
|
|
149
|
+
}
|
|
150
|
+
`,
|
|
151
|
+
// VectorType is valid for number arrays
|
|
152
|
+
/* typescript */ `
|
|
153
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
154
|
+
|
|
155
|
+
@Entity()
|
|
156
|
+
class User {
|
|
157
|
+
@Property({ type: new VectorType(3) })
|
|
158
|
+
embedding!: number[];
|
|
159
|
+
}
|
|
160
|
+
`,
|
|
161
|
+
// VectorType class reference is valid for number arrays
|
|
162
|
+
/* typescript */ `
|
|
163
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
164
|
+
|
|
165
|
+
@Entity()
|
|
166
|
+
class User {
|
|
167
|
+
@Property({ type: VectorType })
|
|
168
|
+
embedding!: number[];
|
|
169
|
+
}
|
|
170
|
+
`,
|
|
171
|
+
// Capitalized primitive wrapper names are supported
|
|
172
|
+
/* typescript */ `
|
|
173
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
174
|
+
|
|
175
|
+
@Entity()
|
|
176
|
+
class User {
|
|
177
|
+
@Property({ type: t.string })
|
|
178
|
+
name!: String;
|
|
179
|
+
|
|
180
|
+
@Property({ type: t.float })
|
|
181
|
+
score!: Number;
|
|
182
|
+
|
|
183
|
+
@Property({ type: t.boolean })
|
|
184
|
+
active!: Boolean;
|
|
185
|
+
}
|
|
186
|
+
`,
|
|
187
|
+
// DecimalType class reference is valid for strings
|
|
188
|
+
/* typescript */ `
|
|
189
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
190
|
+
|
|
191
|
+
@Entity()
|
|
192
|
+
class User {
|
|
193
|
+
@Property({ type: DecimalType })
|
|
194
|
+
amount!: string;
|
|
195
|
+
}
|
|
196
|
+
`,
|
|
197
|
+
// BigIntType class reference is valid for numbers
|
|
198
|
+
/* typescript */ `
|
|
199
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
200
|
+
|
|
201
|
+
@Entity()
|
|
202
|
+
class User {
|
|
203
|
+
@Property({ type: BigIntType })
|
|
204
|
+
amount!: number;
|
|
205
|
+
}
|
|
206
|
+
`,
|
|
207
|
+
// GraphQLJSONObject identifier maps to JSON
|
|
208
|
+
/* typescript */ `
|
|
209
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
210
|
+
|
|
211
|
+
@Entity()
|
|
212
|
+
class User {
|
|
213
|
+
@Property({ type: t.json })
|
|
214
|
+
payload!: GraphQLJSONObject;
|
|
215
|
+
}
|
|
216
|
+
`,
|
|
217
|
+
// Custom type arrays use t.json
|
|
218
|
+
/* typescript */ `
|
|
219
|
+
import { Entity, Property } from "@mikro-orm/core";
|
|
220
|
+
|
|
221
|
+
class Profile {}
|
|
222
|
+
|
|
223
|
+
@Entity()
|
|
224
|
+
class User {
|
|
225
|
+
@Property({ type: t.json })
|
|
226
|
+
profiles!: Profile[];
|
|
227
|
+
}
|
|
228
|
+
`,
|
|
229
|
+
// Collection<T> is skipped
|
|
230
|
+
/* typescript */ `
|
|
231
|
+
import { Collection, Entity, Property } from "@mikro-orm/core";
|
|
232
|
+
|
|
233
|
+
@Entity()
|
|
234
|
+
class User {
|
|
235
|
+
@Property()
|
|
236
|
+
posts!: Collection<Post>;
|
|
237
|
+
}
|
|
238
|
+
`,
|
|
239
|
+
// Methods are ignored
|
|
240
|
+
/* typescript */ `
|
|
241
|
+
import { Entity } from "@mikro-orm/core";
|
|
242
|
+
|
|
243
|
+
@Entity()
|
|
244
|
+
class User {
|
|
245
|
+
method() {
|
|
246
|
+
return "value";
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
`,
|
|
131
250
|
// Non-Entity class is not checked
|
|
132
251
|
/* typescript */ `
|
|
133
252
|
class NotAnEntity {
|
|
@@ -219,7 +338,7 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
219
338
|
}
|
|
220
339
|
`,
|
|
221
340
|
output: /* typescript */ `
|
|
222
|
-
import { Entity, Property } from "@mikro-orm/core";
|
|
341
|
+
import { Entity, Property, Enum } from "@mikro-orm/core";
|
|
223
342
|
|
|
224
343
|
enum Role {
|
|
225
344
|
Admin,
|
|
@@ -354,5 +473,563 @@ tester.run("entity-property-config-from-types", rule, {
|
|
|
354
473
|
`,
|
|
355
474
|
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
356
475
|
},
|
|
476
|
+
// Missing @Property decorator should add one from the TypeScript type
|
|
477
|
+
{
|
|
478
|
+
code: /* typescript */ `import { Entity } from "@mikro-orm/core";
|
|
479
|
+
@Entity()
|
|
480
|
+
class User {
|
|
481
|
+
name!: string;
|
|
482
|
+
}`,
|
|
483
|
+
output: /* typescript */ `import { Entity, Property, t } from "@mikro-orm/core";
|
|
484
|
+
@Entity()
|
|
485
|
+
class User {
|
|
486
|
+
@Property({ type: t.string })
|
|
487
|
+
name!: string;
|
|
488
|
+
}`,
|
|
489
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
490
|
+
},
|
|
491
|
+
// Aliased Property imports should not suppress the unaliased runtime import
|
|
492
|
+
{
|
|
493
|
+
code: /* typescript */ `import { Entity, Property as MikroProperty } from "@mikro-orm/core";
|
|
494
|
+
@Entity()
|
|
495
|
+
class User {
|
|
496
|
+
name!: string;
|
|
497
|
+
}`,
|
|
498
|
+
output: /* typescript */ `import { Entity, Property as MikroProperty, Property, t } from "@mikro-orm/core";
|
|
499
|
+
@Entity()
|
|
500
|
+
class User {
|
|
501
|
+
@Property({ type: t.string })
|
|
502
|
+
name!: string;
|
|
503
|
+
}`,
|
|
504
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
505
|
+
},
|
|
506
|
+
// Record types should use t.json
|
|
507
|
+
{
|
|
508
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
509
|
+
@Entity()
|
|
510
|
+
class User {
|
|
511
|
+
@Property({ type: t.string })
|
|
512
|
+
metadata!: Record<string, unknown>;
|
|
513
|
+
}`,
|
|
514
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
515
|
+
@Entity()
|
|
516
|
+
class User {
|
|
517
|
+
@Property({ type: t.json })
|
|
518
|
+
metadata!: Record<string, unknown>;
|
|
519
|
+
}`,
|
|
520
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
521
|
+
},
|
|
522
|
+
// Union types without nullish members use the first concrete type
|
|
523
|
+
{
|
|
524
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
525
|
+
@Entity()
|
|
526
|
+
class User {
|
|
527
|
+
@Property()
|
|
528
|
+
value!: string | number;
|
|
529
|
+
}`,
|
|
530
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
531
|
+
@Entity()
|
|
532
|
+
class User {
|
|
533
|
+
@Property({ type: t.string })
|
|
534
|
+
value!: string | number;
|
|
535
|
+
}`,
|
|
536
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
537
|
+
},
|
|
538
|
+
// Undefined unions should be nullable
|
|
539
|
+
{
|
|
540
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
541
|
+
@Entity()
|
|
542
|
+
class User {
|
|
543
|
+
@Property({ type: t.string })
|
|
544
|
+
nickname!: string | undefined;
|
|
545
|
+
}`,
|
|
546
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
547
|
+
@Entity()
|
|
548
|
+
class User {
|
|
549
|
+
@Property({ type: t.string, nullable: true })
|
|
550
|
+
nickname!: string | undefined;
|
|
551
|
+
}`,
|
|
552
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
553
|
+
},
|
|
554
|
+
// Ref<T | null> should unwrap the type and preserve nullable
|
|
555
|
+
{
|
|
556
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
557
|
+
@Entity()
|
|
558
|
+
class User {
|
|
559
|
+
@Property({ type: t.string })
|
|
560
|
+
owner!: Ref<User | null>;
|
|
561
|
+
}`,
|
|
562
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
563
|
+
@Entity()
|
|
564
|
+
class User {
|
|
565
|
+
@Property({ nullable: true })
|
|
566
|
+
owner!: Ref<User | null>;
|
|
567
|
+
}`,
|
|
568
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
569
|
+
},
|
|
570
|
+
// Ref<T | undefined> should unwrap the type and preserve nullable
|
|
571
|
+
{
|
|
572
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
573
|
+
@Entity()
|
|
574
|
+
class User {
|
|
575
|
+
@Property()
|
|
576
|
+
owner!: Ref<User | undefined>;
|
|
577
|
+
}`,
|
|
578
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
579
|
+
@Entity()
|
|
580
|
+
class User {
|
|
581
|
+
@Property({ nullable: true })
|
|
582
|
+
owner!: Ref<User | undefined>;
|
|
583
|
+
}`,
|
|
584
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
585
|
+
},
|
|
586
|
+
// PrimaryKey number fields should default to t.integer when missing
|
|
587
|
+
{
|
|
588
|
+
code: /* typescript */ `import { Entity, PrimaryKey } from "@mikro-orm/core";
|
|
589
|
+
@Entity()
|
|
590
|
+
class User {
|
|
591
|
+
@PrimaryKey()
|
|
592
|
+
id!: number;
|
|
593
|
+
}`,
|
|
594
|
+
output: /* typescript */ `import { Entity, PrimaryKey } from "@mikro-orm/core";
|
|
595
|
+
@Entity()
|
|
596
|
+
class User {
|
|
597
|
+
@PrimaryKey({ type: t.integer })
|
|
598
|
+
id!: number;
|
|
599
|
+
}`,
|
|
600
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
601
|
+
},
|
|
602
|
+
// Custom property-like decorators should keep their decorator name
|
|
603
|
+
{
|
|
604
|
+
code: /* typescript */ `import { Entity } from "@mikro-orm/core";
|
|
605
|
+
@Entity()
|
|
606
|
+
class User {
|
|
607
|
+
@EncryptedProperty({ type: t.float, length: 255 })
|
|
608
|
+
secret!: string;
|
|
609
|
+
}`,
|
|
610
|
+
output: /* typescript */ `import { Entity } from "@mikro-orm/core";
|
|
611
|
+
@Entity()
|
|
612
|
+
class User {
|
|
613
|
+
@EncryptedProperty({ type: t.string, length: 255 })
|
|
614
|
+
secret!: string;
|
|
615
|
+
}`,
|
|
616
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
617
|
+
},
|
|
618
|
+
// Custom class types should remove unnecessary type config
|
|
619
|
+
{
|
|
620
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
621
|
+
class Profile {}
|
|
622
|
+
@Entity()
|
|
623
|
+
class User {
|
|
624
|
+
@Property({ type: t.string })
|
|
625
|
+
profile!: Profile;
|
|
626
|
+
}`,
|
|
627
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
628
|
+
class Profile {}
|
|
629
|
+
@Entity()
|
|
630
|
+
class User {
|
|
631
|
+
@Property()
|
|
632
|
+
profile!: Profile;
|
|
633
|
+
}`,
|
|
634
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
635
|
+
},
|
|
636
|
+
// Missing decorators for custom class types should add an empty @Property()
|
|
637
|
+
{
|
|
638
|
+
code: /* typescript */ `import { Entity } from "@mikro-orm/core";
|
|
639
|
+
class Profile {}
|
|
640
|
+
@Entity()
|
|
641
|
+
class User {
|
|
642
|
+
profile!: Profile;
|
|
643
|
+
}`,
|
|
644
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
645
|
+
class Profile {}
|
|
646
|
+
@Entity()
|
|
647
|
+
class User {
|
|
648
|
+
@Property()
|
|
649
|
+
profile!: Profile;
|
|
650
|
+
}`,
|
|
651
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
652
|
+
},
|
|
653
|
+
// String arrays should use t.array
|
|
654
|
+
{
|
|
655
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
656
|
+
@Entity()
|
|
657
|
+
class User {
|
|
658
|
+
@Property({ type: t.string })
|
|
659
|
+
tags!: string[];
|
|
660
|
+
}`,
|
|
661
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
662
|
+
@Entity()
|
|
663
|
+
class User {
|
|
664
|
+
@Property({ type: t.array })
|
|
665
|
+
tags!: string[];
|
|
666
|
+
}`,
|
|
667
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
668
|
+
},
|
|
669
|
+
// Boolean arrays should use JSON storage
|
|
670
|
+
{
|
|
671
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
672
|
+
@Entity()
|
|
673
|
+
class User {
|
|
674
|
+
@Property({ type: t.array })
|
|
675
|
+
flags!: boolean[];
|
|
676
|
+
}`,
|
|
677
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
678
|
+
@Entity()
|
|
679
|
+
class User {
|
|
680
|
+
@Property({ type: t.json })
|
|
681
|
+
flags!: boolean[];
|
|
682
|
+
}`,
|
|
683
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
684
|
+
},
|
|
685
|
+
// Record arrays should use JSON storage
|
|
686
|
+
{
|
|
687
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
688
|
+
@Entity()
|
|
689
|
+
class User {
|
|
690
|
+
@Property({ type: t.array })
|
|
691
|
+
records!: Record<string, unknown>[];
|
|
692
|
+
}`,
|
|
693
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
694
|
+
@Entity()
|
|
695
|
+
class User {
|
|
696
|
+
@Property({ type: t.json })
|
|
697
|
+
records!: Record<string, unknown>[];
|
|
698
|
+
}`,
|
|
699
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
700
|
+
},
|
|
701
|
+
// Bare Array references should remove unnecessary type config
|
|
702
|
+
{
|
|
703
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
704
|
+
@Entity()
|
|
705
|
+
class User {
|
|
706
|
+
@Property({ type: t.string })
|
|
707
|
+
values!: Array;
|
|
708
|
+
}`,
|
|
709
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
710
|
+
@Entity()
|
|
711
|
+
class User {
|
|
712
|
+
@Property()
|
|
713
|
+
values!: Array;
|
|
714
|
+
}`,
|
|
715
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
716
|
+
},
|
|
717
|
+
// Nullable number arrays should keep valid vector config and add nullable
|
|
718
|
+
{
|
|
719
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
720
|
+
@Entity()
|
|
721
|
+
class User {
|
|
722
|
+
@Property({ type: VectorType })
|
|
723
|
+
embedding?: number[];
|
|
724
|
+
}`,
|
|
725
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
726
|
+
@Entity()
|
|
727
|
+
class User {
|
|
728
|
+
@Property({ type: VectorType, nullable: true })
|
|
729
|
+
embedding?: number[];
|
|
730
|
+
}`,
|
|
731
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
732
|
+
},
|
|
733
|
+
// Enum types without decorators should add @Enum
|
|
734
|
+
{
|
|
735
|
+
code: /* typescript */ `import { Entity } from "@mikro-orm/core";
|
|
736
|
+
enum Role {
|
|
737
|
+
Admin,
|
|
738
|
+
User
|
|
739
|
+
}
|
|
740
|
+
@Entity()
|
|
741
|
+
class User {
|
|
742
|
+
role!: Role;
|
|
743
|
+
}`,
|
|
744
|
+
output: /* typescript */ `import { Entity, Enum } from "@mikro-orm/core";
|
|
745
|
+
enum Role {
|
|
746
|
+
Admin,
|
|
747
|
+
User
|
|
748
|
+
}
|
|
749
|
+
@Entity()
|
|
750
|
+
class User {
|
|
751
|
+
@Enum({ items: () => Role })
|
|
752
|
+
role!: Role;
|
|
753
|
+
}`,
|
|
754
|
+
errors: [{ messageId: "useEnumDecorator" }],
|
|
755
|
+
},
|
|
756
|
+
// Aliased Enum imports should not suppress the unaliased runtime import
|
|
757
|
+
{
|
|
758
|
+
code: /* typescript */ `import { Entity, Enum as MikroEnum } from "@mikro-orm/core";
|
|
759
|
+
enum Role {
|
|
760
|
+
Admin,
|
|
761
|
+
User
|
|
762
|
+
}
|
|
763
|
+
@Entity()
|
|
764
|
+
class User {
|
|
765
|
+
role!: Role;
|
|
766
|
+
}`,
|
|
767
|
+
output: /* typescript */ `import { Entity, Enum as MikroEnum, Enum } from "@mikro-orm/core";
|
|
768
|
+
enum Role {
|
|
769
|
+
Admin,
|
|
770
|
+
User
|
|
771
|
+
}
|
|
772
|
+
@Entity()
|
|
773
|
+
class User {
|
|
774
|
+
@Enum({ items: () => Role })
|
|
775
|
+
role!: Role;
|
|
776
|
+
}`,
|
|
777
|
+
errors: [{ messageId: "useEnumDecorator" }],
|
|
778
|
+
},
|
|
779
|
+
// Enum imports should be value imports even when @mikro-orm/core is type-only
|
|
780
|
+
{
|
|
781
|
+
code: /* typescript */ `import type { Ref } from "@mikro-orm/core";
|
|
782
|
+
import { Entity } from "@mikro-orm/postgresql";
|
|
783
|
+
enum Role {
|
|
784
|
+
Admin,
|
|
785
|
+
User
|
|
786
|
+
}
|
|
787
|
+
@Entity()
|
|
788
|
+
class User {
|
|
789
|
+
role!: Role;
|
|
790
|
+
}`,
|
|
791
|
+
output: /* typescript */ `import { Enum } from '@mikro-orm/core';
|
|
792
|
+
import type { Ref } from "@mikro-orm/core";
|
|
793
|
+
import { Entity } from "@mikro-orm/postgresql";
|
|
794
|
+
enum Role {
|
|
795
|
+
Admin,
|
|
796
|
+
User
|
|
797
|
+
}
|
|
798
|
+
@Entity()
|
|
799
|
+
class User {
|
|
800
|
+
@Enum({ items: () => Role })
|
|
801
|
+
role!: Role;
|
|
802
|
+
}`,
|
|
803
|
+
errors: [{ messageId: "useEnumDecorator" }],
|
|
804
|
+
},
|
|
805
|
+
// Empty @Enum() should be rebuilt when nullable configuration is wrong
|
|
806
|
+
{
|
|
807
|
+
code: /* typescript */ `import { Entity, Enum } from "@mikro-orm/core";
|
|
808
|
+
enum Role {
|
|
809
|
+
Admin,
|
|
810
|
+
User
|
|
811
|
+
}
|
|
812
|
+
@Entity()
|
|
813
|
+
class User {
|
|
814
|
+
@Enum()
|
|
815
|
+
role?: Role;
|
|
816
|
+
}`,
|
|
817
|
+
output: /* typescript */ `import { Entity, Enum } from "@mikro-orm/core";
|
|
818
|
+
enum Role {
|
|
819
|
+
Admin,
|
|
820
|
+
User
|
|
821
|
+
}
|
|
822
|
+
@Entity()
|
|
823
|
+
class User {
|
|
824
|
+
@Enum({ items: () => Role, nullable: true })
|
|
825
|
+
role?: Role;
|
|
826
|
+
}`,
|
|
827
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
828
|
+
},
|
|
829
|
+
// Non-object @Enum arguments should be rebuilt
|
|
830
|
+
{
|
|
831
|
+
code: /* typescript */ `import { Entity, Enum } from "@mikro-orm/core";
|
|
832
|
+
enum Role {
|
|
833
|
+
Admin,
|
|
834
|
+
User
|
|
835
|
+
}
|
|
836
|
+
@Entity()
|
|
837
|
+
class User {
|
|
838
|
+
@Enum(() => Role)
|
|
839
|
+
role?: Role;
|
|
840
|
+
}`,
|
|
841
|
+
output: /* typescript */ `import { Entity, Enum } from "@mikro-orm/core";
|
|
842
|
+
enum Role {
|
|
843
|
+
Admin,
|
|
844
|
+
User
|
|
845
|
+
}
|
|
846
|
+
@Entity()
|
|
847
|
+
class User {
|
|
848
|
+
@Enum({ items: () => Role, nullable: true })
|
|
849
|
+
role?: Role;
|
|
850
|
+
}`,
|
|
851
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
852
|
+
},
|
|
853
|
+
// Non-object @Property arguments should be replaced with object config
|
|
854
|
+
{
|
|
855
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
856
|
+
@Entity()
|
|
857
|
+
class User {
|
|
858
|
+
@Property(() => String)
|
|
859
|
+
name!: string;
|
|
860
|
+
}`,
|
|
861
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
862
|
+
@Entity()
|
|
863
|
+
class User {
|
|
864
|
+
@Property({ type: t.string })
|
|
865
|
+
name!: string;
|
|
866
|
+
}`,
|
|
867
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
868
|
+
},
|
|
869
|
+
// Literal initializers without annotations should add Opt<T> and align @Property
|
|
870
|
+
{
|
|
871
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
872
|
+
@Entity()
|
|
873
|
+
class User {
|
|
874
|
+
@Property()
|
|
875
|
+
enabled = true;
|
|
876
|
+
}`,
|
|
877
|
+
output: [
|
|
878
|
+
/* typescript */ `import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
879
|
+
@Entity()
|
|
880
|
+
class User {
|
|
881
|
+
@Property()
|
|
882
|
+
enabled: Opt<boolean> = true;
|
|
883
|
+
}`,
|
|
884
|
+
/* typescript */ `import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
885
|
+
@Entity()
|
|
886
|
+
class User {
|
|
887
|
+
@Property({ type: t.boolean })
|
|
888
|
+
enabled: Opt<boolean> = true;
|
|
889
|
+
}`,
|
|
890
|
+
],
|
|
891
|
+
errors: [
|
|
892
|
+
{ messageId: "useOptTypeForInitializedProperty" },
|
|
893
|
+
{ messageId: "alignPropertyDecoratorWithTsType" },
|
|
894
|
+
],
|
|
895
|
+
},
|
|
896
|
+
// Number literal initializers without annotations should infer Opt<number>
|
|
897
|
+
{
|
|
898
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
899
|
+
@Entity()
|
|
900
|
+
class User {
|
|
901
|
+
@Property()
|
|
902
|
+
score = 1;
|
|
903
|
+
}`,
|
|
904
|
+
output: [
|
|
905
|
+
/* typescript */ `import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
906
|
+
@Entity()
|
|
907
|
+
class User {
|
|
908
|
+
@Property()
|
|
909
|
+
score: Opt<number> = 1;
|
|
910
|
+
}`,
|
|
911
|
+
/* typescript */ `import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
912
|
+
@Entity()
|
|
913
|
+
class User {
|
|
914
|
+
@Property({ type: t.float })
|
|
915
|
+
score: Opt<number> = 1;
|
|
916
|
+
}`,
|
|
917
|
+
],
|
|
918
|
+
errors: [
|
|
919
|
+
{ messageId: "useOptTypeForInitializedProperty" },
|
|
920
|
+
{ messageId: "alignPropertyDecoratorWithTsType" },
|
|
921
|
+
],
|
|
922
|
+
},
|
|
923
|
+
// String literal initializers without annotations should infer Opt<string>
|
|
924
|
+
{
|
|
925
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
926
|
+
@Entity()
|
|
927
|
+
class User {
|
|
928
|
+
@Property()
|
|
929
|
+
title = "hello";
|
|
930
|
+
}`,
|
|
931
|
+
output: [
|
|
932
|
+
/* typescript */ `import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
933
|
+
@Entity()
|
|
934
|
+
class User {
|
|
935
|
+
@Property()
|
|
936
|
+
title: Opt<string> = "hello";
|
|
937
|
+
}`,
|
|
938
|
+
/* typescript */ `import { Entity, Property, Opt } from "@mikro-orm/core";
|
|
939
|
+
@Entity()
|
|
940
|
+
class User {
|
|
941
|
+
@Property({ type: t.string })
|
|
942
|
+
title: Opt<string> = "hello";
|
|
943
|
+
}`,
|
|
944
|
+
],
|
|
945
|
+
errors: [
|
|
946
|
+
{ messageId: "useOptTypeForInitializedProperty" },
|
|
947
|
+
{ messageId: "alignPropertyDecoratorWithTsType" },
|
|
948
|
+
],
|
|
949
|
+
},
|
|
950
|
+
// Opt import should be inserted when there is no @mikro-orm/core import
|
|
951
|
+
{
|
|
952
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/postgresql";
|
|
953
|
+
@Entity()
|
|
954
|
+
class User {
|
|
955
|
+
@Property()
|
|
956
|
+
enabled: boolean = true;
|
|
957
|
+
}`,
|
|
958
|
+
output: [
|
|
959
|
+
/* typescript */ `import { Opt } from '@mikro-orm/core';
|
|
960
|
+
import { Entity, Property } from "@mikro-orm/postgresql";
|
|
961
|
+
@Entity()
|
|
962
|
+
class User {
|
|
963
|
+
@Property()
|
|
964
|
+
enabled: Opt<boolean> = true;
|
|
965
|
+
}`,
|
|
966
|
+
/* typescript */ `import { Opt } from '@mikro-orm/core';
|
|
967
|
+
import { Entity, Property } from "@mikro-orm/postgresql";
|
|
968
|
+
@Entity()
|
|
969
|
+
class User {
|
|
970
|
+
@Property({ type: t.boolean })
|
|
971
|
+
enabled: Opt<boolean> = true;
|
|
972
|
+
}`,
|
|
973
|
+
],
|
|
974
|
+
errors: [
|
|
975
|
+
{ messageId: "useOptTypeForInitializedProperty" },
|
|
976
|
+
{ messageId: "alignPropertyDecoratorWithTsType" },
|
|
977
|
+
],
|
|
978
|
+
},
|
|
979
|
+
// Opt import should be inserted into multiline @mikro-orm/core imports
|
|
980
|
+
{
|
|
981
|
+
code: /* typescript */ `import {
|
|
982
|
+
Entity,
|
|
983
|
+
Property
|
|
984
|
+
} from "@mikro-orm/core";
|
|
985
|
+
@Entity()
|
|
986
|
+
class User {
|
|
987
|
+
@Property({ type: t.boolean })
|
|
988
|
+
enabled: boolean = true;
|
|
989
|
+
}`,
|
|
990
|
+
output: /* typescript */ `import {
|
|
991
|
+
Entity,
|
|
992
|
+
Property,
|
|
993
|
+
Opt
|
|
994
|
+
} from "@mikro-orm/core";
|
|
995
|
+
@Entity()
|
|
996
|
+
class User {
|
|
997
|
+
@Property({ type: t.boolean })
|
|
998
|
+
enabled: Opt<boolean> = true;
|
|
999
|
+
}`,
|
|
1000
|
+
errors: [{ messageId: "useOptTypeForInitializedProperty" }],
|
|
1001
|
+
},
|
|
1002
|
+
// Invalid BigInt string storage for number should be replaced
|
|
1003
|
+
{
|
|
1004
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
1005
|
+
@Entity()
|
|
1006
|
+
class User {
|
|
1007
|
+
@Property({ type: new BigIntType('string') })
|
|
1008
|
+
score!: number;
|
|
1009
|
+
}`,
|
|
1010
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
1011
|
+
@Entity()
|
|
1012
|
+
class User {
|
|
1013
|
+
@Property({ type: t.float })
|
|
1014
|
+
score!: number;
|
|
1015
|
+
}`,
|
|
1016
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
1017
|
+
},
|
|
1018
|
+
// Invalid BigInt number storage for string should be replaced
|
|
1019
|
+
{
|
|
1020
|
+
code: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
1021
|
+
@Entity()
|
|
1022
|
+
class User {
|
|
1023
|
+
@Property({ type: new BigIntType('number') })
|
|
1024
|
+
externalId!: string;
|
|
1025
|
+
}`,
|
|
1026
|
+
output: /* typescript */ `import { Entity, Property } from "@mikro-orm/core";
|
|
1027
|
+
@Entity()
|
|
1028
|
+
class User {
|
|
1029
|
+
@Property({ type: t.string })
|
|
1030
|
+
externalId!: string;
|
|
1031
|
+
}`,
|
|
1032
|
+
errors: [{ messageId: "alignPropertyDecoratorWithTsType" }],
|
|
1033
|
+
},
|
|
357
1034
|
],
|
|
358
1035
|
});
|