@ords/core
Version:
Microservice architecture with service proposals in nodejs and typescript
151 lines (150 loc) • 3.97 kB
TypeScript
import { Observable, Observer } from 'rxjs';
/**
* Proposal for pesant taking care of the microservices
* root: none is attacted
*/
export declare namespace main {
/**
* Operational flags
*/
namespace flag {
/**
* Indicate that a flag is send
*/
const FLAGSEND = "flag_send";
/**
* Flags for datatype
*/
namespace dataType {
/**
* Data type send back is array
*/
const MULTIPLE = "array is returned";
/**
* Object is send back
*/
const OBJECT = "OBJECT IS RETURNED";
/**
* Raw value suca as a number or date returned
*/
const RAW = "string number or other";
}
/**
* Common errors
*/
namespace error {
/**
* No root found
*/
const NO_ROOT_FOUND = "No root found for command";
/**
* No operation by that name is found on root
*/
const NO_NAME_ON_ROOT = "No name on root found";
/**
* Microservice allready exists on root
*/
const NAME_ON_ROOT_EXISTS = "Name on root allready exists";
}
}
/**
* Types used in proposals
*/
namespace types {
/**
* Observable in key value pairs
*/
type PairObserver = Observer<[any, any]>;
/**
* Observable in key value pairs
*/
type PairObservable = Observable<[any, any]>;
/**
* Base package of request
*/
interface _BaseRequest<T> {
/**
* Pairwise content of the request
*/
package: T;
/**
* Authorised user identifier
*/
auth: string;
/**
* Attachted to the request by registry is what msroot and name that is run
*/
_meta?: {
/**
* Microservice root
*/
msRoot: string;
/**
* Microservice name
*/
msName: string;
};
}
/**
* Request package and auth information about the user
*/
type Request = _BaseRequest<PairObservable>;
/**
* Respons and meta of a service
*/
interface Response {
/**
* Pairwise result of the service
*/
package: PairObservable;
/**
* Meta calculated in the service
*/
meta: PairObservable;
}
/**
* Microservice that takes request and two handlers for returned package and meta
*/
type MicroService = {
(request: Request, metaHand: PairObserver, packHand: PairObserver): void;
};
/**
* Hook that can change behavior of either input or output depedning on the load given
*/
type Hook<T> = {
(load: T): T;
};
/**
* Services hold in a pesant
*/
type Services = {
[root: string]: {
[name: string]: MicroService;
};
};
/**
* Hooks hold in a pesant
*/
type Hooks = {
pre: Array<{
root: string;
name: string;
hook: Hook<Request>;
}>;
post: Array<{
root: string;
name: string;
hook: Hook<Response>;
}>;
};
}
/**
* Default content of packages
*/
interface Packages {
/**
* Packages can contain any key with corrosponding value
*/
[key: string]: any;
}
}