Giter Club home page Giter Club logo

type-arango's Introduction

TYPE-ARANGO

Powerful decorators for ArangoDB Foxx Apps when working with TypeScript.

TypeArango manages ArangoDB collections, documents, relations and routes
by taking advantage of TypeScript's typings. It comes with a fast and easy to use permission
system
, provides an ORM, event listeners, documented endpoints as well as plenty of
other tools to make it fun to build ReST APIs in a declarative & elegant manner.
TypeArango is probably the fastest way of setting up documented & validated endpoints.

divider

โญ Features

divider

๐Ÿ’จ Shortcuts

divider

๐ŸŒž TypeArango is in development and will receive additional features. Contributors wanted ๐Ÿ™‹

Mentioned in Awesome ArangoDB last-commit version npm license size

divider

๐Ÿ“ Example

The example will setup a User entity stored inside a Users collection with a total of 6 documented routes.

Various other examples of how to use typeArango with certain features can be found in the ๐Ÿ“˜ examples folder.

import { Document, Entity, Collection, Entities, Route, Authorized, Index, Related, Attribute } 
  from 'type-arango'

// `User` document entity
@Document()
export class User extends Entity {
    @Index(type => 'hash')
    @Attribute(str => str.email())
    email: string;
    
    @Attribute()
    name: string;
    
    @Authorized(readers => ['viewer','admin'], writers => ['admin'])
    @Attribute(nr => nr.min(0).max(100))
    rating: number;
    
    @Attribute()
    createdAt: Type.DateInsert;
    
    @OneToMany(type => Address, Address => Address.owner)
    addresses: Related<Address[]>;
}

// `Users` collection
@Collection(of => User)
@Route.groups(
    creators => ['guest'],
    readers => ['user','admin'],
    writers => ['viewer','admin'],
    deleters => ['admin']
)
@Route.use('GET','POST','PATCH','PUT','DELETE','LIST')
export class Users extends Entities {
    @Route.GET(
        path => ':id/addresses',
        roles => ['viewer'],
        summary => 'Returns User Address[]'
    ) static GET({param}: RouteArg){
        const user = Users.findOne(param.id);
        return user.relation('addresses');
    }
}

divider

โšก World's fastest way to create documented endpoints

TypeArango uses the provided entity types to validate and document routes, for example a simple @Route.all creates five fully documented routes with a role system in place.

Swagger Screenshot Screenshot from ArangoDBs Web Interface

divider

๐Ÿ›ซ Getting started

1. Setup ArangoDB Foxx service

If you don't have a foxx service running yet, you can create one by using arangodb-typescript-setup.

TypeArango requires ArangoDB 3.4.4 or newer.

divider

2. Install

yarn add --D type-arango

or

npm i --save-dev type-arango

divider

3. Create the Entities

Read the ๐Ÿ“˜ Examples or dive into the ๐Ÿ“— API Reference

divider

4. Setup

typeArango() has to be called before the entities are imported, it returns a function to be called after the decorators have been applied. It takes an optional ๐Ÿ“ Configuration argument.

shared/entities/index.ts:

import typeArango from 'type-arango'

const complete = typeArango({
    // Configuration
});

export * from './User';

complete();

divider

5. Create routes

When using the @Route decorator, it is required to provide the Foxx.Router to TypeArango by calling createRoutes(router).

foxx-service/main.ts:

import createRouter from '@arangodb/foxx/router';
import {createRoutes} from 'type-arango';

// Initialize all entities before creating the routes
import * as _Entities from 'shared/entities';

// Create the foxx router and hand it to type-arango
const router = createRoutes( createRouter() );

As the routes are built by the @Route.* decorators, it is required to import all entities before calling createRoutes(Foxx.Router).

divider

๐Ÿ“š Documentation

Read the ๐Ÿ“˜ Examples first, then dive into the ๐Ÿ“— API Reference.

divider

๐ŸŒป Credits

type-arango's People

Contributors

riennevaplus avatar

Watchers

James Cloos avatar  avatar

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.