From aacc0ce90f1ab59ebc8eb2b44c668611b3f2dcaf Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Fri, 19 Aug 2022 10:13:33 -0700 Subject: [PATCH] Tweak Convex example (#39739) This is a followup to #39562 because I realized I made a few mistakes. Remove convex.json file. Developers using the example should generate this on their own by running npx convex init. Switch prettier to a dev dependency. Ignore formatting in Convex generated code while running lint-staged and revert them back to the default generated form (I previously was only ignoring generated code in the main .prettierignore) Change a let to a const cc @thomasballinger Documentation / Examples Make sure the linting passes by running pnpm lint The examples guidelines are followed from our contributing doc --- .prettierignore_staged | 3 +- examples/convex/convex.json | 6 ---- .../convex/convex/_generated/dataModel.ts | 14 +++++----- examples/convex/convex/_generated/react.ts | 28 +++++++++---------- examples/convex/convex/_generated/server.ts | 16 +++++------ examples/convex/convex/incrementCounter.ts | 2 +- examples/convex/package.json | 2 +- 7 files changed, 33 insertions(+), 38 deletions(-) delete mode 100644 examples/convex/convex.json diff --git a/.prettierignore_staged b/.prettierignore_staged index f6426b02078e0c9..2ad75e98a1e2fd9 100644 --- a/.prettierignore_staged +++ b/.prettierignore_staged @@ -7,4 +7,5 @@ packages/next/bundles/webpack/packages/*.runtime.js lerna.json packages/next-codemod/transforms/__testfixtures__/**/* packages/next-codemod/transforms/__tests__/**/* -pnpm-lock.yaml \ No newline at end of file +pnpm-lock.yaml +**/convex/_generated/** diff --git a/examples/convex/convex.json b/examples/convex/convex.json deleted file mode 100644 index 4f972abd4642f0d..000000000000000 --- a/examples/convex/convex.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "authInfo": [], - "functions": "convex/", - "instanceName": "handsome-turtle-915", - "origin": "https://handsome-turtle-915.convex.cloud" -} diff --git a/examples/convex/convex/_generated/dataModel.ts b/examples/convex/convex/_generated/dataModel.ts index 2f229880ec7cfd7..87c7cb3c1fbefef 100644 --- a/examples/convex/convex/_generated/dataModel.ts +++ b/examples/convex/convex/_generated/dataModel.ts @@ -9,8 +9,8 @@ * @module */ -import { AnyDataModel } from 'convex/server' -import { GenericId } from 'convex/values' +import { AnyDataModel } from "convex/server"; +import { GenericId } from "convex/values"; /** * No `schema.ts` file found! @@ -26,12 +26,12 @@ import { GenericId } from 'convex/values' /** * The names of all of your Convex tables. */ -export type TableNames = string +export type TableNames = string; /** * The type of a document stored in Convex. */ -export type Document = any +export type Document = any; /** * An identifier for a document in Convex. @@ -45,8 +45,8 @@ export type Document = any * Using `===` will not work because two different instances of `Id` can refer * to the same document. */ -export type Id = GenericId -export const Id = GenericId +export type Id = GenericId; +export const Id = GenericId; /** * A type describing your Convex data model. @@ -57,4 +57,4 @@ export const Id = GenericId * This type is used to parameterize methods like `queryGeneric` and * `mutationGeneric` to make them type-safe. */ -export type DataModel = AnyDataModel +export type DataModel = AnyDataModel; diff --git a/examples/convex/convex/_generated/react.ts b/examples/convex/convex/_generated/react.ts index 1859ea22336cd59..0ed0e5634a0ccec 100644 --- a/examples/convex/convex/_generated/react.ts +++ b/examples/convex/convex/_generated/react.ts @@ -9,10 +9,10 @@ * @module */ -import type getCounter from '../getCounter' -import type incrementCounter from '../incrementCounter' -import type { OptimisticLocalStore as GenericOptimisticLocalStore } from 'convex/browser' -import type { ClientMutation, ClientQuery } from 'convex/server' +import type getCounter from "../getCounter"; +import type incrementCounter from "../incrementCounter"; +import type { OptimisticLocalStore as GenericOptimisticLocalStore } from "convex/browser"; +import type { ClientMutation, ClientQuery } from "convex/server"; /** * A type describing your app's public Convex API. @@ -25,14 +25,14 @@ import type { ClientMutation, ClientQuery } from 'convex/server' */ export type ConvexAPI = { queries: { - getCounter: ClientQuery - } + getCounter: ClientQuery; + }; mutations: { - incrementCounter: ClientMutation - } -} + incrementCounter: ClientMutation; + }; +}; -import { makeUseQuery, makeUseMutation, makeUseConvex } from 'convex/react' +import { makeUseQuery, makeUseMutation, makeUseConvex } from "convex/react"; /** * Load a reactive query within a React component. @@ -46,7 +46,7 @@ import { makeUseQuery, makeUseMutation, makeUseConvex } from 'convex/react' * @param args - The arguments to the query function. * @returns `undefined` if loading and the query's return value otherwise. */ -export const useQuery = makeUseQuery() +export const useQuery = makeUseQuery(); /** * Construct a new {@link ReactMutation}. @@ -64,7 +64,7 @@ export const useQuery = makeUseQuery() * @param name - The name of the mutation. * @returns The {@link ReactMutation} object with that name. */ -export const useMutation = makeUseMutation() +export const useMutation = makeUseMutation(); /** * Get the {@link ConvexReactClient} within a React component. @@ -73,10 +73,10 @@ export const useMutation = makeUseMutation() * * @returns The active {@link ConvexReactClient} object, or `undefined`. */ -export const useConvex = makeUseConvex() +export const useConvex = makeUseConvex(); /** * A view of the query results currently in the Convex client for use within * optimistic updates. */ -export type OptimisticLocalStore = GenericOptimisticLocalStore +export type OptimisticLocalStore = GenericOptimisticLocalStore; diff --git a/examples/convex/convex/_generated/server.ts b/examples/convex/convex/_generated/server.ts index 833b51dcc8ef08e..0e8d913bbd0a73a 100644 --- a/examples/convex/convex/_generated/server.ts +++ b/examples/convex/convex/_generated/server.ts @@ -16,8 +16,8 @@ import { MutationCtx as GenericMutationCtx, DatabaseReader as GenericDatabaseReader, DatabaseWriter as GenericDatabaseWriter, -} from 'convex/server' -import { DataModel } from './dataModel.js' +} from "convex/server"; +import { DataModel } from "./dataModel.js"; /** * Define a query in this Convex app's public API. @@ -27,7 +27,7 @@ import { DataModel } from './dataModel.js' * @param func - The query function. It receives a {@link QueryCtx} as its first argument. * @returns The wrapped query. Include this as an `export` to name it and make it accessible. */ -export const query = makeQuery() +export const query = makeQuery(); /** * Define a mutation in this Convex app's public API. @@ -37,7 +37,7 @@ export const query = makeQuery() * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument. * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible. */ -export const mutation = makeMutation() +export const mutation = makeMutation(); /** * A set of services for use within Convex query functions. @@ -48,7 +48,7 @@ export const mutation = makeMutation() * This differs from the {@link MutationCtx} because all of the services are * read-only. */ -export type QueryCtx = GenericQueryCtx +export type QueryCtx = GenericQueryCtx; /** * A set of services for use within Convex mutation functions. @@ -56,7 +56,7 @@ export type QueryCtx = GenericQueryCtx * The mutation context is passed as the first argument to any Convex mutation * function run on the server. */ -export type MutationCtx = GenericMutationCtx +export type MutationCtx = GenericMutationCtx; /** * An interface to read from the database within Convex query functions. @@ -65,7 +65,7 @@ export type MutationCtx = GenericMutationCtx * document by its {@link Id}, or {@link DatabaseReader.table}, which starts * building a query. */ -export type DatabaseReader = GenericDatabaseReader +export type DatabaseReader = GenericDatabaseReader; /** * An interface to read from and write to the database within Convex mutation @@ -76,4 +76,4 @@ export type DatabaseReader = GenericDatabaseReader * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control) * for the guarantees Convex provides your functions. */ -export type DatabaseWriter = GenericDatabaseWriter +export type DatabaseWriter = GenericDatabaseWriter; diff --git a/examples/convex/convex/incrementCounter.ts b/examples/convex/convex/incrementCounter.ts index 8e43836c7048f68..b7f6d035883de2c 100644 --- a/examples/convex/convex/incrementCounter.ts +++ b/examples/convex/convex/incrementCounter.ts @@ -2,7 +2,7 @@ import { mutation } from './_generated/server' export default mutation( async ({ db }, counterName: string, increment: number) => { - let counterDoc = await db + const counterDoc = await db .table('counter_table') .filter((q) => q.eq(q.field('name'), counterName)) .first() diff --git a/examples/convex/package.json b/examples/convex/package.json index 24cb00227708b0c..2ad3f092106e0ce 100644 --- a/examples/convex/package.json +++ b/examples/convex/package.json @@ -8,7 +8,6 @@ "dependencies": { "convex": "latest", "next": "latest", - "prettier": "^2.7.1", "react": "^18.2.0", "react-dom": "^18.2.0" }, @@ -16,6 +15,7 @@ "@types/node": "~16.11.12", "@types/react": "17.0.45", "@types/react-dom": "17.0.17", + "prettier": "^2.7.1", "typescript": "^4.7.3" } }