@ethlete/query 4.3.4 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,9 +8,10 @@ export interface PageParamCalculatorOptions {
8
8
  totalPages: number | null;
9
9
  itemsPerPage: number;
10
10
  }
11
- export interface TotalPagesExtractorOptions<QueryResponse> {
11
+ export interface TotalPagesExtractorOptions<QueryResponse, Arguments> {
12
12
  response: QueryResponse;
13
13
  itemsPerPage: number;
14
+ arguments: Arguments;
14
15
  }
15
16
  export interface InfinityQueryConfig<QueryCreator extends AnyQueryCreator, Arguments extends BaseArguments | undefined, QueryResponse, InfinityResponse extends unknown[]> {
16
17
  /**
@@ -87,7 +88,7 @@ export interface InfinityQueryConfig<QueryCreator extends AnyQueryCreator, Argum
87
88
  *
88
89
  * @default "totalPages"
89
90
  */
90
- totalPagesExtractor?: (data: TotalPagesExtractorOptions<QueryResponse>) => number;
91
+ totalPagesExtractor?: (data: TotalPagesExtractorOptions<QueryResponse, Arguments>) => number;
91
92
  };
92
93
  }
93
94
  type OmitUndefined<T> = T extends undefined ? never : T;
@@ -34,6 +34,10 @@ export declare class Query<Response, Arguments extends BaseArguments | undefined
34
34
  * @internal
35
35
  */
36
36
  get _enableSmartPolling(): boolean;
37
+ /**
38
+ * @internal
39
+ */
40
+ get _arguments(): Arguments;
37
41
  get store(): Store | null;
38
42
  constructor(_client: QueryClient, _queryConfig: RestQueryConfig<Route, Response, Arguments, Store, Data, Id> | GqlQueryConfig<Route, Response, Arguments, Store, Data, Id>, _routeWithParams: Route, _args: Arguments);
39
43
  execute(options?: ExecuteQueryOptions): this;
@@ -1,5 +1,5 @@
1
1
  import { GqlTransferOption } from '../query/query.types';
2
- import { CacheAdapterFn, RequestHeaders, RequestHeadersMethodMap, RequestRetryFn } from '../request';
2
+ import { BuildQueryStringConfig, CacheAdapterFn, RequestHeaders, RequestHeadersMethodMap, RequestRetryFn } from '../request';
3
3
  import { QueryClient } from './query-client';
4
4
  export interface QueryClientConfig {
5
5
  /**
@@ -64,6 +64,10 @@ export interface QueryClientConfig {
64
64
  */
65
65
  transferVia?: GqlTransferOption;
66
66
  };
67
+ /**
68
+ * Configuration options for all query strings.
69
+ */
70
+ queryParams?: BuildQueryStringConfig;
67
71
  };
68
72
  /**
69
73
  * Parent query client.
@@ -6,17 +6,10 @@ export interface RequestError<Detail = unknown> {
6
6
  statusText: string;
7
7
  detail: Detail;
8
8
  }
9
- export type ParamPrimitive = string | number | boolean | null | undefined;
10
- export type Params = Record<string | number | symbol, ParamPrimitive | ParamArray>;
11
- export type ParamArray = Array<ParamPrimitive>;
12
- export type UnfilteredParamPrimitive = string | number | boolean | null | undefined;
13
- export type QueryParams = {
14
- [key: string]: UnfilteredParamPrimitive | UnfilteredParamArray | QueryParams;
15
- };
9
+ export type RequestHeaders = Record<string, string>;
10
+ export type QueryParams = Record<string | number, unknown | Array<unknown>>;
16
11
  export type PathParams = Record<string, string | number>;
17
- export type UnfilteredParamArray = Array<UnfilteredParamPrimitive>;
18
12
  export type CacheAdapterFn = (headers: RequestHeaders) => number | null;
19
- export type RequestHeaders = Record<string, string>;
20
13
  export type RequestHeadersMethodMap = {
21
14
  [M in Method]?: RequestHeaders;
22
15
  };
@@ -85,3 +78,33 @@ export type RequestEvent<Response = unknown> = {
85
78
  type: 'cancel';
86
79
  headers: RequestHeaders;
87
80
  };
81
+ export interface BuildQueryStringConfig {
82
+ /**
83
+ * Object notation to use for nested objects.
84
+ *
85
+ * @example
86
+ * // dot notation
87
+ * { foo: { bar: 'baz' } } => "foo.bar=baz"
88
+ *
89
+ * @example
90
+ * // bracket notation
91
+ * { foo: { bar: 'baz' } } => "foo[bar]=baz"
92
+ *
93
+ * @default 'bracket'
94
+ */
95
+ objectNotation?: 'dot' | 'bracket';
96
+ /**
97
+ * Whether to write array indexes in bracket notation.
98
+ *
99
+ * @example
100
+ * // true
101
+ * { foo: ['bar', 'baz'] } => "foo[0]=bar&foo[1]=baz"
102
+ *
103
+ * @example
104
+ * // false
105
+ * { foo: ['bar', 'baz'] } => "foo[]=bar&foo[]=baz"
106
+ *
107
+ * @default false
108
+ */
109
+ writeArrayIndexes?: boolean;
110
+ }
@@ -1,16 +1,13 @@
1
- import { Method, ParamArray, Params, QueryParams, RequestError, RequestHeaders, RequestRetryFn, UnfilteredParamPrimitive } from './request.types';
1
+ import { BuildQueryStringConfig, Method, QueryParams, RequestError, RequestHeaders, RequestRetryFn } from './request.types';
2
2
  export declare const isRequestError: <T = unknown>(error: unknown) => error is RequestError<T>;
3
3
  export declare const buildRoute: (options: {
4
4
  base: string;
5
5
  route: string | ((args: Record<string, unknown>) => string) | null | undefined;
6
6
  pathParams?: Record<string, unknown> | undefined;
7
7
  queryParams?: QueryParams | undefined;
8
+ queryParamConfig?: BuildQueryStringConfig | undefined;
8
9
  }) => string;
9
- export declare const buildQueryString: (params: QueryParams) => string | null;
10
- export declare const buildQueryArrayString: (key: string, array: ParamArray) => string;
11
- export declare const buildQueryObjectString: (key: string, object: QueryParams) => string;
12
- export declare const filterInvalidParams: (params: QueryParams) => Params;
13
- export declare const isParamValid: (primitive: UnfilteredParamPrimitive) => boolean;
10
+ export declare const buildQueryString: (params: QueryParams, config?: BuildQueryStringConfig) => string | null;
14
11
  export declare const extractExpiresInSeconds: (headers: RequestHeaders) => number | null;
15
12
  export declare const buildTimestampFromSeconds: (seconds: number | null) => number | null;
16
13
  export declare const serializeBody: (body: unknown) => ArrayBuffer | URLSearchParams | Blob | FormData | string | null;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@ethlete/query",
3
- "version": "4.3.4",
3
+ "version": "4.4.0",
4
4
  "dependencies": {
5
5
  "tslib": "^2.5.0"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "@angular/common": "^15.2.1 || ^16.0.0",
9
9
  "@angular/core": "^15.2.1 || ^16.0.0",
10
- "@ethlete/core": "2.7.2"
10
+ "@ethlete/core": "2.8.0"
11
11
  },
12
12
  "module": "fesm2022/ethlete-query.mjs",
13
13
  "typings": "index.d.ts",