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.
Files changed (185) hide show
  1. package/AGENTS.md +101 -0
  2. package/agents/codex/AGENTS.md +95 -0
  3. package/agents/codex/CODING_STYLE.md +71 -0
  4. package/agents/codex/agents.md.zip +0 -0
  5. package/agents/codex/client/AGENTS.md +102 -0
  6. package/agents/codex/client/pages/AGENTS.md +35 -0
  7. package/agents/codex/server/routes/AGENTS.md +12 -0
  8. package/agents/codex/server/services/AGENTS.md +137 -0
  9. package/agents/codex/tests/AGENTS.md +8 -0
  10. package/cli/app/config.ts +13 -11
  11. package/cli/app/index.ts +74 -82
  12. package/cli/bin.js +1 -1
  13. package/cli/commands/build.ts +51 -14
  14. package/cli/commands/check.ts +19 -0
  15. package/cli/commands/deploy/app.ts +4 -8
  16. package/cli/commands/deploy/web.ts +16 -20
  17. package/cli/commands/dev.ts +189 -64
  18. package/cli/commands/devEvents.ts +106 -0
  19. package/cli/commands/init.ts +63 -57
  20. package/cli/commands/lint.ts +21 -0
  21. package/cli/commands/refresh.ts +18 -0
  22. package/cli/commands/typecheck.ts +18 -0
  23. package/cli/compiler/client/identite.ts +80 -53
  24. package/cli/compiler/client/index.ts +139 -213
  25. package/cli/compiler/common/bundleAnalysis.ts +94 -0
  26. package/cli/compiler/common/clientManifest.ts +67 -0
  27. package/cli/compiler/common/controllers.ts +288 -0
  28. package/cli/compiler/common/files/autres.ts +7 -18
  29. package/cli/compiler/common/files/images.ts +40 -37
  30. package/cli/compiler/common/files/style.ts +11 -22
  31. package/cli/compiler/common/generatedRouteModules.ts +368 -0
  32. package/cli/compiler/common/index.ts +31 -65
  33. package/cli/compiler/common/loaders/forbid-ssr-import.js +13 -0
  34. package/cli/compiler/common/rspackAliases.ts +13 -0
  35. package/cli/compiler/common/scripts.ts +37 -0
  36. package/cli/compiler/index.ts +781 -230
  37. package/cli/compiler/server/index.ts +59 -75
  38. package/cli/compiler/writeIfChanged.ts +21 -0
  39. package/cli/index.ts +71 -72
  40. package/cli/paths.ts +51 -57
  41. package/cli/print.ts +17 -11
  42. package/cli/tsconfig.json +5 -4
  43. package/cli/utils/agents.ts +100 -0
  44. package/cli/utils/check.ts +71 -0
  45. package/cli/utils/index.ts +1 -3
  46. package/cli/utils/keyboard.ts +8 -25
  47. package/cli/utils/runProcess.ts +30 -0
  48. package/client/app/component.tsx +29 -29
  49. package/client/app/index.ts +36 -57
  50. package/client/app/service.ts +7 -12
  51. package/client/app.tsconfig.json +2 -2
  52. package/client/components/Dialog/Manager.ssr.tsx +40 -0
  53. package/client/components/Dialog/Manager.tsx +119 -150
  54. package/client/components/Dialog/status.tsx +3 -3
  55. package/client/components/index.ts +1 -1
  56. package/client/components/types.d.ts +1 -3
  57. package/client/dev/hmr.ts +65 -0
  58. package/client/global.d.ts +2 -2
  59. package/client/hooks.ts +6 -9
  60. package/client/index.ts +2 -1
  61. package/client/islands/index.ts +7 -0
  62. package/client/islands/useDeferredModule.ts +199 -0
  63. package/client/pages/_layout/index.tsx +4 -12
  64. package/client/pages/useHeader.tsx +14 -21
  65. package/client/router.ts +27 -0
  66. package/client/services/router/components/Link.tsx +34 -27
  67. package/client/services/router/components/Page.tsx +6 -14
  68. package/client/services/router/components/router.ssr.tsx +36 -0
  69. package/client/services/router/components/router.tsx +63 -83
  70. package/client/services/router/index.tsx +185 -220
  71. package/client/services/router/request/api.ts +97 -119
  72. package/client/services/router/request/history.ts +2 -2
  73. package/client/services/router/request/index.ts +13 -12
  74. package/client/services/router/request/multipart.ts +72 -62
  75. package/client/services/router/response/index.tsx +68 -61
  76. package/client/services/router/response/page.ts +28 -32
  77. package/client/utils/dom.ts +17 -33
  78. package/common/app/index.ts +3 -3
  79. package/common/data/chaines/index.ts +22 -23
  80. package/common/data/dates.ts +35 -70
  81. package/common/data/markdown.ts +42 -39
  82. package/common/dev/serverHotReload.ts +26 -0
  83. package/common/errors/index.tsx +110 -142
  84. package/common/router/contracts.ts +29 -0
  85. package/common/router/index.ts +89 -108
  86. package/common/router/layouts.ts +34 -47
  87. package/common/router/pageSetup.ts +50 -0
  88. package/common/router/register.ts +53 -24
  89. package/common/router/request/api.ts +30 -36
  90. package/common/router/request/index.ts +2 -8
  91. package/common/router/response/index.ts +8 -15
  92. package/common/router/response/page.ts +70 -58
  93. package/common/utils.ts +1 -1
  94. package/doc/TODO.md +1 -1
  95. package/eslint.js +62 -0
  96. package/package.json +14 -49
  97. package/prettier.config.cjs +9 -0
  98. package/scripts/cleanup-generated-controllers.ts +62 -0
  99. package/scripts/fix-reference-app-typing.ts +490 -0
  100. package/scripts/refactor-client-app-imports.ts +244 -0
  101. package/scripts/refactor-client-pages.ts +587 -0
  102. package/scripts/refactor-server-controllers.ts +470 -0
  103. package/scripts/refactor-server-runtime-aliases.ts +360 -0
  104. package/scripts/restore-client-app-import-files.ts +41 -0
  105. package/scripts/restore-files-from-git-head.ts +20 -0
  106. package/scripts/update-codex-agents.ts +35 -0
  107. package/server/app/commands.ts +35 -64
  108. package/server/app/container/config.ts +48 -59
  109. package/server/app/container/console/index.ts +202 -248
  110. package/server/app/container/index.ts +33 -71
  111. package/server/app/controller/index.ts +61 -0
  112. package/server/app/index.ts +39 -105
  113. package/server/app/service/container.ts +41 -42
  114. package/server/app/service/index.ts +120 -147
  115. package/server/context.ts +1 -1
  116. package/server/index.ts +25 -1
  117. package/server/services/auth/index.ts +75 -115
  118. package/server/services/auth/router/index.ts +31 -32
  119. package/server/services/auth/router/request.ts +14 -16
  120. package/server/services/cron/CronTask.ts +13 -26
  121. package/server/services/cron/index.ts +14 -36
  122. package/server/services/disks/driver.ts +40 -58
  123. package/server/services/disks/drivers/local/index.ts +79 -90
  124. package/server/services/disks/drivers/s3/index.ts +116 -163
  125. package/server/services/disks/index.ts +23 -38
  126. package/server/services/email/index.ts +45 -104
  127. package/server/services/email/utils.ts +14 -27
  128. package/server/services/fetch/index.ts +53 -85
  129. package/server/services/prisma/Facet.ts +39 -91
  130. package/server/services/prisma/index.ts +74 -110
  131. package/server/services/router/generatedRuntime.ts +29 -0
  132. package/server/services/router/http/index.ts +78 -73
  133. package/server/services/router/http/multipart.ts +19 -42
  134. package/server/services/router/index.ts +378 -365
  135. package/server/services/router/request/api.ts +26 -25
  136. package/server/services/router/request/index.ts +44 -51
  137. package/server/services/router/request/service.ts +7 -11
  138. package/server/services/router/request/validation/zod.ts +111 -148
  139. package/server/services/router/response/index.ts +110 -125
  140. package/server/services/router/response/mask/Filter.ts +31 -72
  141. package/server/services/router/response/mask/index.ts +8 -15
  142. package/server/services/router/response/mask/selecteurs.ts +11 -25
  143. package/server/services/router/response/page/clientManifest.ts +25 -0
  144. package/server/services/router/response/page/document.tsx +199 -127
  145. package/server/services/router/response/page/index.tsx +89 -94
  146. package/server/services/router/service.ts +13 -15
  147. package/server/services/schema/index.ts +17 -26
  148. package/server/services/schema/request.ts +19 -33
  149. package/server/services/schema/router/index.ts +8 -11
  150. package/server/services/security/encrypt/aes/index.ts +15 -35
  151. package/server/utils/slug.ts +29 -35
  152. package/skills/clean-project-code/SKILL.md +63 -0
  153. package/skills/clean-project-code/agents/openai.yaml +4 -0
  154. package/tsconfig.common.json +4 -3
  155. package/tsconfig.json +4 -1
  156. package/types/aliases.d.ts +17 -21
  157. package/types/controller-input.test.ts +48 -0
  158. package/types/express-extra.d.ts +6 -0
  159. package/types/global/constants.d.ts +13 -0
  160. package/types/global/express-extra.d.ts +6 -0
  161. package/types/global/modules.d.ts +13 -16
  162. package/types/global/utils.d.ts +17 -49
  163. package/types/global/vendors.d.ts +62 -0
  164. package/types/icons.d.ts +65 -1
  165. package/types/uuid.d.ts +3 -0
  166. package/types/vendors.d.ts +62 -0
  167. package/cli/compiler/common/babel/index.ts +0 -170
  168. package/cli/compiler/common/babel/plugins/index.ts +0 -0
  169. package/cli/compiler/common/babel/plugins/services.ts +0 -586
  170. package/cli/compiler/common/babel/routes/imports.ts +0 -127
  171. package/cli/compiler/common/babel/routes/routes.ts +0 -1130
  172. package/client/services/captcha/index.ts +0 -67
  173. package/client/services/socket/index.ts +0 -147
  174. package/common/data/rte/nodes.ts +0 -83
  175. package/common/data/stats.ts +0 -90
  176. package/common/utils/rte.ts +0 -183
  177. package/server/services/auth/old.ts +0 -277
  178. package/server/services/cache/commands.ts +0 -41
  179. package/server/services/cache/index.ts +0 -297
  180. package/server/services/cache/service.json +0 -6
  181. package/server/services/socket/index.ts +0 -162
  182. package/server/services/socket/scope.ts +0 -226
  183. package/server/services/socket/service.json +0 -6
  184. package/server/services_old/SocketClient.ts +0 -92
  185. package/server/services_old/Token.old.ts +0 -97
@@ -12,17 +12,14 @@ import path from 'path';
12
12
  import AWS from 'aws-sdk';
13
13
  import dayjs from 'dayjs';
14
14
 
15
- // Core
16
- import type { Application } from '@server/app';
17
- import type { TServiceArgs } from '@server/app/service';
18
-
19
15
  // Specific
20
- import DiskDriver, {
21
- TDrivercnfig,
22
- SourceFile,
16
+ import DiskDriver, {
17
+ TDrivercnfig,
18
+ SourceFile,
23
19
  TOutputFileOptions,
24
- TReadFileOptions
20
+ TReadFileOptions,
25
21
  } from '@server/services/disks/driver';
22
+ import type { TSetupConfig } from '@server/app/service';
26
23
 
27
24
  /*----------------------------------
28
25
  - CONFIG
@@ -34,268 +31,224 @@ const debug = false;
34
31
  - TYPES
35
32
  ----------------------------------*/
36
33
 
37
- export type TConfig = TDrivercnfig & {
38
- accessKeyId: string,
39
- secretAccessKey: string,
40
- region: string,
41
- }
34
+ export type TConfig = TDrivercnfig & { accessKeyId: string; secretAccessKey: string; region: string };
42
35
 
43
36
  /*----------------------------------
44
37
  - SERVICE
45
38
  ----------------------------------*/
46
39
  export default class S3Driver<
47
40
  Config extends TConfig = TConfig,
48
- TBucketName = keyof Config["buckets"]
49
- > extends DiskDriver<TConfig> {
50
-
51
- public s3: AWS.S3;
41
+ TBucketName extends Extract<keyof Config['buckets'], string> = Extract<keyof Config['buckets'], string>,
42
+ > extends DiskDriver<Config, TBucketName> {
43
+ public s3: AWS.S3;
52
44
 
53
- public constructor( config: TConfig, app: Application ) {
45
+ private getBucketName(bucketName: TBucketName) {
46
+ const bucket = this.config.buckets[bucketName];
47
+ if (bucket === undefined) throw new Error(`Bucket "${bucketName}" not found in configuration`);
48
+ return bucket;
49
+ }
54
50
 
51
+ public constructor(config: TSetupConfig<Config>, app: DiskDriver<Config, TBucketName>['app']) {
55
52
  super(config, app);
56
53
 
57
- AWS.config.update({
58
- accessKeyId: this.config.accessKeyId,
59
- secretAccessKey: this.config.secretAccessKey,
60
- });
54
+ AWS.config.update({ accessKeyId: this.config.accessKeyId, secretAccessKey: this.config.secretAccessKey });
61
55
 
62
- this.s3 = new AWS.S3();
56
+ this.s3 = new AWS.S3();
63
57
  }
64
58
 
65
- /*----------------------------------
59
+ /*----------------------------------
66
60
  - DISK LIFECYCLE
67
61
  ----------------------------------*/
68
62
 
69
- public async mount() {
70
-
71
- }
63
+ public async mount() {}
72
64
 
73
- public async unmount() {
74
-
75
- }
65
+ public async unmount() {}
76
66
 
77
67
  /*----------------------------------
78
68
  - ACTIONS
79
69
  ----------------------------------*/
80
70
 
81
- public getFileUrl(
82
- bucketName: TBucketName,
83
- filename: string
84
- ) {
85
-
86
- const bucket = this.config.buckets[bucketName];
87
- if (bucket === undefined)
88
- throw new Error(`Bucket "${bucketName}" not found in configuration`);
89
- return `https://${bucket}.s3.${this.config.region}.amazonaws.com/${filename}`
71
+ public getFileUrl(bucketName: TBucketName, filename: string) {
72
+ const bucket = this.getBucketName(bucketName);
73
+ return `https://${bucket}.s3.${this.config.region}.amazonaws.com/${filename}`;
90
74
  }
91
75
 
92
- public readDir( bucketName: TBucketName, dirname?: string ) {
93
- const bucket = this.config.buckets[bucketName];
76
+ public readDir(bucketName: TBucketName, dirname?: string) {
77
+ const bucket = this.getBucketName(bucketName);
94
78
  return new Promise<SourceFile[]>((resolve, reject) => {
95
- debug && console.log(`readDir ` + (dirname === undefined ? bucket : path.join( bucket, dirname )));
79
+ debug && console.log(`readDir ` + (dirname === undefined ? bucket : path.join(bucket, dirname)));
96
80
  this.s3.listObjectsV2({ Bucket: bucket }, async (err, data) => {
97
-
98
81
  if (err) return reject(err);
99
82
 
100
83
  const files: SourceFile[] = [];
101
- for (const file of data.Contents) {
102
-
84
+ for (const file of data.Contents || []) {
85
+ if (!file.Key) continue;
86
+
103
87
  const [source, ...hierarchy] = file.Key.split('/');
104
- if (hierarchy.length > 1) // Take only direct childs
88
+ if (hierarchy.length > 1)
89
+ // Take only direct childs
105
90
  continue;
106
91
 
107
92
  const filename = hierarchy.join('/');
108
- if (!filename.endsWith('.csv'))
109
- continue;
93
+ if (!filename.endsWith('.csv')) continue;
110
94
 
111
95
  debug && console.log('-', file.Key);
112
96
 
113
- const fileContent = await this.readFile( bucketName, file.Key );
114
- const rowsCount = (fileContent as unknown as string).split('\n').length - 1;
97
+ const fileContent = await this.readFile(bucketName, file.Key, { encoding: 'string' });
98
+ const rowsCount = String(fileContent).split('\n').length - 1;
115
99
 
116
- const name = dayjs(file.LastModified).format('DD/MM HH:mm:ss')
117
- + ' : ' + path.join( source, filename )
118
- + ' : ' + rowsCount + ' contacts'
100
+ const name =
101
+ dayjs(file.LastModified).format('DD/MM HH:mm:ss') +
102
+ ' : ' +
103
+ path.join(source, filename) +
104
+ ' : ' +
105
+ rowsCount +
106
+ ' contacts';
119
107
 
120
108
  files.push({
121
109
  name,
122
110
  path: file.Key,
123
111
  source: source,
124
- modified: file.LastModified,
125
- parentFolder: source
112
+ modified: file.LastModified?.getTime() || 0,
113
+ parentFolder: source,
126
114
  });
127
-
128
115
  }
129
-
116
+
130
117
  debug && console.log(`readDir ${bucket}/${dirname || ''}: ${files.length} objects`);
131
118
  resolve(files);
132
119
  });
133
120
  });
134
121
  }
135
122
 
136
- public readFile(
137
- bucketName: TBucketName,
138
- filename: string,
139
- options: TReadFileOptions = {}
140
- ) {
141
- const bucket = this.config.buckets[bucketName];
123
+ public readFile(bucketName: TBucketName, filename: string, options: TReadFileOptions = {}) {
124
+ const bucket = this.getBucketName(bucketName);
142
125
  debug && console.log(`readFile ${bucket}/${filename}`);
143
- return new Promise<string>(( resolve, reject ) => {
144
- this.s3.getObject({
145
- Bucket: bucket,
146
- Key: filename
147
- }, (err, data) => {
148
-
126
+ return new Promise<Buffer | string>((resolve, reject) => {
127
+ this.s3.getObject({ Bucket: bucket, Key: filename }, (err, data) => {
149
128
  if (err) return reject(err);
150
129
 
151
130
  let body: any;
152
131
  switch (options.encoding) {
153
132
  case 'string':
154
- body = data.Body?.toString()
133
+ body = data.Body?.toString();
155
134
  break;
156
135
  default:
157
136
  body = data.Body;
158
137
  break;
159
138
  }
160
139
 
161
- resolve( body );
140
+ resolve(body);
162
141
  });
163
- })
142
+ });
164
143
  }
165
144
 
166
- public createReadStream( bucketName: TBucketName, filename: string ) {
167
- const bucket = this.config.buckets[bucketName];
145
+ public createReadStream(bucketName: TBucketName, filename: string) {
146
+ const bucket = this.getBucketName(bucketName);
168
147
  debug && console.log(`createReadStream ${bucket}/${filename}`);
169
- return this.s3.getObject({
170
- Bucket: bucket,
171
- Key: filename
172
- }).createReadStream();
148
+ return this.s3.getObject({ Bucket: bucket, Key: filename }).createReadStream();
173
149
  }
174
150
 
175
- public exists( bucketName: TBucketName, filename: string ) {
176
- const bucket = this.config.buckets[bucketName];
151
+ public exists(bucketName: TBucketName, filename: string) {
152
+ const bucket = this.getBucketName(bucketName);
177
153
  debug && console.log(`exists`, path.join(bucket, filename));
178
- return new Promise<boolean>(( resolve, reject ) => {
179
- this.s3.headObject({
180
- Bucket: bucket,
181
- Key: filename
182
- }, (err, metadata) => {
183
-
184
- if (!err)
185
- resolve(true);
186
- else if (err.name === 'NotFound')
187
- resolve(false);
188
- else
189
- reject(err);
154
+ return new Promise<boolean>((resolve, reject) => {
155
+ this.s3.headObject({ Bucket: bucket, Key: filename }, (err, metadata) => {
156
+ if (!err) resolve(true);
157
+ else if (err.name === 'NotFound') resolve(false);
158
+ else reject(err);
190
159
  });
191
- })
160
+ });
192
161
  }
193
162
 
194
- public async move( bucketName: TBucketName, source: string, destination: string, options: { overwrite?: boolean } = {}) {
195
- const bucket = this.config.buckets[bucketName];
163
+ public async move(
164
+ bucketName: TBucketName,
165
+ source: string,
166
+ destination: string,
167
+ options: { overwrite?: boolean } = {},
168
+ ) {
169
+ const bucket = this.getBucketName(bucketName);
196
170
  debug && console.log(`move ${bucket}/${source} to ${bucket}/${destination}`);
197
171
 
198
- if (options.overwrite)
199
- await this.s3.deleteObject({
200
- Bucket: bucket,
201
- Key: destination,
202
- }).promise();
203
-
204
- await this.s3.copyObject({
205
- Bucket: bucket,
206
- CopySource: source,
207
- Key: destination
208
- }).promise();
172
+ if (options.overwrite) await this.s3.deleteObject({ Bucket: bucket, Key: destination }).promise();
209
173
 
210
- debug && console.log(`Move ${bucket}/${source} to ${bucket}/${destination}: OK`);
174
+ await this.s3.copyObject({ Bucket: bucket, CopySource: source, Key: destination }).promise();
211
175
 
176
+ debug && console.log(`Move ${bucket}/${source} to ${bucket}/${destination}: OK`);
212
177
  }
213
178
 
214
- public outputFile(
215
- bucketName: TBucketName,
216
- filename: string,
217
- content: string | Buffer,
218
- options?: TOutputFileOptions
179
+ public outputFile(
180
+ bucketName: TBucketName,
181
+ filename: string,
182
+ content: string | Buffer,
183
+ options?: TOutputFileOptions,
219
184
  ) {
220
- const bucket = this.config.buckets[bucketName];
185
+ const bucket = this.getBucketName(bucketName);
221
186
  debug && console.log(`outputFile ${bucket}/${filename}`);
222
- return new Promise(( resolve, reject ) => {
223
- this.s3.upload({
224
- Bucket: bucket,
225
- Key: filename,
226
- Body: content,
227
- }, (err, data) => {
228
-
229
- if (err) return reject(err);
230
- debug && console.log(`outputFile ${bucket}/${filename}: OK (${data.Location})`);
231
-
232
- resolve({
233
- path: data.Location
234
- });
235
- });
236
- })
187
+ return new Promise<{ path: string }>((resolve, reject) => {
188
+ this.s3.upload(
189
+ { Bucket: bucket, Key: filename, Body: content },
190
+ (err: Error | null, data: AWS.S3.ManagedUpload.SendData) => {
191
+ if (err) return reject(err);
192
+ debug && console.log(`outputFile ${bucket}/${filename}: OK (${data.Location})`);
193
+
194
+ resolve({ path: data.Location || `s3://${bucket}/${filename}` });
195
+ },
196
+ );
197
+ });
237
198
  }
238
199
 
239
- public async readJSON( bucketName: TBucketName, filename: string ) {
240
- const bucket = this.config.buckets[bucketName];
200
+ public async readJSON(bucketName: TBucketName, filename: string) {
201
+ const bucket = this.getBucketName(bucketName);
241
202
  debug && console.log(`readJSON ${bucket}/${filename}`);
242
203
  const filecontent = await this.readFile(bucketName, filename);
243
204
  try {
244
205
  debug && console.log(`readJSON: ${bucket}/${filename} : PARSE JSON`);
245
- return JSON.parse(filecontent);
206
+ return JSON.parse(String(filecontent));
246
207
  } catch (error) {
247
208
  console.error(`Failed to parse file "${filename}" as JSON: `, error);
248
209
  throw new Error(`Failed to parse file "${filename}" as JSON: ` + error);
249
210
  }
250
211
  }
251
212
 
252
- public delete( bucketName: TBucketName, filename: string ) {
253
- const bucket = this.config.buckets[bucketName];
213
+ public delete(bucketName: TBucketName, filename: string) {
214
+ const bucket = this.getBucketName(bucketName);
254
215
  debug && console.log(`delete ${bucket}/${filename}`);
255
- return new Promise<boolean>(( resolve, reject ) => {
256
- this.s3.deleteObject({
257
- Bucket: bucket,
258
- Key: filename
259
- }, (err, metadata) => {
260
-
261
- if (!err)
262
- resolve(true);
263
- else if (err.name === 'NotFound')
264
- resolve(false);
265
- else
266
- reject(err);
216
+ return new Promise<boolean>((resolve, reject) => {
217
+ this.s3.deleteObject({ Bucket: bucket, Key: filename }, (err, metadata) => {
218
+ if (!err) resolve(true);
219
+ else if (err.name === 'NotFound') resolve(false);
220
+ else reject(err);
267
221
  });
268
- })
222
+ });
269
223
  }
270
224
 
271
- public async deleteDir( bucketName: TBucketName, directoryPath: string ) {
272
- const bucket = this.config.buckets[bucketName];
225
+ public async deleteDir(bucketName: TBucketName, directoryPath: string) {
226
+ const bucket = this.getBucketName(bucketName);
273
227
  debug && console.log(`delete ${bucket}/${directoryPath}`);
274
228
  try {
275
229
  // Liste des objets dans le répertoire
276
- const listedObjects = await this.s3.listObjectsV2({
277
- Bucket: bucket,
278
- Prefix: directoryPath
279
- }).promise();
230
+ const listedObjects = await this.s3.listObjectsV2({ Bucket: bucket, Prefix: directoryPath }).promise();
280
231
 
281
- if (!listedObjects.Contents?.length) return;
232
+ if (!listedObjects.Contents?.length) return false;
282
233
 
283
234
  // Supprimer les objets
284
- await this.s3.deleteObjects({
285
- Bucket: bucket,
286
- Delete: {
287
- Objects: listedObjects.Contents.map(({ Key }) => ({ Key }))
288
- }
289
- }).promise();
235
+ await this.s3
236
+ .deleteObjects({
237
+ Bucket: bucket,
238
+ Delete: {
239
+ Objects: listedObjects.Contents.flatMap(({ Key }) => (Key ? [{ Key }] : [])),
240
+ },
241
+ })
242
+ .promise();
290
243
 
291
244
  // Récursivement, traiter d'autres pages d'objets si elles existent
292
245
  //if (listedObjects.IsTruncated) await deleteDirectory();
293
246
 
294
247
  console.log(`Le répertoire ${directoryPath} a été supprimé.`);
295
-
248
+ return true;
296
249
  } catch (error) {
297
- console.error("Erreur lors de la suppression :", error);
250
+ console.error('Erreur lors de la suppression :', error);
251
+ throw error;
298
252
  }
299
253
  }
300
-
301
- }
254
+ }
@@ -3,7 +3,7 @@
3
3
  ----------------------------------*/
4
4
 
5
5
  // Core
6
- import type { Application } from '@server/app';
6
+ import type { Application } from '@server/app/index';
7
7
  import Service, { AnyService, TRegisteredServicesIndex, TServiceArgs } from '@server/app/service';
8
8
 
9
9
  // Specific
@@ -15,76 +15,61 @@ export type { default as Driver } from './driver';
15
15
  ----------------------------------*/
16
16
 
17
17
  type Config = {
18
- debug: boolean,
19
- default: string,//keyof MountpointList,
20
- drivers: {
21
- [driverId: string]: Driver
22
- }
23
- }
18
+ debug: boolean;
19
+ default: string; //keyof MountpointList,
20
+ drivers: { [driverId: string]: Driver };
21
+ };
24
22
 
25
- export type Hooks = {
23
+ export type Hooks = {};
26
24
 
27
- }
28
-
29
- export type Services = {
30
- [diskId: string]: Driver
31
- }
25
+ export type Services = { [diskId: string]: Driver };
32
26
 
33
27
  /*----------------------------------
34
28
  - SERVICE
35
29
  ----------------------------------*/
36
30
  export default class DisksManager<
37
31
  MountpointList extends Services,
38
- TConfig extends Config,
39
- TApplication extends Application
32
+ TConfig extends Config & { default: keyof MountpointList & string; drivers: MountpointList },
33
+ TApplication extends Application,
40
34
  > extends Service<TConfig, Hooks, TApplication, TApplication> {
41
-
42
- public default!: Driver;
35
+ public default!: MountpointList[keyof MountpointList & string];
43
36
 
44
37
  /*----------------------------------
45
38
  - LIFECYCLE
46
39
  ----------------------------------*/
47
40
 
48
- public constructor( ...args: TServiceArgs<DisksManager<MountpointList, TConfig, TApplication>>) {
49
-
41
+ public constructor(...args: TServiceArgs<DisksManager<MountpointList, TConfig, TApplication>>) {
50
42
  super(...args);
51
43
 
52
44
  const drivers = this.config.drivers;
53
-
54
- if (Object.keys( drivers ).length === 0)
55
- throw new Error("At least one disk driver should be mounted.");
45
+
46
+ if (Object.keys(drivers).length === 0) throw new Error('At least one disk driver should be mounted.');
56
47
 
57
48
  // Bind current instance of the service as parent
58
49
  /*for (const driverId in drivers) {
59
50
  drivers[driverId].parent = this;
60
51
  }*/
61
52
 
62
- const defaultDisk = drivers[ this.config.default ];
63
- if (defaultDisk === undefined)
64
- console.log(`Default disk "${this.config.default as string}" not mounted.`);
53
+ const defaultDisk = drivers[this.config.default];
54
+ if (defaultDisk === undefined) console.log(`Default disk "${this.config.default as string}" not mounted.`);
65
55
 
66
56
  this.default = defaultDisk;
67
-
68
57
  }
69
58
 
70
- public async shutdown() {
71
-
72
- }
59
+ public async shutdown() {}
73
60
 
74
61
  /*----------------------------------
75
62
  - LIFECYCLE
76
63
  ----------------------------------*/
77
64
 
78
- public get( diskName?: 'default' | keyof MountpointList ): Driver {
65
+ public get(diskName?: 'default' | keyof MountpointList) {
66
+ const disk =
67
+ diskName === 'default' || diskName === undefined
68
+ ? this.default
69
+ : this.config.drivers[diskName as keyof MountpointList];
79
70
 
80
- const disk = diskName == 'default' || diskName === undefined
81
- ? this.default
82
- : this.config.drivers[diskName];
83
-
84
- if (disk === undefined)
85
- throw new Error(`Disk "${diskName as string}" not found.`);
71
+ if (disk === undefined) throw new Error(`Disk "${diskName as string}" not found.`);
86
72
 
87
73
  return disk;
88
74
  }
89
-
90
- }
75
+ }