3.5.3 • Published 5 years ago

@renanhangai/miniservices v3.5.3

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
5 years ago

miniserver

Installation

yarn add @renanhangai/miniservices

Getting started

First, define your base application class App.ts

import { AppBase } from "@renanhangai/miniservices";
const ServiceConstructorMap = {};
export class App extends AppBase<typeof ServiceConstructorMap> {
	protected serviceConstructorMap = ServiceConstructorMap;
}

Then, define your base service class Service.ts

import { ServiceBaseGeneric } from "@renanhangai/miniservices";

export class ServiceBase extends ServiceBaseGeneric<import("./App").App>;

Define your service Random.ts

import { ServiceBase } from "./Service";

export class RandomService extends ServiceBase {
	getRandom(): number {
		return 2;
	}
}

Define your service in your app file App.ts

import { AppBase } from "@renanhangai/miniservices";
import { RandomService } from "./Random";
const ServiceConstructorMap = {
	random: RandomService
};
class App extends AppBase<typeof ServiceConstructorMap> {}

Run your app index.ts

import { App } from "./App";

async function main() {
	const app = await App.runFromArgv(process.argv);
	console.log(app.services.random.getRandom());
}

main();

Included services

hapi

Create API endpoints

import { ServiceBase } from "...";
import { createService, HapiServer } from "@renanhangai/miniservices/lib/hapi";

export const ApiService = createService(ServiceBase, {
	server: {
		port: 80,
		routes: {
			cors: true
		}
	},
	auth(server: HapiServer) {
		// Called before everything, here you must setup the authorization
		// plugins
	},
	register(server: HapiServer) {
		// Calls registration functions for the hapi server or routes
	},
	// The graphql options automatically setups an apollo server
	graphql: {
		// Path where the middleware will be applied
		path: "/graphql",
		// Apollo options for the server
		apollo: { ... },
	}
});

typeorm

Manage typeorm connections

import { ServiceBase } from "...";
import { createService } from "@renanhangai/miniservices/lib/typeorm";

export const DatabaseService = createService(ServiceBase, {
	default: {
		type: "mysql",
		host: "localhost",
		database: "test",
		username: "root",
		password: "root",
		entities: [ ... ],
	}
});
// Gets the default connection (alias for service.connections.default)
service.connection;
// Object with all the connections
service.connections;
3.5.3

5 years ago

3.5.2

5 years ago

3.5.1

5 years ago

3.5.0

5 years ago

3.4.0

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.4

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-alpha.2

5 years ago

2.0.0-alpha.1

5 years ago

2.0.0-alpha.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago