generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.ts
107 lines (94 loc) · 2.7 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { AugmentedQueries, AugmentedQuery } from '@polkadot/api/types';
import BigNumber from 'bignumber.js';
import { Entity, Procedure } from '~/internal';
/**
* A helper type that will strip `readonly` from the properties of an object. Use with caution
* @hidden
*/
export type Mutable<Immutable> = {
-readonly [K in keyof Immutable]: Immutable[K];
};
/**
* @hidden
*/
export type ProcedureFunc<Args, ReturnValue, Storage> = () => Procedure<Args, ReturnValue, Storage>;
/**
* @hidden
*/
export type UnionOfProcedureFuncs<Args, ReturnValue, Storage> = Args extends unknown
? ProcedureFunc<Args, ReturnValue, Storage>
: never;
/**
* Less strict version of `Parameters<T>`
*/
export type ArgsType<T> = T extends (...args: infer A) => unknown ? A : never;
/**
* Recursively traverse a type and transform its Entity properties into their
* human readable version (as if `.toHuman` had been called on all of them)
*/
export type HumanReadableType<T> = T extends Entity<unknown, infer H>
? HumanReadableType<H>
: T extends BigNumber
? string
: T extends Date
? string
: // eslint-disable-next-line @typescript-eslint/ban-types
T extends object
? {
[K in keyof T]: T[K] extends Entity<unknown, infer E>
? HumanReadableType<E>
: HumanReadableType<T[K]>;
}
: T;
/**
* @hidden
*
* Extract the polkadot.js query function
*
* @example `QueryableStorageFunction<'identity', 'authorizations'>` returns
* `(
* arg1:
* | PolymeshPrimitivesSecondaryKeySignatory
* | { Identity: any }
* | { Account: any }
* | string
* | Uint8Array,
* arg2: u64 | AnyNumber | Uint8Array
* ) => Observable<Option<PolymeshPrimitivesAuthorization>>`
*/
export type QueryFunction<
ModuleName extends keyof AugmentedQueries<'promise'>,
QueryName extends keyof AugmentedQueries<'promise'>[ModuleName]
> = AugmentedQueries<'promise'>[ModuleName][QueryName] extends AugmentedQuery<'promise', infer Fun>
? Fun
: never;
/**
* Override T with the properties of R
*/
export type Modify<T, R> = Omit<T, keyof R> & R;
/**
*
* Ensure a specific property of T is defined
*/
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
/**
* Pick a single property from T and ensure it is defined
*/
export type Ensured<T, K extends keyof T> = Required<Pick<T, K>> & {
[SubKey in K]: NonNullable<T[SubKey]>;
};
export type PaginatedQueryArgs<T> = T & {
size?: number;
start?: number;
};
export type QueryArgs<T, K extends keyof T> = {
[P in K]?: T[P];
};
/**
* @hidden
*
* Create a literal tuple type from a list of arguments
*
* @param args - values to turn into a tuple
*/
export const tuple = <T extends unknown[]>(...args: T): T => args;