proteum 1.0.2 → 2.0.0-1
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/AGENTS.md +101 -0
- package/agents/codex/AGENTS.md +95 -0
- package/agents/codex/CODING_STYLE.md +71 -0
- package/agents/codex/agents.md.zip +0 -0
- package/agents/codex/client/AGENTS.md +102 -0
- package/agents/codex/client/pages/AGENTS.md +35 -0
- package/agents/codex/server/routes/AGENTS.md +12 -0
- package/agents/codex/server/services/AGENTS.md +137 -0
- package/agents/codex/tests/AGENTS.md +8 -0
- package/cli/app/config.ts +13 -11
- package/cli/app/index.ts +74 -82
- package/cli/bin.js +1 -1
- package/cli/commands/build.ts +51 -14
- package/cli/commands/check.ts +19 -0
- package/cli/commands/deploy/app.ts +4 -8
- package/cli/commands/deploy/web.ts +16 -20
- package/cli/commands/dev.ts +189 -64
- package/cli/commands/devEvents.ts +106 -0
- package/cli/commands/init.ts +63 -57
- package/cli/commands/lint.ts +21 -0
- package/cli/commands/refresh.ts +18 -0
- package/cli/commands/typecheck.ts +18 -0
- package/cli/compiler/client/identite.ts +80 -53
- package/cli/compiler/client/index.ts +139 -213
- package/cli/compiler/common/bundleAnalysis.ts +94 -0
- package/cli/compiler/common/clientManifest.ts +67 -0
- package/cli/compiler/common/controllers.ts +288 -0
- package/cli/compiler/common/files/autres.ts +7 -18
- package/cli/compiler/common/files/images.ts +40 -37
- package/cli/compiler/common/files/style.ts +11 -22
- package/cli/compiler/common/generatedRouteModules.ts +368 -0
- package/cli/compiler/common/index.ts +31 -65
- package/cli/compiler/common/loaders/forbid-ssr-import.js +13 -0
- package/cli/compiler/common/rspackAliases.ts +13 -0
- package/cli/compiler/common/scripts.ts +37 -0
- package/cli/compiler/index.ts +781 -230
- package/cli/compiler/server/index.ts +59 -75
- package/cli/compiler/writeIfChanged.ts +21 -0
- package/cli/index.ts +71 -72
- package/cli/paths.ts +51 -57
- package/cli/print.ts +17 -11
- package/cli/tsconfig.json +5 -4
- package/cli/utils/agents.ts +100 -0
- package/cli/utils/check.ts +71 -0
- package/cli/utils/index.ts +1 -3
- package/cli/utils/keyboard.ts +8 -25
- package/cli/utils/runProcess.ts +30 -0
- package/client/app/component.tsx +29 -29
- package/client/app/index.ts +36 -57
- package/client/app/service.ts +7 -12
- package/client/app.tsconfig.json +2 -2
- package/client/components/Dialog/Manager.ssr.tsx +40 -0
- package/client/components/Dialog/Manager.tsx +119 -150
- package/client/components/Dialog/status.tsx +3 -3
- package/client/components/index.ts +1 -1
- package/client/components/types.d.ts +1 -3
- package/client/dev/hmr.ts +65 -0
- package/client/global.d.ts +2 -2
- package/client/hooks.ts +6 -9
- package/client/index.ts +2 -1
- package/client/islands/index.ts +7 -0
- package/client/islands/useDeferredModule.ts +199 -0
- package/client/pages/_layout/index.tsx +4 -12
- package/client/pages/useHeader.tsx +14 -21
- package/client/router.ts +27 -0
- package/client/services/router/components/Link.tsx +34 -27
- package/client/services/router/components/Page.tsx +6 -14
- package/client/services/router/components/router.ssr.tsx +36 -0
- package/client/services/router/components/router.tsx +63 -83
- package/client/services/router/index.tsx +185 -220
- package/client/services/router/request/api.ts +97 -119
- package/client/services/router/request/history.ts +2 -2
- package/client/services/router/request/index.ts +13 -12
- package/client/services/router/request/multipart.ts +72 -62
- package/client/services/router/response/index.tsx +68 -61
- package/client/services/router/response/page.ts +28 -32
- package/client/utils/dom.ts +17 -33
- package/common/app/index.ts +3 -3
- package/common/data/chaines/index.ts +22 -23
- package/common/data/dates.ts +35 -70
- package/common/data/markdown.ts +42 -39
- package/common/dev/serverHotReload.ts +26 -0
- package/common/errors/index.tsx +110 -142
- package/common/router/contracts.ts +29 -0
- package/common/router/index.ts +89 -108
- package/common/router/layouts.ts +34 -47
- package/common/router/pageSetup.ts +50 -0
- package/common/router/register.ts +53 -24
- package/common/router/request/api.ts +30 -36
- package/common/router/request/index.ts +2 -8
- package/common/router/response/index.ts +8 -15
- package/common/router/response/page.ts +70 -58
- package/common/utils.ts +1 -1
- package/doc/TODO.md +1 -1
- package/eslint.js +62 -0
- package/package.json +14 -49
- package/prettier.config.cjs +9 -0
- package/scripts/cleanup-generated-controllers.ts +62 -0
- package/scripts/fix-reference-app-typing.ts +490 -0
- package/scripts/refactor-client-app-imports.ts +244 -0
- package/scripts/refactor-client-pages.ts +587 -0
- package/scripts/refactor-server-controllers.ts +470 -0
- package/scripts/refactor-server-runtime-aliases.ts +360 -0
- package/scripts/restore-client-app-import-files.ts +41 -0
- package/scripts/restore-files-from-git-head.ts +20 -0
- package/scripts/update-codex-agents.ts +35 -0
- package/server/app/commands.ts +35 -64
- package/server/app/container/config.ts +48 -59
- package/server/app/container/console/index.ts +202 -248
- package/server/app/container/index.ts +33 -71
- package/server/app/controller/index.ts +61 -0
- package/server/app/index.ts +39 -105
- package/server/app/service/container.ts +41 -42
- package/server/app/service/index.ts +120 -147
- package/server/context.ts +1 -1
- package/server/index.ts +25 -1
- package/server/services/auth/index.ts +75 -115
- package/server/services/auth/router/index.ts +31 -32
- package/server/services/auth/router/request.ts +14 -16
- package/server/services/cron/CronTask.ts +13 -26
- package/server/services/cron/index.ts +14 -36
- package/server/services/disks/driver.ts +40 -58
- package/server/services/disks/drivers/local/index.ts +79 -90
- package/server/services/disks/drivers/s3/index.ts +116 -163
- package/server/services/disks/index.ts +23 -38
- package/server/services/email/index.ts +45 -104
- package/server/services/email/utils.ts +14 -27
- package/server/services/fetch/index.ts +53 -85
- package/server/services/prisma/Facet.ts +39 -91
- package/server/services/prisma/index.ts +74 -110
- package/server/services/router/generatedRuntime.ts +29 -0
- package/server/services/router/http/index.ts +78 -73
- package/server/services/router/http/multipart.ts +19 -42
- package/server/services/router/index.ts +378 -365
- package/server/services/router/request/api.ts +26 -25
- package/server/services/router/request/index.ts +44 -51
- package/server/services/router/request/service.ts +7 -11
- package/server/services/router/request/validation/zod.ts +111 -148
- package/server/services/router/response/index.ts +110 -125
- package/server/services/router/response/mask/Filter.ts +31 -72
- package/server/services/router/response/mask/index.ts +8 -15
- package/server/services/router/response/mask/selecteurs.ts +11 -25
- package/server/services/router/response/page/clientManifest.ts +25 -0
- package/server/services/router/response/page/document.tsx +199 -127
- package/server/services/router/response/page/index.tsx +89 -94
- package/server/services/router/service.ts +13 -15
- package/server/services/schema/index.ts +17 -26
- package/server/services/schema/request.ts +19 -33
- package/server/services/schema/router/index.ts +8 -11
- package/server/services/security/encrypt/aes/index.ts +15 -35
- package/server/utils/slug.ts +29 -35
- package/skills/clean-project-code/SKILL.md +63 -0
- package/skills/clean-project-code/agents/openai.yaml +4 -0
- package/tsconfig.common.json +4 -3
- package/tsconfig.json +4 -1
- package/types/aliases.d.ts +17 -21
- package/types/controller-input.test.ts +48 -0
- package/types/express-extra.d.ts +6 -0
- package/types/global/constants.d.ts +13 -0
- package/types/global/express-extra.d.ts +6 -0
- package/types/global/modules.d.ts +13 -16
- package/types/global/utils.d.ts +17 -49
- package/types/global/vendors.d.ts +62 -0
- package/types/icons.d.ts +65 -1
- package/types/uuid.d.ts +3 -0
- package/types/vendors.d.ts +62 -0
- package/cli/compiler/common/babel/index.ts +0 -170
- package/cli/compiler/common/babel/plugins/index.ts +0 -0
- package/cli/compiler/common/babel/plugins/services.ts +0 -586
- package/cli/compiler/common/babel/routes/imports.ts +0 -127
- package/cli/compiler/common/babel/routes/routes.ts +0 -1130
- package/client/services/captcha/index.ts +0 -67
- package/client/services/socket/index.ts +0 -147
- package/common/data/rte/nodes.ts +0 -83
- package/common/data/stats.ts +0 -90
- package/common/utils/rte.ts +0 -183
- package/server/services/auth/old.ts +0 -277
- package/server/services/cache/commands.ts +0 -41
- package/server/services/cache/index.ts +0 -297
- package/server/services/cache/service.json +0 -6
- package/server/services/socket/index.ts +0 -162
- package/server/services/socket/scope.ts +0 -226
- package/server/services/socket/service.json +0 -6
- package/server/services_old/SocketClient.ts +0 -92
- package/server/services_old/Token.old.ts +0 -97
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
- DEPENDANCES
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
|
-
// Npm
|
|
6
|
-
import zod from 'zod';
|
|
7
|
-
|
|
8
5
|
// Specific
|
|
9
|
-
import type { Application } from
|
|
10
|
-
import type { Command } from
|
|
6
|
+
import type { Application } from '../index';
|
|
7
|
+
import type { Command } from '../commands';
|
|
11
8
|
import type { TServiceMetas } from './container';
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
9
|
+
import context from '@server/context';
|
|
10
|
+
import type { TRouterContext, TAnyRouter } from '../../services/router';
|
|
14
11
|
|
|
15
12
|
export { schema } from '../../services/router/request/validation/zod';
|
|
16
13
|
export type { z } from '../../services/router/request/validation/zod';
|
|
@@ -19,8 +16,7 @@ export type { z } from '../../services/router/request/validation/zod';
|
|
|
19
16
|
- TYPES: OPTIONS
|
|
20
17
|
----------------------------------*/
|
|
21
18
|
|
|
22
|
-
export type AnyService
|
|
23
|
-
Service<{}, {}, Application>
|
|
19
|
+
export type AnyService = Service<{}, {}, Application, any>;
|
|
24
20
|
|
|
25
21
|
export type { TRegisteredServicesIndex, TRegisteredService } from './container';
|
|
26
22
|
|
|
@@ -28,27 +24,49 @@ export type { TRegisteredServicesIndex, TRegisteredService } from './container';
|
|
|
28
24
|
- TYPES: HOOKS
|
|
29
25
|
----------------------------------*/
|
|
30
26
|
|
|
31
|
-
export type THookCallback<THookArgs extends THookOptions> = (...args: THookArgs[
|
|
27
|
+
export type THookCallback<THookArgs extends THookOptions> = (...args: THookArgs['args']) => Promise<void>;
|
|
32
28
|
|
|
33
|
-
type THooksList = {
|
|
34
|
-
[hookName: string]: THookOptions
|
|
35
|
-
}
|
|
29
|
+
type THooksList = { [hookName: string]: THookOptions };
|
|
36
30
|
|
|
37
|
-
type THookOptions = {
|
|
38
|
-
args: any[]
|
|
39
|
-
}
|
|
31
|
+
type THookOptions = { args: any[] };
|
|
40
32
|
|
|
41
|
-
export type THooksIndex<THooks extends THooksList> = {[name in keyof THooks]?: THookCallback<
|
|
33
|
+
export type THooksIndex<THooks extends THooksList> = { [name in keyof THooks]?: THookCallback<THooks[name]>[] };
|
|
42
34
|
|
|
43
|
-
export type StartedServicesIndex = {
|
|
44
|
-
|
|
45
|
-
}
|
|
35
|
+
export type StartedServicesIndex = { [serviceId: string]: AnyService };
|
|
36
|
+
|
|
37
|
+
type TServiceRouter<TApplication extends Application> = TApplication extends { Router: infer TRouter }
|
|
38
|
+
? TRouter extends TAnyRouter
|
|
39
|
+
? TRouter
|
|
40
|
+
: TAnyRouter
|
|
41
|
+
: TAnyRouter;
|
|
46
42
|
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
export type TServiceRequestContext<TApplication extends Application = Application> = TRouterContext<
|
|
44
|
+
TServiceRouter<TApplication>
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
export type TServiceModelsClient<TApplication extends Application = Application> = TApplication extends {
|
|
48
|
+
Models: { client: infer TModels };
|
|
49
|
+
}
|
|
50
|
+
? TModels
|
|
51
|
+
: TApplication extends {
|
|
52
|
+
models: { client: infer TModels };
|
|
53
|
+
}
|
|
54
|
+
? TModels
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
export type TSetupConfig<TConfig> = TConfig extends (...args: any[]) => any
|
|
58
|
+
? TConfig
|
|
59
|
+
: TConfig extends Array<infer TItem>
|
|
60
|
+
? Array<TSetupConfig<TItem>>
|
|
61
|
+
: TConfig extends object
|
|
62
|
+
? ({ [K in keyof TConfig]?: TSetupConfig<TConfig[K]> } & Record<string, unknown>)
|
|
63
|
+
: TConfig;
|
|
64
|
+
|
|
65
|
+
export type TServiceArgs<TService extends { config: any; app: any; parent: any }> = [
|
|
66
|
+
parent: TService['parent'] | 'self',
|
|
67
|
+
config: null | undefined | TSetupConfig<TService['config']>,
|
|
68
|
+
app: TService['app'] | 'self',
|
|
69
|
+
];
|
|
52
70
|
|
|
53
71
|
/*----------------------------------
|
|
54
72
|
- CONFIG
|
|
@@ -56,128 +74,100 @@ export type TServiceArgs<TService extends AnyService> = [
|
|
|
56
74
|
|
|
57
75
|
const LogPrefix = '[service]';
|
|
58
76
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
[options: Omit<TControllerDefinition, 'controller'>]
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
export function Route( ...args: TDecoratorArgs ) {
|
|
67
|
-
|
|
68
|
-
let path: string | undefined;
|
|
69
|
-
let schema: zod.ZodSchema | undefined;
|
|
70
|
-
let options: Omit<TControllerDefinition, 'controller'|'schema'|'path'> = {};
|
|
71
|
-
|
|
72
|
-
if (typeof args[0] === 'object') {
|
|
73
|
-
const { path: path_, schema: schema_, ...options_ } = args[0];
|
|
74
|
-
path = path_;
|
|
75
|
-
schema = schema_;
|
|
76
|
-
options = options_;
|
|
77
|
-
} else {
|
|
78
|
-
path = args[0];
|
|
79
|
-
schema = args[1];
|
|
80
|
-
options = args[2] || {};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return function (
|
|
84
|
-
target: any,
|
|
85
|
-
propertyKey: string,
|
|
86
|
-
descriptor: PropertyDescriptor
|
|
87
|
-
) {
|
|
88
|
-
// Store the original method
|
|
89
|
-
const originalMethod = descriptor.value;
|
|
90
|
-
|
|
91
|
-
if (path === undefined)
|
|
92
|
-
path = target.constructor.name + '/' + propertyKey;
|
|
93
|
-
|
|
94
|
-
// Ensure the class has a static property to collect routes
|
|
95
|
-
if (!target.__routes) {
|
|
96
|
-
target.__routes = [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Create route object
|
|
100
|
-
const route: TRoute = {
|
|
101
|
-
method: 'POST',
|
|
102
|
-
path: '/api/' + path,
|
|
103
|
-
controller: originalMethod,
|
|
104
|
-
schema: schema,
|
|
105
|
-
options: {
|
|
106
|
-
priority: options.priority || 0
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Add this route to the class's routes collection
|
|
111
|
-
target.__routes.push(route);
|
|
112
|
-
|
|
113
|
-
// Original method is unchanged, just registered with router
|
|
114
|
-
return descriptor;
|
|
115
|
-
};
|
|
116
|
-
}
|
|
77
|
+
const resolveSelfReference = <TSelf extends object, TValue extends object>(
|
|
78
|
+
value: TValue | 'self',
|
|
79
|
+
self: TSelf,
|
|
80
|
+
): TValue | (TSelf & TValue) => (value === 'self' ? (self as TSelf & TValue) : value);
|
|
117
81
|
|
|
118
82
|
/*----------------------------------
|
|
119
83
|
- CLASS
|
|
120
84
|
----------------------------------*/
|
|
121
85
|
export default abstract class Service<
|
|
122
|
-
TConfig extends {},
|
|
86
|
+
TConfig extends {},
|
|
123
87
|
THooks extends THooksList,
|
|
124
|
-
TApplication extends Application,
|
|
125
|
-
TParent extends AnyService
|
|
88
|
+
TApplication extends Application = Application,
|
|
89
|
+
TParent extends object = AnyService,
|
|
126
90
|
> {
|
|
127
|
-
|
|
128
91
|
public started?: Promise<void>;
|
|
92
|
+
public starting?: Promise<void>;
|
|
129
93
|
public status: 'stopped' | 'starting' | 'running' | 'paused' = 'starting';
|
|
130
94
|
|
|
131
95
|
public commands?: Command[];
|
|
132
96
|
public metas!: TServiceMetas;
|
|
133
|
-
public bindings: string[] = []
|
|
97
|
+
public bindings: string[] = [];
|
|
134
98
|
|
|
135
99
|
public parent: TParent;
|
|
136
100
|
public app: TApplication;
|
|
137
101
|
public config: TConfig = {} as TConfig;
|
|
138
102
|
|
|
139
|
-
public constructor(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
103
|
+
public constructor(
|
|
104
|
+
parent: TParent | 'self',
|
|
105
|
+
config: null | undefined | TSetupConfig<TConfig>,
|
|
106
|
+
app: TApplication | 'self',
|
|
107
|
+
) {
|
|
108
|
+
this.parent = resolveSelfReference(parent, this) as TParent;
|
|
144
109
|
|
|
145
|
-
this.app = app
|
|
146
|
-
? this as unknown as TApplication
|
|
147
|
-
: app
|
|
110
|
+
this.app = resolveSelfReference(app, this) as TApplication;
|
|
148
111
|
|
|
149
|
-
this.config = config || {};
|
|
150
|
-
|
|
112
|
+
this.config = (config || {}) as TConfig;
|
|
151
113
|
}
|
|
152
114
|
|
|
153
115
|
public getServiceInstance() {
|
|
154
116
|
return this;
|
|
155
117
|
}
|
|
156
118
|
|
|
119
|
+
public get services(): TApplication {
|
|
120
|
+
return this.app;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public get models(): TServiceModelsClient<TApplication> {
|
|
124
|
+
const app = this.app as {
|
|
125
|
+
models?: { client?: TServiceModelsClient<TApplication> };
|
|
126
|
+
Models?: { client?: TServiceModelsClient<TApplication> };
|
|
127
|
+
};
|
|
128
|
+
const models = app.models?.client ?? app.Models?.client;
|
|
129
|
+
|
|
130
|
+
if (!models)
|
|
131
|
+
throw new Error(`${this.constructor.name} tried to access models but no Models service is registered.`);
|
|
132
|
+
|
|
133
|
+
return models;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected get request(): TServiceRequestContext<TApplication> {
|
|
137
|
+
const store = context.getStore() as { requestContext?: TServiceRequestContext<TApplication> } | undefined;
|
|
138
|
+
const requestContext = store?.requestContext;
|
|
139
|
+
|
|
140
|
+
if (!requestContext)
|
|
141
|
+
throw new Error(
|
|
142
|
+
`${this.constructor.name} tried to access request context outside of a controller request.`,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
return requestContext;
|
|
146
|
+
}
|
|
147
|
+
|
|
157
148
|
/*----------------------------------
|
|
158
149
|
- LIFECYCLE
|
|
159
150
|
----------------------------------*/
|
|
160
151
|
|
|
161
|
-
protected async ready(): Promise<
|
|
152
|
+
protected async ready(): Promise<any> {}
|
|
162
153
|
|
|
163
|
-
protected async shutdown(): Promise<
|
|
154
|
+
protected async shutdown(): Promise<any> {}
|
|
164
155
|
|
|
165
156
|
/*----------------------------------
|
|
166
157
|
- SUBSERVICES
|
|
167
158
|
----------------------------------*/
|
|
168
159
|
|
|
169
|
-
|
|
170
|
-
public use<TService extends AnyService = AnyService>(
|
|
160
|
+
public use<TService extends AnyService = AnyService>(
|
|
171
161
|
serviceId: string,
|
|
172
|
-
useOptions: { optional?: boolean } = {}
|
|
162
|
+
useOptions: { optional?: boolean } = {},
|
|
173
163
|
): TService | undefined {
|
|
164
|
+
const app = this.app as {
|
|
165
|
+
registered?: Record<string, { name: string }>;
|
|
166
|
+
} & Record<string, unknown>;
|
|
167
|
+
const registeredService = app.registered?.[serviceId];
|
|
168
|
+
if (registeredService !== undefined) return app[registeredService.name] as TService;
|
|
174
169
|
|
|
175
|
-
|
|
176
|
-
if (registeredService !== undefined)
|
|
177
|
-
return this.app[ registeredService.name ];
|
|
178
|
-
|
|
179
|
-
if (useOptions.optional === false)
|
|
180
|
-
throw new Error(`Service ${registeredService} not registered.`);
|
|
170
|
+
if (useOptions.optional === false) throw new Error(`Service ${registeredService} not registered.`);
|
|
181
171
|
|
|
182
172
|
return undefined;
|
|
183
173
|
}
|
|
@@ -186,50 +176,33 @@ export default abstract class Service<
|
|
|
186
176
|
- HOOKS
|
|
187
177
|
----------------------------------*/
|
|
188
178
|
|
|
189
|
-
public hooks: THooksIndex<THooks> = {}
|
|
190
|
-
|
|
191
|
-
public on<THookName extends keyof THooksList>(
|
|
192
|
-
name: THookName,
|
|
193
|
-
callback: THookCallback<THooksList[THookName]>
|
|
194
|
-
) {
|
|
179
|
+
public hooks: THooksIndex<THooks> = {};
|
|
195
180
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
else
|
|
200
|
-
this.hooks[ name ] = [callback]
|
|
181
|
+
public on<THookName extends keyof THooksList>(name: THookName, callback: THookCallback<THooksList[THookName]>) {
|
|
182
|
+
const callbacks = this.hooks[name];
|
|
183
|
+
if (callbacks) callbacks.push(callback);
|
|
184
|
+
else this.hooks[name] = [callback];
|
|
201
185
|
|
|
202
186
|
return this;
|
|
203
187
|
}
|
|
204
188
|
|
|
205
|
-
public runHook<THookName extends keyof THooksList>(
|
|
206
|
-
name: THookName,
|
|
207
|
-
...args: THooksList[THookName]["args"]
|
|
208
|
-
) {
|
|
209
|
-
|
|
189
|
+
public runHook<THookName extends keyof THooksList>(name: THookName, ...args: THooksList[THookName]['args']) {
|
|
210
190
|
const callbacks = this.hooks[name];
|
|
211
|
-
if (!callbacks)
|
|
212
|
-
return;// console.info(LogPrefix, `No ${name} hook defined in the current service instance.`);
|
|
191
|
+
if (!callbacks) return; // console.info(LogPrefix, `No ${name} hook defined in the current service instance.`);
|
|
213
192
|
|
|
214
193
|
//this.config.debug && console.info(`[hook] Run all ${name} hook (${callbacks.length}).`);
|
|
215
|
-
return Promise.all(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Let the error hook handle it
|
|
230
|
-
throw e;
|
|
231
|
-
}
|
|
232
|
-
})
|
|
194
|
+
return Promise.all(callbacks.map((cb) => cb(...args)))
|
|
195
|
+
.then(() => {
|
|
196
|
+
//this.config.debug && console.info(`[hook] Hooks ${name} executed with success.`);
|
|
197
|
+
})
|
|
198
|
+
.catch((e) => {
|
|
199
|
+
if (name === 'error') {
|
|
200
|
+
// In error hook = avoid infinite loop
|
|
201
|
+
console.error('Error hook', e);
|
|
202
|
+
} else {
|
|
203
|
+
// Let the error hook handle it
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
233
207
|
}
|
|
234
|
-
|
|
235
|
-
}
|
|
208
|
+
}
|
package/server/context.ts
CHANGED
package/server/index.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import AppContainer from './app/container';
|
|
2
2
|
import Application from '@/server/.generated/app';
|
|
3
|
+
import { isServerHotReloadRequest, serverHotReloadMessageType } from '@common/dev/serverHotReload';
|
|
3
4
|
|
|
4
|
-
AppContainer.start(
|
|
5
|
+
const application = AppContainer.start(Application);
|
|
6
|
+
|
|
7
|
+
if (__DEV__ && typeof process.send === 'function') {
|
|
8
|
+
process.on('message', (message: unknown) => {
|
|
9
|
+
if (!isServerHotReloadRequest(message)) return;
|
|
10
|
+
|
|
11
|
+
void (async () => {
|
|
12
|
+
try {
|
|
13
|
+
await application.Router?.started;
|
|
14
|
+
await application.Router.reloadGeneratedDefinitions(message.changedFiles);
|
|
15
|
+
|
|
16
|
+
process.send?.({ type: serverHotReloadMessageType.succeeded, changedFiles: message.changedFiles });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
const errorMessage = error instanceof Error ? error.stack || error.message : String(error);
|
|
19
|
+
|
|
20
|
+
process.send?.({
|
|
21
|
+
type: serverHotReloadMessageType.failed,
|
|
22
|
+
changedFiles: message.changedFiles,
|
|
23
|
+
error: errorMessage,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
})();
|
|
27
|
+
});
|
|
28
|
+
}
|