vona 1.0.0 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.en-US +3 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -0
- package/dist/app/extend/context.d.ts +4 -0
- package/dist/app/extend/context.js +152 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +35 -0
- package/dist/lib/base/dbTransaction.d.ts +12 -0
- package/dist/lib/base/dbTransaction.js +55 -0
- package/dist/lib/base/error.d.ts +18 -0
- package/dist/lib/base/error.js +70 -0
- package/dist/lib/base/model.d.ts +22 -0
- package/dist/lib/base/model.js +253 -0
- package/dist/lib/bean/_beanLocal_.d.ts +6 -0
- package/dist/lib/bean/_beanLocal_.js +16 -0
- package/dist/lib/bean/beanBase.d.ts +11 -0
- package/dist/lib/bean/beanBase.js +34 -0
- package/dist/lib/bean/beanBaseSimple.d.ts +8 -0
- package/dist/lib/bean/beanBaseSimple.js +31 -0
- package/dist/lib/bean/beanContainer.d.ts +39 -0
- package/dist/lib/bean/beanContainer.js +514 -0
- package/dist/lib/bean/beanLocal.d.ts +6 -0
- package/dist/lib/bean/beanLocal.js +16 -0
- package/dist/lib/bean/beanModuleScopeBase.d.ts +10 -0
- package/dist/lib/bean/beanModuleScopeBase.js +28 -0
- package/dist/lib/bean/beanScopeBase.d.ts +6 -0
- package/dist/lib/bean/beanScopeBase.js +19 -0
- package/dist/lib/bean/beanScopeScene.d.ts +12 -0
- package/dist/lib/bean/beanScopeScene.js +23 -0
- package/dist/lib/bean/beanSimple.d.ts +7 -0
- package/dist/lib/bean/beanSimple.js +24 -0
- package/dist/lib/bean/index.d.ts +8 -0
- package/dist/lib/bean/index.js +24 -0
- package/dist/lib/bean/resource/config/broadcast.d.ts +7 -0
- package/dist/lib/bean/resource/config/broadcast.js +3 -0
- package/dist/lib/bean/resource/config/index.d.ts +2 -0
- package/dist/lib/bean/resource/config/index.js +18 -0
- package/dist/lib/bean/resource/config/middleware.d.ts +9 -0
- package/dist/lib/bean/resource/config/middleware.js +3 -0
- package/dist/lib/bean/resource/config/startup.d.ts +9 -0
- package/dist/lib/bean/resource/config/startup.js +3 -0
- package/dist/lib/bean/resource/config/type.d.ts +43 -0
- package/dist/lib/bean/resource/config/type.js +3 -0
- package/dist/lib/bean/resource/constant/index.d.ts +2 -0
- package/dist/lib/bean/resource/constant/index.js +18 -0
- package/dist/lib/bean/resource/constant/type.d.ts +2 -0
- package/dist/lib/bean/resource/constant/type.js +3 -0
- package/dist/lib/bean/resource/entity/entityBase.d.ts +21 -0
- package/dist/lib/bean/resource/entity/entityBase.js +20 -0
- package/dist/lib/bean/resource/entity/index.d.ts +2 -0
- package/dist/lib/bean/resource/entity/index.js +18 -0
- package/dist/lib/bean/resource/error/beanScopeError.d.ts +11 -0
- package/dist/lib/bean/resource/error/beanScopeError.js +34 -0
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.d.ts +14 -0
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +35 -0
- package/dist/lib/bean/resource/error/errorClass.d.ts +18 -0
- package/dist/lib/bean/resource/error/errorClass.js +78 -0
- package/dist/lib/bean/resource/error/errorContext.d.ts +38 -0
- package/dist/lib/bean/resource/error/errorContext.js +3 -0
- package/dist/lib/bean/resource/error/errorGlobal.d.ts +8 -0
- package/dist/lib/bean/resource/error/errorGlobal.js +3 -0
- package/dist/lib/bean/resource/error/errorInternal.d.ts +67 -0
- package/dist/lib/bean/resource/error/errorInternal.js +70 -0
- package/dist/lib/bean/resource/error/errorObject.d.ts +5 -0
- package/dist/lib/bean/resource/error/errorObject.js +3 -0
- package/dist/lib/bean/resource/error/index.d.ts +9 -0
- package/dist/lib/bean/resource/error/index.js +25 -0
- package/dist/lib/bean/resource/error/type.d.ts +9 -0
- package/dist/lib/bean/resource/error/type.js +3 -0
- package/dist/lib/bean/resource/index.d.ts +8 -0
- package/dist/lib/bean/resource/index.js +24 -0
- package/dist/lib/bean/resource/locale/beanScopeLocale.d.ts +11 -0
- package/dist/lib/bean/resource/locale/beanScopeLocale.js +33 -0
- package/dist/lib/bean/resource/locale/beanScopeLocaleImpl.d.ts +3 -0
- package/dist/lib/bean/resource/locale/beanScopeLocaleImpl.js +14 -0
- package/dist/lib/bean/resource/locale/index.d.ts +4 -0
- package/dist/lib/bean/resource/locale/index.js +20 -0
- package/dist/lib/bean/resource/locale/localeCtx.d.ts +8 -0
- package/dist/lib/bean/resource/locale/localeCtx.js +63 -0
- package/dist/lib/bean/resource/locale/type.d.ts +19 -0
- package/dist/lib/bean/resource/locale/type.js +3 -0
- package/dist/lib/bean/resource/model/beanModelBase.d.ts +24 -0
- package/dist/lib/bean/resource/model/beanModelBase.js +165 -0
- package/dist/lib/bean/resource/model/beanModelBaseInner.d.ts +29 -0
- package/dist/lib/bean/resource/model/beanModelBaseInner.js +86 -0
- package/dist/lib/bean/resource/model/index.d.ts +2 -0
- package/dist/lib/bean/resource/model/index.js +18 -0
- package/dist/lib/bean/resource/model/type.d.ts +12 -0
- package/dist/lib/bean/resource/model/type.js +3 -0
- package/dist/lib/bean/resource/route/index.d.ts +2 -0
- package/dist/lib/bean/resource/route/index.js +18 -0
- package/dist/lib/bean/resource/route/type.d.ts +60 -0
- package/dist/lib/bean/resource/route/type.js +3 -0
- package/dist/lib/bean/scope/beanScopeBase.d.ts +19 -0
- package/dist/lib/bean/scope/beanScopeBase.js +104 -0
- package/dist/lib/bean/scope/beanScopeBean.d.ts +10 -0
- package/dist/lib/bean/scope/beanScopeBean.js +34 -0
- package/dist/lib/bean/scope/beanScopeError.d.ts +11 -0
- package/dist/lib/bean/scope/beanScopeError.js +21 -0
- package/dist/lib/bean/scope/beanScopeErrorImpl.d.ts +14 -0
- package/dist/lib/bean/scope/beanScopeErrorImpl.js +21 -0
- package/dist/lib/bean/scope/beanScopeScene.d.ts +12 -0
- package/dist/lib/bean/scope/beanScopeScene.js +42 -0
- package/dist/lib/bean/scope/index.d.ts +5 -0
- package/dist/lib/bean/scope/index.js +21 -0
- package/dist/lib/bean/scope/type.d.ts +21 -0
- package/dist/lib/bean/scope/type.js +3 -0
- package/dist/lib/bean/type.d.ts +17 -0
- package/dist/lib/bean/type.js +4 -0
- package/dist/lib/core/index.d.ts +5 -0
- package/dist/lib/core/index.js +21 -0
- package/dist/lib/core/meta.d.ts +65 -0
- package/dist/lib/core/meta.js +335 -0
- package/dist/lib/core/metaCtx.d.ts +16 -0
- package/dist/lib/core/metaCtx.js +71 -0
- package/dist/lib/core/metadata.d.ts +12 -0
- package/dist/lib/core/metadata.js +52 -0
- package/dist/lib/core/resource.d.ts +29 -0
- package/dist/lib/core/resource.js +172 -0
- package/dist/lib/decorator/class/aop.d.ts +3 -0
- package/dist/lib/decorator/class/aop.js +23 -0
- package/dist/lib/decorator/class/atom.d.ts +3 -0
- package/dist/lib/decorator/class/atom.js +22 -0
- package/dist/lib/decorator/class/bean.d.ts +3 -0
- package/dist/lib/decorator/class/bean.js +23 -0
- package/dist/lib/decorator/class/controller.d.ts +3 -0
- package/dist/lib/decorator/class/controller.js +22 -0
- package/dist/lib/decorator/class/index.d.ts +10 -0
- package/dist/lib/decorator/class/index.js +26 -0
- package/dist/lib/decorator/class/local.d.ts +3 -0
- package/dist/lib/decorator/class/local.js +23 -0
- package/dist/lib/decorator/class/model.d.ts +3 -0
- package/dist/lib/decorator/class/model.js +28 -0
- package/dist/lib/decorator/class/scope.d.ts +2 -0
- package/dist/lib/decorator/class/scope.js +20 -0
- package/dist/lib/decorator/class/service.d.ts +3 -0
- package/dist/lib/decorator/class/service.js +23 -0
- package/dist/lib/decorator/class/use.d.ts +5 -0
- package/dist/lib/decorator/class/use.js +43 -0
- package/dist/lib/decorator/class/util.d.ts +3 -0
- package/dist/lib/decorator/class/util.js +10 -0
- package/dist/lib/decorator/class/virtual.d.ts +3 -0
- package/dist/lib/decorator/class/virtual.js +24 -0
- package/dist/lib/decorator/index.d.ts +7 -0
- package/dist/lib/decorator/index.js +23 -0
- package/dist/lib/decorator/interface/beanOptions.d.ts +55 -0
- package/dist/lib/decorator/interface/beanOptions.js +8 -0
- package/dist/lib/decorator/interface/useOptions.d.ts +14 -0
- package/dist/lib/decorator/interface/useOptions.js +3 -0
- package/dist/lib/decorator/type/constructable.d.ts +2 -0
- package/dist/lib/decorator/type/constructable.js +3 -0
- package/dist/lib/decorator/type/containerScope.d.ts +2 -0
- package/dist/lib/decorator/type/containerScope.js +3 -0
- package/dist/lib/decorator/type/injectionScope.d.ts +2 -0
- package/dist/lib/decorator/type/injectionScope.js +3 -0
- package/dist/lib/error/error.d.ts +18 -0
- package/dist/lib/error/error.js +71 -0
- package/dist/lib/error/errorClass.d.ts +18 -0
- package/dist/lib/error/errorClass.js +72 -0
- package/dist/lib/error/errorContext.d.ts +38 -0
- package/dist/lib/error/errorContext.js +3 -0
- package/dist/lib/error/errorGlobal.d.ts +8 -0
- package/dist/lib/error/errorGlobal.js +3 -0
- package/dist/lib/error/errorInternal.d.ts +67 -0
- package/dist/lib/error/errorInternal.js +70 -0
- package/dist/lib/error/errorObject.d.ts +5 -0
- package/dist/lib/error/errorObject.js +3 -0
- package/dist/lib/error/index.d.ts +5 -0
- package/dist/lib/error/index.js +21 -0
- package/dist/lib/framework/bootstrap.d.ts +9 -0
- package/dist/lib/framework/bootstrap.js +35 -0
- package/dist/lib/framework/framework.d.ts +11 -0
- package/dist/lib/framework/framework.js +28 -0
- package/dist/lib/framework/loader.d.ts +21 -0
- package/dist/lib/framework/loader.js +57 -0
- package/dist/lib/framework/meta.d.ts +2 -0
- package/dist/lib/framework/meta.js +23 -0
- package/dist/lib/framework/metaClass.d.ts +2 -0
- package/dist/lib/framework/metaClass.js +26 -0
- package/dist/lib/framework/moduleInfo.d.ts +3 -0
- package/dist/lib/framework/moduleInfo.js +67 -0
- package/dist/lib/framework/util.d.ts +4 -0
- package/dist/lib/framework/util.js +15 -0
- package/dist/lib/module/asset/errors.d.ts +68 -0
- package/dist/lib/module/asset/errors.js +69 -0
- package/dist/lib/module/bean/index.d.ts +4 -0
- package/dist/lib/module/bean/index.js +24 -0
- package/dist/lib/module/broadcast/broadcast.d.ts +3 -0
- package/dist/lib/module/broadcast/broadcast.js +49 -0
- package/dist/lib/module/broadcast/broadcastClient.d.ts +24 -0
- package/dist/lib/module/broadcast/broadcastClient.js +91 -0
- package/dist/lib/module/cluster/agent.d.ts +3 -0
- package/dist/lib/module/cluster/agent.js +22 -0
- package/dist/lib/module/cluster/app.d.ts +3 -0
- package/dist/lib/module/cluster/app.js +26 -0
- package/dist/lib/module/config.d.ts +3 -0
- package/dist/lib/module/config.js +67 -0
- package/dist/lib/module/constant.d.ts +3 -0
- package/dist/lib/module/constant.js +46 -0
- package/dist/lib/module/contextPatch.d.ts +3 -0
- package/dist/lib/module/contextPatch.js +16 -0
- package/dist/lib/module/errors.d.ts +3 -0
- package/dist/lib/module/errors.js +49 -0
- package/dist/lib/module/index.d.ts +2 -0
- package/dist/lib/module/index.js +3 -0
- package/dist/lib/module/loader.d.ts +5 -0
- package/dist/lib/module/loader.js +73 -0
- package/dist/lib/module/locales.d.ts +3 -0
- package/dist/lib/module/locales.js +132 -0
- package/dist/lib/module/messenger.d.ts +25 -0
- package/dist/lib/module/messenger.js +128 -0
- package/dist/lib/module/middleware.d.ts +3 -0
- package/dist/lib/module/middleware.js +113 -0
- package/dist/lib/module/model.d.ts +3 -0
- package/dist/lib/module/model.js +47 -0
- package/dist/lib/module/module.d.ts +12 -0
- package/dist/lib/module/module.js +134 -0
- package/dist/lib/module/moduleMeta.d.ts +3 -0
- package/dist/lib/module/moduleMeta.js +26 -0
- package/dist/lib/module/queue/queue.d.ts +3 -0
- package/dist/lib/module/queue/queue.js +59 -0
- package/dist/lib/module/queue/queueClient.d.ts +26 -0
- package/dist/lib/module/queue/queueClient.js +262 -0
- package/dist/lib/module/redis.d.ts +11 -0
- package/dist/lib/module/redis.js +46 -0
- package/dist/lib/module/reload/development.d.ts +3 -0
- package/dist/lib/module/reload/development.js +98 -0
- package/dist/lib/module/reload/reload.d.ts +16 -0
- package/dist/lib/module/reload/reload.js +113 -0
- package/dist/lib/module/reload.d.ts +7 -0
- package/dist/lib/module/reload.js +17 -0
- package/dist/lib/module/route.d.ts +10 -0
- package/dist/lib/module/route.js +239 -0
- package/dist/lib/module/schedule.d.ts +3 -0
- package/dist/lib/module/schedule.js +129 -0
- package/dist/lib/module/service.d.ts +3 -0
- package/dist/lib/module/service.js +35 -0
- package/dist/lib/module/socketio.d.ts +5 -0
- package/dist/lib/module/socketio.js +47 -0
- package/dist/lib/module/startup.d.ts +2 -0
- package/dist/lib/module/startup.js +134 -0
- package/dist/lib/module/version/clear.d.ts +2 -0
- package/dist/lib/module/version/clear.js +42 -0
- package/dist/lib/module/version/ready.d.ts +6 -0
- package/dist/lib/module/version/ready.js +106 -0
- package/dist/lib/resource/error/errorClass.d.ts +18 -0
- package/dist/lib/resource/error/errorClass.js +72 -0
- package/dist/lib/resource/error/errorContext.d.ts +38 -0
- package/dist/lib/resource/error/errorContext.js +3 -0
- package/dist/lib/resource/error/errorGlobal.d.ts +8 -0
- package/dist/lib/resource/error/errorGlobal.js +3 -0
- package/dist/lib/resource/error/errorInternal.d.ts +67 -0
- package/dist/lib/resource/error/errorInternal.js +70 -0
- package/dist/lib/resource/error/errorObject.d.ts +5 -0
- package/dist/lib/resource/error/errorObject.js +3 -0
- package/dist/lib/resource/error/index.d.ts +5 -0
- package/dist/lib/resource/error/index.js +21 -0
- package/dist/lib/utils/index.d.ts +2 -0
- package/dist/lib/utils/index.js +18 -0
- package/dist/lib/utils/isClass.d.ts +2 -0
- package/dist/lib/utils/isClass.js +20 -0
- package/dist/lib/utils/mockUtil.d.ts +11 -0
- package/dist/lib/utils/mockUtil.js +34 -0
- package/dist/lib/utils/mockUtilCtx.d.ts +10 -0
- package/dist/lib/utils/mockUtilCtx.js +35 -0
- package/dist/lib/utils/performAction.d.ts +19 -0
- package/dist/lib/utils/performAction.js +137 -0
- package/dist/lib/utils/util.d.ts +63 -0
- package/dist/lib/utils/util.js +445 -0
- package/dist/lib/utils/utilCtx.d.ts +34 -0
- package/dist/lib/utils/utilCtx.js +137 -0
- package/dist/types/application/app.d.ts +19 -0
- package/dist/types/application/app.js +28 -0
- package/dist/types/application/index.d.ts +2 -0
- package/dist/types/application/index.js +18 -0
- package/dist/types/config/appInfo.d.ts +4 -0
- package/dist/types/config/appInfo.js +3 -0
- package/dist/types/config/config.d.ts +10 -0
- package/dist/types/config/config.js +3 -0
- package/dist/types/config/development.d.ts +4 -0
- package/dist/types/config/development.js +3 -0
- package/dist/types/config/index.d.ts +4 -0
- package/dist/types/config/index.js +20 -0
- package/dist/types/config/locale.d.ts +10 -0
- package/dist/types/config/locale.js +7 -0
- package/dist/types/context/contextBase.d.ts +21 -0
- package/dist/types/context/contextBase.js +3 -0
- package/dist/types/context/contextConfig.d.ts +4 -0
- package/dist/types/context/contextConfig.js +3 -0
- package/dist/types/context/contextError.d.ts +25 -0
- package/dist/types/context/contextError.js +3 -0
- package/dist/types/context/contextLocale.d.ts +9 -0
- package/dist/types/context/contextLocale.js +3 -0
- package/dist/types/context/contextOthers.d.ts +4 -0
- package/dist/types/context/contextOthers.js +3 -0
- package/dist/types/context/contextState.d.ts +8 -0
- package/dist/types/context/contextState.js +3 -0
- package/dist/types/context/index.d.ts +18 -0
- package/dist/types/context/index.js +18 -0
- package/dist/types/enum/appEvent.d.ts +5 -0
- package/dist/types/enum/appEvent.js +9 -0
- package/dist/types/enum/index.d.ts +2 -0
- package/dist/types/enum/index.js +18 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +23 -0
- package/dist/types/interface/broadcast.d.ts +5 -0
- package/dist/types/interface/broadcast.js +3 -0
- package/dist/types/interface/error.d.ts +8 -0
- package/dist/types/interface/error.js +3 -0
- package/dist/types/interface/index.d.ts +6 -0
- package/dist/types/interface/index.js +22 -0
- package/dist/types/interface/module.d.ts +32 -0
- package/dist/types/interface/module.js +18 -0
- package/dist/types/interface/monkey.d.ts +25 -0
- package/dist/types/interface/monkey.js +3 -0
- package/dist/types/interface/queue.d.ts +29 -0
- package/dist/types/interface/queue.js +3 -0
- package/dist/types/interface/schedule.d.ts +11 -0
- package/dist/types/interface/schedule.js +3 -0
- package/dist/types/utils/cast.d.ts +6 -0
- package/dist/types/utils/cast.js +8 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/index.js +19 -0
- package/dist/types/utils/powerPartial.d.ts +4 -0
- package/dist/types/utils/powerPartial.js +3 -0
- package/package.json +61 -14
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ModuleTools = void 0;
|
|
30
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const module_glob_1 = require("@cabloy/module-glob");
|
|
33
|
+
const beanSimple_js_1 = require("../bean/beanSimple.js");
|
|
34
|
+
const node_url_1 = require("node:url");
|
|
35
|
+
const Path = __importStar(require("node:path"));
|
|
36
|
+
// const __import_type_serialization = true;
|
|
37
|
+
const __import_type_serialization = false;
|
|
38
|
+
class ModuleTools extends beanSimple_js_1.BeanSimple {
|
|
39
|
+
async prepare() {
|
|
40
|
+
const app = this.app;
|
|
41
|
+
// all modules
|
|
42
|
+
const { suites, modules, modulesArray } = await (0, module_glob_1.glob)({
|
|
43
|
+
projectMode: 'vona',
|
|
44
|
+
projectPath: path_1.default.join(app.options.baseDir, '../..'),
|
|
45
|
+
disabledModules: process.env.Project_Disabled_Modules,
|
|
46
|
+
disabledSuites: process.env.Project_Disabled_Suites,
|
|
47
|
+
log: !!app.meta.inAgent,
|
|
48
|
+
});
|
|
49
|
+
app.meta.suites = suites;
|
|
50
|
+
app.meta.modules = modules;
|
|
51
|
+
app.meta.modulesArray = modulesArray;
|
|
52
|
+
app.meta.modulesMonkey = {};
|
|
53
|
+
// app monkey
|
|
54
|
+
let pathAppMonkey;
|
|
55
|
+
if (app.meta.isTest || app.meta.isLocal) {
|
|
56
|
+
pathAppMonkey = _pathToHref(path_1.default.resolve(process.cwd(), 'src/backend/config/monkey.mts'));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
pathAppMonkey = _pathToHref(path_1.default.resolve(app.options.baseDir, 'config/monkey.mjs'));
|
|
60
|
+
}
|
|
61
|
+
if (fs_extra_1.default.existsSync(pathAppMonkey)) {
|
|
62
|
+
const AppMonkey = await import(pathAppMonkey);
|
|
63
|
+
app.meta.appMonkey = app.bean._newBean(AppMonkey.AppMonkey);
|
|
64
|
+
}
|
|
65
|
+
return modules;
|
|
66
|
+
}
|
|
67
|
+
async load() {
|
|
68
|
+
const app = this.app;
|
|
69
|
+
// 1. import
|
|
70
|
+
const modulesResource = await this._importModules();
|
|
71
|
+
// 2. resource
|
|
72
|
+
for (let i = 0; i < modulesResource.length; i++) {
|
|
73
|
+
const module = app.meta.modulesArray[i];
|
|
74
|
+
module.resource = modulesResource[i];
|
|
75
|
+
}
|
|
76
|
+
// 3. main / monkey
|
|
77
|
+
for (const module of app.meta.modulesArray) {
|
|
78
|
+
if (module.resource.Main) {
|
|
79
|
+
module.mainInstance = app.bean._newBean(module.resource.Main, module);
|
|
80
|
+
}
|
|
81
|
+
if (module.resource.Monkey) {
|
|
82
|
+
module.monkeyInstance = app.bean._newBean(module.resource.Monkey, module);
|
|
83
|
+
app.meta.modulesMonkey[module.info.relativeName] = module;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async monkey(monkeyName) {
|
|
88
|
+
const app = this.app;
|
|
89
|
+
for (const module of app.meta.modulesArray) {
|
|
90
|
+
await app.meta.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, monkeyName, module);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
_getModuleIndexPath(module) {
|
|
94
|
+
const app = this.app;
|
|
95
|
+
const pathSrc = `${module.root}/src/index.ts`;
|
|
96
|
+
if ((app.meta.isTest || app.meta.isLocal) && fs_extra_1.default.existsSync(pathSrc)) {
|
|
97
|
+
return _pathToHref(pathSrc);
|
|
98
|
+
}
|
|
99
|
+
return _pathToHref(`${module.root}/dist/index.js`);
|
|
100
|
+
}
|
|
101
|
+
async _importModules_serialization() {
|
|
102
|
+
const modulesResource = [];
|
|
103
|
+
for (const module of this.app.meta.modulesArray) {
|
|
104
|
+
modulesResource.push(await import(this._getModuleIndexPath(module)));
|
|
105
|
+
}
|
|
106
|
+
return modulesResource;
|
|
107
|
+
}
|
|
108
|
+
async _importModules_parallelization() {
|
|
109
|
+
const promises = [];
|
|
110
|
+
for (const module of this.app.meta.modulesArray) {
|
|
111
|
+
promises.push(import(this._getModuleIndexPath(module)));
|
|
112
|
+
}
|
|
113
|
+
return await Promise.all(promises);
|
|
114
|
+
}
|
|
115
|
+
async _importModules() {
|
|
116
|
+
const timeBegin = new Date();
|
|
117
|
+
console.log(`import modules begin, pid: ${process.pid}`);
|
|
118
|
+
let modulesResource;
|
|
119
|
+
if (__import_type_serialization) {
|
|
120
|
+
modulesResource = await this._importModules_serialization();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
modulesResource = await this._importModules_parallelization();
|
|
124
|
+
}
|
|
125
|
+
const timeEnd = new Date();
|
|
126
|
+
console.log(`import modules end, pid: ${process.pid}: ${(timeEnd.valueOf() - timeBegin.valueOf()) / 1000}s`);
|
|
127
|
+
return modulesResource;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.ModuleTools = ModuleTools;
|
|
131
|
+
function _pathToHref(fileName) {
|
|
132
|
+
return Path.sep === '\\' ? (0, node_url_1.pathToFileURL)(fileName).href : fileName;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
async function default_1(app, modules) {
|
|
4
|
+
// all metas
|
|
5
|
+
app.meta.metas = {};
|
|
6
|
+
// load metas
|
|
7
|
+
await loadMetas();
|
|
8
|
+
async function loadMetas() {
|
|
9
|
+
for (const key in modules) {
|
|
10
|
+
const module = modules[key];
|
|
11
|
+
// module meta
|
|
12
|
+
if (typeof module.resource.meta === 'function') {
|
|
13
|
+
module.meta = module.resource.meta(app);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
module.meta = module.resource.meta;
|
|
17
|
+
}
|
|
18
|
+
if (module.meta) {
|
|
19
|
+
await app.meta.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, 'metaLoaded', module, module.meta);
|
|
20
|
+
}
|
|
21
|
+
app.meta.metas[module.info.relativeName] = module.meta;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = default_1;
|
|
26
|
+
//# sourceMappingURL=moduleMeta.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const queueClient_js_1 = require("./queueClient.js");
|
|
4
|
+
function default_1(app, modules) {
|
|
5
|
+
// queue
|
|
6
|
+
app.meta.queue = app.bean._newBean(queueClient_js_1.QueueClient);
|
|
7
|
+
// all queues
|
|
8
|
+
const ebQueues = (app.meta.queues = {});
|
|
9
|
+
// load queues
|
|
10
|
+
loadQueues();
|
|
11
|
+
function loadQueues() {
|
|
12
|
+
for (const key in modules) {
|
|
13
|
+
const module = modules[key];
|
|
14
|
+
const config = app.meta.configs[module.info.relativeName];
|
|
15
|
+
if (!config.queues)
|
|
16
|
+
continue;
|
|
17
|
+
for (const queueName in config.queues) {
|
|
18
|
+
const queueConfig = config.queues[queueName];
|
|
19
|
+
const fullKey = `${module.info.relativeName}:${queueName}`;
|
|
20
|
+
// bean
|
|
21
|
+
const beanName = queueConfig.bean;
|
|
22
|
+
if (!beanName)
|
|
23
|
+
throw new Error(`bean not set for queue: ${fullKey}`);
|
|
24
|
+
let bean;
|
|
25
|
+
if (typeof beanName === 'string') {
|
|
26
|
+
bean = {
|
|
27
|
+
module: module.info.relativeName,
|
|
28
|
+
name: beanName,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
bean = {
|
|
33
|
+
module: beanName.module || module.info.relativeName,
|
|
34
|
+
name: beanName.name,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
ebQueues[fullKey] = {
|
|
38
|
+
module: module.info.relativeName,
|
|
39
|
+
name: queueName,
|
|
40
|
+
config: queueConfig,
|
|
41
|
+
bean,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
app.meta._loadQueueWorkers = ({ subdomain }) => {
|
|
47
|
+
for (const fullKey in ebQueues) {
|
|
48
|
+
const queue = ebQueues[fullKey];
|
|
49
|
+
const info = {
|
|
50
|
+
subdomain,
|
|
51
|
+
module: queue.module,
|
|
52
|
+
queueName: queue.name,
|
|
53
|
+
};
|
|
54
|
+
app.meta.queue._ensureWorker(info);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.default = default_1;
|
|
59
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as bull from 'bullmq';
|
|
2
|
+
import { IQueueCallbacks, IQueueQueue, IQueueQueues, IQueueWork, IQueueWorks } from '../../../types/index.js';
|
|
3
|
+
import { BeanSimple } from '../../bean/beanSimple.js';
|
|
4
|
+
export declare class QueueClient extends BeanSimple {
|
|
5
|
+
_workers: IQueueWorks;
|
|
6
|
+
_queues: IQueueQueues;
|
|
7
|
+
_queueCallbacks: IQueueCallbacks;
|
|
8
|
+
push(info: any): void;
|
|
9
|
+
pushAsync(info: any): Promise<unknown>;
|
|
10
|
+
_clearWorkers(): Promise<void>;
|
|
11
|
+
_createWorker(info: any, queueKey: any): IQueueWork;
|
|
12
|
+
_createQueue(info: any, queueKey: any): IQueueQueue;
|
|
13
|
+
_ensureWorker(info: any): void;
|
|
14
|
+
_ensureQueue(info: any): IQueueQueue;
|
|
15
|
+
_getQueue(info: any): bull.Queue<any, any, string>;
|
|
16
|
+
_callCallback(jobId: any, failedReason: any, data: any): void;
|
|
17
|
+
_queuePush(info: any, isAsync: any): Promise<unknown>;
|
|
18
|
+
_combineQueueKey({ subdomain, module, queueName }: {
|
|
19
|
+
subdomain: any;
|
|
20
|
+
module?: string | undefined;
|
|
21
|
+
queueName?: string | undefined;
|
|
22
|
+
}): string;
|
|
23
|
+
_performTask(job: any): Promise<any>;
|
|
24
|
+
_getRepeatKey(name: any, repeat: any): string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=queueClient.d.ts.map
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.QueueClient = void 0;
|
|
27
|
+
const bull = __importStar(require("bullmq"));
|
|
28
|
+
const uuid = __importStar(require("uuid"));
|
|
29
|
+
const beanSimple_js_1 = require("../../bean/beanSimple.js");
|
|
30
|
+
class QueueClient extends beanSimple_js_1.BeanSimple {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
Object.defineProperty(this, "_workers", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: {}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "_queues", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: {}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "_queueCallbacks", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: {}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
push(info) {
|
|
53
|
+
if (!info.dbLevel)
|
|
54
|
+
info.dbLevel = 1;
|
|
55
|
+
this._queuePush(info, false);
|
|
56
|
+
}
|
|
57
|
+
// { locale, subdomain, module, queueName,queueNameSub,data }
|
|
58
|
+
pushAsync(info) {
|
|
59
|
+
if (!info.dbLevel)
|
|
60
|
+
throw new Error('should specify the info.dbLevel');
|
|
61
|
+
return this._queuePush(info, true);
|
|
62
|
+
}
|
|
63
|
+
async _clearWorkers() {
|
|
64
|
+
for (const queueKey in this._workers) {
|
|
65
|
+
const _worker = this._workers[queueKey];
|
|
66
|
+
await _worker.worker.close();
|
|
67
|
+
}
|
|
68
|
+
this._workers = {};
|
|
69
|
+
}
|
|
70
|
+
_createWorker(info, queueKey) {
|
|
71
|
+
const app = this.app;
|
|
72
|
+
// worker
|
|
73
|
+
const _worker = {};
|
|
74
|
+
// prefix
|
|
75
|
+
const prefix = `bull_${app.name}:queue`;
|
|
76
|
+
// queue config
|
|
77
|
+
const queueConfig = app.meta.queues[`${info.module}:${info.queueName}`].config;
|
|
78
|
+
// queueConfig.options: queue/worker/job/redlock
|
|
79
|
+
const workerOptions = (queueConfig.options && queueConfig.options.worker) || null;
|
|
80
|
+
const redlockOptions = (queueConfig.options && queueConfig.options.redlock) || null;
|
|
81
|
+
const _redlockOptions = Object.assign({}, app.config.queue.redlock.options, redlockOptions);
|
|
82
|
+
// redlock
|
|
83
|
+
if (!queueConfig.concurrency) {
|
|
84
|
+
_worker.redlock = app.meta.redlock.create(_redlockOptions);
|
|
85
|
+
}
|
|
86
|
+
// create work
|
|
87
|
+
const connectionWorker = app.redis.get('queue').duplicate();
|
|
88
|
+
const _workerOptions = Object.assign({}, app.config.queue.worker, workerOptions, {
|
|
89
|
+
prefix,
|
|
90
|
+
connection: connectionWorker,
|
|
91
|
+
});
|
|
92
|
+
_worker.worker = new bull.Worker(queueKey, async (job) => {
|
|
93
|
+
// concurrency
|
|
94
|
+
if (queueConfig.concurrency) {
|
|
95
|
+
return await this._performTask(job);
|
|
96
|
+
}
|
|
97
|
+
// redlock
|
|
98
|
+
const _lockResource = `queue:${queueKey}${job.data.queueNameSub ? '#' + job.data.queueNameSub : ''}`;
|
|
99
|
+
return await app.meta.util.lock({
|
|
100
|
+
// subdomain: job.data.subdomain, // need not
|
|
101
|
+
resource: _lockResource,
|
|
102
|
+
options: _redlockOptions,
|
|
103
|
+
redlock: _worker.redlock,
|
|
104
|
+
fn: async () => {
|
|
105
|
+
return await this._performTask(job);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}, _workerOptions);
|
|
109
|
+
_worker.worker.on('failed', (_job, err) => {
|
|
110
|
+
app.logger.error(err);
|
|
111
|
+
});
|
|
112
|
+
_worker.worker.on('error', err => {
|
|
113
|
+
if (err.message && err.message.indexOf('Missing lock for job') > -1) {
|
|
114
|
+
const workerInner = _worker.worker;
|
|
115
|
+
if (!workerInner.running) {
|
|
116
|
+
_worker.worker.run().catch(error => {
|
|
117
|
+
console.error(error);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
// ok
|
|
123
|
+
return _worker;
|
|
124
|
+
}
|
|
125
|
+
_createQueue(info, queueKey) {
|
|
126
|
+
const app = this.app;
|
|
127
|
+
// queue
|
|
128
|
+
const _queue = {};
|
|
129
|
+
// prefix
|
|
130
|
+
const prefix = `bull_${app.name}:queue`;
|
|
131
|
+
// queue config
|
|
132
|
+
const queueConfig = app.meta.queues[`${info.module}:${info.queueName}`].config;
|
|
133
|
+
// queueConfig.options: queue/worker/job/limiter
|
|
134
|
+
const queueOptions = (queueConfig.options && queueConfig.options.queue) || null;
|
|
135
|
+
// create queue
|
|
136
|
+
const connectionQueue = app.redis.get('queue').duplicate();
|
|
137
|
+
const _queueOptions = Object.assign({}, queueOptions, { prefix, connection: connectionQueue });
|
|
138
|
+
_queue.queue = new bull.Queue(queueKey, _queueOptions);
|
|
139
|
+
// create events
|
|
140
|
+
const connectionEvents = app.redis.get('queue').duplicate();
|
|
141
|
+
_queue.queueEvents = new bull.QueueEvents(queueKey, { prefix, connection: connectionEvents });
|
|
142
|
+
_queue.queueEvents.on('completed', ({ jobId, returnvalue }) => {
|
|
143
|
+
this._callCallback(jobId, null, returnvalue);
|
|
144
|
+
});
|
|
145
|
+
_queue.queueEvents.on('failed', ({ jobId, failedReason }) => {
|
|
146
|
+
this._callCallback(jobId, failedReason, null);
|
|
147
|
+
});
|
|
148
|
+
// ok
|
|
149
|
+
return _queue;
|
|
150
|
+
}
|
|
151
|
+
_ensureWorker(info) {
|
|
152
|
+
// queueKey
|
|
153
|
+
const queueKey = this._combineQueueKey(info);
|
|
154
|
+
// worker
|
|
155
|
+
if (!this._workers[queueKey]) {
|
|
156
|
+
this._workers[queueKey] = this._createWorker(info, queueKey);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
_ensureQueue(info) {
|
|
160
|
+
// worker
|
|
161
|
+
this._ensureWorker(info);
|
|
162
|
+
// queueKey
|
|
163
|
+
const queueKey = this._combineQueueKey(info);
|
|
164
|
+
// queue
|
|
165
|
+
if (!this._queues[queueKey]) {
|
|
166
|
+
this._queues[queueKey] = this._createQueue(info, queueKey);
|
|
167
|
+
}
|
|
168
|
+
// ok
|
|
169
|
+
return this._queues[queueKey];
|
|
170
|
+
}
|
|
171
|
+
_getQueue(info) {
|
|
172
|
+
return this._ensureQueue(info).queue;
|
|
173
|
+
}
|
|
174
|
+
_callCallback(jobId, failedReason, data) {
|
|
175
|
+
const _callback = this._queueCallbacks[jobId];
|
|
176
|
+
if (_callback) {
|
|
177
|
+
delete this._queueCallbacks[jobId];
|
|
178
|
+
_callback.callback(failedReason ? new Error(failedReason) : null, data);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
_queuePush(info, isAsync) {
|
|
182
|
+
const app = this.app;
|
|
183
|
+
// queue config
|
|
184
|
+
const fullKey = `${info.module}:${info.queueName}`;
|
|
185
|
+
const queueBase = app.meta.queues[fullKey];
|
|
186
|
+
if (!queueBase)
|
|
187
|
+
throw new Error(`queue config not found: ${fullKey}`);
|
|
188
|
+
const queueConfig = queueBase.config;
|
|
189
|
+
// queueConfig.options: queue/worker/job/limiter
|
|
190
|
+
const jobOptions = (queueConfig.options && queueConfig.options.job) || null;
|
|
191
|
+
// queue
|
|
192
|
+
const queue = this._getQueue(info);
|
|
193
|
+
// job
|
|
194
|
+
const jobId = (info.jobOptions && info.jobOptions.jobId) || uuid.v4();
|
|
195
|
+
const jobName = info.jobName || jobId;
|
|
196
|
+
const _jobOptions = Object.assign({}, jobOptions, info.jobOptions);
|
|
197
|
+
// not async
|
|
198
|
+
if (!isAsync) {
|
|
199
|
+
// add job
|
|
200
|
+
return queue.add(jobName, info, _jobOptions);
|
|
201
|
+
}
|
|
202
|
+
// async
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
// jobId
|
|
205
|
+
if (!_jobOptions.jobId) {
|
|
206
|
+
_jobOptions.jobId = jobId;
|
|
207
|
+
}
|
|
208
|
+
// callback
|
|
209
|
+
this._queueCallbacks[jobId] = {
|
|
210
|
+
info,
|
|
211
|
+
callback: (err, data) => {
|
|
212
|
+
if (err)
|
|
213
|
+
return reject(err);
|
|
214
|
+
resolve(data);
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
// add job
|
|
218
|
+
return queue.add(jobName, info, _jobOptions);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
_combineQueueKey({ subdomain, module = '', queueName = '' }) {
|
|
222
|
+
const app = this.app;
|
|
223
|
+
subdomain = app.meta.util.subdomainDesp(subdomain);
|
|
224
|
+
return `${subdomain}||${module}||${queueName}`;
|
|
225
|
+
}
|
|
226
|
+
async _performTask(job) {
|
|
227
|
+
const app = this.app;
|
|
228
|
+
let { locale, subdomain, module, queueName, queueNameSub, data, ctxParent, dbLevel } = job.data;
|
|
229
|
+
// ctxParent
|
|
230
|
+
if (!ctxParent)
|
|
231
|
+
ctxParent = {};
|
|
232
|
+
ctxParent.dbLevel = dbLevel - 1;
|
|
233
|
+
// context
|
|
234
|
+
const context = { job, data };
|
|
235
|
+
if (queueNameSub) {
|
|
236
|
+
context.queueNameSub = queueNameSub;
|
|
237
|
+
}
|
|
238
|
+
// queue config
|
|
239
|
+
const queue = app.meta.queues[`${module}:${queueName}`];
|
|
240
|
+
// bean
|
|
241
|
+
const bean = queue.bean;
|
|
242
|
+
// execute
|
|
243
|
+
return await app.meta.util.executeBean({
|
|
244
|
+
locale,
|
|
245
|
+
subdomain,
|
|
246
|
+
context,
|
|
247
|
+
beanModule: bean.module,
|
|
248
|
+
beanFullName: `${bean.module}.queue.${bean.name}`,
|
|
249
|
+
transaction: queue.config.transaction,
|
|
250
|
+
ctxParent,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
_getRepeatKey(name, repeat) {
|
|
254
|
+
const endDate = repeat.endDate ? new Date(repeat.endDate).getTime() : '';
|
|
255
|
+
const tz = repeat.tz || '';
|
|
256
|
+
const suffix = (repeat.cron ? repeat.cron : String(repeat.every)) || '';
|
|
257
|
+
const jobId = repeat.jobId ? repeat.jobId : '';
|
|
258
|
+
return `${name}:${jobId}:${endDate}:${tz}:${suffix}`;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.QueueClient = QueueClient;
|
|
262
|
+
//# sourceMappingURL=queueClient.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Bottleneck from 'bottleneck';
|
|
2
|
+
import { VonaApplication } from '../../types/index.js';
|
|
3
|
+
import { BeanSimple } from '../bean/beanSimple.js';
|
|
4
|
+
export declare class AppLimiter extends BeanSimple {
|
|
5
|
+
create(options: any): Bottleneck;
|
|
6
|
+
}
|
|
7
|
+
export declare class AppRedlock extends BeanSimple {
|
|
8
|
+
create(options: any): any;
|
|
9
|
+
}
|
|
10
|
+
export default function (app: VonaApplication): void;
|
|
11
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AppRedlock = exports.AppLimiter = void 0;
|
|
7
|
+
const bottleneck_1 = __importDefault(require("bottleneck"));
|
|
8
|
+
const redlock_1 = __importDefault(require("redlock"));
|
|
9
|
+
const beanSimple_js_1 = require("../bean/beanSimple.js");
|
|
10
|
+
class AppLimiter extends beanSimple_js_1.BeanSimple {
|
|
11
|
+
// https://github.com/SGrondin/bottleneck#clustering
|
|
12
|
+
create(options) {
|
|
13
|
+
options = options || {};
|
|
14
|
+
// datastore
|
|
15
|
+
options.datastore = 'ioredis';
|
|
16
|
+
// connection
|
|
17
|
+
if (options.connection === undefined) {
|
|
18
|
+
options.connection = new bottleneck_1.default.IORedisConnection({
|
|
19
|
+
client: this.app.redis.get('limiter'),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return new bottleneck_1.default(options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.AppLimiter = AppLimiter;
|
|
26
|
+
class AppRedlock extends beanSimple_js_1.BeanSimple {
|
|
27
|
+
// https://github.com/mike-marcacci/node-redlock#configuration
|
|
28
|
+
create(options) {
|
|
29
|
+
// clients
|
|
30
|
+
const clients = [];
|
|
31
|
+
for (const clientName of this.app.config.queue.redlock.clients) {
|
|
32
|
+
const client = this.app.redis.get(clientName) || this.app.redis.get('limiter');
|
|
33
|
+
clients.push(client);
|
|
34
|
+
}
|
|
35
|
+
return new redlock_1.default(clients, options);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.AppRedlock = AppRedlock;
|
|
39
|
+
function default_1(app) {
|
|
40
|
+
// limiter
|
|
41
|
+
app.meta.limiter = app.bean._newBean(AppLimiter);
|
|
42
|
+
// redlock
|
|
43
|
+
app.meta.redlock = app.bean._newBean(AppRedlock);
|
|
44
|
+
}
|
|
45
|
+
exports.default = default_1;
|
|
46
|
+
//# sourceMappingURL=redis.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
9
|
+
const debounce_1 = __importDefault(require("debounce"));
|
|
10
|
+
const process_helper_1 = require("@cabloy/process-helper");
|
|
11
|
+
const cast_js_1 = require("../../../types/utils/cast.js");
|
|
12
|
+
function default_1(app) {
|
|
13
|
+
let watcherDevelopment = null;
|
|
14
|
+
// only in development
|
|
15
|
+
if (app.meta.inAgent && app.meta.isLocal) {
|
|
16
|
+
_register();
|
|
17
|
+
}
|
|
18
|
+
// invoked in agent
|
|
19
|
+
function _register() {
|
|
20
|
+
// watchDirs
|
|
21
|
+
const watchDirs = _collectDevelopmentWatchDirs();
|
|
22
|
+
// close
|
|
23
|
+
if (watcherDevelopment) {
|
|
24
|
+
const _watcher = (0, cast_js_1.Cast)(watcherDevelopment);
|
|
25
|
+
if (!_watcher.__eb_closed) {
|
|
26
|
+
if (_watcher.__eb_ready) {
|
|
27
|
+
_watcher.close();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
_watcher.__eb_closing = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
watcherDevelopment = null;
|
|
34
|
+
}
|
|
35
|
+
// watcher
|
|
36
|
+
const _watcher = chokidar_1.default.watch(watchDirs).on('change', (0, debounce_1.default)(info => {
|
|
37
|
+
_developmentChange(info);
|
|
38
|
+
}, app.config.development.debounce));
|
|
39
|
+
// on ready
|
|
40
|
+
const _watcher2 = (0, cast_js_1.Cast)(_watcher);
|
|
41
|
+
_watcher.once('ready', function () {
|
|
42
|
+
_watcher2.__eb_ready = true;
|
|
43
|
+
if (_watcher2.__eb_closing) {
|
|
44
|
+
_watcher.close();
|
|
45
|
+
_watcher2.__eb_closed = true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// ok
|
|
49
|
+
watcherDevelopment = _watcher;
|
|
50
|
+
}
|
|
51
|
+
// invoked in agent
|
|
52
|
+
function _collectDevelopmentWatchDirs() {
|
|
53
|
+
const __pathes = [
|
|
54
|
+
'src/backend/config',
|
|
55
|
+
'src/backend/demo',
|
|
56
|
+
'src/module',
|
|
57
|
+
'src/module-vendor',
|
|
58
|
+
'src/suite',
|
|
59
|
+
'src/suite-vendor',
|
|
60
|
+
'packages-vona/vona',
|
|
61
|
+
];
|
|
62
|
+
const cwd = process.cwd();
|
|
63
|
+
const watchDirs = [];
|
|
64
|
+
for (const __path of __pathes) {
|
|
65
|
+
const pathDir = path_1.default.join(cwd, __path);
|
|
66
|
+
if (fs_extra_1.default.existsSync(pathDir)) {
|
|
67
|
+
watchDirs.push(pathDir);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return watchDirs;
|
|
71
|
+
// const pathSrc = path.resolve(this.app.config.baseDir, '..');
|
|
72
|
+
// let watchDirs = eggBornUtils.tools.globbySync(`${pathSrc}/**/backend/src`, { onlyDirectories: true });
|
|
73
|
+
// watchDirs = [path.join(pathSrc, 'backend/config')].concat(watchDirs);
|
|
74
|
+
// return watchDirs;
|
|
75
|
+
}
|
|
76
|
+
// invoked in agent
|
|
77
|
+
async function _developmentChange(info) {
|
|
78
|
+
info = info.replace(/\\/g, '/');
|
|
79
|
+
// extname
|
|
80
|
+
const extname = path_1.default.extname(info);
|
|
81
|
+
if (!['.ts', '.mts'].includes(extname))
|
|
82
|
+
return;
|
|
83
|
+
// log
|
|
84
|
+
app.logger.warn(`[agent:development] reload worker because ${info} changed`);
|
|
85
|
+
// tsc
|
|
86
|
+
if (extname !== '.mts') {
|
|
87
|
+
const __pathes = ['src/backend/config', 'src/backend/demo', 'packages-vona/vona'];
|
|
88
|
+
if (__pathes.some(item => info.indexOf(item) > -1)) {
|
|
89
|
+
const processHelper = new process_helper_1.ProcessHelper();
|
|
90
|
+
await processHelper.tsc();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// reload
|
|
94
|
+
app.meta.reload.now();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.default = default_1;
|
|
98
|
+
//# sourceMappingURL=development.js.map
|