oak-domain 3.0.3 → 3.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.
Files changed (158) hide show
  1. package/lib/actions/action.d.ts +8 -8
  2. package/lib/actions/action.js +2 -2
  3. package/lib/actions/relation.d.ts +1 -1
  4. package/lib/actions/relation.js +9 -22
  5. package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
  6. package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
  7. package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
  8. package/lib/base-app-domain/ActionDefDict.js +3 -5
  9. package/lib/base-app-domain/EntityDict.d.ts +5 -1
  10. package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
  11. package/lib/base-app-domain/I18n/Storage.js +5 -5
  12. package/lib/base-app-domain/Modi/Action.d.ts +4 -4
  13. package/lib/base-app-domain/Modi/Action.js +3 -3
  14. package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
  15. package/lib/base-app-domain/Modi/Storage.js +3 -3
  16. package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
  17. package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
  18. package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
  19. package/lib/base-app-domain/Oper/Storage.js +1 -1
  20. package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
  21. package/lib/base-app-domain/OperEntity/Storage.js +2 -2
  22. package/lib/base-app-domain/Path/Schema.d.ts +149 -0
  23. package/lib/base-app-domain/Path/Schema.js +2 -0
  24. package/lib/base-app-domain/Path/Storage.d.ts +3 -0
  25. package/lib/base-app-domain/Path/Storage.js +54 -0
  26. package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
  27. package/lib/base-app-domain/Relation/Storage.js +6 -6
  28. package/lib/base-app-domain/Relation.d.ts +0 -8
  29. package/lib/base-app-domain/Relation.js +1 -7
  30. package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
  31. package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
  32. package/lib/base-app-domain/Storage.js +20 -16
  33. package/lib/base-app-domain/User/Action.d.ts +4 -4
  34. package/lib/base-app-domain/User/Action.js +3 -3
  35. package/lib/base-app-domain/User/Schema.d.ts +40 -27
  36. package/lib/base-app-domain/User/Storage.js +1 -1
  37. package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
  38. package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
  39. package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
  40. package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
  41. package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
  42. package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
  43. package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
  44. package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
  45. package/lib/base-app-domain/UserRelation/Storage.js +7 -7
  46. package/lib/base-app-domain/_SubQuery.d.ts +45 -15
  47. package/lib/base-app-domain/index.js +1 -1
  48. package/lib/checkers/index.js +6 -7
  49. package/lib/compiler/env.js +16 -18
  50. package/lib/compiler/localeBuilder.js +83 -79
  51. package/lib/compiler/schemalBuilder.d.ts +16 -0
  52. package/lib/compiler/schemalBuilder.js +1160 -1378
  53. package/lib/entities/ActionAuth.d.ts +3 -5
  54. package/lib/entities/ActionAuth.js +9 -7
  55. package/lib/entities/I18n.js +1 -1
  56. package/lib/entities/Modi.js +2 -2
  57. package/lib/entities/ModiEntity.js +1 -1
  58. package/lib/entities/Oper.js +1 -1
  59. package/lib/entities/OperEntity.js +1 -1
  60. package/lib/entities/Path.d.ts +8 -0
  61. package/lib/entities/Path.js +35 -0
  62. package/lib/entities/Relation.js +1 -1
  63. package/lib/entities/RelationAuth.d.ts +2 -2
  64. package/lib/entities/RelationAuth.js +1 -1
  65. package/lib/entities/User.js +2 -2
  66. package/lib/entities/UserEntityClaim.d.ts +13 -0
  67. package/lib/entities/UserEntityClaim.js +17 -0
  68. package/lib/entities/UserEntityGrant.d.ts +5 -4
  69. package/lib/entities/UserEntityGrant.js +4 -7
  70. package/lib/entities/UserRelation.js +1 -1
  71. package/lib/index.d.ts +23 -0
  72. package/lib/index.js +37 -0
  73. package/lib/store/AsyncRowStore.d.ts +2 -1
  74. package/lib/store/AsyncRowStore.js +75 -149
  75. package/lib/store/CascadeStore.js +917 -1291
  76. package/lib/store/RelationAuth.d.ts +9 -16
  77. package/lib/store/RelationAuth.js +750 -908
  78. package/lib/store/SyncRowStore.d.ts +1 -1
  79. package/lib/store/SyncRowStore.js +27 -26
  80. package/lib/store/TriggerExecutor.d.ts +17 -10
  81. package/lib/store/TriggerExecutor.js +350 -423
  82. package/lib/store/actionAuth.js +13 -28
  83. package/lib/store/actionDef.js +118 -193
  84. package/lib/store/checker.js +225 -361
  85. package/lib/store/filter.d.ts +2 -3
  86. package/lib/store/filter.js +451 -589
  87. package/lib/store/modi.js +116 -177
  88. package/lib/store/relation.js +17 -17
  89. package/lib/timers/oper.d.ts +1 -1
  90. package/lib/timers/oper.js +44 -47
  91. package/lib/timers/vaccum.d.ts +2 -2
  92. package/lib/timers/vaccum.js +100 -165
  93. package/lib/triggers/index.js +1 -1
  94. package/lib/types/Action.d.ts +7 -7
  95. package/lib/types/AppLoader.d.ts +8 -2
  96. package/lib/types/AppLoader.js +4 -4
  97. package/lib/types/Aspect.d.ts +1 -3
  98. package/lib/types/Auth.d.ts +15 -19
  99. package/lib/types/Connector.d.ts +19 -15
  100. package/lib/types/Connector.js +0 -7
  101. package/lib/types/DataType.d.ts +19 -18
  102. package/lib/types/DataType.js +1 -1
  103. package/lib/types/Demand.d.ts +25 -25
  104. package/lib/types/Endpoint.d.ts +1 -1
  105. package/lib/types/Entity.d.ts +57 -53
  106. package/lib/types/Entity.js +3 -3
  107. package/lib/types/EntityDesc.d.ts +2 -1
  108. package/lib/types/Environment.d.ts +4 -4
  109. package/lib/types/Exception.d.ts +29 -2
  110. package/lib/types/Exception.js +205 -205
  111. package/lib/types/Expression.d.ts +14 -14
  112. package/lib/types/Expression.js +54 -87
  113. package/lib/types/Geo.d.ts +6 -6
  114. package/lib/types/Locale.d.ts +5 -5
  115. package/lib/types/Polyfill.d.ts +9 -9
  116. package/lib/types/Port.d.ts +4 -4
  117. package/lib/types/RowStore.d.ts +3 -3
  118. package/lib/types/RowStore.js +18 -19
  119. package/lib/types/Storage.d.ts +5 -4
  120. package/lib/types/Style.d.ts +2 -2
  121. package/lib/types/Timer.d.ts +3 -3
  122. package/lib/types/Trigger.d.ts +30 -14
  123. package/lib/types/Trigger.js +6 -2
  124. package/lib/types/Watcher.d.ts +2 -2
  125. package/lib/types/index.d.ts +1 -0
  126. package/lib/types/index.js +2 -1
  127. package/lib/types/schema/DataTypes.d.ts +7 -7
  128. package/lib/utils/SimpleConnector.d.ts +24 -10
  129. package/lib/utils/SimpleConnector.js +166 -144
  130. package/lib/utils/assert.js +2 -2
  131. package/lib/utils/concurrent.d.ts +1 -1
  132. package/lib/utils/concurrent.js +31 -57
  133. package/lib/utils/date.js +2 -2
  134. package/lib/utils/geo.js +8 -8
  135. package/lib/utils/lodash.d.ts +3 -1
  136. package/lib/utils/lodash.js +21 -34
  137. package/lib/utils/mask.js +12 -13
  138. package/lib/utils/money.d.ts +1 -1
  139. package/lib/utils/money.js +22 -11
  140. package/lib/utils/projection.d.ts +4 -0
  141. package/lib/utils/projection.js +15 -0
  142. package/lib/utils/random/random.js +11 -16
  143. package/lib/utils/random/random.mp.js +7 -18
  144. package/lib/utils/random/random.web.js +6 -12
  145. package/lib/utils/string.d.ts +4 -4
  146. package/lib/utils/string.js +19 -32
  147. package/lib/utils/url.js +5 -4
  148. package/lib/utils/uuid.d.ts +1 -1
  149. package/lib/utils/uuid.js +46 -85
  150. package/lib/utils/validator.d.ts +4 -3
  151. package/lib/utils/validator.js +35 -32
  152. package/lib/utils/version.js +6 -6
  153. package/package.json +7 -7
  154. package/src/entities/ActionAuth.ts +10 -10
  155. package/src/entities/Path.ts +43 -0
  156. package/src/entities/RelationAuth.ts +2 -1
  157. package/src/entities/UserEntityClaim.ts +30 -0
  158. package/src/entities/UserEntityGrant.ts +9 -12
@@ -1,176 +1,111 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vaccumEntities = void 0;
4
- var tslib_1 = require("tslib");
5
- var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
- var fs_1 = require("fs");
7
- var filter_1 = require("../store/filter");
8
- var stream_1 = require("stream");
9
- var uuid_1 = require("../utils/uuid");
4
+ const tslib_1 = require("tslib");
5
+ const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
+ const fs_1 = require("fs");
7
+ const filter_1 = require("../store/filter");
8
+ const stream_1 = require("stream");
9
+ const uuid_1 = require("../utils/uuid");
10
10
  /**
11
11
  * 删除数据库中的部分数据,减少体积
12
12
  * 一般只删除日志类数据
13
13
  * @param option
14
14
  */
15
- function vaccumEntities(option, context) {
16
- return tslib_1.__awaiter(this, void 0, void 0, function () {
17
- var entities, backupDir, _loop_1, entities_1, entities_1_1, ele, e_1_1;
18
- var e_1, _a;
19
- var _this = this;
20
- return tslib_1.__generator(this, function (_b) {
21
- switch (_b.label) {
22
- case 0:
23
- entities = option.entities, backupDir = option.backupDir;
24
- _loop_1 = function (ele) {
25
- var entity, filter, aliveLine, filter2, zip, now, backFile, fd_1, attributes_1, projection_1, attr, count_1, appendData_1, createGzip, gzip_1, source_1, destination_1, _c, _d, _e;
26
- var _f, _g;
27
- return tslib_1.__generator(this, function (_h) {
28
- switch (_h.label) {
29
- case 0:
30
- entity = ele.entity, filter = ele.filter, aliveLine = ele.aliveLine;
31
- filter2 = {
32
- $$createAt$$: {
33
- $lt: aliveLine,
34
- },
35
- };
36
- if (filter) {
37
- filter2 = (0, filter_1.combineFilters)(entity, context.getSchema(), [filter2, filter]);
38
- }
39
- if (!(backupDir && process.env.OAK_PLATFORM === 'server')) return [3 /*break*/, 4];
40
- zip = option.zip;
41
- now = (0, dayjs_1.default)();
42
- backFile = "".concat(backupDir, "/").concat(entity, "-").concat(now.format('YYYY-MM-DD HH:mm:ss'), ".csv");
43
- if ((0, fs_1.existsSync)(backFile)) {
44
- (0, fs_1.rmSync)(backFile);
45
- }
46
- fd_1 = (0, fs_1.openSync)(backFile, 'a');
47
- attributes_1 = ['id', '$$createAt$$', '$$updateAt$$', '$$deleteAt$$'];
48
- projection_1 = {
49
- id: 1,
50
- $$createAt$$: 1,
51
- $$updateAt$$: 1,
52
- $$deleteAt$$: 1,
53
- };
54
- for (attr in context.getSchema()[entity].attributes) {
55
- Object.assign(projection_1, (_f = {},
56
- _f[attr] = 1,
57
- _f));
58
- attributes_1.push(attr);
59
- }
60
- (0, fs_1.appendFileSync)(fd_1, attributes_1.join(','));
61
- (0, fs_1.appendFileSync)(fd_1, '\n');
62
- count_1 = 0;
63
- appendData_1 = function (minCreateAt) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
64
- var filter3, rows, csvTxt, maxCreateAt;
65
- return tslib_1.__generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0:
68
- filter3 = (0, filter_1.combineFilters)(entity, context.getSchema(), [filter2, {
69
- $$createAt$$: {
70
- $gt: minCreateAt,
71
- },
72
- }]);
73
- return [4 /*yield*/, context.select(entity, {
74
- data: projection_1,
75
- filter: filter3,
76
- sorter: [{
77
- $attr: {
78
- $$createAt$$: 1,
79
- },
80
- $direction: 'asc'
81
- }],
82
- indexFrom: 0,
83
- count: 1000,
84
- }, { includedDeleted: true })];
85
- case 1:
86
- rows = _a.sent();
87
- csvTxt = rows.map(function (row) { return attributes_1.map(function (attr) { return JSON.stringify(row[attr]); }).join(','); }).join('\n');
88
- (0, fs_1.appendFileSync)(fd_1, csvTxt);
89
- (0, fs_1.appendFileSync)(fd_1, '\n');
90
- count_1 += rows.length;
91
- if (rows.length === 1000) {
92
- maxCreateAt = rows[999].$$createAt$$;
93
- return [2 /*return*/, appendData_1(maxCreateAt)];
94
- }
95
- return [2 /*return*/];
96
- }
97
- });
98
- }); };
99
- return [4 /*yield*/, appendData_1(0)];
100
- case 1:
101
- _h.sent();
102
- (0, fs_1.closeSync)(fd_1);
103
- console.log("\u5907\u4EFD".concat(entity, "\u5BF9\u8C61\u5B8C\u6BD5\uFF0C\u5171\u5907\u4EFD\u4E86").concat(count_1, "\u884C\u6570\u636E"));
104
- if (!(count_1 === 0)) return [3 /*break*/, 2];
105
- (0, fs_1.rmSync)(backFile);
106
- return [3 /*break*/, 4];
107
- case 2:
108
- if (!zip) return [3 /*break*/, 4];
109
- createGzip = require('zlib').createGzip;
110
- gzip_1 = createGzip();
111
- source_1 = (0, fs_1.createReadStream)(backFile);
112
- destination_1 = (0, fs_1.createWriteStream)("".concat(backFile, ".zip"));
113
- return [4 /*yield*/, new Promise(function (resolve, reject) {
114
- (0, stream_1.pipeline)(source_1, gzip_1, destination_1, function (err) {
115
- if (err) {
116
- reject(err);
117
- }
118
- else {
119
- resolve(undefined);
120
- }
121
- });
122
- })];
123
- case 3:
124
- _h.sent();
125
- _h.label = 4;
126
- case 4:
127
- _d = (_c = context).operate;
128
- _e = [entity];
129
- _g = {};
130
- return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
131
- case 5:
132
- // 将对应的数据删除
133
- return [4 /*yield*/, _d.apply(_c, _e.concat([(_g.id = _h.sent(),
134
- _g.action = 'remove',
135
- _g.data = {},
136
- _g.filter = filter2,
137
- _g), { deletePhysically: true }]))];
138
- case 6:
139
- // 将对应的数据删除
140
- _h.sent();
141
- return [2 /*return*/];
142
- }
143
- });
144
- };
145
- _b.label = 1;
146
- case 1:
147
- _b.trys.push([1, 6, 7, 8]);
148
- entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next();
149
- _b.label = 2;
150
- case 2:
151
- if (!!entities_1_1.done) return [3 /*break*/, 5];
152
- ele = entities_1_1.value;
153
- return [5 /*yield**/, _loop_1(ele)];
154
- case 3:
155
- _b.sent();
156
- _b.label = 4;
157
- case 4:
158
- entities_1_1 = entities_1.next();
159
- return [3 /*break*/, 2];
160
- case 5: return [3 /*break*/, 8];
161
- case 6:
162
- e_1_1 = _b.sent();
163
- e_1 = { error: e_1_1 };
164
- return [3 /*break*/, 8];
165
- case 7:
166
- try {
167
- if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
168
- }
169
- finally { if (e_1) throw e_1.error; }
170
- return [7 /*endfinally*/];
171
- case 8: return [2 /*return*/];
15
+ async function vaccumEntities(option, context) {
16
+ const { entities, backupDir } = option;
17
+ for (const ele of entities) {
18
+ const { entity, filter, aliveLine } = ele;
19
+ let filter2 = {
20
+ $$createAt$$: {
21
+ $lt: aliveLine,
22
+ },
23
+ };
24
+ if (filter) {
25
+ filter2 = (0, filter_1.combineFilters)(entity, context.getSchema(), [filter2, filter]);
26
+ }
27
+ if (backupDir && process.env.OAK_PLATFORM === 'server') {
28
+ // 使用mysqldump将待删除的数据备份出来
29
+ const { zip: zip } = option;
30
+ const now = (0, dayjs_1.default)();
31
+ const backFile = `${backupDir}/${entity}-${now.format('YYYY-MM-DD HH:mm:ss')}.csv`;
32
+ if ((0, fs_1.existsSync)(backFile)) {
33
+ (0, fs_1.rmSync)(backFile);
172
34
  }
173
- });
174
- });
35
+ const fd = (0, fs_1.openSync)(backFile, 'a');
36
+ const attributes = ['id', '$$createAt$$', '$$updateAt$$', '$$deleteAt$$'];
37
+ const projection = {
38
+ id: 1,
39
+ $$createAt$$: 1,
40
+ $$updateAt$$: 1,
41
+ $$deleteAt$$: 1,
42
+ };
43
+ for (const attr in context.getSchema()[entity].attributes) {
44
+ Object.assign(projection, {
45
+ [attr]: 1,
46
+ });
47
+ attributes.push(attr);
48
+ }
49
+ (0, fs_1.appendFileSync)(fd, attributes.join(','));
50
+ (0, fs_1.appendFileSync)(fd, '\n');
51
+ let count = 0;
52
+ const appendData = async (minCreateAt) => {
53
+ const filter3 = (0, filter_1.combineFilters)(entity, context.getSchema(), [filter2, {
54
+ $$createAt$$: {
55
+ $gt: minCreateAt,
56
+ },
57
+ }]);
58
+ const rows = await context.select(entity, {
59
+ data: projection,
60
+ filter: filter3,
61
+ sorter: [{
62
+ $attr: {
63
+ $$createAt$$: 1,
64
+ },
65
+ $direction: 'asc'
66
+ }],
67
+ indexFrom: 0,
68
+ count: 1000,
69
+ }, { includedDeleted: true });
70
+ const csvTxt = rows.map((row) => attributes.map((attr) => JSON.stringify(row[attr])).join(',')).join('\n');
71
+ (0, fs_1.appendFileSync)(fd, csvTxt);
72
+ (0, fs_1.appendFileSync)(fd, '\n');
73
+ count += rows.length;
74
+ if (rows.length === 1000) {
75
+ const maxCreateAt = rows[999].$$createAt$$;
76
+ return appendData(maxCreateAt);
77
+ }
78
+ };
79
+ await appendData(0);
80
+ (0, fs_1.closeSync)(fd);
81
+ console.log(`备份${entity}对象完毕,共备份了${count}行数据`);
82
+ if (count === 0) {
83
+ (0, fs_1.rmSync)(backFile);
84
+ }
85
+ else if (zip) {
86
+ const { createGzip } = require('zlib');
87
+ const gzip = createGzip();
88
+ const source = (0, fs_1.createReadStream)(backFile);
89
+ const destination = (0, fs_1.createWriteStream)(`${backFile}.zip`);
90
+ await new Promise((resolve, reject) => {
91
+ (0, stream_1.pipeline)(source, gzip, destination, (err) => {
92
+ if (err) {
93
+ reject(err);
94
+ }
95
+ else {
96
+ resolve(undefined);
97
+ }
98
+ });
99
+ });
100
+ }
101
+ }
102
+ // 将对应的数据删除
103
+ await context.operate(entity, {
104
+ id: await (0, uuid_1.generateNewIdAsync)(),
105
+ action: 'remove',
106
+ data: {},
107
+ filter: filter2,
108
+ }, { deletePhysically: true });
109
+ }
175
110
  }
176
111
  exports.vaccumEntities = vaccumEntities;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDynamicTriggers = void 0;
4
- var modi_1 = require("../store/modi");
4
+ const modi_1 = require("../store/modi");
5
5
  function createDynamicTriggers(schema) {
6
6
  return (0, modi_1.createModiRelatedTriggers)(schema);
7
7
  }
@@ -1,20 +1,20 @@
1
1
  import { CascadeRelationItem, EntityDict } from "./Entity";
2
2
  import { GenericAction } from '../actions/action';
3
- export declare type Action = string;
4
- export declare type State = string;
5
- export declare type ActionDef<A extends Action, S extends State> = {
3
+ export type Action = string;
4
+ export type State = string;
5
+ export type ActionDef<A extends Action, S extends State> = {
6
6
  stm: {
7
7
  [a in A]: [p: S | S[], n: S];
8
8
  };
9
9
  is?: S;
10
10
  };
11
- export declare type ActionDictOfEntityDict<E extends EntityDict> = {
11
+ export type ActionDictOfEntityDict<E extends EntityDict> = {
12
12
  [T in keyof E]?: {
13
13
  [A in keyof E[T]['OpSchema']]?: ActionDef<string, string>;
14
14
  };
15
15
  };
16
- export declare type CascadeActionItem = CascadeRelationItem;
17
- export declare type CascadeActionAuth<A extends Action = ''> = {
16
+ export type CascadeActionItem = CascadeRelationItem;
17
+ export type CascadeActionAuth<A extends Action = ''> = {
18
18
  [K in A | GenericAction]?: CascadeActionItem | (CascadeActionItem | CascadeActionItem[])[];
19
19
  };
20
- export declare type ActionOnRemove = 'setNull' | 'remove';
20
+ export type ActionOnRemove = 'setNull' | 'remove';
@@ -1,9 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { IncomingHttpHeaders } from "http";
1
3
  import { AsyncContext, AsyncRowStore } from "../store/AsyncRowStore";
2
- import { EntityDict } from "./Entity";
4
+ import { EntityDict, OpRecord } from "./Entity";
3
5
  export declare abstract class AppLoader<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
4
6
  protected path: string;
5
7
  constructor(path: string);
6
- abstract execAspect(name: string, context: Cxt, params?: any): Promise<any>;
8
+ abstract execAspect(name: string, header?: IncomingHttpHeaders, contextString?: string, params?: any): Promise<{
9
+ opRecords?: OpRecord<ED>[];
10
+ message?: string;
11
+ result: any;
12
+ }>;
7
13
  abstract initialize(dropIfExists?: boolean): Promise<void>;
8
14
  abstract mount(): Promise<void>;
9
15
  abstract unmount(): Promise<void>;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AppLoader = void 0;
4
- var AppLoader = /** @class */ (function () {
5
- function AppLoader(path) {
4
+ class AppLoader {
5
+ path;
6
+ constructor(path) {
6
7
  this.path = path;
7
8
  }
8
- return AppLoader;
9
- }());
9
+ }
10
10
  exports.AppLoader = AppLoader;
@@ -1,4 +1,4 @@
1
- import { EntityDict, SubDataDef } from "./Entity";
1
+ import { EntityDict } from "./Entity";
2
2
  import { OpRecord } from "./Entity";
3
3
  import { AsyncContext } from "../store/AsyncRowStore";
4
4
  export interface Aspect<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
@@ -10,6 +10,4 @@ export interface AspectWrapper<ED extends EntityDict, Cxt extends AsyncContext<E
10
10
  opRecords?: OpRecord<ED>[];
11
11
  message?: string | null;
12
12
  }>;
13
- sub: (data: Array<SubDataDef<ED, keyof ED>>, callback: (records: OpRecord<ED>[], ids: string[]) => void) => Promise<void>;
14
- unsub: (ids: string[]) => Promise<void>;
15
13
  }
@@ -2,23 +2,26 @@ import { CascadeActionAuth, CascadeRelationAuth, ActionOnRemove, SyncOrAsync } f
2
2
  import { AsyncContext } from "../store/AsyncRowStore";
3
3
  import { SyncContext } from "../store/SyncRowStore";
4
4
  import { EntityDict, OperateOption, SelectOption } from "../types/Entity";
5
- export declare type CheckerType = 'relation' | 'row' | 'data' | 'logical' | 'logicalRelation';
5
+ import { ModiTurn } from './Trigger';
6
+ export type CheckerType = 'relation' | 'row' | 'data' | 'logical' | 'logicalRelation' | 'logicalData';
6
7
  /**
7
8
  * conditionalFilter是指该action发生时,operation所操作的行中有满足conditionalFilter的行
8
9
  * 被转化成trigger的filter条件,详细可看trigger中的说明
9
10
  */
10
- export declare type DataChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
11
+ export type DataChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
11
12
  priority?: number;
12
13
  type: 'data';
13
14
  entity: T;
15
+ mt?: ModiTurn;
14
16
  action: Omit<ED[T]['Action'], 'remove'> | Array<Omit<ED[T]['Action'], 'remove'>>;
15
17
  checker: (data: ED[T]['Create']['data'] | ED[T]['Update']['data'], context: Cxt) => SyncOrAsync<any>;
16
18
  conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Selection']['filter']>);
17
19
  };
18
- export declare type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
20
+ export type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
19
21
  priority?: number;
20
22
  type: 'row';
21
23
  entity: T;
24
+ mt?: ModiTurn;
22
25
  action: Omit<ED[T]['Action'], 'create'> | Array<Omit<ED[T]['Action'], 'create'>>;
23
26
  filter: ED[T]['Selection']['filter'] | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<ED[T]['Selection']['filter']>);
24
27
  errMsg?: string;
@@ -28,47 +31,40 @@ export declare type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt ex
28
31
  };
29
32
  conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Update']['filter']>);
30
33
  };
31
- export declare type RelationChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
34
+ export type RelationChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
32
35
  priority?: number;
33
36
  type: 'relation';
34
37
  entity: T;
38
+ mt?: ModiTurn;
35
39
  when?: 'after';
36
40
  action: ED[T]['Action'] | Array<ED[T]['Action']>;
37
41
  relationFilter: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<ED[T]['Selection']['filter']>;
38
42
  errMsg: string | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option?: OperateOption | SelectOption) => string);
39
43
  conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Selection']['filter']>);
40
44
  };
41
- export declare type LogicalChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
45
+ export type LogicalChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
42
46
  priority?: number;
43
- type: 'logical';
47
+ type: 'logical' | 'logicalData' | 'logicalRelation';
44
48
  when?: 'after';
49
+ mt?: ModiTurn;
45
50
  entity: T;
46
51
  action: ED[T]['Action'] | Array<ED[T]['Action']>;
47
52
  checker: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<any>;
48
53
  conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Update']['filter']>);
49
54
  };
50
- export declare type LogicalRelationChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
51
- priority?: number;
52
- type: 'logicalRelation';
53
- when?: 'after';
54
- entity: T;
55
- action: ED[T]['Action'] | Array<ED[T]['Action']>;
56
- checker: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => any | Promise<any>;
57
- conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Update']['filter']>);
58
- };
59
- export declare type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = DataChecker<ED, T, Cxt> | RowChecker<ED, T, Cxt> | RelationChecker<ED, T, Cxt> | LogicalChecker<ED, T, Cxt> | LogicalRelationChecker<ED, T, Cxt>;
60
- export declare type AuthDef<ED extends EntityDict, T extends keyof ED> = {
55
+ export type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = DataChecker<ED, T, Cxt> | RowChecker<ED, T, Cxt> | RelationChecker<ED, T, Cxt> | LogicalChecker<ED, T, Cxt>;
56
+ export type AuthDef<ED extends EntityDict, T extends keyof ED> = {
61
57
  relationAuth?: CascadeRelationAuth<NonNullable<ED[T]['Relation']>>;
62
58
  actionAuth?: CascadeActionAuth<ED[T]['Action']>;
63
59
  cascadeRemove?: {
64
60
  [E in (keyof ED | keyof ED[T]['Schema'] | '@entity')]?: ActionOnRemove;
65
61
  };
66
62
  };
67
- export declare type CascadeRemoveDefDict<ED extends EntityDict> = {
63
+ export type CascadeRemoveDefDict<ED extends EntityDict> = {
68
64
  [T in keyof ED]?: {
69
65
  [E in (keyof ED | keyof ED[T]['Schema'] | '@entity')]?: ActionOnRemove;
70
66
  };
71
67
  };
72
- export declare type AuthDefDict<ED extends EntityDict> = {
68
+ export type AuthDefDict<ED extends EntityDict> = {
73
69
  [K in keyof ED]?: AuthDef<ED, K>;
74
70
  };
@@ -1,33 +1,37 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingHttpHeaders } from "http";
3
- import { AsyncContext, AsyncRowStore } from "../store/AsyncRowStore";
4
3
  import { SyncContext } from "../store/SyncRowStore";
5
4
  import { EntityDict, OpRecord } from "./Entity";
6
5
  import { OakException } from "./Exception";
7
- export declare abstract class Connector<ED extends EntityDict, BackCxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> {
8
- abstract callAspect(name: string, params: any, context: FrontCxt): Promise<{
6
+ export interface Connector<ED extends EntityDict, FrontCxt extends SyncContext<ED>> {
7
+ callAspect: (name: string, params: any, context: FrontCxt) => Promise<{
9
8
  result: any;
10
9
  opRecords?: OpRecord<ED>[];
11
10
  message?: string | null;
12
11
  }>;
13
- abstract getRouter(): string;
14
- abstract parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): Promise<{
15
- name: string;
16
- params: any;
17
- context: BackCxt;
18
- }>;
19
- abstract serializeResult(result: any, context: BackCxt, headers: IncomingHttpHeaders, body: any): Promise<{
12
+ getRouter: () => string;
13
+ parseRequestHeaders: (headers: IncomingHttpHeaders) => {
14
+ contextString?: string;
15
+ aspectName: string;
16
+ };
17
+ serializeResult: (result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, message?: string) => Promise<{
20
18
  body: any;
21
19
  headers?: Record<string, any>;
22
20
  }>;
23
- abstract serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): {
21
+ serializeException: (exception: OakException<ED>, headers: IncomingHttpHeaders, body: any) => {
24
22
  body: any;
25
23
  headers?: Record<string, any>;
26
24
  };
27
- abstract getSubscribeRouter(): string;
28
- abstract getBridgeRouter(): string;
29
- abstract makeBridgeUrl(url: string, headers?: Record<string, string>): string;
30
- abstract parseBridgeRequestQuery(urlParams: string): {
25
+ getSubscribeRouter: () => string;
26
+ getSubscribePointRouter: () => string;
27
+ getSubscribePoint: () => Promise<{
28
+ url: string;
29
+ path: string;
30
+ }>;
31
+ getBridgeRouter: () => string;
32
+ makeBridgeUrl: (url: string, headers?: Record<string, string>) => string;
33
+ getEndpointRouter: () => string;
34
+ parseBridgeRequestQuery: (urlParams: string) => {
31
35
  url: string;
32
36
  headers?: Record<string, string>;
33
37
  };
@@ -1,9 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Connector = void 0;
4
- var Connector = /** @class */ (function () {
5
- function Connector() {
6
- }
7
- return Connector;
8
- }());
9
- exports.Connector = Connector;
@@ -1,24 +1,25 @@
1
1
  import { Geo, SingleGeo } from "./Geo";
2
- export declare type Int<L extends 1 | 2 | 4 | 8> = number;
3
- export declare type Uint<L extends 1 | 2 | 4 | 8> = number;
4
- export declare type Double<P extends number, S extends number> = number;
5
- export declare type Float<P extends number, S extends number> = number;
6
- export declare type String<L extends number> = string;
7
- export declare type Text = string;
8
- export declare type Image = string;
9
- export declare type File = string;
10
- export declare type Datetime = number | Date;
11
- export declare type Day = number | Date;
12
- export declare type Time = number | Date;
13
- export declare type Boolean = boolean;
14
- export declare type Price = number;
15
- export declare type PrimaryKey = string;
16
- export declare type ForeignKey<E extends string> = string;
17
- export declare type Sequence = string;
2
+ export type Int<L extends 1 | 2 | 4 | 8> = number;
3
+ export type Uint<L extends 1 | 2 | 4 | 8> = number;
4
+ export type Double<P extends number, S extends number> = number;
5
+ export type Float<P extends number, S extends number> = number;
6
+ export type Decimal<P extends number, S extends number> = number;
7
+ export type String<L extends number> = string;
8
+ export type Text = string;
9
+ export type Image = string;
10
+ export type File = string;
11
+ export type Datetime = number | Date;
12
+ export type Day = number | Date;
13
+ export type Time = number | Date;
14
+ export type Boolean = boolean;
15
+ export type Price = number;
16
+ export type PrimaryKey = string;
17
+ export type ForeignKey<E extends string> = string;
18
+ export type Sequence = string;
18
19
  export { Geo, SingleGeo } from './Geo';
19
- export declare type DataTypes = number | string | Datetime | Day | Time | Geo | Object | SingleGeo;
20
+ export type DataTypes = number | string | Datetime | Day | Time | Geo | Object | SingleGeo;
20
21
  export declare const types: string[];
21
22
  export declare const unIndexedTypes: string[];
22
- export declare type JsonProjection<O extends object> = {
23
+ export type JsonProjection<O extends object> = {
23
24
  [k in keyof O]?: NonNullable<O[k]> extends object ? JsonProjection<NonNullable<O[k]>> | number : number;
24
25
  };
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unIndexedTypes = exports.types = void 0;
4
4
  exports.types = ['Int', 'Uint', 'Double', 'Float', 'String', 'Text', 'Datetime', 'Day', 'Time',
5
- 'Boolean', 'Image', 'File', 'Geo', 'SingleGeo', 'Price'];
5
+ 'Boolean', 'Image', 'File', 'Geo', 'SingleGeo', 'Price', 'Decimal'];
6
6
  exports.unIndexedTypes = ['Text', 'Image', 'File', 'Object'];