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
|
@@ -7,11 +7,8 @@ import { serialize } from 'v8';
|
|
|
7
7
|
import { formatWithOptions } from 'util';
|
|
8
8
|
import md5 from 'md5';
|
|
9
9
|
import dayjs from 'dayjs';
|
|
10
|
-
import Youch from 'youch';
|
|
11
|
-
import forTerminal from 'youch-terminal';
|
|
12
10
|
|
|
13
11
|
// Npm
|
|
14
|
-
import { v4 as uuid } from 'uuid';
|
|
15
12
|
import { Logger, IMeta, ILogObj, ISettings } from 'tslog';
|
|
16
13
|
import highlight from 'cli-highlight';
|
|
17
14
|
import Ansi2Html from 'ansi-to-html';
|
|
@@ -19,99 +16,74 @@ import Ansi2Html from 'ansi-to-html';
|
|
|
19
16
|
// Core libs
|
|
20
17
|
import type ApplicationContainer from '..';
|
|
21
18
|
import context from '@server/context';
|
|
22
|
-
import type { ServerBug, TCatchedError
|
|
19
|
+
import type { ServerBug, TCatchedError } from '@common/errors';
|
|
23
20
|
import type ServerRequest from '@server/services/router/request';
|
|
24
21
|
|
|
25
22
|
/*----------------------------------
|
|
26
23
|
- SERVICE CONFIG
|
|
27
24
|
----------------------------------*/
|
|
28
25
|
|
|
29
|
-
export type TLogProfile = 'silly' | 'info' | 'warn' | 'error'
|
|
26
|
+
export type TLogProfile = 'silly' | 'info' | 'warn' | 'error';
|
|
30
27
|
|
|
31
|
-
export type Config = {
|
|
32
|
-
debug?: boolean,
|
|
33
|
-
enable: boolean,
|
|
34
|
-
bufferLimit: number,
|
|
35
|
-
level: TLogProfile,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type Hooks = {
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
export type Config = { debug?: boolean; enable: boolean; bufferLimit: number; level: TLogProfile };
|
|
41
29
|
|
|
42
|
-
export type
|
|
30
|
+
export type Hooks = {};
|
|
43
31
|
|
|
44
|
-
}
|
|
32
|
+
export type Services = {};
|
|
45
33
|
|
|
46
34
|
/*----------------------------------
|
|
47
35
|
- TYPES
|
|
48
36
|
----------------------------------*/
|
|
49
37
|
|
|
50
38
|
export type ChannelInfos = {
|
|
51
|
-
channelType: 'cron' | 'master' | 'request' | 'socket'
|
|
52
|
-
channelId?: string
|
|
39
|
+
channelType: 'cron' | 'master' | 'request' | 'socket';
|
|
40
|
+
channelId?: string;
|
|
53
41
|
|
|
54
|
-
method?: string
|
|
55
|
-
path?: string
|
|
42
|
+
method?: string;
|
|
43
|
+
path?: string;
|
|
56
44
|
|
|
57
|
-
user?: string
|
|
58
|
-
}
|
|
45
|
+
user?: string;
|
|
46
|
+
};
|
|
59
47
|
|
|
60
48
|
export type TGuestLogs = {
|
|
61
|
-
id: string
|
|
62
|
-
meet: Date
|
|
63
|
-
activity: Date
|
|
49
|
+
id: string;
|
|
50
|
+
meet: Date;
|
|
51
|
+
activity: Date;
|
|
64
52
|
|
|
65
|
-
device: string
|
|
66
|
-
ip: string
|
|
67
|
-
user?: string
|
|
68
|
-
}
|
|
53
|
+
device: string;
|
|
54
|
+
ip: string;
|
|
55
|
+
user?: string;
|
|
56
|
+
};
|
|
69
57
|
|
|
70
58
|
export type TRequestLogs = {
|
|
59
|
+
id: string;
|
|
60
|
+
date: Date;
|
|
71
61
|
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
method: string;
|
|
63
|
+
url: string;
|
|
64
|
+
data: TObjetDonnees;
|
|
74
65
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
ip: string;
|
|
67
|
+
user?: string;
|
|
68
|
+
clientId: string;
|
|
78
69
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
statusCode: number;
|
|
71
|
+
time: number;
|
|
72
|
+
};
|
|
82
73
|
|
|
83
|
-
|
|
84
|
-
time: number
|
|
85
|
-
}
|
|
74
|
+
export type TDbQueryLog = ChannelInfos & { date: Date; query: string; time: number };
|
|
86
75
|
|
|
87
|
-
export type
|
|
88
|
-
date: Date,
|
|
89
|
-
query: string,
|
|
90
|
-
time: number,
|
|
91
|
-
}
|
|
76
|
+
export type TLogLevel = keyof typeof logLevels;
|
|
92
77
|
|
|
93
|
-
export type
|
|
94
|
-
|
|
95
|
-
export type TJsonLog = {
|
|
96
|
-
time: Date,
|
|
97
|
-
level: TLogLevel,
|
|
98
|
-
args: unknown[],
|
|
99
|
-
channel: ChannelInfos
|
|
100
|
-
}
|
|
78
|
+
export type TJsonLog = { time: Date; level: TLogLevel; args: unknown[]; channel: ChannelInfos };
|
|
101
79
|
|
|
102
80
|
/*----------------------------------
|
|
103
81
|
- CONST
|
|
104
82
|
----------------------------------*/
|
|
105
83
|
|
|
106
|
-
const LogPrefix = '[console]'
|
|
107
|
-
|
|
108
|
-
const logLevels = {
|
|
109
|
-
'log': 0,
|
|
110
|
-
'info': 3,
|
|
111
|
-
'warn': 4,
|
|
112
|
-
'error': 5
|
|
113
|
-
} as const;
|
|
84
|
+
const LogPrefix = '[console]';
|
|
114
85
|
|
|
86
|
+
const logLevels = { silly: -1, log: 0, info: 3, warn: 4, error: 5 } as const;
|
|
115
87
|
|
|
116
88
|
var ansi2Html = new Ansi2Html({
|
|
117
89
|
newline: true,
|
|
@@ -120,40 +92,36 @@ var ansi2Html = new Ansi2Html({
|
|
|
120
92
|
fg: '#fff',
|
|
121
93
|
bg: '#000',
|
|
122
94
|
colors: [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]
|
|
95
|
+
'#252525',
|
|
96
|
+
'#FF5252',
|
|
97
|
+
'#C3D82C',
|
|
98
|
+
'#FFC135',
|
|
99
|
+
'#42A5F5',
|
|
100
|
+
'#D81B60',
|
|
101
|
+
'#00ACC1',
|
|
102
|
+
'#F5F5F5',
|
|
103
|
+
'#708284',
|
|
104
|
+
'#FF5252',
|
|
105
|
+
'#C3D82C',
|
|
106
|
+
'#FFC135',
|
|
107
|
+
'#42A5F5',
|
|
108
|
+
'#D81B60',
|
|
109
|
+
'#00ACC1',
|
|
110
|
+
'#F5F5F5',
|
|
111
|
+
],
|
|
140
112
|
});
|
|
141
113
|
|
|
114
|
+
type TWrappedConsole = typeof console & { _wrapped?: boolean };
|
|
115
|
+
|
|
142
116
|
/*----------------------------------
|
|
143
117
|
- LOGGER
|
|
144
118
|
----------------------------------*/
|
|
145
119
|
export default class Console {
|
|
146
|
-
|
|
147
120
|
// Services
|
|
148
121
|
public logger!: Logger<ILogObj>;
|
|
149
122
|
// Buffers
|
|
150
123
|
public logs: TJsonLog[] = [];
|
|
151
|
-
private reported: {
|
|
152
|
-
[hash: string]: {
|
|
153
|
-
times: number,
|
|
154
|
-
last: Date,
|
|
155
|
-
}
|
|
156
|
-
} = {};
|
|
124
|
+
private reported: { [hash: string]: { times: number; last: Date } } = {};
|
|
157
125
|
|
|
158
126
|
/*----------------------------------
|
|
159
127
|
- LIFECYCLE
|
|
@@ -162,14 +130,13 @@ export default class Console {
|
|
|
162
130
|
WARN: This service should depend on the less services as possible, and be usable ASAP.
|
|
163
131
|
So bug reports can be sent at any state of the app, includoing thre most early
|
|
164
132
|
*/
|
|
165
|
-
public constructor(
|
|
166
|
-
private container: typeof ApplicationContainer,
|
|
133
|
+
public constructor(
|
|
134
|
+
private container: typeof ApplicationContainer,
|
|
167
135
|
private config: Config,
|
|
168
136
|
) {
|
|
137
|
+
console.log('Setting up Console shell module.');
|
|
169
138
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const origLog = console.log
|
|
139
|
+
const origLog = console.log;
|
|
173
140
|
|
|
174
141
|
const Env = container.Environment;
|
|
175
142
|
|
|
@@ -177,70 +144,68 @@ export default class Console {
|
|
|
177
144
|
// Use to improve performance in production
|
|
178
145
|
hideLogPositionForProduction: Env.profile === 'prod',
|
|
179
146
|
type: 'pretty',
|
|
180
|
-
prettyInspectOptions: {
|
|
181
|
-
depth: 2
|
|
182
|
-
},
|
|
147
|
+
prettyInspectOptions: { depth: 2 },
|
|
183
148
|
overwrite: {
|
|
184
149
|
formatMeta: (meta?: IMeta) => {
|
|
185
|
-
|
|
186
150
|
// Shorten file paths
|
|
187
151
|
if (meta?.path !== undefined) {
|
|
188
|
-
meta.path.filePathWithLine = this.shortenFilePath(
|
|
152
|
+
meta.path.filePathWithLine = this.shortenFilePath(meta.path.filePathWithLine);
|
|
189
153
|
}
|
|
190
154
|
|
|
191
|
-
return this.logger[
|
|
155
|
+
return this.logger['_prettyFormatLogObjMeta'](meta);
|
|
192
156
|
},
|
|
193
157
|
transportFormatted: (
|
|
194
|
-
logMetaMarkup: string,
|
|
195
|
-
logArgs: unknown[],
|
|
196
|
-
logErrors: string[],
|
|
197
|
-
|
|
158
|
+
logMetaMarkup: string,
|
|
159
|
+
logArgs: unknown[],
|
|
160
|
+
logErrors: string[],
|
|
161
|
+
_logMeta?: IMeta,
|
|
162
|
+
settings?: ISettings<ILogObj>,
|
|
198
163
|
) => {
|
|
199
164
|
try {
|
|
200
|
-
const logErrorsStr =
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
165
|
+
const logErrorsStr =
|
|
166
|
+
(logErrors.length > 0 && logArgs.length > 0 ? '\n' : '') + logErrors.join('\n');
|
|
167
|
+
const loggerSettings = settings || this.logger.settings;
|
|
168
|
+
loggerSettings.prettyInspectOptions = loggerSettings.prettyInspectOptions || {};
|
|
169
|
+
loggerSettings.prettyInspectOptions.colors = loggerSettings.stylePrettyLogs;
|
|
170
|
+
origLog(
|
|
171
|
+
logMetaMarkup +
|
|
172
|
+
formatWithOptions(loggerSettings.prettyInspectOptions, ...logArgs) +
|
|
173
|
+
logErrorsStr,
|
|
174
|
+
);
|
|
204
175
|
} catch (error) {
|
|
205
|
-
origLog(
|
|
176
|
+
origLog('Error formatting log', error);
|
|
206
177
|
}
|
|
207
178
|
},
|
|
208
|
-
}
|
|
209
|
-
});
|
|
179
|
+
},
|
|
180
|
+
});
|
|
210
181
|
|
|
211
|
-
|
|
212
|
-
|
|
182
|
+
const wrappedConsole = console as TWrappedConsole;
|
|
183
|
+
if (!this.config.enable || wrappedConsole._wrapped !== undefined) return;
|
|
213
184
|
|
|
214
185
|
this.enableLogging(origLog);
|
|
215
186
|
}
|
|
216
187
|
|
|
217
|
-
private enableLogging(
|
|
218
|
-
|
|
188
|
+
private enableLogging(origLog: typeof console.log) {
|
|
189
|
+
const wrappedConsole = console as TWrappedConsole & Record<string, (...args: any[]) => void>;
|
|
219
190
|
const minLogLevel = logLevels[this.config.level];
|
|
220
191
|
|
|
221
192
|
let logLevel: TLogLevel;
|
|
222
193
|
for (logLevel in logLevels) {
|
|
223
194
|
const levelNumber = logLevels[logLevel];
|
|
224
|
-
|
|
225
|
-
|
|
195
|
+
wrappedConsole[logLevel] = (...args: any[]) => {
|
|
226
196
|
// Dev mode = no care about performance = rich logging
|
|
227
197
|
if (levelNumber >= minLogLevel)
|
|
228
198
|
//this.logger[ logLevel ](...args);
|
|
229
199
|
origLog(...args);
|
|
230
|
-
// Prod mode = minimal logging
|
|
200
|
+
// Prod mode = minimal logging
|
|
231
201
|
|
|
232
202
|
const channel = this.getChannel();
|
|
233
203
|
|
|
234
|
-
this.logs.push({
|
|
235
|
-
|
|
236
|
-
level: logLevel,
|
|
237
|
-
args,
|
|
238
|
-
channel
|
|
239
|
-
});
|
|
240
|
-
}
|
|
204
|
+
this.logs.push({ time: new Date(), level: logLevel, args, channel });
|
|
205
|
+
};
|
|
241
206
|
}
|
|
242
207
|
|
|
243
|
-
|
|
208
|
+
wrappedConsole._wrapped = true;
|
|
244
209
|
|
|
245
210
|
setInterval(() => this.clean(), 10000);
|
|
246
211
|
}
|
|
@@ -249,53 +214,47 @@ export default class Console {
|
|
|
249
214
|
- LOGS FORMATTING
|
|
250
215
|
----------------------------------*/
|
|
251
216
|
|
|
252
|
-
public shortenFilePath(
|
|
253
|
-
|
|
254
|
-
if (filepath === undefined)
|
|
255
|
-
return undefined;
|
|
217
|
+
public shortenFilePath(filepath?: string) {
|
|
218
|
+
if (filepath === undefined) return undefined;
|
|
256
219
|
|
|
257
220
|
const projectRoot = this.container.path.root;
|
|
258
|
-
if (filepath.startsWith( projectRoot
|
|
259
|
-
filepath = filepath.substring( projectRoot.length )
|
|
221
|
+
if (filepath.startsWith(projectRoot)) filepath = filepath.substring(projectRoot.length);
|
|
260
222
|
|
|
261
223
|
const frameworkRoot = '/node_modules/proteum/';
|
|
262
|
-
if (filepath.startsWith( frameworkRoot
|
|
263
|
-
filepath = '@' + filepath.substring( frameworkRoot.length )
|
|
224
|
+
if (filepath.startsWith(frameworkRoot)) filepath = '@' + filepath.substring(frameworkRoot.length);
|
|
264
225
|
|
|
265
226
|
return filepath;
|
|
266
|
-
|
|
267
227
|
}
|
|
268
|
-
|
|
269
228
|
|
|
270
229
|
/*----------------------------------
|
|
271
230
|
- ACTIONS
|
|
272
231
|
----------------------------------*/
|
|
273
232
|
|
|
274
|
-
public getLogLevelId(
|
|
275
|
-
return logLevels[
|
|
233
|
+
public getLogLevelId(logLevelName: TLogLevel) {
|
|
234
|
+
return logLevels[logLevelName];
|
|
276
235
|
}
|
|
277
236
|
|
|
278
237
|
private clean() {
|
|
279
|
-
|
|
280
238
|
if (this.config.debug) {
|
|
281
239
|
console.log(
|
|
282
|
-
LogPrefix,
|
|
283
|
-
`Clean logs buffer. Current size:`,
|
|
284
|
-
this.logs.length,
|
|
285
|
-
'
|
|
240
|
+
LogPrefix,
|
|
241
|
+
`Clean logs buffer. Current size:`,
|
|
242
|
+
this.logs.length,
|
|
243
|
+
'/',
|
|
244
|
+
this.config.bufferLimit,
|
|
245
|
+
'Memory Size:',
|
|
246
|
+
serialize(this.logs).byteLength,
|
|
286
247
|
);
|
|
287
248
|
}
|
|
288
249
|
|
|
289
250
|
const bufferOverflow = this.logs.length - this.config.bufferLimit;
|
|
290
|
-
if (bufferOverflow > 0)
|
|
291
|
-
this.logs = this.logs.slice(bufferOverflow);
|
|
251
|
+
if (bufferOverflow > 0) this.logs = this.logs.slice(bufferOverflow);
|
|
292
252
|
}
|
|
293
253
|
|
|
294
254
|
// We don't prevent duplicates because we want to receive all variants of the same error
|
|
295
|
-
public async createBugReport(
|
|
296
|
-
|
|
255
|
+
public async createBugReport(error: TCatchedError, request?: ServerRequest) {
|
|
297
256
|
const application = this.container.application;
|
|
298
|
-
if (application === undefined)
|
|
257
|
+
if (application === undefined)
|
|
299
258
|
return console.error(LogPrefix, "Can't send bug report because the application is not instanciated");
|
|
300
259
|
|
|
301
260
|
// Get context
|
|
@@ -308,157 +267,154 @@ export default class Console {
|
|
|
308
267
|
const inspection = this.getDetailledError(error);
|
|
309
268
|
|
|
310
269
|
// Genertae unique error hash
|
|
311
|
-
const hash = md5(
|
|
270
|
+
const hash = md5(inspection.stacktraces[0]);
|
|
312
271
|
|
|
313
272
|
// Don't send the same error twice in a row (avoid email spamming)
|
|
314
273
|
const lastReport = this.reported[hash];
|
|
315
274
|
let isDuplicate = false;
|
|
316
275
|
if (lastReport === undefined) {
|
|
276
|
+
this.reported[hash] = { times: 0, last: new Date() };
|
|
317
277
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
last: new Date()
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// If error older than 1 day
|
|
324
|
-
} else if (dayjs(now).diff( dayjs(lastReport.last), 'day' ) > 1) {
|
|
325
|
-
|
|
278
|
+
// If error older than 1 day
|
|
279
|
+
} else if (dayjs(now).diff(dayjs(lastReport.last), 'day') > 1) {
|
|
326
280
|
lastReport.times++;
|
|
327
281
|
lastReport.last = now;
|
|
328
|
-
|
|
329
282
|
} else {
|
|
330
|
-
|
|
331
283
|
isDuplicate = true;
|
|
332
284
|
}
|
|
333
285
|
|
|
334
286
|
const bugReport: ServerBug = {
|
|
335
|
-
|
|
336
287
|
// Context
|
|
337
288
|
hash: hash,
|
|
338
289
|
isDuplicate,
|
|
339
290
|
date: now,
|
|
340
|
-
channelType,
|
|
291
|
+
channelType,
|
|
341
292
|
channelId,
|
|
342
293
|
|
|
343
|
-
...(request
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
294
|
+
...(request
|
|
295
|
+
? {
|
|
296
|
+
// User
|
|
297
|
+
user: request.user,
|
|
298
|
+
ip: request.ip,
|
|
299
|
+
|
|
300
|
+
// Request
|
|
301
|
+
request: {
|
|
302
|
+
method: request.method,
|
|
303
|
+
url: request.url,
|
|
304
|
+
data: request.data,
|
|
305
|
+
validatedData: request.validatedData,
|
|
306
|
+
headers: request.headers,
|
|
307
|
+
cookies: request.cookies,
|
|
308
|
+
},
|
|
309
|
+
}
|
|
310
|
+
: {}),
|
|
360
311
|
|
|
361
312
|
// Error
|
|
362
313
|
title: inspection.title,
|
|
363
314
|
stacktraces: inspection.stacktraces,
|
|
364
|
-
context: inspection.context
|
|
365
|
-
}
|
|
315
|
+
context: inspection.context,
|
|
316
|
+
};
|
|
366
317
|
|
|
367
318
|
await application.runHook('bug', bugReport);
|
|
368
319
|
|
|
369
320
|
return bugReport;
|
|
370
321
|
}
|
|
371
322
|
|
|
372
|
-
public getDetailledError(
|
|
373
|
-
|
|
323
|
+
public getDetailledError(error: TCatchedError) {
|
|
374
324
|
const stacktraces: string[] = [];
|
|
375
325
|
const context: object[] = [];
|
|
376
326
|
|
|
377
327
|
let currentError: TCatchedError | undefined = error;
|
|
378
328
|
let title: string | undefined;
|
|
379
329
|
while (currentError !== undefined) {
|
|
380
|
-
|
|
381
|
-
if (title === undefined)
|
|
382
|
-
title = currentError.message;
|
|
330
|
+
if (title === undefined) title = currentError.message;
|
|
383
331
|
|
|
384
332
|
// Stacktrace
|
|
385
333
|
this.logger.error(LogPrefix, `Sending bug report for the following error:`, currentError);
|
|
386
334
|
stacktraces.push(currentError.stack || currentError.message);
|
|
387
335
|
|
|
388
336
|
// Context
|
|
389
|
-
if (
|
|
337
|
+
if ('dataForDebugging' in currentError && currentError.dataForDebugging !== undefined) {
|
|
390
338
|
console.error(LogPrefix, `More data about the error:`, currentError.dataForDebugging);
|
|
391
339
|
context.push(currentError.dataForDebugging || {});
|
|
392
340
|
}
|
|
393
341
|
|
|
394
342
|
// Go deeper
|
|
395
|
-
currentError = 'originalError' in currentError
|
|
396
|
-
? currentError.originalError
|
|
397
|
-
: undefined
|
|
343
|
+
currentError = 'originalError' in currentError ? currentError.originalError : undefined;
|
|
398
344
|
}
|
|
399
345
|
|
|
400
346
|
return { title, stacktraces, context };
|
|
401
347
|
}
|
|
402
348
|
|
|
403
349
|
public getChannel() {
|
|
404
|
-
return context.getStore() || {
|
|
405
|
-
channelType: 'master',
|
|
406
|
-
channelId: undefined
|
|
407
|
-
}
|
|
350
|
+
return context.getStore() || { channelType: 'master', channelId: undefined };
|
|
408
351
|
}
|
|
409
352
|
|
|
410
353
|
/*----------------------------------
|
|
411
354
|
- PRINT
|
|
412
355
|
----------------------------------*/
|
|
413
356
|
|
|
414
|
-
public bugToHtml(
|
|
415
|
-
|
|
357
|
+
public bugToHtml(report: ServerBug) {
|
|
416
358
|
return `
|
|
417
359
|
<b>Channel</b>: ${report.channelType} (${report.channelId})<br />
|
|
418
|
-
<b>User</b>: ${report.user ?
|
|
360
|
+
<b>User</b>: ${report.user ? report.user.name + ' (' + report.user.email + ')' : 'Unknown'}<br />
|
|
419
361
|
<b>IP</b>: ${report.ip}<br />
|
|
420
362
|
|
|
421
363
|
${this.stacktracesToHTML(report.stacktraces)}
|
|
422
364
|
|
|
423
|
-
${report.context
|
|
365
|
+
${report.context
|
|
366
|
+
.map(
|
|
367
|
+
(context, index) => `
|
|
424
368
|
<hr />
|
|
425
369
|
<b>Context ${index + 1}</b>: ${this.jsonToHTML(context)}<br />
|
|
426
|
-
|
|
370
|
+
`,
|
|
371
|
+
)
|
|
372
|
+
.join('')}
|
|
427
373
|
|
|
428
|
-
${
|
|
374
|
+
${
|
|
375
|
+
report.request
|
|
376
|
+
? `
|
|
429
377
|
<hr />
|
|
430
378
|
<b>Request</b>: ${report.request.method} ${report.request.url}<br />
|
|
431
379
|
<b>Headers</b>: ${this.jsonToHTML(report.request.headers)}<br />
|
|
432
380
|
<b>Cookies</b>: ${this.jsonToHTML(report.request.cookies)}<br />
|
|
433
381
|
<b>Raw Data</b>: ${this.jsonToHTML(report.request.data)}<br />
|
|
434
382
|
<b>Validated Data</b>: ${this.jsonToHTML(report.request.validatedData)}
|
|
435
|
-
`
|
|
383
|
+
`
|
|
384
|
+
: ''
|
|
385
|
+
}
|
|
436
386
|
<hr/>
|
|
437
|
-
Logs: ${
|
|
438
|
-
|
|
387
|
+
Logs: ${
|
|
388
|
+
this.config.enable
|
|
389
|
+
? `<br/>` + this.logsToHTML((report as ServerBug & { logs?: TJsonLog[] }).logs || this.logs)
|
|
390
|
+
: 'Logs collection is disabled'
|
|
391
|
+
}<br />
|
|
392
|
+
`;
|
|
439
393
|
}
|
|
440
394
|
|
|
441
|
-
public stacktracesToHTML(
|
|
442
|
-
return stacktraces
|
|
395
|
+
public stacktracesToHTML(stacktraces: string[]): string {
|
|
396
|
+
return stacktraces
|
|
397
|
+
.map(
|
|
398
|
+
(stacktrace, index) => `
|
|
443
399
|
<hr />
|
|
444
400
|
<b>Stacktrace ${index + 1}</b>: ${this.printHtml(stacktrace)}<br />
|
|
445
|
-
|
|
401
|
+
`,
|
|
402
|
+
)
|
|
403
|
+
.join('');
|
|
446
404
|
}
|
|
447
|
-
|
|
448
|
-
public logsToHTML( logs: TJsonLog[] ): string {
|
|
449
405
|
|
|
450
|
-
|
|
406
|
+
public logsToHTML(logs: TJsonLog[]): string {
|
|
407
|
+
let ansi = logs.map((logEntry) => this.logToAnsi(logEntry)).join('<br />');
|
|
451
408
|
|
|
452
409
|
// Convert ANSI to HTML
|
|
453
|
-
const html = ansi2Html.toHtml(ansi)
|
|
410
|
+
const html = ansi2Html.toHtml(ansi);
|
|
454
411
|
|
|
455
|
-
return this.printHtml(
|
|
412
|
+
return this.printHtml(html);
|
|
456
413
|
}
|
|
457
414
|
|
|
458
|
-
private logToAnsi(
|
|
459
|
-
|
|
415
|
+
private logToAnsi(log: TJsonLog) {
|
|
460
416
|
// Print metas as ANSI
|
|
461
|
-
const logMetaMarkup = this.logger[
|
|
417
|
+
const logMetaMarkup = this.logger['_prettyFormatLogObjMeta']({
|
|
462
418
|
date: log.time,
|
|
463
419
|
logLevelId: this.getLogLevelId(log.level),
|
|
464
420
|
logLevelName: log.level,
|
|
@@ -467,53 +423,45 @@ Logs: ${this.config.enable ? `<br/>` + this.logsToHTML(report.logs) : 'Logs coll
|
|
|
467
423
|
});
|
|
468
424
|
|
|
469
425
|
// Print args as ANSI
|
|
470
|
-
const logArgsAndErrorsMarkup = this.logger[
|
|
426
|
+
const logArgsAndErrorsMarkup = this.logger['runtime'].prettyFormatLogObj(log.args, this.logger.settings);
|
|
471
427
|
const logErrors = logArgsAndErrorsMarkup.errors;
|
|
472
428
|
const logArgs = logArgsAndErrorsMarkup.args;
|
|
473
|
-
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ?
|
|
429
|
+
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? '\n' : '') + logErrors.join('\n');
|
|
474
430
|
this.logger.settings.prettyInspectOptions.colors = this.logger.settings.stylePrettyLogs;
|
|
475
|
-
let ansi =
|
|
431
|
+
let ansi =
|
|
432
|
+
logMetaMarkup + formatWithOptions(this.logger.settings.prettyInspectOptions, ...logArgs) + logErrorsStr;
|
|
476
433
|
|
|
477
434
|
return ansi;
|
|
478
435
|
}
|
|
479
436
|
|
|
480
|
-
public jsonToHTML(
|
|
481
|
-
|
|
482
|
-
if (!json)
|
|
483
|
-
return 'No data';
|
|
437
|
+
public jsonToHTML(json: unknown): string {
|
|
438
|
+
if (!json) return 'No data';
|
|
484
439
|
|
|
485
|
-
const coloredJson = highlight(
|
|
486
|
-
JSON.stringify(json, null, 4),
|
|
487
|
-
{ language: 'json', ignoreIllegals: true }
|
|
488
|
-
);
|
|
440
|
+
const coloredJson = highlight(JSON.stringify(json, null, 4), { language: 'json', ignoreIllegals: true });
|
|
489
441
|
|
|
490
|
-
const html = ansi2Html.toHtml(coloredJson)
|
|
442
|
+
const html = ansi2Html.toHtml(coloredJson);
|
|
491
443
|
|
|
492
|
-
return this.printHtml(
|
|
444
|
+
return this.printHtml(html);
|
|
493
445
|
}
|
|
494
446
|
|
|
495
|
-
public printHtml(
|
|
496
|
-
|
|
497
|
-
if (!html)
|
|
498
|
-
return 'No data';
|
|
447
|
+
public printHtml(html: string): string {
|
|
448
|
+
if (!html) return 'No data';
|
|
499
449
|
|
|
500
450
|
// Preserve spaces
|
|
501
|
-
html = html
|
|
502
|
-
.replace(/\t/g, ' ')
|
|
503
|
-
.replace(/ /g, ' ')
|
|
504
|
-
.replace(/\n/g, '<br />');
|
|
451
|
+
html = html.replace(/\t/g, ' ').replace(/ /g, ' ').replace(/\n/g, '<br />');
|
|
505
452
|
|
|
506
453
|
// Create console wrapper
|
|
507
|
-
const consoleCss = `background: #000; padding: 20px; font-family: 'Fira Mono', 'monospace', 'Monaco'; font-size: 12px; line-height: 20px;color: #aaa
|
|
454
|
+
const consoleCss = `background: #000; padding: 20px; font-family: 'Fira Mono', 'monospace', 'Monaco'; font-size: 12px; line-height: 20px;color: #aaa;`;
|
|
508
455
|
html = '<div style="' + consoleCss + '">' + html + '</div>';
|
|
509
456
|
|
|
510
457
|
return html;
|
|
511
458
|
}
|
|
512
459
|
|
|
513
|
-
public printSql = (requete: string) =>
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
460
|
+
public printSql = (requete: string) =>
|
|
461
|
+
highlight(
|
|
462
|
+
requete, //formatSql(requete, { indent: ' '.repeat(4) }),
|
|
463
|
+
{ language: 'sql', ignoreIllegals: true },
|
|
464
|
+
);
|
|
517
465
|
|
|
518
466
|
/*public async getLogs( channelType: ChannelInfos["channelType"], channelId?: string ) {
|
|
519
467
|
|
|
@@ -531,20 +479,26 @@ Logs: ${this.config.enable ? `<br/>` + this.logsToHTML(report.logs) : 'Logs coll
|
|
|
531
479
|
// Remove path prefixs
|
|
532
480
|
if (log.filePath !== undefined) {
|
|
533
481
|
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
482
|
+
for (const prefix of ['/webpack:/', '/rspack:/']) {
|
|
483
|
+
const appPrefix = prefix + this.app.pkg.name + '/';
|
|
484
|
+
const appPrefixIndex = log.filePath.indexOf(appPrefix);
|
|
485
|
+
|
|
486
|
+
const corePrefix = prefix + this.app.pkg.name + '/node_modules/proteum/';
|
|
487
|
+
const corePrefixIndex = log.filePath.indexOf(corePrefix);
|
|
488
|
+
|
|
489
|
+
if (appPrefixIndex !== -1) {
|
|
490
|
+
log.filePath = '@/' + log.filePath.substring(appPrefixIndex + appPrefix.length);
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (corePrefixIndex !== -1) {
|
|
495
|
+
log.filePath = '@' + log.filePath.substring(corePrefixIndex + corePrefix.length);
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
544
499
|
}
|
|
545
500
|
}
|
|
546
501
|
|
|
547
502
|
return this.printHtml( entries );
|
|
548
503
|
}*/
|
|
549
|
-
|
|
550
|
-
}
|
|
504
|
+
}
|