oak-domain 5.0.3 → 5.0.5
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/compiler/dependencyBuilder.js +1 -1
- package/lib/compiler/schemalBuilder.js +11 -1
- package/lib/store/AsyncRowStore.d.ts +1 -0
- package/lib/store/AsyncRowStore.js +4 -7
- package/lib/store/IntrinsicCheckers.js +13 -4
- package/lib/store/checker.js +4 -3
- package/lib/types/Exception.d.ts +9 -4
- package/lib/types/Exception.js +39 -40
- package/package.json +1 -1
|
@@ -199,7 +199,7 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
|
|
|
199
199
|
const { name, initializer } = vd;
|
|
200
200
|
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'e');
|
|
201
201
|
(0, assert_1.default)(ts.isCallExpression(initializer));
|
|
202
|
-
const callExpressions = briefNames.map(ele => factory.createCallExpression(factory.createIdentifier(`make${(0, string_1.firstLetterUpperCase)(ele)}Exception`), [factory.createTypeReferenceNode(factory.createIdentifier("
|
|
202
|
+
const callExpressions = briefNames.map(ele => factory.createCallExpression(factory.createIdentifier(`make${(0, string_1.firstLetterUpperCase)(ele)}Exception`), [factory.createTypeReferenceNode(factory.createIdentifier("ED"), undefined)], [factory.createIdentifier("data")]));
|
|
203
203
|
const rightExpression = callExpressions.length === 1 ? callExpressions[0] :
|
|
204
204
|
callExpressions.length === 2 ? factory.createBinaryExpression(callExpressions[0], factory.createToken(ts.SyntaxKind.BarBarToken), callExpressions[1]) : callExpressions.slice(2).reduce((prev, next) => factory.createBinaryExpression(prev, factory.createToken(ts.SyntaxKind.BarBarToken), next), factory.createBinaryExpression(callExpressions[0], factory.createToken(ts.SyntaxKind.BarBarToken), callExpressions[1]));
|
|
205
205
|
Object.assign(vd, {
|
|
@@ -289,7 +289,17 @@ function tryGetStringLiteralValues(moduleName, filename, obj, node, program) {
|
|
|
289
289
|
// 本地定义的type
|
|
290
290
|
const { name, type } = declaration;
|
|
291
291
|
if (ts.isUnionTypeNode(type)) {
|
|
292
|
-
values.push(...type.types.map(ele =>
|
|
292
|
+
values.push(...(type.types.map(ele => {
|
|
293
|
+
if (ts.isLiteralTypeNode(ele)) {
|
|
294
|
+
return checkStringLiteralLegal(filename, obj, name.text, ele);
|
|
295
|
+
}
|
|
296
|
+
else if (ts.isTypeReferenceNode(ele)) {
|
|
297
|
+
return tryGetStringLiteralValues(moduleName, filename, obj, ele, program);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
throw new Error(`暂时不能处理的type${ele.getText()}`);
|
|
301
|
+
}
|
|
302
|
+
})).flat());
|
|
293
303
|
}
|
|
294
304
|
else if (ts.isLiteralTypeNode(type)) {
|
|
295
305
|
const action = checkStringLiteralLegal(filename, obj, name.text, type);
|
|
@@ -50,6 +50,7 @@ export declare abstract class AsyncContext<ED extends EntityDict> implements Con
|
|
|
50
50
|
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
|
51
51
|
abstract setCurrentUserId(userId: string | undefined): void;
|
|
52
52
|
abstract toString(): Promise<string>;
|
|
53
|
+
protected abstract getSerializedData(): Promise<object>;
|
|
53
54
|
abstract initialize(data?: any, later?: boolean): Promise<void>;
|
|
54
55
|
abstract allowUserUpdate(): boolean;
|
|
55
56
|
abstract openRootMode(): () => void;
|
|
@@ -28,19 +28,16 @@ class AsyncContext {
|
|
|
28
28
|
}
|
|
29
29
|
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
|
30
30
|
async restartToExecute(routine) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
|
36
|
-
}
|
|
31
|
+
const data = await this.getSerializedData();
|
|
32
|
+
const newContext = (new (Object.getPrototypeOf(this).constructor)(this.rowStore));
|
|
33
|
+
await newContext.begin();
|
|
34
|
+
await newContext.initialize(data, true);
|
|
37
35
|
newContext.opRecords = [];
|
|
38
36
|
newContext.events = {
|
|
39
37
|
commit: [],
|
|
40
38
|
rollback: [],
|
|
41
39
|
};
|
|
42
40
|
newContext.opResult = {};
|
|
43
|
-
await newContext.begin();
|
|
44
41
|
try {
|
|
45
42
|
await routine(newContext);
|
|
46
43
|
await newContext.commit();
|
|
@@ -16,10 +16,10 @@ function checkUniqueBetweenRows(rows, uniqAttrs) {
|
|
|
16
16
|
let s = '';
|
|
17
17
|
for (const a of uniqAttrs) {
|
|
18
18
|
if (row[a] === null || row[a] === undefined) {
|
|
19
|
-
s
|
|
19
|
+
s += row.id;
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
s
|
|
22
|
+
s += `-${row[a]}`;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
if (dict[s]) {
|
|
@@ -188,7 +188,17 @@ function createActionTransformerCheckers(actionDefDict) {
|
|
|
188
188
|
type: 'row',
|
|
189
189
|
entity,
|
|
190
190
|
filter: conditionalFilter,
|
|
191
|
-
errMsg: '',
|
|
191
|
+
errMsg: '数据状态已经改变',
|
|
192
|
+
inconsistentRows: {
|
|
193
|
+
entity,
|
|
194
|
+
selection: (filter) => ({
|
|
195
|
+
data: {
|
|
196
|
+
id: 1,
|
|
197
|
+
[attr]: 1,
|
|
198
|
+
},
|
|
199
|
+
filter,
|
|
200
|
+
}),
|
|
201
|
+
},
|
|
192
202
|
});
|
|
193
203
|
// 这里用data类型的checker改数据了不太好,先这样
|
|
194
204
|
checkers.push({
|
|
@@ -331,7 +341,6 @@ function createAttrUpdateCheckers(schema, attrUpdateMatrix) {
|
|
|
331
341
|
}
|
|
332
342
|
if (f) {
|
|
333
343
|
const rr = (0, filter_1.contains)(entity, context.getSchema(), data, f);
|
|
334
|
-
console.log(rr);
|
|
335
344
|
const result = (0, filter_1.checkFilterContains)(entity, context, f, filter, true);
|
|
336
345
|
if (result instanceof Promise) {
|
|
337
346
|
return result.then((v) => {
|
package/lib/store/checker.js
CHANGED
|
@@ -68,7 +68,8 @@ function translateCheckerInAsyncContext(checker, schema) {
|
|
|
68
68
|
throw e;
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
|
|
71
|
+
// 可能会暴露隐私信息,暂时不能这样做。by Xc
|
|
72
|
+
/* const rows2 = await context.select(entity, {
|
|
72
73
|
data: getFullProjection(entity, context.getSchema()),
|
|
73
74
|
filter: Object.assign({}, operationFilter, {
|
|
74
75
|
$not: filter2,
|
|
@@ -76,9 +77,9 @@ function translateCheckerInAsyncContext(checker, schema) {
|
|
|
76
77
|
}, {
|
|
77
78
|
dontCollect: true,
|
|
78
79
|
blockTrigger: true,
|
|
79
|
-
});
|
|
80
|
+
}); */
|
|
80
81
|
const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg);
|
|
81
|
-
e.addData(entity, rows2);
|
|
82
|
+
// e.addData(entity, rows2);
|
|
82
83
|
throw e;
|
|
83
84
|
}
|
|
84
85
|
};
|
package/lib/types/Exception.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { EntityDict, OpRecord
|
|
1
|
+
import { EntityDict, OpRecord } from "./Entity";
|
|
2
2
|
export declare class OakException<ED extends EntityDict> extends Error {
|
|
3
|
-
|
|
3
|
+
opRecords: OpRecord<ED>[];
|
|
4
4
|
constructor(message?: string);
|
|
5
5
|
addData<T extends keyof ED>(entity: T, rows: Partial<ED[T]['OpSchema']>[]): void;
|
|
6
|
-
setOpRecords(
|
|
6
|
+
setOpRecords(opRecords: OpRecord<ED>[]): void;
|
|
7
|
+
getSerialData(): {
|
|
8
|
+
name: string;
|
|
9
|
+
message: string;
|
|
10
|
+
opRecords: OpRecord<ED>[];
|
|
11
|
+
};
|
|
7
12
|
toString(): string;
|
|
8
13
|
}
|
|
9
14
|
export declare class OakMakeSureByMySelfException<ED extends EntityDict> extends OakException<ED> {
|
|
@@ -158,6 +163,6 @@ export declare class OakExternalException<ED extends EntityDict> extends OakUser
|
|
|
158
163
|
export declare function makeException<ED extends EntityDict>(data: {
|
|
159
164
|
name: string;
|
|
160
165
|
message?: string;
|
|
161
|
-
opRecords:
|
|
166
|
+
opRecords: OpRecord<ED>[];
|
|
162
167
|
[A: string]: any;
|
|
163
168
|
}): OakException<ED> | undefined;
|
package/lib/types/Exception.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.makeException = exports.OakExternalException = exports.OakPreConditionUn
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
class OakException extends Error {
|
|
7
|
-
|
|
7
|
+
opRecords;
|
|
8
8
|
constructor(message) {
|
|
9
9
|
super(message);
|
|
10
10
|
this.name = new.target.name;
|
|
@@ -17,36 +17,32 @@ class OakException extends Error {
|
|
|
17
17
|
else {
|
|
18
18
|
this.__proto__ = new.target.prototype;
|
|
19
19
|
}
|
|
20
|
-
this.
|
|
21
|
-
a: 's',
|
|
22
|
-
d: {},
|
|
23
|
-
};
|
|
20
|
+
this.opRecords = [];
|
|
24
21
|
}
|
|
25
22
|
addData(entity, rows) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.assign(rowRoot[id], row);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
rowRoot[id] = row;
|
|
23
|
+
const record = {
|
|
24
|
+
a: 's',
|
|
25
|
+
d: {
|
|
26
|
+
[entity]: {},
|
|
34
27
|
}
|
|
35
28
|
};
|
|
36
|
-
|
|
37
|
-
d[entity] =
|
|
29
|
+
for (const row of rows) {
|
|
30
|
+
record.d[entity][row.id] = row;
|
|
38
31
|
}
|
|
39
|
-
|
|
32
|
+
this.opRecords.push(record);
|
|
40
33
|
}
|
|
41
|
-
setOpRecords(
|
|
42
|
-
this.
|
|
34
|
+
setOpRecords(opRecords) {
|
|
35
|
+
this.opRecords = opRecords;
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
37
|
+
getSerialData() {
|
|
38
|
+
return {
|
|
46
39
|
name: this.constructor.name,
|
|
47
40
|
message: this.message,
|
|
48
|
-
|
|
49
|
-
}
|
|
41
|
+
opRecords: this.opRecords,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
toString() {
|
|
45
|
+
return JSON.stringify(this.getSerialData());
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
exports.OakException = OakException;
|
|
@@ -85,9 +81,9 @@ class OakNoRelationDefException extends OakDataException {
|
|
|
85
81
|
this.actions = actions;
|
|
86
82
|
}
|
|
87
83
|
toString() {
|
|
84
|
+
const data = super.getSerialData();
|
|
88
85
|
return JSON.stringify({
|
|
89
|
-
|
|
90
|
-
message: this.message,
|
|
86
|
+
...data,
|
|
91
87
|
entity: this.entity,
|
|
92
88
|
action: this.actions,
|
|
93
89
|
});
|
|
@@ -105,7 +101,11 @@ class OakRowUnexistedException extends OakDataException {
|
|
|
105
101
|
this.rows = rows;
|
|
106
102
|
}
|
|
107
103
|
toString() {
|
|
108
|
-
|
|
104
|
+
const data = super.getSerialData();
|
|
105
|
+
return JSON.stringify({
|
|
106
|
+
...data,
|
|
107
|
+
rows: this.rows
|
|
108
|
+
});
|
|
109
109
|
}
|
|
110
110
|
getRows() {
|
|
111
111
|
return this.rows;
|
|
@@ -140,10 +140,8 @@ class OakRowInconsistencyException extends OakUserException {
|
|
|
140
140
|
(0, assert_1.default)(!data, '现在使用addData接口来传数据');
|
|
141
141
|
}
|
|
142
142
|
toString() {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
message: this.message,
|
|
146
|
-
});
|
|
143
|
+
const data = super.getSerialData();
|
|
144
|
+
return JSON.stringify(data);
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
exports.OakRowInconsistencyException = OakRowInconsistencyException;
|
|
@@ -169,10 +167,10 @@ class OakInputIllegalException extends OakUserException {
|
|
|
169
167
|
this.attributes = this.attributes.map(ele => `${prefix}.${ele}`);
|
|
170
168
|
}
|
|
171
169
|
toString() {
|
|
170
|
+
const data = super.getSerialData();
|
|
172
171
|
return JSON.stringify({
|
|
172
|
+
...data,
|
|
173
173
|
entity: this.entity,
|
|
174
|
-
name: this.constructor.name,
|
|
175
|
-
message: this.message,
|
|
176
174
|
attributes: this.attributes,
|
|
177
175
|
});
|
|
178
176
|
}
|
|
@@ -209,10 +207,10 @@ class OakUserUnpermittedException extends OakUserException {
|
|
|
209
207
|
this.operation = operation;
|
|
210
208
|
}
|
|
211
209
|
toString() {
|
|
210
|
+
const data = super.getSerialData();
|
|
212
211
|
return JSON.stringify({
|
|
212
|
+
...data,
|
|
213
213
|
entity: this.entity,
|
|
214
|
-
name: this.constructor.name,
|
|
215
|
-
message: this.message,
|
|
216
214
|
operation: this.operation,
|
|
217
215
|
});
|
|
218
216
|
}
|
|
@@ -231,10 +229,10 @@ class OakUserInvisibleException extends OakUserException {
|
|
|
231
229
|
this.operation = operation;
|
|
232
230
|
}
|
|
233
231
|
toString() {
|
|
232
|
+
const data = super.getSerialData();
|
|
234
233
|
return JSON.stringify({
|
|
234
|
+
...data,
|
|
235
235
|
entity: this.entity,
|
|
236
|
-
name: this.constructor.name,
|
|
237
|
-
message: this.message,
|
|
238
236
|
operation: this.operation,
|
|
239
237
|
});
|
|
240
238
|
}
|
|
@@ -279,9 +277,9 @@ class OakCongruentRowExists extends OakUserException {
|
|
|
279
277
|
return this.entity;
|
|
280
278
|
}
|
|
281
279
|
toString() {
|
|
280
|
+
const data = super.getSerialData();
|
|
282
281
|
return JSON.stringify({
|
|
283
|
-
|
|
284
|
-
message: this.message,
|
|
282
|
+
...data,
|
|
285
283
|
data: this.data,
|
|
286
284
|
entity: this.entity,
|
|
287
285
|
});
|
|
@@ -310,9 +308,9 @@ class OakPreConditionUnsetException extends OakUserException {
|
|
|
310
308
|
this.code = code;
|
|
311
309
|
}
|
|
312
310
|
toString() {
|
|
311
|
+
const data = super.getSerialData();
|
|
313
312
|
return JSON.stringify({
|
|
314
|
-
|
|
315
|
-
message: this.message,
|
|
313
|
+
...data,
|
|
316
314
|
code: this.code,
|
|
317
315
|
entity: this.entity,
|
|
318
316
|
});
|
|
@@ -333,9 +331,10 @@ class OakExternalException extends OakUserException {
|
|
|
333
331
|
this.data = data;
|
|
334
332
|
}
|
|
335
333
|
toString() {
|
|
334
|
+
const data = super.getSerialData();
|
|
336
335
|
return JSON.stringify({
|
|
336
|
+
...data,
|
|
337
337
|
code: this.code,
|
|
338
|
-
message: this.message,
|
|
339
338
|
source: this.source,
|
|
340
339
|
data: this.data,
|
|
341
340
|
});
|