@vmm/service
Advanced tools
Comparing version 1.0.32 to 1.0.36
{ | ||
"name": "@vmm/service", | ||
"version": "1.0.32", | ||
"version": "1.0.36", | ||
"main": "src/index.js", | ||
@@ -5,0 +5,0 @@ "description": "VMM Service library", |
@@ -7,3 +7,2 @@ "use strict"; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const debug_1 = __importDefault(require("debug")); | ||
const json5_1 = __importDefault(require("json5")); | ||
@@ -13,5 +12,5 @@ const mkdirp_1 = __importDefault(require("mkdirp")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const package_json_1 = __importDefault(require("../package.json")); | ||
const events_1 = __importDefault(require("events")); | ||
const _d = debug_1.default(package_json_1.default.name + ':' + path_1.default.basename(__filename, '.js')); | ||
const logger_1 = require("./logger"); | ||
const log = logger_1.logger(`${require('@/../package.json').name}:${require('path').parse(__filename).base}`); | ||
function loadConfigFile(fileName, configDefine) { | ||
@@ -28,3 +27,3 @@ let configObject = {}; | ||
catch (e) { | ||
_d('create config dir fail:', dirName, e.message); | ||
log.error('create config dir fail:', dirName, e.message); | ||
process.exit(0); | ||
@@ -35,6 +34,6 @@ } | ||
if (err) { | ||
_d('write config File Error:', fn, err.message); | ||
log.error('write config File Error:', fn, err.message); | ||
} | ||
else { | ||
_d('writeconfig File successed:', fn); | ||
log.debug('writeconfig File successed:', fn); | ||
} | ||
@@ -61,3 +60,3 @@ }); | ||
try { | ||
_d('load config file :', fileName); | ||
log.debug('load config file :', fileName); | ||
const json = json5_1.default.parse(fs_extra_1.default.readFileSync(fileName, 'utf8')); | ||
@@ -70,7 +69,7 @@ if (json) { | ||
catch (e) { | ||
_d('config file open fail:', fileName, e.message); | ||
log.warn('config file open fail:', fileName, e.message); | ||
lodash_1.default.defaultsDeep(configObject, configDefine); | ||
const defaultFile = fileName + '.default'; | ||
if (!fs_extra_1.default.existsSync(defaultFile)) { | ||
_d('please see: default config file :', defaultFile); | ||
log.info('please see: default config file :', defaultFile); | ||
_saveConfig(defaultFile); | ||
@@ -89,3 +88,3 @@ } | ||
setTimeout(() => { | ||
_d('reload config file:', fileName); | ||
log.info('reload config file:', fileName); | ||
conf._load(); | ||
@@ -92,0 +91,0 @@ }, 1000); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const logger_1 = require("./logger"); | ||
const package_json_1 = require("@/../package.json"); | ||
const log = logger_1.logger(`${package_json_1.name}:${__filename}`); | ||
log.debug('vmm lib service start ...'); | ||
const log = logger_1.logger(`${require('@/../package.json').name}:${require('path').parse(__filename).base}`); | ||
log.error('vmm lib service start ...'); | ||
var Service_1 = require("./Service"); | ||
@@ -8,0 +7,0 @@ exports.Service = Service_1.Service; |
@@ -8,3 +8,12 @@ "use strict"; | ||
const process_1 = __importDefault(require("process")); | ||
const safe_1 = __importDefault(require("colors/safe")); | ||
const date_format_1 = __importDefault(require("date-format")); | ||
const originalFactory = loglevel_1.default.methodFactory; | ||
const cfg = { | ||
trace: 'grey', | ||
debug: 'white', | ||
info: 'cyan', | ||
warn: 'yellow', | ||
error: 'red', | ||
}; | ||
function logger(name) { | ||
@@ -14,3 +23,5 @@ const _log = loglevel_1.default.getLogger(name); | ||
const rawMethod = originalFactory(methodName, logLevel, loggerName); | ||
return rawMethod.bind(_log, loggerName); | ||
const co = safe_1.default[cfg[methodName]]; | ||
const m = methodName.substr(0, 1).toUpperCase(); | ||
return rawMethod.bind(_log, date_format_1.default('yyyy:MM:dd hh:mm:ss', new Date()), co(m + ':' + loggerName)); | ||
}; | ||
@@ -17,0 +28,0 @@ if (process_1.default.env['DEBUG']) { |
@@ -7,7 +7,5 @@ "use strict"; | ||
const mongodb_1 = require("mongodb"); | ||
const debug_1 = __importDefault(require("debug")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const path_1 = __importDefault(require("path")); | ||
const package_json_1 = __importDefault(require("../package.json")); | ||
const _d = debug_1.default(package_json_1.default.name + ':' + path_1.default.basename(__filename, '.js')); | ||
const logger_1 = require("./logger"); | ||
const log = logger_1.logger(`${require('@/../package.json').name}:${require('path').parse(__filename).base}`); | ||
class Mongo { | ||
@@ -18,3 +16,3 @@ constructor(url, options, modName, dbCollectionsDefine) { | ||
this._collections = {}; | ||
_d('using db defines:', Object.keys(dbCollectionsDefine)); | ||
log.debug('using db defines:', Object.keys(dbCollectionsDefine)); | ||
this._dbCollectionsDefine = dbCollectionsDefine; | ||
@@ -34,3 +32,3 @@ this._url = url; | ||
async connect() { | ||
_d('connect to mongodb'); | ||
log.debug('connect to mongodb'); | ||
this._client = await mongodb_1.MongoClient.connect(this._url, this._options); | ||
@@ -43,6 +41,6 @@ this._db = await this._client.db(this._modName); | ||
}); | ||
_d('open mongodb successed'); | ||
log.debug('open mongodb successed'); | ||
} | ||
async _ensureSchemaCollections() { | ||
_d('_ensureSchemaCollections:'); | ||
log.debug('_ensureSchemaCollections:'); | ||
if (!this._db) | ||
@@ -52,8 +50,8 @@ return; | ||
const modCollDefines = lodash_1.default.pickBy(this._dbCollectionsDefine, (v) => !lodash_1.default.get(v.collOptions, '_extDb')); | ||
_d('modCollDefines:', Object.keys(modCollDefines)); | ||
log.debug('modCollDefines:', Object.keys(modCollDefines)); | ||
const externCollDefines = lodash_1.default.pickBy(this._dbCollectionsDefine, (v) => !!lodash_1.default.get(v.collOptions, '_extDb')); | ||
_d('externCollDefines:', externCollDefines); | ||
log.debug('externCollDefines:', externCollDefines); | ||
for (const colName of Object.keys(curColls)) { | ||
if (modCollDefines[colName]) { | ||
_d('open existed collection:', colName); | ||
log.debug('open existed collection:', colName); | ||
this._collections[colName] = curColls[colName]; | ||
@@ -66,6 +64,6 @@ } | ||
await this._db.renameCollection(colName, name); | ||
_d('rename unused collection:', name); | ||
log.info('rename unused collection:', name); | ||
} | ||
else { | ||
_d('unused collection:', colName); | ||
log.info('unused collection:', colName); | ||
} | ||
@@ -76,3 +74,3 @@ } | ||
this._collections[newColl] = await this._db.createCollection(newColl, this._dbCollectionsDefine[newColl].collOptions); | ||
_d('create new collection:', newColl); | ||
log.debug('create new collection:', newColl); | ||
} | ||
@@ -89,7 +87,7 @@ for (const k of Object.keys(externCollDefines)) { | ||
if (!extColls[extDbInfo.col]) { | ||
_d('create extern collection ok:', extDbInfo); | ||
log.debug('create extern collection ok:', extDbInfo); | ||
this._collections[k] = await externDb.createCollection(extDbInfo.col, lodash_1.default.omit(v.collOptions, '_extDb')); | ||
} | ||
else { | ||
_d('open extern collection ok:', extDbInfo); | ||
log.debug('open extern collection ok:', extDbInfo); | ||
this._collections[k] = extColls[extDbInfo.col]; | ||
@@ -105,3 +103,3 @@ } | ||
const indexes = lodash_1.default.keyBy(indexsArray, 'name'); | ||
_d('ensure collection indexes:', coll.collectionName, Object.keys(indexSchemas).join()); | ||
log.debug('ensure collection indexes:', coll.collectionName, Object.keys(indexSchemas).join()); | ||
for (const key of Object.keys(indexes)) { | ||
@@ -113,3 +111,3 @@ if (key.startsWith('_id')) | ||
delete indexes[key]; | ||
_d('drop invalid index:', coll.collectionName, key); | ||
log.info('drop invalid index:', coll.collectionName, key); | ||
} | ||
@@ -119,3 +117,3 @@ } | ||
if (lodash_1.default.isEmpty(indexes[key])) { | ||
_d('create new index:', coll.collectionName, key, indexSchemas[key]); | ||
log.info('create new index:', coll.collectionName, key, indexSchemas[key]); | ||
await coll.createIndex(indexSchemas[key].fields, { | ||
@@ -132,15 +130,15 @@ name: key, | ||
this._db.on('drop', () => { | ||
_d('mongodb drop:'); | ||
log.debug('mongodb drop:'); | ||
}); | ||
this._db.on('close', () => { | ||
_d('mongodb close:'); | ||
log.debug('mongodb close:'); | ||
}); | ||
this._db.on('error', (err) => { | ||
_d('mongodb error:', err); | ||
log.debug('mongodb error:', err); | ||
}); | ||
this._db.on('timeout', () => { | ||
_d('mongodb timeout:'); | ||
log.debug('mongodb timeout:'); | ||
}); | ||
this._db.on('reconnect', () => { | ||
_d('mongodb reconnect:'); | ||
log.debug('mongodb reconnect:'); | ||
}); | ||
@@ -147,0 +145,0 @@ } |
@@ -8,6 +8,4 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const path_1 = __importDefault(require("path")); | ||
const debug_1 = __importDefault(require("debug")); | ||
const package_json_1 = __importDefault(require("../package.json")); | ||
const _d = debug_1.default(package_json_1.default.name + ':' + path_1.default.basename(__filename, '.js')); | ||
const logger_1 = require("./logger"); | ||
const log = logger_1.logger(`${require('@/../package.json').name}:${require('path').parse(__filename).base}`); | ||
function _mergeExcludeFields(reqOptions, excludeFields) { | ||
@@ -68,5 +66,5 @@ let options = reqOptions || {}; | ||
const db = mongo.collections()[collName]; | ||
_d('findOne:', collName, req, sessions, _restOptions); | ||
log.debug('findOne:', collName, req, sessions, _restOptions); | ||
const options = _mergeExcludeFields(req.options, _restOptions.excludeFields); | ||
_d('findOne -- options:', options); | ||
log.debug('findOne -- options:', options); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
@@ -78,7 +76,7 @@ return await db.findOne(query, options); | ||
const db = mongo.collections()[collName]; | ||
_d('find:', collName, req, sessions, _restOptions); | ||
log.debug('find:', collName, req, sessions, _restOptions); | ||
const options = _mergeExcludeFields(req.options, _restOptions.excludeFields); | ||
_d('find -- options:', options); | ||
log.debug('find -- options:', options); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
return await db.find(query, options).toArray(); | ||
@@ -89,5 +87,5 @@ }, | ||
const db = mongo.collections()[collName]; | ||
_d('countDocuments:', collName, req, sessions, _restOptions); | ||
log.debug('countDocuments:', collName, req, sessions, _restOptions); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
return await db.countDocuments(query, req.options); | ||
@@ -98,5 +96,5 @@ }, | ||
const db = mongo.collections()[collName]; | ||
_d('estimatedDocumentCount:', collName, req, sessions, _restOptions); | ||
log.debug('estimatedDocumentCount:', collName, req, sessions, _restOptions); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
return await db.estimatedDocumentCount(query, req.options); | ||
@@ -107,5 +105,5 @@ }, | ||
const db = mongo.collections()[collName]; | ||
_d('geoHaystackSearch:', collName, req, sessions, _restOptions); | ||
log.debug('geoHaystackSearch:', collName, req, sessions, _restOptions); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
return await db.geoHaystackSearch(req.x, req.y, req.options); | ||
@@ -124,5 +122,5 @@ }, | ||
const db = mongo.collections()[collName]; | ||
_d('distinct:', collName, req, sessions, _restOptions); | ||
log.debug('distinct:', collName, req, sessions, _restOptions); | ||
let query = _sessionMatch(req.query, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
return await db.distinct(req.key, query); | ||
@@ -133,3 +131,3 @@ }, | ||
const db = mongo.collections()[collName]; | ||
_d('insertOne:', collName, req, sessions, _restOptions); | ||
log.debug('insertOne:', collName, req, sessions, _restOptions); | ||
let doc = req.doc; | ||
@@ -141,3 +139,3 @@ return await db.insertOne(doc); | ||
const db = mongo.collections()[collName]; | ||
_d('insertOne:', collName, req, sessions, _restOptions); | ||
log.debug('insertOne:', collName, req, sessions, _restOptions); | ||
let docs = req.docs; | ||
@@ -150,3 +148,3 @@ return await db.insertMany(docs); | ||
const db = mongo.collections()[collName]; | ||
_d('updateOne 11:', collName, req, sessions, _restOptions); | ||
log.debug('updateOne 11:', collName, req, sessions, _restOptions); | ||
const update = req.update; | ||
@@ -158,5 +156,5 @@ const options = (req.options || {}); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
_d('update:----', update); | ||
_d('options:----', options); | ||
log.debug('query:----', query); | ||
log.debug('update:----', update); | ||
log.debug('options:----', options); | ||
const ret = await db.updateOne(query, update, options); | ||
@@ -169,3 +167,3 @@ return ret['result']; | ||
const db = mongo.collections()[collName]; | ||
_d('updateOne 11:', collName, req, sessions, _restOptions); | ||
log.debug('updateOne 11:', collName, req, sessions, _restOptions); | ||
const update = req.update; | ||
@@ -177,5 +175,5 @@ const options = (req.options || {}); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
_d('update:----', update); | ||
_d('options:----', options); | ||
log.debug('query:----', query); | ||
log.debug('update:----', update); | ||
log.debug('options:----', options); | ||
const ret = await db.updateMany(query, update, options); | ||
@@ -188,3 +186,3 @@ return ret['result']; | ||
const db = mongo.collections()[collName]; | ||
_d('updateOne 11:', collName, req, sessions, _restOptions); | ||
log.debug('updateOne 11:', collName, req, sessions, _restOptions); | ||
const update = req.update; | ||
@@ -196,5 +194,5 @@ const options = _mergeExcludeFields(req.options, _restOptions.excludeFields); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
_d('update:----', update); | ||
_d('options:----', options); | ||
log.debug('query:----', query); | ||
log.debug('update:----', update); | ||
log.debug('options:----', options); | ||
const ret = await db.findOneAndUpdate(query, update, options); | ||
@@ -207,3 +205,3 @@ return ret; | ||
const db = mongo.collections()[collName]; | ||
_d('updateOne 11:', collName, req, sessions, _restOptions); | ||
log.debug('updateOne 11:', collName, req, sessions, _restOptions); | ||
const replacement = req.replacement; | ||
@@ -215,5 +213,5 @@ const options = _mergeExcludeFields(req.options, _restOptions.excludeFields); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
_d('update:----', replacement); | ||
_d('options:----', options); | ||
log.debug('query:----', query); | ||
log.debug('update:----', replacement); | ||
log.debug('options:----', options); | ||
const ret = await db.findOneAndReplace(query, replacement, options); | ||
@@ -225,6 +223,6 @@ return ret; | ||
const db = mongo.collections()[collName]; | ||
_d('deleteOne:', collName, req, sessions, _restOptions); | ||
log.debug('deleteOne:', collName, req, sessions, _restOptions); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
const options = (req.options || {}); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
const ret = await db.deleteOne(query, options); | ||
@@ -236,6 +234,6 @@ return ret['result']; | ||
const db = mongo.collections()[collName]; | ||
_d('deleteOne:', collName, req, sessions, _restOptions); | ||
log.debug('deleteOne:', collName, req, sessions, _restOptions); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
const options = (req.options || {}); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
const ret = await db.deleteMany(query, options); | ||
@@ -247,6 +245,6 @@ return ret['result']; | ||
const db = mongo.collections()[collName]; | ||
_d('deleteOne:', collName, req, sessions, _restOptions); | ||
log.debug('deleteOne:', collName, req, sessions, _restOptions); | ||
const options = _mergeExcludeFields(req.options, _restOptions.excludeFields); | ||
let query = _sessionMatch(req.filter, _restOptions.sessionMatch, sessions); | ||
_d('query:----', query); | ||
log.debug('query:----', query); | ||
const ret = await db.findOneAndDelete(query, options); | ||
@@ -253,0 +251,0 @@ return ret; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44715
17
1126