Files
trans-form-middleware/README.md
T
windychen ccd16bf956
Node.js Build / build (push) Has been skipped
chore: 初始化 trans-form 项目脚手架
- 基于 grill-me Q1-Q61 决策
- Vitest 测试与 CI workflow
- middleware: parseFilters 核心实现
- component: Vue3 TransForm 基础组件 + Storybook

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 00:47:58 +00:00

1.7 KiB
Raw Blame History

@windychen/trans-form-middleware

Node.js ESM library that parses filter arrays emitted by @windychen/trans-form-component into structured conditions. Does not generate SQL — ORM adapters consume the output.

Install

npm install @windychen/trans-form-middleware

Usage

import { parseFilters } from '@windychen/trans-form-middleware';

const componentOutput = [
  { field: 'name', value: 'xx', query: 'EQ' },
  { field: 'tags', value: 'a,b,c', query: 'IN', logic: 'OR' },
];

const filters = parseFilters(componentOutput, {
  allowedFields: ['name', 'tags', 'status'],
  mode: 'pass-through',
  unknownField: 'error',
  skipEmpty: false,
});

See DESIGN.md for the full protocol and grill-me decisions (Q1–Q61).

API

Export Description
parseFilters(conditions, options) Main parser
mapOperators(query, operatorMap?) Map EQ/GT/… to op symbols
toTree(flat) Nest flat array by logic
splitMultiValue(query, value) Parse comma-separated multi-values
DEFAULT_OPERATOR_MAP Built-in operator mapping

parseOptions

Option Default Description
allowedFields (required) Whitelist of field names
mode 'pass-through' 'flat' | 'tree' | 'pass-through'
unknownField 'error' 'error' | 'skip'
strict false Validate item shape
operatorMap {} Merge/override operator mapping
skipFlags ['disabled','hidden'] Skip items with these truthy flags
skipEmpty false Skip items with empty: true

Development

npm install
npm test

License

MIT