* Use .js imports in src * Adjust * Fix imports * Bump dev * Adjust with .js imports for typegen * Adjust * Adjust * Remove target override
32 lines
1007 B
TypeScript
32 lines
1007 B
TypeScript
// Copyright 2017-2023 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Observable } from 'rxjs';
|
|
import type { BN } from '@polkadot/util';
|
|
import type { DeriveApi } from '../types.js';
|
|
import type { Bag, BagExpanded } from './types.js';
|
|
|
|
import { map, switchMap } from 'rxjs';
|
|
|
|
import { objectSpread } from '@polkadot/util';
|
|
|
|
import { memo } from '../util/index.js';
|
|
|
|
export function expand (instanceId: string, api: DeriveApi): (bag: Bag) => Observable<BagExpanded> {
|
|
return memo(instanceId, (bag: Bag): Observable<BagExpanded> =>
|
|
api.derive.bagsList.listNodes(bag.bag).pipe(
|
|
map((nodes) => objectSpread({ nodes }, bag))
|
|
)
|
|
);
|
|
}
|
|
|
|
export function getExpanded (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<BagExpanded> {
|
|
return memo(instanceId, (id: BN | number): Observable<BagExpanded> =>
|
|
api.derive.bagsList.get(id).pipe(
|
|
switchMap((bag) =>
|
|
api.derive.bagsList.expand(bag)
|
|
)
|
|
)
|
|
);
|
|
}
|