@projectinvicta/nails 3.0.1 → 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 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,6 +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.map((finalization) => finalization()));
100
101
  await this.sequelize.sync();
101
102
  }
102
103
 
@@ -173,7 +174,9 @@ export default class Nails {
173
174
  const schema = modelModule.schema;
174
175
  const options = modelModule.options;
175
176
  const defer = modelModule.defer as (() => Promise<void>) | undefined;
176
- this.modelFinalizations.push(modelModule.finalize as () => Promise<void>);
177
+ if (modelModule.finalize) {
178
+ this.modelFinalizations.push(modelModule.finalize as () => Promise<void>);
179
+ }
177
180
  this.modelMigrations.push(modelModule.migrate as () => Promise<void>);
178
181
 
179
182
  modelClass.init(schema, { sequelize: this.sequelize, ...options });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectinvicta/nails",
3
- "version": "3.0.1",
3
+ "version": "3.0.4",
4
4
  "description": "A node.js webserver scaffold",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -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
- it.todo('Should test something');
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
+ }