@adaas/a-server 0.0.15 → 0.0.17
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 +504 -18
- package/dist/index.d.ts +16 -5
- package/dist/index.js +47 -17
- package/dist/index.js.map +1 -1
- package/dist/src/channels/A-Http/A-Http.channel.constants.d.ts +5 -0
- package/dist/src/channels/A-Http/A-Http.channel.constants.js +10 -0
- package/dist/src/channels/A-Http/A-Http.channel.constants.js.map +1 -0
- package/dist/src/channels/A-Http/A-Http.channel.d.ts +28 -0
- package/dist/src/channels/A-Http/A-Http.channel.error.d.ts +4 -0
- package/dist/src/channels/A-Http/A-Http.channel.error.js +9 -0
- package/dist/src/channels/A-Http/A-Http.channel.error.js.map +1 -0
- package/dist/src/channels/A-Http/A-Http.channel.js +148 -0
- package/dist/src/channels/A-Http/A-Http.channel.js.map +1 -0
- package/dist/src/channels/A-Http/A-Http.channel.types.d.ts +59 -0
- package/dist/src/channels/A-Http/A-Http.channel.types.js +3 -0
- package/dist/src/channels/A-Http/A-Http.channel.types.js.map +1 -0
- package/dist/src/components/A-CommandController/A-CommandController.component.d.ts +2 -2
- package/dist/src/components/A-CommandController/A-CommandController.component.js +5 -2
- package/dist/src/components/A-CommandController/A-CommandController.component.js.map +1 -1
- package/dist/src/components/A-Controller/A-Controller.component.js +0 -4
- package/dist/src/components/A-Controller/A-Controller.component.js.map +1 -1
- package/dist/src/components/A-EntityController/A-EntityController.component.d.ts +1 -1
- package/dist/src/components/A-EntityController/A-EntityController.component.js +26 -15
- package/dist/src/components/A-EntityController/A-EntityController.component.js.map +1 -1
- package/dist/src/components/A-EntityRepository/A-EntityRepository.component.d.ts +7 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.component.js +96 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.component.js.map +1 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.error.js +2 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.error.js.map +1 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.types.js +2 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.types.js.map +1 -0
- package/dist/src/components/A-ListingController/A-ListingController.component.d.ts +2 -1
- package/dist/src/components/A-ListingController/A-ListingController.component.js +7 -6
- package/dist/src/components/A-ListingController/A-ListingController.component.js.map +1 -1
- package/dist/src/components/A-Router/A-Router.component.d.ts +3 -2
- package/dist/src/components/A-Router/A-Router.component.js +17 -10
- package/dist/src/components/A-Router/A-Router.component.js.map +1 -1
- package/dist/src/components/A-ServerCORS/A_ServerCORS.component.d.ts +2 -1
- package/dist/src/components/A-ServerCORS/A_ServerCORS.component.js +2 -1
- package/dist/src/components/A-ServerCORS/A_ServerCORS.component.js.map +1 -1
- package/dist/src/components/A-ServerError/A-ServerError.class.d.ts +7 -0
- package/dist/src/components/A-ServerError/A-ServerError.class.js +88 -0
- package/dist/src/components/A-ServerError/A-ServerError.class.js.map +1 -0
- package/dist/src/components/A-ServerError/A-ServerError.constants.d.ts +0 -0
- package/dist/src/components/A-ServerError/A-ServerError.constants.js +2 -0
- package/dist/src/components/A-ServerError/A-ServerError.constants.js.map +1 -0
- package/dist/src/components/A-ServerError/A-ServerError.types.d.ts +13 -0
- package/dist/src/components/A-ServerError/A-ServerError.types.js +3 -0
- package/dist/src/components/A-ServerError/A-ServerError.types.js.map +1 -0
- package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +2 -1
- package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js +7 -3
- package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js.map +1 -1
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.d.ts +3 -2
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.js +6 -7
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.js.map +1 -1
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.types.d.ts +2 -1
- package/dist/src/components/A-ServerProxy/A-ServerProxy.component.d.ts +3 -2
- package/dist/src/components/A-ServerProxy/A-ServerProxy.component.js +4 -3
- package/dist/src/components/A-ServerProxy/A-ServerProxy.component.js.map +1 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.d.ts +2 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.js +3 -2
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.js.map +1 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.d.ts +2 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.js +2 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.js.map +1 -1
- package/dist/src/containers/A-Service/A-Service.container.d.ts +4 -2
- package/dist/src/containers/A-Service/A-Service.container.js +41 -35
- package/dist/src/containers/A-Service/A-Service.container.js.map +1 -1
- package/dist/src/context/A-EntityFactory/A-EntityFactory.context.d.ts +1 -2
- package/dist/src/context/A-EntityFactory/A-EntityFactory.context.js +6 -7
- package/dist/src/context/A-EntityFactory/A-EntityFactory.context.js.map +1 -1
- package/dist/src/context/A-HttpChannel/A-HttpChannel.context.d.ts +12 -0
- package/dist/src/context/A-HttpChannel/A-HttpChannel.context.js +16 -0
- package/dist/src/context/A-HttpChannel/A-HttpChannel.context.js.map +1 -0
- package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.js.map +1 -1
- package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.js.map +1 -1
- package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.js.map +1 -1
- package/dist/src/context/A-ProxyConfig/A_ProxyConfig.types.js.map +1 -0
- package/dist/src/context/A-Server/A_Server.context.d.ts +1 -1
- package/dist/src/context/A-Server/A_Server.context.js.map +1 -1
- package/dist/src/entities/A-Request/A-Request.entity.d.ts +3 -2
- package/dist/src/entities/A-Request/A-Request.entity.js +12 -19
- package/dist/src/entities/A-Request/A-Request.entity.js.map +1 -1
- package/dist/src/entities/A-Request/A-Request.entity.types.d.ts +2 -2
- package/dist/src/entities/A-Response/A-Response.entity.d.ts +3 -3
- package/dist/src/entities/A-Response/A-Response.entity.js +12 -11
- package/dist/src/entities/A-Response/A-Response.entity.js.map +1 -1
- package/dist/src/entities/A-Response/A-Response.entity.types.d.ts +2 -2
- package/dist/src/entities/A-Route/A-Route.entity.js +3 -1
- package/dist/src/entities/A-Route/A-Route.entity.js.map +1 -1
- package/dist/src/entities/A_EntityList/A_EntityList.entity.js +2 -3
- package/dist/src/entities/A_EntityList/A_EntityList.entity.js.map +1 -1
- package/dist/src/entities/A_EntityList/A_EntityList.entity.types.d.ts +2 -2
- package/examples/simple-server/commands/SignIn.command.ts +2 -2
- package/examples/simple-server/components/Test.controller.ts +19 -5
- package/examples/simple-server/components/Users.repository.ts +10 -7
- package/examples/simple-server/concept.ts +19 -20
- package/examples/simple-server/entities/User/User.entity.ts +10 -7
- package/examples/simple-server/entities/User/User.entity.types.ts +2 -2
- package/index.ts +49 -19
- package/jest.config.ts +1 -0
- package/package.json +4 -4
- package/src/channels/A-Http/A-Http.channel.constants.ts +8 -0
- package/src/channels/A-Http/A-Http.channel.error.ts +8 -0
- package/src/channels/A-Http/A-Http.channel.ts +188 -0
- package/src/channels/A-Http/A-Http.channel.types.ts +66 -0
- package/src/components/A-CommandController/A-CommandController.component.ts +7 -2
- package/src/components/A-Controller/A-Controller.component.ts +0 -4
- package/src/components/A-EntityController/A-EntityController.component.ts +27 -10
- package/src/components/A-EntityRepository/A-EntityRepository.component.ts +88 -0
- package/src/components/A-EntityRepository/A-EntityRepository.error.ts +0 -0
- package/src/components/A-EntityRepository/A-EntityRepository.types.ts +0 -0
- package/src/components/A-ListingController/A-ListingController.component.ts +7 -6
- package/src/components/A-Router/A-Router.component.ts +25 -14
- package/src/components/A-Router/A-Router.component.types.ts +1 -1
- package/src/components/A-ServerCORS/A_ServerCORS.component.ts +2 -1
- package/src/components/A-ServerError/A-ServerError.class.ts +98 -0
- package/src/components/A-ServerError/A-ServerError.constants.ts +0 -0
- package/src/components/A-ServerError/A-ServerError.types.ts +22 -0
- package/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.ts +8 -3
- package/src/components/A-ServerLogger/A_ServerLogger.component.ts +6 -9
- package/src/components/A-ServerLogger/A_ServerLogger.component.types.ts +2 -9
- package/src/components/A-ServerProxy/A-ServerProxy.component.ts +3 -2
- package/src/components/A-StaticLoader/A-StaticLoader.component.ts +2 -1
- package/src/components/A-StaticLoader/A-StaticLoader.component.types.ts +2 -3
- package/src/containers/A-Service/A-Service.container.ts +37 -35
- package/src/context/A-EntityFactory/A-EntityFactory.context.ts +1 -2
- package/src/context/A-HttpChannel/A-HttpChannel.context.ts +36 -0
- package/src/context/A-Server/A_Server.context.ts +2 -3
- package/src/entities/A-Request/A-Request.entity.ts +16 -17
- package/src/entities/A-Request/A-Request.entity.types.ts +3 -3
- package/src/entities/A-Response/A-Response.entity.ts +14 -12
- package/src/entities/A-Response/A-Response.entity.types.ts +2 -2
- package/src/entities/A-Route/A-Route.entity.ts +4 -4
- package/src/entities/A_EntityList/A_EntityList.entity.ts +2 -3
- package/src/entities/A_EntityList/A_EntityList.entity.types.ts +5 -5
- package/tests/A-HttpChannel.test.ts +204 -0
- package/tests/A-Service.test.ts +1 -3
- package/tsconfig.build.json +1 -0
- package/tsconfig.json +2 -0
- package/dist/src/context/A_ProxyConfig/A_ProxyConfig.types.js.map +0 -1
- package/dist/src/context/Server.context.types.js +0 -2
- package/dist/src/context/Server.context.types.js.map +0 -1
- /package/dist/src/{context/Server.context.types.d.ts → components/A-EntityRepository/A-EntityRepository.error.d.ts} +0 -0
- /package/{src/context/Server.context.types.ts → dist/src/components/A-EntityRepository/A-EntityRepository.types.d.ts} +0 -0
- /package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.d.ts +0 -0
- /package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.js +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.d.ts +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.js +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.d.ts +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.js +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.types.d.ts +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.types.js +0 -0
- /package/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.ts +0 -0
- /package/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.ts +0 -0
- /package/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.ts +0 -0
- /package/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.types.ts +0 -0
package/README.md
CHANGED
|
@@ -1,48 +1,534 @@
|
|
|
1
1
|
<img align="left" style="margin-right:40px; margin-bottom:80px;" width="180" height="80" src="./docs/a-logo-docs.png" alt="ADAAS Logo">
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# A-Server SDK
|
|
4
4
|
|
|
5
5
|
| LTS | Latest | npm |
|
|
6
6
|
|---------------|----------|---------------------------|
|
|
7
|
-
|
|
|
7
|
+
| v0.0.15 | v0.0.15 | [@adaas/a-server](https://www.npmjs.com/package/@adaas/a-server) |
|
|
8
8
|
|
|
9
|
+
**A-Server** is a powerful SDK for building modular, scalable backend servers with TypeScript. It provides a comprehensive set of components for routing, entity management, CORS handling, health monitoring, and more - all built on the ADAAS ecosystem.
|
|
9
10
|
|
|
10
|
-
##
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🚀 **Modular Architecture** - Component-based server structure
|
|
14
|
+
- 🛡️ **Built-in Security** - CORS, proxy, and error handling
|
|
15
|
+
- 📊 **Health Monitoring** - Real-time server health checks
|
|
16
|
+
- 🔄 **Entity Management** - Advanced CRUD operations with repositories
|
|
17
|
+
- 🌐 **Routing System** - Powerful decorator-based routing
|
|
18
|
+
- 📁 **Static File Serving** - Configurable static asset handling
|
|
19
|
+
- 🔧 **Configuration Management** - Environment-based configuration
|
|
20
|
+
- 📝 **Comprehensive Logging** - Built-in logging capabilities
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
11
23
|
|
|
12
24
|
```bash
|
|
25
|
+
npm install @adaas/a-server
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Environment Variables
|
|
29
|
+
|
|
30
|
+
Configure your server using these environment variables:
|
|
31
|
+
|
|
32
|
+
| Variable | Description | Default | Required |
|
|
33
|
+
|----------|-------------|---------|----------|
|
|
34
|
+
| `A_SERVER_PORT` | Port for the server to listen on | `3000` | No |
|
|
35
|
+
| `A_ROUTER__PARSE_PARAMS_AUTOMATICALLY` | Enable automatic parameter parsing | `true` | No |
|
|
36
|
+
| `CONFIG_VERBOSE` | Enable verbose configuration logging | `false` | No |
|
|
37
|
+
| `DEV_MODE` | Enable development mode features | `false` | No |
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### Basic Server Setup
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import {
|
|
45
|
+
A_Service,
|
|
46
|
+
A_EntityController,
|
|
47
|
+
A_Router,
|
|
48
|
+
A_ServerLogger,
|
|
49
|
+
A_ServerHealthMonitor,
|
|
50
|
+
A_ServerCORS
|
|
51
|
+
} from '@adaas/a-server';
|
|
52
|
+
import { A_Concept, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY } from '@adaas/a-concept';
|
|
53
|
+
import { A_Config, A_ConfigLoader, ENVConfigReader } from '@adaas/a-utils';
|
|
54
|
+
|
|
55
|
+
// Configure your application
|
|
56
|
+
const config = new A_Config({
|
|
57
|
+
variables: [
|
|
58
|
+
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
59
|
+
'A_SERVER_PORT',
|
|
60
|
+
'A_ROUTER__PARSE_PARAMS_AUTOMATICALLY'
|
|
61
|
+
] as const,
|
|
62
|
+
defaults: {
|
|
63
|
+
A_SERVER_PORT: 3000,
|
|
64
|
+
A_ROUTER__PARSE_PARAMS_AUTOMATICALLY: true
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Setup configuration loader
|
|
69
|
+
const SharedConfig = new A_ConfigLoader({
|
|
70
|
+
components: [ENVConfigReader],
|
|
71
|
+
fragments: [config]
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Create server service
|
|
75
|
+
const Server = new A_Service({
|
|
76
|
+
components: [
|
|
77
|
+
A_ServerLogger,
|
|
78
|
+
A_Router,
|
|
79
|
+
A_EntityController,
|
|
80
|
+
A_ServerHealthMonitor,
|
|
81
|
+
A_ServerCORS
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Create and start the concept
|
|
86
|
+
const concept = new A_Concept({
|
|
87
|
+
name: 'my-server',
|
|
88
|
+
containers: [SharedConfig, Server],
|
|
89
|
+
fragments: [config]
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
(async () => {
|
|
93
|
+
await concept.load();
|
|
94
|
+
await concept.start();
|
|
95
|
+
console.log('Server started successfully!');
|
|
96
|
+
})();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Core Components
|
|
100
|
+
|
|
101
|
+
### A_EntityController
|
|
102
|
+
|
|
103
|
+
The `A_EntityController` provides a powerful base class for creating RESTful API endpoints with automatic CRUD operations.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { A_EntityController, A_Router } from '@adaas/a-server';
|
|
107
|
+
import { A_Component, A_Feature } from '@adaas/a-concept';
|
|
108
|
+
|
|
109
|
+
export class UserController extends A_EntityController {
|
|
110
|
+
|
|
111
|
+
@A_Feature.Define({
|
|
112
|
+
name: 'getUsers',
|
|
113
|
+
invoke: false
|
|
114
|
+
})
|
|
115
|
+
@A_Router.Get({
|
|
116
|
+
path: '/users'
|
|
117
|
+
})
|
|
118
|
+
async getUsers(request: A_Request, response: A_Response) {
|
|
119
|
+
// Your custom logic here
|
|
120
|
+
const users = await this.repository.findAll();
|
|
121
|
+
return response.json(users);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@A_Feature.Define({
|
|
125
|
+
name: 'createUser',
|
|
126
|
+
invoke: false
|
|
127
|
+
})
|
|
128
|
+
@A_Router.Post({
|
|
129
|
+
path: '/users'
|
|
130
|
+
})
|
|
131
|
+
async createUser(request: A_Request, response: A_Response) {
|
|
132
|
+
const userData = request.body;
|
|
133
|
+
const user = await this.repository.create(userData);
|
|
134
|
+
return response.status(201).json(user);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### A_Router
|
|
13
140
|
|
|
14
|
-
|
|
15
|
-
npm i @adaas/a-server
|
|
141
|
+
The `A_Router` component provides decorator-based routing with automatic parameter parsing and validation.
|
|
16
142
|
|
|
143
|
+
```typescript
|
|
144
|
+
import { A_Router, A_Request, A_Response } from '@adaas/a-server';
|
|
145
|
+
import { A_Component, A_Feature } from '@adaas/a-concept';
|
|
146
|
+
|
|
147
|
+
export class APIController extends A_Component {
|
|
148
|
+
|
|
149
|
+
@A_Feature.Define({
|
|
150
|
+
name: 'healthCheck',
|
|
151
|
+
invoke: false
|
|
152
|
+
})
|
|
153
|
+
@A_Router.Get({
|
|
154
|
+
path: '/health',
|
|
155
|
+
params: {
|
|
156
|
+
detailed: { type: 'boolean', required: false }
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
async healthCheck(request: A_Request, response: A_Response) {
|
|
160
|
+
const detailed = request.params.detailed;
|
|
161
|
+
|
|
162
|
+
if (detailed) {
|
|
163
|
+
return response.json({
|
|
164
|
+
status: 'healthy',
|
|
165
|
+
timestamp: new Date().toISOString(),
|
|
166
|
+
uptime: process.uptime(),
|
|
167
|
+
memory: process.memoryUsage()
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return response.json({ status: 'ok' });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@A_Router.Post({
|
|
175
|
+
path: '/api/data/:id',
|
|
176
|
+
params: {
|
|
177
|
+
id: { type: 'number', required: true }
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
async processData(request: A_Request, response: A_Response) {
|
|
181
|
+
const id = request.params.id;
|
|
182
|
+
const data = request.body;
|
|
183
|
+
|
|
184
|
+
// Process your data
|
|
185
|
+
return response.json({ id, data, processed: true });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
17
188
|
```
|
|
18
189
|
|
|
190
|
+
### A_ListingController
|
|
19
191
|
|
|
20
|
-
|
|
192
|
+
The `A_ListingController` provides advanced listing capabilities with filtering, sorting, and pagination.
|
|
21
193
|
|
|
22
194
|
```typescript
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
195
|
+
import { A_ListingController } from '@adaas/a-server';
|
|
196
|
+
|
|
197
|
+
export class ProductListingController extends A_ListingController {
|
|
198
|
+
|
|
199
|
+
protected getDefaultFilters() {
|
|
200
|
+
return {
|
|
201
|
+
category: { type: 'string', required: false },
|
|
202
|
+
minPrice: { type: 'number', required: false },
|
|
203
|
+
maxPrice: { type: 'number', required: false },
|
|
204
|
+
inStock: { type: 'boolean', required: false }
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
protected getDefaultSortFields() {
|
|
209
|
+
return ['name', 'price', 'createdAt', 'category'];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
protected async processQuery(filters: any, sort: any, pagination: any) {
|
|
213
|
+
// Your custom query logic
|
|
214
|
+
return await this.repository.findWithFilters(filters, sort, pagination);
|
|
215
|
+
}
|
|
26
216
|
}
|
|
27
217
|
```
|
|
28
218
|
|
|
219
|
+
### A_ServerCORS
|
|
220
|
+
|
|
221
|
+
Configure Cross-Origin Resource Sharing (CORS) for your server.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { A_ServerCORS } from '@adaas/a-server';
|
|
225
|
+
|
|
226
|
+
// Basic CORS configuration
|
|
227
|
+
const corsComponent = new A_ServerCORS({
|
|
228
|
+
origin: ['http://localhost:3000', 'https://mydomain.com'],
|
|
229
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
230
|
+
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
231
|
+
credentials: true
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### A_ServerProxy
|
|
29
236
|
|
|
30
|
-
|
|
237
|
+
Set up proxy configurations for external services.
|
|
31
238
|
|
|
32
239
|
```typescript
|
|
33
|
-
|
|
240
|
+
import { A_ProxyConfig, A_ServerProxy } from '@adaas/a-server';
|
|
34
241
|
|
|
35
|
-
|
|
242
|
+
// Create proxy configuration
|
|
243
|
+
const proxyConfig = new A_ProxyConfig({
|
|
244
|
+
'/api/external': 'https://api.external-service.com',
|
|
245
|
+
'/assets/.*': 'https://cdn.example.com',
|
|
246
|
+
'/docs': 'https://docs.example.com'
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Add to your concept fragments
|
|
250
|
+
const concept = new A_Concept({
|
|
251
|
+
// ... other configuration
|
|
252
|
+
fragments: [
|
|
253
|
+
config,
|
|
254
|
+
proxyConfig
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### A_StaticLoader
|
|
260
|
+
|
|
261
|
+
Serve static files and assets.
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { A_StaticConfig, A_StaticLoader } from '@adaas/a-server';
|
|
265
|
+
|
|
266
|
+
// Configure static file serving
|
|
267
|
+
const staticConfig = new A_StaticConfig([
|
|
268
|
+
'public',
|
|
269
|
+
'docs',
|
|
270
|
+
'assets'
|
|
271
|
+
]);
|
|
272
|
+
|
|
273
|
+
// Add to your server components
|
|
274
|
+
const Server = new A_Service({
|
|
275
|
+
components: [
|
|
276
|
+
// ... other components
|
|
277
|
+
A_StaticLoader
|
|
278
|
+
]
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Add to concept fragments
|
|
282
|
+
const concept = new A_Concept({
|
|
283
|
+
// ... other configuration
|
|
284
|
+
fragments: [
|
|
285
|
+
config,
|
|
286
|
+
staticConfig
|
|
287
|
+
]
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### A_ServerHealthMonitor
|
|
292
|
+
|
|
293
|
+
Monitor your server's health and performance.
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import { A_ServerHealthMonitor } from '@adaas/a-server';
|
|
36
297
|
|
|
37
|
-
|
|
298
|
+
// The health monitor automatically provides endpoints:
|
|
299
|
+
// GET /health - Basic health check
|
|
300
|
+
// GET /health/detailed - Detailed system information
|
|
301
|
+
// GET /metrics - Performance metrics
|
|
302
|
+
|
|
303
|
+
// Add to your server components
|
|
304
|
+
const Server = new A_Service({
|
|
305
|
+
components: [
|
|
306
|
+
A_ServerHealthMonitor,
|
|
307
|
+
// ... other components
|
|
308
|
+
]
|
|
309
|
+
});
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### A_ServerLogger
|
|
313
|
+
|
|
314
|
+
Comprehensive logging capabilities for your server.
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
import { A_ServerLogger } from '@adaas/a-server';
|
|
318
|
+
|
|
319
|
+
export class MyController extends A_Component {
|
|
320
|
+
|
|
321
|
+
@A_Inject()
|
|
322
|
+
private logger!: A_ServerLogger;
|
|
323
|
+
|
|
324
|
+
async someMethod() {
|
|
325
|
+
this.logger.info('Processing request');
|
|
326
|
+
this.logger.warn('This is a warning');
|
|
327
|
+
this.logger.error('An error occurred', { error: 'details' });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Advanced Usage
|
|
333
|
+
|
|
334
|
+
### Entity Repository Pattern
|
|
335
|
+
|
|
336
|
+
Create custom repositories for your entities:
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { A_EntityRepository } from '@adaas/a-server';
|
|
340
|
+
|
|
341
|
+
export class UserRepository extends A_EntityRepository {
|
|
342
|
+
|
|
343
|
+
async findByEmail(email: string) {
|
|
344
|
+
return this.findOne({ email });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async findActiveUsers() {
|
|
348
|
+
return this.findMany({ active: true });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async getUserStats() {
|
|
352
|
+
return {
|
|
353
|
+
total: await this.count(),
|
|
354
|
+
active: await this.count({ active: true }),
|
|
355
|
+
inactive: await this.count({ active: false })
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Command Pattern Implementation
|
|
362
|
+
|
|
363
|
+
Use the command pattern for complex operations:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
import { A_CommandController } from '@adaas/a-server';
|
|
367
|
+
|
|
368
|
+
export class UserCommandController extends A_CommandController {
|
|
369
|
+
|
|
370
|
+
@A_Router.Post({
|
|
371
|
+
path: '/commands/user/signup'
|
|
372
|
+
})
|
|
373
|
+
async executeSignUp(request: A_Request, response: A_Response) {
|
|
374
|
+
const command = new SignUpCommand(request.body);
|
|
375
|
+
const result = await this.executeCommand(command);
|
|
376
|
+
return response.json(result);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Complete Server Example
|
|
382
|
+
|
|
383
|
+
Here's a comprehensive example showing all components working together:
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
import {
|
|
387
|
+
A_Service,
|
|
388
|
+
A_EntityController,
|
|
389
|
+
A_Router,
|
|
390
|
+
A_ServerLogger,
|
|
391
|
+
A_ServerHealthMonitor,
|
|
392
|
+
A_ServerCORS,
|
|
393
|
+
A_ServerProxy,
|
|
394
|
+
A_StaticLoader,
|
|
395
|
+
A_ListingController,
|
|
396
|
+
A_ProxyConfig,
|
|
397
|
+
A_StaticConfig
|
|
398
|
+
} from '@adaas/a-server';
|
|
399
|
+
import {
|
|
400
|
+
A_Concept,
|
|
401
|
+
A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
|
|
402
|
+
} from '@adaas/a-concept';
|
|
403
|
+
import {
|
|
404
|
+
A_Config,
|
|
405
|
+
A_ConfigLoader,
|
|
406
|
+
A_Polyfill,
|
|
407
|
+
ENVConfigReader
|
|
408
|
+
} from '@adaas/a-utils';
|
|
409
|
+
|
|
410
|
+
// Custom entities
|
|
411
|
+
import { User } from './entities/User';
|
|
412
|
+
import { Product } from './entities/Product';
|
|
413
|
+
|
|
414
|
+
// Custom controllers
|
|
415
|
+
import { UserController } from './controllers/UserController';
|
|
416
|
+
import { ProductController } from './controllers/ProductController';
|
|
417
|
+
|
|
418
|
+
// Custom repositories
|
|
419
|
+
import { UserRepository } from './repositories/UserRepository';
|
|
38
420
|
|
|
39
421
|
(async () => {
|
|
40
|
-
|
|
422
|
+
// Configuration
|
|
423
|
+
const config = new A_Config({
|
|
424
|
+
variables: [
|
|
425
|
+
...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
|
|
426
|
+
'A_SERVER_PORT',
|
|
427
|
+
'A_ROUTER__PARSE_PARAMS_AUTOMATICALLY',
|
|
428
|
+
'CONFIG_VERBOSE',
|
|
429
|
+
'DEV_MODE'
|
|
430
|
+
] as const,
|
|
431
|
+
defaults: {
|
|
432
|
+
A_SERVER_PORT: 3000,
|
|
433
|
+
A_ROUTER__PARSE_PARAMS_AUTOMATICALLY: true,
|
|
434
|
+
CONFIG_VERBOSE: true,
|
|
435
|
+
DEV_MODE: true
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
const SharedConfig = new A_ConfigLoader({
|
|
440
|
+
components: [ENVConfigReader],
|
|
441
|
+
fragments: [config]
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// Server service with all components
|
|
445
|
+
const Server = new A_Service({
|
|
446
|
+
components: [
|
|
447
|
+
A_Polyfill,
|
|
448
|
+
A_ServerLogger,
|
|
449
|
+
A_Router,
|
|
450
|
+
A_EntityController,
|
|
451
|
+
A_ServerHealthMonitor,
|
|
452
|
+
A_ServerProxy,
|
|
453
|
+
A_StaticLoader,
|
|
454
|
+
A_ServerCORS,
|
|
455
|
+
A_ListingController,
|
|
456
|
+
UserController,
|
|
457
|
+
ProductController,
|
|
458
|
+
UserRepository
|
|
459
|
+
],
|
|
460
|
+
entities: [
|
|
461
|
+
User,
|
|
462
|
+
Product
|
|
463
|
+
],
|
|
464
|
+
fragments: [config]
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// Main concept
|
|
468
|
+
const concept = new A_Concept({
|
|
469
|
+
name: 'my-complete-server',
|
|
470
|
+
containers: [SharedConfig, Server],
|
|
471
|
+
components: [A_Polyfill],
|
|
472
|
+
fragments: [
|
|
473
|
+
config,
|
|
474
|
+
new A_ProxyConfig({
|
|
475
|
+
'/api/external': 'https://api.external-service.com',
|
|
476
|
+
'/assets/.*': 'https://cdn.example.com'
|
|
477
|
+
}),
|
|
478
|
+
new A_StaticConfig(['public', 'docs'])
|
|
479
|
+
],
|
|
480
|
+
entities: [User, Product]
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
await concept.load();
|
|
484
|
+
await concept.start();
|
|
41
485
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
);
|
|
486
|
+
console.log(`🚀 Server running on port ${config.get('A_SERVER_PORT')}`);
|
|
487
|
+
console.log(`📊 Health check available at /health`);
|
|
488
|
+
console.log(`📁 Static files served from /public and /docs`);
|
|
46
489
|
})();
|
|
47
490
|
```
|
|
48
491
|
|
|
492
|
+
## API Reference
|
|
493
|
+
|
|
494
|
+
### Core Exports
|
|
495
|
+
|
|
496
|
+
- **Containers**: `A_Service`
|
|
497
|
+
- **Contexts**: `A_Server`, `A_ProxyConfig`, `A_StaticConfig`, `A_ListQueryFilter`
|
|
498
|
+
- **Entities**: `A_Request`, `A_Response`, `A_Route`, `A_EntityList`
|
|
499
|
+
- **Components**: `A_ServerLogger`, `A_EntityController`, `A_Router`, `A_ServerHealthMonitor`, `A_ServerProxy`, `A_ServerCORS`, `A_StaticLoader`, `A_Controller`, `A_ListingController`
|
|
500
|
+
|
|
501
|
+
### Environment Variables Reference
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
# Server Configuration
|
|
505
|
+
A_SERVER_PORT=3000
|
|
506
|
+
|
|
507
|
+
# Router Configuration
|
|
508
|
+
A_ROUTER__PARSE_PARAMS_AUTOMATICALLY=true
|
|
509
|
+
|
|
510
|
+
# Development Configuration
|
|
511
|
+
CONFIG_VERBOSE=true
|
|
512
|
+
DEV_MODE=true
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
## Contributing
|
|
516
|
+
|
|
517
|
+
1. Fork the repository
|
|
518
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
519
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
520
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
521
|
+
5. Open a Pull Request
|
|
522
|
+
|
|
523
|
+
## License
|
|
524
|
+
|
|
525
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
526
|
+
|
|
527
|
+
## Support
|
|
528
|
+
|
|
529
|
+
- 📚 [Documentation](https://docs.adaas.org)
|
|
530
|
+
- 🐛 [Issue Tracker](https://github.com/ADAAS-org/adaas-a-server/issues)
|
|
531
|
+
- 💬 [Community Discord](https://discord.gg/adaas)
|
|
532
|
+
- 📧 [Email Support](mailto:support@adaas.org)
|
|
533
|
+
```
|
|
534
|
+
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
export { A_HTTPChannel } from './src/channels/A-Http/A-Http.channel';
|
|
2
|
+
export { A_HTTPChannelError } from './src/channels/A-Http/A-Http.channel.error';
|
|
3
|
+
export * from './src/constants/env.constants';
|
|
1
4
|
export { A_Service } from './src/containers/A-Service/A-Service.container';
|
|
2
5
|
export { A_Server } from './src/context/A-Server/A_Server.context';
|
|
3
|
-
export { A_ProxyConfig } from './src/context/
|
|
6
|
+
export { A_ProxyConfig } from './src/context/A-ProxyConfig/A_ProxyConfig.context';
|
|
4
7
|
export { A_StaticConfig } from './src/context/A-StaticConfig/A-StaticConfig.context';
|
|
5
|
-
export { A_ListQueryFilter } from './src/context/
|
|
8
|
+
export { A_ListQueryFilter } from './src/context/A-ListQueryFilter/A_ListQueryFilter.context';
|
|
9
|
+
export { A_EntityFactory } from './src/context/A-EntityFactory/A-EntityFactory.context';
|
|
10
|
+
export { A_HTTPChannel_RequestContext } from './src/context/A-HttpChannel/A-HttpChannel.context';
|
|
6
11
|
export { A_Request } from './src/entities/A-Request/A-Request.entity';
|
|
7
12
|
export { A_Response } from './src/entities/A-Response/A-Response.entity';
|
|
8
13
|
export { A_Route } from './src/entities/A-Route/A-Route.entity';
|
|
@@ -16,10 +21,16 @@ export { A_ServerCORS } from './src/components/A-ServerCORS/A_ServerCORS.compone
|
|
|
16
21
|
export { A_StaticLoader } from './src/components/A-StaticLoader/A-StaticLoader.component';
|
|
17
22
|
export { A_Controller } from './src/components/A-Controller/A-Controller.component';
|
|
18
23
|
export { A_ListingController } from './src/components/A-ListingController/A-ListingController.component';
|
|
24
|
+
export { A_CommandController } from './src/components/A-CommandController/A-CommandController.component';
|
|
25
|
+
export { A_EntityRepository } from './src/components/A-EntityRepository/A-EntityRepository.component';
|
|
26
|
+
export { A_ServerError } from './src/components/A-ServerError/A-ServerError.class';
|
|
19
27
|
export * from './src/containers/A-Service/A-Service.container.types';
|
|
20
|
-
export * from './src/
|
|
21
|
-
export * from './src/context/
|
|
28
|
+
export * from './src/context/A-ProxyConfig/A_ProxyConfig.types';
|
|
29
|
+
export * from './src/context/A-EntityFactory/A-EntityFactory.context.types';
|
|
22
30
|
export * from './src/entities/A-Request/A-Request.entity.types';
|
|
23
31
|
export * from './src/entities/A-Response/A-Response.entity.types';
|
|
24
32
|
export * from './src/components/A-ServerCORS/A_ServerCORS.component.types';
|
|
25
|
-
export * from
|
|
33
|
+
export * from './src/components/A-Router/A-Router.component.types';
|
|
34
|
+
export * from './src/components/A-ServerError/A-ServerError.types';
|
|
35
|
+
export * from './src/channels/A-Http/A-Http.channel.types';
|
|
36
|
+
export * from './src/channels/A-Http/A-Http.channel.constants';
|