Merge branch 'release'
This commit is contained in:
commit
52cc5ec550
|
|
@ -199,7 +199,7 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
|
|||
const { name, initializer } = vd;
|
||||
(0, assert_1.default)(ts.isIdentifier(name) && name.text === 'e');
|
||||
(0, assert_1.default)(ts.isCallExpression(initializer));
|
||||
const callExpressions = briefNames.map(ele => factory.createCallExpression(factory.createIdentifier(`make${(0, string_1.firstLetterUpperCase)(ele)}Exception`), [factory.createTypeReferenceNode(factory.createIdentifier("EntityDict"), undefined)], [factory.createIdentifier("data")]));
|
||||
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")]));
|
||||
const rightExpression = callExpressions.length === 1 ? callExpressions[0] :
|
||||
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]));
|
||||
Object.assign(vd, {
|
||||
|
|
|
|||
|
|
@ -289,7 +289,17 @@ function tryGetStringLiteralValues(moduleName, filename, obj, node, program) {
|
|||
// 本地定义的type
|
||||
const { name, type } = declaration;
|
||||
if (ts.isUnionTypeNode(type)) {
|
||||
values.push(...type.types.map(ele => checkStringLiteralLegal(filename, obj, name.text, ele)));
|
||||
values.push(...(type.types.map(ele => {
|
||||
if (ts.isLiteralTypeNode(ele)) {
|
||||
return checkStringLiteralLegal(filename, obj, name.text, ele);
|
||||
}
|
||||
else if (ts.isTypeReferenceNode(ele)) {
|
||||
return tryGetStringLiteralValues(moduleName, filename, obj, ele, program);
|
||||
}
|
||||
else {
|
||||
throw new Error(`暂时不能处理的type${ele.getText()}`);
|
||||
}
|
||||
})).flat());
|
||||
}
|
||||
else if (ts.isLiteralTypeNode(type)) {
|
||||
const action = checkStringLiteralLegal(filename, obj, name.text, type);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ export declare abstract class AsyncContext<ED extends EntityDict> implements Con
|
|||
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
||||
abstract setCurrentUserId(userId: string | undefined): void;
|
||||
abstract toString(): Promise<string>;
|
||||
protected abstract getSerializedData(): Promise<object>;
|
||||
abstract initialize(data?: any, later?: boolean): Promise<void>;
|
||||
abstract allowUserUpdate(): boolean;
|
||||
abstract openRootMode(): () => void;
|
||||
|
|
|
|||
|
|
@ -28,19 +28,16 @@ class AsyncContext {
|
|||
}
|
||||
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
||||
async restartToExecute(routine) {
|
||||
const newContext = !this.uuid ? this : {
|
||||
...this,
|
||||
}; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
|
||||
if (newContext !== this) {
|
||||
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
||||
}
|
||||
const data = await this.getSerializedData();
|
||||
const newContext = (new (Object.getPrototypeOf(this).constructor)(this.rowStore));
|
||||
await newContext.begin();
|
||||
await newContext.initialize(data, true);
|
||||
newContext.opRecords = [];
|
||||
newContext.events = {
|
||||
commit: [],
|
||||
rollback: [],
|
||||
};
|
||||
newContext.opResult = {};
|
||||
await newContext.begin();
|
||||
try {
|
||||
await routine(newContext);
|
||||
await newContext.commit();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-domain",
|
||||
"version": "5.0.3",
|
||||
"version": "5.0.4",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ function outputDependentExceptions(
|
|||
ele => factory.createCallExpression(
|
||||
factory.createIdentifier(`make${firstLetterUpperCase(ele)}Exception`),
|
||||
[factory.createTypeReferenceNode(
|
||||
factory.createIdentifier("EntityDict"),
|
||||
factory.createIdentifier("ED"),
|
||||
undefined
|
||||
)],
|
||||
[factory.createIdentifier("data")]
|
||||
|
|
|
|||
|
|
@ -443,9 +443,19 @@ function tryGetStringLiteralValues(
|
|||
const { name, type } = declaration;
|
||||
|
||||
if (ts.isUnionTypeNode(type)) {
|
||||
values.push(...type.types!.map(
|
||||
ele => checkStringLiteralLegal(filename, obj, (<ts.Identifier>name).text, ele)
|
||||
));
|
||||
values.push(...(type.types!.map(
|
||||
ele => {
|
||||
if (ts.isLiteralTypeNode(ele)) {
|
||||
return checkStringLiteralLegal(filename, obj, (<ts.Identifier>name).text, ele);
|
||||
}
|
||||
else if(ts.isTypeReferenceNode(ele)){
|
||||
return tryGetStringLiteralValues(moduleName, filename, obj, ele, program);
|
||||
}
|
||||
else {
|
||||
throw new Error(`暂时不能处理的type${ele.getText()}`)
|
||||
}
|
||||
}
|
||||
)).flat());
|
||||
}
|
||||
else if (ts.isLiteralTypeNode(type!)) {
|
||||
const action = checkStringLiteralLegal(filename, obj, (<ts.Identifier>name).text, type);
|
||||
|
|
|
|||
|
|
@ -38,12 +38,10 @@ export abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|||
|
||||
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
||||
async restartToExecute(routine: (context: this) => Promise<any>) {
|
||||
const newContext = !this.uuid ? this : {
|
||||
...this,
|
||||
}; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
|
||||
if (newContext !== this) {
|
||||
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
||||
}
|
||||
const data = await this.getSerializedData();
|
||||
const newContext = (new (Object.getPrototypeOf(this).constructor)(this.rowStore)) as typeof this;
|
||||
await newContext.begin();
|
||||
await newContext.initialize(data, true);
|
||||
|
||||
newContext.opRecords = [];
|
||||
newContext.events = {
|
||||
|
|
@ -52,7 +50,6 @@ export abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|||
};
|
||||
newContext.opResult = {};
|
||||
|
||||
await newContext.begin();
|
||||
try {
|
||||
await routine(newContext);
|
||||
await newContext.commit();
|
||||
|
|
@ -233,6 +230,8 @@ export abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|||
// 此接口将上下文变成可以serialized的字符串
|
||||
abstract toString(): Promise<string>;
|
||||
|
||||
protected abstract getSerializedData(): Promise<object>;
|
||||
|
||||
// 此接口将字符串parse成对象再进行初始化
|
||||
// later表示允许延时状态,上下文要处理在时间维度上可能的异常(比如用户token已经注销等)
|
||||
abstract initialize(data?: any, later?: boolean): Promise<void>;
|
||||
|
|
|
|||
Loading…
Reference in New Issue