Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
PodaruDragos committed Nov 25, 2023
2 parents 40a5be1 + 3fc6230 commit 408d78d
Show file tree
Hide file tree
Showing 65 changed files with 10,987 additions and 11,114 deletions.
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lib/
es/
es6/
*.d.ts
src/**/*.js
test/**/*.js
.eslintrc.js
jest.config.js
coverage
78 changes: 78 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Rules Severity
- 0 = off
- 1 = warn
- 2 = error
*/
{
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"impliedStrict": true
},
"ecmaVersion": "latest",
"project": "./tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
// Javscript Specific Rules That Are Applied To Typescript Too
"max-len": [
"error",
{
"code": 80,
"ignoreComments": true,
"ignorePattern": "^(import)|(it\\()",
"ignoreTemplateLiterals": true
}
],
"no-console": 1,
"quotes": [
2,
"single"
],
"semi": 2,
"sort-keys": [
2,
"asc",
{
"caseSensitive": true,
"natural": false,
"minKeys": 2
}
],
// Typescript Specific Rules From This Point On
"typescript-sort-keys/string-enum": 0,
"@typescript-eslint/explicit-function-return-type": 2,
"@typescript-eslint/no-explicit-any": 2,
"@typescript-eslint/no-inferrable-types": 2,
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
],
"@typescript-eslint/no-non-null-assertion": 2,
"@typescript-eslint/no-unsafe-call": 2,
"@typescript-eslint/no-unsafe-member-access": 2,
"@typescript-eslint/no-unused-vars": [
2,
{
"argsIgnorePattern": "_",
"ignoreRestSiblings": true
}
],
"@typescript-eslint/no-var-requires": 2,
"@typescript-eslint/require-await": 2
}
}
7 changes: 7 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

name-template: 'Next Release'
tag-template: 'next'
change-template: '- $TITLE #$NUMBER'
no-changes-template: '- No changes yet'
template: |
$CHANGES
34 changes: 34 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]
ts-project: [src/tsconfig.json, src/tsconfig-es6.json]

env:
TS_NODE_PROJECT: ${{ matrix.ts-project }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm cache clean --force
- run: npm ci
- run: npm run build --if-present
- run: npm test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down Expand Up @@ -43,6 +44,7 @@ dts
dist
lib
es
es6

type_definitions/inversify/*.js

Expand Down
5 changes: 3 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
Expand All @@ -19,4 +18,6 @@ wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions
type_definitions
.eslintrc.json
.github/
4 changes: 2 additions & 2 deletions .publishrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
},
"confirm": true,
"publishTag": "latest",
"prePublishScript": "gulp"
}
"prePublishScript": "npm test"
}
18 changes: 13 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
"${workspaceRoot}/test/**/*.test.js"
],
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/test",
"${workspaceRoot}/src"
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--watch",
],
"internalConsoleOptions": "openOnSessionStart"
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
}
]
}
}
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog
All notable changes to this project from 6.4.4 forward will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

### Changed

### Fixed

## [6.4.4]

### Added

### Changed
- Update dependencies (`minimist`, `json5`, `@babel/traverse`, `tough-cookie`, `ansi-regex`, `cookiejar`, `express`, `decode-uri-component`)

### Fixed
- Change JsonContent to return object rather than string (#379 / #378)
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ $ npm install

3 Run build process
```
$ gulp
$ npm run build
```

## Guidelines

- Please try to [combine multiple commits before pushing](http://stackoverflow.com/questions/6934752/combining-multiple-commits-before-pushing-in-git)

- Please use `TDD` when fixing bugs. This means that you should write a unit test that fails because it reproduces the issue,
then fix the issue and finally run the test to ensure that the issue has been resolved. This helps us prevent fixed bugs from
- Please use `TDD` when fixing bugs. This means that you should write a unit test that fails because it reproduces the issue,
then fix the issue and finally run the test to ensure that the issue has been resolved. This helps us prevent fixed bugs from
happening again in the future

- Please keep the test coverage at 100%. Write additional unit tests if necessary
Expand Down
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class FooController implements interfaces.Controller {
constructor( @inject("FooService") private fooService: FooService ) {}

@httpGet("/")
private index(req: express.Request, res: express.Response, next: express.NextFunction): string {
private index(@request() req: express.Request, @response() res: express.Response, @next() next: express.NextFunction): string {
return this.fooService.get(req.query.id);
}

Expand Down Expand Up @@ -281,7 +281,7 @@ Binds a method parameter to the user principal obtained from the AuthProvider.

The `BaseHttpController` is a base class that provides a significant amount of helper functions in order to aid writing testable controllers. When returning a response from a method defined on one of these controllers, you may use the `response` object available on the `httpContext` property described in the next section, or you may return an `HttpResponseMessage`, or you may return an object that implements the IHttpActionResult interface.

The benefit of the latter two methods are that since your controller is no longer directly coupled to requiring an httpContext to send a response, unit testing controllers becomes extraordinarily simple as you no longer need to mock the entire response object, you can simply run assertions on the returned value. This API also allows us to make future improvements in this area and add in functionality that exists in similar frameworks (.NET WebAPI) such as media formatters, content negotation, etc.
The benefit of the latter two methods is that since your controller is no longer directly coupled to requiring an httpContext to send a response, unit testing controllers becomes extraordinarily simple as you no longer need to mock the entire response object, you can simply run assertions on the returned value. This API also allows us to make future improvements in this area and add in functionality that exists in similar frameworks (.NET WebAPI) such as media formatters, content negotation, etc.

```ts
import { injectable, inject } from "inversify";
Expand Down Expand Up @@ -441,7 +441,7 @@ const server = new InversifyExpressServer(
We need to implement the `AuthProvider` interface.
The `AuthProvider` allow us to get an user (`Principal`):
The `AuthProvider` allow us to get a user (`Principal`):
```ts
import { injectable, inject } from "inversify";
Expand Down Expand Up @@ -471,21 +471,21 @@ class CustomAuthProvider implements interfaces.AuthProvider {
We also need to implement the Principal interface.
The `Principal` interface allow us to:
- Access the details of an user
- Access the details of a user
- Check if it has access to certain resource
- Check if it is authenticated
- Check if it is in an user role
- Check if it is in a user role
```ts
class Principal implements interfaces.Principal {
public details: any;
public constructor(details: any) {
class Principal implements interfaces.Principal<T = unknown> {
public details: T;
public constructor(details: T) {
this.details = details;
}
public isAuthenticated(): Promise<boolean> {
return Promise.resolve(true);
}
public isResourceOwner(resourceId: any): Promise<boolean> {
public isResourceOwner(resourceId: unknown): Promise<boolean> {
return Promise.resolve(resourceId === 1111);
}
public isInRole(role: string): Promise<boolean> {
Expand Down Expand Up @@ -516,7 +516,7 @@ class UserDetailsController extends BaseHttpController {
## BaseMiddleware
Extending `BaseMiddleware` allow us to inject dependencies
and to be access the current `HttpContext` in Express middleware function.
and to access the current `HttpContext` in Express middleware function.
```ts
import { BaseMiddleware } from "inversify-express-utils";
Expand Down Expand Up @@ -555,7 +555,6 @@ container.bind<LoggerMiddleware>(TYPES.LoggerMiddleware)
We can then inject `TYPES.LoggerMiddleware` into one of our controllers.
```ts
@injectable()
@controller("/")
class UserDetailsController extends BaseHttpController {

Expand All @@ -570,10 +569,6 @@ class UserDetailsController extends BaseHttpController {
}
}
}

container.bind<interfaces.Controller>(TYPE.Controller)
.to(UserDetailsController)
.whenTargetNamed("UserDetailsController");
```
### Request-scope services
Expand Down
Loading

0 comments on commit 408d78d

Please sign in to comment.