@proventuslabs/nestjs-multipart-form
Version:
A lightweight and efficient NestJS package for handling multipart form data and file uploads with RxJS streaming support and type safety.
82 lines (81 loc) • 3.27 kB
TypeScript
import qs from "qs";
import { Observable } from "rxjs";
import type { MultipartField } from "../core/types";
/**
* RxJS operator that enriches multipart fields with associative syntax parsing.
*
* Transforms fields with associative syntax (e.g., "user[name]", "data[items][0]")
* by adding parsed basename, associations array, and isAssociative flag.
* Fields without associative syntax pass through unchanged.
*
* @returns RxJS operator function that transforms MultipartField observables
*
* @example
* fields$.pipe(
* associateFields()
* ).subscribe(field => {
* // For field name "user[name]" with value "John":
* console.log(field.name); // "user[name]"
* console.log(field.value); // "John"
* console.log(field.isAssociative); // true
* console.log(field.basename); // "user"
* console.log(field.associations); // ["name"]
* });
*/
export declare function associateFields(): (source: Observable<MultipartField>) => Observable<MultipartField>;
/**
* RxJS operator that collects associatives multipart fields into arrays.
* Fields with array-like syntax (field[]) are collected into arrays while
* fields with object-like syntax (field[name]) are collected into objects.
* Uses `qs` under the hood.
*
* @example
* fields$.pipe(
* associateFields(),
* collectAssociatives()
* ).subscribe(fields => {
* // For fields "name[first]=John" and "name[last]=Doe":
* console.log(fields); // { "name": { "first": "John", "last": "Doe" } }
* });
*/
export declare function collectAssociatives(options?: qs.IParseOptions<qs.BooleanOptional> & {
decoder?: never | undefined;
}): (source: Observable<MultipartField>) => Observable<qs.ParsedQs>;
/**
* RxJS operator that converts multipart fields to a simple key-value record.
*
* @returns RxJS operator function that converts MultipartField observables to a record
*
* @example
* fields$.pipe(
* collectToRecord()
* ).subscribe(record => {
* console.log(record); // { name: "John", email: "john@example.com" }
* });
*/
export declare function collectToRecord(): (source: Observable<MultipartField>) => Observable<Record<string, string>>;
/**
* RxJS operator that filters multipart fields by pattern matching.
*
* @param patterns Array of patterns to match against field names
* @returns RxJS operator function that filters MultipartField observables
*
* @example
* fields$.pipe(
* filterFieldsByPatterns(['name', '^user_'])
* ).subscribe(field => console.log('Matched field:', field.name));
*/
export declare function filterFieldsByPatterns(patterns: string[]): (source: Observable<MultipartField>) => Observable<MultipartField>;
/**
* RxJS operator that validates required field patterns are present when stream completes.
*
* @param requiredPatterns Array of required field patterns
* @returns RxJS operator function that validates MultipartField observables
*
* @example
* fields$.pipe(
* filterFieldsByPatterns(['name', '^user_', 'metadata']),
* validateRequiredFields(['name', '^user_'])
* ).subscribe(field => console.log('Valid field:', field.name));
*/
export declare function validateRequiredFields(requiredPatterns: string[]): (source: Observable<MultipartField>) => Observable<MultipartField>;