Comparing version 0.2.0 to 0.3.0
@@ -0,2 +1,3 @@ | ||
export { default as EndpointMapBuilder } from './EndpointMapBuilder'; | ||
export { default as Server } from './Server'; | ||
export { default as makeRequest } from './makeRequest'; | ||
export { default as Server } from './Server'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var EndpointMapBuilder_1 = require("./EndpointMapBuilder"); | ||
exports.EndpointMapBuilder = EndpointMapBuilder_1.default; | ||
var Server_1 = require("./Server"); | ||
exports.Server = Server_1.default; | ||
var makeRequest_1 = require("./makeRequest"); | ||
exports.makeRequest = makeRequest_1.default; | ||
var Server_1 = require("./Server"); | ||
exports.Server = Server_1.default; |
/// <reference types="node" /> | ||
import * as http from 'http'; | ||
import * as Joi from 'joi'; | ||
export interface ServerConfigs { | ||
port?: number; | ||
redisUrl?: string; | ||
} | ||
export interface CacheOption { | ||
ttl: number; | ||
limit?: number; | ||
} | ||
export interface Endpoint { | ||
schema: Joi.Schema; | ||
timeout?: number; | ||
cacheOption?: CacheOption | false; | ||
handler(payload: any, delegator: Delegator): any; | ||
} | ||
export interface Delegator { | ||
makeDelegateRequestAsync(topic: string, payload: any, target: string): any; | ||
} | ||
import { Endpoint, ServerConfigs } from './types'; | ||
export default class Server { | ||
@@ -26,5 +9,5 @@ private app; | ||
private port; | ||
private endpoints; | ||
private endpointMap; | ||
private server; | ||
constructor(configs?: ServerConfigs); | ||
constructor(endpointMap: Map<string, Endpoint>, configs?: ServerConfigs); | ||
getAddress(): { | ||
@@ -35,3 +18,2 @@ port: number; | ||
}; | ||
addEndpoint(topic: string, endpoint: Endpoint): void; | ||
start(): Promise<http.Server | null>; | ||
@@ -38,0 +20,0 @@ terminate(): Promise<void>; |
@@ -13,3 +13,2 @@ "use strict"; | ||
const Boom = require("boom"); | ||
const Redis = require("ioredis"); | ||
const Joi = require("joi"); | ||
@@ -20,6 +19,7 @@ const Koa = require("koa"); | ||
const hash = require("object-hash"); | ||
const createRedisClient_1 = require("./createRedisClient"); | ||
const makeRequest_1 = require("./makeRequest"); | ||
const DEFAULT_TIMEOUT = 20000; | ||
class Server { | ||
constructor(configs = {}) { | ||
constructor(endpointMap, configs = {}) { | ||
this.app = new Koa(); | ||
@@ -42,4 +42,4 @@ this.app.use(bodyParser({ | ||
this.app.use(this.router.routes()); | ||
if (configs.redisUrl) { | ||
this.redis = new Redis(configs.redisUrl); | ||
if (configs.redis) { | ||
this.redis = createRedisClient_1.default(configs.redis.redisUrl, configs.redis.sentinelMasterName); | ||
} | ||
@@ -49,3 +49,3 @@ if (configs.port) { | ||
} | ||
this.endpoints = new Map(); | ||
this.endpointMap = endpointMap; | ||
} | ||
@@ -57,7 +57,2 @@ getAddress() { | ||
} | ||
addEndpoint(topic, endpoint) { | ||
if (this.endpoints.has(topic)) | ||
throw new Error('Endpoint already existed!'); | ||
this.endpoints.set(topic, endpoint); | ||
} | ||
start() { | ||
@@ -116,3 +111,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = this.endpoints.get(topic); | ||
const endpoint = this.endpointMap.get(topic); | ||
if (!endpoint) | ||
@@ -119,0 +114,0 @@ throw Boom.badRequest('Invalid topic'); |
{ | ||
"name": "chayen", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "An RPC framework with so much hype going on. such wow.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128358
17
295