@pezkuwi/types-create 16.5.8 → 16.5.10
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/cjs/packageInfo.js +1 -1
- package/package.json +6 -5
- package/packageInfo.js +1 -1
- package/build/LICENSE +0 -201
- package/build/README.md +0 -3
- package/build/bundle.d.ts +0 -3
- package/build/bundle.js +0 -3
- package/build/cjs/bundle.d.ts +0 -3
- package/build/cjs/bundle.js +0 -9
- package/build/cjs/create/class.d.ts +0 -5
- package/build/cjs/create/class.js +0 -165
- package/build/cjs/create/index.d.ts +0 -2
- package/build/cjs/create/index.js +0 -5
- package/build/cjs/create/type.d.ts +0 -3
- package/build/cjs/create/type.js +0 -66
- package/build/cjs/exports.d.ts +0 -2
- package/build/cjs/exports.js +0 -5
- package/build/cjs/index.d.ts +0 -2
- package/build/cjs/index.js +0 -5
- package/build/cjs/package.json +0 -3
- package/build/cjs/packageDetect.d.ts +0 -1
- package/build/cjs/packageDetect.js +0 -6
- package/build/cjs/packageInfo.d.ts +0 -6
- package/build/cjs/packageInfo.js +0 -4
- package/build/cjs/types/augmentRegistry.d.ts +0 -11
- package/build/cjs/types/augmentRegistry.js +0 -3
- package/build/cjs/types/index.d.ts +0 -4
- package/build/cjs/types/index.js +0 -6
- package/build/cjs/types/lookup.d.ts +0 -14
- package/build/cjs/types/lookup.js +0 -2
- package/build/cjs/types/types.d.ts +0 -43
- package/build/cjs/types/types.js +0 -29
- package/build/cjs/util/encodeTypes.d.ts +0 -11
- package/build/cjs/util/encodeTypes.js +0 -128
- package/build/cjs/util/getTypeDef.d.ts +0 -8
- package/build/cjs/util/getTypeDef.js +0 -195
- package/build/cjs/util/index.d.ts +0 -4
- package/build/cjs/util/index.js +0 -7
- package/build/cjs/util/typeSplit.d.ts +0 -1
- package/build/cjs/util/typeSplit.js +0 -60
- package/build/cjs/util/xcm.d.ts +0 -2
- package/build/cjs/util/xcm.js +0 -9
- package/build/create/class.d.ts +0 -5
- package/build/create/class.js +0 -160
- package/build/create/index.d.ts +0 -2
- package/build/create/index.js +0 -2
- package/build/create/type.d.ts +0 -3
- package/build/create/type.js +0 -63
- package/build/exports.d.ts +0 -2
- package/build/exports.js +0 -2
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -2
- package/build/package.json +0 -290
- package/build/packageDetect.d.ts +0 -1
- package/build/packageDetect.js +0 -4
- package/build/packageInfo.d.ts +0 -6
- package/build/packageInfo.js +0 -1
- package/build/types/augmentRegistry.d.ts +0 -11
- package/build/types/augmentRegistry.js +0 -1
- package/build/types/index.d.ts +0 -4
- package/build/types/index.js +0 -3
- package/build/types/lookup.d.ts +0 -14
- package/build/types/lookup.js +0 -1
- package/build/types/types.d.ts +0 -43
- package/build/types/types.js +0 -26
- package/build/util/encodeTypes.d.ts +0 -11
- package/build/util/encodeTypes.js +0 -123
- package/build/util/getTypeDef.d.ts +0 -8
- package/build/util/getTypeDef.js +0 -192
- package/build/util/index.d.ts +0 -4
- package/build/util/index.js +0 -4
- package/build/util/typeSplit.d.ts +0 -1
- package/build/util/typeSplit.js +0 -57
- package/build/util/xcm.d.ts +0 -2
- package/build/util/xcm.js +0 -5
- package/build-deno/README.md +0 -3
- package/build-deno/bundle.ts +0 -5
- package/build-deno/create/class.ts +0 -252
- package/build-deno/create/index.ts +0 -3
- package/build-deno/create/type.ts +0 -85
- package/build-deno/exports.ts +0 -3
- package/build-deno/index.ts +0 -4
- package/build-deno/mod.ts +0 -2
- package/build-deno/packageDetect.ts +0 -8
- package/build-deno/packageInfo.ts +0 -3
- package/build-deno/types/augmentRegistry.ts +0 -15
- package/build-deno/types/index.ts +0 -7
- package/build-deno/types/lookup.ts +0 -16
- package/build-deno/types/types.ts +0 -45
- package/build-deno/util/encodeTypes.ts +0 -201
- package/build-deno/util/getTypeDef.ts +0 -267
- package/build-deno/util/index.ts +0 -5
- package/build-deno/util/typeSplit.ts +0 -53
- package/build-deno/util/xcm.ts +0 -10
- package/build-tsc/bundle.d.ts +0 -3
- package/build-tsc/create/class.d.ts +0 -5
- package/build-tsc/create/index.d.ts +0 -2
- package/build-tsc/create/type.d.ts +0 -3
- package/build-tsc/exports.d.ts +0 -2
- package/build-tsc/index.d.ts +0 -2
- package/build-tsc/packageDetect.d.ts +0 -1
- package/build-tsc/packageInfo.d.ts +0 -6
- package/build-tsc/types/augmentRegistry.d.ts +0 -11
- package/build-tsc/types/index.d.ts +0 -4
- package/build-tsc/types/lookup.d.ts +0 -14
- package/build-tsc/types/types.d.ts +0 -43
- package/build-tsc/util/encodeTypes.d.ts +0 -11
- package/build-tsc/util/getTypeDef.d.ts +0 -8
- package/build-tsc/util/index.d.ts +0 -4
- package/build-tsc/util/typeSplit.d.ts +0 -1
- package/build-tsc/util/xcm.d.ts +0 -2
- package/build-tsc-cjs/bundle.js +0 -9
- package/build-tsc-cjs/create/class.js +0 -165
- package/build-tsc-cjs/create/index.js +0 -5
- package/build-tsc-cjs/create/type.js +0 -66
- package/build-tsc-cjs/exports.js +0 -5
- package/build-tsc-cjs/index.js +0 -5
- package/build-tsc-cjs/packageDetect.js +0 -6
- package/build-tsc-cjs/packageInfo.js +0 -4
- package/build-tsc-cjs/types/augmentRegistry.js +0 -3
- package/build-tsc-cjs/types/index.js +0 -6
- package/build-tsc-cjs/types/lookup.js +0 -2
- package/build-tsc-cjs/types/types.js +0 -29
- package/build-tsc-cjs/util/encodeTypes.js +0 -128
- package/build-tsc-cjs/util/getTypeDef.js +0 -195
- package/build-tsc-cjs/util/index.js +0 -7
- package/build-tsc-cjs/util/typeSplit.js +0 -60
- package/build-tsc-cjs/util/xcm.js +0 -9
- package/build-tsc-esm/bundle.js +0 -3
- package/build-tsc-esm/create/class.js +0 -160
- package/build-tsc-esm/create/index.js +0 -2
- package/build-tsc-esm/create/type.js +0 -63
- package/build-tsc-esm/exports.js +0 -2
- package/build-tsc-esm/index.js +0 -2
- package/build-tsc-esm/packageDetect.js +0 -4
- package/build-tsc-esm/packageInfo.js +0 -1
- package/build-tsc-esm/types/augmentRegistry.js +0 -1
- package/build-tsc-esm/types/index.js +0 -3
- package/build-tsc-esm/types/lookup.js +0 -1
- package/build-tsc-esm/types/types.js +0 -26
- package/build-tsc-esm/util/encodeTypes.js +0 -123
- package/build-tsc-esm/util/getTypeDef.js +0 -192
- package/build-tsc-esm/util/index.js +0 -4
- package/build-tsc-esm/util/typeSplit.js +0 -57
- package/build-tsc-esm/util/xcm.js +0 -5
- package/src/bundle.ts +0 -9
- package/src/create/class.ts +0 -257
- package/src/create/index.ts +0 -5
- package/src/create/type.ts +0 -94
- package/src/exports.ts +0 -6
- package/src/index.ts +0 -6
- package/src/mod.ts +0 -4
- package/src/packageDetect.ts +0 -12
- package/src/packageInfo.ts +0 -6
- package/src/types/augmentRegistry.ts +0 -19
- package/src/types/index.ts +0 -11
- package/src/types/lookup.ts +0 -21
- package/src/types/types.ts +0 -47
- package/src/util/encodeTypes.spec.ts +0 -217
- package/src/util/encodeTypes.ts +0 -205
- package/src/util/getTypeDef.spec.ts +0 -704
- package/src/util/getTypeDef.ts +0 -279
- package/src/util/index.ts +0 -7
- package/src/util/typeSplit.spec.ts +0 -50
- package/src/util/typeSplit.ts +0 -56
- package/src/util/xcm.ts +0 -12
- package/tsconfig.build.json +0 -15
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -17
- package/tsconfig.spec.tsbuildinfo +0 -1
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTypeUnsafe = createTypeUnsafe;
|
|
4
|
-
const types_codec_1 = require("@pezkuwi/types-codec");
|
|
5
|
-
const util_1 = require("@pezkuwi/util");
|
|
6
|
-
const class_js_1 = require("./class.js");
|
|
7
|
-
function checkInstance(created, matcher) {
|
|
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
|
-
}
|
|
24
|
-
}
|
|
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
|
-
}
|
|
32
|
-
}
|
|
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;
|
|
45
|
-
}
|
|
46
|
-
function createTypeUnsafe(registry, type, params = [], options = {}) {
|
|
47
|
-
let Clazz = null;
|
|
48
|
-
let firstError = null;
|
|
49
|
-
try {
|
|
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}`);
|
|
55
|
-
}
|
|
56
|
-
if (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
|
-
}
|
package/build-tsc-cjs/exports.js
DELETED
package/build-tsc-cjs/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const packageInfo_1 = require("@pezkuwi/types-codec/packageInfo");
|
|
4
|
-
const util_1 = require("@pezkuwi/util");
|
|
5
|
-
const packageInfo_js_1 = require("./packageInfo.js");
|
|
6
|
-
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_1.packageInfo]);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeDefInfo = void 0;
|
|
4
|
-
var TypeDefInfo;
|
|
5
|
-
(function (TypeDefInfo) {
|
|
6
|
-
TypeDefInfo[TypeDefInfo["BTreeMap"] = 0] = "BTreeMap";
|
|
7
|
-
TypeDefInfo[TypeDefInfo["BTreeSet"] = 1] = "BTreeSet";
|
|
8
|
-
TypeDefInfo[TypeDefInfo["Compact"] = 2] = "Compact";
|
|
9
|
-
TypeDefInfo[TypeDefInfo["DoNotConstruct"] = 3] = "DoNotConstruct";
|
|
10
|
-
TypeDefInfo[TypeDefInfo["Enum"] = 4] = "Enum";
|
|
11
|
-
TypeDefInfo[TypeDefInfo["HashMap"] = 5] = "HashMap";
|
|
12
|
-
TypeDefInfo[TypeDefInfo["Int"] = 6] = "Int";
|
|
13
|
-
TypeDefInfo[TypeDefInfo["Linkage"] = 7] = "Linkage";
|
|
14
|
-
TypeDefInfo[TypeDefInfo["Null"] = 8] = "Null";
|
|
15
|
-
TypeDefInfo[TypeDefInfo["Option"] = 9] = "Option";
|
|
16
|
-
TypeDefInfo[TypeDefInfo["Plain"] = 10] = "Plain";
|
|
17
|
-
TypeDefInfo[TypeDefInfo["Range"] = 11] = "Range";
|
|
18
|
-
TypeDefInfo[TypeDefInfo["RangeInclusive"] = 12] = "RangeInclusive";
|
|
19
|
-
TypeDefInfo[TypeDefInfo["Result"] = 13] = "Result";
|
|
20
|
-
TypeDefInfo[TypeDefInfo["Set"] = 14] = "Set";
|
|
21
|
-
TypeDefInfo[TypeDefInfo["Si"] = 15] = "Si";
|
|
22
|
-
TypeDefInfo[TypeDefInfo["Struct"] = 16] = "Struct";
|
|
23
|
-
TypeDefInfo[TypeDefInfo["Tuple"] = 17] = "Tuple";
|
|
24
|
-
TypeDefInfo[TypeDefInfo["UInt"] = 18] = "UInt";
|
|
25
|
-
TypeDefInfo[TypeDefInfo["Vec"] = 19] = "Vec";
|
|
26
|
-
TypeDefInfo[TypeDefInfo["VecFixed"] = 20] = "VecFixed";
|
|
27
|
-
TypeDefInfo[TypeDefInfo["WrapperKeepOpaque"] = 21] = "WrapperKeepOpaque";
|
|
28
|
-
TypeDefInfo[TypeDefInfo["WrapperOpaque"] = 22] = "WrapperOpaque";
|
|
29
|
-
})(TypeDefInfo || (exports.TypeDefInfo = TypeDefInfo = {}));
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.paramsNotation = paramsNotation;
|
|
4
|
-
exports.encodeTypeDef = encodeTypeDef;
|
|
5
|
-
exports.withTypeString = withTypeString;
|
|
6
|
-
const util_1 = require("@pezkuwi/util");
|
|
7
|
-
const index_js_1 = require("../types/index.js");
|
|
8
|
-
const stringIdentity = (value) => value.toString();
|
|
9
|
-
const INFO_WRAP = ['BTreeMap', 'BTreeSet', 'Compact', 'HashMap', 'Option', 'Result', 'Vec'];
|
|
10
|
-
function paramsNotation(outer, inner, transform = stringIdentity) {
|
|
11
|
-
return `${outer}${inner
|
|
12
|
-
? `<${(Array.isArray(inner) ? inner : [inner]).map(transform).join(', ')}>`
|
|
13
|
-
: ''}`;
|
|
14
|
-
}
|
|
15
|
-
function encodeWithParams(registry, typeDef, outer) {
|
|
16
|
-
const { info, sub } = typeDef;
|
|
17
|
-
switch (info) {
|
|
18
|
-
case index_js_1.TypeDefInfo.BTreeMap:
|
|
19
|
-
case index_js_1.TypeDefInfo.BTreeSet:
|
|
20
|
-
case index_js_1.TypeDefInfo.Compact:
|
|
21
|
-
case index_js_1.TypeDefInfo.HashMap:
|
|
22
|
-
case index_js_1.TypeDefInfo.Linkage:
|
|
23
|
-
case index_js_1.TypeDefInfo.Option:
|
|
24
|
-
case index_js_1.TypeDefInfo.Range:
|
|
25
|
-
case index_js_1.TypeDefInfo.RangeInclusive:
|
|
26
|
-
case index_js_1.TypeDefInfo.Result:
|
|
27
|
-
case index_js_1.TypeDefInfo.Vec:
|
|
28
|
-
case index_js_1.TypeDefInfo.WrapperKeepOpaque:
|
|
29
|
-
case index_js_1.TypeDefInfo.WrapperOpaque:
|
|
30
|
-
return paramsNotation(outer, sub, (p) => encodeTypeDef(registry, p));
|
|
31
|
-
}
|
|
32
|
-
throw new Error(`Unable to encode ${(0, util_1.stringify)(typeDef)} with params`);
|
|
33
|
-
}
|
|
34
|
-
function encodeSubTypes(registry, sub, asEnum, extra) {
|
|
35
|
-
const names = sub.map(({ name }) => name);
|
|
36
|
-
if (!names.every((n) => !!n)) {
|
|
37
|
-
throw new Error(`Subtypes does not have consistent names, ${names.join(', ')}`);
|
|
38
|
-
}
|
|
39
|
-
const inner = (0, util_1.objectSpread)({}, extra);
|
|
40
|
-
for (let i = 0, count = sub.length; i < count; i++) {
|
|
41
|
-
const def = sub[i];
|
|
42
|
-
if (!def.name) {
|
|
43
|
-
throw new Error(`No name found in ${(0, util_1.stringify)(def)}`);
|
|
44
|
-
}
|
|
45
|
-
inner[def.name] = encodeTypeDef(registry, def);
|
|
46
|
-
}
|
|
47
|
-
return (0, util_1.stringify)(asEnum
|
|
48
|
-
? { _enum: inner }
|
|
49
|
-
: inner);
|
|
50
|
-
}
|
|
51
|
-
const encoders = {
|
|
52
|
-
[index_js_1.TypeDefInfo.BTreeMap]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'BTreeMap'),
|
|
53
|
-
[index_js_1.TypeDefInfo.BTreeSet]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'BTreeSet'),
|
|
54
|
-
[index_js_1.TypeDefInfo.Compact]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Compact'),
|
|
55
|
-
[index_js_1.TypeDefInfo.DoNotConstruct]: (registry, { displayName, lookupIndex, lookupName }) => `DoNotConstruct<${lookupName || displayName || ((0, util_1.isUndefined)(lookupIndex) ? 'Unknown' : registry.createLookupType(lookupIndex))}>`,
|
|
56
|
-
[index_js_1.TypeDefInfo.Enum]: (registry, { sub }) => {
|
|
57
|
-
if (!Array.isArray(sub)) {
|
|
58
|
-
throw new Error('Unable to encode Enum type');
|
|
59
|
-
}
|
|
60
|
-
// c-like enums have all Null entries
|
|
61
|
-
// TODO We need to take the disciminant into account and auto-add empty entries
|
|
62
|
-
return sub.every(({ type }) => type === 'Null')
|
|
63
|
-
? (0, util_1.stringify)({ _enum: sub.map(({ name }, index) => `${name || `Empty${index}`}`) })
|
|
64
|
-
: encodeSubTypes(registry, sub, true);
|
|
65
|
-
},
|
|
66
|
-
[index_js_1.TypeDefInfo.HashMap]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'HashMap'),
|
|
67
|
-
[index_js_1.TypeDefInfo.Int]: (_registry, { length = 32 }) => `Int<${length}>`,
|
|
68
|
-
[index_js_1.TypeDefInfo.Linkage]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Linkage'),
|
|
69
|
-
[index_js_1.TypeDefInfo.Null]: (_registry, _typeDef) => 'Null',
|
|
70
|
-
[index_js_1.TypeDefInfo.Option]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Option'),
|
|
71
|
-
[index_js_1.TypeDefInfo.Plain]: (_registry, { displayName, type }) => displayName || type,
|
|
72
|
-
[index_js_1.TypeDefInfo.Range]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Range'),
|
|
73
|
-
[index_js_1.TypeDefInfo.RangeInclusive]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'RangeInclusive'),
|
|
74
|
-
[index_js_1.TypeDefInfo.Result]: (registry, typeDef) => encodeWithParams(registry, typeDef, 'Result'),
|
|
75
|
-
[index_js_1.TypeDefInfo.Set]: (_registry, { length = 8, sub }) => {
|
|
76
|
-
if (!Array.isArray(sub)) {
|
|
77
|
-
throw new Error('Unable to encode Set type');
|
|
78
|
-
}
|
|
79
|
-
return (0, util_1.stringify)({
|
|
80
|
-
_set: sub.reduce((all, { index, name }, count) => (0, util_1.objectSpread)(all, { [`${name || `Unknown${index || count}`}`]: index || count }), { _bitLength: length || 8 })
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
[index_js_1.TypeDefInfo.Si]: (_registry, { lookupName, type }) => lookupName || type,
|
|
84
|
-
[index_js_1.TypeDefInfo.Struct]: (registry, { alias, sub }) => {
|
|
85
|
-
if (!Array.isArray(sub)) {
|
|
86
|
-
throw new Error('Unable to encode Struct type');
|
|
87
|
-
}
|
|
88
|
-
return encodeSubTypes(registry, sub, false, alias
|
|
89
|
-
? {
|
|
90
|
-
_alias: [...alias.entries()].reduce((all, [k, v]) => (0, util_1.objectSpread)(all, { [k]: v }), {})
|
|
91
|
-
}
|
|
92
|
-
: {});
|
|
93
|
-
},
|
|
94
|
-
[index_js_1.TypeDefInfo.Tuple]: (registry, { sub }) => {
|
|
95
|
-
if (!Array.isArray(sub)) {
|
|
96
|
-
throw new Error('Unable to encode Tuple type');
|
|
97
|
-
}
|
|
98
|
-
return `(${sub.map((type) => encodeTypeDef(registry, type)).join(',')})`;
|
|
99
|
-
},
|
|
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
|
-
if (!(0, util_1.isNumber)(length) || !sub || Array.isArray(sub)) {
|
|
104
|
-
throw new Error('Unable to encode VecFixed type');
|
|
105
|
-
}
|
|
106
|
-
return `[${sub.type};${length}]`;
|
|
107
|
-
},
|
|
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
|
-
};
|
|
111
|
-
function encodeType(registry, typeDef, withLookup = true) {
|
|
112
|
-
return withLookup && typeDef.lookupName
|
|
113
|
-
? typeDef.lookupName
|
|
114
|
-
: encoders[typeDef.info](registry, typeDef);
|
|
115
|
-
}
|
|
116
|
-
function encodeTypeDef(registry, typeDef) {
|
|
117
|
-
// In the case of contracts we do have the unfortunate situation where the displayName would
|
|
118
|
-
// refer to "Option" when it is an option. For these, string it out, only using when actually
|
|
119
|
-
// not a top-level element to be used
|
|
120
|
-
return (typeDef.displayName && !INFO_WRAP.some((i) => typeDef.displayName === i))
|
|
121
|
-
? typeDef.displayName
|
|
122
|
-
: encodeType(registry, typeDef);
|
|
123
|
-
}
|
|
124
|
-
function withTypeString(registry, typeDef) {
|
|
125
|
-
return (0, util_1.objectSpread)({}, typeDef, {
|
|
126
|
-
type: encodeType(registry, typeDef, false)
|
|
127
|
-
});
|
|
128
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTypeDef = getTypeDef;
|
|
4
|
-
const types_codec_1 = require("@pezkuwi/types-codec");
|
|
5
|
-
const util_1 = require("@pezkuwi/util");
|
|
6
|
-
const index_js_1 = require("../types/index.js");
|
|
7
|
-
const typeSplit_js_1 = require("./typeSplit.js");
|
|
8
|
-
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
|
9
|
-
function getTypeString(typeOrObj) {
|
|
10
|
-
return (0, util_1.isString)(typeOrObj)
|
|
11
|
-
? typeOrObj.toString()
|
|
12
|
-
: (0, util_1.stringify)(typeOrObj);
|
|
13
|
-
}
|
|
14
|
-
function isRustEnum(details) {
|
|
15
|
-
const values = Object.values(details);
|
|
16
|
-
if (values.some((v) => (0, util_1.isNumber)(v))) {
|
|
17
|
-
if (!values.every((v) => (0, util_1.isNumber)(v) && v >= 0 && v <= 255)) {
|
|
18
|
-
throw new Error('Invalid number-indexed enum definition');
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
function _decodeEnum(value, details, count, fallbackType) {
|
|
25
|
-
value.info = index_js_1.TypeDefInfo.Enum;
|
|
26
|
-
value.fallbackType = fallbackType;
|
|
27
|
-
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
|
28
|
-
if (Array.isArray(details)) {
|
|
29
|
-
value.sub = details.map((name, index) => ({
|
|
30
|
-
index,
|
|
31
|
-
info: index_js_1.TypeDefInfo.Plain,
|
|
32
|
-
name,
|
|
33
|
-
type: 'Null'
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
else if (isRustEnum(details)) {
|
|
37
|
-
value.sub = Object.entries(details).map(([name, typeOrObj], index) => (0, util_1.objectSpread)({}, getTypeDef(getTypeString(typeOrObj || 'Null'), { name }, count), { index }));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
value.sub = Object.entries(details).map(([name, index]) => ({
|
|
41
|
-
index,
|
|
42
|
-
info: index_js_1.TypeDefInfo.Plain,
|
|
43
|
-
name,
|
|
44
|
-
type: 'Null'
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
function _decodeSet(value, details, fallbackType) {
|
|
50
|
-
value.info = index_js_1.TypeDefInfo.Set;
|
|
51
|
-
value.fallbackType = fallbackType;
|
|
52
|
-
value.length = details._bitLength;
|
|
53
|
-
value.sub = Object
|
|
54
|
-
.entries(details)
|
|
55
|
-
.filter(([name]) => !name.startsWith('_'))
|
|
56
|
-
.map(([name, index]) => ({
|
|
57
|
-
index,
|
|
58
|
-
info: index_js_1.TypeDefInfo.Plain,
|
|
59
|
-
name,
|
|
60
|
-
type: 'Null'
|
|
61
|
-
}));
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
function _decodeStruct(value, type, _, count) {
|
|
65
|
-
const parsed = JSON.parse(type);
|
|
66
|
-
const keys = Object.keys(parsed);
|
|
67
|
-
if (parsed._enum) {
|
|
68
|
-
return _decodeEnum(value, parsed._enum, count, parsed._fallback);
|
|
69
|
-
}
|
|
70
|
-
else if (parsed._set) {
|
|
71
|
-
return _decodeSet(value, parsed._set, parsed._fallback);
|
|
72
|
-
}
|
|
73
|
-
value.alias = parsed._alias
|
|
74
|
-
? new Map(Object.entries(parsed._alias))
|
|
75
|
-
: undefined;
|
|
76
|
-
value.fallbackType = parsed._fallback;
|
|
77
|
-
value.sub = keys
|
|
78
|
-
.filter((name) => !KNOWN_INTERNALS.includes(name))
|
|
79
|
-
.map((name) => getTypeDef(getTypeString(parsed[name]), { name }, count));
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
function _decodeFixedVec(value, type, _, count) {
|
|
83
|
-
const max = type.length - 1;
|
|
84
|
-
let index = -1;
|
|
85
|
-
let inner = 0;
|
|
86
|
-
for (let i = 1; (i < max) && (index === -1); i++) {
|
|
87
|
-
switch (type[i]) {
|
|
88
|
-
case ';': {
|
|
89
|
-
if (inner === 0) {
|
|
90
|
-
index = i;
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case '[':
|
|
95
|
-
case '(':
|
|
96
|
-
case '<':
|
|
97
|
-
inner++;
|
|
98
|
-
break;
|
|
99
|
-
case ']':
|
|
100
|
-
case ')':
|
|
101
|
-
case '>':
|
|
102
|
-
inner--;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (index === -1) {
|
|
107
|
-
throw new Error(`${type}: Unable to extract location of ';'`);
|
|
108
|
-
}
|
|
109
|
-
const vecType = type.substring(1, index);
|
|
110
|
-
const [strLength, displayName] = type.substring(index + 1, max).split(';');
|
|
111
|
-
const length = parseInt(strLength.trim(), 10);
|
|
112
|
-
if (length > 2048) {
|
|
113
|
-
throw new Error(`${type}: Only support for [Type; <length>], where length <= 2048`);
|
|
114
|
-
}
|
|
115
|
-
value.displayName = displayName;
|
|
116
|
-
value.length = length;
|
|
117
|
-
value.sub = getTypeDef(vecType, {}, count);
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
function _decodeTuple(value, _, subType, count) {
|
|
121
|
-
value.sub = subType.length === 0
|
|
122
|
-
? []
|
|
123
|
-
: (0, typeSplit_js_1.typeSplit)(subType).map((inner) => getTypeDef(inner, {}, count));
|
|
124
|
-
return value;
|
|
125
|
-
}
|
|
126
|
-
function _decodeAnyInt(value, type, _, clazz) {
|
|
127
|
-
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
|
|
128
|
-
const length = parseInt(strLength.trim(), 10);
|
|
129
|
-
if ((length > 8192) || (length % 8)) {
|
|
130
|
-
throw new Error(`${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
|
131
|
-
}
|
|
132
|
-
value.displayName = displayName;
|
|
133
|
-
value.length = length;
|
|
134
|
-
return value;
|
|
135
|
-
}
|
|
136
|
-
function _decodeInt(value, type, subType) {
|
|
137
|
-
return _decodeAnyInt(value, type, subType, 'Int');
|
|
138
|
-
}
|
|
139
|
-
function _decodeUInt(value, type, subType) {
|
|
140
|
-
return _decodeAnyInt(value, type, subType, 'UInt');
|
|
141
|
-
}
|
|
142
|
-
function _decodeDoNotConstruct(value, type, _) {
|
|
143
|
-
const NAME_LENGTH = 'DoNotConstruct'.length;
|
|
144
|
-
value.displayName = type.substring(NAME_LENGTH + 1, type.length - 1);
|
|
145
|
-
return value;
|
|
146
|
-
}
|
|
147
|
-
function hasWrapper(type, [start, end]) {
|
|
148
|
-
return (type.startsWith(start)) && (type.slice(-1 * end.length) === end);
|
|
149
|
-
}
|
|
150
|
-
const nestedExtraction = [
|
|
151
|
-
['[', ']', index_js_1.TypeDefInfo.VecFixed, _decodeFixedVec],
|
|
152
|
-
['{', '}', index_js_1.TypeDefInfo.Struct, _decodeStruct],
|
|
153
|
-
['(', ')', index_js_1.TypeDefInfo.Tuple, _decodeTuple],
|
|
154
|
-
// the inner for these are the same as tuple, multiple values
|
|
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
|
-
];
|
|
162
|
-
const wrappedExtraction = [
|
|
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
|
-
];
|
|
174
|
-
function extractSubType(type, [start, end]) {
|
|
175
|
-
return type.substring(start.length, type.length - end.length);
|
|
176
|
-
}
|
|
177
|
-
function getTypeDef(_type, { displayName, name } = {}, count = 0) {
|
|
178
|
-
// create the type via Type, allowing types to be sanitized
|
|
179
|
-
const type = (0, types_codec_1.sanitize)(_type);
|
|
180
|
-
const value = { displayName, info: index_js_1.TypeDefInfo.Plain, name, type };
|
|
181
|
-
if (++count > 64) {
|
|
182
|
-
throw new Error('getTypeDef: Maximum nested limit reached');
|
|
183
|
-
}
|
|
184
|
-
const nested = nestedExtraction.find((nested) => hasWrapper(type, nested));
|
|
185
|
-
if (nested) {
|
|
186
|
-
value.info = nested[2];
|
|
187
|
-
return nested[3](value, type, extractSubType(type, nested), count);
|
|
188
|
-
}
|
|
189
|
-
const wrapped = wrappedExtraction.find((wrapped) => hasWrapper(type, wrapped));
|
|
190
|
-
if (wrapped) {
|
|
191
|
-
value.info = wrapped[2];
|
|
192
|
-
value.sub = getTypeDef(extractSubType(type, wrapped), {}, count);
|
|
193
|
-
}
|
|
194
|
-
return value;
|
|
195
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
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);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typeSplit = typeSplit;
|
|
4
|
-
function typeSplit(type) {
|
|
5
|
-
const result = [];
|
|
6
|
-
// these are the depths of the various tokens: <, [, {, (
|
|
7
|
-
let c = 0;
|
|
8
|
-
let f = 0;
|
|
9
|
-
let s = 0;
|
|
10
|
-
let t = 0;
|
|
11
|
-
// current start position
|
|
12
|
-
let start = 0;
|
|
13
|
-
for (let i = 0, count = type.length; i < count; i++) {
|
|
14
|
-
switch (type[i]) {
|
|
15
|
-
// if we are not nested, add the type
|
|
16
|
-
case ',': {
|
|
17
|
-
if (!(c || f || s || t)) {
|
|
18
|
-
result.push(type.substring(start, i).trim());
|
|
19
|
-
start = i + 1;
|
|
20
|
-
}
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
// adjust compact/vec (and friends) depth
|
|
24
|
-
case '<':
|
|
25
|
-
c++;
|
|
26
|
-
break;
|
|
27
|
-
case '>':
|
|
28
|
-
c--;
|
|
29
|
-
break;
|
|
30
|
-
// adjust fixed vec depths
|
|
31
|
-
case '[':
|
|
32
|
-
f++;
|
|
33
|
-
break;
|
|
34
|
-
case ']':
|
|
35
|
-
f--;
|
|
36
|
-
break;
|
|
37
|
-
// adjust struct depth
|
|
38
|
-
case '{':
|
|
39
|
-
s++;
|
|
40
|
-
break;
|
|
41
|
-
case '}':
|
|
42
|
-
s--;
|
|
43
|
-
break;
|
|
44
|
-
// adjust tuple depth
|
|
45
|
-
case '(':
|
|
46
|
-
t++;
|
|
47
|
-
break;
|
|
48
|
-
case ')':
|
|
49
|
-
t--;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// ensure we have all the terminators taken care of
|
|
54
|
-
if (c || f || s || t) {
|
|
55
|
-
throw new Error(`Invalid definition (missing terminators) found in ${type}`);
|
|
56
|
-
}
|
|
57
|
-
// the final leg of the journey
|
|
58
|
-
result.push(type.substring(start, type.length).trim());
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XCM_MAPPINGS = void 0;
|
|
4
|
-
exports.mapXcmTypes = mapXcmTypes;
|
|
5
|
-
const util_1 = require("@pezkuwi/util");
|
|
6
|
-
exports.XCM_MAPPINGS = ['AssetInstance', 'Fungibility', 'Junction', 'Junctions', 'MultiAsset', 'MultiAssetFilter', 'MultiLocation', 'Response', 'WildFungibility', 'WildMultiAsset', 'Xcm', 'XcmError'];
|
|
7
|
-
function mapXcmTypes(version) {
|
|
8
|
-
return exports.XCM_MAPPINGS.reduce((all, key) => (0, util_1.objectSpread)(all, { [key]: `${key}${version}` }), {});
|
|
9
|
-
}
|
package/build-tsc-esm/bundle.js
DELETED