mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
修复 @param 在类扩展时作用域污染的问题,完善interface
This commit is contained in:
1 parent
cd6938dd6c
commit
dd7914e1fb
31 files changed
+269
-179
No files matched your search
@@ -43,5 +43,3 @@ export function publish(event, payload, isMaster = true) {
|
||||
global.Hydro.service.bus = {
|
||||
subscribe, unsubscribe, publish,
|
||||
};
|
||||
|
||||
export default global.Hydro.service.bus;
|
||||
+1
-3
@@ -19,6 +19,4 @@ export function collection(c: string) {
|
||||
return db.collection(c);
|
||||
}
|
||||
|
||||
global.Hydro.service.db = { collection };
|
||||
|
||||
export default { collection };
|
||||
global.Hydro.service.db = { collection, db };
|
||||
@@ -1,8 +1,8 @@
|
||||
import { GridFSBucket } from 'mongodb';
|
||||
import { db } from './db';
|
||||
|
||||
const exp = new GridFSBucket(db);
|
||||
export const fs = new GridFSBucket(db);
|
||||
|
||||
global.Hydro.service.gridfs = exp;
|
||||
global.Hydro.service.gridfs = fs;
|
||||
|
||||
export default exp;
|
||||
export default fs;
|
||||
@@ -3,7 +3,7 @@ import * as sysinfo from '../lib/sysinfo';
|
||||
|
||||
const coll = db.collection('status');
|
||||
|
||||
async function update() {
|
||||
export async function update() {
|
||||
const [mid, $set] = await sysinfo.update();
|
||||
await coll.updateOne(
|
||||
{ mid, type: 'server' },
|
||||
@@ -13,7 +13,7 @@ async function update() {
|
||||
global.Hydro.stat.reqCount = 0;
|
||||
}
|
||||
|
||||
async function postInit() {
|
||||
export async function postInit() {
|
||||
const info = await sysinfo.get();
|
||||
await coll.updateOne(
|
||||
{ mid: info.mid, type: 'server' },
|
||||
@@ -23,6 +23,4 @@ async function postInit() {
|
||||
setInterval(update, 60 * 1000);
|
||||
}
|
||||
|
||||
global.Hydro.service.monitor = { postInit };
|
||||
|
||||
export default { postInit };
|
||||
global.Hydro.service.monitor = { update, postInit };
|
||||
@@ -138,12 +138,13 @@ export function param(...args: any): MethodDecorator {
|
||||
}
|
||||
return function desc(target: any, funcName: string, obj: any) {
|
||||
if (!target.__param) target.__param = {};
|
||||
if (!target.__param[funcName]) {
|
||||
target.__param[funcName] = [{ name: 'domainId', type: 'string' }];
|
||||
if (!target.__param[target.constructor.name]) target.__param[target.constructor.name] = {};
|
||||
if (!target.__param[target.constructor.name][funcName]) {
|
||||
target.__param[target.constructor.name][funcName] = [{ name: 'domainId', type: 'string' }];
|
||||
const originalMethod = obj.value;
|
||||
obj.value = function func(rawArgs: any) {
|
||||
const c = [];
|
||||
const arglist: ParamOption[] = this.__param[funcName];
|
||||
const arglist: ParamOption[] = this.__param[target.constructor.name][funcName];
|
||||
for (const item of arglist) {
|
||||
if (!item.isOptional || rawArgs[item.name]) {
|
||||
if (!rawArgs[item.name]) throw new ValidationError(item.name);
|
||||
@@ -160,7 +161,7 @@ export function param(...args: any): MethodDecorator {
|
||||
return originalMethod.call(this, ...c);
|
||||
};
|
||||
}
|
||||
target.__param[funcName].splice(1, 0, ...d);
|
||||
target.__param[target.constructor.name][funcName].splice(1, 0, ...d);
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user