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
@@ -0,0 +1,244 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { parse } from '@babel/parser';
4
+ import traverse, { NodePath } from '@babel/traverse';
5
+ import generate from '@babel/generator';
6
+ import * as types from '@babel/types';
7
+
8
+ const findFiles = (dir: string): string[] => {
9
+ if (!fs.existsSync(dir)) return [];
10
+
11
+ const files: string[] = [];
12
+
13
+ for (const dirent of fs.readdirSync(dir, { withFileTypes: true })) {
14
+ const filepath = path.join(dir, dirent.name);
15
+
16
+ if (dirent.isDirectory()) {
17
+ files.push(...findFiles(filepath));
18
+ continue;
19
+ }
20
+
21
+ if (dirent.isFile() && /\.(tsx?|jsx?)$/.test(filepath)) files.push(filepath);
22
+ }
23
+
24
+ return files;
25
+ };
26
+
27
+ const isFunctionLikePath = (path: NodePath) =>
28
+ path.isFunctionDeclaration() ||
29
+ path.isFunctionExpression() ||
30
+ path.isArrowFunctionExpression() ||
31
+ path.isObjectMethod() ||
32
+ path.isClassMethod();
33
+
34
+ const getOutermostFunctionPath = (path: NodePath) => {
35
+ let current: NodePath | null = path;
36
+ let lastFunctionPath: NodePath | null = null;
37
+
38
+ while (current && !current.isProgram()) {
39
+ if (isFunctionLikePath(current)) lastFunctionPath = current;
40
+
41
+ current = current.parentPath;
42
+ }
43
+
44
+ return lastFunctionPath;
45
+ };
46
+
47
+ const ensureUseContextImport = (programPath: NodePath<types.Program>) => {
48
+ for (const statement of programPath.node.body) {
49
+ if (
50
+ statement.type === 'ImportDeclaration' &&
51
+ statement.source.value === '@/client/context' &&
52
+ statement.specifiers.some(
53
+ (specifier) => specifier.type === 'ImportDefaultSpecifier' && specifier.local.name === 'useContext',
54
+ )
55
+ )
56
+ return;
57
+ }
58
+
59
+ programPath.unshiftContainer(
60
+ 'body',
61
+ types.importDeclaration(
62
+ [types.importDefaultSpecifier(types.identifier('useContext'))],
63
+ types.stringLiteral('@/client/context'),
64
+ ),
65
+ );
66
+ };
67
+
68
+ const ensureBlockBody = (functionPath: NodePath) => {
69
+ if (functionPath.isArrowFunctionExpression() && functionPath.node.body.type !== 'BlockStatement') {
70
+ functionPath.node.body = types.blockStatement([types.returnStatement(functionPath.node.body)]);
71
+ }
72
+
73
+ return functionPath.get('body') as NodePath<types.BlockStatement>;
74
+ };
75
+
76
+ const hasExistingUseContextDeclaration = (bodyPath: NodePath<types.BlockStatement>, names: string[]) => {
77
+ return bodyPath.node.body.some(
78
+ (statement) =>
79
+ statement.type === 'VariableDeclaration' &&
80
+ statement.declarations.some(
81
+ (declaration) =>
82
+ declaration.id.type === 'ObjectPattern' &&
83
+ declaration.init?.type === 'CallExpression' &&
84
+ declaration.init.callee.type === 'Identifier' &&
85
+ declaration.init.callee.name === 'useContext' &&
86
+ names.every((name) =>
87
+ declaration.id.properties.some(
88
+ (property) =>
89
+ property.type === 'ObjectProperty' &&
90
+ property.key.type === 'Identifier' &&
91
+ property.key.name === name,
92
+ ),
93
+ ),
94
+ ),
95
+ );
96
+ };
97
+
98
+ const objectPatternHasProperty = (pattern: types.ObjectPattern, localName: string) =>
99
+ pattern.properties.some(
100
+ (property) =>
101
+ property.type === 'ObjectProperty' &&
102
+ property.value.type === 'Identifier' &&
103
+ property.value.name === localName,
104
+ );
105
+
106
+ const addObjectPatternProperty = (pattern: types.ObjectPattern, keyName: string, localName: string = keyName) => {
107
+ if (objectPatternHasProperty(pattern, localName)) return;
108
+
109
+ pattern.properties.push(
110
+ types.objectProperty(types.identifier(keyName), types.identifier(localName), false, keyName === localName),
111
+ );
112
+ };
113
+
114
+ const getUseContextStatements = (bodyPath: NodePath<types.BlockStatement>) => {
115
+ return bodyPath
116
+ .get('body')
117
+ .filter(
118
+ (statementPath) =>
119
+ statementPath.isVariableDeclaration() &&
120
+ statementPath.node.declarations.length === 1 &&
121
+ statementPath.node.declarations[0].id.type === 'ObjectPattern' &&
122
+ statementPath.node.declarations[0].init?.type === 'CallExpression' &&
123
+ statementPath.node.declarations[0].init.callee.type === 'Identifier' &&
124
+ statementPath.node.declarations[0].init.callee.name === 'useContext',
125
+ ) as NodePath<types.VariableDeclaration>[];
126
+ };
127
+
128
+ const repoRoots = process.argv.slice(2);
129
+ if (!repoRoots.length)
130
+ throw new Error('Usage: ts-node scripts/refactor-client-app-imports.ts <repo-root> [repo-root...]');
131
+
132
+ for (const repoRoot of repoRoots) {
133
+ const clientRoot = path.join(repoRoot, 'client');
134
+ const files = findFiles(clientRoot).filter((filepath) => !filepath.includes('/client/pages/'));
135
+ let changedFiles = 0;
136
+
137
+ for (const filepath of files) {
138
+ const code = fs.readFileSync(filepath, 'utf8');
139
+ if (!code.includes('@app') && !code.includes('"@app"')) continue;
140
+
141
+ const ast = parse(code, {
142
+ sourceType: 'module',
143
+ plugins: ['typescript', 'jsx', 'decorators-legacy', 'classProperties'],
144
+ });
145
+
146
+ const importedNames = new Set<string>();
147
+ const functionBindings = new Map<NodePath, Set<string>>();
148
+ let hasAppImport = false;
149
+
150
+ traverse(ast, {
151
+ ImportDeclaration(path) {
152
+ if (path.node.source.value !== '@app') return;
153
+
154
+ hasAppImport = true;
155
+
156
+ for (const specifier of path.node.specifiers) {
157
+ if (specifier.type === 'ImportSpecifier' && specifier.imported.type === 'Identifier')
158
+ importedNames.add(specifier.local.name);
159
+ }
160
+ },
161
+ Identifier(path) {
162
+ if (!importedNames.has(path.node.name)) return;
163
+
164
+ if (!path.isReferencedIdentifier()) return;
165
+
166
+ const binding = path.scope.getBinding(path.node.name);
167
+ if (!binding?.path.isImportSpecifier()) return;
168
+
169
+ const functionPath = getOutermostFunctionPath(path);
170
+ if (!functionPath) return;
171
+
172
+ const names = functionBindings.get(functionPath) || new Set<string>();
173
+ names.add(path.node.name);
174
+ functionBindings.set(functionPath, names);
175
+ },
176
+ });
177
+
178
+ if (!hasAppImport) continue;
179
+
180
+ traverse(ast, {
181
+ Program(programPath) {
182
+ for (const statementPath of programPath.get('body')) {
183
+ if (!statementPath.isImportDeclaration()) continue;
184
+
185
+ if (statementPath.node.source.value === '@app') statementPath.remove();
186
+ }
187
+
188
+ ensureUseContextImport(programPath);
189
+ },
190
+ });
191
+
192
+ for (const [functionPath, namesSet] of functionBindings) {
193
+ const names = [...namesSet].sort((a, b) => a.localeCompare(b));
194
+ const bodyPath = ensureBlockBody(functionPath);
195
+ const useContextStatements = getUseContextStatements(bodyPath);
196
+
197
+ if (hasExistingUseContextDeclaration(bodyPath, names)) continue;
198
+
199
+ if (useContextStatements.length) {
200
+ const primaryDeclaration = useContextStatements[0].node.declarations[0];
201
+ const primaryPattern = primaryDeclaration.id as types.ObjectPattern;
202
+
203
+ for (const statementPath of useContextStatements.slice(1)) {
204
+ const declaration = statementPath.node.declarations[0];
205
+ const pattern = declaration.id as types.ObjectPattern;
206
+
207
+ for (const property of pattern.properties) {
208
+ if (
209
+ property.type === 'ObjectProperty' &&
210
+ property.key.type === 'Identifier' &&
211
+ property.value.type === 'Identifier'
212
+ )
213
+ addObjectPatternProperty(primaryPattern, property.key.name, property.value.name);
214
+ }
215
+
216
+ statementPath.remove();
217
+ }
218
+
219
+ for (const name of names) addObjectPatternProperty(primaryPattern, name);
220
+
221
+ continue;
222
+ }
223
+
224
+ bodyPath.unshiftContainer(
225
+ 'body',
226
+ types.variableDeclaration('const', [
227
+ types.variableDeclarator(
228
+ types.objectPattern(
229
+ names.map((name) =>
230
+ types.objectProperty(types.identifier(name), types.identifier(name), false, true),
231
+ ),
232
+ ),
233
+ types.callExpression(types.identifier('useContext'), []),
234
+ ),
235
+ ]),
236
+ );
237
+ }
238
+
239
+ fs.writeFileSync(filepath, generate(ast, {}, code).code);
240
+ changedFiles++;
241
+ }
242
+
243
+ console.log(`[refactor-client-app-imports] ${repoRoot}: changed ${changedFiles} files`);
244
+ }