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

63 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# @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
```bash
npm install @windychen/trans-form-middleware
```
## Usage
```js
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
```bash
npm install
npm test
```
## License
MIT