morphi
Isomorphic solution for expressjs and angular5
Last updated a year ago by darekf77 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install morphi 
SYNC missed versions from official npm registry.

MorphiJSlogo

Morphi v2 (BETA)

Isomorphic framework in TypeScript for NodeJS back-end and browser (web/mobile) front-end.


Do no repeat yourself anymore, never !!!

  • -NO MORE SEPARATION BETWEEN BACKEND AND FRONTEND !
  • - Isomorphic classes as Angular/Ionic Services and ExpressJS controllers.
  • One node_modules folder for browser, mobile and server.
  • - Write everything in TypeScript all the time and
    automaticly strip off server code for browser/ionic versions.
  • - Use power of TypeORM framwork to write awesome, robust, clean NodeJS backend
    connected to SQLite, Mysql, WebSQL, MongoDB and many others...
  • - Keep amazing code consistency thanks to isomorphic entities classes, that you can use to
    create backend tables and also inside frontend-angular templates with type checking.
  • - Change business logic in the fastest possible way!
    - generate formly objects from entites
    - have typescript typechecking from entity in db to html template!
    - set default values to entities
  • Support project to develop only amazing, creative things in the future...
  • Project is under development, but every juicy features just works... try example.


  • TODO:
    - firebase like... realtime update of backend/frontend (in progress)
    - extended authentication based on isomorphic decorators metadata and db roles (in progress)
    - isomoprhic unit tests (with inheritance) in mocha/jasmine
    - vscode extension to support @backend, @backendFunc #regions

Instalation

Global CLI

First install global tool:

npm install -g morphi

Create new Isomorphic Workspace project ( mobile, web, server + sqlite db + basic rest authentication )

morphi new:workspace myAwesomeIsomrphicApp

OR create Isomorphic Single File backend/frontend project

morphi new:simple myAwesomeIsomrphicApp

Visual Studio Code (recommended editor)

Open your project in VSCode to get the maximum of development experience.

code myAwesomeIsomrphicApp

Installation - Isomorphi Workspace

Link one version of node_modules

Once you have your app opened...

files

run:

npm install
npm run link

to install and link node_module folder for each subproject.

Build and run sub-projects with auto-reload

  • isomorphic-lib: npm run build:watch #or morphi:watch + F5 to run server
  • angular-client: npm run build:watch + open browser http:\\localhost:4200
  • ionic-client: npm run build:watch + open browser http:\\localhost:8100

Instead of npm run build:watch you can also open each sub-project in separated vscode window code <sub-project-name> and press: ctrl(cmd) + shift + b.

Installation - Isomorphi Single File

Install dependencies

Once you have your app opened... run:

npm install

Run isomorphic build

morphi build:watch

Run frontend client

npm run build:watch

Backend controllers, entities directly in the frontend

Isomorphic TypeScript Classes

The main reason why this framework has huge potential is that you can use your backend code ( usualy ExpressJS, REST controllers ) as Anguar 2+ (or any other js framework) services, to access your RESTfull backend without dealing with backend patches and unessery source code.

This will allow you to change business login very quickly, without confusion and keep no separation between your frontend/backend application.

Morphi CLI tool

Is responsible for magic behing stripping of backend code for browser version ( web app or ionic mobile app).

Regions @backend,@backendFunc

The difference between @backend and @backendFunc is that @backendFunc will replace code with 'return undefined' (it is needed for typescript compilation) and @backend will precisely delete all lines between.

HOW IT WORKS:

+ Isomorphi initilization

Initialization for backend and frontend

import { Morphi } from 'morphi';


@Morphi.init({
  controllers: [ /* Your controllers clases here */ UserController  ],
  entites: [ /* Your entites clases here */  User ],
  host: 'http://localhost:4000' // host for backend and frontend,
  //#region @backend
  config: { /* Your db config clases here */  }
  //#endregion
})

To inject providers you can use

import { Morphi } from 'morphi';

...
  providers: [  ...Morphi.Providers  ]
...

+ Isomorphi backend

Typeorm isomorphic ENTITY in NodeJS backend:

import { Morphi } from 'morphi';

@Morphi.Entity()
export class User {

    //#region @backend
    @Morphi.Orm.Column.Primary()
    //#endregion
    id: number;

    //#region @backend
    @Morphi.Orm.Column.Custom()
    //#endregion
    name: string;

    //#region @backend
    @Morphi.Orm.Column.Custom()
    //#endregion
    surname: string;

    fullName() {
      return `${this.name} ${this.surname}`
    }
    
    //#region @backend 
    password: string
    //#endregion

}

Morphi isomorphic CONTROLLER in NodeJS backend:

import { Morphi } from 'morphi'

@Morphi.Controller() 
class UserController {
		
	@Morphi.Http.GET()
	getAllUser() {
		//#region @backendFunc 
		const  repository  =  this.connection.getRepository(User) as  any;
		return  async (req, res) => {
			return await  this.repository.findAll();
		}
		//#endregion
	}	
}

After isomorphic compilation by morphi;

morphi build

or (incremental watch build)

morphi build:watch

will be generated browser version.

+ Generated borwser version

The result for browser client will be like below:

Typeorm isomorphic ENTITY in browser version:

import { Morphi } from 'morphi/browser';

@Morphi.Entity()
export class User {

    id: number;

    name: string;

    surname: string;

    fullName() {
      return `${this.name} ${this.surname}`
    }
}

Morphi isomorphic CONTROLLER in browser version:

import { Morphi } from 'morphi/browser'

@Morphi.Controller()
class UserController {
	 // 'return undefined' is for purpose on the browser side
	 // The function body will be replaced through decorate
	 // to access REST endpoint
	@Morphi.Http.GET()
	getAllUser() { 
    return undefined; 
    }	
}

Angular 2+ services

Morphi.Controller(s) you can use as Angular 2+ services. If you used Morphi.Entity your browser <-> backend REST communication will keep entity type and automaticly reproduce it.

@Component({
	selector:  'app-test',
	templateUrl:'app-test.html'
})
class  AppTestComponent  implements  OnInit {

	// Inject isomorphic class as service into component
	constructor(public users: UserController) { } 
	
	async ngOnInit() {
          const data = await this.users.getAllUsers().received;
          const users = data.body.json;
          const firstUser = users[0]
          console.log( firstUser instanceOf User ) // true
	}
}

Directly in html template

To simplify object receiving from backend you can use async pipes (available with Angular4+) and really make you MVVM amazing.

Morphi and Angular4+ lets you use backend functions in html frontend template.

app-test.html

Users:
<ul   *ngIf="users.getAllUsers().received.observable | async; else loader; let users" >

  <li  *ngFor="let user of users"> 
  		{{user.id}} {{user.fullName()}} <!-- BACKEND FUNCTION IN FRONTEND TEMPLATE ! -->
		  <br>
		<input type="name" [(NgModel)]="user.name" >
  </li>

</ul>

<ng-template #loader> loading users...  </ng-template>

Of course Angular services can be used inside Angular web and Ionic mobile apps.

Current Tags

  • 2.0.64                                ...           latest (8 days ago)

133 Versions

  • 2.0.64                                ...           8 days ago
  • 2.0.63                                ...           24 days ago
  • 2.0.61                                ...           2 months ago
  • 2.0.59                                ...           3 months ago
  • 2.0.58                                ...           3 months ago
  • 2.0.56                                ...           3 months ago
  • 2.0.55                                ...           3 months ago
  • 2.0.54                                ...           3 months ago
  • 2.0.52                                ...           4 months ago
  • 2.0.51                                ...           5 months ago
  • 2.0.50                                ...           5 months ago
  • 2.0.45                                ...           5 months ago
  • 2.0.44                                ...           5 months ago
  • 2.0.43                                ...           5 months ago
  • 2.0.42                                ...           5 months ago
  • 2.0.41                                ...           5 months ago
  • 2.0.40                                ...           5 months ago
  • 2.0.39                                ...           5 months ago
  • 2.0.32                                ...           5 months ago
  • 2.0.31                                ...           5 months ago
  • 2.0.30                                ...           6 months ago
  • 2.0.29                                ...           6 months ago
  • 2.0.28                                ...           6 months ago
  • 2.0.27                                ...           6 months ago
  • 2.0.26                                ...           6 months ago
  • 2.0.25                                ...           6 months ago
  • 2.0.24                                ...           6 months ago
  • 2.0.23                                ...           6 months ago
  • 2.0.21                                ...           7 months ago
  • 2.0.20                                ...           7 months ago
  • 2.0.19                                ...           7 months ago
  • 2.0.18                                ...           7 months ago
  • 2.0.17                                ...           7 months ago
  • 2.0.16                                ...           8 months ago
  • 2.0.15                                ...           8 months ago
  • 2.0.14                                ...           8 months ago
  • 2.0.13                                ...           8 months ago
  • 2.0.12                                ...           8 months ago
  • 2.0.11                                ...           8 months ago
  • 2.0.10                                ...           8 months ago
  • 2.0.9                                ...           9 months ago
  • 2.0.8                                ...           9 months ago
  • 2.0.6                                ...           10 months ago
  • 2.0.5                                ...           10 months ago
  • 2.0.4                                ...           10 months ago
  • 2.0.3                                ...           10 months ago
  • 2.0.2                                ...           10 months ago
  • 2.0.1                                ...           10 months ago
  • 1.0.78                                ...           10 months ago
  • 1.0.77                                ...           10 months ago
  • 1.0.76                                ...           10 months ago
  • 1.0.75                                ...           10 months ago
  • 1.0.74                                ...           10 months ago
  • 1.0.73                                ...           10 months ago
  • 1.0.70                                ...           10 months ago
  • 1.0.69                                ...           10 months ago
  • 1.0.68                                ...           10 months ago
  • 1.0.67                                ...           a year ago
  • 1.0.66                                ...           a year ago
  • 1.0.65                                ...           a year ago
  • 1.0.64                                ...           a year ago
  • 1.0.63                                ...           a year ago
  • 1.0.62                                ...           a year ago
  • 1.0.61                                ...           a year ago
  • 1.0.60                                ...           a year ago
  • 1.0.59                                ...           a year ago
  • 1.0.58                                ...           a year ago
  • 1.0.57                                ...           a year ago
  • 1.0.56                                ...           a year ago
  • 1.0.55                                ...           a year ago
  • 1.0.54                                ...           a year ago
  • 1.0.53                                ...           a year ago
  • 1.0.52                                ...           a year ago
  • 1.0.51                                ...           a year ago
  • 1.0.50                                ...           a year ago
  • 1.0.49                                ...           a year ago
  • 1.0.48                                ...           a year ago
  • 1.0.47                                ...           a year ago
  • 1.0.46                                ...           a year ago
  • 1.0.45                                ...           a year ago
  • 1.0.44                                ...           a year ago
  • 1.0.43                                ...           a year ago
  • 1.0.42                                ...           a year ago
  • 1.0.41                                ...           a year ago
  • 1.0.40                                ...           a year ago
  • 1.0.39                                ...           a year ago
  • 1.0.38                                ...           a year ago
  • 1.0.37                                ...           a year ago
  • 1.0.36                                ...           a year ago
  • 1.0.35                                ...           a year ago
  • 1.0.33                                ...           a year ago
  • 1.0.32                                ...           a year ago
  • 1.0.31                                ...           a year ago
  • 1.0.30                                ...           a year ago
  • 1.0.29                                ...           a year ago
  • 1.0.28                                ...           a year ago
  • 1.0.27                                ...           a year ago
  • 1.0.26                                ...           a year ago
  • 1.0.24                                ...           a year ago
  • 1.0.23                                ...           a year ago
  • 1.0.22                                ...           a year ago
  • 1.0.20                                ...           a year ago
  • 1.0.18                                ...           2 years ago
  • 1.0.16                                ...           2 years ago
  • 1.0.14                                ...           2 years ago
  • 1.0.13                                ...           2 years ago
  • 1.0.12                                ...           2 years ago
  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           2 years ago
  • 0.0.17                                ...           2 years ago
  • 0.0.16                                ...           2 years ago
  • 0.0.15                                ...           2 years ago
  • 0.0.13                                ...           2 years ago
  • 0.0.12                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.10                                ...           2 years ago
  • 0.0.9                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 20
Last Day 0
Last Week 18
Last Month 25
Dependencies (37)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |