@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321

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 (216) hide show
  1. package/EntityManager.d.ts +71 -63
  2. package/EntityManager.js +365 -283
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -142
  5. package/README.md +7 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -2
  7. package/cache/FileCacheAdapter.js +19 -14
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +1 -2
  11. package/cache/index.js +0 -2
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +37 -15
  14. package/drivers/DatabaseDriver.d.ts +25 -18
  15. package/drivers/DatabaseDriver.js +144 -45
  16. package/drivers/IDatabaseDriver.d.ts +118 -23
  17. package/entity/BaseEntity.d.ts +63 -4
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +473 -115
  21. package/entity/EntityAssigner.js +37 -25
  22. package/entity/EntityFactory.d.ts +7 -1
  23. package/entity/EntityFactory.js +116 -64
  24. package/entity/EntityHelper.d.ts +2 -2
  25. package/entity/EntityHelper.js +69 -27
  26. package/entity/EntityLoader.d.ts +11 -10
  27. package/entity/EntityLoader.js +264 -102
  28. package/entity/EntityRepository.d.ts +28 -8
  29. package/entity/EntityRepository.js +8 -2
  30. package/entity/PolymorphicRef.d.ts +12 -0
  31. package/entity/PolymorphicRef.js +18 -0
  32. package/entity/Reference.d.ts +2 -6
  33. package/entity/Reference.js +52 -19
  34. package/entity/WrappedEntity.d.ts +3 -8
  35. package/entity/WrappedEntity.js +6 -7
  36. package/entity/defineEntity.d.ts +525 -311
  37. package/entity/defineEntity.js +134 -290
  38. package/entity/index.d.ts +2 -2
  39. package/entity/index.js +2 -2
  40. package/entity/utils.d.ts +6 -1
  41. package/entity/utils.js +46 -11
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +66 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +13 -17
  46. package/errors.d.ts +20 -10
  47. package/errors.js +63 -31
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +24 -13
  50. package/events/index.d.ts +1 -1
  51. package/events/index.js +0 -1
  52. package/exceptions.js +9 -2
  53. package/hydration/Hydrator.js +1 -2
  54. package/hydration/ObjectHydrator.d.ts +4 -4
  55. package/hydration/ObjectHydrator.js +105 -46
  56. package/index.d.ts +2 -2
  57. package/index.js +1 -2
  58. package/logging/DefaultLogger.d.ts +1 -1
  59. package/logging/DefaultLogger.js +3 -4
  60. package/logging/SimpleLogger.d.ts +1 -1
  61. package/logging/colors.d.ts +1 -1
  62. package/logging/colors.js +5 -7
  63. package/logging/index.d.ts +2 -1
  64. package/logging/index.js +1 -1
  65. package/logging/inspect.d.ts +2 -0
  66. package/logging/inspect.js +11 -0
  67. package/metadata/EntitySchema.d.ts +47 -23
  68. package/metadata/EntitySchema.js +103 -34
  69. package/metadata/MetadataDiscovery.d.ts +64 -9
  70. package/metadata/MetadataDiscovery.js +867 -354
  71. package/metadata/MetadataProvider.d.ts +11 -2
  72. package/metadata/MetadataProvider.js +71 -2
  73. package/metadata/MetadataStorage.d.ts +13 -11
  74. package/metadata/MetadataStorage.js +72 -41
  75. package/metadata/MetadataValidator.d.ts +32 -9
  76. package/metadata/MetadataValidator.js +214 -44
  77. package/metadata/discover-entities.d.ts +5 -0
  78. package/metadata/discover-entities.js +40 -0
  79. package/metadata/index.d.ts +1 -1
  80. package/metadata/index.js +0 -1
  81. package/metadata/types.d.ts +577 -0
  82. package/metadata/types.js +1 -0
  83. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  84. package/naming-strategy/AbstractNamingStrategy.js +26 -5
  85. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  86. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  87. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/MongoNamingStrategy.js +6 -6
  89. package/naming-strategy/NamingStrategy.d.ts +28 -4
  90. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  91. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  92. package/naming-strategy/index.d.ts +1 -1
  93. package/naming-strategy/index.js +0 -1
  94. package/not-supported.d.ts +2 -0
  95. package/not-supported.js +8 -0
  96. package/package.json +47 -36
  97. package/platforms/ExceptionConverter.js +1 -1
  98. package/platforms/Platform.d.ts +33 -15
  99. package/platforms/Platform.js +125 -69
  100. package/serialization/EntitySerializer.d.ts +6 -3
  101. package/serialization/EntitySerializer.js +53 -29
  102. package/serialization/EntityTransformer.js +33 -21
  103. package/serialization/SerializationContext.d.ts +6 -6
  104. package/serialization/SerializationContext.js +4 -4
  105. package/types/ArrayType.d.ts +1 -1
  106. package/types/ArrayType.js +2 -3
  107. package/types/BigIntType.js +1 -1
  108. package/types/BlobType.d.ts +0 -1
  109. package/types/BlobType.js +0 -3
  110. package/types/BooleanType.d.ts +1 -0
  111. package/types/BooleanType.js +3 -0
  112. package/types/DecimalType.js +2 -2
  113. package/types/DoubleType.js +1 -1
  114. package/types/EnumArrayType.js +1 -2
  115. package/types/JsonType.d.ts +1 -1
  116. package/types/JsonType.js +7 -2
  117. package/types/TinyIntType.js +1 -1
  118. package/types/Type.d.ts +2 -4
  119. package/types/Type.js +3 -3
  120. package/types/Uint8ArrayType.d.ts +0 -1
  121. package/types/Uint8ArrayType.js +1 -4
  122. package/types/UuidType.d.ts +2 -0
  123. package/types/UuidType.js +14 -2
  124. package/types/index.d.ts +3 -2
  125. package/typings.d.ts +427 -170
  126. package/typings.js +100 -45
  127. package/unit-of-work/ChangeSet.d.ts +4 -6
  128. package/unit-of-work/ChangeSet.js +8 -9
  129. package/unit-of-work/ChangeSetComputer.d.ts +3 -8
  130. package/unit-of-work/ChangeSetComputer.js +49 -26
  131. package/unit-of-work/ChangeSetPersister.d.ts +13 -12
  132. package/unit-of-work/ChangeSetPersister.js +107 -44
  133. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  134. package/unit-of-work/CommitOrderCalculator.js +17 -15
  135. package/unit-of-work/IdentityMap.d.ts +12 -0
  136. package/unit-of-work/IdentityMap.js +39 -1
  137. package/unit-of-work/UnitOfWork.d.ts +34 -4
  138. package/unit-of-work/UnitOfWork.js +294 -107
  139. package/utils/AbstractMigrator.d.ts +101 -0
  140. package/utils/AbstractMigrator.js +303 -0
  141. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  142. package/utils/AbstractSchemaGenerator.js +30 -18
  143. package/utils/AsyncContext.d.ts +6 -0
  144. package/utils/AsyncContext.js +42 -0
  145. package/utils/Configuration.d.ts +796 -211
  146. package/utils/Configuration.js +160 -197
  147. package/utils/ConfigurationLoader.d.ts +1 -52
  148. package/utils/ConfigurationLoader.js +1 -330
  149. package/utils/Cursor.d.ts +0 -3
  150. package/utils/Cursor.js +29 -14
  151. package/utils/DataloaderUtils.d.ts +10 -5
  152. package/utils/DataloaderUtils.js +42 -22
  153. package/utils/EntityComparator.d.ts +16 -9
  154. package/utils/EntityComparator.js +202 -96
  155. package/utils/QueryHelper.d.ts +34 -7
  156. package/utils/QueryHelper.js +183 -72
  157. package/utils/RawQueryFragment.d.ts +28 -34
  158. package/utils/RawQueryFragment.js +37 -72
  159. package/utils/RequestContext.js +2 -2
  160. package/utils/TransactionContext.js +2 -2
  161. package/utils/TransactionManager.js +11 -7
  162. package/utils/Utils.d.ts +16 -127
  163. package/utils/Utils.js +106 -401
  164. package/utils/clone.js +13 -23
  165. package/utils/env-vars.d.ts +7 -0
  166. package/utils/env-vars.js +98 -0
  167. package/utils/fs-utils.d.ts +34 -0
  168. package/utils/fs-utils.js +193 -0
  169. package/utils/index.d.ts +1 -3
  170. package/utils/index.js +1 -3
  171. package/utils/upsert-utils.d.ts +9 -4
  172. package/utils/upsert-utils.js +51 -5
  173. package/decorators/Check.d.ts +0 -3
  174. package/decorators/Check.js +0 -13
  175. package/decorators/CreateRequestContext.d.ts +0 -3
  176. package/decorators/CreateRequestContext.js +0 -32
  177. package/decorators/Embeddable.d.ts +0 -8
  178. package/decorators/Embeddable.js +0 -11
  179. package/decorators/Embedded.d.ts +0 -12
  180. package/decorators/Embedded.js +0 -18
  181. package/decorators/Entity.d.ts +0 -33
  182. package/decorators/Entity.js +0 -12
  183. package/decorators/Enum.d.ts +0 -9
  184. package/decorators/Enum.js +0 -16
  185. package/decorators/Filter.d.ts +0 -2
  186. package/decorators/Filter.js +0 -8
  187. package/decorators/Formula.d.ts +0 -4
  188. package/decorators/Formula.js +0 -15
  189. package/decorators/Indexed.d.ts +0 -19
  190. package/decorators/Indexed.js +0 -20
  191. package/decorators/ManyToMany.d.ts +0 -42
  192. package/decorators/ManyToMany.js +0 -14
  193. package/decorators/ManyToOne.d.ts +0 -34
  194. package/decorators/ManyToOne.js +0 -14
  195. package/decorators/OneToMany.d.ts +0 -28
  196. package/decorators/OneToMany.js +0 -17
  197. package/decorators/OneToOne.d.ts +0 -28
  198. package/decorators/OneToOne.js +0 -7
  199. package/decorators/PrimaryKey.d.ts +0 -8
  200. package/decorators/PrimaryKey.js +0 -20
  201. package/decorators/Property.d.ts +0 -250
  202. package/decorators/Property.js +0 -32
  203. package/decorators/Transactional.d.ts +0 -14
  204. package/decorators/Transactional.js +0 -28
  205. package/decorators/hooks.d.ts +0 -16
  206. package/decorators/hooks.js +0 -47
  207. package/decorators/index.d.ts +0 -17
  208. package/decorators/index.js +0 -17
  209. package/entity/ArrayCollection.d.ts +0 -118
  210. package/entity/ArrayCollection.js +0 -407
  211. package/entity/EntityValidator.d.ts +0 -19
  212. package/entity/EntityValidator.js +0 -150
  213. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  214. package/metadata/ReflectMetadataProvider.js +0 -44
  215. package/utils/resolveContextProvider.d.ts +0 -10
  216. package/utils/resolveContextProvider.js +0 -28
@@ -1,330 +1 @@
1
- import dotenv from 'dotenv';
2
- import { realpathSync } from 'node:fs';
3
- import { colors } from '../logging/colors.js';
4
- import { Configuration } from './Configuration.js';
5
- import { Utils } from './Utils.js';
6
- /**
7
- * @internal
8
- */
9
- export class ConfigurationLoader {
10
- static async getConfiguration(contextName = 'default', paths = ConfigurationLoader.getConfigPaths(), options = {}) {
11
- // Backwards compatibility layer
12
- if (typeof contextName === 'boolean' || !Array.isArray(paths)) {
13
- this.registerDotenv(options);
14
- const configPathFromArg = ConfigurationLoader.configPathsFromArg();
15
- const configPaths = configPathFromArg ?? (Array.isArray(paths) ? paths : ConfigurationLoader.getConfigPaths());
16
- const config = contextName
17
- ? (await ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPaths, Array.isArray(paths) ? {} : paths))
18
- : await (async () => {
19
- const env = await this.loadEnvironmentVars();
20
- const [path, tmp] = await this.getConfigFile(configPaths);
21
- if (!path) {
22
- if (Utils.hasObjectKeys(env)) {
23
- return new Configuration(Utils.mergeConfig({}, options, env), false);
24
- }
25
- throw new Error(`MikroORM config file not found in ['${configPaths.join(`', '`)}']`);
26
- }
27
- return new Configuration(Utils.mergeConfig(tmp, options, env), false);
28
- })();
29
- if (configPathFromArg) {
30
- config.getLogger().warn('deprecated', 'Path for config file was inferred from the command line arguments. Instead, you should set the MIKRO_ORM_CLI_CONFIG environment variable to specify the path, or if you really must use the command line arguments, import the config manually based on them, and pass it to init.', { label: 'D0001' });
31
- }
32
- return config;
33
- }
34
- const env = await this.loadEnvironmentVars();
35
- const configFinder = (cfg) => {
36
- return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : (contextName === 'default'));
37
- };
38
- const isValidConfigFactoryResult = (cfg) => {
39
- return typeof cfg === 'object' && cfg !== null && (!('contextName' in cfg) || cfg.contextName === contextName);
40
- };
41
- const result = await this.getConfigFile(paths);
42
- if (!result[0]) {
43
- if (Utils.hasObjectKeys(env)) {
44
- return new Configuration(Utils.mergeConfig({ contextName }, options, env));
45
- }
46
- throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
47
- }
48
- const path = result[0];
49
- let tmp = result[1];
50
- if (Array.isArray(tmp)) {
51
- const tmpFirstIndex = tmp.findIndex(configFinder);
52
- if (tmpFirstIndex === -1) {
53
- // Static config not found. Try factory functions
54
- let configCandidate;
55
- for (let i = 0, l = tmp.length; i < l; ++i) {
56
- const f = tmp[i];
57
- if (typeof f !== 'function') {
58
- continue;
59
- }
60
- configCandidate = await f(contextName);
61
- if (!isValidConfigFactoryResult(configCandidate)) {
62
- continue;
63
- }
64
- tmp = configCandidate;
65
- break;
66
- }
67
- if (Array.isArray(tmp)) {
68
- throw new Error(`MikroORM config '${contextName}' was not found within the config file '${path}'. Either add a config with this name to the array, or add a function that when given this name will return a configuration object without a name, or with name set to this name.`);
69
- }
70
- }
71
- else {
72
- const tmpLastIndex = tmp.findLastIndex(configFinder);
73
- if (tmpLastIndex !== tmpFirstIndex) {
74
- throw new Error(`MikroORM config '${contextName}' is not unique within the array exported by '${path}' (first occurrence index: ${tmpFirstIndex}; last occurrence index: ${tmpLastIndex})`);
75
- }
76
- tmp = tmp[tmpFirstIndex];
77
- }
78
- }
79
- else {
80
- if (tmp instanceof Function) {
81
- tmp = await tmp(contextName);
82
- if (!isValidConfigFactoryResult(tmp)) {
83
- throw new Error(`MikroORM config '${contextName}' was not what the function exported from '${path}' provided. Ensure it returns a config object with no name, or name matching the requested one.`);
84
- }
85
- }
86
- else {
87
- if (!configFinder(tmp)) {
88
- throw new Error(`MikroORM config '${contextName}' was not what the default export from '${path}' provided.`);
89
- }
90
- }
91
- }
92
- const esmConfigOptions = this.isESM() ? { entityGenerator: { esmImport: true } } : {};
93
- return new Configuration(Utils.mergeConfig({}, esmConfigOptions, tmp, options, env));
94
- }
95
- static async getConfigFile(paths) {
96
- for (let path of paths) {
97
- path = Utils.absolutePath(path);
98
- path = Utils.normalizePath(path);
99
- if (Utils.pathExistsSync(path)) {
100
- const config = await Utils.dynamicImport(path);
101
- /* v8 ignore next */
102
- return [path, await (config.default ?? config)];
103
- }
104
- }
105
- return [];
106
- }
107
- static getPackageConfig(basePath = process.cwd()) {
108
- if (Utils.pathExistsSync(`${basePath}/package.json`)) {
109
- /* v8 ignore next 5 */
110
- try {
111
- return Utils.readJSONSync(`${basePath}/package.json`);
112
- }
113
- catch {
114
- return {};
115
- }
116
- }
117
- const parentFolder = realpathSync(`${basePath}/..`);
118
- // we reached the root folder
119
- if (basePath === parentFolder) {
120
- return {};
121
- }
122
- return this.getPackageConfig(parentFolder);
123
- }
124
- static getSettings() {
125
- const config = ConfigurationLoader.getPackageConfig();
126
- const settings = { ...config['mikro-orm'] };
127
- const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
128
- settings.preferTs = process.env.MIKRO_ORM_CLI_PREFER_TS != null ? bool(process.env.MIKRO_ORM_CLI_PREFER_TS) : settings.preferTs;
129
- settings.tsConfigPath = process.env.MIKRO_ORM_CLI_TS_CONFIG_PATH ?? settings.tsConfigPath;
130
- settings.alwaysAllowTs = process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS != null ? bool(process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS) : settings.alwaysAllowTs;
131
- settings.verbose = process.env.MIKRO_ORM_CLI_VERBOSE != null ? bool(process.env.MIKRO_ORM_CLI_VERBOSE) : settings.verbose;
132
- if (process.env.MIKRO_ORM_CLI_CONFIG?.endsWith('.ts')) {
133
- settings.preferTs = true;
134
- }
135
- return settings;
136
- }
137
- static configPathsFromArg() {
138
- const options = Utils.parseArgs();
139
- const configArgName = process.env.MIKRO_ORM_CONFIG_ARG_NAME ?? 'config';
140
- if (options[configArgName]) {
141
- return [options[configArgName]];
142
- }
143
- return undefined;
144
- }
145
- static getConfigPaths() {
146
- const paths = [];
147
- const settings = ConfigurationLoader.getSettings();
148
- if (process.env.MIKRO_ORM_CLI_CONFIG) {
149
- paths.push(process.env.MIKRO_ORM_CLI_CONFIG);
150
- }
151
- paths.push(...(settings.configPaths || []));
152
- const alwaysAllowTs = settings.alwaysAllowTs ?? process.versions.bun;
153
- if (settings.preferTs !== false || alwaysAllowTs) {
154
- paths.push('./src/mikro-orm.config.ts');
155
- paths.push('./mikro-orm.config.ts');
156
- }
157
- const distDir = Utils.pathExistsSync(process.cwd() + '/dist');
158
- const buildDir = Utils.pathExistsSync(process.cwd() + '/build');
159
- /* v8 ignore next */
160
- const path = distDir ? 'dist' : (buildDir ? 'build' : 'src');
161
- paths.push(`./${path}/mikro-orm.config.js`);
162
- paths.push('./mikro-orm.config.js');
163
- const typeScriptSupport = Utils.detectTypeScriptSupport();
164
- /* v8 ignore next */
165
- return Utils.unique(paths).filter(p => p.endsWith('.js') || typeScriptSupport || alwaysAllowTs);
166
- }
167
- static isESM() {
168
- const config = ConfigurationLoader.getPackageConfig();
169
- const type = config?.type ?? '';
170
- return type === 'module';
171
- }
172
- static async registerTypeScriptSupport(configPath = 'tsconfig.json') {
173
- /* v8 ignore next 3 */
174
- if (process.versions.bun) {
175
- return true;
176
- }
177
- process.env.SWC_NODE_PROJECT ??= configPath;
178
- process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
179
- const esm = this.isESM();
180
- /* v8 ignore next 2 */
181
- const importMethod = esm ? 'tryImport' : 'tryRequire';
182
- const module = esm ? '@swc-node/register/esm-register' : '@swc-node/register';
183
- const supported = await Utils[importMethod]({
184
- module,
185
- warning: '@swc-node/register and @swc/core are not installed, support for working with TypeScript files might not work',
186
- });
187
- return !!supported;
188
- }
189
- static registerDotenv(options) {
190
- const path = process.env.MIKRO_ORM_ENV ?? ((options?.baseDir ?? process.cwd()) + '/.env');
191
- const env = {};
192
- dotenv.config({ path, processEnv: env, quiet: true });
193
- // only propagate known env vars
194
- for (const key of Object.keys(env)) {
195
- if (key.startsWith('MIKRO_ORM_')) {
196
- process.env[key] ??= env[key]; // respect user provided values
197
- }
198
- }
199
- }
200
- static async loadEnvironmentVars() {
201
- const ret = this.loadEnvironmentVarsSync();
202
- // only to keep some sort of back compatibility with those using env vars only, to support `MIKRO_ORM_TYPE`
203
- const PLATFORMS = {
204
- mongo: { className: 'MongoDriver', module: '@mikro-orm/mongodb' },
205
- mysql: { className: 'MySqlDriver', module: '@mikro-orm/mysql' },
206
- mssql: { className: 'MsSqlDriver', module: '@mikro-orm/mssql' },
207
- mariadb: { className: 'MariaDbDriver', module: '@mikro-orm/mariadb' },
208
- postgresql: { className: 'PostgreSqlDriver', module: '@mikro-orm/postgresql' },
209
- sqlite: { className: 'SqliteDriver', module: '@mikro-orm/sqlite' },
210
- libsql: { className: 'LibSqlDriver', module: '@mikro-orm/libsql' },
211
- };
212
- if (process.env.MIKRO_ORM_TYPE) {
213
- const val = process.env.MIKRO_ORM_TYPE;
214
- const driver = await import(PLATFORMS[val].module);
215
- ret.driver = driver[PLATFORMS[val].className];
216
- }
217
- return ret;
218
- }
219
- static loadEnvironmentVarsSync() {
220
- const ret = {};
221
- const array = (v) => v.split(',').map(vv => vv.trim());
222
- const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
223
- const num = (v) => +v;
224
- const read = (o, envKey, key, mapper = v => v) => {
225
- if (!(envKey in process.env)) {
226
- return;
227
- }
228
- const val = process.env[envKey];
229
- o[key] = mapper(val);
230
- };
231
- const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
232
- read(ret, 'MIKRO_ORM_BASE_DIR', 'baseDir');
233
- read(ret, 'MIKRO_ORM_ENTITIES', 'entities', array);
234
- read(ret, 'MIKRO_ORM_ENTITIES_TS', 'entitiesTs', array);
235
- read(ret, 'MIKRO_ORM_CLIENT_URL', 'clientUrl');
236
- read(ret, 'MIKRO_ORM_HOST', 'host');
237
- read(ret, 'MIKRO_ORM_PORT', 'port', num);
238
- read(ret, 'MIKRO_ORM_USER', 'user');
239
- read(ret, 'MIKRO_ORM_PASSWORD', 'password');
240
- read(ret, 'MIKRO_ORM_DB_NAME', 'dbName');
241
- read(ret, 'MIKRO_ORM_SCHEMA', 'schema');
242
- read(ret, 'MIKRO_ORM_LOAD_STRATEGY', 'loadStrategy');
243
- read(ret, 'MIKRO_ORM_BATCH_SIZE', 'batchSize', num);
244
- read(ret, 'MIKRO_ORM_USE_BATCH_INSERTS', 'useBatchInserts', bool);
245
- read(ret, 'MIKRO_ORM_USE_BATCH_UPDATES', 'useBatchUpdates', bool);
246
- read(ret, 'MIKRO_ORM_STRICT', 'strict', bool);
247
- read(ret, 'MIKRO_ORM_VALIDATE', 'validate', bool);
248
- read(ret, 'MIKRO_ORM_ALLOW_GLOBAL_CONTEXT', 'allowGlobalContext', bool);
249
- read(ret, 'MIKRO_ORM_AUTO_JOIN_ONE_TO_ONE_OWNER', 'autoJoinOneToOneOwner', bool);
250
- read(ret, 'MIKRO_ORM_POPULATE_AFTER_FLUSH', 'populateAfterFlush', bool);
251
- read(ret, 'MIKRO_ORM_FORCE_ENTITY_CONSTRUCTOR', 'forceEntityConstructor', bool);
252
- read(ret, 'MIKRO_ORM_FORCE_UNDEFINED', 'forceUndefined', bool);
253
- read(ret, 'MIKRO_ORM_FORCE_UTC_TIMEZONE', 'forceUtcTimezone', bool);
254
- read(ret, 'MIKRO_ORM_TIMEZONE', 'timezone');
255
- read(ret, 'MIKRO_ORM_ENSURE_INDEXES', 'ensureIndexes', bool);
256
- read(ret, 'MIKRO_ORM_IMPLICIT_TRANSACTIONS', 'implicitTransactions', bool);
257
- read(ret, 'MIKRO_ORM_DEBUG', 'debug', bool);
258
- read(ret, 'MIKRO_ORM_COLORS', 'colors', bool);
259
- ret.discovery = {};
260
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_WARN_WHEN_NO_ENTITIES', 'warnWhenNoEntities', bool);
261
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_REQUIRE_ENTITIES_ARRAY', 'requireEntitiesArray', bool);
262
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_ALWAYS_ANALYSE_PROPERTIES', 'alwaysAnalyseProperties', bool);
263
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_DISABLE_DYNAMIC_FILE_ACCESS', 'disableDynamicFileAccess', bool);
264
- cleanup(ret, 'discovery');
265
- ret.migrations = {};
266
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TABLE_NAME', 'tableName');
267
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_PATH', 'path');
268
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_PATH_TS', 'pathTs');
269
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_GLOB', 'glob');
270
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TRANSACTIONAL', 'transactional', bool);
271
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_DISABLE_FOREIGN_KEYS', 'disableForeignKeys', bool);
272
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_ALL_OR_NOTHING', 'allOrNothing', bool);
273
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_DROP_TABLES', 'dropTables', bool);
274
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SAFE', 'safe', bool);
275
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SILENT', 'silent', bool);
276
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_EMIT', 'emit');
277
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SNAPSHOT', 'snapshot', bool);
278
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SNAPSHOT_NAME', 'snapshotName');
279
- cleanup(ret, 'migrations');
280
- ret.schemaGenerator = {};
281
- read(ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_DISABLE_FOREIGN_KEYS', 'disableForeignKeys', bool);
282
- read(ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_CREATE_FOREIGN_KEY_CONSTRAINTS', 'createForeignKeyConstraints', bool);
283
- cleanup(ret, 'schemaGenerator');
284
- ret.seeder = {};
285
- read(ret.seeder, 'MIKRO_ORM_SEEDER_PATH', 'path');
286
- read(ret.seeder, 'MIKRO_ORM_SEEDER_PATH_TS', 'pathTs');
287
- read(ret.seeder, 'MIKRO_ORM_SEEDER_GLOB', 'glob');
288
- read(ret.seeder, 'MIKRO_ORM_SEEDER_EMIT', 'emit');
289
- read(ret.seeder, 'MIKRO_ORM_SEEDER_DEFAULT_SEEDER', 'defaultSeeder');
290
- cleanup(ret, 'seeder');
291
- return ret;
292
- }
293
- static getORMPackages() {
294
- const pkg = this.getPackageConfig();
295
- return new Set([
296
- ...Object.keys(pkg.dependencies ?? {}),
297
- ...Object.keys(pkg.devDependencies ?? {}),
298
- ]);
299
- }
300
- static getORMPackageVersion(name) {
301
- try {
302
- const pkg = Utils.requireFrom(`${name}/package.json`);
303
- /* v8 ignore next */
304
- return pkg?.version;
305
- }
306
- catch (e) {
307
- return undefined;
308
- }
309
- }
310
- // inspired by https://github.com/facebook/docusaurus/pull/3386
311
- static checkPackageVersion() {
312
- const coreVersion = Utils.getORMVersion();
313
- if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === 'N/A') {
314
- return coreVersion;
315
- }
316
- const deps = this.getORMPackages();
317
- const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
318
- const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
319
- for (const ormPackage of ormPackages) {
320
- const version = this.getORMPackageVersion(ormPackage);
321
- if (version != null && version !== coreVersion) {
322
- throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
323
- `All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
324
- `Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
325
- `Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
326
- }
327
- }
328
- return coreVersion;
329
- }
330
- }
1
+ export {};
package/utils/Cursor.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { inspect } from 'node:util';
2
1
  import type { EntityMetadata, FilterObject, Loaded } from '../typings.js';
3
2
  import type { FindByCursorOptions, OrderDefinition } from '../drivers/IDatabaseDriver.js';
4
3
  import { type QueryOrder } from '../enums.js';
@@ -71,6 +70,4 @@ export declare class Cursor<Entity extends object, Hint extends string = never,
71
70
  static encode(value: unknown[]): string;
72
71
  static decode(value: string): unknown[];
73
72
  static getDefinition<Entity extends object>(meta: EntityMetadata<Entity>, orderBy: OrderDefinition<Entity>): [never, QueryOrder][];
74
- /** @ignore */
75
- [inspect.custom](): string;
76
73
  }
package/utils/Cursor.js CHANGED
@@ -1,10 +1,10 @@
1
- import { inspect } from 'node:util';
2
1
  import { Utils } from './Utils.js';
3
2
  import { ReferenceKind } from '../enums.js';
4
3
  import { Reference } from '../entity/Reference.js';
5
4
  import { helper } from '../entity/wrap.js';
6
- import { RawQueryFragment } from '../utils/RawQueryFragment.js';
5
+ import { Raw } from '../utils/RawQueryFragment.js';
7
6
  import { CursorError } from '../errors.js';
7
+ import { inspect } from '../logging/inspect.js';
8
8
  /**
9
9
  * As an alternative to the offset-based pagination with `limit` and `offset`, we can paginate based on a cursor.
10
10
  * A cursor is an opaque string that defines a specific place in ordered entity graph. You can use `em.findByCursor()`
@@ -95,15 +95,22 @@ export class Cursor {
95
95
  from(entity) {
96
96
  const processEntity = (entity, prop, direction, object = false) => {
97
97
  if (Utils.isPlainObject(direction)) {
98
+ const unwrapped = Reference.unwrapReference(entity[prop]);
99
+ // Check if the relation is loaded - for nested properties, undefined means not populated
100
+ if (Utils.isEntity(unwrapped) && !helper(unwrapped).isInitialized()) {
101
+ throw CursorError.entityNotPopulated(entity, prop);
102
+ }
98
103
  return Utils.keys(direction).reduce((o, key) => {
99
- Object.assign(o, processEntity(Reference.unwrapReference(entity[prop]), key, direction[key], true));
104
+ Object.assign(o, processEntity(unwrapped, key, direction[key], true));
100
105
  return o;
101
106
  }, {});
102
107
  }
103
- if (entity[prop] == null) {
104
- throw CursorError.entityNotPopulated(entity, prop);
105
- }
106
108
  let value = entity[prop];
109
+ // Allow null/undefined values in cursor - they will be handled in createCursorCondition
110
+ // undefined can occur with forceUndefined config option which converts null to undefined
111
+ if (value == null) {
112
+ return object ? { [prop]: null } : null;
113
+ }
107
114
  if (Utils.isEntity(value, true)) {
108
115
  value = helper(value).getPrimaryKey();
109
116
  }
@@ -111,7 +118,7 @@ export class Cursor {
111
118
  value = value.unwrap();
112
119
  }
113
120
  if (object) {
114
- return ({ [prop]: value });
121
+ return { [prop]: value };
115
122
  }
116
123
  return value;
117
124
  };
@@ -131,14 +138,20 @@ export class Cursor {
131
138
  */
132
139
  static for(meta, entity, orderBy) {
133
140
  const definition = this.getDefinition(meta, orderBy);
134
- return Cursor.encode(definition.map(([key]) => entity[key]));
141
+ return Cursor.encode(definition.map(([key]) => {
142
+ const value = entity[key];
143
+ if (value === undefined) {
144
+ throw CursorError.missingValue(meta.className, key);
145
+ }
146
+ return value;
147
+ }));
135
148
  }
136
149
  static encode(value) {
137
150
  return Buffer.from(JSON.stringify(value)).toString('base64url');
138
151
  }
139
152
  static decode(value) {
140
153
  return JSON.parse(Buffer.from(value, 'base64url').toString('utf8')).map((value) => {
141
- if (typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/)) {
154
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/.exec(value)) {
142
155
  return new Date(value);
143
156
  }
144
157
  return value;
@@ -147,14 +160,16 @@ export class Cursor {
147
160
  static getDefinition(meta, orderBy) {
148
161
  return Utils.asArray(orderBy).flatMap(order => {
149
162
  const ret = [];
150
- for (const key of Utils.keys(order)) {
151
- if (RawQueryFragment.isKnownFragment(key)) {
163
+ for (const key of Utils.getObjectQueryKeys(order)) {
164
+ if (Raw.isKnownFragmentSymbol(key)) {
152
165
  ret.push([key, order[key]]);
153
166
  continue;
154
167
  }
155
168
  const prop = meta.properties[key];
156
169
  /* v8 ignore next */
157
- if (!prop || !([ReferenceKind.SCALAR, ReferenceKind.EMBEDDED, ReferenceKind.MANY_TO_ONE].includes(prop.kind) || (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner))) {
170
+ if (!prop ||
171
+ !([ReferenceKind.SCALAR, ReferenceKind.EMBEDDED, ReferenceKind.MANY_TO_ONE].includes(prop.kind) ||
172
+ (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner))) {
158
173
  continue;
159
174
  }
160
175
  ret.push([prop.name, order[prop.name]]);
@@ -162,9 +177,9 @@ export class Cursor {
162
177
  return ret;
163
178
  });
164
179
  }
165
- /* v8 ignore start */
166
180
  /** @ignore */
167
- [inspect.custom]() {
181
+ /* v8 ignore next */
182
+ [Symbol.for('nodejs.util.inspect.custom')]() {
168
183
  const type = this.items[0]?.constructor.name;
169
184
  const { items, startCursor, endCursor, hasPrevPage, hasNextPage, totalCount, length } = this;
170
185
  const options = inspect({ startCursor, endCursor, totalCount, hasPrevPage, hasNextPage, items, length }, { depth: 0 });
@@ -1,9 +1,10 @@
1
- import type DataLoader from 'dataloader';
2
- import type { Primary, Ref } from '../typings.js';
1
+ import type { Constructor, Primary, Ref } from '../typings.js';
3
2
  import { Collection, type InitCollectionOptions } from '../entity/Collection.js';
4
3
  import { type EntityManager } from '../EntityManager.js';
5
4
  import { type LoadReferenceOptions } from '../entity/Reference.js';
5
+ type BatchLoadFn<K, V> = (keys: readonly K[]) => PromiseLike<ArrayLike<V | Error>>;
6
6
  export declare class DataloaderUtils {
7
+ private static DataLoader?;
7
8
  /**
8
9
  * Groups identified references by entity and returns a Map with the
9
10
  * class name as the index and the corresponding primary keys as the value.
@@ -13,7 +14,7 @@ export declare class DataloaderUtils {
13
14
  * Returns the reference dataloader batchLoadFn, which aggregates references by entity,
14
15
  * makes one query per entity and maps each input reference to the corresponding result.
15
16
  */
16
- static getRefBatchLoadFn(em: EntityManager): DataLoader.BatchLoadFn<[Ref<any>, Omit<LoadReferenceOptions<any, any>, 'dataloader'>?], any>;
17
+ static getRefBatchLoadFn(em: EntityManager): BatchLoadFn<[Ref<any>, Omit<LoadReferenceOptions<any, any>, 'dataloader'>?], any>;
17
18
  /**
18
19
  * Groups collections by entity and returns a Map whose keys are the entity names and whose values are filter Maps
19
20
  * which we can use to narrow down the find query to return just the items of the collections that have been dataloaded.
@@ -37,10 +38,14 @@ export declare class DataloaderUtils {
37
38
  * Returns the 1:M collection dataloader batchLoadFn, which aggregates collections by entity,
38
39
  * makes one query per entity and maps each input collection to the corresponding result.
39
40
  */
40
- static getColBatchLoadFn(em: EntityManager): DataLoader.BatchLoadFn<[Collection<any>, Omit<InitCollectionOptions<any, any>, 'dataloader'>?], any>;
41
+ static getColBatchLoadFn(em: EntityManager): BatchLoadFn<[Collection<any>, Omit<InitCollectionOptions<any, any>, 'dataloader'>?], any>;
41
42
  /**
42
43
  * Returns the M:N collection dataloader batchLoadFn, which aggregates collections by entity,
43
44
  * makes one query per entity and maps each input collection to the corresponding result.
44
45
  */
45
- static getManyToManyColBatchLoadFn(em: EntityManager): DataLoader.BatchLoadFn<[Collection<any>, Omit<InitCollectionOptions<any, any>, 'dataloader'>?], any>;
46
+ static getManyToManyColBatchLoadFn(em: EntityManager): BatchLoadFn<[Collection<any>, Omit<InitCollectionOptions<any, any>, 'dataloader'>?], any>;
47
+ static getDataLoader(): Promise<Constructor<{
48
+ load: (...args: unknown[]) => Promise<unknown>;
49
+ }>>;
46
50
  }
51
+ export {};
@@ -3,6 +3,7 @@ import { helper } from '../entity/wrap.js';
3
3
  import { Reference } from '../entity/Reference.js';
4
4
  import { Utils } from './Utils.js';
5
5
  export class DataloaderUtils {
6
+ static DataLoader;
6
7
  /**
7
8
  * Groups identified references by entity and returns a Map with the
8
9
  * class name as the index and the corresponding primary keys as the value.
@@ -10,7 +11,7 @@ export class DataloaderUtils {
10
11
  static groupPrimaryKeysByEntityAndOpts(refsWithOpts) {
11
12
  const map = new Map();
12
13
  for (const [ref, opts] of refsWithOpts) {
13
- /* The key is a combination of the className and a stringified version if the load options because we want
14
+ /* The key is a combination of the uniqueName (a unique table name based identifier) and a stringified version if the load options because we want
14
15
  to map each combination of entities/options into separate find queries in order to return accurate results.
15
16
  This could be further optimized finding the "lowest common denominator" among the different options
16
17
  for each Entity and firing a single query for each Entity instead of Entity+options combination.
@@ -23,7 +24,7 @@ export class DataloaderUtils {
23
24
  Thus such approach should probably be configurable, if not opt-in.
24
25
  NOTE: meta + opts multi maps (https://github.com/martian17/ds-js) might be a more elegant way
25
26
  to implement this but not necessarily faster. */
26
- const key = `${helper(ref).__meta.className}|${JSON.stringify(opts ?? {})}`;
27
+ const key = `${helper(ref).__meta.uniqueName}|${JSON.stringify(opts ?? {})}`;
27
28
  let primaryKeysSet = map.get(key);
28
29
  if (primaryKeysSet == null) {
29
30
  primaryKeysSet = new Set();
@@ -41,9 +42,10 @@ export class DataloaderUtils {
41
42
  return async (refsWithOpts) => {
42
43
  const groupedIdsMap = DataloaderUtils.groupPrimaryKeysByEntityAndOpts(refsWithOpts);
43
44
  const promises = Array.from(groupedIdsMap).map(([key, idsSet]) => {
44
- const className = key.substring(0, key.indexOf('|'));
45
+ const uniqueName = key.substring(0, key.indexOf('|'));
45
46
  const opts = JSON.parse(key.substring(key.indexOf('|') + 1));
46
- return em.find(className, Array.from(idsSet), opts);
47
+ const meta = em.getMetadata().getByUniqueName(uniqueName);
48
+ return em.find(meta.class, Array.from(idsSet), opts);
47
49
  });
48
50
  await Promise.all(promises);
49
51
  /* Instead of assigning each find result to the original reference we use a shortcut
@@ -69,7 +71,7 @@ export class DataloaderUtils {
69
71
  The value is another Map which we can use to filter the find query to get results pertaining to the collections that have been dataloaded:
70
72
  its keys are the props we are going to filter to and its values are the corresponding PKs.
71
73
  */
72
- const key = `${col.property.targetMeta.className}|${JSON.stringify(opts ?? {})}`;
74
+ const key = `${col.property.targetMeta.uniqueName}|${JSON.stringify(opts ?? {})}`;
73
75
  let filterMap = entitiesMap.get(key); // We are going to use this map to filter the entities pertaining to the collections that have been dataloaded.
74
76
  if (filterMap == null) {
75
77
  filterMap = new Map();
@@ -96,31 +98,33 @@ export class DataloaderUtils {
96
98
  */
97
99
  static entitiesAndOptsMapToQueries(entitiesAndOptsMap, em) {
98
100
  return Array.from(entitiesAndOptsMap, async ([key, filterMap]) => {
99
- const className = key.substring(0, key.indexOf('|'));
101
+ const uniqueName = key.substring(0, key.indexOf('|'));
100
102
  const opts = JSON.parse(key.substring(key.indexOf('|') + 1));
101
- const res = await em.find(className, opts?.where != null && Object.keys(opts.where).length > 0 ?
102
- {
103
+ const meta = em.getMetadata().getByUniqueName(uniqueName);
104
+ const res = await em.find(meta.class, opts?.where != null && Object.keys(opts.where).length > 0
105
+ ? {
103
106
  $and: [
104
107
  {
105
108
  $or: Array.from(filterMap.entries()).map(([prop, pks]) => {
106
- return ({ [prop]: Array.from(pks) });
109
+ return { [prop]: Array.from(pks) };
107
110
  }),
108
111
  },
109
112
  opts.where,
110
113
  ],
111
- } : {
112
- // The entries of the filter Map will be used as the values of the $or operator
113
- $or: Array.from(filterMap.entries()).map(([prop, pks]) => {
114
- return ({ [prop]: Array.from(pks) });
115
- }),
116
- }, {
114
+ }
115
+ : {
116
+ // The entries of the filter Map will be used as the values of the $or operator
117
+ $or: Array.from(filterMap.entries()).map(([prop, pks]) => {
118
+ return { [prop]: Array.from(pks) };
119
+ }),
120
+ }, {
117
121
  ...opts,
118
122
  // We need to populate the inverse side of the relationship in order to be able to later retrieve the PK(s) from its item(s)
119
123
  populate: [
120
- ...(opts.populate === false ? [] : opts.populate ?? []),
124
+ ...(opts.populate === false ? [] : (opts.populate ?? [])),
121
125
  ...Array.from(filterMap.keys()).filter(
122
126
  // We need to do so only if the inverse side is a collection, because we can already retrieve the PK from a reference without having to load it
123
- prop => em.getMetadata(className).properties[prop]?.ref !== true),
127
+ prop => meta.properties[prop]?.ref !== true),
124
128
  ],
125
129
  });
126
130
  return [key, res];
@@ -163,11 +167,11 @@ export class DataloaderUtils {
163
167
  // We need to filter the results in order to map each input collection
164
168
  // to a subset of each query matching the collection items.
165
169
  return collsWithOpts.map(([col, opts]) => {
166
- const key = `${col.property.targetMeta.className}|${JSON.stringify(opts ?? {})}`;
170
+ const key = `${col.property.targetMeta.uniqueName}|${JSON.stringify(opts ?? {})}`;
167
171
  const entities = resultsMap.get(key);
168
172
  if (entities == null) {
169
173
  // Should never happen
170
- /* v8 ignore next 3 */
174
+ /* v8 ignore next */
171
175
  throw new Error('Cannot match results');
172
176
  }
173
177
  return entities.filter(DataloaderUtils.getColFilter(col));
@@ -182,7 +186,7 @@ export class DataloaderUtils {
182
186
  return async (collsWithOpts) => {
183
187
  const groups = new Map();
184
188
  for (const [col, opts] of collsWithOpts) {
185
- const key = `${col.property.targetMeta.className}.${col.property.name}|${JSON.stringify(opts ?? {})}`;
189
+ const key = `${col.property.targetMeta.uniqueName}.${col.property.name}|${JSON.stringify(opts ?? {})}`;
186
190
  const value = groups.get(key) ?? [];
187
191
  value.push([col, opts ?? {}]);
188
192
  groups.set(key, value);
@@ -197,17 +201,33 @@ export class DataloaderUtils {
197
201
  const owners = group.map(c => c[0].owner);
198
202
  const $or = [];
199
203
  // a bit of a hack, but we need to prefix the key, since we have only a column name, not a property name
200
- const alias = em.config.getNamingStrategy().aliasName(prop.pivotEntity, 0);
204
+ const alias = em.config.getNamingStrategy().aliasName(Utils.className(prop.pivotEntity), 0);
201
205
  const fk = `${alias}.${Utils.getPrimaryKeyHash(prop.joinColumns)}`;
202
206
  for (const c of group) {
203
207
  $or.push({ $and: [c[1]?.where ?? {}, { [fk]: c[0].owner }] });
204
208
  options.refresh ??= c[1]?.refresh;
205
209
  }
206
210
  options.where = wrap({ $or });
207
- const r = await em.getEntityLoader().findChildrenFromPivotTable(owners, prop, options, orderBy, populate, group[0][1]?.ref);
211
+ const r = await em
212
+ .getEntityLoader()
213
+ .findChildrenFromPivotTable(owners, prop, options, orderBy, populate, group[0][1]?.ref);
208
214
  ret.push(...r);
209
215
  }
210
216
  return ret;
211
217
  };
212
218
  }
219
+ static async getDataLoader() {
220
+ if (this.DataLoader) {
221
+ return this.DataLoader;
222
+ }
223
+ try {
224
+ const mod = await import('dataloader');
225
+ const DataLoader = mod.default;
226
+ return (this.DataLoader ??= DataLoader);
227
+ }
228
+ catch {
229
+ /* v8 ignore next */
230
+ throw new Error("DataLoader is not found, make sure `dataloader` package is installed in your project's dependencies.");
231
+ }
232
+ }
213
233
  }