chore: 初始化 trans-form 项目脚手架
Node.js Build / build (push) Has been skipped

- 基于 grill-me Q1-Q61 决策
- Vitest 测试与 CI workflow
- middleware: parseFilters 核心实现
- component: Vue3 TransForm 基础组件 + Storybook

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-07 00:47:58 +00:00
commit ccd16bf956
14 changed files with 2126 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
# @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