Giter Site home page Giter Site logo

get-convex / convex-js Goto Github PK

View Code? Open in Web Editor NEW
56.0 2.0 5.0 574 KB

TypeScript/JavaScript client library for Convex

Home Page: https://docs.convex.dev

License: Apache License 2.0

JavaScript 2.87% Python 0.52% TypeScript 96.54% Shell 0.07%
convex data-loading database javascript realtime-database typescript websocket

convex-js's People

Contributors

emmaling27 avatar ldanilek avatar nipunn1313 avatar pashabitz avatar renovate[bot] avatar sshader avatar thomasballinger avatar xixixao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

convex-js's Issues

[Suggestion] Don't Delete convex.json When Running npx convex dev

Background Information

I'm developing a project within a team wherein our React client consumes the Convex API. As of the moment, the onboarding process and development environment setup is quite cumbersome due to unintended(?) actions caused by npx convex dev.

We have a client/convex.json file that specifies the following information that is crucial to the functionality of the client side:

{
    "functions": "./src/_convex"
}

Running npx convex dev and going through the setup wizard deletes this file and then results in a [CONVEX Q(files:getFilesByDocumentId)] Could not find public function for 'files:getFilesByDocumentId'. Did you forget to run `npx convex dev` or `npx convex deploy`? error.

Demo

demo

The Suggestion

If it's possible, npx convex dev shouldn't delete these configuration files on directories without .env.local's Convex files. Or perhaps, the wizard can ask questions if there is an existing configuration files or if there are files to ignore during the initialization process.

Also, an npx convex dev --verbose flag would be nice to see explicit updates on any file changes.

Convex Actions - returning anything from "runQuery" or "runMutations" ends with circular reference error

When creating the app for the Web Dev Cody's hackathon, I found that returning anything from the ctx.runQuery or ctx.runMutation when using the Convex Actions ends with "circularly references" error.

reproduction repo: https://github.com/Willaiem/convex-ts-bug

Reproduction steps:

  1. Create the Vite app with React with npm init vite@latest and choose React + TS.
  2. Install the dependencies.
  3. Run npx convex dev
  4. Create actions.ts and paste the code below.

actions.ts

import { action, internalQuery } from "./_generated/server";
import { internal } from "./_generated/api";

export const getTasks = internalQuery({
    args: {},
    handler: async (ctx) => {
        const tasks = await ctx.db.query('tasks').collect()

        return tasks
    }
})


export const invokeAction = action({
    args: {},
    handler: async (ctx) => {
        const tasks = await ctx.runQuery(internal.actions.getTasks)

        const texts = tasks.map(task => task.text)

        // do something else...

        return texts 
    }
})

The error from the Convex CLI:

PS E:\programowaniefiles\convex-ts-bug> npx convex dev
✖ TypeScript typecheck via `tsc` failed.
To ignore failing typecheck, use `--typecheck=disable`.
convex/_generated/api.d.ts:27:15 - error TS2502: 'fullApi' is referenced directly or indirectly in its own type annotation.

27 declare const fullApi: ApiFromModules<{
                 ~~~~~~~
convex/_generated/api.d.ts:27:24 - error TS2615: Type of property 'actions' circularly references itself in mapped type '{ [Key in keyof { actions: FunctionReferencesInModule<typeof import("E:/programowaniefiles/convex-ts-bug/convex/actions")>; }]: ExpandModulesAndDirs<{ actions: FunctionReferencesInModule<typeof import("E:/programowaniefiles/convex-ts-bug/convex/actions")>; }[Key]>; }'.

27 declare const fullApi: ApiFromModules<{
                          ~~~~~~~~~~~~~~~~
28   actions: typeof actions;
   ~~~~~~~~~~~~~~~~~~~~~~~~~~
29 }>;
   ~~

convex/_generated/api.d.ts:34:22 - error TS2502: 'internal' is referenced directly or indirectly in its own type annotation.

34 export declare const internal: FilterApi<
                        ~~~~~~~~

convex/_generated/api.d.ts:35:10 - error TS2615: Type of property 'actions' circularly references itself in mapped type '{ actions: { getTasks: FunctionReference<"query", "internal", {}, { _id: Id<"tasks">; _creationTime: number; text: string; isCompleted: boolean; }[]>; invokeAction: FunctionReference<...> | ... 1 more ... | FunctionReference<...>; }; }'.

35   typeof fullApi,
            ~~~~~~~

convex/actions.ts:15:14 - error TS7022: 'invokeAction' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

15 export const invokeAction = action({
                ~~~~~~~~~~~~

convex/actions.ts:18:15 - error TS7022: 'tasks' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

18         const tasks = await ctx.runQuery(internal.actions.getTasks)
                 ~~~~~

convex/actions.ts:20:15 - error TS7022: 'texts' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

20         const texts = tasks.map(task => task.text)
                 ~~~~~

convex/actions.ts:20:33 - error TS7006: Parameter 'task' implicitly has an 'any' type.

20         const texts = tasks.map(task => task.text)
                                   ~~~~

Found 8 errors in 2 files.

Errors  Files
     4  convex/_generated/api.d.ts:27
     4  convex/actions.ts:15

Mutation: Prevent empty string in args

Hello, is there any way to prevent an empty string when we call a mutation?

In my case, I have a users table, and in the "create" mutation I accept "name" args, currently empty string is accepted.

Is there any built in method? Or do I need to reject it in handler?

Thanks in advance

Add the 'use client' directive to the react `auth_helpers`

Hey guys,

Currently the auth_helpers don't work in Nextjs app router server-side rendered components because they use the useConvexAuth hook, and they haven't declared they are to be run on the client. Could you please add the 'use client' directive at the top of the auth_helpers?

Trouble using nodemailer package with "use node" flag

I'm trying to send an email (a verification code), which should only happen in the server in convex
I've have used "use node" flag at the top of the file. and imported the package, in the convex env I added the envs as needed
Below is function
`export const sendMail = async ({ name, to, subject, body }: {
to: string,
name: string,
subject: string,
body: string,
}) => {
const { SMTP_EMAIL, SMTP_PASSWORD } = process.env;

const transport = createTransport({
    service: "gmail",
    auth: {
        user: SMTP_EMAIL,
        pass: SMTP_PASSWORD
    }
});

try {
    const testResult = await transport.verify()
    console.log("TEST: ", testResult);
} catch (error) {
    console.log("Mail Error: ", error)
}

try {
    const sendResult = await transport.sendMail({
        from: SMTP_EMAIL,
        to,
        subject,
        html: body,
    });
    console.log(sendResult);
} catch (error) {
    console.log(error);
    return
}

}`

but npx convex dev fails with errors:

node_modules/.pnpm/[email protected]/node_modules/nodemailer/lib/dkim/message-parser.js:3:26:
      3 │ const Transform = require('stream').Transform;
        ╵                           ~~~~~~~~

  The package "stream" wasn't found on the file system but is built  
  into node. Are you trying to bundle for node? You can use
  "platform: 'node'" to do that, which will remove this error.       

X [ERROR] Could not resolve "crypto"

    node_modules/.pnpm/[email protected]/node_modules/nodemailer/lib/dkim/sign.js:5:23:
      5 │ const crypto = require('crypto');
        ╵                        ~~~~~~~~

  The package "crypto" wasn't found on the file system but is built  
  into node. Are you trying to bundle for node? You can use
  "platform: 'node'" to do that, which will remove this error.  

removing the function body even with the import inplace, convex compile just fine, what am I missing or doing wrong?

NOTE: Other packages works just fine like svix and bcrypt-ts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.