Skip to content

Commit

Permalink
Allow to use booleans in FetchApiRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Apr 3, 2023
1 parent ab5c118 commit 8bf8b77
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-wolves-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@farfetched/core': patch
---

Allow to use booleans in FetchApiRecord
2 changes: 1 addition & 1 deletion packages/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"size": {
"executor": "./tools/executors/size-limit:size-limit",
"options": {
"limit": "18.3 kB",
"limit": "18.4 kB",
"outputPath": "dist/packages/core"
},
"dependsOn": [
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/fetch/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export type FetchApiRecord = Record<string, string | string[] | number>;
export type FetchApiRecord = Record<
string,
string | string[] | number | boolean
>;

export function mergeRecords(
...records: (FetchApiRecord | undefined | null)[]
Expand Down Expand Up @@ -96,8 +99,10 @@ function recordToUrlSearchParams(record: FetchApiRecord): URLSearchParams {
return params;
}

function clearValue(value: string | string[] | number): string | string[] {
if (typeof value === 'number') {
function clearValue(
value: string | string[] | number | boolean
): string | string[] {
if (typeof value === 'number' || typeof value === 'boolean') {
return value.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { describe, test } from 'vitest';
import { createJsonQuery } from '../create_json_query';
import { Contract } from '../../contract/type';
import { createStore } from 'effector';
import { declareParams } from '../../remote_operation/params';
import { unknownContract } from '../../contract/unknown_contract';

describe('createJsonQuery query', () => {
const response = {
Expand Down Expand Up @@ -35,4 +37,23 @@ describe('createJsonQuery query', () => {
response,
});
});

test('supports boolean field in params', () => {
const query = createJsonQuery({
params: declareParams<{
id: string;
from: number;
to: number;
monthly: boolean;
}>(),
request: {
url,
method: 'GET',
query: ({ from, to, monthly }) => ({ from, to, monthly }),
},
response: {
contract: unknownContract,
},
});
});
});

0 comments on commit 8bf8b77

Please sign in to comment.