oak-domain 2.6.10 → 3.0.0

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.
Files changed (122) hide show
  1. package/lib/actions/action.d.ts +1 -1
  2. package/lib/actions/action.js +2 -2
  3. package/lib/base-app-domain/ActionAuth/Schema.d.ts +25 -21
  4. package/lib/base-app-domain/ActionAuth/Storage.js +6 -13
  5. package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
  6. package/lib/base-app-domain/ActionDefDict.js +3 -1
  7. package/lib/base-app-domain/EntityDict.d.ts +2 -0
  8. package/lib/base-app-domain/I18n/Schema.d.ts +129 -0
  9. package/lib/base-app-domain/I18n/Schema.js +2 -0
  10. package/lib/base-app-domain/I18n/Storage.d.ts +3 -0
  11. package/lib/base-app-domain/I18n/Storage.js +59 -0
  12. package/lib/base-app-domain/Modi/Action.d.ts +1 -1
  13. package/lib/base-app-domain/Modi/Schema.d.ts +10 -9
  14. package/lib/base-app-domain/ModiEntity/Schema.d.ts +42 -28
  15. package/lib/base-app-domain/ModiEntity/Storage.js +1 -1
  16. package/lib/base-app-domain/Oper/Schema.d.ts +15 -13
  17. package/lib/base-app-domain/OperEntity/Schema.d.ts +41 -27
  18. package/lib/base-app-domain/OperEntity/Storage.js +1 -1
  19. package/lib/base-app-domain/Relation/Schema.d.ts +50 -22
  20. package/lib/base-app-domain/Relation/Storage.js +1 -4
  21. package/lib/base-app-domain/Relation.d.ts +10 -0
  22. package/lib/base-app-domain/Relation.js +10 -0
  23. package/lib/base-app-domain/RelationAuth/Schema.d.ts +67 -43
  24. package/lib/base-app-domain/RelationAuth/Storage.js +9 -12
  25. package/lib/base-app-domain/Storage.js +20 -18
  26. package/lib/base-app-domain/User/Action.d.ts +1 -1
  27. package/lib/base-app-domain/User/Schema.d.ts +20 -14
  28. package/lib/base-app-domain/User/Storage.js +1 -2
  29. package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -0
  30. package/lib/base-app-domain/UserEntityGrant/Action.js +5 -0
  31. package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +53 -17
  32. package/lib/base-app-domain/UserEntityGrant/Storage.js +5 -7
  33. package/lib/base-app-domain/UserRelation/Schema.d.ts +35 -16
  34. package/lib/base-app-domain/UserRelation/Storage.js +21 -1
  35. package/lib/base-app-domain/_SubQuery.d.ts +40 -4
  36. package/lib/base-app-domain/index.d.ts +1 -0
  37. package/lib/base-app-domain/index.js +1 -0
  38. package/lib/checkers/index.d.ts +2 -2
  39. package/lib/checkers/index.js +2 -5
  40. package/lib/compiler/env.d.ts +3 -1
  41. package/lib/compiler/env.js +12 -2
  42. package/lib/compiler/localeBuilder.d.ts +22 -0
  43. package/lib/compiler/localeBuilder.js +169 -0
  44. package/lib/compiler/schemalBuilder.d.ts +9 -0
  45. package/lib/compiler/schemalBuilder.js +774 -362
  46. package/lib/entities/ActionAuth.d.ts +3 -2
  47. package/lib/entities/ActionAuth.js +21 -22
  48. package/lib/entities/I18n.d.ts +9 -0
  49. package/lib/entities/I18n.js +37 -0
  50. package/lib/entities/Modi.js +35 -33
  51. package/lib/entities/ModiEntity.js +12 -10
  52. package/lib/entities/Oper.js +15 -13
  53. package/lib/entities/OperEntity.js +12 -10
  54. package/lib/entities/Relation.d.ts +3 -3
  55. package/lib/entities/Relation.js +27 -25
  56. package/lib/entities/RelationAuth.d.ts +2 -5
  57. package/lib/entities/RelationAuth.js +27 -23
  58. package/lib/entities/User.js +20 -18
  59. package/lib/entities/UserEntityGrant.d.ts +2 -1
  60. package/lib/entities/UserEntityGrant.js +12 -7
  61. package/lib/entities/UserRelation.d.ts +3 -0
  62. package/lib/entities/UserRelation.js +30 -20
  63. package/lib/store/AsyncRowStore.d.ts +3 -0
  64. package/lib/store/AsyncRowStore.js +3 -0
  65. package/lib/store/CascadeStore.d.ts +9 -3
  66. package/lib/store/CascadeStore.js +247 -113
  67. package/lib/store/RelationAuth.d.ts +96 -0
  68. package/lib/store/RelationAuth.js +1307 -0
  69. package/lib/store/TriggerExecutor.d.ts +1 -2
  70. package/lib/store/TriggerExecutor.js +22 -22
  71. package/lib/store/actionAuth.d.ts +4 -0
  72. package/lib/store/actionAuth.js +40 -0
  73. package/lib/store/actionDef.d.ts +4 -3
  74. package/lib/store/actionDef.js +14 -10
  75. package/lib/store/checker.d.ts +2 -9
  76. package/lib/store/checker.js +39 -815
  77. package/lib/store/filter.d.ts +31 -18
  78. package/lib/store/filter.js +1256 -422
  79. package/lib/store/modi.d.ts +1 -1
  80. package/lib/store/modi.js +108 -9
  81. package/lib/store/relation.d.ts +3 -4
  82. package/lib/timers/oper.js +1 -1
  83. package/lib/timers/vaccum.js +2 -2
  84. package/lib/triggers/index.d.ts +2 -3
  85. package/lib/triggers/index.js +2 -5
  86. package/lib/types/Auth.d.ts +5 -0
  87. package/lib/types/DataType.d.ts +3 -0
  88. package/lib/types/Demand.d.ts +11 -0
  89. package/lib/types/Demand.js +2 -1
  90. package/lib/types/Entity.d.ts +10 -3
  91. package/lib/types/EntityDesc.d.ts +8 -0
  92. package/lib/types/EntityDesc.js +2 -0
  93. package/lib/types/Environment.d.ts +57 -0
  94. package/lib/types/Environment.js +2 -0
  95. package/lib/types/Exception.d.ts +6 -0
  96. package/lib/types/Exception.js +25 -1
  97. package/lib/types/Logger.d.ts +1 -0
  98. package/lib/types/RowStore.d.ts +6 -4
  99. package/lib/types/Style.d.ts +1 -1
  100. package/lib/types/Trigger.d.ts +4 -5
  101. package/lib/types/Trigger.js +11 -6
  102. package/lib/types/index.d.ts +2 -0
  103. package/lib/types/index.js +2 -0
  104. package/lib/utils/SimpleConnector.js +1 -1
  105. package/lib/utils/string.d.ts +6 -0
  106. package/lib/utils/string.js +13 -1
  107. package/lib/utils/uuid.d.ts +5 -0
  108. package/lib/utils/uuid.js +64 -1
  109. package/package.json +3 -3
  110. package/src/entities/ActionAuth.ts +25 -33
  111. package/src/entities/I18n.ts +46 -0
  112. package/src/entities/Modi.ts +36 -36
  113. package/src/entities/ModiEntity.ts +14 -13
  114. package/src/entities/Oper.ts +17 -16
  115. package/src/entities/OperEntity.ts +13 -11
  116. package/src/entities/Relation.ts +31 -37
  117. package/src/entities/RelationAuth.ts +31 -37
  118. package/src/entities/User.ts +24 -21
  119. package/src/entities/UserEntityGrant.ts +16 -14
  120. package/src/entities/UserRelation.ts +33 -27
  121. package/lib/triggers/modi.d.ts +0 -5
  122. package/lib/triggers/modi.js +0 -72
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var assert_1 = tslib_1.__importDefault(require("assert"));
5
+ var ts = tslib_1.__importStar(require("typescript"));
6
+ var factory = ts.factory;
7
+ var path_1 = require("path");
8
+ var crypto_1 = require("crypto");
9
+ var fs_1 = tslib_1.__importDefault(require("fs"));
10
+ var env_1 = require("./env");
11
+ var string_1 = require("../utils/string");
12
+ /**
13
+ * 将一个object展开编译为一棵语法树,只有string和object两种键值对象
14
+ * @param data
15
+ */
16
+ function transferObjectToObjectLiteral(data) {
17
+ return factory.createObjectLiteralExpression(Object.keys(data).map(function (k) {
18
+ var type = typeof data[k];
19
+ if (type === 'string') {
20
+ return factory.createPropertyAssignment(factory.createStringLiteral(k), factory.createStringLiteral(data[k]));
21
+ }
22
+ (0, assert_1.default)(type === 'object');
23
+ return factory.createPropertyAssignment(factory.createStringLiteral(k), transferObjectToObjectLiteral(data[k]));
24
+ }), true);
25
+ }
26
+ /**
27
+ * 这个类的作用是把项目和所有相关的模块下的locales编译成为src/data/i18n中的数据
28
+ */
29
+ var LocaleBuilder = /** @class */ (function () {
30
+ function LocaleBuilder(asLib) {
31
+ var pwd = process.cwd();
32
+ this.pwd = pwd;
33
+ this.asLib = !!asLib;
34
+ var dependencyFile = (0, env_1.OAK_EXTERNAL_LIBS_FILEPATH)((0, path_1.join)(pwd, 'src'));
35
+ if (fs_1.default.existsSync(dependencyFile)) {
36
+ this.dependencies = require(dependencyFile);
37
+ }
38
+ else {
39
+ this.dependencies = [];
40
+ }
41
+ this.locales = {};
42
+ this.hash = (0, crypto_1.createHash)('md5');
43
+ }
44
+ /**
45
+ * 将locales输出成为data/i18n.ts中的数据
46
+ * 如果有Dependency需要引出来
47
+ */
48
+ LocaleBuilder.prototype.outputDataFile = function () {
49
+ var _this = this;
50
+ var statements = [
51
+ factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, factory.createIdentifier("CreateOperationData"), factory.createIdentifier("I18n"))])), factory.createStringLiteral("../oak-app-domain/I18n/Schema"), undefined)
52
+ ];
53
+ if (this.dependencies) {
54
+ this.dependencies.forEach(function (ele, idx) { return statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, factory.createIdentifier("i18ns".concat(idx)), undefined), factory.createStringLiteral("".concat(ele, "/lib/data/i18n")), undefined)); });
55
+ }
56
+ statements.push(factory.createVariableStatement(undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("i18ns"), undefined, factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier("I18n"), undefined)), factory.createArrayLiteralExpression(Object.keys(this.locales).map(function (k) {
57
+ var _a = tslib_1.__read(_this.locales[k], 4), module = _a[0], position = _a[1], language = _a[2], data = _a[3];
58
+ // 用哈希计算来保证id唯一性
59
+ var h = _this.hash.copy();
60
+ h.update("".concat(k, "-").concat(language));
61
+ var id = h.digest('hex');
62
+ (0, assert_1.default)(id.length <= 36);
63
+ return factory.createObjectLiteralExpression([
64
+ factory.createPropertyAssignment(factory.createIdentifier("id"), factory.createStringLiteral(id)),
65
+ factory.createPropertyAssignment(factory.createIdentifier("namespace"), factory.createStringLiteral(k)),
66
+ factory.createPropertyAssignment(factory.createIdentifier("language"), factory.createStringLiteral(language)),
67
+ factory.createPropertyAssignment(factory.createIdentifier("module"), factory.createStringLiteral(module)),
68
+ factory.createPropertyAssignment(factory.createIdentifier("position"), factory.createStringLiteral(position)),
69
+ factory.createPropertyAssignment(factory.createIdentifier("data"), transferObjectToObjectLiteral(data))
70
+ ], true);
71
+ }), true))], ts.NodeFlags.Const)));
72
+ if (this.dependencies.length > 0) {
73
+ statements.push(factory.createExportAssignment(undefined, undefined, undefined, factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("i18ns"), factory.createIdentifier("concat")), undefined, this.dependencies.map(function (ele, idx) { return factory.createIdentifier("i18ns".concat(idx)); }))));
74
+ }
75
+ else {
76
+ statements.push(factory.createExportAssignment(undefined, undefined, undefined, factory.createIdentifier("i18ns")));
77
+ }
78
+ var printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
79
+ var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS));
80
+ var filename = (0, path_1.join)(this.pwd, 'src', 'data', 'i18n.ts');
81
+ var result2 = (0, string_1.unescapeUnicode)("// \u672C\u6587\u4EF6\u4E3A\u81EA\u52A8\u7F16\u8BD1\u4EA7\u751F\uFF0C\u8BF7\u52FF\u76F4\u63A5\u4FEE\u6539\n\n".concat(result));
82
+ fs_1.default.writeFileSync(filename, result2, { flag: 'w' });
83
+ };
84
+ LocaleBuilder.prototype.parseFile = function (module, namespace, position, filename, filepath, watch) {
85
+ var _this = this;
86
+ var language = (filename.split('.')[0]).replace('_', '-'); // 历史原因,会命名成zh_CN.json
87
+ var data = require(filepath);
88
+ var ns = module ? "".concat(module, "-").concat(namespace) : (0, string_1.firstLetterLowerCase)(namespace);
89
+ this.locales[ns] = [module, position.replace(/\\/g, '/'), language, data];
90
+ if (watch) {
91
+ fs_1.default.watch(filepath, function () {
92
+ var data = require(filepath);
93
+ _this.locales[ns] = [module, position.replace(/\\/g, '/'), language, data];
94
+ _this.outputDataFile();
95
+ });
96
+ }
97
+ };
98
+ LocaleBuilder.prototype.traverse = function (module, nsPrefix, position, dirPath, inLocale, localeFolderName, watch) {
99
+ var _this = this;
100
+ var files = fs_1.default.readdirSync(dirPath);
101
+ files.forEach(function (file) {
102
+ var filepath = (0, path_1.join)(dirPath, file);
103
+ var stat = fs_1.default.statSync(filepath);
104
+ if (stat.isFile() && inLocale && file.endsWith('.json')) {
105
+ _this.parseFile(module, nsPrefix, position, file, filepath, watch);
106
+ }
107
+ else if (stat.isDirectory() && !inLocale) {
108
+ var nsPrefix2 = nsPrefix ? "".concat(nsPrefix, "-").concat(file) : file;
109
+ var isLocaleFolder = file === localeFolderName;
110
+ _this.traverse(module, isLocaleFolder ? nsPrefix : nsPrefix2, isLocaleFolder ? position : (0, path_1.join)(position, file), (0, path_1.join)(dirPath, file), isLocaleFolder, localeFolderName, watch);
111
+ }
112
+ });
113
+ };
114
+ LocaleBuilder.prototype.buildproject = function (root, src, watch) {
115
+ var _this = this;
116
+ var packageJson = (0, path_1.join)(root, 'package.json');
117
+ var name = require(packageJson).name;
118
+ var pagePath = (0, path_1.join)(src ? 'src' : 'lib', 'pages');
119
+ this.traverse(name, 'p', pagePath, (0, path_1.join)(root, pagePath), false, 'locales', watch);
120
+ var componentPath = (0, path_1.join)(src ? 'src' : 'lib', 'components');
121
+ this.traverse(name, 'c', componentPath, (0, path_1.join)(root, componentPath), false, 'locales', watch);
122
+ var localePath = (0, path_1.join)(root, src ? 'src' : 'lib', 'locales');
123
+ if (fs_1.default.existsSync(localePath)) {
124
+ var files = fs_1.default.readdirSync(localePath);
125
+ files.forEach(function (file) {
126
+ var filepath = (0, path_1.join)(localePath, file);
127
+ var stat = fs_1.default.statSync(filepath);
128
+ if (stat.isDirectory()) {
129
+ _this.traverse(name, "l-".concat(file), (0, path_1.join)('locales', file), (0, path_1.join)(localePath, file), true, file, watch);
130
+ }
131
+ });
132
+ }
133
+ if (!this.asLib && src) {
134
+ // 不是lib的话将oak-app-domain中的对象的locale也收集起来
135
+ var domainPath = (0, path_1.join)(root, 'src', 'oak-app-domain');
136
+ if (fs_1.default.existsSync(domainPath)) {
137
+ this.traverse('', '', 'oak-app-domain', domainPath, false, 'locales', watch);
138
+ }
139
+ // 还有web和wechatMp的目录
140
+ var webSrcPath = (0, path_1.join)('web', 'src');
141
+ this.traverse(name, 'w', webSrcPath, (0, path_1.join)(root, webSrcPath), false, 'locales', watch);
142
+ // 小程序可能有多于一个,按规范用wechatMp, wechatMp2这样命名
143
+ var wechatMpSrcPath = (0, path_1.join)('wechatMp', 'src');
144
+ this.traverse(name, 'wmp', wechatMpSrcPath, (0, path_1.join)(root, webSrcPath), false, 'locales', watch);
145
+ var iter = 1;
146
+ while (true) {
147
+ var mpSrcPath = "".concat(wechatMpSrcPath).concat(iter);
148
+ if (fs_1.default.existsSync((0, path_1.join)(root, mpSrcPath))) {
149
+ this.traverse(name, "wmp".concat(iter), mpSrcPath, (0, path_1.join)(root, mpSrcPath), false, 'locales', watch);
150
+ iter++;
151
+ }
152
+ else {
153
+ break;
154
+ }
155
+ }
156
+ }
157
+ };
158
+ LocaleBuilder.prototype.build = function (watch) {
159
+ this.buildproject(this.pwd, true, watch);
160
+ if (!this.asLib) {
161
+ // 如果不是lib,把front里的数据也处理掉
162
+ var fbPath = (0, path_1.join)(this.pwd, 'node_modules', 'oak-frontend-base');
163
+ this.buildproject(fbPath, false, watch);
164
+ }
165
+ this.outputDataFile();
166
+ };
167
+ return LocaleBuilder;
168
+ }());
169
+ exports.default = LocaleBuilder;
@@ -1,2 +1,11 @@
1
+ export declare function registerIgnoredForeignKeyMap(map: Record<string, string[]>): void;
2
+ export declare function registerFreeEntities(selectFreeEntities?: string[], createFreeEntities?: string[], updateFreeEntities?: string[]): void;
3
+ export declare function registerIgnoredRelationPathMap(map: Record<string, string[]>): void;
4
+ /**
5
+ * 很多路径虽然最后指向同一对象,但不能封掉,封了会导致查询的时候找不到对应的路径path
6
+ * @param map
7
+ */
8
+ export declare function registerFixedDestinationPathMap(map: Record<string, string[]>): void;
9
+ export declare function registerDeducedRelationMap(map: Record<string, string>): void;
1
10
  export declare function analyzeEntities(inputDir: string, relativePath?: string): void;
2
11
  export declare function buildSchema(outputDir: string): void;