@polkadot/types-create 7.4.2-3 → 7.4.2-7
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.
- package/bundle.cjs +10 -10
- package/bundle.js +1 -1
- package/create/class.cjs +23 -23
- package/create/class.d.ts +4 -4
- package/create/class.js +1 -1
- package/create/type.d.ts +2 -2
- package/package.json +20 -5
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
- package/types/augmentRegistry.cjs +1 -0
- package/types/augmentRegistry.d.ts +10 -0
- package/types/augmentRegistry.js +1 -0
- package/types/index.cjs +33 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +5 -0
- package/types/lookup.cjs +1 -0
- package/types/lookup.d.ts +10 -0
- package/types/lookup.js +1 -0
- package/{types.cjs → types/types.cjs} +0 -0
- package/{types.d.ts → types/types.d.ts} +0 -16
- package/{types.js → types/types.js} +0 -0
- package/util/encodeTypes.cjs +34 -34
- package/util/encodeTypes.d.ts +3 -3
- package/util/encodeTypes.js +1 -1
- package/util/getTypeDef.cjs +11 -11
- package/util/getTypeDef.js +1 -1
package/bundle.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var _exportNames = {
|
|
|
10
10
|
Object.defineProperty(exports, "TypeDefInfo", {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function () {
|
|
13
|
-
return
|
|
13
|
+
return _index.TypeDefInfo;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "packageInfo", {
|
|
@@ -22,32 +22,32 @@ Object.defineProperty(exports, "packageInfo", {
|
|
|
22
22
|
|
|
23
23
|
var _packageInfo = require("./packageInfo.cjs");
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _index = require("./types/index.cjs");
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _index2 = require("./create/index.cjs");
|
|
28
28
|
|
|
29
|
-
Object.keys(
|
|
29
|
+
Object.keys(_index2).forEach(function (key) {
|
|
30
30
|
if (key === "default" || key === "__esModule") return;
|
|
31
31
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
-
if (key in exports && exports[key] ===
|
|
32
|
+
if (key in exports && exports[key] === _index2[key]) return;
|
|
33
33
|
Object.defineProperty(exports, key, {
|
|
34
34
|
enumerable: true,
|
|
35
35
|
get: function () {
|
|
36
|
-
return
|
|
36
|
+
return _index2[key];
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
var
|
|
41
|
+
var _index3 = require("./util/index.cjs");
|
|
42
42
|
|
|
43
|
-
Object.keys(
|
|
43
|
+
Object.keys(_index3).forEach(function (key) {
|
|
44
44
|
if (key === "default" || key === "__esModule") return;
|
|
45
45
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
46
|
-
if (key in exports && exports[key] ===
|
|
46
|
+
if (key in exports && exports[key] === _index3[key]) return;
|
|
47
47
|
Object.defineProperty(exports, key, {
|
|
48
48
|
enumerable: true,
|
|
49
49
|
get: function () {
|
|
50
|
-
return
|
|
50
|
+
return _index3[key];
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
});
|
package/bundle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
export { packageInfo } from "./packageInfo.js";
|
|
4
|
-
export { TypeDefInfo } from "./types.js";
|
|
4
|
+
export { TypeDefInfo } from "./types/index.js";
|
|
5
5
|
export * from "./create/index.js";
|
|
6
6
|
export * from "./util/index.js";
|
package/create/class.cjs
CHANGED
|
@@ -11,7 +11,7 @@ var _typesCodec = require("@polkadot/types-codec");
|
|
|
11
11
|
|
|
12
12
|
var _util = require("@polkadot/util");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _index = require("../types/index.cjs");
|
|
15
15
|
|
|
16
16
|
var _getTypeDef = require("../util/getTypeDef.cjs");
|
|
17
17
|
|
|
@@ -75,11 +75,11 @@ function createWithSub(Clazz, value) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const infoMapping = {
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
78
|
+
[_index.TypeDefInfo.BTreeMap]: (registry, value) => createHashMap(_typesCodec.BTreeMap, value),
|
|
79
|
+
[_index.TypeDefInfo.BTreeSet]: (registry, value) => createWithSub(_typesCodec.BTreeSet, value),
|
|
80
|
+
[_index.TypeDefInfo.Compact]: (registry, value) => createWithSub(_typesCodec.Compact, value),
|
|
81
|
+
[_index.TypeDefInfo.DoNotConstruct]: (registry, value) => _typesCodec.DoNotConstruct.with(value.displayName || value.type),
|
|
82
|
+
[_index.TypeDefInfo.Enum]: (registry, value) => {
|
|
83
83
|
const subs = getSubDefArray(value);
|
|
84
84
|
return _typesCodec.Enum.with(subs.every(_ref3 => {
|
|
85
85
|
let {
|
|
@@ -95,10 +95,10 @@ const infoMapping = {
|
|
|
95
95
|
return out;
|
|
96
96
|
}, {}) : getTypeClassMap(value));
|
|
97
97
|
},
|
|
98
|
-
[
|
|
99
|
-
[
|
|
98
|
+
[_index.TypeDefInfo.HashMap]: (registry, value) => createHashMap(_typesCodec.HashMap, value),
|
|
99
|
+
[_index.TypeDefInfo.Int]: (registry, value) => createInt(_typesCodec.Int, value),
|
|
100
100
|
// We have circular deps between Linkage & Struct
|
|
101
|
-
[
|
|
101
|
+
[_index.TypeDefInfo.Linkage]: (registry, value) => {
|
|
102
102
|
const type = `Option<${getSubType(value)}>`; // eslint-disable-next-line sort-keys
|
|
103
103
|
|
|
104
104
|
const Clazz = _typesCodec.Struct.with({
|
|
@@ -115,11 +115,11 @@ const infoMapping = {
|
|
|
115
115
|
return Clazz;
|
|
116
116
|
},
|
|
117
117
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
118
|
-
[
|
|
119
|
-
[
|
|
120
|
-
[
|
|
121
|
-
[
|
|
122
|
-
[
|
|
118
|
+
[_index.TypeDefInfo.Null]: (registry, _) => _typesCodec.Null,
|
|
119
|
+
[_index.TypeDefInfo.Option]: (registry, value) => createWithSub(_typesCodec.Option, value),
|
|
120
|
+
[_index.TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
|
|
121
|
+
[_index.TypeDefInfo.Range]: (registry, value) => (value.type.includes('RangeInclusive') ? _typesCodec.RangeInclusive : _typesCodec.Range).with(getSubType(value)),
|
|
122
|
+
[_index.TypeDefInfo.Result]: (registry, value) => {
|
|
123
123
|
const [Ok, Err] = getTypeClassArray(value); // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
124
124
|
|
|
125
125
|
return _typesCodec.Result.with({
|
|
@@ -127,7 +127,7 @@ const infoMapping = {
|
|
|
127
127
|
Ok
|
|
128
128
|
});
|
|
129
129
|
},
|
|
130
|
-
[
|
|
130
|
+
[_index.TypeDefInfo.Set]: (registry, value) => _typesCodec.CodecSet.with(getSubDefArray(value).reduce((result, _ref5) => {
|
|
131
131
|
let {
|
|
132
132
|
index,
|
|
133
133
|
name
|
|
@@ -135,18 +135,18 @@ const infoMapping = {
|
|
|
135
135
|
result[name] = index;
|
|
136
136
|
return result;
|
|
137
137
|
}, {}), value.length),
|
|
138
|
-
[
|
|
139
|
-
[
|
|
140
|
-
[
|
|
141
|
-
[
|
|
142
|
-
[
|
|
138
|
+
[_index.TypeDefInfo.Si]: (registry, value) => getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
|
|
139
|
+
[_index.TypeDefInfo.Struct]: (registry, value) => _typesCodec.Struct.with(getTypeClassMap(value), value.alias),
|
|
140
|
+
[_index.TypeDefInfo.Tuple]: (registry, value) => _typesCodec.Tuple.with(getTypeClassArray(value)),
|
|
141
|
+
[_index.TypeDefInfo.UInt]: (registry, value) => createInt(_typesCodec.UInt, value),
|
|
142
|
+
[_index.TypeDefInfo.Vec]: (registry, _ref6) => {
|
|
143
143
|
let {
|
|
144
144
|
sub
|
|
145
145
|
} = _ref6;
|
|
146
146
|
(0, _util.assert)(sub && !Array.isArray(sub), 'Expected type information for vector');
|
|
147
147
|
return sub.type === 'u8' ? _typesCodec.Bytes : _typesCodec.Vec.with(getTypeDefType(sub));
|
|
148
148
|
},
|
|
149
|
-
[
|
|
149
|
+
[_index.TypeDefInfo.VecFixed]: (registry, _ref7) => {
|
|
150
150
|
let {
|
|
151
151
|
displayName,
|
|
152
152
|
length,
|
|
@@ -155,8 +155,8 @@ const infoMapping = {
|
|
|
155
155
|
(0, _util.assert)(sub && (0, _util.isNumber)(length) && !Array.isArray(sub), 'Expected length & type information for fixed vector');
|
|
156
156
|
return sub.type === 'u8' ? _typesCodec.U8aFixed.with(length * 8, displayName) : _typesCodec.VecFixed.with(getTypeDefType(sub), length);
|
|
157
157
|
},
|
|
158
|
-
[
|
|
159
|
-
[
|
|
158
|
+
[_index.TypeDefInfo.WrapperKeepOpaque]: (registry, value) => createWithSub(_typesCodec.WrapperKeepOpaque, value),
|
|
159
|
+
[_index.TypeDefInfo.WrapperOpaque]: (registry, value) => createWithSub(_typesCodec.WrapperOpaque, value)
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
function constructTypeClass(registry, typeDef) {
|
package/create/class.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Codec, CodecClass,
|
|
1
|
+
import type { Codec, CodecClass, Registry } from '@polkadot/types-codec/types';
|
|
2
2
|
import type { TypeDef } from '../types';
|
|
3
|
-
export declare function constructTypeClass<T extends Codec = Codec>(registry:
|
|
4
|
-
export declare function getTypeClass<T extends Codec = Codec>(registry:
|
|
5
|
-
export declare function createClassUnsafe<T extends Codec = Codec, K extends string = string>(registry:
|
|
3
|
+
export declare function constructTypeClass<T extends Codec = Codec>(registry: Registry, typeDef: TypeDef): CodecClass<T>;
|
|
4
|
+
export declare function getTypeClass<T extends Codec = Codec>(registry: Registry, typeDef: TypeDef): CodecClass<T>;
|
|
5
|
+
export declare function createClassUnsafe<T extends Codec = Codec, K extends string = string>(registry: Registry, type: K): CodecClass<T>;
|
package/create/class.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperKeepOpaque, WrapperOpaque } from '@polkadot/types-codec';
|
|
4
4
|
import { assert, isNumber, stringify } from '@polkadot/util';
|
|
5
|
-
import { TypeDefInfo } from "../types.js";
|
|
5
|
+
import { TypeDefInfo } from "../types/index.js";
|
|
6
6
|
import { getTypeDef } from "../util/getTypeDef.js";
|
|
7
7
|
|
|
8
8
|
function getTypeDefType({
|
package/create/type.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Codec,
|
|
1
|
+
import type { Codec, Registry } from '@polkadot/types-codec/types';
|
|
2
2
|
import type { CreateOptions } from '../types';
|
|
3
|
-
export declare function createTypeUnsafe<T extends Codec = Codec, K extends string = string>(registry:
|
|
3
|
+
export declare function createTypeUnsafe<T extends Codec = Codec, K extends string = string>(registry: Registry, type: K, params?: unknown[], options?: CreateOptions): T;
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./detectPackage.cjs"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "7.4.2-
|
|
23
|
+
"version": "7.4.2-7",
|
|
24
24
|
"main": "index.cjs",
|
|
25
25
|
"module": "index.js",
|
|
26
26
|
"types": "index.d.ts",
|
|
@@ -69,9 +69,24 @@
|
|
|
69
69
|
"default": "./packageInfo.js"
|
|
70
70
|
},
|
|
71
71
|
"./types": {
|
|
72
|
-
"types": "./types.d.ts",
|
|
73
|
-
"require": "./types.cjs",
|
|
74
|
-
"default": "./types.js"
|
|
72
|
+
"types": "./types/index.d.ts",
|
|
73
|
+
"require": "./types/index.cjs",
|
|
74
|
+
"default": "./types/index.js"
|
|
75
|
+
},
|
|
76
|
+
"./types/augmentRegistry": {
|
|
77
|
+
"types": "./types/augmentRegistry.d.ts",
|
|
78
|
+
"require": "./types/augmentRegistry.cjs",
|
|
79
|
+
"default": "./types/augmentRegistry.js"
|
|
80
|
+
},
|
|
81
|
+
"./types/lookup": {
|
|
82
|
+
"types": "./types/lookup.d.ts",
|
|
83
|
+
"require": "./types/lookup.cjs",
|
|
84
|
+
"default": "./types/lookup.js"
|
|
85
|
+
},
|
|
86
|
+
"./types/types": {
|
|
87
|
+
"types": "./types/types.d.ts",
|
|
88
|
+
"require": "./types/types.cjs",
|
|
89
|
+
"default": "./types/types.js"
|
|
75
90
|
},
|
|
76
91
|
"./util": {
|
|
77
92
|
"types": "./util/index.d.ts",
|
|
@@ -101,7 +116,7 @@
|
|
|
101
116
|
},
|
|
102
117
|
"dependencies": {
|
|
103
118
|
"@babel/runtime": "^7.16.7",
|
|
104
|
-
"@polkadot/types-codec": "7.4.2-
|
|
119
|
+
"@polkadot/types-codec": "7.4.2-7",
|
|
105
120
|
"@polkadot/util": "^8.3.2"
|
|
106
121
|
}
|
|
107
122
|
}
|
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Codec, CodecClass, ICompact, INumber } from '@polkadot/types-codec/types';
|
|
2
|
+
import type { ILookup, TypeDef } from '@polkadot/types-create/types';
|
|
3
|
+
declare module '@polkadot/types-codec/types/registry' {
|
|
4
|
+
interface Registry {
|
|
5
|
+
readonly lookup: ILookup;
|
|
6
|
+
createLookupType(lookupId: ICompact<INumber> | number): string;
|
|
7
|
+
setLookup(lookup: ILookup): void;
|
|
8
|
+
getUnsafe<T extends Codec = Codec, K extends string = string>(name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<T> | undefined;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
require("./augmentRegistry.cjs");
|
|
8
|
+
|
|
9
|
+
var _lookup = require("./lookup.cjs");
|
|
10
|
+
|
|
11
|
+
Object.keys(_lookup).forEach(function (key) {
|
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
|
13
|
+
if (key in exports && exports[key] === _lookup[key]) return;
|
|
14
|
+
Object.defineProperty(exports, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _lookup[key];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
var _types = require("./types.cjs");
|
|
23
|
+
|
|
24
|
+
Object.keys(_types).forEach(function (key) {
|
|
25
|
+
if (key === "default" || key === "__esModule") return;
|
|
26
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
27
|
+
Object.defineProperty(exports, key, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _types[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
package/types/index.d.ts
ADDED
package/types/index.js
ADDED
package/types/lookup.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ICompact, INumber } from '@polkadot/types-codec/types';
|
|
2
|
+
import type { TypeDef } from './types';
|
|
3
|
+
export interface ILookup {
|
|
4
|
+
getSiType(lookupId: ICompact<INumber> | string | number): {
|
|
5
|
+
def: {
|
|
6
|
+
asTuple: ICompact<INumber>[];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
getTypeDef(lookupId: ICompact<INumber> | string | number): TypeDef;
|
|
10
|
+
}
|
package/types/lookup.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Codec, CodecClass, CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types';
|
|
2
|
-
export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types';
|
|
3
1
|
export declare enum TypeDefInfo {
|
|
4
2
|
BTreeMap = 0,
|
|
5
3
|
BTreeSet = 1,
|
|
@@ -42,17 +40,3 @@ export interface TypeDef {
|
|
|
42
40
|
type: string;
|
|
43
41
|
typeName?: string;
|
|
44
42
|
}
|
|
45
|
-
export interface ILookup {
|
|
46
|
-
getSiType(lookupId: ICompact<INumber> | string | number): {
|
|
47
|
-
def: {
|
|
48
|
-
asTuple: ICompact<INumber>[];
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
getTypeDef(lookupId: ICompact<INumber> | string | number): TypeDef;
|
|
52
|
-
}
|
|
53
|
-
export interface CreateRegistry extends CodecRegistry {
|
|
54
|
-
lookup: ILookup;
|
|
55
|
-
createLookupType(lookupId: ICompact<INumber> | number): string;
|
|
56
|
-
setLookup(lookup: ILookup): void;
|
|
57
|
-
getUnsafe<T extends Codec = Codec, K extends string = string>(name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<T> | undefined;
|
|
58
|
-
}
|
|
File without changes
|
package/util/encodeTypes.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.withTypeString = withTypeString;
|
|
|
9
9
|
|
|
10
10
|
var _util = require("@polkadot/util");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _index = require("../types/index.cjs");
|
|
13
13
|
|
|
14
14
|
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
|
15
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -29,17 +29,17 @@ function encodeWithParams(registry, typeDef, outer) {
|
|
|
29
29
|
} = typeDef;
|
|
30
30
|
|
|
31
31
|
switch (info) {
|
|
32
|
-
case
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
36
|
-
case
|
|
37
|
-
case
|
|
38
|
-
case
|
|
39
|
-
case
|
|
40
|
-
case
|
|
41
|
-
case
|
|
42
|
-
case
|
|
32
|
+
case _index.TypeDefInfo.BTreeMap:
|
|
33
|
+
case _index.TypeDefInfo.BTreeSet:
|
|
34
|
+
case _index.TypeDefInfo.Compact:
|
|
35
|
+
case _index.TypeDefInfo.HashMap:
|
|
36
|
+
case _index.TypeDefInfo.Linkage:
|
|
37
|
+
case _index.TypeDefInfo.Option:
|
|
38
|
+
case _index.TypeDefInfo.Range:
|
|
39
|
+
case _index.TypeDefInfo.Result:
|
|
40
|
+
case _index.TypeDefInfo.Vec:
|
|
41
|
+
case _index.TypeDefInfo.WrapperKeepOpaque:
|
|
42
|
+
case _index.TypeDefInfo.WrapperOpaque:
|
|
43
43
|
return paramsNotation(outer, sub, p => encodeTypeDef(registry, p));
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -69,10 +69,10 @@ function encodeSubTypes(registry, sub, asEnum, extra) {
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
const encoders = {
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
72
|
+
[_index.TypeDefInfo.BTreeMap]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'BTreeMap'),
|
|
73
|
+
[_index.TypeDefInfo.BTreeSet]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'BTreeSet'),
|
|
74
|
+
[_index.TypeDefInfo.Compact]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Compact'),
|
|
75
|
+
[_index.TypeDefInfo.DoNotConstruct]: (registry, _ref2) => {
|
|
76
76
|
let {
|
|
77
77
|
displayName,
|
|
78
78
|
lookupIndex,
|
|
@@ -80,7 +80,7 @@ const encoders = {
|
|
|
80
80
|
} = _ref2;
|
|
81
81
|
return `DoNotConstruct<${lookupName || displayName || ((0, _util.isUndefined)(lookupIndex) ? 'Unknown' : registry.createLookupType(lookupIndex))}>`;
|
|
82
82
|
},
|
|
83
|
-
[
|
|
83
|
+
[_index.TypeDefInfo.Enum]: (registry, _ref3) => {
|
|
84
84
|
let {
|
|
85
85
|
sub
|
|
86
86
|
} = _ref3;
|
|
@@ -101,29 +101,29 @@ const encoders = {
|
|
|
101
101
|
})
|
|
102
102
|
}) : encodeSubTypes(registry, sub, true);
|
|
103
103
|
},
|
|
104
|
-
[
|
|
105
|
-
[
|
|
104
|
+
[_index.TypeDefInfo.HashMap]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'HashMap'),
|
|
105
|
+
[_index.TypeDefInfo.Int]: (registry, _ref6) => {
|
|
106
106
|
let {
|
|
107
107
|
length = 32
|
|
108
108
|
} = _ref6;
|
|
109
109
|
return `Int<${length}>`;
|
|
110
110
|
},
|
|
111
|
-
[
|
|
111
|
+
[_index.TypeDefInfo.Linkage]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Linkage'),
|
|
112
112
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
113
|
-
[
|
|
114
|
-
[
|
|
113
|
+
[_index.TypeDefInfo.Null]: (registry, typeDef) => 'Null',
|
|
114
|
+
[_index.TypeDefInfo.Option]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Option'),
|
|
115
115
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
116
|
-
[
|
|
116
|
+
[_index.TypeDefInfo.Plain]: (registry, _ref7) => {
|
|
117
117
|
let {
|
|
118
118
|
displayName,
|
|
119
119
|
type
|
|
120
120
|
} = _ref7;
|
|
121
121
|
return displayName || type;
|
|
122
122
|
},
|
|
123
|
-
[
|
|
124
|
-
[
|
|
123
|
+
[_index.TypeDefInfo.Range]: (registry, typeDef) => encodeWithParams(registry, typeDef, typeDef.type.includes('RangeInclusive') ? 'RangeInclusive' : 'Range'),
|
|
124
|
+
[_index.TypeDefInfo.Result]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Result'),
|
|
125
125
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
126
|
-
[
|
|
126
|
+
[_index.TypeDefInfo.Set]: (registry, _ref8) => {
|
|
127
127
|
let {
|
|
128
128
|
length = 8,
|
|
129
129
|
sub
|
|
@@ -144,14 +144,14 @@ const encoders = {
|
|
|
144
144
|
});
|
|
145
145
|
},
|
|
146
146
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
147
|
-
[
|
|
147
|
+
[_index.TypeDefInfo.Si]: (registry, _ref10) => {
|
|
148
148
|
let {
|
|
149
149
|
lookupName,
|
|
150
150
|
type
|
|
151
151
|
} = _ref10;
|
|
152
152
|
return lookupName || type;
|
|
153
153
|
},
|
|
154
|
-
[
|
|
154
|
+
[_index.TypeDefInfo.Struct]: (registry, _ref11) => {
|
|
155
155
|
let {
|
|
156
156
|
alias,
|
|
157
157
|
sub
|
|
@@ -166,21 +166,21 @@ const encoders = {
|
|
|
166
166
|
}, {})
|
|
167
167
|
} : {});
|
|
168
168
|
},
|
|
169
|
-
[
|
|
169
|
+
[_index.TypeDefInfo.Tuple]: (registry, _ref13) => {
|
|
170
170
|
let {
|
|
171
171
|
sub
|
|
172
172
|
} = _ref13;
|
|
173
173
|
(0, _util.assert)(sub && Array.isArray(sub), 'Unable to encode Tuple type');
|
|
174
174
|
return `(${sub.map(type => encodeTypeDef(registry, type)).join(',')})`;
|
|
175
175
|
},
|
|
176
|
-
[
|
|
176
|
+
[_index.TypeDefInfo.UInt]: (registry, _ref14) => {
|
|
177
177
|
let {
|
|
178
178
|
length = 32
|
|
179
179
|
} = _ref14;
|
|
180
180
|
return `UInt<${length}>`;
|
|
181
181
|
},
|
|
182
|
-
[
|
|
183
|
-
[
|
|
182
|
+
[_index.TypeDefInfo.Vec]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Vec'),
|
|
183
|
+
[_index.TypeDefInfo.VecFixed]: (registry, _ref15) => {
|
|
184
184
|
let {
|
|
185
185
|
length,
|
|
186
186
|
sub
|
|
@@ -188,8 +188,8 @@ const encoders = {
|
|
|
188
188
|
(0, _util.assert)((0, _util.isNumber)(length) && !(0, _util.isUndefined)(sub) && !Array.isArray(sub), 'Unable to encode VecFixed type');
|
|
189
189
|
return `[${sub.type};${length}]`;
|
|
190
190
|
},
|
|
191
|
-
[
|
|
192
|
-
[
|
|
191
|
+
[_index.TypeDefInfo.WrapperKeepOpaque]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'WrapperKeepOpaque'),
|
|
192
|
+
[_index.TypeDefInfo.WrapperOpaque]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'WrapperOpaque')
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
function encodeType(registry, typeDef) {
|
package/util/encodeTypes.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Registry } from '@polkadot/types-codec/types';
|
|
2
2
|
import type { TypeDef } from '@polkadot/types-create/types';
|
|
3
3
|
export declare function paramsNotation<T>(outer: string, inner?: T | T[], transform?: (_: T) => string): string;
|
|
4
|
-
export declare function encodeTypeDef(registry:
|
|
5
|
-
export declare function withTypeString(registry:
|
|
4
|
+
export declare function encodeTypeDef(registry: Registry, typeDef: TypeDef): string;
|
|
5
|
+
export declare function withTypeString(registry: Registry, typeDef: Omit<TypeDef, 'type'> & {
|
|
6
6
|
type?: string;
|
|
7
7
|
}): TypeDef;
|
package/util/encodeTypes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { assert, isNumber, isUndefined, objectSpread, stringify } from '@polkadot/util';
|
|
4
|
-
import { TypeDefInfo } from "../types.js";
|
|
4
|
+
import { TypeDefInfo } from "../types/index.js";
|
|
5
5
|
|
|
6
6
|
const stringIdentity = value => value.toString();
|
|
7
7
|
|
package/util/getTypeDef.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var _typesCodec = require("@polkadot/types-codec");
|
|
|
9
9
|
|
|
10
10
|
var _util = require("@polkadot/util");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _index = require("../types/index.cjs");
|
|
13
13
|
|
|
14
14
|
var _typeSplit = require("./typeSplit.cjs");
|
|
15
15
|
|
|
@@ -38,12 +38,12 @@ function isRustEnum(details) {
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
function _decodeEnum(value, details, count) {
|
|
41
|
-
value.info =
|
|
41
|
+
value.info = _index.TypeDefInfo.Enum; // not as pretty, but remain compatible with oo7 for both struct and Array types
|
|
42
42
|
|
|
43
43
|
if (Array.isArray(details)) {
|
|
44
44
|
value.sub = details.map((name, index) => ({
|
|
45
45
|
index,
|
|
46
|
-
info:
|
|
46
|
+
info: _index.TypeDefInfo.Plain,
|
|
47
47
|
name,
|
|
48
48
|
type: 'Null'
|
|
49
49
|
}));
|
|
@@ -61,7 +61,7 @@ function _decodeEnum(value, details, count) {
|
|
|
61
61
|
let [name, index] = _ref2;
|
|
62
62
|
return {
|
|
63
63
|
index,
|
|
64
|
-
info:
|
|
64
|
+
info: _index.TypeDefInfo.Plain,
|
|
65
65
|
name,
|
|
66
66
|
type: 'Null'
|
|
67
67
|
};
|
|
@@ -74,7 +74,7 @@ function _decodeEnum(value, details, count) {
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
function _decodeSet(value, details) {
|
|
77
|
-
value.info =
|
|
77
|
+
value.info = _index.TypeDefInfo.Set;
|
|
78
78
|
value.length = details._bitLength;
|
|
79
79
|
value.sub = Object.entries(details).filter(_ref3 => {
|
|
80
80
|
let [name] = _ref3;
|
|
@@ -83,7 +83,7 @@ function _decodeSet(value, details) {
|
|
|
83
83
|
let [name, index] = _ref4;
|
|
84
84
|
return {
|
|
85
85
|
index,
|
|
86
|
-
info:
|
|
86
|
+
info: _index.TypeDefInfo.Plain,
|
|
87
87
|
name,
|
|
88
88
|
type: 'Null'
|
|
89
89
|
};
|
|
@@ -184,10 +184,10 @@ function hasWrapper(type, _ref5) {
|
|
|
184
184
|
return type.substr(0, start.length) === start && type.substr(-1 * end.length) === end;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
const nestedExtraction = [['[', ']',
|
|
188
|
-
['BTreeMap<', '>',
|
|
189
|
-
['Range<', '>',
|
|
190
|
-
const wrappedExtraction = [['BTreeSet<', '>',
|
|
187
|
+
const nestedExtraction = [['[', ']', _index.TypeDefInfo.VecFixed, _decodeFixedVec], ['{', '}', _index.TypeDefInfo.Struct, _decodeStruct], ['(', ')', _index.TypeDefInfo.Tuple, _decodeTuple], // the inner for these are the same as tuple, multiple values
|
|
188
|
+
['BTreeMap<', '>', _index.TypeDefInfo.BTreeMap, _decodeTuple], ['HashMap<', '>', _index.TypeDefInfo.HashMap, _decodeTuple], ['Int<', '>', _index.TypeDefInfo.Int, _decodeInt], // Not sure about these, have a specific implementation?
|
|
189
|
+
['Range<', '>', _index.TypeDefInfo.Tuple, _decodeRange], ['RangeInclusive<', '>', _index.TypeDefInfo.Tuple, _decodeRange], ['Result<', '>', _index.TypeDefInfo.Result, _decodeTuple], ['UInt<', '>', _index.TypeDefInfo.UInt, _decodeUInt], ['DoNotConstruct<', '>', _index.TypeDefInfo.DoNotConstruct, _decodeDoNotConstruct]];
|
|
190
|
+
const wrappedExtraction = [['BTreeSet<', '>', _index.TypeDefInfo.BTreeSet], ['Compact<', '>', _index.TypeDefInfo.Compact], ['Linkage<', '>', _index.TypeDefInfo.Linkage], ['Option<', '>', _index.TypeDefInfo.Option], ['Vec<', '>', _index.TypeDefInfo.Vec], ['WrapperKeepOpaque<', '>', _index.TypeDefInfo.WrapperKeepOpaque], ['WrapperOpaque<', '>', _index.TypeDefInfo.WrapperOpaque]];
|
|
191
191
|
|
|
192
192
|
function extractSubType(type, _ref6) {
|
|
193
193
|
let [start, end] = _ref6;
|
|
@@ -205,7 +205,7 @@ function getTypeDef(_type) {
|
|
|
205
205
|
const type = (0, _typesCodec.sanitize)(_type);
|
|
206
206
|
const value = {
|
|
207
207
|
displayName,
|
|
208
|
-
info:
|
|
208
|
+
info: _index.TypeDefInfo.Plain,
|
|
209
209
|
name,
|
|
210
210
|
type
|
|
211
211
|
};
|
package/util/getTypeDef.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { sanitize } from '@polkadot/types-codec';
|
|
4
4
|
import { assert, isNumber, isString, objectSpread } from '@polkadot/util';
|
|
5
|
-
import { TypeDefInfo } from "../types.js";
|
|
5
|
+
import { TypeDefInfo } from "../types/index.js";
|
|
6
6
|
import { typeSplit } from "./typeSplit.js";
|
|
7
7
|
const MAX_NESTED = 64;
|
|
8
8
|
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|