runtimeContext的声明修正
This commit is contained in:
parent
d6a67f7c57
commit
d7e0d255a6
|
|
@ -15,12 +15,12 @@ declare type AppType = SelectRowShape<EntityDict['application']['Schema'], {
|
|||
};
|
||||
}>;
|
||||
export declare abstract class GeneralRuntimeContext<ED extends EntityDict> extends UniversalContext<ED> {
|
||||
private applicationId?;
|
||||
private application?;
|
||||
private token?;
|
||||
private rwLockApplication;
|
||||
constructor(store: RowStore<ED, GeneralRuntimeContext<ED>>, applicationId?: string);
|
||||
private loadApplication;
|
||||
getApplicationId(): string;
|
||||
getApplicationId(): string | undefined;
|
||||
getSystemId(): string;
|
||||
setToken(token?: string): void;
|
||||
getApplication(): Promise<SelectRowShape<import("general-app-domain/Application/Schema").Schema, {
|
||||
|
|
@ -34,7 +34,7 @@ export declare abstract class GeneralRuntimeContext<ED extends EntityDict> exten
|
|||
name: 1;
|
||||
config: 1;
|
||||
};
|
||||
}>>;
|
||||
}> | undefined>;
|
||||
setApplication(app: AppType): void;
|
||||
getToken(): Promise<SelectRowShape<ED["token"]["Schema"], {
|
||||
id: 1;
|
||||
|
|
|
|||
|
|
@ -9,41 +9,20 @@ const lodash_1 = require("lodash");
|
|||
const concurrent_1 = require("oak-domain/lib/utils/concurrent");
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
|
||||
applicationId;
|
||||
application;
|
||||
token;
|
||||
rwLockApplication;
|
||||
constructor(store, applicationId) {
|
||||
super(store);
|
||||
this.rwLockApplication = new concurrent_1.RWLock();
|
||||
this.rwLockApplication.acquire('X');
|
||||
if (applicationId) {
|
||||
this.loadApplication(applicationId);
|
||||
this.applicationId = applicationId;
|
||||
if (!applicationId) {
|
||||
this.rwLockApplication.acquire('X');
|
||||
}
|
||||
}
|
||||
async loadApplication(id) {
|
||||
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);
|
||||
this.application = application;
|
||||
this.rwLockApplication.release();
|
||||
}
|
||||
getApplicationId() {
|
||||
const result = this.application?.id;
|
||||
return result;
|
||||
return this.applicationId;
|
||||
}
|
||||
getSystemId() {
|
||||
return this.application.systemId;
|
||||
|
|
@ -52,14 +31,39 @@ class GeneralRuntimeContext extends UniversalContext_1.UniversalContext {
|
|||
this.token = token;
|
||||
}
|
||||
async getApplication() {
|
||||
await this.rwLockApplication.acquire('S');
|
||||
const result = this.application;
|
||||
let result;
|
||||
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: {
|
||||
id: 1,
|
||||
name: 1,
|
||||
config: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: this.applicationId,
|
||||
},
|
||||
}, this);
|
||||
result = application;
|
||||
this.application = application;
|
||||
}
|
||||
this.rwLockApplication.release();
|
||||
return result;
|
||||
}
|
||||
setApplication(app) {
|
||||
(0, assert_1.default)(!this.application);
|
||||
this.application = app;
|
||||
this.applicationId = app.id;
|
||||
this.rwLockApplication.release();
|
||||
}
|
||||
async getToken() {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ exports.createWechatQrCode = void 0;
|
|||
const assert_1 = __importDefault(require("assert"));
|
||||
async function createWechatQrCode(options, context) {
|
||||
const { entity, entityId, applicationId, tag, lifetimeLength, permanent, props } = options;
|
||||
const { type: appType, config } = await context.getApplication();
|
||||
const { type: appType, config } = (await context.getApplication());
|
||||
if (appType === 'wechatMp') {
|
||||
const { qrCodePrefix } = config;
|
||||
const id = await generateNewId();
|
||||
|
|
|
|||
|
|
@ -96,22 +96,25 @@ const triggers = [
|
|||
when: 'before',
|
||||
fn: async ({ operation }, context) => {
|
||||
const app = await context.getApplication();
|
||||
const { filter } = operation;
|
||||
if (!filter) {
|
||||
(0, lodash_1.assign)(operation, {
|
||||
filter: {
|
||||
systemId: app.systemId,
|
||||
},
|
||||
});
|
||||
if (app) {
|
||||
const { filter } = operation;
|
||||
if (!filter) {
|
||||
(0, lodash_1.assign)(operation, {
|
||||
filter: {
|
||||
systemId: app.systemId,
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
(0, lodash_1.assign)(operation, {
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
systemId: app.systemId,
|
||||
}, filter),
|
||||
});
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
(0, lodash_1.assign)(operation, {
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
systemId: app.systemId,
|
||||
}, filter),
|
||||
});
|
||||
}
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const triggers = [
|
|||
const { data, filter } = operation;
|
||||
const fn = async (userEntityGrantData) => {
|
||||
const { userId } = (await context.getToken());
|
||||
const { id: applicationId, config: appConfig, system: { config: SystemConfig } } = await context.getApplication();
|
||||
const { id: applicationId, config: appConfig, system: { config: SystemConfig } } = (await context.getApplication());
|
||||
(0, assert_1.default)(userId);
|
||||
const { type, entity, entityId, relation, id } = userEntityGrantData;
|
||||
const { result } = await context.rowStore.select('userEntityGrant', {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ export abstract class GeneralRuntimeContext<ED extends EntityDict> extends Unive
|
|||
id: this.applicationId,
|
||||
},
|
||||
}, this);
|
||||
result = application;
|
||||
result = application as AppType;
|
||||
this.application = application as AppType;
|
||||
}
|
||||
this.rwLockApplication.release();
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ export async function loginWechatMp<ED extends EntityDict, Cxt extends GeneralRu
|
|||
id,
|
||||
userId: wechatUser2.userId as string,
|
||||
playerId: wechatUser2.userId as string,
|
||||
applicationId: application.id,
|
||||
applicationId: application!.id,
|
||||
entity: 'wechatUser',
|
||||
entityId: wechatUser2.id as string,
|
||||
wechatUser: {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ const triggers: Trigger<EntityDict, 'userEntityGrant', GeneralRuntimeContext<Ent
|
|||
expired: false,
|
||||
});
|
||||
// 如果是微信体系的应用,为之创建一个默认的weChatQrCode
|
||||
if (['wechatPublic', 'wechatMp'].includes(appConfig.type)) {
|
||||
if (['wechatPublic', 'wechatMp'].includes(appConfig!.type)) {
|
||||
await createWechatQrCode(
|
||||
{
|
||||
entity: 'userEntityGrant',
|
||||
|
|
|
|||
Loading…
Reference in New Issue