proteum 1.0.2 → 2.0.0
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 +12 -47
- 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
|
@@ -1,142 +1,90 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import * as runtime from '@/var/prisma/runtime/library.js';
|
|
1
|
+
import type { PrismaClient } from '@models/types';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
findMany(args?:
|
|
6
|
-
findFirst(args?:
|
|
7
|
-
}
|
|
3
|
+
export type TDelegate<R = unknown> = {
|
|
4
|
+
findMany(args?: Record<string, unknown>): Promise<R[]>;
|
|
5
|
+
findFirst(args?: Record<string, unknown>): Promise<R | null>;
|
|
6
|
+
};
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export type TWithStats = { $table: string; $key: string } & Record<string, string>;
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
export type TSubset = (...args: any[]) => Record<string, unknown> & { withStats?: TWithStats };
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
export type TDelegate<R> = PrismaClient[string];
|
|
15
|
-
|
|
16
|
-
/*export type TExtractPayload<D extends TDelegate<never>> =
|
|
17
|
-
D extends { [K in symbol]: { types: { payload: infer P } } } ? P : never;
|
|
18
|
-
|
|
19
|
-
export type TExtractPayload2<D> =
|
|
20
|
-
D extends { [K: symbol]: { types: Prisma.TypeMap<infer E>['model'][infer M] } }
|
|
21
|
-
? Prisma.TypeMap<E>['model'][M & keyof Prisma.TypeMap<E>['model']]['payload']
|
|
22
|
-
: never;*/
|
|
23
|
-
|
|
24
|
-
export type Transform<S extends TSubset, R, RT> = (
|
|
25
|
-
row: runtime.Types.Result.GetResult<
|
|
26
|
-
Prisma.$ProspectContactLeadPayload,
|
|
27
|
-
ReturnType<S>,
|
|
28
|
-
'findMany'
|
|
29
|
-
>[number]
|
|
30
|
-
) => RT
|
|
31
|
-
|
|
32
|
-
export type TWithStats = {
|
|
33
|
-
$table: string,
|
|
34
|
-
$key: string
|
|
35
|
-
} & {
|
|
36
|
-
[key: string]: string // key => SQL
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type TSubset = (...a: any[]) => Prisma.ProspectContactLeadFindFirstArgs & {
|
|
40
|
-
withStats?: TWithStats
|
|
41
|
-
}
|
|
12
|
+
export type Transform<S extends TSubset, R, RT> = (row: R) => RT;
|
|
42
13
|
|
|
43
14
|
export default class Facet<
|
|
44
15
|
D extends TDelegate<R>,
|
|
45
16
|
S extends TSubset,
|
|
46
|
-
R
|
|
47
|
-
RT
|
|
17
|
+
R = unknown,
|
|
18
|
+
RT = R,
|
|
48
19
|
> {
|
|
49
20
|
constructor(
|
|
50
|
-
|
|
51
21
|
private readonly prisma: PrismaClient,
|
|
52
|
-
|
|
53
22
|
private readonly delegate: D,
|
|
54
23
|
private readonly subset: S,
|
|
55
|
-
|
|
56
|
-
/* the **ONLY** line that changed ↓↓↓ */
|
|
57
24
|
private readonly transform?: Transform<S, R, RT>,
|
|
58
|
-
) {
|
|
59
|
-
|
|
60
|
-
public async findMany(
|
|
61
|
-
...args: Parameters<S>
|
|
62
|
-
): Promise<RT[]> {
|
|
25
|
+
) {}
|
|
63
26
|
|
|
27
|
+
public async findMany(...args: Parameters<S>): Promise<RT[]> {
|
|
64
28
|
const { withStats, ...subset } = this.subset(...args);
|
|
65
29
|
|
|
66
30
|
const results = await this.delegate.findMany(subset);
|
|
67
|
-
if (results.length === 0)
|
|
68
|
-
return [];
|
|
31
|
+
if (results.length === 0) return [];
|
|
69
32
|
|
|
70
|
-
|
|
71
|
-
const stats = withStats
|
|
72
|
-
? await this.fetchStats( withStats, results )
|
|
73
|
-
: [];
|
|
33
|
+
const stats = withStats ? await this.fetchStats(withStats, results) : [];
|
|
74
34
|
|
|
75
|
-
return results.map(row => this.transformResult(row, stats, withStats));
|
|
35
|
+
return results.map((row) => this.transformResult(row, stats, withStats));
|
|
76
36
|
}
|
|
77
37
|
|
|
78
|
-
public async findFirst(
|
|
79
|
-
...args: Parameters<S>
|
|
80
|
-
): Promise<RT | null> {
|
|
81
|
-
|
|
38
|
+
public async findFirst(...args: Parameters<S>): Promise<RT | null> {
|
|
82
39
|
const { withStats, ...subset } = this.subset(...args);
|
|
83
40
|
|
|
84
41
|
const result = await this.delegate.findFirst(subset);
|
|
85
|
-
if (!result)
|
|
86
|
-
return null;
|
|
42
|
+
if (!result) return null;
|
|
87
43
|
|
|
88
|
-
const stats = withStats
|
|
89
|
-
? await this.fetchStats( withStats, [result] )
|
|
90
|
-
: [];
|
|
44
|
+
const stats = withStats ? await this.fetchStats(withStats, [result]) : [];
|
|
91
45
|
|
|
92
46
|
return this.transformResult(result, stats, withStats);
|
|
93
47
|
}
|
|
94
48
|
|
|
95
49
|
private async fetchStats(
|
|
96
50
|
{ $table, $key, ...withStats }: TWithStats,
|
|
97
|
-
results:
|
|
98
|
-
): Promise<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
51
|
+
results: R[],
|
|
52
|
+
): Promise<Record<string, unknown>[]> {
|
|
53
|
+
const select = Object.entries(withStats).map(
|
|
54
|
+
([key, sql]) =>
|
|
55
|
+
`(COALESCE((
|
|
102
56
|
${sql}
|
|
103
|
-
), 0)) as ${key}
|
|
57
|
+
), 0)) as ${key}`,
|
|
104
58
|
);
|
|
105
59
|
|
|
106
|
-
const
|
|
60
|
+
const statRows = (await this.prisma.$queryRawUnsafe(`
|
|
107
61
|
SELECT ${$key}, ${select.join(', ')}
|
|
108
62
|
FROM ${$table}
|
|
109
63
|
WHERE ${$key} IN (
|
|
110
|
-
${results.map(
|
|
64
|
+
${(results as Array<Record<string, unknown>>).map((row) => "'" + row[$key] + "'").join(',')}
|
|
111
65
|
)
|
|
112
|
-
`);
|
|
66
|
+
`)) as Record<string, unknown>[];
|
|
113
67
|
|
|
114
|
-
for (const stat of
|
|
68
|
+
for (const stat of statRows) {
|
|
115
69
|
for (const key in stat) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
continue;
|
|
119
|
-
|
|
120
|
-
stat[key] = stat[key] ? parseInt(stat[key]) : 0;
|
|
70
|
+
if (key === $key) continue;
|
|
71
|
+
stat[key] = stat[key] ? parseInt(String(stat[key]), 10) : 0;
|
|
121
72
|
}
|
|
122
73
|
}
|
|
123
74
|
|
|
124
|
-
return
|
|
75
|
+
return statRows;
|
|
125
76
|
}
|
|
126
77
|
|
|
127
|
-
private transformResult(
|
|
128
|
-
|
|
129
|
-
// Transform stats
|
|
78
|
+
private transformResult(result: R, stats: Record<string, unknown>[], withStats?: TWithStats): RT {
|
|
79
|
+
const resultRecord = result as Record<string, unknown>;
|
|
130
80
|
const resultStats = withStats
|
|
131
|
-
? stats.find(stat => stat[withStats.$key] ===
|
|
81
|
+
? stats.find((stat) => stat[withStats.$key] === resultRecord[withStats.$key]) || {}
|
|
132
82
|
: {};
|
|
133
83
|
|
|
134
|
-
if (this.transform)
|
|
135
|
-
result = this.transform(result);
|
|
84
|
+
if (!this.transform) return { ...resultRecord, ...resultStats } as RT;
|
|
136
85
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
86
|
+
const transformed = this.transform(result);
|
|
87
|
+
|
|
88
|
+
return { ...(transformed as object), ...resultStats } as RT;
|
|
141
89
|
}
|
|
142
|
-
}
|
|
90
|
+
}
|
|
@@ -9,7 +9,7 @@ import type PrismaClientType from '@prisma/client';
|
|
|
9
9
|
const safeStringify = require('fast-safe-stringify'); // remplace les références circulairs par un [Circular]
|
|
10
10
|
|
|
11
11
|
// Core
|
|
12
|
-
import type { Application } from '@server/app';
|
|
12
|
+
import type { Application } from '@server/app/index';
|
|
13
13
|
import Service from '@server/app/service';
|
|
14
14
|
|
|
15
15
|
// Specific
|
|
@@ -20,182 +20,146 @@ import { NotFound } from '@common/errors';
|
|
|
20
20
|
- TYPES
|
|
21
21
|
----------------------------------*/
|
|
22
22
|
|
|
23
|
-
export type SqlQuery = ReturnType<ModelsManager[
|
|
23
|
+
export type SqlQuery = ReturnType<ModelsManager['SQL']>;
|
|
24
24
|
|
|
25
25
|
/*----------------------------------
|
|
26
26
|
- SERVICE CONFIG
|
|
27
27
|
----------------------------------*/
|
|
28
28
|
|
|
29
|
-
export type Config = {
|
|
30
|
-
debug?: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type Hooks = {
|
|
34
|
-
|
|
35
|
-
}
|
|
29
|
+
export type Config = { debug?: boolean };
|
|
36
30
|
|
|
37
|
-
export type
|
|
31
|
+
export type Hooks = {};
|
|
38
32
|
|
|
39
|
-
}
|
|
33
|
+
export type Services = {};
|
|
40
34
|
|
|
41
35
|
/*----------------------------------
|
|
42
36
|
- CLASSE
|
|
43
37
|
----------------------------------*/
|
|
44
38
|
|
|
45
39
|
export default class ModelsManager extends Service<Config, Hooks, Application, Application> {
|
|
46
|
-
|
|
47
40
|
public client = new PrismaClient() as PrismaClientType.PrismaClient;
|
|
48
41
|
|
|
49
42
|
public async ready() {
|
|
50
|
-
|
|
51
43
|
await this.client.$executeRaw`SET time_zone = '+00:00'`;
|
|
52
|
-
|
|
53
44
|
}
|
|
54
|
-
|
|
45
|
+
|
|
55
46
|
public async shutdown() {
|
|
56
|
-
await this.client.$disconnect()
|
|
47
|
+
await this.client.$disconnect();
|
|
57
48
|
}
|
|
58
49
|
|
|
59
|
-
public Facet<
|
|
60
|
-
|
|
61
|
-
S extends TSubset,
|
|
62
|
-
R,
|
|
63
|
-
RT
|
|
64
|
-
>(...args: [D, S, Transform<S, R, RT>]) {
|
|
65
|
-
|
|
66
|
-
return new Facet(
|
|
67
|
-
this.client,
|
|
68
|
-
...args
|
|
69
|
-
);
|
|
50
|
+
public Facet<D extends TDelegate<R>, S extends TSubset, R, RT>(...args: [D, S, Transform<S, R, RT>]) {
|
|
51
|
+
return new Facet(this.client, ...args);
|
|
70
52
|
}
|
|
71
53
|
|
|
72
54
|
/*----------------------------------
|
|
73
55
|
- OPERATIONS: PARSING
|
|
74
56
|
----------------------------------*/
|
|
75
|
-
public SQL<TRowData extends {}|number|string>(
|
|
76
|
-
|
|
57
|
+
public SQL<TRowData extends {} | number | string>(strings: TemplateStringsArray, ...data: any[]) {
|
|
77
58
|
const string = this.string(strings, ...data);
|
|
78
59
|
|
|
79
60
|
const query = () => {
|
|
80
61
|
return this.client.$queryRawUnsafe(string) as Promise<TRowData[]>;
|
|
81
|
-
}
|
|
62
|
+
};
|
|
82
63
|
|
|
83
64
|
query.all = query;
|
|
84
|
-
query.value = <TValue extends any = number>() =>
|
|
65
|
+
query.value = <TValue extends any = number>() =>
|
|
66
|
+
query().then((resultatRequetes: any) => {
|
|
67
|
+
const resultat = resultatRequetes[0];
|
|
68
|
+
|
|
69
|
+
if (!resultat) return null;
|
|
85
70
|
|
|
86
|
-
|
|
71
|
+
return Object.values(resultat)[0] as TValue;
|
|
72
|
+
});
|
|
87
73
|
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
query.first = () =>
|
|
75
|
+
query().then((resultatRequetes: any) => {
|
|
76
|
+
return resultatRequetes[0] || null;
|
|
77
|
+
});
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
query.firstOrFail = (message: string) =>
|
|
80
|
+
query().then((resultatRequetes: any) => {
|
|
81
|
+
if (resultatRequetes.length === 0) throw new NotFound(message);
|
|
93
82
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
query.firstOrFail = (message: string) => query().then((resultatRequetes: any) => {
|
|
99
|
-
|
|
100
|
-
if (resultatRequetes.length === 0)
|
|
101
|
-
throw new NotFound(message);
|
|
102
|
-
|
|
103
|
-
return resultatRequetes[0];
|
|
104
|
-
});
|
|
83
|
+
return resultatRequetes[0];
|
|
84
|
+
});
|
|
105
85
|
|
|
106
86
|
query.string = string;
|
|
107
87
|
|
|
108
88
|
return query;
|
|
109
89
|
}
|
|
110
90
|
|
|
111
|
-
public esc(
|
|
112
|
-
|
|
91
|
+
public esc(data: any, forStorage: boolean = false) {
|
|
113
92
|
// JSON object
|
|
114
93
|
// TODO: do it via datatypes.ts
|
|
115
94
|
if (typeof data === 'object' && data !== null) {
|
|
116
|
-
|
|
117
95
|
// Object: stringify in JSON
|
|
118
|
-
if (data.constructor.name ===
|
|
119
|
-
data = safeStringify(data);
|
|
96
|
+
if (data.constructor.name === 'Object') data = safeStringify(data);
|
|
120
97
|
// Array: if for storage, reparate items with a comma
|
|
121
|
-
else if (forStorage && Array.isArray(
|
|
122
|
-
data = data.join(',')
|
|
123
|
-
}
|
|
98
|
+
else if (forStorage && Array.isArray(data)) {
|
|
99
|
+
data = data.join(',');
|
|
100
|
+
}
|
|
124
101
|
}
|
|
125
|
-
|
|
102
|
+
|
|
126
103
|
return mysql.escape(data);
|
|
127
104
|
}
|
|
128
105
|
|
|
129
106
|
public string = (strings: TemplateStringsArray, ...data: any[]) => {
|
|
130
107
|
const iMax = data.length - 1;
|
|
131
108
|
|
|
132
|
-
if (typeof data === 'function')
|
|
109
|
+
if (typeof data === 'function')
|
|
133
110
|
throw new Error(`A function has been passed into the sql string template: ` + data);
|
|
134
111
|
|
|
135
|
-
return strings
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const prefix = stringBefore[stringBefore.length - 1];
|
|
142
|
-
|
|
143
|
-
// Null
|
|
144
|
-
if (value === undefined || value === null) {
|
|
112
|
+
return strings
|
|
113
|
+
.map((stringBefore, i) => {
|
|
114
|
+
if (i <= iMax) {
|
|
115
|
+
let value = data[i];
|
|
116
|
+
stringBefore = stringBefore.trim();
|
|
117
|
+
const prefix = stringBefore[stringBefore.length - 1];
|
|
145
118
|
|
|
146
|
-
|
|
119
|
+
// Null
|
|
120
|
+
if (value === undefined || value === null) {
|
|
121
|
+
value = 'NULL';
|
|
147
122
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
stringBefore = stringBefore.substring(0, stringBefore.length - 1) + 'IS ';
|
|
123
|
+
// Replace ""= NULL" by "IS NULL"
|
|
124
|
+
if (prefix === '=') stringBefore = stringBefore.substring(0, stringBefore.length - 1) + 'IS ';
|
|
151
125
|
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
// Prefix = special parse
|
|
127
|
+
} else if (prefix === ':' || prefix === '&') {
|
|
128
|
+
// Remove the prefix
|
|
129
|
+
stringBefore = stringBefore.substring(0, stringBefore.length - 1);
|
|
154
130
|
|
|
155
|
-
|
|
156
|
-
|
|
131
|
+
// Object: `WHERE :${filters}` => `SET requestId = "" AND col = 3`
|
|
132
|
+
if (typeof value === 'object') {
|
|
133
|
+
const keyword = prefix === '&' ? ' AND ' : ', ';
|
|
157
134
|
|
|
158
|
-
|
|
159
|
-
if (typeof value === 'object') {
|
|
135
|
+
value = Object.keys(value).length === 0 ? '1' : this.equalities(value).join(keyword);
|
|
160
136
|
|
|
161
|
-
|
|
137
|
+
// String: `SET :${column} = ${data}` => `SET balance = 10`
|
|
138
|
+
} else {
|
|
139
|
+
}
|
|
162
140
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
//
|
|
166
|
-
|
|
141
|
+
// SQL query
|
|
142
|
+
} else if (typeof value === 'function' && value.string !== undefined) value = ' ' + value.string;
|
|
143
|
+
// Escape value
|
|
144
|
+
else {
|
|
145
|
+
const lastKeyword = stringBefore.trim().split(' ').pop();
|
|
167
146
|
|
|
147
|
+
// Escape table name
|
|
148
|
+
if (lastKeyword === 'FROM') value = '`' + value + '`';
|
|
149
|
+
else value = mysql.escape(value);
|
|
168
150
|
|
|
151
|
+
value = ' ' + value;
|
|
169
152
|
}
|
|
170
|
-
|
|
171
|
-
// SQL query
|
|
172
|
-
} else if (typeof value === 'function' && value.string !== undefined)
|
|
173
|
-
value = ' ' + value.string;
|
|
174
|
-
// Escape value
|
|
175
|
-
else {
|
|
176
|
-
|
|
177
|
-
const lastKeyword = stringBefore.trim().split(' ').pop();
|
|
178
|
-
|
|
179
|
-
// Escape table name
|
|
180
|
-
if (lastKeyword === 'FROM')
|
|
181
|
-
value = '`' + value + '`';
|
|
182
|
-
else
|
|
183
|
-
value = mysql.escape(value);
|
|
184
|
-
|
|
185
|
-
value = ' ' + value;
|
|
153
|
+
stringBefore += value;
|
|
186
154
|
}
|
|
187
|
-
stringBefore += value;
|
|
188
155
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
156
|
+
return stringBefore;
|
|
157
|
+
})
|
|
158
|
+
.join(' ')
|
|
159
|
+
.trim();
|
|
160
|
+
};
|
|
195
161
|
|
|
196
162
|
public equalities = (data: TObjetDonnees, forStorage: boolean = false) => {
|
|
197
|
-
return Object.keys(data).map(k => '' + k + ' = ' + this.esc(
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
163
|
+
return Object.keys(data).map((k) => '' + k + ' = ' + this.esc(data[k], forStorage));
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
type TGeneratedRuntimeBundleName = 'routes' | 'controllers';
|
|
5
|
+
|
|
6
|
+
const generatedRuntimeBundleFiles: Record<TGeneratedRuntimeBundleName, string> = {
|
|
7
|
+
routes: '__proteum_dev_routes.js',
|
|
8
|
+
controllers: '__proteum_dev_controllers.js',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Use Node's native require so the running server can reload freshly compiled
|
|
12
|
+
// dev bundles from disk instead of resolving the copies embedded in server.js.
|
|
13
|
+
const nativeRequire = eval('require') as NodeJS.Require;
|
|
14
|
+
|
|
15
|
+
const getGeneratedRuntimeBundlePath = (bundleName: TGeneratedRuntimeBundleName) =>
|
|
16
|
+
path.join(process.cwd(), APP_OUTPUT_DIR, generatedRuntimeBundleFiles[bundleName]);
|
|
17
|
+
|
|
18
|
+
export const loadGeneratedRuntimeBundle = <T>(bundleName: TGeneratedRuntimeBundleName): T | undefined => {
|
|
19
|
+
if (!__DEV__) return undefined;
|
|
20
|
+
|
|
21
|
+
const bundlePath = getGeneratedRuntimeBundlePath(bundleName);
|
|
22
|
+
if (!fs.existsSync(bundlePath)) return undefined;
|
|
23
|
+
|
|
24
|
+
const resolvedPath = nativeRequire.resolve(bundlePath);
|
|
25
|
+
delete nativeRequire.cache[resolvedPath];
|
|
26
|
+
|
|
27
|
+
const loadedModule = nativeRequire(resolvedPath);
|
|
28
|
+
return (loadedModule.default || loadedModule) as T;
|
|
29
|
+
};
|