oak-backend-base 4.1.20 → 4.1.21
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/lib/AppLoader.js +11 -16
- package/lib/DbStore.d.ts +1 -0
- package/lib/DbStore.js +3 -0
- package/lib/routines/i18n.d.ts +15 -0
- package/lib/routines/i18n.js +78 -0
- package/lib/utils/requirePrj.d.ts +1 -0
- package/lib/utils/requirePrj.js +23 -0
- package/package.json +3 -3
package/lib/AppLoader.js
CHANGED
|
@@ -17,6 +17,7 @@ const DataSubscriber_1 = tslib_1.__importDefault(require("./cluster/DataSubscrib
|
|
|
17
17
|
const env_1 = require("./cluster/env");
|
|
18
18
|
const Synchronizer_1 = tslib_1.__importDefault(require("./Synchronizer"));
|
|
19
19
|
const i18n_1 = tslib_1.__importDefault(require("oak-domain/lib/data/i18n"));
|
|
20
|
+
const requirePrj_1 = tslib_1.__importDefault(require("./utils/requirePrj"));
|
|
20
21
|
class AppLoader extends types_1.AppLoader {
|
|
21
22
|
dbStore;
|
|
22
23
|
aspectDict;
|
|
@@ -28,21 +29,7 @@ class AppLoader extends types_1.AppLoader {
|
|
|
28
29
|
watcherTimerId;
|
|
29
30
|
scheduledJobs = {};
|
|
30
31
|
requireSth(filePath) {
|
|
31
|
-
|
|
32
|
-
let sth;
|
|
33
|
-
if ((0, fs_1.existsSync)(`${depFilePath}.js`)) {
|
|
34
|
-
sth = require((0, path_1.join)(this.path, filePath)).default;
|
|
35
|
-
}
|
|
36
|
-
const sthExternal = this.externalDependencies.map(ele => {
|
|
37
|
-
const depFilePath = (0, path_1.join)(this.path, 'node_modules', ele, filePath);
|
|
38
|
-
if ((0, fs_1.existsSync)(`${depFilePath}.js`)) {
|
|
39
|
-
return require(depFilePath).default;
|
|
40
|
-
}
|
|
41
|
-
}).filter(ele => !!ele);
|
|
42
|
-
if (sth) {
|
|
43
|
-
sthExternal.push(sth);
|
|
44
|
-
}
|
|
45
|
-
return (0, lodash_1.mergeConcatMany)(sthExternal);
|
|
32
|
+
return (0, requirePrj_1.default)(this.path, filePath, this.externalDependencies);
|
|
46
33
|
}
|
|
47
34
|
async makeContext(cxtStr, headers) {
|
|
48
35
|
const context = this.contextBuilder(this.dbStore);
|
|
@@ -506,7 +493,15 @@ class AppLoader extends types_1.AppLoader {
|
|
|
506
493
|
}
|
|
507
494
|
async execRoutine(routine) {
|
|
508
495
|
const context = await this.makeContext();
|
|
509
|
-
|
|
496
|
+
try {
|
|
497
|
+
const result = await routine(context);
|
|
498
|
+
await context.commit();
|
|
499
|
+
return result;
|
|
500
|
+
}
|
|
501
|
+
catch (e) {
|
|
502
|
+
await context.rollback();
|
|
503
|
+
throw e;
|
|
504
|
+
}
|
|
510
505
|
}
|
|
511
506
|
}
|
|
512
507
|
exports.AppLoader = AppLoader;
|
package/lib/DbStore.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare class DbStore<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|
|
8
8
|
private executor;
|
|
9
9
|
private relationAuth;
|
|
10
10
|
constructor(storageSchema: StorageSchema<ED>, contextBuilder: () => Cxt, mysqlConfiguration: MySQLConfiguration, authDeduceRelationMap: AuthDeduceRelationMap<ED>, selectFreeEntities?: SelectFreeEntities<ED>, updateFreeDict?: UpdateFreeDict<ED>, onVolatileTrigger?: <T extends keyof ED>(entity: T, trigger: VolatileTrigger<ED, T, Cxt>, ids: string[], cxtStr: string, option: OperateOption) => Promise<void>);
|
|
11
|
+
checkRelationAsync<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, operation: Omit<ED[T]["Operation"] | ED[T]["Selection"], "id">, context: Cxt): Promise<void>;
|
|
11
12
|
protected cascadeUpdateAsync<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
|
12
13
|
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: MysqlOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
|
13
14
|
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: MySqlSelectOption): Promise<Partial<ED[T]["Schema"]>[]>;
|
package/lib/DbStore.js
CHANGED
|
@@ -12,6 +12,9 @@ class DbStore extends oak_db_1.MysqlStore {
|
|
|
12
12
|
this.executor = new TriggerExecutor_1.TriggerExecutor(contextBuilder, undefined, onVolatileTrigger);
|
|
13
13
|
this.relationAuth = new RelationAuth_1.RelationAuth(storageSchema, authDeduceRelationMap, selectFreeEntities, updateFreeDict);
|
|
14
14
|
}
|
|
15
|
+
checkRelationAsync(entity, operation, context) {
|
|
16
|
+
return this.relationAuth.checkRelationAsync(entity, operation, context);
|
|
17
|
+
}
|
|
15
18
|
async cascadeUpdateAsync(entity, operation, context, option) {
|
|
16
19
|
// 如果是在modi处理过程中,所有的trigger也可以延时到apply时再处理(这时候因为modi中的数据并不实际存在,处理会有问题)
|
|
17
20
|
if (!option.blockTrigger) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EntityDict } from 'oak-domain/lib/types';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
|
3
|
+
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
|
4
|
+
/**
|
|
5
|
+
* 检查项目目录下的i18n数据和数据库中的差异
|
|
6
|
+
* @param context
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkI18n<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(context: Cxt): Promise<(void | Awaited<import("oak-domain/lib/types").OperationResult<ED>>)[]>;
|
|
10
|
+
/**
|
|
11
|
+
* 检查项目目录下的i18n数据和数据库中的差异,并更新
|
|
12
|
+
* @param context
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkAndUpdateI18n<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(context: Cxt): Promise<(void | Awaited<import("oak-domain/lib/types").OperationResult<ED>>)[]>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkAndUpdateI18n = exports.checkI18n = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const requirePrj_1 = tslib_1.__importDefault(require("../utils/requirePrj"));
|
|
7
|
+
const dependencyBuilder_1 = require("oak-domain/lib/compiler/dependencyBuilder");
|
|
8
|
+
const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
11
|
+
async function checkAndUpdateI18nInner(context, onlyCheck) {
|
|
12
|
+
const pwd = process.cwd();
|
|
13
|
+
const i18nData = (0, requirePrj_1.default)(pwd, (0, node_path_1.join)('lib', 'data', 'i18n'), (0, dependencyBuilder_1.analyzeDepedency)(pwd).ascOrder);
|
|
14
|
+
const originI18nData = await context.select('i18n', {
|
|
15
|
+
data: {
|
|
16
|
+
id: 1,
|
|
17
|
+
namespace: 1,
|
|
18
|
+
language: 1,
|
|
19
|
+
module: 1,
|
|
20
|
+
position: 1,
|
|
21
|
+
data: 1,
|
|
22
|
+
},
|
|
23
|
+
}, { dontCollect: true });
|
|
24
|
+
const originDataDict = {};
|
|
25
|
+
originI18nData.forEach((data) => originDataDict[data.id] = data);
|
|
26
|
+
const result = i18nData.map(async (i18n) => {
|
|
27
|
+
const { id, namespace, language, module, position, data } = i18n;
|
|
28
|
+
const origin = originDataDict[id];
|
|
29
|
+
if (origin) {
|
|
30
|
+
(0, node_assert_1.default)(namespace === origin.namespace && language === origin.language && module === origin.module && position === origin.position);
|
|
31
|
+
if (!(0, lodash_1.isEqual)(data, origin.data)) {
|
|
32
|
+
console.log(`[${namespace}]数据${onlyCheck ? '需要更新' : '将被更新'}`);
|
|
33
|
+
if (!onlyCheck) {
|
|
34
|
+
return context.operate('i18n', {
|
|
35
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
36
|
+
action: 'update',
|
|
37
|
+
data: {
|
|
38
|
+
data,
|
|
39
|
+
},
|
|
40
|
+
filter: {
|
|
41
|
+
id,
|
|
42
|
+
},
|
|
43
|
+
}, {});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(`[${namespace}]数据${onlyCheck ? '需要新建' : '将被新建'}`);
|
|
49
|
+
if (!onlyCheck) {
|
|
50
|
+
return context.operate('i18n', {
|
|
51
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
52
|
+
action: 'create',
|
|
53
|
+
data: i18n,
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
});
|
|
59
|
+
return await Promise.all(result);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 检查项目目录下的i18n数据和数据库中的差异
|
|
63
|
+
* @param context
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
function checkI18n(context) {
|
|
67
|
+
return checkAndUpdateI18nInner(context, true);
|
|
68
|
+
}
|
|
69
|
+
exports.checkI18n = checkI18n;
|
|
70
|
+
/**
|
|
71
|
+
* 检查项目目录下的i18n数据和数据库中的差异,并更新
|
|
72
|
+
* @param context
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
function checkAndUpdateI18n(context) {
|
|
76
|
+
return checkAndUpdateI18nInner(context);
|
|
77
|
+
}
|
|
78
|
+
exports.checkAndUpdateI18n = checkAndUpdateI18n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function requireSth(prjPath: string, filePath: string, dependencies: string[]): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("fs");
|
|
4
|
+
const lodash_1 = require("oak-domain/lib/utils/lodash");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
function requireSth(prjPath, filePath, dependencies) {
|
|
7
|
+
const depFilePath = (0, path_1.join)(prjPath, filePath);
|
|
8
|
+
let sth;
|
|
9
|
+
if ((0, fs_1.existsSync)(`${depFilePath}.js`)) {
|
|
10
|
+
sth = require((0, path_1.join)(prjPath, filePath)).default;
|
|
11
|
+
}
|
|
12
|
+
const sthExternal = dependencies.map(ele => {
|
|
13
|
+
const depFilePath = (0, path_1.join)(prjPath, 'node_modules', ele, filePath);
|
|
14
|
+
if ((0, fs_1.existsSync)(`${depFilePath}.js`)) {
|
|
15
|
+
return require(depFilePath).default;
|
|
16
|
+
}
|
|
17
|
+
}).filter(ele => !!ele);
|
|
18
|
+
if (sth) {
|
|
19
|
+
sthExternal.push(sth);
|
|
20
|
+
}
|
|
21
|
+
return (0, lodash_1.mergeConcatMany)(sthExternal);
|
|
22
|
+
}
|
|
23
|
+
exports.default = requireSth;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-backend-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.21",
|
|
4
4
|
"description": "oak-backend-base",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"node-schedule": "^2.1.0",
|
|
24
24
|
"oak-common-aspect": "^3.0.5",
|
|
25
25
|
"oak-db": "^3.3.8",
|
|
26
|
-
"oak-domain": "^5.1.
|
|
27
|
-
"oak-frontend-base": "^5.3.
|
|
26
|
+
"oak-domain": "^5.1.27",
|
|
27
|
+
"oak-frontend-base": "^5.3.34",
|
|
28
28
|
"socket.io": "^4.8.1",
|
|
29
29
|
"socket.io-client": "^4.7.2",
|
|
30
30
|
"uuid": "^8.3.2"
|