mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
Merge pull request #17208 from ssddi456/yog2-defininations
add yog2-kernel yog-log yog-bigpipe node-ral
This commit is contained in:
Vendored
+207
@@ -0,0 +1,207 @@
|
||||
// Type definitions for node-ral 0.18
|
||||
// Project: https://github.com/fex-team/node-ral
|
||||
// Definitions by: ssddi456 <https://github.com/ssddi456>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
export interface LogInfo {
|
||||
service: string;
|
||||
requestID: string;
|
||||
conv: string;
|
||||
prot: string;
|
||||
method: string;
|
||||
path: string;
|
||||
proxy: string;
|
||||
query: string;
|
||||
remote: string;
|
||||
cost: string;
|
||||
talk: string;
|
||||
write: string;
|
||||
read: string;
|
||||
pack: string;
|
||||
unpack: string;
|
||||
retry: string;
|
||||
}
|
||||
|
||||
export function RAL(serviceName: string, options?: {}): RAL.RalRunner;
|
||||
export namespace RAL {
|
||||
function appendExtPath(extPath: string): void;
|
||||
function setConfigNormalizer(normalizers: ConfigNormalizer): void;
|
||||
function getConf(name: string): Config;
|
||||
function getRawConf(name: string): Config;
|
||||
function init(options?: {}): void;
|
||||
function reload(options?: {}): void;
|
||||
|
||||
class RalRunner extends EventEmitter {
|
||||
constructor(serviceName: string, options?: {});
|
||||
doRequest(): void;
|
||||
getLogInfo(): LogInfo;
|
||||
throwError(err: any): void;
|
||||
callRetry(err: any): void;
|
||||
}
|
||||
|
||||
class NormalizerManager {
|
||||
constructor()
|
||||
normalizers: string[];
|
||||
setConfigNormalizer(normalizers: string[]): void;
|
||||
needUpdate(config: any): boolean;
|
||||
apply(config: {}): {};
|
||||
}
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
loadRawConf(config?: Service): Service;
|
||||
load(confPath: string): {};
|
||||
normalizerManager: RAL.NormalizerManager;
|
||||
normalize(config?: Service): {};
|
||||
getContext(serviceID: string, options?: Service): Service;
|
||||
getConf(name: string): Service;
|
||||
clearConf(): void;
|
||||
getConfNames(): string[];
|
||||
getRawConf(): any;
|
||||
getUpdateNeededRawConf(): any;
|
||||
enableUpdate(interval: number, all: boolean, cb: (err: any, confs: any) => any): void;
|
||||
disableUpdate(): void;
|
||||
isAutoUpdateEnabled(): boolean;
|
||||
}
|
||||
|
||||
export const Config: Config;
|
||||
|
||||
export abstract class RalModule {
|
||||
constructor();
|
||||
|
||||
abstract getCategory(): string;
|
||||
|
||||
abstract getName(): string;
|
||||
|
||||
static clearCache(): void;
|
||||
|
||||
static load(pathOrModule: string | RalModule): void;
|
||||
|
||||
static modules: {
|
||||
[key: string]: RalModule
|
||||
};
|
||||
}
|
||||
|
||||
export interface Server {
|
||||
idc?: string;
|
||||
host: string;
|
||||
port: string | number;
|
||||
}
|
||||
|
||||
export type buildInConverter = 'form' | 'formData' | 'json' | 'protobuf' | 'querystring' | 'raw' | 'redis' | 'stream' | 'string';
|
||||
export interface Service {
|
||||
method?: 'GET' | 'POST';
|
||||
server: Server[];
|
||||
hybird?: boolean;
|
||||
timeout?: number;
|
||||
retry?: number;
|
||||
unpack: buildInConverter;
|
||||
pack: buildInConverter;
|
||||
encoding?: 'utf-8' | 'GBK';
|
||||
balance: 'random' | 'roundrobin' | 'hashring';
|
||||
protocol: 'http' | 'https' | 'soap' | 'redis';
|
||||
headers?: {
|
||||
[key: string]: string | number
|
||||
};
|
||||
query?: any;
|
||||
data?: any;
|
||||
path?: string;
|
||||
}
|
||||
|
||||
export type BalanceContextConstructor = new (serviceID: string, service: Service) => Balance.BalanceContextClass;
|
||||
|
||||
export abstract class Balance {
|
||||
constructor();
|
||||
|
||||
abstract fetchServer(balanceContext: Balance.BalanceContextClass, conf: any, prevBackend: Server): Server;
|
||||
|
||||
getCategory(): any;
|
||||
|
||||
getContextClass(): BalanceContextConstructor;
|
||||
|
||||
static BalanceContext: BalanceContextConstructor;
|
||||
}
|
||||
|
||||
export namespace Balance {
|
||||
class BalanceContextClass {
|
||||
constructor(serviceID: string, service: Service)
|
||||
currentIDC: string;
|
||||
serviceID: string;
|
||||
reqIDCServers: string[];
|
||||
crossIDCServers: string[];
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class Converter extends RalModule {
|
||||
constructor();
|
||||
|
||||
getCategory(): string;
|
||||
|
||||
abstract pack(config: Service, data: any): Buffer;
|
||||
|
||||
abstract unpack(config: Service, data: any): any;
|
||||
|
||||
isStreamify: false;
|
||||
}
|
||||
|
||||
export abstract class Protocol extends RalModule {
|
||||
constructor();
|
||||
|
||||
beforeRequest(context: any): any;
|
||||
|
||||
getCategory(): string;
|
||||
|
||||
normalizeConfig(context: any): any;
|
||||
|
||||
talk(config: any, callback: any): any;
|
||||
|
||||
abstract _request(config: any, callback: (...param: any[]) => any): any;
|
||||
|
||||
static beforeRequest(context: any): any;
|
||||
|
||||
static normalizeConfig(context: any): any;
|
||||
}
|
||||
|
||||
export interface LoggerFactory {
|
||||
(prefix: string): RalLogger;
|
||||
options: {
|
||||
format_wf: string;
|
||||
log_path: string;
|
||||
app: string;
|
||||
logInstance: RalLogger;
|
||||
};
|
||||
}
|
||||
export interface RalLogger {
|
||||
notice(...param: any[]): void;
|
||||
warning(...param: any[]): void;
|
||||
fatal(...param: any[]): void;
|
||||
trace(...param: any[]): void;
|
||||
debug(...param: any[]): void;
|
||||
}
|
||||
|
||||
export const Logger: LoggerFactory;
|
||||
|
||||
export abstract class ConfigNormalizer extends RalModule {
|
||||
constructor();
|
||||
|
||||
getCategory(): string;
|
||||
|
||||
abstract normalizeConfig(config: any): Config;
|
||||
|
||||
abstract needUpdate(config?: any): boolean;
|
||||
}
|
||||
|
||||
export function Middleware(options?: Service): (req: Request, resp: Response, next: NextFunction) => void;
|
||||
|
||||
export function RALPromise<T>(name: string, options?: {}): Promise<T>;
|
||||
export namespace RALPromise {
|
||||
import appendExtPath = RAL.appendExtPath;
|
||||
import setConfigNormalizer = RAL.setConfigNormalizer;
|
||||
import getConf = RAL.getConf;
|
||||
import getRawConf = RAL.getRawConf;
|
||||
import init = RAL.init;
|
||||
import reload = RAL.reload;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import * as nodeRal from "node-ral";
|
||||
|
||||
class FormConverter extends nodeRal.Converter {
|
||||
pack(config: nodeRal.Service, data: {}) {
|
||||
return new Buffer('123');
|
||||
}
|
||||
unpack(config: nodeRal.Service, data: {}) {
|
||||
return {};
|
||||
}
|
||||
getName() {
|
||||
return 'form';
|
||||
}
|
||||
}
|
||||
|
||||
class HashringBalance extends nodeRal.Balance {
|
||||
getName() {
|
||||
return 'hashring';
|
||||
}
|
||||
fetchServer(balanceContext: nodeRal.Balance.BalanceContextClass, conf: {}, prevBackend: nodeRal.Server) {
|
||||
return <nodeRal.Server> {};
|
||||
}
|
||||
}
|
||||
|
||||
class HttpProtocol extends nodeRal.Protocol {
|
||||
getName() {
|
||||
return 'http';
|
||||
}
|
||||
_request(config: any, callback: (err: any, data: any) => any) {
|
||||
callback(new Error(), '123');
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultConfigNormalizer extends nodeRal.ConfigNormalizer {
|
||||
getName() {
|
||||
return 'default';
|
||||
}
|
||||
needUpdate() {
|
||||
return false;
|
||||
}
|
||||
normalizeConfig(config: any) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
const runner = nodeRal.RAL('test', {});
|
||||
runner.on('data', function() {
|
||||
// yeap
|
||||
});
|
||||
runner.doRequest();
|
||||
|
||||
nodeRal.RAL.init();
|
||||
|
||||
nodeRal.RALPromise('test', {}).then;
|
||||
|
||||
nodeRal.Config.loadRawConf;
|
||||
nodeRal.Config.load;
|
||||
nodeRal.Config.normalizerManager;
|
||||
nodeRal.Config.normalize;
|
||||
nodeRal.Config.getContext;
|
||||
nodeRal.Config.getConf;
|
||||
nodeRal.Config.clearConf;
|
||||
nodeRal.Config.getConfNames;
|
||||
nodeRal.Config.getRawConf;
|
||||
nodeRal.Config.getUpdateNeededRawConf;
|
||||
nodeRal.Config.enableUpdate;
|
||||
nodeRal.Config.disableUpdate;
|
||||
nodeRal.Config.isAutoUpdateEnabled;
|
||||
|
||||
const logger = nodeRal.Logger('some');
|
||||
logger.debug('test');
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"node-ral-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"only-arrow-functions": [
|
||||
false
|
||||
]
|
||||
}
|
||||
}
|
||||
Vendored
+141
@@ -0,0 +1,141 @@
|
||||
// Type definitions for yog-bigpipe 0.4
|
||||
// Project: https://github.com/fex-team/yog-bigpipe
|
||||
// Definitions by: ssddi456 <https://github.com/ssddi456>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { Readable } from 'stream';
|
||||
import { RequestHandler } from 'express';
|
||||
|
||||
interface BigPipeOption {
|
||||
skipAnalysis?: boolean;
|
||||
tpl?: {
|
||||
_default?: string,
|
||||
quickling?: string
|
||||
};
|
||||
}
|
||||
|
||||
type Callback = (done: (err: any, data: any) => any) => any;
|
||||
|
||||
interface AddPageletConfig {
|
||||
id: string;
|
||||
lazy?: boolean;
|
||||
mode?: yogBigpipe.Pagelet.mode;
|
||||
}
|
||||
|
||||
declare function yogBigpipe(option?: BigPipeOption): RequestHandler;
|
||||
|
||||
export = yogBigpipe;
|
||||
declare namespace yogBigpipe {
|
||||
class BigPipe extends Readable {
|
||||
constructor(option?: BigPipeOption)
|
||||
map: { [key: string]: Pagelet };
|
||||
pagelets: Pagelet[];
|
||||
pipelines: Pagelet[];
|
||||
rendered: Pagelet[];
|
||||
sources: {};
|
||||
state: Pagelet.status;
|
||||
quicklings: {};
|
||||
parentQuicklings: string[];
|
||||
Pagelet: PageletConstructor<Pagelet>;
|
||||
pageletData: {};
|
||||
|
||||
bind(id: string, fn: Callback): BigPipe;
|
||||
|
||||
bindPageOnly(fn: Callback): void;
|
||||
|
||||
addQuicklingPagelets(pagelets: string[]): void;
|
||||
|
||||
isQuicklingMode(): boolean;
|
||||
|
||||
isQuickingMode(): boolean;
|
||||
|
||||
addPagelet(obj: AddPageletConfig): void;
|
||||
|
||||
isQuicklingWidget(item: { 'mode': Pagelet.mode, [key: string]: any }): void;
|
||||
|
||||
render(): void;
|
||||
|
||||
preparePageOnly(): Promise<any>;
|
||||
|
||||
prepareAllSources(): Promise<any>;
|
||||
|
||||
renderPagelet(pagelet: Pagelet): void;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
_onPageletDone(pagelet: Pagelet): void;
|
||||
|
||||
_checkFinish(): void;
|
||||
|
||||
outputPagelet(pagelet: Pagelet): void;
|
||||
|
||||
format(pagelet: Pagelet): string;
|
||||
|
||||
_markPageletRendered(pagelet: Pagelet): void;
|
||||
}
|
||||
|
||||
type PageletConstructor<T> = new (obj: PageletOption) => T;
|
||||
|
||||
interface PageletOption {
|
||||
id: string;
|
||||
mode?: Pagelet.mode;
|
||||
lazy?: boolean;
|
||||
reqID: string;
|
||||
skipAnalysis: boolean;
|
||||
|
||||
locals?: {};
|
||||
compiled?: boolean;
|
||||
container?: string;
|
||||
for?: string;
|
||||
model: {};
|
||||
}
|
||||
interface PageletData {
|
||||
container: string;
|
||||
reqID: string;
|
||||
id: string;
|
||||
html: string;
|
||||
js: string[];
|
||||
css: string[];
|
||||
styles: string[];
|
||||
scripts: string[];
|
||||
}
|
||||
class Pagelet extends EventEmitter {
|
||||
constructor(obj: PageletOption)
|
||||
|
||||
model: {};
|
||||
container: string;
|
||||
mode: Pagelet.mode;
|
||||
id: string;
|
||||
locals: {};
|
||||
compiled: boolean;
|
||||
reqID: string;
|
||||
skipAnalysis: boolean;
|
||||
state: Pagelet.status;
|
||||
scripts: string[];
|
||||
styles: string[];
|
||||
js: string[];
|
||||
css: string[];
|
||||
html: string;
|
||||
|
||||
addCss(css: string | string[]): void;
|
||||
addCsses(css: string | string[]): void;
|
||||
addJs(css: string | string[]): void;
|
||||
addJses(css: string | string[]): void;
|
||||
|
||||
addScript(css: string | string[]): void;
|
||||
addScripts(css: string | string[]): void;
|
||||
addStyle(css: string | string[]): void;
|
||||
addStyles(css: string | string[]): void;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
start(provider: Promise<any>, sync: boolean): void;
|
||||
toJson(): PageletData;
|
||||
}
|
||||
|
||||
namespace Pagelet {
|
||||
type status = 'pending' | 'rendering' | 'fulfilled' | 'failed';
|
||||
type mode = 'async' | 'pipeline' | 'quickling';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"yog-bigpipe-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,14 @@
|
||||
import yogBigpipe = require("yog-bigpipe");
|
||||
|
||||
yogBigpipe();
|
||||
yogBigpipe({});
|
||||
yogBigpipe({
|
||||
skipAnalysis: true
|
||||
});
|
||||
|
||||
yogBigpipe({
|
||||
tpl: {
|
||||
_default: '',
|
||||
quickling: '[test]'
|
||||
}
|
||||
});
|
||||
Vendored
+115
@@ -0,0 +1,115 @@
|
||||
// Type definitions for yog-log 0.1
|
||||
// Project: https://github.com/fex-team/yog-log
|
||||
// Definitions by: ssddi456 <https://github.com/ssddi456>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
interface LEVELS {
|
||||
// 访问日志
|
||||
0: 'ACCESS';
|
||||
3: 'ACCESS_ERROR';
|
||||
// 应用日志等级 ODP格式
|
||||
1: 'FATAL';
|
||||
2: 'WARNING';
|
||||
4: 'NOTICE';
|
||||
8: 'TRACE';
|
||||
16: 'DEBUG';
|
||||
}
|
||||
|
||||
type LevelInt = keyof LEVELS | 0 | 3 | 1 | 2 | 4 | 8 | 16;
|
||||
type LevelName = LEVELS[LevelInt];
|
||||
|
||||
type LogReturn = undefined | false;
|
||||
|
||||
interface LogConfig {
|
||||
LogIdName?: string;
|
||||
// 模板文件地址,可以不填
|
||||
data_path?: string;
|
||||
// 用户只需要填写log_path配置
|
||||
log_path?: string;
|
||||
|
||||
debug?: 0 | 1;
|
||||
intLevel?: 16;
|
||||
auto_rotate?: 0 | 1;
|
||||
use_sub_dir?: 0 | 1;
|
||||
IS_ODP?: boolean;
|
||||
IS_OMP?: 0 | 1;
|
||||
|
||||
access_log_path?: string;
|
||||
access_error_log_path?: string;
|
||||
|
||||
access?: string;
|
||||
format_wf?: string;
|
||||
}
|
||||
|
||||
interface WriteLogConfig {
|
||||
filename_suffix: string;
|
||||
errno: number;
|
||||
escape_msg: boolean;
|
||||
}
|
||||
|
||||
interface LogInfo {
|
||||
msg: string;
|
||||
custom: {};
|
||||
}
|
||||
|
||||
type LogInput = string | LogInfo | Error;
|
||||
|
||||
declare function yog_log(config?: LogConfig): ((req: Request, resp: Response, next: NextFunction) => any);
|
||||
|
||||
declare namespace yog_log {
|
||||
class Logger {
|
||||
constructor(opts: LogConfig, req: Request);
|
||||
|
||||
extend(destination: {}, source: {}): {};
|
||||
|
||||
log(level: string, obj: string | {}): void | false;
|
||||
|
||||
notice(info: LogInput): void | false;
|
||||
|
||||
debug(info: LogInput): void | false;
|
||||
|
||||
fatal(info: LogInput): void | false;
|
||||
|
||||
trace(info: LogInput): void | false;
|
||||
|
||||
warning(info: LogInput): void | false;
|
||||
|
||||
getCookie(name: string): string | false;
|
||||
|
||||
getLogFile(intLevel: LevelInt): string;
|
||||
|
||||
getLogFormat(level: LevelName): string | false;
|
||||
|
||||
getLogID(req: Request, logIDName: string): string;
|
||||
|
||||
getLogLevelInt(level: LevelName): LevelInt | -1;
|
||||
|
||||
getLogPrefix(): string;
|
||||
|
||||
getLogString(format: string): string;
|
||||
|
||||
getParams(name: string): string;
|
||||
|
||||
md5(data: string | Buffer, len: number): string;
|
||||
|
||||
parseCustomLog(obj: {}): void;
|
||||
|
||||
// 解析日志配置,生成相应的模板函数的字符串内容
|
||||
parseFormat(format: string): string;
|
||||
|
||||
parseReqParams(req: Request, res: Response): void | false;
|
||||
|
||||
parseStackInfo(info: LogInfo | Error): void;
|
||||
|
||||
setParams(name: string, value: any): void;
|
||||
|
||||
writeLog(intLevel: LevelInt, options: WriteLogConfig, log_format: string): void | false;
|
||||
}
|
||||
|
||||
function getLogger(config?: LogConfig): Logger;
|
||||
}
|
||||
|
||||
export = yog_log;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"yog-log-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,39 @@
|
||||
import yogLog = require('yog-log');
|
||||
import express = require('express');
|
||||
|
||||
const log = yogLog.getLogger({});
|
||||
|
||||
log.log('debug', 'test');
|
||||
|
||||
log.notice('test');
|
||||
log.debug('test');
|
||||
log.fatal('test');
|
||||
log.fatal('test');
|
||||
log.trace('test');
|
||||
log.warning('test');
|
||||
|
||||
const cookie_value = log.getCookie('test');
|
||||
const getLogFile = log.getLogFile(0);
|
||||
const log_format = log.getLogFormat('ACCESS');
|
||||
|
||||
const logid = log.getLogID( <express.Request> {}, 'test');
|
||||
const intlevel = log.getLogLevelInt('ACCESS');
|
||||
const prfix = log.getLogPrefix();
|
||||
const log_str = log.getLogString('test');
|
||||
const param = log.getParams('test');
|
||||
const md5_tag = log.md5('test', 123);
|
||||
|
||||
log.parseCustomLog({ test : 1});
|
||||
|
||||
const formater = log.parseFormat('test');
|
||||
|
||||
log.parseStackInfo(new Error());
|
||||
|
||||
log.setParams('test', 'some');
|
||||
|
||||
log.writeLog(0, { escape_msg : false, filename_suffix : '123', errno : 0 }, 'test');
|
||||
|
||||
const middleware = yogLog({});
|
||||
|
||||
const app = express();
|
||||
app.get('/', middleware);
|
||||
Vendored
+92
@@ -0,0 +1,92 @@
|
||||
// Type definitions for yog2-kernel 1.9
|
||||
// Project: https://github.com/fex-team/yog2-kernel
|
||||
// Definitions by: ssddi456 <https://github.com/ssddi456>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as express from "express";
|
||||
import * as _ from "lodash";
|
||||
import * as ral from "node-ral";
|
||||
import * as log from "yog-log";
|
||||
import * as yogBigpipe from "yog-bigpipe";
|
||||
|
||||
declare global {
|
||||
const yog: yog.Yog;
|
||||
}
|
||||
|
||||
export interface YogBootstrapOption {
|
||||
// 设置yog根目录,默认使用启动文件的目录
|
||||
rootPath?: string;
|
||||
// 设置plugins目录
|
||||
pluginsPath?: string;
|
||||
// 设置conf目录
|
||||
confPath?: string;
|
||||
// 设置app,未设置则直接使用express
|
||||
app?: express.Express;
|
||||
}
|
||||
export interface Request extends express.Request {
|
||||
CURRENT_APP: string;
|
||||
ral: typeof ral.RAL;
|
||||
ralP: typeof ral.RALPromise;
|
||||
}
|
||||
export interface Response extends express.Response {
|
||||
bigpipe: yogBigpipe.BigPipe;
|
||||
}
|
||||
|
||||
export interface ActionObject {
|
||||
get?: express.RequestHandler;
|
||||
post?: express.RequestHandler;
|
||||
put?: express.RequestHandler;
|
||||
delete?: express.RequestHandler;
|
||||
del?: express.RequestHandler;
|
||||
copy?: express.RequestHandler;
|
||||
head?: express.RequestHandler;
|
||||
options?: express.RequestHandler;
|
||||
purge?: express.RequestHandler;
|
||||
lock?: express.RequestHandler;
|
||||
unlock?: express.RequestHandler;
|
||||
propfind?: express.RequestHandler;
|
||||
view?: express.RequestHandler;
|
||||
link?: express.RequestHandler;
|
||||
unlick?: express.RequestHandler;
|
||||
patch?: express.RequestHandler;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface Router extends express.Router {
|
||||
action(actionName: string): express.RequestHandler | ActionObject;
|
||||
wrapAsync(fn: () => any): express.RequestHandler;
|
||||
}
|
||||
|
||||
export namespace yog {
|
||||
class Yog {
|
||||
express: typeof express;
|
||||
app: express.Express;
|
||||
_: typeof _;
|
||||
|
||||
log: log.Logger;
|
||||
|
||||
// 当 yog.conf.promise.overrideRAL 为true时,可以当作promise使用
|
||||
ral: typeof ral.RAL | typeof ral.RALPromise;
|
||||
RAL: typeof ral.RAL;
|
||||
|
||||
ralP: typeof ral.RALPromise;
|
||||
|
||||
view: {
|
||||
// 清除viewcache
|
||||
cleanCache(): void;
|
||||
};
|
||||
|
||||
// debug模式时存在
|
||||
reloadApp?(appName: string): void;
|
||||
// debug模式时存在
|
||||
reloadView?(): void;
|
||||
// debug模式时存在
|
||||
reloadIsomorphic?(): void;
|
||||
|
||||
ROOT_PATH: string;
|
||||
|
||||
bootstrap(option: YogBootstrapOption, callback?: () => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
export default yog;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2015",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"yog2-kernel-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"only-arrow-functions": [
|
||||
false
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import * as yog2Kernel from 'yog2-kernel';
|
||||
import { NextFunction } from 'express';
|
||||
|
||||
yog.log.notice('some debug');
|
||||
yog.log.debug('some debug');
|
||||
yog.log.trace('some debug');
|
||||
yog.log.warning('some debug');
|
||||
yog.log.fatal('some debug');
|
||||
|
||||
const handler = async function(req: yog2Kernel.Request, resp: yog2Kernel.Response, next: NextFunction) {
|
||||
const test = await req.ralP("test", {});
|
||||
|
||||
resp.bigpipe.bind("test", function(done) {
|
||||
done(null, 'yeap');
|
||||
});
|
||||
|
||||
resp.render("test", {});
|
||||
};
|
||||
|
||||
const router = <yog2Kernel.Router> {};
|
||||
(<yog2Kernel.ActionObject> router.action("test")).get;
|
||||
|
||||
const handler2 = router.wrapAsync(function() { });
|
||||
|
||||
yog.bootstrap({});
|
||||
|
||||
yog.bootstrap({
|
||||
rootPath: ''
|
||||
});
|
||||
Reference in New Issue
Block a user