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!
KitaJS is a routing meta framework.
๐ท Performant & type safe fastify router โ end-to-end safety with ZERO abstraction cost!
Home Page: https://kita.js.org
License: MIT License
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!
KitaJS is a routing meta framework.
Currently, lack of documentation is the major problem of Kita.
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
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
Routes like /users/[userid]-[userage]
should work, not only /users/[userid]/[userage]
.
The transform schema function should also be validated at compile time.
/** @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" } }
}
}
}
}
}
}
}
.kita
folder would follow the dotfolder convention like many other frameworks, e.g .next
and .astro
. This would solve many other problems related to files inside node_modules
and the generated reference.
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.
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
};
Needs integration with @fastify/multipart
should also be done. MultipartFile
and SavedMultipartFile
.
Currently, you can use:
export default function get() {
return 'Hello!'
}
and kita will try to import it normally, default functions should emit a parsing error.
Direct controller binds causes #152 and multiple other issues, we should only export the light my request typings and let the user extract reusable logic into services.
A getIndexUrl = '/index'
string constant should be exported. Additionally a getIndexMethod = 'GET'
could also be generated.
Maybe add Elysia?
Elysia is a bun web framework with great prefomance and DX!
We should be able to use all of the example below to register provider hooks, schema transformers, routes and everything else:
export const get = () => {}
export const get = function () {}
export let get = () => {}
export let get = function () {}
export function get() {}
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.
A fastify.hasPlugin()
call should be made before registering plugins like @fastify/sensible
...
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.
Use https://www.npmjs.com/package/@openapi-contrib/json-schema-to-openapi-schema to convert schemas, probably somewhere in this class:
Fastify either requires done() call or return promise.
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 }]
}
Req
and Res
should change to the defaults FastifyRequest
and FastifyResponse
Query
type, we shouldn't break types when runtime execution works.this
parameter usage, it gets messy when calling routes programatically. This resolves to void, which doesn't impact on calling the routes manuallyAdd a type only generation step to prevent unknown types when a route return type depends on.
Currently, some packages have docs, others have a "documentation yet to be written".
All packages should remove this message and have a single link to our official documentation.
https://github.com/uNetworking/uWebSockets.js
A uWebSockts.js kindly needs an abstraction to write routes and kita would be a awesome fit.
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.
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.
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'
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.
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: {}
})
Providers created with .tsx
extension aren't recognized.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.