Code Monkey home page Code Monkey logo

materia-server's Introduction

Build Status npm version dependencies Status

Materia Server

Materia Server is the core of Materia. It handles your Materia Application and host them anywhere.

Materia logo

Installation

You can install Materia Server globally using NPM:

$ (sudo) npm install -g @materia/server

or yarn:

$ (sudo) yarn global add @materia/server

then you can use Materia Server in 3 ways:

  • CLI Interface,

  • Javascript interface,

  • HTTP Admin API.

CLI Interface

Manipulating the server

Start the server

$ materia start

Basic information

Get the current version of Materia Server

$ materia version

You can see more information in the Materia documentation.

The guide to use materia deploy

Javascript Interface

The API Reference is available on getmateria.com/docs/api-reference.

You can include these object (using require()) to create a Materia Application and save it on the Filesystem.

HTTP Admin Interface

The API reference is available here.

To interact with your running server through the HTTP Admin API, you first need to authenticate with your root password to retrieve your admin access token.

Your admin token has to be used as Bearer token. You can then use all the protected http endpoints to model your application.

Licensing

Materia Server is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

materia-server's People

Contributors

geoastronaute avatar bumpmann avatar thyb avatar dependabot[bot] avatar

Stargazers

 avatar Anibal Centurion avatar George Naranjo avatar ezzabuzaid avatar Valeriy Sotnikov avatar RYeah Sh avatar Vassil Verguilov avatar GS Chavan avatar  avatar Wildan Zulfikar avatar Michael Timko avatar Jonas mg avatar Waseem avatar Garrett Sullins avatar  avatar  avatar Jacob Son avatar Amit Jindal avatar Sushil Nagpal avatar Charlie Smith avatar  avatar Daniel Sef avatar MBuffenoir avatar Weirong Yang avatar Andrew Lewin avatar Bruno Costa - Garu avatar  avatar Nikolaus Schlemm avatar dissociative.space avatar Florin Cosmin avatar Reece Webb avatar Michael Jeffrey Wu avatar Mike Ivars avatar  avatar Alexey Yakovlev avatar wonkwh avatar Emmanuel Pays avatar Aaron Callahan avatar Oğuz Çelikdemir avatar GeekShip avatar 南知 avatar Kliment Petrov avatar dokenzy avatar Kunal Varma avatar Victor Hugo Bernardes de Souza avatar Sam avatar Raí Siqueira avatar Joohun, Maeng avatar Yuki MIZUNO avatar Naoto Yokoyama avatar Kazuki Hashimoto avatar Cierra Sparks avatar Alex avatar Zaher Ghaibeh avatar Valentin Vichnal avatar  avatar Kenny Freeman avatar David Rebd avatar Jonathan Frankel avatar Alejandro avatar nth avatar Kevin J. Hanna avatar  avatar Aaron avatar Steven Edwards avatar Kevin Segal avatar Darshil Patel avatar Filipe Oliveira avatar  avatar James Tyler Morin avatar Kin Lane avatar  avatar David M. avatar Chew Chit Siang avatar Emrah Bayraktaroglu avatar  avatar  avatar Gosha Spark avatar  avatar Emanoel Queiroz avatar Nick Stalter avatar Daniel Mascena avatar Joshua Stauter avatar Gilberto Olimpio avatar Samuel Gyger avatar Arsalan Ahmad avatar Vlad avatar Constantin Rack avatar sbyinin avatar Jose Browne avatar Vien Luong avatar Adrian Lanzafame avatar chaozh avatar Scott Covert avatar 塟愛鎵镞の風仯 avatar John Eo avatar  avatar Joseph Patton-Robson avatar R. Burke Squires avatar X4 avatar

Watchers

 avatar James Cloos avatar  avatar Mahdi Medjaoui avatar  avatar  avatar

materia-server's Issues

support windows paths

Expected behavior

Use windows path with backslash.

Actual behavior

Some path use linux-style slash


  • Materia Version: pre-release

Query should directly use params without the need to map them in opts.values

Expected behavior

The following query config should works without addition "opts.values" field:

{
    "id": "companiesSince",
    "type": "sql",
    "params": [
        {
            "name": "date",
            "type": "date",
            "required": true
        }
    ],
    "opts": {
        "query": "SELECT speaker.company\nFROM speaker, event\nWHERE event.date_start >= :date\n    AND event.slug = speaker.slug_event\nGROUP BY speaker.company"
    }
}

Actual behavior

This query config is working

{
    "id": "companiesSince",
    "type": "sql",
    "params": [
        {
            "name": "date",
            "type": "date",
            "required": true
        }
    ],
    "opts": {
        "values": {
            "date": "="
        },
        "query": "SELECT speaker.company\nFROM speaker, event\nWHERE event.date_start >= :date\n    AND event.slug = speaker.slug_event\nGROUP BY speaker.company"
    }
}

but without opts.values (as in the expected behavior), it throws:

Error: Named parameter ":date" has no value in the given object.

  • Materia Version: pre-release

Integrate @materia/users in @materia/server and use admin users to remove rootPassword

If we integrate @materia/users in this repository and install it by default in every applications, we can use admin role to connect materia-server admin API instead of using rootPassword.

Advantage:

  • no rootPassword written in clear text in materia.json & materia.prod.json
  • Same login system than the one used in the application (not duplicated in 2 different system)

If no database setup, we can still connect to a local sqlite database to have the minimal user structure

If no admin user defined, need a cli command to initialize the first admin user (to let materia-designer connect the admin API)


  • Materia Version: v1.0.0-beta.1

Custom Query don't save the Javascript file

Expected behavior

when creating the CustomQuery object with opts.query which contain the code. It should write the code in the file opts.file.

Actual behavior

The custom query can load the Javascript file and execute it. When saving the query, it return the JSON with the filename in opts.file but there is no way to store the query or retrieve the code of the query.


  • Materia Version: pre-release

Update primary key when changing a field

Expected behavior

This should alter the table to add/remove the primary key in db, to match the entity.

Actual behavior

Does not change the primary key(s)

Step to reproduce the behavior

Update a field to add or remove a primary key, and check in db that did not changed the pk, or launch a synchronization and watch the diff.


  • Materia Version: pre-release

command materia start don't work after a global installation

Expected behavior

launch the server with the command line materia start

Actual behavior

Error in the console when running materia start:

command not found
/usr/local/bin/materia: line 3: syntax error near unexpected token `('
/usr/local/bin/materia: line 3: `let argv = require('minimist')(process.argv.slice(2))'

Actually the server can be run with forever start ./node_modules/materia-server/cli/index.js start

Step to reproduce the behavior

  • sudo npm install -g materia-server
  • materia start

  • Materia Version: v0.1.1

An endpoint should be a list of query

Expected behavior

An endpoint is linked to a list of query. In this list, only one query can be a findAll or a findOne query. When the endpoint is called, every query are executed in parallel.

Actual behavior

An endpoint is linked to a single query.


  • Materia Version: pre-release

Install / update / remove addons from the CLI

Expected behavior

$> materia addons install {addon-name|addon-url}[#{version}]
Install an addon by its name or url to the latest version or to the specified version if it is specified

$> materia addons update {addon-name|addon-url}[#{version}]
Update an addon by its name or url to the latest version or to the specified version if it is specified

$> materia addons remove {addon-name|addon-url}
Remove an addon by its name or url

$> materia addons search {query}
Search an addon

The feature would be developed in /lib to be used programmatically from Materia designer and from the CLI.
All addons would be installed first in the Materia directory, then a symbolic link is created to the current app. Then, if another app is using the same addon, just a symbolic link is needed.


  • Materia Version: pre-release

Field 'default' should be a method 'hasDefault'

Expected behavior

Do not have a field default stored in entities and use only defaultValue, and replace default field by a hasDefault method

Actual behavior

Rely on default boolean

Step to reproduce the behavior

Create an entity


  • Materia Version: pre-release

Handle multiple "server profile" in materia.*.json

Currently, we have 2 server profile: dev and prod defined respectively in materia.json and materia.prod.json

We could handle more server profile by detecting materia.json + materia.*.json files
Each files materia.*.json is a new server profile where * is the profile name

In Materia Designer, we could connect in live mode to any server profile (e.g. prod / staging / prod2 etc...).


  • Materia Version: v1.0.0-beta.1

Endpoints should deduce their params/data in function of the query associated

Expected behavior

If GET method:
All params from the query goes as endpoint params

If POST method:
All params from the query goes as endpoint data

If PUT method:
All params from the query goes as endpoint data

If DELETE method:
All params from the query goes as endpoint params

If there is params in the URL (e.g. /customers/:id), they are pushed as endpoint params

The actual behavior is still needed when the query is a custom Javascript function

Actual behavior

For the moment, endpoints declare their params and data while the query associated also declare its params


  • Materia Version: pre-release

Change field type from 'text' to other type

Expected behavior

When updating a field type from text to integer (or boolean, date...), this should cast the data to the new type (c.f. http://stackoverflow.com/questions/13170570/change-type-of-varchar-field-to-integer-cannot-be-cast-automatically-to-type-i)

Actual behavior

The SQL request looks like ALTER TABLE "..." ALTER COLUMN "..." TYPE TEXT

Step to reproduce the behavior

Changing a field type from type text to number, date or boolean throws an error when it should cast the data to the new type:

column "..." cannot be cast automatically to type ...


  • Materia Version: pre-release

Deploy an app from the CLI

Expected behavior

$> materia deploy {provider} [--{param}={value}]*

Deploy an app directly from the CLI. The feature would be developed in /lib to be used programmatically from Materia designer and from the CLI


  • Materia Version: pre-release

Merge queries files and entity model files

It would be easier to write models and custom queries if they were in the same file (hopefully Typescript).

This is an example of what I mean by merging queries and models in a single file:

@Entity('user')
class UserModel {
    @Field({type: DataType.NUMBER, primary: true, autoIncrement: true}) id;
    @Field({type: DataType.TEXT, required: true}) email;
    @Field({type: DataType.TEXT, required: true}) password;
    @Field({type: DataType.BOOLEAN}) public_email = false

    constructor(private app: App) {}

    @CustomQuery({
        params: [{
            name: 'email',
            type: DataType.TEXT
            required: true
        },{
            name: 'password',
            type: DataType.TEXT
            required: true
        }]
    })
    signin(params) {
        // todo
    }
}

Many requirements are needed to implement this new syntax:

  • Handle Typescript files in server/ folder (compilation in watch mode in Materia Designer)
  • Need to be able to edit the class programmatically without breaking existing code
  • Need to be able to read the class as we were reading the json file (reflexion / introspection of the class).

  • Materia Version: v1.0.0-beta.1

Controllers should store information contained in api.json

When an application begin to have lots of endpoints, api.json can be long and hard to read.

As #31, endpoints would be probably easier to read/write if api.json + controllers were merged

Something like the following example could work if as #31 we are able to edit / read the information contained in the class

@Controller('user')
class UserController {
  constructor(private app: App) {}

  @Get('/user/:email')
  getUser = {
     entity: 'user',
     query: 'getByEmail'
  }

  @Post({
    endpoint: '/user/signin',
    params: [{
      name: 'email',
      type: DataType.TEXT,
      required: true
    },{
      name: 'password',
      type: DataType.TEXT,
      required: true
    }]
  })
  signin(req, res) {
      //todo
      res.status(200).send('ok')
  }
}

  • Materia Version: v1.0.0-beta.1

Warning when using node 7.0.0

Expected behavior

No warning

Actual behavior

(node:97572)   DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.
  
  - connection.js:299 Object.<anonymous>
    [materia-server]/[pg]/lib/connection.js:299:19
  
  - module.js:20 require
    internal/module.js:20:19
  
  - client.js:18 Object.<anonymous>
    [materia-server]/[pg]/lib/client.js:18:18

Step to reproduce the behavior

with node v7.0.0:

materia start in any app

It's related to brianc/node-postgres#1163


  • Materia Version: v0.3.2

Crash silently if `database.json` is missing

Expected behavior

Materia Server should handle optional database.

If database.json is missing, it should:

  • Print a warning message in the console
  • Don't load Entities and Queries
  • Don't load Endpoints that rely on a query

--no-db option in the CLI should be available to remove the warning (and skip the verification of database.json etc.)

Actual behavior

It crash silently and the process is terminated

~/materia-apps/MateriaWebMap> materia start 
Starting materia in /Users/thyb/materia-apps/MateriaWebMap
~/materia-apps/MateriaWebMap>

Step to reproduce the behavior

  • in the application directory: mv database.json database.json.bak
  • then run materia start

  • Materia Version: v0.1.1

Not able to list and remove existing permissions

Expected behavior

  • app.api.permissions.findAll() should list all permissions added by name

  • app.api.permissions.add(permissionName, middlewareFunction) should add a permission by its name

  • app.api.permissions.remove(permissionName) should remove a permission by its name

  • middlewareFunction should have this prototype:

    function(req, res, next) {
         //todo
    }
    

Actual behavior

  • Not able to list permission

  • app.api.permissions.addFilter(middlewareFunction) without setting up a name

  • Not able to remove a permission

  • Currently, the middlewareFunction have this prototype:

    function(permissions, req, res) {
        //TODO
    }
    

It allows the same permissions features but it adds the possibility to list and remove existing permission (e.g. if an addon is removed, it is expected to remove the associated permissions)

The API changes are also more similar to other Materia Object (e.g. app.endpoints.findAll() etc...)


  • Materia Version: pre-release

Virtual entities generated by addons can affect the readability of Entities structure view

Addons like Mailjet or Stripe generate lots of Virtual Entities and it can be hard to visualize everything easily when combined with the entities made by the users.

As a simple workaround, we can add filters in Entities Structure view in Materia Designer to hide unwanted entities

A better solution would be to be able to create Folder which contains Entity

e.g. add a folder key in the model file to display this entity in a folder

{
   ...
   folder: 'Stripe'
}

  • Materia Version: v0.1.1

Should be able to retrieve metadata from app.addons

Expected behavior

app.addons.findAll() -> get the list of installed addons with the associated metadata: name, description, logo, author
These metadata are in the package.json file in the addon directory.

Actual behavior

app.addons.findAll() doesn't exist.
app.addons.addons is an array containing installed addons without the metadata (we can't even know the name of the addon without checking the class name)


  • Materia Version: pre-release

Support field type `Image` and `File`

Expected behavior

Support Field type Image and File which represent image and file upload via the API.

Behind the scene, the SQL column is a TEXT containing the link/path of an image or a file.
A file upload input needs to be displayed as query/endpoint params (for create/update queries)
Endpoints need to handle file upload correctly.
Some options can be added when creating/updating a field of this type:

  • The directory of the file
  • Resize/crop for image

Validators associated with these new type:

  • MaxSizeValidator
  • MinSizeValidator
  • FileExtensionValidator

  • Materia Version: pre-release

unique with index name in fields

Expected behavior

Define an index name to group unicity on more fields. e.g.

uniqueOne: { type: Sequelize.STRING,  unique: 'compositeIndex'},
uniqueTwo: { type: Sequelize.INTEGER, unique: 'compositeIndex'}

Actual behavior

the unique property accepts only a boolean


  • Materia Version: pre-release

Enable manual database migrations for deployments

The automatic migration may sometimes break. When updating entities, we should generate a migration file that can be applied when deploying the application.

We can use this to generate migrations step:
http://docs.sequelizejs.com/manual/tutorial/migrations.html

Migrations should be displayed in Materia designer and should be editable easily.

The migrations could be automatically applied at deployments time to get the same behavior than what we currently have with automatic migration but it would add some control on how the migration is done.


  • Materia Version: v1.0.0-beta.1

Ignore auto increment on type that is not a number

Expected behavior

Ignore auto increment flag when creating / updating a field that is not a number

Actual behavior

Try to add serial in DB

Step to reproduce the behavior

On designer, change a field type number which has auto increment to type text (without uncheck it before)


  • Materia Version: pre-release

Entity and Field should have an id to detect rename

Expected behavior

An entity should have an id (unique). So when an entity or a field is rename, as the id doesn't change, materia can know it's just a rename and apply this change in the database without data loss.

Actual behavior

An entity is currently identified by its name. The issue is when a user update a json file to rename an entity or a field, materia synchronize the database with the json file and don't see that it's a rename. Instead, it will delete the entity and create a new entity with the new name.

This is dangerous because data can be lost by removing an entire table.

Step to reproduce the behavior

  • Create an entity
  • Create a row of data
  • Go edit the name of the entity directly in the json.
  • Go back to check the data => the table is cleared

  • Materia Version: pre-release

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.