General fixes. Still far from good or working

This commit is contained in:
2026-01-11 13:21:01 -05:00
parent 0a361f51a1
commit 67daefb919
83 changed files with 733 additions and 1053 deletions

View File

@@ -7,9 +7,9 @@ A query function that takes two arguments looks like:
```ts
// functions.js
import { v } from "convex/values";
import { v } from 'convex/values';
import { query } from "./_generated/server";
import { query } from './_generated/server';
export const myQueryFunction = query({
// Validators for arguments.
@@ -22,7 +22,7 @@ export const myQueryFunction = query({
handler: async (ctx, args) => {
// Read the database as many times as you need here.
// See https://docs.convex.dev/database/reading-data.
const documents = await ctx.db.query("tablename").collect();
const documents = await ctx.db.query('tablename').collect();
// Arguments passed from the client are properties of the args object.
console.log(args.first, args.second);
@@ -39,7 +39,7 @@ Using this query function in a React component looks like:
```ts
const data = useQuery(api.functions.myQueryFunction, {
first: 10,
second: "hello",
second: 'hello',
});
```
@@ -47,9 +47,9 @@ A mutation function looks like:
```ts
// functions.js
import { v } from "convex/values";
import { v } from 'convex/values';
import { mutation } from "./_generated/server";
import { mutation } from './_generated/server';
export const myMutationFunction = mutation({
// Validators for arguments.
@@ -64,7 +64,7 @@ export const myMutationFunction = mutation({
// Mutations can also read from the database like queries.
// See https://docs.convex.dev/database/writing-data.
const message = { body: args.first, author: args.second };
const id = await ctx.db.insert("messages", message);
const id = await ctx.db.insert('messages', message);
// Optionally, return a value from your mutation.
return await ctx.db.get(id);
@@ -78,10 +78,10 @@ Using this mutation function in a React component looks like:
const mutation = useMutation(api.functions.myMutationFunction);
function handleButtonPress() {
// fire and forget, the most common way to use mutations
mutation({ first: "Hello!", second: "me" });
mutation({ first: 'Hello!', second: 'me' });
// OR
// use the result once the mutation has completed
mutation({ first: "Hello!", second: "me" }).then((result) =>
mutation({ first: 'Hello!', second: 'me' }).then((result) =>
console.log(result),
);
}

View File

@@ -12,11 +12,11 @@ import type {
ApiFromModules,
FilterApi,
FunctionReference,
} from "convex/server";
} from 'convex/server';
import type * as notes from "../notes.js";
import type * as openai from "../openai.js";
import type * as utils from "../utils.js";
import type * as notes from '../notes.js';
import type * as openai from '../openai.js';
import type * as utils from '../utils.js';
/**
* A utility for referencing Convex functions in your app's API.
@@ -33,9 +33,9 @@ declare const fullApi: ApiFromModules<{
}>;
export declare const api: FilterApi<
typeof fullApi,
FunctionReference<any, "public">
FunctionReference<any, 'public'>
>;
export declare const internal: FilterApi<
typeof fullApi,
FunctionReference<any, "internal">
FunctionReference<any, 'internal'>
>;

View File

@@ -8,7 +8,7 @@
* @module
*/
import { anyApi } from "convex/server";
import { anyApi } from 'convex/server';
/**
* A utility for referencing Convex functions in your app's API.

View File

@@ -13,10 +13,10 @@ import type {
DocumentByName,
SystemTableNames,
TableNamesInDataModel,
} from "convex/server";
import type { GenericId } from "convex/values";
} from 'convex/server';
import type { GenericId } from 'convex/values';
import schema from "../schema.js";
import schema from '../schema.js';
/**
* The names of all of your Convex tables.

View File

@@ -18,9 +18,9 @@ import {
HttpActionBuilder,
MutationBuilder,
QueryBuilder,
} from "convex/server";
} from 'convex/server';
import type { DataModel } from "./dataModel.js";
import type { DataModel } from './dataModel.js';
/**
* Define a query in this Convex app's public API.
@@ -30,7 +30,7 @@ import type { 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 declare const query: QueryBuilder<DataModel, "public">;
export declare const query: QueryBuilder<DataModel, 'public'>;
/**
* Define a query that is only accessible from other Convex functions (but not from the client).
@@ -40,7 +40,7 @@ export declare const query: QueryBuilder<DataModel, "public">;
* @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 declare const internalQuery: QueryBuilder<DataModel, "internal">;
export declare const internalQuery: QueryBuilder<DataModel, 'internal'>;
/**
* Define a mutation in this Convex app's public API.
@@ -50,7 +50,7 @@ export declare const internalQuery: QueryBuilder<DataModel, "internal">;
* @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 declare const mutation: MutationBuilder<DataModel, "public">;
export declare const mutation: MutationBuilder<DataModel, 'public'>;
/**
* Define a mutation that is only accessible from other Convex functions (but not from the client).
@@ -60,7 +60,7 @@ export declare const mutation: MutationBuilder<DataModel, "public">;
* @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 declare const internalMutation: MutationBuilder<DataModel, "internal">;
export declare const internalMutation: MutationBuilder<DataModel, 'internal'>;
/**
* Define an action in this Convex app's public API.
@@ -73,7 +73,7 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
*/
export declare const action: ActionBuilder<DataModel, "public">;
export declare const action: ActionBuilder<DataModel, 'public'>;
/**
* Define an action that is only accessible from other Convex functions (but not from the client).
@@ -81,7 +81,7 @@ export declare const action: ActionBuilder<DataModel, "public">;
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
*/
export declare const internalAction: ActionBuilder<DataModel, "internal">;
export declare const internalAction: ActionBuilder<DataModel, 'internal'>;
/**
* Define an HTTP action.

View File

@@ -16,7 +16,7 @@ import {
internalQueryGeneric,
mutationGeneric,
queryGeneric,
} from "convex/server";
} from 'convex/server';
/**
* Define a query in this Convex app's public API.

View File

@@ -2,7 +2,7 @@ export default {
providers: [
{
domain: process.env.CLERK_ISSUER_URL,
applicationID: "convex",
applicationID: 'convex',
},
],
};

View File

@@ -1,8 +1,8 @@
import { Auth } from "convex/server";
import { v } from "convex/values";
import { Auth } from 'convex/server';
import { v } from 'convex/values';
import { internal } from "../convex/_generated/api";
import { mutation, query } from "./_generated/server";
import { internal } from '../convex/_generated/api';
import { mutation, query } from './_generated/server';
export const getUserId = async (ctx: { auth: Auth }) => {
return (await ctx.auth.getUserIdentity())?.subject;
@@ -16,8 +16,8 @@ export const getNotes = query({
if (!userId) return null;
const notes = await ctx.db
.query("notes")
.filter((q) => q.eq(q.field("userId"), userId))
.query('notes')
.filter((q) => q.eq(q.field('userId'), userId))
.collect();
return notes;
@@ -27,7 +27,7 @@ export const getNotes = query({
// Get note for a specific note
export const getNote = query({
args: {
id: v.optional(v.id("notes")),
id: v.optional(v.id('notes')),
},
handler: async (ctx, args) => {
const { id } = args;
@@ -46,8 +46,8 @@ export const createNote = mutation({
},
handler: async (ctx, { title, content, isSummary }) => {
const userId = await getUserId(ctx);
if (!userId) throw new Error("User not found");
const noteId = await ctx.db.insert("notes", { userId, title, content });
if (!userId) throw new Error('User not found');
const noteId = await ctx.db.insert('notes', { userId, title, content });
if (isSummary) {
await ctx.scheduler.runAfter(0, internal.openai.summary, {
@@ -63,7 +63,7 @@ export const createNote = mutation({
export const deleteNote = mutation({
args: {
noteId: v.id("notes"),
noteId: v.id('notes'),
},
handler: async (ctx, args) => {
await ctx.db.delete(args.noteId);

View File

@@ -1,9 +1,9 @@
import { v } from "convex/values";
import OpenAI from "openai";
import { v } from 'convex/values';
import OpenAI from 'openai';
import { internal } from "./_generated/api";
import { internalAction, internalMutation, query } from "./_generated/server";
import { missingEnvVariableUrl } from "./utils";
import { internal } from './_generated/api';
import { internalAction, internalMutation, query } from './_generated/server';
import { missingEnvVariableUrl } from './utils';
export const openaiKeySet = query({
args: {},
@@ -14,7 +14,7 @@ export const openaiKeySet = query({
export const summary = internalAction({
args: {
id: v.id("notes"),
id: v.id('notes'),
title: v.string(),
content: v.string(),
},
@@ -24,8 +24,8 @@ export const summary = internalAction({
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
const error = missingEnvVariableUrl(
"OPENAI_API_KEY",
"https://platform.openai.com/account/api-keys",
'OPENAI_API_KEY',
'https://platform.openai.com/account/api-keys',
);
console.error(error);
await ctx.runMutation(internal.openai.saveSummary, {
@@ -38,14 +38,14 @@ export const summary = internalAction({
const output = await openai.chat.completions.create({
messages: [
{
role: "system",
role: 'system',
content:
"You are a helpful assistant designed to output JSON in this format: {summary: string}",
'You are a helpful assistant designed to output JSON in this format: {summary: string}',
},
{ role: "user", content: prompt },
{ role: 'user', content: prompt },
],
model: "gpt-4-1106-preview",
response_format: { type: "json_object" },
model: 'gpt-4-1106-preview',
response_format: { type: 'json_object' },
});
// Pull the message content out of the response
@@ -65,7 +65,7 @@ export const summary = internalAction({
export const saveSummary = internalMutation({
args: {
id: v.id("notes"),
id: v.id('notes'),
summary: v.string(),
},
handler: async (ctx, { id, summary }) => {

View File

@@ -1,5 +1,5 @@
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
import { defineSchema, defineTable } from 'convex/server';
import { v } from 'convex/values';
export default defineSchema({
notes: defineTable({

View File

@@ -11,6 +11,6 @@ export function missingEnvVariableUrl(envVarName: string, whereToGet: string) {
export function deploymentName() {
const url = process.env.CONVEX_CLOUD_URL;
if (!url) return undefined;
const regex = new RegExp("https://(.+).convex.cloud");
const regex = new RegExp('https://(.+).convex.cloud');
return regex.exec(url)?.[1];
}