From 518242e22df342b9d5f4dc2bae286f6f27933210 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Thu, 14 Sep 2023 18:14:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7ts=E5=88=B05=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/AppLoader.d.ts | 2 +- lib/AppLoader.js | 15 ++++++++++++++- lib/DataSubscriber.d.ts | 3 ++- lib/DataSubscriber.js | 9 ++++----- lib/polyfill.d.ts | 2 +- package.json | 4 ++-- src/DataSubscriber.ts | 3 +++ tsconfig.json | 1 + 8 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/AppLoader.d.ts b/lib/AppLoader.d.ts index 27b2420..151991f 100644 --- a/lib/AppLoader.d.ts +++ b/lib/AppLoader.d.ts @@ -23,7 +23,7 @@ export declare class AppLoader; initialize(dropIfExists?: boolean): Promise; getStore(): DbStore; - getEndpoints(): [string, "get" | "delete" | "post" | "put", string, (params: Record, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise][]; + getEndpoints(): [string, "get" | "post" | "put" | "delete", string, (params: Record, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise][]; startTimers(): void; execStartRoutines(): Promise; execRoutine(routine: (context: Cxt) => Promise): Promise; diff --git a/lib/AppLoader.js b/lib/AppLoader.js index 8f7b8db..3046544 100644 --- a/lib/AppLoader.js +++ b/lib/AppLoader.js @@ -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.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.contextBuilder = contextBuilder; if (io) { 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() { diff --git a/lib/DataSubscriber.d.ts b/lib/DataSubscriber.d.ts index 6ba3814..5fe2f04 100644 --- a/lib/DataSubscriber.d.ts +++ b/lib/DataSubscriber.d.ts @@ -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 { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore'; import { Server } from 'socket.io'; @@ -12,4 +12,5 @@ export default class DataSubscriber[], userId?: string): void; } diff --git a/lib/DataSubscriber.js b/lib/DataSubscriber.js index 3665b7c..482f4de 100644 --- a/lib/DataSubscriber.js +++ b/lib/DataSubscriber.js @@ -34,9 +34,9 @@ class DataSubscriber { data.forEach((ele) => { const { id, entity, filter } = ele; console.log('sub', id, entity, filter); + // 尝试select此filter,如果失败说明权限越界 + // todo const globalId = this.calcEntityFilterID(entity, filter); - const rooms = this.io.of("/").adapter.rooms; - console.log(rooms); socket.idMap[id] = globalId; socket.join(globalId); }); @@ -45,10 +45,7 @@ class DataSubscriber { console.log('unsub', ids); ids.forEach((id) => { const globalId = socket.idMap[id]; - const rooms = this.io.of("/").adapter.rooms; - console.log(rooms); socket.leave(globalId); - console.log(rooms); }); }); socket.on('disconnect', (reason) => { @@ -56,5 +53,7 @@ class DataSubscriber { }); }); } + onDataCommited(records, userId) { + } } exports.default = DataSubscriber; diff --git a/lib/polyfill.d.ts b/lib/polyfill.d.ts index 2ca4881..46d82ec 100644 --- a/lib/polyfill.d.ts +++ b/lib/polyfill.d.ts @@ -1,3 +1,3 @@ -export declare type GenerateIdOption = { +export type GenerateIdOption = { shuffle?: boolean; }; diff --git a/package.json b/package.json index a67a520..afe9b84 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,12 @@ }, "license": "ISC", "devDependencies": { - "@types/node": "^17.0.40", + "@types/node": "^20.6.0", "@types/node-schedule": "^2.1.0", "@types/uuid": "^8.3.4", "copyfiles": "^2.4.1", "ts-node": "~10.9.1", "tslib": "^2.4.0", - "typescript": "^4.7.4" + "typescript": "^5.2.2" } } diff --git a/src/DataSubscriber.ts b/src/DataSubscriber.ts index a99d91a..3764d13 100644 --- a/src/DataSubscriber.ts +++ b/src/DataSubscriber.ts @@ -44,6 +44,9 @@ export default class DataSubscriber { const { id, entity, filter } = ele; console.log('sub', id, entity, filter); + // 尝试select此filter,如果失败说明权限越界 + // todo + const globalId = this.calcEntityFilterID(entity, filter); (socket as any).idMap[id] = globalId; socket.join(globalId); diff --git a/tsconfig.json b/tsconfig.json index db25e2d..175ccc7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -53,6 +53,7 @@ // "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. */ "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. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ /* Source Map Options */