v0.6.0-beta.5
Pre-release
Pre-release
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
tofalse
intsconfig.json
and remove thets-ignore
s (#234). - Simplify shell scripts (#235).
- Make ajv global instance coerce types, remove additional properties if required and use default values (#236).
- Add
ValidateParams
andValidateHeaders
(#236). - Simplify dependency injection mechanism (#237).
- Remove modules and let controllers have sub-controllers (#238).
Contributors
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
- Create the directory
src/e2e
. - Install
supertest
:npm install --save-dev supertest
. - Create or replace these files:
- Change the commands in your
package.json
by these ones: https://github.com/FoalTS/foal/blob/fd037498bde5798452a46f87b22ad4c456af64b1/packages/cli/src/generate/specs/app/package.json - Create a file named
e2e.ts
insrc/
with this content:process.env.NODE_ENV = 'e2e'
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
andService
. - 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
RestController
s 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
orcreateController
.
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
tosub-apps
. - In
src/index.ts
, importAppController
instead ofAppModule
as it no longer exists.