-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-ignore-fields' into 'dev'
create axios package See merge request ergo/rosen-bridge/network-client!23
- Loading branch information
Showing
20 changed files
with
893 additions
and
993 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ node_modules | |
yarn.lock | ||
dist | ||
.nyc_output | ||
# TypeScript cache | ||
*.tsbuildinfo |
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
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 |
---|---|---|
@@ -1,59 +1,9 @@ | ||
import Axios, { AxiosRequestConfig } from 'axios'; | ||
import JsonBigintFactory from 'json-bigint'; | ||
|
||
const JsonBigInt = JsonBigintFactory({ | ||
alwaysParseAsBig: false, | ||
useNativeBigInt: true, | ||
}); | ||
|
||
const transformBigInt = (obj: any, bigIntObj: any, field: string): any => { | ||
if (Array.isArray(obj)) { | ||
return (obj as unknown as Array<JSON>).map((row, index) => { | ||
return transformBigInt( | ||
row, | ||
(bigIntObj as unknown as Array<JSON>)[index], | ||
field | ||
); | ||
}) as unknown as JSON; | ||
} | ||
if (!Object.hasOwn(obj, field.split('.')[0])) { | ||
return { | ||
...obj, | ||
}; | ||
} | ||
if (field.indexOf('.') !== -1) { | ||
const subKeys = field.split('.'); | ||
return { | ||
...obj, | ||
[subKeys[0]]: transformBigInt( | ||
obj[subKeys[0]], | ||
bigIntObj[subKeys[0]], | ||
subKeys.slice(1).join('.') | ||
), | ||
}; | ||
} | ||
return { ...obj, [field]: BigInt(bigIntObj[field]) }; | ||
}; | ||
export const JsonFieldBigintFactory = (fields: Array<string>) => { | ||
return (data: any) => { | ||
let dataJson = JSON.parse(data); | ||
const dataBigInt = JsonBigInt.parse(data); | ||
fields.forEach((field) => { | ||
dataJson = transformBigInt(dataJson, dataBigInt, field); | ||
}); | ||
return dataJson; | ||
}; | ||
}; | ||
|
||
export const axiosInstance = Axios.create(); | ||
|
||
export const createAxiosInstance = (url: string, authToken?: string) => { | ||
const instance = Axios.create(); | ||
instance.defaults.baseURL = url; | ||
if (authToken) { | ||
instance.defaults.headers.common['Authorization'] = `Bearer ${authToken}`; | ||
} | ||
return <T>(config: AxiosRequestConfig): Promise<T> => { | ||
return instance.request<T>(config).then((response) => response.data); | ||
}; | ||
import { createAxiosInstanceWithHeaders } from '@rosen-clients/axios'; | ||
export { | ||
JsonFieldBigintFactory, | ||
createAxiosInstanceWithHeaders, | ||
} from '@rosen-clients/axios'; | ||
|
||
export const createAxiosInstance = (url: string) => { | ||
return createAxiosInstanceWithHeaders(url, {}); | ||
}; |
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
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 |
---|---|---|
@@ -1,54 +1,6 @@ | ||
import Axios, { AxiosRequestConfig } from 'axios'; | ||
import JsonBigintFactory from 'json-bigint'; | ||
|
||
const JsonBigInt = JsonBigintFactory({ | ||
alwaysParseAsBig: false, | ||
useNativeBigInt: true, | ||
}); | ||
|
||
const transformBigInt = (obj: any, bigIntObj: any, field: string): any => { | ||
if (Array.isArray(obj)) { | ||
return (obj as unknown as Array<JSON>).map((row, index) => { | ||
return transformBigInt( | ||
row, | ||
(bigIntObj as unknown as Array<JSON>)[index], | ||
field | ||
); | ||
}) as unknown as JSON; | ||
} | ||
if (!Object.hasOwn(obj, field.split('.')[0])) { | ||
return { | ||
...obj, | ||
}; | ||
} | ||
if (field.indexOf('.') !== -1) { | ||
const subKeys = field.split('.'); | ||
return { | ||
...obj, | ||
[subKeys[0]]: transformBigInt( | ||
obj[subKeys[0]], | ||
bigIntObj[subKeys[0]], | ||
subKeys.slice(1).join('.') | ||
), | ||
}; | ||
} | ||
return { ...obj, [field]: BigInt(bigIntObj[field]) }; | ||
}; | ||
export const JsonFieldBigintFactory = (fields: Array<string>) => { | ||
return (data: any) => { | ||
let dataJson = JSON.parse(data); | ||
const dataBigInt = JsonBigInt.parse(data); | ||
fields.forEach((field) => { | ||
dataJson = transformBigInt(dataJson, dataBigInt, field); | ||
}); | ||
return dataJson; | ||
}; | ||
}; | ||
import { createAxiosInstanceWithHeaders } from '@rosen-clients/axios'; | ||
export { JsonFieldBigintFactory } from '@rosen-clients/axios'; | ||
|
||
export const createAxiosInstance = (url: string) => { | ||
const instance = Axios.create(); | ||
instance.defaults.baseURL = url; | ||
return <T>(config: AxiosRequestConfig): Promise<T> => { | ||
return instance.request<T>(config).then((response) => response.data); | ||
}; | ||
return createAxiosInstanceWithHeaders(url, {}); | ||
}; |
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
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 |
---|---|---|
@@ -1,56 +1,6 @@ | ||
import Axios, { AxiosRequestConfig } from 'axios'; | ||
import JsonBigintFactory from 'json-bigint'; | ||
|
||
const JsonBigInt = JsonBigintFactory({ | ||
alwaysParseAsBig: false, | ||
useNativeBigInt: true, | ||
}); | ||
|
||
const transformBigInt = (obj: any, bigIntObj: any, field: string): any => { | ||
if (Array.isArray(obj)) { | ||
return (obj as unknown as Array<JSON>).map((row, index) => { | ||
return transformBigInt( | ||
row, | ||
(bigIntObj as unknown as Array<JSON>)[index], | ||
field | ||
); | ||
}) as unknown as JSON; | ||
} | ||
if (!Object.hasOwn(obj, field.split('.')[0])) { | ||
return { | ||
...obj, | ||
}; | ||
} | ||
if (field.indexOf('.') !== -1) { | ||
const subKeys = field.split('.'); | ||
return { | ||
...obj, | ||
[subKeys[0]]: transformBigInt( | ||
obj[subKeys[0]], | ||
bigIntObj[subKeys[0]], | ||
subKeys.slice(1).join('.') | ||
), | ||
}; | ||
} | ||
return { ...obj, [field]: BigInt(bigIntObj[field]) }; | ||
}; | ||
export const JsonFieldBigintFactory = (fields: Array<string>) => { | ||
return (data: any) => { | ||
let dataJson = JSON.parse(data); | ||
const dataBigInt = JsonBigInt.parse(data); | ||
fields.forEach((field) => { | ||
dataJson = transformBigInt(dataJson, dataBigInt, field); | ||
}); | ||
return dataJson; | ||
}; | ||
}; | ||
|
||
export const axiosInstance = Axios.create(); | ||
import { createAxiosInstanceWithHeaders } from '@rosen-clients/axios'; | ||
export { JsonFieldBigintFactory } from '@rosen-clients/axios'; | ||
|
||
export const createAxiosInstance = (url: string) => { | ||
const instance = Axios.create(); | ||
instance.defaults.baseURL = url; | ||
return <T>(config: AxiosRequestConfig): Promise<T> => { | ||
return instance.request<T>(config).then((response) => response.data); | ||
}; | ||
return createAxiosInstanceWithHeaders(url, {}); | ||
}; |
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
Oops, something went wrong.