Skip to content

Commit

Permalink
Merge pull request #169 from ar-io/types
Browse files Browse the repository at this point in the history
fix(types): remove deprecated types, standardize existing types
  • Loading branch information
dtfiedler authored Aug 6, 2024
2 parents adba856 + c674876 commit aaabbb0
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 540 deletions.
39 changes: 0 additions & 39 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ import {
} from '@permaweb/aoconnect';
import { Signer } from 'arbundles';

import {
AllowedProtocols,
GatewayConnectionSettings,
GatewayMetadata,
GatewayStakingSettings,
} from './contract-state.js';
import { mIOToken } from './token.js';

export type BlockHeight = number;
export type SortKey = string;
export type Timestamp = number;
Expand Down Expand Up @@ -64,43 +56,12 @@ export type WriteParameters<Input> = WithSigner<

export type AoMessageResult = { id: string };

// Helper type to overwrite properties of A with B
type Overwrite<T, U> = {
[K in keyof T]: K extends keyof U ? U[K] : T[K];
};

export type JoinNetworkParams = Overwrite<
GatewayConnectionSettings & GatewayStakingSettings & GatewayMetadata,
{
minDelegatedStake: number | mIOToken; // TODO: this is for backwards compatibility
}
>;

// Original type definition refined with proper field-specific types
export type UpdateGatewaySettingsParamsBase = {
allowDelegatedStaking?: boolean;
delegateRewardShareRatio?: number;
fqdn?: string;
label?: string;
minDelegatedStake?: number | mIOToken; // TODO: this is for backwards compatibility - eventually we'll drop number
note?: string;
port?: number;
properties?: string;
protocol?: AllowedProtocols;
autoStake?: boolean;
observerAddress?: WalletAddress;
};

// Utility type to require at least one of the fields
export type AtLeastOne<
T,
U = { [K in keyof T]-?: Record<K, T[K]> },
> = Partial<T> & U[keyof U];

// Define the type used for function parameters
export type UpdateGatewaySettingsParams =
AtLeastOne<UpdateGatewaySettingsParamsBase>;

export interface HTTPClient {
get<I, K>({
endpoint,
Expand Down
12 changes: 6 additions & 6 deletions src/common/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {
ANTRecord,
AoANTRead,
AoANTRecord,
AoANTState,
AoANTWrite,
AoMessageResult,
Expand Down Expand Up @@ -107,29 +107,29 @@ export class AoANTReadable implements AoANTRead {
* ant.getRecord({ undername: "john" });
* ```
*/
async getRecord({ undername }: { undername: string }): Promise<ANTRecord> {
async getRecord({ undername }: { undername: string }): Promise<AoANTRecord> {
const tags = [
{ name: 'Sub-Domain', value: undername },
{ name: 'Action', value: 'Record' },
];

const record = await this.process.read<ANTRecord>({
const record = await this.process.read<AoANTRecord>({
tags,
});
return record;
}

/**
* @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
* @returns {Promise<Record<string, AoANTRecord>>} All the undernames managed by the ANT.
* @example
* Get the current records
* ```ts
* ant.getRecords();
* ````
*/
async getRecords(): Promise<Record<string, ANTRecord>> {
async getRecords(): Promise<Record<string, AoANTRecord>> {
const tags = [{ name: 'Action', value: 'Records' }];
const records = await this.process.read<Record<string, ANTRecord>>({
const records = await this.process.read<Record<string, AoANTRecord>>({
tags,
});
return records;
Expand Down
51 changes: 23 additions & 28 deletions src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
import Arweave from 'arweave';

import { IO_TESTNET_PROCESS_ID } from '../constants.js';
import {
ArNSReservedNameData,
EpochDistributionData,
EpochObservations,
WeightedObserver,
} from '../contract-state.js';
import {
AoArNSNameData,
AoEpochData,
Expand All @@ -37,17 +31,21 @@ import {
import { AoSigner, mIOToken } from '../token.js';
import {
AoArNSNameDataWithName,
AoArNSReservedNameData,
AoBalanceWithAddress,
AoEpochDistributionData,
AoEpochObservationData,
AoGatewayWithAddress,
AoJoinNetworkParams,
AoMessageResult,
AoUpdateGatewaySettingsParams,
AoWeightedObserver,
ContractSigner,
JoinNetworkParams,
OptionalSigner,
PaginationParams,
PaginationResult,
ProcessConfiguration,
TransactionId,
UpdateGatewaySettingsParams,
WalletAddress,
WithSigner,
WriteOptions,
Expand Down Expand Up @@ -243,9 +241,9 @@ export class IOReadable implements AoIORead {
}

async getArNSReservedNames(): Promise<
Record<string, ArNSReservedNameData> | Record<string, never>
Record<string, AoArNSReservedNameData> | Record<string, never>
> {
return this.process.read<Record<string, ArNSReservedNameData>>({
return this.process.read<Record<string, AoArNSReservedNameData>>({
tags: [{ name: 'Action', value: 'Reserved-Names' }],
});
}
Expand All @@ -254,8 +252,8 @@ export class IOReadable implements AoIORead {
name,
}: {
name: string;
}): Promise<ArNSReservedNameData | undefined> {
return this.process.read<ArNSReservedNameData>({
}): Promise<AoArNSReservedNameData | undefined> {
return this.process.read<AoArNSReservedNameData>({
tags: [
{ name: 'Action', value: 'Reserved-Name' },
{ name: 'Name', value: name },
Expand Down Expand Up @@ -354,7 +352,7 @@ export class IOReadable implements AoIORead {

async getPrescribedObservers(
epoch?: EpochInput,
): Promise<WeightedObserver[]> {
): Promise<AoWeightedObserver[]> {
const allTags = [
{ name: 'Action', value: 'Epoch-Prescribed-Observers' },
{
Expand Down Expand Up @@ -385,7 +383,7 @@ export class IOReadable implements AoIORead {
}): tag is { name: string; value: string } => tag.value !== undefined,
);

return this.process.read<WeightedObserver[]>({
return this.process.read<AoWeightedObserver[]>({
tags: prunedTags,
});
}
Expand Down Expand Up @@ -426,7 +424,7 @@ export class IOReadable implements AoIORead {
});
}

async getObservations(epoch?: EpochInput): Promise<EpochObservations> {
async getObservations(epoch?: EpochInput): Promise<AoEpochObservationData> {
const allTags = [
{ name: 'Action', value: 'Epoch-Observations' },
{
Expand Down Expand Up @@ -457,12 +455,12 @@ export class IOReadable implements AoIORead {
}): tag is { name: string; value: string } => tag.value !== undefined,
);

return this.process.read<EpochObservations>({
return this.process.read<AoEpochObservationData>({
tags: prunedTags,
});
}

async getDistributions(epoch?: EpochInput): Promise<EpochDistributionData> {
async getDistributions(epoch?: EpochInput): Promise<AoEpochDistributionData> {
const allTags = [
{ name: 'Action', value: 'Epoch-Distributions' },
{
Expand Down Expand Up @@ -493,7 +491,7 @@ export class IOReadable implements AoIORead {
}): tag is { name: string; value: string } => tag.value !== undefined,
);

return this.process.read<EpochDistributionData>({
return this.process.read<AoEpochDistributionData>({
tags: prunedTags,
});
}
Expand Down Expand Up @@ -653,10 +651,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite {
protocol,
autoStake,
observerAddress,
}: Omit<JoinNetworkParams, 'observerWallet' | 'qty'> & {
observerAddress: string;
operatorStake: number | mIOToken;
},
}: AoJoinNetworkParams,
options?: WriteOptions,
): Promise<AoMessageResult> {
const { tags = [] } = options || {};
Expand All @@ -669,11 +664,11 @@ export class IOWriteable extends IOReadable implements AoIOWrite {
},
{
name: 'Allow-Delegated-Staking',
value: allowDelegatedStaking.toString(),
value: allowDelegatedStaking?.toString(),
},
{
name: 'Delegate-Reward-Share-Ratio',
value: delegateRewardShareRatio.toString(),
value: delegateRewardShareRatio?.toString(),
},
{
name: 'FQDN',
Expand All @@ -685,15 +680,15 @@ export class IOWriteable extends IOReadable implements AoIOWrite {
},
{
name: 'Min-Delegated-Stake',
value: minDelegatedStake.valueOf().toString(),
value: minDelegatedStake?.valueOf().toString(),
},
{
name: 'Note',
value: note,
},
{
name: 'Port',
value: port.toString(),
value: port?.toString(),
},
{
name: 'Properties',
Expand All @@ -705,7 +700,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite {
},
{
name: 'Auto-Stake',
value: autoStake.toString(),
value: autoStake?.toString(),
},
{
name: 'Observer-Address',
Expand Down Expand Up @@ -747,7 +742,7 @@ export class IOWriteable extends IOReadable implements AoIOWrite {
protocol,
autoStake,
observerAddress,
}: UpdateGatewaySettingsParams,
}: AoUpdateGatewaySettingsParams,
options?: WriteOptions,
): Promise<AoMessageResult> {
const { tags = [] } = options || {};
Expand Down
Loading

0 comments on commit aaabbb0

Please sign in to comment.