feat: enhance configuration handling and add type definitions for query and URL serializers
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user