@mikro-orm/reflection 7.0.0-dev.1 → 7.0.0-dev.3

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.
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TsMorphMetadataProvider = void 0;
4
- const ts_morph_1 = require("ts-morph");
5
- const core_1 = require("@mikro-orm/core");
6
- class TsMorphMetadataProvider extends core_1.MetadataProvider {
1
+ import { ModuleKind, Project } from 'ts-morph';
2
+ import { MetadataError, MetadataProvider, MetadataStorage, ReferenceKind, Utils, ConfigurationLoader, } from '@mikro-orm/core';
3
+ export class TsMorphMetadataProvider extends MetadataProvider {
7
4
  project;
8
5
  sources;
9
6
  useCache() {
@@ -33,11 +30,11 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
33
30
  }
34
31
  }
35
32
  extractType(prop) {
36
- if (core_1.Utils.isString(prop.entity)) {
33
+ if (Utils.isString(prop.entity)) {
37
34
  return prop.entity;
38
35
  }
39
36
  if (prop.entity) {
40
- return core_1.Utils.className(prop.entity());
37
+ return Utils.className(prop.entity());
41
38
  }
42
39
  return prop.type;
43
40
  }
@@ -78,9 +75,9 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
78
75
  readTypeFromSource(meta, prop) {
79
76
  const source = this.getExistingSourceFile(meta.path);
80
77
  const cls = source.getClass(meta.className);
81
- /* istanbul ignore next */
78
+ /* v8 ignore next 3 */
82
79
  if (!cls) {
83
- throw new core_1.MetadataError(`Source class for entity ${meta.className} not found. Verify you have 'compilerOptions.declaration' enabled in your 'tsconfig.json'. If you are using webpack, see https://bit.ly/35pPDNn`);
80
+ throw new MetadataError(`Source class for entity ${meta.className} not found. Verify you have 'compilerOptions.declaration' enabled in your 'tsconfig.json'. If you are using webpack, see https://bit.ly/35pPDNn`);
84
81
  }
85
82
  const properties = cls.getInstanceProperties();
86
83
  const property = properties.find(v => v.getName() === prop.name);
@@ -94,7 +91,7 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
94
91
  }
95
92
  if (tsType.isArray()) {
96
93
  prop.array = true;
97
- /* istanbul ignore else */
94
+ /* v8 ignore next 3 */
98
95
  if (tsType.getArrayElementType().isEnum()) {
99
96
  prop.items = tsType.getArrayElementType().getUnionTypes().map(t => t.getLiteralValueOrThrow());
100
97
  }
@@ -112,7 +109,7 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
112
109
  .replace(/\[]$/, '') // remove array suffix
113
110
  .replace(/\((.*)\)/, '$1'); // unwrap union types
114
111
  // keep the array suffix in the type, it is needed in few places in discovery and comparator (`prop.array` is used only for enum arrays)
115
- if (prop.array && !type.includes(' | ') && prop.kind === core_1.ReferenceKind.SCALAR) {
112
+ if (prop.array && !type.includes(' | ') && prop.kind === ReferenceKind.SCALAR) {
116
113
  type += '[]';
117
114
  }
118
115
  return { type, optional };
@@ -125,13 +122,13 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
125
122
  const outDir = this.project.getCompilerOptions().outDir;
126
123
  let path = tsPath;
127
124
  if (outDir != null) {
128
- const outDirRelative = core_1.Utils.relativePath(outDir, baseDir);
125
+ const outDirRelative = Utils.relativePath(outDir, baseDir);
129
126
  path = path.replace(new RegExp(`^${outDirRelative}`), '');
130
127
  }
131
- path = core_1.Utils.stripRelativePath(path);
128
+ path = Utils.stripRelativePath(path);
132
129
  const source = this.sources.find(s => s.getFilePath().endsWith(path));
133
130
  if (!source && validate) {
134
- throw new core_1.MetadataError(`Source file '${tsPath}' not found. Check your 'entitiesTs' option and verify you have 'compilerOptions.declaration' enabled in your 'tsconfig.json'. If you are using webpack, see https://bit.ly/35pPDNn`);
131
+ throw new MetadataError(`Source file '${tsPath}' not found. Check your 'entitiesTs' option and verify you have 'compilerOptions.declaration' enabled in your 'tsconfig.json'. If you are using webpack, see https://bit.ly/35pPDNn`);
135
132
  }
136
133
  return source;
137
134
  }
@@ -154,24 +151,24 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
154
151
  }
155
152
  }
156
153
  initProject() {
157
- const settings = core_1.ConfigurationLoader.getSettings();
158
- /* istanbul ignore next */
154
+ const settings = ConfigurationLoader.getSettings();
155
+ /* v8 ignore next */
159
156
  const tsConfigFilePath = this.config.get('discovery').tsConfigPath ?? settings.tsConfigPath ?? './tsconfig.json';
160
157
  try {
161
- this.project = new ts_morph_1.Project({
162
- tsConfigFilePath: core_1.Utils.normalizePath(process.cwd(), tsConfigFilePath),
158
+ this.project = new Project({
159
+ tsConfigFilePath: Utils.normalizePath(process.cwd(), tsConfigFilePath),
163
160
  compilerOptions: {
164
161
  strictNullChecks: true,
165
- module: ts_morph_1.ModuleKind.Node16,
162
+ module: ModuleKind.Node16,
166
163
  },
167
164
  });
168
165
  }
169
166
  catch (e) {
170
167
  this.config.getLogger().warn('discovery', e.message);
171
- this.project = new ts_morph_1.Project({
168
+ this.project = new Project({
172
169
  compilerOptions: {
173
170
  strictNullChecks: true,
174
- module: ts_morph_1.ModuleKind.Node16,
171
+ module: ModuleKind.Node16,
175
172
  },
176
173
  });
177
174
  }
@@ -182,11 +179,11 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
182
179
  }
183
180
  this.sources = [];
184
181
  // All entity files are first required during the discovery, before we reach here, so it is safe to get the parts from the global
185
- // metadata storage. We know the path thanks to the decorators being executed. In case we are running via ts-node, the extension
182
+ // metadata storage. We know the path thanks to the decorators being executed. In case we are running the TS code, the extension
186
183
  // will be already `.ts`, so no change is needed. `.js` files will get renamed to `.d.ts` files as they will be used as a source for
187
184
  // the ts-morph reflection.
188
- for (const meta of core_1.Utils.values(core_1.MetadataStorage.getMetadata())) {
189
- /* istanbul ignore next */
185
+ for (const meta of Utils.values(MetadataStorage.getMetadata())) {
186
+ /* v8 ignore next 3 */
190
187
  const path = meta.path.match(/\.[jt]s$/)
191
188
  ? meta.path.replace(/\.js$/, '.d.ts')
192
189
  : `${meta.path}.d.ts`; // when entities are bundled, their paths are just their names
@@ -197,4 +194,3 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
197
194
  }
198
195
  }
199
196
  }
200
- exports.TsMorphMetadataProvider = TsMorphMetadataProvider;
package/index.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * @packageDocumentation
3
3
  * @module reflection
4
4
  */
5
- export * from './TsMorphMetadataProvider';
5
+ export * from './TsMorphMetadataProvider.js';
package/index.js CHANGED
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
1
  /**
18
2
  * @packageDocumentation
19
3
  * @module reflection
20
4
  */
21
- __exportStar(require("./TsMorphMetadataProvider"), exports);
5
+ export * from './TsMorphMetadataProvider.js';
package/package.json CHANGED
@@ -1,19 +1,11 @@
1
1
  {
2
2
  "name": "@mikro-orm/reflection",
3
- "version": "7.0.0-dev.1",
3
+ "type": "module",
4
+ "version": "7.0.0-dev.3",
4
5
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
- "main": "index.js",
6
- "module": "index.mjs",
7
- "typings": "index.d.ts",
8
6
  "exports": {
9
7
  "./package.json": "./package.json",
10
- ".": {
11
- "import": {
12
- "types": "./index.d.ts",
13
- "default": "./index.mjs"
14
- },
15
- "require": "./index.js"
16
- }
8
+ ".": "./index.js"
17
9
  },
18
10
  "repository": {
19
11
  "type": "git",
@@ -49,7 +41,7 @@
49
41
  "node": ">= 22.11.0"
50
42
  },
51
43
  "scripts": {
52
- "build": "yarn clean && yarn compile && yarn copy && yarn run -T gen-esm-wrapper index.js index.mjs",
44
+ "build": "yarn clean && yarn compile && yarn copy",
53
45
  "clean": "yarn run -T rimraf ./dist",
54
46
  "compile": "yarn run -T tsc -p tsconfig.build.json",
55
47
  "copy": "node ../../scripts/copy.mjs"
@@ -65,6 +57,6 @@
65
57
  "@mikro-orm/core": "^6.4.5"
66
58
  },
67
59
  "peerDependencies": {
68
- "@mikro-orm/core": "7.0.0-dev.1"
60
+ "@mikro-orm/core": "7.0.0-dev.3"
69
61
  }
70
62
  }
package/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- import mod from "./index.js";
2
-
3
- export default mod;
4
- export const TsMorphMetadataProvider = mod.TsMorphMetadataProvider;