-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Preslav Le
committed
Dec 8, 2022
0 parents
commit f35dc07
Showing
26 changed files
with
4,278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.next | ||
convex/_generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Convex | ||
|
||
This example demonstrates the Convex global state management framework. | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example): | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/convex&project-name=convex&repository-name=convex) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example convex convex-app | ||
# or | ||
yarn create next-app --example convex convex-app | ||
# or | ||
pnpm create next-app --example convex convex-app | ||
``` | ||
|
||
Run | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
to run `next dev` and a Convex file watcher at the same time. This command will log you into Convex, so you'll need to create a Convex account if this is your first project. | ||
|
||
Once everything is working, commit your code and deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). | ||
|
||
Use `npx convex deploy && npm run build` as the build command and set the `CONVEX_DEPLOY_KEY` environmental variable in Vercel ([Documentation](https://docs.convex.dev/getting-started/deployment/hosting/vercel)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Welcome to your Convex functions directory! | ||
|
||
Write your Convex functions here. See | ||
https://docs.convex.dev/using/writing-convex-functions for more. | ||
|
||
A query function that takes two arguments looks like: | ||
|
||
```typescript | ||
// myQueryFunction.ts | ||
import { query } from './_generated/server' | ||
|
||
export default query(async ({ db }, first: number, second: string) => { | ||
// Validate arguments here. | ||
if (typeof first !== 'number' || first < 0) { | ||
throw new Error('First argument is not a non-negative number.') | ||
} | ||
if (typeof second !== 'string' || second.length > 1000) { | ||
throw new Error('Second argument is not a string of length 1000 or less.') | ||
} | ||
|
||
// Query the database as many times as you need here. | ||
// See https://docs.convex.dev/using/database-queries to learn how to write queries. | ||
const documents = await db.query('tablename').collect() | ||
|
||
// Write arbitrary JavaScript here: filter, aggregate, build derived data, | ||
// remove non-public properties, or create new objects. | ||
return documents | ||
}) | ||
``` | ||
|
||
Using this query function in a React component looks like: | ||
|
||
```typescript | ||
const data = useQuery('myQueryFunction', 10, 'hello') | ||
``` | ||
|
||
A mutation function looks like: | ||
|
||
```typescript | ||
// myMutationFunction.ts | ||
import { mutation } from './_generated/server' | ||
|
||
export default mutation(async ({ db }, first: string, second: string) => { | ||
// Validate arguments here. | ||
if (typeof first !== 'string' || typeof second !== 'string') { | ||
throw new Error('Both arguments must be strings') | ||
} | ||
|
||
// Insert or modify documents in the database here. | ||
// Mutations can also read from the database like queries. | ||
const message = { body: first, author: second } | ||
const id = await db.insert('messages', message) | ||
|
||
// Optionally, return a value from your mutation. | ||
return await db.get(id) | ||
}) | ||
``` | ||
|
||
Using this mutation function in a React component looks like: | ||
|
||
```typescript | ||
const mutation = useMutation('myMutationFunction') | ||
function handleButtonPress() { | ||
// fire and forget, the most common way to use mutations | ||
mutation('Hello!', 'me') | ||
// OR | ||
// use the result once the mutation has completed | ||
mutation('Hello!', 'me').then((result) => console.log(result)) | ||
} | ||
``` | ||
|
||
The Convex CLI is your friend. See everything it can do by running | ||
`npx convex -h` in your project root directory. To learn more, launch the docs | ||
with `npx convex docs`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable */ | ||
/** | ||
* Generated API. | ||
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex codegen`. | ||
* @module | ||
*/ | ||
|
||
import type { ApiFromModules } from "convex/api"; | ||
import type * as listMessages from "../listMessages"; | ||
import type * as sendMessage from "../sendMessage"; | ||
|
||
/** | ||
* A type describing your app's public Convex API. | ||
* | ||
* This `API` type includes information about the arguments and return | ||
* types of your app's query and mutation functions. | ||
* | ||
* This type should be used with type-parameterized classes like | ||
* `ConvexReactClient` to create app-specific types. | ||
*/ | ||
export type API = ApiFromModules<{ | ||
listMessages: typeof listMessages; | ||
sendMessage: typeof sendMessage; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable */ | ||
/** | ||
* Generated development client configuration. | ||
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex codegen`. | ||
* @module | ||
*/ | ||
|
||
import type { ClientConfiguration } from "convex/browser"; | ||
|
||
/** | ||
* The DEV Convex client configuration. | ||
* | ||
* This configuration connects your client to your dev Convex deployment | ||
* when `npx convex dev` is running. | ||
* | ||
* To generate the production version, run `npx convex deploy`. | ||
* | ||
* Usage: | ||
* | ||
* ```ts | ||
* import clientConfig from "../convex/_generated/clientConfig"; | ||
* | ||
* const convex = new ConvexReactClient(clientConfig); | ||
* ``` | ||
*/ | ||
declare const clientConfig: ClientConfiguration; | ||
export default clientConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable */ | ||
/** | ||
* Generated development client configuration. | ||
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex codegen`. | ||
* @module | ||
*/ | ||
|
||
/** | ||
* The DEV Convex client configuration. | ||
* | ||
* This configuration connects your client to your dev Convex deployment | ||
* when `npx convex dev` is running. | ||
* | ||
* To generate the production version, run `npx convex deploy`. | ||
* | ||
* Usage: | ||
* | ||
* ```ts | ||
* import clientConfig from "../convex/_generated/clientConfig"; | ||
* | ||
* const convex = new ConvexReactClient(clientConfig); | ||
* ``` | ||
*/ | ||
const clientConfig = { | ||
address: "http://localhost:8187", | ||
}; | ||
export default clientConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-disable */ | ||
/** | ||
* Generated data model types. | ||
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex codegen`. | ||
* @module | ||
*/ | ||
|
||
import type { | ||
DataModelFromSchemaDefinition, | ||
DocumentMapFromSchemaDefinition, | ||
} from "convex/schema"; | ||
import type { TableNamesInDataModel } from "convex/server"; | ||
import { GenericId, GenericIdConstructor } from "convex/values"; | ||
import schema from "../schema"; | ||
|
||
/** | ||
* The names of all of your Convex tables. | ||
*/ | ||
export type TableNames = TableNamesInDataModel<DataModel>; | ||
|
||
/** | ||
* The type of a document stored in Convex. | ||
* | ||
* @typeParam TableName - A string literal type of the table name (like "users"). | ||
*/ | ||
export type Document<TableName extends TableNames> = | ||
DocumentMapFromSchemaDefinition<typeof schema>[TableName]; | ||
|
||
/** | ||
* An identifier for a document in Convex. | ||
* | ||
* Convex documents are uniquely identified by their `Id`, which is accessible | ||
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling). | ||
* | ||
* Documents can be loaded using `db.get(id)` in query and mutation functions. | ||
* | ||
* **Important**: Use `myId.equals(otherId)` to check for equality. | ||
* Using `===` will not work because two different instances of `Id` can refer | ||
* to the same document. | ||
* | ||
* @typeParam TableName - A string literal type of the table name (like "users"). | ||
*/ | ||
export type Id<TableName extends TableNames> = GenericId<TableName>; | ||
|
||
/** | ||
* An identifier for a document in Convex. | ||
* | ||
* Convex documents are uniquely identified by their `Id`, which is accessible | ||
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling). | ||
* | ||
* Documents can be loaded using `db.get(id)` in query and mutation functions. | ||
* | ||
* **Important**: Use `myId.equals(otherId)` to check for equality. | ||
* Using `===` will not work because two different instances of `Id` can refer | ||
* to the same document. | ||
*/ | ||
export declare const Id: GenericIdConstructor<TableNames>; | ||
|
||
/** | ||
* A type describing your Convex data model. | ||
* | ||
* This type includes information about what tables you have, the type of | ||
* documents stored in those tables, and the indexes defined on them. | ||
* | ||
* This type is used to parameterize methods like `queryGeneric` and | ||
* `mutationGeneric` to make them type-safe. | ||
*/ | ||
export type DataModel = DataModelFromSchemaDefinition<typeof schema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable */ | ||
/** | ||
* Generated data model types. | ||
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex codegen`. | ||
* @module | ||
*/ | ||
|
||
import { GenericId } from "convex/values"; | ||
|
||
/** | ||
* An identifier for a document in Convex. | ||
* | ||
* Convex documents are uniquely identified by their `Id`, which is accessible | ||
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling). | ||
* | ||
* Documents can be loaded using `db.get(id)` in query and mutation functions. | ||
* | ||
* **Important**: Use `myId.equals(otherId)` to check for equality. | ||
* Using `===` will not work because two different instances of `Id` can refer | ||
* to the same document. | ||
*/ | ||
export const Id = GenericId; |
Oops, something went wrong.