mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-11-05 07:21:06 +00:00
Fix the lint errors
Most are object keys out of order after the rename (dicle, pezkuwi, bizinikiwi, teyrchains and zagros sort differently from the names they replaced); they are sorted, behaviour is unchanged. The rest: - createClass: header.hash is already the BlockHash type; the `as any` cast is removed - ScProvider: WellKnownChain is a string union in @bizinikiwi/connect, so `string | WellKnownChain` was `string`; the spec parameter says so - ScProvider: the jsonRpcResponses loop is a named async function whose rejection (chain removed, client terminated) is caught explicitly instead of a floating promise - the fake chain in the spec no longer needs a non-null assertion - Extrinsic.hash: redundant non-null assertion removed - metadata-get.mjs writes the 2026 header
This commit is contained in:
1 parent
611d410f28
commit
7c6cac97da
19 files changed
+87
-81
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2025 @pezkuwi/rpc-provider authors & contributors
|
||||
// Copyright 2017-2026 @pezkuwi/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
||||
@@ -103,8 +103,10 @@ function getFakeChain (spec: string): MockChain {
|
||||
};
|
||||
|
||||
const nextJsonRpcResponse = (): Promise<string> => {
|
||||
if (_pendingResponses.length > 0) {
|
||||
return Promise.resolve(_pendingResponses.shift()!);
|
||||
const pending = _pendingResponses.shift();
|
||||
|
||||
if (pending !== undefined) {
|
||||
return Promise.resolve(pending);
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
@@ -141,6 +143,8 @@ function getFakeChain (spec: string): MockChain {
|
||||
_triggerCallback: triggerCallback,
|
||||
addChain: (chainSpec) =>
|
||||
Promise.resolve(getFakeChain(chainSpec)),
|
||||
jsonRpcResponses,
|
||||
nextJsonRpcResponse,
|
||||
remove: () => {
|
||||
terminateInterceptor();
|
||||
_isTerminated = true;
|
||||
@@ -148,9 +152,7 @@ function getFakeChain (spec: string): MockChain {
|
||||
sendJsonRpc: (rpc) => {
|
||||
sendJsonRpcInterceptor(rpc);
|
||||
_receivedRequests.push(rpc);
|
||||
},
|
||||
nextJsonRpcResponse,
|
||||
jsonRpcResponses
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -563,6 +565,7 @@ describe('ScProvider', () => {
|
||||
}, 0);
|
||||
|
||||
const cb = jest.fn();
|
||||
|
||||
await provider.subscribe(
|
||||
'foo',
|
||||
'chain_subscribeNewHeads',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2025 @pezkuwi/rpc-provider authors & contributors
|
||||
// Copyright 2017-2026 @pezkuwi/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type * as ScType from '@bizinikiwi/connect';
|
||||
@@ -53,7 +53,7 @@ interface ActiveSubs {
|
||||
export class ScProvider implements ProviderInterface {
|
||||
readonly #Sc: BizinikiwiConnect;
|
||||
readonly #coder: RpcCoder = new RpcCoder();
|
||||
readonly #spec: string | ScType.WellKnownChain;
|
||||
readonly #spec: string;
|
||||
readonly #sharedSandbox?: ScProvider | undefined;
|
||||
readonly #subscriptions = new Map<string, [ResponseCallback, { unsubscribeMethod: string; id: string | number }]>();
|
||||
readonly #resubscribeMethods = new Map<string, ActiveSubs>();
|
||||
@@ -64,7 +64,7 @@ export class ScProvider implements ProviderInterface {
|
||||
#chain: Promise<ScType.Chain> | null = null;
|
||||
#isChainReady = false;
|
||||
|
||||
public constructor (Sc: BizinikiwiConnect, spec: string | ScType.WellKnownChain, sharedSandbox?: ScProvider) {
|
||||
public constructor (Sc: BizinikiwiConnect, spec: string, sharedSandbox?: ScProvider) {
|
||||
if (!isObject(Sc) || !isObject(Sc.WellKnownChain) || !isFunction(Sc.createScClient)) {
|
||||
throw new Error('Expected an @bizinikiwi/connect interface as first parameter to ScProvider');
|
||||
}
|
||||
@@ -171,15 +171,15 @@ export class ScProvider implements ProviderInterface {
|
||||
|
||||
// Start async response processing loop
|
||||
// This replaces the callback-based API from older @substrate/connect versions
|
||||
(async () => {
|
||||
try {
|
||||
for await (const res of chain.jsonRpcResponses) {
|
||||
onResponse(res);
|
||||
}
|
||||
} catch {
|
||||
// Chain was removed or connection closed - this is expected
|
||||
const processResponses = async (): Promise<void> => {
|
||||
for await (const res of chain.jsonRpcResponses) {
|
||||
onResponse(res);
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
processResponses().catch(() => {
|
||||
// Chain was removed or connection closed - this is expected
|
||||
});
|
||||
|
||||
this.#isChainReady = false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user