Skip to content

v0.6.0-beta.5

Pre-release
Pre-release
Compare
Choose a tag to compare
@LoicPoullain LoicPoullain released this 19 Sep 06:10
· 4064 commits to master since this release

General Note

This release introduces numerous breaking changes. They are the fruit of several feedbacks and should be the last breaking changes of this version. v0.6.0 will come out soon!

Features

  • Make the tests run with NODE_ENV=test on both Unix and Windows systems (issue: #187) (PR: #219).
  • Improve the 'Successfully Installed' page (#215).
  • Add the utility isCommon to test if a password is too common (issue: #111) (#229).
  • Reduce the size of the FoalTS packages (#232).
  • [@foal/cli] Add e2e tests to the generated apps and improve builds (issue: #138) (#233).
  • Set strictPropertyInitialization to false in tsconfig.json and remove the ts-ignores (#234).
  • Simplify shell scripts (#235).
  • Make ajv global instance coerce types, remove additional properties if required and use default values (#236).
  • Add ValidateParams and ValidateHeaders(#236).
  • Simplify dependency injection mechanism (#237).
  • Remove modules and let controllers have sub-controllers (#238).

Contributors

@LoicPoullain
@Jrfidellis

How to migrate

Update you dependencies

  • Update your local dependencies: npm update.
  • Update globally @foal/cli: npm -g update @foal/cli.

Bug #187

Create a new file src/test.ts with the content process.env.NODE_ENV = 'test';. Then in your package.json make the commands start:test and start:test:w start with mocha --file \"./lib/test.js\".

Support e2e tests and improve builds

Simplify shell scripts

Update your scripts following this pattern:

const argSchema = {
  /* ... */
};

export function main(argv) {
  const args = getCommandLineArguments(argv);	
  try {	
    validate(argSchema, args);	
  } catch (error) {	
    if (error instanceof ValidationError) {	
      error.content.forEach(err => {	
        console.log(`The command line arguments ${err.message}`);	
      });	
      return;	
    }	
    throw error;	
  }	
  /* ... */
}

// Replace this with:

export const schema = {
  /* ... */
};

export function main(args) {
  /* ... */
}

ValidateQuery & ValidateBody

The hooks ValidateQuery and ValidateBody now use under the hood this configuration of Ajv:

{
  coerceTypes: true,  // change data type of data to match type keyword
  removeAdditional: true, // remove additional properties
  useDefaults: true, // replace missing properties and items with the values from corresponding default keyword
}

Dependency Injection

  • Remove all the occurrences of the decorators Module, Controller and Service.
  • Follow this pattern in your controllers and services:
@Controller()
export class MyController {
  constructor(private myService1: MyService1, public myService2: MyService2) {}
}
// becomes:
export class MyController {
  @dependency
  private myService1: MyService1;

  @dependency
  myService2: MyService2;
}
  • Change your RestControllers following this pattern:
export class MyController extends RestController {
  collectionClass = MyCollectionClass;
}
// becomes:
export class MyController extends RestController {
  @dependency
  collection: MyCollectionClass;
}
  • If you need to instantiate controllers or services in your tests, use createService or createController.

Modules -> Controllers and SubControllers

  • Rename all your files **.module.ts into **.controller.ts
  • Change the content of your module files following this pattern:
export AppModule implements IModule {
  controllers = [
    controller('/foo', Controller1)
  ];

  subModules = [
     subModule('/api', ApiModule)
  ];
}
// Replace this with:
export AppController {
  subControllers = [
    controller('/foo', Controller1),
    controller('/api', ApiController)
  ];
}
  • Rename the directories sub-modules to sub-apps.
  • In src/index.ts, import AppController instead of AppModule as it no longer exists.