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
|
@@ -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 from '@server/app/service';
|
|
8
8
|
import { NotFound } from '@common/errors';
|
|
9
9
|
import context from '@server/context';
|
|
@@ -20,25 +20,18 @@ export { default as CronTask } from './CronTask';
|
|
|
20
20
|
- SERVICE CONFIG
|
|
21
21
|
----------------------------------*/
|
|
22
22
|
|
|
23
|
-
export type Config = {
|
|
24
|
-
debug?: boolean
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type Hooks = {
|
|
28
|
-
|
|
29
|
-
}
|
|
23
|
+
export type Config = { debug?: boolean };
|
|
30
24
|
|
|
31
|
-
export type
|
|
25
|
+
export type Hooks = {};
|
|
32
26
|
|
|
33
|
-
}
|
|
27
|
+
export type Services = {};
|
|
34
28
|
|
|
35
29
|
/*----------------------------------
|
|
36
30
|
- CLASSE
|
|
37
31
|
----------------------------------*/
|
|
38
32
|
|
|
39
33
|
export default class CronManager extends Service<Config, Hooks, Application, Application> {
|
|
40
|
-
|
|
41
|
-
public static taches: { [nom: string]: CronTask } = {}
|
|
34
|
+
public static taches: { [nom: string]: CronTask } = {};
|
|
42
35
|
public static timer: NodeJS.Timeout;
|
|
43
36
|
|
|
44
37
|
/*----------------------------------
|
|
@@ -46,15 +39,10 @@ export default class CronManager extends Service<Config, Hooks, Application, App
|
|
|
46
39
|
----------------------------------*/
|
|
47
40
|
|
|
48
41
|
public async ready() {
|
|
49
|
-
|
|
50
42
|
clearInterval(CronManager.timer);
|
|
51
43
|
CronManager.timer = setInterval(() => {
|
|
52
|
-
|
|
53
|
-
for (const id in CronManager.taches)
|
|
54
|
-
CronManager.taches[id].run();
|
|
55
|
-
|
|
44
|
+
for (const id in CronManager.taches) CronManager.taches[id].run();
|
|
56
45
|
}, 10000);
|
|
57
|
-
|
|
58
46
|
}
|
|
59
47
|
|
|
60
48
|
/*----------------------------------
|
|
@@ -67,46 +55,36 @@ export default class CronManager extends Service<Config, Hooks, Application, App
|
|
|
67
55
|
* @param frequence When to execute this task.
|
|
68
56
|
* - Date: The date at which to execute this task (one time execution)
|
|
69
57
|
* - string: Cron expression to define the interval for executing this task
|
|
70
|
-
* @param run Function to run
|
|
58
|
+
* @param run Function to run
|
|
71
59
|
* @param autoexec true to execute the task immediatly
|
|
72
60
|
* @returns The CronTask that just have been created
|
|
73
61
|
*/
|
|
74
62
|
public task(nom: string, frequence: TFrequence, run: TRunner, autoexec?: boolean) {
|
|
75
63
|
return new Promise<CronTask>((resolve, reject) => {
|
|
76
64
|
context.run({ channelType: 'cron', channelId: nom }, async () => {
|
|
77
|
-
|
|
78
65
|
CronManager.taches[nom] = new CronTask(this, nom, frequence, run, autoexec);
|
|
79
66
|
|
|
80
|
-
if (autoexec)
|
|
81
|
-
await CronManager.taches[nom].run(true);
|
|
67
|
+
if (autoexec) await CronManager.taches[nom].run(true);
|
|
82
68
|
|
|
83
|
-
resolve(
|
|
84
|
-
|
|
85
|
-
})
|
|
69
|
+
resolve(CronManager.taches[nom]);
|
|
70
|
+
});
|
|
86
71
|
});
|
|
87
|
-
|
|
88
72
|
}
|
|
89
73
|
|
|
90
74
|
public async exec(nom: string) {
|
|
91
|
-
|
|
92
75
|
const tache = CronManager.taches[nom];
|
|
93
76
|
|
|
94
|
-
if (tache === undefined)
|
|
95
|
-
throw new NotFound("Tâche NotFound: " + nom);
|
|
77
|
+
if (tache === undefined) throw new NotFound('Tâche NotFound: ' + nom);
|
|
96
78
|
|
|
97
79
|
await tache.run(true);
|
|
98
|
-
|
|
99
80
|
}
|
|
100
81
|
public get(): typeof CronManager.taches;
|
|
101
82
|
public get(name: string): CronTask;
|
|
102
83
|
public get(name?: string): CronTask | typeof CronManager.taches {
|
|
103
|
-
|
|
104
|
-
if (name === undefined)
|
|
105
|
-
return CronManager.taches;
|
|
84
|
+
if (name === undefined) return CronManager.taches;
|
|
106
85
|
|
|
107
86
|
const cron = CronManager.taches[name];
|
|
108
|
-
if (cron === undefined)
|
|
109
|
-
throw new Error(`L'instance de la tâche cron ${name} n'a pas été trouvée`);
|
|
87
|
+
if (cron === undefined) throw new Error(`L'instance de la tâche cron ${name} n'a pas été trouvée`);
|
|
110
88
|
return cron;
|
|
111
89
|
}
|
|
112
|
-
}
|
|
90
|
+
}
|
|
@@ -3,51 +3,35 @@
|
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
5
|
// Core
|
|
6
|
-
import type { Application } from '@server/app';
|
|
7
|
-
import Service from '@server/app/service';
|
|
6
|
+
import type { Application } from '@server/app/index';
|
|
7
|
+
import Service, { TSetupConfig } from '@server/app/service';
|
|
8
8
|
|
|
9
9
|
/*----------------------------------
|
|
10
10
|
- CONFIG
|
|
11
11
|
----------------------------------*/
|
|
12
12
|
|
|
13
|
-
export type THooks = {
|
|
13
|
+
export type THooks = {};
|
|
14
14
|
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type Services = {
|
|
18
|
-
|
|
19
|
-
}
|
|
15
|
+
export type Services = {};
|
|
20
16
|
|
|
21
17
|
/*----------------------------------
|
|
22
18
|
- TYPE
|
|
23
19
|
----------------------------------*/
|
|
24
20
|
|
|
25
21
|
export type TDrivercnfig = {
|
|
22
|
+
debug: boolean;
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
rootDir: string;
|
|
25
|
+
buckets: { [id: string]: string };
|
|
26
|
+
};
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
buckets: {
|
|
31
|
-
[id: string]: string
|
|
32
|
-
}
|
|
33
|
-
}
|
|
28
|
+
export type SourceFile = { name: string; path: string; modified: number; parentFolder: string; source: string };
|
|
34
29
|
|
|
35
|
-
export type
|
|
36
|
-
name: string,
|
|
37
|
-
path: string,
|
|
38
|
-
modified: number,
|
|
39
|
-
parentFolder: string,
|
|
40
|
-
source: string
|
|
41
|
-
}
|
|
30
|
+
export type TOutputFileOptions = { encoding: string };
|
|
42
31
|
|
|
43
|
-
export type
|
|
44
|
-
encoding: string
|
|
45
|
-
}
|
|
32
|
+
export type TReadFileOptions = { encoding?: 'string' | 'buffer'; withMetas?: boolean };
|
|
46
33
|
|
|
47
|
-
|
|
48
|
-
encoding?: 'string'|'buffer',
|
|
49
|
-
withMetas?: boolean
|
|
50
|
-
}
|
|
34
|
+
type TBucketNameFromConfig<TConfig extends TDrivercnfig> = Extract<keyof TConfig['buckets'], string>;
|
|
51
35
|
|
|
52
36
|
/*----------------------------------
|
|
53
37
|
- CLASS
|
|
@@ -55,49 +39,47 @@ export type TReadFileOptions = {
|
|
|
55
39
|
|
|
56
40
|
export default abstract class FsDriver<
|
|
57
41
|
Config extends TDrivercnfig = TDrivercnfig,
|
|
58
|
-
TBucketName =
|
|
42
|
+
TBucketName extends TBucketNameFromConfig<Config> = TBucketNameFromConfig<Config>,
|
|
59
43
|
> extends Service<Config, {}, Application, Application> {
|
|
60
|
-
|
|
61
|
-
public constructor( config: Config, app: Application ) {
|
|
44
|
+
public constructor(config: TSetupConfig<Config>, app: Application) {
|
|
62
45
|
super(app, config, app);
|
|
63
46
|
}
|
|
64
47
|
|
|
65
48
|
public abstract mount(): Promise<void>;
|
|
66
49
|
|
|
67
|
-
public abstract getFileUrl(
|
|
68
|
-
bucketName: TBucketName,
|
|
69
|
-
filename: string
|
|
70
|
-
): string;
|
|
71
|
-
|
|
72
|
-
public abstract readDir( bucketName: TBucketName, dirname?: string ): Promise<SourceFile[]>;
|
|
50
|
+
public abstract getFileUrl(bucketName: TBucketName, filename: string): string;
|
|
73
51
|
|
|
74
|
-
public abstract
|
|
75
|
-
bucketName: TBucketName,
|
|
76
|
-
filename: string,
|
|
77
|
-
options: TReadFileOptions
|
|
78
|
-
): Promise<Buffer>;
|
|
52
|
+
public abstract readDir(bucketName: TBucketName, dirname?: string): Promise<SourceFile[]>;
|
|
79
53
|
|
|
80
|
-
public abstract
|
|
54
|
+
public abstract readFile(
|
|
55
|
+
bucketName: TBucketName,
|
|
56
|
+
filename: string,
|
|
57
|
+
options?: TReadFileOptions,
|
|
58
|
+
): Promise<Buffer | string>;
|
|
81
59
|
|
|
82
|
-
public abstract
|
|
60
|
+
public abstract createReadStream(bucketName: TBucketName, filename: string): unknown;
|
|
83
61
|
|
|
84
|
-
public abstract
|
|
62
|
+
public abstract exists(bucketName: TBucketName, filename: string): Promise<boolean>;
|
|
85
63
|
|
|
86
|
-
public abstract
|
|
87
|
-
bucketName: TBucketName,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
options?:
|
|
91
|
-
): Promise<
|
|
92
|
-
path: string
|
|
93
|
-
}>;
|
|
64
|
+
public abstract move(
|
|
65
|
+
bucketName: TBucketName,
|
|
66
|
+
source: string,
|
|
67
|
+
destination: string,
|
|
68
|
+
options: { overwrite?: boolean },
|
|
69
|
+
): Promise<void>;
|
|
94
70
|
|
|
95
|
-
public abstract
|
|
71
|
+
public abstract outputFile(
|
|
72
|
+
bucketName: TBucketName,
|
|
73
|
+
filename: string,
|
|
74
|
+
content: string | Buffer,
|
|
75
|
+
options?: TOutputFileOptions,
|
|
76
|
+
): Promise<{ path: string }>;
|
|
96
77
|
|
|
97
|
-
public abstract
|
|
78
|
+
public abstract readJSON(bucketName: TBucketName, filename: string): Promise<any>;
|
|
98
79
|
|
|
99
|
-
public abstract
|
|
80
|
+
public abstract delete(bucketName: TBucketName, filename: string): Promise<boolean>;
|
|
100
81
|
|
|
101
|
-
public abstract
|
|
82
|
+
public abstract deleteDir(bucketName: TBucketName, dirname: string): Promise<boolean>;
|
|
102
83
|
|
|
103
|
-
|
|
84
|
+
public abstract unmount(): Promise<void>;
|
|
85
|
+
}
|
|
@@ -16,7 +16,7 @@ import fs from 'fs-extra';
|
|
|
16
16
|
import AppContainer from '@server/app/container';
|
|
17
17
|
|
|
18
18
|
// Specific
|
|
19
|
-
import DiskDriver, { TDrivercnfig, SourceFile, TOutputFileOptions } from '../../driver';
|
|
19
|
+
import DiskDriver, { TDrivercnfig, SourceFile, TOutputFileOptions, TReadFileOptions } from '../../driver';
|
|
20
20
|
|
|
21
21
|
/*----------------------------------
|
|
22
22
|
- CONFIG
|
|
@@ -26,163 +26,152 @@ import DiskDriver, { TDrivercnfig, SourceFile, TOutputFileOptions } from '../../
|
|
|
26
26
|
- TYPES
|
|
27
27
|
----------------------------------*/
|
|
28
28
|
|
|
29
|
-
export type TConfig = TDrivercnfig & {
|
|
30
|
-
|
|
31
|
-
}
|
|
29
|
+
export type TConfig = TDrivercnfig & {};
|
|
32
30
|
|
|
33
31
|
/*----------------------------------
|
|
34
32
|
- SERVICE
|
|
35
33
|
----------------------------------*/
|
|
36
34
|
export default class LocalFS<
|
|
37
35
|
Config extends TConfig = TConfig,
|
|
38
|
-
TBucketName = keyof Config[
|
|
39
|
-
> extends DiskDriver<
|
|
40
|
-
|
|
36
|
+
TBucketName extends Extract<keyof Config['buckets'], string> = Extract<keyof Config['buckets'], string>,
|
|
37
|
+
> extends DiskDriver<Config, TBucketName> {
|
|
41
38
|
public rootDir = AppContainer.path.var;
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
private getBucketDir(bucketName: TBucketName) {
|
|
41
|
+
const bucketDir = this.config.buckets[bucketName];
|
|
42
|
+
if (bucketDir === undefined) throw new Error(`Bucket "${bucketName}" not found in configuration`);
|
|
43
|
+
return bucketDir;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
public async
|
|
46
|
+
public async mount() {}
|
|
48
47
|
|
|
49
|
-
}
|
|
48
|
+
public async unmount() {}
|
|
50
49
|
|
|
51
50
|
/*----------------------------------
|
|
52
51
|
- ACTIONS
|
|
53
52
|
----------------------------------*/
|
|
54
53
|
|
|
55
|
-
public getFileUrl(
|
|
56
|
-
|
|
57
|
-
filename
|
|
58
|
-
) {
|
|
59
|
-
const bucketDir = this.config.buckets[bucketName];
|
|
60
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename || '.' );
|
|
54
|
+
public getFileUrl(bucketName: TBucketName, filename: string) {
|
|
55
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
56
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename || '.');
|
|
61
57
|
return fullPath;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
public async readDir(
|
|
60
|
+
public async readDir(bucketName: TBucketName, dirname?: string) {
|
|
61
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
65
62
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const fullPath = path.join( this.rootDir, bucketDir, dirname || '.' );
|
|
63
|
+
const fullPath = path.join(this.rootDir, bucketDir, dirname || '.');
|
|
69
64
|
|
|
70
65
|
// Combine the files list of all source directory
|
|
71
66
|
const files: SourceFile[] = [];
|
|
72
|
-
const sources = fs.readdirSync(
|
|
67
|
+
const sources = fs.readdirSync(fullPath, { withFileTypes: true });
|
|
73
68
|
for (const source of sources) {
|
|
74
|
-
|
|
75
|
-
if (!source.isDirectory())
|
|
76
|
-
continue;
|
|
69
|
+
if (!source.isDirectory()) continue;
|
|
77
70
|
|
|
78
71
|
const parentFolder = source.name;
|
|
79
|
-
const csvFiles = fs.readdirSync(
|
|
80
|
-
path.join( fullPath, parentFolder ),
|
|
81
|
-
{ withFileTypes: true }
|
|
82
|
-
);
|
|
72
|
+
const csvFiles = fs.readdirSync(path.join(fullPath, parentFolder), { withFileTypes: true });
|
|
83
73
|
|
|
84
74
|
for (const file of csvFiles) {
|
|
75
|
+
if (!file.isFile() || !file.name.endsWith('.csv')) continue;
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const relPath = path.join( source.name, file.name );
|
|
90
|
-
const fullpath = path.join( fullPath, relPath );
|
|
77
|
+
const relPath = path.join(source.name, file.name);
|
|
78
|
+
const fullpath = path.join(fullPath, relPath);
|
|
91
79
|
const stats = fs.statSync(fullpath);
|
|
92
80
|
|
|
93
|
-
const rowsCount = fs.readFileSync(
|
|
81
|
+
const rowsCount = fs.readFileSync(fullpath, 'utf-8').split('\n').length - 1;
|
|
94
82
|
|
|
95
|
-
const name =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
parentFolder,
|
|
103
|
-
source: source.name,
|
|
104
|
-
modified: stats.mtimeMs
|
|
105
|
-
});
|
|
83
|
+
const name =
|
|
84
|
+
dayjs(stats.mtime).format('DD/MM HH:mm:ss') +
|
|
85
|
+
' : ' +
|
|
86
|
+
path.join(source.name, file.name) +
|
|
87
|
+
' : ' +
|
|
88
|
+
rowsCount +
|
|
89
|
+
' contacts';
|
|
106
90
|
|
|
91
|
+
files.push({ name, path: relPath, parentFolder, source: source.name, modified: stats.mtimeMs });
|
|
107
92
|
}
|
|
108
93
|
}
|
|
109
|
-
|
|
94
|
+
|
|
110
95
|
this.config.debug && console.log(`readDir ${fullPath}: ${files.length} objects`);
|
|
111
96
|
return files;
|
|
112
97
|
}
|
|
113
98
|
|
|
114
|
-
public async readFile(
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
99
|
+
public async readFile(bucketName: TBucketName, filename: string, options: TReadFileOptions = {}) {
|
|
100
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
101
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename);
|
|
118
102
|
|
|
119
103
|
this.config.debug && console.log(`readFile ${fullPath}`);
|
|
120
|
-
return fs.readFileSync(
|
|
104
|
+
return options.encoding === 'string' ? fs.readFileSync(fullPath, 'utf8') : fs.readFileSync(fullPath);
|
|
121
105
|
}
|
|
122
106
|
|
|
123
|
-
public createReadStream(
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
107
|
+
public createReadStream(bucketName: TBucketName, filename: string) {
|
|
108
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
109
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename);
|
|
127
110
|
|
|
128
111
|
this.config.debug && console.log(`createReadStream ${fullPath}`);
|
|
129
|
-
return fs.createReadStream(
|
|
112
|
+
return fs.createReadStream(fullPath);
|
|
130
113
|
}
|
|
131
114
|
|
|
132
|
-
public async exists(
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
115
|
+
public async exists(bucketName: TBucketName, filename: string) {
|
|
116
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
117
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename);
|
|
136
118
|
|
|
137
119
|
this.config.debug && console.log(`exists ${fullPath}`);
|
|
138
|
-
return fs.existsSync(
|
|
120
|
+
return fs.existsSync(fullPath);
|
|
139
121
|
}
|
|
140
122
|
|
|
141
|
-
public async move(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
123
|
+
public async move(
|
|
124
|
+
bucketName: TBucketName,
|
|
125
|
+
source: string,
|
|
126
|
+
destination: string,
|
|
127
|
+
options: { overwrite?: boolean } = {},
|
|
128
|
+
) {
|
|
129
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
130
|
+
const fullPathSource = path.join(this.rootDir, bucketDir, source);
|
|
131
|
+
const fullPathDestination = path.join(this.rootDir, bucketDir, destination);
|
|
146
132
|
|
|
147
133
|
this.config.debug && console.log(`move ${fullPathSource} to ${fullPathDestination}`);
|
|
148
134
|
return fs.moveSync(fullPathSource, fullPathDestination, options);
|
|
149
135
|
}
|
|
150
136
|
|
|
151
|
-
public async outputFile(
|
|
152
|
-
bucketName: TBucketName,
|
|
153
|
-
filename: string,
|
|
154
|
-
content: string | Buffer,
|
|
155
|
-
options?: TOutputFileOptions
|
|
137
|
+
public async outputFile(
|
|
138
|
+
bucketName: TBucketName,
|
|
139
|
+
filename: string,
|
|
140
|
+
content: string | Buffer,
|
|
141
|
+
options?: TOutputFileOptions,
|
|
156
142
|
) {
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
143
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
144
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename);
|
|
160
145
|
this.config.debug && console.log(`outputFile`, fullPath);
|
|
161
146
|
|
|
162
|
-
fs.outputFileSync(
|
|
147
|
+
fs.outputFileSync(fullPath, content, options);
|
|
163
148
|
|
|
164
|
-
return {
|
|
165
|
-
path: fullPath
|
|
166
|
-
}
|
|
149
|
+
return { path: fullPath };
|
|
167
150
|
}
|
|
168
151
|
|
|
169
|
-
public async readJSON(
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
152
|
+
public async readJSON(bucketName: TBucketName, filename: string) {
|
|
153
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
154
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename);
|
|
173
155
|
|
|
174
156
|
this.config.debug && console.log(`readJSON ${fullPath}`);
|
|
175
|
-
return fs.readJsonSync(
|
|
157
|
+
return fs.readJsonSync(fullPath);
|
|
176
158
|
}
|
|
177
159
|
|
|
178
|
-
public async delete(
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
const fullPath = path.join( this.rootDir, bucketDir, filename );
|
|
160
|
+
public async delete(bucketName: TBucketName, filename: string) {
|
|
161
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
162
|
+
const fullPath = path.join(this.rootDir, bucketDir, filename);
|
|
182
163
|
|
|
183
164
|
this.config.debug && console.log(`delete ${fullPath}`);
|
|
184
|
-
fs.removeSync(
|
|
165
|
+
fs.removeSync(fullPath);
|
|
185
166
|
return true;
|
|
186
167
|
}
|
|
187
168
|
|
|
188
|
-
|
|
169
|
+
public async deleteDir(bucketName: TBucketName, dirname: string) {
|
|
170
|
+
const bucketDir = this.getBucketDir(bucketName);
|
|
171
|
+
const fullPath = path.join(this.rootDir, bucketDir, dirname);
|
|
172
|
+
|
|
173
|
+
this.config.debug && console.log(`deleteDir ${fullPath}`);
|
|
174
|
+
fs.removeSync(fullPath);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|