Skip to content

Commit

Permalink
fix(generics): use named generic
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 15, 2024
1 parent 37f27d3 commit af121fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class ArIO implements ContractCache {
* Fetches the state of a contract.
* @param {string} contractTxId - The Arweave transaction id of the contract.
*/
async getContractState<T>({
async getContractState<ContractState>({
contractTxId,
}: {
contractTxId: string;
}): Promise<T> {
return this.contractStateProvider.getContractState({ contractTxId });
}): Promise<ContractState> {
return this.contractStateProvider.getContractState<ContractState>({
contractTxId,
});
}
}
8 changes: 5 additions & 3 deletions src/common/caches/arns-remote-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ export class ArNSRemoteCache implements ContractCache {
});
}

async getContractState<T>({
async getContractState<ContractState>({
contractTxId,
}: {
contractTxId: string;
}): Promise<T> {
}): Promise<ContractState> {
this.logger.debug(`Fetching contract state`);

const { state } = await this.http.get<EvaluatedContractState<T>>({
const { state } = await this.http.get<
EvaluatedContractState<ContractState>
>({
endpoint: `/contract/${contractTxId.toString()}`,
});

Expand Down
15 changes: 10 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ export interface ContractCache {
/**
* The ContractStateProvider interface is used to define a contract state provider.
*/
getContractState<T>({ contractTxId }: { contractTxId: string }): Promise<T>;
getContractState<ContractState>({
contractTxId,
}: {
contractTxId: string;
}): Promise<ContractState>;
}

export type EvaluatedContractState<T> = EvalStateResult<T> & {
sortKey: string;
evaluationOptions: EvaluationOptions;
};
export type EvaluatedContractState<ContractState> =
EvalStateResult<ContractState> & {
sortKey: string;
evaluationOptions: EvaluationOptions;
};

/* eslint-disable @typescript-eslint/no-explicit-any */
export interface Logger {
Expand Down

0 comments on commit af121fa

Please sign in to comment.