修改commit的两个trigger

This commit is contained in:
Xu Chang 2023-10-10 12:09:23 +08:00
parent 7cba48f8ad
commit f7ea97cfcf
12 changed files with 38 additions and 135 deletions

View File

@ -25,7 +25,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
*
*/
protected initialized(): Promise<void>;
private initialize;
protected initialize(data?: SerializedData): Promise<void>;
getApplicationId(): ED["application"]["Schema"]["id"] | undefined;
getSystemId(): ED["application"]["Schema"]["systemId"] | undefined;
getApplication(): Partial<ED["application"]["Schema"]> | undefined;
@ -34,7 +34,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
getToken(allowUnloggedIn?: boolean): Partial<ED["token"]["Schema"]> | undefined;
getCurrentUserId(allowUnloggedIn?: boolean): string;
setTemporaryUserId(userId: string | undefined): void;
toString(): string;
protected getSerializedData(): SerializedData;
isRoot(): boolean;
isReallyRoot(): boolean;
sendMessage(data: ED['message']['CreateSingle']['data']): Promise<import("oak-domain").OperationResult<ED>>;

View File

@ -189,11 +189,14 @@ export class BackendRuntimeContext extends BRC {
setTemporaryUserId(userId) {
this.temporaryUserId = userId;
}
toString() {
if (this.rootMode) {
return JSON.stringify({ rootMode: true });
}
return JSON.stringify({ a: this.application?.id, t: this.token?.id });
getSerializedData() {
const data = super.getSerializedData();
return {
...data,
a: this.application?.id,
t: this.token?.id,
rm: this.rootMode,
};
}
isRoot() {
if (this.rootMode) {

View File

@ -11,6 +11,7 @@ export type AspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
export interface SerializedData extends Fsd {
a?: string;
t?: string;
rm?: boolean;
}
export declare abstract class FrontendRuntimeContext<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Frc<ED, Cxt, AD> implements RuntimeContext {
private application;

View File

@ -33,36 +33,8 @@ const triggers = [
strict: 'makeSure',
entity: 'extraFile',
action: 'remove',
fn: async ({ operation }, context) => {
const { filter } = operation;
const extraFileList = await context.select('extraFile', {
data: {
id: 1,
origin: 1,
type: 1,
bucket: 1,
objectId: 1,
tag1: 1,
tag2: 1,
filename: 1,
md5: 1,
entity: 1,
entityId: 1,
extra1: 1,
extension: 1,
size: 1,
sort: 1,
fileType: 1,
isBridge: 1,
uploadState: 1,
uploadMeta: 1,
},
filter,
}, {
includedDeleted: true,
dontCollect: true,
});
for (const extraFile of extraFileList) {
fn: async ({ rows }, context) => {
for (const extraFile of rows) {
const { origin } = extraFile;
const uploader = getCos(origin);
await uploader.removeFile(extraFile, context);

View File

@ -240,17 +240,11 @@ const triggers = [
action: 'create',
when: 'commit',
strict: 'takeEasy',
fn: async ({ operation }, context) => {
const { data } = operation;
fn: async ({ rows }, context) => {
const closeRootMode = context.openRootMode();
try {
if (data instanceof Array) {
for (const d of data) {
await sendNotification(d, context);
}
}
else {
await sendNotification(data, context);
for (const row of rows) {
await sendNotification(row, context);
}
}
catch (err) {

View File

@ -25,7 +25,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
*
*/
protected initialized(): Promise<void>;
private initialize;
protected initialize(data?: SerializedData): Promise<void>;
getApplicationId(): ED["application"]["Schema"]["id"] | undefined;
getSystemId(): ED["application"]["Schema"]["systemId"] | undefined;
getApplication(): Partial<ED["application"]["Schema"]> | undefined;
@ -34,7 +34,7 @@ export declare abstract class BackendRuntimeContext<ED extends EntityDict & Base
getToken(allowUnloggedIn?: boolean): Partial<ED["token"]["Schema"]> | undefined;
getCurrentUserId(allowUnloggedIn?: boolean): string;
setTemporaryUserId(userId: string | undefined): void;
toString(): string;
protected getSerializedData(): SerializedData;
isRoot(): boolean;
isReallyRoot(): boolean;
sendMessage(data: ED['message']['CreateSingle']['data']): Promise<import("oak-domain").OperationResult<ED>>;

View File

@ -192,11 +192,14 @@ class BackendRuntimeContext extends oak_frontend_base_1.BackendRuntimeContext {
setTemporaryUserId(userId) {
this.temporaryUserId = userId;
}
toString() {
if (this.rootMode) {
return JSON.stringify({ rootMode: true });
}
return JSON.stringify({ a: this.application?.id, t: this.token?.id });
getSerializedData() {
const data = super.getSerializedData();
return {
...data,
a: this.application?.id,
t: this.token?.id,
rm: this.rootMode,
};
}
isRoot() {
if (this.rootMode) {

View File

@ -11,6 +11,7 @@ export type AspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
export interface SerializedData extends Fsd {
a?: string;
t?: string;
rm?: boolean;
}
export declare abstract class FrontendRuntimeContext<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>, AD extends AspectDict<ED, Cxt>> extends Frc<ED, Cxt, AD> implements RuntimeContext {
private application;

View File

@ -35,36 +35,8 @@ const triggers = [
strict: 'makeSure',
entity: 'extraFile',
action: 'remove',
fn: async ({ operation }, context) => {
const { filter } = operation;
const extraFileList = await context.select('extraFile', {
data: {
id: 1,
origin: 1,
type: 1,
bucket: 1,
objectId: 1,
tag1: 1,
tag2: 1,
filename: 1,
md5: 1,
entity: 1,
entityId: 1,
extra1: 1,
extension: 1,
size: 1,
sort: 1,
fileType: 1,
isBridge: 1,
uploadState: 1,
uploadMeta: 1,
},
filter,
}, {
includedDeleted: true,
dontCollect: true,
});
for (const extraFile of extraFileList) {
fn: async ({ rows }, context) => {
for (const extraFile of rows) {
const { origin } = extraFile;
const uploader = (0, cos_1.getCos)(origin);
await uploader.removeFile(extraFile, context);

View File

@ -242,17 +242,11 @@ const triggers = [
action: 'create',
when: 'commit',
strict: 'takeEasy',
fn: async ({ operation }, context) => {
const { data } = operation;
fn: async ({ rows }, context) => {
const closeRootMode = context.openRootMode();
try {
if (data instanceof Array) {
for (const d of data) {
await sendNotification(d, context);
}
}
else {
await sendNotification(data, context);
for (const row of rows) {
await sendNotification(row, context);
}
}
catch (err) {

View File

@ -41,40 +41,8 @@ const triggers: Trigger<EntityDict, 'extraFile', BackendRuntimeContext<EntityDic
strict: 'makeSure',
entity: 'extraFile',
action: 'remove',
fn: async ({ operation }, context) => {
const { filter } = operation;
const extraFileList = await context.select(
'extraFile',
{
data: {
id: 1,
origin: 1,
type: 1,
bucket: 1,
objectId: 1,
tag1: 1,
tag2: 1,
filename: 1,
md5: 1,
entity: 1,
entityId: 1,
extra1: 1,
extension: 1,
size: 1,
sort: 1,
fileType: 1,
isBridge: 1,
uploadState: 1,
uploadMeta: 1,
},
filter,
},
{
includedDeleted: true,
dontCollect: true,
}
);
for (const extraFile of extraFileList) {
fn: async ({ rows }, context) => {
for (const extraFile of rows) {
const { origin } = extraFile;
const uploader = getCos(origin!);
await uploader.removeFile(extraFile as EntityDict['extraFile']['OpSchema'], context);

View File

@ -12,7 +12,7 @@ import { sendSms } from '../utils/sms';
import { tryMakeSmsNotification } from './message';
import { composeDomainUrl } from '../utils/domain';
async function sendNotification(notification: CreateNotificationData, context: BackendRuntimeContext<EntityDict>) {
async function sendNotification(notification: EntityDict['notification']['OpSchema'], context: BackendRuntimeContext<EntityDict>) {
const { data, templateId, channel, messageSystemId, data1, id } = notification;
const [messageSystem] = await context.select('messageSystem', {
data: {
@ -281,16 +281,11 @@ const triggers: Trigger<EntityDict, 'notification', BackendRuntimeContext<Entity
action: 'create',
when: 'commit',
strict: 'takeEasy',
fn: async ({ operation }, context) => {
const { data } = operation;
fn: async ({ rows }, context) => {
const closeRootMode = context.openRootMode();
try {
if (data instanceof Array) {
for (const d of data) {
await sendNotification(d, context);
}
} else {
await sendNotification(data, context);
for (const row of rows) {
await sendNotification(row, context);
}
} catch (err) {
closeRootMode();