oak-domain 5.0.20 → 5.1.1
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/ActionDefDict.d.ts +6 -0
- package/lib/base-app-domain/ActionDefDict.js +8 -4
- package/lib/base-app-domain/EntityDict.d.ts +2 -0
- package/lib/base-app-domain/Log/Action.d.ts +12 -0
- package/lib/base-app-domain/Log/Action.js +14 -0
- package/lib/base-app-domain/Log/Schema.d.ts +135 -0
- package/lib/base-app-domain/Log/Schema.js +2 -0
- package/lib/base-app-domain/Log/Storage.d.ts +3 -0
- package/lib/base-app-domain/Log/Storage.js +28 -0
- package/lib/base-app-domain/Log/Style.d.ts +3 -0
- package/lib/base-app-domain/Log/Style.js +15 -0
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +34 -5
- package/lib/base-app-domain/ModiEntity/Storage.js +1 -1
- package/lib/base-app-domain/Oper/Action.d.ts +12 -0
- package/lib/base-app-domain/Oper/Action.js +14 -0
- package/lib/base-app-domain/Oper/Schema.d.ts +56 -6
- package/lib/base-app-domain/Oper/Storage.js +14 -3
- package/lib/base-app-domain/Oper/Style.d.ts +3 -0
- package/lib/base-app-domain/Oper/Style.js +15 -0
- package/lib/base-app-domain/OperEntity/Schema.d.ts +46 -6
- package/lib/base-app-domain/OperEntity/Storage.js +1 -1
- package/lib/base-app-domain/Storage.js +24 -22
- package/lib/base-app-domain/StyleDict.js +8 -4
- package/lib/base-app-domain/User/Schema.d.ts +2 -2
- package/lib/base-app-domain/_SubQuery.d.ts +12 -0
- package/lib/compiler/schemalBuilder.js +22 -1
- package/lib/entities/Log.d.ts +16 -0
- package/lib/entities/Log.js +45 -0
- package/lib/entities/Oper.d.ts +9 -0
- package/lib/entities/Oper.js +33 -3
- package/lib/store/AsyncRowStore.d.ts +3 -2
- package/lib/store/AsyncRowStore.js +6 -0
- package/lib/store/CascadeStore.d.ts +1 -1
- package/lib/store/CascadeStore.js +83 -46
- package/lib/store/IntrinsicCheckers.js +7 -2
- package/lib/store/IntrinsicLogics.js +2 -2
- package/lib/store/RelationAuth.js +9 -0
- package/lib/store/SyncRowStore.d.ts +3 -2
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/relation.js +4 -4
- package/lib/store/triggers.d.ts +6 -0
- package/lib/store/triggers.js +351 -0
- package/lib/types/AppLoader.d.ts +2 -1
- package/lib/types/Aspect.d.ts +3 -2
- package/lib/types/Auth.d.ts +9 -8
- package/lib/types/Endpoint.d.ts +3 -2
- package/lib/types/Entity.d.ts +4 -0
- package/lib/types/EntityDesc.d.ts +1 -1
- package/lib/types/Exception.d.ts +6 -0
- package/lib/types/Exception.js +15 -1
- package/lib/types/Port.d.ts +3 -2
- package/lib/types/RowStore.d.ts +4 -3
- package/lib/types/Storage.d.ts +1 -0
- package/lib/types/Timer.d.ts +6 -5
- package/lib/types/Trigger.d.ts +21 -20
- package/lib/types/Trigger.js +1 -0
- package/lib/types/Watcher.d.ts +5 -4
- package/package.json +1 -1
- package/src/entities/Log.ts +59 -0
- package/src/entities/ModiEntity.ts +26 -26
- package/src/entities/Oper.ts +45 -4
- package/src/entities/OperEntity.ts +27 -27
- package/src/entities/Relation.ts +43 -43
- package/src/entities/UserEntityClaim.ts +29 -29
- package/src/entities/UserEntityGrant.ts +24 -24
- package/src/entities/UserRelation.ts +50 -50
- package/lib/store/actionAuth.d.ts +0 -4
- package/lib/store/actionAuth.js +0 -25
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logTriggers = exports.actionAuthTriggers = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const uuid_1 = require("../utils/uuid");
|
|
7
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
|
+
const filter_1 = require("./filter");
|
|
9
|
+
exports.actionAuthTriggers = [
|
|
10
|
+
{
|
|
11
|
+
name: '当actionAuth的deActions被置空后,删除此条数据',
|
|
12
|
+
entity: 'actionAuth',
|
|
13
|
+
action: 'update',
|
|
14
|
+
fn: async ({ operation }, context, option) => {
|
|
15
|
+
const { data, filter } = operation;
|
|
16
|
+
if (data.deActions && data.deActions.length === 0) {
|
|
17
|
+
await context.operate('actionAuth', {
|
|
18
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
19
|
+
action: 'remove',
|
|
20
|
+
data: {},
|
|
21
|
+
filter,
|
|
22
|
+
}, option);
|
|
23
|
+
return 1;
|
|
24
|
+
}
|
|
25
|
+
return 0;
|
|
26
|
+
},
|
|
27
|
+
when: 'after',
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* 回滚某条日志的修改
|
|
32
|
+
* @param log
|
|
33
|
+
* @param context
|
|
34
|
+
*/
|
|
35
|
+
async function undoLog(log, context) {
|
|
36
|
+
const { iState, oper$log } = log;
|
|
37
|
+
for (const oper of oper$log) {
|
|
38
|
+
const { action, targetEntity, filter, undoData, iState } = oper;
|
|
39
|
+
(0, assert_1.default)(iState === 'normal', '非正常状态的oper怎能回滚');
|
|
40
|
+
switch (action) {
|
|
41
|
+
case 'create': {
|
|
42
|
+
await context.operate(targetEntity, {
|
|
43
|
+
id: 'dummy',
|
|
44
|
+
action: 'remove',
|
|
45
|
+
data: {},
|
|
46
|
+
filter: filter,
|
|
47
|
+
}, {
|
|
48
|
+
blockTrigger: true,
|
|
49
|
+
dontCollect: true,
|
|
50
|
+
dontCreateOper: true,
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'remove': {
|
|
55
|
+
const ids = (0, filter_1.getRelevantIds)(filter);
|
|
56
|
+
(0, assert_1.default)(ids.length > 0);
|
|
57
|
+
for (const id of ids) {
|
|
58
|
+
await context.operate(targetEntity, {
|
|
59
|
+
id: 'dummy',
|
|
60
|
+
action: 'create',
|
|
61
|
+
data: undoData[id],
|
|
62
|
+
}, {
|
|
63
|
+
blockTrigger: true,
|
|
64
|
+
dontCollect: true,
|
|
65
|
+
dontCreateOper: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
default: {
|
|
71
|
+
// 全按update处理
|
|
72
|
+
const ids = (0, filter_1.getRelevantIds)(filter);
|
|
73
|
+
(0, assert_1.default)(ids.length > 0);
|
|
74
|
+
for (const id of ids) {
|
|
75
|
+
await context.operate(targetEntity, {
|
|
76
|
+
id: 'dummy',
|
|
77
|
+
action: 'update',
|
|
78
|
+
data: undoData[id],
|
|
79
|
+
filter: {
|
|
80
|
+
id,
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
blockTrigger: true,
|
|
84
|
+
dontCollect: true,
|
|
85
|
+
dontCreateOper: true,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
await context.operate('oper', {
|
|
93
|
+
id: 'dummy',
|
|
94
|
+
action: 'undo',
|
|
95
|
+
data: {
|
|
96
|
+
iState: 'rollbacked',
|
|
97
|
+
},
|
|
98
|
+
filter: {
|
|
99
|
+
id: {
|
|
100
|
+
$in: oper$log.map(ele => ele.id)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
blockTrigger: true,
|
|
105
|
+
dontCollect: true,
|
|
106
|
+
dontCreateOper: true,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 重做某条日志的修改
|
|
111
|
+
* @param log
|
|
112
|
+
* @param context
|
|
113
|
+
*/
|
|
114
|
+
async function redoLog(log, context) {
|
|
115
|
+
const { oper$log } = log;
|
|
116
|
+
for (const oper of oper$log) {
|
|
117
|
+
const { action, targetEntity, filter, data, iState } = oper;
|
|
118
|
+
(0, assert_1.default)(iState === 'rollbacked', '非正常状态的oper怎能回滚');
|
|
119
|
+
switch (action) {
|
|
120
|
+
case 'create': {
|
|
121
|
+
await context.operate(targetEntity, {
|
|
122
|
+
id: 'dummy',
|
|
123
|
+
action: 'create',
|
|
124
|
+
data: data,
|
|
125
|
+
}, {
|
|
126
|
+
blockTrigger: true,
|
|
127
|
+
dontCollect: true,
|
|
128
|
+
dontCreateOper: true,
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'remove': {
|
|
133
|
+
await context.operate(targetEntity, {
|
|
134
|
+
id: 'dummy',
|
|
135
|
+
action: 'remove',
|
|
136
|
+
data: {},
|
|
137
|
+
filter: filter,
|
|
138
|
+
}, {
|
|
139
|
+
blockTrigger: true,
|
|
140
|
+
dontCollect: true,
|
|
141
|
+
dontCreateOper: true,
|
|
142
|
+
});
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
default: {
|
|
146
|
+
await context.operate(targetEntity, {
|
|
147
|
+
id: 'dummy',
|
|
148
|
+
action,
|
|
149
|
+
data,
|
|
150
|
+
filter: filter,
|
|
151
|
+
}, {
|
|
152
|
+
blockTrigger: true,
|
|
153
|
+
dontCollect: true,
|
|
154
|
+
dontCreateOper: true,
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
await context.operate('oper', {
|
|
161
|
+
id: 'dummy',
|
|
162
|
+
action: 'redo',
|
|
163
|
+
data: {
|
|
164
|
+
iState: 'normal',
|
|
165
|
+
},
|
|
166
|
+
filter: {
|
|
167
|
+
id: {
|
|
168
|
+
$in: oper$log.map(ele => ele.id)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, {
|
|
172
|
+
blockTrigger: true,
|
|
173
|
+
dontCollect: true,
|
|
174
|
+
dontCreateOper: true,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
exports.logTriggers = [
|
|
178
|
+
{
|
|
179
|
+
name: '当log被undo时,同一entity上所有在其之后的log全部回滚',
|
|
180
|
+
entity: 'log',
|
|
181
|
+
action: 'undo',
|
|
182
|
+
when: 'after',
|
|
183
|
+
fn: async ({ operation }, context) => {
|
|
184
|
+
const { filter } = operation;
|
|
185
|
+
(0, assert_1.default)(filter);
|
|
186
|
+
const ids = (0, filter_1.getRelevantIds)(filter);
|
|
187
|
+
(0, assert_1.default)(ids.length === 1);
|
|
188
|
+
const [log] = await context.select('log', {
|
|
189
|
+
data: {
|
|
190
|
+
id: 1,
|
|
191
|
+
oper$log: {
|
|
192
|
+
$entity: 'oper',
|
|
193
|
+
data: {
|
|
194
|
+
id: 1,
|
|
195
|
+
undoData: 1,
|
|
196
|
+
action: 1,
|
|
197
|
+
targetEntity: 1,
|
|
198
|
+
filter: 1,
|
|
199
|
+
[types_1.SeqAttribute]: 1,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
entity: 1,
|
|
203
|
+
entityId: 1,
|
|
204
|
+
},
|
|
205
|
+
filter: {
|
|
206
|
+
id: ids[0],
|
|
207
|
+
},
|
|
208
|
+
}, {});
|
|
209
|
+
const logs = await context.select('log', {
|
|
210
|
+
data: {
|
|
211
|
+
id: 1,
|
|
212
|
+
oper$log: {
|
|
213
|
+
$entity: 'oper',
|
|
214
|
+
data: {
|
|
215
|
+
id: 1,
|
|
216
|
+
undoData: 1,
|
|
217
|
+
action: 1,
|
|
218
|
+
targetEntity: 1,
|
|
219
|
+
filter: 1,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
filter: {
|
|
224
|
+
iState: 'normal',
|
|
225
|
+
entity: log.entity,
|
|
226
|
+
entityId: log.entityId,
|
|
227
|
+
[types_1.SeqAttribute]: {
|
|
228
|
+
$gte: log[types_1.SeqAttribute],
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
sorter: [
|
|
232
|
+
{
|
|
233
|
+
$attr: {
|
|
234
|
+
[types_1.SeqAttribute]: 1,
|
|
235
|
+
},
|
|
236
|
+
$direction: 'desc',
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
}, { dontCollect: true });
|
|
240
|
+
(0, assert_1.default)(logs.length > 0);
|
|
241
|
+
for (const log2 of logs) {
|
|
242
|
+
await undoLog(log2, context);
|
|
243
|
+
}
|
|
244
|
+
return logs.length;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: '当log被redo时,同一entity上所有在其之前的log全部重做',
|
|
249
|
+
entity: 'log',
|
|
250
|
+
action: 'redo',
|
|
251
|
+
when: 'after',
|
|
252
|
+
fn: async ({ operation }, context) => {
|
|
253
|
+
const { filter } = operation;
|
|
254
|
+
(0, assert_1.default)(filter);
|
|
255
|
+
const ids = (0, filter_1.getRelevantIds)(filter);
|
|
256
|
+
(0, assert_1.default)(ids.length === 1);
|
|
257
|
+
const [log] = await context.select('log', {
|
|
258
|
+
data: {
|
|
259
|
+
id: 1,
|
|
260
|
+
oper$log: {
|
|
261
|
+
$entity: 'oper',
|
|
262
|
+
data: {
|
|
263
|
+
id: 1,
|
|
264
|
+
data: 1,
|
|
265
|
+
action: 1,
|
|
266
|
+
targetEntity: 1,
|
|
267
|
+
filter: 1,
|
|
268
|
+
[types_1.SeqAttribute]: 1,
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
iState: 1,
|
|
272
|
+
entity: 1,
|
|
273
|
+
entityId: 1,
|
|
274
|
+
},
|
|
275
|
+
filter: {
|
|
276
|
+
id: ids[0],
|
|
277
|
+
},
|
|
278
|
+
}, {});
|
|
279
|
+
const logs = await context.select('log', {
|
|
280
|
+
data: {
|
|
281
|
+
id: 1,
|
|
282
|
+
oper$log: {
|
|
283
|
+
$entity: 'oper',
|
|
284
|
+
data: {
|
|
285
|
+
id: 1,
|
|
286
|
+
data: 1,
|
|
287
|
+
action: 1,
|
|
288
|
+
targetEntity: 1,
|
|
289
|
+
filter: 1,
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
filter: {
|
|
294
|
+
iState: 'rollbacked',
|
|
295
|
+
entity: log.entity,
|
|
296
|
+
entityId: log.entityId,
|
|
297
|
+
[types_1.SeqAttribute]: {
|
|
298
|
+
$lte: log[types_1.SeqAttribute],
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
sorter: [
|
|
302
|
+
{
|
|
303
|
+
$attr: {
|
|
304
|
+
[types_1.SeqAttribute]: 1,
|
|
305
|
+
},
|
|
306
|
+
$direction: 'asc',
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
}, { dontCollect: true, forUpdate: true });
|
|
310
|
+
(0, assert_1.default)(logs.length > 0);
|
|
311
|
+
for (const log2 of logs) {
|
|
312
|
+
await redoLog(log2, context);
|
|
313
|
+
}
|
|
314
|
+
return logs.length;
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
name: '当插入新的日志时,过去的rollbacked状态的日志可以删除',
|
|
319
|
+
entity: 'log',
|
|
320
|
+
action: 'create',
|
|
321
|
+
when: 'after',
|
|
322
|
+
fn: async ({ operation }, context, option) => {
|
|
323
|
+
const { data } = operation;
|
|
324
|
+
(0, assert_1.default)(!(data instanceof Array));
|
|
325
|
+
const { entity, entityId } = data;
|
|
326
|
+
const result = await context.operate('oper', {
|
|
327
|
+
id: 'dummy',
|
|
328
|
+
action: 'remove',
|
|
329
|
+
data: {},
|
|
330
|
+
filter: {
|
|
331
|
+
iState: 'rollbacked',
|
|
332
|
+
log: {
|
|
333
|
+
entity: entity,
|
|
334
|
+
entityId: entityId,
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
}, {});
|
|
338
|
+
const result2 = await context.operate('log', {
|
|
339
|
+
id: 'dummy',
|
|
340
|
+
action: 'remove',
|
|
341
|
+
data: {},
|
|
342
|
+
filter: {
|
|
343
|
+
entity: entity,
|
|
344
|
+
entityId: entityId,
|
|
345
|
+
iState: 'rollbacked',
|
|
346
|
+
},
|
|
347
|
+
}, {});
|
|
348
|
+
return (result.oper.remove || 0) + (result2.log.remove || 0);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
];
|
package/lib/types/AppLoader.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { IncomingHttpHeaders } from "http";
|
|
3
3
|
import { AsyncContext, AsyncRowStore } from "../store/AsyncRowStore";
|
|
4
4
|
import { EntityDict, OpRecord } from "./Entity";
|
|
5
|
-
|
|
5
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
6
|
+
export declare abstract class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
|
|
6
7
|
protected path: string;
|
|
7
8
|
constructor(path: string);
|
|
8
9
|
abstract execAspect(name: string, header?: IncomingHttpHeaders, contextString?: string, params?: any): Promise<{
|
package/lib/types/Aspect.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { EntityDict } from "./Entity";
|
|
2
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
2
3
|
import { OpRecord } from "./Entity";
|
|
3
4
|
import { AsyncContext } from "../store/AsyncRowStore";
|
|
4
|
-
export interface Aspect<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
|
|
5
|
+
export interface Aspect<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> {
|
|
5
6
|
(params: any, context: Cxt): Promise<any>;
|
|
6
7
|
}
|
|
7
|
-
export interface AspectWrapper<ED extends EntityDict, Cxt extends AsyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>> {
|
|
8
|
+
export interface AspectWrapper<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>> {
|
|
8
9
|
exec: <T extends keyof AD>(name: T, params: Parameters<AD[T]>[0], ignoreContext?: true) => Promise<{
|
|
9
10
|
result: Awaited<ReturnType<AD[T]>>;
|
|
10
11
|
opRecords?: OpRecord<ED>[];
|
package/lib/types/Auth.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ 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
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
5
6
|
import { ModiTurn } from './Trigger';
|
|
6
|
-
export type CheckerType = 'row' | 'data' | 'logical' | 'logicalData';
|
|
7
|
+
export type CheckerType = 'row' | 'data' | 'logical' | 'logicalData' | 'relation';
|
|
7
8
|
/**
|
|
8
9
|
* conditionalFilter是指该action发生时,operation所操作的行中有满足conditionalFilter的行
|
|
9
10
|
* 被转化成trigger的filter条件,详细可看trigger中的说明
|
|
10
11
|
*/
|
|
11
|
-
export type DataChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
12
|
+
export type DataChecker<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
12
13
|
priority?: number;
|
|
13
14
|
type: 'data';
|
|
14
15
|
entity: T;
|
|
@@ -16,7 +17,7 @@ export type DataChecker<ED extends EntityDict, T extends keyof ED, Cxt extends A
|
|
|
16
17
|
action: Omit<ED[T]['Action'], 'remove'> | Array<Omit<ED[T]['Action'], 'remove'>>;
|
|
17
18
|
checker: (data: Readonly<ED[T]['Create']['data'] | ED[T]['Update']['data']>, context: Cxt) => SyncOrAsync<any>;
|
|
18
19
|
};
|
|
19
|
-
export type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
20
|
+
export type RowChecker<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
20
21
|
priority?: number;
|
|
21
22
|
type: 'row';
|
|
22
23
|
entity: T;
|
|
@@ -30,7 +31,7 @@ export type RowChecker<ED extends EntityDict, T extends keyof ED, Cxt extends As
|
|
|
30
31
|
};
|
|
31
32
|
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Update']['filter']>);
|
|
32
33
|
};
|
|
33
|
-
export type LogicalChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
34
|
+
export type LogicalChecker<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {
|
|
34
35
|
priority?: number;
|
|
35
36
|
type: 'logical' | 'logicalData';
|
|
36
37
|
mt?: ModiTurn;
|
|
@@ -39,19 +40,19 @@ export type LogicalChecker<ED extends EntityDict, T extends keyof ED, Cxt extend
|
|
|
39
40
|
checker: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<any>;
|
|
40
41
|
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Update']['filter']>);
|
|
41
42
|
};
|
|
42
|
-
export type Checker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = DataChecker<ED, T, Cxt> | RowChecker<ED, T, Cxt> | LogicalChecker<ED, T, Cxt>;
|
|
43
|
-
export type AuthDef<ED extends EntityDict, T extends keyof ED> = {
|
|
43
|
+
export type Checker<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = DataChecker<ED, T, Cxt> | RowChecker<ED, T, Cxt> | LogicalChecker<ED, T, Cxt>;
|
|
44
|
+
export type AuthDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
|
|
44
45
|
relationAuth?: CascadeRelationAuth<NonNullable<ED[T]['Relation']>>;
|
|
45
46
|
actionAuth?: CascadeActionAuth<ED[T]['Action']>;
|
|
46
47
|
cascadeRemove?: {
|
|
47
48
|
[E in (keyof ED | keyof ED[T]['Schema'] | '@entity')]?: ActionOnRemove;
|
|
48
49
|
};
|
|
49
50
|
};
|
|
50
|
-
export type CascadeRemoveDefDict<ED extends EntityDict> = {
|
|
51
|
+
export type CascadeRemoveDefDict<ED extends EntityDict & BaseEntityDict> = {
|
|
51
52
|
[T in keyof ED]?: {
|
|
52
53
|
[E in (keyof ED | keyof ED[T]['Schema'] | '@entity')]?: ActionOnRemove;
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
|
-
export type AuthDefDict<ED extends EntityDict> = {
|
|
56
|
+
export type AuthDefDict<ED extends EntityDict & BaseEntityDict> = {
|
|
56
57
|
[K in keyof ED]?: AuthDef<ED, K>;
|
|
57
58
|
};
|
package/lib/types/Endpoint.d.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import { IncomingHttpHeaders, IncomingMessage } from "http";
|
|
3
3
|
import { AsyncContext } from "../store/AsyncRowStore";
|
|
4
4
|
import { EntityDict } from "./Entity";
|
|
5
|
-
|
|
5
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
6
|
+
export interface EndpointItem<ED extends EntityDict & BaseEntityDict, BackCxt extends AsyncContext<ED>> {
|
|
6
7
|
name: string;
|
|
7
8
|
params?: string[];
|
|
8
9
|
method: 'get' | 'post' | 'put' | 'delete';
|
|
9
10
|
fn: (context: BackCxt, params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<any>;
|
|
10
11
|
}
|
|
11
|
-
export type Endpoint<ED extends EntityDict, BackCxt extends AsyncContext<ED>> = EndpointItem<ED, BackCxt> | EndpointItem<ED, BackCxt>[];
|
|
12
|
+
export type Endpoint<ED extends EntityDict & BaseEntityDict, BackCxt extends AsyncContext<ED>> = EndpointItem<ED, BackCxt> | EndpointItem<ED, BackCxt>[];
|
package/lib/types/Entity.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export type OperateOption = {
|
|
|
39
39
|
allowExists?: boolean;
|
|
40
40
|
modiParentId?: string;
|
|
41
41
|
modiParentEntity?: string;
|
|
42
|
+
logId?: string;
|
|
42
43
|
deletePhysically?: boolean;
|
|
43
44
|
applyingModi?: boolean;
|
|
44
45
|
dummy?: 1;
|
|
@@ -161,6 +162,9 @@ export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
|
161
162
|
export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|
162
163
|
id: string;
|
|
163
164
|
a: 'r';
|
|
165
|
+
d: {
|
|
166
|
+
[DeleteAtAttribute]: number;
|
|
167
|
+
};
|
|
164
168
|
e: T;
|
|
165
169
|
f?: Filter;
|
|
166
170
|
};
|
|
@@ -18,7 +18,7 @@ export type AttrUpdateMatrix<ED extends EntityDict> = {
|
|
|
18
18
|
[T in keyof ED]?: {
|
|
19
19
|
[A in keyof ED[T]['Update']['data']]?: {
|
|
20
20
|
actions?: ED[T]['Action'][];
|
|
21
|
-
filter?: NonNullable<ED[T]['Selection']['filter']
|
|
21
|
+
filter?: (NonNullable<ED[T]['Selection']['filter']>) | ((action: ED[T]['Action']) => NonNullable<ED[T]['Selection']['filter']>);
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
};
|
package/lib/types/Exception.d.ts
CHANGED
|
@@ -169,6 +169,12 @@ export declare class OakExternalException<ED extends EntityDict & BaseEntityDict
|
|
|
169
169
|
constructor(source: string, code?: string, message?: string, data?: any);
|
|
170
170
|
toString(): string;
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* socket连接异常
|
|
174
|
+
*/
|
|
175
|
+
export declare class OakSocketConnectException<ED extends EntityDict & BaseEntityDict> extends OakUserException<ED> {
|
|
176
|
+
constructor(message?: string);
|
|
177
|
+
}
|
|
172
178
|
export declare function makeException<ED extends EntityDict & BaseEntityDict>(data: {
|
|
173
179
|
name: string;
|
|
174
180
|
message?: string;
|
package/lib/types/Exception.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakDataException = exports.OakPartialSuccess = exports.OakMakeSureByMySelfException = exports.OakException = void 0;
|
|
3
|
+
exports.makeException = exports.OakSocketConnectException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakDataException = exports.OakPartialSuccess = exports.OakMakeSureByMySelfException = exports.OakException = void 0;
|
|
4
4
|
const relation_1 = require("../store/relation");
|
|
5
5
|
const lodash_1 = require("../utils/lodash");
|
|
6
6
|
class OakException extends Error {
|
|
@@ -385,6 +385,16 @@ class OakExternalException extends OakUserException {
|
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
exports.OakExternalException = OakExternalException;
|
|
388
|
+
/**
|
|
389
|
+
* socket连接异常
|
|
390
|
+
*/
|
|
391
|
+
class OakSocketConnectException extends OakUserException {
|
|
392
|
+
constructor(message) {
|
|
393
|
+
super(message || '连接出现问题,请尝试刷新页面');
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
exports.OakSocketConnectException = OakSocketConnectException;
|
|
397
|
+
;
|
|
388
398
|
function makeException(data) {
|
|
389
399
|
const { name } = data;
|
|
390
400
|
let e = undefined;
|
|
@@ -473,6 +483,10 @@ function makeException(data) {
|
|
|
473
483
|
e = new OakServerProxyException(data.message);
|
|
474
484
|
break;
|
|
475
485
|
}
|
|
486
|
+
case 'OakSocketConnectException': {
|
|
487
|
+
e = new OakSocketConnectException(data.message);
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
476
490
|
default:
|
|
477
491
|
return;
|
|
478
492
|
}
|
package/lib/types/Port.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncContext } from "../store/AsyncRowStore";
|
|
2
2
|
import { EntityDict } from "./Entity";
|
|
3
|
-
|
|
3
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
4
|
+
export type Exportation<ED extends EntityDict & BaseEntityDict, T extends keyof ED, K extends string, Cxt extends AsyncContext<ED>> = {
|
|
4
5
|
name: string;
|
|
5
6
|
id: string;
|
|
6
7
|
entity: T;
|
|
@@ -9,7 +10,7 @@ export type Exportation<ED extends EntityDict, T extends keyof ED, K extends str
|
|
|
9
10
|
makeHeaders?: (dataList: Partial<ED[T]['Schema']>[]) => string[];
|
|
10
11
|
fn: (data: ED[T]['Schema'], context?: Cxt, properties?: Record<string, any>) => Promise<Partial<Record<string, string | number | boolean | null>>> | Partial<Record<string, string | number | boolean | null>>;
|
|
11
12
|
};
|
|
12
|
-
export type Importation<ED extends EntityDict, T extends keyof ED, K extends string, Cxt extends AsyncContext<ED>> = {
|
|
13
|
+
export type Importation<ED extends EntityDict & BaseEntityDict, T extends keyof ED, K extends string, Cxt extends AsyncContext<ED>> = {
|
|
13
14
|
name: string;
|
|
14
15
|
id: string;
|
|
15
16
|
entity: T;
|
package/lib/types/RowStore.d.ts
CHANGED
|
@@ -3,12 +3,13 @@ import { StorageSchema } from './Storage';
|
|
|
3
3
|
import { AsyncContext } from '../store/AsyncRowStore';
|
|
4
4
|
import { SyncContext } from '../store/SyncRowStore';
|
|
5
5
|
import { OperateOption, SelectOption } from '.';
|
|
6
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
6
7
|
export type TxnOption = {
|
|
7
8
|
isolationLevel: 'repeatable read' | 'serializable';
|
|
8
9
|
};
|
|
9
|
-
export type SelectionRewriter<ED extends EntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>, Op extends SelectOption> = (schema: StorageSchema<ED>, entity: keyof ED, selection: ED[keyof ED]['Selection'] | ED[keyof ED]['Aggregation'], context: Cxt, option: Op, isAggr?: true) => void | Promise<void>;
|
|
10
|
-
export type OperationRewriter<ED extends EntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>, Op extends OperateOption> = (schema: StorageSchema<ED>, entity: keyof ED, operate: ED[keyof ED]['Operation'], context: Cxt, option: Op) => void | Promise<void>;
|
|
11
|
-
export declare abstract class RowStore<ED extends EntityDict> {
|
|
10
|
+
export type SelectionRewriter<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>, Op extends SelectOption> = (schema: StorageSchema<ED>, entity: keyof ED, selection: ED[keyof ED]['Selection'] | ED[keyof ED]['Aggregation'], context: Cxt, option: Op, isAggr?: true) => void | Promise<void>;
|
|
11
|
+
export type OperationRewriter<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>, Op extends OperateOption> = (schema: StorageSchema<ED>, entity: keyof ED, operate: ED[keyof ED]['Operation'], context: Cxt, option: Op) => void | Promise<void>;
|
|
12
|
+
export declare abstract class RowStore<ED extends EntityDict & BaseEntityDict> {
|
|
12
13
|
protected storageSchema: StorageSchema<ED>;
|
|
13
14
|
constructor(storageSchema: StorageSchema<ED>);
|
|
14
15
|
abstract registerOperationRewriter(rewriter: OperationRewriter<ED, AsyncContext<ED> | SyncContext<ED>, SelectOption>): void;
|
package/lib/types/Storage.d.ts
CHANGED
package/lib/types/Timer.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule';
|
|
2
2
|
import { EntityDict } from './Entity';
|
|
3
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
4
|
import { AsyncContext } from '../store/AsyncRowStore';
|
|
4
5
|
import { Watcher } from './Watcher';
|
|
5
6
|
import { OperationResult } from '.';
|
|
6
|
-
type FreeOperateFn<ED extends EntityDict, Cxt extends AsyncContext<ED>> = (context: Cxt) => Promise<OperationResult<ED>>;
|
|
7
|
-
export type FreeRoutine<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
|
7
|
+
type FreeOperateFn<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = (context: Cxt) => Promise<OperationResult<ED>>;
|
|
8
|
+
export type FreeRoutine<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = {
|
|
8
9
|
name: string;
|
|
9
10
|
routine: FreeOperateFn<ED, Cxt>;
|
|
10
11
|
};
|
|
11
|
-
export type FreeTimer<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
|
12
|
+
export type FreeTimer<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = {
|
|
12
13
|
name: string;
|
|
13
14
|
cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number;
|
|
14
15
|
timer: FreeOperateFn<ED, Cxt>;
|
|
15
16
|
singleton?: true;
|
|
16
17
|
};
|
|
17
|
-
export type Routine<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> = FreeRoutine<ED, Cxt> | Watcher<ED, T, Cxt>;
|
|
18
|
-
export type Timer<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> = FreeTimer<ED, Cxt> | Watcher<ED, T, Cxt> & {
|
|
18
|
+
export type Routine<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> = FreeRoutine<ED, Cxt> | Watcher<ED, T, Cxt>;
|
|
19
|
+
export type Timer<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>> = FreeTimer<ED, Cxt> | Watcher<ED, T, Cxt> & {
|
|
19
20
|
cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number;
|
|
20
21
|
};
|
|
21
22
|
export {};
|