@mikro-orm/core 6.5.9-dev.0 → 6.5.9-dev.2
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/entity/EntityFactory.js +4 -0
- package/entity/defineEntity.d.ts +273 -400
- package/entity/defineEntity.js +33 -190
- package/index.mjs +2 -8
- package/package.json +2 -2
- package/platforms/Platform.d.ts +1 -1
- package/platforms/Platform.js +1 -5
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/unit-of-work/UnitOfWork.js +2 -2
package/entity/defineEntity.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.p = exports.OneToManyOptionsBuilderOnlyMappedBy = exports.UniversalPropertyOptionsBuilder = void 0;
|
|
4
4
|
exports.defineEntity = defineEntity;
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const EntitySchema_1 = require("../metadata/EntitySchema");
|
|
7
7
|
/** @internal */
|
|
8
|
-
class
|
|
8
|
+
class UniversalPropertyOptionsBuilder {
|
|
9
9
|
'~options';
|
|
10
10
|
'~type';
|
|
11
11
|
constructor(options) {
|
|
12
12
|
this['~options'] = options;
|
|
13
13
|
}
|
|
14
14
|
assignOptions(options) {
|
|
15
|
-
return new
|
|
15
|
+
return new UniversalPropertyOptionsBuilder({ ...this['~options'], ...options });
|
|
16
|
+
}
|
|
17
|
+
$type() {
|
|
18
|
+
return this.assignOptions({});
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* Alias for `fieldName`.
|
|
@@ -326,20 +329,6 @@ class PropertyOptionsBuilder {
|
|
|
326
329
|
ignoreSchemaChanges(...ignoreSchemaChanges) {
|
|
327
330
|
return this.assignOptions({ ignoreSchemaChanges });
|
|
328
331
|
}
|
|
329
|
-
$type() {
|
|
330
|
-
return this.assignOptions({});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
exports.PropertyOptionsBuilder = PropertyOptionsBuilder;
|
|
334
|
-
/** @internal */
|
|
335
|
-
class EnumOptionsBuilder extends PropertyOptionsBuilder {
|
|
336
|
-
constructor(options) {
|
|
337
|
-
super(options);
|
|
338
|
-
this['~options'] = options;
|
|
339
|
-
}
|
|
340
|
-
assignOptions(options) {
|
|
341
|
-
return new EnumOptionsBuilder({ ...this['~options'], ...options });
|
|
342
|
-
}
|
|
343
332
|
array(array = true) {
|
|
344
333
|
return this.assignOptions({ array });
|
|
345
334
|
}
|
|
@@ -347,17 +336,6 @@ class EnumOptionsBuilder extends PropertyOptionsBuilder {
|
|
|
347
336
|
nativeEnumName(nativeEnumName) {
|
|
348
337
|
return this.assignOptions({ nativeEnumName });
|
|
349
338
|
}
|
|
350
|
-
}
|
|
351
|
-
exports.EnumOptionsBuilder = EnumOptionsBuilder;
|
|
352
|
-
/** @internal */
|
|
353
|
-
class EmbeddedOptionsBuilder extends PropertyOptionsBuilder {
|
|
354
|
-
constructor(options) {
|
|
355
|
-
super(options);
|
|
356
|
-
this['~options'] = options;
|
|
357
|
-
}
|
|
358
|
-
assignOptions(options) {
|
|
359
|
-
return new EmbeddedOptionsBuilder({ ...this['~options'], ...options });
|
|
360
|
-
}
|
|
361
339
|
prefix(prefix) {
|
|
362
340
|
return this.assignOptions({ prefix });
|
|
363
341
|
}
|
|
@@ -367,17 +345,6 @@ class EmbeddedOptionsBuilder extends PropertyOptionsBuilder {
|
|
|
367
345
|
object(object = true) {
|
|
368
346
|
return this.assignOptions({ object });
|
|
369
347
|
}
|
|
370
|
-
array(array = true) {
|
|
371
|
-
return this.assignOptions({ array });
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
exports.EmbeddedOptionsBuilder = EmbeddedOptionsBuilder;
|
|
375
|
-
/** @internal */
|
|
376
|
-
class ReferenceOptionsBuilder extends PropertyOptionsBuilder {
|
|
377
|
-
constructor(options) {
|
|
378
|
-
super(options);
|
|
379
|
-
this['~options'] = options;
|
|
380
|
-
}
|
|
381
348
|
/** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
|
|
382
349
|
cascade(...cascade) {
|
|
383
350
|
return this.assignOptions({ cascade });
|
|
@@ -390,17 +357,6 @@ class ReferenceOptionsBuilder extends PropertyOptionsBuilder {
|
|
|
390
357
|
strategy(strategy) {
|
|
391
358
|
return this.assignOptions({ strategy });
|
|
392
359
|
}
|
|
393
|
-
}
|
|
394
|
-
exports.ReferenceOptionsBuilder = ReferenceOptionsBuilder;
|
|
395
|
-
/** @internal */
|
|
396
|
-
class ManyToManyOptionsBuilder extends ReferenceOptionsBuilder {
|
|
397
|
-
constructor(options) {
|
|
398
|
-
super(options);
|
|
399
|
-
this['~options'] = options;
|
|
400
|
-
}
|
|
401
|
-
assignOptions(options) {
|
|
402
|
-
return new ManyToManyOptionsBuilder({ ...this['~options'], ...options });
|
|
403
|
-
}
|
|
404
360
|
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
405
361
|
owner(owner = true) {
|
|
406
362
|
return this.assignOptions({ owner });
|
|
@@ -469,180 +425,66 @@ class ManyToManyOptionsBuilder extends ReferenceOptionsBuilder {
|
|
|
469
425
|
updateRule(updateRule) {
|
|
470
426
|
return this.assignOptions({ updateRule });
|
|
471
427
|
}
|
|
472
|
-
}
|
|
473
|
-
exports.ManyToManyOptionsBuilder = ManyToManyOptionsBuilder;
|
|
474
|
-
/** @internal */
|
|
475
|
-
class ManyToOneOptionsBuilder extends ReferenceOptionsBuilder {
|
|
476
|
-
constructor(options) {
|
|
477
|
-
super(options);
|
|
478
|
-
this['~options'] = options;
|
|
479
|
-
}
|
|
480
|
-
assignOptions(options) {
|
|
481
|
-
return new ManyToOneOptionsBuilder({ ...this['~options'], ...options });
|
|
482
|
-
}
|
|
483
|
-
/** Point to the inverse side property name. */
|
|
484
|
-
inversedBy(inversedBy) {
|
|
485
|
-
return this.assignOptions({ inversedBy });
|
|
486
|
-
}
|
|
487
428
|
/** Map this relation to the primary key value instead of an entity. */
|
|
488
429
|
mapToPk(mapToPk = true) {
|
|
489
430
|
return this.assignOptions({ mapToPk });
|
|
490
431
|
}
|
|
491
|
-
/**
|
|
492
|
-
|
|
493
|
-
return this.assignOptions({
|
|
494
|
-
}
|
|
495
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
496
|
-
joinColumns(...joinColumns) {
|
|
497
|
-
return this.assignOptions({ joinColumns });
|
|
432
|
+
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
433
|
+
deferMode(deferMode) {
|
|
434
|
+
return this.assignOptions({ deferMode });
|
|
498
435
|
}
|
|
499
436
|
/** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
|
|
500
437
|
ownColumns(...ownColumns) {
|
|
501
438
|
return this.assignOptions({ ownColumns });
|
|
502
439
|
}
|
|
503
|
-
/**
|
|
504
|
-
|
|
505
|
-
return this.assignOptions({
|
|
506
|
-
}
|
|
507
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
508
|
-
referencedColumnNames(...referencedColumnNames) {
|
|
509
|
-
return this.assignOptions({ referencedColumnNames });
|
|
510
|
-
}
|
|
511
|
-
/** What to do when the target entity gets deleted. */
|
|
512
|
-
deleteRule(deleteRule) {
|
|
513
|
-
return this.assignOptions({ deleteRule });
|
|
440
|
+
/** Enable/disable foreign key constraint creation on this relation */
|
|
441
|
+
createForeignKeyConstraint(createForeignKeyConstraint = true) {
|
|
442
|
+
return this.assignOptions({ createForeignKeyConstraint });
|
|
514
443
|
}
|
|
515
|
-
/**
|
|
516
|
-
|
|
517
|
-
return this.assignOptions({
|
|
518
|
-
}
|
|
519
|
-
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
520
|
-
deferMode(deferMode) {
|
|
521
|
-
return this.assignOptions({ deferMode });
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
exports.ManyToOneOptionsBuilder = ManyToOneOptionsBuilder;
|
|
525
|
-
/** @internal */
|
|
526
|
-
class OneToManyOptionsBuilder extends ReferenceOptionsBuilder {
|
|
527
|
-
constructor(options) {
|
|
528
|
-
super(options);
|
|
529
|
-
this['~options'] = options;
|
|
530
|
-
}
|
|
531
|
-
assignOptions(options) {
|
|
532
|
-
return new OneToManyOptionsBuilder({ ...this['~options'], ...options });
|
|
444
|
+
/** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
|
|
445
|
+
foreignKeyName(foreignKeyName) {
|
|
446
|
+
return this.assignOptions({ foreignKeyName });
|
|
533
447
|
}
|
|
534
448
|
/** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
|
|
535
449
|
orphanRemoval(orphanRemoval = true) {
|
|
536
450
|
return this.assignOptions({ orphanRemoval });
|
|
537
451
|
}
|
|
538
|
-
/** Set default ordering. */
|
|
539
|
-
orderBy(orderBy) {
|
|
540
|
-
return this.assignOptions({ orderBy });
|
|
541
|
-
}
|
|
542
|
-
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
543
|
-
where(where) {
|
|
544
|
-
return this.assignOptions({ where });
|
|
545
|
-
}
|
|
546
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
547
|
-
joinColumn(joinColumn) {
|
|
548
|
-
return this.assignOptions({ joinColumn });
|
|
549
|
-
}
|
|
550
|
-
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
551
|
-
joinColumns(...joinColumns) {
|
|
552
|
-
return this.assignOptions({ joinColumns });
|
|
553
|
-
}
|
|
554
|
-
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
555
|
-
inverseJoinColumn(inverseJoinColumn) {
|
|
556
|
-
return this.assignOptions({ inverseJoinColumn });
|
|
557
|
-
}
|
|
558
|
-
/** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
559
|
-
inverseJoinColumns(...inverseJoinColumns) {
|
|
560
|
-
return this.assignOptions({ inverseJoinColumns });
|
|
561
|
-
}
|
|
562
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
563
|
-
referenceColumnName(referenceColumnName) {
|
|
564
|
-
return this.assignOptions({ referenceColumnName });
|
|
565
|
-
}
|
|
566
|
-
/** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
|
|
567
|
-
referencedColumnNames(...referencedColumnNames) {
|
|
568
|
-
return this.assignOptions({ referencedColumnNames });
|
|
569
|
-
}
|
|
570
452
|
}
|
|
571
|
-
exports.
|
|
453
|
+
exports.UniversalPropertyOptionsBuilder = UniversalPropertyOptionsBuilder;
|
|
572
454
|
/** @internal */
|
|
573
|
-
class OneToManyOptionsBuilderOnlyMappedBy {
|
|
574
|
-
constructor(options) {
|
|
575
|
-
this['~options'] = options;
|
|
576
|
-
}
|
|
455
|
+
class OneToManyOptionsBuilderOnlyMappedBy extends UniversalPropertyOptionsBuilder {
|
|
577
456
|
/** Point to the owning side property name. */
|
|
578
457
|
mappedBy(mappedBy) {
|
|
579
|
-
return new
|
|
458
|
+
return new UniversalPropertyOptionsBuilder({ ...this['~options'], mappedBy });
|
|
580
459
|
}
|
|
581
460
|
}
|
|
582
461
|
exports.OneToManyOptionsBuilderOnlyMappedBy = OneToManyOptionsBuilderOnlyMappedBy;
|
|
583
|
-
/** @internal */
|
|
584
|
-
class OneToOneOptionsBuilder extends ReferenceOptionsBuilder {
|
|
585
|
-
constructor(options) {
|
|
586
|
-
super(options);
|
|
587
|
-
this['~options'] = options;
|
|
588
|
-
}
|
|
589
|
-
assignOptions(options) {
|
|
590
|
-
return new OneToOneOptionsBuilder({ ...this['~options'], ...options });
|
|
591
|
-
}
|
|
592
|
-
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
593
|
-
owner(owner = true) {
|
|
594
|
-
return this.assignOptions({ owner });
|
|
595
|
-
}
|
|
596
|
-
/** Point to the inverse side property name. */
|
|
597
|
-
inversedBy(inversedBy) {
|
|
598
|
-
return this.assignOptions({ inversedBy });
|
|
599
|
-
}
|
|
600
|
-
/** Map this relation to the primary key value instead of an entity. */
|
|
601
|
-
mapToPk(mapToPk = true) {
|
|
602
|
-
return this.assignOptions({ mapToPk });
|
|
603
|
-
}
|
|
604
|
-
/** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
|
|
605
|
-
ownColumns(...ownColumns) {
|
|
606
|
-
return this.assignOptions({ ownColumns });
|
|
607
|
-
}
|
|
608
|
-
/** What to do when the target entity gets deleted. */
|
|
609
|
-
deleteRule(deleteRule) {
|
|
610
|
-
return this.assignOptions({ deleteRule });
|
|
611
|
-
}
|
|
612
|
-
/** What to do when the reference to the target entity gets updated. */
|
|
613
|
-
updateRule(updateRule) {
|
|
614
|
-
return this.assignOptions({ updateRule });
|
|
615
|
-
}
|
|
616
|
-
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
617
|
-
deferMode(deferMode) {
|
|
618
|
-
return this.assignOptions({ deferMode });
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
exports.OneToOneOptionsBuilder = OneToOneOptionsBuilder;
|
|
622
462
|
function createPropertyBuilders(options) {
|
|
623
|
-
return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new
|
|
463
|
+
return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new UniversalPropertyOptionsBuilder({ type: value })]));
|
|
624
464
|
}
|
|
625
465
|
const propertyBuilders = {
|
|
626
466
|
...createPropertyBuilders(types_1.types),
|
|
627
|
-
bigint: (mode) => new
|
|
628
|
-
array: (toJsValue = i => i, toDbValue = i => i) => new
|
|
629
|
-
decimal: (mode) => new
|
|
630
|
-
json: () => new
|
|
631
|
-
formula: (formula) => new
|
|
632
|
-
|
|
633
|
-
|
|
467
|
+
bigint: (mode) => new UniversalPropertyOptionsBuilder({ type: new types_1.types.bigint(mode) }),
|
|
468
|
+
array: (toJsValue = i => i, toDbValue = i => i) => new UniversalPropertyOptionsBuilder({ type: new types_1.types.array(toJsValue, toDbValue) }),
|
|
469
|
+
decimal: (mode) => new UniversalPropertyOptionsBuilder({ type: new types_1.types.decimal(mode) }),
|
|
470
|
+
json: () => new UniversalPropertyOptionsBuilder({ type: types_1.types.json }),
|
|
471
|
+
formula: (formula) => new UniversalPropertyOptionsBuilder({ formula }),
|
|
472
|
+
datetime: (length) => new UniversalPropertyOptionsBuilder({ type: types_1.types.datetime, length }),
|
|
473
|
+
time: (length) => new UniversalPropertyOptionsBuilder({ type: types_1.types.time, length }),
|
|
474
|
+
type: (type) => new UniversalPropertyOptionsBuilder({ type }),
|
|
475
|
+
enum: (items) => new UniversalPropertyOptionsBuilder({
|
|
634
476
|
enum: true,
|
|
635
477
|
items,
|
|
636
478
|
}),
|
|
637
|
-
embedded: (target) => new
|
|
479
|
+
embedded: (target) => new UniversalPropertyOptionsBuilder({
|
|
638
480
|
entity: () => target,
|
|
639
481
|
kind: 'embedded',
|
|
640
482
|
}),
|
|
641
|
-
manyToMany: (target) => new
|
|
483
|
+
manyToMany: (target) => new UniversalPropertyOptionsBuilder({
|
|
642
484
|
entity: () => target,
|
|
643
485
|
kind: 'm:n',
|
|
644
486
|
}),
|
|
645
|
-
manyToOne: (target) => new
|
|
487
|
+
manyToOne: (target) => new UniversalPropertyOptionsBuilder({
|
|
646
488
|
entity: () => target,
|
|
647
489
|
kind: 'm:1',
|
|
648
490
|
}),
|
|
@@ -650,11 +492,12 @@ const propertyBuilders = {
|
|
|
650
492
|
entity: () => target,
|
|
651
493
|
kind: '1:m',
|
|
652
494
|
}),
|
|
653
|
-
oneToOne: (target) => new
|
|
495
|
+
oneToOne: (target) => new UniversalPropertyOptionsBuilder({
|
|
654
496
|
entity: () => target,
|
|
655
497
|
kind: '1:1',
|
|
656
498
|
}),
|
|
657
499
|
};
|
|
500
|
+
exports.p = propertyBuilders;
|
|
658
501
|
function getBuilderOptions(builder) {
|
|
659
502
|
return '~options' in builder ? builder['~options'] : builder;
|
|
660
503
|
}
|
package/index.mjs
CHANGED
|
@@ -56,7 +56,6 @@ export const DriverException = mod.DriverException;
|
|
|
56
56
|
export const EagerProps = mod.EagerProps;
|
|
57
57
|
export const Embeddable = mod.Embeddable;
|
|
58
58
|
export const Embedded = mod.Embedded;
|
|
59
|
-
export const EmbeddedOptionsBuilder = mod.EmbeddedOptionsBuilder;
|
|
60
59
|
export const EnsureRequestContext = mod.EnsureRequestContext;
|
|
61
60
|
export const Entity = mod.Entity;
|
|
62
61
|
export const EntityAssigner = mod.EntityAssigner;
|
|
@@ -77,7 +76,6 @@ export const EntityTransformer = mod.EntityTransformer;
|
|
|
77
76
|
export const EntityValidator = mod.EntityValidator;
|
|
78
77
|
export const Enum = mod.Enum;
|
|
79
78
|
export const EnumArrayType = mod.EnumArrayType;
|
|
80
|
-
export const EnumOptionsBuilder = mod.EnumOptionsBuilder;
|
|
81
79
|
export const EnumType = mod.EnumType;
|
|
82
80
|
export const EventManager = mod.EventManager;
|
|
83
81
|
export const EventType = mod.EventType;
|
|
@@ -107,9 +105,7 @@ export const LoadStrategy = mod.LoadStrategy;
|
|
|
107
105
|
export const LockMode = mod.LockMode;
|
|
108
106
|
export const LockWaitTimeoutException = mod.LockWaitTimeoutException;
|
|
109
107
|
export const ManyToMany = mod.ManyToMany;
|
|
110
|
-
export const ManyToManyOptionsBuilder = mod.ManyToManyOptionsBuilder;
|
|
111
108
|
export const ManyToOne = mod.ManyToOne;
|
|
112
|
-
export const ManyToOneOptionsBuilder = mod.ManyToOneOptionsBuilder;
|
|
113
109
|
export const MediumIntType = mod.MediumIntType;
|
|
114
110
|
export const MemoryCacheAdapter = mod.MemoryCacheAdapter;
|
|
115
111
|
export const MetadataDiscovery = mod.MetadataDiscovery;
|
|
@@ -130,10 +126,8 @@ export const ObjectHydrator = mod.ObjectHydrator;
|
|
|
130
126
|
export const OnInit = mod.OnInit;
|
|
131
127
|
export const OnLoad = mod.OnLoad;
|
|
132
128
|
export const OneToMany = mod.OneToMany;
|
|
133
|
-
export const OneToManyOptionsBuilder = mod.OneToManyOptionsBuilder;
|
|
134
129
|
export const OneToManyOptionsBuilderOnlyMappedBy = mod.OneToManyOptionsBuilderOnlyMappedBy;
|
|
135
130
|
export const OneToOne = mod.OneToOne;
|
|
136
|
-
export const OneToOneOptionsBuilder = mod.OneToOneOptionsBuilder;
|
|
137
131
|
export const Opt = mod.Opt;
|
|
138
132
|
export const OptimisticLockError = mod.OptimisticLockError;
|
|
139
133
|
export const OptionalProps = mod.OptionalProps;
|
|
@@ -144,7 +138,6 @@ export const PopulatePath = mod.PopulatePath;
|
|
|
144
138
|
export const PrimaryKey = mod.PrimaryKey;
|
|
145
139
|
export const PrimaryKeyProp = mod.PrimaryKeyProp;
|
|
146
140
|
export const Property = mod.Property;
|
|
147
|
-
export const PropertyOptionsBuilder = mod.PropertyOptionsBuilder;
|
|
148
141
|
export const QueryFlag = mod.QueryFlag;
|
|
149
142
|
export const QueryHelper = mod.QueryHelper;
|
|
150
143
|
export const QueryOperator = mod.QueryOperator;
|
|
@@ -155,7 +148,6 @@ export const ReadOnlyException = mod.ReadOnlyException;
|
|
|
155
148
|
export const Ref = mod.Ref;
|
|
156
149
|
export const Reference = mod.Reference;
|
|
157
150
|
export const ReferenceKind = mod.ReferenceKind;
|
|
158
|
-
export const ReferenceOptionsBuilder = mod.ReferenceOptionsBuilder;
|
|
159
151
|
export const ReflectMetadataProvider = mod.ReflectMetadataProvider;
|
|
160
152
|
export const RequestContext = mod.RequestContext;
|
|
161
153
|
export const RequiredNullable = mod.RequiredNullable;
|
|
@@ -185,6 +177,7 @@ export const UnderscoreNamingStrategy = mod.UnderscoreNamingStrategy;
|
|
|
185
177
|
export const Unique = mod.Unique;
|
|
186
178
|
export const UniqueConstraintViolationException = mod.UniqueConstraintViolationException;
|
|
187
179
|
export const UnitOfWork = mod.UnitOfWork;
|
|
180
|
+
export const UniversalPropertyOptionsBuilder = mod.UniversalPropertyOptionsBuilder;
|
|
188
181
|
export const UnknownType = mod.UnknownType;
|
|
189
182
|
export const Utils = mod.Utils;
|
|
190
183
|
export const UuidType = mod.UuidType;
|
|
@@ -206,6 +199,7 @@ export const getOnConflictFields = mod.getOnConflictFields;
|
|
|
206
199
|
export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
|
|
207
200
|
export const getWhereCondition = mod.getWhereCondition;
|
|
208
201
|
export const helper = mod.helper;
|
|
202
|
+
export const p = mod.p;
|
|
209
203
|
export const parseJsonSafe = mod.parseJsonSafe;
|
|
210
204
|
export const quote = mod.quote;
|
|
211
205
|
export const raw = mod.raw;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.5.9-dev.
|
|
3
|
+
"version": "6.5.9-dev.2",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.2",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.5.9-dev.
|
|
67
|
+
"mikro-orm": "6.5.9-dev.2",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -156,7 +156,7 @@ export declare abstract class Platform {
|
|
|
156
156
|
getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
|
|
157
157
|
convertsJsonAutomatically(): boolean;
|
|
158
158
|
convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
|
|
159
|
-
convertJsonToJSValue(value: unknown,
|
|
159
|
+
convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
|
|
160
160
|
convertDateToJSValue(value: string | Date): string;
|
|
161
161
|
convertIntervalToJSValue(value: string): unknown;
|
|
162
162
|
convertIntervalToDatabaseValue(value: unknown): unknown;
|
package/platforms/Platform.js
CHANGED
|
@@ -288,11 +288,7 @@ class Platform {
|
|
|
288
288
|
convertJsonToDatabaseValue(value, context) {
|
|
289
289
|
return JSON.stringify(value);
|
|
290
290
|
}
|
|
291
|
-
convertJsonToJSValue(value,
|
|
292
|
-
const isObjectEmbedded = prop.embedded && prop.object;
|
|
293
|
-
if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
|
|
294
|
-
return value;
|
|
295
|
-
}
|
|
291
|
+
convertJsonToJSValue(value, context) {
|
|
296
292
|
return (0, Utils_1.parseJsonSafe)(value);
|
|
297
293
|
}
|
|
298
294
|
convertDateToJSValue(value) {
|
package/types/JsonType.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class JsonType extends Type<unknown, string | null> {
|
|
|
5
5
|
convertToDatabaseValue(value: unknown, platform: Platform, context?: TransformContext): string | null;
|
|
6
6
|
convertToJSValueSQL(key: string, platform: Platform): string;
|
|
7
7
|
convertToDatabaseValueSQL(key: string, platform: Platform): string;
|
|
8
|
-
convertToJSValue(value: string | unknown, platform: Platform): unknown;
|
|
8
|
+
convertToJSValue(value: string | unknown, platform: Platform, context?: TransformContext): unknown;
|
|
9
9
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
10
10
|
ensureComparable<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>): boolean;
|
|
11
11
|
compareAsType(): string;
|
package/types/JsonType.js
CHANGED
|
@@ -15,8 +15,13 @@ class JsonType extends Type_1.Type {
|
|
|
15
15
|
convertToDatabaseValueSQL(key, platform) {
|
|
16
16
|
return key + platform.castColumn(this.prop);
|
|
17
17
|
}
|
|
18
|
-
convertToJSValue(value, platform) {
|
|
19
|
-
|
|
18
|
+
convertToJSValue(value, platform, context) {
|
|
19
|
+
const isJsonColumn = ['json', 'jsonb', platform.getJsonDeclarationSQL()].includes(this.prop.columnTypes[0]);
|
|
20
|
+
const isObjectEmbedded = this.prop.embedded && this.prop.object;
|
|
21
|
+
if ((platform.convertsJsonAutomatically() || isObjectEmbedded) && isJsonColumn && !context?.force) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return platform.convertJsonToJSValue(value, context);
|
|
20
25
|
}
|
|
21
26
|
getColumnType(prop, platform) {
|
|
22
27
|
return platform.getJsonDeclarationSQL();
|
package/types/Type.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Platform } from '../platforms';
|
|
|
3
3
|
import type { Constructor, EntityMetadata, EntityProperty } from '../typings';
|
|
4
4
|
export interface TransformContext {
|
|
5
5
|
fromQuery?: boolean;
|
|
6
|
+
force?: boolean;
|
|
6
7
|
key?: string;
|
|
7
8
|
mode?: 'hydration' | 'query' | 'query-data' | 'discovery' | 'serialization';
|
|
8
9
|
}
|
|
@@ -23,7 +24,7 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
|
|
|
23
24
|
/**
|
|
24
25
|
* Converts a value from its database representation to its JS representation of this type.
|
|
25
26
|
*/
|
|
26
|
-
convertToJSValue(value: DBType, platform: Platform): JSType;
|
|
27
|
+
convertToJSValue(value: DBType, platform: Platform, context?: TransformContext): JSType;
|
|
27
28
|
/**
|
|
28
29
|
* Converts a value from its JS representation to its database representation of this type.
|
|
29
30
|
*/
|
package/types/Type.js
CHANGED
|
@@ -99,8 +99,8 @@ class UnitOfWork {
|
|
|
99
99
|
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta, true);
|
|
100
100
|
}
|
|
101
101
|
if (prop.hydrate === false && prop.customType?.ensureComparable(wrapped.__meta, prop)) {
|
|
102
|
-
const converted = prop.customType.convertToJSValue(data[key], this.platform);
|
|
103
|
-
data[key] = prop.customType.convertToDatabaseValue(converted, this.platform);
|
|
102
|
+
const converted = prop.customType.convertToJSValue(data[key], this.platform, { key, mode: 'hydration', force: true });
|
|
103
|
+
data[key] = prop.customType.convertToDatabaseValue(converted, this.platform, { key, mode: 'hydration' });
|
|
104
104
|
}
|
|
105
105
|
if (forceUndefined) {
|
|
106
106
|
if (data[key] === null) {
|