@polkadot/types-create 10.0.1 → 10.1.2
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.d.ts +4 -4
- package/cjs/bundle.js +6 -6
- package/cjs/create/class.js +26 -26
- package/cjs/create/index.js +2 -2
- package/cjs/create/type.js +3 -3
- package/cjs/detectPackage.js +3 -3
- package/cjs/index.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/types/index.js +3 -3
- package/cjs/util/encodeTypes.js +36 -36
- package/cjs/util/getTypeDef.js +28 -28
- package/cjs/util/index.js +4 -4
- package/create/class.d.ts +1 -1
- package/create/index.d.ts +2 -2
- package/create/type.d.ts +1 -1
- package/index.d.ts +2 -2
- package/package.json +3 -3
- package/packageInfo.js +1 -1
- package/types/index.d.ts +3 -3
- package/types/lookup.d.ts +1 -1
- package/util/index.d.ts +4 -4
package/bundle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { packageInfo } from './packageInfo';
|
|
2
|
-
export { TypeDefInfo } from './types';
|
|
3
|
-
export * from './create';
|
|
4
|
-
export * from './util';
|
|
1
|
+
export { packageInfo } from './packageInfo.js';
|
|
2
|
+
export { TypeDefInfo } from './types/index.js';
|
|
3
|
+
export * from './create/index.js';
|
|
4
|
+
export * from './util/index.js';
|
package/cjs/bundle.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypeDefInfo = exports.packageInfo = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
var
|
|
6
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "TypeDefInfo", { enumerable: true, get: function () { return
|
|
9
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./util"), exports);
|
|
5
|
+
var packageInfo_js_1 = require("./packageInfo.js");
|
|
6
|
+
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
7
|
+
var index_js_1 = require("./types/index.js");
|
|
8
|
+
Object.defineProperty(exports, "TypeDefInfo", { enumerable: true, get: function () { return index_js_1.TypeDefInfo; } });
|
|
9
|
+
tslib_1.__exportStar(require("./create/index.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./util/index.js"), exports);
|
package/cjs/create/class.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createClassUnsafe = exports.getTypeClass = exports.constructTypeClass = void 0;
|
|
4
4
|
const types_codec_1 = require("@polkadot/types-codec");
|
|
5
5
|
const util_1 = require("@polkadot/util");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
7
|
+
const getTypeDef_js_1 = require("../util/getTypeDef.js");
|
|
8
8
|
function getTypeDefType({ lookupName, type }) {
|
|
9
9
|
return lookupName || type;
|
|
10
10
|
}
|
|
@@ -48,11 +48,11 @@ function createWithSub(Clazz, value) {
|
|
|
48
48
|
return Clazz.with(getSubType(value));
|
|
49
49
|
}
|
|
50
50
|
const infoMapping = {
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
51
|
+
[index_js_1.TypeDefInfo.BTreeMap]: (registry, value) => createHashMap(types_codec_1.BTreeMap, value),
|
|
52
|
+
[index_js_1.TypeDefInfo.BTreeSet]: (registry, value) => createWithSub(types_codec_1.BTreeSet, value),
|
|
53
|
+
[index_js_1.TypeDefInfo.Compact]: (registry, value) => createWithSub(types_codec_1.Compact, value),
|
|
54
|
+
[index_js_1.TypeDefInfo.DoNotConstruct]: (registry, value) => types_codec_1.DoNotConstruct.with(value.displayName || value.type),
|
|
55
|
+
[index_js_1.TypeDefInfo.Enum]: (registry, value) => {
|
|
56
56
|
const subs = getSubDefArray(value);
|
|
57
57
|
return types_codec_1.Enum.with(subs.every(({ type }) => type === 'Null')
|
|
58
58
|
? subs.reduce((out, { index, name }, count) => {
|
|
@@ -61,10 +61,10 @@ const infoMapping = {
|
|
|
61
61
|
}, {})
|
|
62
62
|
: getTypeClassMap(value));
|
|
63
63
|
},
|
|
64
|
-
[
|
|
65
|
-
[
|
|
64
|
+
[index_js_1.TypeDefInfo.HashMap]: (registry, value) => createHashMap(types_codec_1.HashMap, value),
|
|
65
|
+
[index_js_1.TypeDefInfo.Int]: (registry, value) => createInt(types_codec_1.Int, value),
|
|
66
66
|
// We have circular deps between Linkage & Struct
|
|
67
|
-
[
|
|
67
|
+
[index_js_1.TypeDefInfo.Linkage]: (registry, value) => {
|
|
68
68
|
const type = `Option<${getSubType(value)}>`;
|
|
69
69
|
// eslint-disable-next-line sort-keys
|
|
70
70
|
const Clazz = types_codec_1.Struct.with({ previous: type, next: type });
|
|
@@ -76,8 +76,8 @@ const infoMapping = {
|
|
|
76
76
|
return Clazz;
|
|
77
77
|
},
|
|
78
78
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
|
-
[
|
|
80
|
-
[
|
|
79
|
+
[index_js_1.TypeDefInfo.Null]: (registry, _) => types_codec_1.Null,
|
|
80
|
+
[index_js_1.TypeDefInfo.Option]: (registry, value) => {
|
|
81
81
|
if (!value.sub || Array.isArray(value.sub)) {
|
|
82
82
|
throw new Error('Expected type information for Option');
|
|
83
83
|
}
|
|
@@ -87,23 +87,23 @@ const infoMapping = {
|
|
|
87
87
|
// }
|
|
88
88
|
return createWithSub(types_codec_1.Option, value);
|
|
89
89
|
},
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
90
|
+
[index_js_1.TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
|
|
91
|
+
[index_js_1.TypeDefInfo.Range]: (registry, value) => createWithSub(types_codec_1.Range, value),
|
|
92
|
+
[index_js_1.TypeDefInfo.RangeInclusive]: (registry, value) => createWithSub(types_codec_1.RangeInclusive, value),
|
|
93
|
+
[index_js_1.TypeDefInfo.Result]: (registry, value) => {
|
|
94
94
|
const [Ok, Err] = getTypeClassArray(value);
|
|
95
95
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
96
96
|
return types_codec_1.Result.with({ Err, Ok });
|
|
97
97
|
},
|
|
98
|
-
[
|
|
98
|
+
[index_js_1.TypeDefInfo.Set]: (registry, value) => types_codec_1.CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
|
|
99
99
|
result[name] = index;
|
|
100
100
|
return result;
|
|
101
101
|
}, {}), value.length),
|
|
102
|
-
[
|
|
103
|
-
[
|
|
104
|
-
[
|
|
105
|
-
[
|
|
106
|
-
[
|
|
102
|
+
[index_js_1.TypeDefInfo.Si]: (registry, value) => getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
|
|
103
|
+
[index_js_1.TypeDefInfo.Struct]: (registry, value) => types_codec_1.Struct.with(getTypeClassMap(value), value.alias),
|
|
104
|
+
[index_js_1.TypeDefInfo.Tuple]: (registry, value) => types_codec_1.Tuple.with(getTypeClassArray(value)),
|
|
105
|
+
[index_js_1.TypeDefInfo.UInt]: (registry, value) => createInt(types_codec_1.UInt, value),
|
|
106
|
+
[index_js_1.TypeDefInfo.Vec]: (registry, { sub }) => {
|
|
107
107
|
if (!sub || Array.isArray(sub)) {
|
|
108
108
|
throw new Error('Expected type information for vector');
|
|
109
109
|
}
|
|
@@ -111,7 +111,7 @@ const infoMapping = {
|
|
|
111
111
|
? types_codec_1.Bytes
|
|
112
112
|
: types_codec_1.Vec.with(getTypeDefType(sub)));
|
|
113
113
|
},
|
|
114
|
-
[
|
|
114
|
+
[index_js_1.TypeDefInfo.VecFixed]: (registry, { displayName, length, sub }) => {
|
|
115
115
|
if (!(0, util_1.isNumber)(length) || !sub || Array.isArray(sub)) {
|
|
116
116
|
throw new Error('Expected length & type information for fixed vector');
|
|
117
117
|
}
|
|
@@ -119,8 +119,8 @@ const infoMapping = {
|
|
|
119
119
|
? types_codec_1.U8aFixed.with((length * 8), displayName)
|
|
120
120
|
: types_codec_1.VecFixed.with(getTypeDefType(sub), length));
|
|
121
121
|
},
|
|
122
|
-
[
|
|
123
|
-
[
|
|
122
|
+
[index_js_1.TypeDefInfo.WrapperKeepOpaque]: (registry, value) => createWithSub(types_codec_1.WrapperKeepOpaque, value),
|
|
123
|
+
[index_js_1.TypeDefInfo.WrapperOpaque]: (registry, value) => createWithSub(types_codec_1.WrapperOpaque, value)
|
|
124
124
|
};
|
|
125
125
|
function constructTypeClass(registry, typeDef) {
|
|
126
126
|
try {
|
|
@@ -152,6 +152,6 @@ function createClassUnsafe(registry, type) {
|
|
|
152
152
|
// we don't have an existing type, create the class via typeDef
|
|
153
153
|
getTypeClass(registry, registry.isLookupType(type)
|
|
154
154
|
? registry.lookup.getTypeDef(type)
|
|
155
|
-
: (0,
|
|
155
|
+
: (0, getTypeDef_js_1.getTypeDef)(type)));
|
|
156
156
|
}
|
|
157
157
|
exports.createClassUnsafe = createClassUnsafe;
|
package/cjs/create/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./class"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./type"), exports);
|
|
4
|
+
tslib_1.__exportStar(require("./class.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./type.js"), exports);
|
package/cjs/create/type.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTypeUnsafe = void 0;
|
|
4
4
|
const types_codec_1 = require("@polkadot/types-codec");
|
|
5
5
|
const util_1 = require("@polkadot/util");
|
|
6
|
-
const
|
|
6
|
+
const class_js_1 = require("./class.js");
|
|
7
7
|
function checkInstance(created, matcher) {
|
|
8
8
|
const u8a = created.toU8a();
|
|
9
9
|
const rawType = created.toRawType();
|
|
@@ -47,7 +47,7 @@ function createTypeUnsafe(registry, type, params = [], options = {}) {
|
|
|
47
47
|
let Clazz = null;
|
|
48
48
|
let firstError = null;
|
|
49
49
|
try {
|
|
50
|
-
Clazz = (0,
|
|
50
|
+
Clazz = (0, class_js_1.createClassUnsafe)(registry, type);
|
|
51
51
|
return initType(registry, Clazz, params, options);
|
|
52
52
|
}
|
|
53
53
|
catch (error) {
|
|
@@ -55,7 +55,7 @@ function createTypeUnsafe(registry, type, params = [], options = {}) {
|
|
|
55
55
|
}
|
|
56
56
|
if (Clazz && Clazz.__fallbackType) {
|
|
57
57
|
try {
|
|
58
|
-
Clazz = (0,
|
|
58
|
+
Clazz = (0, class_js_1.createClassUnsafe)(registry, Clazz.__fallbackType);
|
|
59
59
|
return initType(registry, Clazz, params, options);
|
|
60
60
|
}
|
|
61
61
|
catch {
|
package/cjs/detectPackage.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const util_1 = require("@polkadot/util");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
(0, util_1.detectPackage)(
|
|
5
|
+
const detectOther_js_1 = tslib_1.__importDefault(require("./detectOther.js"));
|
|
6
|
+
const packageInfo_js_1 = require("./packageInfo.js");
|
|
7
|
+
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, detectOther_js_1.default);
|
package/cjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
require("./detectPackage");
|
|
5
|
-
tslib_1.__exportStar(require("./bundle"), exports);
|
|
4
|
+
require("./detectPackage.js");
|
|
5
|
+
tslib_1.__exportStar(require("./bundle.js"), exports);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.packageInfo = void 0;
|
|
4
|
-
exports.packageInfo = { name: '@polkadot/types-create', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/types-create', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.1.2' };
|
package/cjs/types/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
require("./augmentRegistry");
|
|
5
|
-
tslib_1.__exportStar(require("./lookup"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
4
|
+
require("./augmentRegistry.js");
|
|
5
|
+
tslib_1.__exportStar(require("./lookup.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
package/cjs/util/encodeTypes.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withTypeString = exports.encodeTypeDef = exports.paramsNotation = void 0;
|
|
4
4
|
const util_1 = require("@polkadot/util");
|
|
5
|
-
const
|
|
5
|
+
const index_js_1 = require("../types/index.js");
|
|
6
6
|
const stringIdentity = (value) => value.toString();
|
|
7
7
|
const INFO_WRAP = ['BTreeMap', 'BTreeSet', 'Compact', 'HashMap', 'Option', 'Result', 'Vec'];
|
|
8
8
|
function paramsNotation(outer, inner, transform = stringIdentity) {
|
|
@@ -14,18 +14,18 @@ exports.paramsNotation = paramsNotation;
|
|
|
14
14
|
function encodeWithParams(registry, typeDef, outer) {
|
|
15
15
|
const { info, sub } = typeDef;
|
|
16
16
|
switch (info) {
|
|
17
|
-
case
|
|
18
|
-
case
|
|
19
|
-
case
|
|
20
|
-
case
|
|
21
|
-
case
|
|
22
|
-
case
|
|
23
|
-
case
|
|
24
|
-
case
|
|
25
|
-
case
|
|
26
|
-
case
|
|
27
|
-
case
|
|
28
|
-
case
|
|
17
|
+
case index_js_1.TypeDefInfo.BTreeMap:
|
|
18
|
+
case index_js_1.TypeDefInfo.BTreeSet:
|
|
19
|
+
case index_js_1.TypeDefInfo.Compact:
|
|
20
|
+
case index_js_1.TypeDefInfo.HashMap:
|
|
21
|
+
case index_js_1.TypeDefInfo.Linkage:
|
|
22
|
+
case index_js_1.TypeDefInfo.Option:
|
|
23
|
+
case index_js_1.TypeDefInfo.Range:
|
|
24
|
+
case index_js_1.TypeDefInfo.RangeInclusive:
|
|
25
|
+
case index_js_1.TypeDefInfo.Result:
|
|
26
|
+
case index_js_1.TypeDefInfo.Vec:
|
|
27
|
+
case index_js_1.TypeDefInfo.WrapperKeepOpaque:
|
|
28
|
+
case index_js_1.TypeDefInfo.WrapperOpaque:
|
|
29
29
|
return paramsNotation(outer, sub, (p) => encodeTypeDef(registry, p));
|
|
30
30
|
}
|
|
31
31
|
throw new Error(`Unable to encode ${(0, util_1.stringify)(typeDef)} with params`);
|
|
@@ -45,11 +45,11 @@ function encodeSubTypes(registry, sub, asEnum, extra) {
|
|
|
45
45
|
: inner);
|
|
46
46
|
}
|
|
47
47
|
const encoders = {
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
48
|
+
[index_js_1.TypeDefInfo.BTreeMap]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'BTreeMap'),
|
|
49
|
+
[index_js_1.TypeDefInfo.BTreeSet]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'BTreeSet'),
|
|
50
|
+
[index_js_1.TypeDefInfo.Compact]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Compact'),
|
|
51
|
+
[index_js_1.TypeDefInfo.DoNotConstruct]: (registry, { displayName, lookupIndex, lookupName }) => `DoNotConstruct<${lookupName || displayName || ((0, util_1.isUndefined)(lookupIndex) ? 'Unknown' : registry.createLookupType(lookupIndex))}>`,
|
|
52
|
+
[index_js_1.TypeDefInfo.Enum]: (registry, { sub }) => {
|
|
53
53
|
if (!Array.isArray(sub)) {
|
|
54
54
|
throw new Error('Unable to encode Enum type');
|
|
55
55
|
}
|
|
@@ -59,19 +59,19 @@ const encoders = {
|
|
|
59
59
|
? (0, util_1.stringify)({ _enum: sub.map(({ name }, index) => `${name || `Empty${index}`}`) })
|
|
60
60
|
: encodeSubTypes(registry, sub, true);
|
|
61
61
|
},
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
62
|
+
[index_js_1.TypeDefInfo.HashMap]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'HashMap'),
|
|
63
|
+
[index_js_1.TypeDefInfo.Int]: (registry, { length = 32 }) => `Int<${length}>`,
|
|
64
|
+
[index_js_1.TypeDefInfo.Linkage]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Linkage'),
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
-
[
|
|
67
|
-
[
|
|
66
|
+
[index_js_1.TypeDefInfo.Null]: (registry, typeDef) => 'Null',
|
|
67
|
+
[index_js_1.TypeDefInfo.Option]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Option'),
|
|
68
68
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
69
|
+
[index_js_1.TypeDefInfo.Plain]: (registry, { displayName, type }) => displayName || type,
|
|
70
|
+
[index_js_1.TypeDefInfo.Range]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Range'),
|
|
71
|
+
[index_js_1.TypeDefInfo.RangeInclusive]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'RangeInclusive'),
|
|
72
|
+
[index_js_1.TypeDefInfo.Result]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Result'),
|
|
73
73
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
74
|
-
[
|
|
74
|
+
[index_js_1.TypeDefInfo.Set]: (registry, { length = 8, sub }) => {
|
|
75
75
|
if (!Array.isArray(sub)) {
|
|
76
76
|
throw new Error('Unable to encode Set type');
|
|
77
77
|
}
|
|
@@ -80,8 +80,8 @@ const encoders = {
|
|
|
80
80
|
});
|
|
81
81
|
},
|
|
82
82
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
-
[
|
|
84
|
-
[
|
|
83
|
+
[index_js_1.TypeDefInfo.Si]: (registry, { lookupName, type }) => lookupName || type,
|
|
84
|
+
[index_js_1.TypeDefInfo.Struct]: (registry, { alias, sub }) => {
|
|
85
85
|
if (!Array.isArray(sub)) {
|
|
86
86
|
throw new Error('Unable to encode Struct type');
|
|
87
87
|
}
|
|
@@ -91,22 +91,22 @@ const encoders = {
|
|
|
91
91
|
}
|
|
92
92
|
: {});
|
|
93
93
|
},
|
|
94
|
-
[
|
|
94
|
+
[index_js_1.TypeDefInfo.Tuple]: (registry, { sub }) => {
|
|
95
95
|
if (!Array.isArray(sub)) {
|
|
96
96
|
throw new Error('Unable to encode Tuple type');
|
|
97
97
|
}
|
|
98
98
|
return `(${sub.map((type) => encodeTypeDef(registry, type)).join(',')})`;
|
|
99
99
|
},
|
|
100
|
-
[
|
|
101
|
-
[
|
|
102
|
-
[
|
|
100
|
+
[index_js_1.TypeDefInfo.UInt]: (registry, { length = 32 }) => `UInt<${length}>`,
|
|
101
|
+
[index_js_1.TypeDefInfo.Vec]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Vec'),
|
|
102
|
+
[index_js_1.TypeDefInfo.VecFixed]: (registry, { length, sub }) => {
|
|
103
103
|
if (!(0, util_1.isNumber)(length) || !sub || Array.isArray(sub)) {
|
|
104
104
|
throw new Error('Unable to encode VecFixed type');
|
|
105
105
|
}
|
|
106
106
|
return `[${sub.type};${length}]`;
|
|
107
107
|
},
|
|
108
|
-
[
|
|
109
|
-
[
|
|
108
|
+
[index_js_1.TypeDefInfo.WrapperKeepOpaque]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'WrapperKeepOpaque'),
|
|
109
|
+
[index_js_1.TypeDefInfo.WrapperOpaque]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'WrapperOpaque')
|
|
110
110
|
};
|
|
111
111
|
function encodeType(registry, typeDef, withLookup = true) {
|
|
112
112
|
return withLookup && typeDef.lookupName
|
package/cjs/util/getTypeDef.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTypeDef = void 0;
|
|
4
4
|
const types_codec_1 = require("@polkadot/types-codec");
|
|
5
5
|
const util_1 = require("@polkadot/util");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
7
|
+
const typeSplit_js_1 = require("./typeSplit.js");
|
|
8
8
|
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
|
9
9
|
function getTypeString(typeOrObj) {
|
|
10
10
|
return (0, util_1.isString)(typeOrObj)
|
|
@@ -22,13 +22,13 @@ function isRustEnum(details) {
|
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
function _decodeEnum(value, details, count, fallbackType) {
|
|
25
|
-
value.info =
|
|
25
|
+
value.info = index_js_1.TypeDefInfo.Enum;
|
|
26
26
|
value.fallbackType = fallbackType;
|
|
27
27
|
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
|
28
28
|
if (Array.isArray(details)) {
|
|
29
29
|
value.sub = details.map((name, index) => ({
|
|
30
30
|
index,
|
|
31
|
-
info:
|
|
31
|
+
info: index_js_1.TypeDefInfo.Plain,
|
|
32
32
|
name,
|
|
33
33
|
type: 'Null'
|
|
34
34
|
}));
|
|
@@ -39,7 +39,7 @@ function _decodeEnum(value, details, count, fallbackType) {
|
|
|
39
39
|
else {
|
|
40
40
|
value.sub = Object.entries(details).map(([name, index]) => ({
|
|
41
41
|
index,
|
|
42
|
-
info:
|
|
42
|
+
info: index_js_1.TypeDefInfo.Plain,
|
|
43
43
|
name,
|
|
44
44
|
type: 'Null'
|
|
45
45
|
}));
|
|
@@ -47,7 +47,7 @@ function _decodeEnum(value, details, count, fallbackType) {
|
|
|
47
47
|
return value;
|
|
48
48
|
}
|
|
49
49
|
function _decodeSet(value, details, fallbackType) {
|
|
50
|
-
value.info =
|
|
50
|
+
value.info = index_js_1.TypeDefInfo.Set;
|
|
51
51
|
value.fallbackType = fallbackType;
|
|
52
52
|
value.length = details._bitLength;
|
|
53
53
|
value.sub = Object
|
|
@@ -55,7 +55,7 @@ function _decodeSet(value, details, fallbackType) {
|
|
|
55
55
|
.filter(([name]) => !name.startsWith('_'))
|
|
56
56
|
.map(([name, index]) => ({
|
|
57
57
|
index,
|
|
58
|
-
info:
|
|
58
|
+
info: index_js_1.TypeDefInfo.Plain,
|
|
59
59
|
name,
|
|
60
60
|
type: 'Null'
|
|
61
61
|
}));
|
|
@@ -120,7 +120,7 @@ function _decodeFixedVec(value, type, _, count) {
|
|
|
120
120
|
function _decodeTuple(value, _, subType, count) {
|
|
121
121
|
value.sub = subType.length === 0
|
|
122
122
|
? []
|
|
123
|
-
: (0,
|
|
123
|
+
: (0, typeSplit_js_1.typeSplit)(subType).map((inner) => getTypeDef(inner, {}, count));
|
|
124
124
|
return value;
|
|
125
125
|
}
|
|
126
126
|
function _decodeAnyInt(value, type, _, clazz) {
|
|
@@ -148,28 +148,28 @@ function hasWrapper(type, [start, end]) {
|
|
|
148
148
|
return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
|
|
149
149
|
}
|
|
150
150
|
const nestedExtraction = [
|
|
151
|
-
['[', ']',
|
|
152
|
-
['{', '}',
|
|
153
|
-
['(', ')',
|
|
151
|
+
['[', ']', index_js_1.TypeDefInfo.VecFixed, _decodeFixedVec],
|
|
152
|
+
['{', '}', index_js_1.TypeDefInfo.Struct, _decodeStruct],
|
|
153
|
+
['(', ')', index_js_1.TypeDefInfo.Tuple, _decodeTuple],
|
|
154
154
|
// the inner for these are the same as tuple, multiple values
|
|
155
|
-
['BTreeMap<', '>',
|
|
156
|
-
['HashMap<', '>',
|
|
157
|
-
['Int<', '>',
|
|
158
|
-
['Result<', '>',
|
|
159
|
-
['UInt<', '>',
|
|
160
|
-
['DoNotConstruct<', '>',
|
|
155
|
+
['BTreeMap<', '>', index_js_1.TypeDefInfo.BTreeMap, _decodeTuple],
|
|
156
|
+
['HashMap<', '>', index_js_1.TypeDefInfo.HashMap, _decodeTuple],
|
|
157
|
+
['Int<', '>', index_js_1.TypeDefInfo.Int, _decodeInt],
|
|
158
|
+
['Result<', '>', index_js_1.TypeDefInfo.Result, _decodeTuple],
|
|
159
|
+
['UInt<', '>', index_js_1.TypeDefInfo.UInt, _decodeUInt],
|
|
160
|
+
['DoNotConstruct<', '>', index_js_1.TypeDefInfo.DoNotConstruct, _decodeDoNotConstruct]
|
|
161
161
|
];
|
|
162
162
|
const wrappedExtraction = [
|
|
163
|
-
['BTreeSet<', '>',
|
|
164
|
-
['Compact<', '>',
|
|
165
|
-
['Linkage<', '>',
|
|
166
|
-
['Opaque<', '>',
|
|
167
|
-
['Option<', '>',
|
|
168
|
-
['Range<', '>',
|
|
169
|
-
['RangeInclusive<', '>',
|
|
170
|
-
['Vec<', '>',
|
|
171
|
-
['WrapperKeepOpaque<', '>',
|
|
172
|
-
['WrapperOpaque<', '>',
|
|
163
|
+
['BTreeSet<', '>', index_js_1.TypeDefInfo.BTreeSet],
|
|
164
|
+
['Compact<', '>', index_js_1.TypeDefInfo.Compact],
|
|
165
|
+
['Linkage<', '>', index_js_1.TypeDefInfo.Linkage],
|
|
166
|
+
['Opaque<', '>', index_js_1.TypeDefInfo.WrapperOpaque],
|
|
167
|
+
['Option<', '>', index_js_1.TypeDefInfo.Option],
|
|
168
|
+
['Range<', '>', index_js_1.TypeDefInfo.Range],
|
|
169
|
+
['RangeInclusive<', '>', index_js_1.TypeDefInfo.RangeInclusive],
|
|
170
|
+
['Vec<', '>', index_js_1.TypeDefInfo.Vec],
|
|
171
|
+
['WrapperKeepOpaque<', '>', index_js_1.TypeDefInfo.WrapperKeepOpaque],
|
|
172
|
+
['WrapperOpaque<', '>', index_js_1.TypeDefInfo.WrapperOpaque]
|
|
173
173
|
];
|
|
174
174
|
function extractSubType(type, [start, end]) {
|
|
175
175
|
return type.substring(start.length, type.length - end.length);
|
|
@@ -177,7 +177,7 @@ function extractSubType(type, [start, end]) {
|
|
|
177
177
|
function getTypeDef(_type, { displayName, name } = {}, count = 0) {
|
|
178
178
|
// create the type via Type, allowing types to be sanitized
|
|
179
179
|
const type = (0, types_codec_1.sanitize)(_type);
|
|
180
|
-
const value = { displayName, info:
|
|
180
|
+
const value = { displayName, info: index_js_1.TypeDefInfo.Plain, name, type };
|
|
181
181
|
if (++count > 64) {
|
|
182
182
|
throw new Error('getTypeDef: Maximum nested limit reached');
|
|
183
183
|
}
|
package/cjs/util/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./encodeTypes"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./getTypeDef"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./typeSplit"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./xcm"), exports);
|
|
4
|
+
tslib_1.__exportStar(require("./encodeTypes.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./getTypeDef.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./typeSplit.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./xcm.js"), exports);
|
package/create/class.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Codec, CodecClass, Registry } from '@polkadot/types-codec/types';
|
|
2
|
-
import type { TypeDef } from '../types';
|
|
2
|
+
import type { TypeDef } from '../types/index.js';
|
|
3
3
|
export declare function constructTypeClass<T extends Codec = Codec>(registry: Registry, typeDef: TypeDef): CodecClass<T>;
|
|
4
4
|
export declare function getTypeClass<T extends Codec = Codec>(registry: Registry, typeDef: TypeDef): CodecClass<T>;
|
|
5
5
|
export declare function createClassUnsafe<T extends Codec = Codec, K extends string = string>(registry: Registry, type: K): CodecClass<T>;
|
package/create/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './class';
|
|
2
|
-
export * from './type';
|
|
1
|
+
export * from './class.js';
|
|
2
|
+
export * from './type.js';
|
package/create/type.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Codec, Registry } from '@polkadot/types-codec/types';
|
|
2
|
-
import type { CreateOptions } from '../types';
|
|
2
|
+
import type { CreateOptions } from '../types/index.js';
|
|
3
3
|
export declare function createTypeUnsafe<T extends Codec = Codec, K extends string = string>(registry: Registry, type: K, params?: unknown[], options?: CreateOptions): T;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './detectPackage';
|
|
2
|
-
export * from './bundle';
|
|
1
|
+
import './detectPackage.js';
|
|
2
|
+
export * from './bundle.js';
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "10.
|
|
23
|
+
"version": "10.1.2",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -123,8 +123,8 @@
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
"dependencies": {
|
|
126
|
-
"@polkadot/types-codec": "10.
|
|
127
|
-
"@polkadot/util": "^11.0.
|
|
126
|
+
"@polkadot/types-codec": "10.1.2",
|
|
127
|
+
"@polkadot/util": "^11.0.2",
|
|
128
128
|
"tslib": "^2.5.0"
|
|
129
129
|
}
|
|
130
130
|
}
|
package/packageInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const packageInfo = { name: '@polkadot/types-create', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.
|
|
1
|
+
export const packageInfo = { name: '@polkadot/types-create', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.1.2' };
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './augmentRegistry';
|
|
1
|
+
import './augmentRegistry.js';
|
|
2
2
|
export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types';
|
|
3
|
-
export * from './lookup';
|
|
4
|
-
export * from './types';
|
|
3
|
+
export * from './lookup.js';
|
|
4
|
+
export * from './types.js';
|
package/types/lookup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Option, Text } from '@polkadot/types-codec';
|
|
2
2
|
import type { ICompact, INumber, LookupString } from '@polkadot/types-codec/types';
|
|
3
|
-
import type { TypeDef } from './types';
|
|
3
|
+
import type { TypeDef } from './types.js';
|
|
4
4
|
interface SiTypeBase {
|
|
5
5
|
def: {
|
|
6
6
|
asTuple: ICompact<INumber>[];
|
package/util/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './encodeTypes';
|
|
2
|
-
export * from './getTypeDef';
|
|
3
|
-
export * from './typeSplit';
|
|
4
|
-
export * from './xcm';
|
|
1
|
+
export * from './encodeTypes.js';
|
|
2
|
+
export * from './getTypeDef.js';
|
|
3
|
+
export * from './typeSplit.js';
|
|
4
|
+
export * from './xcm.js';
|