@mikro-orm/core 7.0.0-dev.23 → 7.0.0-dev.231

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 (209) hide show
  1. package/EntityManager.d.ts +91 -59
  2. package/EntityManager.js +303 -251
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -143
  5. package/README.md +2 -0
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +17 -8
  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 +12 -5
  13. package/connections/Connection.js +21 -12
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +118 -35
  16. package/drivers/IDatabaseDriver.d.ts +42 -19
  17. package/entity/BaseEntity.d.ts +61 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +436 -104
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +7 -1
  24. package/entity/EntityFactory.js +83 -54
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +48 -15
  27. package/entity/EntityLoader.d.ts +7 -6
  28. package/entity/EntityLoader.js +221 -93
  29. package/entity/EntityRepository.d.ts +27 -7
  30. package/entity/EntityRepository.js +8 -2
  31. package/entity/PolymorphicRef.d.ts +12 -0
  32. package/entity/PolymorphicRef.js +18 -0
  33. package/entity/Reference.d.ts +1 -5
  34. package/entity/Reference.js +21 -12
  35. package/entity/WrappedEntity.d.ts +0 -5
  36. package/entity/WrappedEntity.js +2 -7
  37. package/entity/defineEntity.d.ts +380 -310
  38. package/entity/defineEntity.js +124 -273
  39. package/entity/index.d.ts +2 -2
  40. package/entity/index.js +2 -2
  41. package/entity/utils.js +1 -1
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +65 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +2 -1
  46. package/errors.d.ts +20 -10
  47. package/errors.js +55 -23
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +19 -11
  50. package/hydration/Hydrator.js +1 -2
  51. package/hydration/ObjectHydrator.d.ts +4 -4
  52. package/hydration/ObjectHydrator.js +87 -35
  53. package/index.d.ts +2 -2
  54. package/index.js +1 -2
  55. package/logging/DefaultLogger.d.ts +1 -1
  56. package/logging/DefaultLogger.js +1 -0
  57. package/logging/SimpleLogger.d.ts +1 -1
  58. package/logging/colors.d.ts +1 -1
  59. package/logging/colors.js +7 -6
  60. package/logging/index.d.ts +1 -0
  61. package/logging/index.js +1 -0
  62. package/logging/inspect.d.ts +2 -0
  63. package/logging/inspect.js +11 -0
  64. package/metadata/EntitySchema.d.ts +47 -23
  65. package/metadata/EntitySchema.js +92 -33
  66. package/metadata/MetadataDiscovery.d.ts +64 -9
  67. package/metadata/MetadataDiscovery.js +778 -325
  68. package/metadata/MetadataProvider.d.ts +11 -2
  69. package/metadata/MetadataProvider.js +46 -2
  70. package/metadata/MetadataStorage.d.ts +13 -11
  71. package/metadata/MetadataStorage.js +70 -37
  72. package/metadata/MetadataValidator.d.ts +32 -9
  73. package/metadata/MetadataValidator.js +196 -41
  74. package/metadata/discover-entities.d.ts +5 -0
  75. package/metadata/discover-entities.js +40 -0
  76. package/metadata/index.d.ts +1 -1
  77. package/metadata/index.js +1 -1
  78. package/metadata/types.d.ts +526 -0
  79. package/metadata/types.js +1 -0
  80. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  81. package/naming-strategy/AbstractNamingStrategy.js +20 -2
  82. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  83. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  84. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  85. package/naming-strategy/MongoNamingStrategy.js +6 -6
  86. package/naming-strategy/NamingStrategy.d.ts +28 -4
  87. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  89. package/not-supported.d.ts +2 -0
  90. package/not-supported.js +4 -0
  91. package/package.json +19 -11
  92. package/platforms/ExceptionConverter.js +1 -1
  93. package/platforms/Platform.d.ts +7 -14
  94. package/platforms/Platform.js +20 -43
  95. package/serialization/EntitySerializer.d.ts +5 -0
  96. package/serialization/EntitySerializer.js +47 -27
  97. package/serialization/EntityTransformer.js +28 -18
  98. package/serialization/SerializationContext.d.ts +6 -6
  99. package/serialization/SerializationContext.js +3 -3
  100. package/types/ArrayType.d.ts +1 -1
  101. package/types/ArrayType.js +2 -3
  102. package/types/BigIntType.d.ts +8 -6
  103. package/types/BigIntType.js +1 -1
  104. package/types/BlobType.d.ts +0 -1
  105. package/types/BlobType.js +0 -3
  106. package/types/BooleanType.d.ts +1 -0
  107. package/types/BooleanType.js +3 -0
  108. package/types/DecimalType.d.ts +6 -4
  109. package/types/DecimalType.js +2 -2
  110. package/types/DoubleType.js +1 -1
  111. package/types/EnumArrayType.js +1 -2
  112. package/types/JsonType.d.ts +1 -1
  113. package/types/JsonType.js +7 -2
  114. package/types/TinyIntType.js +1 -1
  115. package/types/Type.d.ts +2 -4
  116. package/types/Type.js +3 -3
  117. package/types/Uint8ArrayType.d.ts +0 -1
  118. package/types/Uint8ArrayType.js +1 -4
  119. package/types/index.d.ts +1 -1
  120. package/typings.d.ts +381 -171
  121. package/typings.js +97 -44
  122. package/unit-of-work/ChangeSet.d.ts +4 -6
  123. package/unit-of-work/ChangeSet.js +4 -5
  124. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  125. package/unit-of-work/ChangeSetComputer.js +35 -14
  126. package/unit-of-work/ChangeSetPersister.d.ts +7 -3
  127. package/unit-of-work/ChangeSetPersister.js +83 -25
  128. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  129. package/unit-of-work/CommitOrderCalculator.js +13 -13
  130. package/unit-of-work/IdentityMap.d.ts +12 -0
  131. package/unit-of-work/IdentityMap.js +39 -1
  132. package/unit-of-work/UnitOfWork.d.ts +27 -3
  133. package/unit-of-work/UnitOfWork.js +258 -92
  134. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  135. package/utils/AbstractSchemaGenerator.js +28 -17
  136. package/utils/AsyncContext.d.ts +6 -0
  137. package/utils/AsyncContext.js +42 -0
  138. package/utils/Configuration.d.ts +795 -209
  139. package/utils/Configuration.js +150 -192
  140. package/utils/ConfigurationLoader.d.ts +1 -54
  141. package/utils/ConfigurationLoader.js +1 -352
  142. package/utils/Cursor.d.ts +0 -3
  143. package/utils/Cursor.js +24 -11
  144. package/utils/DataloaderUtils.d.ts +10 -5
  145. package/utils/DataloaderUtils.js +29 -12
  146. package/utils/EntityComparator.d.ts +16 -9
  147. package/utils/EntityComparator.js +158 -58
  148. package/utils/QueryHelper.d.ts +18 -6
  149. package/utils/QueryHelper.js +76 -23
  150. package/utils/RawQueryFragment.d.ts +28 -34
  151. package/utils/RawQueryFragment.js +35 -71
  152. package/utils/RequestContext.js +2 -2
  153. package/utils/TransactionContext.js +2 -2
  154. package/utils/TransactionManager.js +28 -4
  155. package/utils/Utils.d.ts +14 -127
  156. package/utils/Utils.js +85 -397
  157. package/utils/clone.js +8 -23
  158. package/utils/env-vars.d.ts +7 -0
  159. package/utils/env-vars.js +97 -0
  160. package/utils/fs-utils.d.ts +33 -0
  161. package/utils/fs-utils.js +192 -0
  162. package/utils/index.d.ts +1 -1
  163. package/utils/index.js +1 -1
  164. package/utils/upsert-utils.d.ts +9 -4
  165. package/utils/upsert-utils.js +46 -3
  166. package/decorators/Check.d.ts +0 -3
  167. package/decorators/Check.js +0 -13
  168. package/decorators/CreateRequestContext.d.ts +0 -3
  169. package/decorators/CreateRequestContext.js +0 -32
  170. package/decorators/Embeddable.d.ts +0 -8
  171. package/decorators/Embeddable.js +0 -11
  172. package/decorators/Embedded.d.ts +0 -12
  173. package/decorators/Embedded.js +0 -18
  174. package/decorators/Entity.d.ts +0 -33
  175. package/decorators/Entity.js +0 -12
  176. package/decorators/Enum.d.ts +0 -9
  177. package/decorators/Enum.js +0 -16
  178. package/decorators/Filter.d.ts +0 -2
  179. package/decorators/Filter.js +0 -8
  180. package/decorators/Formula.d.ts +0 -4
  181. package/decorators/Formula.js +0 -15
  182. package/decorators/Indexed.d.ts +0 -19
  183. package/decorators/Indexed.js +0 -20
  184. package/decorators/ManyToMany.d.ts +0 -42
  185. package/decorators/ManyToMany.js +0 -14
  186. package/decorators/ManyToOne.d.ts +0 -34
  187. package/decorators/ManyToOne.js +0 -14
  188. package/decorators/OneToMany.d.ts +0 -28
  189. package/decorators/OneToMany.js +0 -17
  190. package/decorators/OneToOne.d.ts +0 -28
  191. package/decorators/OneToOne.js +0 -7
  192. package/decorators/PrimaryKey.d.ts +0 -8
  193. package/decorators/PrimaryKey.js +0 -20
  194. package/decorators/Property.d.ts +0 -250
  195. package/decorators/Property.js +0 -32
  196. package/decorators/Transactional.d.ts +0 -14
  197. package/decorators/Transactional.js +0 -28
  198. package/decorators/hooks.d.ts +0 -16
  199. package/decorators/hooks.js +0 -47
  200. package/decorators/index.d.ts +0 -17
  201. package/decorators/index.js +0 -17
  202. package/entity/ArrayCollection.d.ts +0 -118
  203. package/entity/ArrayCollection.js +0 -407
  204. package/entity/EntityValidator.d.ts +0 -19
  205. package/entity/EntityValidator.js +0 -150
  206. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  207. package/metadata/ReflectMetadataProvider.js +0 -44
  208. package/utils/resolveContextProvider.d.ts +0 -10
  209. package/utils/resolveContextProvider.js +0 -28
@@ -0,0 +1,5 @@
1
+ import { type Constructor } from '../typings.js';
2
+ import { EntitySchema } from './EntitySchema.js';
3
+ export declare function discoverEntities(paths: string | string[], options?: {
4
+ baseDir?: string;
5
+ }): Promise<Iterable<EntitySchema | Constructor>>;
@@ -0,0 +1,40 @@
1
+ import { basename } from 'node:path';
2
+ import { fs } from '../utils/fs-utils.js';
3
+ import { Utils } from '../utils/Utils.js';
4
+ import { MetadataStorage } from './MetadataStorage.js';
5
+ import { EntitySchema } from './EntitySchema.js';
6
+ async function getEntityClassOrSchema(filepath, allTargets, baseDir) {
7
+ const path = fs.normalizePath(baseDir, filepath);
8
+ const exports = await fs.dynamicImport(path);
9
+ const targets = Object.values(exports);
10
+ // ignore class implementations that are linked from an EntitySchema
11
+ for (const item of targets) {
12
+ if (item instanceof EntitySchema) {
13
+ for (const item2 of targets) {
14
+ if (item.meta.class === item2) {
15
+ targets.splice(targets.indexOf(item2), 1);
16
+ }
17
+ }
18
+ }
19
+ }
20
+ for (const item of targets) {
21
+ const validTarget = item instanceof EntitySchema || (item instanceof Function && MetadataStorage.isKnownEntity(item.name));
22
+ if (validTarget && !allTargets.has(item)) {
23
+ allTargets.set(item, path);
24
+ }
25
+ }
26
+ }
27
+ export async function discoverEntities(paths, options) {
28
+ paths = Utils.asArray(paths).map(path => fs.normalizePath(path));
29
+ const baseDir = fs.absolutePath(options?.baseDir ?? process.cwd());
30
+ const files = fs.glob(paths, fs.normalizePath(baseDir));
31
+ const found = new Map();
32
+ for (const filepath of files) {
33
+ const filename = basename(filepath);
34
+ if (!filename.match(/\.[cm]?[jt]s$/) || filename.match(/\.d\.[cm]?ts/)) {
35
+ continue;
36
+ }
37
+ await getEntityClassOrSchema(filepath, found, baseDir);
38
+ }
39
+ return found.keys();
40
+ }
@@ -1,6 +1,6 @@
1
+ export * from './types.js';
1
2
  export * from './EntitySchema.js';
2
3
  export * from './MetadataDiscovery.js';
3
4
  export * from './MetadataStorage.js';
4
5
  export * from './MetadataProvider.js';
5
6
  export * from './MetadataValidator.js';
6
- export * from './ReflectMetadataProvider.js';
package/metadata/index.js CHANGED
@@ -1,6 +1,6 @@
1
+ export * from './types.js';
1
2
  export * from './EntitySchema.js';
2
3
  export * from './MetadataDiscovery.js';
3
4
  export * from './MetadataStorage.js';
4
5
  export * from './MetadataProvider.js';
5
6
  export * from './MetadataValidator.js';
6
- export * from './ReflectMetadataProvider.js';
@@ -0,0 +1,526 @@
1
+ import type { AnyEntity, Constructor, EntityName, AnyString, CheckCallback, GeneratedColumnCallback, FormulaCallback, FilterQuery, Dictionary, AutoPath, EntityClass, IndexCallback, ObjectQuery, Raw } from '../typings.js';
2
+ import type { Cascade, LoadStrategy, DeferMode, QueryOrderMap, EmbeddedPrefixMode } from '../enums.js';
3
+ import type { Type, types } from '../types/index.js';
4
+ import type { EntityManager } from '../EntityManager.js';
5
+ import type { FilterOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
6
+ import type { SerializeOptions } from '../serialization/EntitySerializer.js';
7
+ export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
8
+ /** Override default collection/table name. Alias for `collection`. */
9
+ tableName?: string;
10
+ /** Sets the schema name. */
11
+ schema?: string;
12
+ /** Override default collection/table name. Alias for `tableName`. */
13
+ collection?: string;
14
+ /**
15
+ * Set default ordering for this entity. This ordering is applied when:
16
+ * - Querying the entity directly via `em.find()`, `em.findAll()`, etc.
17
+ * - Populating the entity as a relation
18
+ *
19
+ * All orderings are combined together. Precedence (highest to lowest):
20
+ * 1. Runtime `FindOptions.orderBy`
21
+ * 2. Relation-level `@OneToMany({ orderBy })` / `@ManyToMany({ orderBy })`
22
+ * 3. Entity-level `@Entity({ orderBy })`
23
+ */
24
+ orderBy?: QueryOrderMap<E> | QueryOrderMap<E>[];
25
+ /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
26
+ discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
27
+ /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
28
+ discriminatorMap?: Dictionary<string>;
29
+ /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
30
+ discriminatorValue?: number | string;
31
+ /** Set inheritance strategy: 'tpt' for {@doclink inheritance-mapping#table-per-type-inheritance-tpt | Table-Per-Type} inheritance. When set on the root entity, each entity in the hierarchy gets its own table with a FK from child PK to parent PK. */
32
+ inheritance?: 'tpt';
33
+ /** Enforce use of constructor when creating managed entity instances. */
34
+ forceConstructor?: boolean;
35
+ /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
36
+ constructorParams?: (T extends EntityClass<infer P> ? keyof P : string)[];
37
+ /** Specify comment to table. (SQL only) */
38
+ comment?: string;
39
+ /** Marks entity as abstract, such entities are inlined during discovery. */
40
+ abstract?: boolean;
41
+ /** Disables change tracking - such entities are ignored during flush. */
42
+ readonly?: boolean;
43
+ /** Marks entity as {@doclink virtual-entities | virtual}. This is set automatically when you use `expression` option (unless `view` is set). */
44
+ virtual?: boolean;
45
+ /**
46
+ * Marks entity as a database view. Unlike virtual entities which evaluate expressions at query time,
47
+ * view entities create actual database views. The `expression` option must be provided when `view` is true.
48
+ * View entities are read-only by default.
49
+ *
50
+ * Use `view: true` for regular views, or `view: { materialized: true }` for materialized views (PostgreSQL only).
51
+ * Materialized views store the query results and must be refreshed to update data.
52
+ * Use `view: { materialized: true, withData: false }` to create an unpopulated materialized view.
53
+ */
54
+ view?: boolean | {
55
+ materialized?: boolean;
56
+ withData?: boolean;
57
+ };
58
+ /** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
59
+ hasTriggers?: boolean;
60
+ /** SQL query that maps to a {@doclink virtual-entities | virtual entity}, or for view entities, the view definition. */
61
+ expression?: string | ((em: any, where: ObjectQuery<E>, options: FindOptions<E, any, any, any>, stream?: boolean) => object);
62
+ /** Set {@doclink repositories#custom-repository | custom repository class}. */
63
+ repository?: () => Constructor;
64
+ };
65
+ export interface PropertyOptions<Owner> {
66
+ /**
67
+ * Alias for `fieldName`.
68
+ */
69
+ name?: string;
70
+ /**
71
+ * Specify database column name for this property.
72
+ *
73
+ * @see https://mikro-orm.io/docs/naming-strategy
74
+ */
75
+ fieldName?: string;
76
+ /**
77
+ * Specify database column names for this property.
78
+ * Same as `fieldName` but for composite FKs.
79
+ *
80
+ * @see https://mikro-orm.io/docs/naming-strategy
81
+ */
82
+ fieldNames?: string[];
83
+ /**
84
+ * 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)
85
+ */
86
+ columnType?: ColumnType | AnyString;
87
+ /**
88
+ * 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)
89
+ */
90
+ columnTypes?: (ColumnType | AnyString)[];
91
+ /**
92
+ * Explicitly specify the runtime type.
93
+ *
94
+ * @see https://mikro-orm.io/docs/metadata-providers
95
+ * @see https://mikro-orm.io/docs/custom-types
96
+ */
97
+ type?: keyof typeof types | 'ObjectId' | Date | Constructor<AnyEntity> | Constructor<Type<any>> | Type<any> | (() => unknown) | ColumnType | AnyString;
98
+ /**
99
+ * 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`.
100
+ * 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`.
101
+ */
102
+ runtimeType?: string;
103
+ /**
104
+ * 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)
105
+ */
106
+ length?: number;
107
+ /**
108
+ * Set precision of database column to represent the number of significant digits. (SQL only)
109
+ */
110
+ precision?: number;
111
+ /**
112
+ * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
113
+ */
114
+ scale?: number;
115
+ /**
116
+ * Explicitly specify the auto increment of the primary key.
117
+ */
118
+ autoincrement?: boolean;
119
+ /**
120
+ * Add the property to the `returning` statement.
121
+ */
122
+ returning?: boolean;
123
+ /**
124
+ * Automatically set the property value when entity gets created, executed during flush operation.
125
+ * @param entity
126
+ */
127
+ onCreate?: (entity: Owner, em: EntityManager) => any;
128
+ /**
129
+ * Automatically update the property value every time entity gets updated, executed during flush operation.
130
+ * @param entity
131
+ */
132
+ onUpdate?: (entity: Owner, em: EntityManager) => any;
133
+ /**
134
+ * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
135
+ * This is a runtime value, assignable to the entity property. (SQL only)
136
+ */
137
+ default?: string | string[] | number | number[] | boolean | null | Date | Raw;
138
+ /**
139
+ * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
140
+ * Since v4 you should use defaultRaw for SQL functions. e.g. now()
141
+ */
142
+ defaultRaw?: string | Raw;
143
+ /**
144
+ * Set to map some SQL snippet for the entity.
145
+ *
146
+ * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
147
+ */
148
+ formula?: string | FormulaCallback<Owner>;
149
+ /**
150
+ * For generated columns. This will be appended to the column type after the `generated always` clause.
151
+ */
152
+ generated?: string | Raw | GeneratedColumnCallback<Owner>;
153
+ /**
154
+ * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
155
+ */
156
+ nullable?: boolean;
157
+ /**
158
+ * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
159
+ */
160
+ unsigned?: boolean;
161
+ /**
162
+ * Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
163
+ */
164
+ persist?: boolean;
165
+ /**
166
+ * Set false to disable hydration of this property. Useful for persisted getters.
167
+ */
168
+ hydrate?: boolean;
169
+ /**
170
+ * 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.
171
+ */
172
+ ref?: boolean;
173
+ /**
174
+ * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
175
+ */
176
+ hidden?: boolean;
177
+ /**
178
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
179
+ */
180
+ version?: boolean;
181
+ /**
182
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
183
+ */
184
+ concurrencyCheck?: boolean;
185
+ /**
186
+ * Explicitly specify index on a property.
187
+ */
188
+ index?: boolean | string;
189
+ /**
190
+ * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
191
+ */
192
+ unique?: boolean | string;
193
+ /**
194
+ * Specify column with check constraints. (Postgres driver only)
195
+ *
196
+ * @see https://mikro-orm.io/docs/defining-entities#check-constraints
197
+ */
198
+ check?: string | CheckCallback<Owner>;
199
+ /**
200
+ * Set to omit the property from the select clause for lazy loading.
201
+ *
202
+ * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
203
+ */
204
+ lazy?: boolean;
205
+ /**
206
+ * Set true to define entity's unique primary key identifier.
207
+ * Alias for `@PrimaryKey()` decorator
208
+ *
209
+ * @see https://mikro-orm.io/docs/decorators#primarykey
210
+ */
211
+ primary?: boolean;
212
+ /**
213
+ * Set true to define the properties as setter. (virtual)
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * @Property({ setter: true })
218
+ * set address(value: string) {
219
+ * this._address = value.toLocaleLowerCase();
220
+ * }
221
+ * ```
222
+ */
223
+ setter?: boolean;
224
+ /**
225
+ * Set true to define the properties as getter. (virtual)
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * @Property({ getter: true })
230
+ * get fullName() {
231
+ * return this.firstName + this.lastName;
232
+ * }
233
+ * ```
234
+ */
235
+ getter?: boolean;
236
+ /**
237
+ * When defining a property over a method (not a getter, a regular function), you can use this option to point
238
+ * to the method name.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * @Property({ getter: true })
243
+ * getFullName() {
244
+ * return this.firstName + this.lastName;
245
+ * }
246
+ * ```
247
+ */
248
+ getterName?: keyof Owner;
249
+ /**
250
+ * When using a private property backed by a public get/set pair, use the `accessor` option to point to the other side.
251
+ *
252
+ * > The `fieldName` will be inferred based on the accessor name unless specified explicitly.
253
+ *
254
+ * If the `accessor` option points to something, the ORM will use the backing property directly.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * @Entity()
259
+ * export class User {
260
+ * // the ORM will use the backing field directly
261
+ * @Property({ accessor: 'email' })
262
+ * private _email: string;
263
+ *
264
+ * get email() {
265
+ * return this._email;
266
+ * }
267
+ *
268
+ * set email() {
269
+ * return this._email;
270
+ * }
271
+ * }
272
+ *```
273
+ *
274
+ * If you want to the ORM to use your accessor internally too, use `accessor: true` on the get/set property instead.
275
+ * This is handy if you want to use a native private property for the backing field.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * @Entity({ forceConstructor: true })
280
+ * export class User {
281
+ * #email: string;
282
+ *
283
+ * // the ORM will use the accessor internally
284
+ * @Property({ accessor: true })
285
+ * get email() {
286
+ * return this.#email;
287
+ * }
288
+ *
289
+ * set email() {
290
+ * return this.#email;
291
+ * }
292
+ * }
293
+ * ```
294
+ */
295
+ accessor?: keyof Owner | AnyString | boolean;
296
+ /**
297
+ * Set to define serialized primary key for MongoDB. (virtual)
298
+ * Alias for `@SerializedPrimaryKey()` decorator.
299
+ *
300
+ * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
301
+ */
302
+ serializedPrimaryKey?: boolean;
303
+ /**
304
+ * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
305
+ *
306
+ * @see https://mikro-orm.io/docs/serializing#property-serializers
307
+ */
308
+ serializer?: (value: any, options?: SerializeOptions<any>) => any;
309
+ /**
310
+ * Specify name of key for the serialized value.
311
+ */
312
+ serializedName?: string;
313
+ /**
314
+ * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
315
+ * otherwise only properties with a matching group are included.
316
+ */
317
+ groups?: string[];
318
+ /**
319
+ * Specify a custom order based on the values. (SQL only)
320
+ */
321
+ customOrder?: string[] | number[] | boolean[];
322
+ /**
323
+ * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
324
+ */
325
+ comment?: string;
326
+ /** mysql only */
327
+ extra?: string;
328
+ /**
329
+ * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
330
+ *
331
+ * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
332
+ */
333
+ ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
334
+ }
335
+ export interface ReferenceOptions<Owner, Target> extends PropertyOptions<Owner> {
336
+ /** Set target entity type. For polymorphic relations, pass an array of entity types. */
337
+ entity?: () => EntityName<Target> | EntityName<Target>[];
338
+ /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
339
+ cascade?: Cascade[];
340
+ /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
341
+ eager?: boolean;
342
+ /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
343
+ strategy?: LoadStrategy | `${LoadStrategy}`;
344
+ /** Control filter parameters for the relation. This will serve as a default value when processing filters on this relation. It's value can be overridden via `em.fork()` or `FindOptions`. */
345
+ filters?: FilterOptions;
346
+ }
347
+ /**
348
+ * Inspired by https://github.com/typeorm/typeorm/blob/941b584ba135617e55d6685caef671172ec1dc03/src/driver/types/ColumnTypes.ts
349
+ * @ignore
350
+ */
351
+ 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';
352
+ interface PolymorphicOptions {
353
+ /**
354
+ * For polymorphic relations. Specifies the property name that stores the entity type discriminator.
355
+ * Defaults to the property name. Only used when `entity` returns an array of types.
356
+ * For M:N relations, this is the column name in the pivot table.
357
+ */
358
+ discriminator?: string;
359
+ /**
360
+ * For polymorphic relations. Custom mapping of discriminator values to entity class names.
361
+ * If not provided, table names are used as discriminator values.
362
+ */
363
+ discriminatorMap?: Dictionary<string>;
364
+ }
365
+ export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target>, PolymorphicOptions {
366
+ /** Point to the inverse side property name. */
367
+ inversedBy?: (string & keyof Target) | ((e: Target) => any);
368
+ /** Wrap the entity in {@apilink Reference} wrapper. */
369
+ ref?: boolean;
370
+ /** Use this relation as a primary key. */
371
+ primary?: boolean;
372
+ /** Map this relation to the primary key value instead of an entity. */
373
+ mapToPk?: boolean;
374
+ /** 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. */
375
+ joinColumn?: string;
376
+ /** 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. */
377
+ joinColumns?: string[];
378
+ /** 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. */
379
+ ownColumns?: string[];
380
+ /** 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. */
381
+ referenceColumnName?: string;
382
+ /** 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. */
383
+ referencedColumnNames?: string[];
384
+ /** Specify the property name on the target entity that this FK references instead of the primary key. */
385
+ targetKey?: string & keyof Target;
386
+ /** What to do when the target entity gets deleted. */
387
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
388
+ /** What to do when the reference to the target entity gets updated. */
389
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
390
+ /** 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. */
391
+ deferMode?: DeferMode | `${DeferMode}`;
392
+ /** Enable/disable foreign key constraint creation on this relation */
393
+ createForeignKeyConstraint?: boolean;
394
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
395
+ foreignKeyName?: string;
396
+ }
397
+ export interface OneToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
398
+ /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
399
+ orphanRemoval?: boolean;
400
+ /** Set default ordering. */
401
+ orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
402
+ /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
403
+ where?: FilterQuery<Target>;
404
+ /** 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. */
405
+ joinColumn?: string;
406
+ /** 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. */
407
+ joinColumns?: string[];
408
+ /** 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. */
409
+ inverseJoinColumn?: string;
410
+ /** 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. */
411
+ inverseJoinColumns?: string[];
412
+ /** 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. */
413
+ referenceColumnName?: string;
414
+ /** 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. */
415
+ referencedColumnNames?: string[];
416
+ /** Point to the owning side property name. */
417
+ mappedBy: (string & keyof Target) | ((e: Target) => any);
418
+ }
419
+ export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>>, PolymorphicOptions {
420
+ /** 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. */
421
+ owner?: boolean;
422
+ /** Point to the inverse side property name. */
423
+ inversedBy?: (string & keyof Target) | ((e: Target) => any);
424
+ /** Wrap the entity in {@apilink Reference} wrapper. */
425
+ ref?: boolean;
426
+ /** Use this relation as a primary key. */
427
+ primary?: boolean;
428
+ /** Map this relation to the primary key value instead of an entity. */
429
+ mapToPk?: boolean;
430
+ /** 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. */
431
+ ownColumns?: string[];
432
+ /** Specify the property name on the target entity that this FK references instead of the primary key. */
433
+ targetKey?: string & keyof Target;
434
+ /** What to do when the target entity gets deleted. */
435
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
436
+ /** What to do when the reference to the target entity gets updated. */
437
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
438
+ /** 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. */
439
+ deferMode?: DeferMode | `${DeferMode}`;
440
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
441
+ foreignKeyName?: string;
442
+ /** Enable/disable foreign key constraint creation on this relation */
443
+ createForeignKeyConstraint?: boolean;
444
+ }
445
+ export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target>, PolymorphicOptions {
446
+ /** 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. */
447
+ owner?: boolean;
448
+ /** Point to the inverse side property name. */
449
+ inversedBy?: (string & keyof Target) | ((e: Target) => any);
450
+ /** Point to the owning side property name. */
451
+ mappedBy?: (string & keyof Target) | ((e: Target) => any);
452
+ /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
453
+ where?: FilterQuery<Target>;
454
+ /** Set default ordering. */
455
+ orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
456
+ /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
457
+ fixedOrder?: boolean;
458
+ /** Override default order column name (`id`) for fixed ordering. */
459
+ fixedOrderColumn?: string;
460
+ /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
461
+ pivotTable?: string;
462
+ /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
463
+ pivotEntity?: () => EntityName;
464
+ /** 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. */
465
+ joinColumn?: string;
466
+ /** 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. */
467
+ joinColumns?: string[];
468
+ /** 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. */
469
+ inverseJoinColumn?: string;
470
+ /** 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. */
471
+ inverseJoinColumns?: string[];
472
+ /** 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. */
473
+ referenceColumnName?: string;
474
+ /** 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. */
475
+ referencedColumnNames?: string[];
476
+ /** What to do when the target entity gets deleted. */
477
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
478
+ /** What to do when the reference to the target entity gets updated. */
479
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
480
+ /** Enable/disable foreign key constraint creation on this relation */
481
+ createForeignKeyConstraint?: boolean;
482
+ }
483
+ export interface EmbeddedOptions<Owner, Target> extends PropertyOptions<Owner> {
484
+ entity?: () => EntityName<Target> | EntityName[];
485
+ prefix?: string | boolean;
486
+ prefixMode?: EmbeddedPrefixMode;
487
+ object?: boolean;
488
+ array?: boolean;
489
+ }
490
+ export interface EmbeddableOptions<Owner> {
491
+ /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
492
+ constructorParams?: (Owner extends EntityClass<infer P> ? keyof P : string)[];
493
+ /** For polymorphic embeddables. Specify the property name that stores the discriminator value. Alias for `discriminatorColumn`. */
494
+ discriminator?: (Owner extends EntityClass<infer P> ? keyof P : string) | AnyString;
495
+ /** For polymorphic embeddables. @deprecated Use `discriminator` instead. */
496
+ discriminatorColumn?: (Owner extends EntityClass<infer P> ? keyof P : string) | AnyString;
497
+ discriminatorMap?: Dictionary<string>;
498
+ discriminatorValue?: number | string;
499
+ abstract?: boolean;
500
+ }
501
+ export interface EnumOptions<T> extends PropertyOptions<T> {
502
+ items?: (number | string)[] | (() => Dictionary);
503
+ array?: boolean;
504
+ /** for postgres, by default it uses text column with check constraint */
505
+ nativeEnumName?: string;
506
+ }
507
+ export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
508
+ }
509
+ export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
510
+ type?: any;
511
+ }
512
+ type MaybeArray<T> = T | T[];
513
+ type Properties<T, H extends string> = MaybeArray<AutoPath<T, H>>;
514
+ interface BaseOptions<T, H extends string> {
515
+ name?: string;
516
+ properties?: (T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>);
517
+ options?: Dictionary;
518
+ expression?: string | (T extends EntityClass<infer P> ? IndexCallback<P> : IndexCallback<T>);
519
+ }
520
+ export interface UniqueOptions<T, H extends string = string> extends BaseOptions<T, H> {
521
+ deferMode?: DeferMode | `${DeferMode}`;
522
+ }
523
+ export interface IndexOptions<T, H extends string = string> extends BaseOptions<T, H> {
524
+ type?: string;
525
+ }
526
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -12,7 +12,11 @@ export declare abstract class AbstractNamingStrategy implements NamingStrategy {
12
12
  /**
13
13
  * @inheritDoc
14
14
  */
15
- getEnumClassName(columnName: string, tableName: string, schemaName?: string): string;
15
+ getEnumClassName(columnName: string, tableName: string | undefined, schemaName?: string): string;
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ getEnumTypeName(columnName: string, tableName: string | undefined, schemaName?: string): string;
16
20
  /**
17
21
  * @inheritDoc
18
22
  */
@@ -22,10 +26,18 @@ export declare abstract class AbstractNamingStrategy implements NamingStrategy {
22
26
  * @inheritDoc
23
27
  */
24
28
  inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
25
- abstract classToTableName(entityName: string): string;
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ manyToManyPropertyName(ownerEntityName: string, targetEntityName: string, pivotTableName: string, ownerTableName: string, schemaName?: string): string;
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ discriminatorColumnName(baseName: string): string;
37
+ abstract classToTableName(entityName: string, tableName?: string): string;
26
38
  abstract joinColumnName(propertyName: string): string;
27
- abstract joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
28
- abstract joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string): string;
39
+ abstract joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
40
+ abstract joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string, tableName?: string): string;
29
41
  abstract propertyToColumnName(propertyName: string, object?: boolean): string;
30
42
  abstract referenceColumnName(): string;
31
43
  }