From 1d11e92cb754816f5f0036c2abb1e0704df58141 Mon Sep 17 00:00:00 2001 From: Lee Danilek Date: Fri, 3 Jan 2025 12:20:55 -0500 Subject: [PATCH] `npm run format` (#35) * . * . * . --- .github/workflows/node.js.yml | 2 +- compare.ts | 11 ++++----- convex/argumentsValidation.test.ts | 14 +++++------- convex/argumentsValidation.ts | 9 +++++--- convex/component.ts | 10 ++++++--- convex/components.test.ts | 6 +---- convex/messages.test.ts | 10 +++++---- convex/mutations.test.ts | 11 ++++++--- convex/mutations.ts | 36 ++++++++++++++++++++++-------- convex/pagination.test.ts | 6 ++++- convex/scheduler.test.ts | 8 +++---- convex/scheduler.ts | 8 +++++-- counter/component/public.ts | 6 ++++- package.json | 3 ++- 14 files changed, 90 insertions(+), 50 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 650a729..968c943 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -18,5 +18,5 @@ jobs: cache: "npm" - run: npm i - run: npm ci + - run: npm run lint - run: npm test - diff --git a/compare.ts b/compare.ts index 059d221..d2719da 100644 --- a/compare.ts +++ b/compare.ts @@ -21,10 +21,10 @@ function compareSameTypeValues(v1: T, v2: T): number { return 0; } if ( - typeof v1 === "bigint" - || typeof v1 === "number" - || typeof v1 === "boolean" - || typeof v1 === "string" + typeof v1 === "bigint" || + typeof v1 === "number" || + typeof v1 === "boolean" || + typeof v1 === "string" ) { return v1 < v2 ? -1 : v1 === v2 ? 0 : 1; } @@ -61,7 +61,8 @@ function makeComparable(v: Value | undefined): [number, any] { return [2, v]; } if (typeof v === "number") { - if (isNaN(v)) { // Consider all NaNs to be equal. + if (isNaN(v)) { + // Consider all NaNs to be equal. return [3.5, 0]; } return [3, v]; diff --git a/convex/argumentsValidation.test.ts b/convex/argumentsValidation.test.ts index be20676..fbb567c 100644 --- a/convex/argumentsValidation.test.ts +++ b/convex/argumentsValidation.test.ts @@ -6,7 +6,6 @@ import counterSchema from "../counter/component/schema"; const counterModules = import.meta.glob("../counter/component/**/*.ts"); - test("query arguments validation", async () => { const t = convexTest(schema); await expect( @@ -50,25 +49,24 @@ test("optional fields", async () => { function testWithCounter() { const t = convexTest(schema); - t.registerComponent( - "counter", - counterSchema, - counterModules - ); + t.registerComponent("counter", counterSchema, counterModules); return t; } test("component mutation arguments validation", async () => { const t = testWithCounter(); expect( - await t.mutation(api.argumentsValidation.componentMutationWithNumberArg, { a: 42 }) + await t.mutation(api.argumentsValidation.componentMutationWithNumberArg, { + a: 42, + }), ).toEqual(42); await expect( t.mutation(api.argumentsValidation.componentMutationWithNumberArg, { a: "bad" as any, }), ).rejects.toThrowError(/Validator error/); - expect(await t.mutation(api.argumentsValidation.componentMutationWithNumberArg, { + expect( + await t.mutation(api.argumentsValidation.componentMutationWithNumberArg, { a: Number.POSITIVE_INFINITY, }), ).toEqual(Number.POSITIVE_INFINITY); diff --git a/convex/argumentsValidation.ts b/convex/argumentsValidation.ts index dced37a..2328aec 100644 --- a/convex/argumentsValidation.ts +++ b/convex/argumentsValidation.ts @@ -47,9 +47,12 @@ export const queryWithOptionalArgs = query({ export const componentMutationWithNumberArg = mutation({ args: { a: v.any() }, handler: (ctx, args) => { - const result = ctx.runMutation(components.counter.public.mutationWithNumberArg, { - a: args.a, - }); + const result = ctx.runMutation( + components.counter.public.mutationWithNumberArg, + { + a: args.a, + }, + ); return result; }, }); diff --git a/convex/component.ts b/convex/component.ts index 0b9c8be..5ac988a 100644 --- a/convex/component.ts +++ b/convex/component.ts @@ -25,7 +25,9 @@ export const directCall = internalMutation({ export const mutationWithNestedQuery = internalMutation({ args: {}, handler: async (ctx, _args): Promise => { - return await ctx.runMutation(components.counter.public.mutationWithNestedQuery); + return await ctx.runMutation( + components.counter.public.mutationWithNestedQuery, + ); }, }); @@ -42,7 +44,9 @@ export const directCall2 = internalQuery({ export const schedule = internalMutation({ args: {}, handler: async (ctx, _args) => { - await ctx.runMutation(components.counter.public.schedule, { name: "beans" }); + await ctx.runMutation(components.counter.public.schedule, { + name: "beans", + }); }, }); @@ -80,4 +84,4 @@ export const scheduleHandle = internalMutation({ { name: "beans", count: 3 }, ); }, -}); \ No newline at end of file +}); diff --git a/convex/components.test.ts b/convex/components.test.ts index 0a85a77..6f06971 100644 --- a/convex/components.test.ts +++ b/convex/components.test.ts @@ -10,11 +10,7 @@ const counterModules = import.meta.glob("../counter/component/**/*.ts"); function testWithCounter() { const t = convexTest(schema); - t.registerComponent( - "counter", - counterSchema, - counterModules - ); + t.registerComponent("counter", counterSchema, counterModules); return t; } diff --git a/convex/messages.test.ts b/convex/messages.test.ts index 7f1a9a8..dc88403 100644 --- a/convex/messages.test.ts +++ b/convex/messages.test.ts @@ -52,14 +52,16 @@ test("all types serde", async () => { expect(byGet).not.toBeNull(); expectBodiesEq(byGet!.body, body); // Indexed db.query - const byIndex = await ctx.db.query("messages") - .withIndex("body", q=>q.eq("body", body)) + const byIndex = await ctx.db + .query("messages") + .withIndex("body", (q) => q.eq("body", body)) .unique(); expect(byIndex).not.toBeNull(); expectBodiesEq(byIndex!.body, body); // Filtered db.query - const byFilter = await ctx.db.query("messages") - .filter(q=>q.eq(q.field("body"), body)) + const byFilter = await ctx.db + .query("messages") + .filter((q) => q.eq(q.field("body"), body)) .unique(); expect(byFilter).not.toBeNull(); expectBodiesEq(byFilter!.body, body); diff --git a/convex/mutations.test.ts b/convex/mutations.test.ts index 7aef184..bef7974 100644 --- a/convex/mutations.test.ts +++ b/convex/mutations.test.ts @@ -106,7 +106,6 @@ test("patch undefined", async () => { expect(embedding).toBeUndefined(); }); - test("replace after insert", async () => { const t = convexTest(schema); const messages = await t.run(async (ctx) => { @@ -169,12 +168,18 @@ test("subtransaction commit then rollback parent", async () => { // Regression test, making sure we merge writes in the correct order. test("insert then patch in subtransaction", async () => { const t = convexTest(schema); - const result = await t.mutation(api.mutations.insertThenPatchInSubtransaction, {}); + const result = await t.mutation( + api.mutations.insertThenPatchInSubtransaction, + {}, + ); expect(result).toEqual(["hi"]); }); test("insert then delete in subtransaction", async () => { const t = convexTest(schema); - const result = await t.mutation(api.mutations.insertThenDeleteInSubtransaction, {}); + const result = await t.mutation( + api.mutations.insertThenDeleteInSubtransaction, + {}, + ); expect(result).toEqual([]); }); diff --git a/convex/mutations.ts b/convex/mutations.ts index 9713966..1d95f94 100644 --- a/convex/mutations.ts +++ b/convex/mutations.ts @@ -72,7 +72,10 @@ export const rolledBackSubtransaction = mutation({ handler: async (ctx) => { await ctx.db.insert("messages", { body: "hello", author: "sarah" }); try { - await ctx.runMutation(api.mutations.throws, { body: "hello", author: "lee" }); + await ctx.runMutation(api.mutations.throws, { + body: "hello", + author: "lee", + }); } catch (e) { // ignore } @@ -85,8 +88,14 @@ export const rolledBackSubtransaction = mutation({ export const subtransactionCommitThenRollbackParent = mutation({ args: {}, handler: async (ctx) => { - await ctx.runMutation(api.mutations.insert, { body: "hello", author: "sarah" }); - await ctx.runMutation(api.mutations.throws, { body: "hello", author: "lee" }); + await ctx.runMutation(api.mutations.insert, { + body: "hello", + author: "sarah", + }); + await ctx.runMutation(api.mutations.throws, { + body: "hello", + author: "lee", + }); }, }); @@ -95,14 +104,20 @@ export const patchAndRead = mutation({ handler: async (ctx, { id, body }): Promise => { await ctx.db.patch(id, { body }); return (await ctx.db.query("messages").collect()).map(({ body }) => body); - } + }, }); export const insertThenPatchInSubtransaction = mutation({ args: {}, handler: async (ctx): Promise => { - const id = await ctx.db.insert("messages", { body: "hello", author: "sarah" }); - return await ctx.runMutation(api.mutations.patchAndRead, { id, body: "hi" }); + const id = await ctx.db.insert("messages", { + body: "hello", + author: "sarah", + }); + return await ctx.runMutation(api.mutations.patchAndRead, { + id, + body: "hi", + }); }, }); @@ -111,13 +126,16 @@ export const deleteAndRead = mutation({ handler: async (ctx, { id }): Promise => { await ctx.db.delete(id); return (await ctx.db.query("messages").collect()).map(({ body }) => body); - } + }, }); export const insertThenDeleteInSubtransaction = mutation({ args: {}, handler: async (ctx): Promise => { - const id = await ctx.db.insert("messages", { body: "hello", author: "sarah" }); + const id = await ctx.db.insert("messages", { + body: "hello", + author: "sarah", + }); return await ctx.runMutation(api.mutations.deleteAndRead, { id }); }, -}); \ No newline at end of file +}); diff --git a/convex/pagination.test.ts b/convex/pagination.test.ts index c1f9755..4e5126c 100644 --- a/convex/pagination.test.ts +++ b/convex/pagination.test.ts @@ -26,7 +26,11 @@ test("paginate", async () => { { author: "sarah", body: "hello2" }, ]); expect(isDone).toEqual(false); - const { continueCursor: continueCursor2, isDone: isDone2, page: page2 } = await t.query(api.pagination.list, { + const { + continueCursor: continueCursor2, + isDone: isDone2, + page: page2, + } = await t.query(api.pagination.list, { author: "sarah", paginationOptions: { cursor: continueCursor, diff --git a/convex/scheduler.test.ts b/convex/scheduler.test.ts index c276ad5..1512d2d 100644 --- a/convex/scheduler.test.ts +++ b/convex/scheduler.test.ts @@ -170,9 +170,9 @@ test("self-scheduling mutation", async () => { const t = convexTest(schema); await t.mutation(api.scheduler.selfSchedulingMutation, {}); - await expect(t.finishAllScheduledFunctions(vi.runAllTimers)) - .rejects - .toThrowError(/Check for infinitely recursive scheduled functions/); + await expect( + t.finishAllScheduledFunctions(vi.runAllTimers), + ).rejects.toThrowError(/Check for infinitely recursive scheduled functions/); vi.useRealTimers(); -}); \ No newline at end of file +}); diff --git a/convex/scheduler.ts b/convex/scheduler.ts index 8d206f2..87c6da9 100644 --- a/convex/scheduler.ts +++ b/convex/scheduler.ts @@ -103,6 +103,10 @@ export const actionSchedulingActionNTimes = action({ export const selfSchedulingMutation = mutation({ args: {}, handler: async (ctx) => { - await ctx.scheduler.runAfter(1000, api.scheduler.selfSchedulingMutation, {}); + await ctx.scheduler.runAfter( + 1000, + api.scheduler.selfSchedulingMutation, + {}, + ); }, -}); \ No newline at end of file +}); diff --git a/counter/component/public.ts b/counter/component/public.ts index 95b01a4..e8e7bfc 100644 --- a/counter/component/public.ts +++ b/counter/component/public.ts @@ -57,7 +57,11 @@ export const schedule = mutation({ export const mutationWithNestedQuery = mutation({ args: {}, handler: async (ctx, _args) => { - const id = await ctx.db.insert("counters", { name: "beans", value: 3, shard: 0 }); + const id = await ctx.db.insert("counters", { + name: "beans", + value: 3, + shard: 0, + }); await ctx.runQuery(api.public.count, { name: "beans" }); const doc = await ctx.db.get(id); return doc!.value; diff --git a/package.json b/package.json index c728eed..46bc1e6 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,10 @@ "dist/*.map" ], "scripts": { + "format": "prettier --write .", "prebuild": "npm run lint && npm run test:once", "build": "tsc && replace-in-file '\"./convex/**/*.*s\"' '\"../../../convex/**/*.*s\"' ./dist/index.js", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 && prettier --check .", "test": "vitest", "test:once": "vitest run", "test:debug": "vitest --inspect-brk --no-file-parallelism",