5htp-core 0.3.1-1 → 0.3.1-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.
- package/package.json +1 -1
- package/src/server/app/index.ts +12 -3
- package/src/server/app/service/container.ts +1 -1
- package/src/server/app/service/index.ts +25 -7
- package/src/server/services/database/datatypes.ts +1 -0
- package/src/server/services/disks/index.ts +1 -2
- package/src/server/services/router/http/index.ts +1 -1
- package/src/server/services/router/index.ts +7 -8
- package/src/server/services/router/response/index.ts +2 -2
- package/src/server/services/schema/router/index.ts +1 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.3.1-
|
|
4
|
+
"version": "0.3.1-2",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
package/src/server/app/index.ts
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
// Core
|
|
6
6
|
import AppContainer from './container';
|
|
7
|
-
import ApplicationService, {
|
|
7
|
+
import ApplicationService, { StartedServicesIndex } from './service';
|
|
8
8
|
import CommandsManager from './commands';
|
|
9
|
-
import ServicesContainer, {
|
|
9
|
+
import ServicesContainer, {
|
|
10
|
+
ServicesContainer as ServicesContainerClass,
|
|
11
|
+
TRegisteredService,
|
|
12
|
+
TServiceMetas
|
|
13
|
+
} from './service/container';
|
|
10
14
|
import type { ServerBug } from '../services/console';
|
|
11
15
|
|
|
12
16
|
// Built-in
|
|
@@ -49,7 +53,12 @@ export const Service = ServicesContainer;
|
|
|
49
53
|
/*----------------------------------
|
|
50
54
|
- FUNCTIONS
|
|
51
55
|
----------------------------------*/
|
|
52
|
-
export class Application
|
|
56
|
+
export class Application<
|
|
57
|
+
TServicesContainer extends ServicesContainerClass = ServicesContainerClass
|
|
58
|
+
> extends ApplicationService<Config, Hooks, /* TODO: this ? */Application, {}> {
|
|
59
|
+
|
|
60
|
+
public app!: this;
|
|
61
|
+
public servicesContainer!: TServicesContainer;
|
|
53
62
|
|
|
54
63
|
/*----------------------------------
|
|
55
64
|
- PROPERTIES
|
|
@@ -53,7 +53,7 @@ export class ServicesContainer<
|
|
|
53
53
|
public registered: TRegisteredServicesIndex = {}
|
|
54
54
|
|
|
55
55
|
// All service instances by service id
|
|
56
|
-
public allServices:
|
|
56
|
+
public allServices: TServicesIndex = {} as TServicesIndex
|
|
57
57
|
|
|
58
58
|
public setup<TServiceId extends keyof TServicesIndex>(
|
|
59
59
|
serviceId: keyof TServicesIndex,
|
|
@@ -12,7 +12,8 @@ import ServicesContainer from './container';
|
|
|
12
12
|
- TYPES: OPTIONS
|
|
13
13
|
----------------------------------*/
|
|
14
14
|
|
|
15
|
-
export type AnyService =
|
|
15
|
+
export type AnyService<TSubServices extends StartedServicesIndex = StartedServicesIndex> =
|
|
16
|
+
Service<{}, {}, Application, TSubServices>
|
|
16
17
|
|
|
17
18
|
type TServiceConfig = {
|
|
18
19
|
debug?: boolean
|
|
@@ -40,6 +41,12 @@ export type StartedServicesIndex = {
|
|
|
40
41
|
[serviceId: string]: AnyService
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
type ClassType<T = {}> = new (...args: any[]) => T;
|
|
45
|
+
|
|
46
|
+
type ServiceWithSubservices<TService extends ClassType<AnyService>, TSubservices extends StartedServicesIndex> = {
|
|
47
|
+
new (...args: any[]): TService & { services: TSubservices }
|
|
48
|
+
};
|
|
49
|
+
|
|
43
50
|
/*----------------------------------
|
|
44
51
|
- CONFIG
|
|
45
52
|
----------------------------------*/
|
|
@@ -140,10 +147,21 @@ export default abstract class Service<
|
|
|
140
147
|
// this.use immediatly instanciate the subservice for few reasons:
|
|
141
148
|
// - The subservice instance can be accesses from another service in the constructor, no matter the order of loading of the services
|
|
142
149
|
// - Consistency: the subserviuce proprties shouldn't be assogned to two different values according depending on the app lifecycle
|
|
143
|
-
public use<
|
|
150
|
+
public use<
|
|
151
|
+
TInstalledServices extends this["app"]["servicesContainer"]["allServices"],
|
|
152
|
+
TServiceId extends keyof TInstalledServices,
|
|
153
|
+
TServiceClass extends TInstalledServices[TServiceId],
|
|
154
|
+
TSubServices extends TServiceClass["services"],
|
|
155
|
+
>(
|
|
144
156
|
serviceId: TServiceId,
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
subServices?: TSubServices
|
|
158
|
+
): (
|
|
159
|
+
{
|
|
160
|
+
new (...args: any[]): TServiceClass & { services: TSubServices }
|
|
161
|
+
}
|
|
162
|
+
/*Omit<TServiceClass, 'services'> & {
|
|
163
|
+
services: TSubServices
|
|
164
|
+
}*/
|
|
147
165
|
) {
|
|
148
166
|
|
|
149
167
|
// Check of the service has been configurated
|
|
@@ -152,7 +170,7 @@ export default abstract class Service<
|
|
|
152
170
|
throw new Error(`Unable to use service "${serviceId}": This one hasn't been setup.`);
|
|
153
171
|
|
|
154
172
|
// Bind subservices
|
|
155
|
-
registered.subServices = subServices;
|
|
173
|
+
registered.subServices = subServices || {};
|
|
156
174
|
|
|
157
175
|
// Check if not already instanciated
|
|
158
176
|
const existing = ServicesContainer.allServices[ serviceId ];
|
|
@@ -176,7 +194,7 @@ export default abstract class Service<
|
|
|
176
194
|
return service;
|
|
177
195
|
}
|
|
178
196
|
|
|
179
|
-
|
|
197
|
+
public bindService( localName: string, service: AnyService ) {
|
|
180
198
|
|
|
181
199
|
const serviceScope = this.constructor.name + '.' + localName;
|
|
182
200
|
|
|
@@ -196,7 +214,7 @@ export default abstract class Service<
|
|
|
196
214
|
|
|
197
215
|
}
|
|
198
216
|
|
|
199
|
-
|
|
217
|
+
public async startService( localName: string, service: AnyService ) {
|
|
200
218
|
// Service already started
|
|
201
219
|
if (!service.started) {
|
|
202
220
|
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
// Core
|
|
6
6
|
import type { Application } from '@server/app';
|
|
7
7
|
import Service, { AnyService } from '@server/app/service';
|
|
8
|
-
import type { TRegisteredServicesIndex } from '@server/app/service/container';
|
|
9
8
|
|
|
10
9
|
// Specific
|
|
11
10
|
import type Driver from './driver';
|
|
@@ -25,7 +24,7 @@ export type Hooks = {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export type Services = {
|
|
28
|
-
|
|
27
|
+
[diskId: string]: Driver
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
/*----------------------------------
|
|
@@ -225,7 +225,7 @@ export default class HttpServer {
|
|
|
225
225
|
// Impossible donc de créer un serveur http ici, on le fera dans start.js
|
|
226
226
|
console.info("Lancement du serveur web");
|
|
227
227
|
this.http.listen(this.config.port, () => {
|
|
228
|
-
console.info(`
|
|
228
|
+
console.info(`Web server ready on ${this.publicUrl}`);
|
|
229
229
|
});
|
|
230
230
|
|
|
231
231
|
}
|
|
@@ -95,8 +95,6 @@ export type Config<
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export type Services = {
|
|
98
|
-
disks?: DisksManager
|
|
99
|
-
} & {
|
|
100
98
|
[routerServiceId: string]: RouterService
|
|
101
99
|
}
|
|
102
100
|
|
|
@@ -113,14 +111,15 @@ export type Hooks = {
|
|
|
113
111
|
- CLASSE
|
|
114
112
|
----------------------------------*/
|
|
115
113
|
export default class ServerRouter<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
> extends Service<TConfig, Hooks, TApplication, Services> implements BaseRouter {
|
|
114
|
+
TSubservices extends Services = Services
|
|
115
|
+
> extends Service<Config, Hooks, Application, TSubservices> implements BaseRouter {
|
|
119
116
|
|
|
117
|
+
public disks = this.use('Core/Disks') as unknown as DisksManager;
|
|
118
|
+
|
|
120
119
|
// Services
|
|
121
120
|
public http: HTTP;
|
|
122
121
|
public render: DocumentRenderer<this>;
|
|
123
|
-
protected routerServices:
|
|
122
|
+
protected routerServices: TSubservices = {} as TSubservices
|
|
124
123
|
|
|
125
124
|
// Indexed
|
|
126
125
|
public routes: TRoute[] = []; // API + pages front front
|
|
@@ -133,9 +132,9 @@ export default class ServerRouter<
|
|
|
133
132
|
|
|
134
133
|
public constructor(
|
|
135
134
|
parent: AnyService,
|
|
136
|
-
config:
|
|
135
|
+
config: Config,
|
|
137
136
|
services: Services,
|
|
138
|
-
app:
|
|
137
|
+
app: Application,
|
|
139
138
|
) {
|
|
140
139
|
|
|
141
140
|
super(parent, config, services, app);
|
|
@@ -242,11 +242,11 @@ export default class ServerResponse<
|
|
|
242
242
|
// ? this.app.path.root + '/bin' + fichier
|
|
243
243
|
// : this.app.path.data + '/' + fichier;
|
|
244
244
|
// Disk not provided = file response disabled
|
|
245
|
-
if (this.router.
|
|
245
|
+
if (this.router.disks === undefined)
|
|
246
246
|
throw new Anomaly("Router: Unable to return file response in router, because no disk has been given in the router config.");
|
|
247
247
|
|
|
248
248
|
// Retirve disk driver
|
|
249
|
-
const disk = this.router.
|
|
249
|
+
const disk = this.router.disks.get('default');
|
|
250
250
|
|
|
251
251
|
// Verif existance
|
|
252
252
|
const fileExists = await disk.exists('data', fichier);
|
|
@@ -14,7 +14,6 @@ import RequestValidator, { TConfig } from '../request';
|
|
|
14
14
|
- TYPES
|
|
15
15
|
----------------------------------*/
|
|
16
16
|
|
|
17
|
-
type TRouterWithSchema<TAuthService extends SchemaRouterService> = Router<RouterConfig<{ auth: TAuthService }>>
|
|
18
17
|
|
|
19
18
|
/*----------------------------------
|
|
20
19
|
- SERVICE
|
|
@@ -43,7 +42,7 @@ export default class SchemaRouterService<
|
|
|
43
42
|
- ROUTER SERVICE LIFECYCLE
|
|
44
43
|
----------------------------------*/
|
|
45
44
|
|
|
46
|
-
public requestService( request: ServerRequest
|
|
45
|
+
public requestService( request: ServerRequest ): RequestValidator {
|
|
47
46
|
return new RequestValidator( request, this.config );
|
|
48
47
|
}
|
|
49
48
|
}
|