@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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @pezkuwi/api-base
2
+
3
+ API Base interfaces
@@ -0,0 +1 @@
1
+ export { packageInfo } from './packageInfo.js';
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,23 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { DecoratedRpc, QueryableCalls, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '@pezkuwi/api-base/types';
3
+ import type { RpcInterface } from '@pezkuwi/rpc-core/types';
4
+ import type { Metadata } from '@pezkuwi/types';
5
+ import type { Hash, RuntimeVersion } from '@pezkuwi/types/interfaces';
6
+ import type { Registry, Signer } from '@pezkuwi/types/types';
7
+ export interface ApiInterfaceRx {
8
+ call: QueryableCalls<'rxjs'>;
9
+ consts: QueryableConsts<'rxjs'>;
10
+ extrinsicType: number;
11
+ genesisHash?: Hash | undefined;
12
+ hasSubscriptions: boolean;
13
+ registry: Registry;
14
+ runtimeMetadata: Metadata;
15
+ runtimeVersion: RuntimeVersion;
16
+ query: QueryableStorage<'rxjs'>;
17
+ queryMulti: QueryableStorageMulti<'rxjs'>;
18
+ rpc: DecoratedRpc<'rxjs', RpcInterface>;
19
+ tx: SubmittableExtrinsics<'rxjs'>;
20
+ signer?: Signer | undefined;
21
+ callAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableCalls<'rxjs'>>;
22
+ queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableStorage<'rxjs'>>;
23
+ }
@@ -0,0 +1,36 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { AnyFunction, Callback, Codec } from '@pezkuwi/types/types';
3
+ export type Push<T extends readonly unknown[], V> = [...T, V];
4
+ export type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any?] ? U : [...T];
5
+ export type ApiTypes = 'promise' | 'rxjs';
6
+ export type ObsInnerType<O extends Observable<any>> = O extends Observable<infer U> ? U : never;
7
+ export type VoidFn = () => void;
8
+ export type UnsubscribePromise = Promise<VoidFn>;
9
+ export type PromiseOrObs<ApiType extends ApiTypes, T> = ApiType extends 'rxjs' ? Observable<T> : Promise<T>;
10
+ export type MethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiType extends 'rxjs' ? RxResult<F> : PromiseResult<F>;
11
+ export interface RxResult<F extends AnyFunction> {
12
+ (...args: Parameters<F>): Observable<ObsInnerType<ReturnType<F>>>;
13
+ <T>(...args: Parameters<F>): Observable<T>;
14
+ }
15
+ export interface PromiseResult<F extends AnyFunction> {
16
+ (...args: Parameters<F>): Promise<ObsInnerType<ReturnType<F>>>;
17
+ (...args: Push<Parameters<F>, Callback<ObsInnerType<ReturnType<F>>>>): UnsubscribePromise;
18
+ <T extends Codec | Codec[]>(...args: Parameters<F>): Promise<T>;
19
+ <T extends Codec | Codec[]>(...args: Push<Parameters<F>, Callback<T>>): UnsubscribePromise;
20
+ }
21
+ export interface DecorateMethodOptions {
22
+ methodName?: string;
23
+ overrideNoSub?: (...args: unknown[]) => Observable<Codec>;
24
+ }
25
+ export type DecorateFn<T extends Codec> = (...args: any[]) => Observable<T>;
26
+ export interface PaginationOptions<A = unknown> {
27
+ args: A[];
28
+ pageSize: number;
29
+ startKey?: string;
30
+ }
31
+ export type DecorateMethod<_ApiType extends ApiTypes, T = any> = <M extends (...args: any[]) => Observable<any>>(method: M, options?: DecorateMethodOptions) => T;
32
+ type AsCodec<R> = R extends Codec ? R : Codec;
33
+ export type ReturnCodec<F extends AnyFunction> = AsCodec<ObsInnerType<ReturnType<F>>>;
34
+ export interface EmptyBase<_> {
35
+ }
36
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { AnyFunction, Codec, DefinitionCallNamed } from '@pezkuwi/types/types';
3
+ import type { ApiTypes, EmptyBase, ReturnCodec } from './base.js';
4
+ export type DecoratedCallBase<ApiType extends ApiTypes, F extends AnyFunction = (...args: any[]) => Observable<Codec>> = ApiType extends 'rxjs' ? <T = ReturnCodec<F>>(...args: Parameters<F>) => Observable<T> : <T = ReturnCodec<F>>(...args: Parameters<F>) => Promise<T>;
5
+ export type AugmentedCall<ApiType extends ApiTypes, F extends AnyFunction = (...args: any[]) => Observable<Codec>> = DecoratedCallBase<ApiType, F> & {
6
+ /** The metadata/description/definition for this method */
7
+ meta: DefinitionCallNamed;
8
+ };
9
+ export interface AugmentedCalls<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
10
+ }
11
+ export interface QueryableCalls<ApiType extends ApiTypes> extends AugmentedCalls<ApiType> {
12
+ [key: string]: QueryableModuleCalls<ApiType>;
13
+ }
14
+ export type QueryableModuleCalls<ApiType extends ApiTypes> = Record<string, DecoratedCallBase<ApiType>>;
@@ -0,0 +1,12 @@
1
+ import type { PalletConstantMetadataLatest } from '@pezkuwi/types/interfaces';
2
+ import type { Codec } from '@pezkuwi/types/types';
3
+ import type { ApiTypes, EmptyBase } from './base.js';
4
+ export interface AugmentedConst<_ extends ApiTypes> {
5
+ meta: PalletConstantMetadataLatest;
6
+ }
7
+ export interface AugmentedConsts<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
8
+ }
9
+ export interface QueryableConsts<ApiType extends ApiTypes> extends AugmentedConsts<ApiType> {
10
+ [key: string]: QueryableModuleConsts;
11
+ }
12
+ export type QueryableModuleConsts = Record<string, Codec>;
@@ -0,0 +1,4 @@
1
+ import type { Observable } from 'rxjs';
2
+ type DeriveCreator = (instanceId: string, api: unknown) => (...args: unknown[]) => Observable<any>;
3
+ export type DeriveCustom = Record<string, Record<string, DeriveCreator>>;
4
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { IsError } from '@pezkuwi/types/metadata/decorate/types';
2
+ import type { ApiTypes, EmptyBase } from './base.js';
3
+ export type AugmentedError<_ extends ApiTypes> = IsError;
4
+ export interface AugmentedErrors<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
5
+ }
6
+ export interface DecoratedErrors<ApiType extends ApiTypes> extends AugmentedErrors<ApiType> {
7
+ [key: string]: ModuleErrors<ApiType>;
8
+ }
9
+ export type ModuleErrors<ApiType extends ApiTypes> = Record<string, AugmentedError<ApiType>>;
@@ -0,0 +1,10 @@
1
+ import type { IsEvent } from '@pezkuwi/types/metadata/decorate/types';
2
+ import type { AnyTuple } from '@pezkuwi/types/types';
3
+ import type { ApiTypes, EmptyBase } from './base.js';
4
+ export type AugmentedEvent<_ extends ApiTypes, T extends AnyTuple = AnyTuple, N = unknown> = IsEvent<T, N>;
5
+ export interface AugmentedEvents<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
6
+ }
7
+ export interface DecoratedEvents<ApiType extends ApiTypes> extends AugmentedEvents<ApiType> {
8
+ [key: string]: ModuleEvents<ApiType>;
9
+ }
10
+ export type ModuleEvents<ApiType extends ApiTypes> = Record<string, AugmentedEvent<ApiType>>;
@@ -0,0 +1,10 @@
1
+ export * from '@pezkuwi/api-base/types/calls';
2
+ export * from '@pezkuwi/api-base/types/consts';
3
+ export * from '@pezkuwi/api-base/types/errors';
4
+ export * from '@pezkuwi/api-base/types/events';
5
+ export * from '@pezkuwi/api-base/types/storage';
6
+ export * from '@pezkuwi/api-base/types/submittable';
7
+ export * from './api.js';
8
+ export * from './base.js';
9
+ export * from './derive.js';
10
+ export * from './rpc.js';
@@ -0,0 +1,21 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { AnyFunction, AnyJson, Callback, DefinitionRpc } from '@pezkuwi/types/types';
3
+ import type { ApiTypes, PromiseResult, Push, RxResult, UnsubscribePromise } from './base.js';
4
+ export type { AugmentedRpc } from '@pezkuwi/rpc-core/types';
5
+ export interface RxRpcResult<F extends AnyFunction> extends RxResult<F> {
6
+ raw<T>(...args: Parameters<F>): Observable<T>;
7
+ meta: DefinitionRpc;
8
+ }
9
+ export interface PromiseRpcResult<F extends AnyFunction> extends PromiseResult<F> {
10
+ raw<T>(...args: Parameters<F>): Promise<T>;
11
+ raw<T>(...args: Push<Parameters<F>, Callback<T>>): UnsubscribePromise;
12
+ meta: DefinitionRpc;
13
+ }
14
+ export type RpcMethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiType extends 'rxjs' ? RxRpcResult<F> : PromiseRpcResult<F>;
15
+ export type DecoratedRpcSection<ApiType extends ApiTypes, Section> = {
16
+ [M in keyof Section]: Section[M] extends AnyFunction ? RpcMethodResult<ApiType, Section[M]> : never;
17
+ };
18
+ export type RawRpcType<ApiType extends ApiTypes> = (method: string, ...params: unknown[]) => ApiType extends 'rxjs' ? Observable<AnyJson> : Promise<AnyJson>;
19
+ export type DecoratedRpc<ApiType extends ApiTypes, AllSections> = {
20
+ [S in keyof AllSections]: DecoratedRpcSection<ApiType, AllSections[S]>;
21
+ } & RawRpcType<ApiType>;
@@ -0,0 +1,81 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { StorageKey, u64 } from '@pezkuwi/types';
3
+ import type { Hash } from '@pezkuwi/types/interfaces';
4
+ import type { StorageEntry } from '@pezkuwi/types/primitive/types';
5
+ import type { AnyFunction, AnyTuple, Callback, Codec, IStorageKey } from '@pezkuwi/types/types';
6
+ import type { ApiTypes, DropLast, EmptyBase, MethodResult, PaginationOptions, PromiseOrObs, ReturnCodec, UnsubscribePromise } from './base.js';
7
+ type StorageEntryObservableMulti<R extends Codec = Codec> = <T extends Codec = R>(args: unknown[]) => Observable<T[]>;
8
+ interface StorageEntryPromiseMulti<R extends Codec = Codec> {
9
+ <T extends Codec = R>(args: unknown[]): Promise<T[]>;
10
+ <T extends Codec = R>(args: unknown[], callback: Callback<T[]>): UnsubscribePromise;
11
+ }
12
+ export interface StorageEntryPromiseOverloads {
13
+ (arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<Codec>;
14
+ <T extends Codec>(arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<T>;
15
+ <T extends Codec>(callback: Callback<T>): UnsubscribePromise;
16
+ <T extends Codec>(arg: unknown, callback: Callback<T>): UnsubscribePromise;
17
+ <T extends Codec>(arg1: unknown, arg2: unknown, callback: Callback<T>): UnsubscribePromise;
18
+ <T extends Codec>(arg1: unknown, arg2: unknown, arg3: unknown, callback: Callback<T>): UnsubscribePromise;
19
+ }
20
+ export interface StorageEntryPromiseOverloadsAt {
21
+ (arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<Codec>;
22
+ <T extends Codec>(arg1?: unknown, arg2?: unknown, arg3?: unknown): Promise<T>;
23
+ }
24
+ export type GenericStorageEntryFunction = (...args: unknown[]) => Observable<Codec>;
25
+ export type QueryableStorageEntry<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> = ApiType extends 'rxjs' ? AugmentedQuery<'rxjs', GenericStorageEntryFunction, A> : AugmentedQuery<'promise', GenericStorageEntryFunction, A> & StorageEntryPromiseOverloads;
26
+ export type QueryableStorageEntryAt<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> = ApiType extends 'rxjs' ? AugmentedQueryAt<'rxjs', GenericStorageEntryFunction, A> : AugmentedQueryAt<'promise', GenericStorageEntryFunction, A> & StorageEntryPromiseOverloadsAt;
27
+ export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> extends StorageEntryBaseAt<ApiType, F, A> {
28
+ /**
29
+ * @deprecated Use api.at(<blockHash>)
30
+ */
31
+ at: <T = ReturnCodec<F>>(hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, T>;
32
+ creator: StorageEntry;
33
+ /**
34
+ * @deprecated Use api.at(<blockHash>)
35
+ */
36
+ entriesAt: <T = ReturnCodec<F>, K extends AnyTuple = A>(hash: Hash | Uint8Array | string, ...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, [StorageKey<K>, T][]>;
37
+ /**
38
+ * @deprecated Use api.at(<blockHash>)
39
+ */
40
+ keysAt: <K extends AnyTuple = A>(hash: Hash | Uint8Array | string, ...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, StorageKey<K>[]>;
41
+ /**
42
+ * @deprecated Use api.at(<blockHash>)
43
+ */
44
+ sizeAt: (hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, u64>;
45
+ multi: ApiType extends 'rxjs' ? StorageEntryObservableMulti<ReturnCodec<F>> : StorageEntryPromiseMulti<ReturnCodec<F>>;
46
+ }
47
+ export interface StorageEntryBaseAt<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> {
48
+ entries: <T = ReturnCodec<F>, K extends AnyTuple = A>(...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, [StorageKey<K>, T][]>;
49
+ entriesPaged: <T = ReturnCodec<F>, K extends AnyTuple = A>(opts: PaginationOptions<Parameters<F>[0]>) => PromiseOrObs<ApiType, [StorageKey<K>, T][]>;
50
+ hash: (...args: Parameters<F>) => PromiseOrObs<ApiType, Hash>;
51
+ is: (key: IStorageKey<AnyTuple>) => key is IStorageKey<A>;
52
+ key: (...args: Parameters<F>) => string;
53
+ keyPrefix: (...args: DropLast<Parameters<F>>) => string;
54
+ keys: <K extends AnyTuple = A>(...args: DropLast<Parameters<F>>) => PromiseOrObs<ApiType, StorageKey<K>[]>;
55
+ keysPaged: <K extends AnyTuple = A>(opts: PaginationOptions<Parameters<F>[0]>) => PromiseOrObs<ApiType, StorageKey<K>[]>;
56
+ size: (...args: Parameters<F>) => PromiseOrObs<ApiType, u64>;
57
+ }
58
+ export type QueryableModuleStorage<ApiType extends ApiTypes> = Record<string, QueryableStorageEntry<ApiType, AnyTuple>>;
59
+ export type QueryableModuleStorageAt<ApiType extends ApiTypes> = Record<string, QueryableStorageEntryAt<ApiType, AnyTuple>>;
60
+ export type QueryableStorageMultiArg<ApiType extends ApiTypes> = QueryableStorageEntry<ApiType> | [
61
+ QueryableStorageEntry<ApiType>,
62
+ ...unknown[]
63
+ ];
64
+ export type QueryableStorageMultiBase<ApiType extends ApiTypes> = <T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[]) => Observable<T>;
65
+ export interface QueryableStorageMultiPromise<ApiType extends ApiTypes> {
66
+ <T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[], callback: Callback<T>): UnsubscribePromise;
67
+ <T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[]): Promise<T>;
68
+ }
69
+ export type QueryableStorageMulti<ApiType extends ApiTypes> = ApiType extends 'rxjs' ? QueryableStorageMultiBase<ApiType> : QueryableStorageMultiPromise<ApiType>;
70
+ export type AugmentedQuery<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F, A>;
71
+ export type AugmentedQueryAt<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = MethodResult<ApiType, F> & StorageEntryBaseAt<ApiType, F, A>;
72
+ export type AugmentedQueryDoubleMap<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = AugmentedQuery<ApiType, F, A>;
73
+ export interface AugmentedQueries<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
74
+ }
75
+ export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
76
+ [key: string]: QueryableModuleStorage<ApiType>;
77
+ }
78
+ export interface QueryableStorageAt<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
79
+ [key: string]: QueryableModuleStorageAt<ApiType>;
80
+ }
81
+ export {};
@@ -0,0 +1,72 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { AccountId, Address, ApplyExtrinsicResult, BlockNumber, Call, DispatchError, DispatchInfo, EventRecord, Extrinsic, ExtrinsicStatus, Hash, RuntimeDispatchInfo } from '@pezkuwi/types/interfaces';
3
+ import type { AnyFunction, AnyNumber, AnyTuple, AnyU8a, Callback, CallBase, Codec, IExtrinsicEra, IKeyringPair, ISubmittableResult, Signer } from '@pezkuwi/types/types';
4
+ import type { ApiTypes, EmptyBase, PromiseOrObs } from './base.js';
5
+ export type AugmentedSubmittable<T extends AnyFunction, A extends AnyTuple = AnyTuple> = T & CallBase<A>;
6
+ export type AddressOrPair = IKeyringPair | string | AccountId | Address;
7
+ export interface SignerOptions {
8
+ blockHash: Uint8Array | string;
9
+ era?: IExtrinsicEra | number;
10
+ nonce: AnyNumber | Codec;
11
+ signer?: Signer;
12
+ tip?: AnyNumber;
13
+ assetId?: AnyNumber | object;
14
+ mode?: AnyNumber;
15
+ metadataHash?: AnyU8a;
16
+ withSignedTransaction?: boolean;
17
+ }
18
+ export type SubmittableDryRunResult<ApiType extends ApiTypes> = ApiType extends 'rxjs' ? Observable<ApplyExtrinsicResult> : Promise<ApplyExtrinsicResult>;
19
+ export type SubmittableResultResult<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> = ApiType extends 'rxjs' ? Observable<R> : Promise<Hash>;
20
+ export type SubmittableResultSubscription<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> = ApiType extends 'rxjs' ? Observable<R> : Promise<() => void>;
21
+ export type SubmittablePaymentResult<ApiType extends ApiTypes> = ApiType extends 'rxjs' ? Observable<RuntimeDispatchInfo> : Promise<RuntimeDispatchInfo>;
22
+ export interface SubmittableResultValue {
23
+ dispatchError?: DispatchError | undefined;
24
+ dispatchInfo?: DispatchInfo | undefined;
25
+ events?: EventRecord[];
26
+ internalError?: Error | undefined;
27
+ status: ExtrinsicStatus;
28
+ txHash: Hash;
29
+ txIndex?: number | undefined;
30
+ blockNumber?: BlockNumber;
31
+ }
32
+ export interface SubmittableExtrinsic<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> extends Extrinsic {
33
+ /** true if api.rpc.system.dryRun is available, enabling dryRun(...) */
34
+ hasDryRun: boolean;
35
+ /** true if api.call.transactionPaymentApi.queryInfo is available, enabling paymentInfo(...) */
36
+ hasPaymentInfo: boolean;
37
+ dryRun(account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableDryRunResult<ApiType>;
38
+ paymentInfo(account: AddressOrPair, options?: Partial<SignerOptions>): SubmittablePaymentResult<ApiType>;
39
+ send(): SubmittableResultResult<ApiType>;
40
+ send(statusCb: Callback<R>): SubmittableResultSubscription<ApiType, R>;
41
+ /**
42
+ * @description Sign the constructed transaction asynchronously.
43
+ *
44
+ * The result is a signed extrinsic that is ready to be broadcast to the network via `.send()`, `rpc.author.submitExtrinsic()`, or
45
+ * any custom submission logic.
46
+ */
47
+ signAsync(account: AddressOrPair, _options?: Partial<SignerOptions>): PromiseOrObs<ApiType, this>;
48
+ /**
49
+ * @description Sign and broadcast the constructued transaction.
50
+ *
51
+ * Note for injected signers:
52
+ * As of v12.0.1 and up the `SignerResult` return type for `signPayload` allows for the `signedTransaction` field.
53
+ * This allows the signer to input a signed transaction that will be directly broadcasted. This
54
+ * bypasses the api adding the signature to the payload. The api will ensure that the Call Data is not changed before it broadcasts the
55
+ * transaction. This allows for the signer to modify the payload to add things like `mode`, and `metadataHash` for
56
+ * signedExtensions such as `CheckMetadataHash`.
57
+ */
58
+ signAndSend(account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableResultResult<ApiType, R>;
59
+ signAndSend(account: AddressOrPair, statusCb: Callback<R>): SubmittableResultSubscription<ApiType>;
60
+ signAndSend(account: AddressOrPair, options: Partial<SignerOptions>, statusCb?: Callback<R>): SubmittableResultSubscription<ApiType, R>;
61
+ withResultTransform(transform: (input: ISubmittableResult) => ISubmittableResult): this;
62
+ }
63
+ export interface SubmittableExtrinsicFunction<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> extends CallBase<A> {
64
+ (...params: any[]): SubmittableExtrinsic<ApiType>;
65
+ }
66
+ export interface AugmentedSubmittables<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
67
+ }
68
+ export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {
69
+ (extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;
70
+ [key: string]: SubmittableModuleExtrinsics<ApiType>;
71
+ }
72
+ export type SubmittableModuleExtrinsics<ApiType extends ApiTypes> = Record<string, SubmittableExtrinsicFunction<ApiType>>;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
4
+ "description": "Interfaces for interacting with contracts and contract ABIs",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-api/tree/master/packages/api-base#readme",
9
+ "license": "Apache-2.0",
10
+ "name": "@pezkuwi/api-base",
11
+ "repository": {
12
+ "directory": "packages/api-base",
13
+ "type": "git",
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-api.git"
15
+ },
16
+ "sideEffects": [
17
+ "./packageDetect.js",
18
+ "./packageDetect.cjs"
19
+ ],
20
+ "type": "module",
21
+ "version": "16.5.5",
22
+ "main": "index.js",
23
+ "dependencies": {
24
+ "@pezkuwi/rpc-core": "16.5.5",
25
+ "@pezkuwi/types": "16.5.5",
26
+ "@pezkuwi/util": "14.0.5",
27
+ "rxjs": "^7.8.1",
28
+ "tslib": "^2.8.1"
29
+ }
30
+ }
package/src/bundle.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { packageInfo } from './packageInfo.js';
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import './packageDetect.js';
5
+
6
+ export * from './bundle.js';
package/src/mod.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './index.js';
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+ // (packageInfo imports will be kept as-is, user-editable)
6
+
7
+ import { packageInfo as rpcInfo } from '@pezkuwi/rpc-core/packageInfo';
8
+ import { packageInfo as typesInfo } from '@pezkuwi/types/packageInfo';
9
+ import { detectPackage } from '@pezkuwi/util';
10
+
11
+ import { packageInfo } from './packageInfo.js';
12
+
13
+ detectPackage(packageInfo, null, [rpcInfo, typesInfo]);
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+
6
+ export const packageInfo = { name: '@pezkuwi/api-base', path: 'auto', type: 'auto', version: '16.5.5' };
@@ -0,0 +1,29 @@
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 { DecoratedRpc, QueryableCalls, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '@pezkuwi/api-base/types';
6
+ import type { RpcInterface } from '@pezkuwi/rpc-core/types';
7
+ import type { Metadata } from '@pezkuwi/types';
8
+ import type { Hash, RuntimeVersion } from '@pezkuwi/types/interfaces';
9
+ import type { Registry, Signer } from '@pezkuwi/types/types';
10
+
11
+ // A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
12
+ export interface ApiInterfaceRx {
13
+ call: QueryableCalls<'rxjs'>;
14
+ consts: QueryableConsts<'rxjs'>;
15
+ extrinsicType: number;
16
+ genesisHash?: Hash | undefined;
17
+ hasSubscriptions: boolean;
18
+ registry: Registry;
19
+ runtimeMetadata: Metadata;
20
+ runtimeVersion: RuntimeVersion;
21
+ query: QueryableStorage<'rxjs'>;
22
+ queryMulti: QueryableStorageMulti<'rxjs'>;
23
+ rpc: DecoratedRpc<'rxjs', RpcInterface>;
24
+ tx: SubmittableExtrinsics<'rxjs'>;
25
+ signer?: Signer | undefined;
26
+
27
+ callAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableCalls<'rxjs'>>;
28
+ queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableStorage<'rxjs'>>;
29
+ }
@@ -0,0 +1,78 @@
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, Callback, Codec } from '@pezkuwi/types/types';
6
+
7
+ export type Push<T extends readonly unknown[], V> = [...T, V]
8
+
9
+ export type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any?] ? U : [...T];
10
+
11
+ export type ApiTypes = 'promise' | 'rxjs';
12
+
13
+ // Returns the inner type of an Observable
14
+ export type ObsInnerType<O extends Observable<any>> = O extends Observable<infer U> ? U : never;
15
+
16
+ export type VoidFn = () => void;
17
+
18
+ export type UnsubscribePromise = Promise<VoidFn>;
19
+
20
+ export type PromiseOrObs<ApiType extends ApiTypes, T> =
21
+ ApiType extends 'rxjs'
22
+ ? Observable<T>
23
+ : Promise<T>;
24
+
25
+ export type MethodResult<ApiType extends ApiTypes, F extends AnyFunction> =
26
+ ApiType extends 'rxjs'
27
+ ? RxResult<F>
28
+ : PromiseResult<F>;
29
+
30
+ // Here are the return types of these parts of the api:
31
+ // - api.query.*.*: no exact typings
32
+ // - api.tx.*.*: SubmittableExtrinsic<ApiType extends ApiTypes>
33
+ // - api.derive.*.*: MethodResult<ApiType, F>
34
+ // - api.rpc.*.*: no exact typings (for now, FIXME: should be MethodResult<ApiType, F>, like in derive)
35
+
36
+ // These are the types that don't lose type information (used for api.derive.*)
37
+ // Also use these for api.rpc.* https://github.com/polkadot-js/api/issues/1009
38
+ export interface RxResult<F extends AnyFunction> {
39
+ (...args: Parameters<F>): Observable<ObsInnerType<ReturnType<F>>>;
40
+ <T>(...args: Parameters<F>): Observable<T>;
41
+ }
42
+
43
+ export interface PromiseResult<F extends AnyFunction> {
44
+ (...args: Parameters<F>): Promise<ObsInnerType<ReturnType<F>>>;
45
+ (...args: Push<Parameters<F>, Callback<ObsInnerType<ReturnType<F>>>>): UnsubscribePromise;
46
+ <T extends Codec | Codec[]>(...args: Parameters<F>): Promise<T>;
47
+ <T extends Codec | Codec[]>(...args: Push<Parameters<F>, Callback<T>>): UnsubscribePromise;
48
+ }
49
+
50
+ // In the abstract `decorateMethod` in Base.ts, we can also pass in some meta-
51
+ // information. This describes it.
52
+ export interface DecorateMethodOptions {
53
+ methodName?: string;
54
+ overrideNoSub?: (...args: unknown[]) => Observable<Codec>;
55
+ }
56
+
57
+ export type DecorateFn <T extends Codec> = (...args: any[]) => Observable<T>;
58
+
59
+ export interface PaginationOptions<A = unknown> {
60
+ args: A[];
61
+ pageSize: number;
62
+ startKey?: string;
63
+ }
64
+
65
+ export type DecorateMethod<_ApiType extends ApiTypes, T = any> =
66
+ <M extends (...args: any[]) => Observable<any>>(method: M, options?: DecorateMethodOptions) => T;
67
+
68
+ type AsCodec<R> = R extends Codec
69
+ ? R
70
+ : Codec;
71
+
72
+ export type ReturnCodec<F extends AnyFunction> = AsCodec<ObsInnerType<ReturnType<F>>>;
73
+
74
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
75
+ export interface EmptyBase<_> {
76
+ // this is use to allow use to have unused vars in augmented interfaces,
77
+ // so intentionally left empty
78
+ }
@@ -0,0 +1,31 @@
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, Codec, DefinitionCallNamed } from '@pezkuwi/types/types';
6
+ import type { ApiTypes, EmptyBase, ReturnCodec } from './base.js';
7
+
8
+ export type DecoratedCallBase<ApiType extends ApiTypes, F extends AnyFunction = (...args: any[]) => Observable<Codec>> =
9
+ ApiType extends 'rxjs'
10
+ ? <T = ReturnCodec<F>> (...args: Parameters<F>) => Observable<T>
11
+ : <T = ReturnCodec<F>> (...args: Parameters<F>) => Promise<T>;
12
+
13
+ export type AugmentedCall<ApiType extends ApiTypes, F extends AnyFunction = (...args: any[]) => Observable<Codec>> = DecoratedCallBase<ApiType, F> & {
14
+ /** The metadata/description/definition for this method */
15
+ meta: DefinitionCallNamed
16
+ };
17
+
18
+ // augmented interfaces
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
21
+ export interface AugmentedCalls<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
22
+ // augmented
23
+ }
24
+
25
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
26
+ export interface QueryableCalls<ApiType extends ApiTypes> extends AugmentedCalls<ApiType> {
27
+ // when non-augmented, we need to at least have Codec results
28
+ [key: string]: QueryableModuleCalls<ApiType>;
29
+ }
30
+
31
+ export type QueryableModuleCalls<ApiType extends ApiTypes> = Record<string, DecoratedCallBase<ApiType>>;
@@ -0,0 +1,25 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { PalletConstantMetadataLatest } from '@pezkuwi/types/interfaces';
5
+ import type { Codec } from '@pezkuwi/types/types';
6
+ import type { ApiTypes, EmptyBase } from './base.js';
7
+
8
+ export interface AugmentedConst<_ extends ApiTypes> {
9
+ meta: PalletConstantMetadataLatest;
10
+ }
11
+
12
+ // augmented interfaces
13
+
14
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
15
+ export interface AugmentedConsts<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
16
+ // augmented
17
+ }
18
+
19
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
20
+ export interface QueryableConsts<ApiType extends ApiTypes> extends AugmentedConsts<ApiType> {
21
+ // when non-augmented, we need to at least have Codec results
22
+ [key: string]: QueryableModuleConsts;
23
+ }
24
+
25
+ export type QueryableModuleConsts = Record<string, Codec>;
@@ -0,0 +1,8 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+
6
+ type DeriveCreator = (instanceId: string, api: unknown) => (...args: unknown[]) => Observable<any>;
7
+
8
+ export type DeriveCustom = Record<string, Record<string, DeriveCreator>>;
@@ -0,0 +1,22 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { IsError } from '@pezkuwi/types/metadata/decorate/types';
5
+ import type { ApiTypes, EmptyBase } from './base.js';
6
+
7
+ export type AugmentedError<_ extends ApiTypes> = IsError;
8
+
9
+ // augmented interfaces
10
+
11
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
12
+ export interface AugmentedErrors<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
13
+ // augmented
14
+ }
15
+
16
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
17
+ export interface DecoratedErrors<ApiType extends ApiTypes> extends AugmentedErrors<ApiType> {
18
+ // when non-augmented, we need to at least have Codec results
19
+ [key: string]: ModuleErrors<ApiType>;
20
+ }
21
+
22
+ export type ModuleErrors<ApiType extends ApiTypes> = Record<string, AugmentedError<ApiType>>;
@@ -0,0 +1,23 @@
1
+ // Copyright 2017-2025 @polkadot/api-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { IsEvent } from '@pezkuwi/types/metadata/decorate/types';
5
+ import type { AnyTuple } from '@pezkuwi/types/types';
6
+ import type { ApiTypes, EmptyBase } from './base.js';
7
+
8
+ export type AugmentedEvent<_ extends ApiTypes, T extends AnyTuple = AnyTuple, N = unknown> = IsEvent<T, N>;
9
+
10
+ // augmented interfaces
11
+
12
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
13
+ export interface AugmentedEvents<ApiType extends ApiTypes> extends EmptyBase<ApiType> {
14
+ // augmented
15
+ }
16
+
17
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
18
+ export interface DecoratedEvents<ApiType extends ApiTypes> extends AugmentedEvents<ApiType> {
19
+ // when non-augmented, we need to at least have Codec results
20
+ [key: string]: ModuleEvents<ApiType>;
21
+ }
22
+
23
+ export type ModuleEvents<ApiType extends ApiTypes> = Record<string, AugmentedEvent<ApiType>>;