Releases: FoalTS/foal
v0.6.0
Features
- Let hooks execute functions after the method execution (#253).
- Let createApp accept a custom express instance as base (#264).
- Support the missing HTTP methods
HEAD
andOPTIONS
(#262). - [Internal] Make the CLI unit tests work on Windows (issue: #207) (#260, #261).
- Rename the hook
Authenticate
toAuthenticateWithSessionAndCookie
(#263).
Breaking changes
- The returned type of a hook function is now
void | HttpResponse | HookPostFunction | Promise <void | HttpResponse | HookPostFunction>
and notany
anymore.
This means that if you have a hook defined like@Hook(ctx => ctx.state.foo = 2)
, you to have update its definition as follows:@Hook(ctx => { ctx.state.foo = 2; })
- The hook
Authenticate
is now namedAuthenticateWithSessionAndCookie
.
Contributors
v0.6.0-beta.6
Features
- Use
getAjvInstance
inLoginController
. - [@foal/cli] Generate vscode config files for fast debugging (#244).
- Let the
Log
hook print information about the HTTP request (#246) (breaking change). - Add the
logIn
andlogOut
utilities (#247). - [@foal/cli] Prettify the CLI outputs with colors (#249).
- [@foal/cli] Register the controllers with their kebab names (#250).
- Make
HttpResponse
support headers and cookies (#251).
Breaking changes
- The property
headers
ofHttpResponse
is now private. You need to use thesetHeader
,getHeader
andgetHeaders
methods instead. - The optional parameter of the
Log
Hook is not the log function anymore but anoptions
object.@Log('hello', console.error) // before @Log('hello', { logFn: console.error }) // after
v0.6.0-beta.5
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.
v0.6.0-beta.4
Features
- Change framework description.
- [Internal] Use both male and female names in tests (#194).
- Add validate util and add it by default when generating an
EntityResourceCollection
(#196). - Add getCommandLineArguments util and
create-user
,create-group
andcreate-perm
scripts (issue: #162) (PR: #197). - [Internal] Add e2e tests in Travis (#198).
- Add a script generator (#199).
- Automatically register controllers upon creation (#200).
- Update session default configuration following OWASP recommandations (#201).
- Add the
foal run-script
feature (#202). - Correct typeorm scripts (issue: #204) (#206).
How to migrate
Update you dependencies
Update your local dependencies: npm update
.
Update globally @foal/cli
: npm -g update @foal/cli
.
Database migrations
The entity Group
now has a codeName
.
- If you have
synchronize
set totrue
in yourormconfig.json
then the database schema will automatically be updated. - Otherwise run the following commands to update the db schema:
npm run build
npm run migration:generate -- -n add-codename-to-group
npm run build
npm run migration:run
Shell scripts
Remove src/scripts/create-users.ts
and add the following scripts:
Session configuration
Remove the line "sessionCookieDomain": "localhost"
in config/settings.production.json
.
v0.6.0-beta.3
Features
- Do not build test when running npm run build (#182).
- Remove all the outdated test.ts which are not required anymore in v0.6.0-beta.2 (#182).
- Make
render
use template paths (#184). - Move migrations to
src/migrations
(issue: #175) (#185). - Add the exports to the
index.ts
when creating a file (#186). - [@foal/cli] [Internal] Refactor @foal/cli (#188).
How to migrate
Update your dependencies by running npm update
.
The render
util
// Before
import { readFileSync } from 'fs';
import { join } from 'path';
const login = readFileSync(join(__dirname, './templates/login.html'), 'utf8');
render(login, { csrfToken: ctx.request.csrfToken() });
// After
render('./templates/login.html', { csrfToken: ctx.request.csrfToken() }, __dirname);
The migrations
- Move you root
migrations
directory (if it exists) tosrc
. - Update your
tslint.json
andormconfig.json
with:
{
...
"linterOptions": {
"exclude": "src/migrations/*.ts"
}
}
{
...
"migrations": ["lib/migrations/*.js"],
"cli": {
"migrationsDir": "src/migrations"
},
}
v0.6.0-beta.2
- Make the
copy
command work on Windows (hot fix).
v0.6.0-beta.1
Features
- Do not have to manually register each entity (issue #174).
- Improve installation speed (from 28/31/34 s to 12/14/14 s) (issue #174).
- Reduce the number of dependencies (mainly for security reasons) (total dependencies for
@foal/cli
: 901 -> 34) (issue #174). - Set the stage to have a REPL shell (issue #137).
- Set the stage to create users, groups and permissions easily through a command line (issue #162).
- Be able to use the database in the constructor of a service or more widely before a request is received.
- Fix this issue: if the first requests are made simultaneously then some of them may not have the connection established to the database.
- Improve the test experience: the client should be able to run its tests without registering them into a
test.ts
file (issue #174). - Set the stage to improve "smooth" debugging in vscode (issue #174).
- Improve "hard" (by hand) debugging (issue #174).
- Support multiple database connections
- [Internal] Remove build complexity (issue #174).
Steps
- Remove
InitDB
and add acreateConnection
in the mainindex.ts
file instead. - Update the build, run and test commands to use
copy
and to get rid ofwebpack
. - Update
tsconfig.json
andormconfig.json
to use the correct paths. - Move the
scripts/
directory intosrc
. - Replace all the
require('**/*.html')
byfs
reads.
How to migrate
- Delete your
lib/
directory. - Update your dependencies by running
npm update
. - The hook
InitDB
does not longer exist and you don't need to register your entities anymore. Remove the hook from your code and replace the content ofsrc/index.ts
by this:
// The imports ...
async function main() {
await createConnection();
const app = createApp(AppModule, {
store: session => new (sqliteStoreFactory(session))({ db: 'db.sqlite3' })
});
const httpServer = http.createServer(app);
const port = Config.get('settings', 'port', 3000);
httpServer.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
}
main();
- Change the commands of your
package.json
by this:
{
"build": "tsc && copy-cli \"src/**/*.html\" lib",
"build:w": "tsc -w",
"start": "node ./lib/index.js",
"start:w": "supervisor -w ./lib --no-restart-on error ./lib/index.js",
"develop": "npm run build && concurrently \"npm run build:w\" \"npm run start:w\"",
"build:test": "tsc && copy-cli \"src/**/*.html\" lib",
"build:test:w": "tsc -w",
"start:test": "mocha \"./lib/**/*.spec.js\"",
"start:test:w": "mocha -w \"./lib/**/*.spec.js\"",
"test": "npm run build:test && concurrently \"npm run build:test:w\" \"npm run start:test:w\"",
"lint": "tslint -c tslint.json -p tsconfig.json",
"migration:generate": "ts-node ./node_modules/.bin/typeorm migration:generate",
"migration:run": "ts-node ./node_modules/.bin/typeorm migration:run",
"migration:revert": "ts-node ./node_modules/.bin/typeorm migration:revert"
}
- Update the following properties in your
tsconfig.json
andormconfig.json
:
// tsconfig
"outDir": "lib"
//ormconfig
"entities": ["lib/app/**/*.entity.js"],
- Move your
scripts/
directory tosrc
. - Replace all your
require('./foobar.html')
tofs.readFileSync(path.join(__dirname, './foobar.html'), 'utf8')
.
v0.6.0-beta.0
Goal: Create complex REST API.
- Rename
ISerializer
toIResourceCollection
andEntitySerializer
toEntityResourceCollection
(#170). - Change
IResourceCollection
interface (#172). - [@foal/cli] Make
User
entity andscripts/create-users
consistent (#176). - [REST] Support postgres and sqlite (#173).
- [REST] Support
PermissionDenied
andValidationError
inEntityCollection
s (#173). - [REST] Add
allowedOperations
,loadedRelations
andmiddlewares
inEntityResourceCollection
(#173). - [REST] Use
params.fields
inEntityResourceCollection
to restrict the returned representations (#173). - [REST] Let the client create several resources within one request (#173).
v0.6.0-alpha.4
Goal: having an authentication and authorization system that work.
- Infer response type from
isHttpResponseXXX
(#160). - [@foal/cli] Add
Authenticate
hook in generated apps (#164). - Add url-encoded parsing and add more tests (#165).
- Add the
createController
util (#166). - Fix the
LoginController
bug"get" of undefined
(#166). - [@foal/cli] Generate controller specs (empty controllers) (#166).
- Support custom session store (#167).
- [@foal/cli] Generated apps now use by default an sqlite3 session store to not loose the user authentication when reloading the server (#167).
- Add e2e tests for authentication and authorization (#168).
- Add redirect URL to
PermissionRequired
.
v0.6.0-alpha.3
- [@foal/cli] Remove
chai
from created apps. (#155). - [@foal/cli] Give a default User path in generated authenticator files.
- [@foal/cli] Generate
Login
controllers (#157). - Add redirect option in
LoginRequired
. - [@foal/cli] Add
HookDecorator
to hook template. - Add
ValidateQuery
hook (#158). - Remove
bootstrap
from@foal/cli
(#159).