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