@polkadot/types-codec 9.11.3 → 9.13.1

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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/abstract/Array.d.ts +2 -0
  3. package/abstract/Base.d.ts +14 -3
  4. package/abstract/Base.js +16 -4
  5. package/abstract/Int.d.ts +3 -1
  6. package/abstract/Int.js +13 -9
  7. package/abstract/Object.d.ts +67 -0
  8. package/abstract/Object.js +51 -0
  9. package/base/Compact.d.ts +2 -1
  10. package/base/DoNotConstruct.d.ts +1 -0
  11. package/base/Enum.d.ts +2 -1
  12. package/base/Null.d.ts +2 -1
  13. package/base/Null.js +0 -1
  14. package/base/Option.d.ts +1 -0
  15. package/base/Option.js +1 -1
  16. package/base/Tuple.d.ts +0 -1
  17. package/base/Tuple.js +18 -10
  18. package/base/Vec.d.ts +1 -2
  19. package/base/Vec.js +21 -8
  20. package/base/VecFixed.d.ts +0 -1
  21. package/cjs/abstract/Base.js +16 -4
  22. package/cjs/abstract/Int.js +12 -8
  23. package/cjs/abstract/Object.js +58 -0
  24. package/cjs/base/Null.js +0 -1
  25. package/cjs/base/Option.js +1 -1
  26. package/cjs/base/Tuple.js +18 -10
  27. package/cjs/base/Vec.js +20 -7
  28. package/cjs/native/Bool.js +1 -0
  29. package/cjs/native/Date.js +1 -0
  30. package/cjs/native/Struct.js +6 -14
  31. package/cjs/packageInfo.js +1 -1
  32. package/extended/BTreeSet.d.ts +2 -1
  33. package/extended/Map.d.ts +2 -1
  34. package/native/Bool.d.ts +2 -0
  35. package/native/Bool.js +1 -0
  36. package/native/Date.d.ts +2 -0
  37. package/native/Date.js +1 -0
  38. package/native/Float.d.ts +3 -2
  39. package/native/Json.d.ts +2 -0
  40. package/native/Raw.d.ts +3 -2
  41. package/native/Set.d.ts +2 -0
  42. package/native/Struct.d.ts +3 -2
  43. package/native/Struct.js +7 -15
  44. package/native/Text.d.ts +3 -2
  45. package/package.json +9 -9
  46. package/packageInfo.js +1 -1
  47. package/types/codec.d.ts +32 -12
  48. package/types/helpers.d.ts +9 -1
  49. package/types/registry.d.ts +4 -3
  50. package/abstract/BigInt.d.ts +0 -4
  51. package/abstract/BigInt.js +0 -14
  52. package/cjs/abstract/BigInt.js +0 -20
package/types/codec.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyJson } from './helpers';
2
+ import type { AnyJson, ToString } from './helpers';
3
3
  import type { IU8a } from './interfaces';
4
4
  import type { Registry } from './registry';
5
5
  export type BareOpts = boolean | Record<string, boolean>;
@@ -11,11 +11,35 @@ export interface Inspect {
11
11
  /**
12
12
  * @name Codec
13
13
  * @description
14
- * The base Codec interface. All types implement the interface provided here. Additionally
15
- * implementors can add their own specific interfaces and helpers with getters and functions.
16
- * The Codec Base is however required for operating as an encoding/decoding layer
14
+ * The base Codec interface. All types implement the interface provided here.
15
+ * Additionally implementors can add their own specific interfaces and helpers
16
+ * with getters and functions. The Codec Base is however required for operating
17
+ * as an encoding/decoding layer
17
18
  */
18
19
  export interface Codec {
20
+ /**
21
+ * @description
22
+ * The block at which this value was retrieved/created (set to non-empty when
23
+ * retrieved from storage)
24
+ */
25
+ createdAtHash?: IU8a;
26
+ /**
27
+ * @description
28
+ * The length of the initial encoded value (Only available when the value was
29
+ * constructed from a Uint8Array input)
30
+ */
31
+ initialU8aLength?: number;
32
+ /**
33
+ * @description
34
+ * (internal usage) Indicates that the value was created via a fallback. This
35
+ * is used when with data specified in the metadata when the storage entry is
36
+ * empty.
37
+ *
38
+ * With metadata fallback values (available as defaults on most storage entries)
39
+ * any empty storage item should erturn the default. (This is the same as the
40
+ * implementation on the Substrate runtime)
41
+ */
42
+ isStorageFallback?: boolean;
19
43
  /**
20
44
  * @description The length of the value when encoded as a Uint8Array
21
45
  */
@@ -24,10 +48,6 @@ export interface Codec {
24
48
  * @description Returns a hash of the value
25
49
  */
26
50
  readonly hash: IU8a;
27
- /**
28
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
29
- */
30
- readonly initialU8aLength?: number;
31
51
  /**
32
52
  * @description Checks if the value is an empty value
33
53
  */
@@ -36,10 +56,6 @@ export interface Codec {
36
56
  * @description The registry associated with this object
37
57
  */
38
58
  readonly registry: Registry;
39
- /**
40
- * @description The block at which this value was retrieved/created (set to non-empty when retrieved from storage)
41
- */
42
- createdAtHash?: IU8a;
43
59
  /**
44
60
  * @description Compares the value of the input to see if there is a match
45
61
  */
@@ -85,5 +101,9 @@ export interface CodecClass<T = Codec> {
85
101
  readonly __fallbackType?: string;
86
102
  new (registry: Registry, ...args: any[]): T;
87
103
  }
104
+ export interface CodecObject<T extends ToString> extends Codec {
105
+ readonly $: T;
106
+ valueOf(): T;
107
+ }
88
108
  export type CodecTo = 'toHex' | 'toJSON' | 'toPrimitive' | 'toString' | 'toU8a';
89
109
  export type ArgsDef = Record<string, CodecClass | string>;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import type { BN } from '@polkadot/util';
3
+ import type { HexString } from '@polkadot/util/types';
3
4
  import type { Codec } from './codec';
4
5
  export type AnyJson = string | number | boolean | null | undefined | AnyJson[] | {
5
6
  [index: string]: AnyJson;
@@ -13,4 +14,11 @@ export type AnyTuple = Codec[];
13
14
  export type AnyU8a = Uint8Array | number[] | string;
14
15
  export type UIntBitLength = 8 | 16 | 32 | 64 | 128 | 256;
15
16
  export type U8aBitLength = 8 | 16 | 32 | 64 | 128 | 160 | 256 | 264 | 512 | 520 | 1024 | 2048;
16
- export type AnyTupleValue = AnyU8a | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
17
+ export type AnyTupleValue = Exclude<AnyU8a, string> | HexString | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
18
+ export interface ToString {
19
+ toString: () => string;
20
+ }
21
+ export interface ToBn {
22
+ toBn: () => BN;
23
+ }
24
+ export type LookupString = `Lookup${number}`;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="bn.js" />
2
2
  import type { BN } from '@polkadot/util';
3
3
  import type { Codec, CodecClass } from './codec';
4
- import type { AnyTuple } from './helpers';
4
+ import type { AnyTuple, LookupString } from './helpers';
5
5
  import type { ICompact, IEnum, IMap, IMethod, INumber, IOption, IResult, ISet, IStruct, ITuple, IU8a, IVec } from './interfaces';
6
6
  export 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
7
  export interface RegistryError {
@@ -19,6 +19,7 @@ export type RegistryTypes = Record<string, CodecClass | string | Record<string,
19
19
  }>;
20
20
  export interface CodecCreateOptions {
21
21
  blockHash?: Uint8Array | string | null;
22
+ isFallback?: boolean;
22
23
  isOptional?: boolean;
23
24
  isPedantic?: boolean;
24
25
  }
@@ -44,8 +45,8 @@ export interface Registry {
44
45
  index: BN;
45
46
  }): RegistryError;
46
47
  findMetaEvent(eventIndex: Uint8Array): CodecClass<any>;
47
- isLookupType(value: string): boolean;
48
- createLookupType(lookupId: ICompact<INumber> | number): string;
48
+ isLookupType(value: string): value is LookupString;
49
+ createLookupType(lookupId: ICompact<INumber> | number): LookupString;
49
50
  createClassUnsafe<T extends Codec = Codec, K extends string = string>(type: K): CodecClass<T>;
50
51
  createTypeUnsafe<T extends Codec = Codec, K extends string = string>(type: K, params: unknown[], options?: CodecCreateOptions): T;
51
52
  getClassName(clazz: CodecClass): string | undefined;
@@ -1,4 +0,0 @@
1
- import { BigInt } from '@polkadot/x-bigint';
2
- export declare abstract class AbstractBigInt extends BigInt {
3
- constructor(value: string | number | bigint | boolean);
4
- }
@@ -1,14 +0,0 @@
1
- // Copyright 2017-2023 @polkadot/types-codec authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { BigInt } from '@polkadot/x-bigint';
5
-
6
- // @ts-expect-error not extensible, we make it extensible here
7
- export class AbstractBigInt extends BigInt {
8
- // @ts-expect-error super() not required, the self magic does that
9
- constructor(value) {
10
- const self = Object(BigInt(value));
11
- Object.setPrototypeOf(self, AbstractBigInt.prototype);
12
- return self;
13
- }
14
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AbstractBigInt = void 0;
7
- var _xBigint = require("@polkadot/x-bigint");
8
- // Copyright 2017-2023 @polkadot/types-codec authors & contributors
9
- // SPDX-License-Identifier: Apache-2.0
10
-
11
- // @ts-expect-error not extensible, we make it extensible here
12
- class AbstractBigInt extends _xBigint.BigInt {
13
- // @ts-expect-error super() not required, the self magic does that
14
- constructor(value) {
15
- const self = Object((0, _xBigint.BigInt)(value));
16
- Object.setPrototypeOf(self, AbstractBigInt.prototype);
17
- return self;
18
- }
19
- }
20
- exports.AbstractBigInt = AbstractBigInt;