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.
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 +12 -47
  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
@@ -1,142 +1,90 @@
1
- import type { Prisma, PrismaClient } from '@models/types';
2
- import * as runtime from '@/var/prisma/runtime/library.js';
1
+ import type { PrismaClient } from '@models/types';
3
2
 
4
- /*export type TDelegate<R> = {
5
- findMany(args?: any): Promise<R[]>
6
- findFirst(args?: any): Promise<R | null>
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, // Result type
47
- RT // Transformed result type
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
- // Load stats
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: any[]
98
- ): Promise<any[]> {
99
-
100
- const select = Object.entries(withStats).map(([key, sql]) =>
101
- `(COALESCE((
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 stats = await this.prisma.$queryRawUnsafe(`
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(r => "'" + r[ $key ] + "'").join(',')}
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 stats) {
68
+ for (const stat of statRows) {
115
69
  for (const key in stat) {
116
-
117
- if (key === $key)
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 stats;
75
+ return statRows;
125
76
  }
126
77
 
127
- private transformResult( result: any, stats: any[], withStats?: TWithStats ) {
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] === result[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
- return {
138
- ...result,
139
- ...resultStats
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["SQL"]>
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 Services = {
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
- D extends TDelegate<R>,
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>( strings: TemplateStringsArray, ...data: any[] ) {
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>() => query().then((resultatRequetes: any) => {
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
- const resultat = resultatRequetes[0];
71
+ return Object.values(resultat)[0] as TValue;
72
+ });
87
73
 
88
- if (!resultat)
89
- return null;
74
+ query.first = () =>
75
+ query().then((resultatRequetes: any) => {
76
+ return resultatRequetes[0] || null;
77
+ });
90
78
 
91
- return Object.values(resultat)[0] as TValue;
92
- });
79
+ query.firstOrFail = (message: string) =>
80
+ query().then((resultatRequetes: any) => {
81
+ if (resultatRequetes.length === 0) throw new NotFound(message);
93
82
 
94
- query.first = () => query().then((resultatRequetes: any) => {
95
- return resultatRequetes[0] || null;
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( data: any, forStorage: boolean = false ) {
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 === "Object")
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( data )) {
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.map((stringBefore, i) => {
136
-
137
- if (i <= iMax) {
138
-
139
- let value = data[i];
140
- stringBefore = stringBefore.trim();
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
- value = 'NULL';
119
+ // Null
120
+ if (value === undefined || value === null) {
121
+ value = 'NULL';
147
122
 
148
- // Replace ""= NULL" by "IS NULL"
149
- if (prefix === '=')
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
- // Prefix = special parse
153
- } else if (prefix === ':' || prefix === '&') {
126
+ // Prefix = special parse
127
+ } else if (prefix === ':' || prefix === '&') {
128
+ // Remove the prefix
129
+ stringBefore = stringBefore.substring(0, stringBefore.length - 1);
154
130
 
155
- // Remove the prefix
156
- stringBefore = stringBefore.substring(0, stringBefore.length - 1);
131
+ // Object: `WHERE :${filters}` => `SET requestId = "" AND col = 3`
132
+ if (typeof value === 'object') {
133
+ const keyword = prefix === '&' ? ' AND ' : ', ';
157
134
 
158
- // Object: `WHERE :${filters}` => `SET requestId = "" AND col = 3`
159
- if (typeof value === 'object') {
135
+ value = Object.keys(value).length === 0 ? '1' : this.equalities(value).join(keyword);
160
136
 
161
- const keyword = prefix === '&' ? ' AND ' : ', '
137
+ // String: `SET :${column} = ${data}` => `SET balance = 10`
138
+ } else {
139
+ }
162
140
 
163
- value = Object.keys(value).length === 0 ? '1' : this.equalities(value).join( keyword );
164
-
165
- // String: `SET :${column} = ${data}` => `SET balance = 10`
166
- } else {
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
- return stringBefore;
192
-
193
- }).join(' ').trim();
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( data[k], forStorage ))
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
+ };