Skip to content

Commit

Permalink
Add exports
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Oct 6, 2024
1 parent 1651cfa commit 486982d
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 23 deletions.
6 changes: 1 addition & 5 deletions packages/drift/src/adapter/MockAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ import type { OptionalKeys } from "src/utils/types";

// TODO: Allow configuration of error throwing/default return value behavior
export class MockAdapter implements ReadWriteAdapter {
mocks: MockStore<ReadWriteAdapter>;

constructor(store = new MockStore<ReadWriteAdapter>()) {
this.mocks = store;
}
mocks = new MockStore<ReadWriteAdapter>();

reset = () => this.mocks.reset();

Expand Down
20 changes: 10 additions & 10 deletions packages/drift/src/client/Contract/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ export class ReadContract<
adapter: TAdapter;
address: Address;
cache: TCache;
namespace?: PropertyKey;
cacheNamespace?: PropertyKey;

constructor({
abi,
adapter,
address,
cache = createClientCache() as TCache,
cacheNamespace: namespace,
cacheNamespace,
}: ReadContractParams<TAbi, TAdapter, TCache>) {
this.abi = abi;
this.adapter = adapter;
this.address = address;
this.cache = cache;
this.namespace = namespace;
this.cacheNamespace = cacheNamespace;
}

// Events //
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ReadContract<
},
): MaybePromise<void> => {
return this.cache.preloadEvents({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
abi: this.abi,
address: this.address,
...params,
Expand All @@ -127,7 +127,7 @@ export class ReadContract<
...[event, options]: ContractGetEventsArgs<TAbi, TEventName>
): SerializableKey => {
return this.cache.eventsKey({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
abi: this.abi,
address: this.address,
event,
Expand Down Expand Up @@ -174,7 +174,7 @@ export class ReadContract<
},
): MaybePromise<void> => {
this.cache.preloadRead({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
// TODO: Cleanup type casting required due to an incompatibility between
// `Omit` and the conditional args param.
abi: this.abi as Abi,
Expand All @@ -187,7 +187,7 @@ export class ReadContract<
...[fn, args, options]: ContractReadArgs<TAbi, TFunctionName>
): MaybePromise<void> {
return this.cache.invalidateRead({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
// TODO: Cleanup type casting required due to an incompatibility between
// `Omit` and the conditional args param.
abi: this.abi as Abi,
Expand All @@ -204,7 +204,7 @@ export class ReadContract<
options?: ContractReadOptions,
): MaybePromise<void> => {
const matchKey = this.cache.partialReadKey({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
abi: this.abi,
address: this.address,
fn,
Expand All @@ -231,7 +231,7 @@ export class ReadContract<
...[fn, args, options]: ContractReadArgs<TAbi, TFunctionName>
): SerializableKey => {
return this.cache.readKey({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
// TODO: Cleanup type casting required due to an incompatibility between
// `Omit` and the conditional args param.
abi: this.abi as Abi,
Expand All @@ -248,7 +248,7 @@ export class ReadContract<
options?: ContractReadOptions,
): SerializableKey => {
return this.cache.partialReadKey({
cacheNamespace: this.namespace,
cacheNamespace: this.cacheNamespace,
abi: this.abi,
address: this.address,
fn,
Expand Down
4 changes: 2 additions & 2 deletions packages/drift/src/client/Contract/MockContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export class MockContract<
constructor({
abi,
address = ZERO_ADDRESS,
cacheNamespace: namespace,
cacheNamespace,
}: MockContractParams<TAbi>) {
super({
abi,
adapter: new MockAdapter(),
address,
cacheNamespace: namespace,
cacheNamespace,
});
}

Expand Down
12 changes: 6 additions & 6 deletions packages/drift/src/client/Drift/Drift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Drift<
> {
adapter: TAdapter;
cache: ClientCache<TCache>;
namespace?: PropertyKey;
cacheNamespace?: PropertyKey;

// Write-only property definitions //

Expand All @@ -70,11 +70,11 @@ export class Drift<

constructor(
adapter: TAdapter,
{ cache, cacheNamespace: namespace }: DriftOptions<TCache> = {},
{ cache, cacheNamespace }: DriftOptions<TCache> = {},
) {
this.adapter = adapter;
this.cache = createClientCache(cache);
this.namespace = namespace;
this.cacheNamespace = cacheNamespace;

// Write-only property assignment //

Expand Down Expand Up @@ -111,7 +111,7 @@ export class Drift<
abi,
address,
cache = this.cache,
cacheNamespace: namespace = this.namespace,
cacheNamespace = this.cacheNamespace,
}: ContractParams<TAbi>): Contract<TAbi, TAdapter, TCache> => {
return (
this.isReadWrite()
Expand All @@ -120,14 +120,14 @@ export class Drift<
adapter: this.adapter,
address,
cache,
cacheNamespace: namespace,
cacheNamespace,
})
: new ReadContract({
abi,
adapter: this.adapter,
address,
cache,
cacheNamespace: namespace,
cacheNamespace,
})
) as Contract<TAbi, TAdapter, TCache>;
};
Expand Down
144 changes: 144 additions & 0 deletions packages/drift/src/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// adapter //

export type {
AbiArrayType,
AbiEntry,
AbiEntryName,
AbiFriendlyType,
AbiObjectType,
AbiParameters,
AbiParametersToObject,
NamedAbiParameter,
} from "src/adapter/types/Abi";
export type {
Adapter,
AdapterArgsParam,
AdapterDecodeFunctionDataParams,
AdapterEncodeFunctionDataParams,
AdapterGetEventsParams,
AdapterReadParams,
AdapterWriteParams,
OnMinedParam,
ReadAdapter,
ReadWriteAdapter,
} from "src/adapter/types/Adapter";
export type {
Block,
BlockTag,
} from "src/adapter/types/Block";
export type {
ContractGetEventsOptions,
ContractReadOptions,
ContractWriteOptions,
} from "src/adapter/types/Contract";
export type {
ContactEvent,
EventArgs,
EventFilter,
EventName,
} from "src/adapter/types/Event";
export type {
ConstructorArgs,
DecodedFunctionData,
FunctionArgs,
FunctionName,
FunctionReturn,
} from "src/adapter/types/Function";
export type {
Network,
NetworkGetBalanceParams,
NetworkGetBlockOptions,
NetworkGetBlockParams,
NetworkGetTransactionParams,
NetworkWaitForTransactionParams,
} from "src/adapter/types/Network";
export type {
MinedTransaction,
Transaction,
TransactionInfo,
TransactionReceipt,
} from "src/adapter/types/Transaction";

export { arrayToFriendly } from "src/adapter/utils/arrayToFriendly";
export { arrayToObject } from "src/adapter/utils/arrayToObject";
export {
AbiEntryNotFoundError,
getAbiEntry,
} from "src/adapter/utils/getAbiEntry";
export { objectToArray } from "src/adapter/utils/objectToArray";

// cache //

export type {
BalanceKeyParams,
BlockKeyParams,
ChainIdKeyParams,
ClientCache,
EventsKeyParams,
NameSpaceParam,
ReadKeyParams,
TransactionKeyParams,
} from "src/cache/ClientCache/types";
export { createClientCache } from "src/cache/ClientCache/createClientCache";

export type { SimpleCache } from "src/cache/SimpleCache/types";
export { createLruSimpleCache } from "src/cache/SimpleCache/createLruSimpleCache";

// clients //

export {
type Contract,
type ContractEncodeFunctionDataArgs,
type ContractGetEventsArgs,
type ContractParams,
type ContractReadArgs,
type ContractWriteArgs,
type ReadContractParams,
type ReadWriteContractParams,
ReadContract,
ReadWriteContract,
} from "src/client/Contract/Contract";

export {
type DecodeFunctionDataParams,
type DriftOptions,
type EncodeFunctionDataParams,
type GetBalanceParams,
type GetBlockParams,
type GetChainIdParams,
type GetEventsParams,
type GetTransactionParams,
type ReadParams,
type SimulateWriteParams,
type WaitForTransactionParams,
type WriteParams,
Drift,
} from "src/client/Drift/Drift";

// utils //

export type {
AnyFunction,
AnyObject,
DeepPartial,
EmptyObject,
FunctionKey,
MaybePromise,
MergeKeys,
OptionalKeys,
Pretty,
ReplaceKeys,
RequiredKeys,
UnionToIntersection,
} from "src/utils/types";
export {
type SerializableKey,
createSerializableKey,
} from "src/utils/createSerializableKey";
export { extendInstance } from "src/utils/extendInstance";

// ...rest //

export type { Address, Bytes, HexString, TransactionHash } from "src/types";
export { ZERO_ADDRESS } from "src/constants";
export { DriftError } from "src/error";

0 comments on commit 486982d

Please sign in to comment.