Update api.derive to use api.queryMulti (#911)
* session api.queryMulti * Make a single subscription to retrieve all session info * Adjustments * WIP * Seems mostly comprehensive, need to full test e2e * e2e tests for operations * Allow "create from empty" * skip * Remove comment * Remove ancient ?'s * Update types.ts
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
import { AnyU8a } from '../types';
|
||||
|
||||
import { isFunction } from '@plugnet/util';
|
||||
import { assert, isFunction, isString, isU8a } from '@plugnet/util';
|
||||
|
||||
import Bytes from './Bytes';
|
||||
import { StorageFunctionMetadata as MetaV0 } from '../Metadata/v0/Storage';
|
||||
@@ -29,25 +29,28 @@ export default class StorageKey extends Bytes {
|
||||
private _meta: MetaV0 | MetaV4 | null;
|
||||
private _outputType: string | null;
|
||||
|
||||
constructor (value: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]) {
|
||||
constructor (value?: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]) {
|
||||
super(StorageKey.decodeStorageKey(value));
|
||||
|
||||
this._meta = StorageKey.getMeta(value as StorageKey);
|
||||
this._outputType = StorageKey.getType(value as StorageKey);
|
||||
}
|
||||
|
||||
static decodeStorageKey (value: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]): Uint8Array {
|
||||
if (isFunction(value)) {
|
||||
static decodeStorageKey (value?: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]): Uint8Array | string | undefined {
|
||||
if (!value || isU8a(value) || isString(value)) {
|
||||
// let Bytes handle these inputs
|
||||
return value;
|
||||
} else if (isFunction(value)) {
|
||||
return value();
|
||||
} else if (Array.isArray(value)) {
|
||||
const [fn, ...arg] = value;
|
||||
|
||||
if (isFunction(fn)) {
|
||||
return fn(...arg);
|
||||
}
|
||||
assert(isFunction(fn), 'Expected function input for key construction');
|
||||
|
||||
return (fn as Function)(...arg);
|
||||
}
|
||||
|
||||
return value as Uint8Array;
|
||||
throw new Error(`Unable to convert input ${value} to StorageKey`);
|
||||
}
|
||||
|
||||
static getMeta (value: StorageKey | StorageFunction | [StorageFunction, any]): MetaV0 | MetaV4 | null {
|
||||
|
||||
Reference in New Issue
Block a user