@pezkuwi/api-base 16.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ // Copyright 2017-2025 @polkadot/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // These are augmented, do an augmentation export
5
+ export * from '@pezkuwi/api-base/types/calls';
6
+ export * from '@pezkuwi/api-base/types/consts';
7
+ export * from '@pezkuwi/api-base/types/errors';
8
+ export * from '@pezkuwi/api-base/types/events';
9
+ export * from '@pezkuwi/api-base/types/storage';
10
+ export * from '@pezkuwi/api-base/types/submittable';
11
+
12
+ // normal exports
13
+ export * from './api.js';
14
+ export * from './base.js';
15
+ export * from './derive.js';
16
+ export * from './rpc.js';
@@ -0,0 +1,35 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { AnyFunction, AnyJson, Callback, DefinitionRpc } from '@pezkuwi/types/types';
6
+ import type { ApiTypes, PromiseResult, Push, RxResult, UnsubscribePromise } from './base.js';
7
+
8
+ export type { AugmentedRpc } from '@pezkuwi/rpc-core/types';
9
+
10
+ export interface RxRpcResult<F extends AnyFunction> extends RxResult<F> {
11
+ raw <T> (...args: Parameters<F>): Observable<T>;
12
+ meta: DefinitionRpc;
13
+ }
14
+
15
+ export interface PromiseRpcResult<F extends AnyFunction> extends PromiseResult<F> {
16
+ raw <T> (...args: Parameters<F>): Promise<T>;
17
+ raw <T> (...args: Push<Parameters<F>, Callback<T>>): UnsubscribePromise;
18
+ meta: DefinitionRpc;
19
+ }
20
+
21
+ export type RpcMethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiType extends 'rxjs'
22
+ ? RxRpcResult<F>
23
+ : PromiseRpcResult<F>;
24
+
25
+ export type DecoratedRpcSection<ApiType extends ApiTypes, Section> = {
26
+ [M in keyof Section]: Section[M] extends AnyFunction
27
+ ? RpcMethodResult<ApiType, Section[M]>
28
+ : never
29
+ }
30
+
31
+ export type RawRpcType<ApiType extends ApiTypes> = (method: string, ...params: unknown[]) => ApiType extends 'rxjs' ? Observable<AnyJson> : Promise<AnyJson>;
32
+
33
+ export type DecoratedRpc<ApiType extends ApiTypes, AllSections> = {
34
+ [S in keyof AllSections]: DecoratedRpcSection<ApiType, AllSections[S]>
35
+ } & RawRpcType<ApiType>
@@ -0,0 +1,123 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { StorageKey, u64 } from '@pezkuwi/types';
6
+ import type { Hash } from '@pezkuwi/types/interfaces';
7
+ import type { StorageEntry } from '@pezkuwi/types/primitive/types';
8
+ import type { AnyFunction, AnyTuple, Callback, Codec, IStorageKey } from '@pezkuwi/types/types';
9
+ import type { ApiTypes, DropLast, EmptyBase, MethodResult, PaginationOptions, PromiseOrObs, ReturnCodec, UnsubscribePromise } from './base.js';
10
+
11
+ type StorageEntryObservableMulti<R extends Codec = Codec> = <T extends Codec = R>(args: unknown[]) => Observable<T[]>;
12
+
13
+ interface StorageEntryPromiseMulti<R extends Codec = Codec> {
14
+ <T extends Codec = R>(args: unknown[]): Promise<T[]>;
15
+ <T extends Codec = R>(args: unknown[], callback: Callback<T[]>): UnsubscribePromise;
16
+ }
17
+
18
+ export interface StorageEntryPromiseOverloads {
19
+ (arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<Codec>;
20
+ <T extends Codec>(arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<T>;
21
+ <T extends Codec>(callback: Callback<T>): UnsubscribePromise;
22
+ <T extends Codec>(arg: unknown, callback: Callback<T>): UnsubscribePromise;
23
+ <T extends Codec>(arg1: unknown, arg2: unknown, callback: Callback<T>): UnsubscribePromise;
24
+ <T extends Codec>(arg1: unknown, arg2: unknown, arg3: unknown, callback: Callback<T>): UnsubscribePromise;
25
+ }
26
+
27
+ export interface StorageEntryPromiseOverloadsAt {
28
+ (arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<Codec>;
29
+ <T extends Codec>(arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<T>;
30
+ }
31
+
32
+ // This is the most generic typings we can have for a storage entry function
33
+ export type GenericStorageEntryFunction = (...args: unknown[]) => Observable<Codec>
34
+
35
+ export type QueryableStorageEntry<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> =
36
+ ApiType extends 'rxjs'
37
+ ? AugmentedQuery<'rxjs', GenericStorageEntryFunction, A>
38
+ : AugmentedQuery<'promise', GenericStorageEntryFunction, A> & StorageEntryPromiseOverloads;
39
+
40
+ export type QueryableStorageEntryAt<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> =
41
+ ApiType extends 'rxjs'
42
+ ? AugmentedQueryAt<'rxjs', GenericStorageEntryFunction, A>
43
+ : AugmentedQueryAt<'promise', GenericStorageEntryFunction, A> & StorageEntryPromiseOverloadsAt;
44
+
45
+ export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> extends StorageEntryBaseAt<ApiType, F, A> {
46
+ /**
47
+ * @deprecated Use api.at(<blockHash>)
48
+ */
49
+ at: <T = ReturnCodec<F>>(hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, T>;
50
+ creator: StorageEntry;
51
+ /**
52
+ * @deprecated Use api.at(<blockHash>)
53
+ */
54
+ entriesAt: <T = ReturnCodec<F>, K extends AnyTuple = A>(hash: Hash | Uint8Array | string, ...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, [StorageKey<K>, T][]>;
55
+ /**
56
+ * @deprecated Use api.at(<blockHash>)
57
+ */
58
+ keysAt: <K extends AnyTuple = A> (hash: Hash | Uint8Array | string, ...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, StorageKey<K>[]>;
59
+ /**
60
+ * @deprecated Use api.at(<blockHash>)
61
+ */
62
+ sizeAt: (hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, u64>;
63
+ multi: ApiType extends 'rxjs'
64
+ ? StorageEntryObservableMulti<ReturnCodec<F>>
65
+ : StorageEntryPromiseMulti<ReturnCodec<F>>;
66
+ }
67
+
68
+ export interface StorageEntryBaseAt<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> {
69
+ entries: <T = ReturnCodec<F>, K extends AnyTuple = A>(...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, [StorageKey<K>, T][]>;
70
+ entriesPaged: <T = ReturnCodec<F>, K extends AnyTuple = A>(opts: PaginationOptions<Parameters<F>[0]>) => PromiseOrObs<ApiType, [StorageKey<K>, T][]>;
71
+ hash: (...args: Parameters<F>) => PromiseOrObs<ApiType, Hash>;
72
+ is: (key: IStorageKey<AnyTuple>) => key is IStorageKey<A>;
73
+ key: (...args: Parameters<F>) => string;
74
+ keyPrefix: (...args: DropLast<Parameters<F>>) => string;
75
+ keys: <K extends AnyTuple = A> (...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, StorageKey<K>[]>;
76
+ keysPaged: <K extends AnyTuple = A> (opts: PaginationOptions<Parameters<F>[0]>) => PromiseOrObs<ApiType, StorageKey<K>[]>;
77
+ size: (...args: Parameters<F>) => PromiseOrObs<ApiType, u64>;
78
+ }
79
+
80
+ export type QueryableModuleStorage<ApiType extends ApiTypes> = Record<string, QueryableStorageEntry<ApiType, AnyTuple>>;
81
+
82
+ export type QueryableModuleStorageAt<ApiType extends ApiTypes> = Record<string, QueryableStorageEntryAt<ApiType, AnyTuple>>;
83
+
84
+ export type QueryableStorageMultiArg<ApiType extends ApiTypes> =
85
+ QueryableStorageEntry<ApiType> |
86
+ [QueryableStorageEntry<ApiType>, ...unknown[]];
87
+
88
+ export type QueryableStorageMultiBase<ApiType extends ApiTypes> = <T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[]) => Observable<T>;
89
+
90
+ export interface QueryableStorageMultiPromise<ApiType extends ApiTypes> {
91
+ <T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[], callback: Callback<T>): UnsubscribePromise;
92
+ <T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[]): Promise<T>;
93
+ }
94
+
95
+ export type QueryableStorageMulti<ApiType extends ApiTypes> =
96
+ ApiType extends 'rxjs'
97
+ ? QueryableStorageMultiBase<ApiType>
98
+ : QueryableStorageMultiPromise<ApiType>;
99
+
100
+ export type AugmentedQuery<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F, A>;
101
+
102
+ export type AugmentedQueryAt<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = MethodResult<ApiType, F> & StorageEntryBaseAt<ApiType, F, A>;
103
+
104
+ // backwards compatibility-only
105
+ export type AugmentedQueryDoubleMap<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = AugmentedQuery<ApiType, F, A>;
106
+
107
+ // augmented interfaces
108
+
109
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
110
+ export interface AugmentedQueries<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
111
+ // augmented
112
+ }
113
+
114
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
115
+ export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
116
+ // when non-augmented, we need to at least have Codec results
117
+ [key: string]: QueryableModuleStorage<ApiType>;
118
+ }
119
+
120
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
121
+ export interface QueryableStorageAt<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
122
+ [key: string]: QueryableModuleStorageAt<ApiType>;
123
+ }
@@ -0,0 +1,114 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { AccountId, Address, ApplyExtrinsicResult, BlockNumber, Call, DispatchError, DispatchInfo, EventRecord, Extrinsic, ExtrinsicStatus, Hash, RuntimeDispatchInfo } from '@pezkuwi/types/interfaces';
6
+ import type { AnyFunction, AnyNumber, AnyTuple, AnyU8a, Callback, CallBase, Codec, IExtrinsicEra, IKeyringPair, ISubmittableResult, Signer } from '@pezkuwi/types/types';
7
+ import type { ApiTypes, EmptyBase, PromiseOrObs } from './base.js';
8
+
9
+ export type AugmentedSubmittable<T extends AnyFunction, A extends AnyTuple = AnyTuple> = T & CallBase<A>;
10
+
11
+ export type AddressOrPair = IKeyringPair | string | AccountId | Address;
12
+
13
+ export interface SignerOptions {
14
+ blockHash: Uint8Array | string;
15
+ era?: IExtrinsicEra | number;
16
+ nonce: AnyNumber | Codec;
17
+ signer?: Signer;
18
+ tip?: AnyNumber;
19
+ assetId?: AnyNumber | object;
20
+ mode?: AnyNumber;
21
+ metadataHash?: AnyU8a;
22
+ withSignedTransaction?: boolean;
23
+ }
24
+
25
+ export type SubmittableDryRunResult<ApiType extends ApiTypes> =
26
+ ApiType extends 'rxjs'
27
+ ? Observable<ApplyExtrinsicResult>
28
+ : Promise<ApplyExtrinsicResult>;
29
+
30
+ export type SubmittableResultResult<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> =
31
+ ApiType extends 'rxjs'
32
+ ? Observable<R>
33
+ : Promise<Hash>;
34
+
35
+ export type SubmittableResultSubscription<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> =
36
+ ApiType extends 'rxjs'
37
+ ? Observable<R>
38
+ : Promise<() => void>;
39
+
40
+ export type SubmittablePaymentResult<ApiType extends ApiTypes> =
41
+ ApiType extends 'rxjs'
42
+ ? Observable<RuntimeDispatchInfo>
43
+ : Promise<RuntimeDispatchInfo>;
44
+
45
+ export interface SubmittableResultValue {
46
+ dispatchError?: DispatchError | undefined;
47
+ dispatchInfo?: DispatchInfo | undefined;
48
+ events?: EventRecord[];
49
+ internalError?: Error | undefined;
50
+ status: ExtrinsicStatus;
51
+ txHash: Hash;
52
+ txIndex?: number | undefined;
53
+ blockNumber?: BlockNumber;
54
+ }
55
+
56
+ export interface SubmittableExtrinsic<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> extends Extrinsic {
57
+ /** true if api.rpc.system.dryRun is available, enabling dryRun(...) */
58
+ hasDryRun: boolean;
59
+ /** true if api.call.transactionPaymentApi.queryInfo is available, enabling paymentInfo(...) */
60
+ hasPaymentInfo: boolean;
61
+
62
+ dryRun (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableDryRunResult<ApiType>;
63
+
64
+ paymentInfo (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittablePaymentResult<ApiType>;
65
+
66
+ send (): SubmittableResultResult<ApiType>;
67
+
68
+ send (statusCb: Callback<R>): SubmittableResultSubscription<ApiType, R>;
69
+
70
+ /**
71
+ * @description Sign the constructed transaction asynchronously.
72
+ *
73
+ * The result is a signed extrinsic that is ready to be broadcast to the network via `.send()`, `rpc.author.submitExtrinsic()`, or
74
+ * any custom submission logic.
75
+ */
76
+ signAsync (account: AddressOrPair, _options?: Partial<SignerOptions>): PromiseOrObs<ApiType, this>;
77
+
78
+ /**
79
+ * @description Sign and broadcast the constructued transaction.
80
+ *
81
+ * Note for injected signers:
82
+ * As of v12.0.1 and up the `SignerResult` return type for `signPayload` allows for the `signedTransaction` field.
83
+ * This allows the signer to input a signed transaction that will be directly broadcasted. This
84
+ * bypasses the api adding the signature to the payload. The api will ensure that the Call Data is not changed before it broadcasts the
85
+ * transaction. This allows for the signer to modify the payload to add things like `mode`, and `metadataHash` for
86
+ * signedExtensions such as `CheckMetadataHash`.
87
+ */
88
+ signAndSend (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableResultResult<ApiType, R>;
89
+
90
+ signAndSend (account: AddressOrPair, statusCb: Callback<R>): SubmittableResultSubscription<ApiType>;
91
+
92
+ signAndSend (account: AddressOrPair, options: Partial<SignerOptions>, statusCb?: Callback<R>): SubmittableResultSubscription<ApiType, R>;
93
+
94
+ withResultTransform (transform: (input: ISubmittableResult) => ISubmittableResult): this;
95
+ }
96
+
97
+ export interface SubmittableExtrinsicFunction<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> extends CallBase<A> {
98
+ (...params: any[]): SubmittableExtrinsic<ApiType>;
99
+ }
100
+
101
+ // augmented interfaces
102
+
103
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
104
+ export interface AugmentedSubmittables<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
105
+ // augmented
106
+ }
107
+
108
+ export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {
109
+ (extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;
110
+ // when non-augmented, we need to at least have Codec results
111
+ [key: string]: SubmittableModuleExtrinsics<ApiType>;
112
+ }
113
+
114
+ export type SubmittableModuleExtrinsics<ApiType extends ApiTypes> = Record<string, SubmittableExtrinsicFunction<ApiType>>;
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": "..",
5
+ "outDir": "./build",
6
+ "rootDir": "./src"
7
+ },
8
+ "exclude": [
9
+ "**/mod.ts"
10
+ ],
11
+ "references": [
12
+ { "path": "../rpc-core/tsconfig.build.json" },
13
+ { "path": "../types/tsconfig.build.json" }
14
+ ]
15
+ }