5htp-core 0.4.9-9 → 0.4.9-91
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/app/component.tsx +2 -2
- package/src/client/services/router/index.tsx +3 -3
- package/src/client/services/router/response/page.ts +2 -2
- package/src/common/router/index.ts +9 -26
- package/src/common/router/response/page.ts +11 -7
- package/src/server/services/router/response/index.ts +1 -2
- package/src/server/services/router/response/page/index.tsx +2 -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.4.9-
|
|
4
|
+
"version": "0.4.9-91",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@ import DialogManager from '@client/components/Dialog/Manager'
|
|
|
12
12
|
|
|
13
13
|
// Core components
|
|
14
14
|
import RouterComponent from '@client/services/router/components/router';
|
|
15
|
-
import type {
|
|
15
|
+
import type { TClientOrServerContextForPage } from '@common/router';
|
|
16
16
|
|
|
17
17
|
// Resources
|
|
18
18
|
import '@client/assets/css/core.less';
|
|
@@ -21,7 +21,7 @@ import '@client/assets/css/core.less';
|
|
|
21
21
|
- COMPOSANT
|
|
22
22
|
----------------------------------*/
|
|
23
23
|
export default function App ({ context }: {
|
|
24
|
-
context:
|
|
24
|
+
context: TClientOrServerContextForPage,
|
|
25
25
|
}) {
|
|
26
26
|
|
|
27
27
|
const curLayout = context.page?.layout;
|
|
@@ -16,7 +16,7 @@ import type { TBasicSSrData } from '@server/services/router/response';
|
|
|
16
16
|
|
|
17
17
|
import BaseRouter, {
|
|
18
18
|
defaultOptions, TRoute, TErrorRoute,
|
|
19
|
-
|
|
19
|
+
TClientOrServerContextForPage, TRouteModule,
|
|
20
20
|
matchRoute, buildUrl, TDomainsList
|
|
21
21
|
} from '@common/router'
|
|
22
22
|
import { getLayout } from '@common/router/layouts';
|
|
@@ -282,7 +282,7 @@ export default class ClientRouter<
|
|
|
282
282
|
...defaultOptions,
|
|
283
283
|
...options
|
|
284
284
|
},
|
|
285
|
-
controller: (context:
|
|
285
|
+
controller: (context: TClientOrServerContextForPage) => new ClientPage(route, renderer, context, layout)
|
|
286
286
|
};
|
|
287
287
|
|
|
288
288
|
this.routes.push(route);
|
|
@@ -301,7 +301,7 @@ export default class ClientRouter<
|
|
|
301
301
|
|
|
302
302
|
const route: TErrorRoute = {
|
|
303
303
|
code,
|
|
304
|
-
controller: (context:
|
|
304
|
+
controller: (context: TClientOrServerContextForPage) => new ClientPage(route, renderer, context, layout),
|
|
305
305
|
options
|
|
306
306
|
};
|
|
307
307
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type { ComponentChild } from 'preact';
|
|
7
7
|
|
|
8
8
|
// Core
|
|
9
|
-
import type {
|
|
9
|
+
import type { TClientOrServerContextForPage, Layout, TRoute, TErrorRoute } from '@common/router';
|
|
10
10
|
import PageResponse, { TFrontRenderer } from "@common/router/response/page";
|
|
11
11
|
|
|
12
12
|
// Specific
|
|
@@ -29,7 +29,7 @@ export default class ClientPage<TRouter = ClientRouter> extends PageResponse<TRo
|
|
|
29
29
|
public constructor(
|
|
30
30
|
public route: TRoute | TErrorRoute,
|
|
31
31
|
public component: TFrontRenderer,
|
|
32
|
-
public context:
|
|
32
|
+
public context: TClientOrServerContextForPage,
|
|
33
33
|
public layout?: Layout
|
|
34
34
|
) {
|
|
35
35
|
|
|
@@ -35,7 +35,7 @@ export type { default as Response } from './response';
|
|
|
35
35
|
|
|
36
36
|
export type ClientOrServerRouter = ClientRouter | ServerRouter;
|
|
37
37
|
|
|
38
|
-
export type TRoute<RouterContext extends
|
|
38
|
+
export type TRoute<RouterContext extends TClientOrServerContextForPage = TClientOrServerContextForPage> = {
|
|
39
39
|
|
|
40
40
|
// Match
|
|
41
41
|
method: TRouteHttpMethod,
|
|
@@ -44,41 +44,24 @@ export type TRoute<RouterContext extends TClientOrServerContext = TClientOrServe
|
|
|
44
44
|
keys: (number | string)[],
|
|
45
45
|
|
|
46
46
|
// Execute
|
|
47
|
-
controller: TRouteController<RouterContext
|
|
47
|
+
controller: TRouteController<RouterContext>,
|
|
48
48
|
options: TRouteOptions
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export type TErrorRoute<RouterContext extends
|
|
51
|
+
export type TErrorRoute<RouterContext extends TClientOrServerContextForPage = TClientOrServerContextForPage> = {
|
|
52
52
|
code,
|
|
53
53
|
controller: TRouteController<RouterContext>,
|
|
54
54
|
options: TRouteOptions
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export type TAnyRoute<RouterContext extends
|
|
57
|
+
export type TAnyRoute<RouterContext extends TClientOrServerContextForPage = TClientOrServerContextForPage> =
|
|
58
58
|
TRoute<RouterContext> | TErrorRoute<RouterContext>
|
|
59
59
|
|
|
60
|
-
export type TClientOrServerContext =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
|
|
|
67
|
-
(
|
|
68
|
-
// Tell that all the keys of client context are existing but undefined
|
|
69
|
-
// This avoids errors: "Property 'page' is optional in type '{ app: Application; ..."
|
|
70
|
-
// When we destructure the context from the page controller
|
|
71
|
-
// While making reference to a key only available in client context
|
|
72
|
-
// So here, we put the
|
|
73
|
-
//{[clientContextKey in keyof ClientRouterContext/*Omit<ClientRouterContext, TClientOnlyContextKeys>*/]: undefined}
|
|
74
|
-
//&
|
|
75
|
-
|
|
76
|
-
// Page is always available in client context
|
|
77
|
-
With<ServerRouterContext, 'page'>
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
export type TRouteController<RouterContext extends TClientOrServerContext = TClientOrServerContext> =
|
|
60
|
+
export type TClientOrServerContext = ClientRouterContext | ServerRouterContext;
|
|
61
|
+
|
|
62
|
+
export type TClientOrServerContextForPage = With<TClientOrServerContext, 'page'>
|
|
63
|
+
|
|
64
|
+
export type TRouteController<RouterContext extends TClientOrServerContextForPage = TClientOrServerContextForPage> =
|
|
82
65
|
(context: RouterContext) => /* Page to render */Page | /* Any data (html, json) */Promise<any>
|
|
83
66
|
|
|
84
67
|
export type TRouteOptions = {
|
|
@@ -7,7 +7,7 @@ import type { VNode } from 'preact';
|
|
|
7
7
|
import type { Thing } from 'schema-dts';
|
|
8
8
|
|
|
9
9
|
// Core libs
|
|
10
|
-
import { ClientOrServerRouter,
|
|
10
|
+
import { ClientOrServerRouter, TClientOrServerContextForPage, TRoute, TErrorRoute } from '@common/router';
|
|
11
11
|
import { TFetcherList, TDataReturnedByFetchers } from '@common/router/request/api';
|
|
12
12
|
|
|
13
13
|
/*----------------------------------
|
|
@@ -16,7 +16,7 @@ import { TFetcherList, TDataReturnedByFetchers } from '@common/router/request/ap
|
|
|
16
16
|
|
|
17
17
|
// The function that fetch data from the api before to pass them as context to the renderer
|
|
18
18
|
export type TDataProvider<TProvidedData extends TFetcherList = TFetcherList> = (
|
|
19
|
-
context:
|
|
19
|
+
context: TClientOrServerContextForPage & {
|
|
20
20
|
// URL query parameters
|
|
21
21
|
// TODO: typings
|
|
22
22
|
data: {[key: string]: string | number}
|
|
@@ -30,12 +30,12 @@ export type TFrontRenderer<
|
|
|
30
30
|
TRouter = ClientOrServerRouter,
|
|
31
31
|
> = (
|
|
32
32
|
context: (
|
|
33
|
-
|
|
33
|
+
TClientOrServerContextForPage
|
|
34
34
|
&
|
|
35
35
|
TAdditionnalData
|
|
36
36
|
&
|
|
37
37
|
{
|
|
38
|
-
context:
|
|
38
|
+
context: TClientOrServerContextForPage,
|
|
39
39
|
data: {[key: string]: PrimitiveValue}
|
|
40
40
|
}
|
|
41
41
|
)
|
|
@@ -52,7 +52,11 @@ export type TPageResource = {
|
|
|
52
52
|
preload?: boolean
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
type
|
|
55
|
+
type TMetasDict = {
|
|
56
|
+
[key: string]: string | Date | undefined | null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type TMetasList = ({ $: string } & TMetasDict)[]
|
|
56
60
|
|
|
57
61
|
const debug = false;
|
|
58
62
|
|
|
@@ -71,7 +75,7 @@ export default abstract class PageResponse<TRouter extends ClientOrServerRouter
|
|
|
71
75
|
|
|
72
76
|
// Resources
|
|
73
77
|
public head: TMetasList = [];
|
|
74
|
-
public metas:
|
|
78
|
+
public metas: TMetasDict = {};
|
|
75
79
|
public jsonld: Thing[] = [];
|
|
76
80
|
public scripts: TPageResource[] = [];
|
|
77
81
|
public style: TPageResource[] = [];
|
|
@@ -83,7 +87,7 @@ export default abstract class PageResponse<TRouter extends ClientOrServerRouter
|
|
|
83
87
|
public constructor(
|
|
84
88
|
public route: TRoute | TErrorRoute,
|
|
85
89
|
public renderer: TFrontRenderer,
|
|
86
|
-
public context:
|
|
90
|
+
public context: TClientOrServerContextForPage
|
|
87
91
|
) {
|
|
88
92
|
|
|
89
93
|
this.chunkId = context.route.options["id"];
|
|
@@ -52,8 +52,7 @@ export type TRouterContext<TRouter extends ServerRouter = ServerRouter> = (
|
|
|
52
52
|
|
|
53
53
|
Router: TRouter,
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
TRouterContextServices<TRouter>
|
|
55
|
+
//& TRouterContextServices<TRouter>
|
|
57
56
|
)
|
|
58
57
|
|
|
59
58
|
export type TRouterContextServices<TRouter extends ServerRouter> = (
|
|
@@ -8,7 +8,7 @@ import renderToString from "preact-render-to-string";
|
|
|
8
8
|
|
|
9
9
|
// Core
|
|
10
10
|
import { default as Router, TRouterContext } from "@server/services/router";
|
|
11
|
-
import type { Layout, TRoute, TErrorRoute } from '@common/router';
|
|
11
|
+
import type { Layout, TRoute, TErrorRoute, TClientOrServerContext } from '@common/router';
|
|
12
12
|
import PageResponse, { TFrontRenderer } from "@common/router/response/page";
|
|
13
13
|
|
|
14
14
|
// Composants UI
|
|
@@ -30,7 +30,7 @@ const seoLimits = {
|
|
|
30
30
|
- FONCTION
|
|
31
31
|
----------------------------------*/
|
|
32
32
|
|
|
33
|
-
export default class
|
|
33
|
+
export default class ServerPage<TRouter extends Router = Router> extends PageResponse<TRouter> {
|
|
34
34
|
|
|
35
35
|
public constructor(
|
|
36
36
|
public route: TRoute | TErrorRoute,
|