0.0.14 • Published 7 years ago

exf v0.0.14

Weekly downloads
3
License
ISC
Repository
-
Last release
7 years ago

Overview

Introduction

"exf" provides a collection of helper modules that help defining Models and Controllers on Express framework.

"exf" consists of three types of modules, "generators", "controllers" and "modifiers".

In addition to these, "express" & "restfulize" provides collection of functional wrapper for basic Express modules.

generators

"generators" generates Model or controller from specific name, base module that like Model(at controller) or db connection and schema definitions(at Model), and options.

Even without options, it generates module that has basic methods though, with options, you can extend or modify that.

options are defined with "extenders" or "modifiers".

extenders

"extenders" extends methods that are defined in generators. If you need some special process before/after the basic methods, you can use this.

modifiers

"modifiers" extends methods that are defined in generators. If you need to modify the basic methods, you can use this.

Generator module List

ModelController
generatorsGenerates Model from db connection definitionsGenerates Controller from specific Model module
extendersExtends basic methods of generated ModelExtends basic methods of generated Controller
modifiersModifies basic methods of generated ModelModifies basic methods of generated Controller

Usage

Controller Generator

To define the common controller generator may be good.

{
  generators: {controller: generate}
  extenders: {controller: {modify_query_before}}
  modifiers: {controller: {query: {set_filter_from_query}}}
  } = require \exf

  module.exports = (name, {queries_to_filter}:options?)->
  generate name, (require "../models/#name.ls"), options
  |> if_ queries_to_filter?,
  modify_query_before \index, set_filter_from_query queries_to_filter

A specific controller is defined by to call the common generator (simple controller)

generate = require \../services/app-controller-generator.ls

module.exports =
  generate \product

A specific controller is defined by to calls the common generator (with extender)

generate = require \../services/app-model-generator.ls
...
{find} = module.exports =
  generate \layout, schema
  #extend basic method
  |> before \update, (body, cb, next)->
    ...
  #add the specific methods
  |> merge (
    get_states: get_states = (layout, cb)-->
      ...
    get_fleet_units: get_fleet_units = (layout, cb)-->
      ...
    ...
    )

Model Generator

To define the common model generator may be good.

{
  generators: {"mongo-model": generate}
  modifiers: {model: {body: {add_date}}}
  extenders: {model: {modify_body_before}}
} = require \exf
{apply: apply_schema} = require \schemaf
host = env \MONGODB_HOST
port = env \MONGODB_PORT
db = env \MONGODB_DB

module.exports = (name, schema, options)->
  generate name, host, port, db, options
  |> modify_body_before \persist,
    (add_date \created_date)
    >> (add_date \updated_date)
    >> (apply_schema schema)
  |> modify_body_before \update,
    (add_date \updated_date)
    >> (apply_schema schema)
  |> modify_body_before \delete,
    (apply_schema schema)

A specific controller is defined by to calls the common generator.

generate = require \../services/app-model-generator.ls
...

module.exports =
  generate \product, (
    _id: mongo_object_id
    name: string
    created_date: date
    updated_date: date
  )

A specific controller is defined by to calls the common generator(with extender).

generate = require \../services/app-model-generator.ls
...
{find} = module.exports =
  generate \layout, schema
  |> before \update, (body, cb, next)->
    ...
  |> merge (
    get_states: get_states = (layout, cb)-->
      ...
    get_fleet_units: get_fleet_units = (layout, cb)-->
      ...

express & restfulize

"express" provides functional style wrapper of Express modules. "restfulize" provides the interface of controller that follows REST architecture style.

{static: static_}:express = require \express
{
  restfulize,
  express: {
    listen, set: _set, get: _get,
    use, use_in, render, end
  }
} = require \exf
...
configure =
  act $$ [
    listen port
    _set \views, "#__dirname/../../views"
...
  ]
serve =
  express
  >> configure
  >> ($$ map restfulize, controllers)
  >> (lazy console~info, "Server is ready.")
0.0.14

7 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago