升级ts到5版

This commit is contained in:
Xu Chang 2023-09-14 18:14:59 +08:00
parent 9032783680
commit 518242e22d
8 changed files with 28 additions and 11 deletions

2
lib/AppLoader.d.ts vendored
View File

@ -23,7 +23,7 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
}>; }>;
initialize(dropIfExists?: boolean): Promise<void>; initialize(dropIfExists?: boolean): Promise<void>;
getStore(): DbStore<ED, Cxt>; getStore(): DbStore<ED, Cxt>;
getEndpoints(): [string, "get" | "delete" | "post" | "put", string, (params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<any>][]; getEndpoints(): [string, "get" | "post" | "put" | "delete", string, (params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<any>][];
startTimers(): void; startTimers(): void;
execStartRoutines(): Promise<void>; execStartRoutines(): Promise<void>;
execRoutine(routine: (context: Cxt) => Promise<void>): Promise<void>; execRoutine(routine: (context: Cxt) => Promise<void>): Promise<void>;

View File

@ -93,9 +93,22 @@ class AppLoader extends types_1.AppLoader {
this.externalDependencies = require((0, env_1.OAK_EXTERNAL_LIBS_FILEPATH)((0, path_1.join)(path, 'lib'))); this.externalDependencies = require((0, env_1.OAK_EXTERNAL_LIBS_FILEPATH)((0, path_1.join)(path, 'lib')));
this.aspectDict = Object.assign({}, index_1.default, this.requireSth('lib/aspects/index')); this.aspectDict = Object.assign({}, index_1.default, this.requireSth('lib/aspects/index'));
this.dbStore = new DbStore_1.DbStore(storageSchema, contextBuilder, dbConfig, ActionCascadePathGraph, RelationCascadePathGraph, deducedRelationMap, selectFreeEntities, createFreeEntities, updateFreeEntities); this.dbStore = new DbStore_1.DbStore(storageSchema, contextBuilder, dbConfig, ActionCascadePathGraph, RelationCascadePathGraph, deducedRelationMap, selectFreeEntities, createFreeEntities, updateFreeEntities);
this.contextBuilder = contextBuilder;
if (io) { if (io) {
this.dataSubscriber = new DataSubscriber_1.default(io, (scene) => this.contextBuilder(scene)(this.dbStore)); this.dataSubscriber = new DataSubscriber_1.default(io, (scene) => this.contextBuilder(scene)(this.dbStore));
this.contextBuilder = (scene) => async (store) => {
const context = await contextBuilder(scene)(store);
// 注入在提交前向dataSubscribe
const originCommit = context.commit;
context.commit = async () => {
const { opRecords } = context;
const userId = context.getCurrentUserId();
originCommit.call(context);
};
return context;
};
}
else {
this.contextBuilder = contextBuilder;
} }
} }
initTriggers() { initTriggers() {

View File

@ -1,4 +1,4 @@
import { EntityDict } from 'oak-domain/lib/types'; import { EntityDict, OpRecord } from 'oak-domain/lib/types';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
import { Server } from 'socket.io'; import { Server } from 'socket.io';
@ -12,4 +12,5 @@ export default class DataSubscriber<ED extends EntityDict & BaseEntityDict, Cont
* socket连接 * socket连接
*/ */
private startup; private startup;
onDataCommited(records: OpRecord<ED>[], userId?: string): void;
} }

View File

@ -34,9 +34,9 @@ class DataSubscriber {
data.forEach((ele) => { data.forEach((ele) => {
const { id, entity, filter } = ele; const { id, entity, filter } = ele;
console.log('sub', id, entity, filter); console.log('sub', id, entity, filter);
// 尝试select此filter如果失败说明权限越界
// todo
const globalId = this.calcEntityFilterID(entity, filter); const globalId = this.calcEntityFilterID(entity, filter);
const rooms = this.io.of("/").adapter.rooms;
console.log(rooms);
socket.idMap[id] = globalId; socket.idMap[id] = globalId;
socket.join(globalId); socket.join(globalId);
}); });
@ -45,10 +45,7 @@ class DataSubscriber {
console.log('unsub', ids); console.log('unsub', ids);
ids.forEach((id) => { ids.forEach((id) => {
const globalId = socket.idMap[id]; const globalId = socket.idMap[id];
const rooms = this.io.of("/").adapter.rooms;
console.log(rooms);
socket.leave(globalId); socket.leave(globalId);
console.log(rooms);
}); });
}); });
socket.on('disconnect', (reason) => { socket.on('disconnect', (reason) => {
@ -56,5 +53,7 @@ class DataSubscriber {
}); });
}); });
} }
onDataCommited(records, userId) {
}
} }
exports.default = DataSubscriber; exports.default = DataSubscriber;

2
lib/polyfill.d.ts vendored
View File

@ -1,3 +1,3 @@
export declare type GenerateIdOption = { export type GenerateIdOption = {
shuffle?: boolean; shuffle?: boolean;
}; };

View File

@ -28,12 +28,12 @@
}, },
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@types/node": "^17.0.40", "@types/node": "^20.6.0",
"@types/node-schedule": "^2.1.0", "@types/node-schedule": "^2.1.0",
"@types/uuid": "^8.3.4", "@types/uuid": "^8.3.4",
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"ts-node": "~10.9.1", "ts-node": "~10.9.1",
"tslib": "^2.4.0", "tslib": "^2.4.0",
"typescript": "^4.7.4" "typescript": "^5.2.2"
} }
} }

View File

@ -44,6 +44,9 @@ export default class DataSubscriber<ED extends EntityDict & BaseEntityDict, Cont
(ele) => { (ele) => {
const { id, entity, filter } = ele; const { id, entity, filter } = ele;
console.log('sub', id, entity, filter); console.log('sub', id, entity, filter);
// 尝试select此filter如果失败说明权限越界
// todo
const globalId = this.calcEntityFilterID(entity, filter); const globalId = this.calcEntityFilterID(entity, filter);
(socket as any).idMap[id] = globalId; (socket as any).idMap[id] = globalId;
socket.join(globalId); socket.join(globalId);

View File

@ -53,6 +53,7 @@
// "types": [], /* Type declaration files to be included in compilation. */ // "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibCheck": true,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */ /* Source Map Options */