getta 1.0.20 → 1.0.21

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "getta",
3
3
  "description": "An isomorphic rest client based on the Fetch API.",
4
- "version": "1.0.20",
4
+ "version": "1.0.21",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/getta",
@@ -1,5 +1,6 @@
1
1
  import { isFunction, omitBy } from 'lodash-es';
2
2
  import queryString from 'query-string';
3
+ import { type SearchParams } from '#types.js';
3
4
  import { type BuildEndpointOptions } from './types.ts';
4
5
 
5
6
  export const buildEndpoint = (
@@ -25,12 +26,12 @@ export const buildEndpoint = (
25
26
 
26
27
  export const appendSearchParams = (
27
28
  endpoint: string,
28
- searchParams: Record<string, string> | ((endpoint: string) => Record<string, string>),
29
- searchParamOverrides: Record<string, string> = {},
29
+ searchParams: SearchParams,
30
+ extraSearchParam: Record<string, string> = {},
30
31
  ) => {
31
32
  const mergedSearchParams = {
32
- ...(isFunction(searchParams) ? searchParams(endpoint) : searchParams),
33
- ...searchParamOverrides,
33
+ ...(isFunction(searchParams) ? searchParams(endpoint, extraSearchParam) : searchParams),
34
+ ...extraSearchParam,
34
35
  };
35
36
 
36
37
  // We have seen instances where value can be undefined
package/src/main.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  type RequestOptions,
26
26
  type RequestQueue,
27
27
  type RequestTracker,
28
+ type SearchParams,
28
29
  type ShortcutProperties,
29
30
  type Shortcuts,
30
31
  type StreamReader,
@@ -44,7 +45,7 @@ export class Getta {
44
45
  private _pathTemplateCallback: PathTemplateCallback;
45
46
  private _pathTemplateRegExp: RegExp;
46
47
  private _performance: Performance;
47
- private _queryParams: Record<string, string> | ((endpoint: string) => Record<string, string>);
48
+ private _queryParams: SearchParams;
48
49
  private _rateLimit: boolean;
49
50
  private _rateLimitCount = 0;
50
51
  private _rateLimitedRequestQueue: RequestQueue = [];
package/src/types.ts CHANGED
@@ -18,6 +18,10 @@ export type ShortcutProperties<T extends string | number> = Record<
18
18
  <Resource = PlainObject>(...args: any[]) => Promise<FetchResponse<Resource>>
19
19
  >;
20
20
 
21
+ export type SearchParams =
22
+ | Record<string, string>
23
+ | ((endpoint: string, extraSearchParams?: Record<string, string>) => Record<string, string>);
24
+
21
25
  export interface ConstructorOptions {
22
26
  /**
23
27
  * The base path of the url for all requests made from
@@ -91,7 +95,7 @@ export interface ConstructorOptions {
91
95
  /**
92
96
  * Any query params to attach to every request.
93
97
  */
94
- queryParams?: Record<string, string> | ((endpoint: string) => Record<string, string>);
98
+ queryParams?: SearchParams;
95
99
  /**
96
100
  * Whether to enable the rate limit feature.
97
101
  */