feat: format and rebuild
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
aeedbc4222
commit
f541290f47
@ -1,7 +1,7 @@
|
||||
import { VaildError } from './interfaces'
|
||||
import { METADATA_KEY } from './constants'
|
||||
import { Container, interfaces as inversify_interfaces } from 'inversify'
|
||||
import { TYPE, interfaces as express_interfaces } from 'inversify-express-utils'
|
||||
import { METADATA_KEY } from './constants'
|
||||
import { VaildError } from './interfaces'
|
||||
import { getVaildMethodMetadata, getVaildControllerMetadata, getVaildModelMetadata } from './utils'
|
||||
|
||||
let handler = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'reflect-metadata'
|
||||
import { METADATA_KEY, VAILD_TYPE } from './constants';
|
||||
import { getVaildControllerMetadata, getVaildModelMetadata } from './utils'
|
||||
import { VaildFunction, interfaces } from './interfaces'
|
||||
import { getVaildControllerMetadata, getVaildModelMetadata } from './utils'
|
||||
/**
|
||||
* ParameterVaild
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { METADATA_KEY } from './constants'
|
||||
import { interfaces } from './interfaces'
|
||||
import { METADATA_KEY } from './constants'
|
||||
|
||||
function getVaildControllerMetadata(model: Object) {
|
||||
let controllerMetadata: interfaces.MethodMetadata = Reflect.getMetadata(
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { lazyInjectNamed } from '@cc-server/ioc'
|
||||
import { controller, httpPost, requestBody } from '@cc-server/binding';
|
||||
import { namespace, listener, interfaces, io, TYPE } from '@cc-server/ws'
|
||||
import { lazyInjectNamed } from '@cc-server/ioc'
|
||||
|
||||
@namespace('/', (socket: io.Socket, next: (err?: any) => void) => {
|
||||
console.log(socket.nsp.name, socket.id, 'before connection');
|
||||
|
@ -4,24 +4,15 @@ const connStr = process.env.FAAS_MONGO_URL || 'mongodb://192.168.0.2:27017';
|
||||
const dbName = process.env.FAAS_MONGO_DB || "faas";
|
||||
|
||||
export class MongoDBConnection {
|
||||
private static isConnected: boolean = false;
|
||||
private static db: Db;
|
||||
|
||||
public static getConnection(result: (connection: Db) => void) {
|
||||
if (this.isConnected) {
|
||||
return result(this.db);
|
||||
} else {
|
||||
this.connect((error: Error, db: Db) => {
|
||||
return result(this.db);
|
||||
});
|
||||
}
|
||||
public static async getConnection(): Promise<Db> {
|
||||
if (!this.db) { this.db = await this.connect() }
|
||||
return this.db;
|
||||
}
|
||||
|
||||
private static connect(result: (error: Error, db: Db) => void) {
|
||||
MongoClient.connect(connStr, { useNewUrlParser: true }, (err, client) => {
|
||||
this.db = client.db(dbName);
|
||||
this.isConnected = true;
|
||||
return result(err, this.db);
|
||||
});
|
||||
private static async connect(): Promise<Db> {
|
||||
let client = await MongoClient.connect(connStr, { useNewUrlParser: true });
|
||||
return client.db(dbName);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Db, ObjectID, Collection } from 'mongodb';
|
||||
import { MongoDBConnection } from './connection';
|
||||
import { provide } from '@cc-server/ioc'
|
||||
import { DBClient } from '@cc-server/db'
|
||||
import { MongoDBConnection } from './connection'
|
||||
import { Db, ObjectID, Collection } from 'mongodb'
|
||||
import { provide, postConstruct } from '@cc-server/ioc'
|
||||
|
||||
@provide(DBClient)
|
||||
export class MongoDBClient<T = any> implements DBClient {
|
||||
@ -9,13 +9,12 @@ export class MongoDBClient<T = any> implements DBClient {
|
||||
private db: Db;
|
||||
private collection: Collection<T>;
|
||||
|
||||
constructor() {
|
||||
MongoDBConnection.getConnection((connection) => {
|
||||
this.db = connection;
|
||||
if (this.table) {
|
||||
this.collection = this.db.collection(this.table);
|
||||
}
|
||||
});
|
||||
@postConstruct()
|
||||
private async init() {
|
||||
this.db = await MongoDBConnection.getConnection();
|
||||
if (this.table) {
|
||||
this.collection = this.db.collection(this.table);
|
||||
}
|
||||
}
|
||||
|
||||
public getProvide<P>(): P {
|
||||
|
@ -1,2 +1,2 @@
|
||||
export * from 'mongodb'
|
||||
export * from './client'
|
||||
export * from 'mongodb';
|
@ -19,6 +19,7 @@
|
||||
"url": "git+https://github.com/502647092/cc-server-parent.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cc-server/ioc": "^0.5.0",
|
||||
"inversify": "^5.0.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"socket.io": "^2.2.0"
|
||||
|
@ -1,9 +1,9 @@
|
||||
import "reflect-metadata";
|
||||
import { Container } from 'inversify'
|
||||
import { interfaces, BroadcastMessage } from './interfaces'
|
||||
import { TYPE } from './constants'
|
||||
import { getNamespaces, getNamespaceMetadata, getNamespaceListenerMetadata } from './utils'
|
||||
import * as io from 'socket.io'
|
||||
import { Container } from 'inversify'
|
||||
import { TYPE } from './constants'
|
||||
import { interfaces, BroadcastMessage } from './interfaces'
|
||||
import { getNamespaces, getNamespaceMetadata, getNamespaceListenerMetadata } from './utils'
|
||||
|
||||
export function buildWebSocket(container: Container, server: io.Server) {
|
||||
let constructors = getNamespaces();
|
||||
@ -53,10 +53,6 @@ function flatten(arr: Array<any>) {
|
||||
}
|
||||
|
||||
function applyMiddlewares(namespaceEventMetadata: interfaces.ListenerMetadata[], socket: io.Socket) {
|
||||
// socket.use((packet: io.Packet, next: (err?: any) => void) => {
|
||||
// Reflect.defineMetadata(TYPE.SocketContext, socket, packet);
|
||||
// next();
|
||||
// })
|
||||
let middlewares = [...new Set(flatten(namespaceEventMetadata.map((data) => data.middleware)))];
|
||||
for (const middleware of middlewares) {
|
||||
socket.use((packet: io.Packet, next: (err?: any) => void) => { middleware(socket, packet, next); });
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { inject, injectable, decorate } from "inversify";
|
||||
import { interfaces } from './interfaces'
|
||||
import { METADATA_KEY, TYPE } from './constants'
|
||||
import { METADATA_KEY } from './constants'
|
||||
import { injectable, decorate } from "inversify";
|
||||
import { getNamespaceListenerMetadata, getNamespacesMetadata } from './utils'
|
||||
import { provideNamed, fluentProvide } from "@cc-server/ioc/src";
|
||||
|
||||
/**
|
||||
* Socket.io Namespace
|
||||
@ -17,10 +16,6 @@ export function namespace(name?: string, ...middleware: interfaces.Middleware[])
|
||||
target: target
|
||||
};
|
||||
decorate(injectable(), target);
|
||||
//decorate(fluentProvide(TYPE.Namespace)
|
||||
// .inSingletonScope()
|
||||
// .whenTargetNamed(target.constructor.name)
|
||||
// .done(), target);
|
||||
Reflect.defineMetadata(METADATA_KEY.namespace, currentMetadata, target);
|
||||
const previousMetadata: interfaces.NamespaceMetadata[] = getNamespacesMetadata();
|
||||
Reflect.defineMetadata(METADATA_KEY.namespace, [currentMetadata, ...previousMetadata], Reflect);
|
||||
|
@ -1,9 +1,8 @@
|
||||
import * as io from 'socket.io'
|
||||
|
||||
export { io }
|
||||
export * from './debug'
|
||||
export * from './builder'
|
||||
export * from './decorators'
|
||||
export * from './interfaces'
|
||||
export * from './debug'
|
||||
export { TYPE } from './constants'
|
||||
export { getSocketContext } from './utils'
|
||||
export { io }
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { METADATA_KEY, TYPE } from './constants'
|
||||
import { interfaces } from './interfaces'
|
||||
import { METADATA_KEY } from './constants'
|
||||
|
||||
function getNamespaces() {
|
||||
return getNamespacesMetadata().map((target) => target.target);
|
||||
@ -29,14 +29,9 @@ function getNamespaceListenerMetadata(target: any) {
|
||||
return eventMetadata;
|
||||
}
|
||||
|
||||
function getSocketContext(packet: any) {
|
||||
return Reflect.getMetadata(TYPE.SocketContext, packet);
|
||||
}
|
||||
|
||||
export {
|
||||
getNamespaces,
|
||||
getNamespaceMetadata,
|
||||
getNamespacesMetadata,
|
||||
getNamespaceListenerMetadata,
|
||||
getSocketContext
|
||||
getNamespaceListenerMetadata
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user