Skip to content

Releases: FoalTS/foal

v0.6.0

24 Oct 13:41
Compare
Choose a tag to compare

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 and OPTIONS (#262).
  • [Internal] Make the CLI unit tests work on Windows (issue: #207) (#260, #261).
  • Rename the hook Authenticate to AuthenticateWithSessionAndCookie (#263).

Breaking changes

  • The returned type of a hook function is now void | HttpResponse | HookPostFunction | Promise <void | HttpResponse | HookPostFunction> and not any 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 named AuthenticateWithSessionAndCookie.

Contributors

@LoicPoullain
@Jrfidellis

v0.6.0-beta.6

10 Oct 09:02
Compare
Choose a tag to compare
v0.6.0-beta.6 Pre-release
Pre-release

Features

  • Use getAjvInstance in LoginController.
  • [@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 and logOut 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 of HttpResponse is now private. You need to use the setHeader, getHeader and getHeaders methods instead.
  • The optional parameter of the Log Hook is not the log function anymore but an options object.
    @Log('hello', console.error) // before
    @Log('hello', { logFn: console.error }) // after

v0.6.0-beta.5

19 Sep 06:10
Compare
Choose a tag to compare
v0.6.0-beta.5 Pre-release
Pre-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.

v0.6.0-beta.4

07 Sep 08:53
Compare
Choose a tag to compare
v0.6.0-beta.4 Pre-release
Pre-release

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 and create-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 to true in your ormconfig.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

27 Aug 10:14
Compare
Choose a tag to compare
v0.6.0-beta.3 Pre-release
Pre-release

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) to src.
  • Update your tslint.json and ormconfig.json with:
{
   ...
   "linterOptions": {
      "exclude": "src/migrations/*.ts"
   }
}
{
   ...
   "migrations": ["lib/migrations/*.js"],
   "cli": {
      "migrationsDir": "src/migrations"
   },
}

v0.6.0-beta.2

22 Aug 09:06
Compare
Choose a tag to compare
v0.6.0-beta.2 Pre-release
Pre-release
  • Make the copy command work on Windows (hot fix).

v0.6.0-beta.1

22 Aug 08:18
Compare
Choose a tag to compare
v0.6.0-beta.1 Pre-release
Pre-release

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 a createConnection in the main index.ts file instead.
  • Update the build, run and test commands to use copy and to get rid of webpack.
  • Update tsconfig.json and ormconfig.json to use the correct paths.
  • Move the scripts/ directory into src.
  • Replace all the require('**/*.html') by fs 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 of src/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 and ormconfig.json:
// tsconfig
"outDir": "lib" 
//ormconfig
 "entities": ["lib/app/**/*.entity.js"],
  • Move your scripts/ directory to src.
  • Replace all your require('./foobar.html') to fs.readFileSync(path.join(__dirname, './foobar.html'), 'utf8').

v0.6.0-beta.0

21 Aug 11:17
Compare
Choose a tag to compare
v0.6.0-beta.0 Pre-release
Pre-release

Goal: Create complex REST API.

  • Rename ISerializer to IResourceCollection and EntitySerializer to EntityResourceCollection(#170).
  • Change IResourceCollection interface (#172).
  • [@foal/cli] Make User entity and scripts/create-users consistent (#176).
  • [REST] Support postgres and sqlite (#173).
  • [REST] Support PermissionDenied and ValidationError in EntityCollections (#173).
  • [REST] Add allowedOperations, loadedRelations and middlewaresin EntityResourceCollection (#173).
  • [REST] Use params.fields in EntityResourceCollection to restrict the returned representations (#173).
  • [REST] Let the client create several resources within one request (#173).

v0.6.0-alpha.4

13 Aug 18:56
Compare
Choose a tag to compare
v0.6.0-alpha.4 Pre-release
Pre-release

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

06 Aug 06:43
Compare
Choose a tag to compare
v0.6.0-alpha.3 Pre-release
Pre-release
  • [@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).