windychen
  • Joined on 2026-05-26

@windychen/trans-form-middleware (0.1.0)

Published 2026-08-07 09:28:00 +08:00 by windychen

Installation

@windychen:registry=https://gitea.windychen00n.work/api/packages/windychen/npm/
npm install @windychen/trans-form-middleware@0.1.0
"@windychen/trans-form-middleware": "0.1.0"

About this package

@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.

版本 0.1.0 — 首个可发布版本:parseFilters / mapOperators / toTree / splitMultiValue,零依赖,纯 ESM。

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

Dependencies

Development Dependencies

ID Version
vitest ^3.2.4

Keywords

filter query middleware trans-form
Details
npm
2026-08-07 09:28:00 +08:00
2
MIT
latest
2.8 KiB
Assets (1)
Versions (1) View all
0.1.0 2026-08-07