Skip to content

Latest commit

 

History

History
105 lines (92 loc) · 5.42 KB

README.md

File metadata and controls

105 lines (92 loc) · 5.42 KB

This project is being rewritten to follow the actual demands.

Should be found here

Densky Framework

maintained - no Made with Rust Made with Deno

📝 Table of Content

📓 What is Densky?

Densky is a backend framework based on file-routing and optimization build step. The build step is the most important feature because this makes the app super fast without complex code. This expect to be deployed on the egde with Deno Deploy

🌟 Features

  • Deno deploy: Support for Deno Deploy.
  • Rust core: All the core code are written in Rust, this makes the app blazing fast.
  • File routing: This solves the organization problem without imports hell.
  • Optimized Router: There's an algorithm to reduce the cost of routing using simple if's and reduced loops, avoiding complex regex.
  • Route Params: The route params can be used with $ at start of filename.
  • 🚧 Websockets: Support websockets with zero config, and file routing for message topic.
  • 🚧 DB ORM: Own ORM with auto-generated endpoint specified on the model.

🚀 Getting started

🚧 Work in progress (CLI is not working)

Initialize the proyect:

$ densky init

Run in dev mode:

$ densky dev

Production:

$ densky build # Build .densky, the main.ts is always there
$ densky preview

🏍️ Router

The algorithm of the router try to make the most compact tree, here's the decision tree of algorithm: Super simplified abstract version:

  • There's brother on container?
    • Expand it, and join to him
    • Join as unique son

The result can be visualized with the following graph:

Optimized Others
Optimized Tree Graph Others Tree Graph

There's a significant node reduction that translate to less validations, but it have more to show, the type of validations is with a simple if. Here's an example of output code for simple node:

export default function(req) {
  if (req.__accomulator__.path === "route-a") {
    // Update the accumulator for next nodes
    req.__accumulator__.segments = req.__accumulator__.segments.slice(1);
    req.__accumulator__.path = req.__accumulator__.segments.join("/");
    // ...
  }
}

Route params

The route params are also supported by the same router, at the three is treated like any other node but, the compiler change the validation. Here's an example of output code for route param node:

const __matcher_serial = [{
  raw: "$varname",
  isVar: true,
  varname: "varname"
}];
const __matcher_start = (/* ... */) => Densky.Runtime.matcherStart(__matcher_serial, /* ... */);
export default function(req) {
  if (__matcher_start(req.__accumulator__.segments, new Map(), req.params)) {
    // Update the accumulator for next nodes
    req.__accumulator__.segments = req.__accumulator__.segments.slice(1);
    req.__accumulator__.path = req.__accumulator__.segments.join("/");
    // Now can use the param
    req.params.get("varname"); // OK
    // ...
  }
}