Skip to content

Commit ef213cb

Browse files
committed
feat: add convex package
1 parent b8546cc commit ef213cb

File tree

14 files changed

+755
-6
lines changed

14 files changed

+755
-6
lines changed

.env.example

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1+
# Convex deployment identifier in the format <team>:<deployment-name>
2+
# For development: use "anonymous:anonymous-next-starter"
3+
# For production: replace with your actual team and deployment name
4+
CONVEX_DEPLOYMENT=anonymous:anonymous-next-starter
5+
6+
# URL endpoint for your Convex backend server
7+
# Local development default: http://127.0.0.1:3210
8+
# Production: this will be your deployed Convex URL
9+
CONVEX_URL=http://127.0.0.1:3210
10+
111
# PostgreSQL connection string for the database
212
# Format: postgresql://<username>:<password>@<host>:<port>/<database>
313
# Default: postgresql://postgres:postgres@localhost:5432/postgres
14+
# TODO: DEPRECATE
415
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
516

617
# Secret key used for authentication and session management
718
# Warning: Use a strong, random value in production
19+
# Generate with: openssl rand -base64 32
820
BETTER_AUTH_SECRET=secret
921

10-
# Base URL for the auth service
22+
# Base URL for the Better Auth service
23+
# This URL is exposed to the client (NEXT_PUBLIC_ prefix)
1124
# Default: http://localhost:3002
25+
# Update to match your auth service deployment URL
1226
NEXT_PUBLIC_BETTER_AUTH_BASE_URL=http://localhost:3002
1327

14-
# Comma-separated list of allowed origins for CORS.
15-
# This controls which domains can access your API endpoints.
16-
# Example:
28+
# Comma-separated list of allowed origins for CORS
29+
# Controls which domains can access your API endpoints
30+
# Examples:
1731
# - Single origin: "https://example.com"
1832
# - Multiple origins: "https://app.example.com,https://admin.example.com"
1933
# - Development: "http://localhost:3000,http://localhost:3001"
20-
# Use "*" to allow all origins (not recommended for production)
21-
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001,http://localhost:3002
34+
# - Use "*" to allow all origins (not recommended for production)
35+
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001,http://localhost:3002
36+
37+
# Node Environment
38+
# Runtime environment identifier
39+
# Options: "development" (local dev), "production" (live), "test" (testing)
40+
# Affects logging, error handling, and performance optimizations
41+
NODE_ENV=development

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"check-types": "turbo run check-types",
66
"lint": "turbo run lint",
77
"format": "turbo run format",
8+
"init": "dotenv-run turbo run init",
89
"build": "turbo run build",
910
"dev": "docker compose up -d && dotenv-run turbo run dev",
1011
"auth:generate": "dotenv-run turbo run auth:generate --filter=@repo/auth",

packages/convex/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.env.local

packages/convex/biome.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
3+
"extends": ["@repo/biome-config/base"]
4+
}

packages/convex/convex.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/get-convex/convex-backend/refs/heads/main/npm-packages/convex/schemas/convex.schema.json",
3+
"functions": "src/functions"
4+
}

packages/convex/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@repo/convex",
3+
"version": "0.0.0",
4+
"private": true,
5+
"imports": {
6+
"#src/*": "./src/*"
7+
},
8+
"exports": {
9+
".": "./src/index.ts"
10+
},
11+
"scripts": {
12+
"lint": "biome check",
13+
"format": "biome format --write",
14+
"init": "convex dev --once",
15+
"dev": "convex dev",
16+
"build": "convex build"
17+
},
18+
"dependencies": {
19+
"@repo/env": "workspace:^",
20+
"convex": "^1.26.2",
21+
"zod": "^4.1.3"
22+
},
23+
"devDependencies": {
24+
"@biomejs/biome": "^2.2.2",
25+
"@repo/biome-config": "workspace:^",
26+
"@repo/typescript-config": "workspace:^",
27+
"@types/node": "^24.3.0",
28+
"@types/pg": "^8.15.5",
29+
"tsx": "^4.20.5",
30+
"typescript": "^5.9.2"
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated `api` utility.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* To regenerate, run `npx convex dev`.
8+
* @module
9+
*/
10+
11+
import type {
12+
ApiFromModules,
13+
FilterApi,
14+
FunctionReference,
15+
} from "convex/server";
16+
17+
/**
18+
* A utility for referencing Convex functions in your app's API.
19+
*
20+
* Usage:
21+
* ```js
22+
* const myFunctionReference = api.myModule.myFunction;
23+
* ```
24+
*/
25+
declare const fullApi: ApiFromModules<{}>;
26+
export declare const api: FilterApi<
27+
typeof fullApi,
28+
FunctionReference<any, "public">
29+
>;
30+
export declare const internal: FilterApi<
31+
typeof fullApi,
32+
FunctionReference<any, "internal">
33+
>;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated `api` utility.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* To regenerate, run `npx convex dev`.
8+
* @module
9+
*/
10+
11+
import { anyApi } from "convex/server";
12+
13+
/**
14+
* A utility for referencing Convex functions in your app's API.
15+
*
16+
* Usage:
17+
* ```js
18+
* const myFunctionReference = api.myModule.myFunction;
19+
* ```
20+
*/
21+
export const api = anyApi;
22+
export const internal = anyApi;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated data model types.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* To regenerate, run `npx convex dev`.
8+
* @module
9+
*/
10+
11+
import { AnyDataModel } from "convex/server";
12+
import type { GenericId } from "convex/values";
13+
14+
/**
15+
* No `schema.ts` file found!
16+
*
17+
* This generated code has permissive types like `Doc = any` because
18+
* Convex doesn't know your schema. If you'd like more type safety, see
19+
* https://docs.convex.dev/using/schemas for instructions on how to add a
20+
* schema file.
21+
*
22+
* After you change a schema, rerun codegen with `npx convex dev`.
23+
*/
24+
25+
/**
26+
* The names of all of your Convex tables.
27+
*/
28+
export type TableNames = string;
29+
30+
/**
31+
* The type of a document stored in Convex.
32+
*/
33+
export type Doc = any;
34+
35+
/**
36+
* An identifier for a document in Convex.
37+
*
38+
* Convex documents are uniquely identified by their `Id`, which is accessible
39+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40+
*
41+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
42+
*
43+
* IDs are just strings at runtime, but this type can be used to distinguish them from other
44+
* strings when type checking.
45+
*/
46+
export type Id<TableName extends TableNames = TableNames> =
47+
GenericId<TableName>;
48+
49+
/**
50+
* A type describing your Convex data model.
51+
*
52+
* This type includes information about what tables you have, the type of
53+
* documents stored in those tables, and the indexes defined on them.
54+
*
55+
* This type is used to parameterize methods like `queryGeneric` and
56+
* `mutationGeneric` to make them type-safe.
57+
*/
58+
export type DataModel = AnyDataModel;
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated utilities for implementing server-side Convex query and mutation functions.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* To regenerate, run `npx convex dev`.
8+
* @module
9+
*/
10+
11+
import {
12+
ActionBuilder,
13+
HttpActionBuilder,
14+
MutationBuilder,
15+
QueryBuilder,
16+
GenericActionCtx,
17+
GenericMutationCtx,
18+
GenericQueryCtx,
19+
GenericDatabaseReader,
20+
GenericDatabaseWriter,
21+
} from "convex/server";
22+
import type { DataModel } from "./dataModel.js";
23+
24+
/**
25+
* Define a query in this Convex app's public API.
26+
*
27+
* This function will be allowed to read your Convex database and will be accessible from the client.
28+
*
29+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
30+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
31+
*/
32+
export declare const query: QueryBuilder<DataModel, "public">;
33+
34+
/**
35+
* Define a query that is only accessible from other Convex functions (but not from the client).
36+
*
37+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
38+
*
39+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
40+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
41+
*/
42+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
43+
44+
/**
45+
* Define a mutation in this Convex app's public API.
46+
*
47+
* This function will be allowed to modify your Convex database and will be accessible from the client.
48+
*
49+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
50+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
51+
*/
52+
export declare const mutation: MutationBuilder<DataModel, "public">;
53+
54+
/**
55+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
56+
*
57+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
58+
*
59+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
60+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
61+
*/
62+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
63+
64+
/**
65+
* Define an action in this Convex app's public API.
66+
*
67+
* An action is a function which can execute any JavaScript code, including non-deterministic
68+
* code and code with side-effects, like calling third-party services.
69+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
70+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
71+
*
72+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
73+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
74+
*/
75+
export declare const action: ActionBuilder<DataModel, "public">;
76+
77+
/**
78+
* Define an action that is only accessible from other Convex functions (but not from the client).
79+
*
80+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
81+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
82+
*/
83+
export declare const internalAction: ActionBuilder<DataModel, "internal">;
84+
85+
/**
86+
* Define an HTTP action.
87+
*
88+
* This function will be used to respond to HTTP requests received by a Convex
89+
* deployment if the requests matches the path and method where this action
90+
* is routed. Be sure to route your action in `convex/http.js`.
91+
*
92+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
93+
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
94+
*/
95+
export declare const httpAction: HttpActionBuilder;
96+
97+
/**
98+
* A set of services for use within Convex query functions.
99+
*
100+
* The query context is passed as the first argument to any Convex query
101+
* function run on the server.
102+
*
103+
* This differs from the {@link MutationCtx} because all of the services are
104+
* read-only.
105+
*/
106+
export type QueryCtx = GenericQueryCtx<DataModel>;
107+
108+
/**
109+
* A set of services for use within Convex mutation functions.
110+
*
111+
* The mutation context is passed as the first argument to any Convex mutation
112+
* function run on the server.
113+
*/
114+
export type MutationCtx = GenericMutationCtx<DataModel>;
115+
116+
/**
117+
* A set of services for use within Convex action functions.
118+
*
119+
* The action context is passed as the first argument to any Convex action
120+
* function run on the server.
121+
*/
122+
export type ActionCtx = GenericActionCtx<DataModel>;
123+
124+
/**
125+
* An interface to read from the database within Convex query functions.
126+
*
127+
* The two entry points are {@link DatabaseReader.get}, which fetches a single
128+
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
129+
* building a query.
130+
*/
131+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
132+
133+
/**
134+
* An interface to read from and write to the database within Convex mutation
135+
* functions.
136+
*
137+
* Convex guarantees that all writes within a single mutation are
138+
* executed atomically, so you never have to worry about partial writes leaving
139+
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
140+
* for the guarantees Convex provides your functions.
141+
*/
142+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;

0 commit comments

Comments
 (0)