@dauflo/nest-fixtures 1.2.0 → 1.4.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.
|
@@ -4,6 +4,10 @@ on:
|
|
|
4
4
|
release:
|
|
5
5
|
types: [published]
|
|
6
6
|
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
7
11
|
jobs:
|
|
8
12
|
release:
|
|
9
13
|
name: Release
|
|
@@ -19,9 +23,9 @@ jobs:
|
|
|
19
23
|
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
|
|
20
24
|
|
|
21
25
|
- name: Setup node
|
|
22
|
-
uses: actions/setup-node@
|
|
26
|
+
uses: actions/setup-node@v4
|
|
23
27
|
with:
|
|
24
|
-
node-version: '
|
|
28
|
+
node-version: '24.x'
|
|
25
29
|
registry-url: 'https://registry.npmjs.org'
|
|
26
30
|
|
|
27
31
|
- name: Bumd package version
|
|
@@ -34,6 +38,4 @@ jobs:
|
|
|
34
38
|
run: npm run build
|
|
35
39
|
|
|
36
40
|
- name: Publish package
|
|
37
|
-
run: npm publish
|
|
38
|
-
env:
|
|
39
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
41
|
+
run: npm publish
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Connection } from 'mongoose';
|
|
2
2
|
import { CommandRunner } from 'nest-commander';
|
|
3
3
|
import { Fixtures } from './fixtures';
|
|
4
|
-
|
|
4
|
+
type FixturesObject = {
|
|
5
5
|
[key: string]: Fixtures;
|
|
6
6
|
};
|
|
7
7
|
export declare class FixturesCommand extends CommandRunner {
|
package/dist/fixtures.command.js
CHANGED
|
@@ -66,6 +66,7 @@ let FixturesCommand = class FixturesCommand extends nest_commander_1.CommandRunn
|
|
|
66
66
|
console.log('Database purging done');
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
exports.FixturesCommand = FixturesCommand;
|
|
69
70
|
__decorate([
|
|
70
71
|
(0, nest_commander_1.Option)({
|
|
71
72
|
flags: '--delete',
|
|
@@ -75,10 +76,9 @@ __decorate([
|
|
|
75
76
|
__metadata("design:paramtypes", []),
|
|
76
77
|
__metadata("design:returntype", void 0)
|
|
77
78
|
], FixturesCommand.prototype, "purgeDatabase", null);
|
|
78
|
-
FixturesCommand = __decorate([
|
|
79
|
+
exports.FixturesCommand = FixturesCommand = __decorate([
|
|
79
80
|
(0, nest_commander_1.Command)({ name: 'fixtures', description: 'load fixtures into the database' }),
|
|
80
81
|
__param(0, (0, common_1.Inject)('FIXTURES')),
|
|
81
82
|
__param(1, (0, mongoose_1.InjectConnection)()),
|
|
82
83
|
__metadata("design:paramtypes", [Object, mongoose_2.Connection])
|
|
83
84
|
], FixturesCommand);
|
|
84
|
-
exports.FixturesCommand = FixturesCommand;
|
package/dist/fixtures.js
CHANGED
|
@@ -34,10 +34,10 @@ let ReferenceRepository = class ReferenceRepository {
|
|
|
34
34
|
return this.reference[key];
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
ReferenceRepository =
|
|
37
|
+
exports.ReferenceRepository = ReferenceRepository;
|
|
38
|
+
exports.ReferenceRepository = ReferenceRepository = __decorate([
|
|
38
39
|
(0, common_1.Injectable)()
|
|
39
40
|
], ReferenceRepository);
|
|
40
|
-
exports.ReferenceRepository = ReferenceRepository;
|
|
41
41
|
class Fixtures {
|
|
42
42
|
load() {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/fixtures.module.js
CHANGED
|
@@ -14,12 +14,12 @@ const mongoose_1 = require("@nestjs/mongoose");
|
|
|
14
14
|
const glob_1 = require("glob");
|
|
15
15
|
const fixtures_1 = require("./fixtures");
|
|
16
16
|
class FixturesModule {
|
|
17
|
-
static forRootAsync(
|
|
18
|
-
return __awaiter(this,
|
|
17
|
+
static forRootAsync(fixturesPathPattern_1, entitiesPathPattern_1) {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* (fixturesPathPattern, entitiesPathPattern, discriminatorDir = 'discriminatorDir') {
|
|
19
19
|
const fixturesPath = glob_1.glob.sync(fixturesPathPattern);
|
|
20
20
|
const fixturesRelativePath = fixturesPath.map((path) => path.replace('src/', `${process.cwd()}/dist/`)).map((path) => path.replace('.ts', ''));
|
|
21
21
|
const fixturesProviders = [];
|
|
22
|
-
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve().then(
|
|
22
|
+
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve(`${path}`).then(s => require(s))));
|
|
23
23
|
importedFixtures.forEach((fixture) => {
|
|
24
24
|
fixturesProviders.push(fixture[Object.keys(fixture)[0]]);
|
|
25
25
|
});
|
|
@@ -29,14 +29,14 @@ class FixturesModule {
|
|
|
29
29
|
const discriminatorsRelativePath = entitiesRelativePath.filter((e) => e.includes(discriminatorDir));
|
|
30
30
|
const entitiesProviders = [];
|
|
31
31
|
for (const entity of nonDiscriminatorsRelativePath) {
|
|
32
|
-
const importedEntity = yield Promise.resolve().then(
|
|
32
|
+
const importedEntity = yield Promise.resolve(`${entity}`).then(s => require(s));
|
|
33
33
|
const provider = {
|
|
34
34
|
name: importedEntity[Object.keys(importedEntity)[0]].name,
|
|
35
35
|
schema: importedEntity[Object.keys(importedEntity)[1]],
|
|
36
36
|
};
|
|
37
37
|
const discriminators = discriminatorsRelativePath.filter((e) => e.includes(entity.replace(/(.+)(\/.+)$/gm, '$1')));
|
|
38
38
|
if (discriminators.length !== 0) {
|
|
39
|
-
const importedDiscriminators = yield Promise.all(discriminators.map((path) => Promise.resolve().then(
|
|
39
|
+
const importedDiscriminators = yield Promise.all(discriminators.map((path) => Promise.resolve(`${path}`).then(s => require(s))));
|
|
40
40
|
provider['discriminators'] = importedDiscriminators.map((e) => {
|
|
41
41
|
return { name: e[Object.keys(e)[0]].name, schema: e[Object.keys(e)[1]] };
|
|
42
42
|
});
|
|
@@ -63,29 +63,33 @@ class FixturesModule {
|
|
|
63
63
|
};
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
static forRootAsyncMonorepo(
|
|
67
|
-
return __awaiter(this,
|
|
66
|
+
static forRootAsyncMonorepo(fixturesPathPattern_1, entitiesPathPattern_1) {
|
|
67
|
+
return __awaiter(this, arguments, void 0, function* (fixturesPathPattern, entitiesPathPattern, discriminatorDir = 'discriminators', buildDir = 'dist') {
|
|
68
68
|
const fixturesPath = glob_1.glob.sync(fixturesPathPattern);
|
|
69
|
-
const fixturesRelativePath = fixturesPath
|
|
69
|
+
const fixturesRelativePath = fixturesPath
|
|
70
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-2).join('/')}`)
|
|
71
|
+
.map((path) => path.replace('.ts', ''));
|
|
70
72
|
const fixturesProviders = [];
|
|
71
|
-
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve().then(
|
|
73
|
+
const importedFixtures = yield Promise.all(fixturesRelativePath.map((path) => Promise.resolve(`${path}`).then(s => require(s))));
|
|
72
74
|
importedFixtures.forEach((fixture) => {
|
|
73
75
|
fixturesProviders.push(fixture[Object.keys(fixture)[0]]);
|
|
74
76
|
});
|
|
75
77
|
const entitiesPath = glob_1.glob.sync(entitiesPathPattern);
|
|
76
|
-
const entitiesRelativePath = entitiesPath
|
|
78
|
+
const entitiesRelativePath = entitiesPath
|
|
79
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-3).join('/')}`)
|
|
80
|
+
.map((path) => path.replace('.ts', ''));
|
|
77
81
|
const nonDiscriminatorsRelativePath = entitiesRelativePath.filter((e) => !e.includes(discriminatorDir));
|
|
78
82
|
const discriminatorsRelativePath = entitiesRelativePath.filter((e) => e.includes(discriminatorDir));
|
|
79
83
|
const entitiesProviders = [];
|
|
80
84
|
for (const entity of nonDiscriminatorsRelativePath) {
|
|
81
|
-
const importedEntity = yield Promise.resolve().then(
|
|
85
|
+
const importedEntity = yield Promise.resolve(`${entity}`).then(s => require(s));
|
|
82
86
|
const provider = {
|
|
83
87
|
name: importedEntity[Object.keys(importedEntity)[0]].name,
|
|
84
88
|
schema: importedEntity[Object.keys(importedEntity)[1]],
|
|
85
89
|
};
|
|
86
90
|
const discriminators = discriminatorsRelativePath.filter((e) => e.includes(entity.replace(/(.+)(\/.+)$/gm, '$1')));
|
|
87
91
|
if (discriminators.length !== 0) {
|
|
88
|
-
const importedDiscriminators = yield Promise.all(discriminators.map((path) => Promise.resolve().then(
|
|
92
|
+
const importedDiscriminators = yield Promise.all(discriminators.map((path) => Promise.resolve(`${path}`).then(s => require(s))));
|
|
89
93
|
provider['discriminators'] = importedDiscriminators.map((e) => {
|
|
90
94
|
return { name: e[Object.keys(e)[0]].name, schema: e[Object.keys(e)[1]] };
|
|
91
95
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dauflo/nest-fixtures",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "A module for making fixtures with NestJS. This package is inspired by Doctrine fixtures.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,17 +23,18 @@
|
|
|
23
23
|
"author": "Aloïs Ceola <alois.ceola@hotmail.fr>",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@nestjs/common": "^
|
|
27
|
-
"@nestjs/core": "^
|
|
28
|
-
"@nestjs/mongoose": "^
|
|
29
|
-
"@types/glob": "^
|
|
30
|
-
"glob": "^
|
|
31
|
-
"mongoose": "^
|
|
32
|
-
"nest-commander": "^3.1
|
|
33
|
-
"reflect-metadata": "^0.
|
|
26
|
+
"@nestjs/common": "^11.1.13",
|
|
27
|
+
"@nestjs/core": "^11.1.13",
|
|
28
|
+
"@nestjs/mongoose": "^11.0.4",
|
|
29
|
+
"@types/glob": "^9.0.0",
|
|
30
|
+
"glob": "^13.0.2",
|
|
31
|
+
"mongoose": "^9.2.1",
|
|
32
|
+
"nest-commander": "^3.20.1",
|
|
33
|
+
"reflect-metadata": "^0.2.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"@types/node": "^25.2.3",
|
|
37
|
+
"prettier": "^3.8.1",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/src/fixtures.command.ts
CHANGED
|
@@ -12,7 +12,10 @@ type FixturesObject = {
|
|
|
12
12
|
export class FixturesCommand extends CommandRunner {
|
|
13
13
|
private fixturesDone: string[] = []
|
|
14
14
|
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(
|
|
16
|
+
@Inject('FIXTURES') private fixtures: FixturesObject,
|
|
17
|
+
@InjectConnection() private readonly connection: Connection,
|
|
18
|
+
) {
|
|
16
19
|
super()
|
|
17
20
|
}
|
|
18
21
|
|
package/src/fixtures.module.ts
CHANGED
|
@@ -72,7 +72,9 @@ export class FixturesModule {
|
|
|
72
72
|
): Promise<DynamicModule> {
|
|
73
73
|
// import fixtures
|
|
74
74
|
const fixturesPath = glob.sync(fixturesPathPattern)
|
|
75
|
-
const fixturesRelativePath = fixturesPath
|
|
75
|
+
const fixturesRelativePath = fixturesPath
|
|
76
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-2).join('/')}`)
|
|
77
|
+
.map((path) => path.replace('.ts', ''))
|
|
76
78
|
const fixturesProviders: any[] = []
|
|
77
79
|
const importedFixtures = await Promise.all(fixturesRelativePath.map((path) => import(path)))
|
|
78
80
|
|
|
@@ -82,7 +84,9 @@ export class FixturesModule {
|
|
|
82
84
|
|
|
83
85
|
// import entities
|
|
84
86
|
const entitiesPath = glob.sync(entitiesPathPattern)
|
|
85
|
-
const entitiesRelativePath = entitiesPath
|
|
87
|
+
const entitiesRelativePath = entitiesPath
|
|
88
|
+
.map((path) => `${process.cwd()}/${buildDir}/${path.split('/').slice(-3).join('/')}`)
|
|
89
|
+
.map((path) => path.replace('.ts', ''))
|
|
86
90
|
|
|
87
91
|
const nonDiscriminatorsRelativePath = entitiesRelativePath.filter((e) => !e.includes(discriminatorDir))
|
|
88
92
|
const discriminatorsRelativePath = entitiesRelativePath.filter((e) => e.includes(discriminatorDir))
|