Socket
Book a DemoInstallSign in
Socket

final-server

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

final-server

A component-based server framework for ES6+, with a React-like lifecycle. Experimental.

0.9.14
latest
Source
npmnpm
Version published
Weekly downloads
1
-94.12%
Maintainers
1
Weekly downloads
 
Created
Source

Final

Dependency check

This is a very experimental proof of concept for a server framework. It takes ideas from ES6+ and React to see if there's a more enjoyable, versatile way to create APIs.

Key concepts are:

Classes

Each endpoint has a class, which extends the component class. The main method of the class is respond which decides what is returned upon each request.

Lifecycle

Each component has a lifecycle, with names similar to the lifecycle components of React components.

Decorators

Decorators are used to add actions and in-memory state to components. The example decorator that's included is for ArangoDB. A reduxConnect decorator is also currently part of the library.

WebSockets

WebSocket-functionality is built-in (at present). Depending on how you wish to use the library, you can have components that repeat their lifecycle whenever state is changed. This is most useful for WebSocket servers becuase there may be multiple responses per connection. An http request will fire response onece, but a WebSocket connection might do it many times.

Installation

Use yarn or npm to install like so. Arango is optional, and it may also be possible to use without Babel, but documentation assumes you can use decorators and class properties.

yarn add final-server final-arango
yarn add --dev @babel/core @babel/preset-env @babel/plugin-proposal-class-properties @babel/preset-stage-0

Usage

See the /examples and files matching the patter **/*.test.js for more usage and explanation. Be warned the API will change a lot.

import Final, { reduxConnect, database } from './src/index'
import { bindActionCreators } from 'redux'
import { middleware, store } from './example/middleware'
import { moveUp } from './redux/modules/player'
import { UserSchema } from './schemas' // not an actual thing that's included

/*
  The `findDecorator` adds a few funtions to the class, like `this.findOne`.
*/
@database({
  // this decorator will verify collection or create new one
  collection: 'Post',
  url: 'http://root:@127.0.0.1:8529', // this value is the default
  arangoVersion: 30300 // this is also the default
})
@reduxConnect(
  (state) => ({
    players: state
  }),
  (dispatch) => ({
    moveUp
  })
)
class Post extends Final.Component {
  /*
    The path decides what requests will match this component and the params.
  */
  path = '/post/:post?'
  /*
    Define the schema which is enforced by the arango decorator on `save` commands.
  */
  schema = UserSchema
  uniques = ['email']

  async respond () {
    console.log('this.props.params', this.props.params)
    console.log('this.actions.moveUp', this.action.moveUp)
    const output = await this.actions.findOne({
      where: {"body": "Updated!"} // The `database` has special find functions with query-building
    })
    return {
      data: {
        players: this.props.players,
        output
      }
    }
  }
}

Final.createServer({
  components: [Post],
  port: 3001,
  store, // optional, see `examples/game-server.js`
  // middleware, /* Removed. Purpose needs to be decided. */
})

Keywords

rest

FAQs

Package last updated on 25 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.