Adjust derive definitions for no reexport of types (#5536)
* Adjust derive definitions for no reexport of types * Additional for hasProposals
This commit is contained in:
@@ -3,10 +3,6 @@
|
||||
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { u32 } from '@polkadot/types';
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export const members = /*#__PURE__*/ collectiveMembers('allianceMotion');
|
||||
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('allianceMotion');
|
||||
|
||||
@@ -5,9 +5,6 @@ import type { DeriveApi } from '../types.js';
|
||||
|
||||
import { createBlockNumberDerive } from './util.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
/**
|
||||
* @name bestNumber
|
||||
* @returns The latest block number.
|
||||
|
||||
@@ -5,9 +5,6 @@ import type { DeriveApi } from '../types.js';
|
||||
|
||||
import { createBlockNumberDerive } from './util.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
/**
|
||||
* @name bestNumberFinalized
|
||||
* @returns A BlockNumber
|
||||
|
||||
@@ -12,7 +12,9 @@ import { combineLatest, map, of } from 'rxjs';
|
||||
|
||||
import { memo, unwrapBlockNumber } from '../util/index.js';
|
||||
|
||||
export function createBlockNumberDerive <T extends { number: Compact<BlockNumber> | BlockNumber }> (fn: (api: DeriveApi) => Observable<T>): (instanceId: string, api: DeriveApi) => () => Observable<BlockNumber> {
|
||||
export type BlockNumberDerive = (instanceId: string, api: DeriveApi) => () => Observable<BlockNumber>;
|
||||
|
||||
export function createBlockNumberDerive <T extends { number: Compact<BlockNumber> | BlockNumber }> (fn: (api: DeriveApi) => Observable<T>): BlockNumberDerive {
|
||||
return (instanceId: string, api: DeriveApi) =>
|
||||
memo(instanceId, () =>
|
||||
fn(api).pipe(
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// Copyright 2017-2023 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { MembersFn } from './types.js';
|
||||
|
||||
import { callMethod } from './helpers.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export const members = /*#__PURE__*/ callMethod<AccountId[]>('members', []);
|
||||
export const members: MembersFn = /*#__PURE__*/ callMethod('members', []);
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { DeriveApi } from '../types.js';
|
||||
import type { Collective } from './types.js';
|
||||
import type { Collective, PrimeFnRet } from './types.js';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -12,10 +11,7 @@ import { isFunction } from '@polkadot/util';
|
||||
|
||||
import { withSection } from './helpers.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export function prime (section: Collective): (instanceId: string, api: DeriveApi) => () => Observable<AccountId | null> {
|
||||
export function prime (section: Collective): PrimeFnRet {
|
||||
return withSection(section, (query) =>
|
||||
(): Observable<AccountId | null> =>
|
||||
isFunction(query?.prime)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option, u32 } from '@polkadot/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||
import type { DeriveApi, DeriveCollectiveProposal } from '../types.js';
|
||||
import type { Collective } from './types.js';
|
||||
import type { Collective, HasProposalsFnRet, ProposalCountFn, ProposalFnRet, ProposalHashesFn, ProposalsFnRet } from './types.js';
|
||||
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -14,10 +14,6 @@ import { isFunction } from '@polkadot/util';
|
||||
import { firstObservable } from '../util/index.js';
|
||||
import { callMethod, withSection } from './helpers.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { Option, u32 } from '@polkadot/types';
|
||||
export type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||
|
||||
type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]];
|
||||
|
||||
function parse (api: DeriveApi, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] {
|
||||
@@ -48,14 +44,14 @@ function _proposalsFrom (api: DeriveApi, query: DeriveApi['query']['council'], h
|
||||
);
|
||||
}
|
||||
|
||||
export function hasProposals (section: Collective): (instanceId: string, api: DeriveApi) => () => Observable<boolean> {
|
||||
export function hasProposals (section: Collective): HasProposalsFnRet {
|
||||
return withSection(section, (query) =>
|
||||
(): Observable<boolean> =>
|
||||
of(isFunction(query?.proposals))
|
||||
);
|
||||
}
|
||||
|
||||
export function proposals (section: Collective): (instanceId: string, api: DeriveApi) => () => Observable<DeriveCollectiveProposal[]> {
|
||||
export function proposals (section: Collective): ProposalsFnRet {
|
||||
return withSection(section, (query, api) =>
|
||||
(): Observable<DeriveCollectiveProposal[]> =>
|
||||
api.derive[section as 'council'].proposalHashes().pipe(
|
||||
@@ -64,7 +60,7 @@ export function proposals (section: Collective): (instanceId: string, api: Deriv
|
||||
);
|
||||
}
|
||||
|
||||
export function proposal (section: Collective): (instanceId: string, api: DeriveApi) => (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
export function proposal (section: Collective): ProposalFnRet {
|
||||
return withSection(section, (query, api) =>
|
||||
(hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
|
||||
isFunction(query?.proposals)
|
||||
@@ -73,5 +69,5 @@ export function proposal (section: Collective): (instanceId: string, api: Derive
|
||||
);
|
||||
}
|
||||
|
||||
export const proposalCount = /*#__PURE__*/ callMethod<u32 | null>('proposalCount', null);
|
||||
export const proposalHashes = /*#__PURE__*/ callMethod<Hash[]>('proposals', []);
|
||||
export const proposalCount: ProposalCountFn = /*#__PURE__*/ callMethod('proposalCount', null);
|
||||
export const proposalHashes: ProposalHashesFn = /*#__PURE__*/ callMethod('proposals', []);
|
||||
|
||||
@@ -1,4 +1,30 @@
|
||||
// Copyright 2017-2023 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { u32 } from '@polkadot/types';
|
||||
import type { AccountId, Hash } from '@polkadot/types/interfaces';
|
||||
import type { DeriveApi, DeriveCollectiveProposal } from '../types.js';
|
||||
|
||||
export type Collective = 'allianceMotion' | 'council' | 'membership' | 'technicalCommittee';
|
||||
|
||||
export type HasProposalsFnRet = (instanceId: string, api: DeriveApi) => () => Observable<boolean>;
|
||||
export type HasProposalsFn = (section: Collective) => HasProposalsFnRet;
|
||||
|
||||
export type MembersFnRet = (instanceId: string, api: DeriveApi) => () => Observable<AccountId[]>;
|
||||
export type MembersFn = (section: Collective) => MembersFnRet;
|
||||
|
||||
export type PrimeFnRet = (instanceId: string, api: DeriveApi) => () => Observable<AccountId | null>;
|
||||
export type PrimeFn = (section: Collective) => PrimeFnRet;
|
||||
|
||||
export type ProposalFnRet = (instanceId: string, api: DeriveApi) => (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null>;
|
||||
export type ProposalFn = (section: Collective) => ProposalFnRet;
|
||||
|
||||
export type ProposalsFnRet = (instanceId: string, api: DeriveApi) => () => Observable<DeriveCollectiveProposal[]>;
|
||||
export type ProposalsFn = (section: Collective) => ProposalsFnRet;
|
||||
|
||||
export type ProposalCountFnRet = (instanceId: string, api: DeriveApi) => () => Observable<u32 | null>;
|
||||
export type ProposalCountFn = (section: Collective) => ProposalCountFnRet;
|
||||
|
||||
export type ProposalHashesFnRet = (instanceId: string, api: DeriveApi) => () => Observable<Hash[]>;
|
||||
export type ProposalHashesFn = (section: Collective) => ProposalHashesFnRet;
|
||||
|
||||
@@ -6,10 +6,6 @@ import { hasProposals as collectiveHasProposals, members as collectiveMembers, p
|
||||
export * from './votes.js';
|
||||
export * from './votesOf.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { u32 } from '@polkadot/types';
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export const members = /*#__PURE__*/ collectiveMembers('council');
|
||||
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('council');
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { u32 } from '@polkadot/types';
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export const members = /*#__PURE__*/ collectiveMembers('membership');
|
||||
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('membership');
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { u32 } from '@polkadot/types';
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export const members = /*#__PURE__*/ collectiveMembers('technicalCommittee');
|
||||
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('technicalCommittee');
|
||||
|
||||
Reference in New Issue
Block a user