oak-domain 5.0.12 → 5.0.14
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/base-app-domain/Path/Schema.d.ts +6 -0
- package/lib/base-app-domain/Path/Storage.js +6 -0
- package/lib/compiler/dependencyBuilder.js +31 -57
- package/lib/compiler/routerBuilder.js +1 -1
- package/lib/entities/Path.d.ts +1 -0
- package/lib/entities/Path.js +3 -2
- package/lib/types/Exception.d.ts +6 -0
- package/lib/types/Exception.js +7 -0
- package/lib/utils/row.d.ts +12 -0
- package/lib/utils/row.js +67 -0
- package/package.json +1 -1
- package/src/entities/Path.ts +4 -2
|
@@ -12,6 +12,7 @@ export type OpSchema = EntityShape & {
|
|
|
12
12
|
value: String<256>;
|
|
13
13
|
recursive: Boolean;
|
|
14
14
|
sourceEntity: String<32>;
|
|
15
|
+
desc?: String<256> | null;
|
|
15
16
|
};
|
|
16
17
|
export type OpAttr = keyof OpSchema;
|
|
17
18
|
export type Schema = EntityShape & {
|
|
@@ -19,6 +20,7 @@ export type Schema = EntityShape & {
|
|
|
19
20
|
value: String<256>;
|
|
20
21
|
recursive: Boolean;
|
|
21
22
|
sourceEntity: String<32>;
|
|
23
|
+
desc?: String<256> | null;
|
|
22
24
|
actionAuth$path?: Array<ActionAuth.Schema>;
|
|
23
25
|
actionAuth$path$$aggr?: AggregationResult<ActionAuth.Schema>;
|
|
24
26
|
relationAuth$path?: Array<RelationAuth.Schema>;
|
|
@@ -39,6 +41,7 @@ type AttrFilter = {
|
|
|
39
41
|
value: Q_StringValue;
|
|
40
42
|
recursive: Q_BooleanValue;
|
|
41
43
|
sourceEntity: Q_StringValue;
|
|
44
|
+
desc: Q_StringValue;
|
|
42
45
|
actionAuth$path: ActionAuth.Filter & SubQueryPredicateMetadata;
|
|
43
46
|
relationAuth$path: RelationAuth.Filter & SubQueryPredicateMetadata;
|
|
44
47
|
modiEntity$entity: ModiEntity.Filter & SubQueryPredicateMetadata;
|
|
@@ -56,6 +59,7 @@ export type Projection = {
|
|
|
56
59
|
value?: number;
|
|
57
60
|
recursive?: number;
|
|
58
61
|
sourceEntity?: number;
|
|
62
|
+
desc?: number;
|
|
59
63
|
actionAuth$path?: ActionAuth.Selection & {
|
|
60
64
|
$entity: "actionAuth";
|
|
61
65
|
};
|
|
@@ -100,6 +104,8 @@ export type SortAttr = {
|
|
|
100
104
|
recursive: number;
|
|
101
105
|
} | {
|
|
102
106
|
sourceEntity: number;
|
|
107
|
+
} | {
|
|
108
|
+
desc: number;
|
|
103
109
|
} | {
|
|
104
110
|
[k: string]: any;
|
|
105
111
|
} | OneOf<ExprOp<OpAttr | string>>;
|
|
@@ -96,11 +96,13 @@ function destructVariableDeclaration(vd) {
|
|
|
96
96
|
(0, assert_1.default)(ts.isIdentifier(vd.name));
|
|
97
97
|
(0, assert_1.default)(vd.name.text.startsWith('total'));
|
|
98
98
|
const on = (0, string_1.firstLetterLowerCase)(vd.name.text.slice(5));
|
|
99
|
-
const { initializer } = vd;
|
|
100
|
-
(0, assert_1.default)(ts.
|
|
101
|
-
|
|
102
|
-
(0, assert_1.default)(
|
|
103
|
-
|
|
99
|
+
const { initializer: nonNullExpression } = vd;
|
|
100
|
+
(0, assert_1.default)(ts.isNonNullExpression(nonNullExpression));
|
|
101
|
+
const { expression: callExpression } = nonNullExpression;
|
|
102
|
+
(0, assert_1.default)(ts.isCallExpression(callExpression));
|
|
103
|
+
(0, assert_1.default)(ts.isIdentifier(callExpression.expression) && callExpression.expression.text === 'mergeConcatMany');
|
|
104
|
+
(0, assert_1.default)(callExpression.arguments.length === 1);
|
|
105
|
+
const [arg] = callExpression.arguments;
|
|
104
106
|
(0, assert_1.default)(ts.isAsExpression(arg));
|
|
105
107
|
const { expression } = arg;
|
|
106
108
|
(0, assert_1.default)(ts.isArrayLiteralExpression(expression));
|
|
@@ -276,17 +278,17 @@ function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filenam
|
|
|
276
278
|
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
277
279
|
console.log(`构建${filename}文件成功`);
|
|
278
280
|
}
|
|
279
|
-
function
|
|
281
|
+
function outputContext(depGraph, sourceFile, printer, filename) {
|
|
280
282
|
// 目前只支持单向依赖,未来可以利用mixin来实现多类的继承
|
|
281
283
|
// assert(depGraph.roots.length <= 1);
|
|
282
284
|
let root = depGraph.ascOrder.length > 0 ? depGraph.ascOrder[depGraph.ascOrder.length - 1] : 'oak-frontend-base';
|
|
283
|
-
const statements =
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
const { statements } = sourceFile;
|
|
286
|
+
const isBackend = filename.includes('BackendRuntimeContext');
|
|
287
|
+
const statements2 = [
|
|
288
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(isBackend ? "BaseBackendRuntimeContext" : "BaseFrontendRuntimeContext"), undefined), factory.createStringLiteral(`${root}/es/context/${isBackend ? 'BackendRuntimeContext' : 'FrontendRuntimeContext'}`), undefined),
|
|
289
|
+
...statements
|
|
288
290
|
];
|
|
289
|
-
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(
|
|
291
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
290
292
|
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
291
293
|
console.log(`构建${filename}文件成功`);
|
|
292
294
|
}
|
|
@@ -480,17 +482,6 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
480
482
|
objectDict.common = [variableName];
|
|
481
483
|
}
|
|
482
484
|
}
|
|
483
|
-
// render
|
|
484
|
-
if ((0, fs_1.existsSync)(join(destDir, 'configuration', 'render.js'))) {
|
|
485
|
-
const variableName = `${briefNames[idx]}Render`;
|
|
486
|
-
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, factory.createIdentifier(variableName), undefined), factory.createStringLiteral(join(dep, destDirName, 'configuration', 'render')), undefined));
|
|
487
|
-
if (objectDict.render) {
|
|
488
|
-
objectDict.render.push(variableName);
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
objectDict.render = [variableName];
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
485
|
// features
|
|
495
486
|
if ((0, fs_1.existsSync)(join(destDir, 'features'))) {
|
|
496
487
|
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
|
|
@@ -689,20 +680,6 @@ function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, prin
|
|
|
689
680
|
factory.createTypeReferenceNode('EntityDict')
|
|
690
681
|
])))
|
|
691
682
|
});
|
|
692
|
-
Object.assign(funcStmt.body, {
|
|
693
|
-
statements: [
|
|
694
|
-
...features.map((ele, idx) => {
|
|
695
|
-
const args = [
|
|
696
|
-
factory.createIdentifier("features"),
|
|
697
|
-
];
|
|
698
|
-
if (dependencies[idx] === 'oak-general-business') {
|
|
699
|
-
args.push(factory.createIdentifier("accessConfiguration"));
|
|
700
|
-
}
|
|
701
|
-
return factory.createExpressionStatement(factory.createAwaitExpression(factory.createCallExpression(factory.createIdentifier(`initialize${(0, string_1.firstLetterUpperCase)(ele)}Features`), undefined, args)));
|
|
702
|
-
}).flat(),
|
|
703
|
-
...funcStmt.body.statements,
|
|
704
|
-
]
|
|
705
|
-
});
|
|
706
683
|
}
|
|
707
684
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
708
685
|
(0, fs_1.writeFileSync)(filename, result, { flag: 'w' });
|
|
@@ -778,18 +755,6 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer) {
|
|
|
778
755
|
const moduleDir = join(cwd, 'node_modules', dep);
|
|
779
756
|
const moduleTemplateDir = join(moduleDir, 'template');
|
|
780
757
|
if ((0, fs_1.existsSync)(moduleTemplateDir)) {
|
|
781
|
-
const entitiesDir = join(moduleTemplateDir, 'entities');
|
|
782
|
-
if ((0, fs_1.existsSync)(entitiesDir)) {
|
|
783
|
-
// entities目录下的定义直接拷贝过去(如果尚不存在的话)
|
|
784
|
-
const prjEntitiesDir = join(cwd, 'src', 'entities');
|
|
785
|
-
const result = (0, fs_1.readdirSync)(entitiesDir);
|
|
786
|
-
result.forEach((filename) => {
|
|
787
|
-
if (!(0, fs_1.existsSync)(join(prjEntitiesDir, filename))) {
|
|
788
|
-
console.log(`拷贝${join(entitiesDir, filename)}到${prjEntitiesDir}目录下`);
|
|
789
|
-
(0, fs_extra_1.copySync)(join(entitiesDir, filename), join(prjEntitiesDir, filename));
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
758
|
// data.ts中规定的初始化数据,拷贝到data目录下,并注入到data/index.ts
|
|
794
759
|
const dataFile = join(moduleTemplateDir, 'data', 'data.ts');
|
|
795
760
|
if ((0, fs_1.existsSync)(dataFile)) {
|
|
@@ -868,7 +833,9 @@ function buildDependency(rebuild) {
|
|
|
868
833
|
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'RuntimeCxt.ts'),
|
|
869
834
|
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'DependentExceptions.ts'),
|
|
870
835
|
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'polyfill.d.ts'),
|
|
871
|
-
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'features/index.ts')
|
|
836
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'features/index.ts'),
|
|
837
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'BackendRuntimeContext.ts'),
|
|
838
|
+
join(cwd, 'node_modules', env_1.OAK_CLI_MODULE_NAME, 'templateFiles', 'FrontendRuntimeContext.ts')
|
|
872
839
|
];
|
|
873
840
|
const program = ts.createProgram(templateFileList, {});
|
|
874
841
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
@@ -895,13 +862,6 @@ function buildDependency(rebuild) {
|
|
|
895
862
|
outputIntializeFeatures(cwd, dependencies, briefNames, program.getSourceFile(templateFileList[2]), printer, initFeaturesFile);
|
|
896
863
|
}
|
|
897
864
|
}
|
|
898
|
-
const dependentContextFile = join(cwd, 'src', 'context', 'DependentContext.ts');
|
|
899
|
-
if ((0, fs_1.existsSync)(dependentContextFile) && !rebuild) {
|
|
900
|
-
console.log(`[${dependentContextFile}]文件已经存在,无需构建启动文件`);
|
|
901
|
-
}
|
|
902
|
-
else {
|
|
903
|
-
outputDependentContext(depGraph, printer, dependentContextFile);
|
|
904
|
-
}
|
|
905
865
|
const runtimeCxtFile = join(cwd, 'src', 'types', 'RuntimeCxt.ts');
|
|
906
866
|
if ((0, fs_1.existsSync)(runtimeCxtFile) && !rebuild) {
|
|
907
867
|
console.log(`[${runtimeCxtFile}]文件已经存在,无需构建启动文件`);
|
|
@@ -930,6 +890,20 @@ function buildDependency(rebuild) {
|
|
|
930
890
|
else {
|
|
931
891
|
outputFeatureIndex(dependencies, briefNames, program.getSourceFile(templateFileList[6]), printer, featureIndexFile, isModule);
|
|
932
892
|
}
|
|
893
|
+
let contextFile = join(cwd, 'src', 'context', 'BackendRuntimeContext.ts');
|
|
894
|
+
if ((0, fs_1.existsSync)(contextFile) && !rebuild) {
|
|
895
|
+
console.log(`[${contextFile}]文件已经存在,无需构建启动文件`);
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
outputContext(depGraph, program.getSourceFile(templateFileList[7]), printer, contextFile);
|
|
899
|
+
}
|
|
900
|
+
contextFile = join(cwd, 'src', 'context', 'FrontendRuntimeContext.ts');
|
|
901
|
+
if ((0, fs_1.existsSync)(contextFile) && !rebuild) {
|
|
902
|
+
console.log(`[${contextFile}]文件已经存在,无需构建启动文件`);
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
outputContext(depGraph, program.getSourceFile(templateFileList[8]), printer, contextFile);
|
|
906
|
+
}
|
|
933
907
|
// 把各个依赖项目的一些初始化的文件拷贝过去
|
|
934
908
|
if (!isModule) {
|
|
935
909
|
tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer);
|
|
@@ -119,7 +119,7 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir) {
|
|
|
119
119
|
const children = Object.values(pages).filter((ele) => ele.hasWeb).map(({ path, oakDisablePulldownRefresh }) => {
|
|
120
120
|
const properties = [
|
|
121
121
|
factory.createPropertyAssignment('path', factory.createStringLiteral(path)),
|
|
122
|
-
factory.createPropertyAssignment('namespace', factory.createStringLiteral(
|
|
122
|
+
factory.createPropertyAssignment('namespace', factory.createStringLiteral(ns)),
|
|
123
123
|
factory.createPropertyAssignment('meta', factory.createObjectLiteralExpression([
|
|
124
124
|
factory.createPropertyAssignment('oakDisablePulldownRefresh', oakDisablePulldownRefresh ? factory.createTrue() : factory.createFalse())
|
|
125
125
|
])),
|
package/lib/entities/Path.d.ts
CHANGED
package/lib/entities/Path.js
CHANGED
package/lib/types/Exception.d.ts
CHANGED
|
@@ -8,8 +8,14 @@ export declare class OakException<ED extends EntityDict> extends Error {
|
|
|
8
8
|
name: string;
|
|
9
9
|
message: string;
|
|
10
10
|
opRecords: OpRecord<ED>[];
|
|
11
|
+
tag1: string | undefined;
|
|
12
|
+
tag2: boolean | undefined;
|
|
13
|
+
tag3: any;
|
|
11
14
|
};
|
|
12
15
|
toString(): string;
|
|
16
|
+
tag1?: string;
|
|
17
|
+
tag2?: boolean;
|
|
18
|
+
tag3?: any;
|
|
13
19
|
}
|
|
14
20
|
export declare class OakMakeSureByMySelfException<ED extends EntityDict> extends OakException<ED> {
|
|
15
21
|
}
|
package/lib/types/Exception.js
CHANGED
|
@@ -37,11 +37,18 @@ class OakException extends Error {
|
|
|
37
37
|
name: this.constructor.name,
|
|
38
38
|
message: this.message,
|
|
39
39
|
opRecords: this.opRecords,
|
|
40
|
+
tag1: this.tag1,
|
|
41
|
+
tag2: this.tag2,
|
|
42
|
+
tag3: this.tag3,
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
toString() {
|
|
43
46
|
return JSON.stringify(this.getSerialData());
|
|
44
47
|
}
|
|
48
|
+
// 留三个tag1供其它类使用
|
|
49
|
+
tag1;
|
|
50
|
+
tag2;
|
|
51
|
+
tag3;
|
|
45
52
|
}
|
|
46
53
|
exports.OakException = OakException;
|
|
47
54
|
// 这个异常表示模块自己处理跨事务一致性,框架pass(在分布式数据传递时会用到)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EntityDict } from '../types/Entity';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
|
+
import { StorageSchema } from '../types';
|
|
4
|
+
export declare function compareRow<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, row1: Partial<ED[T]['Schema']>, row2: Partial<ED[T]['Schema']>): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* 比较两行数据是否完全相等
|
|
7
|
+
* @param entity
|
|
8
|
+
* @param schema
|
|
9
|
+
* @param row1
|
|
10
|
+
* @param row2
|
|
11
|
+
*/
|
|
12
|
+
export declare function compareRows<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, rows1: Partial<ED[T]['Schema']>[], rows2: Partial<ED[T]['Schema']>[]): boolean;
|
package/lib/utils/row.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareRows = exports.compareRow = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = require("./lodash");
|
|
6
|
+
const relation_1 = require("../store/relation");
|
|
7
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
|
+
function compareRow(schema, entity, row1, row2) {
|
|
9
|
+
const attrs1 = Object.keys(row1).filter(ele => !ele.startsWith('$$'));
|
|
10
|
+
const attrs2 = Object.keys(row2).filter(ele => !ele.startsWith('$$'));
|
|
11
|
+
if ((0, lodash_1.difference)(attrs1, attrs2).length > 0) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
for (const attr of attrs1) {
|
|
15
|
+
const rel = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
16
|
+
if (rel === 0) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
else if (rel === 1) {
|
|
20
|
+
if (row1[attr] !== row2[attr]) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (rel === 2) {
|
|
25
|
+
if (!compareRow(schema, attr, row1[attr], row2[attr])) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (typeof rel === 'string') {
|
|
30
|
+
if (!compareRow(schema, rel, row1[attr], row2[attr])) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
(0, assert_1.default)(rel instanceof Array);
|
|
36
|
+
// 如果两组对象一样但顺序不一样怎么办?暂时应该不用考虑这种情况,因为只有前台runningTree使用(by Xc)
|
|
37
|
+
if (!compareRows(schema, rel[0], row1[attr], row2[attr])) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
exports.compareRow = compareRow;
|
|
45
|
+
/**
|
|
46
|
+
* 比较两行数据是否完全相等
|
|
47
|
+
* @param entity
|
|
48
|
+
* @param schema
|
|
49
|
+
* @param row1
|
|
50
|
+
* @param row2
|
|
51
|
+
*/
|
|
52
|
+
function compareRows(schema, entity, rows1, rows2) {
|
|
53
|
+
if (rows1.length !== rows2.length) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
let idx = 0;
|
|
57
|
+
while (idx < rows1.length) {
|
|
58
|
+
const row1 = rows1[idx];
|
|
59
|
+
const row2 = rows2[idx];
|
|
60
|
+
if (!compareRow(schema, entity, row1, row2)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
idx++;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
exports.compareRows = compareRows;
|
package/package.json
CHANGED
package/src/entities/Path.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface Schema extends EntityShape {
|
|
|
7
7
|
value: String<256>;
|
|
8
8
|
recursive: Boolean;
|
|
9
9
|
sourceEntity: String<32>;
|
|
10
|
+
desc?: String<256>;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
const entityDesc: EntityDesc<Schema> = {
|
|
@@ -34,9 +35,10 @@ const entityDesc: EntityDesc<Schema> = {
|
|
|
34
35
|
name: '关系路径',
|
|
35
36
|
attr: {
|
|
36
37
|
sourceEntity: '源对象',
|
|
37
|
-
value: '
|
|
38
|
+
value: '路径',
|
|
38
39
|
destEntity: '目标对象',
|
|
39
|
-
recursive: '
|
|
40
|
+
recursive: '是否递归',
|
|
41
|
+
desc: '描述',
|
|
40
42
|
},
|
|
41
43
|
},
|
|
42
44
|
},
|