-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b612b0
commit 01dff74
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { FilterGroupsConfig } from '../../../components'; | ||
import Logger from '../../../util/logger'; | ||
import { NsParamsType } from './nsQueryFunctions'; | ||
|
||
/** | ||
* Returns a string, or null, which stripes-connect will use to construct a resource query. | ||
* | ||
* Accepts four params: | ||
* @param queryParams An object containing the UI URL's query parameters (as accessed by ?{name}). | ||
* @param pathComponents An object containing the UI URL's path components (as accessed by :{name}). | ||
* @param resourceData An object containing the component's resources' data (as accessed by %{name}). | ||
* @param logger A logger object. | ||
*/ | ||
export type QueryFunction = ( | ||
queryParams: Record<string, unknown>, | ||
pathComponents: Record<string, unknown>, | ||
resourceData: { query: Record<string, unknown> }, | ||
logger: Logger, | ||
) => string | null; | ||
|
||
/** | ||
* Builds a {@link QueryFunction} | ||
* | ||
* @param findAll CQL query to retrieve all records when there is a sort clause but no CQL query | ||
* @param queryTemplate CQL query to interpolate, or function which will return CQL | ||
* @param sortMap map from sort keys to CQL fields | ||
* @param filterConfig list of filter objects, see {@link FilterGroupsConfig} | ||
* @param failOnCondition one of the following: | ||
* - 0 (or false (legacy)): do not fail even if query and filters and empty | ||
* - 1 (or true (legacy)): fail if query is empty, whatever the filter state | ||
* - 2: fail if both query and filters and empty | ||
* @param nsParams namespace keys | ||
* @param configOrEscape an object containing configuration parameters: | ||
* - escape: whether to escape the query string (default true) | ||
* - rightTrunc: whether to right-truncate the query string (default true) | ||
* For backwards compatibility, this parameter may also be a boolean, in which case it is used as the `escape` configuration value. | ||
*/ | ||
export default function makeQueryFunction( | ||
findAll: string, | ||
queryTemplate: | ||
| string | ||
| (( | ||
nsQueryParams: Record<string, unknown>, | ||
pathComponents: Record<string, unknown>, | ||
queryObj: { query: Record<string, unknown> }, | ||
) => string), | ||
sortMap: Record<string, string>, | ||
filterConfig: FilterGroupsConfig, | ||
failOnCondition: 0 | 1 | 2 | true | false, | ||
nsParams: NsParamsType, | ||
configOrEscape: boolean | { escape?: boolean; rightTrunc?: boolean }, | ||
): QueryFunction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export type NsParamsType = string | Record<string, unknown> | undefined | null; | ||
|
||
export function getNsKey(key: string, params?: NsParamsType): string; | ||
|
||
/** | ||
* | ||
* Adds namespace / prefix to keys in whitelist for given values object | ||
* | ||
* @example | ||
* ``` | ||
* values = mapNsKeys({ query: "test", filters: 'active', userId: 1 }, 'users') | ||
* // result: { "users.query" : "test", "users.filters": "active", userId: 1 } | ||
* ``` | ||
*/ | ||
export function mapNsKeys( | ||
values: Record<string, unknown>, | ||
params?: NsParamsType, | ||
): Record<string, unknown>; | ||
|
||
/** | ||
* Removes namespace / prefix from keys for given values object | ||
* | ||
* @example | ||
* ``` | ||
* values = removeNsKeys({ "users.query" : "test", "users.filters": "active" }, 'users') | ||
* // result: { query: "test", filters: 'active' } | ||
* ``` | ||
*/ | ||
export function removeNsKeys( | ||
values: Record<string, unknown>, | ||
params?: NsParamsType, | ||
): Record<string, unknown>; |