mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-10-22 19:56:16 +00:00
Move to @pezkuwi/dev 0.86 (eslint 10 toolchain)
- @pezkuwi/dev, dev-test, dev-ts ^0.86.3; disable directives renamed for the new rule names, or removed where the rule no longer reports - rethrown errors carry the original as `cause` (13 sites) - optional chains where a guard expression tested the same value - Init: the registry cache settles with the creator's own promise, dropping the entry in finally(), instead of re-wrapping it - Combinator: a typed call instead of `Function` - checkTypes.manual: synchronous checks run outside Promise.all - sortValues, createTypeUnsafe: initial values that were never read - typegen util: load docs.js for its side effect (it registers the `docs` Handlebars partial) now that its types are re-exported type-only - MockProvider keeps its Header assertion: the package's own build does not load api-augment, so createType returns a plain Codec there - Decorate keeps `delete queue[i]`: the hole marks a fired queue and later indexes must not shift
This commit is contained in:
1 parent
8c9af013b5
commit
60e0f73ffa
166 files changed
+2757
-3731
No files matched your search
@@ -56,7 +56,7 @@ const l = logger('api/init');
|
||||
let instanceCounter = 0;
|
||||
|
||||
function getAtQueryFn<ApiType extends ApiTypes> (api: ApiDecoration<ApiType>, { method, section }: StorageEntry): AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> {
|
||||
return assertReturn(api.rx.query[section] && api.rx.query[section][method], () => `query.${section}.${method} is not available in this version of the metadata`);
|
||||
return assertReturn(api.rx.query[section]?.[method], () => `query.${section}.${method} is not available in this version of the metadata`);
|
||||
}
|
||||
|
||||
export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
@@ -728,7 +728,6 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
decorated.is = (other: IMethod<AnyTuple>) =>
|
||||
method.is(other);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return this._decorateFunctionMeta(method as unknown as MetaDecoration, decorated as unknown as MetaDecoration) as unknown as SubmittableExtrinsicFunction<ApiType>;
|
||||
}
|
||||
|
||||
@@ -760,13 +759,13 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
map((api) => getAtQueryFn(api, creator)));
|
||||
|
||||
// Disable this where it occurs for each field we are decorating
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
const decorated: AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> & MetaDecoration = this._decorateStorageCall(creator, decorateMethod);
|
||||
|
||||
decorated.creator = creator;
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
decorated.at = decorateMethod((blockHash: Hash, ...args: unknown[]): Observable<Codec> =>
|
||||
getQueryAt(blockHash).pipe(
|
||||
switchMap((q) => q(...args))));
|
||||
@@ -787,7 +786,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
decorated.size = decorateMethod((...args: unknown[]): Observable<u64> =>
|
||||
this._rpcCore.state.getStorageSize(getArgs(args)));
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<u64> =>
|
||||
getQueryAt(blockHash).pipe(
|
||||
switchMap((q) =>
|
||||
@@ -799,7 +798,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
memo(this.#instanceId, (...args: unknown[]): Observable<[StorageKey, Codec][]> =>
|
||||
this._retrieveMapEntries(creator, null, args)));
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
decorated.entriesAt = decorateMethod(
|
||||
memo(this.#instanceId, (blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<[StorageKey, Codec][]> =>
|
||||
getQueryAt(blockHash).pipe(
|
||||
@@ -813,7 +812,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
memo(this.#instanceId, (...args: unknown[]): Observable<StorageKey[]> =>
|
||||
this._retrieveMapKeys(creator, null, args)));
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
decorated.keysAt = decorateMethod(
|
||||
memo(this.#instanceId, (blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<StorageKey[]> =>
|
||||
getQueryAt(blockHash).pipe(
|
||||
@@ -833,7 +832,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
);
|
||||
}
|
||||
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
return this._decorateFunctionMeta(creator as unknown as MetaDecoration, decorated) as unknown as QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
@@ -842,7 +841,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
const getArgs = (args: unknown[]): unknown[] => extractStorageArgs(registry, creator, args);
|
||||
|
||||
// Disable this where it occurs for each field we are decorating
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
const decorated: AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> & MetaDecoration = decorateMethod((...args: unknown[]): Observable<Codec> =>
|
||||
this._rpcCore.state.getStorage(getArgs(args), blockHash));
|
||||
@@ -893,7 +892,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
);
|
||||
}
|
||||
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
return this._decorateFunctionMeta(creator as unknown as MetaDecoration, decorated) as unknown as QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
@@ -924,6 +923,9 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
// (anything after this will be added to a new queue)
|
||||
const calls = queue[queueIdx][1];
|
||||
|
||||
// The hole marks this queue as fired (see the check above);
|
||||
// removing the entry instead would shift every later index.
|
||||
// eslint-disable-next-line @typescript-eslint/no-array-delete
|
||||
delete queue[queueIdx];
|
||||
|
||||
resolve(calls);
|
||||
|
||||
@@ -151,16 +151,8 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
if (isUndefined(waiting)) {
|
||||
// nothing waiting, construct new
|
||||
waiting = this.#waitingRegistries[key] = new Promise<VersionedRegistry<ApiType>>((resolve, reject): void => {
|
||||
creator()
|
||||
.then((registry): void => {
|
||||
delete this.#waitingRegistries[key];
|
||||
resolve(registry);
|
||||
})
|
||||
.catch((error): void => {
|
||||
delete this.#waitingRegistries[key];
|
||||
reject(error);
|
||||
});
|
||||
waiting = this.#waitingRegistries[key] = creator().finally((): void => {
|
||||
delete this.#waitingRegistries[key];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ async function query (api: ApiPromise, pairs: TestKeyringMapBizinikiwi): Promise
|
||||
const bal2 = await api.query.balances.totalIssuance('WRONG_ARG'); // bal2 is Codec (wrong args)
|
||||
const override = await api.query.balances.totalIssuance<Header>(); // override is still available
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
const oldBal = await api.query.balances.totalIssuance.at('abcd');
|
||||
|
||||
// For older queries we can cast with `<Balance>` (newer chain have multi typed)
|
||||
@@ -144,7 +144,7 @@ async function queryExtra (api: ApiPromise): Promise<void> {
|
||||
});
|
||||
|
||||
// at queries
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
const events = await api.query.system.events.at('0x12345');
|
||||
|
||||
console.log(`Received ${events.length} events:`);
|
||||
@@ -221,7 +221,7 @@ async function rpc (api: ApiPromise): Promise<void> {
|
||||
});
|
||||
|
||||
// deprecated methods
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
await api.rpc.state.getPairs('123');
|
||||
}
|
||||
|
||||
@@ -304,17 +304,18 @@ async function main (): Promise<void> {
|
||||
const api = await ApiPromise.create();
|
||||
const pairs = createTestPairs();
|
||||
|
||||
consts(api);
|
||||
errors(api);
|
||||
events(api);
|
||||
types(api);
|
||||
|
||||
await Promise.all([
|
||||
calls(api),
|
||||
consts(api),
|
||||
derive(api),
|
||||
errors(api),
|
||||
events(api),
|
||||
query(api, pairs),
|
||||
queryExtra(api),
|
||||
queryMulti(api, pairs),
|
||||
rpc(api),
|
||||
types(api),
|
||||
tx(api, pairs),
|
||||
at(api)
|
||||
]);
|
||||
|
||||
@@ -150,7 +150,7 @@ export class ApiPromise extends ApiBase<'promise'> {
|
||||
public static create (options?: ApiOptions): Promise<ApiPromise> {
|
||||
const instance = new ApiPromise(options);
|
||||
|
||||
if (options && options.throwOnConnect) {
|
||||
if (options?.throwOnConnect) {
|
||||
return instance.isReadyOrError;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export class Combinator<T extends unknown[] = unknown[]> {
|
||||
constructor (fns: (CombinatorFunction | [CombinatorFunction, ...unknown[]])[], callback: CombinatorCallback<T>) {
|
||||
this.#callback = callback;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/require-await
|
||||
this.#subscriptions = fns.map(async (input, index): UnsubscribePromise => {
|
||||
const [fn, ...args] = Array.isArray(input)
|
||||
? input
|
||||
@@ -31,9 +30,8 @@ export class Combinator<T extends unknown[] = unknown[]> {
|
||||
this.#fired.push(false);
|
||||
this.#fns.push(fn);
|
||||
|
||||
// Not quite 100% how to have a variable number at the front here
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/ban-types
|
||||
return (fn as Function)(...args, this._createCallback(index));
|
||||
// the leading arguments vary per function, the callback is always last
|
||||
return (fn as (...params: unknown[]) => UnsubscribePromise)(...args, this._createCallback(index));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,6 @@ describe('Combinator', (): void => {
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it('unsubscribes as required', async (): Promise<void> => {
|
||||
await new Promise<void>((resolve) => {
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
const mocker = () => Promise.resolve(resolve);
|
||||
const combinator = new Combinator([
|
||||
mocker,
|
||||
|
||||
@@ -106,7 +106,7 @@ function decorateSubscribe<M extends DecorateFn<CodecReturnType<M>>> (method: M,
|
||||
* @description Decorate method for ApiPromise, where the results are converted to the Promise equivalent
|
||||
*/
|
||||
export function toPromiseMethod<M extends DecorateFn<CodecReturnType<M>>> (method: M, options?: DecorateMethodOptions): StorageEntryPromiseOverloads {
|
||||
const needsCallback = !!(options?.methodName && options.methodName.includes('subscribe'));
|
||||
const needsCallback = !!(options?.methodName?.includes('subscribe'));
|
||||
|
||||
return function (...args: unknown[]): Promise<CodecReturnType<M>> | UnsubscribePromise {
|
||||
const [actualArgs, resultCb] = extractArgs(args, needsCallback);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable no-dupe-class-members */
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Address, ApplyExtrinsicResult, Call, Extrinsic, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo, SignerPayload } from '@pezkuwi/types/interfaces';
|
||||
import type { Callback, Codec, CodecClass, ISubmittableResult, SignatureOptions } from '@pezkuwi/types/types';
|
||||
@@ -365,7 +363,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
|
||||
const ext = this.registry.createTypeUnsafe<Extrinsic>('Extrinsic', [result.signedTransaction]);
|
||||
const newSignerPayload = this.registry.createTypeUnsafe<SignerPayload>('SignerPayload', [objectSpread({}, {
|
||||
address,
|
||||
assetId: ext.assetId && ext.assetId.isSome ? ext.assetId.toHex() : null,
|
||||
assetId: ext.assetId?.isSome ? ext.assetId.toHex() : null,
|
||||
blockHash: payload.blockHash,
|
||||
blockNumber: header ? header.number : 0,
|
||||
era: ext.era.toHex(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@pezkuwi/api-base/types/calls';
|
||||
export type * from '@pezkuwi/api-base/types/calls';
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@pezkuwi/api-base/types/consts';
|
||||
export type * from '@pezkuwi/api-base/types/consts';
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@pezkuwi/api-base/types/errors';
|
||||
export type * from '@pezkuwi/api-base/types/errors';
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@pezkuwi/api-base/types/events';
|
||||
export type * from '@pezkuwi/api-base/types/events';
|
||||
@@ -25,20 +25,20 @@ export type { Signer, SignerResult } from '@pezkuwi/types/types';
|
||||
export { ApiBase } from '../base/index.js';
|
||||
|
||||
// all starred
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api/types/calls';
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api/types/consts';
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api/types/errors';
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api/types/events';
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api/types/storage';
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api/types/submittable';
|
||||
// eslint-disable-next-line import/export
|
||||
export * from '@pezkuwi/api-base/types';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api/types/calls';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api/types/consts';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api/types/errors';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api/types/events';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api/types/storage';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api/types/submittable';
|
||||
// eslint-disable-next-line import-x/export
|
||||
export type * from '@pezkuwi/api-base/types';
|
||||
|
||||
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
|
||||
export interface ApiInterfaceRx extends ApiInterfaceBase {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@pezkuwi/api-base/types/storage';
|
||||
export type * from '@pezkuwi/api-base/types/storage';
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2026 @pezkuwi/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@pezkuwi/api-base/types/submittable';
|
||||
export type * from '@pezkuwi/api-base/types/submittable';
|
||||
Reference in new issue
Block a user