Giter Site home page Giter Site logo

terris / convex-helpers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from get-convex/convex-helpers

0.0 0.0 0.0 499 KB

A collection of useful code to complement the official packages.

License: MIT License

Shell 0.54% JavaScript 3.48% TypeScript 94.76% CSS 1.04% HTML 0.18%

convex-helpers's Introduction

convex-helpers

A collection of useful code to complement the official packages.

convex-helpers npm package

In the packages directory there's the convex-helpers directory, so you can npm install convex-helpers@latest.

It doesn't have all of the below features, but the ones it has can be used directly, rather than copying the code from this repo.

See the README for more details on:

  1. Customizing Functions (customQuery, customMutation, customAction).
  2. Relationship utilities to navigate database references.
  3. Row-Level Security (to be used with Custom Functions).
  4. Zod validation for function arguments and schemas.

Server-Persisted Session Data

See the guide on Stack for tips on how to set up and use Sessions.

To use sessions, you'll need the files:

  • withSession.ts on the server-side to give you function wrappers like mutation(withSession(...)).
  • sessions.ts on the server-side as a place to write your custom session creation logic.
  • useServerSession.ts on the client-side to give you hooks like useSessionMutation(...).
  • You'll need to define a table in your convex/schema.ts for whatever your session data looks like. Here we just use s.any().

Authentication: withUser

See the Stack post on withUser

Use the withUser wrappers in your functions to easily look up a user. You'll need to add an entry in your schema similar to convex/schema.ts.

Migrations: Data mutations

See the Stack post on migrations and the migration primer Stack post.

Use the migration wrapper to define a function to run over a given table. It generates an internalMutation to migrate a batch of documents.

Run the mutation to test it out, then run it over the whole table with the runMigration action.

HTTP Endpoints: Using Hono for advanced functionality

See the guide on Stack for tips on using Hono for HTTP endpoints.

To use Hono, you'll need the file honoWithConvex.ts.

Throttling client-side requests by Single-Flighting

See the Stack post on single-flighting for info on a technique to limit client requests.

You'll need the useSingleFlight.ts file, or useLatestValue.ts utilities.

Stable query results via useStableQuery

If you're fine getting stale results from queries when parameters change, check out the Stack post on useStableQuery.

You'll need the useStableQuery.ts file.

Presence

See the Stack post on implementing presence for details on how to implement presence in your app.

Related files:

  • presence.ts for server-side presence functions. Intended to be modified for your application.
  • usePresence.ts for client-side React hooks. Modify to match your server API.
  • (optional)useTypingIndicator.ts for specifically doing typing indicator presence.
  • (optional)Facepile.tsx for showing a facepile based on presence data. Intended to be used as an example to extend.

convex-helpers's People

Contributors

ianmacartney avatar sshader avatar ldanilek avatar renovate[bot] avatar vakila avatar xixixao avatar varunsingh87 avatar

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.