@mikro-orm/seeder 7.0.0-dev.1 → 7.0.0-dev.100

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/Factory.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Factory = void 0;
4
- class Factory {
1
+ export class Factory {
5
2
  em;
6
3
  eachFunction;
7
4
  constructor(em) {
@@ -72,4 +69,3 @@ class Factory {
72
69
  return this;
73
70
  }
74
71
  }
75
- exports.Factory = Factory;
package/README.md CHANGED
@@ -11,7 +11,6 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
11
11
  [![Chat on discord](https://img.shields.io/discord/1214904142443839538?label=discord&color=blue)](https://discord.gg/w8bjxFHS7X)
12
12
  [![Downloads](https://img.shields.io/npm/dm/@mikro-orm/core.svg)](https://www.npmjs.com/package/@mikro-orm/core)
13
13
  [![Coverage Status](https://img.shields.io/coveralls/mikro-orm/mikro-orm.svg)](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
14
- [![Maintainability](https://api.codeclimate.com/v1/badges/27999651d3adc47cfa40/maintainability)](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
15
14
  [![Build Status](https://github.com/mikro-orm/mikro-orm/workflows/tests/badge.svg?branch=master)](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
16
15
 
17
16
  ## 🤔 Unit of What?
@@ -141,7 +140,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
141
140
  - [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
142
141
  - [Filters](https://mikro-orm.io/docs/filters)
143
142
  - [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
144
- - [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate)
143
+ - [Populating relations](https://mikro-orm.io/docs/populating-relations)
145
144
  - [Property Validation](https://mikro-orm.io/docs/property-validation)
146
145
  - [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
147
146
  - [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
@@ -382,6 +381,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
382
381
 
383
382
  Please ⭐️ this repository if this project helped you!
384
383
 
384
+ > If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
385
+
385
386
  ## 📝 License
386
387
 
387
388
  Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
package/SeedManager.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Constructor, type EntityManager, type ISeedManager, type MikroORM } from '@mikro-orm/core';
2
- import type { Seeder } from './Seeder';
2
+ import type { Seeder } from './Seeder.js';
3
3
  export declare class SeedManager implements ISeedManager {
4
4
  private readonly em;
5
5
  private readonly config;
@@ -7,12 +7,20 @@ export declare class SeedManager implements ISeedManager {
7
7
  private readonly absolutePath;
8
8
  constructor(em: EntityManager);
9
9
  static register(orm: MikroORM): void;
10
+ /**
11
+ * Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
12
+ * If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
13
+ * used for the TS variant (`pathTs` option).
14
+ *
15
+ * If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
16
+ * break existing projects, only help with the new ones.
17
+ */
18
+ private detectSourceFolder;
10
19
  seed(...classNames: Constructor<Seeder>[]): Promise<void>;
11
20
  /**
12
21
  * @internal
13
22
  */
14
23
  seedString(...classNames: string[]): Promise<void>;
15
- createSeeder(className: string): Promise<string>;
16
- private ensureSeedersDirExists;
24
+ create(className: string): Promise<string>;
17
25
  private generate;
18
26
  }
package/SeedManager.js CHANGED
@@ -1,13 +1,8 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SeedManager = void 0;
7
- const core_1 = require("@mikro-orm/core");
8
- const fs_extra_1 = require("fs-extra");
9
- const globby_1 = __importDefault(require("globby"));
10
- class SeedManager {
1
+ import { Utils, } from '@mikro-orm/core';
2
+ import { fs } from '@mikro-orm/core/fs-utils';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { glob } from 'tinyglobby';
5
+ export class SeedManager {
11
6
  em;
12
7
  config;
13
8
  options;
@@ -18,13 +13,40 @@ class SeedManager {
18
13
  this.options = this.config.get('seeder');
19
14
  this.em = this.em.fork();
20
15
  this.config.set('persistOnCreate', true);
21
- /* istanbul ignore next */
22
- const key = (this.config.get('preferTs', core_1.Utils.detectTsNode()) && this.options.pathTs) ? 'pathTs' : 'path';
23
- this.absolutePath = core_1.Utils.absolutePath(this.options[key], this.config.get('baseDir'));
16
+ this.detectSourceFolder();
17
+ /* v8 ignore next */
18
+ const key = (this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs) ? 'pathTs' : 'path';
19
+ this.absolutePath = Utils.absolutePath(this.options[key], this.config.get('baseDir'));
24
20
  }
25
21
  static register(orm) {
26
22
  orm.config.registerExtension('@mikro-orm/seeder', () => new SeedManager(orm.em));
27
23
  }
24
+ /**
25
+ * Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
26
+ * If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
27
+ * used for the TS variant (`pathTs` option).
28
+ *
29
+ * If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
30
+ * break existing projects, only help with the new ones.
31
+ */
32
+ detectSourceFolder() {
33
+ const baseDir = this.config.get('baseDir');
34
+ const defaultPath = './seeders';
35
+ if (!fs.pathExists(baseDir + '/src')) {
36
+ this.options.path ??= defaultPath;
37
+ return;
38
+ }
39
+ const exists = fs.pathExists(`${baseDir}/${defaultPath}`);
40
+ const distDir = fs.pathExists(baseDir + '/dist');
41
+ const buildDir = fs.pathExists(baseDir + '/build');
42
+ // if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
43
+ const path = distDir ? './dist' : (buildDir ? './build' : './src');
44
+ // only if the user did not provide any values and if the default path does not exist
45
+ if (!this.options.path && !this.options.pathTs && !exists) {
46
+ this.options.path = `${path}/seeders`;
47
+ this.options.pathTs = './src/seeders';
48
+ }
49
+ }
28
50
  async seed(...classNames) {
29
51
  for (const SeederClass of classNames) {
30
52
  const seeder = new SeederClass();
@@ -38,10 +60,10 @@ class SeedManager {
38
60
  */
39
61
  async seedString(...classNames) {
40
62
  const path = `${this.absolutePath}/${this.options.glob}`;
41
- const files = await (0, globby_1.default)(path);
63
+ const files = await glob(path);
42
64
  const classMap = new Map();
43
65
  for (const path of files) {
44
- const exports = await core_1.Utils.dynamicImport(path);
66
+ const exports = await Utils.dynamicImport(path);
45
67
  for (const name of Object.keys(exports)) {
46
68
  classMap.set(name, exports[name]);
47
69
  }
@@ -49,18 +71,15 @@ class SeedManager {
49
71
  for (const className of classNames) {
50
72
  const seederClass = classMap.get(className);
51
73
  if (!seederClass) {
52
- throw new Error(`Seeder class ${className} not found in ${core_1.Utils.relativePath(path, process.cwd())}`);
74
+ throw new Error(`Seeder class ${className} not found in ${Utils.relativePath(path, process.cwd())}`);
53
75
  }
54
76
  await this.seed(seederClass);
55
77
  }
56
78
  }
57
- async createSeeder(className) {
58
- await this.ensureSeedersDirExists();
79
+ async create(className) {
80
+ fs.ensureDir(this.absolutePath);
59
81
  return this.generate(className);
60
82
  }
61
- async ensureSeedersDirExists() {
62
- await (0, fs_extra_1.ensureDir)(this.absolutePath);
63
- }
64
83
  async generate(className) {
65
84
  const fileName = `${this.options.fileName(className)}.${this.options.emit}`;
66
85
  const filePath = `${this.absolutePath}/${fileName}`;
@@ -81,8 +100,7 @@ class SeedManager {
81
100
  ret += `}\n`;
82
101
  ret += `exports.${className} = ${className};\n`;
83
102
  }
84
- await (0, fs_extra_1.writeFile)(filePath, ret, { flush: true });
103
+ await writeFile(filePath, ret, { flush: true });
85
104
  return filePath;
86
105
  }
87
106
  }
88
- exports.SeedManager = SeedManager;
package/Seeder.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Seeder = void 0;
4
- class Seeder {
1
+ export class Seeder {
5
2
  async call(em, seeders, context = {}) {
6
3
  for (const Seeder of seeders) {
7
4
  const fork = em.fork();
@@ -11,4 +8,3 @@ class Seeder {
11
8
  }
12
9
  }
13
10
  }
14
- exports.Seeder = Seeder;
package/index.d.ts CHANGED
@@ -2,6 +2,6 @@
2
2
  * @packageDocumentation
3
3
  * @module seeder
4
4
  */
5
- export * from './Seeder';
6
- export * from './Factory';
7
- export * from './SeedManager';
5
+ export * from './Seeder.js';
6
+ export * from './Factory.js';
7
+ export * from './SeedManager.js';
package/index.js CHANGED
@@ -1,24 +1,7 @@
1
- "use strict";
2
1
  /**
3
2
  * @packageDocumentation
4
3
  * @module seeder
5
4
  */
6
- /* istanbul ignore file */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- __exportStar(require("./Seeder"), exports);
23
- __exportStar(require("./Factory"), exports);
24
- __exportStar(require("./SeedManager"), exports);
5
+ export * from './Seeder.js';
6
+ export * from './Factory.js';
7
+ export * from './SeedManager.js';
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@mikro-orm/seeder",
3
- "version": "7.0.0-dev.1",
3
+ "type": "module",
4
+ "version": "7.0.0-dev.100",
4
5
  "description": "Seeder package for MikroORM.",
5
- "main": "index.js",
6
- "typings": "index.d.ts",
6
+ "exports": {
7
+ "./package.json": "./package.json",
8
+ ".": "./index.js"
9
+ },
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
@@ -36,7 +39,7 @@
36
39
  },
37
40
  "homepage": "https://mikro-orm.io",
38
41
  "engines": {
39
- "node": ">= 22.11.0"
42
+ "node": ">= 22.17.0"
40
43
  },
41
44
  "scripts": {
42
45
  "build": "yarn clean && yarn compile && yarn copy",
@@ -48,13 +51,12 @@
48
51
  "access": "public"
49
52
  },
50
53
  "dependencies": {
51
- "fs-extra": "11.3.0",
52
- "globby": "11.1.0"
54
+ "tinyglobby": "0.2.15"
53
55
  },
54
56
  "devDependencies": {
55
- "@mikro-orm/core": "^6.4.5"
57
+ "@mikro-orm/core": "^6.6.2"
56
58
  },
57
59
  "peerDependencies": {
58
- "@mikro-orm/core": "7.0.0-dev.1"
60
+ "@mikro-orm/core": "7.0.0-dev.100"
59
61
  }
60
62
  }