From eb339ccc495973c67196324352f7b22f50dce7b6 Mon Sep 17 00:00:00 2001 From: wc24 Date: Mon, 29 Jun 2026 20:40:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(filter):=20buildQuery=20=E6=94=BE=E8=A1=8C?= =?UTF-8?q?=20=5Fid=20=E7=B2=BE=E7=A1=AE=E8=BF=87=E6=BB=A4(=E5=8D=95?= =?UTF-8?q?=E9=A1=B9=E6=9F=A5=E7=9C=8B/relation=20=E8=B7=B3=E8=BD=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit filter 原本只认 filterable 字段,_id 会被丢弃。新增: key==='_id' 时始终以 eq 放行, 让 ?filter={_id} 能过滤到单条。_id 是主键精确匹配、用户已有列表权限,无安全顾虑。 --- package.json | 2 +- src/Shrimp/ShrimpTableModule.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7d6a992..85349d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shrimp-server", - "version": "0.6.7", + "version": "0.6.8", "description": "Shrimp 框架后端 — 声明式字段驱动的 Node.js 管理后台框架(Express + Mongoose + JWT)", "main": "dist/main/index.js", "types": "dist/main/index.d.ts", diff --git a/src/Shrimp/ShrimpTableModule.ts b/src/Shrimp/ShrimpTableModule.ts index 0dad6ef..642a101 100644 --- a/src/Shrimp/ShrimpTableModule.ts +++ b/src/Shrimp/ShrimpTableModule.ts @@ -300,6 +300,11 @@ export class ShrimpTableModule = ITableCrudProto const stringLikeTypes = new Set(['string', 'textarea']) const where: Record = {} for (const [key, value] of Object.entries(filter)) { + // _id 始终放行精确过滤(单项查看/relation 跳转用),无需配 filterable + if (key === '_id') { + if (value != null && value !== '') where['_id'] = { eq: value } + continue + } const field = filterableFields.get(key) if (!field) continue if (value == null) continue