5htp-core 0.3.1-2 → 0.3.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/client/services/router/components/Link.tsx +1 -1
- package/src/client/services/router/components/Page.tsx +2 -1
- package/src/client/services/router/index.tsx +17 -26
- package/src/client/services/router/request/api.ts +12 -4
- package/src/client/services/router/response/page.ts +5 -7
- package/src/common/router/index.ts +2 -1
- package/src/common/router/register.ts +5 -8
- package/src/common/router/response/page.ts +31 -17
- package/src/server/app/service/index.ts +6 -7
- package/src/server/services/database/datatypes.ts +13 -2
- package/src/server/services/router/http/index.ts +1 -1
- package/src/server/services/router/index.ts +7 -5
- package/src/server/services/router/request/api.ts +8 -1
- package/src/server/services/router/response/page/index.tsx +4 -5
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.
|
|
4
|
+
"version": "0.3.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",
|
|
@@ -19,7 +19,7 @@ export const Link = ({ to, ...props }: {
|
|
|
19
19
|
} & React.HTMLProps<HTMLAnchorElement>) => {
|
|
20
20
|
|
|
21
21
|
// External = open in new tab by default
|
|
22
|
-
if (to[0] !== '/' || to.startsWith('//'))
|
|
22
|
+
if (to && (to[0] !== '/' || to.startsWith('//')))
|
|
23
23
|
props.target = '_blank';
|
|
24
24
|
// Otherwise, propagate to the router
|
|
25
25
|
else
|
|
@@ -22,6 +22,7 @@ export default ({ page, isCurrent }: { page: Page, isCurrent?: boolean }) => {
|
|
|
22
22
|
page.loading ? null : page.data
|
|
23
23
|
);
|
|
24
24
|
page.setAllData = setApiData;
|
|
25
|
+
context.data = apiData;
|
|
25
26
|
|
|
26
27
|
React.useEffect(() => {
|
|
27
28
|
|
|
@@ -50,7 +51,7 @@ export default ({ page, isCurrent }: { page: Page, isCurrent?: boolean }) => {
|
|
|
50
51
|
// URL params
|
|
51
52
|
{...context.request.data}
|
|
52
53
|
// API data
|
|
53
|
-
{
|
|
54
|
+
data={apiData}
|
|
54
55
|
/>
|
|
55
56
|
|
|
56
57
|
) : null
|
|
@@ -20,7 +20,7 @@ import BaseRouter, {
|
|
|
20
20
|
import { getLayout } from '@common/router/layouts';
|
|
21
21
|
import { getRegisterPageArgs, buildRegex } from '@common/router/register';
|
|
22
22
|
import { TFetcherList } from '@common/router/request/api';
|
|
23
|
-
import type { TFrontRenderer
|
|
23
|
+
import type { TFrontRenderer } from '@common/router/response/page';
|
|
24
24
|
|
|
25
25
|
import App from '@client/app/component';
|
|
26
26
|
import type ClientApplication from '@client/app';
|
|
@@ -61,21 +61,18 @@ export type Response = ClientResponse<ClientRouter> | ServerResponse<ServerRoute
|
|
|
61
61
|
- TYPES: ROUTES LOADING
|
|
62
62
|
----------------------------------*/
|
|
63
63
|
|
|
64
|
-
// WARN: To be updated with the mplemenations list of Router.page
|
|
64
|
+
// WARN: To be updated with the mplemenations list of Router.page AND the routes babel plugin
|
|
65
65
|
// (both server and client side)
|
|
66
|
-
export type TRegisterPageArgs<
|
|
66
|
+
export type TRegisterPageArgs<
|
|
67
|
+
TProvidedData extends TFetcherList = TFetcherList,
|
|
68
|
+
TRouter extends Router = Router
|
|
69
|
+
> = ([
|
|
67
70
|
path: string,
|
|
68
|
-
controller: TDataProvider<TProvidedData> | null,
|
|
69
71
|
renderer: TFrontRenderer<TProvidedData>
|
|
70
72
|
] | [
|
|
71
73
|
path: string,
|
|
72
74
|
options: Partial<TRoute["options"]>,
|
|
73
75
|
renderer: TFrontRenderer<TProvidedData>
|
|
74
|
-
] | [
|
|
75
|
-
path: string,
|
|
76
|
-
options: Partial<TRoute["options"]>,
|
|
77
|
-
controller: TDataProvider<TProvidedData> | null,
|
|
78
|
-
renderer: TFrontRenderer<TProvidedData>
|
|
79
76
|
])
|
|
80
77
|
|
|
81
78
|
// Route definition passed by the server
|
|
@@ -221,28 +218,20 @@ export default class ClientRouter<
|
|
|
221
218
|
return currentRoute;
|
|
222
219
|
}
|
|
223
220
|
|
|
224
|
-
public page(
|
|
221
|
+
public page<TProvidedData extends TFetcherList = TFetcherList>(
|
|
225
222
|
path: string,
|
|
226
|
-
|
|
227
|
-
renderer: TFrontRenderer<{}>
|
|
223
|
+
renderer: TFrontRenderer<TProvidedData>
|
|
228
224
|
): TRoute;
|
|
229
225
|
|
|
230
|
-
public page(
|
|
226
|
+
public page<TProvidedData extends TFetcherList = TFetcherList>(
|
|
231
227
|
path: string,
|
|
232
228
|
options: Partial<TRoute["options"]>,
|
|
233
|
-
renderer: TFrontRenderer<
|
|
234
|
-
): TRoute;
|
|
235
|
-
|
|
236
|
-
public page(
|
|
237
|
-
path: string,
|
|
238
|
-
options: Partial<TRoute["options"]>,
|
|
239
|
-
controller: TDataProvider<{}> | null,
|
|
240
|
-
renderer: TFrontRenderer<{}>
|
|
229
|
+
renderer: TFrontRenderer<TProvidedData>
|
|
241
230
|
): TRoute;
|
|
242
231
|
|
|
243
232
|
public page(...args: TRegisterPageArgs): TRoute {
|
|
244
233
|
|
|
245
|
-
const { path, options,
|
|
234
|
+
const { path, options, renderer, layout } = getRegisterPageArgs(...args);
|
|
246
235
|
|
|
247
236
|
// S'il s'agit d'une page, son id doit avoir été injecté via le plugin babel
|
|
248
237
|
const id = options["id"];
|
|
@@ -260,7 +249,7 @@ export default class ClientRouter<
|
|
|
260
249
|
...defaultOptions,
|
|
261
250
|
...options
|
|
262
251
|
},
|
|
263
|
-
controller: (context: TClientOrServerContext) => new ClientPage(
|
|
252
|
+
controller: (context: TClientOrServerContext) => new ClientPage(route, renderer, context, layout)
|
|
264
253
|
};
|
|
265
254
|
|
|
266
255
|
this.routes.push(route);
|
|
@@ -275,7 +264,7 @@ export default class ClientRouter<
|
|
|
275
264
|
|
|
276
265
|
const route: TErrorRoute = {
|
|
277
266
|
code,
|
|
278
|
-
controller: (context: TClientOrServerContext) => new ClientPage(
|
|
267
|
+
controller: (context: TClientOrServerContext) => new ClientPage(route, renderer, context, layout),
|
|
279
268
|
options
|
|
280
269
|
};
|
|
281
270
|
|
|
@@ -391,7 +380,9 @@ export default class ClientRouter<
|
|
|
391
380
|
|
|
392
381
|
const response = await this.createResponse(route, request, apiData)
|
|
393
382
|
|
|
394
|
-
ReactDOM.hydrate(
|
|
383
|
+
ReactDOM.hydrate((
|
|
384
|
+
<App context={response.context} />
|
|
385
|
+
), document.body, () => {
|
|
395
386
|
|
|
396
387
|
console.log(`Render complete`);
|
|
397
388
|
|
|
@@ -404,7 +395,7 @@ export default class ClientRouter<
|
|
|
404
395
|
pageData: {} = {}
|
|
405
396
|
): Promise<ClientPage> {
|
|
406
397
|
|
|
407
|
-
// Load if not done before
|
|
398
|
+
// Load the route if not done before
|
|
408
399
|
if ('load' in route)
|
|
409
400
|
route = this.routes[route.index] = await this.load(route);
|
|
410
401
|
|
|
@@ -9,7 +9,8 @@ import axios, { AxiosResponse, AxiosError, AxiosRequestConfig } from 'axios';
|
|
|
9
9
|
import type { TApiResponseData } from '@server/services/router';
|
|
10
10
|
import ApiClientService, {
|
|
11
11
|
TPostData,
|
|
12
|
-
TApiFetchOptions, TFetcherList, TFetcherArgs, TFetcher
|
|
12
|
+
TApiFetchOptions, TFetcherList, TFetcherArgs, TFetcher,
|
|
13
|
+
TDataReturnedByFetchers
|
|
13
14
|
} from '@common/router/request/api';
|
|
14
15
|
import { instancierViaCode, NetworkError } from '@common/errors';
|
|
15
16
|
import type ClientApplication from '@client/app';
|
|
@@ -46,6 +47,13 @@ export default class ApiClient implements ApiClientService {
|
|
|
46
47
|
/*----------------------------------
|
|
47
48
|
- HIGH LEVEL
|
|
48
49
|
----------------------------------*/
|
|
50
|
+
|
|
51
|
+
public fetch<TProvidedData extends TFetcherList = TFetcherList>(
|
|
52
|
+
fetchers: TFetcherList
|
|
53
|
+
): TDataReturnedByFetchers<TProvidedData> {
|
|
54
|
+
throw new Error("api.fetch shouldn't be called here.");
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
public get = <TData extends unknown = unknown>(path: string, data?: TPostData, opts?: TApiFetchOptions) =>
|
|
50
58
|
this.createFetcher<TData>('GET', path, data, opts);
|
|
51
59
|
|
|
@@ -120,7 +128,7 @@ export default class ApiClient implements ApiClientService {
|
|
|
120
128
|
/*if (options?.captcha !== undefined)
|
|
121
129
|
await this.gui.captcha.check(options?.captcha);*/
|
|
122
130
|
|
|
123
|
-
return await this.
|
|
131
|
+
return await this.execute<TData>(method, path, data, options).catch((e) => {
|
|
124
132
|
this.app.handleError(e);
|
|
125
133
|
throw e; // Throw to break the loop
|
|
126
134
|
})
|
|
@@ -141,7 +149,7 @@ export default class ApiClient implements ApiClientService {
|
|
|
141
149
|
// Fetch all the api data thanks to one http request
|
|
142
150
|
const fetchedData = fetchersCount === 0
|
|
143
151
|
? 0
|
|
144
|
-
: await this.
|
|
152
|
+
: await this.execute("POST", "/api", {
|
|
145
153
|
fetchers: fetchersToRun
|
|
146
154
|
}).then((res) => {
|
|
147
155
|
|
|
@@ -201,7 +209,7 @@ export default class ApiClient implements ApiClientService {
|
|
|
201
209
|
return config;
|
|
202
210
|
}
|
|
203
211
|
|
|
204
|
-
public
|
|
212
|
+
public execute<TData = unknown>(...args: TFetcherArgs): Promise<TData> {
|
|
205
213
|
|
|
206
214
|
const config = this.configure(...args);
|
|
207
215
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import type { ComponentChild } from 'preact';
|
|
7
7
|
|
|
8
8
|
// Core
|
|
9
|
-
import type { TClientOrServerContext, Layout } from '@common/router';
|
|
10
|
-
import PageResponse, {
|
|
9
|
+
import type { TClientOrServerContext, Layout, TRoute, TErrorRoute } from '@common/router';
|
|
10
|
+
import PageResponse, { TFrontRenderer } from "@common/router/response/page";
|
|
11
11
|
|
|
12
12
|
// Specific
|
|
13
13
|
import type ClientRouter from '..';
|
|
@@ -29,15 +29,13 @@ export default class ClientPage<TRouter = ClientRouter> extends PageResponse<TRo
|
|
|
29
29
|
public scrollToId: string;
|
|
30
30
|
|
|
31
31
|
public constructor(
|
|
32
|
-
public
|
|
32
|
+
public route: TRoute | TErrorRoute,
|
|
33
33
|
public component: TFrontRenderer,
|
|
34
34
|
public context: TClientOrServerContext,
|
|
35
|
-
public layout?: Layout
|
|
36
|
-
|
|
37
|
-
public route = context.route
|
|
35
|
+
public layout?: Layout
|
|
38
36
|
) {
|
|
39
37
|
|
|
40
|
-
super(
|
|
38
|
+
super(route, component, context);
|
|
41
39
|
|
|
42
40
|
this.bodyId = context.route.options.bodyId;
|
|
43
41
|
this.scrollToId = context.request.hash;
|
|
@@ -20,7 +20,7 @@ import type { TUserRole } from '@server/services/users';
|
|
|
20
20
|
import type { TAppArrowFunction } from '@common/app';
|
|
21
21
|
|
|
22
22
|
// Specfic
|
|
23
|
-
import type { default as Page, TFrontRenderer } from './response/page';
|
|
23
|
+
import type { default as Page, TFrontRenderer, TDataProvider } from './response/page';
|
|
24
24
|
|
|
25
25
|
/*----------------------------------
|
|
26
26
|
- TYPES: ROUTES
|
|
@@ -81,6 +81,7 @@ export type TRouteOptions = {
|
|
|
81
81
|
|
|
82
82
|
// Injected by the page plugin
|
|
83
83
|
filepath?: string,
|
|
84
|
+
data?: TDataProvider
|
|
84
85
|
|
|
85
86
|
// Indexing
|
|
86
87
|
bodyId?: string,
|
|
@@ -10,7 +10,7 @@ import { getLayout } from './layouts';
|
|
|
10
10
|
|
|
11
11
|
// types
|
|
12
12
|
import type { TRouteOptions } from '.';
|
|
13
|
-
import type {
|
|
13
|
+
import type { TFrontRenderer } from './response/page';
|
|
14
14
|
import type { TRegisterPageArgs } from '@client/services/router';
|
|
15
15
|
|
|
16
16
|
/*----------------------------------
|
|
@@ -21,20 +21,17 @@ export const getRegisterPageArgs = (...args: TRegisterPageArgs) => {
|
|
|
21
21
|
|
|
22
22
|
let path: string;
|
|
23
23
|
let options: Partial<TRouteOptions> = {};
|
|
24
|
-
let controller: TDataProvider|null;
|
|
25
24
|
let renderer: TFrontRenderer;
|
|
26
25
|
|
|
27
|
-
if (args.length ===
|
|
28
|
-
([path,
|
|
29
|
-
else if (typeof args[1] === 'object')
|
|
30
|
-
([path, options, renderer] = args)
|
|
26
|
+
if (args.length === 2)
|
|
27
|
+
([path, renderer] = args)
|
|
31
28
|
else
|
|
32
|
-
([path,
|
|
29
|
+
([path, options, renderer] = args)
|
|
33
30
|
|
|
34
31
|
// Automatic layout form the nearest _layout folder
|
|
35
32
|
const layout = getLayout(path, options);
|
|
36
33
|
|
|
37
|
-
return { path, options,
|
|
34
|
+
return { path, options, renderer, layout }
|
|
38
35
|
|
|
39
36
|
}
|
|
40
37
|
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
- DEPENDANCES
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Npm
|
|
6
|
+
import type { VNode } from 'preact';
|
|
6
7
|
|
|
7
8
|
// Core libs
|
|
8
|
-
import { ClientOrServerRouter, TClientOrServerContext } from '@common/router';
|
|
9
|
+
import { ClientOrServerRouter, TClientOrServerContext, TRoute, TErrorRoute } from '@common/router';
|
|
9
10
|
import { TFetcherList, TDataReturnedByFetchers } from '@common/router/request/api';
|
|
10
11
|
import { history } from '@client/services/router/request/history';
|
|
11
12
|
|
|
@@ -14,21 +15,30 @@ import { history } from '@client/services/router/request/history';
|
|
|
14
15
|
----------------------------------*/
|
|
15
16
|
|
|
16
17
|
// The function that fetch data from the api before to pass them as context to the renderer
|
|
17
|
-
export type TDataProvider<TProvidedData extends TFetcherList =
|
|
18
|
-
|
|
18
|
+
export type TDataProvider<TProvidedData extends TFetcherList = TFetcherList> = (
|
|
19
|
+
context: TClientOrServerContext & {
|
|
20
|
+
// URL query parameters
|
|
21
|
+
// TODO: typings
|
|
22
|
+
data: {[key: string]: string | number}
|
|
23
|
+
}
|
|
24
|
+
) => TProvidedData
|
|
19
25
|
|
|
20
26
|
// The function that renders routes
|
|
21
27
|
export type TFrontRenderer<
|
|
22
|
-
TProvidedData extends TFetcherList =
|
|
23
|
-
TAdditionnalData = {},
|
|
28
|
+
TProvidedData extends TFetcherList = TFetcherList,
|
|
29
|
+
TAdditionnalData extends {} = {},
|
|
24
30
|
TRouter = ClientOrServerRouter,
|
|
25
|
-
> =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
> = (
|
|
32
|
+
context: (
|
|
33
|
+
TClientOrServerContext
|
|
34
|
+
&
|
|
35
|
+
TAdditionnalData
|
|
36
|
+
&
|
|
37
|
+
{
|
|
38
|
+
data: TDataReturnedByFetchers<TProvidedData>
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
) => VNode<any> | null
|
|
32
42
|
|
|
33
43
|
// Script or CSS resource
|
|
34
44
|
export type TPageResource = {
|
|
@@ -46,7 +56,7 @@ const debug = false;
|
|
|
46
56
|
/*----------------------------------
|
|
47
57
|
- CLASS
|
|
48
58
|
----------------------------------*/
|
|
49
|
-
export default class PageResponse<TRouter extends ClientOrServerRouter = ClientOrServerRouter> {
|
|
59
|
+
export default abstract class PageResponse<TRouter extends ClientOrServerRouter = ClientOrServerRouter> {
|
|
50
60
|
|
|
51
61
|
// Metadata
|
|
52
62
|
public chunkId: string;
|
|
@@ -65,7 +75,7 @@ export default class PageResponse<TRouter extends ClientOrServerRouter = ClientO
|
|
|
65
75
|
public data: TObjetDonnees = {};
|
|
66
76
|
|
|
67
77
|
public constructor(
|
|
68
|
-
public
|
|
78
|
+
public route: TRoute | TErrorRoute,
|
|
69
79
|
public renderer: TFrontRenderer,
|
|
70
80
|
public context: TClientOrServerContext
|
|
71
81
|
) {
|
|
@@ -77,8 +87,12 @@ export default class PageResponse<TRouter extends ClientOrServerRouter = ClientO
|
|
|
77
87
|
public async fetchData() {
|
|
78
88
|
|
|
79
89
|
// Load the fetchers list to load data if needed
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
const dataFetcher = this.route.options.data;
|
|
91
|
+
if (dataFetcher)
|
|
92
|
+
this.fetchers = dataFetcher({
|
|
93
|
+
...this.context,
|
|
94
|
+
data: this.context.request.data
|
|
95
|
+
});
|
|
82
96
|
|
|
83
97
|
// Execute the fetchers for missing data
|
|
84
98
|
debug && console.log(`[router][page] Fetching api data:` + Object.keys(this.fetchers));
|
|
@@ -41,12 +41,6 @@ export type StartedServicesIndex = {
|
|
|
41
41
|
[serviceId: string]: AnyService
|
|
42
42
|
}
|
|
43
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
|
-
|
|
50
44
|
/*----------------------------------
|
|
51
45
|
- CONFIG
|
|
52
46
|
----------------------------------*/
|
|
@@ -156,8 +150,13 @@ export default abstract class Service<
|
|
|
156
150
|
serviceId: TServiceId,
|
|
157
151
|
subServices?: TSubServices
|
|
158
152
|
): (
|
|
153
|
+
// We can't pass the services types as a generic to TServiceClass
|
|
154
|
+
// So we overwrite the services property
|
|
155
|
+
ReturnType< TServiceClass["getServiceInstance"] >
|
|
156
|
+
&
|
|
159
157
|
{
|
|
160
|
-
new (...args: any[]): TServiceClass & { services: TSubServices }
|
|
158
|
+
new (...args: any[]): TServiceClass & { services: TSubServices },
|
|
159
|
+
services: TSubServices
|
|
161
160
|
}
|
|
162
161
|
/*Omit<TServiceClass, 'services'> & {
|
|
163
162
|
services: TSubServices
|
|
@@ -107,13 +107,16 @@ export const mysqlToJs = {
|
|
|
107
107
|
'POINT': 'float',
|
|
108
108
|
|
|
109
109
|
// Integres
|
|
110
|
-
'
|
|
111
|
-
'BIGINT': 'int',
|
|
110
|
+
'BIT': 'int',
|
|
112
111
|
'LONG': 'int',
|
|
113
112
|
'LONGLONG': 'int',
|
|
113
|
+
|
|
114
114
|
'TINYINT': 'int',
|
|
115
115
|
'SMALLINT': 'int',
|
|
116
116
|
'MEDIUMINT': 'int',
|
|
117
|
+
'INT': 'int',
|
|
118
|
+
'INTEGER': 'int',
|
|
119
|
+
'BIGINT': 'int',
|
|
117
120
|
|
|
118
121
|
// Dates
|
|
119
122
|
'DATE': 'date',
|
|
@@ -121,10 +124,18 @@ export const mysqlToJs = {
|
|
|
121
124
|
|
|
122
125
|
// Strings
|
|
123
126
|
'VARCHAR': 'string',
|
|
127
|
+
'BINARY': 'string',
|
|
128
|
+
'VARBINARY': 'string',
|
|
129
|
+
'TINYBLOB': 'string',
|
|
130
|
+
'TINY_BLOB': 'string',
|
|
131
|
+
'MEDIUM_BLOB': 'string',
|
|
124
132
|
'BLOB': 'string',
|
|
133
|
+
'LONG_BLOB': 'string',
|
|
125
134
|
'CHAR': 'string',
|
|
126
135
|
'VAR_STRING': 'string',
|
|
127
136
|
'LONGTEXT': 'string',
|
|
137
|
+
'TINYTEXT': 'string',
|
|
138
|
+
'MEDIUMTEXT': 'string',
|
|
128
139
|
'TEXT': 'string',
|
|
129
140
|
'ENUM': 'enum',
|
|
130
141
|
|
|
@@ -194,7 +194,7 @@ export default class HttpServer {
|
|
|
194
194
|
----------------------------------*/
|
|
195
195
|
|
|
196
196
|
// TODO: Migrer dans app
|
|
197
|
-
routes.use('/chrome', cors());
|
|
197
|
+
//routes.use('/chrome', cors());
|
|
198
198
|
// TODO: Trouver une solution pour n'autoriser les requetes que depuis l'application & dopamyn.io
|
|
199
199
|
// https://www.google.com/search?q=http+cors+from+android%7Cwindows%7Cdesktop%7Cmodile+app
|
|
200
200
|
//routes.use('/auth', cors());
|
|
@@ -133,7 +133,7 @@ export default class ServerRouter<
|
|
|
133
133
|
public constructor(
|
|
134
134
|
parent: AnyService,
|
|
135
135
|
config: Config,
|
|
136
|
-
services:
|
|
136
|
+
services: TSubservices,
|
|
137
137
|
app: Application,
|
|
138
138
|
) {
|
|
139
139
|
|
|
@@ -216,7 +216,7 @@ export default class ServerRouter<
|
|
|
216
216
|
|
|
217
217
|
public page(...args: TRegisterPageArgs) {
|
|
218
218
|
|
|
219
|
-
const { path, options,
|
|
219
|
+
const { path, options, renderer, layout } = getRegisterPageArgs(...args);
|
|
220
220
|
|
|
221
221
|
const { regex, keys } = buildRegex(path);
|
|
222
222
|
|
|
@@ -225,7 +225,7 @@ export default class ServerRouter<
|
|
|
225
225
|
path,
|
|
226
226
|
regex,
|
|
227
227
|
keys,
|
|
228
|
-
controller: (context: TRouterContext<this>) => new Page(
|
|
228
|
+
controller: (context: TRouterContext<this>) => new Page(route, renderer, context, layout),
|
|
229
229
|
options: {
|
|
230
230
|
...defaultOptions,
|
|
231
231
|
accept: 'html', // Les pages retournent forcémment du html
|
|
@@ -248,11 +248,13 @@ export default class ServerRouter<
|
|
|
248
248
|
// Automatic layout form the nearest _layout folder
|
|
249
249
|
const layout = getLayout('Error ' + code, options);
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
const route = {
|
|
252
252
|
code,
|
|
253
|
-
controller: (context: TRouterContext<this>) => new Page(
|
|
253
|
+
controller: (context: TRouterContext<this>) => new Page(route, renderer, context, layout),
|
|
254
254
|
options
|
|
255
255
|
};
|
|
256
|
+
|
|
257
|
+
this.errors[code] = route;
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
public all = (...args: TApiRegisterArgs<this>) => this.registerApi('*', ...args);
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import RequestService from './service';
|
|
8
8
|
|
|
9
9
|
import ApiClientService, {
|
|
10
|
-
TApiFetchOptions, TFetcherList, TFetcherArgs, TFetcher
|
|
10
|
+
TApiFetchOptions, TFetcherList, TFetcherArgs, TFetcher,
|
|
11
|
+
TDataReturnedByFetchers
|
|
11
12
|
} from '@common/router/request/api';
|
|
12
13
|
|
|
13
14
|
/*----------------------------------
|
|
@@ -28,6 +29,12 @@ export default class ApiClientRequest extends RequestService implements ApiClien
|
|
|
28
29
|
- HIGH LEVEL
|
|
29
30
|
----------------------------------*/
|
|
30
31
|
|
|
32
|
+
public fetch<TProvidedData extends TFetcherList = TFetcherList>(
|
|
33
|
+
fetchers: TFetcherList
|
|
34
|
+
): TDataReturnedByFetchers<TProvidedData> {
|
|
35
|
+
throw new Error("api.fetch shouldn't be called here.");
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
public get = <TData extends unknown = unknown>(path: string, data?: TObjetDonnees, opts?: TApiFetchOptions) =>
|
|
32
39
|
this.createFetcher<TData>('GET', path, data, opts);
|
|
33
40
|
|
|
@@ -9,8 +9,8 @@ const safeStringify = require('fast-safe-stringify'); // remplace les référenc
|
|
|
9
9
|
|
|
10
10
|
// Core
|
|
11
11
|
import { default as Router, TRouterContext } from "@server/services/router";
|
|
12
|
-
import type { Layout } from '@common/router';
|
|
13
|
-
import PageResponse, {
|
|
12
|
+
import type { Layout, TRoute, TErrorRoute } from '@common/router';
|
|
13
|
+
import PageResponse, { TFrontRenderer } from "@common/router/response/page";
|
|
14
14
|
|
|
15
15
|
// Composants UI
|
|
16
16
|
import App from '@client/app/component';
|
|
@@ -34,18 +34,17 @@ const seoLimits = {
|
|
|
34
34
|
export default class Page<TRouter extends Router = Router> extends PageResponse<TRouter> {
|
|
35
35
|
|
|
36
36
|
public constructor(
|
|
37
|
-
public
|
|
37
|
+
public route: TRoute | TErrorRoute,
|
|
38
38
|
public renderer: TFrontRenderer,
|
|
39
39
|
public context: TRouterContext,
|
|
40
40
|
public layout?: Layout,
|
|
41
41
|
|
|
42
|
-
public route = context.route,
|
|
43
42
|
public app = context.app,
|
|
44
43
|
public router = context.request.router,
|
|
45
44
|
|
|
46
45
|
) {
|
|
47
46
|
|
|
48
|
-
super(
|
|
47
|
+
super(route, renderer, context)
|
|
49
48
|
|
|
50
49
|
}
|
|
51
50
|
|