Skip to content

Commit

Permalink
Fix result class
Browse files Browse the repository at this point in the history
  • Loading branch information
fukaoi committed Dec 5, 2023
1 parent 6321267 commit 8404514
Show file tree
Hide file tree
Showing 91 changed files with 1,428 additions and 1,831 deletions.
30 changes: 12 additions & 18 deletions packages/account/dist/index.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/account/dist/index.mjs

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions packages/converter/dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKey, ParsedTransactionWithMeta, Keypair } from '@solana/web3.js';
import { PublicKey, ParsedTransactionWithMeta, TransactionSignature, Keypair } from '@solana/web3.js';
import { Metadata as Metadata$1, DataV2 } from '@metaplex-foundation/mpl-token-metadata';
import BN from 'bn.js';
import { MetadataArgs } from 'mpl-bubblegum-instruction';
Expand All @@ -8,7 +8,7 @@ declare const secretNominality: unique symbol;
type Pubkey$1 = (string & {
[pubKeyNominality]: never;
}) | string;
type Secret = (string & {
type Secret$1 = (string & {
[secretNominality]: never;
}) | string;

Expand All @@ -26,7 +26,7 @@ type Uses = {
};
type InputCreators = {
address: Pubkey$1;
secret: Secret;
secret: Secret$1;
share: number;
};

Expand Down Expand Up @@ -305,6 +305,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down Expand Up @@ -527,7 +533,7 @@ type ExplorerOptions = {

declare namespace Converter$6 {
namespace Properties {
const intoInfra: (input: Properties | undefined, callbackFunc: (filePath: FileType, storageType: StorageType, feePayer?: Secret) => Promise<Result<string, Error>>, storageType: StorageType, feePayer?: Secret) => Promise<Properties>;
const intoInfra: (input: Properties | undefined, callbackFunc: (filePath: FileType, storageType: StorageType, feePayer?: Secret$1) => Promise<Result<string, Error>>, storageType: StorageType, feePayer?: Secret$1) => Promise<Properties>;
}
}

Expand Down
14 changes: 10 additions & 4 deletions packages/converter/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKey, ParsedTransactionWithMeta, Keypair } from '@solana/web3.js';
import { PublicKey, ParsedTransactionWithMeta, TransactionSignature, Keypair } from '@solana/web3.js';
import { Metadata as Metadata$1, DataV2 } from '@metaplex-foundation/mpl-token-metadata';
import BN from 'bn.js';
import { MetadataArgs } from 'mpl-bubblegum-instruction';
Expand All @@ -8,7 +8,7 @@ declare const secretNominality: unique symbol;
type Pubkey$1 = (string & {
[pubKeyNominality]: never;
}) | string;
type Secret = (string & {
type Secret$1 = (string & {
[secretNominality]: never;
}) | string;

Expand All @@ -26,7 +26,7 @@ type Uses = {
};
type InputCreators = {
address: Pubkey$1;
secret: Secret;
secret: Secret$1;
share: number;
};

Expand Down Expand Up @@ -305,6 +305,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down Expand Up @@ -527,7 +533,7 @@ type ExplorerOptions = {

declare namespace Converter$6 {
namespace Properties {
const intoInfra: (input: Properties | undefined, callbackFunc: (filePath: FileType, storageType: StorageType, feePayer?: Secret) => Promise<Result<string, Error>>, storageType: StorageType, feePayer?: Secret) => Promise<Properties>;
const intoInfra: (input: Properties | undefined, callbackFunc: (filePath: FileType, storageType: StorageType, feePayer?: Secret$1) => Promise<Result<string, Error>>, storageType: StorageType, feePayer?: Secret$1) => Promise<Properties>;
}
}

Expand Down
30 changes: 12 additions & 18 deletions packages/converter/dist/index.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/converter/dist/index.mjs

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion packages/das-api/dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKey, Keypair } from '@solana/web3.js';
import { TransactionSignature, PublicKey, Keypair } from '@solana/web3.js';

declare abstract class AbstractResult<T, E extends Error> {
protected abstract _chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
Expand All @@ -11,6 +11,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down
8 changes: 7 additions & 1 deletion packages/das-api/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PublicKey, Keypair } from '@solana/web3.js';
import { TransactionSignature, PublicKey, Keypair } from '@solana/web3.js';

declare abstract class AbstractResult<T, E extends Error> {
protected abstract _chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
Expand All @@ -11,6 +11,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down
30 changes: 12 additions & 18 deletions packages/das-api/dist/index.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/das-api/dist/index.mjs

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/global/dist/index.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/global/dist/index.mjs

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion packages/node/dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _solana_web3_js from '@solana/web3.js';
import { PublicKey, Keypair, Connection, Commitment } from '@solana/web3.js';
import { TransactionSignature, PublicKey, Keypair, Connection, Commitment } from '@solana/web3.js';

declare abstract class AbstractResult<T, E extends Error> {
protected abstract _chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
Expand All @@ -12,6 +12,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down
8 changes: 7 additions & 1 deletion packages/node/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _solana_web3_js from '@solana/web3.js';
import { PublicKey, Keypair, Connection, Commitment } from '@solana/web3.js';
import { TransactionSignature, PublicKey, Keypair, Connection, Commitment } from '@solana/web3.js';

declare abstract class AbstractResult<T, E extends Error> {
protected abstract _chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
Expand All @@ -12,6 +12,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down
30 changes: 12 additions & 18 deletions packages/node/dist/index.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/node/dist/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/shared/dist/exports.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-8dfdb5db.js';
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-b52866c6.js';
import '@solana/web3.js';
import 'bn.js';
import '@metaplex-foundation/mpl-token-metadata';
2 changes: 1 addition & 1 deletion packages/shared/dist/exports.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-8dfdb5db.js';
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-b52866c6.js';
import '@solana/web3.js';
import 'bn.js';
import '@metaplex-foundation/mpl-token-metadata';
30 changes: 12 additions & 18 deletions packages/shared/dist/exports.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/shared/dist/exports.mjs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _solana_web3_js from '@solana/web3.js';
import { TransactionInstruction, PublicKey, Keypair, Connection, Commitment } from '@solana/web3.js';
import { TransactionSignature, TransactionInstruction, PublicKey, Keypair, Connection, Commitment } from '@solana/web3.js';
import BN from 'bn.js';
import { DataV2 } from '@metaplex-foundation/mpl-token-metadata';

Expand All @@ -14,6 +14,12 @@ declare abstract class AbstractResult<T, E extends Error> {
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(ok: (value: T) => Result<X, U>, err: (error: E) => Result<X, U>): Result<X, U>;
match<U, F>(ok: (value: T) => U, err: (error: E) => F): void | Promise<void>;
submit(feePayer?: any): Promise<Result<TransactionSignature, Error>>;
}
declare global {
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}
declare class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
readonly value: T;
Expand Down Expand Up @@ -210,12 +216,12 @@ declare const secretNominality: unique symbol;
type Pubkey = (string & {
[pubKeyNominality]: never;
}) | string;
type Secret = (string & {
type Secret$1 = (string & {
[secretNominality]: never;
}) | string;
type KeypairAccount = {
pubkey: Pubkey;
secret: Secret;
secret: Secret$1;
};
type OwnerInfo = {
sol: number;
Expand Down Expand Up @@ -243,7 +249,7 @@ declare namespace Account$3 {
* @param {Secret} feePayer
* @returns Promise<string>
*/
const retryGetOrCreate: (mint: Pubkey, owner: Pubkey, feePayer: Secret) => Promise<string>;
const retryGetOrCreate: (mint: Pubkey, owner: Pubkey, feePayer: Secret$1) => Promise<string>;
/**
* [Main logic]Get Associated token Account.
* if not created, create new token accouint
Expand All @@ -262,16 +268,16 @@ declare namespace Account$3 {

declare namespace Account$2 {
class Keypair {
secret: Secret;
secret: Secret$1;
pubkey: Pubkey;
constructor(params: {
pubkey?: Pubkey;
secret: Secret;
secret: Secret$1;
});
toPublicKey(): PublicKey;
toKeypair(): Keypair;
static isPubkey: (value: string) => value is Pubkey;
static isSecret: (value: string) => value is Secret;
static isSecret: (value: string) => value is Secret$1;
static create: () => Keypair;
static toKeyPair: (keypair: Keypair) => Keypair;
}
Expand Down Expand Up @@ -328,7 +334,7 @@ type Uses = {
};
type InputCreators = {
address: Pubkey;
secret: Secret;
secret: Secret$1;
share: number;
};

Expand Down Expand Up @@ -537,4 +543,4 @@ type ExplorerOptions = {
replacePath: string;
};

export { Account as A, FilterType as F, KeypairAccount as K, ModuleName as M, Node as N, OwnerInfo as O, Pubkey as P, Result as R, Secret as S, Transfer as T, Validator as V, WithMemo as W, ValidatorError as a, FilterOptions as b, PostTokenAccount as c, MintTo as d, MintToChecked as e, TransferChecked as f, Memo as g };
export { Account as A, FilterType as F, KeypairAccount as K, ModuleName as M, Node as N, OwnerInfo as O, Pubkey as P, Result as R, Secret$1 as S, Transfer as T, Validator as V, WithMemo as W, ValidatorError as a, FilterOptions as b, PostTokenAccount as c, MintTo as d, MintToChecked as e, TransferChecked as f, Memo as g };
4 changes: 2 additions & 2 deletions packages/shared/dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PublicKey, Commitment } from '@solana/web3.js';
import { R as Result } from './index-8dfdb5db.js';
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-8dfdb5db.js';
import { R as Result } from './index-b52866c6.js';
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-b52866c6.js';
import 'bn.js';
import '@metaplex-foundation/mpl-token-metadata';

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PublicKey, Commitment } from '@solana/web3.js';
import { R as Result } from './index-8dfdb5db.js';
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-8dfdb5db.js';
import { R as Result } from './index-b52866c6.js';
export { A as Account, b as FilterOptions, F as FilterType, K as KeypairAccount, g as Memo, d as MintTo, e as MintToChecked, M as ModuleName, N as Node, O as OwnerInfo, c as PostTokenAccount, P as Pubkey, S as Secret, T as Transfer, f as TransferChecked, V as Validator, a as ValidatorError, W as WithMemo } from './index-b52866c6.js';
import 'bn.js';
import '@metaplex-foundation/mpl-token-metadata';

Expand Down
30 changes: 12 additions & 18 deletions packages/shared/dist/index.js

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions packages/shared/dist/index.mjs

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions packages/shared/src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class AbstractResult<T, E extends Error> {
unwrap<U>(ok: (value: T) => U): U;
unwrap<U, V>(ok: (value: T) => U, err: (error: E) => V): U | V;
// unified-signatures. into line 10
// unwrap<U>(ok: (value: T) => U, err: (error: E) => U): U;
unwrap<U>(ok: (value: T) => U, err: (error: E) => U): U;
unwrap(ok?: (value: T) => unknown, err?: (error: E) => unknown): unknown {
const r = this._chain(
(value) => Result.ok(ok ? ok(value) : value),
Expand All @@ -38,9 +38,7 @@ abstract class AbstractResult<T, E extends Error> {

//// chain ////
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X>(ok: (value: T) => Result<X, E>): // unified-signatures. into line 37
// err: (error: E) => Result<X, E>
Result<X, E>;
chain<X>(ok: (value: T) => Result<X, E>): Result<X, E>;
chain<X, U extends Error>(
ok: (value: T) => Result<X, U>,
err: (error: E) => Result<X, U>,
Expand All @@ -67,23 +65,26 @@ abstract class AbstractResult<T, E extends Error> {

/// submit (alias Instruction.submit) ////
/* eslint-disable @typescript-eslint/no-explicit-any */
// TODO: refactoring
// async submit(feePayer?: any): Promise<Result<TransactionSignature, Error>> {
// try {
// const instruction = this.unwrap() as any;
// if (
// instruction.instructions ||
// instruction.hexInstruction ||
// instruction[0].instructions ||
// instruction[0].hexInstruction
// ) {
// return await instruction.submit(feePayer);
// }
// return Result.err(Error('Only Instruction object'));
// } catch (err) {
// return Result.err(err as Error);
// }
// }
async submit(feePayer?: any): Promise<Result<TransactionSignature, Error>> {
try {
const instruction = this.unwrap() as any;
if (instruction.instructions || instruction.hexInstruction) {
return await instruction.submit(feePayer);
} else if (Array.isArray(instruction)) {
return await instruction.submit(feePayer);
}
return Result.err(Error('Only Instruction object'));
} catch (err) {
return Result.err(err as Error);
}
}
}

declare global {
/* eslint-disable @typescript-eslint/no-unused-vars */
interface Array<T> {
submit(feePayer?: Secret): Promise<Result<TransactionSignature, Error>>;
}
}

class InternalOk<T, E extends Error> extends AbstractResult<T, E> {
Expand Down
Loading

0 comments on commit 8404514

Please sign in to comment.