0.1.0 • Published 10 months ago

@bunarcane/arcane v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Arcane

A minimal Bun web toolkit, designed with a focus on modern application development, offering built-in features to quickly making a web application.

Warning - This project is still highly unstable. If you are using this, please do not put it into production. Well, obviously.

Design Principles:

  • Security by Default - Providing best practice for securing an application.
  • Promote Modularity and Reusability - Structuring and organizing the application to be scalable.
  • Ease of Use - Less complexity, fairly comprehensible.
  • Performant - High performance and optimization.
  • Out-of-the-Box - Providing extra features out-of-the-box.
  • Customizable - No constraints, flexibility is key.

Table of Content

Installation

bun install @bunarcane/arcane

Quick Start

To get started with Arcane, you simply import the Arcane class from package and

Routing

Routing in Arcane is very straightforward, just simply import the method createRouter() and use the chain HTTP methods provided from it.

import { Arcane, createRouter, ok } from '@bunarcane/arcane'

const HelloWorld = createRouter()
    .get('/', () => ok('Hello World'))
    .compose()

new Arcane()
	.use(HelloWorld)
	.serve({
	    port: 7000,
	    context: 'Application starting on localhost:7000'
	})

Reusable Modules

Arcane provided two types of method in order to make reusable modules:

  • createBridge - Used for creating controller, that can communicate with the Request context.
  • createModule - As the name says, this method is used to create regular method.

In terms of implementation, these two are similar; the only difference is that createBridge contains a method that includes the Request context, which is used for handling request body, etc., while createModule does not contain that method but can have flexible parameters similar to regular functions.

Creating a controller

import { 
	Arcane, 
	createRouter, 
	createBridge, 
	response, 
	ok
} from '@bunarcane/arcane'

const FooBarController = createBridge()
    .impl('foo', () => ok('Hello! This is foo!'))
    .impl('bar', () => response('Hi! This is bar!'))
    .compose()

// Injecting to router
const FooBarRouter = createRouter()
    .get('/foo', FooBarController.foo)
    .get('/bar', FooBarController.bar)
    .compose()

new Arcane()
	.use(FooBarController)
	.serve({
	    port: 7000,
	    context: 'Application starting on localhost:7000'
	})

Creating a module

// middlewares.ts
import { createModule, useQuery } from '@bunarcane/arcane'

export type TFoo = {
    bar: string
}

export type TBar= {
    foo: string
}

export const FooBarMiddlewares = createModule()
    .mod('validateFoo', (body: TFoo) => {
        if (!body.bar) throw new Error('Bar is required!')
    })
    .mod('validateBar', () => {
        const { foo } = useQuery<TBar>()
        if (!foo) throw new Error('Foo is required!')
    })
    .compose()
// controller.ts
import { createBridge } from '@bunarcane/arcane'
import { TFoo, TBar, FooBarMiddlewares  } from './middleware'

const FooBarController = createBridge()
    .impl('foo', async (req) => {
        const body = await req.json<TFoo>()
        FooBarMiddlewares.validateFoo(body)
        return response(body)
    })
    .impl('bar', () => {
        FooBarMiddlewares.validateBar()
        return ok('Hello! This is bar!')
    })
    .compose()
0.1.0

10 months ago

0.0.36

10 months ago

0.0.35

10 months ago

0.0.34

10 months ago

0.0.33

10 months ago

0.0.32

10 months ago

0.0.31

10 months ago

0.0.30

10 months ago

0.0.2-9.9

10 months ago

0.0.2-9.8

10 months ago

0.0.2-9.7

10 months ago

0.0.2-9.6

10 months ago

0.0.2-9.5

10 months ago

0.0.2-9.4

10 months ago

0.0.2-9.3

10 months ago

0.0.2-9.2

10 months ago

0.0.2-9.1

10 months ago

0.0.29

10 months ago

0.0.28

10 months ago

0.0.27

10 months ago

0.0.26

10 months ago

0.0.25

10 months ago

0.0.24

10 months ago

0.0.23

10 months ago

0.0.22

10 months ago

0.0.21

10 months ago

0.0.20

10 months ago

0.0.19

10 months ago

0.0.18

10 months ago

0.0.17

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago