@mikro-orm/core 7.0.4 → 7.0.5-dev.1

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 (206) hide show
  1. package/EntityManager.d.ts +583 -884
  2. package/EntityManager.js +1895 -1922
  3. package/MikroORM.d.ts +74 -103
  4. package/MikroORM.js +179 -178
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +24 -30
  8. package/cache/FileCacheAdapter.js +78 -80
  9. package/cache/GeneratedCacheAdapter.d.ts +20 -18
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +20 -18
  12. package/cache/MemoryCacheAdapter.js +36 -35
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +84 -95
  16. package/connections/Connection.js +168 -165
  17. package/drivers/DatabaseDriver.d.ts +80 -186
  18. package/drivers/DatabaseDriver.js +443 -450
  19. package/drivers/IDatabaseDriver.d.ts +301 -440
  20. package/entity/BaseEntity.d.ts +83 -120
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +179 -212
  23. package/entity/Collection.js +721 -727
  24. package/entity/EntityAssigner.d.ts +77 -88
  25. package/entity/EntityAssigner.js +230 -231
  26. package/entity/EntityFactory.d.ts +54 -66
  27. package/entity/EntityFactory.js +383 -425
  28. package/entity/EntityHelper.d.ts +22 -34
  29. package/entity/EntityHelper.js +267 -280
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +72 -98
  33. package/entity/EntityLoader.js +723 -753
  34. package/entity/EntityRepository.d.ts +201 -316
  35. package/entity/EntityRepository.js +213 -213
  36. package/entity/PolymorphicRef.d.ts +5 -5
  37. package/entity/PolymorphicRef.js +10 -10
  38. package/entity/Reference.d.ts +82 -126
  39. package/entity/Reference.js +274 -278
  40. package/entity/WrappedEntity.d.ts +72 -115
  41. package/entity/WrappedEntity.js +166 -168
  42. package/entity/defineEntity.d.ts +636 -1315
  43. package/entity/defineEntity.js +518 -527
  44. package/entity/utils.d.ts +3 -13
  45. package/entity/utils.js +73 -71
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +253 -258
  49. package/enums.js +252 -251
  50. package/errors.d.ts +72 -114
  51. package/errors.js +253 -350
  52. package/events/EventManager.d.ts +14 -26
  53. package/events/EventManager.js +77 -79
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +8 -15
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +40 -23
  58. package/exceptions.js +52 -35
  59. package/hydration/Hydrator.d.ts +17 -42
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +17 -50
  62. package/hydration/ObjectHydrator.js +416 -481
  63. package/index.d.ts +2 -116
  64. package/index.js +1 -10
  65. package/logging/DefaultLogger.d.ts +32 -34
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +11 -13
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +10 -11
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +127 -211
  74. package/metadata/EntitySchema.js +398 -397
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1870 -1951
  77. package/metadata/MetadataProvider.d.ts +21 -24
  78. package/metadata/MetadataProvider.js +84 -82
  79. package/metadata/MetadataStorage.d.ts +32 -38
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +338 -381
  83. package/metadata/discover-entities.d.ts +2 -5
  84. package/metadata/discover-entities.js +37 -35
  85. package/metadata/types.d.ts +531 -615
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
  87. package/naming-strategy/AbstractNamingStrategy.js +85 -90
  88. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  89. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  90. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  91. package/naming-strategy/MongoNamingStrategy.js +18 -18
  92. package/naming-strategy/NamingStrategy.d.ts +99 -109
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +4 -7
  96. package/package.json +1 -1
  97. package/platforms/ExceptionConverter.d.ts +1 -1
  98. package/platforms/ExceptionConverter.js +4 -4
  99. package/platforms/Platform.d.ts +301 -310
  100. package/platforms/Platform.js +640 -663
  101. package/serialization/EntitySerializer.d.ts +26 -49
  102. package/serialization/EntitySerializer.js +218 -224
  103. package/serialization/EntityTransformer.d.ts +6 -10
  104. package/serialization/EntityTransformer.js +217 -219
  105. package/serialization/SerializationContext.d.ts +23 -27
  106. package/serialization/SerializationContext.js +105 -105
  107. package/types/ArrayType.d.ts +8 -8
  108. package/types/ArrayType.js +33 -33
  109. package/types/BigIntType.d.ts +10 -17
  110. package/types/BigIntType.js +37 -37
  111. package/types/BlobType.d.ts +3 -3
  112. package/types/BlobType.js +13 -13
  113. package/types/BooleanType.d.ts +4 -4
  114. package/types/BooleanType.js +12 -12
  115. package/types/CharacterType.d.ts +2 -2
  116. package/types/CharacterType.js +6 -6
  117. package/types/DateTimeType.d.ts +5 -5
  118. package/types/DateTimeType.js +15 -15
  119. package/types/DateType.d.ts +5 -5
  120. package/types/DateType.js +15 -15
  121. package/types/DecimalType.d.ts +7 -7
  122. package/types/DecimalType.js +26 -26
  123. package/types/DoubleType.d.ts +3 -3
  124. package/types/DoubleType.js +12 -12
  125. package/types/EnumArrayType.d.ts +5 -5
  126. package/types/EnumArrayType.js +24 -24
  127. package/types/EnumType.d.ts +3 -3
  128. package/types/EnumType.js +11 -11
  129. package/types/FloatType.d.ts +3 -3
  130. package/types/FloatType.js +9 -9
  131. package/types/IntegerType.d.ts +3 -3
  132. package/types/IntegerType.js +9 -9
  133. package/types/IntervalType.d.ts +4 -4
  134. package/types/IntervalType.js +12 -12
  135. package/types/JsonType.d.ts +8 -8
  136. package/types/JsonType.js +32 -32
  137. package/types/MediumIntType.d.ts +1 -1
  138. package/types/MediumIntType.js +3 -3
  139. package/types/SmallIntType.d.ts +3 -3
  140. package/types/SmallIntType.js +9 -9
  141. package/types/StringType.d.ts +4 -4
  142. package/types/StringType.js +12 -12
  143. package/types/TextType.d.ts +3 -3
  144. package/types/TextType.js +9 -9
  145. package/types/TimeType.d.ts +5 -5
  146. package/types/TimeType.js +17 -17
  147. package/types/TinyIntType.d.ts +3 -3
  148. package/types/TinyIntType.js +10 -10
  149. package/types/Type.d.ts +79 -83
  150. package/types/Type.js +82 -82
  151. package/types/Uint8ArrayType.d.ts +4 -4
  152. package/types/Uint8ArrayType.js +21 -21
  153. package/types/UnknownType.d.ts +4 -4
  154. package/types/UnknownType.js +12 -12
  155. package/types/UuidType.d.ts +5 -5
  156. package/types/UuidType.js +19 -19
  157. package/types/index.d.ts +49 -75
  158. package/types/index.js +26 -52
  159. package/typings.d.ts +737 -1250
  160. package/typings.js +231 -244
  161. package/unit-of-work/ChangeSet.d.ts +26 -26
  162. package/unit-of-work/ChangeSet.js +56 -56
  163. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  164. package/unit-of-work/ChangeSetComputer.js +170 -178
  165. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  166. package/unit-of-work/ChangeSetPersister.js +421 -442
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +88 -89
  169. package/unit-of-work/IdentityMap.d.ts +31 -31
  170. package/unit-of-work/IdentityMap.js +105 -105
  171. package/unit-of-work/UnitOfWork.d.ts +141 -181
  172. package/unit-of-work/UnitOfWork.js +1183 -1200
  173. package/utils/AbstractMigrator.d.ts +91 -111
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +34 -43
  176. package/utils/AbstractSchemaGenerator.js +122 -121
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +35 -34
  179. package/utils/Configuration.d.ts +808 -852
  180. package/utils/Configuration.js +344 -359
  181. package/utils/Cursor.d.ts +22 -40
  182. package/utils/Cursor.js +127 -135
  183. package/utils/DataloaderUtils.d.ts +43 -58
  184. package/utils/DataloaderUtils.js +198 -203
  185. package/utils/EntityComparator.d.ts +81 -98
  186. package/utils/EntityComparator.js +732 -828
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +51 -79
  190. package/utils/QueryHelper.js +361 -372
  191. package/utils/RawQueryFragment.d.ts +34 -50
  192. package/utils/RawQueryFragment.js +105 -107
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +53 -52
  195. package/utils/TransactionContext.d.ts +16 -16
  196. package/utils/TransactionContext.js +27 -27
  197. package/utils/TransactionManager.d.ts +58 -58
  198. package/utils/TransactionManager.js +197 -199
  199. package/utils/Utils.d.ts +145 -204
  200. package/utils/Utils.js +812 -812
  201. package/utils/clone.js +113 -104
  202. package/utils/env-vars.js +88 -90
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +181 -180
  205. package/utils/upsert-utils.d.ts +5 -20
  206. package/utils/upsert-utils.js +116 -114
package/utils/fs-utils.js CHANGED
@@ -5,188 +5,189 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  import { Utils } from './Utils.js';
6
6
  import { colors } from '../logging/colors.js';
7
7
  let globSync = (patterns, options) => {
8
- const files = nodeGlobSync(patterns, { ...options, withFileTypes: true });
9
- return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
8
+ const files = nodeGlobSync(patterns, { ...options, withFileTypes: true });
9
+ return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
10
10
  };
11
11
  export const fs = {
12
- async init() {
13
- const tinyGlobby = await import('tinyglobby').catch(() => null);
14
- if (tinyGlobby) {
15
- globSync = (patterns, options) => {
16
- patterns = Utils.asArray(patterns).map(p => p.replace(/\\/g, '/'));
17
- if (options?.cwd) {
18
- options = { ...options, cwd: options.cwd.replace(/\\/g, '/') };
19
- }
20
- return tinyGlobby.globSync(patterns, { ...options, expandDirectories: false });
21
- };
22
- }
23
- },
24
- pathExists(path) {
25
- if (/[*?[\]]/.test(path)) {
26
- return globSync(path).length > 0;
27
- }
28
- return existsSync(path);
29
- },
30
- ensureDir(path) {
31
- if (!existsSync(path)) {
32
- mkdirSync(path, { recursive: true });
33
- }
34
- },
35
- readJSONSync(path) {
36
- const file = readFileSync(path);
37
- return JSON.parse(file.toString());
38
- },
39
- glob(input, cwd) {
40
- const patterns = Array.isArray(input) ? input : [input];
41
- const positive = [];
42
- const negative = [];
43
- for (const p of patterns) {
44
- if (p.startsWith('!')) {
45
- negative.push(p.slice(1));
46
- } else {
47
- positive.push(p);
48
- }
49
- }
50
- const included = new Set(this.resolveGlob(positive, cwd));
51
- if (included.size > 0 && negative.length > 0) {
52
- const excluded = this.resolveGlob(negative, cwd);
53
- for (const file of excluded) {
54
- included.delete(file);
55
- }
56
- }
57
- return [...included];
58
- },
59
- resolveGlob(input, cwd) {
60
- if (Array.isArray(input)) {
61
- return input.flatMap(paths => this.resolveGlob(paths, cwd));
62
- }
63
- const hasGlobChars = /[*?[\]]/.test(input);
64
- if (!hasGlobChars) {
65
- try {
66
- const s = statSync(cwd ? this.normalizePath(cwd, input) : input);
67
- if (s.isDirectory()) {
68
- return globSync(join(input, '**'), { cwd });
69
- }
70
- } catch {
71
- // ignore
72
- }
73
- }
74
- return globSync(input, { cwd });
75
- },
76
- getPackageConfig(basePath = process.cwd()) {
77
- if (this.pathExists(`${basePath}/package.json`)) {
78
- try {
79
- const path = this.normalizePath(import.meta.resolve(`${basePath}/package.json`));
80
- return this.readJSONSync(path);
81
- } catch (e) {
12
+ async init() {
13
+ const tinyGlobby = await import('tinyglobby').catch(() => null);
14
+ if (tinyGlobby) {
15
+ globSync = (patterns, options) => {
16
+ patterns = Utils.asArray(patterns).map(p => p.replace(/\\/g, '/'));
17
+ if (options?.cwd) {
18
+ options = { ...options, cwd: options.cwd.replace(/\\/g, '/') };
19
+ }
20
+ return tinyGlobby.globSync(patterns, { ...options, expandDirectories: false });
21
+ };
22
+ }
23
+ },
24
+ pathExists(path) {
25
+ if (/[*?[\]]/.test(path)) {
26
+ return globSync(path).length > 0;
27
+ }
28
+ return existsSync(path);
29
+ },
30
+ ensureDir(path) {
31
+ if (!existsSync(path)) {
32
+ mkdirSync(path, { recursive: true });
33
+ }
34
+ },
35
+ readJSONSync(path) {
36
+ const file = readFileSync(path);
37
+ return JSON.parse(file.toString());
38
+ },
39
+ glob(input, cwd) {
40
+ const patterns = Array.isArray(input) ? input : [input];
41
+ const positive = [];
42
+ const negative = [];
43
+ for (const p of patterns) {
44
+ if (p.startsWith('!')) {
45
+ negative.push(p.slice(1));
46
+ }
47
+ else {
48
+ positive.push(p);
49
+ }
50
+ }
51
+ const included = new Set(this.resolveGlob(positive, cwd));
52
+ if (included.size > 0 && negative.length > 0) {
53
+ const excluded = this.resolveGlob(negative, cwd);
54
+ for (const file of excluded) {
55
+ included.delete(file);
56
+ }
57
+ }
58
+ return [...included];
59
+ },
60
+ resolveGlob(input, cwd) {
61
+ if (Array.isArray(input)) {
62
+ return input.flatMap(paths => this.resolveGlob(paths, cwd));
63
+ }
64
+ const hasGlobChars = /[*?[\]]/.test(input);
65
+ if (!hasGlobChars) {
66
+ try {
67
+ const s = statSync(cwd ? this.normalizePath(cwd, input) : input);
68
+ if (s.isDirectory()) {
69
+ return globSync(join(input, '**'), { cwd });
70
+ }
71
+ }
72
+ catch {
73
+ // ignore
74
+ }
75
+ }
76
+ return globSync(input, { cwd });
77
+ },
78
+ getPackageConfig(basePath = process.cwd()) {
79
+ if (this.pathExists(`${basePath}/package.json`)) {
80
+ try {
81
+ const path = this.normalizePath(import.meta.resolve(`${basePath}/package.json`));
82
+ return this.readJSONSync(path);
83
+ }
84
+ catch (e) {
85
+ /* v8 ignore next */
86
+ return {};
87
+ }
88
+ }
89
+ const parentFolder = realpathSync(`${basePath}/..`);
90
+ // we reached the root folder
91
+ if (basePath === parentFolder) {
92
+ return {};
93
+ }
94
+ return this.getPackageConfig(parentFolder);
95
+ },
96
+ getORMPackages() {
97
+ const pkg = this.getPackageConfig();
98
+ return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
99
+ },
100
+ getORMPackageVersion(name) {
101
+ try {
102
+ const path = import.meta.resolve(`${name}/package.json`);
103
+ const pkg = this.readJSONSync(fileURLToPath(path));
104
+ return pkg?.version;
105
+ }
106
+ catch (e) {
107
+ return undefined;
108
+ }
109
+ },
110
+ // inspired by https://github.com/facebook/docusaurus/pull/3386
111
+ checkPackageVersion() {
112
+ const coreVersion = Utils.getORMVersion();
113
+ if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
114
+ return;
115
+ }
116
+ const deps = this.getORMPackages();
117
+ const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
118
+ const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
119
+ for (const ormPackage of ormPackages) {
120
+ const version = this.getORMPackageVersion(ormPackage);
121
+ if (version != null && version !== coreVersion) {
122
+ throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
123
+ `All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
124
+ `Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
125
+ `Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
126
+ }
127
+ }
128
+ },
129
+ /**
130
+ * Resolves and normalizes a series of path parts relative to each preceding part.
131
+ * If any part is a `file:` URL, it is converted to a local path. If any part is an
132
+ * absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
133
+ * Trailing directory separators are removed, and all directory separators are converted
134
+ * to POSIX-style separators (`/`).
135
+ */
136
+ normalizePath(...parts) {
137
+ let start = 0;
138
+ for (let i = 0; i < parts.length; i++) {
139
+ const part = parts[i];
140
+ if (isAbsolute(part)) {
141
+ start = i;
142
+ }
143
+ else if (part.startsWith('file:')) {
144
+ start = i;
145
+ parts[i] = fileURLToPath(part);
146
+ }
147
+ }
148
+ if (start > 0) {
149
+ parts = parts.slice(start);
150
+ }
151
+ let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
152
+ path = normalize(path).replace(/\\/g, '/');
153
+ return /^[/.]|[a-zA-Z]:/.exec(path) || path.startsWith('!') ? path : './' + path;
154
+ },
155
+ /**
156
+ * Determines the relative path between two paths. If either path is a `file:` URL,
157
+ * it is converted to a local path.
158
+ */
159
+ relativePath(path, relativeTo) {
160
+ if (!path) {
161
+ return path;
162
+ }
163
+ path = this.normalizePath(path);
164
+ if (path.startsWith('.')) {
165
+ return path;
166
+ }
167
+ path = relative(this.normalizePath(relativeTo), path);
168
+ return this.normalizePath(path);
169
+ },
170
+ /**
171
+ * Computes the absolute path to for the given path relative to the provided base directory.
172
+ * If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
173
+ */
174
+ absolutePath(path, baseDir = process.cwd()) {
175
+ if (!path) {
176
+ return this.normalizePath(baseDir);
177
+ }
178
+ if (!isAbsolute(path) && !path.startsWith('file://')) {
179
+ path = baseDir + '/' + path;
180
+ }
181
+ return this.normalizePath(path);
182
+ },
183
+ async writeFile(path, data, options) {
184
+ await nodeWriteFile(path, data, options);
185
+ },
186
+ async dynamicImport(id) {
82
187
  /* v8 ignore next */
83
- return {};
84
- }
85
- }
86
- const parentFolder = realpathSync(`${basePath}/..`);
87
- // we reached the root folder
88
- if (basePath === parentFolder) {
89
- return {};
90
- }
91
- return this.getPackageConfig(parentFolder);
92
- },
93
- getORMPackages() {
94
- const pkg = this.getPackageConfig();
95
- return new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
96
- },
97
- getORMPackageVersion(name) {
98
- try {
99
- const path = import.meta.resolve(`${name}/package.json`);
100
- const pkg = this.readJSONSync(fileURLToPath(path));
101
- return pkg?.version;
102
- } catch (e) {
103
- return undefined;
104
- }
105
- },
106
- // inspired by https://github.com/facebook/docusaurus/pull/3386
107
- checkPackageVersion() {
108
- const coreVersion = Utils.getORMVersion();
109
- if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
110
- return;
111
- }
112
- const deps = this.getORMPackages();
113
- const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
114
- const ormPackages = [...deps].filter(
115
- d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)),
116
- );
117
- for (const ormPackage of ormPackages) {
118
- const version = this.getORMPackageVersion(ormPackage);
119
- if (version != null && version !== coreVersion) {
120
- throw new Error(
121
- `Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
122
- `All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
123
- `Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
124
- `Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`,
125
- );
126
- }
127
- }
128
- },
129
- /**
130
- * Resolves and normalizes a series of path parts relative to each preceding part.
131
- * If any part is a `file:` URL, it is converted to a local path. If any part is an
132
- * absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
133
- * Trailing directory separators are removed, and all directory separators are converted
134
- * to POSIX-style separators (`/`).
135
- */
136
- normalizePath(...parts) {
137
- let start = 0;
138
- for (let i = 0; i < parts.length; i++) {
139
- const part = parts[i];
140
- if (isAbsolute(part)) {
141
- start = i;
142
- } else if (part.startsWith('file:')) {
143
- start = i;
144
- parts[i] = fileURLToPath(part);
145
- }
146
- }
147
- if (start > 0) {
148
- parts = parts.slice(start);
149
- }
150
- let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
151
- path = normalize(path).replace(/\\/g, '/');
152
- return /^[/.]|[a-zA-Z]:/.exec(path) || path.startsWith('!') ? path : './' + path;
153
- },
154
- /**
155
- * Determines the relative path between two paths. If either path is a `file:` URL,
156
- * it is converted to a local path.
157
- */
158
- relativePath(path, relativeTo) {
159
- if (!path) {
160
- return path;
161
- }
162
- path = this.normalizePath(path);
163
- if (path.startsWith('.')) {
164
- return path;
165
- }
166
- path = relative(this.normalizePath(relativeTo), path);
167
- return this.normalizePath(path);
168
- },
169
- /**
170
- * Computes the absolute path to for the given path relative to the provided base directory.
171
- * If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
172
- */
173
- absolutePath(path, baseDir = process.cwd()) {
174
- if (!path) {
175
- return this.normalizePath(baseDir);
176
- }
177
- if (!isAbsolute(path) && !path.startsWith('file://')) {
178
- path = baseDir + '/' + path;
179
- }
180
- return this.normalizePath(path);
181
- },
182
- async writeFile(path, data, options) {
183
- await nodeWriteFile(path, data, options);
184
- },
185
- async dynamicImport(id) {
186
- /* v8 ignore next */
187
- const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
188
- const dynamicImportProvider = globalThis.dynamicImportProvider ?? (id => import(id));
189
- return dynamicImportProvider(specifier);
190
- },
188
+ const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
189
+ const dynamicImportProvider = globalThis.dynamicImportProvider ?? ((id) => import(id));
190
+ return dynamicImportProvider(specifier);
191
+ },
191
192
  };
192
193
  export * from '../cache/FileCacheAdapter.js';
@@ -2,26 +2,11 @@ import type { EntityData, EntityMetadata, FilterQuery } from '../typings.js';
2
2
  import type { UpsertOptions } from '../drivers/IDatabaseDriver.js';
3
3
  import { type Raw } from '../utils/RawQueryFragment.js';
4
4
  /** @internal */
5
- export declare function getOnConflictFields<T>(
6
- meta: EntityMetadata<T> | undefined,
7
- data: EntityData<T>,
8
- uniqueFields: (keyof T)[] | Raw,
9
- options: UpsertOptions<T>,
10
- ): (keyof T)[];
5
+ export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T>): (keyof T)[];
11
6
  /** @internal */
12
- export declare function getOnConflictReturningFields<T, P extends string>(
13
- meta: EntityMetadata<T> | undefined,
14
- data: EntityData<T>,
15
- uniqueFields: (keyof T)[] | Raw,
16
- options: UpsertOptions<T, P>,
17
- ): (keyof T)[] | '*';
7
+ export declare function getOnConflictReturningFields<T, P extends string>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | Raw, options: UpsertOptions<T, P>): (keyof T)[] | '*';
18
8
  /** @internal */
19
- export declare function getWhereCondition<T extends object>(
20
- meta: EntityMetadata<T>,
21
- onConflictFields: (keyof T)[] | Raw | undefined,
22
- data: EntityData<T>,
23
- where: FilterQuery<T>,
24
- ): {
25
- where: FilterQuery<T>;
26
- propIndex: number | false;
9
+ export declare function getWhereCondition<T extends object>(meta: EntityMetadata<T>, onConflictFields: (keyof T)[] | Raw | undefined, data: EntityData<T>, where: FilterQuery<T>): {
10
+ where: FilterQuery<T>;
11
+ propIndex: number | false;
27
12
  };
@@ -1,142 +1,144 @@
1
1
  import { isRaw } from '../utils/RawQueryFragment.js';
2
2
  import { Utils } from './Utils.js';
3
3
  function expandEmbeddedProperties(prop, key) {
4
- if (prop.object) {
5
- return [prop.name];
6
- }
7
- return Object.values(prop.embeddedProps).flatMap(p => {
8
- /* v8 ignore next */
9
- if (p.embeddable && !p.object) {
10
- return expandEmbeddedProperties(p);
4
+ if (prop.object) {
5
+ return [prop.name];
11
6
  }
12
- return [p.name];
13
- });
7
+ return Object.values(prop.embeddedProps).flatMap(p => {
8
+ /* v8 ignore next */
9
+ if (p.embeddable && !p.object) {
10
+ return expandEmbeddedProperties(p);
11
+ }
12
+ return [p.name];
13
+ });
14
14
  }
15
15
  /**
16
16
  * Expands dot paths and stars
17
17
  */
18
18
  function expandFields(meta, fields) {
19
- return fields.flatMap(f => {
20
- if (f === '*' && meta) {
21
- return meta.comparableProps.filter(p => !p.lazy && !p.embeddable).map(p => p.name);
22
- }
23
- if (f.includes('.')) {
24
- const [k, ...tmp] = f.split('.');
25
- const rest = tmp.join('.');
26
- const prop = meta?.properties[k];
27
- if (prop?.embeddable) {
28
- if (rest === '*') {
29
- return expandEmbeddedProperties(prop);
19
+ return fields.flatMap(f => {
20
+ if (f === '*' && meta) {
21
+ return meta.comparableProps.filter(p => !p.lazy && !p.embeddable).map(p => p.name);
30
22
  }
31
- return expandEmbeddedProperties(prop, rest);
32
- }
33
- }
34
- const prop = meta?.properties[f];
35
- if (prop?.embeddable) {
36
- return expandEmbeddedProperties(prop);
37
- }
38
- return [f];
39
- });
23
+ if (f.includes('.')) {
24
+ const [k, ...tmp] = f.split('.');
25
+ const rest = tmp.join('.');
26
+ const prop = meta?.properties[k];
27
+ if (prop?.embeddable) {
28
+ if (rest === '*') {
29
+ return expandEmbeddedProperties(prop);
30
+ }
31
+ return expandEmbeddedProperties(prop, rest);
32
+ }
33
+ }
34
+ const prop = meta?.properties[f];
35
+ if (prop?.embeddable) {
36
+ return expandEmbeddedProperties(prop);
37
+ }
38
+ return [f];
39
+ });
40
40
  }
41
41
  /** @internal */
42
42
  export function getOnConflictFields(meta, data, uniqueFields, options) {
43
- if (options.onConflictMergeFields) {
44
- const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
45
- return onConflictMergeFields.flatMap(f => {
46
- const prop = meta?.properties[f];
47
- /* v8 ignore next */
48
- if (prop?.embeddable && !prop.object) {
49
- return Object.values(prop.embeddedProps).map(p => p.name);
50
- }
51
- return f;
52
- });
53
- }
54
- const keys = Object.keys(data).flatMap(f => {
55
- if (!(Array.isArray(uniqueFields) && !uniqueFields.includes(f))) {
56
- return [];
43
+ if (options.onConflictMergeFields) {
44
+ const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
45
+ return onConflictMergeFields.flatMap(f => {
46
+ const prop = meta?.properties[f];
47
+ /* v8 ignore next */
48
+ if (prop?.embeddable && !prop.object) {
49
+ return Object.values(prop.embeddedProps).map(p => p.name);
50
+ }
51
+ return f;
52
+ });
57
53
  }
58
- const prop = meta?.properties[f];
59
- if (prop?.embeddable && !prop.object) {
60
- return expandEmbeddedProperties(prop);
54
+ const keys = Object.keys(data).flatMap(f => {
55
+ if (!(Array.isArray(uniqueFields) && !uniqueFields.includes(f))) {
56
+ return [];
57
+ }
58
+ const prop = meta?.properties[f];
59
+ if (prop?.embeddable && !prop.object) {
60
+ return expandEmbeddedProperties(prop);
61
+ }
62
+ return [f];
63
+ });
64
+ if (options.onConflictExcludeFields) {
65
+ const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
66
+ return keys.filter(f => !onConflictExcludeFields.includes(f));
61
67
  }
62
- return [f];
63
- });
64
- if (options.onConflictExcludeFields) {
65
- const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
66
- return keys.filter(f => !onConflictExcludeFields.includes(f));
67
- }
68
- return keys;
68
+ return keys;
69
69
  }
70
70
  /** @internal */
71
71
  export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
72
- /* v8 ignore next */
73
- if (!meta) {
74
- return '*';
75
- }
76
- const keys = meta.comparableProps
77
- .filter(p => {
78
- if (p.lazy || p.embeddable) {
79
- return false;
80
- }
81
- if (p.autoincrement) {
82
- return true;
83
- }
84
- return Array.isArray(uniqueFields) && !uniqueFields.includes(p.name);
72
+ /* v8 ignore next */
73
+ if (!meta) {
74
+ return '*';
75
+ }
76
+ const keys = meta.comparableProps
77
+ .filter(p => {
78
+ if (p.lazy || p.embeddable) {
79
+ return false;
80
+ }
81
+ if (p.autoincrement) {
82
+ return true;
83
+ }
84
+ return Array.isArray(uniqueFields) && !uniqueFields.includes(p.name);
85
85
  })
86
- .map(p => p.name);
87
- if (meta.versionProperty) {
88
- keys.push(meta.versionProperty);
89
- }
90
- if (options.onConflictAction === 'ignore') {
91
- return keys;
92
- }
93
- if (options.onConflictMergeFields) {
94
- const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
95
- return keys.filter(key => !onConflictMergeFields.includes(key));
96
- }
97
- if (options.onConflictExcludeFields) {
98
- const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
99
- return [...new Set(keys.concat(...onConflictExcludeFields))];
100
- }
101
- return keys.filter(key => !(key in data));
86
+ .map(p => p.name);
87
+ if (meta.versionProperty) {
88
+ keys.push(meta.versionProperty);
89
+ }
90
+ if (options.onConflictAction === 'ignore') {
91
+ return keys;
92
+ }
93
+ if (options.onConflictMergeFields) {
94
+ const onConflictMergeFields = expandFields(meta, options.onConflictMergeFields);
95
+ return keys.filter(key => !onConflictMergeFields.includes(key));
96
+ }
97
+ if (options.onConflictExcludeFields) {
98
+ const onConflictExcludeFields = expandFields(meta, options.onConflictExcludeFields);
99
+ return [...new Set(keys.concat(...onConflictExcludeFields))];
100
+ }
101
+ return keys.filter(key => !(key in data));
102
102
  }
103
103
  function getPropertyValue(obj, key) {
104
- if (!key.includes('.')) {
105
- return obj[key];
106
- }
107
- const parts = key.split('.');
108
- let curr = obj;
109
- for (let i = 0; i < parts.length - 1; i++) {
110
- curr[parts[i]] ??= {};
111
- curr = curr[parts[i]];
112
- }
113
- return curr[parts[parts.length - 1]];
104
+ if (!key.includes('.')) {
105
+ return obj[key];
106
+ }
107
+ const parts = key.split('.');
108
+ let curr = obj;
109
+ for (let i = 0; i < parts.length - 1; i++) {
110
+ curr[parts[i]] ??= {};
111
+ curr = curr[parts[i]];
112
+ }
113
+ return curr[parts[parts.length - 1]];
114
114
  }
115
115
  /** @internal */
116
116
  export function getWhereCondition(meta, onConflictFields, data, where) {
117
- const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
118
- const propIndex = !isRaw(unique) && unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
119
- if (onConflictFields || where == null) {
120
- if (propIndex !== false && propIndex >= 0) {
121
- let key = unique[propIndex];
122
- if (key.includes('.')) {
123
- const prop = meta.properties[key.substring(0, key.indexOf('.'))];
124
- if (prop) {
125
- key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
117
+ const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
118
+ const propIndex = !isRaw(unique) &&
119
+ unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
120
+ if (onConflictFields || where == null) {
121
+ if (propIndex !== false && propIndex >= 0) {
122
+ let key = unique[propIndex];
123
+ if (key.includes('.')) {
124
+ const prop = meta.properties[key.substring(0, key.indexOf('.'))];
125
+ if (prop) {
126
+ key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
127
+ }
128
+ }
129
+ where = { [key]: getPropertyValue(data, unique[propIndex]) };
126
130
  }
127
- }
128
- where = { [key]: getPropertyValue(data, unique[propIndex]) };
129
- } else if (meta.uniques.length > 0) {
130
- for (const u of meta.uniques) {
131
- if (Utils.asArray(u.properties).every(p => data[p] != null)) {
132
- where = Utils.asArray(u.properties).reduce((o, key) => {
133
- o[key] = data[key];
134
- return o;
135
- }, {});
136
- break;
131
+ else if (meta.uniques.length > 0) {
132
+ for (const u of meta.uniques) {
133
+ if (Utils.asArray(u.properties).every(p => data[p] != null)) {
134
+ where = Utils.asArray(u.properties).reduce((o, key) => {
135
+ o[key] = data[key];
136
+ return o;
137
+ }, {});
138
+ break;
139
+ }
140
+ }
137
141
  }
138
- }
139
142
  }
140
- }
141
- return { where, propIndex };
143
+ return { where, propIndex };
142
144
  }