-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
223 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import createClient from "openapi-fetch"; | ||
|
||
import type { paths } from "./types/openapi-schema.js"; | ||
|
||
export type Client = typeof client; | ||
|
||
export const client = createClient<paths>(); |
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 +1,4 @@ | ||
export * from "./types.js"; | ||
export * from "./types/components-alias.js"; | ||
export * from "./types/openapi-schema.js"; | ||
export * from "./client.js"; | ||
export * from "./requests.js"; |
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 |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import type { FetchResponse, MaybeOptionalInit } from "openapi-fetch"; | ||
import { objectToCamel, objectToSnake } from "ts-case-convert"; | ||
|
||
import { type Client, client as defaultClient } from "./client.js"; | ||
import type { paths } from "./types/openapi-schema.js"; | ||
import type { | ||
CamelCaseData, | ||
CommonQuery, | ||
HttpMethod, | ||
} from "./types/utilities.js"; | ||
|
||
function createRequest< | ||
Path extends keyof paths, | ||
Method extends HttpMethod, | ||
FetchInit extends MaybeOptionalInit<paths[Path], Method>, | ||
Params, | ||
>(path: Path, method: Method, getInit: (params: Params) => FetchInit) { | ||
return async ( | ||
params: Params, | ||
init?: Omit<MaybeOptionalInit<paths[Path], Method>, "params"> | null, | ||
client: Client = defaultClient, | ||
): Promise< | ||
CamelCaseData< | ||
FetchResponse<paths[Path][Method], FetchInit, `${string}/${string}`> | ||
> | ||
> => { | ||
// biome-ignore lint/suspicious/noExplicitAny: Too complex to type | ||
const res = await (client as any)[ | ||
method.toUpperCase() as Uppercase<Method> | ||
](path, { ...getInit(params), ...init }); | ||
|
||
if (res.data && typeof res.data === "object") { | ||
res.data = objectToCamel(res.data); | ||
} | ||
|
||
return res; | ||
}; | ||
} | ||
|
||
export const getActivity = createRequest( | ||
"/decentralized/tx/{id}", | ||
"get", | ||
({ id, ...query }: CommonQuery<"/decentralized/tx/{id}", "get">) => ({ | ||
params: { path: { id }, query: objectToSnake(query) }, | ||
}), | ||
); | ||
|
||
export const getAccountActivities = createRequest( | ||
"/decentralized/{account}", | ||
"get", | ||
({ account, ...query }: CommonQuery<"/decentralized/{account}", "get">) => ({ | ||
params: { path: { account }, query: objectToSnake(query) }, | ||
}), | ||
); | ||
|
||
export const getRssActivity = createRequest( | ||
"/rss/{path}", | ||
"get", | ||
(path: CommonQuery<"/rss/{path}", "get">) => ({ | ||
params: { path }, | ||
}), | ||
); | ||
|
||
const o = { | ||
"/nta/bridge/transactions": { | ||
get: "getBridgingTransactions", | ||
}, | ||
"/nta/bridge/transactions/{transaction_hash}": { | ||
get: "getBridgingTransactionByHash", | ||
}, | ||
"/nta/stake/transactions": { | ||
get: "getStakingTransactions", | ||
}, | ||
"/nta/stake/transactions/{transaction_hash}": { | ||
get: "getStakingTransactionByHash", | ||
}, | ||
"/nta/stake/stakings": { | ||
get: "getListofStakersAndNodes", | ||
}, | ||
"/nta/stake/{staker_address}/profit": { | ||
get: "getStakingProfitByStaker", | ||
}, | ||
"/nta/chips": { | ||
get: "getAllChips", | ||
}, | ||
"/nta/chips/{chip_id}": { | ||
get: "getChipById", | ||
}, | ||
"/nta/chips/{chip_id}/image.svg": { | ||
get: "getChipImageById", | ||
}, | ||
"/nta/snapshots/nodes/count": { | ||
get: "getNodeCountSnapshot", | ||
}, | ||
"/nta/snapshots/nodes/min_tokens_to_stake": { | ||
post: "minimumStakingAmountSnapshot", | ||
}, | ||
"/nta/snapshots/stakers/count": { | ||
get: "getStakerCountSnapshot", | ||
}, | ||
"/nta/snapshots/stakers/profit": { | ||
get: "getStakerProfitSnapshot", | ||
}, | ||
"/nta/snapshots/nodes/operation/profit": { | ||
get: "getOperationProfitSnapshot", | ||
}, | ||
"/nta/snapshots/epochs/apy": { | ||
get: "getEpochsApySnapshot", | ||
}, | ||
"/nta/nodes": { | ||
get: "getAllNodes", | ||
}, | ||
"/nta/nodes/{address}": { | ||
get: "getNodeByAddress", | ||
}, | ||
"/nta/nodes/{address}/avatar.svg": { | ||
get: "getNodeAvatarByAddress", | ||
}, | ||
"/nta/nodes/{address}/events": { | ||
get: "getNodeEventsByAddress", | ||
}, | ||
"/nta/nodes/{node_address}/operation/profit": { | ||
get: "getNodeOperationProfitByAddress", | ||
}, | ||
"/nta/epochs": { | ||
get: "getAllEpochs", | ||
}, | ||
"/nta/epochs/{epoch_id}": { | ||
get: "getEpochById", | ||
}, | ||
"/nta/epochs/distributions/{transaction_hash}": { | ||
get: "getEpochTransactionByHash", | ||
}, | ||
"/nta/epochs/{node_address}/rewards": { | ||
get: "getNodeRewardsByEpoch", | ||
}, | ||
"/nta/epochs/apy": { | ||
get: "getAverageEpochsApy", | ||
}, | ||
"/nta/networks": { | ||
get: "getAllCompatibleNetworks", | ||
}, | ||
"/nta/networks/{network_name}/list_workers": { | ||
get: "getAvailableWorkersByNetwork", | ||
}, | ||
"/nta/networks/{network_name}/workers/{worker_name}": { | ||
get: "getConfigByNetworkAndWorker", | ||
}, | ||
}; |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { ObjectToCamel } from "ts-case-convert/lib/caseConvert.js"; | ||
|
||
import type { paths } from "./openapi-schema.js"; | ||
|
||
export type CamelCaseKeys<T> = T extends object ? ObjectToCamel<T> : T; | ||
|
||
export type CamelCaseData<T> = T extends { data: infer D } | ||
? Omit<T, "data"> & { data: CamelCaseKeys<D> } | ||
: T; | ||
|
||
export type HttpMethod = | ||
| "get" | ||
| "put" | ||
| "post" | ||
| "delete" | ||
| "options" | ||
| "head" | ||
| "patch" | ||
| "trace"; | ||
|
||
type MapNeverTo<T, R> = [T] extends [never] ? R : T; | ||
|
||
type PathParameters<Method> = MapNeverTo< | ||
Method extends { parameters: { path: infer P } } ? P : never, | ||
object | ||
>; | ||
|
||
type QueryParameters<Method> = MapNeverTo< | ||
Method extends { parameters: { query?: infer Q } } | ||
? Q extends object | ||
? Q | ||
: never | ||
: never, | ||
object | ||
>; | ||
|
||
export type CommonQuery< | ||
Path extends keyof paths, | ||
Method extends HttpMethod, | ||
> = CamelCaseKeys< | ||
PathParameters<paths[Path][Method]> & QueryParameters<paths[Path][Method]> | ||
>; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.