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
@kitajs/html: 4.1.0
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?
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
}
}
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.
A getIndexUrl = '/index'
string constant should be exported. Additionally a getIndexMethod = 'GET'
could also be generated.
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.
Maybe add Elysia?
Elysia is a bun web framework with great prefomance and DX!
Add a type only generation step to prevent unknown types when a route return type depends on.
https://github.com/uNetworking/uWebSockets.js
A uWebSockts.js kindly needs an abstraction to write routes and kita would be a awesome fit.
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.
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
};
Routes with @internal
still shows their return type in Schemas.
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() {}
Needs integration with @fastify/multipart
should also be done. MultipartFile
and SavedMultipartFile
.
Use https://www.npmjs.com/package/@openapi-contrib/json-schema-to-openapi-schema to convert schemas, probably somewhere in this class:
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.
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 manuallyHaving 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: {}
})
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.
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.
@kitajs/cli: 1.1.31
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.
nvm install 20.0.0
and then run nvm use 20.0.0
.npm start
;npm start
;The required node engine should be higher than 20.6.0
.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.
The transform schema function should also be validated at compile time.
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.
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 /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" } }
}
}
}
}
}
}
}
A fastify.hasPlugin()
call should be made before registering plugins like @fastify/sensible
...
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
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.
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
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'
Providers created with .tsx
extension aren't recognized.
Routes like /users/[userid]-[userage]
should work, not only /users/[userid]/[userage]
.
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 }]
}
Currently, some packages have docs, others have a "documentation yet to be written" message.
All packages should remove this message and have a single link to our official documentation.
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.