Merge branch 'dev' of codeup.aliyun.com:61c14a7efa282c88e103c23f/oak-general-business into dev

This commit is contained in:
Xu Chang 2022-09-09 18:57:36 +08:00
commit d2b5d97db2
37 changed files with 183 additions and 32 deletions

View File

@ -49,5 +49,6 @@ export declare abstract class GeneralRuntimeContext<ED extends EntityDict> exten
scene: any;
token: any;
};
isRoot(): Promise<boolean>;
}
export {};

View File

@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
var UniversalContext_1 = require("oak-domain/lib/store/UniversalContext");
var concurrent_1 = require("oak-domain/lib/utils/concurrent");
var assert_1 = require("oak-domain/lib/utils/assert");
var constants_1 = require("./constants");
var GeneralRuntimeContext = /** @class */ (function (_super) {
tslib_1.__extends(GeneralRuntimeContext, _super);
function GeneralRuntimeContext(store, applicationId) {
@ -100,7 +101,7 @@ var GeneralRuntimeContext = /** @class */ (function (_super) {
filter: {
id: tokenValue,
ableState: 'enabled',
}
},
}, this, {})];
case 1:
_a = tslib_1.__read.apply(void 0, [(_b.sent()).result, 1]), token = _a[0];
@ -156,6 +157,47 @@ var GeneralRuntimeContext = /** @class */ (function (_super) {
token: token,
};
};
GeneralRuntimeContext.prototype.isRoot = function () {
var _a, _b, _c;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var tokenValue, _d, token;
return tslib_1.__generator(this, function (_e) {
switch (_e.label) {
case 0:
tokenValue = this.token;
if (!tokenValue) {
return [2 /*return*/, false];
}
return [4 /*yield*/, this.rowStore.select('token', {
data: {
id: 1,
userId: 1,
ableState: 1,
player: {
id: 1,
userRole$user: {
$entity: 'userRole',
data: {
id: 1,
userId: 1,
roleId: 1,
},
},
},
},
filter: {
id: tokenValue,
},
}, this, {})];
case 1:
_d = tslib_1.__read.apply(void 0, [(_e.sent()).result, 1]), token = _d[0];
return [2 /*return*/, ((_a = token === null || token === void 0 ? void 0 : token.player) === null || _a === void 0 ? void 0 : _a.userRole$user).length > 0
? ((_c = ((_b = token === null || token === void 0 ? void 0 : token.player) === null || _b === void 0 ? void 0 : _b.userRole$user)[0]) === null || _c === void 0 ? void 0 : _c.roleId) === constants_1.ROOT_ROLE_ID
: false];
}
});
});
};
return GeneralRuntimeContext;
}(UniversalContext_1.UniversalContext));
exports.GeneralRuntimeContext = GeneralRuntimeContext;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1,2 +1,3 @@
/// <reference types="react" />
import '@wangeditor/editor/dist/css/style.css';
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -6,6 +6,7 @@ import { RowStore } from 'oak-domain/lib/types';
import { RWLock } from 'oak-domain/lib/utils/concurrent';
import { assert } from 'oak-domain/lib/utils/assert';
import { ROOT_ROLE_ID } from './constants';
type AppType = SelectRowShape<EntityDict['application']['Schema'], {
id: 1,
@ -20,13 +21,18 @@ type AppType = SelectRowShape<EntityDict['application']['Schema'], {
},
}>;
export abstract class GeneralRuntimeContext<ED extends EntityDict> extends UniversalContext<ED> {
export abstract class GeneralRuntimeContext<
ED extends EntityDict
> extends UniversalContext<ED> {
private applicationId?: string;
private application?: AppType;
private token?: string;
private rwLockApplication: RWLock;
constructor(store: RowStore<ED, GeneralRuntimeContext<ED>>, applicationId?: string) {
constructor(
store: RowStore<ED, GeneralRuntimeContext<ED>>,
applicationId?: string
) {
super(store);
this.rwLockApplication = new RWLock();
this.applicationId = applicationId;
@ -53,25 +59,31 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
await this.rwLockApplication.acquire('X');
if (this.application) {
result = this.application;
}
else if (this.applicationId) {
const { result: [application]} = await this.rowStore.select('application', {
data: {
id: 1,
name: 1,
config: 1,
type: 1,
systemId: 1,
system: {
} else if (this.applicationId) {
const {
result: [application],
} = await this.rowStore.select(
'application',
{
data: {
id: 1,
name: 1,
config: 1,
type: 1,
systemId: 1,
system: {
id: 1,
name: 1,
config: 1,
},
},
filter: {
id: this.applicationId,
},
},
filter: {
id: this.applicationId,
},
}, this, {});
this,
{}
);
result = application as AppType;
this.application = application as AppType;
}
@ -89,17 +101,27 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
async getToken() {
const tokenValue = this.token;
if (tokenValue) {
const { result: [token] } = await this.rowStore.select('token', {
data: {
id: 1,
userId: 1,
playerId: 1,
const {
result: [token],
} = (await this.rowStore.select(
'token',
{
data: {
id: 1,
userId: 1,
playerId: 1,
},
filter: {
id: tokenValue,
ableState: 'enabled',
},
},
filter: {
id: tokenValue,
ableState: 'enabled',
}
}, this, {}) as SelectionResult<ED['token']['Schema'], { id: 1, userId: 1, playerId: 1 }>;
this,
{}
)) as SelectionResult<
ED['token']['Schema'],
{ id: 1; userId: 1; playerId: 1 }
>;
return token;
}
@ -133,11 +155,7 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
}
protected static fromString(strCxt: string) {
const {
applicationId,
scene,
token,
} = JSON.parse(strCxt);
const { applicationId, scene, token } = JSON.parse(strCxt);
return {
applicationId,
@ -145,4 +163,60 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
token,
};
}
async isRoot(): Promise<boolean> {
const tokenValue = this.token;
if (!tokenValue) {
return false;
}
const {
result: [token],
} = (await this.rowStore.select(
'token',
{
data: {
id: 1,
userId: 1,
ableState: 1,
player: {
id: 1,
userRole$user: {
$entity: 'userRole',
data: {
id: 1,
userId: 1,
roleId: 1,
},
},
},
},
filter: {
id: tokenValue,
},
},
this,
{}
)) as SelectionResult<
ED['token']['Schema'],
{
id: 1;
userId: 1;
ableState: 1;
player: {
id: 1;
userRole$user: {
$entity: 'userRole';
data: {
id: 1;
userId: 1;
roleId: 1;
};
};
};
}
>;
return (token?.player?.userRole$user as any).length > 0
? (token?.player?.userRole$user as any)[0]?.roleId === ROOT_ROLE_ID
: false;
}
};