diff --git a/deno.json b/deno.json deleted file mode 100644 index 90f67fd5..00000000 --- a/deno.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "fmt": { - "useTabs": true - } -} diff --git a/deno.jsonc b/deno.jsonc new file mode 100644 index 00000000..c95c57d3 --- /dev/null +++ b/deno.jsonc @@ -0,0 +1,46 @@ +{ + "tasks": { + // Format + "format": "deno fmt modules/", + "format:check": "deno fmt --check modules/", + + // Check + "check": "deno check modules/**/*.ts", + + // Lint + "lint": "deno lint modules/", + "lint:fix": "deno lint --fix modules/" + }, + "lint": { + "include": ["src/"], + "exclude": ["tests/"], + "rules": { + "exclude": ["no-empty-interface", "no-explicit-any", "require-await"] + } + }, + "fmt": { + "useTabs": true + }, + "compilerOptions": { + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "useUnknownInCatchVariables": true, + "alwaysStrict": true, + // "noUnusedLocals": true, + // "noUnusedParameters": true, + // "exactOptionalPropertyTypes": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + // "noPropertyAccessFromIndexSignature": true, + "allowUnusedLabels": true, + "allowUnreachableCode": true, + "noImplicitAny": true + } +} diff --git a/modules/email/config.ts b/modules/email/config.ts index 59d9a7ae..ee607926 100644 --- a/modules/email/config.ts +++ b/modules/email/config.ts @@ -4,9 +4,7 @@ export interface Config { export type Provider = { test: ProviderTest } | { sendGrid: ProviderSendGrid }; -export interface ProviderTest { - // No configuration -} +export type ProviderTest = Record; export interface ProviderSendGrid { apiKeyVariable?: string; diff --git a/modules/email/scripts/send_email.ts b/modules/email/scripts/send_email.ts index ab717c91..5c912f18 100644 --- a/modules/email/scripts/send_email.ts +++ b/modules/email/scripts/send_email.ts @@ -14,8 +14,7 @@ export interface Request { text?: string; } -export interface Response { -} +export type Response = Record; export async function run( ctx: ScriptContext, diff --git a/modules/friends/scripts/accept_request.ts b/modules/friends/scripts/accept_request.ts index a852dd39..3f35b035 100644 --- a/modules/friends/scripts/accept_request.ts +++ b/modules/friends/scripts/accept_request.ts @@ -57,7 +57,7 @@ export async function run( } // Sort the user IDs to ensure consistency - const [userIdA, userIdB] = [ + const userIds = [ friendRequest.senderUserId, friendRequest.targetUserId, ].sort(); @@ -70,7 +70,7 @@ export async function run( data: { acceptedAt: new Date(), friend: { - create: { userIdA, userIdB }, + create: { userIdA: userIds[0]!, userIdB: userIds[1]! }, }, }, }); diff --git a/modules/friends/scripts/remove_friend.ts b/modules/friends/scripts/remove_friend.ts index db3c633d..ac4cc3d2 100644 --- a/modules/friends/scripts/remove_friend.ts +++ b/modules/friends/scripts/remove_friend.ts @@ -18,11 +18,11 @@ export async function run( }); // Sort the user IDs to ensure consistency - const [userIdA, userIdB] = [userId, req.targetUserId].sort(); + const userIds = [userId, req.targetUserId].sort(); const updated = await ctx.db.friend.update({ where: { - userIdA_userIdB: { userIdA, userIdB }, + userIdA_userIdB: { userIdA: userIds[0]!, userIdB: userIds[1]! }, removedAt: null, }, data: { @@ -31,7 +31,9 @@ export async function run( select: { userIdA: true, userIdB: true }, }); if (!updated) { - throw new RuntimeError("FRIEND_NOT_FOUND", { meta: { userIdA, userIdB } }); + throw new RuntimeError("FRIEND_NOT_FOUND", { + meta: { userIdA: userIds[0], userIdB: userIds[1] }, + }); } return {}; diff --git a/modules/tokens/scripts/create.ts b/modules/tokens/scripts/create.ts index 9945cce9..ef5fc5a7 100644 --- a/modules/tokens/scripts/create.ts +++ b/modules/tokens/scripts/create.ts @@ -52,7 +52,7 @@ function generateToken(type: string): string { // Map to characters let output = ""; for (let i = 0; i < buf.length; i++) { - output += CHARACTERS[buf[i] % CHARACTERS.length]; + output += CHARACTERS[buf[i]! % CHARACTERS.length]; } return `${type}_${output}`; diff --git a/modules/tokens/scripts/revoke.ts b/modules/tokens/scripts/revoke.ts index 18d2a1c5..40f2a743 100644 --- a/modules/tokens/scripts/revoke.ts +++ b/modules/tokens/scripts/revoke.ts @@ -1,4 +1,4 @@ -import { Prisma, ScriptContext } from "../module.gen.ts"; +import { ScriptContext } from "../module.gen.ts"; export interface Request { tokenIds: string[]; diff --git a/modules/tokens/tests/e2e.ts b/modules/tokens/tests/e2e.ts index 9be2f24b..bdf59754 100644 --- a/modules/tokens/tests/e2e.ts +++ b/modules/tokens/tests/e2e.ts @@ -35,7 +35,7 @@ test("e2e", async (ctx: TestContext) => { const getAfterRevoke = await ctx.modules.tokens.fetch({ tokenIds: [token.id], }); - assertExists(getAfterRevoke.tokens[0].revokedAt); + assertExists(getAfterRevoke.tokens[0]!.revokedAt); const revokeTwiceRes = await ctx.modules.tokens.revoke({ tokenIds: [token.id], diff --git a/modules/uploads/tests/e2e.ts b/modules/uploads/tests/e2e.ts index 4fbe8ad3..158d28b7 100644 --- a/modules/uploads/tests/e2e.ts +++ b/modules/uploads/tests/e2e.ts @@ -34,7 +34,7 @@ test("e2e", async (ctx: TestContext) => { // Upload the data using the presigned URL(s) returned const uploadPutReq = await fetch( - presigned.files[0].presignedChunks[0].url, + presigned.files[0]!.presignedChunks[0]!.url, { method: "PUT", body: fileData, @@ -77,10 +77,11 @@ test("e2e", async (ctx: TestContext) => { assertEquals(completed, retrieved); // Get presigned URLs to download the files from - const { files: [{ url: fileDownloadUrl }] } = await ctx.modules.uploads + const { files } = await ctx.modules.uploads .getPublicFileUrls({ files: [{ uploadId: completed.id, path: path }], }); + const fileDownloadUrl = files[0]!.url; // Download the files, and make sure the data matches const fileDownloadReq = await fetch(fileDownloadUrl); diff --git a/modules/uploads/tests/multipart.ts b/modules/uploads/tests/multipart.ts index c3ee4cc9..5518a3ab 100644 --- a/modules/uploads/tests/multipart.ts +++ b/modules/uploads/tests/multipart.ts @@ -41,8 +41,7 @@ test("multipart uploads", async (ctx: TestContext) => { }, ], }); - - const { files: [{ presignedChunks }] } = presigned; + const presignedChunks = presigned.files[0]!.presignedChunks; for (const chunk of presignedChunks) { // Upload the data using the presigned URL(s) returned @@ -94,10 +93,11 @@ test("multipart uploads", async (ctx: TestContext) => { assertEquals(completed, retrieved); // Get presigned URLs to download the files from - const { files: [{ url: fileDownloadUrl }] } = await ctx.modules.uploads + const { files } = await ctx.modules.uploads .getPublicFileUrls({ files: [{ uploadId: completed.id, path: path }], }); + const fileDownloadUrl = files[0]!.url; // Download the files, and make sure the data matches const fileDownloadReq = await fetch(fileDownloadUrl); diff --git a/modules/uploads/utils/bucket.ts b/modules/uploads/utils/bucket.ts index 30a517fb..e4b029cf 100644 --- a/modules/uploads/utils/bucket.ts +++ b/modules/uploads/utils/bucket.ts @@ -235,7 +235,7 @@ export async function keyExists( await client.send(command); return true; } catch (error) { - if (error.name === "NotFound") { + if (error instanceof Error && error.name === "NotFound") { return false; } throw error; diff --git a/tests/basic/deno.json b/tests/basic/deno.json deleted file mode 100644 index 12f4307e..00000000 --- a/tests/basic/deno.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "lint": { - "include": [ - "src/" - ], - "exclude": [ - "tests/" - ], - "rules": { - "exclude": [ - "no-empty-interface", - "no-explicit-any", - "require-await" - ] - } - }, - "fmt": { - "useTabs": true - } -} \ No newline at end of file diff --git a/tests/basic/deno.lock b/tests/basic/deno.lock index f493f1ee..a6304c20 100644 --- a/tests/basic/deno.lock +++ b/tests/basic/deno.lock @@ -4,7 +4,9 @@ "specifiers": { "npm:@prisma/adapter-pg@^5.12.0": "npm:@prisma/adapter-pg@5.15.0_pg@8.12.0", "npm:@types/node": "npm:@types/node@18.16.19", - "npm:pg@^8.11.3": "npm:pg@8.12.0" + "npm:pg@^8.11.3": "npm:pg@8.12.0", + "npm:zod-validation-error@3.3.0": "npm:zod-validation-error@3.3.0_zod@3.23.8", + "npm:zod@3.23.8": "npm:zod@3.23.8" }, "npm": { "@prisma/adapter-pg@5.15.0_pg@8.12.0": { @@ -107,6 +109,16 @@ "xtend@4.0.2": { "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", "dependencies": {} + }, + "zod-validation-error@3.3.0_zod@3.23.8": { + "integrity": "sha512-Syib9oumw1NTqEv4LT0e6U83Td9aVRk9iTXPUQr1otyV1PuXQKOvOwhMNqZIq5hluzHP2pMgnOmHEo7kPdI2mw==", + "dependencies": { + "zod": "zod@3.23.8" + } + }, + "zod@3.23.8": { + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "dependencies": {} } } },