Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the build system #397

Merged
merged 4 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"typescript-sort-keys"
"@typescript-eslint"
],
"rules": {
// Javscript Specific Rules That Are Applied To Typescript Too
Expand Down Expand Up @@ -53,11 +52,16 @@
}
],
// Typescript Specific Rules From This Point On
"typescript-sort-keys/interface": 2,
"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,
Expand Down
11,765 changes: 2,300 additions & 9,465 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@
},
"dependencies": {
"express": "4.18.2",
"http-status-codes": "2.2.0",
"inversify": "6.0.1"
"http-status-codes": "2.3.0",
"inversify": "6.0.2"
},
"description": "Some utilities for the development of express applications with Inversify",
"devDependencies": {
"@types/async": "3.2.12",
"@types/cookie-parser": "1.4.2",
"@types/express": "4.17.13",
"@types/jest": "27.4.0",
"@types/node": "17.0.13",
"@types/supertest": "2.0.11",
"@typescript-eslint/eslint-plugin": "5.10.1",
"@typescript-eslint/parser": "5.10.1",
"async": "3.2.3",
"@types/async": "3.2.24",
"@types/cookie-parser": "1.4.6",
"@types/express": "4.17.21",
"@types/jest": "29.5.10",
"@types/node": "20.10.0",
"@types/supertest": "2.0.16",
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"async": "3.2.5",
"cookie-parser": "1.4.6",
"eslint": "8.7.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-typescript-sort-keys": "2.1.0",
"jest": "27.4.7",
"eslint": "8.54.0",
"eslint-plugin-import": "2.29.0",
"jest": "29.7.0",
"publish-please": "5.5.2",
"reflect-metadata": "0.1.13",
"supertest": "6.2.2",
"ts-jest": "27.1.3",
"typescript": "4.5.5",
"updates": "13.0.0"
"supertest": "6.3.3",
"ts-jest": "29.1.1",
"typescript": "5.3.2",
"updates": "15.0.4"
},
"homepage": "https://github.com/inversify/inversify-express-utils#readme",
"jsnext:main": "es/index.js",
Expand Down Expand Up @@ -62,4 +61,4 @@
},
"types": "./lib/index.d.ts",
"version": "6.4.5"
}
}
21 changes: 12 additions & 9 deletions src/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable, decorate } from 'inversify';
import { TYPE, METADATA_KEY, PARAMETER_TYPE, HTTP_VERBS_ENUM, } from './constants';
import type { Controller, DecoratorTarget, Middleware, ControllerMetadata, HandlerDecorator, ControllerMethodMetadata, ControllerParameterMetadata, ParameterMetadata } from './interfaces';
import type { DecoratorTarget, Middleware, ControllerMetadata, HandlerDecorator, ControllerMethodMetadata, ControllerParameterMetadata, ParameterMetadata } from './interfaces';


export const injectHttpContext = inject(TYPE.HttpContext);
Expand Down Expand Up @@ -161,15 +161,18 @@ export const principal: () => ParameterDecorator =

function paramDecoratorFactory(
parameterType: PARAMETER_TYPE,
): (name?: string) => ParameterDecorator {
return (name?: string): ParameterDecorator =>
): (name?: string | symbol) => ParameterDecorator {
return (name?: string | symbol): ParameterDecorator =>
params(parameterType, name);
}

export function params(type: PARAMETER_TYPE, parameterName?: string) {
export function params(
type: PARAMETER_TYPE,
parameterName?: string | symbol
) {
return (
target: unknown | Controller,
methodName: string | symbol,
target: object,
methodName: string | symbol | undefined,
index: number
): void => {
let metadataList: ControllerParameterMetadata = {};
Expand All @@ -183,14 +186,14 @@ export function params(type: PARAMETER_TYPE, parameterName?: string) {
if (
!Reflect.hasOwnMetadata(
METADATA_KEY.controllerParameter,
(target as Controller).constructor
target.constructor
)
) {
parameterMetadataList.unshift(parameterMetadata);
} else {
metadataList = Reflect.getOwnMetadata(
METADATA_KEY.controllerParameter,
(target as Controller).constructor,
target.constructor,
) as ControllerParameterMetadata;
if (metadataList[methodName as string]) {
parameterMetadataList = metadataList[methodName as string] || [];
Expand All @@ -201,7 +204,7 @@ export function params(type: PARAMETER_TYPE, parameterName?: string) {
Reflect.defineMetadata(
METADATA_KEY.controllerParameter,
metadataList,
(target as Controller).constructor
target.constructor
);
};
}
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface ControllerParameterMetadata {
export interface ParameterMetadata {
index: number;
injectRoot: boolean;
parameterName?: string | undefined;
parameterName?: string | symbol | undefined;
type: PARAMETER_TYPE;
}

Expand Down
18 changes: 12 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'reflect-metadata';

import express, { Application, NextFunction, Request, RequestHandler, Response, Router } from 'express';
import { interfaces } from 'inversify';
import { BaseMiddleware, Controller } from './index';
Expand Down Expand Up @@ -161,11 +163,12 @@ export class InversifyExpressServer {
if (parameterMetadata) {
paramList = parameterMetadata[metadata.key] || [];
}
const handler: express.RequestHandler = this.handlerFactory(
const handler: RequestHandler = this.handlerFactory(
(controllerMetadata.target as { name: string }).name,
metadata.key,
paramList,
);

const routeMiddleware = this.resolveMidleware(...metadata.middleware);
this._router[metadata.method](
`${controllerMetadata.path}${metadata.path}`,
Expand Down Expand Up @@ -244,7 +247,7 @@ export class InversifyExpressServer {
controllerName: string,
key: string,
parameterMetadata: Array<ParameterMetadata>,
): express.RequestHandler {
): RequestHandler {
return async (
req: Request,
res: Response,
Expand Down Expand Up @@ -384,15 +387,18 @@ export class InversifyExpressServer {
source: Request,
paramType: 'params' | 'query' | 'headers' | 'cookies',
injectRoot: boolean,
name?: string,
): Record<string, unknown> | unknown | undefined {
const key = paramType === 'headers' ? name?.toLowerCase() : name;
name?: string | symbol,
): unknown {
const key = paramType === 'headers' ?
typeof name === 'symbol' ?
name.toString() :
name?.toLowerCase() :
name as string;
const param = source[paramType] as Record<string, unknown>;

if (injectRoot) {
return param;
}

return (param && key) ? param[key] : undefined;
}

Expand Down
9 changes: 3 additions & 6 deletions src/tsconfig-es.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"compilerOptions": {
"outDir": "../es",
"module": "ES2015"
"outDir": "../es6",
"target": "ES6"
},
"extends": "../tsconfig.json",
"include": [
"./**/*.ts"
]
"extends": "../tsconfig.json"
}
9 changes: 3 additions & 6 deletions src/tsconfig-es6.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"compilerOptions": {
"target": "ES6",
"outDir": "../es6"
"outDir": "../es6",
"target": "ES6"
},
"extends": "../tsconfig.json",
"include": [
"./**/*.ts"
]
"extends": "../tsconfig.json"
}
11 changes: 6 additions & 5 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"include": [
"./**/*.ts"
],
"extends": "../tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"outDir": "../lib",
"rootDir": "."
"rootDir": ".",
"target": "ES2015"
},
"extends": "../tsconfig.json",
"include": [
"./**/*.ts"
]
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"target": "ES5",
"strictNullChecks": true,
"types": [
"node",
"reflect-metadata",
"jest"
],
"typeRoots": [
Expand Down
Loading