@expressots/adapter-express 1.8.2 → 3.0.0-beta.2

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.
Files changed (49) hide show
  1. package/lib/CHANGELOG.md +168 -139
  2. package/lib/cjs/adapter-express/application-express.base.js +2 -12
  3. package/lib/cjs/adapter-express/application-express.js +132 -52
  4. package/lib/cjs/adapter-express/application-express.types.js +0 -20
  5. package/lib/cjs/adapter-express/express-utils/base-middleware.js +2 -2
  6. package/lib/cjs/adapter-express/express-utils/constants.js +1 -3
  7. package/lib/cjs/adapter-express/express-utils/decorators.js +26 -12
  8. package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +10 -5
  9. package/lib/cjs/adapter-express/express-utils/utils.js +3 -0
  10. package/lib/cjs/adapter-express/index.js +4 -1
  11. package/lib/cjs/adapter-express/micro-api/application-express-micro-container.js +51 -0
  12. package/lib/cjs/adapter-express/micro-api/application-express-micro-route.js +101 -0
  13. package/lib/cjs/adapter-express/micro-api/application-express-micro.js +177 -0
  14. package/lib/cjs/adapter-express/micro-api/index.js +5 -0
  15. package/lib/cjs/adapter-express/render/constants.js +40 -0
  16. package/lib/cjs/adapter-express/render/engine.js +52 -11
  17. package/lib/cjs/adapter-express/render/index.js +0 -3
  18. package/lib/cjs/di/di.interfaces.js +10 -0
  19. package/lib/cjs/types/adapter-express/application-express.base.d.ts +17 -0
  20. package/lib/cjs/types/adapter-express/application-express.d.ts +58 -23
  21. package/lib/cjs/types/adapter-express/application-express.types.d.ts +1 -41
  22. package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts +1 -1
  23. package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +1 -1
  24. package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +18 -4
  25. package/lib/cjs/types/adapter-express/express-utils/http-status-middleware.d.ts +2 -0
  26. package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts +1 -1
  27. package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts +1 -1
  28. package/lib/cjs/types/adapter-express/express-utils/utils.d.ts +1 -1
  29. package/lib/cjs/types/adapter-express/index.d.ts +2 -2
  30. package/lib/cjs/types/adapter-express/micro-api/application-express-micro-container.d.ts +47 -0
  31. package/lib/cjs/types/adapter-express/micro-api/application-express-micro-route.d.ts +93 -0
  32. package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +79 -0
  33. package/lib/cjs/types/adapter-express/micro-api/index.d.ts +1 -0
  34. package/lib/cjs/types/adapter-express/render/constants.d.ts +26 -0
  35. package/lib/cjs/types/adapter-express/render/engine.d.ts +14 -22
  36. package/lib/cjs/types/adapter-express/render/index.d.ts +4 -4
  37. package/lib/cjs/types/di/di.interfaces.d.ts +289 -0
  38. package/lib/package.json +11 -16
  39. package/package.json +11 -16
  40. package/lib/cjs/adapter-express/application-express.interface.js +0 -2
  41. package/lib/cjs/adapter-express/render/ejs/ejs.config.js +0 -37
  42. package/lib/cjs/adapter-express/render/ejs/ejs.types.js +0 -3
  43. package/lib/cjs/adapter-express/render/handlebars/hbs.config.js +0 -38
  44. package/lib/cjs/adapter-express/render/pug/pug.config.js +0 -25
  45. package/lib/cjs/types/adapter-express/application-express.interface.d.ts +0 -20
  46. package/lib/cjs/types/adapter-express/render/ejs/ejs.config.d.ts +0 -21
  47. package/lib/cjs/types/adapter-express/render/ejs/ejs.types.d.ts +0 -169
  48. package/lib/cjs/types/adapter-express/render/handlebars/hbs.config.d.ts +0 -20
  49. package/lib/cjs/types/adapter-express/render/pug/pug.config.d.ts +0 -17
@@ -2,67 +2,75 @@ import "reflect-metadata";
2
2
  import { PARAMETER_TYPE, HTTP_VERBS_ENUM } from "./constants";
3
3
  import type { HandlerDecorator, Middleware } from "./interfaces";
4
4
  import { Request } from "express";
5
- export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol | undefined, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<unknown>) => void;
5
+ export declare const injectHttpContext: (target: import("@expressots/core/lib/cjs/types/di/annotation/decorator_utils").DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<unknown>) => void;
6
6
  /**
7
7
  * Controller decorator to define a new controller
8
8
  * @param path route path
9
9
  * @param middleware array of middleware to be applied to all routes in the controller
10
+ * @public API
10
11
  */
11
12
  export declare function controller(path: string, ...middleware: Array<Middleware>): (target: NewableFunction) => void;
12
13
  /**
13
14
  * Http decorator to define the status code for a route
14
15
  * @param code
15
16
  * @returns MethodDecorator
16
- * @example
17
- * ```ts
17
+ * @example ```typescript
18
18
  * @Http(200)
19
19
  * @Get("/")
20
20
  * hello() {
21
21
  * return "Hello World";
22
22
  * }
23
23
  * ```
24
+ * @public API
24
25
  */
25
26
  export declare function Http(code: number): (target: object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
26
27
  /**
27
28
  * Decorator to allow accept all HTTP methods
28
29
  * @param path route path, wildcard
29
30
  * @param middleware array of middleware to be applied to all routes defined in path logic
31
+ * @public API
30
32
  */
31
33
  export declare function All(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
32
34
  /**
33
35
  * Decorator to allow GET HTTP method
34
36
  * @param path route path
35
37
  * @param middleware array of middleware to be applied to the route
38
+ * @public API
36
39
  */
37
40
  export declare function Get(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
38
41
  /**
39
42
  * Decorator to allow POST HTTP method
40
43
  * @param path route path
41
44
  * @param middleware array of middleware to be applied to the route
45
+ * @public API
42
46
  */
43
47
  export declare function Post(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
44
48
  /**
45
49
  * Decorator to allow PUT HTTP method
46
50
  * @param path route path
47
51
  * @param middleware array of middleware to be applied to the route
52
+ * @public API
48
53
  */
49
54
  export declare function Put(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
50
55
  /**
51
56
  * Decorator to allow PATCH HTTP method
52
57
  * @param path route path
53
58
  * @param middleware array of middleware to be applied to the route
59
+ * @public API
54
60
  */
55
61
  export declare function Patch(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
56
62
  /**
57
63
  * Decorator to allow HEAD HTTP method
58
64
  * @param path route path
59
65
  * @param middleware array of middleware to be applied to the route
66
+ * @public API
60
67
  */
61
68
  export declare function Head(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
62
69
  /**
63
70
  * Decorator to allow DELETE HTTP method
64
71
  * @param path route path
65
72
  * @param middleware array of middleware to be applied to the route
73
+ * @public API
66
74
  */
67
75
  export declare function Delete(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
68
76
  /**
@@ -70,6 +78,7 @@ export declare function Delete(path: string, ...middleware: Array<Middleware>):
70
78
  * @param method custom HTTP method
71
79
  * @param path route path
72
80
  * @param middleware array of middleware to be applied to the route
81
+ * @public API
73
82
  */
74
83
  export declare function Method(method: keyof typeof HTTP_VERBS_ENUM, path: string, ...middleware: Array<Middleware>): HandlerDecorator;
75
84
  /**
@@ -120,13 +129,17 @@ export declare const principal: () => ParameterDecorator;
120
129
  /**
121
130
  * Parameter decorator to inject the request object
122
131
  * @returns ParameterDecorator
132
+ * @param type - The type of parameter to inject
133
+ * @param parameterName - The name of the parameter to inject
134
+ * @public API
123
135
  */
124
136
  export declare function params(type: PARAMETER_TYPE, parameterName?: string): ParameterDecorator;
125
137
  /**
126
138
  * Render decorator to define the template and default data for a route
127
139
  * @param template The template to render
128
140
  * @param defaultData The default data to pass to the template
129
- * @returns
141
+ * @returns MethodDecorator
142
+ * @public API
130
143
  */
131
144
  export declare function Render(template: string, defaultData?: Record<string, unknown>): MethodDecorator;
132
145
  export declare function getRenderMetadata(target: object, propertyKey: string | symbol): {
@@ -187,6 +200,7 @@ type FieldOptions = {
187
200
  * @param multerOptions
188
201
  * @default { none: true }
189
202
  * @returns MethodDecorator
203
+ * @public API
190
204
  */
191
205
  export declare function FileUpload(options?: FieldOptions | Array<FieldOptions> | {
192
206
  none?: boolean;
@@ -6,6 +6,8 @@ import { ExpressoMiddleware } from "@expressots/core";
6
6
  * @returns express.RequestHandler
7
7
  */
8
8
  export declare class HttpStatusCodeMiddleware extends ExpressoMiddleware {
9
+ private globalPrefix;
10
+ constructor(globalPrefix?: string);
9
11
  use(req: Request, res: Response, next: NextFunction): void | Promise<void>;
10
12
  /**
11
13
  * Find the matching parameter path.
@@ -1,5 +1,5 @@
1
1
  import type { Application, NextFunction, Request, RequestHandler, Response } from "express";
2
- import { interfaces as inversifyInterfaces } from "inversify";
2
+ import { interfaces as inversifyInterfaces } from "../../di/di.interfaces";
3
3
  import { HTTP_VERBS_ENUM, PARAMETER_TYPE } from "./constants";
4
4
  import { HttpResponseMessage } from "./httpResponseMessage";
5
5
  type Prototype<T> = {
@@ -1,5 +1,5 @@
1
1
  import express, { Application, Router } from "express";
2
- import { interfaces } from "inversify";
2
+ import { interfaces } from "../../di/di.interfaces";
3
3
  import type { AuthProvider, ConfigFunction, RoutingConfig } from "./interfaces";
4
4
  export declare class InversifyExpressServer {
5
5
  private _router;
@@ -1,4 +1,4 @@
1
- import { interfaces } from "inversify";
1
+ import { interfaces } from "../../di/di.interfaces";
2
2
  import type { BaseController, ControllerMetadata, ControllerMethodMetadata, ControllerParameterMetadata, DecoratorTarget, IHttpActionResult } from "./interfaces";
3
3
  export declare function getControllersFromContainer(container: interfaces.Container, forceControllers: boolean): Array<BaseController>;
4
4
  export declare function getControllersFromMetadata(): Array<DecoratorTarget>;
@@ -1,5 +1,5 @@
1
1
  export * from "./express-utils";
2
2
  export { AppExpress } from "./application-express";
3
- export { IWebServerPublic } from "./application-express.interface";
4
- export { IWebServer, IWebServerConstructor } from "./application-express.types";
3
+ export * from "./micro-api";
4
+ export { IWebServerPublic, IWebServer, IWebServerConstructor, Environment, IEnvironment, RenderEngine, } from "@expressots/shared";
5
5
  export * from "./render";
@@ -0,0 +1,47 @@
1
+ import { interfaces } from "@expressots/core";
2
+ /**
3
+ * Inversion of Control Container interface
4
+ * @public API
5
+ */
6
+ export interface IIOC {
7
+ addSingleton<T>(concrete: interfaces.Newable<T>): void;
8
+ addTransient<T>(concrete: interfaces.Newable<T>): void;
9
+ addScoped<T>(concrete: interfaces.Newable<T>): void;
10
+ get<I>(identifier: interfaces.ServiceIdentifier<I>): I;
11
+ }
12
+ /**
13
+ * Inversion of Control Container
14
+ * @public API
15
+ */
16
+ export declare class IOC {
17
+ private container;
18
+ constructor(containerOptions?: interfaces.ContainerOptions);
19
+ /**
20
+ * Add a singleton to the container
21
+ * @param identifierOrConcrete - The identifier or concrete class
22
+ * @param concrete - The concrete class if identifier is provided
23
+ * @public API
24
+ */
25
+ addSingleton<T>(concrete: interfaces.Newable<T>): void;
26
+ /**
27
+ * Add a transient to the container
28
+ * @param identifierOrConcrete - The identifier or concrete class
29
+ * @param concrete - The concrete class if identifier is provided
30
+ * @public API
31
+ */
32
+ addTransient<T>(concrete: interfaces.Newable<T>): void;
33
+ /**
34
+ * Add a scoped to the container
35
+ * @param identifierOrConcrete - The identifier or concrete class
36
+ * @param concrete - The concrete class if identifier is provided
37
+ * @public API
38
+ */
39
+ addScoped<T>(concrete: interfaces.Newable<T>): void;
40
+ /**
41
+ * Get an instance from the container
42
+ * @param identifier - The identifier for the instance
43
+ * @returns The resolved instance
44
+ * @public API
45
+ */
46
+ get(identifier: interfaces.ServiceIdentifier): any;
47
+ }
@@ -0,0 +1,93 @@
1
+ import express from "express";
2
+ import { Middleware } from "../express-utils/interfaces";
3
+ type RouteDefinition = {
4
+ method: "get" | "post" | "put" | "patch" | "delete";
5
+ path: string;
6
+ handler: express.RequestHandler;
7
+ middleware: Array<Middleware>;
8
+ };
9
+ /**
10
+ * Route manager for Express Micro API adapter
11
+ * @public API
12
+ */
13
+ export interface IRoute {
14
+ define(method: "get" | "post" | "put" | "delete" | "patch", path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
15
+ get(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
16
+ post(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
17
+ put(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
18
+ delete(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
19
+ patch(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
20
+ }
21
+ export declare class Route implements IRoute {
22
+ private logger;
23
+ private routes;
24
+ private app;
25
+ private globalPrefix;
26
+ constructor(app: express.Application);
27
+ /**
28
+ * Set the global route prefix
29
+ * @param prefix
30
+ * @public API
31
+ */
32
+ setGlobalRoutePrefix(prefix: string): void;
33
+ /**
34
+ * Define a route
35
+ * @param method - HTTP method
36
+ * @param path - Route path
37
+ * @param handler - Route handler
38
+ * @param middleware - Route middleware
39
+ * @public API
40
+ */
41
+ define(method: "get" | "post" | "put" | "delete" | "patch", path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
42
+ /**
43
+ * Define a GET route
44
+ * @param path - Route path
45
+ * @param handler - Route handler
46
+ * @param middleware - Route middleware
47
+ * @public API
48
+ */
49
+ get(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
50
+ /**
51
+ * Define a POST route
52
+ * @param path - Route path
53
+ * @param handler - Route handler
54
+ * @param middleware - Route middleware
55
+ * @public API
56
+ */
57
+ post(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
58
+ /**
59
+ * Define a PUT route
60
+ * @param path - Route path
61
+ * @param handler - Route handler
62
+ * @param middleware - Route middleware
63
+ * @public API
64
+ */
65
+ put(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
66
+ /**
67
+ * Define a DELETE route
68
+ * @param path - Route path
69
+ * @param handler - Route handler
70
+ * @param middleware - Route middleware
71
+ * @public API
72
+ */
73
+ delete(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
74
+ /**
75
+ * Define a PATCH route
76
+ * @param path - Route path
77
+ * @param handler - Route handler
78
+ * @param middleware - Route middleware
79
+ * @public API
80
+ */
81
+ patch(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
82
+ /**
83
+ * Apply the routes to the Express application
84
+ */
85
+ applyRoutes(): void;
86
+ /**
87
+ * Get the routes
88
+ * @returns Array of route definitions
89
+ * @public API
90
+ */
91
+ get Routes(): Array<RouteDefinition>;
92
+ }
93
+ export {};
@@ -0,0 +1,79 @@
1
+ import { IMiddleware, interfaces } from "@expressots/core";
2
+ import { Env, IConsoleMessage } from "@expressots/shared";
3
+ import express from "express";
4
+ import { IIOC } from "./application-express-micro-container";
5
+ import { IRoute } from "./application-express-micro-route";
6
+ /**
7
+ * Configuration options for the Express Micro API adapter
8
+ * @public API
9
+ */
10
+ export type MicroAPIConfig = {
11
+ containerOptions: interfaces.ContainerOptions;
12
+ };
13
+ /**
14
+ * Interface for the Create Method of Express Micro API adapter
15
+ */
16
+ export interface ICreateMicroAPI {
17
+ /**
18
+ * Initialize the environment for the application
19
+ * @param environment - The environment to initialize
20
+ * @param options - Options for the environment initialization
21
+ * @public API
22
+ */
23
+ initEnvironment(environment: Env.Environment, options?: Env.IEnvironment): void;
24
+ /**
25
+ * Set the global route prefix
26
+ * @param prefix - The global route prefix
27
+ * @public API
28
+ */
29
+ setGlobalRoutePrefix(prefix: string): void;
30
+ /**
31
+ * Get the Container instance
32
+ * @returns IIOC - The container instance interface
33
+ * @public API
34
+ */
35
+ get Container(): IIOC;
36
+ /**
37
+ * Get the Express HTTP Server instance
38
+ * @returns express.Application
39
+ * @public API
40
+ */
41
+ getHttpServer(): express.Application;
42
+ /**
43
+ * Build the Web Server Micro API
44
+ * @returns IWebServerMicroAPI
45
+ * @public API
46
+ */
47
+ build(): IWebServerMicroAPI;
48
+ }
49
+ /**
50
+ * Interface for the Build Method of the Web Server Micro API adapter
51
+ */
52
+ export interface IWebServerMicroAPI {
53
+ /**
54
+ * Get the Middleware instance
55
+ * @returns IMiddleware
56
+ * @public API
57
+ */
58
+ get Middleware(): IMiddleware;
59
+ /**
60
+ * Get the Route instance
61
+ * @returns IRoute
62
+ * @public API
63
+ */
64
+ get Route(): IRoute;
65
+ /**
66
+ * Listen for incoming requests
67
+ * @param port - The port to listen on
68
+ * @param appInfo - Information about the application
69
+ * @public API
70
+ */
71
+ listen(port: number | string, appInfo?: IConsoleMessage): Promise<void>;
72
+ }
73
+ /**
74
+ * Create a new instance of the Express Micro API adapter
75
+ * @param config - Configuration options
76
+ * @returns ICreateMicroAPI
77
+ * @public API
78
+ */
79
+ export declare function createMicroAPI(config?: MicroAPIConfig): ICreateMicroAPI;
@@ -0,0 +1 @@
1
+ export { createMicroAPI, MicroAPIConfig } from "./application-express-micro";
@@ -0,0 +1,26 @@
1
+ import { RenderEngine } from "@expressots/shared";
2
+ /**
3
+ * Ejs defaults
4
+ * @type {EjsOptions}
5
+ * @constant
6
+ * @default
7
+ */
8
+ export declare const EJS_DEFAULTS: RenderEngine.EjsOptions;
9
+ /**
10
+ * Handlebars defaults
11
+ * @type {HandlebarsOptions}
12
+ * @constant
13
+ * @default
14
+ */
15
+ export declare const HANDLEBARS_DEFAULTS: RenderEngine.HandlebarsOptions;
16
+ /**
17
+ * Default partials directory
18
+ */
19
+ export declare const DEFAULT_PARTIALS_DIR: string;
20
+ /**
21
+ * Pug defaults
22
+ * @type {PugOptions}
23
+ * @constant
24
+ * @default
25
+ */
26
+ export declare const PUG_DEFAULTS: RenderEngine.PugOptions;
@@ -1,28 +1,20 @@
1
- import { EjsOptions } from "./ejs/ejs.config";
2
- import { HandlebarsOptions } from "./handlebars/hbs.config";
1
+ import { Application } from "express";
2
+ import { RenderEngine } from "@expressots/shared";
3
3
  /**
4
- * The configuration options for the view engine.
5
- * @typedef {HandlebarsOptions | EjsOptions} EngineOptions
6
- * @private
4
+ * Set Ejs as the view engine
5
+ * @param {Application} app - The express application
6
+ * @param {EjsOptions} [options=EJS_DEFAULTS] - The ejs options
7
7
  */
8
- export type RenderOptions = {
9
- engine: Engine;
10
- options?: EngineOptions;
11
- };
8
+ export declare function setEngineEjs(app: Application, options?: RenderEngine.EjsOptions): Promise<void>;
12
9
  /**
13
- * The supported view engines.
14
- * @enum {string}
15
- * @readonly
16
- * @public
10
+ * Set Handlebars as the view engine
11
+ * @param {express.Application} app - The express application
12
+ * @param {HandlebarsOptions} [options=HANDLEBARS_DEFAULTS] - The handlebars options
17
13
  */
18
- export declare enum Engine {
19
- HBS = "hbs",
20
- EJS = "ejs",
21
- PUG = "pug"
22
- }
14
+ export declare function setEngineHandlebars(app: Application, options?: RenderEngine.HandlebarsOptions): Promise<void>;
23
15
  /**
24
- * The configuration options for the view engine.
25
- * @typedef {HandlebarsOptions | EjsOptions} EngineOptions
26
- * @public
16
+ * Set Pug as the view engine
17
+ * @param {express.Application} app - The express application
18
+ * @param {PugOptions} [options=PUG_DEFAULTS] - The pug options
27
19
  */
28
- export type EngineOptions = HandlebarsOptions | EjsOptions;
20
+ export declare function setEnginePug(app: Application, options?: RenderEngine.PugOptions): Promise<void>;
@@ -1,4 +1,4 @@
1
- export { EjsOptions as EJS } from "./ejs/ejs.config";
2
- export { HandlebarsOptions as HBS } from "./handlebars/hbs.config";
3
- export { PugOptions as PUG } from "./pug/pug.config";
4
- export { Engine } from "./engine";
1
+ import { RenderEngine } from "@expressots/shared";
2
+ export type EJS = RenderEngine.EjsOptions;
3
+ export type HBS = RenderEngine.HandlebarsOptions;
4
+ export type PUG = RenderEngine.PugOptions;