vona 1.0.0 → 5.0.7
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 +21 -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 +516 -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 +18 -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/entity/type.d.ts +4 -0
- package/dist/lib/bean/resource/entity/type.js +3 -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 +14 -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 +68 -0
- package/dist/lib/core/meta.js +345 -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 +173 -0
- package/dist/lib/decorator/class/aop.d.ts +3 -0
- package/dist/lib/decorator/class/aop.js +22 -0
- package/dist/lib/decorator/class/atom.d.ts +2 -0
- package/dist/lib/decorator/class/atom.js +20 -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 +2 -0
- package/dist/lib/decorator/class/controller.js +20 -0
- package/dist/lib/decorator/class/entity.d.ts +4 -0
- package/dist/lib/decorator/class/entity.js +33 -0
- package/dist/lib/decorator/class/index.d.ts +11 -0
- package/dist/lib/decorator/class/index.js +27 -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 +21 -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 +2 -0
- package/dist/lib/decorator/class/service.js +20 -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 +44 -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 +24 -0
- package/dist/lib/framework/loader.js +69 -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 +135 -0
- package/dist/lib/module/moduleMeta.d.ts +3 -0
- package/dist/lib/module/moduleMeta.js +23 -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 +21 -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 +22 -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 +4 -0
- package/dist/types/utils/index.js +20 -0
- package/dist/types/utils/powerPartial.d.ts +4 -0
- package/dist/types/utils/powerPartial.js +3 -0
- package/dist/types/utils/type.d.ts +4 -0
- package/dist/types/utils/type.js +3 -0
- package/package.json +62 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present Vona
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vona
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# vona
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
const raw_body_1 = __importDefault(require("raw-body"));
|
|
30
|
+
const inflation_1 = __importDefault(require("inflation"));
|
|
31
|
+
const ModuleInfo = __importStar(require("@cabloy/module-info"));
|
|
32
|
+
const metaCtx_js_1 = require("../../lib/core/metaCtx.js");
|
|
33
|
+
const cast_js_1 = require("../../types/utils/cast.js");
|
|
34
|
+
const MODULE = Symbol.for('Context#__module');
|
|
35
|
+
const META = Symbol.for('Context#__meta');
|
|
36
|
+
const INNERACCESS = Symbol.for('Context#__inneraccess');
|
|
37
|
+
const SUBDOMAIN = Symbol.for('Context#__subdomain');
|
|
38
|
+
const CTXCALLER = Symbol.for('Context#__ctxcaller');
|
|
39
|
+
const TAILCALLBACKS = Symbol.for('Context#__tailcallbacks');
|
|
40
|
+
const DBLEVEL = Symbol.for('Context#__dblevel');
|
|
41
|
+
const context = {
|
|
42
|
+
get module() {
|
|
43
|
+
const self = (0, cast_js_1.Cast)(this);
|
|
44
|
+
if (this[MODULE] === undefined) {
|
|
45
|
+
const url = self.req.url || '';
|
|
46
|
+
let info;
|
|
47
|
+
if (url.indexOf('/api/static/public/') === 0) {
|
|
48
|
+
info = null;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
info = ModuleInfo.parseInfo(ModuleInfo.parseName(url));
|
|
52
|
+
}
|
|
53
|
+
if (!info) {
|
|
54
|
+
info = ModuleInfo.parseInfo('a-base');
|
|
55
|
+
}
|
|
56
|
+
if (info) {
|
|
57
|
+
const module = self.app.meta.modules[info.relativeName];
|
|
58
|
+
// should not throw error, because the url maybe not valid
|
|
59
|
+
// if (!module) throw new Error(`module not found: ${info.relativeName}`);
|
|
60
|
+
this[MODULE] = module || null;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this[MODULE] = null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return this[MODULE];
|
|
67
|
+
},
|
|
68
|
+
get meta() {
|
|
69
|
+
const self = (0, cast_js_1.Cast)(this);
|
|
70
|
+
if (!this[META]) {
|
|
71
|
+
this[META] = self.bean._newBean(metaCtx_js_1.CtxMeta);
|
|
72
|
+
}
|
|
73
|
+
return this[META];
|
|
74
|
+
},
|
|
75
|
+
get innerAccess() {
|
|
76
|
+
return this[INNERACCESS];
|
|
77
|
+
},
|
|
78
|
+
set innerAccess(value) {
|
|
79
|
+
this[INNERACCESS] = value;
|
|
80
|
+
},
|
|
81
|
+
get dbLevel() {
|
|
82
|
+
return this[DBLEVEL] || 0;
|
|
83
|
+
},
|
|
84
|
+
set dbLevel(value) {
|
|
85
|
+
this[DBLEVEL] = value;
|
|
86
|
+
},
|
|
87
|
+
get subdomain() {
|
|
88
|
+
const self = (0, cast_js_1.Cast)(this);
|
|
89
|
+
return typeof this[SUBDOMAIN] === 'undefined' ? self.subdomains.join('.') : this[SUBDOMAIN];
|
|
90
|
+
},
|
|
91
|
+
set subdomain(value) {
|
|
92
|
+
this[SUBDOMAIN] = value;
|
|
93
|
+
},
|
|
94
|
+
get ctxCaller() {
|
|
95
|
+
return this[CTXCALLER];
|
|
96
|
+
},
|
|
97
|
+
set ctxCaller(value) {
|
|
98
|
+
// ctxCaller
|
|
99
|
+
this[CTXCALLER] = value;
|
|
100
|
+
// innerAccess
|
|
101
|
+
this.innerAccess = true;
|
|
102
|
+
// transaction
|
|
103
|
+
(0, cast_js_1.Cast)(this).dbMeta = value.dbMeta;
|
|
104
|
+
// dbLevel
|
|
105
|
+
this.dbLevel = value.dbLevel;
|
|
106
|
+
},
|
|
107
|
+
get cache() {
|
|
108
|
+
const self = (0, cast_js_1.Cast)(this);
|
|
109
|
+
return self.bean._getBean('cache');
|
|
110
|
+
},
|
|
111
|
+
tail(cb) {
|
|
112
|
+
if (!(0, cast_js_1.Cast)(this).dbMeta.master) {
|
|
113
|
+
this.ctxCaller.tail(cb);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.tailCallbacks.push(cb);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async tailDone() {
|
|
120
|
+
while (true) {
|
|
121
|
+
const cb = this.tailCallbacks.shift();
|
|
122
|
+
if (!cb)
|
|
123
|
+
break;
|
|
124
|
+
await cb();
|
|
125
|
+
// try {
|
|
126
|
+
// await cb();
|
|
127
|
+
// } catch (err) {
|
|
128
|
+
// this.app.logger.error(err);
|
|
129
|
+
// }
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
get tailCallbacks() {
|
|
133
|
+
if (!this[TAILCALLBACKS]) {
|
|
134
|
+
this[TAILCALLBACKS] = [];
|
|
135
|
+
}
|
|
136
|
+
return this[TAILCALLBACKS];
|
|
137
|
+
},
|
|
138
|
+
successMore(list, index, size) {
|
|
139
|
+
const self = (0, cast_js_1.Cast)(this);
|
|
140
|
+
self.success({
|
|
141
|
+
list,
|
|
142
|
+
index: index + list.length,
|
|
143
|
+
finished: size === -1 || size === 0 || list.length < size,
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
async getPayload(options) {
|
|
147
|
+
const self = (0, cast_js_1.Cast)(this);
|
|
148
|
+
return await (0, raw_body_1.default)((0, inflation_1.default)(self.req), options);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
exports.default = context;
|
|
152
|
+
//# sourceMappingURL=context.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '@cabloy/set';
|
|
2
|
+
import '@cabloy/json5';
|
|
3
|
+
import 'regenerator-runtime';
|
|
4
|
+
export * from './types/index.js';
|
|
5
|
+
export * from './lib/bean/index.js';
|
|
6
|
+
export * from './lib/core/index.js';
|
|
7
|
+
export * from './lib/decorator/index.js';
|
|
8
|
+
export * from './lib/module/index.js';
|
|
9
|
+
export * from './lib/framework/framework.js';
|
|
10
|
+
export * from './lib/utils/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
require("@cabloy/set");
|
|
21
|
+
require("@cabloy/json5");
|
|
22
|
+
require("regenerator-runtime");
|
|
23
|
+
const module_alias_1 = __importDefault(require("module-alias"));
|
|
24
|
+
const cluster_reload_1 = __importDefault(require("@cabloy/cluster-reload"));
|
|
25
|
+
const master_js_1 = __importDefault(require("egg-cluster/lib/master.js"));
|
|
26
|
+
module_alias_1.default.addAlias('koa-static-cache', '@cabloy/koa-static-cache');
|
|
27
|
+
master_js_1.default.prototype.onReload = cluster_reload_1.default;
|
|
28
|
+
__exportStar(require("./types/index.js"), exports);
|
|
29
|
+
__exportStar(require("./lib/bean/index.js"), exports);
|
|
30
|
+
__exportStar(require("./lib/core/index.js"), exports);
|
|
31
|
+
__exportStar(require("./lib/decorator/index.js"), exports);
|
|
32
|
+
__exportStar(require("./lib/module/index.js"), exports);
|
|
33
|
+
__exportStar(require("./lib/framework/framework.js"), exports);
|
|
34
|
+
__exportStar(require("./lib/utils/index.js"), exports);
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CabloyContext } from '../../types/index.js';
|
|
2
|
+
export default class DbTransaction {
|
|
3
|
+
_ctx: CabloyContext;
|
|
4
|
+
_transactionCounter: number;
|
|
5
|
+
_connection: any;
|
|
6
|
+
constructor(ctx: any);
|
|
7
|
+
get inTransaction(): boolean;
|
|
8
|
+
get connection(): any;
|
|
9
|
+
set connection(value: any);
|
|
10
|
+
begin(fn: any): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=dbTransaction.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class DbTransaction {
|
|
4
|
+
constructor(ctx) {
|
|
5
|
+
this._ctx = ctx;
|
|
6
|
+
this._transactionCounter = 0;
|
|
7
|
+
this._connection = null;
|
|
8
|
+
}
|
|
9
|
+
get inTransaction() {
|
|
10
|
+
return this._transactionCounter > 0;
|
|
11
|
+
}
|
|
12
|
+
get connection() {
|
|
13
|
+
return this._connection;
|
|
14
|
+
}
|
|
15
|
+
set connection(value) {
|
|
16
|
+
this._connection = value;
|
|
17
|
+
}
|
|
18
|
+
async begin(fn) {
|
|
19
|
+
let res;
|
|
20
|
+
const db = this._ctx.meta.util.getDbOriginal();
|
|
21
|
+
try {
|
|
22
|
+
if (++this._transactionCounter === 1) {
|
|
23
|
+
this._connection = await db.beginTransaction();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
this._transactionCounter--;
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
res = await fn();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (--this._transactionCounter === 0) {
|
|
35
|
+
await this._connection.rollback();
|
|
36
|
+
this._connection = null;
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
if (--this._transactionCounter === 0) {
|
|
42
|
+
await this._connection.commit();
|
|
43
|
+
this._connection = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
await this._connection.rollback();
|
|
48
|
+
this._connection = null;
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = DbTransaction;
|
|
55
|
+
//# sourceMappingURL=dbTransaction.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BeanSimple } from '../bean/beanSimple.js';
|
|
2
|
+
export declare class ErrorClass extends BeanSimple {
|
|
3
|
+
ebErrors: any;
|
|
4
|
+
constructor(ebErrors: any);
|
|
5
|
+
success(module: any, data: any, code: any, ...args: any[]): void;
|
|
6
|
+
fail(module: any, code: any, ...args: any[]): void;
|
|
7
|
+
throw(module: any, code: any, ...args: any[]): void;
|
|
8
|
+
parseFail(module: any, code: any, ...args: any[]): any;
|
|
9
|
+
parseSuccess(module: any, code: any, ...args: any[]): {
|
|
10
|
+
code: any;
|
|
11
|
+
message: null;
|
|
12
|
+
};
|
|
13
|
+
parseCode(module: any, codeDefault: any, code: any, ...args: any[]): {
|
|
14
|
+
code: any;
|
|
15
|
+
message: null;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorClass = void 0;
|
|
4
|
+
const beanSimple_js_1 = require("../bean/beanSimple.js");
|
|
5
|
+
class ErrorClass extends beanSimple_js_1.BeanSimple {
|
|
6
|
+
constructor(ebErrors) {
|
|
7
|
+
super();
|
|
8
|
+
this.ebErrors = ebErrors;
|
|
9
|
+
}
|
|
10
|
+
// data,code/message,args
|
|
11
|
+
success(module, data, code, ...args) {
|
|
12
|
+
const body = this.parseSuccess(module, code, ...args);
|
|
13
|
+
this.ctx.response.status = 200;
|
|
14
|
+
this.ctx.response.type = 'application/json';
|
|
15
|
+
this.ctx.response.body = { code: 0, message: body.message, data };
|
|
16
|
+
}
|
|
17
|
+
// code/message,args
|
|
18
|
+
fail(module, code, ...args) {
|
|
19
|
+
const body = this.parseFail(module, code, ...args);
|
|
20
|
+
this.ctx.response.status = 200;
|
|
21
|
+
this.ctx.response.type = 'application/json';
|
|
22
|
+
this.ctx.response.body = { code: __combineErrorCode(module, body.code), message: body.message }; // body maybe Error
|
|
23
|
+
}
|
|
24
|
+
// code/message,args
|
|
25
|
+
throw(module, code, ...args) {
|
|
26
|
+
const body = this.parseFail(module, code, ...args);
|
|
27
|
+
const err = new Error();
|
|
28
|
+
err.code = __combineErrorCode(module, body.code);
|
|
29
|
+
err.message = body.message;
|
|
30
|
+
if (body.code < 500)
|
|
31
|
+
err.status = body.code;
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
// code/message,args
|
|
35
|
+
parseFail(module, code, ...args) {
|
|
36
|
+
if (typeof code === 'object')
|
|
37
|
+
return code;
|
|
38
|
+
return this.parseCode(module, 1, code, ...args);
|
|
39
|
+
}
|
|
40
|
+
// code/message,args
|
|
41
|
+
parseSuccess(module, code, ...args) {
|
|
42
|
+
return this.parseCode(module, 0, code, ...args);
|
|
43
|
+
}
|
|
44
|
+
// parseCode
|
|
45
|
+
parseCode(module, codeDefault, code, ...args) {
|
|
46
|
+
const ebError = this.ebErrors[module];
|
|
47
|
+
let message = null;
|
|
48
|
+
if (code === undefined || code === null || code === '') {
|
|
49
|
+
code = codeDefault;
|
|
50
|
+
}
|
|
51
|
+
else if (typeof code === 'string') {
|
|
52
|
+
message = this.ctx.text(code, ...args);
|
|
53
|
+
code = codeDefault;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
message = this.ctx.text(ebError[code], ...args);
|
|
57
|
+
}
|
|
58
|
+
if (!message) {
|
|
59
|
+
message = this.ctx.text(ebError[codeDefault]);
|
|
60
|
+
}
|
|
61
|
+
return { code, message };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ErrorClass = ErrorClass;
|
|
65
|
+
function __combineErrorCode(module, code) {
|
|
66
|
+
if (code <= 1000)
|
|
67
|
+
return code;
|
|
68
|
+
return module ? `${module}:${code}` : code;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BeanSimple } from '../bean/beanSimple.js';
|
|
2
|
+
export declare class Model extends BeanSimple {
|
|
3
|
+
table: string;
|
|
4
|
+
options: any;
|
|
5
|
+
constructor({ table, options }: {
|
|
6
|
+
table: any;
|
|
7
|
+
options?: {} | undefined;
|
|
8
|
+
});
|
|
9
|
+
get disableDeleted(): any;
|
|
10
|
+
get disableInstance(): any;
|
|
11
|
+
columns(tableName?: string): Promise<any>;
|
|
12
|
+
columnsClear(tableName: any): any;
|
|
13
|
+
columnsClearAll(): boolean;
|
|
14
|
+
prepareData(item: any): Promise<{}>;
|
|
15
|
+
default(data: any): Promise<any>;
|
|
16
|
+
_coerceTypeOfDefault(column: any): any;
|
|
17
|
+
create(data: any, ...args: any[]): Promise<any>;
|
|
18
|
+
write(data: any, ...args: any[]): Promise<any>;
|
|
19
|
+
_rowCheck(row: any): void;
|
|
20
|
+
_insertRowsCheck(rows: any): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1,253 @@
|
|
|
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.Model = void 0;
|
|
7
|
+
const is_type_of_1 = __importDefault(require("is-type-of"));
|
|
8
|
+
const beanSimple_js_1 = require("../bean/beanSimple.js");
|
|
9
|
+
let __columns = {};
|
|
10
|
+
class Model extends beanSimple_js_1.BeanSimple {
|
|
11
|
+
constructor({ table, options = {} }) {
|
|
12
|
+
super();
|
|
13
|
+
this.table = table;
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
get disableDeleted() {
|
|
17
|
+
return this.options.disableDeleted === undefined
|
|
18
|
+
? this.app.config.model.disableDeleted
|
|
19
|
+
: this.options.disableDeleted;
|
|
20
|
+
}
|
|
21
|
+
get disableInstance() {
|
|
22
|
+
return this.options.disableInstance === undefined
|
|
23
|
+
? this.app.config.model.disableInstance
|
|
24
|
+
: this.options.disableInstance;
|
|
25
|
+
}
|
|
26
|
+
async columns(tableName) {
|
|
27
|
+
tableName = tableName || this.table;
|
|
28
|
+
let columns = __columns[tableName];
|
|
29
|
+
if (!columns) {
|
|
30
|
+
const list = await this.ctx.db.query(`show columns from ${this.ctx.db.format('??', tableName)}`);
|
|
31
|
+
columns = __columns[tableName] = {};
|
|
32
|
+
for (const item of list) {
|
|
33
|
+
columns[item.Field] = item;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return columns;
|
|
37
|
+
}
|
|
38
|
+
columnsClear(tableName) {
|
|
39
|
+
tableName = tableName || this.table;
|
|
40
|
+
const exists = __columns[tableName];
|
|
41
|
+
delete __columns[tableName];
|
|
42
|
+
return exists;
|
|
43
|
+
}
|
|
44
|
+
columnsClearAll() {
|
|
45
|
+
const exists = Object.keys(__columns).length > 0;
|
|
46
|
+
__columns = {};
|
|
47
|
+
return exists;
|
|
48
|
+
}
|
|
49
|
+
async prepareData(item) {
|
|
50
|
+
// columns
|
|
51
|
+
const columns = await this.columns();
|
|
52
|
+
// data
|
|
53
|
+
const data = {};
|
|
54
|
+
for (const columnName in columns) {
|
|
55
|
+
if (item[columnName] !== undefined) {
|
|
56
|
+
data[columnName] = item[columnName];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
async default(data) {
|
|
62
|
+
data = data || {};
|
|
63
|
+
// columns
|
|
64
|
+
const columns = await this.columns();
|
|
65
|
+
for (const columnName in columns) {
|
|
66
|
+
const column = columns[columnName];
|
|
67
|
+
data[columnName] = this._coerceTypeOfDefault(column);
|
|
68
|
+
}
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
_coerceTypeOfDefault(column) {
|
|
72
|
+
// type
|
|
73
|
+
let type = column.Type;
|
|
74
|
+
const pos = type.indexOf('(');
|
|
75
|
+
if (pos > -1)
|
|
76
|
+
type = type.substring(0, pos);
|
|
77
|
+
// default value
|
|
78
|
+
const value = column.Default;
|
|
79
|
+
// coerce
|
|
80
|
+
if (value === null)
|
|
81
|
+
return value;
|
|
82
|
+
if (['timestamp'].includes(type) && value === 'CURRENT_TIMESTAMP')
|
|
83
|
+
return new Date();
|
|
84
|
+
if (['bit', 'bool'].includes(type))
|
|
85
|
+
return Boolean(value);
|
|
86
|
+
if (['float', 'double'].includes(type))
|
|
87
|
+
return Number(value);
|
|
88
|
+
if (['tinyint', 'smallint', 'mediumint', 'int', 'bigint'].includes(type))
|
|
89
|
+
return Number(value);
|
|
90
|
+
// others
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
async create(data, ...args) {
|
|
94
|
+
const data2 = await this.prepareData(data);
|
|
95
|
+
const res = await this.insert(data2, ...args);
|
|
96
|
+
return res.insertId;
|
|
97
|
+
}
|
|
98
|
+
async write(data, ...args) {
|
|
99
|
+
const data2 = await this.prepareData(data);
|
|
100
|
+
return await this.update(data2, ...args);
|
|
101
|
+
}
|
|
102
|
+
_rowCheck(row) {
|
|
103
|
+
if ((!this.table || !this.disableInstance) && row.iid === undefined) {
|
|
104
|
+
row.iid = this.ctx.instance.id;
|
|
105
|
+
}
|
|
106
|
+
if (this.table && !this.disableDeleted && row.deleted === undefined) {
|
|
107
|
+
row.deleted = 0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
_insertRowsCheck(rows) {
|
|
111
|
+
if (!Array.isArray(rows))
|
|
112
|
+
return this._rowCheck(rows);
|
|
113
|
+
for (const row of rows) {
|
|
114
|
+
this._rowCheck(row);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.Model = Model;
|
|
119
|
+
[
|
|
120
|
+
'literals', //
|
|
121
|
+
'escape',
|
|
122
|
+
'escapeId',
|
|
123
|
+
'format',
|
|
124
|
+
'_formatValue',
|
|
125
|
+
'_formatWhere',
|
|
126
|
+
'_where',
|
|
127
|
+
'_orders',
|
|
128
|
+
'raw',
|
|
129
|
+
'query',
|
|
130
|
+
'queryOne',
|
|
131
|
+
'_query',
|
|
132
|
+
'_selectColumns',
|
|
133
|
+
'_limit',
|
|
134
|
+
].forEach(method => {
|
|
135
|
+
Object.defineProperty(Model.prototype, method, {
|
|
136
|
+
get() {
|
|
137
|
+
if (is_type_of_1.default.function(this.ctx.db[method])) {
|
|
138
|
+
return function (...args) {
|
|
139
|
+
return this.ctx.db[method](...args);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// property
|
|
143
|
+
return this.ctx.db[method];
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
['insert'].forEach(method => {
|
|
148
|
+
Object.defineProperty(Model.prototype, method, {
|
|
149
|
+
get() {
|
|
150
|
+
return function (...args) {
|
|
151
|
+
if (args.length === 0) {
|
|
152
|
+
args.push({});
|
|
153
|
+
}
|
|
154
|
+
if (this.table) {
|
|
155
|
+
args.unshift(this.table);
|
|
156
|
+
}
|
|
157
|
+
this._insertRowsCheck(args[1]);
|
|
158
|
+
return this.ctx.db[method](...args);
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
['update'].forEach(method => {
|
|
164
|
+
Object.defineProperty(Model.prototype, method, {
|
|
165
|
+
get() {
|
|
166
|
+
return function (...args) {
|
|
167
|
+
const _args = [];
|
|
168
|
+
if (this.table)
|
|
169
|
+
_args.push(this.table);
|
|
170
|
+
for (const arg of args)
|
|
171
|
+
_args.push(arg);
|
|
172
|
+
if (_args[2] && _args[2].where) {
|
|
173
|
+
this._rowCheck(_args[2].where);
|
|
174
|
+
}
|
|
175
|
+
return this.ctx.db[method](..._args);
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
['delete'].forEach(method => {
|
|
181
|
+
Object.defineProperty(Model.prototype, method, {
|
|
182
|
+
get() {
|
|
183
|
+
return function (...args) {
|
|
184
|
+
const _args = [];
|
|
185
|
+
if (this.table)
|
|
186
|
+
_args.push(this.table);
|
|
187
|
+
for (const arg of args)
|
|
188
|
+
_args.push(arg);
|
|
189
|
+
_args[1] = _args[1] || {};
|
|
190
|
+
this._rowCheck(_args[1]);
|
|
191
|
+
if (this.table && !this.disableDeleted) {
|
|
192
|
+
const sql = this.ctx.db.format('UPDATE ?? SET deleted=1 ', [_args[0]]) + this.ctx.db._where(_args[1]);
|
|
193
|
+
return this.ctx.db.query(sql);
|
|
194
|
+
}
|
|
195
|
+
return this.ctx.db[method](..._args);
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
['count'].forEach(method => {
|
|
201
|
+
Object.defineProperty(Model.prototype, method, {
|
|
202
|
+
get() {
|
|
203
|
+
return function (...args) {
|
|
204
|
+
const _args = [];
|
|
205
|
+
if (this.table)
|
|
206
|
+
_args.push(this.table);
|
|
207
|
+
for (const arg of args)
|
|
208
|
+
_args.push(arg);
|
|
209
|
+
_args[1] = _args[1] || {};
|
|
210
|
+
this._rowCheck(_args[1]);
|
|
211
|
+
return this.ctx.db[method](..._args);
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
['get'].forEach(method => {
|
|
217
|
+
Object.defineProperty(Model.prototype, method, {
|
|
218
|
+
get() {
|
|
219
|
+
return function (...args) {
|
|
220
|
+
// console.log(this.constructor.name, arguments);
|
|
221
|
+
const _args = [];
|
|
222
|
+
if (this.table)
|
|
223
|
+
_args.push(this.table);
|
|
224
|
+
for (const arg of args)
|
|
225
|
+
_args.push(arg);
|
|
226
|
+
_args[1] = _args[1] || {};
|
|
227
|
+
// if (_args[1].id) {
|
|
228
|
+
// return this.ctx.db[method].apply(this.ctx.db, _args);
|
|
229
|
+
// }
|
|
230
|
+
this._rowCheck(_args[1]);
|
|
231
|
+
return this.ctx.db[method](..._args);
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
['select'].forEach(method => {
|
|
237
|
+
Object.defineProperty(Model.prototype, method, {
|
|
238
|
+
get() {
|
|
239
|
+
return function (...args) {
|
|
240
|
+
const _args = [];
|
|
241
|
+
if (this.table)
|
|
242
|
+
_args.push(this.table);
|
|
243
|
+
for (const arg of args)
|
|
244
|
+
_args.push(arg);
|
|
245
|
+
_args[1] = _args[1] || {};
|
|
246
|
+
_args[1].where = _args[1].where || {};
|
|
247
|
+
this._rowCheck(_args[1].where);
|
|
248
|
+
return this.ctx.db[method](..._args);
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
//# sourceMappingURL=model.js.map
|