cache暴露了registerSelectionRewriter的接口

This commit is contained in:
Xu Chang 2025-09-03 22:58:20 +08:00
parent 2df8fec88e
commit 89514145e4
9 changed files with 101 additions and 17 deletions

View File

@ -1,4 +1,4 @@
import { EntityDict, OperateOption, SelectOption, OpRecord, CheckerType, Aspect, StorageSchema, Checker, Connector, AggregationResult } from 'oak-domain/lib/types';
import { EntityDict, OperateOption, SelectOption, OpRecord, CheckerType, Aspect, StorageSchema, Checker, Connector, AggregationResult, SelectionRewriter, OperationRewriter } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AspectDict as CommonAspectDict } from 'oak-common-aspect';
import { Feature } from '../types/Feature';
@ -36,6 +36,8 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict> extends Featu
private connector;
private baseRelationAuth;
private entityActionAuthDict;
registerSelectionRewriter(rewriter: SelectionRewriter<ED, AsyncContext<ED> | SyncContext<ED>, SelectOption>): void;
registerOperationRewriter(rewriter: OperationRewriter<ED, AsyncContext<ED> | SyncContext<ED>, OperateOption>): void;
constructor(storageSchema: StorageSchema<ED>, connector: Connector<ED, SyncContext<ED>>, frontendContextBuilder: (store: CacheStore<ED>) => SyncContext<ED>, checkers: Array<Checker<ED, keyof ED, SyncContext<ED>>>, localStorage: LocalStorage, common: CommonConfiguration<ED>);
/**
* cache中需要缓存的数据

View File

@ -24,6 +24,12 @@ export class Cache extends Feature {
baseRelationAuth;
// 缓存在某一时间戳状态下对某行进行某个action的判断结果
entityActionAuthDict;
registerSelectionRewriter(rewriter) {
this.cacheStore.registerSelectionRewriter(rewriter);
}
registerOperationRewriter(rewriter) {
this.cacheStore.registerOperationRewriter(rewriter);
}
constructor(storageSchema, connector, frontendContextBuilder, checkers, localStorage, common) {
super();
this.syncEventsCallbacks = [];

View File

@ -211,7 +211,7 @@ export class SubScriber extends Feature {
}
});
invalidEvents.forEach(event => unset(this.eventMap, event));
if (this.socketState === 'connected') {
if (this.socketState === 'connected' || this.socketState === 'connecting') {
this.socket.emit('unsub', events);
if (Object.keys(this.eventMap).length === 0) {
this.socket.disconnect();

View File

@ -1,4 +1,4 @@
import { EntityDict, OperateOption, SelectOption, OpRecord, CheckerType, Aspect, StorageSchema, Checker, Connector, AggregationResult } from 'oak-domain/lib/types';
import { EntityDict, OperateOption, SelectOption, OpRecord, CheckerType, Aspect, StorageSchema, Checker, Connector, AggregationResult, SelectionRewriter, OperationRewriter } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AspectDict as CommonAspectDict } from 'oak-common-aspect';
import { Feature } from '../types/Feature';
@ -36,6 +36,8 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict> extends Featu
private connector;
private baseRelationAuth;
private entityActionAuthDict;
registerSelectionRewriter(rewriter: SelectionRewriter<ED, AsyncContext<ED> | SyncContext<ED>, SelectOption>): void;
registerOperationRewriter(rewriter: OperationRewriter<ED, AsyncContext<ED> | SyncContext<ED>, OperateOption>): void;
constructor(storageSchema: StorageSchema<ED>, connector: Connector<ED, SyncContext<ED>>, frontendContextBuilder: (store: CacheStore<ED>) => SyncContext<ED>, checkers: Array<Checker<ED, keyof ED, SyncContext<ED>>>, localStorage: LocalStorage, common: CommonConfiguration<ED>);
/**
* cache中需要缓存的数据

View File

@ -27,6 +27,12 @@ class Cache extends Feature_1.Feature {
baseRelationAuth;
// 缓存在某一时间戳状态下对某行进行某个action的判断结果
entityActionAuthDict;
registerSelectionRewriter(rewriter) {
this.cacheStore.registerSelectionRewriter(rewriter);
}
registerOperationRewriter(rewriter) {
this.cacheStore.registerOperationRewriter(rewriter);
}
constructor(storageSchema, connector, frontendContextBuilder, checkers, localStorage, common) {
super();
this.syncEventsCallbacks = [];

View File

@ -215,7 +215,7 @@ class SubScriber extends Feature_1.Feature {
}
});
invalidEvents.forEach(event => (0, lodash_1.unset)(this.eventMap, event));
if (this.socketState === 'connected') {
if (this.socketState === 'connected' || this.socketState === 'connecting') {
this.socket.emit('unsub', events);
if (Object.keys(this.eventMap).length === 0) {
this.socket.disconnect();

View File

@ -1,3 +1,3 @@
export declare class Upload {
uploadFile(file: File | string, name: string, uploadUrl: string, formData: Record<string, any>, autoInform?: boolean): Promise<any>;
uploadFile(file: File | string, name: string, uploadUrl: string, formData: Record<string, any>, autoInform?: boolean, getPercent?: Function): Promise<any>;
}

View File

@ -2,18 +2,78 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.Upload = void 0;
class Upload {
async uploadFile(file, name, uploadUrl, formData, autoInform) {
const formData2 = new FormData();
for (const key of Object.keys(formData)) {
formData2.append(key, formData[key]);
// async uploadFile(
// file: File | string,
// name: string,
// uploadUrl: string,
// formData: Record<string, any>,
// autoInform?: boolean
// ): Promise<any> {
// const formData2 = new FormData();
// for (const key of Object.keys(formData)) {
// formData2.append(key, formData[key]);
// }
// formData2.append(name || 'file', file as File);
// const options = {
// body: formData2,
// method: 'POST',
// };
// const result = await fetch(uploadUrl, options);
// return result;
// }
async uploadFile(file, name, uploadUrl, formData, autoInform, getPercent) {
if (getPercent) {
const formData2 = new FormData();
Object.entries(formData).forEach(([key, value]) => {
formData2.append(key, value);
});
formData2.append(name || 'file', file);
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
let percent = 0;
xhr.upload.addEventListener('progress', (event) => {
if (event.lengthComputable) {
percent = Math.round((event.loaded / event.total) * 100);
getPercent(percent);
}
});
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
if (xhr.status === 204) {
resolve({ status: 204 }); // 正确返回状态码
}
else {
try {
const data = JSON.parse(xhr.responseText);
resolve(data);
}
catch (e) {
resolve({ status: xhr.status, raw: xhr.responseText });
}
}
}
else {
reject(new Error(`HTTP Error: ${xhr.status}`));
}
};
xhr.onerror = () => reject(new Error('Network Error'));
xhr.open('POST', uploadUrl);
xhr.send(formData2);
});
}
else {
const formData2 = new FormData();
for (const key of Object.keys(formData)) {
formData2.append(key, formData[key]);
}
formData2.append(name || 'file', file);
const options = {
body: formData2,
method: 'POST',
};
const result = await fetch(uploadUrl, options);
return result;
}
formData2.append(name || 'file', file);
const options = {
body: formData2,
method: 'POST',
};
const result = await fetch(uploadUrl, options);
return result;
}
}
exports.Upload = Upload;

View File

@ -1,4 +1,4 @@
import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, CheckerType, Aspect, SelectOpResult, StorageSchema, Checker, SubDataDef, AttrUpdateMatrix, Connector, AggregationResult } from 'oak-domain/lib/types';
import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, CheckerType, Aspect, SelectOpResult, StorageSchema, Checker, SubDataDef, AttrUpdateMatrix, Connector, AggregationResult, SelectionRewriter, OperationRewriter } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AspectDict as CommonAspectDict } from 'oak-common-aspect';
import { Feature } from '../types/Feature';
@ -64,6 +64,14 @@ export class Cache<ED extends EntityDict & BaseEntityDict> extends Feature {
};
};
registerSelectionRewriter(rewriter: SelectionRewriter<ED, AsyncContext<ED> | SyncContext<ED>, SelectOption>) {
this.cacheStore.registerSelectionRewriter(rewriter);
}
registerOperationRewriter(rewriter: OperationRewriter<ED, AsyncContext<ED> | SyncContext<ED>, OperateOption>) {
this.cacheStore.registerOperationRewriter(rewriter);
}
constructor(
storageSchema: StorageSchema<ED>,
connector: Connector<ED, SyncContext<ED>>,