@projectinvicta/nails 3.0.3 → 3.0.4
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/index.ts +2 -4
- package/lib/Nails.ts +4 -2
- package/package.json +1 -1
- package/tests/nails.spec.js +16 -2
- package/tests/services/integration/server/models/dog.js +6 -0
package/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import Nails from './lib/Nails.ts';
|
|
2
2
|
import ControllerInternal from './lib/Controller.ts';
|
|
3
3
|
|
|
4
|
-
export { DataTypes } from 'sequelize';
|
|
4
|
+
export { DataTypes, Model } from 'sequelize';
|
|
5
5
|
|
|
6
6
|
export default Nails;
|
|
7
7
|
|
|
8
8
|
export const Controller = ControllerInternal;
|
|
9
|
-
export * from './lib/config.ts';
|
|
10
|
-
|
|
11
|
-
export { Model } from 'sequelize';
|
|
9
|
+
export * from './lib/config.ts';
|
package/lib/Nails.ts
CHANGED
|
@@ -97,7 +97,7 @@ export default class Nails {
|
|
|
97
97
|
|
|
98
98
|
async initializeModels() {
|
|
99
99
|
await this.loadModels(this.config.service.MODELS_ROOT);
|
|
100
|
-
await Promise.all(this.modelFinalizations);
|
|
100
|
+
await Promise.all(this.modelFinalizations.map((finalization) => finalization()));
|
|
101
101
|
await this.sequelize.sync();
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -174,7 +174,9 @@ export default class Nails {
|
|
|
174
174
|
const schema = modelModule.schema;
|
|
175
175
|
const options = modelModule.options;
|
|
176
176
|
const defer = modelModule.defer as (() => Promise<void>) | undefined;
|
|
177
|
-
|
|
177
|
+
if (modelModule.finalize) {
|
|
178
|
+
this.modelFinalizations.push(modelModule.finalize as () => Promise<void>);
|
|
179
|
+
}
|
|
178
180
|
this.modelMigrations.push(modelModule.migrate as () => Promise<void>);
|
|
179
181
|
|
|
180
182
|
modelClass.init(schema, { sequelize: this.sequelize, ...options });
|
package/package.json
CHANGED
package/tests/nails.spec.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
// TODO test all initialization here
|
|
2
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { describe, beforeAll, it, test, expect, vi } from 'vitest';
|
|
3
|
+
import Dog from './services/integration/server/models/dog.js';
|
|
4
|
+
import Owner from './services/integration/server/models/owner.js';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
let nails;
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
nails = (await import('./services/integration/server.js')).default;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("finalize is called during model initialization", async () => {
|
|
13
|
+
const owner = await Owner.create({});
|
|
14
|
+
const dog = await owner.createDog({name: "Fido"});
|
|
15
|
+
const dogOwner = await dog.getOwner();
|
|
16
|
+
expect(dogOwner).toBeDefined();
|
|
17
|
+
expect(dogOwner.id).toEqual(owner.id);
|
|
18
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Model, DataTypes} from '../../../../../index.ts';
|
|
2
|
+
import Owner from './owner.js';
|
|
2
3
|
|
|
3
4
|
export const schema = {
|
|
4
5
|
good: DataTypes.BOOLEAN,
|
|
@@ -6,3 +7,8 @@ export const schema = {
|
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export default class Dog extends Model {};
|
|
10
|
+
|
|
11
|
+
export async function finalize() {
|
|
12
|
+
Dog.belongsTo(Owner);
|
|
13
|
+
await Dog.sync({alter: {drop: false}});
|
|
14
|
+
}
|