@qlover/create-app 0.10.2 → 0.10.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/CHANGELOG.md +37 -0
- package/dist/configs/_common/.github/workflows/general-check.yml +1 -1
- package/dist/configs/_common/.github/workflows/release.yml +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/dist/templates/next-app/eslint.config.mjs +5 -1
- package/dist/templates/next-app/package.json +4 -2
- package/dist/templates/next-app/src/base/cases/AdminPageManager.ts +3 -3
- package/dist/templates/next-app/src/base/cases/AppConfig.ts +14 -13
- package/dist/templates/next-app/src/base/cases/Datetime.ts +3 -3
- package/dist/templates/next-app/src/base/cases/DialogErrorPlugin.ts +8 -2
- package/dist/templates/next-app/src/base/cases/DialogHandler.ts +30 -4
- package/dist/templates/next-app/src/base/cases/InversifyContainer.ts +16 -4
- package/dist/templates/next-app/src/base/cases/NavigateBridge.ts +8 -2
- package/dist/templates/next-app/src/base/cases/RequestEncryptPlugin.ts +8 -2
- package/dist/templates/next-app/src/base/cases/ResourceState.ts +3 -3
- package/dist/templates/next-app/src/base/cases/RouterService.ts +24 -6
- package/dist/templates/next-app/src/base/cases/StringEncryptor.ts +14 -2
- package/dist/templates/next-app/src/base/cases/TranslateI18nInterface.ts +1 -1
- package/dist/templates/next-app/src/base/cases/UserServiceApi.ts +20 -5
- package/dist/templates/next-app/src/base/cases/ZodColumnBuilder.ts +31 -8
- package/dist/templates/next-app/src/base/port/AdminLayoutInterface.ts +4 -1
- package/dist/templates/next-app/src/base/port/I18nServiceInterface.ts +27 -7
- package/dist/templates/next-app/src/base/services/AdminPageEvent.ts +1 -1
- package/dist/templates/next-app/src/base/services/AdminPageScheduler.ts +3 -3
- package/dist/templates/next-app/src/base/services/I18nService.ts +20 -10
- package/dist/templates/next-app/src/base/services/ResourceService.ts +32 -11
- package/dist/templates/next-app/src/base/services/UserService.ts +12 -3
- package/dist/templates/next-app/src/base/services/adminApi/AdminLocalesApi.ts +9 -6
- package/dist/templates/next-app/src/base/services/adminApi/AdminUserApi.ts +20 -5
- package/dist/templates/next-app/src/base/services/appApi/AppApiPlugin.ts +21 -4
- package/dist/templates/next-app/src/base/services/appApi/AppUserApi.ts +12 -3
- package/dist/templates/next-app/src/base/services/appApi/AppUserApiBootstrap.ts +10 -2
- package/dist/templates/next-app/src/core/bootstraps/BootstrapClient.ts +2 -2
- package/dist/templates/next-app/src/core/bootstraps/BootstrapServer.ts +25 -7
- package/dist/templates/next-app/src/core/bootstraps/BootstrapsRegistry.ts +6 -3
- package/dist/templates/next-app/src/core/clientIoc/ClientIOC.ts +11 -2
- package/dist/templates/next-app/src/core/clientIoc/ClientIOCRegister.ts +5 -0
- package/dist/templates/next-app/src/core/serverIoc/ServerIOC.ts +13 -4
- package/dist/templates/next-app/src/core/serverIoc/ServerIOCRegister.ts +8 -1
- package/dist/templates/next-app/src/pages/_app.tsx +1 -1
- package/dist/templates/next-app/src/server/AppErrorApi.ts +1 -1
- package/dist/templates/next-app/src/server/AppPageRouteParams.ts +13 -0
- package/dist/templates/next-app/src/server/AppSuccessApi.ts +1 -1
- package/dist/templates/next-app/src/server/NextApiServer.ts +11 -2
- package/dist/templates/next-app/src/server/PagesRouteParams.ts +11 -1
- package/dist/templates/next-app/src/server/PasswordEncrypt.ts +8 -2
- package/dist/templates/next-app/src/server/ServerAuth.ts +20 -5
- package/dist/templates/next-app/src/server/SupabaseBridge.ts +48 -8
- package/dist/templates/next-app/src/server/UserCredentialToken.ts +8 -2
- package/dist/templates/next-app/src/server/controllers/AdminLocalesController.ts +16 -4
- package/dist/templates/next-app/src/server/controllers/AdminUserController.ts +4 -1
- package/dist/templates/next-app/src/server/controllers/LocalesController.ts +4 -1
- package/dist/templates/next-app/src/server/controllers/UserController.ts +12 -3
- package/dist/templates/next-app/src/server/repositorys/LocalesRepository.ts +23 -7
- package/dist/templates/next-app/src/server/repositorys/UserRepository.ts +15 -6
- package/dist/templates/next-app/src/server/services/AIService.ts +3 -1
- package/dist/templates/next-app/src/server/services/AdminAuthPlugin.ts +5 -2
- package/dist/templates/next-app/src/server/services/ApiLocaleService.ts +5 -5
- package/dist/templates/next-app/src/server/services/ApiUserService.ts +1 -1
- package/dist/templates/next-app/src/server/services/UserService.ts +12 -3
- package/dist/templates/next-app/src/server/validators/LocalesValidator.ts +20 -5
- package/dist/templates/next-app/src/server/validators/LoginValidator.ts +16 -4
- package/dist/templates/next-app/src/server/validators/PaginationValidator.ts +8 -2
- package/dist/templates/next-app/src/uikit/components/IOCProvider.tsx +1 -1
- package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportEvent.ts +7 -1
- package/dist/templates/react-app/__tests__/__mocks__/BootstrapTest.ts +3 -1
- package/dist/templates/react-app/__tests__/__mocks__/MockAppConfig.ts +19 -19
- package/dist/templates/react-app/__tests__/__mocks__/MockDialogHandler.ts +8 -8
- package/dist/templates/react-app/__tests__/__mocks__/MockLogger.ts +9 -9
- package/dist/templates/react-app/__tests__/__mocks__/components/TestBootstrapsProvider.tsx +1 -1
- package/dist/templates/react-app/__tests__/__mocks__/i18nextHttpBackend.ts +5 -5
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOC.ts +9 -5
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOCRegister.ts +8 -4
- package/dist/templates/react-app/__tests__/src/base/cases/I18nKeyErrorPlugin.test.ts +4 -4
- package/dist/templates/react-app/__tests__/src/base/cases/InversifyContainer.test.ts +5 -5
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapClient.test.ts +3 -3
- package/dist/templates/react-app/__tests__/src/uikit/components/chatMessage/ChatRoot.test.tsx +1 -1
- package/dist/templates/react-app/docs/en/components/chat-message-component.md +35 -29
- package/dist/templates/react-app/docs/en/components/chat-message-refactor.md +18 -5
- package/dist/templates/react-app/docs/en/components/message-base-list-component.md +11 -12
- package/dist/templates/react-app/docs/en/request.md +1 -3
- package/dist/templates/react-app/docs/zh/components/chat-message-component.md +35 -29
- package/dist/templates/react-app/docs/zh/components/chat-message-refactor.md +18 -5
- package/dist/templates/react-app/docs/zh/components/message-base-list-component.md +11 -12
- package/dist/templates/react-app/docs/zh/request.md +1 -3
- package/dist/templates/react-app/eslint.config.mjs +10 -5
- package/dist/templates/react-app/src/App.tsx +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApi.ts +2 -2
- package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +14 -11
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +10 -16
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +12 -10
- package/dist/templates/react-app/src/base/cases/AppConfig.ts +19 -19
- package/dist/templates/react-app/src/base/cases/DialogHandler.ts +28 -5
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +5 -2
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +16 -4
- package/dist/templates/react-app/src/base/cases/PublicAssetsPath.ts +1 -1
- package/dist/templates/react-app/src/base/cases/RequestLanguages.ts +6 -3
- package/dist/templates/react-app/src/base/cases/RequestLogger.ts +17 -8
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +4 -6
- package/dist/templates/react-app/src/base/cases/ResourceState.ts +3 -3
- package/dist/templates/react-app/src/base/cases/RouterLoader.ts +3 -3
- package/dist/templates/react-app/src/base/cases/TranslateI18nInterface.ts +1 -1
- package/dist/templates/react-app/src/base/port/ExecutorPageBridgeInterface.ts +2 -2
- package/dist/templates/react-app/src/base/port/IOCInterface.ts +4 -2
- package/dist/templates/react-app/src/base/port/JSONStoragePageBridgeInterface.ts +5 -5
- package/dist/templates/react-app/src/base/port/RequestPageBridgeInterface.ts +7 -7
- package/dist/templates/react-app/src/base/port/RouteServiceInterface.ts +8 -8
- package/dist/templates/react-app/src/base/port/UserServiceInterface.ts +4 -2
- package/dist/templates/react-app/src/base/services/BaseLayoutService.ts +3 -3
- package/dist/templates/react-app/src/base/services/I18nService.ts +24 -13
- package/dist/templates/react-app/src/base/services/IdentifierService.ts +21 -26
- package/dist/templates/react-app/src/base/services/RouteService.ts +8 -8
- package/dist/templates/react-app/src/base/services/UserBootstrap.ts +2 -2
- package/dist/templates/react-app/src/base/services/UserGatewayPlugin.ts +9 -5
- package/dist/templates/react-app/src/base/services/UserService.ts +10 -4
- package/dist/templates/react-app/src/core/bootstraps/BootstrapClient.ts +3 -1
- package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +5 -2
- package/dist/templates/react-app/src/core/clientIoc/ClientIOC.ts +11 -4
- package/dist/templates/react-app/src/core/clientIoc/ClientIOCRegister.ts +5 -4
- package/dist/templates/react-app/src/pages/base/Layout.tsx +1 -1
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/_default.css +0 -44
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/dark.css +0 -44
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/pink.css +0 -44
- package/dist/templates/react-app/src/styles/css/index.css +1 -1
- package/dist/templates/react-app/src/styles/css/scrollbar.css +34 -0
- package/dist/templates/react-app/src/uikit/bridges/ExecutorPageBridge.ts +2 -2
- package/dist/templates/react-app/src/uikit/bridges/JSONStoragePageBridge.ts +4 -4
- package/dist/templates/react-app/src/uikit/bridges/NavigateBridge.ts +8 -2
- package/dist/templates/react-app/src/uikit/bridges/RequestPageBridge.ts +6 -6
- package/dist/templates/react-app/src/uikit/components/AppRouterProvider.tsx +1 -1
- package/dist/templates/react-app/src/uikit/components/BootstrapsProvider.tsx +1 -3
- package/dist/templates/react-app/src/uikit/components/MessageBaseList.tsx +4 -1
- package/dist/templates/react-app/src/uikit/components/chatMessage/ChatMessageBridge.ts +39 -16
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessageApi.ts +4 -2
- package/package.json +3 -3
- package/dist/templates/react-app/makes/eslint-utils.mjs +0 -195
|
@@ -6,14 +6,14 @@ import type {
|
|
|
6
6
|
} from '@qlover/fe-corekit';
|
|
7
7
|
|
|
8
8
|
export class RequestLanguages implements ExecutorPlugin {
|
|
9
|
-
readonly pluginName = 'RequestLanguages';
|
|
9
|
+
public readonly pluginName = 'RequestLanguages';
|
|
10
10
|
|
|
11
11
|
constructor(
|
|
12
12
|
protected i18nService: I18nServiceInterface,
|
|
13
13
|
protected headerName = 'accept-language'
|
|
14
14
|
) {}
|
|
15
15
|
|
|
16
|
-
buildAcceptLanguage(langs: string[]): string {
|
|
16
|
+
public buildAcceptLanguage(langs: string[]): string {
|
|
17
17
|
return langs
|
|
18
18
|
.map((lang, index) => {
|
|
19
19
|
const q = Math.max(1 - index * 0.1, 0.1).toFixed(1);
|
|
@@ -22,7 +22,10 @@ export class RequestLanguages implements ExecutorPlugin {
|
|
|
22
22
|
.join(',');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @override
|
|
27
|
+
*/
|
|
28
|
+
public onBefore(context: ExecutorContext<RequestAdapterConfig>): void {
|
|
26
29
|
const currentLanguage = this.i18nService.getCurrentLanguage();
|
|
27
30
|
const languages = this.i18nService.getSupportedLanguages();
|
|
28
31
|
|
|
@@ -13,14 +13,17 @@ import { injectable, inject } from 'inversify';
|
|
|
13
13
|
import type { LoggerInterface } from '@qlover/logger';
|
|
14
14
|
|
|
15
15
|
@injectable()
|
|
16
|
-
export class RequestLogger
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
readonly pluginName = 'RequestLogger';
|
|
16
|
+
export class RequestLogger implements ExecutorPlugin<RequestAdapterFetchConfig> {
|
|
17
|
+
public readonly pluginName = 'RequestLogger';
|
|
20
18
|
|
|
21
19
|
constructor(@inject(IOCIdentifier.Logger) public logger: LoggerInterface) {}
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @override
|
|
23
|
+
*/
|
|
24
|
+
public onBefore(
|
|
25
|
+
context: ExecutorContext<RequestAdapterFetchConfig<unknown>>
|
|
26
|
+
): void {
|
|
24
27
|
this.logger.log(
|
|
25
28
|
`%c[Request before]%c [${new Date().toLocaleString()}] ${context.parameters.method} ${context.parameters.url}`,
|
|
26
29
|
'color: #0ff;',
|
|
@@ -29,7 +32,10 @@ export class RequestLogger
|
|
|
29
32
|
);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @override
|
|
37
|
+
*/
|
|
38
|
+
public async onSuccess({
|
|
33
39
|
parameters,
|
|
34
40
|
returnValue
|
|
35
41
|
}: ExecutorContext<
|
|
@@ -53,14 +59,17 @@ export class RequestLogger
|
|
|
53
59
|
);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
/**
|
|
63
|
+
* @override
|
|
64
|
+
*/
|
|
65
|
+
public onError({
|
|
57
66
|
parameters,
|
|
58
67
|
error
|
|
59
68
|
}: ExecutorContext<RequestAdapterFetchConfig>): void {
|
|
60
69
|
this.loggerError(parameters, error);
|
|
61
70
|
}
|
|
62
71
|
|
|
63
|
-
loggerError(config: RequestAdapterFetchConfig, error: unknown): void {
|
|
72
|
+
public loggerError(config: RequestAdapterFetchConfig, error: unknown): void {
|
|
64
73
|
this.logger.log(
|
|
65
74
|
`%c[Request error]%c [${new Date().toLocaleString()}] ${config.method} ${config.url}`,
|
|
66
75
|
'color: #f00;',
|
|
@@ -5,9 +5,7 @@ import type { RequestAdapterResponse } from '@qlover/fe-corekit';
|
|
|
5
5
|
import type { LoggerInterface } from '@qlover/logger';
|
|
6
6
|
|
|
7
7
|
@injectable()
|
|
8
|
-
export class RequestStatusCatcher
|
|
9
|
-
implements RequestCatcherInterface<RequestAdapterResponse>
|
|
10
|
-
{
|
|
8
|
+
export class RequestStatusCatcher implements RequestCatcherInterface<RequestAdapterResponse> {
|
|
11
9
|
constructor(
|
|
12
10
|
@inject(IOCIdentifier.Logger) protected logger: LoggerInterface
|
|
13
11
|
) {}
|
|
@@ -16,7 +14,7 @@ export class RequestStatusCatcher
|
|
|
16
14
|
* default handler
|
|
17
15
|
* @override
|
|
18
16
|
*/
|
|
19
|
-
default(context: RequestAdapterResponse<unknown, unknown>): void {
|
|
17
|
+
public default(context: RequestAdapterResponse<unknown, unknown>): void {
|
|
20
18
|
this.logger.warn(`RequestStatusCatcher default handler`, context);
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -24,7 +22,7 @@ export class RequestStatusCatcher
|
|
|
24
22
|
* handler
|
|
25
23
|
* @override
|
|
26
24
|
*/
|
|
27
|
-
handler(context: RequestAdapterResponse<unknown, unknown>): void {
|
|
25
|
+
public handler(context: RequestAdapterResponse<unknown, unknown>): void {
|
|
28
26
|
const { status } = context;
|
|
29
27
|
|
|
30
28
|
const _handler = this[`case${status}` as keyof RequestStatusCatcher];
|
|
@@ -36,7 +34,7 @@ export class RequestStatusCatcher
|
|
|
36
34
|
return this.default(context);
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
case200(_context: RequestAdapterResponse<unknown, unknown>): void {
|
|
37
|
+
public case200(_context: RequestAdapterResponse<unknown, unknown>): void {
|
|
40
38
|
// this.logger.info(`RequestStatusCatcher case200 handler`, context);
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -12,12 +12,12 @@ export interface PaginationInterface<T> {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class ResourceState implements ResourceStateInterface {
|
|
15
|
-
searchParams: ResourceQuery = {
|
|
15
|
+
public searchParams: ResourceQuery = {
|
|
16
16
|
page: 1,
|
|
17
17
|
pageSize: 10,
|
|
18
18
|
orderBy: 'updated_at',
|
|
19
19
|
order: 1
|
|
20
20
|
};
|
|
21
|
-
initState = new RequestState<unknown>();
|
|
22
|
-
listState = new RequestState<PaginationInterface<unknown>>();
|
|
21
|
+
public initState = new RequestState<unknown>();
|
|
22
|
+
public listState = new RequestState<PaginationInterface<unknown>>();
|
|
23
23
|
}
|
|
@@ -123,7 +123,7 @@ export class RouterLoader {
|
|
|
123
123
|
* Get the component mapping object
|
|
124
124
|
* @returns Component mapping dictionary
|
|
125
125
|
*/
|
|
126
|
-
getComponentMaps(): ComponentValue {
|
|
126
|
+
public getComponentMaps(): ComponentValue {
|
|
127
127
|
const { componentMaps = {} } = this.options;
|
|
128
128
|
return componentMaps;
|
|
129
129
|
}
|
|
@@ -134,7 +134,7 @@ export class RouterLoader {
|
|
|
134
134
|
* @returns Component loader function
|
|
135
135
|
* @throws Error if component is not found in componentMaps
|
|
136
136
|
*/
|
|
137
|
-
getComponent(element: string): () => RouteComponentType {
|
|
137
|
+
public getComponent(element: string): () => RouteComponentType {
|
|
138
138
|
const maps = this.getComponentMaps();
|
|
139
139
|
const component = maps[element];
|
|
140
140
|
|
|
@@ -150,7 +150,7 @@ export class RouterLoader {
|
|
|
150
150
|
* @param route Route configuration object
|
|
151
151
|
* @returns React Router route object
|
|
152
152
|
*/
|
|
153
|
-
toRoute(route: RouteConfigValue): RouteObject {
|
|
153
|
+
public toRoute(route: RouteConfigValue): RouteObject {
|
|
154
154
|
const { render } = this.options;
|
|
155
155
|
const { element, children, ...rest } = route;
|
|
156
156
|
|
|
@@ -9,7 +9,7 @@ import type { TFunction } from 'i18next';
|
|
|
9
9
|
* @returns The translated i18n interface
|
|
10
10
|
*/
|
|
11
11
|
export class TranslateI18nInterface {
|
|
12
|
-
static translate<T extends PageI18nInterface | Record<string, string>>(
|
|
12
|
+
public static translate<T extends PageI18nInterface | Record<string, string>>(
|
|
13
13
|
source: T,
|
|
14
14
|
t: TFunction<string, string>
|
|
15
15
|
): T {
|
|
@@ -15,9 +15,9 @@ export interface ExecutorPageStateInterface extends StoreStateInterface {
|
|
|
15
15
|
* const executorPageBridge = new ExecutorPageBridge();
|
|
16
16
|
*/
|
|
17
17
|
export abstract class ExecutorPageBridgeInterface extends StoreInterface<ExecutorPageStateInterface> {
|
|
18
|
-
selector = {
|
|
18
|
+
public selector = {
|
|
19
19
|
helloState: (state: ExecutorPageStateInterface) => state.helloState
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
abstract onTestPlugins: () => Promise<void>;
|
|
22
|
+
public abstract onTestPlugins: () => Promise<void>;
|
|
23
23
|
}
|
|
@@ -32,5 +32,7 @@ export interface IOCInterface<
|
|
|
32
32
|
/**
|
|
33
33
|
* 提供一个快捷的注册器类型名
|
|
34
34
|
*/
|
|
35
|
-
export interface IOCRegister
|
|
36
|
-
|
|
35
|
+
export interface IOCRegister extends IOCRegisterInterface<
|
|
36
|
+
IOCContainerInterface,
|
|
37
|
+
IocRegisterOptions
|
|
38
|
+
> {}
|
|
@@ -9,13 +9,13 @@ export interface JSONStoragePageStateInterface extends StoreStateInterface {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export abstract class JSONStoragePageBridgeInterface extends StoreInterface<JSONStoragePageStateInterface> {
|
|
12
|
-
selector = {
|
|
12
|
+
public selector = {
|
|
13
13
|
requestTimeout: (state: JSONStoragePageStateInterface) =>
|
|
14
14
|
state.requestTimeout
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
abstract changeRandomTestKey1: () => void;
|
|
18
|
-
abstract onChangeRandomTestKey2: () => void;
|
|
19
|
-
abstract changeExpireTime: (expireTime: number) => void;
|
|
20
|
-
abstract changeRequestTimeout: (requestTimeout: number) => void;
|
|
17
|
+
public abstract changeRandomTestKey1: () => void;
|
|
18
|
+
public abstract onChangeRandomTestKey2: () => void;
|
|
19
|
+
public abstract changeExpireTime: (expireTime: number) => void;
|
|
20
|
+
public abstract changeRequestTimeout: (requestTimeout: number) => void;
|
|
21
21
|
}
|
|
@@ -10,14 +10,14 @@ export interface RequestPageStateInterface extends StoreStateInterface {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export abstract class RequestPageBridgeInterface extends StoreInterface<RequestPageStateInterface> {
|
|
13
|
-
abstract onHello: () => void;
|
|
14
|
-
abstract onIpInfo: () => void;
|
|
15
|
-
abstract onRandomUser: () => void;
|
|
16
|
-
abstract onTriggerApiCatchResult: () => void;
|
|
17
|
-
abstract onTriggerAbortRequest: () => void;
|
|
18
|
-
abstract stopAbortRequest: () => void;
|
|
13
|
+
public abstract onHello: () => void;
|
|
14
|
+
public abstract onIpInfo: () => void;
|
|
15
|
+
public abstract onRandomUser: () => void;
|
|
16
|
+
public abstract onTriggerApiCatchResult: () => void;
|
|
17
|
+
public abstract onTriggerAbortRequest: () => void;
|
|
18
|
+
public abstract stopAbortRequest: () => void;
|
|
19
19
|
|
|
20
|
-
emitState(state: Partial<RequestPageStateInterface>): void {
|
|
20
|
+
public emitState(state: Partial<RequestPageStateInterface>): void {
|
|
21
21
|
this.emit(this.cloneState(state));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -10,18 +10,18 @@ export interface RouteServiceStateInterface extends StoreStateInterface {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export abstract class RouteServiceInterface extends StoreInterface<RouteServiceStateInterface> {
|
|
13
|
-
abstract get logger(): LoggerInterface;
|
|
13
|
+
public abstract get logger(): LoggerInterface;
|
|
14
14
|
|
|
15
|
-
abstract getRoutes(): RouteConfigValue[];
|
|
16
|
-
abstract changeRoutes(routes: RouteConfigValue[]): void;
|
|
17
|
-
abstract goto(
|
|
15
|
+
public abstract getRoutes(): RouteConfigValue[];
|
|
16
|
+
public abstract changeRoutes(routes: RouteConfigValue[]): void;
|
|
17
|
+
public abstract goto(
|
|
18
18
|
path: string,
|
|
19
19
|
options?: NavigateOptions & { navigate?: NavigateFunction }
|
|
20
20
|
): void;
|
|
21
|
-
abstract gotoLogin(): void;
|
|
22
|
-
abstract replaceToHome(): void;
|
|
23
|
-
abstract redirectToDefault(navigate: NavigateFunction): void;
|
|
24
|
-
abstract i18nGuard(
|
|
21
|
+
public abstract gotoLogin(): void;
|
|
22
|
+
public abstract replaceToHome(): void;
|
|
23
|
+
public abstract redirectToDefault(navigate: NavigateFunction): void;
|
|
24
|
+
public abstract i18nGuard(
|
|
25
25
|
currentPath: string,
|
|
26
26
|
lng: string,
|
|
27
27
|
navigate?: NavigateFunction
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { UserInfo, UserCredential } from '@/base/apis/userApi/UserApiType';
|
|
2
2
|
import type { UserServiceInterface as CorekitBridgeUserServiceInterface } from '@qlover/corekit-bridge';
|
|
3
3
|
|
|
4
|
-
export interface UserServiceInterface
|
|
5
|
-
|
|
4
|
+
export interface UserServiceInterface extends CorekitBridgeUserServiceInterface<
|
|
5
|
+
UserInfo,
|
|
6
|
+
UserCredential
|
|
7
|
+
> {
|
|
6
8
|
// You can add your own methods here
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -24,18 +24,18 @@ export class BaseLayoutService {
|
|
|
24
24
|
this.use(new UserBootstrap(userService));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
use(plugin: ExecutorPlugin): this {
|
|
27
|
+
public use(plugin: ExecutorPlugin): this {
|
|
28
28
|
this.executor.use(plugin);
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
handler(): Promise<{ success: boolean }> {
|
|
32
|
+
public handler(): Promise<{ success: boolean }> {
|
|
33
33
|
return Promise.resolve({
|
|
34
34
|
success: true
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async starup(ioc: IOCContainerInterface): Promise<unknown> {
|
|
38
|
+
public async starup(ioc: IOCContainerInterface): Promise<unknown> {
|
|
39
39
|
const context: BootstrapContextValue = {
|
|
40
40
|
root: {},
|
|
41
41
|
logger: this.logger,
|
|
@@ -16,7 +16,7 @@ import type { I18nServiceInterface } from '../port/I18nServiceInterface';
|
|
|
16
16
|
const { supportedLngs, fallbackLng } = i18nConfig;
|
|
17
17
|
|
|
18
18
|
export class I18nServiceState implements StoreStateInterface {
|
|
19
|
-
loading: boolean = false;
|
|
19
|
+
public loading: boolean = false;
|
|
20
20
|
constructor(public language: LocaleType) {}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -24,9 +24,9 @@ export class I18nService
|
|
|
24
24
|
extends StoreInterface<I18nServiceState>
|
|
25
25
|
implements I18nServiceInterface
|
|
26
26
|
{
|
|
27
|
-
readonly pluginName = 'I18nService';
|
|
27
|
+
public readonly pluginName = 'I18nService';
|
|
28
28
|
|
|
29
|
-
selector = {
|
|
29
|
+
public selector = {
|
|
30
30
|
loading: (state: I18nServiceState) => state.loading,
|
|
31
31
|
language: (state: I18nServiceState) => state.language
|
|
32
32
|
};
|
|
@@ -35,10 +35,7 @@ export class I18nService
|
|
|
35
35
|
super(() => new I18nServiceState(i18n.language as LocaleType));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
* @override
|
|
40
|
-
*/
|
|
41
|
-
onBefore(): void {
|
|
38
|
+
public onBefore(): void {
|
|
42
39
|
const debug = false;
|
|
43
40
|
|
|
44
41
|
i18n
|
|
@@ -83,40 +80,54 @@ export class I18nService
|
|
|
83
80
|
});
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
|
|
83
|
+
/**
|
|
84
|
+
* @override
|
|
85
|
+
*/
|
|
86
|
+
public async changeLanguage(language: LocaleType): Promise<void> {
|
|
87
87
|
await i18n.changeLanguage(language);
|
|
88
88
|
// Sync state with i18n.language
|
|
89
89
|
this.emit({ ...this.state, language });
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
/**
|
|
93
|
+
* @override
|
|
94
|
+
*/
|
|
95
|
+
public changeLoading(loading: boolean): void {
|
|
93
96
|
this.emit({ ...this.state, loading });
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
|
|
99
|
+
/**
|
|
100
|
+
* @override
|
|
101
|
+
*/
|
|
102
|
+
public getCurrentLanguage(): LocaleType {
|
|
97
103
|
return i18n.language as LocaleType;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
101
107
|
* check if the language is supported
|
|
108
|
+
* @override
|
|
102
109
|
* @param language - language to check
|
|
103
110
|
* @returns true if the language is supported, false otherwise
|
|
104
111
|
*/
|
|
105
|
-
isValidLanguage(language: string): language is LocaleType {
|
|
112
|
+
public isValidLanguage(language: string): language is LocaleType {
|
|
106
113
|
return supportedLngs.includes(language as LocaleType);
|
|
107
114
|
}
|
|
108
115
|
|
|
109
|
-
|
|
116
|
+
/**
|
|
117
|
+
* @override
|
|
118
|
+
*/
|
|
119
|
+
public getSupportedLanguages(): LocaleType[] {
|
|
110
120
|
return [...supportedLngs];
|
|
111
121
|
}
|
|
112
122
|
|
|
113
123
|
/**
|
|
114
124
|
* translate the key
|
|
125
|
+
* @override
|
|
115
126
|
* @param key - key to translate
|
|
116
127
|
* @param params - params to pass to the translation
|
|
117
128
|
* @returns translated value
|
|
118
129
|
*/
|
|
119
|
-
t(key: string, params?: Record<string, unknown>): string {
|
|
130
|
+
public t(key: string, params?: Record<string, unknown>): string {
|
|
120
131
|
const i18nValue = i18n.t(key, {
|
|
121
132
|
lng: i18n.language,
|
|
122
133
|
nsSeparator: false,
|
|
@@ -20,14 +20,15 @@ export interface IdentifierRecord {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
@injectable()
|
|
23
|
-
export class IdentifierService<T>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
23
|
+
export class IdentifierService<T> implements ResourceServiceInterface<
|
|
24
|
+
T,
|
|
25
|
+
ResourceStore<ResourceStateInterface>
|
|
26
|
+
> {
|
|
27
|
+
public readonly unionKey: string = 'id';
|
|
28
|
+
public readonly serviceName: string = 'IdentifierService';
|
|
29
|
+
public readonly store: ResourceStore<ResourceStateInterface>;
|
|
29
30
|
// Not implemented
|
|
30
|
-
readonly resourceApi!: ResourceInterface<T>;
|
|
31
|
+
public readonly resourceApi!: ResourceInterface<T>;
|
|
31
32
|
private unsubscribe: (() => void) | null = null;
|
|
32
33
|
|
|
33
34
|
constructor(
|
|
@@ -37,7 +38,10 @@ export class IdentifierService<T>
|
|
|
37
38
|
this.store = new ResourceStore(() => new ResourceState());
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @override
|
|
43
|
+
*/
|
|
44
|
+
public getStore(): ResourceStore<ResourceStateInterface> {
|
|
41
45
|
return this.store;
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -58,10 +62,7 @@ export class IdentifierService<T>
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
* @override
|
|
63
|
-
*/
|
|
64
|
-
async created(): Promise<unknown> {
|
|
65
|
+
public async created(): Promise<unknown> {
|
|
65
66
|
this.unsubscribe = this.i18nService.observe(
|
|
66
67
|
(state) => state.language,
|
|
67
68
|
() => {
|
|
@@ -72,22 +73,16 @@ export class IdentifierService<T>
|
|
|
72
73
|
return this.init();
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
* @override
|
|
77
|
-
*/
|
|
78
|
-
destroyed(): void {
|
|
76
|
+
public destroyed(): void {
|
|
79
77
|
this.unsubscribe?.();
|
|
80
78
|
this.unsubscribe = null;
|
|
81
79
|
|
|
82
80
|
this.store.reset();
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
* @override
|
|
87
|
-
*/
|
|
88
|
-
updated(): void {}
|
|
83
|
+
public updated(): void {}
|
|
89
84
|
|
|
90
|
-
async search(
|
|
85
|
+
public async search(
|
|
91
86
|
params: Partial<ResourceQuery & { locale: LocaleType }>
|
|
92
87
|
): Promise<PaginationInterface<IdentifierRecord>> {
|
|
93
88
|
this.store.changeListState(
|
|
@@ -123,21 +118,21 @@ export class IdentifierService<T>
|
|
|
123
118
|
return result;
|
|
124
119
|
}
|
|
125
120
|
|
|
126
|
-
refresh(): Promise<unknown> {
|
|
121
|
+
public refresh(): Promise<unknown> {
|
|
127
122
|
return this.search(this.store.state.searchParams);
|
|
128
123
|
}
|
|
129
124
|
|
|
130
|
-
async update(_data: Partial<T>): Promise<unknown> {
|
|
125
|
+
public async update(_data: Partial<T>): Promise<unknown> {
|
|
131
126
|
return Promise.resolve(null);
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
create(_data: T): Promise<unknown> {
|
|
129
|
+
public create(_data: T): Promise<unknown> {
|
|
135
130
|
return Promise.resolve(null);
|
|
136
131
|
}
|
|
137
|
-
remove(_data: T): Promise<unknown> {
|
|
132
|
+
public remove(_data: T): Promise<unknown> {
|
|
138
133
|
return Promise.resolve(null);
|
|
139
134
|
}
|
|
140
|
-
export(_data: T): Promise<unknown> {
|
|
135
|
+
public export(_data: T): Promise<unknown> {
|
|
141
136
|
return Promise.resolve(null);
|
|
142
137
|
}
|
|
143
138
|
}
|
|
@@ -39,7 +39,7 @@ export class RouteService extends RouteServiceInterface {
|
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
override get logger(): LoggerInterface {
|
|
42
|
+
public override get logger(): LoggerInterface {
|
|
43
43
|
return this.options.logger;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -51,15 +51,15 @@ export class RouteService extends RouteServiceInterface {
|
|
|
51
51
|
return path.startsWith('/') ? path : `/${path}`;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
override getRoutes(): RouteConfigValue[] {
|
|
54
|
+
public override getRoutes(): RouteConfigValue[] {
|
|
55
55
|
return this.state.routes;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
override changeRoutes(routes: RouteConfigValue[]): void {
|
|
58
|
+
public override changeRoutes(routes: RouteConfigValue[]): void {
|
|
59
59
|
this.emit(this.cloneState({ routes }));
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
override goto(
|
|
62
|
+
public override goto(
|
|
63
63
|
path: string,
|
|
64
64
|
options?: NavigateOptions & {
|
|
65
65
|
navigate?: NavigateFunction;
|
|
@@ -72,19 +72,19 @@ export class RouteService extends RouteServiceInterface {
|
|
|
72
72
|
(navigate || this.uiBridge.getUIBridge())?.(path, rest);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
override gotoLogin(): void {
|
|
75
|
+
public override gotoLogin(): void {
|
|
76
76
|
this.goto('/login', { replace: true });
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
override replaceToHome(): void {
|
|
79
|
+
public override replaceToHome(): void {
|
|
80
80
|
this.goto('/', { replace: true });
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
override redirectToDefault(navigate?: NavigateFunction): void {
|
|
83
|
+
public override redirectToDefault(navigate?: NavigateFunction): void {
|
|
84
84
|
this.goto('/', { replace: true, navigate });
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
override i18nGuard(
|
|
87
|
+
public override i18nGuard(
|
|
88
88
|
currentPath: string,
|
|
89
89
|
lng: string,
|
|
90
90
|
navigate?: NavigateFunction
|
|
@@ -7,14 +7,14 @@ import type { BootstrapExecutorPlugin } from '@qlover/corekit-bridge';
|
|
|
7
7
|
|
|
8
8
|
@injectable()
|
|
9
9
|
export class UserBootstrap implements BootstrapExecutorPlugin {
|
|
10
|
-
readonly pluginName = 'UserBootstrap';
|
|
10
|
+
public readonly pluginName = 'UserBootstrap';
|
|
11
11
|
|
|
12
12
|
constructor(
|
|
13
13
|
@inject(I.UserServiceInterface)
|
|
14
14
|
protected userService: UserServiceInterface
|
|
15
15
|
) {}
|
|
16
16
|
|
|
17
|
-
async onBefore(): Promise<void> {
|
|
17
|
+
public async onBefore(): Promise<void> {
|
|
18
18
|
const userService = this.userService;
|
|
19
19
|
|
|
20
20
|
if (userService.isAuthenticated()) {
|
|
@@ -2,14 +2,18 @@ import type { UserInfo, UserCredential } from '@/base/apis/userApi/UserApiType';
|
|
|
2
2
|
import type { RouteServiceInterface } from '../port/RouteServiceInterface';
|
|
3
3
|
import type { UserServicePluginInterface } from '@qlover/corekit-bridge';
|
|
4
4
|
|
|
5
|
-
export class UserGatewayPlugin
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export class UserGatewayPlugin implements UserServicePluginInterface<
|
|
6
|
+
UserInfo,
|
|
7
|
+
UserCredential
|
|
8
|
+
> {
|
|
9
|
+
public readonly pluginName = 'UserGatewayPlugin';
|
|
9
10
|
|
|
10
11
|
constructor(protected routerService: RouteServiceInterface) {}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @override
|
|
15
|
+
*/
|
|
16
|
+
public onLogoutSuccess(): void {
|
|
13
17
|
this.routerService.reset();
|
|
14
18
|
this.routerService.gotoLogin();
|
|
15
19
|
}
|
|
@@ -45,11 +45,14 @@ export class UserService
|
|
|
45
45
|
* @override
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
|
-
getToken(): string {
|
|
48
|
+
public getToken(): string {
|
|
49
49
|
return this.getCredential()?.token ?? '';
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* @override
|
|
54
|
+
*/
|
|
55
|
+
public isUserInfo(value: unknown): value is UserInfo {
|
|
53
56
|
return (
|
|
54
57
|
isObject(value) &&
|
|
55
58
|
'name' in value &&
|
|
@@ -61,11 +64,14 @@ export class UserService
|
|
|
61
64
|
);
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
/**
|
|
68
|
+
* @override
|
|
69
|
+
*/
|
|
70
|
+
public isUserCredential(value: unknown): value is UserCredential {
|
|
65
71
|
return isObject(value) && 'token' in value && isString(value.token);
|
|
66
72
|
}
|
|
67
73
|
|
|
68
|
-
override isAuthenticated(): boolean {
|
|
74
|
+
public override isAuthenticated(): boolean {
|
|
69
75
|
if (!super.isAuthenticated()) {
|
|
70
76
|
return false;
|
|
71
77
|
}
|
|
@@ -47,7 +47,9 @@ export type BootstrapClientArgs = {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
export class BootstrapClient {
|
|
50
|
-
static async main(
|
|
50
|
+
public static async main(
|
|
51
|
+
args: BootstrapClientArgs
|
|
52
|
+
): Promise<BootstrapClientArgs> {
|
|
51
53
|
const {
|
|
52
54
|
root,
|
|
53
55
|
bootHref,
|
|
@@ -24,11 +24,14 @@ export class BootstrapsRegistry implements BootstrapsRegistryInterface {
|
|
|
24
24
|
protected IOC: IOCFunctionInterface<IOCIdentifierMap, IOCContainerInterface>
|
|
25
25
|
) {}
|
|
26
26
|
|
|
27
|
-
get appConfig(): EnvConfigInterface {
|
|
27
|
+
public get appConfig(): EnvConfigInterface {
|
|
28
28
|
return this.IOC(I.AppConfig);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @override
|
|
33
|
+
*/
|
|
34
|
+
public register(): BootstrapExecutorPlugin[] {
|
|
32
35
|
const IOC = this.IOC;
|
|
33
36
|
|
|
34
37
|
const bootstrapList = [
|