feat: enhance configuration handling and add type definitions for query and URL serializers

This commit is contained in:
2026-03-02 00:13:29 -05:00
parent 8cf5bfd9ec
commit 66d6a98ac4
7 changed files with 109 additions and 43 deletions

View File

@@ -9,23 +9,50 @@ export interface FLuentUrlPlainObject {
queries: QueriesPlainObject
}
export interface QuerySerializer {
parseQuery: (str: string) => QueriesPlainObject
stringifyQuery: (obj: QueriesPlainObject) => string
export type PlainObjectConstraint = Record<string, any>
export interface ParseQueryOptions extends PlainObjectConstraint {
[k: string]: any
}
export interface UrlSerializer {
parseUrl: (args: {
str: string
parseQuery: QuerySerializer['parseQuery']
}) => FLuentUrlPlainObject
stringifyUrl: (args: {
obj: FLuentUrlPlainObject
stringifyQuery: QuerySerializer['stringifyQuery']
}) => string
export type ParseQuery<T extends PlainObjectConstraint> = (
str: string,
options?: T,
) => QueriesPlainObject
export interface StringifyQueryOptions extends PlainObjectConstraint {
[k: string]: any
}
export interface FluentUrlConfig {
parseQuery: QuerySerializer['parseQuery']
stringifyQuery: QuerySerializer['stringifyQuery']
export type StringifyQuery<T extends PlainObjectConstraint> = (
obj: QueriesPlainObject,
options?: T,
) => string
export interface ParseUrlArgs<T extends PlainObjectConstraint> {
str: string
parseQuery: ParseQuery<T>
parseQueryOptions?: T
}
export interface StringifyUrlArgs<T extends PlainObjectConstraint> {
obj: FLuentUrlPlainObject
stringifyQuery: StringifyQuery<T>
stringifyQueryOptions?: T
}
export interface FluentUrlConfig<
PQO extends PlainObjectConstraint,
SQO extends PlainObjectConstraint,
> {
parseQuery: ParseQuery<PQO>
parseQueryOptions?: PQO
stringifyQuery: StringifyQuery<SQO>
stringifyQueryOptions?: SQO
}
export interface NormalizeOptionsArgs<T extends PlainObjectConstraint> {
urlOrOptions?: Partial<FLuentUrlPlainObject> | string
parseQuery: ParseQuery<T>
parseQueryOptions?: T
}