@mikro-orm/cli 7.1.0-dev.9 → 7.1.0
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.
- package/CLIHelper.js +12 -2
- package/README.md +2 -1
- package/cli.js +0 -0
- package/commands/DiscoveryExportCommand.js +24 -16
- package/commands/MigrationCommandFactory.d.ts +1 -0
- package/commands/MigrationCommandFactory.js +9 -4
- package/package.json +3 -3
package/CLIHelper.js
CHANGED
|
@@ -24,7 +24,6 @@ export class CLIHelper {
|
|
|
24
24
|
}
|
|
25
25
|
contextName ??= process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default';
|
|
26
26
|
const env = await this.loadEnvironmentVars();
|
|
27
|
-
await loadOptionalDependencies(options);
|
|
28
27
|
// oxfmt-ignore
|
|
29
28
|
const configFinder = (cfg) => {
|
|
30
29
|
return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : contextName === 'default');
|
|
@@ -35,7 +34,9 @@ export class CLIHelper {
|
|
|
35
34
|
const result = await this.getConfigFile(paths);
|
|
36
35
|
if (!result[0]) {
|
|
37
36
|
if (Utils.hasObjectKeys(env)) {
|
|
38
|
-
|
|
37
|
+
const merged = Utils.mergeConfig({ contextName }, options.preferEnvVars ? options : env, options.preferEnvVars ? env : options);
|
|
38
|
+
await loadOptionalDependencies(merged);
|
|
39
|
+
return new Configuration(merged);
|
|
39
40
|
}
|
|
40
41
|
throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
|
|
41
42
|
}
|
|
@@ -209,6 +210,15 @@ export class CLIHelper {
|
|
|
209
210
|
case 'postgresql':
|
|
210
211
|
ret.driver ??= await import('@mikro-orm/postgresql').then(m => m.PostgreSqlDriver);
|
|
211
212
|
break;
|
|
213
|
+
case 'pglite': {
|
|
214
|
+
// Variable specifier (instead of a literal) keeps `@electric-sql/pglite`'s
|
|
215
|
+
// d.ts — which references DOM/Emscripten ambient globals not in our TS
|
|
216
|
+
// lib — out of the CLI's compile graph. Safe here: the CLI is a Node
|
|
217
|
+
// binary, not bundled into end-user apps.
|
|
218
|
+
const name = '@mikro-orm/pglite';
|
|
219
|
+
ret.driver ??= (await import(name)).PgliteDriver;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
212
222
|
case 'sqlite':
|
|
213
223
|
ret.driver ??= await import('@mikro-orm/sqlite').then(m => m.SqliteDriver);
|
|
214
224
|
break;
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL (including CockroachDB and PGlite), SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
@@ -19,6 +19,7 @@ Install a driver package for your database:
|
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install @mikro-orm/postgresql # PostgreSQL
|
|
22
|
+
npm install @mikro-orm/pglite # PGlite (embedded PostgreSQL in WASM)
|
|
22
23
|
npm install @mikro-orm/mysql # MySQL
|
|
23
24
|
npm install @mikro-orm/mariadb # MariaDB
|
|
24
25
|
npm install @mikro-orm/sqlite # SQLite
|
package/cli.js
CHANGED
|
File without changes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { basename, dirname, join,
|
|
2
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
3
3
|
import { colors, EntitySchema, MetadataStorage } from '@mikro-orm/core';
|
|
4
4
|
import { fs } from '@mikro-orm/core/fs-utils';
|
|
5
5
|
import { CLIHelper } from '../CLIHelper.js';
|
|
6
6
|
const driverPackageMap = {
|
|
7
7
|
PostgreSqlDriver: '@mikro-orm/postgresql',
|
|
8
|
+
PgliteDriver: '@mikro-orm/pglite',
|
|
8
9
|
MySqlDriver: '@mikro-orm/mysql',
|
|
9
10
|
MariaDbDriver: '@mikro-orm/mariadb',
|
|
10
11
|
SqliteDriver: '@mikro-orm/sqlite',
|
|
@@ -176,10 +177,8 @@ export class DiscoveryExportCommand {
|
|
|
176
177
|
}
|
|
177
178
|
// Generate import lines
|
|
178
179
|
for (const [filePath, items] of byFile) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
rel = './' + rel;
|
|
182
|
-
}
|
|
180
|
+
// `fs.relativePath` ensures POSIX separators (node:path.relative returns backslashes on Windows)
|
|
181
|
+
let rel = fs.relativePath(filePath, outDir);
|
|
183
182
|
// Remove .ts extension and optionally add .js for ESM
|
|
184
183
|
rel = rel.replace(/\.[cm]?[jt]s$/, '');
|
|
185
184
|
if (esm) {
|
|
@@ -195,11 +194,12 @@ export class DiscoveryExportCommand {
|
|
|
195
194
|
lines.push(`import { ${names} } from '${rel}';`);
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
|
-
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
// Bring in the driver's `EntityManager` class as a runtime value, not just
|
|
198
|
+
// a type — DI containers (NestJS, etc.) read it via `design:paramtypes`
|
|
199
|
+
// reflect-metadata, so the consumer needs the actual class reference, not
|
|
200
|
+
// an erased type alias. Aliasing keeps the local name free for our own
|
|
201
|
+
// `EntityManager` re-export.
|
|
202
|
+
lines.push(`import { EntityManager as DriverEntityManager } from '${driverPackage}';`);
|
|
203
203
|
lines.push('');
|
|
204
204
|
// entities array
|
|
205
205
|
lines.push('export const entities = [');
|
|
@@ -207,12 +207,20 @@ export class DiscoveryExportCommand {
|
|
|
207
207
|
lines.push(` ${item.exportName},`);
|
|
208
208
|
}
|
|
209
209
|
lines.push('] as const;');
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
lines.push('');
|
|
211
|
+
// The entity tuple type — usable in `MikroORM<Driver, EM, Database>`,
|
|
212
|
+
// for typed repository helpers, and anywhere entity classes/schemas are
|
|
213
|
+
// accepted as a tuple.
|
|
214
|
+
lines.push('export type Database = typeof entities;');
|
|
215
|
+
lines.push('');
|
|
216
|
+
// Typed `EntityManager` for DI / NestJS contexts. Declaration merging
|
|
217
|
+
// lets us export the same name twice: the `type` carries the entity
|
|
218
|
+
// tuple via the `'~entities'` graft (so `em.getKysely(opts)` keeps full
|
|
219
|
+
// inference), and the `const` is the driver's actual EM class — so
|
|
220
|
+
// `constructor(em: EntityManager) {}` resolves through Nest's container
|
|
221
|
+
// just like importing the class straight from the driver package.
|
|
222
|
+
lines.push("export type EntityManager = DriverEntityManager & { '~entities': Database };");
|
|
223
|
+
lines.push('export const EntityManager = DriverEntityManager;');
|
|
216
224
|
lines.push('');
|
|
217
225
|
return lines.join('\n');
|
|
218
226
|
}
|
|
@@ -62,6 +62,11 @@ export class MigrationCommandFactory {
|
|
|
62
62
|
type: 'string',
|
|
63
63
|
desc: 'Migrate only specified versions',
|
|
64
64
|
});
|
|
65
|
+
args.option('s', {
|
|
66
|
+
alias: 'schema',
|
|
67
|
+
type: 'string',
|
|
68
|
+
desc: 'Target schema to run the migration against (PostgreSQL, MySQL, Oracle)',
|
|
69
|
+
});
|
|
65
70
|
return args;
|
|
66
71
|
}
|
|
67
72
|
static configureCreateCommand(args) {
|
|
@@ -215,11 +220,11 @@ export class MigrationCommandFactory {
|
|
|
215
220
|
CLIHelper.dump(colors.green(`${ret.fileName} successfully created (rollup)`));
|
|
216
221
|
}
|
|
217
222
|
static getUpDownOptions(flags) {
|
|
218
|
-
|
|
219
|
-
return { migrations: flags.only.split(/[, ]+/) };
|
|
220
|
-
}
|
|
221
|
-
const ret = {};
|
|
223
|
+
const ret = !flags.to && !flags.from && flags.only ? { migrations: flags.only.split(/[, ]+/) } : {};
|
|
222
224
|
['from', 'to'].filter(k => flags[k]).forEach(k => (ret[k] = flags[k] === '0' ? 0 : flags[k]));
|
|
225
|
+
if (flags.schema) {
|
|
226
|
+
ret.schema = flags.schema;
|
|
227
|
+
}
|
|
223
228
|
return ret;
|
|
224
229
|
}
|
|
225
230
|
static getUpDownSuccessMessage(method, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
|
-
"version": "7.1.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"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
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"copy": "node ../../scripts/copy.mjs"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/core": "7.1.0
|
|
54
|
-
"mikro-orm": "7.1.0
|
|
53
|
+
"@mikro-orm/core": "7.1.0",
|
|
54
|
+
"mikro-orm": "7.1.0",
|
|
55
55
|
"yargs": "17.7.2"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|