Skip to content

Commit

Permalink
Allow custom paramsSerializer to be able to implement React Native …
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbosco committed May 24, 2024
1 parent 287b1d0 commit 9f976f1
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 21 deletions.
37 changes: 21 additions & 16 deletions dist/typesense.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/typesense.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.min.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/Typesense/ApiCall.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Typesense/ApiCall.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions lib/Typesense/Configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export interface ConfigurationOptions {
* @type {HTTPSAgent}
*/
httpsAgent?: HTTPSAgent;
/**
* Set a custom paramsSerializer
*
* See axios documentation for more information on how to use this parameter: https://axios-http.com/docs/req_config
* This is helpful for handling React Native issues like this: https://github.com/axios/axios/issues/6102#issuecomment-2085301397
* @type {any}
*/
paramsSerializer?: any;
}
export default class Configuration {
readonly nodes: NodeConfiguration[] | NodeConfigurationWithHostname[] | NodeConfigurationWithUrl[];
Expand All @@ -84,6 +92,7 @@ export default class Configuration {
readonly additionalHeaders?: Record<string, string>;
readonly httpAgent?: HTTPAgent;
readonly httpsAgent?: HTTPSAgent;
readonly paramsSerializer?: any;
constructor(options: ConfigurationOptions);
validate(): boolean;
private validateNodes;
Expand Down
1 change: 1 addition & 0 deletions lib/Typesense/Configuration.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Typesense/Configuration.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/Typesense/ApiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ export default class ApiCall {
requestOptions.httpsAgent = new HTTPSAgent({ keepAlive: true });
}

if (this.configuration.paramsSerializer) {
this.logger.debug(
`Request #${requestNumber}: Using custom paramsSerializer`,
);
requestOptions.paramsSerializer = this.configuration.paramsSerializer;
}

if (
bodyParameters &&
((typeof bodyParameters === "string" &&
Expand Down
12 changes: 12 additions & 0 deletions src/Typesense/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export interface ConfigurationOptions {
* @type {HTTPSAgent}
*/
httpsAgent?: HTTPSAgent;

/**
* Set a custom paramsSerializer
*
* See axios documentation for more information on how to use this parameter: https://axios-http.com/docs/req_config
* This is helpful for handling React Native issues like this: https://github.com/axios/axios/issues/6102#issuecomment-2085301397
* @type {any}
*/
paramsSerializer?: any;
}

export default class Configuration {
Expand All @@ -110,6 +119,7 @@ export default class Configuration {
readonly additionalHeaders?: Record<string, string>;
readonly httpAgent?: HTTPAgent;
readonly httpsAgent?: HTTPSAgent;
readonly paramsSerializer?: any;

constructor(options: ConfigurationOptions) {
this.nodes = options.nodes || [];
Expand Down Expand Up @@ -155,6 +165,8 @@ export default class Configuration {
this.httpAgent = options.httpAgent;
this.httpsAgent = options.httpsAgent;

this.paramsSerializer = options.paramsSerializer;

this.showDeprecationWarnings(options);
this.validate();
}
Expand Down

0 comments on commit 9f976f1

Please sign in to comment.