npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

final-server

v0.9.14

Published

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

Downloads

5

Readme

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. */
})