@expressots/core 2.16.2 → 3.0.0-beta.3
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/README.md +2 -2
- package/lib/CHANGELOG.md +321 -321
- package/lib/README.md +2 -2
- package/lib/cjs/application/application-container.js +18 -21
- package/lib/cjs/application/application-factory.js +4 -5
- package/lib/cjs/{common/server-env.types.js → application/application.types.js} +1 -0
- package/lib/cjs/application/index.js +3 -1
- package/lib/cjs/console/console.js +8 -20
- package/lib/cjs/container-module/container-module.js +10 -18
- package/lib/cjs/decorator/scope-binding.js +12 -11
- package/lib/cjs/di/annotation/decorator_utils.js +121 -0
- package/lib/cjs/di/annotation/inject.js +44 -0
- package/lib/cjs/di/annotation/inject_base.js +17 -0
- package/lib/cjs/di/annotation/injectable.js +44 -0
- package/lib/cjs/di/annotation/lazy_service_identifier.js +12 -0
- package/lib/cjs/di/annotation/multi_inject.js +30 -0
- package/lib/cjs/di/annotation/named.js +34 -0
- package/lib/cjs/di/annotation/optional.js +32 -0
- package/lib/cjs/di/annotation/post_construct.js +31 -0
- package/lib/cjs/di/annotation/pre_destroy.js +31 -0
- package/lib/cjs/di/annotation/property_event_decorator.js +15 -0
- package/lib/cjs/di/annotation/tagged.js +9 -0
- package/lib/cjs/di/annotation/target_name.js +35 -0
- package/lib/cjs/di/annotation/unmanaged.js +35 -0
- package/lib/cjs/di/binding-decorator/constants.js +7 -0
- package/lib/cjs/di/binding-decorator/decorator/fluent_provide.js +20 -0
- package/lib/cjs/di/binding-decorator/decorator/provide.js +37 -0
- package/lib/cjs/di/binding-decorator/factory/module_factory.js +17 -0
- package/lib/cjs/di/binding-decorator/index.js +14 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_done_syntax.js +42 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_in_syntax.js +33 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_in_when_on_syntax.js +64 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_on_syntax.js +22 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_when_on_syntax.js +57 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_when_syntax.js +89 -0
- package/lib/cjs/di/binding-decorator/utils/auto_wire.js +18 -0
- package/lib/cjs/di/bindings/binding.js +40 -0
- package/lib/cjs/di/bindings/binding_count.js +8 -0
- package/lib/cjs/di/constants/error_msgs.js +60 -0
- package/lib/cjs/di/constants/literal_types.js +26 -0
- package/lib/cjs/di/constants/metadata_keys.js +38 -0
- package/lib/cjs/di/container/container.js +521 -0
- package/lib/cjs/di/container/container_module.js +18 -0
- package/lib/cjs/di/container/container_snapshot.js +15 -0
- package/lib/cjs/di/container/lookup.js +132 -0
- package/lib/cjs/di/container/module_activation_store.js +49 -0
- package/lib/cjs/di/interfaces/interfaces.js +2 -0
- package/lib/cjs/di/inversify.js +78 -0
- package/lib/cjs/di/planning/context.js +17 -0
- package/lib/cjs/di/planning/metadata.js +42 -0
- package/lib/cjs/di/planning/metadata_reader.js +45 -0
- package/lib/cjs/di/planning/plan.js +10 -0
- package/lib/cjs/di/planning/planner.js +186 -0
- package/lib/cjs/di/planning/queryable_string.js +27 -0
- package/lib/cjs/di/planning/reflection_utils.js +178 -0
- package/lib/cjs/di/planning/request.js +23 -0
- package/lib/cjs/di/planning/target.js +108 -0
- package/lib/cjs/di/resolution/instantiation.js +150 -0
- package/lib/cjs/di/resolution/resolver.js +188 -0
- package/lib/cjs/di/scope/scope.js +50 -0
- package/lib/cjs/di/syntax/binding_in_syntax.js +23 -0
- package/lib/cjs/di/syntax/binding_in_when_on_syntax.js +75 -0
- package/lib/cjs/di/syntax/binding_on_syntax.js +18 -0
- package/lib/cjs/di/syntax/binding_to_syntax.js +111 -0
- package/lib/cjs/di/syntax/binding_when_on_syntax.js +64 -0
- package/lib/cjs/di/syntax/binding_when_syntax.js +84 -0
- package/lib/cjs/di/syntax/constraint_helpers.js +68 -0
- package/lib/cjs/di/utils/async.js +15 -0
- package/lib/cjs/di/utils/binding_utils.js +77 -0
- package/lib/cjs/di/utils/clonable.js +9 -0
- package/lib/cjs/di/utils/exceptions.js +46 -0
- package/lib/cjs/di/utils/factory_type.js +9 -0
- package/lib/cjs/di/utils/id.js +7 -0
- package/lib/cjs/di/utils/js.js +15 -0
- package/lib/cjs/di/utils/serialization.js +132 -0
- package/lib/cjs/error/app-error.js +5 -2
- package/lib/cjs/error/report.js +24 -15
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/middleware/middleware-interface.js +2 -0
- package/lib/cjs/middleware/middleware-service.js +9 -24
- package/lib/cjs/provider/db-in-memory/base-repo.repository.js +29 -88
- package/lib/cjs/provider/db-in-memory/db-in-memory.interface.js +2 -0
- package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +92 -60
- package/lib/cjs/provider/db-in-memory/db-in-memory.types.js +25 -0
- package/lib/cjs/provider/db-in-memory/index.js +11 -0
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +4 -4
- package/lib/cjs/provider/dto-validator/package-resolver.js +56 -0
- package/lib/cjs/provider/environment/env-validator.provider.js +14 -12
- package/lib/cjs/provider/index.js +16 -5
- package/lib/cjs/provider/logger/logger.provider.js +10 -5
- package/lib/cjs/provider/provider-manager.js +72 -29
- package/lib/cjs/types/application/application-container.d.ts +12 -25
- package/lib/cjs/types/application/application-factory.d.ts +10 -7
- package/lib/cjs/types/{common/server-env.types.d.ts → application/application.types.d.ts} +1 -0
- package/lib/cjs/types/application/index.d.ts +1 -0
- package/lib/cjs/types/console/console.d.ts +3 -10
- package/lib/cjs/types/console/index.d.ts +2 -1
- package/lib/cjs/types/container-module/container-module.d.ts +3 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts +9 -9
- package/lib/cjs/types/di/annotation/decorator_utils.d.ts +16 -0
- package/lib/cjs/types/di/annotation/inject.d.ts +16 -0
- package/lib/cjs/types/di/annotation/inject_base.d.ts +3 -0
- package/lib/cjs/types/di/annotation/injectable.d.ts +7 -0
- package/lib/cjs/types/di/annotation/lazy_service_identifier.d.ts +7 -0
- package/lib/cjs/types/di/annotation/multi_inject.d.ts +2 -0
- package/lib/cjs/types/di/annotation/named.d.ts +2 -0
- package/lib/cjs/types/di/annotation/optional.d.ts +2 -0
- package/lib/cjs/types/di/annotation/post_construct.d.ts +4 -0
- package/lib/cjs/types/di/annotation/pre_destroy.d.ts +4 -0
- package/lib/cjs/types/di/annotation/property_event_decorator.d.ts +4 -0
- package/lib/cjs/types/di/annotation/tagged.d.ts +2 -0
- package/lib/cjs/types/di/annotation/target_name.d.ts +3 -0
- package/lib/cjs/types/di/annotation/unmanaged.d.ts +3 -0
- package/lib/cjs/types/di/binding-decorator/constants.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/decorator/fluent_provide.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/decorator/provide.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/factory/module_factory.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/index.d.ts +8 -0
- package/lib/cjs/types/di/binding-decorator/interfaces/interfaces.d.ts +39 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_done_syntax.d.ts +7 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_in_syntax.d.ts +11 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_in_when_on_syntax.d.ts +27 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_on_syntax.d.ts +10 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_when_on_syntax.d.ts +24 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_when_syntax.d.ts +23 -0
- package/lib/cjs/types/di/binding-decorator/utils/auto_wire.d.ts +3 -0
- package/lib/cjs/types/di/bindings/binding.d.ts +20 -0
- package/lib/cjs/types/di/bindings/binding_count.d.ts +5 -0
- package/lib/cjs/types/di/constants/error_msgs.d.ts +32 -0
- package/lib/cjs/types/di/constants/literal_types.d.ts +5 -0
- package/lib/cjs/types/di/constants/metadata_keys.d.ts +13 -0
- package/lib/cjs/types/di/container/container.d.ts +73 -0
- package/lib/cjs/types/di/container/container_module.d.ts +11 -0
- package/lib/cjs/types/di/container/container_snapshot.d.ts +10 -0
- package/lib/cjs/types/di/container/lookup.d.ts +16 -0
- package/lib/cjs/types/di/container/module_activation_store.d.ts +10 -0
- package/lib/cjs/types/di/interfaces/interfaces.d.ts +299 -0
- package/lib/cjs/types/di/inversify.d.ts +25 -0
- package/lib/cjs/types/di/planning/context.d.ts +11 -0
- package/lib/cjs/types/di/planning/metadata.d.ts +8 -0
- package/lib/cjs/types/di/planning/metadata_reader.d.ts +6 -0
- package/lib/cjs/types/di/planning/plan.d.ts +7 -0
- package/lib/cjs/types/di/planning/planner.d.ts +5 -0
- package/lib/cjs/types/di/planning/queryable_string.d.ts +11 -0
- package/lib/cjs/types/di/planning/reflection_utils.d.ts +5 -0
- package/lib/cjs/types/di/planning/request.d.ts +14 -0
- package/lib/cjs/types/di/planning/target.d.ts +23 -0
- package/lib/cjs/types/di/resolution/instantiation.d.ts +3 -0
- package/lib/cjs/types/di/resolution/resolver.d.ts +3 -0
- package/lib/cjs/types/di/scope/scope.d.ts +3 -0
- package/lib/cjs/types/di/syntax/binding_in_syntax.d.ts +9 -0
- package/lib/cjs/types/di/syntax/binding_in_when_on_syntax.d.ts +29 -0
- package/lib/cjs/types/di/syntax/binding_on_syntax.d.ts +8 -0
- package/lib/cjs/types/di/syntax/binding_to_syntax.d.ts +18 -0
- package/lib/cjs/types/di/syntax/binding_when_on_syntax.d.ts +25 -0
- package/lib/cjs/types/di/syntax/binding_when_syntax.d.ts +21 -0
- package/lib/cjs/types/di/syntax/constraint_helpers.d.ts +6 -0
- package/lib/cjs/types/di/utils/async.d.ts +3 -0
- package/lib/cjs/types/di/utils/binding_utils.d.ts +4 -0
- package/lib/cjs/types/di/utils/clonable.d.ts +3 -0
- package/lib/cjs/types/di/utils/exceptions.d.ts +2 -0
- package/lib/cjs/types/di/utils/factory_type.d.ts +5 -0
- package/lib/cjs/types/di/utils/id.d.ts +2 -0
- package/lib/cjs/types/di/utils/js.d.ts +1 -0
- package/lib/cjs/types/di/utils/serialization.d.ts +10 -0
- package/lib/cjs/types/error/report.d.ts +7 -5
- package/lib/cjs/types/index.d.ts +1 -2
- package/lib/cjs/types/middleware/index.d.ts +2 -1
- package/lib/cjs/types/middleware/middleware-interface.d.ts +185 -0
- package/lib/cjs/types/middleware/middleware-service.d.ts +11 -163
- package/lib/cjs/types/provider/db-in-memory/base-repo.repository.d.ts +15 -60
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.interface.d.ts +43 -0
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +25 -35
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.types.d.ts +14 -0
- package/lib/cjs/types/provider/db-in-memory/index.d.ts +4 -0
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +2 -3
- package/lib/cjs/types/{common → provider/dto-validator}/package-resolver.d.ts +1 -2
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +7 -3
- package/lib/cjs/types/provider/index.d.ts +1 -2
- package/lib/cjs/types/provider/logger/logger.provider.d.ts +5 -0
- package/lib/cjs/types/provider/provider-manager.d.ts +46 -6
- package/lib/package.json +9 -15
- package/package.json +9 -15
- package/lib/cjs/common/index.js +0 -5
- package/lib/cjs/common/package-resolver.js +0 -34
- package/lib/cjs/controller/base-controller.js +0 -63
- package/lib/cjs/controller/index.js +0 -5
- package/lib/cjs/types/common/index.d.ts +0 -2
- package/lib/cjs/types/common/project-config.d.ts +0 -56
- package/lib/cjs/types/controller/base-controller.d.ts +0 -32
- package/lib/cjs/types/controller/index.d.ts +0 -1
- /package/lib/cjs/{common → console}/color-codes.js +0 -0
- /package/lib/cjs/{common/project-config.js → di/binding-decorator/interfaces/interfaces.js} +0 -0
- /package/lib/cjs/types/{common → console}/color-codes.d.ts +0 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { IProvider } from "../provider";
|
|
1
2
|
import { AppError } from "./app-error";
|
|
2
3
|
/**
|
|
3
4
|
* Report class is a utility class to manage and log errors within the application.
|
|
4
5
|
* It is responsible for creating a standardized error object, logging it,
|
|
5
6
|
* and then throwing the error for further handling.
|
|
6
7
|
*/
|
|
7
|
-
declare class Report {
|
|
8
|
+
export declare class Report implements IProvider {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
author: string;
|
|
12
|
+
repo: string;
|
|
8
13
|
static stack: string;
|
|
9
|
-
private logger;
|
|
10
|
-
constructor();
|
|
11
14
|
/**
|
|
12
15
|
* The Error method is responsible for generating a standardized error object,
|
|
13
16
|
* logging the error, and then throwing it for further handling.
|
|
@@ -20,6 +23,5 @@ declare class Report {
|
|
|
20
23
|
*
|
|
21
24
|
* @throws An object of the custom type AppError, which includes details about the error.
|
|
22
25
|
*/
|
|
23
|
-
error(error: Error | string, statusCode?: number, service?: string): AppError;
|
|
26
|
+
error(error: Error | string | object | any, statusCode?: number, service?: string): AppError;
|
|
24
27
|
}
|
|
25
|
-
export { Report };
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from "./application";
|
|
2
|
-
export * from "./common";
|
|
3
2
|
export * from "./console";
|
|
4
3
|
export * from "./container-module";
|
|
5
|
-
export * from "./controller";
|
|
6
4
|
export * from "./decorator";
|
|
7
5
|
export * from "./error";
|
|
8
6
|
export * from "./middleware";
|
|
9
7
|
export * from "./provider";
|
|
8
|
+
export * from "./di/inversify";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Middleware, ExpressHandler, ExpressoMiddleware, MiddlewareOptions, } from "./middleware-service";
|
|
2
|
+
export { ErrorHandlerOptions, IMiddleware } from "./middleware-interface";
|
|
2
3
|
export { OptionsJson } from "./interfaces/body-parser.interface";
|
|
3
4
|
export { CorsOptions } from "./interfaces/cors.interface";
|
|
4
5
|
export { CompressionOptions } from "./interfaces/compression.interface";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ExpressHandler, MiddlewareOptions } from "./middleware-service";
|
|
2
|
+
import { OptionsJson } from "./interfaces/body-parser.interface";
|
|
3
|
+
import { CompressionOptions } from "./interfaces/compression.interface";
|
|
4
|
+
import { CookieParserOptions } from "./interfaces/cookie-parser.interface";
|
|
5
|
+
import { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
|
|
6
|
+
import { CorsOptions } from "./interfaces/cors.interface";
|
|
7
|
+
import { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
|
|
8
|
+
import { SessionOptions } from "./interfaces/express-session.interface";
|
|
9
|
+
import { OptionsHelmet } from "./interfaces/helmet.interface";
|
|
10
|
+
import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
|
|
11
|
+
import { multer } from "./interfaces/multer.interface";
|
|
12
|
+
import { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
|
|
13
|
+
import { ServeStaticOptions } from "./interfaces/serve-static.interface";
|
|
14
|
+
import { OptionsUrlencoded } from "./interfaces/url-encoded.interface";
|
|
15
|
+
/**
|
|
16
|
+
* ErrorHandlerOptions Interface
|
|
17
|
+
*
|
|
18
|
+
* The ErrorHandlerOptions interface specifies the configuration options for the error handler middleware.
|
|
19
|
+
* @param errorHandler: An Express error handler function that takes care of processing errors and formulating the response.
|
|
20
|
+
* @param showStackTrace: A boolean value indicating whether to include the stack trace in the error response. The default value is false.
|
|
21
|
+
* @public API
|
|
22
|
+
*/
|
|
23
|
+
export interface ErrorHandlerOptions {
|
|
24
|
+
errorHandler?: ExpressHandler;
|
|
25
|
+
showStackTrace?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface for configuring and managing middlewares in the application.
|
|
29
|
+
* Provides methods to be added automatically in the application without the need to import packages.
|
|
30
|
+
* @public API
|
|
31
|
+
*/
|
|
32
|
+
export interface IMiddleware {
|
|
33
|
+
/**
|
|
34
|
+
* Adds a URL Encoded Parser middleware to the middleware collection.
|
|
35
|
+
* The URL Encoded Parser is responsible for parsing the URL-encoded data in the incoming request bodies.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Optional configuration options for the URL Encoded Parser.
|
|
38
|
+
* @public API
|
|
39
|
+
*/
|
|
40
|
+
addUrlEncodedParser(options?: OptionsUrlencoded): void;
|
|
41
|
+
/**
|
|
42
|
+
* Adds a Rate Limit middleware to the middleware collection.
|
|
43
|
+
* The rate limiter is responsible for adding dynamic rate limit and request throttling to the application.
|
|
44
|
+
*
|
|
45
|
+
* @param options - Optional configuration options for the rate limiter.
|
|
46
|
+
* @public API
|
|
47
|
+
*/
|
|
48
|
+
addRateLimiter(options?: RateLimitOptions): void;
|
|
49
|
+
/**
|
|
50
|
+
* Adds a Body Parser middleware to the middleware collection.
|
|
51
|
+
* The body parser is responsible for parsing the incoming request bodies in a middleware.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Optional configuration options for the JSON body parser.
|
|
54
|
+
* @public API
|
|
55
|
+
*/
|
|
56
|
+
addBodyParser(options?: OptionsJson): void;
|
|
57
|
+
/**
|
|
58
|
+
* Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
|
|
61
|
+
* @public API
|
|
62
|
+
*/
|
|
63
|
+
addCors(options?: CorsOptions): void;
|
|
64
|
+
/**
|
|
65
|
+
* Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
|
|
66
|
+
*
|
|
67
|
+
* @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
|
|
68
|
+
* @public API
|
|
69
|
+
*/
|
|
70
|
+
addCompression(options?: CompressionOptions): void;
|
|
71
|
+
/**
|
|
72
|
+
* Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
|
|
73
|
+
*
|
|
74
|
+
* @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
|
|
75
|
+
* @param options - Optional configuration options for Cookie Parser.
|
|
76
|
+
* @public API
|
|
77
|
+
*/
|
|
78
|
+
addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions): void;
|
|
79
|
+
/**
|
|
80
|
+
* Adds Cookie Session middleware to enable cookie-based sessions.
|
|
81
|
+
*
|
|
82
|
+
* @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
|
|
83
|
+
* @public API
|
|
84
|
+
*/
|
|
85
|
+
addCookieSession(options: CookieSessionOptions): void;
|
|
86
|
+
/**
|
|
87
|
+
* Adds Morgan middleware to log HTTP requests.
|
|
88
|
+
*
|
|
89
|
+
* @param format - The log format. Can be a string or a function.
|
|
90
|
+
* @param options - Optional configuration options for Morgan. Defines the behavior of the logger like the output stream, buffer duration, etc.
|
|
91
|
+
* @public API
|
|
92
|
+
*/
|
|
93
|
+
addMorgan(format: string | FormatFn, options?: OptionsMorgan): void;
|
|
94
|
+
/**
|
|
95
|
+
* Adds a middleware to serve the favicon to the middleware collection.
|
|
96
|
+
* The favicon is the icon that is displayed in the browser tab for the application.
|
|
97
|
+
*
|
|
98
|
+
* @param path - The path to the favicon file.
|
|
99
|
+
* @param options - Optional configuration options for serving the favicon. Defines the behavior of the favicon middleware like cache control, custom headers, etc.
|
|
100
|
+
* @public API
|
|
101
|
+
*/
|
|
102
|
+
addServeFavicon(path: string | Buffer, options?: ServeFaviconOptions): void;
|
|
103
|
+
/**
|
|
104
|
+
* Add a middleware to enable express-session.
|
|
105
|
+
*
|
|
106
|
+
* @param options - Optional configuration options for Session.
|
|
107
|
+
* @public API
|
|
108
|
+
*/
|
|
109
|
+
addSession(options: SessionOptions): void;
|
|
110
|
+
/**
|
|
111
|
+
* Configures the error handling middleware for the application.
|
|
112
|
+
*
|
|
113
|
+
* @param options - The object containing the configuration options for the error handler middleware.
|
|
114
|
+
* @option errorHandler - The Express error handler function that takes care of processing errors and formulating the response.
|
|
115
|
+
* @option showStackTrace - A boolean value indicating whether to show the stack trace in the response.
|
|
116
|
+
* @public API
|
|
117
|
+
*/
|
|
118
|
+
setErrorHandler(options?: ErrorHandlerOptions): void;
|
|
119
|
+
/**
|
|
120
|
+
* Adds a middleware to serve static files from the specified root directory.
|
|
121
|
+
* Allows the application to serve files like images, CSS, JavaScript, etc.
|
|
122
|
+
*
|
|
123
|
+
* @param root - The root directory from which the static assets are to be served.
|
|
124
|
+
* @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
|
|
125
|
+
* @public API
|
|
126
|
+
*/
|
|
127
|
+
serveStatic(root: string, options?: ServeStaticOptions): void;
|
|
128
|
+
/**
|
|
129
|
+
* Adds a middleware to the middleware collection.
|
|
130
|
+
*
|
|
131
|
+
* @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
|
|
132
|
+
* that is composed by a route and an expressjs handler, or a custom Expresso middleware.
|
|
133
|
+
*
|
|
134
|
+
* @example Express Handler
|
|
135
|
+
* const middleware = (req, res, next) => {
|
|
136
|
+
* // Your middleware logic here
|
|
137
|
+
* next();
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* @example Middleware Configuration Object
|
|
141
|
+
* const middleware = {
|
|
142
|
+
* path: "/",
|
|
143
|
+
* middlewares: [] // Array of Express Handlers
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* @example Expresso Middleware
|
|
147
|
+
* class CustomMiddleware implements IExpressoMiddleware {
|
|
148
|
+
* use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
|
|
149
|
+
* // Your middleware logic here
|
|
150
|
+
* next();
|
|
151
|
+
* }
|
|
152
|
+
* }
|
|
153
|
+
* @public API
|
|
154
|
+
*/
|
|
155
|
+
addMiddleware(options: MiddlewareOptions): void;
|
|
156
|
+
/**
|
|
157
|
+
* View middleware pipeline formatted.
|
|
158
|
+
* @returns void
|
|
159
|
+
* @public API
|
|
160
|
+
*/
|
|
161
|
+
viewMiddlewarePipeline(): void;
|
|
162
|
+
/**
|
|
163
|
+
* Gets the configured error handler middleware.
|
|
164
|
+
*
|
|
165
|
+
* @returns The error handler middleware.
|
|
166
|
+
* @public API
|
|
167
|
+
*/
|
|
168
|
+
getErrorHandler(): ExpressHandler;
|
|
169
|
+
/**
|
|
170
|
+
* Adds Helmet middleware to enhance security by setting various HTTP headers.
|
|
171
|
+
*
|
|
172
|
+
* @param options - Optional configuration options for Helmet.
|
|
173
|
+
* @returns The configuration options for Helmet middleware.
|
|
174
|
+
* @public API
|
|
175
|
+
*/
|
|
176
|
+
addHelmet(options?: OptionsHelmet): void;
|
|
177
|
+
/**
|
|
178
|
+
* Adds Multer middleware for handling multipart/form-data, typically used for file uploads.
|
|
179
|
+
*
|
|
180
|
+
* @param options - Optional configuration options for Multer.
|
|
181
|
+
* @returns The Multer middleware.
|
|
182
|
+
* @public API
|
|
183
|
+
*/
|
|
184
|
+
setupMulter(options?: multer.Options): multer.Multer;
|
|
185
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ErrorRequestHandler, NextFunction, Request, RequestHandler, RequestParamHandler, Response } from "express";
|
|
2
|
+
import { ErrorHandlerOptions, IMiddleware } from "./middleware-interface";
|
|
2
3
|
import { OptionsJson } from "./interfaces/body-parser.interface";
|
|
3
4
|
import { CompressionOptions } from "./interfaces/compression.interface";
|
|
4
|
-
import { CorsOptions } from "./interfaces/cors.interface";
|
|
5
5
|
import { CookieParserOptions } from "./interfaces/cookie-parser.interface";
|
|
6
|
-
import { ServeStaticOptions } from "./interfaces/serve-static.interface";
|
|
7
6
|
import { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
|
|
8
|
-
import {
|
|
9
|
-
import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
|
|
7
|
+
import { CorsOptions } from "./interfaces/cors.interface";
|
|
10
8
|
import { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
|
|
9
|
+
import { SessionOptions } from "./interfaces/express-session.interface";
|
|
11
10
|
import { OptionsHelmet } from "./interfaces/helmet.interface";
|
|
11
|
+
import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
|
|
12
12
|
import { multer } from "./interfaces/multer.interface";
|
|
13
|
-
import {
|
|
13
|
+
import { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
|
|
14
|
+
import { ServeStaticOptions } from "./interfaces/serve-static.interface";
|
|
14
15
|
import { OptionsUrlencoded } from "./interfaces/url-encoded.interface";
|
|
15
16
|
/**
|
|
16
17
|
* ExpressHandler Type
|
|
@@ -22,7 +23,7 @@ import { OptionsUrlencoded } from "./interfaces/url-encoded.interface";
|
|
|
22
23
|
* - express.RequestHandler: General request handler.
|
|
23
24
|
* - undefined: Represents the absence of a handler.
|
|
24
25
|
*/
|
|
25
|
-
export type ExpressHandler =
|
|
26
|
+
export type ExpressHandler = ErrorRequestHandler | RequestParamHandler | RequestHandler | undefined;
|
|
26
27
|
/**
|
|
27
28
|
* Expresso middleware interface.
|
|
28
29
|
*/
|
|
@@ -67,166 +68,15 @@ interface MiddlewarePipeline {
|
|
|
67
68
|
timestamp: Date;
|
|
68
69
|
middleware: ExpressHandler | MiddlewareConfig | IExpressoMiddleware;
|
|
69
70
|
}
|
|
70
|
-
/**
|
|
71
|
-
* ErrorHandlerOptions Interface
|
|
72
|
-
*
|
|
73
|
-
* The ErrorHandlerOptions interface specifies the configuration options for the error handler middleware.
|
|
74
|
-
* @param errorHandler: An Express error handler function that takes care of processing errors and formulating the response.
|
|
75
|
-
* @param showStackTrace: A boolean value indicating whether to include the stack trace in the error response. The default value is false.
|
|
76
|
-
*/
|
|
77
|
-
export interface ErrorHandlerOptions {
|
|
78
|
-
errorHandler?: ExpressHandler;
|
|
79
|
-
showStackTrace?: boolean;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Interface for configuring and managing middlewares in the application.
|
|
83
|
-
* Provides methods to be added automatically in the application without the need to import packages.
|
|
84
|
-
*/
|
|
85
|
-
interface IMiddleware {
|
|
86
|
-
/**
|
|
87
|
-
* Adds a URL Encoded Parser middleware to the middleware collection.
|
|
88
|
-
* The URL Encoded Parser is responsible for parsing the URL-encoded data in the incoming request bodies.
|
|
89
|
-
*
|
|
90
|
-
* @param options - Optional configuration options for the URL Encoded Parser.
|
|
91
|
-
*/
|
|
92
|
-
addUrlEncodedParser(options?: OptionsUrlencoded): void;
|
|
93
|
-
/**
|
|
94
|
-
* Adds a Rate Limit middleware to the middleware collection.
|
|
95
|
-
* The rate limiter is responsible for adding dynamic rate limit and request throttling to the application.
|
|
96
|
-
*
|
|
97
|
-
* @param options - Optional configuration options for the rate limiter.
|
|
98
|
-
*/
|
|
99
|
-
addRateLimiter(options?: RateLimitOptions): void;
|
|
100
|
-
/**
|
|
101
|
-
* Adds a Body Parser middleware to the middleware collection.
|
|
102
|
-
* The body parser is responsible for parsing the incoming request bodies in a middleware.
|
|
103
|
-
*
|
|
104
|
-
* @param options - Optional configuration options for the JSON body parser.
|
|
105
|
-
*/
|
|
106
|
-
addBodyParser(options?: OptionsJson): void;
|
|
107
|
-
/**
|
|
108
|
-
* Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
|
|
109
|
-
*
|
|
110
|
-
* @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
|
|
111
|
-
*/
|
|
112
|
-
addCors(options?: CorsOptions): void;
|
|
113
|
-
/**
|
|
114
|
-
* Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
|
|
115
|
-
*
|
|
116
|
-
* @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
|
|
117
|
-
*/
|
|
118
|
-
addCompression(options?: CompressionOptions): void;
|
|
119
|
-
/**
|
|
120
|
-
* Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
|
|
121
|
-
*
|
|
122
|
-
* @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
|
|
123
|
-
* @param options - Optional configuration options for Cookie Parser.
|
|
124
|
-
*/
|
|
125
|
-
addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions): void;
|
|
126
|
-
/**
|
|
127
|
-
* Adds Cookie Session middleware to enable cookie-based sessions.
|
|
128
|
-
*
|
|
129
|
-
* @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
|
|
130
|
-
*/
|
|
131
|
-
addCookieSession(options: CookieSessionOptions): void;
|
|
132
|
-
/**
|
|
133
|
-
* Adds Morgan middleware to log HTTP requests.
|
|
134
|
-
*
|
|
135
|
-
* @param format - The log format. Can be a string or a function.
|
|
136
|
-
* @param options - Optional configuration options for Morgan. Defines the behavior of the logger like the output stream, buffer duration, etc.
|
|
137
|
-
*/
|
|
138
|
-
addMorgan(format: string | FormatFn, options?: OptionsMorgan): void;
|
|
139
|
-
/**
|
|
140
|
-
* Adds a middleware to serve the favicon to the middleware collection.
|
|
141
|
-
* The favicon is the icon that is displayed in the browser tab for the application.
|
|
142
|
-
*
|
|
143
|
-
* @param path - The path to the favicon file.
|
|
144
|
-
* @param options - Optional configuration options for serving the favicon. Defines the behavior of the favicon middleware like cache control, custom headers, etc.
|
|
145
|
-
*/
|
|
146
|
-
addServeFavicon(path: string | Buffer, options?: ServeFaviconOptions): void;
|
|
147
|
-
/**
|
|
148
|
-
* Add a middleware to enable express-session.
|
|
149
|
-
*
|
|
150
|
-
* @param options - Optional configuration options for Session.
|
|
151
|
-
*
|
|
152
|
-
*/
|
|
153
|
-
addSession(options: SessionOptions): void;
|
|
154
|
-
/**
|
|
155
|
-
* Configures the error handling middleware for the application.
|
|
156
|
-
*
|
|
157
|
-
* @param options - The object containing the configuration options for the error handler middleware.
|
|
158
|
-
* @param errorHandler - The Express error handler function that takes care of processing errors and formulating the response.
|
|
159
|
-
* @param showStackTrace - A boolean value indicating whether to show the stack trace in the response.
|
|
160
|
-
*/
|
|
161
|
-
setErrorHandler(options?: ErrorHandlerOptions): void;
|
|
162
|
-
/**
|
|
163
|
-
* Adds a middleware to serve static files from the specified root directory.
|
|
164
|
-
* Allows the application to serve files like images, CSS, JavaScript, etc.
|
|
165
|
-
*
|
|
166
|
-
* @param root - The root directory from which the static assets are to be served.
|
|
167
|
-
* @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
|
|
168
|
-
*/
|
|
169
|
-
serveStatic(root: string, options?: ServeStaticOptions): void;
|
|
170
|
-
/**
|
|
171
|
-
* Adds a middleware to the middleware collection.
|
|
172
|
-
*
|
|
173
|
-
* @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
|
|
174
|
-
* that is composed by a route and an expressjs handler, or a custom Expresso middleware.
|
|
175
|
-
*
|
|
176
|
-
* @example Express Handler
|
|
177
|
-
* const middleware = (req, res, next) => {
|
|
178
|
-
* // Your middleware logic here
|
|
179
|
-
* next();
|
|
180
|
-
* }
|
|
181
|
-
*
|
|
182
|
-
* @example Middleware Configuration Object
|
|
183
|
-
* const middleware = {
|
|
184
|
-
* path: "/",
|
|
185
|
-
* middlewares: [] // Array of Express Handlers
|
|
186
|
-
* }
|
|
187
|
-
*
|
|
188
|
-
* @example Expresso Middleware
|
|
189
|
-
* class CustomMiddleware implements IExpressoMiddleware {
|
|
190
|
-
* use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
|
|
191
|
-
* // Your middleware logic here
|
|
192
|
-
* next();
|
|
193
|
-
* }
|
|
194
|
-
* }
|
|
195
|
-
*/
|
|
196
|
-
addMiddleware(options: MiddlewareOptions): void;
|
|
197
|
-
/**
|
|
198
|
-
* View middleware pipeline formatted.
|
|
199
|
-
* @returns void
|
|
200
|
-
*/
|
|
201
|
-
viewMiddlewarePipeline(): void;
|
|
202
|
-
/**
|
|
203
|
-
* Gets the configured error handler middleware.
|
|
204
|
-
*
|
|
205
|
-
* @returns The error handler middleware.
|
|
206
|
-
*/
|
|
207
|
-
getErrorHandler(): ExpressHandler;
|
|
208
|
-
/**
|
|
209
|
-
* Adds Helmet middleware to enhance security by setting various HTTP headers.
|
|
210
|
-
*
|
|
211
|
-
* @param options - Optional configuration options for Helmet.
|
|
212
|
-
* @returns The configuration options for Helmet middleware.
|
|
213
|
-
*/
|
|
214
|
-
addHelmet(options?: OptionsHelmet): void;
|
|
215
|
-
/**
|
|
216
|
-
* Adds Multer middleware for handling multipart/form-data, typically used for file uploads.
|
|
217
|
-
*
|
|
218
|
-
* @param options - Optional configuration options for Multer.
|
|
219
|
-
*/
|
|
220
|
-
setupMulter(options?: multer.Options): multer.Multer;
|
|
221
|
-
}
|
|
222
71
|
/**
|
|
223
72
|
* Singleton class that implements the IConfigure interface.
|
|
224
73
|
* Manages the middleware configuration for the application,
|
|
225
74
|
* including adding Body Parser and retrieving all configured middlewares.
|
|
226
75
|
*
|
|
227
76
|
* @see IConfigure
|
|
77
|
+
* @public API
|
|
228
78
|
*/
|
|
229
|
-
declare class Middleware implements IMiddleware {
|
|
79
|
+
export declare class Middleware implements IMiddleware {
|
|
230
80
|
private middlewarePipeline;
|
|
231
81
|
private errorHandler;
|
|
232
82
|
private logger;
|
|
@@ -234,7 +84,6 @@ declare class Middleware implements IMiddleware {
|
|
|
234
84
|
* Retrieves the type of the middleware.
|
|
235
85
|
*
|
|
236
86
|
* @param middleware - The middleware to be checked.
|
|
237
|
-
*
|
|
238
87
|
* @returns The type of the middleware.
|
|
239
88
|
*/
|
|
240
89
|
private getMiddlewareType;
|
|
@@ -242,7 +91,6 @@ declare class Middleware implements IMiddleware {
|
|
|
242
91
|
* Checks if a middleware with the given name exists in the middleware collection.
|
|
243
92
|
*
|
|
244
93
|
* @param middlewareName - The name of the middleware to be checked.
|
|
245
|
-
*
|
|
246
94
|
* @returns A boolean value indicating whether the middleware exists or not.
|
|
247
95
|
*/
|
|
248
96
|
private middlewareExists;
|
|
@@ -394,4 +242,4 @@ declare class Middleware implements IMiddleware {
|
|
|
394
242
|
*/
|
|
395
243
|
getErrorHandler(): ExpressHandler;
|
|
396
244
|
}
|
|
397
|
-
export {
|
|
245
|
+
export {};
|
|
@@ -1,63 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface IBaseRepository<T extends IMemoryDBEntity> {
|
|
3
|
-
create(item: T): T | null;
|
|
4
|
-
update(item: T): T | null;
|
|
5
|
-
delete(id: string): boolean;
|
|
6
|
-
find(id: string): T | null;
|
|
7
|
-
findAll(): Array<T> | null;
|
|
8
|
-
}
|
|
1
|
+
import { IDataProvider, IDataTable, IEntity, IRepository } from "./db-in-memory.interface";
|
|
9
2
|
/**
|
|
10
|
-
* Base
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @decorator @provide(BaseRepository)
|
|
3
|
+
* Base repository class using the repository pattern.
|
|
4
|
+
* @template T - The type of entity to be stored in the repository.
|
|
5
|
+
* @public API
|
|
15
6
|
*/
|
|
16
|
-
export declare class BaseRepository<T extends
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @returns {T[]} - An array of entities.
|
|
28
|
-
*/
|
|
29
|
-
protected get table(): Array<T>;
|
|
30
|
-
/**
|
|
31
|
-
* create Method
|
|
32
|
-
* @param item - The entity to be created.
|
|
33
|
-
* @returns {T | null} - The created entity or null if the entity already exists.
|
|
34
|
-
* @throws {Error} - If the entity already exists.
|
|
35
|
-
*/
|
|
36
|
-
create(item: T): T | null;
|
|
37
|
-
/**
|
|
38
|
-
* delete Method
|
|
39
|
-
* @param id - The id of the entity to be deleted.
|
|
40
|
-
* @returns {boolean} - True if the entity was deleted, false otherwise.
|
|
41
|
-
* @throws {Error} - If the entity does not exist.
|
|
42
|
-
*/
|
|
43
|
-
delete(id: string): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* update Method
|
|
46
|
-
* @param item - The entity to be updated.
|
|
47
|
-
* @returns {T | null} - The updated entity or null if the entity does not exist
|
|
48
|
-
* @throws {Error} - If the entity does not exist.
|
|
49
|
-
*/
|
|
50
|
-
update(item: T): T | null;
|
|
51
|
-
/**
|
|
52
|
-
* find Method
|
|
53
|
-
* @param id - The id of the entity to find.
|
|
54
|
-
* @returns {T | null} - The entity if it exists, null otherwise
|
|
55
|
-
* @throws {Error} - If the entity does not exist.
|
|
56
|
-
*/
|
|
57
|
-
find(id: string): T | null;
|
|
58
|
-
/**
|
|
59
|
-
* findAll Method
|
|
60
|
-
* @returns {T[] | null} - An array of entities or null if the table is empty.
|
|
61
|
-
*/
|
|
62
|
-
findAll(): Array<T> | null;
|
|
7
|
+
export declare class BaseRepository<T extends IEntity> implements IRepository<T> {
|
|
8
|
+
protected dataTable: IDataTable<T>;
|
|
9
|
+
protected entityName: string;
|
|
10
|
+
constructor(dataProvider: IDataProvider, tableName: string);
|
|
11
|
+
create(item: T): Promise<T>;
|
|
12
|
+
update(item: T): Promise<T>;
|
|
13
|
+
delete(id: string): Promise<boolean>;
|
|
14
|
+
find(id: string): Promise<T>;
|
|
15
|
+
findAll(): Promise<Array<T>>;
|
|
16
|
+
query(predicate: (item: T) => boolean): Promise<Array<T>>;
|
|
17
|
+
transaction(actions: () => Promise<void>): Promise<void>;
|
|
63
18
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IProvider } from "../provider-manager";
|
|
2
|
+
export interface IEntity {
|
|
3
|
+
id?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* IRepository Interface
|
|
7
|
+
* Generic interface that defines the structure of a repository.
|
|
8
|
+
* @template T - The type of entity to be stored in the repository.
|
|
9
|
+
* @public API
|
|
10
|
+
*/
|
|
11
|
+
export interface IRepository<T extends IEntity> {
|
|
12
|
+
create(item: T): Promise<T>;
|
|
13
|
+
update(item: T): Promise<T>;
|
|
14
|
+
delete(id: string): Promise<boolean>;
|
|
15
|
+
find(id: string): Promise<T>;
|
|
16
|
+
findAll(): Promise<Array<T>>;
|
|
17
|
+
query(predicate: (item: T) => boolean): Promise<Array<T>>;
|
|
18
|
+
transaction(actions: () => Promise<void>): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* IDataTable Interface for CRUD operations
|
|
22
|
+
* Generic interface that defines the structure of a data table.
|
|
23
|
+
* @template T - The type of entity to be stored in the data table.
|
|
24
|
+
* @public API
|
|
25
|
+
*/
|
|
26
|
+
export interface IDataTable<T extends IEntity> {
|
|
27
|
+
insert(item: T): Promise<T>;
|
|
28
|
+
insertMany(items: Array<T>): Promise<Array<T>>;
|
|
29
|
+
update(item: T): Promise<T>;
|
|
30
|
+
delete(id: string): Promise<boolean>;
|
|
31
|
+
find(id: string): Promise<T>;
|
|
32
|
+
findAll(): Promise<Array<T>>;
|
|
33
|
+
query(predicate: (item: T) => boolean): Promise<Array<T>>;
|
|
34
|
+
transaction(actions: () => Promise<void>): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* IDataProvider Interface for obtaining data tables
|
|
38
|
+
* Generic interface that defines the structure of a data provider.
|
|
39
|
+
* @public API
|
|
40
|
+
*/
|
|
41
|
+
export interface IDataProvider extends IProvider {
|
|
42
|
+
getTable<T extends IEntity>(tableName: string): IDataTable<T>;
|
|
43
|
+
}
|
|
@@ -1,43 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface IMemoryDBEntity {
|
|
3
|
-
id: string;
|
|
4
|
-
}
|
|
1
|
+
import { IDataProvider, IEntity, IDataTable } from "./db-in-memory.interface";
|
|
5
2
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* This class and its methods offer functionalities to simulate an in-memory database.
|
|
9
|
-
* It is particularly useful for developers starting with ExpressoTS without any database connection.
|
|
10
|
-
*
|
|
11
|
-
* @decorator @provideSingleton(InMemoryDB)
|
|
3
|
+
* In-memory data provider implementation.
|
|
4
|
+
* @public API
|
|
12
5
|
*/
|
|
13
|
-
export declare class
|
|
6
|
+
export declare class InMemoryDataProvider implements IDataProvider {
|
|
14
7
|
name: string;
|
|
15
8
|
version: string;
|
|
16
9
|
author: string;
|
|
17
10
|
repo: string;
|
|
18
11
|
private tables;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* @param tableName - The name of the table to print.
|
|
41
|
-
*/
|
|
42
|
-
printTable(tableName: string): void;
|
|
12
|
+
getTable<T extends IEntity>(tableName: string): IDataTable<T>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* In-memory data table implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare class InMemoryDataTable<T extends IEntity> implements IDataTable<T> {
|
|
18
|
+
private items;
|
|
19
|
+
private tableName;
|
|
20
|
+
private transactionStack;
|
|
21
|
+
constructor(tableName: string);
|
|
22
|
+
insert(item: T): Promise<T>;
|
|
23
|
+
insertMany(items: Array<T>): Promise<Array<T>>;
|
|
24
|
+
update(item: T): Promise<T>;
|
|
25
|
+
delete(id: string): Promise<boolean>;
|
|
26
|
+
find(id: string): Promise<T>;
|
|
27
|
+
findAll(): Promise<Array<T>>;
|
|
28
|
+
query(predicate: (item: T) => boolean): Promise<Array<T>>;
|
|
29
|
+
transaction(actions: () => Promise<void>): Promise<void>;
|
|
30
|
+
private beginTransaction;
|
|
31
|
+
private commitTransaction;
|
|
32
|
+
private rollbackTransaction;
|
|
43
33
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when an entity is not found.
|
|
3
|
+
* @public API
|
|
4
|
+
*/
|
|
5
|
+
export declare class EntityNotFoundError extends Error {
|
|
6
|
+
constructor(entityName: string, id: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when an entity already exists.
|
|
10
|
+
* @public API
|
|
11
|
+
*/
|
|
12
|
+
export declare class EntityAlreadyExistsError extends Error {
|
|
13
|
+
constructor(entityName: string, id: string);
|
|
14
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { InMemoryDataProvider, InMemoryDataTable, } from "./db-in-memory.provider";
|
|
2
|
+
export { EntityNotFoundError, EntityAlreadyExistsError, } from "./db-in-memory.types";
|
|
3
|
+
export { BaseRepository } from "./base-repo.repository";
|
|
4
|
+
export { IEntity, IRepository, IDataTable, IDataProvider, } from "./db-in-memory.interface";
|