Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
172c49816e | ||
|
|
a8cd07f851 |
Generated
+8
-5
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "shrimp-server",
|
"name": "shrimp-server",
|
||||||
"version": "0.7.2",
|
"version": "0.7.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "shrimp-server",
|
"name": "shrimp-server",
|
||||||
"version": "0.7.2",
|
"version": "0.7.4",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"shrimp-server": "git+http://git.zeromvc.com/wc24/shrimp-server.git#v0.7.2"
|
"shrimp-server": "git+http://git.zeromvc.com/wc24/shrimp-server.git#v0.7.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcrypt": "^5.0.0",
|
"@types/bcrypt": "^5.0.0",
|
||||||
@@ -3374,8 +3374,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/shrimp-server": {
|
"node_modules/shrimp-server": {
|
||||||
"version": "0.7.2",
|
"version": "0.7.4",
|
||||||
"resolved": "git+http://git.zeromvc.com/wc24/shrimp-server.git#6383aade980b848871390eacaf52bb53c11387cb",
|
"resolved": "git+http://git.zeromvc.com/wc24/shrimp-server.git#a8cd07f8511487186732dfd884121f7acb77f5c0",
|
||||||
|
"dependencies": {
|
||||||
|
"shrimp-server": "git+http://git.zeromvc.com/wc24/shrimp-server.git#v0.7.3"
|
||||||
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"bcrypt": "^5 || ^6",
|
"bcrypt": "^5 || ^6",
|
||||||
"express": "^4 || ^5",
|
"express": "^4 || ^5",
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shrimp-server",
|
"name": "shrimp-server",
|
||||||
"version": "0.7.3",
|
"version": "0.7.5",
|
||||||
"description": "Shrimp 框架后端 — 声明式字段驱动的 Node.js 管理后台框架(Express + Mongoose + JWT)",
|
"description": "Shrimp 框架后端 — 声明式字段驱动的 Node.js 管理后台框架(Express + Mongoose + JWT)",
|
||||||
"main": "dist/main/index.js",
|
"main": "dist/main/index.js",
|
||||||
"types": "dist/main/index.d.ts",
|
"types": "dist/main/index.d.ts",
|
||||||
@@ -57,6 +57,6 @@
|
|||||||
"vitest": "^1.4.0"
|
"vitest": "^1.4.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"shrimp-server": "git+http://git.zeromvc.com/wc24/shrimp-server.git#v0.7.2"
|
"shrimp-server": "git+http://git.zeromvc.com/wc24/shrimp-server.git#v0.7.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,7 +193,9 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
|||||||
/** 递归校验:本节点 validateField,出错即抛(带 path);再下钻复合(tab/object/array)子节点。第一版 fail-fast */
|
/** 递归校验:本节点 validateField,出错即抛(带 path);再下钻复合(tab/object/array)子节点。第一版 fail-fast */
|
||||||
private async validateNode(field: IFieldConfig, value: any, path: (string | number)[], rootItem: Record<string, any>): Promise<void> {
|
private async validateNode(field: IFieldConfig, value: any, path: (string | number)[], rootItem: Record<string, any>): Promise<void> {
|
||||||
const err = await this.validateField(field, value, rootItem)
|
const err = await this.validateField(field, value, rootItem)
|
||||||
if (err) throw new ShrimpError(this.errWithPath(err, path))
|
// 出错只发字段名(label) + i18n key 的 message,不把开发用的 path 拼进可见文案。
|
||||||
|
// path 仍递归往下传(供将来 inline 标红按结构化方式携带,不在这里塞进 message)。
|
||||||
|
if (err) throw new ShrimpError(err)
|
||||||
for (const child of this.childrenOf(field, value)) {
|
for (const child of this.childrenOf(field, value)) {
|
||||||
await this.validateNode(child.field, child.value, [...path, child.key], rootItem)
|
await this.validateNode(child.field, child.value, [...path, child.key], rootItem)
|
||||||
}
|
}
|
||||||
@@ -215,14 +217,6 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 嵌套字段出错时把 path 缀进 message(顶层不缀,已有字段名),让用户知道是哪个嵌套位置 */
|
|
||||||
private errWithPath(err: ILabel, path: (string | number)[]): ILabel {
|
|
||||||
if (path.length <= 1 || typeof err !== "object" || err === null) return err
|
|
||||||
const e = err as any
|
|
||||||
const tag = `[${path.join(".")}]`
|
|
||||||
return { ...e, params: { ...e.params, field: e.params?.field != null ? `${e.params.field} ${tag}` : tag } }
|
|
||||||
}
|
|
||||||
|
|
||||||
private async processResItem(item: Record<string, any>): Promise<Record<string, any>> {
|
private async processResItem(item: Record<string, any>): Promise<Record<string, any>> {
|
||||||
const result = { ...item }
|
const result = { ...item }
|
||||||
for (const field of this.fields) {
|
for (const field of this.fields) {
|
||||||
@@ -303,6 +297,19 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
|||||||
return this.excludeKeys(item, ["__v", ...this.fields.filter(f => f.hidden).map(f => f.key)])
|
return this.excludeKeys(item, ["__v", ...this.fields.filter(f => f.hidden).map(f => f.key)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 递归收集标了 filterable 的字段 → 点路径(object 子 / tab 分支子)。array 暂不下钻(后续) */
|
||||||
|
private collectFilterablePaths(fields: IFieldConfig[], base: string[], out: Map<string, IFieldConfig>): void {
|
||||||
|
for (const f of fields) {
|
||||||
|
const path = [...base, f.key]
|
||||||
|
if (f.filterable) out.set(path.join("."), f)
|
||||||
|
if (f.type === ShrimpFieldTypes.Tab && Array.isArray(f.tabs)) {
|
||||||
|
for (const t of f.tabs) this.collectFilterablePaths(t.fields, path, out)
|
||||||
|
} else if (f.type === ShrimpFieldTypes.Object && Array.isArray(f.fields)) {
|
||||||
|
this.collectFilterablePaths(f.fields, path, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private buildQuery(query?: IPageQuery & any): IShrimpQuery {
|
private buildQuery(query?: IPageQuery & any): IShrimpQuery {
|
||||||
const { keyword, page, pageSize, sortBy, sortOrder, filter, ownerId } = query || {}
|
const { keyword, page, pageSize, sortBy, sortOrder, filter, ownerId } = query || {}
|
||||||
const p = page || 1
|
const p = page || 1
|
||||||
@@ -313,7 +320,9 @@ export class ShrimpTableModule<T, P extends ITableCrudProto<T> = ITableCrudProto
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filter && typeof filter === 'object') {
|
if (filter && typeof filter === 'object') {
|
||||||
const filterableFields = new Map(this.fields.filter(f => f.filterable).map(f => [f.key, f]))
|
// filterable 路径(含 object/tab 嵌套叶子,点路径如 condition.level)→ 白名单。点路径本就是 mongoose 嵌套查询,翻译逻辑不变
|
||||||
|
const filterableFields = new Map<string, IFieldConfig>()
|
||||||
|
this.collectFilterablePaths(this.fields, [], filterableFields)
|
||||||
const stringLikeTypes = new Set(['string', 'textarea'])
|
const stringLikeTypes = new Set(['string', 'textarea'])
|
||||||
const where: Record<string, IShrimpCondition> = {}
|
const where: Record<string, IShrimpCondition> = {}
|
||||||
for (const [key, value] of Object.entries(filter)) {
|
for (const [key, value] of Object.entries(filter)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user