Giter Site home page Giter Site logo

kitajs / kitajs Goto Github PK

View Code? Open in Web Editor NEW
276.0 3.0 12.0 3.85 MB

🌷 Performant & type safe fastify router β€” end-to-end safety with ZERO abstraction cost!

Home Page: https://kita.js.org

License: MIT License

TypeScript 97.79% JavaScript 1.02% Shell 0.15% CSS 1.03%
backend fast framework nodejs code fastify generator minimal api open

kitajs's Introduction

Using this package? Please consider donating to support my open source work ❀️
Help kitajs grow! Star and share this amazing repository with your friends and co-workers!


Kita JS logo


Discord License Codecov Last commit Stars


🌷 KitaJS

KitaJS is a routing meta framework.


πŸŽ‰ Kita is officially Stable! Try it out today!


Star History

Star History Chart

All Thanks To Our Contributors:

kitajs's People

Contributors

arthurfiorette avatar dependabot[bot] avatar devzolo avatar github-actions[bot] avatar imgbot[bot] avatar joao-cabral avatar zmarques 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  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  avatar

kitajs's Issues

Improve documentation.

Currently, lack of documentation is the major problem of Kita.

  • Finish all sections
    • Routing
    • Learn By building
      • setup
      • api routes
      • frontend
    • Learn by example
      • file uploads
      • authentication
      • logging
    • Guide
    • Templating (Should we have this? Probably fit better in kitajs/html)
    • Integrations
      • auth
      • (what more?)

I wrote the entire kita.js.org documentation alone. I'm 100% sure there will be grammar mistakes that can be easily fixed.

Site: https://kita.js.org
Documentation: https://github.com/kitajs/docs

  • Have at least 3 grammar revisors.

Cannot find module '@kitajs/html/jsx-runtime' or its corresponding type declarations on NodeJS

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Versions

@kitajs/html: 4.1.0

Description

When using kitajs as JSX to string transformer in AdonisJS I get the error Cannot find module '@kitajs/html/jsx-runtime' or its corresponding type declarations.

It worked before, with the tsconfig:

{
  // ...
  "compilerOptions": {
   // ...
   "jsx": "react",
   "jsxFactory": "Html.createElement",
   "jsxFragmentFactory": "Html.Fragment",
   "plugins": [{ "name": "@kitajs/ts-html-plugin" }]
  }
}

And adding import '@kitajs/html/register.js' to bin/server.ts . But it was complaining about being a deprecated method, so I tried to get the new method to work, but was not able to.

The new method seems not to work with compilerOptions: { module: NodeNext }. Is this library not supported on NodeJS?

Steps to Reproduce

Install AdonisJS, install @kitajs/html & @kitajs/ts-html-plugin.

Create a tsx file:

import router from '@adonisjs/core/services/router'

router.get('/', () => <div>foo</div>);

Set tsconfig.json to

{
  "extends": "@adonisjs/tsconfig/tsconfig.app.json",
  "compilerOptions": {
    "rootDir": "./",
    "outDir": "./build",
    "jsx": "react-jsx",
    "jsxImportSource": "@kitajs/html",
    "plugins": [
      {
        "name": "@kitajs/ts-html-plugin"
      }
    ]
  },
}

@adonisjs/tsconfig/tsconfig.app.json:

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "declaration": false,
    "sourceMap": true,
    "emitDecoratorMetadata": true,
  }
}

@adonisjs/tsconfig/tsconfig.base.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "lib": ["ESNext"],
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "isolatedModules": true,
    "removeComments": true,
    "esModuleInterop": true,
    "strictNullChecks": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "strictPropertyInitialization": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "skipLibCheck": false
  },
  "ts-node": {
    "swc": true
  }
}

Expected Behavior

It does not give error Cannot find module '@kitajs/html/jsx-runtime' or its corresponding type declarations when using the new way of setting the JSX transformer up.

Awaited should be used defined in the controller response type.

export type ControllerResponse = ReturnType<typeof controller>;

export declare function controllerHandler(
  req: FastifyRequest,
  reply: FastifyReply
): Promise<Awaited<ControllerResponse>>;

should be

export type ControllerResponse = Awaited<ReturnType<typeof controller>>;

export declare function controllerHandler(
  req: FastifyRequest,
  reply: FastifyReply
): Promise<ControllerResponse>;

Otherwise using ControllerResponse is impractical without adding Awaited everywhere.

`Environment` provider

Add a /providers/environment.ts specific provider which should only default export a interface which its json schema should be parsed by env-schema.

// providers/environment.ts

export default interface Environment {
  /**
   * My description
   *
   * @default '...'
   * @minLength 32
   * @maxLength 64
   */
  MY_ENV: string;
}

export const options: EnvSchemaOpt = {
  dotenv: true
};

Multipart support

Needs integration with @fastify/multipart should also be done. MultipartFile and SavedMultipartFile.

Improve route parameters

  • Req and Res should change to the defaults FastifyRequest and FastifyResponse
  • Simplify Query type, we shouldn't break types when runtime execution works.
  • Remove this parameter usage, it gets messy when calling routes programatically. This resolves to void, which doesn't impact on calling the routes manually
  • Add tests and type tests for every parameter type.

Automatically add properties to all required plugins.

Having the end user to manually register plugins like the following example is bad:

// Register fastify sensible to allow error handling
app.register(fastifySensible, {
  sharedSchemaId: "HttpError",
});

// Registers fastify's swagger support
app.register(fastifySwagger);
app.register(fastifySwaggerUi);

// Registers the generated kita plugin
app.register(Kita);

Every plugin kita needs, depending on providers/parameters usage, we should add the typings and the object as properties, like the following example:

app.register(Kita, {
  swagger: {},
  swaggerUi: {},
  sensible: {},

  // If other parameters like websocket are used, a `websocket` property should be added in case
  // the user wants to change some configuration. We should also consider good defaults.
  // websocket: {}
})

Warn on file without routes

KitaJS should emit warnings on files inside routes that does not exports any route method and/or exported functions that does not represent any routes.

Unusual providers registration order

Currently, providers must be prefixed with number like 1z.ts and a.ts when a.ts used z.ts as parameter, otherwise a.ts would throw because z was not registered yet.

Node engine 20.0.0 does not support built-in .env file

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Versions

@kitajs/cli: 1.1.31

Description

When using node 20.0.0 version, the server does not start.
Using the dev command it does not throw, which makes the issue a little bit harder to detect. When using the start command it throws, making it clear that the issue is about the .env file.

Steps to Reproduce

  1. Set the node version to 20.0.0;
    • When using nvm you can run nvm install 20.0.0 and then run nvm use 20.0.0.
  2. Run npm start;
  3. Check the error;
  4. Set the node version to 20.6.x (in the video I use 20.6.1 but 20.6.0 works as well);
  5. Run npm start;
  6. Check the server runs normally.

Record reproduction:

Screen.Recording.2024-06-24.at.13.05.17.mov

Expected Behavior

The required node engine should be higher than 20.6.0

`kita create` command needs a test suite.

After #365 (a bug that only happened on windows), its clear that it requires a full test suite across all 3 operating systems.

Our only problem is to ensure a copy of @kitajs/runtime instead of linking, otherwise the generated folder will get updated and break all other packages tests.

Support for wildcard routes

Using [...].ts should work as a fastify wildcard route. Currently this is the only hacky way to do it:

/**
 * @url /api/a/*
 */
export function get({ url, params }: FastifyRequest) {
  return { url, params };
}

returns = {
  "params": {
    "*": "asdasd/asd"
  },
  "url": "/api/a/asdasd/asd"
}

The Path parameter should also validate when its being used outside a /[named]/ route and a variant of it should be defined to get the request.params['*'] when the route is wildcard.

@url jsdoc is not working

/** @url /users */
export function get() {}

generates the following schema:

{
  "openapi": "3.1.0",
  "info": {
    "title": "API Reference",
    "description": "Powered by [Scalar](https://scalar.com/) & Generated by [KitaJS](https://kita.js.org/)",
    "version": "1.1.22"
  },
  "components": { "schemas": {} },
  "paths": {
    "/users": {
      "get": {
        "operationId": "getIndex",
        "responses": {
          "2XX": {
            "description": "Default Response",
            "content": {
              "application/json": { "schema": { "type": "boolean" } }
            }
          }
        }
      }
    }
  }
}

Better HTTP error detection

The same way a HTTP route can read throw clauses to add errors, providers should also include throw clauses it the route they are used.

Maybe custom errors should also be added by inferring their type

Force `async` routes

Libraries like prisma may extend the promise return type, e.g PrismaPromise and it cannot be unwrapped into a real promise, making the return type incorrect.

Error: `gyp` failed with exit code: 1 no module named 'distutils'

node_modules/.pnpm/[email protected]/node_modules/deasync: Running install script, failed in 341ms
.../[email protected]/node_modules/deasync install$ node ./build.js
β”‚ gyp info it worked if it ends with ok
β”‚ gyp info using [email protected]
β”‚ gyp info using [email protected] | darwin | arm64
β”‚ gyp info find Python using Python version 3.12.2 found at "/opt/homebrew/opt/[email protected]/bin/python3.12"
β”‚ gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.12
β”‚ gyp info spawn args [
β”‚ gyp info spawn args   '/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py',
β”‚ gyp info spawn args   'binding.gyp',
β”‚ gyp info spawn args   '-f',
β”‚ gyp info spawn args   'make',
β”‚ gyp info spawn args   '-I',
β”‚ gyp info spawn args   '/Users/griffith/www/kita-app/node_modules/.pnpm/[email protected]/node_modules/deasync/build/confi…
β”‚ gyp info spawn args   '-I',
β”‚ gyp info spawn args   '/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/addon.gypi',
β”‚ gyp info spawn args   '-I',
β”‚ gyp info spawn args   '/Users/griffith/Library/Caches/node-gyp/21.7.3/include/node/common.gypi',
β”‚ gyp info spawn args   '-Dlibrary=shared_library',
β”‚ gyp info spawn args   '-Dvisibility=default',
β”‚ gyp info spawn args   '-Dnode_root_dir=/Users/griffith/Library/Caches/node-gyp/21.7.3',
β”‚ gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp',
β”‚ gyp info spawn args   '-Dnode_lib_file=/Users/griffith/Library/Caches/node-gyp/21.7.3/<(target_arch)/node.lib',
β”‚ gyp info spawn args   '-Dmodule_root_dir=/Users/griffith/www/kita-app/node_modules/.pnpm/[email protected]/node_modules/d…
β”‚ gyp info spawn args   '-Dnode_engine=v8',
β”‚ gyp info spawn args   '--depth=.',
β”‚ gyp info spawn args   '--no-parallel',
β”‚ gyp info spawn args   '--generator-output',
β”‚ gyp info spawn args   'build',
β”‚ gyp info spawn args   '-Goutput_dir=.'
β”‚ gyp info spawn args ]
β”‚ Traceback (most recent call last):
β”‚   File "/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
β”‚     import gyp  # noqa: E402
β”‚     ^^^^^^^^^^
β”‚   File "/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
β”‚     import gyp.input
β”‚   File "/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module>
β”‚     from distutils.version import StrictVersion
β”‚ ModuleNotFoundError: No module named 'distutils'
β”‚ gyp ERR! configure error 
β”‚ gyp ERR! stack Error: `gyp` failed with exit code: 1
β”‚ gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/lib/configure…
β”‚ gyp ERR! stack     at ChildProcess.emit (node:events:519:28)
β”‚ gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
β”‚ gyp ERR! System Darwin 23.4.0
β”‚ gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/pnpm/dist/node_modules/node-gyp/bin/node-gyp.js" "…
β”‚ gyp ERR! cwd /Users/griffith/www/kita-app/node_modules/.pnpm/[email protected]/node_modules/deasync
β”‚ gyp ERR! node -v v21.7.3
β”‚ gyp ERR! node-gyp -v v9.4.1
β”‚ gyp ERR! not ok 
β”‚ Build failed
└─ Failed in 341ms at /Users/griffith/www/kita-app/node_modules/.pnpm/[email protected]/node_modules/deasync

Provider hooks

We should be able to use application hooks like the following:

// providers/test.ts

export default function() : Data {
}

// Registered as the fastify onRouteHandler
export function onRoute() {

}

// ... So on for 'onRegister', 'onReady', 'onListen', 'onClose', 'preClose'

Provider Parameters

Providers should have the hability to provide generic parameters.

export function get(a: MyGenericProvider<'a', 2, true, {a:1}>) {}

Should have this definition:

export default function (params: ProviderParameters) {
  console.log(params) // ['a', '2', 'true', '{a:1}']
}

If possible, parsed JSON values should be cool.

export default function (params: ProviderParameters) {
  console.log(params) // ['a', 2, true, { a: 1 }]
}

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.