@polkadot/types-create 9.14.2 → 10.1.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.
- package/bundle.d.ts +4 -4
- package/bundle.js +4 -7
- package/cjs/bundle.js +9 -46
- package/cjs/create/class.js +129 -172
- package/cjs/create/index.js +4 -26
- package/cjs/create/type.js +60 -75
- package/cjs/detectOther.js +3 -10
- package/cjs/detectPackage.js +6 -11
- package/cjs/index.js +4 -16
- package/cjs/packageInfo.js +2 -16
- package/cjs/types/augmentRegistry.js +1 -1
- package/cjs/types/index.js +5 -27
- package/cjs/types/lookup.js +2 -1
- package/cjs/types/types.js +26 -32
- package/cjs/util/encodeTypes.js +116 -199
- package/cjs/util/getTypeDef.js +166 -190
- package/cjs/util/index.js +6 -48
- package/cjs/util/typeSplit.js +57 -72
- package/cjs/util/xcm.js +7 -16
- package/create/class.d.ts +1 -1
- package/create/class.js +121 -153
- package/create/index.d.ts +2 -2
- package/create/index.js +2 -5
- package/create/type.d.ts +1 -1
- package/create/type.js +52 -61
- package/detectOther.js +0 -3
- package/detectPackage.js +2 -7
- package/index.d.ts +2 -2
- package/index.js +2 -5
- package/package.json +8 -5
- package/packageInfo.js +1 -11
- package/types/augmentRegistry.js +0 -5
- package/types/index.d.ts +3 -3
- package/types/index.js +3 -6
- package/types/lookup.d.ts +1 -1
- package/types/types.js +24 -27
- package/util/encodeTypes.js +108 -152
- package/util/getTypeDef.js +159 -165
- package/util/index.d.ts +4 -4
- package/util/index.js +4 -7
- package/util/typeSplit.js +53 -66
- package/util/xcm.js +1 -6
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/bundle.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export { TypeDefInfo } from "./types/index.js";
|
|
6
|
-
export * from "./create/index.js";
|
|
7
|
-
export * from "./util/index.js";
|
|
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
|
@@ -1,47 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _types.TypeDefInfo;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "packageInfo", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return _packageInfo.packageInfo;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
var _packageInfo = require("./packageInfo");
|
|
23
|
-
var _types = require("./types");
|
|
24
|
-
var _create = require("./create");
|
|
25
|
-
Object.keys(_create).forEach(function (key) {
|
|
26
|
-
if (key === "default" || key === "__esModule") return;
|
|
27
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
-
if (key in exports && exports[key] === _create[key]) return;
|
|
29
|
-
Object.defineProperty(exports, key, {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return _create[key];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
var _util = require("./util");
|
|
37
|
-
Object.keys(_util).forEach(function (key) {
|
|
38
|
-
if (key === "default" || key === "__esModule") return;
|
|
39
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
-
if (key in exports && exports[key] === _util[key]) return;
|
|
41
|
-
Object.defineProperty(exports, key, {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return _util[key];
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeDefInfo = exports.packageInfo = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
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
|
@@ -1,200 +1,157 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _util = require("@polkadot/util");
|
|
11
|
-
var _types = require("../types");
|
|
12
|
-
var _getTypeDef = require("../util/getTypeDef");
|
|
13
|
-
// Copyright 2017-2023 @polkadot/types-create authors & contributors
|
|
14
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
15
|
-
|
|
16
|
-
function getTypeDefType(_ref) {
|
|
17
|
-
let {
|
|
18
|
-
lookupName,
|
|
19
|
-
type
|
|
20
|
-
} = _ref;
|
|
21
|
-
return lookupName || type;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClassUnsafe = exports.getTypeClass = exports.constructTypeClass = void 0;
|
|
4
|
+
const types_codec_1 = require("@polkadot/types-codec");
|
|
5
|
+
const util_1 = require("@polkadot/util");
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
7
|
+
const getTypeDef_js_1 = require("../util/getTypeDef.js");
|
|
8
|
+
function getTypeDefType({ lookupName, type }) {
|
|
9
|
+
return lookupName || type;
|
|
22
10
|
}
|
|
23
11
|
function getSubDefArray(value) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
if (!Array.isArray(value.sub)) {
|
|
13
|
+
throw new Error(`Expected subtype as TypeDef[] in ${(0, util_1.stringify)(value)}`);
|
|
14
|
+
}
|
|
15
|
+
return value.sub;
|
|
28
16
|
}
|
|
29
17
|
function getSubDef(value) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
if (!value.sub || Array.isArray(value.sub)) {
|
|
19
|
+
throw new Error(`Expected subtype as TypeDef in ${(0, util_1.stringify)(value)}`);
|
|
20
|
+
}
|
|
21
|
+
return value.sub;
|
|
34
22
|
}
|
|
35
23
|
function getSubType(value) {
|
|
36
|
-
|
|
24
|
+
return getTypeDefType(getSubDef(value));
|
|
37
25
|
}
|
|
38
|
-
|
|
39
|
-
// create a maps of type string CodecClasss from the input
|
|
40
26
|
function getTypeClassMap(value) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
const subs = getSubDefArray(value);
|
|
28
|
+
const map = {};
|
|
29
|
+
for (let i = 0; i < subs.length; i++) {
|
|
30
|
+
map[subs[i].name] = getTypeDefType(subs[i]);
|
|
31
|
+
}
|
|
32
|
+
return map;
|
|
47
33
|
}
|
|
48
|
-
|
|
49
|
-
// create an array of type string CodecClasss from the input
|
|
50
34
|
function getTypeClassArray(value) {
|
|
51
|
-
|
|
35
|
+
return getSubDefArray(value).map(getTypeDefType);
|
|
52
36
|
}
|
|
53
|
-
function createInt(Clazz,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (!(0, _util.isNumber)(length)) {
|
|
59
|
-
throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
|
|
60
|
-
}
|
|
61
|
-
return Clazz.with(length, displayName);
|
|
37
|
+
function createInt(Clazz, { displayName, length }) {
|
|
38
|
+
if (!(0, util_1.isNumber)(length)) {
|
|
39
|
+
throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
|
|
40
|
+
}
|
|
41
|
+
return Clazz.with(length, displayName);
|
|
62
42
|
}
|
|
63
43
|
function createHashMap(Clazz, value) {
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
const [keyType, valueType] = getTypeClassArray(value);
|
|
45
|
+
return Clazz.with(keyType, valueType);
|
|
66
46
|
}
|
|
67
47
|
function createWithSub(Clazz, value) {
|
|
68
|
-
|
|
48
|
+
return Clazz.with(getSubType(value));
|
|
69
49
|
}
|
|
70
50
|
const infoMapping = {
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
[_types.TypeDefInfo.Struct]: (registry, value) => _typesCodec.Struct.with(getTypeClassMap(value), value.alias),
|
|
145
|
-
[_types.TypeDefInfo.Tuple]: (registry, value) => _typesCodec.Tuple.with(getTypeClassArray(value)),
|
|
146
|
-
[_types.TypeDefInfo.UInt]: (registry, value) => createInt(_typesCodec.UInt, value),
|
|
147
|
-
[_types.TypeDefInfo.Vec]: (registry, _ref6) => {
|
|
148
|
-
let {
|
|
149
|
-
sub
|
|
150
|
-
} = _ref6;
|
|
151
|
-
if (!sub || Array.isArray(sub)) {
|
|
152
|
-
throw new Error('Expected type information for vector');
|
|
153
|
-
}
|
|
154
|
-
return sub.type === 'u8' ? _typesCodec.Bytes : _typesCodec.Vec.with(getTypeDefType(sub));
|
|
155
|
-
},
|
|
156
|
-
[_types.TypeDefInfo.VecFixed]: (registry, _ref7) => {
|
|
157
|
-
let {
|
|
158
|
-
displayName,
|
|
159
|
-
length,
|
|
160
|
-
sub
|
|
161
|
-
} = _ref7;
|
|
162
|
-
if (!(0, _util.isNumber)(length) || !sub || Array.isArray(sub)) {
|
|
163
|
-
throw new Error('Expected length & type information for fixed vector');
|
|
164
|
-
}
|
|
165
|
-
return sub.type === 'u8' ? _typesCodec.U8aFixed.with(length * 8, displayName) : _typesCodec.VecFixed.with(getTypeDefType(sub), length);
|
|
166
|
-
},
|
|
167
|
-
[_types.TypeDefInfo.WrapperKeepOpaque]: (registry, value) => createWithSub(_typesCodec.WrapperKeepOpaque, value),
|
|
168
|
-
[_types.TypeDefInfo.WrapperOpaque]: (registry, value) => createWithSub(_typesCodec.WrapperOpaque, value)
|
|
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
|
+
const subs = getSubDefArray(value);
|
|
57
|
+
return types_codec_1.Enum.with(subs.every(({ type }) => type === 'Null')
|
|
58
|
+
? subs.reduce((out, { index, name }, count) => {
|
|
59
|
+
out[name] = index || count;
|
|
60
|
+
return out;
|
|
61
|
+
}, {})
|
|
62
|
+
: getTypeClassMap(value));
|
|
63
|
+
},
|
|
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
|
+
// We have circular deps between Linkage & Struct
|
|
67
|
+
[index_js_1.TypeDefInfo.Linkage]: (registry, value) => {
|
|
68
|
+
const type = `Option<${getSubType(value)}>`;
|
|
69
|
+
// eslint-disable-next-line sort-keys
|
|
70
|
+
const Clazz = types_codec_1.Struct.with({ previous: type, next: type });
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
72
|
+
Clazz.prototype.toRawType = function () {
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
|
74
|
+
return `Linkage<${this.next.toRawType(true)}>`;
|
|
75
|
+
};
|
|
76
|
+
return Clazz;
|
|
77
|
+
},
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
|
+
[index_js_1.TypeDefInfo.Null]: (registry, _) => types_codec_1.Null,
|
|
80
|
+
[index_js_1.TypeDefInfo.Option]: (registry, value) => {
|
|
81
|
+
if (!value.sub || Array.isArray(value.sub)) {
|
|
82
|
+
throw new Error('Expected type information for Option');
|
|
83
|
+
}
|
|
84
|
+
// NOTE This is opt-in (unhandled), not by default
|
|
85
|
+
// if (value.sub.type === 'bool') {
|
|
86
|
+
// return OptionBool;
|
|
87
|
+
// }
|
|
88
|
+
return createWithSub(types_codec_1.Option, value);
|
|
89
|
+
},
|
|
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
|
+
const [Ok, Err] = getTypeClassArray(value);
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
96
|
+
return types_codec_1.Result.with({ Err, Ok });
|
|
97
|
+
},
|
|
98
|
+
[index_js_1.TypeDefInfo.Set]: (registry, value) => types_codec_1.CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
|
|
99
|
+
result[name] = index;
|
|
100
|
+
return result;
|
|
101
|
+
}, {}), value.length),
|
|
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
|
+
if (!sub || Array.isArray(sub)) {
|
|
108
|
+
throw new Error('Expected type information for vector');
|
|
109
|
+
}
|
|
110
|
+
return (sub.type === 'u8'
|
|
111
|
+
? types_codec_1.Bytes
|
|
112
|
+
: types_codec_1.Vec.with(getTypeDefType(sub)));
|
|
113
|
+
},
|
|
114
|
+
[index_js_1.TypeDefInfo.VecFixed]: (registry, { displayName, length, sub }) => {
|
|
115
|
+
if (!(0, util_1.isNumber)(length) || !sub || Array.isArray(sub)) {
|
|
116
|
+
throw new Error('Expected length & type information for fixed vector');
|
|
117
|
+
}
|
|
118
|
+
return (sub.type === 'u8'
|
|
119
|
+
? types_codec_1.U8aFixed.with((length * 8), displayName)
|
|
120
|
+
: types_codec_1.VecFixed.with(getTypeDefType(sub), length));
|
|
121
|
+
},
|
|
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)
|
|
169
124
|
};
|
|
170
125
|
function constructTypeClass(registry, typeDef) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
126
|
+
try {
|
|
127
|
+
const Type = infoMapping[typeDef.info](registry, typeDef);
|
|
128
|
+
if (!Type) {
|
|
129
|
+
throw new Error('No class created');
|
|
130
|
+
}
|
|
131
|
+
// don't clobber any existing
|
|
132
|
+
if (!Type.__fallbackType && typeDef.fallbackType) {
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
134
|
+
// @ts-ignore ...this is the only place we we actually assign this...
|
|
135
|
+
Type.__fallbackType = typeDef.fallbackType;
|
|
136
|
+
}
|
|
137
|
+
return Type;
|
|
175
138
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (!Type.__fallbackType && typeDef.fallbackType) {
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
180
|
-
// @ts-ignore ...this is the only place we we actually assign this...
|
|
181
|
-
Type.__fallbackType = typeDef.fallbackType;
|
|
139
|
+
catch (error) {
|
|
140
|
+
throw new Error(`Unable to construct class from ${(0, util_1.stringify)(typeDef)}: ${error.message}`);
|
|
182
141
|
}
|
|
183
|
-
return Type;
|
|
184
|
-
} catch (error) {
|
|
185
|
-
throw new Error(`Unable to construct class from ${(0, _util.stringify)(typeDef)}: ${error.message}`);
|
|
186
|
-
}
|
|
187
142
|
}
|
|
188
|
-
|
|
189
|
-
// Returns the type Class for construction
|
|
143
|
+
exports.constructTypeClass = constructTypeClass;
|
|
190
144
|
function getTypeClass(registry, typeDef) {
|
|
191
|
-
|
|
145
|
+
return registry.getUnsafe(typeDef.type, false, typeDef);
|
|
192
146
|
}
|
|
147
|
+
exports.getTypeClass = getTypeClass;
|
|
193
148
|
function createClassUnsafe(registry, type) {
|
|
194
|
-
|
|
149
|
+
return (
|
|
195
150
|
// just retrieve via name, no creation via typeDef
|
|
196
151
|
registry.getUnsafe(type) ||
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
152
|
+
// we don't have an existing type, create the class via typeDef
|
|
153
|
+
getTypeClass(registry, registry.isLookupType(type)
|
|
154
|
+
? registry.lookup.getTypeDef(type)
|
|
155
|
+
: (0, getTypeDef_js_1.getTypeDef)(type)));
|
|
156
|
+
}
|
|
157
|
+
exports.createClassUnsafe = createClassUnsafe;
|
package/cjs/create/index.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _class = require("./class");
|
|
7
|
-
Object.keys(_class).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _class[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _class[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _type = require("./type");
|
|
18
|
-
Object.keys(_type).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _type[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _type[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./class.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./type.js"), exports);
|
package/cjs/create/type.js
CHANGED
|
@@ -1,82 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _typesCodec = require("@polkadot/types-codec");
|
|
8
|
-
var _util = require("@polkadot/util");
|
|
9
|
-
var _class = require("./class");
|
|
10
|
-
// Copyright 2017-2023 @polkadot/types-create authors & contributors
|
|
11
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
|
|
13
|
-
// With isPedantic, actually check that the encoding matches that supplied. This
|
|
14
|
-
// is much slower, but verifies that we have the correct types defined
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTypeUnsafe = void 0;
|
|
4
|
+
const types_codec_1 = require("@polkadot/types-codec");
|
|
5
|
+
const util_1 = require("@polkadot/util");
|
|
6
|
+
const class_js_1 = require("./class.js");
|
|
15
7
|
function checkInstance(created, matcher) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
const u8a = created.toU8a();
|
|
9
|
+
const rawType = created.toRawType();
|
|
10
|
+
const isOk = (
|
|
11
|
+
// full match, all ok
|
|
12
|
+
(0, util_1.u8aEq)(u8a, matcher) ||
|
|
13
|
+
(
|
|
14
|
+
// on a length-prefixed type, just check the actual length
|
|
15
|
+
['Bytes', 'Text', 'Type'].includes(rawType) &&
|
|
16
|
+
matcher.length === created.length) ||
|
|
17
|
+
(
|
|
18
|
+
// when the created is empty and matcher is also empty, let it slide...
|
|
19
|
+
created.isEmpty &&
|
|
20
|
+
matcher.every((v) => !v)));
|
|
21
|
+
if (!isOk) {
|
|
22
|
+
throw new Error(`${rawType}:: Decoded input doesn't match input, received ${(0, util_1.u8aToHex)(matcher, 512)} (${matcher.length} bytes), created ${(0, util_1.u8aToHex)(u8a, 512)} (${u8a.length} bytes)`);
|
|
23
|
+
}
|
|
28
24
|
}
|
|
29
|
-
function checkPedantic(created,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
function checkPedantic(created, [value]) {
|
|
26
|
+
if ((0, util_1.isU8a)(value)) {
|
|
27
|
+
checkInstance(created, value);
|
|
28
|
+
}
|
|
29
|
+
else if ((0, util_1.isHex)(value)) {
|
|
30
|
+
checkInstance(created, (0, util_1.u8aToU8a)(value));
|
|
31
|
+
}
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
isPedantic && checkPedantic(created, params);
|
|
50
|
-
if (blockHash) {
|
|
51
|
-
created.createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]);
|
|
52
|
-
}
|
|
53
|
-
if (isFallback) {
|
|
54
|
-
created.isStorageFallback = true;
|
|
55
|
-
}
|
|
56
|
-
return created;
|
|
33
|
+
function initType(registry, Type, params = [], { blockHash, isFallback, isOptional, isPedantic } = {}) {
|
|
34
|
+
const created = new (isOptional
|
|
35
|
+
? types_codec_1.Option.with(Type)
|
|
36
|
+
: Type)(registry, ...params);
|
|
37
|
+
isPedantic && checkPedantic(created, params);
|
|
38
|
+
if (blockHash) {
|
|
39
|
+
created.createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]);
|
|
40
|
+
}
|
|
41
|
+
if (isFallback) {
|
|
42
|
+
created.isStorageFallback = true;
|
|
43
|
+
}
|
|
44
|
+
return created;
|
|
57
45
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// runtime error.
|
|
62
|
-
function createTypeUnsafe(registry, type) {
|
|
63
|
-
let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
64
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
65
|
-
let Clazz = null;
|
|
66
|
-
let firstError = null;
|
|
67
|
-
try {
|
|
68
|
-
Clazz = (0, _class.createClassUnsafe)(registry, type);
|
|
69
|
-
return initType(registry, Clazz, params, options);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
firstError = new Error(`createType(${type}):: ${error.message}`);
|
|
72
|
-
}
|
|
73
|
-
if (Clazz && Clazz.__fallbackType) {
|
|
46
|
+
function createTypeUnsafe(registry, type, params = [], options = {}) {
|
|
47
|
+
let Clazz = null;
|
|
48
|
+
let firstError = null;
|
|
74
49
|
try {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
50
|
+
Clazz = (0, class_js_1.createClassUnsafe)(registry, type);
|
|
51
|
+
return initType(registry, Clazz, params, options);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
firstError = new Error(`createType(${type}):: ${error.message}`);
|
|
79
55
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
56
|
+
if (Clazz && Clazz.__fallbackType) {
|
|
57
|
+
try {
|
|
58
|
+
Clazz = (0, class_js_1.createClassUnsafe)(registry, Clazz.__fallbackType);
|
|
59
|
+
return initType(registry, Clazz, params, options);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// swallow, we will throw the first error again
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw firstError;
|
|
66
|
+
}
|
|
67
|
+
exports.createTypeUnsafe = createTypeUnsafe;
|
package/cjs/detectOther.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _packageInfo = require("@polkadot/types-codec/cjs/packageInfo");
|
|
8
|
-
// Copyright 2017-2023 @polkadot/types-create authors & contributors
|
|
9
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
-
var _default = [_packageInfo.packageInfo];
|
|
11
|
-
exports.default = _default;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const packageInfo_1 = require("@polkadot/types-codec/cjs/packageInfo");
|
|
4
|
+
exports.default = [packageInfo_1.packageInfo];
|
package/cjs/detectPackage.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
-
|
|
12
|
-
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
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);
|