@trapi/query
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -1,3 +0,3 @@ | ||
import { FieldRecord } from "./type"; | ||
export declare function buildQueryFields<T>(data: FieldRecord<T>): Record<string, any> | string | string[]; | ||
import { FieldsQueryRecord } from "./type"; | ||
export declare function buildQueryFields<T>(data: FieldsQueryRecord<T>): Record<string, any> | string | string[]; | ||
//# sourceMappingURL=build.d.ts.map |
@@ -1,4 +0,4 @@ | ||
import { FieldsOptions, FieldsParsed } from "./type"; | ||
export declare function buildDomainFields(data: Record<string, string[]> | string[], options?: FieldsOptions): Record<string, string[]>; | ||
export declare function parseFields(data: unknown, options: FieldsOptions): FieldsParsed; | ||
import { FieldsParseOptions, FieldsParsed } from "./type"; | ||
export declare function buildDomainFields(data: Record<string, string[]> | string[], options?: FieldsParseOptions): Record<string, string[]>; | ||
export declare function parseFields(data: unknown, options: FieldsParseOptions): FieldsParsed; | ||
//# sourceMappingURL=parse.d.ts.map |
@@ -34,3 +34,3 @@ "use strict"; | ||
options.aliasMapping ??= {}; | ||
options.includes ??= []; | ||
options.include ??= []; | ||
options.defaultAlias ??= type_1.DEFAULT_ALIAS_ID; | ||
@@ -76,3 +76,3 @@ let allowedDomainFields; | ||
key: fieldsArr[i], | ||
...(operator ? { operator } : {}) | ||
...(operator ? { value: operator } : {}) | ||
}); | ||
@@ -85,4 +85,4 @@ } | ||
alias !== options.defaultAlias && | ||
typeof options.includes !== 'undefined') { | ||
const includesMatched = options.includes.filter(include => include.alias === alias); | ||
typeof options.include !== 'undefined') { | ||
const includesMatched = options.include.filter(include => include.value === alias); | ||
if (includesMatched.length === 0) { | ||
@@ -89,0 +89,0 @@ continue; |
@@ -1,16 +0,5 @@ | ||
import { IncludesParsed } from "../includes"; | ||
import { ParsedElementBase, ParseOptionsBase } from "../parse"; | ||
import { QueryKey } from "../type"; | ||
import { Flatten, KeyWithOptionalPrefix, OnlyObject, ToOneAndMany } from "../utils"; | ||
export declare const DEFAULT_ALIAS_ID: string; | ||
export declare type FieldsOptions = { | ||
aliasMapping?: Record<string, string>; | ||
allowed?: Record<string, string[]> | string[]; | ||
includes?: IncludesParsed; | ||
defaultAlias?: string; | ||
}; | ||
export declare type FieldParsed = { | ||
key: string; | ||
alias?: string; | ||
operator?: FieldOperator; | ||
}; | ||
export declare type FieldsParsed = FieldParsed[]; | ||
export declare enum FieldOperator { | ||
@@ -21,8 +10,11 @@ INCLUDE = "+", | ||
declare type FieldWithOperator<T extends Record<string, any>> = KeyWithOptionalPrefix<keyof T, FieldOperator> | KeyWithOptionalPrefix<keyof T, FieldOperator>[]; | ||
export declare type FieldRecord<T> = { | ||
[K in keyof T]?: T[K] extends OnlyObject<T[K]> ? (FieldRecord<Flatten<T[K]>> | FieldWithOperator<Flatten<T[K]>>) : never; | ||
export declare type FieldsQueryRecord<T> = { | ||
[K in keyof T]?: T[K] extends OnlyObject<T[K]> ? (FieldsQueryRecord<Flatten<T[K]>> | FieldWithOperator<Flatten<T[K]>>) : never; | ||
} | { | ||
[key: string]: ToOneAndMany<KeyWithOptionalPrefix<keyof T, FieldOperator>[]>; | ||
} | FieldWithOperator<T>; | ||
export declare type FieldsParseOptions = ParseOptionsBase<QueryKey.FIELDS, Record<string, string[]> | string[]>; | ||
export declare type FieldsParsedElement = ParsedElementBase<QueryKey.FIELDS, FieldOperator>; | ||
export declare type FieldsParsed = FieldsParsedElement[]; | ||
export {}; | ||
//# sourceMappingURL=type.d.ts.map |
@@ -12,2 +12,4 @@ "use strict"; | ||
// ----------------------------------------------------------- | ||
// Build | ||
// ----------------------------------------------------------- | ||
var FieldOperator; | ||
@@ -14,0 +16,0 @@ (function (FieldOperator) { |
@@ -1,3 +0,3 @@ | ||
import { FilterRecord } from "./type"; | ||
export declare function buildQueryFilters<T>(data: FilterRecord<T>): Record<string, string>; | ||
import { FiltersQueryRecord } from "./type"; | ||
export declare function buildQueryFilters<T>(data: FiltersQueryRecord<T>): Record<string, string>; | ||
//# sourceMappingURL=build.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { FiltersOptions, FiltersParsed } from "./type"; | ||
export declare function parseFilters(data: unknown, options?: FiltersOptions): FiltersParsed; | ||
import { FiltersParseOptions, FiltersParsed } from "./type"; | ||
export declare function parseFilters(data: unknown, options?: FiltersParseOptions): FiltersParsed; | ||
//# sourceMappingURL=parse.d.ts.map |
@@ -22,3 +22,3 @@ "use strict"; | ||
} | ||
options.includes ??= []; | ||
options.include ??= []; | ||
return options; | ||
@@ -67,3 +67,3 @@ } | ||
const fieldDetails = (0, utils_1.getFieldDetails)(key); | ||
if (!(0, utils_1.isFieldAllowedByIncludes)(fieldDetails, options.includes, { defaultAlias: options.defaultAlias })) { | ||
if (!(0, utils_1.isFieldAllowedByIncludes)(fieldDetails, options.include, { defaultAlias: options.defaultAlias })) { | ||
continue; | ||
@@ -70,0 +70,0 @@ } |
@@ -1,20 +0,5 @@ | ||
import { IncludesParsed } from "../includes"; | ||
import { ParsedElementBase, ParseOptionsBase } from "../parse"; | ||
import { QueryKey } from "../type"; | ||
import { Flatten, OnlyObject, OnlyScalar } from "../utils"; | ||
export declare type FiltersOptions = { | ||
aliasMapping?: Record<string, string>; | ||
allowed?: string[]; | ||
includes?: IncludesParsed; | ||
defaultAlias?: string; | ||
queryBindingKeyFn?: (key: string) => string; | ||
}; | ||
export declare type FilterParsed = { | ||
key: string; | ||
alias?: string; | ||
operator?: { | ||
[K in FilterOperatorLabel]?: boolean; | ||
}; | ||
value: FilterValue<string | number | boolean | null>; | ||
}; | ||
export declare type FiltersParsed = FilterParsed[]; | ||
export declare type OperatorConfig<V, O> = { | ||
export declare type FilterOperatorConfig<V, O> = { | ||
operator: O | O[]; | ||
@@ -36,6 +21,13 @@ value: V | V[]; | ||
declare type FilterValueOperator<V extends string | number | boolean> = `!${V}` | `!~${V}` | `~${V}`; | ||
export declare type FilterRecord<T> = { | ||
[K in keyof T]?: T[K] extends OnlyScalar<T[K]> ? T[K] | FilterValueWithOperator<T[K]> | OperatorConfig<T[K], FilterOperator> : T[K] extends OnlyObject<T[K]> ? FilterRecord<Flatten<T[K]>> : never; | ||
export declare type FiltersQueryRecord<T> = { | ||
[K in keyof T]?: T[K] extends OnlyScalar<T[K]> ? T[K] | FilterValueWithOperator<T[K]> | FilterOperatorConfig<T[K], FilterOperator> : T[K] extends OnlyObject<T[K]> ? FiltersQueryRecord<Flatten<T[K]>> : never; | ||
}; | ||
export declare type FiltersParseOptions = ParseOptionsBase<QueryKey.FILTER>; | ||
export declare type FiltersParsedElement = ParsedElementBase<QueryKey.FILTER, FilterValue<string | number | boolean | null>> & { | ||
operator?: { | ||
[K in FilterOperatorLabel]?: boolean; | ||
}; | ||
}; | ||
export declare type FiltersParsed = FiltersParsedElement[]; | ||
export {}; | ||
//# sourceMappingURL=type.d.ts.map |
export * from './build'; | ||
export * from './fields'; | ||
export * from './filters'; | ||
export * from './includes'; | ||
export * from './relations'; | ||
export * from './pagination'; | ||
@@ -9,2 +9,9 @@ export * from './parse'; | ||
export * from './type'; | ||
export { QueryRecordParsed } from "./parse"; | ||
export { QueryKeyParseOptions } from "./parse"; | ||
export { QueryParseOutput } from "./parse"; | ||
export { QueryParseOptions } from "./parse"; | ||
export { QueryParseInput } from "./parse"; | ||
export { QueryRecordType } from "./build"; | ||
export { QueryRecord } from "./build"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -22,3 +22,3 @@ "use strict"; | ||
__exportStar(require("./filters"), exports); | ||
__exportStar(require("./includes"), exports); | ||
__exportStar(require("./relations"), exports); | ||
__exportStar(require("./pagination"), exports); | ||
@@ -25,0 +25,0 @@ __exportStar(require("./parse"), exports); |
@@ -1,2 +0,2 @@ | ||
import { PaginationOptions, PaginationParsed } from "./type"; | ||
import { PaginationParseOptions, PaginationParsed } from "./type"; | ||
/** | ||
@@ -8,3 +8,3 @@ * Transform pagination data to an appreciate data format. | ||
*/ | ||
export declare function parsePagination(data: unknown, options?: PaginationOptions): PaginationParsed; | ||
export declare function parsePagination(data: unknown, options?: PaginationParseOptions): PaginationParsed; | ||
//# sourceMappingURL=parse.d.ts.map |
@@ -1,9 +0,11 @@ | ||
export declare type PaginationOptions = { | ||
maxLimit?: number; | ||
}; | ||
export declare type PaginationParsed = { | ||
import { ParseOptionsBase } from "../parse"; | ||
import { QueryKey } from "../type"; | ||
export declare type PaginationQueryRecord<T> = { | ||
limit?: number; | ||
offset?: number; | ||
}; | ||
export declare type PaginationRecord<T> = { | ||
export declare type PaginationParseOptions = ParseOptionsBase<QueryKey.PAGE> & { | ||
maxLimit?: number; | ||
}; | ||
export declare type PaginationParsed = ParseOptionsBase<QueryKey.PAGE> & { | ||
limit?: number; | ||
@@ -10,0 +12,0 @@ offset?: number; |
@@ -1,3 +0,3 @@ | ||
import { SortRecord } from "./type"; | ||
export declare function buildQuerySort<T>(data: SortRecord<T>): Record<string, any> | import("../utils").KeyWithOptionalPrefix<keyof T, "-">; | ||
import { SortQueryRecord } from "./type"; | ||
export declare function buildQuerySort<T>(data: SortQueryRecord<T>): Record<string, any> | import("../utils").KeyWithOptionalPrefix<keyof T, "-">; | ||
//# sourceMappingURL=build.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { SortOptions, SortParsed } from "./type"; | ||
import { SortParseOptions, SortParsed } from "./type"; | ||
/** | ||
@@ -7,3 +7,3 @@ * Transform sort data to appreciate data format. | ||
*/ | ||
export declare function parseSort(data: unknown, options?: SortOptions): SortParsed; | ||
export declare function parseSort(data: unknown, options?: SortParseOptions): SortParsed; | ||
//# sourceMappingURL=parse.d.ts.map |
@@ -71,3 +71,3 @@ "use strict"; | ||
const fieldDetails = (0, utils_1.getFieldDetails)(key); | ||
if (!(0, utils_1.isFieldAllowedByIncludes)(fieldDetails, options.includes, { defaultAlias: options.defaultAlias })) { | ||
if (!(0, utils_1.isFieldAllowedByIncludes)(fieldDetails, options.include, { defaultAlias: options.defaultAlias })) { | ||
continue; | ||
@@ -74,0 +74,0 @@ } |
@@ -1,9 +0,4 @@ | ||
import { IncludesParsed } from "../includes"; | ||
import { ParsedElementBase, ParseOptionsBase } from "../parse"; | ||
import { QueryKey } from "../type"; | ||
import { Flatten, KeyWithOptionalPrefix, OnlyObject, OnlyScalar } from "../utils"; | ||
export declare type SortOptions = { | ||
aliasMapping?: Record<string, string>; | ||
allowed?: string[] | string[][]; | ||
includes?: IncludesParsed; | ||
defaultAlias?: string; | ||
}; | ||
export declare enum SortDirection { | ||
@@ -13,14 +8,11 @@ ASC = "ASC", | ||
} | ||
export declare type SortElementParsed = { | ||
alias?: string; | ||
key: string; | ||
value: SortDirection; | ||
}; | ||
export declare type SortParsed = SortElementParsed[]; | ||
declare type SortOperatorDesc = '-'; | ||
declare type SortWithOperator<T extends Record<string, any>> = KeyWithOptionalPrefix<keyof T, SortOperatorDesc> | KeyWithOptionalPrefix<keyof T, SortOperatorDesc>[]; | ||
export declare type SortRecord<T> = { | ||
[K in keyof T]?: T[K] extends OnlyScalar<T[K]> ? SortDirection : T[K] extends OnlyObject<T[K]> ? SortRecord<Flatten<T[K]>> | SortWithOperator<Flatten<T[K]>> : never; | ||
export declare type SortQueryRecord<T> = { | ||
[K in keyof T]?: T[K] extends OnlyScalar<T[K]> ? SortDirection : T[K] extends OnlyObject<T[K]> ? SortQueryRecord<Flatten<T[K]>> | SortWithOperator<Flatten<T[K]>> : never; | ||
} | SortWithOperator<T>; | ||
export declare type SortParseOptions = ParseOptionsBase<QueryKey.SORT, string[] | string[][]>; | ||
export declare type SortParsedElement = ParsedElementBase<QueryKey.SORT, SortDirection>; | ||
export declare type SortParsed = SortParsedElement[]; | ||
export {}; | ||
//# sourceMappingURL=type.d.ts.map |
@@ -1,6 +0,1 @@ | ||
import { FieldRecord, FieldsOptions, FieldsParsed } from "./fields"; | ||
import { FilterRecord, FiltersOptions, FiltersParsed } from "./filters"; | ||
import { IncludeRecord, IncludesOptions, IncludesParsed } from "./includes"; | ||
import { PaginationOptions, PaginationRecord, PaginationParsed } from "./pagination"; | ||
import { SortOptions, SortRecord, SortParsed } from "./sort"; | ||
export declare enum QueryKey { | ||
@@ -13,17 +8,2 @@ FILTER = "filter", | ||
} | ||
export declare type QueryRecord<R extends Record<string, any>> = { | ||
[K in QueryKey]?: QueryRecordType<K, R>; | ||
}; | ||
export declare type QueryRecordType<T extends QueryKey, R extends Record<string, any>> = T extends QueryKey.FIELDS ? FieldRecord<R> : T extends QueryKey.FILTER ? FilterRecord<R> : T extends QueryKey.INCLUDE ? IncludeRecord<R> : T extends QueryKey.PAGE ? PaginationRecord<R> : T extends QueryKey.SORT ? SortRecord<R> : never; | ||
export declare type QueryParseInput = { | ||
[K in QueryKey]?: any; | ||
}; | ||
export declare type QueryParseOptions = { | ||
[K in QueryKey]?: QueryKeyOption<K> | boolean; | ||
}; | ||
export declare type QueryParseOutput = { | ||
[K in QueryKey]?: QueryRecordTransformed<K>; | ||
}; | ||
export declare type QueryKeyOption<T extends QueryKey> = T extends QueryKey.FIELDS ? FieldsOptions : T extends QueryKey.FILTER ? FiltersOptions : T extends QueryKey.INCLUDE ? IncludesOptions : T extends QueryKey.PAGE ? PaginationOptions : T extends QueryKey.SORT ? SortOptions : never; | ||
export declare type QueryRecordTransformed<T extends QueryKey> = T extends QueryKey.FIELDS ? FieldsParsed : T extends QueryKey.FILTER ? FiltersParsed : T extends QueryKey.INCLUDE ? IncludesParsed : T extends QueryKey.PAGE ? PaginationParsed : T extends QueryKey.SORT ? SortParsed : never; | ||
//# sourceMappingURL=type.d.ts.map |
@@ -19,2 +19,3 @@ "use strict"; | ||
})(QueryKey = exports.QueryKey || (exports.QueryKey = {})); | ||
// ----------------------------------------------------------- | ||
//# sourceMappingURL=type.js.map |
@@ -1,4 +0,4 @@ | ||
import { IncludesParsed } from "../includes"; | ||
import { RelationsParsed } from "../relations"; | ||
import { FieldDetails } from "./field"; | ||
export declare function isFieldAllowedByIncludes(field: string | FieldDetails, includes?: IncludesParsed, options?: { | ||
export declare function isFieldAllowedByIncludes(field: string | FieldDetails, includes?: RelationsParsed, options?: { | ||
defaultAlias?: string; | ||
@@ -5,0 +5,0 @@ }): boolean; |
@@ -27,3 +27,3 @@ "use strict"; | ||
} | ||
return includes.filter(include => include.alias === details.path || include.alias === details.alias).length > 0; | ||
return includes.filter(include => include.value === details.path || include.value === details.alias).length > 0; | ||
} | ||
@@ -30,0 +30,0 @@ exports.isFieldAllowedByIncludes = isFieldAllowedByIncludes; |
{ | ||
"name": "@trapi/query", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "An tiny library which provides utility types/functions for request and response query handling.", | ||
@@ -53,3 +53,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "9cfbe2c6cd88204e5905170be27f8a368d93836f" | ||
"gitHead": "53d75cb70b5318468097755a5f08e92e36997fcf" | ||
} |
249
README.MD
@@ -8,9 +8,9 @@ # @trapi/query 🌈 | ||
This is a library for building `JSON:API` like REST-APIs. | ||
This is a library to build efficient and optimized `JSON:API` like REST-APIs. | ||
It extends the specification format between request- & response-handling for querying and fetching data according the following query parameters: | ||
It extends the specification format between request- & response-handling based on the following query parameters: | ||
- `fields` Return only specific fields or extend the default selection. | ||
- `filter`: Filter the data set, according specific criteria. | ||
- `include` Include related resources of the primary data. | ||
- `page` Limit the number of resources returned of the whole set. | ||
- `include` Include related resources (aka `relations`) of the primary data. | ||
- `page` Limit the number of resources returned of the whole set (`pagination`). | ||
- `sort` Sort the resources according one or more keys in asc/desc direction. | ||
@@ -37,20 +37,20 @@ | ||
- [QueryKey](#querykey) | ||
- [QueryKeyOption](#querykeyoption) | ||
- [QueryKeyParseOptions](#querykeyparseoptions) | ||
- [Record](#record) | ||
- [QueryRecord](#queryrecord) | ||
- [Parse](#parse) | ||
- [QueryParseOption](#queryparseoptions) | ||
- [QueryParseOutput](#queryparseoutput) | ||
- [Parsed](#parsed) | ||
- [FieldsParsed](#fieldsparsed) | ||
- [FiltersParsed](#filtersparsed) | ||
- [IncludeParsed](#includesparsed) | ||
- [PaginationParsed](#paginationparsed) | ||
- [SortParsed](#sortparsed) | ||
- [Options](#options) | ||
- [FieldsOptions](#fieldsoptions) | ||
- [FiltersOptions](#filtersoptions) | ||
- [IncludeOptions](#includesoptions) | ||
- [PaginationOptions](#paginationoptions) | ||
- [SortOptions](#sortoptions) | ||
- [Parse](#parse-types) | ||
- [Input](#queryparseinput) | ||
- [Output](#queryparseoutput) | ||
- [Fields](#fieldsparsed) | ||
- [Filter[s]](#filtersparsed) | ||
- [Relations/Include](#relationsparsed) | ||
- [Pagination/Page](#paginationparsed) | ||
- [Sort](#sortparsed) | ||
- [Parse Options](#parseoptions-types) | ||
- [General](#queryparseoptions) | ||
- [Fields](#fieldsparseoptions) | ||
- [Filter[s]](#filtersparseoptions) | ||
- [Relations/Include](#relationsparseoptions) | ||
- [Pagination/Page](#paginationparseoptions) | ||
- [Sort](#sortparseoptions) | ||
@@ -68,3 +68,3 @@ ## Installation | ||
The general idea is to construct a `QueryRecord` at the frontend side, which will be formatted to a string and passed to the backend application as URL query string. | ||
The backend application is than always fully capable of processing the request, as far the provided query was not malformed. | ||
The backend application is than always fully capable of processing the request. | ||
@@ -77,4 +77,4 @@ Therefore, two components of this module are required in the frontend application: | ||
In the following example a Class which will represent the structure of a `User`. | ||
The `getAPIUsers` will handle the resource request to the resource API. | ||
In the following example a Class which will represent the structure of a `User` and a function called | ||
`getAPIUsers`, which will handle the resource request to the resource API, will be defined. | ||
@@ -107,3 +107,5 @@ ```typescript | ||
export async function getAPIUsers(record: QueryRecord<User>): Promise<ResponsePayload> { | ||
export async function getAPIUsers( | ||
record: QueryRecord<User> | ||
): Promise<ResponsePayload> { | ||
const response = await axios.get('users' + buildQuery(record)); | ||
@@ -192,7 +194,4 @@ | ||
In this example [typeorm](https://www.npmjs.com/package/typeorm) is used as the object-relational mapping (ORM) and [typeorm-extension](https://www.npmjs.com/package/typeorm-extension) is used | ||
to apply the parsed request query parameters on the db query. | ||
to apply the parsed request query parameters on the db query and [express](https://www.npmjs.com/package/express) to handle requests. | ||
When you use [express](https://www.npmjs.com/package/express) or another library, you can use the API utils accordingly to the | ||
following code snippet: | ||
#### Parse - In Detail | ||
@@ -207,3 +206,3 @@ | ||
parseFilters, | ||
parseIncludes, | ||
parseRelations, | ||
parsePagination, | ||
@@ -246,3 +245,3 @@ parseSort, | ||
const includesParsed = parseIncludes(include, { | ||
const relationsParsed = parseRelations(include, { | ||
allowed: 'profile' | ||
@@ -255,3 +254,3 @@ }); | ||
// profile.id can only be used as sorting key, if the relation 'profile' is included. | ||
includes: includesParsed | ||
relations: relationsParsed | ||
}); | ||
@@ -262,3 +261,3 @@ | ||
allowed: ['id', 'name', 'profile.id'], // profile.id can only be used as sorting key, if the relation 'profile' is included. | ||
includes: includesParsed | ||
relations: relationsParsed | ||
}); | ||
@@ -273,3 +272,3 @@ | ||
allowed: ['id', 'name', 'profile.id'], // profile.id can only be used as sorting key, if the relation 'profile' is included. | ||
includes: includesParsed | ||
relations: relationsParsed | ||
}); | ||
@@ -281,3 +280,3 @@ | ||
[QueryKey.FILTER]: filterParsed, | ||
[QueryKey.INCLUDE]: includesParsed, | ||
[QueryKey.INCLUDE]: relationsParsed, | ||
// only allow to select 20 items at maximum. | ||
@@ -396,3 +395,3 @@ [QueryKey.PAGE]: pageParsed, | ||
applyFilters, | ||
applyIncludes, | ||
applyRelations, | ||
applyPagination, | ||
@@ -430,3 +429,3 @@ applySort | ||
const includes = applyIncludes(query, include, { | ||
const relations = applyRelations(query, include, { | ||
defaultAlias: 'user', | ||
@@ -440,3 +439,3 @@ allowed: ['profile'] | ||
// profile.id can only be used as sorting key, if the relation 'profile' is included. | ||
includes: includes | ||
relations: includes | ||
}); | ||
@@ -448,3 +447,3 @@ | ||
// porfile fields can only be included, if the relation 'profile' is included. | ||
includes: includes | ||
relations: includes | ||
}) | ||
@@ -457,3 +456,3 @@ | ||
// porfile.id can only be used as a filter, if the relation 'profile' is included. | ||
includes: includes | ||
relations: includes | ||
}); | ||
@@ -524,3 +523,3 @@ | ||
| `record` | `QueryRecord`<`T`> | Query specification [more](#record). | | ||
| `options` | `QueryBuildOptions` | Options for building fields, filter, include, ... query [more](#fieldsoptions) | ||
| `options` | `QueryBuildOptions` | Options for building fields, filter, include, ... | ||
@@ -590,3 +589,3 @@ #### Returns | ||
The function return an object. | ||
The function returns an object. | ||
## Types | ||
@@ -606,5 +605,5 @@ | ||
#### QueryKeyOption | ||
#### QueryKeyParseOptions | ||
```typescript | ||
export type QueryKeyOption<T extends QueryKey> = T extends QueryKey.FIELDS ? | ||
export type QueryKeyParseOptions<T extends QueryKey> = T extends QueryKey.FIELDS ? | ||
FieldsOptions : | ||
@@ -653,3 +652,3 @@ T extends QueryKey.FILTER ? | ||
T extends QueryKey.INCLUDE ? | ||
IncludesParsed : | ||
RelationsParsed : | ||
T extends QueryKey.PAGE ? | ||
@@ -662,12 +661,3 @@ PaginationParsed : | ||
### Parse | ||
#### QueryParseOptions | ||
```typescript | ||
export type QueryParseOptions = { | ||
/** | ||
* On default all query keys are enabled. | ||
*/ | ||
[K in QueryKey]?: QueryKeyOption<K> | boolean | ||
} | ||
``` | ||
### Parse Types | ||
@@ -688,4 +678,2 @@ #### QueryParseInput | ||
### Parsed | ||
#### FieldsParsed | ||
@@ -699,9 +687,17 @@ | ||
export type FieldParsed = { | ||
key: string, | ||
export type FieldsParsedElement = ParsedElementBase<QueryKey.FIELDS, FieldOperator>; | ||
export type FieldsParsed = FieldsParsedElement[]; | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
// relation/resource alias | ||
alias?: string, | ||
operator?: FieldOperator | ||
}; | ||
export type FieldsParsed = FieldParsed[]; | ||
// field name | ||
key: string, | ||
// '+' | '-' | ||
value?: FieldOperator | ||
} | ||
``` | ||
@@ -718,24 +714,43 @@ | ||
export type FilterParsed = { | ||
export type FiltersParsedElement = ParsedElementBase<QueryKey.FILTER, FilterValue<string | number | boolean | null>> & { | ||
operator?: { | ||
[K in FilterOperatorLabel]?: boolean | ||
} | ||
}; | ||
export type FiltersParsed = FiltersParsedElement[]; | ||
``` | ||
```text | ||
{ | ||
// relation/resource alias | ||
alias?: string, | ||
// filter name | ||
key: string, | ||
alias?: string, | ||
// {in: ..., ...} | ||
operator?: { | ||
[K in FilterOperatorLabel]?: boolean | ||
}, | ||
value: FilterValue<string | number | boolean | null> | ||
}; | ||
export type FiltersParsed = FilterParsed[]; | ||
} | ||
``` | ||
#### IncludesParsed | ||
#### RelationsParsed | ||
```typescript | ||
export type IncludeParsed = { | ||
property: string, | ||
alias: string | ||
}; | ||
export type IncludesParsed = IncludeParsed[]; | ||
export type RelationParsedElement = ParsedElementBase<QueryKey.INCLUDE, string>; | ||
export type RelationsParsed = RelationParsedElement[]; | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
// relation relative depth path | ||
key: string, | ||
// relation alias | ||
value: string | ||
} | ||
``` | ||
#### PaginationParsed | ||
@@ -758,58 +773,98 @@ | ||
export type SortElementParsed = { | ||
export type SortParsedElement = ParsedElementBase<QueryKey.SORT, SortDirection>; | ||
export type SortParsed = SortParsedElement[]; | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
// resource/relation alias | ||
alias?: string, | ||
// field name | ||
key: string, | ||
// 'ASC' | 'DESC' | ||
value: SortDirection | ||
} | ||
export type SortParsed = SortElementParsed[]; | ||
``` | ||
### Options | ||
### ParseOptions Types | ||
#### FieldsOptions | ||
#### QueryParseOptions | ||
```typescript | ||
export type FieldsOptions = { | ||
export type QueryParseOptions = { | ||
/** | ||
* On default all query keys are enabled. | ||
*/ | ||
[K in QueryKey]?: QueryKeyParseOptions<K> | boolean | ||
} | ||
``` | ||
#### FieldsParseOptions | ||
```typescript | ||
export type FieldsParseOptions = ParseOptionsBase<QueryKey.FIELDS, Record<string, string[]> | string[]>; | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
aliasMapping?: Record<string, string>, | ||
allowed?: Record<string, string[]> | string[], | ||
includes?: IncludesParsed, | ||
relations?: RelationsParsed, | ||
defaultAlias?: string | ||
}; | ||
} | ||
``` | ||
#### FiltersOptions | ||
#### FiltersParseOptions | ||
```typescript | ||
export type FiltersOptions = { | ||
export type FiltersParseOptions = ParseOptionsBase<QueryKey.FILTER> | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
aliasMapping?: Record<string, string>, | ||
allowed?: string[], | ||
includes?: IncludesParsed, | ||
defaultAlias?: string, | ||
queryBindingKeyFn?: (key: string) => string | ||
relations?: RelationsParsed, | ||
defaultAlias?: string | ||
} | ||
``` | ||
#### PaginationParseOptions | ||
```typescript | ||
export type PaginationParseOptions = ParseOptionsBase<QueryKey.PAGE> & { | ||
maxLimit?: number | ||
}; | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
maxLimit?: number | ||
} | ||
``` | ||
#### IncludesOptions | ||
#### RelationsParseOptions | ||
```typescript | ||
export type IncludesOptions = { | ||
export type RelationsParseOptions = ParseOptionsBase<QueryKey.SORT, string[] | string[][]>; | ||
``` | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
aliasMapping?: Record<string, string>, | ||
allowed?: string[], | ||
defaultAlias?: string, | ||
includeParents?: boolean | string[] | string | ||
defaultAlias?: string, | ||
}; | ||
} | ||
``` | ||
#### PaginationOptions | ||
#### SortParseOptions | ||
```typescript | ||
export type PaginationOptions = { | ||
maxLimit?: number | ||
}; | ||
export type SortOptions = ParseOptionsBase<QueryKey.SORT, string[] | string[][]>; | ||
``` | ||
#### SortOptions | ||
```typescript | ||
export type SortOptions = { | ||
The type looks like this from the structure: | ||
```text | ||
{ | ||
aliasMapping?: Record<string, string>, | ||
allowed?: string[] | string[][], | ||
includes?: IncludesParsed, | ||
defaultAlias?: string | ||
}; | ||
relations?: RelationsParsed | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132080
142
1454
845