Skip to content

Commit cd7ad6c

Browse files
authored
chore(refactor): kebab-case /shared folder (#803)
* chore(refactor): kebab-case /shared/db * all shared folder
1 parent 07c1493 commit cd7ad6c

File tree

309 files changed

+571
-426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

309 files changed

+571
-426
lines changed

renamer.ts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
// Convert camelCase to kebab-case
5+
function toKebabCase(filename: string): string {
6+
return filename.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
7+
}
8+
9+
// Iteratively process files and directories
10+
function processFilesAndFolders(rootDir: string) {
11+
const queue: string[] = [rootDir];
12+
13+
while (queue.length > 0) {
14+
const currentPath = queue.pop()!;
15+
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
16+
17+
for (const entry of entries) {
18+
const fullPath = path.join(currentPath, entry.name);
19+
20+
// Handle directories first
21+
if (entry.isDirectory()) {
22+
const newName = toKebabCase(entry.name);
23+
if (newName !== entry.name) {
24+
const newPath = path.join(currentPath, newName);
25+
26+
if (fs.existsSync(newPath)) {
27+
console.error(
28+
`Conflict: ${newPath} already exists. Skipping ${fullPath}`,
29+
);
30+
continue;
31+
}
32+
33+
console.log(`Renaming directory: ${fullPath} -> ${newPath}`);
34+
fs.renameSync(fullPath, newPath);
35+
36+
// Update imports after renaming
37+
updateImports(fullPath, newPath);
38+
39+
// Add the renamed directory back to the queue for further processing
40+
queue.push(newPath);
41+
} else {
42+
queue.push(fullPath); // If no renaming, continue processing the directory
43+
}
44+
} else {
45+
// Handle files
46+
const newName = toKebabCase(entry.name);
47+
if (newName !== entry.name) {
48+
const newPath = path.join(currentPath, newName);
49+
50+
if (fs.existsSync(newPath)) {
51+
console.error(
52+
`Conflict: ${newPath} already exists. Skipping ${fullPath}`,
53+
);
54+
continue;
55+
}
56+
57+
console.log(`Renaming file: ${fullPath} -> ${newPath}`);
58+
fs.renameSync(fullPath, newPath);
59+
60+
// Update imports after renaming
61+
updateImports(fullPath, newPath);
62+
}
63+
}
64+
}
65+
}
66+
}
67+
68+
// Corrected `updateImports` function
69+
function updateImports(oldPath: string, newPath: string) {
70+
const projectRoot = path.resolve("./"); // Adjust project root if needed
71+
const allFiles = getAllFiles(projectRoot, /\.(ts|js|tsx|jsx)$/);
72+
73+
const normalizedOldPath = normalizePath(oldPath);
74+
const normalizedNewPath = normalizePath(newPath);
75+
76+
for (const file of allFiles) {
77+
let content = fs.readFileSync(file, "utf-8");
78+
79+
const relativeOldPath = normalizePath(
80+
formatRelativePath(file, normalizedOldPath),
81+
);
82+
const relativeNewPath = normalizePath(
83+
formatRelativePath(file, normalizedNewPath),
84+
);
85+
86+
const importRegex = new RegExp(
87+
`(['"\`])(${escapeRegex(relativeOldPath)})(['"\`])`,
88+
"g",
89+
);
90+
91+
if (importRegex.test(content)) {
92+
const updatedContent = content.replace(
93+
importRegex,
94+
`$1${relativeNewPath}$3`,
95+
);
96+
fs.writeFileSync(file, updatedContent, "utf-8");
97+
console.log(`Updated imports in: ${file}`);
98+
}
99+
}
100+
}
101+
102+
// Normalize file paths for consistent imports
103+
function normalizePath(p: string): string {
104+
return p.replace(/\\/g, "/").replace(/\.[tj]sx?$/, ""); // Ensure forward slashes and remove extensions
105+
}
106+
107+
// Format paths as relative imports
108+
function formatRelativePath(from: string, to: string): string {
109+
const relativePath = path.relative(path.dirname(from), to);
110+
return normalizePath(
111+
relativePath.startsWith(".") ? relativePath : `./${relativePath}`,
112+
); // Ensure ./ prefix
113+
}
114+
115+
// Escape special regex characters in paths
116+
function escapeRegex(string: string): string {
117+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
118+
}
119+
120+
// Get all project files iteratively
121+
function getAllFiles(rootDir: string, extensions: RegExp): string[] {
122+
const result: string[] = [];
123+
const stack: string[] = [rootDir];
124+
125+
while (stack.length > 0) {
126+
const currentDir = stack.pop()!;
127+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
128+
129+
for (const entry of entries) {
130+
const fullPath = path.join(currentDir, entry.name);
131+
132+
if (entry.isDirectory() && !entry.name.startsWith(".")) {
133+
stack.push(fullPath);
134+
} else if (extensions.test(entry.name)) {
135+
result.push(fullPath);
136+
}
137+
}
138+
}
139+
140+
return result;
141+
}
142+
143+
// Run the script
144+
const projectRoot = path.resolve("./src/shared/utils"); // Change as needed
145+
processFilesAndFolders(projectRoot);

src/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fastify, { type FastifyInstance } from "fastify";
33
import * as fs from "node:fs";
44
import path from "node:path";
55
import { URL } from "node:url";
6-
import { clearCacheCron } from "../shared/utils/cron/clearCacheCron";
6+
import { clearCacheCron } from "../shared/utils/cron/clear-cache-cron";
77
import { env } from "../shared/utils/env";
88
import { logger } from "../shared/utils/logger";
99
import { metricsServer } from "../shared/utils/prometheus";

src/server/middleware/auth.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import type { FastifyInstance } from "fastify";
1010
import type { FastifyRequest } from "fastify/types/request";
1111
import jsonwebtoken, { type JwtPayload } from "jsonwebtoken";
1212
import { validate as uuidValidate } from "uuid";
13-
import { getPermissions } from "../../shared/db/permissions/getPermissions";
14-
import { createToken } from "../../shared/db/tokens/createToken";
15-
import { revokeToken } from "../../shared/db/tokens/revokeToken";
13+
import { getPermissions } from "../../shared/db/permissions/get-permissions";
14+
import { createToken } from "../../shared/db/tokens/create-token";
15+
import { revokeToken } from "../../shared/db/tokens/revoke-token";
1616
import { WebhooksEventTypes } from "../../shared/schemas/webhooks";
1717
import { THIRDWEB_DASHBOARD_ISSUER, handleSiwe } from "../../shared/utils/auth";
18-
import { getAccessToken } from "../../shared/utils/cache/accessToken";
19-
import { getAuthWallet } from "../../shared/utils/cache/authWallet";
20-
import { getConfig } from "../../shared/utils/cache/getConfig";
21-
import { getWebhooksByEventType } from "../../shared/utils/cache/getWebhook";
18+
import { getAccessToken } from "../../shared/utils/cache/access-token";
19+
import { getAuthWallet } from "../../shared/utils/cache/auth-wallet";
20+
import { getConfig } from "../../shared/utils/cache/get-config";
21+
import { getWebhooksByEventType } from "../../shared/utils/cache/get-webhook";
2222
import { getKeypair } from "../../shared/utils/cache/keypair";
2323
import { env } from "../../shared/utils/env";
2424
import { logger } from "../../shared/utils/logger";

src/server/middleware/cors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FastifyInstance } from "fastify";
2-
import { getConfig } from "../../shared/utils/cache/getConfig";
2+
import { getConfig } from "../../shared/utils/cache/get-config";
33
import { ADMIN_QUEUES_BASEPATH } from "./adminRoutes";
44

55
const STANDARD_METHODS = "GET,POST,DELETE,PUT,PATCH,HEAD,PUT,PATCH,POST,DELETE";

src/server/routes/admin/nonces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
lastUsedNonceKey,
1313
recycledNoncesKey,
1414
sentNoncesKey,
15-
} from "../../../shared/db/wallets/walletNonce";
15+
} from "../../../shared/db/wallets/wallet-nonce";
1616
import { getChain } from "../../../shared/utils/chain";
1717
import { redis } from "../../../shared/utils/redis/redis";
1818
import { thirdwebClient } from "../../../shared/utils/sdk";

src/server/routes/admin/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { FastifyInstance } from "fastify";
44
import { StatusCodes } from "http-status-codes";
55
import { stringify } from "thirdweb/utils";
66
import { TransactionDB } from "../../../shared/db/transactions/db";
7-
import { getConfig } from "../../../shared/utils/cache/getConfig";
8-
import { maybeDate } from "../../../shared/utils/primitiveTypes";
7+
import { getConfig } from "../../../shared/utils/cache/get-config";
8+
import { maybeDate } from "../../../shared/utils/primitive-types";
99
import { redis } from "../../../shared/utils/redis/redis";
1010
import { MineTransactionQueue } from "../../../worker/queues/mineTransactionQueue";
1111
import { SendTransactionQueue } from "../../../worker/queues/sendTransactionQueue";

src/server/routes/auth/access-tokens/create.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { buildJWT } from "@thirdweb-dev/auth";
33
import { LocalWallet } from "@thirdweb-dev/wallets";
44
import type { FastifyInstance } from "fastify";
55
import { StatusCodes } from "http-status-codes";
6-
import { updateConfiguration } from "../../../../shared/db/configuration/updateConfiguration";
7-
import { createToken } from "../../../../shared/db/tokens/createToken";
8-
import { accessTokenCache } from "../../../../shared/utils/cache/accessToken";
9-
import { getConfig } from "../../../../shared/utils/cache/getConfig";
6+
import { updateConfiguration } from "../../../../shared/db/configuration/update-configuration";
7+
import { createToken } from "../../../../shared/db/tokens/create-token";
8+
import { accessTokenCache } from "../../../../shared/utils/cache/access-token";
9+
import { getConfig } from "../../../../shared/utils/cache/get-config";
1010
import { env } from "../../../../shared/utils/env";
1111
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
1212
import { AccessTokenSchema } from "./getAll";

src/server/routes/auth/access-tokens/getAll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { getAccessTokens } from "../../../../shared/db/tokens/getAccessTokens";
4+
import { getAccessTokens } from "../../../../shared/db/tokens/get-access-tokens";
55
import { AddressSchema } from "../../../schemas/address";
66
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
77

src/server/routes/auth/access-tokens/revoke.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { revokeToken } from "../../../../shared/db/tokens/revokeToken";
5-
import { accessTokenCache } from "../../../../shared/utils/cache/accessToken";
4+
import { revokeToken } from "../../../../shared/db/tokens/revoke-token";
5+
import { accessTokenCache } from "../../../../shared/utils/cache/access-token";
66
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
77

88
const requestBodySchema = Type.Object({

src/server/routes/auth/access-tokens/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { updateToken } from "../../../../shared/db/tokens/updateToken";
5-
import { accessTokenCache } from "../../../../shared/utils/cache/accessToken";
4+
import { updateToken } from "../../../../shared/db/tokens/update-token";
5+
import { accessTokenCache } from "../../../../shared/utils/cache/access-token";
66
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
77

88
const requestBodySchema = Type.Object({

src/server/routes/auth/permissions/grant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { updatePermissions } from "../../../../shared/db/permissions/updatePermissions";
4+
import { updatePermissions } from "../../../../shared/db/permissions/update-permissions";
55
import { AddressSchema } from "../../../schemas/address";
66
import { permissionsSchema } from "../../../../shared/schemas/auth";
77
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";

src/server/routes/auth/permissions/revoke.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { deletePermissions } from "../../../../shared/db/permissions/deletePermissions";
4+
import { deletePermissions } from "../../../../shared/db/permissions/delete-permissions";
55
import { AddressSchema } from "../../../schemas/address";
66
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
77

src/server/routes/backend-wallet/cancel-nonces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { eth_getTransactionCount, getRpcClient } from "thirdweb";
55
import { checksumAddress } from "thirdweb/utils";
66
import { getChain } from "../../../shared/utils/chain";
77
import { thirdwebClient } from "../../../shared/utils/sdk";
8-
import { sendCancellationTransaction } from "../../../shared/utils/transaction/cancelTransaction";
8+
import { sendCancellationTransaction } from "../../../shared/utils/transaction/cancel-transaction";
99
import {
1010
requestQuerystringSchema,
1111
standardResponseSchema,

src/server/routes/backend-wallet/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ENTRYPOINT_ADDRESS_v0_7,
88
} from "thirdweb/wallets/smart";
99
import { WalletType } from "../../../shared/schemas/wallet";
10-
import { getConfig } from "../../../shared/utils/cache/getConfig";
10+
import { getConfig } from "../../../shared/utils/cache/get-config";
1111
import { createCustomError } from "../../middleware/error";
1212
import { AddressSchema } from "../../schemas/address";
1313
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";

src/server/routes/backend-wallet/getAll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { getAllWallets } from "../../../shared/db/wallets/getAllWallets";
4+
import { getAllWallets } from "../../../shared/db/wallets/get-all-wallets";
55
import {
66
standardResponseSchema,
77
walletDetailsSchema,

src/server/routes/backend-wallet/getBalance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type Static, Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { getSdk } from "../../../shared/utils/cache/getSdk";
4+
import { getSdk } from "../../../shared/utils/cache/get-sdk";
55
import { AddressSchema } from "../../schemas/address";
66
import {
77
currencyValueSchema,

src/server/routes/backend-wallet/getNonce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import type { Address } from "thirdweb";
5-
import { inspectNonce } from "../../../shared/db/wallets/walletNonce";
5+
import { inspectNonce } from "../../../shared/db/wallets/wallet-nonce";
66
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
77
import { walletWithAddressParamSchema } from "../../schemas/wallet";
88
import { getChainIdFromChain } from "../../utils/chain";

src/server/routes/backend-wallet/getTransactionsByNonce.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { TransactionDB } from "../../../shared/db/transactions/db";
5-
import { getNonceMap } from "../../../shared/db/wallets/nonceMap";
6-
import { normalizeAddress } from "../../../shared/utils/primitiveTypes";
5+
import { getNonceMap } from "../../../shared/db/wallets/nonce-map";
6+
import { normalizeAddress } from "../../../shared/utils/primitive-types";
77
import type { AnyTransaction } from "../../../shared/utils/transaction/types";
88
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
99
import {

src/server/routes/backend-wallet/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { getConfig } from "../../../shared/utils/cache/getConfig";
4+
import { getConfig } from "../../../shared/utils/cache/get-config";
55
import { createCustomError } from "../../middleware/error";
66
import { AddressSchema } from "../../schemas/address";
77
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";

src/server/routes/backend-wallet/remove.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type Static, Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import type { Address } from "thirdweb";
5-
import { deleteWalletDetails } from "../../../shared/db/wallets/deleteWalletDetails";
5+
import { deleteWalletDetails } from "../../../shared/db/wallets/delete-wallet-details";
66
import { AddressSchema } from "../../schemas/address";
77
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
88

src/server/routes/backend-wallet/reset-nonces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
deleteNoncesForBackendWallets,
77
getUsedBackendWallets,
88
syncLatestNonceFromOnchain,
9-
} from "../../../shared/db/wallets/walletNonce";
9+
} from "../../../shared/db/wallets/wallet-nonce";
1010
import { AddressSchema } from "../../schemas/address";
1111
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
1212

src/server/routes/backend-wallet/sendTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import type { Address, Hex } from "thirdweb";
5-
import { insertTransaction } from "../../../shared/utils/transaction/insertTransaction";
5+
import { insertTransaction } from "../../../shared/utils/transaction/insert-transaction";
66
import { AddressSchema } from "../../schemas/address";
77
import {
88
requestQuerystringSchema,

src/server/routes/backend-wallet/sendTransactionBatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Type, type Static } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import type { Address, Hex } from "thirdweb";
5-
import { insertTransaction } from "../../../shared/utils/transaction/insertTransaction";
5+
import { insertTransaction } from "../../../shared/utils/transaction/insert-transaction";
66
import { AddressSchema } from "../../schemas/address";
77
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
88
import { txOverridesWithValueSchema } from "../../schemas/txOverrides";

src/server/routes/backend-wallet/signMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { arbitrumSepolia } from "thirdweb/chains";
66
import {
77
getWalletDetails,
88
isSmartBackendWallet,
9-
} from "../../../shared/db/wallets/getWalletDetails";
9+
} from "../../../shared/db/wallets/get-wallet-details";
1010
import { walletDetailsToAccount } from "../../../shared/utils/account";
1111
import { getChain } from "../../../shared/utils/chain";
1212
import { createCustomError } from "../../middleware/error";

src/server/routes/backend-wallet/signTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getChecksumAddress,
88
maybeBigInt,
99
maybeInt,
10-
} from "../../../shared/utils/primitiveTypes";
10+
} from "../../../shared/utils/primitive-types";
1111
import { toTransactionType } from "../../../shared/utils/sdk";
1212
import { createCustomError } from "../../middleware/error";
1313
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";

src/server/routes/backend-wallet/signTypedData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { TypedDataSigner } from "@ethersproject/abstract-signer";
22
import { type Static, Type } from "@sinclair/typebox";
33
import type { FastifyInstance } from "fastify";
44
import { StatusCodes } from "http-status-codes";
5-
import { getWallet } from "../../../shared/utils/cache/getWallet";
5+
import { getWallet } from "../../../shared/utils/cache/get-wallet";
66
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
77
import { walletHeaderSchema } from "../../schemas/wallet";
88

0 commit comments

Comments
 (0)