web_api_base 6.0.3 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/readme.md +36 -12
- package/dist/Application.d.ts +0 -28
- package/dist/Application.js +0 -643
- package/dist/Application.js.map +0 -1
- package/dist/ApplicationConfiguration.d.ts +0 -20
- package/dist/ApplicationConfiguration.js +0 -132
- package/dist/ApplicationConfiguration.js.map +0 -1
- package/dist/bin/CreateApplication.d.ts +0 -1
- package/dist/bin/CreateApplication.js +0 -6
- package/dist/bin/CreateApplication.js.map +0 -1
- package/dist/bin/CreateController.d.ts +0 -1
- package/dist/bin/CreateController.js +0 -5
- package/dist/bin/CreateController.js.map +0 -1
- package/dist/bin/Factory.d.ts +0 -2
- package/dist/bin/Factory.js +0 -81
- package/dist/bin/Factory.js.map +0 -1
- package/dist/controllers/AcceptedResult.d.ts +0 -4
- package/dist/controllers/AcceptedResult.js +0 -13
- package/dist/controllers/AcceptedResult.js.map +0 -1
- package/dist/controllers/ActionResult.d.ts +0 -5
- package/dist/controllers/ActionResult.js +0 -10
- package/dist/controllers/ActionResult.js.map +0 -1
- package/dist/controllers/BadRequestResult.d.ts +0 -4
- package/dist/controllers/BadRequestResult.js +0 -13
- package/dist/controllers/BadRequestResult.js.map +0 -1
- package/dist/controllers/CreatedResult.d.ts +0 -4
- package/dist/controllers/CreatedResult.js +0 -13
- package/dist/controllers/CreatedResult.js.map +0 -1
- package/dist/controllers/DownloadFileResult.d.ts +0 -4
- package/dist/controllers/DownloadFileResult.js +0 -13
- package/dist/controllers/DownloadFileResult.js.map +0 -1
- package/dist/controllers/ErrorResult.d.ts +0 -4
- package/dist/controllers/ErrorResult.js +0 -13
- package/dist/controllers/ErrorResult.js.map +0 -1
- package/dist/controllers/ForbiddenResult.d.ts +0 -4
- package/dist/controllers/ForbiddenResult.js +0 -13
- package/dist/controllers/ForbiddenResult.js.map +0 -1
- package/dist/controllers/GenericResult.d.ts +0 -5
- package/dist/controllers/GenericResult.js +0 -13
- package/dist/controllers/GenericResult.js.map +0 -1
- package/dist/controllers/NoContentResult.d.ts +0 -4
- package/dist/controllers/NoContentResult.js +0 -13
- package/dist/controllers/NoContentResult.js.map +0 -1
- package/dist/controllers/NotFoundResult.d.ts +0 -4
- package/dist/controllers/NotFoundResult.js +0 -13
- package/dist/controllers/NotFoundResult.js.map +0 -1
- package/dist/controllers/OKResult.d.ts +0 -4
- package/dist/controllers/OKResult.js +0 -13
- package/dist/controllers/OKResult.js.map +0 -1
- package/dist/controllers/SendFileResult.d.ts +0 -4
- package/dist/controllers/SendFileResult.js +0 -13
- package/dist/controllers/SendFileResult.js.map +0 -1
- package/dist/controllers/UnauthorizedResult.d.ts +0 -4
- package/dist/controllers/UnauthorizedResult.js +0 -13
- package/dist/controllers/UnauthorizedResult.js.map +0 -1
- package/dist/controllers/base/ControllerBase.d.ts +0 -32
- package/dist/controllers/base/ControllerBase.js +0 -84
- package/dist/controllers/base/ControllerBase.js.map +0 -1
- package/dist/decorators/controllers/ControllerDecorators.d.ts +0 -65
- package/dist/decorators/controllers/ControllerDecorators.js +0 -256
- package/dist/decorators/controllers/ControllerDecorators.js.map +0 -1
- package/dist/decorators/documentation/DocumentationDecorators.d.ts +0 -23
- package/dist/decorators/documentation/DocumentationDecorators.js +0 -69
- package/dist/decorators/documentation/DocumentationDecorators.js.map +0 -1
- package/dist/decorators/validations/ValidationDecorators.d.ts +0 -53
- package/dist/decorators/validations/ValidationDecorators.js +0 -181
- package/dist/decorators/validations/ValidationDecorators.js.map +0 -1
- package/dist/dependencyInjection/DependecyService.d.ts +0 -28
- package/dist/dependencyInjection/DependecyService.js +0 -136
- package/dist/dependencyInjection/DependecyService.js.map +0 -1
- package/dist/dependencyInjection/IDIContext.d.ts +0 -7
- package/dist/dependencyInjection/IDIContext.js +0 -3
- package/dist/dependencyInjection/IDIContext.js.map +0 -1
- package/dist/documentation/CSS.d.ts +0 -6
- package/dist/documentation/CSS.js +0 -302
- package/dist/documentation/CSS.js.map +0 -1
- package/dist/documentation/Documentation.d.ts +0 -7
- package/dist/documentation/Documentation.js +0 -89
- package/dist/documentation/Documentation.js.map +0 -1
- package/dist/documentation/HTML.d.ts +0 -4
- package/dist/documentation/HTML.js +0 -26
- package/dist/documentation/HTML.js.map +0 -1
- package/dist/documentation/JS.d.ts +0 -5
- package/dist/documentation/JS.js +0 -416
- package/dist/documentation/JS.js.map +0 -1
- package/dist/enums/httpVerbs/HttpVerbs.d.ts +0 -6
- package/dist/enums/httpVerbs/HttpVerbs.js +0 -11
- package/dist/enums/httpVerbs/HttpVerbs.js.map +0 -1
- package/dist/exceptions/ArgumentNullException.d.ts +0 -3
- package/dist/exceptions/ArgumentNullException.js +0 -10
- package/dist/exceptions/ArgumentNullException.js.map +0 -1
- package/dist/exceptions/BodyParseException.d.ts +0 -3
- package/dist/exceptions/BodyParseException.js +0 -10
- package/dist/exceptions/BodyParseException.js.map +0 -1
- package/dist/exceptions/ControllerLoadException.d.ts +0 -3
- package/dist/exceptions/ControllerLoadException.js +0 -10
- package/dist/exceptions/ControllerLoadException.js.map +0 -1
- package/dist/exceptions/DecoratorException.d.ts +0 -3
- package/dist/exceptions/DecoratorException.js +0 -10
- package/dist/exceptions/DecoratorException.js.map +0 -1
- package/dist/exceptions/Exception.d.ts +0 -4
- package/dist/exceptions/Exception.js +0 -10
- package/dist/exceptions/Exception.js.map +0 -1
- package/dist/exceptions/FileNotFoundException.d.ts +0 -3
- package/dist/exceptions/FileNotFoundException.js +0 -10
- package/dist/exceptions/FileNotFoundException.js.map +0 -1
- package/dist/exceptions/FindDependencyException.d.ts +0 -3
- package/dist/exceptions/FindDependencyException.js +0 -10
- package/dist/exceptions/FindDependencyException.js.map +0 -1
- package/dist/exceptions/InvalidEntityException.d.ts +0 -3
- package/dist/exceptions/InvalidEntityException.js +0 -10
- package/dist/exceptions/InvalidEntityException.js.map +0 -1
- package/dist/file/AbstractFileService.d.ts +0 -11
- package/dist/file/AbstractFileService.js +0 -6
- package/dist/file/AbstractFileService.js.map +0 -1
- package/dist/file/AbstractMultiPartRequestService.d.ts +0 -16
- package/dist/file/AbstractMultiPartRequestService.js +0 -12
- package/dist/file/AbstractMultiPartRequestService.js.map +0 -1
- package/dist/file/File.d.ts +0 -5
- package/dist/file/File.js +0 -10
- package/dist/file/File.js.map +0 -1
- package/dist/file/FileService.d.ts +0 -12
- package/dist/file/FileService.js +0 -136
- package/dist/file/FileService.js.map +0 -1
- package/dist/file/FormidableMultiPartRequestService.d.ts +0 -4
- package/dist/file/FormidableMultiPartRequestService.js +0 -73
- package/dist/file/FormidableMultiPartRequestService.js.map +0 -1
- package/dist/index.d.ts +0 -76
- package/dist/index.js +0 -225
- package/dist/index.js.map +0 -1
- package/dist/interfaces/IApplication.d.ts +0 -14
- package/dist/interfaces/IApplication.js +0 -3
- package/dist/interfaces/IApplication.js.map +0 -1
- package/dist/interfaces/IApplicationConfiguration.d.ts +0 -14
- package/dist/interfaces/IApplicationConfiguration.js +0 -3
- package/dist/interfaces/IApplicationConfiguration.js.map +0 -1
- package/dist/interfaces/IController.d.ts +0 -5
- package/dist/interfaces/IController.js +0 -3
- package/dist/interfaces/IController.js.map +0 -1
- package/dist/metadata/FunctionAnalizer.d.ts +0 -9
- package/dist/metadata/FunctionAnalizer.js +0 -57
- package/dist/metadata/FunctionAnalizer.js.map +0 -1
- package/dist/metadata/OwnMetaDataContainer.d.ts +0 -12
- package/dist/metadata/OwnMetaDataContainer.js +0 -33
- package/dist/metadata/OwnMetaDataContainer.js.map +0 -1
- package/dist/metadata/Type.d.ts +0 -7
- package/dist/metadata/Type.js +0 -139
- package/dist/metadata/Type.js.map +0 -1
- package/dist/midlewares/IMidleware.d.ts +0 -19
- package/dist/midlewares/IMidleware.js +0 -3
- package/dist/midlewares/IMidleware.js.map +0 -1
- package/dist/utils/Utils.d.ts +0 -3
- package/dist/utils/Utils.js +0 -11
- package/dist/utils/Utils.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "web_api_base",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "web api base",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,11 +29,10 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/express": "^4.17.15",
|
|
31
31
|
"@types/formidable": "^3.4.5",
|
|
32
|
-
"@types/jest": "^29.
|
|
32
|
+
"@types/jest": "^29.5.13",
|
|
33
33
|
"@types/node": "^18.11.17",
|
|
34
34
|
"@types/reflect-metadata": "^0.1.0",
|
|
35
|
-
"jest": "^29.
|
|
36
|
-
"ts-jest": "^29.
|
|
37
|
-
"ts-node": "^10.9.1"
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"ts-jest": "^29.2.5"
|
|
38
37
|
}
|
|
39
38
|
}
|
package/readme.md
CHANGED
|
@@ -96,10 +96,10 @@ export class SampleService extends SampleServiceAbstract
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export class
|
|
99
|
+
export class GenericService<T>
|
|
100
100
|
{
|
|
101
|
-
public
|
|
102
|
-
console.log("
|
|
101
|
+
public SomeGenericResult<T>(obj : T) {
|
|
102
|
+
console.log("typeof obj: " + typeof obj);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
```
|
|
@@ -111,7 +111,7 @@ We can use the DI service like this
|
|
|
111
111
|
```typescript
|
|
112
112
|
|
|
113
113
|
import { ControllerBase, Route, GET, Inject } from "web_api_base";
|
|
114
|
-
import {SampleServiceAbstract } from '../services/SampleService.ts';
|
|
114
|
+
import {SampleServiceAbstract, GenericService } from '../services/SampleService.ts';
|
|
115
115
|
|
|
116
116
|
@Route()
|
|
117
117
|
export default class SampleController extends ControllerBase
|
|
@@ -119,10 +119,18 @@ export default class SampleController extends ControllerBase
|
|
|
119
119
|
@Inject() // say to DI that this property will be inject on the instance
|
|
120
120
|
public SomeDepency : SampleServiceAbstract;
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
@Inject() // say to DI that this property will be inject on the instance
|
|
123
|
+
//the type argument do not exists on runtime, on .js result files. The DI system will work fine and we
|
|
124
|
+
//will still have the type check on development time
|
|
125
|
+
public SomeGenericDepency : GenericService<string> ;
|
|
126
|
+
|
|
127
|
+
constructor(someDependecy : SampleServiceAbstract, someGenericDepency: GenericService<string>)
|
|
123
128
|
{
|
|
124
129
|
super();
|
|
125
|
-
this.SomeDepency = someDependecy ;
|
|
130
|
+
this.SomeDepency = someDependecy ;
|
|
131
|
+
this.SomeGenericDepency = someGenericDepency;
|
|
132
|
+
this.SomeGenericDepency.SomeGenericresult("Test") // typeof obj: string
|
|
133
|
+
//this.SomeGenericDepency.SomeGenericresult(10) // compiler error
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
@GET()
|
|
@@ -142,7 +150,7 @@ And we can register our dependecies in Application ConfigureAsync method
|
|
|
142
150
|
|
|
143
151
|
import { Application, IApplicationConfiguration} from "web_api_base";
|
|
144
152
|
|
|
145
|
-
import { SampleService, SampleServiceAbstract } from './service/SampleService';
|
|
153
|
+
import { SampleService, SampleServiceAbstract, GenericService } from './service/SampleService';
|
|
146
154
|
|
|
147
155
|
|
|
148
156
|
export default class App extends Application
|
|
@@ -157,8 +165,21 @@ export default class App extends Application
|
|
|
157
165
|
this.UseCors();
|
|
158
166
|
|
|
159
167
|
//DI AddScoped, AddTransient and AddSingleton
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
appConfig.AddScoped(SampleServiceAbstract, SampleService);
|
|
169
|
+
appConfig.AddScoped(GenericService) // will register for all generic type arguments
|
|
170
|
+
|
|
171
|
+
//will register only for GenericService<User>. We need use @InjectTypeArgument(User) on dependecy
|
|
172
|
+
//to work fine
|
|
173
|
+
//appConfig.AddGenericScoped(GenericService, User)
|
|
174
|
+
|
|
175
|
+
//will register only for GenericService<User>. We need use @InjectTypeArgument(User) on dependecy
|
|
176
|
+
//to work fine
|
|
177
|
+
//appConfig.AddGenericScoped(GenericService, undefined, undefined, typeArgument =>
|
|
178
|
+
//{
|
|
179
|
+
// here we can determine how to create the instance. We have access of type argument on typeArgument
|
|
180
|
+
// argument. After this function execution, the instance will pass for DI pipeline to get all
|
|
181
|
+
// dependecies
|
|
182
|
+
//})
|
|
162
183
|
this.UseControllers();
|
|
163
184
|
|
|
164
185
|
}
|
|
@@ -222,13 +243,16 @@ Send a status code and a optional body
|
|
|
222
243
|
Append a delegate to execute **before** the controller´s action
|
|
223
244
|
```typescript
|
|
224
245
|
@Route("/status")
|
|
225
|
-
@UseBefore(context =>
|
|
246
|
+
@UseBefore(async context =>
|
|
226
247
|
{
|
|
227
248
|
|
|
228
249
|
if(context.Request.headers["token"] != "we have access to request object")
|
|
250
|
+
{
|
|
229
251
|
context.Response.json({Message : "we have access to response object"});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
230
254
|
else
|
|
231
|
-
context.Next(); // call next function in the pipeline
|
|
255
|
+
return await context.Next(); // call next function in the pipeline
|
|
232
256
|
})
|
|
233
257
|
export default class StatusController extends ControllerBase
|
|
234
258
|
{
|
|
@@ -238,7 +262,7 @@ export default class StatusController extends ControllerBase
|
|
|
238
262
|
Append a delegate to execute **after** the controller´s action
|
|
239
263
|
```typescript
|
|
240
264
|
@Route("/status")
|
|
241
|
-
@UseAfter(actionResult =>
|
|
265
|
+
@UseAfter(async actionResult =>
|
|
242
266
|
{
|
|
243
267
|
|
|
244
268
|
if(actionResult.Exception) // if a exception was launched
|
package/dist/Application.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Express } from "express";
|
|
2
|
-
import IApplication, { ApplicationExceptionHandler } from "./interfaces/IApplication";
|
|
3
|
-
import IApplicationConfiguration from "./interfaces/IApplicationConfiguration";
|
|
4
|
-
import { ControllerBase } from "./controllers/base/ControllerBase";
|
|
5
|
-
import AbstractMultiPartRequestService from "./file/AbstractMultiPartRequestService";
|
|
6
|
-
export default abstract class Application implements IApplication {
|
|
7
|
-
static Configurations: IApplicationConfiguration;
|
|
8
|
-
private _createdControllers;
|
|
9
|
-
private _URIs;
|
|
10
|
-
ApplicationConfiguration: IApplicationConfiguration;
|
|
11
|
-
Express: Express;
|
|
12
|
-
ApplicationThreadExeptionHandler?: ApplicationExceptionHandler;
|
|
13
|
-
constructor();
|
|
14
|
-
StartAsync(): Promise<void>;
|
|
15
|
-
protected UseCors(): void;
|
|
16
|
-
private GetIgnoredPaths;
|
|
17
|
-
private TryFindControllerFolder;
|
|
18
|
-
protected UseControllersAsync(root?: string): Promise<void>;
|
|
19
|
-
protected UseCustomMultiPartRequestHandler<T extends AbstractMultiPartRequestService>(cTor: new (...args: any[]) => T): void;
|
|
20
|
-
protected AppendController<T extends ControllerBase>(ctor: {
|
|
21
|
-
new (...args: any[]): T;
|
|
22
|
-
}): void;
|
|
23
|
-
CreateDocumentation(): void;
|
|
24
|
-
private SendResponseIfNecessary;
|
|
25
|
-
private CastToExpection;
|
|
26
|
-
private CallErrorHandler;
|
|
27
|
-
abstract ConfigureAsync(appConfig: IApplicationConfiguration): Promise<void>;
|
|
28
|
-
}
|