@mikro-orm/core 7.0.0-dev.8 → 7.0.0-dev.80

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 (181) hide show
  1. package/EntityManager.d.ts +85 -48
  2. package/EntityManager.js +300 -225
  3. package/MikroORM.d.ts +40 -31
  4. package/MikroORM.js +98 -137
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +6 -5
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +0 -1
  11. package/cache/index.js +0 -1
  12. package/connections/Connection.d.ts +11 -7
  13. package/connections/Connection.js +16 -14
  14. package/drivers/DatabaseDriver.d.ts +11 -5
  15. package/drivers/DatabaseDriver.js +17 -8
  16. package/drivers/IDatabaseDriver.d.ts +27 -5
  17. package/entity/BaseEntity.d.ts +0 -1
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +98 -30
  20. package/entity/Collection.js +432 -93
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +15 -7
  23. package/entity/EntityFactory.d.ts +7 -0
  24. package/entity/EntityFactory.js +64 -41
  25. package/entity/EntityHelper.js +26 -9
  26. package/entity/EntityLoader.d.ts +5 -4
  27. package/entity/EntityLoader.js +73 -40
  28. package/entity/EntityRepository.d.ts +1 -1
  29. package/entity/Reference.d.ts +9 -7
  30. package/entity/Reference.js +33 -6
  31. package/entity/WrappedEntity.d.ts +2 -4
  32. package/entity/WrappedEntity.js +1 -5
  33. package/entity/defineEntity.d.ts +549 -0
  34. package/entity/defineEntity.js +529 -0
  35. package/entity/index.d.ts +3 -2
  36. package/entity/index.js +3 -2
  37. package/entity/utils.d.ts +7 -0
  38. package/entity/utils.js +16 -4
  39. package/entity/validators.d.ts +11 -0
  40. package/entity/validators.js +65 -0
  41. package/enums.d.ts +21 -6
  42. package/enums.js +14 -1
  43. package/errors.d.ts +6 -2
  44. package/errors.js +14 -9
  45. package/events/EventSubscriber.d.ts +3 -1
  46. package/hydration/Hydrator.js +1 -2
  47. package/hydration/ObjectHydrator.d.ts +4 -4
  48. package/hydration/ObjectHydrator.js +36 -25
  49. package/index.d.ts +2 -2
  50. package/index.js +1 -2
  51. package/logging/DefaultLogger.d.ts +1 -1
  52. package/logging/SimpleLogger.d.ts +1 -1
  53. package/metadata/EntitySchema.d.ts +9 -13
  54. package/metadata/EntitySchema.js +44 -26
  55. package/metadata/MetadataDiscovery.d.ts +6 -9
  56. package/metadata/MetadataDiscovery.js +167 -206
  57. package/metadata/MetadataProvider.d.ts +11 -2
  58. package/metadata/MetadataProvider.js +44 -2
  59. package/metadata/MetadataStorage.d.ts +1 -6
  60. package/metadata/MetadataStorage.js +6 -18
  61. package/metadata/MetadataValidator.d.ts +0 -7
  62. package/metadata/MetadataValidator.js +4 -13
  63. package/metadata/discover-entities.d.ts +5 -0
  64. package/metadata/discover-entities.js +40 -0
  65. package/metadata/index.d.ts +1 -1
  66. package/metadata/index.js +1 -1
  67. package/metadata/types.d.ts +480 -0
  68. package/metadata/types.js +1 -0
  69. package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
  70. package/naming-strategy/AbstractNamingStrategy.js +8 -2
  71. package/naming-strategy/NamingStrategy.d.ts +11 -1
  72. package/not-supported.d.ts +2 -0
  73. package/not-supported.js +4 -0
  74. package/package.json +18 -10
  75. package/platforms/ExceptionConverter.js +1 -1
  76. package/platforms/Platform.d.ts +6 -10
  77. package/platforms/Platform.js +14 -39
  78. package/serialization/EntitySerializer.d.ts +2 -0
  79. package/serialization/EntitySerializer.js +32 -14
  80. package/serialization/EntityTransformer.js +22 -12
  81. package/serialization/SerializationContext.js +16 -13
  82. package/types/ArrayType.d.ts +1 -1
  83. package/types/ArrayType.js +2 -3
  84. package/types/BigIntType.d.ts +8 -6
  85. package/types/BigIntType.js +1 -1
  86. package/types/BlobType.d.ts +0 -1
  87. package/types/BlobType.js +0 -3
  88. package/types/BooleanType.d.ts +2 -1
  89. package/types/BooleanType.js +3 -0
  90. package/types/DecimalType.d.ts +6 -4
  91. package/types/DecimalType.js +3 -3
  92. package/types/DoubleType.js +2 -2
  93. package/types/JsonType.d.ts +1 -1
  94. package/types/JsonType.js +7 -2
  95. package/types/TinyIntType.js +1 -1
  96. package/types/Type.d.ts +2 -1
  97. package/types/Type.js +1 -1
  98. package/types/Uint8ArrayType.d.ts +0 -1
  99. package/types/Uint8ArrayType.js +1 -4
  100. package/types/index.d.ts +1 -1
  101. package/typings.d.ts +113 -77
  102. package/typings.js +41 -35
  103. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  104. package/unit-of-work/ChangeSetComputer.js +11 -9
  105. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  106. package/unit-of-work/ChangeSetPersister.js +58 -20
  107. package/unit-of-work/UnitOfWork.d.ts +8 -1
  108. package/unit-of-work/UnitOfWork.js +115 -57
  109. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  110. package/utils/AbstractSchemaGenerator.js +11 -9
  111. package/utils/Configuration.d.ts +757 -206
  112. package/utils/Configuration.js +139 -187
  113. package/utils/ConfigurationLoader.d.ts +1 -54
  114. package/utils/ConfigurationLoader.js +1 -352
  115. package/utils/Cursor.d.ts +3 -3
  116. package/utils/Cursor.js +4 -1
  117. package/utils/DataloaderUtils.d.ts +15 -5
  118. package/utils/DataloaderUtils.js +54 -8
  119. package/utils/EntityComparator.d.ts +8 -4
  120. package/utils/EntityComparator.js +111 -64
  121. package/utils/QueryHelper.d.ts +9 -1
  122. package/utils/QueryHelper.js +70 -9
  123. package/utils/RawQueryFragment.d.ts +36 -4
  124. package/utils/RawQueryFragment.js +35 -14
  125. package/utils/TransactionManager.d.ts +65 -0
  126. package/utils/TransactionManager.js +223 -0
  127. package/utils/Utils.d.ts +8 -97
  128. package/utils/Utils.js +88 -303
  129. package/utils/clone.js +2 -3
  130. package/utils/env-vars.d.ts +3 -0
  131. package/utils/env-vars.js +87 -0
  132. package/utils/fs-utils.d.ts +12 -0
  133. package/utils/fs-utils.js +96 -0
  134. package/utils/index.d.ts +2 -1
  135. package/utils/index.js +2 -1
  136. package/utils/upsert-utils.d.ts +7 -2
  137. package/utils/upsert-utils.js +55 -4
  138. package/decorators/Check.d.ts +0 -3
  139. package/decorators/Check.js +0 -13
  140. package/decorators/CreateRequestContext.d.ts +0 -3
  141. package/decorators/CreateRequestContext.js +0 -32
  142. package/decorators/Embeddable.d.ts +0 -8
  143. package/decorators/Embeddable.js +0 -11
  144. package/decorators/Embedded.d.ts +0 -18
  145. package/decorators/Embedded.js +0 -18
  146. package/decorators/Entity.d.ts +0 -18
  147. package/decorators/Entity.js +0 -12
  148. package/decorators/Enum.d.ts +0 -9
  149. package/decorators/Enum.js +0 -16
  150. package/decorators/Filter.d.ts +0 -2
  151. package/decorators/Filter.js +0 -8
  152. package/decorators/Formula.d.ts +0 -4
  153. package/decorators/Formula.js +0 -15
  154. package/decorators/Indexed.d.ts +0 -19
  155. package/decorators/Indexed.js +0 -20
  156. package/decorators/ManyToMany.d.ts +0 -40
  157. package/decorators/ManyToMany.js +0 -14
  158. package/decorators/ManyToOne.d.ts +0 -30
  159. package/decorators/ManyToOne.js +0 -14
  160. package/decorators/OneToMany.d.ts +0 -28
  161. package/decorators/OneToMany.js +0 -17
  162. package/decorators/OneToOne.d.ts +0 -24
  163. package/decorators/OneToOne.js +0 -7
  164. package/decorators/PrimaryKey.d.ts +0 -8
  165. package/decorators/PrimaryKey.js +0 -20
  166. package/decorators/Property.d.ts +0 -250
  167. package/decorators/Property.js +0 -32
  168. package/decorators/Transactional.d.ts +0 -13
  169. package/decorators/Transactional.js +0 -28
  170. package/decorators/hooks.d.ts +0 -16
  171. package/decorators/hooks.js +0 -47
  172. package/decorators/index.d.ts +0 -17
  173. package/decorators/index.js +0 -17
  174. package/entity/ArrayCollection.d.ts +0 -116
  175. package/entity/ArrayCollection.js +0 -402
  176. package/entity/EntityValidator.d.ts +0 -19
  177. package/entity/EntityValidator.js +0 -150
  178. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  179. package/metadata/ReflectMetadataProvider.js +0 -44
  180. package/utils/resolveContextProvider.d.ts +0 -10
  181. package/utils/resolveContextProvider.js +0 -28
@@ -1,14 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function ManyToMany(entity, mappedBy, options = {}) {
6
- return function (target, propertyName) {
7
- options = Utils.processDecoratorParameters({ entity, mappedBy, options });
8
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
9
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_MANY);
10
- const property = { name: propertyName, kind: ReferenceKind.MANY_TO_MANY };
11
- meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }
@@ -1,30 +0,0 @@
1
- import type { ReferenceOptions } from './Property.js';
2
- import { type DeferMode } from '../enums.js';
3
- import type { AnyString, EntityName } from '../typings.js';
4
- export declare function ManyToOne<Target extends object, Owner extends object>(entity?: ManyToOneOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), options?: Partial<ManyToOneOptions<Owner, Target>>): (target: Owner, propertyName: keyof Owner) => any;
5
- export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
6
- /** Point to the inverse side property name. */
7
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
8
- /** Wrap the entity in {@apilink Reference} wrapper. */
9
- ref?: boolean;
10
- /** Use this relation as a primary key. */
11
- primary?: boolean;
12
- /** Map this relation to the primary key value instead of an entity. */
13
- mapToPk?: boolean;
14
- /** 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. */
15
- joinColumn?: string;
16
- /** 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. */
17
- joinColumns?: string[];
18
- /** 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. */
19
- ownColumns?: string[];
20
- /** 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. */
21
- referenceColumnName?: string;
22
- /** 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. */
23
- referencedColumnNames?: string[];
24
- /** What to do when the target entity gets deleted. */
25
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
26
- /** What to do when the reference to the target entity gets updated. */
27
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
28
- /** 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. */
29
- deferMode?: DeferMode | `${DeferMode}`;
30
- }
@@ -1,14 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function ManyToOne(entity = {}, options = {}) {
6
- return function (target, propertyName) {
7
- options = Utils.processDecoratorParameters({ entity, options });
8
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
9
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.MANY_TO_ONE);
10
- const property = { name: propertyName, kind: ReferenceKind.MANY_TO_ONE };
11
- meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }
@@ -1,28 +0,0 @@
1
- import type { ReferenceOptions } from './Property.js';
2
- import { ReferenceKind, type QueryOrderMap } from '../enums.js';
3
- import type { EntityName, FilterQuery } from '../typings.js';
4
- export declare function createOneToDecorator<Target, Owner>(entity: OneToManyOptions<Owner, Target> | string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any) | undefined, options: Partial<OneToManyOptions<Owner, Target>>, kind: ReferenceKind): (target: Owner, propertyName: string) => any;
5
- export declare function OneToMany<Target, Owner>(entity: string | ((e?: any) => EntityName<Target>), mappedBy: (string & keyof Target) | ((e: Target) => any), options?: Partial<OneToManyOptions<Owner, Target>>): (target: Owner, propertyName: string) => void;
6
- export declare function OneToMany<Target, Owner>(options: OneToManyOptions<Owner, Target>): (target: Owner, propertyName: string) => void;
7
- export interface OneToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
8
- /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
9
- orphanRemoval?: boolean;
10
- /** Set default ordering. */
11
- orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
12
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
13
- where?: FilterQuery<Target>;
14
- /** 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. */
15
- joinColumn?: string;
16
- /** 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. */
17
- joinColumns?: string[];
18
- /** 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. */
19
- inverseJoinColumn?: string;
20
- /** 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. */
21
- inverseJoinColumns?: string[];
22
- /** 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. */
23
- referenceColumnName?: string;
24
- /** 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. */
25
- referencedColumnNames?: string[];
26
- /** Point to the owning side property name. */
27
- mappedBy: (string & keyof Target) | ((e: Target) => any);
28
- }
@@ -1,17 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function createOneToDecorator(entity, mappedBy, options, kind) {
6
- return function (target, propertyName) {
7
- options = Utils.processDecoratorParameters({ entity, mappedBy, options });
8
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
9
- MetadataValidator.validateSingleDecorator(meta, propertyName, kind);
10
- const property = { name: propertyName, kind };
11
- meta.properties[propertyName] = Object.assign(meta.properties[propertyName] ?? {}, property, options);
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }
15
- export function OneToMany(entity, mappedBy, options = {}) {
16
- return createOneToDecorator(entity, mappedBy, options, ReferenceKind.ONE_TO_MANY);
17
- }
@@ -1,24 +0,0 @@
1
- import { type DeferMode } from '../enums.js';
2
- import { type OneToManyOptions } from './OneToMany.js';
3
- import type { AnyString, EntityName } from '../typings.js';
4
- export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: Owner, propertyName: string) => any;
5
- export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>> {
6
- /** 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. */
7
- owner?: boolean;
8
- /** Point to the inverse side property name. */
9
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
10
- /** Wrap the entity in {@apilink Reference} wrapper. */
11
- ref?: boolean;
12
- /** Use this relation as a primary key. */
13
- primary?: boolean;
14
- /** Map this relation to the primary key value instead of an entity. */
15
- mapToPk?: boolean;
16
- /** 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. */
17
- ownColumns?: string[];
18
- /** What to do when the target entity gets deleted. */
19
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
20
- /** What to do when the reference to the target entity gets updated. */
21
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
22
- /** 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. */
23
- deferMode?: DeferMode | `${DeferMode}`;
24
- }
@@ -1,7 +0,0 @@
1
- import { ReferenceKind } from '../enums.js';
2
- import { createOneToDecorator } from './OneToMany.js';
3
- export function OneToOne(entity, mappedByOrOptions, options = {}) {
4
- const mappedBy = typeof mappedByOrOptions === 'object' ? mappedByOrOptions.mappedBy : mappedByOrOptions;
5
- options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
6
- return createOneToDecorator(entity, mappedBy, options, ReferenceKind.ONE_TO_ONE);
7
- }
@@ -1,8 +0,0 @@
1
- import type { PropertyOptions } from './Property.js';
2
- export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
3
- export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: T, propertyName: string) => any;
4
- export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
5
- }
6
- export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
7
- type?: any;
8
- }
@@ -1,20 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { ReferenceKind } from '../enums.js';
4
- import { Utils } from '../utils/Utils.js';
5
- function createDecorator(options, serialized) {
6
- return function (target, propertyName) {
7
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
8
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.SCALAR);
9
- const k = serialized ? 'serializedPrimaryKey' : 'primary';
10
- options[k] = true;
11
- meta.properties[propertyName] = { name: propertyName, kind: ReferenceKind.SCALAR, ...options };
12
- return Utils.propertyDecoratorReturnValue();
13
- };
14
- }
15
- export function PrimaryKey(options = {}) {
16
- return createDecorator(options, false);
17
- }
18
- export function SerializedPrimaryKey(options = {}) {
19
- return createDecorator(options, true);
20
- }
@@ -1,250 +0,0 @@
1
- import { type Cascade, type LoadStrategy } from '../enums.js';
2
- import type { EntityName, Constructor, CheckCallback, GeneratedColumnCallback, AnyString, AnyEntity } from '../typings.js';
3
- import type { Type, types } from '../types/index.js';
4
- import type { EntityManager } from '../EntityManager.js';
5
- import type { SerializeOptions } from '../serialization/EntitySerializer.js';
6
- export declare function Property<T extends object>(options?: PropertyOptions<T>): (target: T, propertyName: string) => any;
7
- export interface PropertyOptions<Owner> {
8
- /**
9
- * Alias for `fieldName`.
10
- */
11
- name?: string;
12
- /**
13
- * Specify database column name for this property.
14
- *
15
- * @see https://mikro-orm.io/docs/naming-strategy
16
- */
17
- fieldName?: string;
18
- /**
19
- * Specify database column names for this property.
20
- * Same as `fieldName` but for composite FKs.
21
- *
22
- * @see https://mikro-orm.io/docs/naming-strategy
23
- */
24
- fieldNames?: string[];
25
- /**
26
- * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is only for simple properties represented by a single column. (SQL only)
27
- */
28
- columnType?: ColumnType | AnyString;
29
- /**
30
- * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is suitable for composite keys, where one property is represented by multiple columns. (SQL only)
31
- */
32
- columnTypes?: (ColumnType | AnyString)[];
33
- /**
34
- * Explicitly specify the runtime type.
35
- *
36
- * @see https://mikro-orm.io/docs/metadata-providers
37
- * @see https://mikro-orm.io/docs/custom-types
38
- */
39
- type?: keyof typeof types | 'ObjectId' | Date | Constructor<AnyEntity> | Constructor<Type<any>> | Type<any> | (() => unknown) | ColumnType | AnyString;
40
- /**
41
- * Runtime type of the property. This is the JS type that your property is mapped to, e.g. `string` or `number`, and is normally inferred automatically via `reflect-metadata`.
42
- * In some cases, the inference won't work, and you might need to specify the `runtimeType` explicitly - the most common one is when you use a union type with null like `foo: number | null`.
43
- */
44
- runtimeType?: string;
45
- /**
46
- * Set length of database column, used for datetime/timestamp/varchar column types for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
47
- */
48
- length?: number;
49
- /**
50
- * Set precision of database column to represent the number of significant digits. (SQL only)
51
- */
52
- precision?: number;
53
- /**
54
- * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
55
- */
56
- scale?: number;
57
- /**
58
- * Explicitly specify the auto increment of the primary key.
59
- */
60
- autoincrement?: boolean;
61
- /**
62
- * Add the property to the `returning` statement.
63
- */
64
- returning?: boolean;
65
- /**
66
- * Automatically set the property value when entity gets created, executed during flush operation.
67
- * @param entity
68
- */
69
- onCreate?: (entity: Owner, em: EntityManager) => any;
70
- /**
71
- * Automatically update the property value every time entity gets updated, executed during flush operation.
72
- * @param entity
73
- */
74
- onUpdate?: (entity: Owner, em: EntityManager) => any;
75
- /**
76
- * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
77
- * This is a runtime value, assignable to the entity property. (SQL only)
78
- */
79
- default?: string | string[] | number | number[] | boolean | null;
80
- /**
81
- * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
82
- * Since v4 you should use defaultRaw for SQL functions. e.g. now()
83
- */
84
- defaultRaw?: string;
85
- /**
86
- * Set to map some SQL snippet for the entity.
87
- *
88
- * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
89
- */
90
- formula?: string | ((alias: string) => string);
91
- /**
92
- * For generated columns. This will be appended to the column type after the `generated always` clause.
93
- */
94
- generated?: string | GeneratedColumnCallback<Owner>;
95
- /**
96
- * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
97
- */
98
- nullable?: boolean;
99
- /**
100
- * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
101
- */
102
- unsigned?: boolean;
103
- /**
104
- * Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
105
- */
106
- persist?: boolean;
107
- /**
108
- * Set false to disable hydration of this property. Useful for persisted getters.
109
- */
110
- hydrate?: boolean;
111
- /**
112
- * Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
113
- */
114
- ref?: boolean;
115
- /**
116
- * Set false to disable change tracking on a property level.
117
- *
118
- * @see https://mikro-orm.io/docs/unit-of-work#change-tracking-and-performance-considerations
119
- */
120
- trackChanges?: boolean;
121
- /**
122
- * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
123
- */
124
- hidden?: boolean;
125
- /**
126
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
127
- */
128
- version?: boolean;
129
- /**
130
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
131
- */
132
- concurrencyCheck?: boolean;
133
- /**
134
- * Explicitly specify index on a property.
135
- */
136
- index?: boolean | string;
137
- /**
138
- * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
139
- */
140
- unique?: boolean | string;
141
- /**
142
- * Specify column with check constraints. (Postgres driver only)
143
- *
144
- * @see https://mikro-orm.io/docs/defining-entities#check-constraints
145
- */
146
- check?: string | CheckCallback<Owner>;
147
- /**
148
- * Set to omit the property from the select clause for lazy loading.
149
- *
150
- * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
151
- */
152
- lazy?: boolean;
153
- /**
154
- * Set true to define entity's unique primary key identifier.
155
- * Alias for `@PrimaryKey()` decorator
156
- *
157
- * @see https://mikro-orm.io/docs/decorators#primarykey
158
- */
159
- primary?: boolean;
160
- /**
161
- * Set true to define the properties as setter. (virtual)
162
- *
163
- * @example
164
- * ```
165
- * @Property({ setter: true })
166
- * set address(value: string) {
167
- * this._address = value.toLocaleLowerCase();
168
- * }
169
- * ```
170
- */
171
- setter?: boolean;
172
- /**
173
- * Set true to define the properties as getter. (virtual)
174
- *
175
- * @example
176
- * ```
177
- * @Property({ getter: true })
178
- * get fullName() {
179
- * return this.firstName + this.lastName;
180
- * }
181
- * ```
182
- */
183
- getter?: boolean;
184
- /**
185
- * When defining a property over a method (not a getter, a regular function), you can use this option to point
186
- * to the method name.
187
- *
188
- * @example
189
- * ```
190
- * @Property({ getter: true })
191
- * getFullName() {
192
- * return this.firstName + this.lastName;
193
- * }
194
- * ```
195
- */
196
- getterName?: keyof Owner;
197
- /**
198
- * Set to define serialized primary key for MongoDB. (virtual)
199
- * Alias for `@SerializedPrimaryKey()` decorator.
200
- *
201
- * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
202
- */
203
- serializedPrimaryKey?: boolean;
204
- /**
205
- * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
206
- *
207
- * @see https://mikro-orm.io/docs/serializing#property-serializers
208
- */
209
- serializer?: (value: any, options?: SerializeOptions<any>) => any;
210
- /**
211
- * Specify name of key for the serialized value.
212
- */
213
- serializedName?: string;
214
- /**
215
- * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
216
- * otherwise only properties with a matching group are included.
217
- */
218
- groups?: string[];
219
- /**
220
- * Specify a custom order based on the values. (SQL only)
221
- */
222
- customOrder?: string[] | number[] | boolean[];
223
- /**
224
- * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
225
- */
226
- comment?: string;
227
- /** mysql only */
228
- extra?: string;
229
- /**
230
- * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
231
- *
232
- * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
233
- */
234
- ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
235
- }
236
- export interface ReferenceOptions<Owner, Target> extends PropertyOptions<Owner> {
237
- /** Set target entity type. */
238
- entity?: string | (() => EntityName<Target>);
239
- /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
240
- cascade?: Cascade[];
241
- /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
242
- eager?: boolean;
243
- /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
244
- strategy?: LoadStrategy | `${LoadStrategy}`;
245
- }
246
- /**
247
- * Inspired by https://github.com/typeorm/typeorm/blob/941b584ba135617e55d6685caef671172ec1dc03/src/driver/types/ColumnTypes.ts
248
- * @ignore
249
- */
250
- export type ColumnType = 'int' | 'int4' | 'integer' | 'bigint' | 'int8' | 'int2' | 'tinyint' | 'smallint' | 'mediumint' | 'double' | 'double precision' | 'real' | 'float8' | 'decimal' | 'numeric' | 'float' | 'float4' | 'datetime' | 'time' | 'time with time zone' | 'timestamp' | 'timestamp with time zone' | 'timetz' | 'timestamptz' | 'date' | 'interval' | 'character varying' | 'varchar' | 'char' | 'character' | 'uuid' | 'text' | 'tinytext' | 'mediumtext' | 'longtext' | 'boolean' | 'bool' | 'bit' | 'enum' | 'blob' | 'tinyblob' | 'mediumblob' | 'longblob' | 'bytea' | 'point' | 'line' | 'lseg' | 'box' | 'circle' | 'path' | 'polygon' | 'geometry' | 'tsvector' | 'tsquery' | 'json' | 'jsonb';
@@ -1,32 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { MetadataValidator } from '../metadata/MetadataValidator.js';
3
- import { Utils } from '../utils/Utils.js';
4
- import { ReferenceKind } from '../enums.js';
5
- export function Property(options = {}) {
6
- return function (target, propertyName) {
7
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
8
- const desc = Object.getOwnPropertyDescriptor(target, propertyName) || {};
9
- MetadataValidator.validateSingleDecorator(meta, propertyName, ReferenceKind.SCALAR);
10
- const name = options.name || propertyName;
11
- if (propertyName !== name && !(desc.value instanceof Function)) {
12
- Utils.renameKey(options, 'name', 'fieldName');
13
- }
14
- options.name = propertyName;
15
- const { check, ...opts } = options;
16
- const prop = { kind: ReferenceKind.SCALAR, ...opts };
17
- prop.getter = !!desc.get;
18
- prop.setter = !!desc.set;
19
- if (desc.value instanceof Function) {
20
- prop.getter = true;
21
- prop.persist = false;
22
- prop.type = 'method';
23
- prop.getterName = propertyName;
24
- prop.name = name;
25
- }
26
- if (check) {
27
- meta.checks.push({ property: prop.name, expression: check });
28
- }
29
- meta.properties[prop.name] = prop;
30
- return Utils.propertyDecoratorReturnValue();
31
- };
32
- }
@@ -1,13 +0,0 @@
1
- import type { TransactionOptions } from '../enums.js';
2
- import type { ContextProvider } from '../typings.js';
3
- type TransactionalOptions<T> = TransactionOptions & {
4
- context?: ContextProvider<T>;
5
- };
6
- /**
7
- * This decorator wraps the method with `em.transactional()`, so you can provide `TransactionOptions` just like with `em.transactional()`.
8
- * The difference is that you can specify the context in which the transaction begins by providing `context` option,
9
- * and if omitted, the transaction will begin in the current context implicitly.
10
- * It works on async functions and can be nested with `em.transactional()`.
11
- */
12
- export declare function Transactional<T extends object>(options?: TransactionalOptions<T>): MethodDecorator;
13
- export {};
@@ -1,28 +0,0 @@
1
- import { RequestContext } from '../utils/RequestContext.js';
2
- import { resolveContextProvider } from '../utils/resolveContextProvider.js';
3
- import { TransactionContext } from '../utils/TransactionContext.js';
4
- /**
5
- * This decorator wraps the method with `em.transactional()`, so you can provide `TransactionOptions` just like with `em.transactional()`.
6
- * The difference is that you can specify the context in which the transaction begins by providing `context` option,
7
- * and if omitted, the transaction will begin in the current context implicitly.
8
- * It works on async functions and can be nested with `em.transactional()`.
9
- */
10
- export function Transactional(options = {}) {
11
- return function (target, propertyKey, descriptor) {
12
- const originalMethod = descriptor.value;
13
- if (originalMethod.constructor.name !== 'AsyncFunction') {
14
- throw new Error('@Transactional() should be use with async functions');
15
- }
16
- descriptor.value = async function (...args) {
17
- const { context, ...txOptions } = options;
18
- const em = (await resolveContextProvider(this, context))
19
- || TransactionContext.getEntityManager()
20
- || RequestContext.getEntityManager();
21
- if (!em) {
22
- throw new Error(`@Transactional() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@Transactional(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
23
- }
24
- return em.transactional(() => originalMethod.apply(this, args), txOptions);
25
- };
26
- return descriptor;
27
- };
28
- }
@@ -1,16 +0,0 @@
1
- export declare function BeforeCreate(): (target: any, method: string) => void;
2
- export declare function AfterCreate(): (target: any, method: string) => void;
3
- export declare function BeforeUpdate(): (target: any, method: string) => void;
4
- export declare function AfterUpdate(): (target: any, method: string) => void;
5
- export declare function BeforeUpsert(): (target: any, method: string) => void;
6
- export declare function AfterUpsert(): (target: any, method: string) => void;
7
- export declare function OnInit(): (target: any, method: string) => void;
8
- export declare function OnLoad(): (target: any, method: string) => void;
9
- /**
10
- * Called before deleting entity, but only when providing initialized entity to EM#remove()
11
- */
12
- export declare function BeforeDelete(): (target: any, method: string) => void;
13
- /**
14
- * Called after deleting entity, but only when providing initialized entity to EM#remove()
15
- */
16
- export declare function AfterDelete(): (target: any, method: string) => void;
@@ -1,47 +0,0 @@
1
- import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
- import { EventType } from '../enums.js';
3
- function hook(type) {
4
- return function (target, method) {
5
- const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
6
- if (!meta.hooks[type]) {
7
- meta.hooks[type] = [];
8
- }
9
- meta.hooks[type].push(method);
10
- };
11
- }
12
- export function BeforeCreate() {
13
- return hook(EventType.beforeCreate);
14
- }
15
- export function AfterCreate() {
16
- return hook(EventType.afterCreate);
17
- }
18
- export function BeforeUpdate() {
19
- return hook(EventType.beforeUpdate);
20
- }
21
- export function AfterUpdate() {
22
- return hook(EventType.afterUpdate);
23
- }
24
- export function BeforeUpsert() {
25
- return hook(EventType.beforeUpsert);
26
- }
27
- export function AfterUpsert() {
28
- return hook(EventType.afterUpsert);
29
- }
30
- export function OnInit() {
31
- return hook(EventType.onInit);
32
- }
33
- export function OnLoad() {
34
- return hook(EventType.onLoad);
35
- }
36
- /**
37
- * Called before deleting entity, but only when providing initialized entity to EM#remove()
38
- */
39
- export function BeforeDelete() {
40
- return hook(EventType.beforeDelete);
41
- }
42
- /**
43
- * Called after deleting entity, but only when providing initialized entity to EM#remove()
44
- */
45
- export function AfterDelete() {
46
- return hook(EventType.afterDelete);
47
- }
@@ -1,17 +0,0 @@
1
- export * from './PrimaryKey.js';
2
- export * from './Entity.js';
3
- export * from './OneToOne.js';
4
- export * from './ManyToOne.js';
5
- export * from './ManyToMany.js';
6
- export { OneToMany, OneToManyOptions } from './OneToMany.js';
7
- export * from './Property.js';
8
- export * from './Check.js';
9
- export * from './Enum.js';
10
- export * from './Formula.js';
11
- export * from './Indexed.js';
12
- export * from './Embeddable.js';
13
- export * from './Embedded.js';
14
- export * from './Filter.js';
15
- export * from './CreateRequestContext.js';
16
- export * from './hooks.js';
17
- export * from './Transactional.js';
@@ -1,17 +0,0 @@
1
- export * from './PrimaryKey.js';
2
- export * from './Entity.js';
3
- export * from './OneToOne.js';
4
- export * from './ManyToOne.js';
5
- export * from './ManyToMany.js';
6
- export { OneToMany } from './OneToMany.js';
7
- export * from './Property.js';
8
- export * from './Check.js';
9
- export * from './Enum.js';
10
- export * from './Formula.js';
11
- export * from './Indexed.js';
12
- export * from './Embeddable.js';
13
- export * from './Embedded.js';
14
- export * from './Filter.js';
15
- export * from './CreateRequestContext.js';
16
- export * from './hooks.js';
17
- export * from './Transactional.js';