├── src
├── runner
│ ├── index.ts
│ └── runner.ts
├── structs
│ ├── index.ts
│ └── response.ts
├── log
│ ├── index.ts
│ ├── stub.ts
│ └── pino.ts
├── redis
│ ├── index.ts
│ ├── factory.ts
│ └── client.ts
├── config
│ ├── index.ts
│ ├── constants.ts
│ └── app_config.ts
├── meter
│ ├── index.ts
│ ├── stub.ts
│ ├── statsd.ts
│ └── meter.ts
├── ids
│ ├── index.ts
│ ├── round_counter.ts
│ ├── snow_flake.ts
│ └── the-ids.ts
├── rpc
│ ├── index.ts
│ ├── constants.ts
│ ├── status.ts
│ ├── cache.ts
│ ├── adapter
│ │ └── redis.ts
│ └── agnostic.ts
├── types
│ ├── index.ts
│ ├── band.ts
│ ├── config.ts
│ ├── log.ts
│ ├── meter.ts
│ ├── redis.ts
│ └── rpc.ts
└── index.ts
├── .gitignore
├── .bumpversion.cfg
├── @types
├── flake-idgen
│ └── index.d.ts
├── cctz
│ └── index.d.ts
├── merge-options
│ └── index.d.ts
├── xxhash
│ └── index.d.ts
└── redis-fast-driver
│ └── index.d.ts
├── .editorconfig
├── Dockerfile
├── README.md
├── tsconfig.json
├── makefile
├── package.json
├── .travis.yml
├── LICENSE
└── yarn.lock
/src/runner/index.ts:
--------------------------------------------------------------------------------
1 | export * from './runner';
2 |
--------------------------------------------------------------------------------
/src/structs/index.ts:
--------------------------------------------------------------------------------
1 | export * from './response';
2 |
--------------------------------------------------------------------------------
/src/log/index.ts:
--------------------------------------------------------------------------------
1 | export * from './pino';
2 | export * from './stub';
3 |
--------------------------------------------------------------------------------
/src/redis/index.ts:
--------------------------------------------------------------------------------
1 | export * from './client'
2 | export * from './factory'
3 |
--------------------------------------------------------------------------------
/src/config/index.ts:
--------------------------------------------------------------------------------
1 | export * from './app_config';
2 | export * from './constants';
3 |
--------------------------------------------------------------------------------
/src/meter/index.ts:
--------------------------------------------------------------------------------
1 | export * from './statsd'
2 | export * from './meter'
3 | export * from './stub'
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.vscode
2 | /node_modules
3 | /yarn-error.log
4 | /deploy
5 | /.env*
6 | /dist
7 | /emergency
8 |
--------------------------------------------------------------------------------
/src/ids/index.ts:
--------------------------------------------------------------------------------
1 | export * from './round_counter';
2 | export * from './the-ids';
3 | export * from './snow_flake';
4 |
--------------------------------------------------------------------------------
/src/config/constants.ts:
--------------------------------------------------------------------------------
1 | export const ENV_DEV = 'dev';
2 | export const ENV_PROD = 'production';
3 | export const ENV_STAGE = 'stage';
4 |
--------------------------------------------------------------------------------
/src/rpc/index.ts:
--------------------------------------------------------------------------------
1 | export * from './agnostic'
2 | export * from './adapter/redis'
3 | export * from './constants'
4 | export * from './status'
5 |
--------------------------------------------------------------------------------
/src/types/index.ts:
--------------------------------------------------------------------------------
1 | export * from './meter';
2 | export * from './redis';
3 | export * from './rpc';
4 | export * from './log'
5 | export * from './config';
6 | export * from './band';
7 |
--------------------------------------------------------------------------------
/.bumpversion.cfg:
--------------------------------------------------------------------------------
1 | [bumpversion]
2 | current_version = 1.8.5
3 | commit = True
4 | tag = False
5 |
6 | [bumpversion:file:package.json]
7 |
8 | [bumpversion:file:Dockerfile]
9 |
10 | [bumpversion:file:src/index.ts]
11 |
12 |
--------------------------------------------------------------------------------
/@types/flake-idgen/index.d.ts:
--------------------------------------------------------------------------------
1 |
2 | ///
3 |
4 | declare module 'flake-idgen' {
5 |
6 | class FlakeId {
7 | constructor(options?: any);
8 | next(cb?: (id: Buffer) => any): Buffer;
9 | }
10 |
11 | namespace FlakeId { }
12 | export = FlakeId;
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './ids';
2 | export * from './meter';
3 | export * from './rpc';
4 | export * from './types';
5 | export * from './log';
6 | export * from './redis';
7 | export * from './config';
8 | export * from './structs';
9 | // export * from './runner';
10 | export const version = '1.8.5';
--------------------------------------------------------------------------------
/@types/cctz/index.d.ts:
--------------------------------------------------------------------------------
1 | // TypeScript Version: 2.7
2 |
3 | ///
4 |
5 | declare module 'cctz' //{
6 |
7 | // interface cctz {
8 | // format(format: string, unix: number, timezone?: string): string;
9 | // }
10 |
11 | // namespace cctz { }
12 | // export = cctz;
13 | // }
14 |
--------------------------------------------------------------------------------
/src/rpc/constants.ts:
--------------------------------------------------------------------------------
1 | export const SERVICE_DIRECTOR = 'director';
2 | export const SERVICE_KERNEL = 'kernel';
3 | export const SERVICE_TRACK = 'track';
4 |
5 | export const METHOD_IAMALIVE = '__iamalive';
6 | export const METHOD_STATUS = '__status';
7 |
8 | export const BROADCAST = 'broadcast';
9 |
10 |
11 |
12 | // ### Orchastration
13 |
14 | export const STATUS_RUNNING = 'running';
15 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # http://editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 | indent_style = space
9 | indent_size = 2
10 | end_of_line = lf
11 | charset = utf-8
12 | trim_trailing_whitespace = true
13 | insert_final_newline = true
14 |
15 | [*.md]
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/src/meter/stub.ts:
--------------------------------------------------------------------------------
1 | import { MeterFacade } from '../types';
2 |
3 | export class StubMeter implements MeterFacade {
4 | tick(metric: string, tags?: { [k: string]: string | number }): void { }
5 | timenote(metric: string, tags?: { [k: string]: string | number }): () => number {
6 | return () => 0;
7 | }
8 | time(metric: string, duration: number, tags?: { [k: string]: string | number }): void { }
9 | }
10 |
--------------------------------------------------------------------------------
/src/redis/factory.ts:
--------------------------------------------------------------------------------
1 | import { RedisClient } from "../redis";
2 | import { RedisClientOptions, RedisFactoryType } from "../types";
3 |
4 |
5 | export class RedisFactory implements RedisFactoryType {
6 | options: RedisClientOptions;
7 |
8 | constructor(options: RedisClientOptions) {
9 | this.options = options;
10 | }
11 |
12 | create(): RedisClient {
13 | return new RedisClient(this.options)
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/ids/round_counter.ts:
--------------------------------------------------------------------------------
1 |
2 | const DEFAULT_SIZE = 99999;
3 |
4 | export class IdGenRoundCounter {
5 | num: number;
6 | size: number;
7 |
8 | constructor(size: number = DEFAULT_SIZE) {
9 | this.num = Math.round(Math.random() * size);
10 | this.size = size;
11 | }
12 |
13 | take(): number {
14 | if (this.num === this.size) {
15 | this.num = 0;
16 | }
17 | return ++this.num;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:8-alpine
2 |
3 | LABEL maintainer="Dmitry Rodin "
4 | LABEL band.base-ts.version="1.8.5"
5 |
6 | ENV TZ UTC
7 | ENV LOG_LEVEL warn
8 |
9 | RUN apk add python --no-cache make build-base gcc git curl
10 |
11 | WORKDIR /usr/src/rockme
12 |
13 | COPY package.json .
14 | COPY yarn.lock .
15 |
16 | RUN yarn install \
17 | && yarn cache clean
18 |
19 | COPY . .
20 |
21 | RUN yarn build && yarn link
22 |
--------------------------------------------------------------------------------
/src/ids/snow_flake.ts:
--------------------------------------------------------------------------------
1 | import * as FlakeIdGen from 'flake-idgen';
2 | import { Uint64BE } from 'int64-buffer'
3 |
4 | export class IdGenShowFlake {
5 |
6 | idGen: FlakeIdGen;
7 |
8 | constructor() {
9 | this.idGen = new FlakeIdGen();
10 | }
11 |
12 | take(): string {
13 | const idBuff = this.idGen.next();
14 | return new Uint64BE(idBuff).toString();
15 | }
16 |
17 | withTime() {
18 | return {
19 | id: this.take(),
20 |
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/@types/merge-options/index.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for merge-options
2 | // Project:
3 | // Definitions by: Dmitry Rodin
4 | // TypeScript Version: 2.8
5 |
6 | declare module 'merge-options' {
7 |
8 | // type anyobj = { [key: string]: string };
9 | type OptionsType = object
10 | interface Assign {
11 | (...obj: OptionsType[]): any;
12 | }
13 | const mergeOptions: Assign;
14 |
15 | namespace mergeOptions { }
16 | export = mergeOptions;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/rpc/status.ts:
--------------------------------------------------------------------------------
1 | import { format as dateFormat } from 'cctz';
2 | import { RPCAppStatus, RequestHandler } from '../types';
3 |
4 | export class AppStatus {
5 | appStarted: Date = new Date();
6 |
7 | get: RequestHandler