-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathfix-schemas.js
More file actions
67 lines (59 loc) · 2.14 KB
/
fix-schemas.js
File metadata and controls
67 lines (59 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
const path = require('path');
const fixSchemaNames = (filePath, schemaNames) => {
let content = fs.readFileSync(filePath, 'utf8');
let modified = false;
schemaNames.forEach(schemaName => {
const lines = content.split('\n');
let processedCount = 0;
for (let i = 0; i < lines.length; i++) {
if (/^export const\s+=\s+z/.test(lines[i])) {
// Find the next usage of any schema name after this line
let found = false;
for (let j = i + 1; j < lines.length && j < i + 50; j++) {
if (lines[j].includes(schemaName + '.parse') || lines[j].includes(schemaName + '.safeParse')) {
if (processedCount === 0) {
lines[i] = lines[i].replace(/^export const\s+=/, `export const ${schemaName} =`);
modified = true;
found = true;
processedCount++;
break;
}
}
}
if (!found) {
processedCount++;
}
}
}
if (modified) {
content = lines.join('\n');
}
});
if (modified) {
fs.writeFileSync(filePath, content, 'utf8');
return true;
}
return false;
};
const controllersDir = './src/controllers';
const schemas = {
"burnController.ts": ["bodySchema"],
"fiatController.ts": ["faucetSchema", "onRampSchema", "offRampSchema"],
"investmentController.ts": ["requestSchema", "getWithdrawRequestsQuerySchema"],
"mintController.ts": ["usdcBodySchema", "depositBodySchema"],
"onrampController.ts": ["bodySchema"],
"recoveryController.ts": ["unlockAppSchema", "verifyRecoveryOtpSchema"],
"salaryController.ts": ["postSalaryDisburseSchema", "postSalaryScheduleSchema"],
"transactionController.ts": ["listTransactionsQuerySchema"],
"transferController.ts": ["getTransfersQuerySchema"],
"userController.ts": ["patchMeSchema", "addContactSchema", "addGuardianSchema", "walletConfirmSchema"]
};
const fixed = [];
Object.entries(schemas).forEach(([file, names]) => {
const filePath = path.join(controllersDir, file);
if (fixSchemaNames(filePath, names)) {
fixed.push(file);
}
});
console.log('Fixed files:', fixed.join(', '));