Giter VIP home page Giter VIP logo

cheetah's Issues

API versioning

I know it's possible to write code like following to version api:

api
  .use('/v1', v1Routes)
  .use('/v2', v2Routes);

But If I want to implement something like Header versioning or other type like nestjs has https://docs.nestjs.com/techniques/versioning I will have to write some magic extension code (I believe)

Would be cool a) to have global config to specify default version, specify version for one route? configure how versioning is specified/handled

Helpers to register custom routes from extension

Would be helpful to make a way to add new routes from custom extension to extend code
Maybe developers could use it to simply add extension like .use(healthcheck()) that would register it's own route /healthcheck and add some logic before that

For now it's kinda possible to do by adding it to app.routes Set, but it can be improved to make it as easy as app.routes.add('GET', '/healtcheck, (c) => '๐Ÿ’š') or with .get / .post methods

option to validate request params

You can already define a schema for headers, query, body, & cookies. It'd definitely be a good addition to allow you to define a schema for params.

Roadmap for v1.1

Roadmap

  • deprecate c.req.blob(), c.req.buffer(), c.req.formData() (extend body validation: z.instanceof(Blob) etc.) (delayed due to insufficient support by zod)
  • add etag extension (delayed to v1.2)
  • add favicon extension (respond to /favicon.ico requests) #126
  • add pretty extension (pretty-print json) #123
  • move transform option to c.req.body() method #118

+ other unscheduled revisions:

Roadmap for v1.2

Roadmap

  • built-in high-performant server for static files (Cloudflare R2, S3 bucket or local files)
  • simple WebSockets implementation (experimental)
  • deprecate setup/build scripts & introduce an entire CLI with more commands
  • development mode (load env variables from a local .env file, make debugging easier, & add cheetah dev command)
  • improve DX when building an API for Cloudflare Workers (install wrangler package behind the scenes, type-safe wranger.toml, etc.)

When will v1.2 go public?

  • canary: Late July - Early August
  • current: Late August

add support for denoland/deno_kv_oauth

I am trailing this out and attempting to use denoland/deno_kv_oauth as an oauth provider. Seems that I am able to get passed the signIn leg of the auth_code flow, however I am not able to get a response from the callbackย 

I think in the discord you mentioned that ctx.req.raw is the underlining request however that seems to not be working so will be trying to look into that.

server.get("/signin", async (ctx) => {
    console.log("signIn::before");
    const response = await signIn(ctx.req.raw, oauth2Client);
    console.log("signIn::after");
    ctx.res.redirect(response.headers.get("location")!, Status.Found);
});

server.get("/callback", async (ctx) => {
    console.log("callback::before");
    const { response } = await handleCallback(ctx.req.raw, oauth2Client);
    console.log("callback::after");
    ctx.res.redirect(response.headers.get("location")!, Status.Found);
});

and the log is showing

Listening on http://localhost:3000/
signIn::before
signIn::after
callback::before

include validation errors in the response body

I need to be able to retrieve failed network requests that fail to pass through Zod's validation.

Right now, it seems to return default 400 BAD REQUEST responses by default, but I prefer to know why those requests failed, so I can return that data to the browser and display alerts for all their errors, in case they manage to get through the frontend validation somehow.

I'm using zod as a validation middleware before the response is sent. This is my code:

app.put(
  //path
  "/register",
  //validation
  {
    body: z.object({
      username: z.string({
        required_error: "Name is required",
        invalid_type_error: "Name must be a string",
      }).min(6, { message: "Must be 6 or more characters long" }),
      email: z.string().email({ message: "Invalid email address" }),
      password: z.string({
        required_error: "Password is required",
        invalid_type_error: "Password must be a string",
      }).min(8, { message: "Password must be 8 or more characters long" }),
      confirmPassword: z.string({
        required_error: "Password confirmation is required",
        invalid_type_error: "Password confirmation must be a string",
      }).min(8, {
        message: "Password confirmation must be 8 or more characters long",
      }),
    }),
  },
  // response
  async (c) => {
    const reqBody = await c.req.body();
    console.log("body:", reqBody);
  },
);

When an error happens, the response is sent before reaching the response block.

c.exception() missing for extensions.

1.4.0

I'm getting a deprecated warning when using new Exception telling me to use c.exception() instead, but ExtensionContext doesn't have that function.

image

It's working well with normal routes, though.

image

Roadmap for v1.0

  • Built-in support for tRPC (#13)
  • Replace medleyjs/router with a custom router #29
  • Option to extend context
  • Parse headers without deep validation (refer to dae083f)
  • Improve the build script
    • Pre-compile pathname to regex
    • Remove if-else logic for plugins if none are used

enhance dx for cloudflare

Enhance DX when building an API for Cloudflare Workers (install wrangler package behind the scenes, type-safe wrangler.toml, etc.).

refactor: types for environment variables

I have no idea how to work around this, so I'll just leave this issue open until someone comes up with a good solution.

How should we handle the types for environment variables without affecting the cheetah/Collection classes?

Add support for tRPC

cheetah should support trpc out of the box.

Generating the type declarations should be as simple as running deno run -A https://deno.land/x/cheetah/trpc.ts

Make `waitUntil` function suitable for Deno Deploy and self-hosting

As of now, the c.waitUntil method does nothing other than setting a timeout that fires after 1 second. If the logic after the call of this function takes longer than 1 second to execute, the whole benefit of this feature goes to waste.

The method should behave just like in Cloudflare Workers to make migration easier.

Roadmap for v1.0

This issue is meant as both a roadmap and note regarding the upcoming v1.0 release.

Roadmap

  • reimagine the plugins api #77
  • implement documentation generation (part of v1.1)
  • introduce custom api client (will be a standalone module)
  • major performance enhancements
  • implement gzip compression using foras (not necessary for cloudflare workers or deno deploy) #79
  • support basic jsx rendering #96
  • standardize c.env across runtimes #85

Canceled

  • allow extending the fetch context

Breaking Changes

`ctx.req` isn't a standard `Request` object

I am trying to upgrade a connection to a websocket connection, and according to the Deno documentation, Deno.upgradeWebsocket() is what I should use. However, ctx.req is not a standard Request object, therefore it cannot be used with that method. Is there a way that I can get a standard Request object?

Demo code:

import cheetah from "https://deno.land/x/[email protected]/mod.ts";
import { serve } from "https://deno.land/[email protected]/http/server.ts";

const app = new cheetah();
app.get("/upgrade", (ctx) => {
  Deno.upgradeWebSocket(ctx.req)
})

introduction of `c.res.cookies`

The c.res.cookies object provides something similar to a Map but for managing cookies in a simple and secure high-level way. It'll also be the replacement for c.res.cookie() which will be deprecated. c.res.cookie() will be a shortcut to c.res.cookies.set() for now.

Roadmap for Official Plugins

cheetah v0.4.0 introduced support for plugins.

The following should be offered officially:

  • cache (Deno.KV, Redis, Cache API)
  • helmet (ported from here) #22
  • ratelimit (in-memory, Redis, Deno.KV, Cloudflare Durable Objects)

Please leave a comment below if you are planning to contribute so we can avoid duplicate work.

Roadmap for v0.11.0

  • deprecate cache.duration option #46
  • enhance internal routing (delayed to v1.0 due to breaking changes)
  • add per-collection cache/cors options #50
  • implement automatic HEAD responses #49
  • add runtime option to build script #47
  • publish new guide (will be released separately this week)

Setup script - folder name param

Now when running deno run -Ar https://deno.land/x/cheetah/setup.ts you cannot specify name, neither write it before/after being asked about runtime. And we end up with cheetahland-template-deno-basic-6ae3a45 folder that has to be renamed manually
A small DX touch to let developer specify folder name where to place new project

(non-issue) question about using jsdevlivr with esm.sh

Hi, i'm the maintainer of esm.sh. This project looks promising! i'm trying to learn your code, i found something vary interesting and iโ€˜m just wondering can you please share why you choosed jsdevlivr to import npm packages with esm.sh types. i'm not saying you should use esm.sh, jsdevlivr is great! i'm just curious did you try to use esm.sh with trouble or something, if that i can fix/improve.

// @deno-types='https://esm.sh/@sinclair/[email protected]/value'
import { Value } from 'https://cdn.jsdelivr.net/npm/@sinclair/[email protected]/value/value.js/+esm'

anyway, thanks for creating this cool project! (and sorry i filed this non-issue issue i did not find the GH discusisions enabled.)

`req.text()` sets additional `Content-Type` header

I have this code:

app.get("/", (ctx) => {
  ctx.res.header("Content-Type", "text/html");
  ctx.res.text(Deno.readTextFileSync("./index.html").replace("$TURNSTILE_SITE_KEY", Deno.env.get("TURNSTILE_SITE_KEY") || ""));
});

It should send a Content-Type: text/html header, however, it adds another text/plain; charset=utf-8 header. Is this expected behavior?

Screenshot:
image

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.