adding microgears definitions (#8930)

This commit is contained in:
Marcus David Bronstein
2016-04-12 12:20:20 -03:00
committed by Masahiro Wakame
parent d890dbd5f3
commit b572283659
2 changed files with 91 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
/// <reference path="microgears.d.ts" />
function verify_module_file() {
var tracePlugin = new TracePlugin();
microgears.addPlugin(tracePlugin);
var service = new UserService();
var userService = microgears.addService(service);
}
class TracePlugin implements microgears.Plugin {
name: 'TracePlugin';
public beforeChain(args:Array<any>, _meta: microgears.MetaInformation) {
var serviceName = _meta.serviceName,
method = _meta.methodName;
console.log('before call-> ' + serviceName + '.' + method);
_meta.extra = {
count: 1
};
return args
}
public afterChain(result:any, _meta: microgears.MetaInformation) {
var serviceName = _meta.serviceName,
method = _meta.methodName;
console.log('after of-> ' + serviceName + '.' + method);
if (_meta.extra.count) {
console.log('this number comes to the beforeChain: ' + _meta.extra.count);
}
return result;
}
}
class User {
name: string;
email: string;
constructor(name: string, email: string) {
this.email = email;
this.name = name;
}
}
class UserService implements microgears.Service {
name: string = "userService";
namespace: string = "services.user";
public findUserById(id: number) {
return new User('test', 'test@example.com');
}
}

33
microgears/microgears.d.ts vendored Normal file
View File

@@ -0,0 +1,33 @@
// Type definitions for microgears v4.0.0
// Project: http://github.com/marcusdb/microgears
// Definitions by: Marcus David Bronstein <https://github.com/marcusdb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace microgears {
export interface Service {
name: string;
async?: boolean;
pathname?: string;
namespace: string;
}
interface MetaInformation {
serviceName: string;
methodName: string;
serviceNameSpace: string;
extra: any;
}
interface Plugin {
name: string;
beforeChain(arguments: Array<any>, metaInfo: MetaInformation): Array<any>;
afterChain<T>(result: T, metaInfo: MetaInformation): T;
}
function addService(service: Service): Service;
function addPlugin(plugin: Plugin): void;
}
declare module "microgears" {
export = microgears;
}