@polkadot/types-codec 6.12.2-21 → 6.12.2-25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/abstract/AbstractArray.d.ts +84 -0
  2. package/abstract/AbstractInt.d.ts +75 -0
  3. package/abstract/index.d.ts +2 -0
  4. package/base/Base.d.ts +56 -0
  5. package/base/Compact.d.ts +83 -0
  6. package/base/DoNotConstruct.d.ts +33 -0
  7. package/base/Enum.d.ts +105 -0
  8. package/base/Int.d.ts +16 -0
  9. package/base/Null.d.ts +54 -0
  10. package/base/Option.d.ts +88 -0
  11. package/base/Result.d.ts +46 -0
  12. package/base/Tuple.d.ts +39 -0
  13. package/base/UInt.d.ts +15 -0
  14. package/base/Vec.d.ts +28 -0
  15. package/base/VecAny.d.ts +15 -0
  16. package/base/VecFixed.d.ts +26 -0
  17. package/base/index.d.ts +13 -0
  18. package/bundle.d.ts +7 -0
  19. package/detectPackage.d.ts +1 -0
  20. package/extended/BTreeMap.d.ts +5 -0
  21. package/extended/BTreeSet.d.ts +55 -0
  22. package/extended/BitVec.d.ts +26 -0
  23. package/extended/Bytes.d.ts +25 -0
  24. package/extended/HashMap.d.ts +5 -0
  25. package/extended/Linkage.d.ts +31 -0
  26. package/extended/Map.d.ts +50 -0
  27. package/extended/Range.d.ts +30 -0
  28. package/extended/Type.d.ts +16 -0
  29. package/extended/U8aFixed.d.ts +16 -0
  30. package/extended/WrapperOpaque.d.ts +14 -0
  31. package/extended/index.d.ts +11 -0
  32. package/index.d.ts +2 -0
  33. package/native/Bool.d.ts +62 -0
  34. package/native/Date.d.ts +76 -0
  35. package/native/Json.d.ts +56 -0
  36. package/native/Raw.d.ts +90 -0
  37. package/native/Set.d.ts +76 -0
  38. package/native/Struct.d.ts +93 -0
  39. package/native/Text.d.ts +71 -0
  40. package/native/index.d.ts +7 -0
  41. package/package.json +74 -3
  42. package/packageInfo.cjs +1 -1
  43. package/packageInfo.d.ts +4 -0
  44. package/packageInfo.js +1 -1
  45. package/primitive/I128.d.ts +11 -0
  46. package/primitive/I16.d.ts +11 -0
  47. package/primitive/I256.d.ts +11 -0
  48. package/primitive/I32.d.ts +11 -0
  49. package/primitive/I64.d.ts +11 -0
  50. package/primitive/I8.d.ts +11 -0
  51. package/primitive/U128.d.ts +11 -0
  52. package/primitive/U16.d.ts +11 -0
  53. package/primitive/U256.d.ts +11 -0
  54. package/primitive/U32.d.ts +11 -0
  55. package/primitive/U64.d.ts +11 -0
  56. package/primitive/U8.d.ts +11 -0
  57. package/primitive/USize.d.ts +12 -0
  58. package/primitive/index.d.ts +13 -0
  59. package/types/codec.d.ts +77 -0
  60. package/types/helpers.d.ts +14 -0
  61. package/types/index.d.ts +4 -0
  62. package/types/interfaces.d.ts +69 -0
  63. package/types/registry.d.ts +61 -0
  64. package/utils/compareArray.d.ts +1 -0
  65. package/utils/compareMap.d.ts +1 -0
  66. package/utils/compareSet.d.ts +1 -0
  67. package/utils/decodeU8a.d.ts +13 -0
  68. package/utils/index.d.ts +9 -0
  69. package/utils/mapToTypeMap.d.ts +5 -0
  70. package/utils/sanitize.d.ts +16 -0
  71. package/utils/sortValues.d.ts +13 -0
  72. package/utils/typeToConstructor.d.ts +2 -0
  73. package/utils/typesToMap.d.ts +2 -0
  74. package/utils/util.d.ts +3 -0
@@ -0,0 +1,69 @@
1
+ /// <reference types="bn.js" />
2
+ import type { BN } from '@polkadot/util';
3
+ import type { ArgsDef, Codec } from './codec';
4
+ import type { AnyTuple } from './helpers';
5
+ export interface ICompact<T extends INumber = INumber> extends Codec {
6
+ toBigInt(): bigint;
7
+ toBn(): BN;
8
+ toNumber(): number;
9
+ unwrap(): T;
10
+ }
11
+ export interface IEnum extends Codec {
12
+ readonly defIndexes: number[];
13
+ readonly defKeys: string[];
14
+ readonly index: number;
15
+ readonly isBasic: boolean;
16
+ readonly type: string;
17
+ readonly value: Codec;
18
+ toNumber(): number;
19
+ }
20
+ export interface IMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V>, Codec {
21
+ }
22
+ export interface INumber extends Codec {
23
+ bitLength(): number;
24
+ toBigInt(): bigint;
25
+ toBn(): BN;
26
+ toNumber(): number;
27
+ }
28
+ export interface IOption<T extends Codec = Codec> extends Codec {
29
+ readonly isNone: boolean;
30
+ readonly isSome: boolean;
31
+ readonly value: Codec;
32
+ unwrap(): T;
33
+ unwrapOr<O>(other: O): T | O;
34
+ unwrapOrDefault(): T;
35
+ }
36
+ export interface IResult<O extends Codec = Codec, E extends Codec = Codec> extends IEnum {
37
+ readonly asErr: E;
38
+ readonly asOk: O;
39
+ readonly isErr: boolean;
40
+ readonly isOk: boolean;
41
+ }
42
+ export interface ISet<K = string> extends Set<K>, Codec {
43
+ readonly strings: string[];
44
+ }
45
+ export interface IStruct<K = string, V extends Codec = Codec> extends Map<K, V>, Codec {
46
+ readonly defKeys: string[];
47
+ getAtIndex(index: number): Codec;
48
+ toArray(): Codec[];
49
+ }
50
+ export declare type ITuple<T extends AnyTuple = Codec[]> = T & Codec;
51
+ export interface IU8a extends Uint8Array, Codec {
52
+ readonly isAscii: boolean;
53
+ readonly isUtf8: boolean;
54
+ bitLength(): number;
55
+ toHuman(isExtended?: boolean): any;
56
+ toJSON(): any;
57
+ toUtf8(): string;
58
+ }
59
+ export interface IVec<T extends Codec = Codec> extends Array<T>, Codec {
60
+ toArray(): T[];
61
+ }
62
+ export interface IMethod<A extends AnyTuple = AnyTuple, M = any> extends Codec {
63
+ readonly args: A;
64
+ readonly argsDef: ArgsDef;
65
+ readonly callIndex: Uint8Array;
66
+ readonly data: Uint8Array;
67
+ readonly meta: M;
68
+ is: (tx: IMethod<AnyTuple>) => tx is IMethod<A>;
69
+ }
@@ -0,0 +1,61 @@
1
+ /// <reference types="bn.js" />
2
+ import type { BN } from '@polkadot/util';
3
+ import type { Codec, CodecClass } from './codec';
4
+ import type { AnyTuple } from './helpers';
5
+ import type { ICompact, IEnum, IMap, IMethod, INumber, IOption, IResult, ISet, IStruct, ITuple, IU8a, IVec } from './interfaces';
6
+ export declare type OnlyCodec<K, T, Types> = K extends keyof Types ? Types[K] : T extends ICompact | IEnum | IMap | IMethod | INumber | IOption | IResult | ISet | IStruct | ITuple | IU8a | IVec ? T : T extends Codec ? T : never;
7
+ export interface RegistryError {
8
+ args: string[];
9
+ docs: string[];
10
+ index: number;
11
+ method: string;
12
+ name: string;
13
+ section: string;
14
+ }
15
+ export declare type RegistryTypes = Record<string, CodecClass | string | Record<string, string> | {
16
+ _enum: string[] | Record<string, number> | Record<string, string | null>;
17
+ } | {
18
+ _set: Record<string, number>;
19
+ }>;
20
+ export interface CodecCreateOptions {
21
+ blockHash?: Uint8Array | string | null;
22
+ isOptional?: boolean;
23
+ isPedantic?: boolean;
24
+ }
25
+ export interface CallBase<A extends AnyTuple, M = any> extends IMethod<A, M> {
26
+ readonly method: string;
27
+ readonly section: string;
28
+ toJSON: () => any;
29
+ }
30
+ export interface CallFunction<A extends AnyTuple = AnyTuple, M = any> extends CallBase<A, M> {
31
+ (...args: any[]): IMethod<A, M>;
32
+ }
33
+ export interface CodecRegistry {
34
+ readonly chainDecimals: number[];
35
+ readonly chainSS58: number | undefined;
36
+ readonly chainTokens: string[];
37
+ createdAtHash?: IU8a;
38
+ findMetaCall(callIndex: Uint8Array): CallFunction;
39
+ findMetaError(errorIndex: Uint8Array | {
40
+ error: BN;
41
+ index: BN;
42
+ }): RegistryError;
43
+ findMetaEvent(eventIndex: Uint8Array): CodecClass<any>;
44
+ isLookupType(value: string): boolean;
45
+ createLookupType(lookupId: ICompact<INumber> | number): string;
46
+ createClassUnsafe<T extends Codec = Codec, K extends string = string>(type: K): CodecClass<T>;
47
+ createTypeUnsafe<T extends Codec = Codec, K extends string = string>(type: K, params: unknown[], options?: CodecCreateOptions): T;
48
+ getClassName(clazz: CodecClass): string | undefined;
49
+ getOrThrow<T extends Codec = Codec, K extends string = string>(name: K, msg?: string): CodecClass<T>;
50
+ getOrUnknown<T extends Codec = Codec, K extends string = string>(name: K): CodecClass<T>;
51
+ getSignedExtensionExtra(): Record<string, string>;
52
+ getSignedExtensionTypes(): Record<string, string>;
53
+ hasClass(name: string): boolean;
54
+ hasDef(name: string): boolean;
55
+ hasType(name: string): boolean;
56
+ hash(data: Uint8Array): IU8a;
57
+ register(type: CodecClass | RegistryTypes): void;
58
+ register(name: string, type: CodecClass): void;
59
+ register(arg1: string | CodecClass | RegistryTypes, arg2?: CodecClass): void;
60
+ setMetadata(metadata: unknown, signedExtensions?: string[], userExtensions?: unknown): void;
61
+ }
@@ -0,0 +1 @@
1
+ export declare function compareArray(a: unknown[], b?: unknown): boolean;
@@ -0,0 +1 @@
1
+ export declare function compareMap(a: Map<unknown, unknown>, b?: unknown): boolean;
@@ -0,0 +1 @@
1
+ export declare function compareSet(a: Set<unknown>, b?: unknown): boolean;
@@ -0,0 +1,13 @@
1
+ import type { Codec, CodecClass, CodecRegistry } from '../types';
2
+ /**
3
+ * Given an u8a, and an array of Type constructors, decode the u8a against the
4
+ * types, and return an array of decoded values.
5
+ *
6
+ * @param u8a - The u8a to decode.
7
+ * @param result - The result array (will be returned with values pushed)
8
+ * @param types - The array of CodecClass to decode the U8a against.
9
+ */
10
+ export declare function decodeU8a<T extends Codec = Codec, E = T>(registry: CodecRegistry, u8a: Uint8Array, types: CodecClass[] | {
11
+ [index: string]: CodecClass;
12
+ }, withZip?: boolean): [E[], number];
13
+ export declare function decodeU8aVec<T extends Codec = Codec>(registry: CodecRegistry, u8a: Uint8Array, start: number, Type: CodecClass<T>, count: number): [T[], number, number];
@@ -0,0 +1,9 @@
1
+ export { compareArray } from './compareArray';
2
+ export { compareMap } from './compareMap';
3
+ export { compareSet } from './compareSet';
4
+ export { decodeU8a, decodeU8aVec } from './decodeU8a';
5
+ export { mapToTypeMap } from './mapToTypeMap';
6
+ export { typeToConstructor } from './typeToConstructor';
7
+ export { sanitize } from './sanitize';
8
+ export { sortAsc, sortSet, sortMap } from './sortValues';
9
+ export { typesToMap } from './typesToMap';
@@ -0,0 +1,5 @@
1
+ import type { CodecClass, CodecRegistry } from '../types';
2
+ /**
3
+ * @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
4
+ */
5
+ export declare function mapToTypeMap(registry: CodecRegistry, input: Record<string, string | CodecClass>): Record<string, CodecClass>;
@@ -0,0 +1,16 @@
1
+ interface SanitizeOptions {
2
+ allowNamespaces?: boolean;
3
+ }
4
+ declare type Mapper = (value: string, options?: SanitizeOptions) => string;
5
+ export declare function findClosing(value: string, start: number): number;
6
+ export declare function alias(src: string, dest: string, withChecks?: boolean): Mapper;
7
+ export declare function cleanupCompact(): Mapper;
8
+ export declare function flattenSingleTuple(): Mapper;
9
+ export declare function removeExtensions(type: string, isSized: boolean): Mapper;
10
+ export declare function removeColons(): Mapper;
11
+ export declare function removeGenerics(): Mapper;
12
+ export declare function removePairOf(): Mapper;
13
+ export declare function removeTraits(): Mapper;
14
+ export declare function removeWrap(check: string): Mapper;
15
+ export declare function sanitize(value: String | string, options?: SanitizeOptions): string;
16
+ export {};
@@ -0,0 +1,13 @@
1
+ /// <reference types="bn.js" />
2
+ import type { BN } from '@polkadot/util';
3
+ import type { Codec } from '../types';
4
+ declare type SortArg = Codec | Codec[] | number[] | BN | bigint | number | Uint8Array;
5
+ /**
6
+ * Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
7
+ * (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
8
+ * (https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html)
9
+ */
10
+ export declare function sortAsc<V extends SortArg = Codec>(a: V, b: V): number;
11
+ export declare function sortSet<V extends Codec = Codec>(set: Set<V>): Set<V>;
12
+ export declare function sortMap<K extends Codec = Codec, V extends Codec = Codec>(map: Map<K, V>): Map<K, V>;
13
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Codec, CodecClass, CodecRegistry } from '../types';
2
+ export declare function typeToConstructor<T extends Codec = Codec>(registry: CodecRegistry, type: string | CodecClass<T>): CodecClass<T>;
@@ -0,0 +1,2 @@
1
+ import type { CodecClass, CodecRegistry } from '../types';
2
+ export declare function typesToMap(registry: CodecRegistry, Types: Record<string, CodecClass>): Record<string, string>;
@@ -0,0 +1,3 @@
1
+ export declare function hasEq(o: unknown): o is {
2
+ eq: (other: unknown) => boolean;
3
+ };