@pezkuwi/types-create 16.5.20 → 16.5.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/package.json +9 -9
  2. package/build/LICENSE +0 -201
  3. package/build/README.md +0 -3
  4. package/build/bundle.js +0 -3
  5. package/build/cjs/bundle.d.ts +0 -3
  6. package/build/cjs/bundle.js +0 -9
  7. package/build/cjs/create/class.js +0 -165
  8. package/build/cjs/create/index.js +0 -5
  9. package/build/cjs/create/type.js +0 -66
  10. package/build/cjs/exports.js +0 -5
  11. package/build/cjs/index.js +0 -5
  12. package/build/cjs/packageInfo.js +0 -4
  13. package/build/cjs/types/augmentRegistry.js +0 -3
  14. package/build/cjs/types/index.js +0 -6
  15. package/build/cjs/types/lookup.js +0 -2
  16. package/build/cjs/types/types.js +0 -29
  17. package/build/cjs/util/encodeTypes.js +0 -128
  18. package/build/cjs/util/getTypeDef.js +0 -195
  19. package/build/cjs/util/index.js +0 -7
  20. package/build/cjs/util/typeSplit.js +0 -60
  21. package/build/cjs/util/xcm.js +0 -9
  22. package/build/create/class.d.ts +0 -5
  23. package/build/create/class.js +0 -160
  24. package/build/create/index.d.ts +0 -2
  25. package/build/create/index.js +0 -2
  26. package/build/create/type.d.ts +0 -3
  27. package/build/create/type.js +0 -63
  28. package/build/exports.d.ts +0 -2
  29. package/build/exports.js +0 -2
  30. package/build/index.d.ts +0 -2
  31. package/build/index.js +0 -2
  32. package/build/package.json +0 -291
  33. package/build/packageDetect.d.ts +0 -1
  34. package/build/packageDetect.js +0 -4
  35. package/build/packageInfo.d.ts +0 -6
  36. package/build/packageInfo.js +0 -1
  37. package/build/types/augmentRegistry.d.ts +0 -11
  38. package/build/types/augmentRegistry.js +0 -1
  39. package/build/types/index.d.ts +0 -4
  40. package/build/types/index.js +0 -3
  41. package/build/types/lookup.d.ts +0 -14
  42. package/build/types/lookup.js +0 -1
  43. package/build/types/types.d.ts +0 -43
  44. package/build/types/types.js +0 -26
  45. package/build/util/encodeTypes.d.ts +0 -11
  46. package/build/util/encodeTypes.js +0 -123
  47. package/build/util/getTypeDef.d.ts +0 -8
  48. package/build/util/getTypeDef.js +0 -192
  49. package/build/util/index.d.ts +0 -4
  50. package/build/util/index.js +0 -4
  51. package/build/util/typeSplit.d.ts +0 -1
  52. package/build/util/typeSplit.js +0 -57
  53. package/build/util/xcm.d.ts +0 -2
  54. package/build/util/xcm.js +0 -5
  55. package/build-deno/README.md +0 -3
  56. package/build-deno/bundle.ts +0 -5
  57. package/build-deno/create/class.ts +0 -252
  58. package/build-deno/create/index.ts +0 -3
  59. package/build-deno/create/type.ts +0 -85
  60. package/build-deno/exports.ts +0 -3
  61. package/build-deno/index.ts +0 -4
  62. package/build-deno/mod.ts +0 -2
  63. package/build-deno/packageDetect.ts +0 -8
  64. package/build-deno/packageInfo.ts +0 -3
  65. package/build-deno/types/augmentRegistry.ts +0 -15
  66. package/build-deno/types/index.ts +0 -7
  67. package/build-deno/types/lookup.ts +0 -16
  68. package/build-deno/types/types.ts +0 -45
  69. package/build-deno/util/encodeTypes.ts +0 -201
  70. package/build-deno/util/getTypeDef.ts +0 -267
  71. package/build-deno/util/index.ts +0 -5
  72. package/build-deno/util/typeSplit.ts +0 -53
  73. package/build-deno/util/xcm.ts +0 -10
  74. package/build-tsc-cjs/packageDetect.js +0 -6
  75. package/src/bundle.ts +0 -9
  76. package/src/create/class.ts +0 -257
  77. package/src/create/index.ts +0 -5
  78. package/src/create/type.ts +0 -94
  79. package/src/exports.ts +0 -6
  80. package/src/index.ts +0 -6
  81. package/src/mod.ts +0 -4
  82. package/src/packageDetect.ts +0 -12
  83. package/src/packageInfo.ts +0 -6
  84. package/src/types/augmentRegistry.ts +0 -19
  85. package/src/types/index.ts +0 -11
  86. package/src/types/lookup.ts +0 -21
  87. package/src/types/types.ts +0 -47
  88. package/src/util/encodeTypes.spec.ts +0 -217
  89. package/src/util/encodeTypes.ts +0 -205
  90. package/src/util/getTypeDef.spec.ts +0 -704
  91. package/src/util/getTypeDef.ts +0 -279
  92. package/src/util/index.ts +0 -7
  93. package/src/util/typeSplit.spec.ts +0 -50
  94. package/src/util/typeSplit.ts +0 -56
  95. package/src/util/xcm.ts +0 -12
  96. package/tsconfig.build.json +0 -15
  97. package/tsconfig.build.tsbuildinfo +0 -1
  98. package/tsconfig.spec.json +0 -17
  99. package/tsconfig.spec.tsbuildinfo +0 -1
  100. /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
  101. /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
  102. /package/{build → cjs}/bundle.d.ts +0 -0
  103. /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
  104. /package/{build-tsc → cjs}/create/class.d.ts +0 -0
  105. /package/{build-tsc-cjs → cjs}/create/class.js +0 -0
  106. /package/{build-tsc → cjs}/create/index.d.ts +0 -0
  107. /package/{build-tsc-cjs → cjs}/create/index.js +0 -0
  108. /package/{build-tsc → cjs}/create/type.d.ts +0 -0
  109. /package/{build-tsc-cjs → cjs}/create/type.js +0 -0
  110. /package/{build-tsc → cjs}/exports.d.ts +0 -0
  111. /package/{build-tsc-cjs → cjs}/exports.js +0 -0
  112. /package/{build-tsc → cjs}/index.d.ts +0 -0
  113. /package/{build-tsc-cjs → cjs}/index.js +0 -0
  114. /package/{build/cjs → cjs}/package.json +0 -0
  115. /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
  116. /package/{build/cjs → cjs}/packageDetect.js +0 -0
  117. /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
  118. /package/{build-tsc-cjs → cjs}/packageInfo.js +0 -0
  119. /package/{build-tsc → cjs}/types/augmentRegistry.d.ts +0 -0
  120. /package/{build-tsc-cjs → cjs}/types/augmentRegistry.js +0 -0
  121. /package/{build-tsc → cjs}/types/index.d.ts +0 -0
  122. /package/{build-tsc-cjs → cjs}/types/index.js +0 -0
  123. /package/{build-tsc → cjs}/types/lookup.d.ts +0 -0
  124. /package/{build-tsc-cjs → cjs}/types/lookup.js +0 -0
  125. /package/{build-tsc → cjs}/types/types.d.ts +0 -0
  126. /package/{build-tsc-cjs → cjs}/types/types.js +0 -0
  127. /package/{build-tsc → cjs}/util/encodeTypes.d.ts +0 -0
  128. /package/{build-tsc-cjs → cjs}/util/encodeTypes.js +0 -0
  129. /package/{build-tsc → cjs}/util/getTypeDef.d.ts +0 -0
  130. /package/{build-tsc-cjs → cjs}/util/getTypeDef.js +0 -0
  131. /package/{build-tsc → cjs}/util/index.d.ts +0 -0
  132. /package/{build-tsc-cjs → cjs}/util/index.js +0 -0
  133. /package/{build-tsc → cjs}/util/typeSplit.d.ts +0 -0
  134. /package/{build-tsc-cjs → cjs}/util/typeSplit.js +0 -0
  135. /package/{build-tsc → cjs}/util/xcm.d.ts +0 -0
  136. /package/{build-tsc-cjs → cjs}/util/xcm.js +0 -0
  137. /package/{build/cjs/create → create}/class.d.ts +0 -0
  138. /package/{build-tsc-esm/create → create}/class.js +0 -0
  139. /package/{build/cjs/create → create}/index.d.ts +0 -0
  140. /package/{build-tsc-esm/create → create}/index.js +0 -0
  141. /package/{build/cjs/create → create}/type.d.ts +0 -0
  142. /package/{build-tsc-esm/create → create}/type.js +0 -0
  143. /package/{build/cjs/exports.d.ts → exports.d.ts} +0 -0
  144. /package/{build-tsc-esm/exports.js → exports.js} +0 -0
  145. /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
  146. /package/{build-tsc-esm/index.js → index.js} +0 -0
  147. /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  148. /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
  149. /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  150. /package/{build-tsc-esm/packageInfo.js → packageInfo.js} +0 -0
  151. /package/{build/cjs/types → types}/augmentRegistry.d.ts +0 -0
  152. /package/{build-tsc-esm/types → types}/augmentRegistry.js +0 -0
  153. /package/{build/cjs/types → types}/index.d.ts +0 -0
  154. /package/{build-tsc-esm/types → types}/index.js +0 -0
  155. /package/{build/cjs/types → types}/lookup.d.ts +0 -0
  156. /package/{build-tsc-esm/types → types}/lookup.js +0 -0
  157. /package/{build/cjs/types → types}/types.d.ts +0 -0
  158. /package/{build-tsc-esm/types → types}/types.js +0 -0
  159. /package/{build/cjs/util → util}/encodeTypes.d.ts +0 -0
  160. /package/{build-tsc-esm/util → util}/encodeTypes.js +0 -0
  161. /package/{build/cjs/util → util}/getTypeDef.d.ts +0 -0
  162. /package/{build-tsc-esm/util → util}/getTypeDef.js +0 -0
  163. /package/{build/cjs/util → util}/index.d.ts +0 -0
  164. /package/{build-tsc-esm/util → util}/index.js +0 -0
  165. /package/{build/cjs/util → util}/typeSplit.d.ts +0 -0
  166. /package/{build-tsc-esm/util → util}/typeSplit.js +0 -0
  167. /package/{build/cjs/util → util}/xcm.d.ts +0 -0
  168. /package/{build-tsc-esm/util → util}/xcm.js +0 -0
@@ -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
- }
@@ -1,5 +0,0 @@
1
- import type { Codec, CodecClass, Registry } from '@pezkuwi/types-codec/types';
2
- import type { TypeDef } from '../types/index.js';
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>;
@@ -1,160 +0,0 @@
1
- import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperKeepOpaque, WrapperOpaque } from '@pezkuwi/types-codec';
2
- import { isNumber, stringify } from '@pezkuwi/util';
3
- import { TypeDefInfo } from '../types/index.js';
4
- import { getTypeDef } from '../util/getTypeDef.js';
5
- function getTypeDefType({ lookupName, type }) {
6
- return lookupName || type;
7
- }
8
- function getSubDefArray(value) {
9
- if (!Array.isArray(value.sub)) {
10
- throw new Error(`Expected subtype as TypeDef[] in ${stringify(value)}`);
11
- }
12
- return value.sub;
13
- }
14
- function getSubDef(value) {
15
- if (!value.sub || Array.isArray(value.sub)) {
16
- throw new Error(`Expected subtype as TypeDef in ${stringify(value)}`);
17
- }
18
- return value.sub;
19
- }
20
- function getSubType(value) {
21
- return getTypeDefType(getSubDef(value));
22
- }
23
- function getTypeClassMap(value) {
24
- const subs = getSubDefArray(value);
25
- const map = {};
26
- for (let i = 0, count = subs.length; i < count; i++) {
27
- const sub = subs[i];
28
- if (!sub.name) {
29
- throw new Error(`No name found in definition ${stringify(sub)}`);
30
- }
31
- map[sub.name] = getTypeDefType(sub);
32
- }
33
- return map;
34
- }
35
- function getTypeClassArray(value) {
36
- return getSubDefArray(value).map(getTypeDefType);
37
- }
38
- function createInt(Clazz, { displayName, length }) {
39
- if (!isNumber(length)) {
40
- throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
41
- }
42
- return Clazz.with(length, displayName);
43
- }
44
- function createHashMap(Clazz, value) {
45
- const [keyType, valueType] = getTypeClassArray(value);
46
- return Clazz.with(keyType, valueType);
47
- }
48
- function createWithSub(Clazz, value) {
49
- return Clazz.with(getSubType(value));
50
- }
51
- const infoMapping = {
52
- [TypeDefInfo.BTreeMap]: (_registry, value) => createHashMap(BTreeMap, value),
53
- [TypeDefInfo.BTreeSet]: (_registry, value) => createWithSub(BTreeSet, value),
54
- [TypeDefInfo.Compact]: (_registry, value) => createWithSub(Compact, value),
55
- [TypeDefInfo.DoNotConstruct]: (_registry, value) => DoNotConstruct.with(value.displayName || value.type),
56
- [TypeDefInfo.Enum]: (_registry, value) => {
57
- const subs = getSubDefArray(value);
58
- return Enum.with(subs.every(({ type }) => type === 'Null')
59
- ? subs.reduce((out, { index, name }, count) => {
60
- if (!name) {
61
- throw new Error('No name found in sub definition');
62
- }
63
- out[name] = index || count;
64
- return out;
65
- }, {})
66
- : getTypeClassMap(value));
67
- },
68
- [TypeDefInfo.HashMap]: (_registry, value) => createHashMap(HashMap, value),
69
- [TypeDefInfo.Int]: (_registry, value) => createInt(Int, value),
70
- // We have circular deps between Linkage & Struct
71
- [TypeDefInfo.Linkage]: (_registry, value) => {
72
- const type = `Option<${getSubType(value)}>`;
73
- // eslint-disable-next-line sort-keys
74
- const Clazz = Struct.with({ previous: type, next: type });
75
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
76
- Clazz.prototype.toRawType = function () {
77
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
78
- return `Linkage<${this.next.toRawType(true)}>`;
79
- };
80
- return Clazz;
81
- },
82
- [TypeDefInfo.Null]: (_registry, _value) => Null,
83
- [TypeDefInfo.Option]: (_registry, value) => {
84
- if (!value.sub || Array.isArray(value.sub)) {
85
- throw new Error('Expected type information for Option');
86
- }
87
- // NOTE This is opt-in (unhandled), not by default
88
- // if (value.sub.type === 'bool') {
89
- // return OptionBool;
90
- // }
91
- return createWithSub(Option, value);
92
- },
93
- [TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
94
- [TypeDefInfo.Range]: (_registry, value) => createWithSub(Range, value),
95
- [TypeDefInfo.RangeInclusive]: (_registry, value) => createWithSub(RangeInclusive, value),
96
- [TypeDefInfo.Result]: (_registry, value) => {
97
- const [Ok, Err] = getTypeClassArray(value);
98
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
99
- return Result.with({ Err, Ok });
100
- },
101
- [TypeDefInfo.Set]: (_registry, value) => CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
102
- if (!name || !isNumber(index)) {
103
- throw new Error('No name found in sub definition');
104
- }
105
- result[name] = index;
106
- return result;
107
- }, {}), value.length),
108
- [TypeDefInfo.Si]: (registry, value) => getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
109
- [TypeDefInfo.Struct]: (_registry, value) => Struct.with(getTypeClassMap(value), value.alias),
110
- [TypeDefInfo.Tuple]: (_registry, value) => Tuple.with(getTypeClassArray(value)),
111
- [TypeDefInfo.UInt]: (_registry, value) => createInt(UInt, value),
112
- [TypeDefInfo.Vec]: (_registry, { sub }) => {
113
- if (!sub || Array.isArray(sub)) {
114
- throw new Error('Expected type information for vector');
115
- }
116
- return (sub.type === 'u8'
117
- ? Bytes
118
- : Vec.with(getTypeDefType(sub)));
119
- },
120
- [TypeDefInfo.VecFixed]: (_registry, { displayName, length, sub }) => {
121
- if (!isNumber(length) || !sub || Array.isArray(sub)) {
122
- throw new Error('Expected length & type information for fixed vector');
123
- }
124
- return (sub.type === 'u8'
125
- ? U8aFixed.with((length * 8), displayName)
126
- : VecFixed.with(getTypeDefType(sub), length));
127
- },
128
- [TypeDefInfo.WrapperKeepOpaque]: (_registry, value) => createWithSub(WrapperKeepOpaque, value),
129
- [TypeDefInfo.WrapperOpaque]: (_registry, value) => createWithSub(WrapperOpaque, value)
130
- };
131
- export function constructTypeClass(registry, typeDef) {
132
- try {
133
- const Type = infoMapping[typeDef.info](registry, typeDef);
134
- if (!Type) {
135
- throw new Error('No class created');
136
- }
137
- // don't clobber any existing
138
- if (!Type.__fallbackType && typeDef.fallbackType) {
139
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
140
- // @ts-ignore ...this is the only place we we actually assign this...
141
- Type.__fallbackType = typeDef.fallbackType;
142
- }
143
- return Type;
144
- }
145
- catch (error) {
146
- throw new Error(`Unable to construct class from ${stringify(typeDef)}: ${error.message}`);
147
- }
148
- }
149
- export function getTypeClass(registry, typeDef) {
150
- return registry.getUnsafe(typeDef.type, false, typeDef);
151
- }
152
- export function createClassUnsafe(registry, type) {
153
- return (
154
- // just retrieve via name, no creation via typeDef
155
- registry.getUnsafe(type) ||
156
- // we don't have an existing type, create the class via typeDef
157
- getTypeClass(registry, registry.isLookupType(type)
158
- ? registry.lookup.getTypeDef(type)
159
- : getTypeDef(type)));
160
- }
@@ -1,2 +0,0 @@
1
- export * from './class.js';
2
- export * from './type.js';
@@ -1,2 +0,0 @@
1
- export * from './class.js';
2
- export * from './type.js';
@@ -1,3 +0,0 @@
1
- import type { Codec, Registry } from '@pezkuwi/types-codec/types';
2
- import type { CreateOptions } from '../types/index.js';
3
- export declare function createTypeUnsafe<T extends Codec = Codec, K extends string = string>(registry: Registry, type: K, params?: unknown[], options?: CreateOptions): T;
@@ -1,63 +0,0 @@
1
- import { Option } from '@pezkuwi/types-codec';
2
- import { isHex, isU8a, u8aEq, u8aToHex, u8aToU8a } from '@pezkuwi/util';
3
- import { createClassUnsafe } from './class.js';
4
- function checkInstance(created, matcher) {
5
- const u8a = created.toU8a();
6
- const rawType = created.toRawType();
7
- const isOk = (
8
- // full match, all ok
9
- u8aEq(u8a, matcher) ||
10
- (
11
- // on a length-prefixed type, just check the actual length
12
- ['Bytes', 'Text', 'Type'].includes(rawType) &&
13
- matcher.length === created.length) ||
14
- (
15
- // when the created is empty and matcher is also empty, let it slide...
16
- created.isEmpty &&
17
- matcher.every((v) => !v)));
18
- if (!isOk) {
19
- throw new Error(`${rawType}:: Decoded input doesn't match input, received ${u8aToHex(matcher, 512)} (${matcher.length} bytes), created ${u8aToHex(u8a, 512)} (${u8a.length} bytes)`);
20
- }
21
- }
22
- function checkPedantic(created, [value]) {
23
- if (isU8a(value)) {
24
- checkInstance(created, value);
25
- }
26
- else if (isHex(value)) {
27
- checkInstance(created, u8aToU8a(value));
28
- }
29
- }
30
- function initType(registry, Type, params = [], { blockHash, isFallback, isOptional, isPedantic } = {}) {
31
- const created = new (isOptional
32
- ? Option.with(Type)
33
- : Type)(registry, ...params);
34
- isPedantic && checkPedantic(created, params);
35
- if (blockHash) {
36
- created.createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]);
37
- }
38
- if (isFallback) {
39
- created.isStorageFallback = true;
40
- }
41
- return created;
42
- }
43
- export function createTypeUnsafe(registry, type, params = [], options = {}) {
44
- let Clazz = null;
45
- let firstError = null;
46
- try {
47
- Clazz = createClassUnsafe(registry, type);
48
- return initType(registry, Clazz, params, options);
49
- }
50
- catch (error) {
51
- firstError = new Error(`createType(${type}):: ${error.message}`);
52
- }
53
- if (Clazz?.__fallbackType) {
54
- try {
55
- Clazz = createClassUnsafe(registry, Clazz.__fallbackType);
56
- return initType(registry, Clazz, params, options);
57
- }
58
- catch {
59
- // swallow, we will throw the first error again
60
- }
61
- }
62
- throw firstError;
63
- }
@@ -1,2 +0,0 @@
1
- export * from './create/index.js';
2
- export * from './util/index.js';
package/build/exports.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './create/index.js';
2
- export * from './util/index.js';
package/build/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import './packageDetect.js';
2
- export * from './bundle.js';
package/build/index.js DELETED
@@ -1,2 +0,0 @@
1
- import './packageDetect.js';
2
- export * from './bundle.js';