From f13e98568b94cae4adce3d7f159a6d111348f262 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Tue, 7 Jan 2020 10:00:32 +0800 Subject: [PATCH] v0.7.0 --- lerna.json | 2 +- packages/binding/package.json | 8 ++++---- packages/binding/src/index.ts | 4 ++-- packages/core/package.json | 30 +++++++++++++++--------------- packages/core/src/index.ts | 16 ++++++++++++---- packages/core/src/server.ts | 9 +++------ packages/db-mongo/package.json | 16 ++++++++-------- packages/db-mongo/src/client.ts | 9 +++++---- packages/db/package.json | 8 ++++---- packages/ioc/package.json | 8 ++++---- packages/ws/package.json | 14 +++++++------- 11 files changed, 65 insertions(+), 59 deletions(-) diff --git a/lerna.json b/lerna.json index 21861ca..5bb7a02 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,7 @@ { "npmClient": "yarn", "useWorkspaces": true, - "version": "0.6.9", + "version": "0.7.0", "packages": [ "packages/*" ], diff --git a/packages/binding/package.json b/packages/binding/package.json index f76e933..c17baf4 100644 --- a/packages/binding/package.json +++ b/packages/binding/package.json @@ -1,6 +1,6 @@ { "name": "@cc-server/binding", - "version": "0.6.9", + "version": "0.7.0", "description": "> TODO: description", "author": "MiaoWoo ", "homepage": "https://github.com/502647092/cc-server-parent#readme", @@ -24,9 +24,9 @@ "reflect-metadata": "^0.1.13" }, "devDependencies": { - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "typescript": "^3.5.1" + "mocha": "^7.0.0", + "rimraf": "^3.0.0", + "typescript": "^3.7.4" }, "bugs": { "url": "https://github.com/502647092/cc-server-parent/issues" diff --git a/packages/binding/src/index.ts b/packages/binding/src/index.ts index 4ce7070..6745dcf 100644 --- a/packages/binding/src/index.ts +++ b/packages/binding/src/index.ts @@ -1,5 +1,5 @@ -import { httpGet as get, httpPost as post } from 'inversify-express-utils' +import { httpGet as get, httpPost as post, httpPut as put, httpPatch as patch, httpDelete as del } from 'inversify-express-utils' export * from './decorators' export * from './activation' export * from 'inversify-express-utils' -export { get, post } +export { get, post, put, patch, del } diff --git a/packages/core/package.json b/packages/core/package.json index 03937d5..60903e9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@cc-server/core", - "version": "0.6.9", + "version": "0.7.0", "description": "> TODO: description", "author": "MiaoWoo ", "homepage": "https://github.com/502647092/cc-server-parent#readme", @@ -21,27 +21,27 @@ "url": "git+https://github.com/502647092/cc-server-parent.git" }, "dependencies": { - "@cc-server/binding": "^0.6.9", - "@cc-server/db-mongo": "^0.6.9", - "@cc-server/ioc": "^0.6.9", - "@cc-server/ws": "^0.6.9", + "@cc-server/binding": "^0.7.0", + "@cc-server/db-mongo": "^0.7.0", + "@cc-server/ioc": "^0.7.0", + "@cc-server/ws": "^0.7.0", "body-parser": "^1.19.0", - "globby": "^9.2.0", + "globby": "^10.0.2", "inversify": "^5.0.1", "inversify-express-utils": "^6.3.2", "prettyjson": "^1.2.1", - "socket.io": "^2.2.0" + "socket.io": "^2.3.0" }, "devDependencies": { - "@types/body-parser": "^1.17.0", - "@types/express": "^4.17.0", + "@types/body-parser": "^1.17.1", + "@types/express": "4.17.0", "@types/prettyjson": "^0.0.29", - "@types/socket.io": "^2.1.2", - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "ts-node": "^8.2.0", - "ts-node-dev": "^1.0.0-pre.40", - "typescript": "^3.5.1" + "@types/socket.io": "^2.1.4", + "mocha": "^7.0.0", + "rimraf": "^3.0.0", + "ts-node": "^8.5.4", + "ts-node-dev": "^1.0.0-pre.44", + "typescript": "^3.7.4" }, "gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728" } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index abd308a..e7c1707 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,6 +1,7 @@ import 'reflect-metadata'; import * as fs from 'fs'; import * as http from 'http'; +import * as path from 'path'; import * as globby from "globby"; import * as express from "express"; import * as prettyjson from "prettyjson"; @@ -104,11 +105,18 @@ export class CcServerBoot { return this; } - public scan(path: fs.PathLike) { - let files = fs.readdirSync(path); - for (const file of files) { - + public scan(scanDir: string) { + let files = fs.readdirSync(scanDir); + for (let file of files) { + let moduleDir = path.join(scanDir, file) + let stat = fs.statSync(moduleDir); + if (stat.isDirectory()) { + this.scan(moduleDir) + } else if (stat.isFile() && (file.endsWith('.js') || file.endsWith('.ts'))) { + require(moduleDir); + } } + return this; } public build() { diff --git a/packages/core/src/server.ts b/packages/core/src/server.ts index 886f02e..c969d17 100644 --- a/packages/core/src/server.ts +++ b/packages/core/src/server.ts @@ -1,17 +1,14 @@ -import { CcServerBoot, express } from './index' - -import './function/http'; -import './function/websocket'; +import { CcServerBoot } from './index' import { DBClient } from '@cc-server/db'; import { MongoClient } from 'mongodb'; import { MongoCollection } from '@cc-server/db-mongo'; -let boot = new CcServerBoot().static('public'); +let boot = new CcServerBoot().scan(__dirname + '/function'); MongoClient.connect("mongodb://192.168.2.5:27017", { useNewUrlParser: true }, (error, client) => { if (error) { console.log(error) } else { boot.container.bind(DBClient).toConstantValue(new MongoCollection(client.db("faas").collection("users"))).whenTargetNamed("users") - boot.build().listen(); + boot.start(); } }) diff --git a/packages/db-mongo/package.json b/packages/db-mongo/package.json index 179456c..fcb2eb6 100644 --- a/packages/db-mongo/package.json +++ b/packages/db-mongo/package.json @@ -1,6 +1,6 @@ { "name": "@cc-server/db-mongo", - "version": "0.6.9", + "version": "0.7.0", "description": "> TODO: description", "author": "MiaoWoo ", "homepage": "https://faas.yumc.pw", @@ -20,17 +20,17 @@ "url": "git+https://github.com/502647092/cc-server-parent.git" }, "dependencies": { - "@cc-server/db": "^0.6.9", - "@cc-server/ioc": "^0.6.9", + "@cc-server/db": "^0.7.0", + "@cc-server/ioc": "^0.7.0", "inversify": "^5.0.1", - "mongodb": "^3.2.7", + "mongodb": "^3.4.1", "reflect-metadata": "^0.1.13" }, "devDependencies": { - "@types/mongodb": "^3.1.28", - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "typescript": "^3.5.1" + "@types/mongodb": "^3.3.14", + "mocha": "^7.0.0", + "rimraf": "^3.0.0", + "typescript": "^3.7.4" }, "gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728" } diff --git a/packages/db-mongo/src/client.ts b/packages/db-mongo/src/client.ts index f665f31..4217d32 100644 --- a/packages/db-mongo/src/client.ts +++ b/packages/db-mongo/src/client.ts @@ -16,7 +16,7 @@ export class MongoCollection implements DBClient { return await this.collection.find(filter).toArray(); } - public async findOne(filter: Object): Promise { + public async findOne(filter: object): Promise { let result = await this.collection.find(filter).limit(1).toArray(); return result[0]; } @@ -26,20 +26,21 @@ export class MongoCollection implements DBClient { } public async insertOne(model: T): Promise { + //@ts-ignore var insert = await this.collection.insertOne(model); return insert.ops[0]; } - public async updateOne(where: any, model: any): Promise { + public async updateOne(where: any, model: T): Promise { let result = await this.collection.updateOne(where, { $set: model }); return result.result.ok == 1 && result.result.n > 0; } - public async updateById(objectId: string, model: any): Promise { + public async updateById(objectId: string, model: T): Promise { return await this.updateOne({ _id: new ObjectID(objectId) }, model) } - public async deleteOne(where: any): Promise { + public async deleteOne(where: object): Promise { let result = await this.collection.deleteOne(where); return result.result.ok === 1 && result.result.n > 0 } diff --git a/packages/db/package.json b/packages/db/package.json index 1c5fdb4..c4ec1fc 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@cc-server/db", - "version": "0.6.9", + "version": "0.7.0", "description": "> TODO: description", "author": "MiaoWoo ", "homepage": "https://github.com/502647092/cc-server-parent#readme", @@ -23,8 +23,8 @@ "url": "https://github.com/502647092/cc-server-parent/issues" }, "devDependencies": { - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "typescript": "^3.5.1" + "mocha": "^7.0.0", + "rimraf": "^3.0.0", + "typescript": "^3.7.4" } } diff --git a/packages/ioc/package.json b/packages/ioc/package.json index e7a0627..58ea823 100644 --- a/packages/ioc/package.json +++ b/packages/ioc/package.json @@ -1,6 +1,6 @@ { "name": "@cc-server/ioc", - "version": "0.6.9", + "version": "0.7.0", "description": "> TODO: description", "author": "MiaoWoo ", "homepage": "https://faas.yumc.pw", @@ -25,9 +25,9 @@ "reflect-metadata": "^0.1.13" }, "devDependencies": { - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "typescript": "^3.5.1" + "mocha": "^7.0.0", + "rimraf": "^3.0.0", + "typescript": "^3.7.4" }, "gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728" } diff --git a/packages/ws/package.json b/packages/ws/package.json index 645c5c4..2f50ca8 100644 --- a/packages/ws/package.json +++ b/packages/ws/package.json @@ -1,6 +1,6 @@ { "name": "@cc-server/ws", - "version": "0.6.9", + "version": "0.7.0", "description": "> TODO: description", "author": "MiaoWoo ", "homepage": "https://faas.yumc.pw", @@ -20,16 +20,16 @@ "url": "git+https://github.com/502647092/cc-server-parent.git" }, "dependencies": { - "@cc-server/ioc": "^0.6.9", + "@cc-server/ioc": "^0.7.0", "inversify": "^5.0.1", "reflect-metadata": "^0.1.13", - "socket.io": "^2.2.0" + "socket.io": "^2.3.0" }, "devDependencies": { - "@types/socket.io": "^2.1.2", - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "typescript": "^3.5.1" + "@types/socket.io": "^2.1.4", + "mocha": "^7.0.0", + "rimraf": "^3.0.0", + "typescript": "^3.7.4" }, "gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728" }