Skip to content

Instantly share code, notes, and snippets.

@christopherobin
Created April 24, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherobin/9969d18277de74b218f9ca7007906d0a to your computer and use it in GitHub Desktop.
Save christopherobin/9969d18277de74b218f9ca7007906d0a to your computer and use it in GitHub Desktop.
// Type definitions for MAGE 1.0.2
// Project: https://github.com/mage/mage
// Definitions by: Christophe Robin <crobin@nekoo.com>
/// <reference types="node" />
import events = require('events');
declare namespace mage {
interface IMage {
task: ITask;
version: string;
require(packageName: string): any;
getRunState(): string;
setRunState(state: string): string;
setTask(name: string, options: any): void;
getTask(): ITask;
setupCoreLibs(): IMage;
quit(exitCode?: number, hard?: boolean): never;
fatalError(...args: any[]): never;
addModulesPath(modPath: string): IMage;
useModules(modules: string[]): IMage;
useApplicationModules(): IMage;
getModulePath(name: string): string;
listModules(): string[];
setupModules(cb: (Error) => void): void;
setup(cb?: (error?: Error) => void): IMage;
start(cb?: (error?: Error) => void): IMage;
boot(cb?: (error?: Error) => void): void;
isDevelopmentMode(feature?: string): boolean;
getClientConfig(appName: string, baseUrl: string): any;
// common modules
core: {
modules: { [key: string]: IModule },
config: any,
logger?: LogCreator;
session?: ISessionModule;
}
auth?: IAuthModule;
time?: ITimeModule;
}
interface ITask {
setup(cb: (error?: Error) => void): void;
start(cb: (error?: Error) => void): void;
shutdown(cb: (error?: Error) => void): void;
}
interface IModule {
setup?(state: IState, cb: (error?: Error) => void): void;
start?(state: IState, cb: (error?: Error) => void): void;
shutdown?(state: IState, cb: (error?: Error) => void): void;
}
interface IState {
archivist?: IArchivist;
setTimeout(timeout: number): void;
clearTimeout(): void;
registerSession(session: ISession): void;
}
interface IArchivistModule extends IModule, events.EventEmitter {
listPeerDependencies(): { [description: string]: string[] };
getPersistentVaults(): { [name: string]: IVault };
assertTopicAbilities(topic: string, index: IArchivistIndex, operations: string[]): void;
closeVaults(): void;
topicExists(topic: string): boolean;
getTopics(): { [topic: string]: { index: string[] } };
getTopicApi(topic: string, vaultName: string): any;
migrateToVersion(targetVersion: string, cb: (error?: Error) => void): void;
Archivist: IArchivist;
}
interface IArchivist {
state: IState;
loaded: object;
privateVaults: { [vaultName: string]: IVault };
constructor(state: IState);
clearCache(): void;
createVault(vaultName: string, vaultType: string, vaultConfig: object, cb: (error?: Error) => void): void;
getTopicApi(topic: string, vaultName: string): any;
getPrivateVault(name: string): IVault;
getListVault(name: string): IVault;
getListVaults(): IVault[];
getReadVault(name: string): IVault;
getReadVaults(): IVault[];
getWriteVault(name: string): IVault;
getWriteVaults(): IVault[];
// operations
exists(topic: string, index: IArchivistIndex, cb: (error?: Error, exists?: boolean) => void): void;
get<T>(topic: string, index: IArchivistIndex, cb: (error?: Error, value?: T) => void): void;
get<T>(topic: string, index: IArchivistIndex, options: object, cb: (error?: Error, value?: T) => void): void;
getValue<T>(topic: string, index: IArchivistIndex, cb: (error?: Error, value?: IVaultValue<T>) => void): void;
getValue<T>(topic: string, index: IArchivistIndex, options: object, cb: (error?: Error, value?: IVaultValue<T>) => void): void;
mget<T>(queries: IArchivistMgetQueries, cb: (error?: Error, results?: T) => void): void;
mget<T>(queries: IArchivistMgetQueries, options: object, cb: (error?: Error, results?: T) => void): void;
mgetValues(queries: IArchivistMgetQueries, cb: (error?: Error, results?: IVaultValue<any>) => void): void;
mgetValues(queries: IArchivistMgetQueries, options: object, cb: (error?: Error, results?: IVaultValue<any>) => void): void;
list(topic: string, partialIndex: any, cb: (error?: Error, indexes?: IArchivistIndex[]) => void): void;
list(topic: string, partialIndex: any, options: object, cb: (error?: Error, indexes?: IArchivistIndex[]) => void): void;
add(topic: string, index: IArchivistIndex, data: any, mediaType?: string, encoding?: string, expirationTime?: number): void;
set(topic: string, index: IArchivistIndex, data: any, mediaType?: string, encoding?: string, expirationTime?: number): void;
del(topic: string, index: IArchivistIndex): void;
touch(topic: string, index: IArchivistIndex, expirationTime?: number): void;
}
interface IArchivistIndex {
[key: string]: any
}
type IArchivistMgetQueries = { [key: string]: IArchivistMgetQuery }|IArchivistMgetQuery[];
type IArchivistMgetQuery = { topic: string, index: IArchivistIndex };
interface IVaultValue<T> {
operation: string;
data: T;
encoding: string;
resetOption(): void;
hasOperation(): boolean;
getOperationForVault(vault: IVault): string;
registerReadMiss(vault: IVault): void;
didNotExist(): void;
add(mediaType: string, data: T, encoding: string): void;
set(mediaType: string, data: T, encoding: string): void;
touch(expirationTime: number): void;
del(): void;
getDiff(): object[]|null;
}
interface IVault {
}
interface IAuthModule extends IModule {
authenticate(state: IState, username: string, password: string, cb: (error?: Error, userId?: string, acl?: string[]) => void): void;
login(state: IState, username: string, password: string, cb: (error?: Error, session?: ISession) => void): void;
loginAnonymous(state: IState, options: UserOptions): ISession;
register(state: IState, username: string, password: string, options: UserOptions, cb: (error?: Error, userId?: string|number) => void): void;
// internal stuff
getSessionModule(): ISessionModule;
getHashConfiguration(): object;
getArchivistTopic(): string;
checkArchivistConfiguration(topic: string, index: string[], operations: string[]): void;
}
type UserOptions = { userId?: string|number, acl?: string[] };
interface LogCreator extends IModule {
constructor(distributor: IDistributor);
enableChannel(name: string): void;
disableChannel(name: string): void;
addContexts(...contexts: string[]): void;
context(...contexts: string[]): LogCreator;
createChannelHandler(channelName: string): void;
createChannelDecoy(channelName: string): void;
simulate(engine: string): void;
// here are the usual channels created
time?: ILogHandler;
verbose?: ILogHandler;
debug?: ILogHandler;
info?: ILogHandler;
notice?: ILogHandler;
warning?: ILogHandler;
error?: ILogHandler;
critical?: ILogHandler;
alert?: ILogHandler;
emergency?: ILogHandler;
_contexts: string[];
_distributor: IDistributor;
}
interface ILogHandler {
(...messageArgs: string[]): void;
context(...contexts: string[]): this;
details(...details: string[]): this;
data(label?: string, data?: any): this;
log: this;
}
interface IDistributor {
// not accessed by the user
}
interface ISessionModule extends IModule {
sessionTTL: number;
getActorAddresses(state: IState, actorIds: string[], cb: (error?: Error, addresses?: string[]) => void): void;
register(state: IState, actorId: string, language: string, meta?: any): ISession;
reassign(state: IState, fromActorId: string, toActorId: string, cb: (error?: Error, session?: ISession) => void): void;
getActorSession(state: IState, actorId: string, cb: (error?: Error, session?: ISession) => void): void;
resove(state: IState, key: string, cb: (error?: Error, session?: ISession) => void): void;
getNewExpirationTime(): number;
}
interface ISession {
constructor(meta: any, actorId: string, language: string, key: string, clusterId: string, creationTime: number, version: string);
getFullKey(): string;
expire(state: IState, reason: string): void;
extend(state: IState): void;
save(state: IState): void;
setOnClient(state: IState): void;
getData(key: string): any;
setData(state: IState, key: string, value: any): void;
delData(state: IState, key: string): void;
}
interface ISessionFactory {
create(meta: any, actorId: string, language: string): ISession;
fromData(data: any): ISession;
}
interface ITimeModule extends IModule {
bend(offset: number, accelerationFactor: number, startAt: number): void;
getConfig(): ITimeConfig;
msec(): number;
now(msecOut?: boolean): number;
sec(): number;
translate(timestamp: number, msecOut?: boolean): number;
unbend(): void;
}
interface ITimeConfig {
offset: number;
accelerationFactor: number;
startAt: number;
}
type MageCallback = (error?: Error) => void;
}
declare var mage: mage.IMage;
export = mage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment