@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,267 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import type { AnyString } from 'https://deno.land/x/pezkuwi/types-codec/types/index.ts';
|
|
3
|
-
import type { TypeDef } from 'https://deno.land/x/pezkuwi/types-create/types/index.ts';
|
|
4
|
-
|
|
5
|
-
import { sanitize } from 'https://deno.land/x/pezkuwi/types-codec/mod.ts';
|
|
6
|
-
import { isNumber, isString, objectSpread, stringify } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
7
|
-
|
|
8
|
-
import { TypeDefInfo } from '../types/index.ts';
|
|
9
|
-
import { typeSplit } from './typeSplit.ts';
|
|
10
|
-
|
|
11
|
-
interface TypeDefOptions {
|
|
12
|
-
name?: string;
|
|
13
|
-
displayName?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface SetDetails {
|
|
17
|
-
_bitLength: number;
|
|
18
|
-
index: number;
|
|
19
|
-
|
|
20
|
-
[key: string]: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface ParsedDef {
|
|
24
|
-
_alias: string;
|
|
25
|
-
_enum?: string[];
|
|
26
|
-
_fallback?: string;
|
|
27
|
-
_set?: SetDetails;
|
|
28
|
-
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
|
33
|
-
|
|
34
|
-
function getTypeString (typeOrObj: any): string {
|
|
35
|
-
return isString(typeOrObj)
|
|
36
|
-
? typeOrObj.toString()
|
|
37
|
-
: stringify(typeOrObj);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function isRustEnum (details: Record<string, string> | Record<string, number>): details is Record<string, string> {
|
|
41
|
-
const values = Object.values(details);
|
|
42
|
-
|
|
43
|
-
if (values.some((v) => isNumber(v))) {
|
|
44
|
-
if (!values.every((v) => isNumber(v) && v >= 0 && v <= 255)) {
|
|
45
|
-
throw new Error('Invalid number-indexed enum definition');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function _decodeEnum (value: TypeDef, details: string[] | Record<string, string> | Record<string, number>, count: number, fallbackType?: string): TypeDef {
|
|
55
|
-
value.info = TypeDefInfo.Enum;
|
|
56
|
-
value.fallbackType = fallbackType;
|
|
57
|
-
|
|
58
|
-
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
|
59
|
-
if (Array.isArray(details)) {
|
|
60
|
-
value.sub = details.map((name, index): TypeDef => ({
|
|
61
|
-
index,
|
|
62
|
-
info: TypeDefInfo.Plain,
|
|
63
|
-
name,
|
|
64
|
-
type: 'Null'
|
|
65
|
-
}));
|
|
66
|
-
} else if (isRustEnum(details)) {
|
|
67
|
-
value.sub = Object.entries(details).map(([name, typeOrObj], index): TypeDef =>
|
|
68
|
-
objectSpread({}, getTypeDef(getTypeString(typeOrObj || 'Null'), { name }, count), { index })
|
|
69
|
-
);
|
|
70
|
-
} else {
|
|
71
|
-
value.sub = Object.entries(details).map(([name, index]): TypeDef => ({
|
|
72
|
-
index,
|
|
73
|
-
info: TypeDefInfo.Plain,
|
|
74
|
-
name,
|
|
75
|
-
type: 'Null'
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function _decodeSet (value: TypeDef, details: SetDetails, fallbackType: string | undefined): TypeDef {
|
|
83
|
-
value.info = TypeDefInfo.Set;
|
|
84
|
-
value.fallbackType = fallbackType;
|
|
85
|
-
value.length = details._bitLength;
|
|
86
|
-
value.sub = Object
|
|
87
|
-
.entries(details)
|
|
88
|
-
.filter(([name]): boolean => !name.startsWith('_'))
|
|
89
|
-
.map(([name, index]): TypeDef => ({
|
|
90
|
-
index,
|
|
91
|
-
info: TypeDefInfo.Plain,
|
|
92
|
-
name,
|
|
93
|
-
type: 'Null'
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function _decodeStruct (value: TypeDef, type: string, _: string, count: number): TypeDef {
|
|
100
|
-
const parsed = JSON.parse(type) as ParsedDef;
|
|
101
|
-
const keys = Object.keys(parsed);
|
|
102
|
-
|
|
103
|
-
if (parsed._enum) {
|
|
104
|
-
return _decodeEnum(value, parsed._enum, count, parsed._fallback);
|
|
105
|
-
} else if (parsed._set) {
|
|
106
|
-
return _decodeSet(value, parsed._set, parsed._fallback);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
value.alias = parsed._alias
|
|
110
|
-
? new Map(Object.entries(parsed._alias))
|
|
111
|
-
: undefined;
|
|
112
|
-
value.fallbackType = parsed._fallback;
|
|
113
|
-
value.sub = keys
|
|
114
|
-
.filter((name) => !KNOWN_INTERNALS.includes(name))
|
|
115
|
-
.map((name) =>
|
|
116
|
-
getTypeDef(getTypeString(parsed[name]), { name }, count)
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return value;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function _decodeFixedVec (value: TypeDef, type: string, _: string, count: number): TypeDef {
|
|
123
|
-
const max = type.length - 1;
|
|
124
|
-
let index = -1;
|
|
125
|
-
let inner = 0;
|
|
126
|
-
|
|
127
|
-
for (let i = 1; (i < max) && (index === -1); i++) {
|
|
128
|
-
switch (type[i]) {
|
|
129
|
-
case ';': {
|
|
130
|
-
if (inner === 0) {
|
|
131
|
-
index = i;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
case '[':
|
|
138
|
-
case '(':
|
|
139
|
-
case '<':
|
|
140
|
-
inner++;
|
|
141
|
-
break;
|
|
142
|
-
|
|
143
|
-
case ']':
|
|
144
|
-
case ')':
|
|
145
|
-
case '>':
|
|
146
|
-
inner--;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (index === -1) {
|
|
152
|
-
throw new Error(`${type}: Unable to extract location of ';'`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const vecType = type.substring(1, index);
|
|
156
|
-
const [strLength, displayName] = type.substring(index + 1, max).split(';');
|
|
157
|
-
const length = parseInt(strLength.trim(), 10);
|
|
158
|
-
|
|
159
|
-
if (length > 2048) {
|
|
160
|
-
throw new Error(`${type}: Only support for [Type; <length>], where length <= 2048`);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
value.displayName = displayName;
|
|
164
|
-
value.length = length;
|
|
165
|
-
value.sub = getTypeDef(vecType, {}, count);
|
|
166
|
-
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function _decodeTuple (value: TypeDef, _: string, subType: string, count: number): TypeDef {
|
|
171
|
-
value.sub = subType.length === 0
|
|
172
|
-
? []
|
|
173
|
-
: typeSplit(subType).map((inner) => getTypeDef(inner, {}, count));
|
|
174
|
-
|
|
175
|
-
return value;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function _decodeAnyInt (value: TypeDef, type: string, _: string, clazz: 'Int' | 'UInt'): TypeDef {
|
|
179
|
-
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
|
|
180
|
-
const length = parseInt(strLength.trim(), 10);
|
|
181
|
-
|
|
182
|
-
if ((length > 8192) || (length % 8)) {
|
|
183
|
-
throw new Error(`${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
value.displayName = displayName;
|
|
187
|
-
value.length = length;
|
|
188
|
-
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function _decodeInt (value: TypeDef, type: string, subType: string): TypeDef {
|
|
193
|
-
return _decodeAnyInt(value, type, subType, 'Int');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function _decodeUInt (value: TypeDef, type: string, subType: string): TypeDef {
|
|
197
|
-
return _decodeAnyInt(value, type, subType, 'UInt');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function _decodeDoNotConstruct (value: TypeDef, type: string, _: string): TypeDef {
|
|
201
|
-
const NAME_LENGTH = 'DoNotConstruct'.length;
|
|
202
|
-
|
|
203
|
-
value.displayName = type.substring(NAME_LENGTH + 1, type.length - 1);
|
|
204
|
-
|
|
205
|
-
return value;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, any?]): boolean {
|
|
209
|
-
return (type.startsWith(start)) && (type.slice(-1 * end.length) === end);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: string, subType: string, count: number) => TypeDef][] = [
|
|
213
|
-
['[', ']', TypeDefInfo.VecFixed, _decodeFixedVec],
|
|
214
|
-
['{', '}', TypeDefInfo.Struct, _decodeStruct],
|
|
215
|
-
['(', ')', TypeDefInfo.Tuple, _decodeTuple],
|
|
216
|
-
// the inner for these are the same as tuple, multiple values
|
|
217
|
-
['BTreeMap<', '>', TypeDefInfo.BTreeMap, _decodeTuple],
|
|
218
|
-
['HashMap<', '>', TypeDefInfo.HashMap, _decodeTuple],
|
|
219
|
-
['Int<', '>', TypeDefInfo.Int, _decodeInt],
|
|
220
|
-
['Result<', '>', TypeDefInfo.Result, _decodeTuple],
|
|
221
|
-
['UInt<', '>', TypeDefInfo.UInt, _decodeUInt],
|
|
222
|
-
['DoNotConstruct<', '>', TypeDefInfo.DoNotConstruct, _decodeDoNotConstruct]
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
const wrappedExtraction: [string, string, TypeDefInfo][] = [
|
|
226
|
-
['BTreeSet<', '>', TypeDefInfo.BTreeSet],
|
|
227
|
-
['Compact<', '>', TypeDefInfo.Compact],
|
|
228
|
-
['Linkage<', '>', TypeDefInfo.Linkage],
|
|
229
|
-
['Opaque<', '>', TypeDefInfo.WrapperOpaque],
|
|
230
|
-
['Option<', '>', TypeDefInfo.Option],
|
|
231
|
-
['Range<', '>', TypeDefInfo.Range],
|
|
232
|
-
['RangeInclusive<', '>', TypeDefInfo.RangeInclusive],
|
|
233
|
-
['Vec<', '>', TypeDefInfo.Vec],
|
|
234
|
-
['WrapperKeepOpaque<', '>', TypeDefInfo.WrapperKeepOpaque],
|
|
235
|
-
['WrapperOpaque<', '>', TypeDefInfo.WrapperOpaque]
|
|
236
|
-
];
|
|
237
|
-
|
|
238
|
-
function extractSubType (type: string, [start, end]: [string, string, TypeDefInfo, any?]): string {
|
|
239
|
-
return type.substring(start.length, type.length - end.length);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export function getTypeDef (_type: AnyString, { displayName, name }: TypeDefOptions = {}, count = 0): TypeDef {
|
|
243
|
-
// create the type via Type, allowing types to be sanitized
|
|
244
|
-
const type = sanitize(_type);
|
|
245
|
-
const value: TypeDef = { displayName, info: TypeDefInfo.Plain, name, type };
|
|
246
|
-
|
|
247
|
-
if (++count > 64) {
|
|
248
|
-
throw new Error('getTypeDef: Maximum nested limit reached');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const nested = nestedExtraction.find((nested) => hasWrapper(type, nested));
|
|
252
|
-
|
|
253
|
-
if (nested) {
|
|
254
|
-
value.info = nested[2];
|
|
255
|
-
|
|
256
|
-
return nested[3](value, type, extractSubType(type, nested), count);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const wrapped = wrappedExtraction.find((wrapped) => hasWrapper(type, wrapped));
|
|
260
|
-
|
|
261
|
-
if (wrapped) {
|
|
262
|
-
value.info = wrapped[2];
|
|
263
|
-
value.sub = getTypeDef(extractSubType(type, wrapped), {}, count);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return value;
|
|
267
|
-
}
|
package/build-deno/util/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function typeSplit (type: string): string[] {
|
|
3
|
-
const result: string[] = [];
|
|
4
|
-
|
|
5
|
-
// these are the depths of the various tokens: <, [, {, (
|
|
6
|
-
let c = 0;
|
|
7
|
-
let f = 0;
|
|
8
|
-
let s = 0;
|
|
9
|
-
let t = 0;
|
|
10
|
-
|
|
11
|
-
// current start position
|
|
12
|
-
let start = 0;
|
|
13
|
-
|
|
14
|
-
for (let i = 0, count = type.length; i < count; i++) {
|
|
15
|
-
switch (type[i]) {
|
|
16
|
-
// if we are not nested, add the type
|
|
17
|
-
case ',': {
|
|
18
|
-
if (!(c || f || s || t)) {
|
|
19
|
-
result.push(type.substring(start, i).trim());
|
|
20
|
-
start = i + 1;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// adjust compact/vec (and friends) depth
|
|
27
|
-
case '<': c++; break;
|
|
28
|
-
case '>': c--; break;
|
|
29
|
-
|
|
30
|
-
// adjust fixed vec depths
|
|
31
|
-
case '[': f++; break;
|
|
32
|
-
case ']': f--; break;
|
|
33
|
-
|
|
34
|
-
// adjust struct depth
|
|
35
|
-
case '{': s++; break;
|
|
36
|
-
case '}': s--; break;
|
|
37
|
-
|
|
38
|
-
// adjust tuple depth
|
|
39
|
-
case '(': t++; break;
|
|
40
|
-
case ')': t--; break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// ensure we have all the terminators taken care of
|
|
45
|
-
if (c || f || s || t) {
|
|
46
|
-
throw new Error(`Invalid definition (missing terminators) found in ${type}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// the final leg of the journey
|
|
50
|
-
result.push(type.substring(start, type.length).trim());
|
|
51
|
-
|
|
52
|
-
return result;
|
|
53
|
-
}
|
package/build-deno/util/xcm.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { objectSpread } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
3
|
-
|
|
4
|
-
export const XCM_MAPPINGS = ['AssetInstance', 'Fungibility', 'Junction', 'Junctions', 'MultiAsset', 'MultiAssetFilter', 'MultiLocation', 'Response', 'WildFungibility', 'WildMultiAsset', 'Xcm', 'XcmError'];
|
|
5
|
-
|
|
6
|
-
export function mapXcmTypes (version: 'V0' | 'V1' | 'V2' | 'V3' | 'V4' | 'V5'): Record<string, string> {
|
|
7
|
-
return XCM_MAPPINGS.reduce<Record<string, string>>((all, key) =>
|
|
8
|
-
objectSpread(all, { [key]: `${key}${version}` }), {}
|
|
9
|
-
);
|
|
10
|
-
}
|
package/build-tsc/bundle.d.ts
DELETED
|
@@ -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,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;
|
package/build-tsc/exports.d.ts
DELETED
package/build-tsc/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import '@pezkuwi/types-codec/types/registry';
|
|
2
|
-
import type { Codec, CodecClass, ICompact, INumber, LookupString } from '@pezkuwi/types-codec/types';
|
|
3
|
-
import type { ILookup, TypeDef } from '@pezkuwi/types-create/types';
|
|
4
|
-
declare module '@pezkuwi/types-codec/types/registry' {
|
|
5
|
-
interface Registry {
|
|
6
|
-
readonly lookup: ILookup;
|
|
7
|
-
createLookupType(lookupId: ICompact<INumber> | number): LookupString;
|
|
8
|
-
getUnsafe<T extends Codec = Codec, K extends string = string>(name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<T> | undefined;
|
|
9
|
-
setLookup(lookup: ILookup): void;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Option, Text } from '@pezkuwi/types-codec';
|
|
2
|
-
import type { ICompact, INumber, LookupString } from '@pezkuwi/types-codec/types';
|
|
3
|
-
import type { TypeDef } from './types.js';
|
|
4
|
-
interface SiTypeBase {
|
|
5
|
-
def: {
|
|
6
|
-
asTuple: ICompact<INumber>[];
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export interface ILookup {
|
|
10
|
-
getSiType(lookupId: ICompact<INumber> | LookupString | number): SiTypeBase;
|
|
11
|
-
getTypeDef(lookupId: ICompact<INumber> | LookupString | number): TypeDef;
|
|
12
|
-
sanitizeField(name: Option<Text>): [string | null, string | null];
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export declare enum TypeDefInfo {
|
|
2
|
-
BTreeMap = 0,
|
|
3
|
-
BTreeSet = 1,
|
|
4
|
-
Compact = 2,
|
|
5
|
-
DoNotConstruct = 3,
|
|
6
|
-
Enum = 4,
|
|
7
|
-
HashMap = 5,
|
|
8
|
-
Int = 6,
|
|
9
|
-
Linkage = 7,
|
|
10
|
-
Null = 8,
|
|
11
|
-
Option = 9,
|
|
12
|
-
Plain = 10,
|
|
13
|
-
Range = 11,
|
|
14
|
-
RangeInclusive = 12,
|
|
15
|
-
Result = 13,
|
|
16
|
-
Set = 14,
|
|
17
|
-
Si = 15,
|
|
18
|
-
Struct = 16,
|
|
19
|
-
Tuple = 17,
|
|
20
|
-
UInt = 18,
|
|
21
|
-
Vec = 19,
|
|
22
|
-
VecFixed = 20,
|
|
23
|
-
WrapperKeepOpaque = 21,
|
|
24
|
-
WrapperOpaque = 22
|
|
25
|
-
}
|
|
26
|
-
export interface TypeDef {
|
|
27
|
-
alias?: Map<string, string> | undefined;
|
|
28
|
-
displayName?: string | undefined;
|
|
29
|
-
docs?: string[] | undefined;
|
|
30
|
-
fallbackType?: string | undefined;
|
|
31
|
-
info: TypeDefInfo;
|
|
32
|
-
index?: number;
|
|
33
|
-
isFromSi?: boolean;
|
|
34
|
-
length?: number;
|
|
35
|
-
lookupIndex?: number;
|
|
36
|
-
lookupName?: string | undefined;
|
|
37
|
-
lookupNameRoot?: string | undefined;
|
|
38
|
-
name?: string | undefined;
|
|
39
|
-
namespace?: string | undefined;
|
|
40
|
-
sub?: TypeDef | TypeDef[];
|
|
41
|
-
type: string;
|
|
42
|
-
typeName?: string | undefined;
|
|
43
|
-
}
|
|
@@ -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,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 +0,0 @@
|
|
|
1
|
-
export declare function typeSplit(type: string): string[];
|
package/build-tsc/util/xcm.d.ts
DELETED
package/build-tsc-cjs/bundle.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeDefInfo = exports.packageInfo = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
var packageInfo_js_1 = require("./packageInfo.js");
|
|
6
|
-
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
|
7
|
-
var index_js_1 = require("./types/index.js");
|
|
8
|
-
Object.defineProperty(exports, "TypeDefInfo", { enumerable: true, get: function () { return index_js_1.TypeDefInfo; } });
|
|
9
|
-
tslib_1.__exportStar(require("./exports.js"), exports);
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constructTypeClass = constructTypeClass;
|
|
4
|
-
exports.getTypeClass = getTypeClass;
|
|
5
|
-
exports.createClassUnsafe = createClassUnsafe;
|
|
6
|
-
const types_codec_1 = require("@pezkuwi/types-codec");
|
|
7
|
-
const util_1 = require("@pezkuwi/util");
|
|
8
|
-
const index_js_1 = require("../types/index.js");
|
|
9
|
-
const getTypeDef_js_1 = require("../util/getTypeDef.js");
|
|
10
|
-
function getTypeDefType({ lookupName, type }) {
|
|
11
|
-
return lookupName || type;
|
|
12
|
-
}
|
|
13
|
-
function getSubDefArray(value) {
|
|
14
|
-
if (!Array.isArray(value.sub)) {
|
|
15
|
-
throw new Error(`Expected subtype as TypeDef[] in ${(0, util_1.stringify)(value)}`);
|
|
16
|
-
}
|
|
17
|
-
return value.sub;
|
|
18
|
-
}
|
|
19
|
-
function getSubDef(value) {
|
|
20
|
-
if (!value.sub || Array.isArray(value.sub)) {
|
|
21
|
-
throw new Error(`Expected subtype as TypeDef in ${(0, util_1.stringify)(value)}`);
|
|
22
|
-
}
|
|
23
|
-
return value.sub;
|
|
24
|
-
}
|
|
25
|
-
function getSubType(value) {
|
|
26
|
-
return getTypeDefType(getSubDef(value));
|
|
27
|
-
}
|
|
28
|
-
function getTypeClassMap(value) {
|
|
29
|
-
const subs = getSubDefArray(value);
|
|
30
|
-
const map = {};
|
|
31
|
-
for (let i = 0, count = subs.length; i < count; i++) {
|
|
32
|
-
const sub = subs[i];
|
|
33
|
-
if (!sub.name) {
|
|
34
|
-
throw new Error(`No name found in definition ${(0, util_1.stringify)(sub)}`);
|
|
35
|
-
}
|
|
36
|
-
map[sub.name] = getTypeDefType(sub);
|
|
37
|
-
}
|
|
38
|
-
return map;
|
|
39
|
-
}
|
|
40
|
-
function getTypeClassArray(value) {
|
|
41
|
-
return getSubDefArray(value).map(getTypeDefType);
|
|
42
|
-
}
|
|
43
|
-
function createInt(Clazz, { displayName, length }) {
|
|
44
|
-
if (!(0, util_1.isNumber)(length)) {
|
|
45
|
-
throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
|
|
46
|
-
}
|
|
47
|
-
return Clazz.with(length, displayName);
|
|
48
|
-
}
|
|
49
|
-
function createHashMap(Clazz, value) {
|
|
50
|
-
const [keyType, valueType] = getTypeClassArray(value);
|
|
51
|
-
return Clazz.with(keyType, valueType);
|
|
52
|
-
}
|
|
53
|
-
function createWithSub(Clazz, value) {
|
|
54
|
-
return Clazz.with(getSubType(value));
|
|
55
|
-
}
|
|
56
|
-
const infoMapping = {
|
|
57
|
-
[index_js_1.TypeDefInfo.BTreeMap]: (_registry, value) => createHashMap(types_codec_1.BTreeMap, value),
|
|
58
|
-
[index_js_1.TypeDefInfo.BTreeSet]: (_registry, value) => createWithSub(types_codec_1.BTreeSet, value),
|
|
59
|
-
[index_js_1.TypeDefInfo.Compact]: (_registry, value) => createWithSub(types_codec_1.Compact, value),
|
|
60
|
-
[index_js_1.TypeDefInfo.DoNotConstruct]: (_registry, value) => types_codec_1.DoNotConstruct.with(value.displayName || value.type),
|
|
61
|
-
[index_js_1.TypeDefInfo.Enum]: (_registry, value) => {
|
|
62
|
-
const subs = getSubDefArray(value);
|
|
63
|
-
return types_codec_1.Enum.with(subs.every(({ type }) => type === 'Null')
|
|
64
|
-
? subs.reduce((out, { index, name }, count) => {
|
|
65
|
-
if (!name) {
|
|
66
|
-
throw new Error('No name found in sub definition');
|
|
67
|
-
}
|
|
68
|
-
out[name] = index || count;
|
|
69
|
-
return out;
|
|
70
|
-
}, {})
|
|
71
|
-
: getTypeClassMap(value));
|
|
72
|
-
},
|
|
73
|
-
[index_js_1.TypeDefInfo.HashMap]: (_registry, value) => createHashMap(types_codec_1.HashMap, value),
|
|
74
|
-
[index_js_1.TypeDefInfo.Int]: (_registry, value) => createInt(types_codec_1.Int, value),
|
|
75
|
-
// We have circular deps between Linkage & Struct
|
|
76
|
-
[index_js_1.TypeDefInfo.Linkage]: (_registry, value) => {
|
|
77
|
-
const type = `Option<${getSubType(value)}>`;
|
|
78
|
-
// eslint-disable-next-line sort-keys
|
|
79
|
-
const Clazz = types_codec_1.Struct.with({ previous: type, next: type });
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
81
|
-
Clazz.prototype.toRawType = function () {
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
|
83
|
-
return `Linkage<${this.next.toRawType(true)}>`;
|
|
84
|
-
};
|
|
85
|
-
return Clazz;
|
|
86
|
-
},
|
|
87
|
-
[index_js_1.TypeDefInfo.Null]: (_registry, _value) => types_codec_1.Null,
|
|
88
|
-
[index_js_1.TypeDefInfo.Option]: (_registry, value) => {
|
|
89
|
-
if (!value.sub || Array.isArray(value.sub)) {
|
|
90
|
-
throw new Error('Expected type information for Option');
|
|
91
|
-
}
|
|
92
|
-
// NOTE This is opt-in (unhandled), not by default
|
|
93
|
-
// if (value.sub.type === 'bool') {
|
|
94
|
-
// return OptionBool;
|
|
95
|
-
// }
|
|
96
|
-
return createWithSub(types_codec_1.Option, value);
|
|
97
|
-
},
|
|
98
|
-
[index_js_1.TypeDefInfo.Plain]: (registry, value) => registry.getOrUnknown(value.type),
|
|
99
|
-
[index_js_1.TypeDefInfo.Range]: (_registry, value) => createWithSub(types_codec_1.Range, value),
|
|
100
|
-
[index_js_1.TypeDefInfo.RangeInclusive]: (_registry, value) => createWithSub(types_codec_1.RangeInclusive, value),
|
|
101
|
-
[index_js_1.TypeDefInfo.Result]: (_registry, value) => {
|
|
102
|
-
const [Ok, Err] = getTypeClassArray(value);
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
104
|
-
return types_codec_1.Result.with({ Err, Ok });
|
|
105
|
-
},
|
|
106
|
-
[index_js_1.TypeDefInfo.Set]: (_registry, value) => types_codec_1.CodecSet.with(getSubDefArray(value).reduce((result, { index, name }) => {
|
|
107
|
-
if (!name || !(0, util_1.isNumber)(index)) {
|
|
108
|
-
throw new Error('No name found in sub definition');
|
|
109
|
-
}
|
|
110
|
-
result[name] = index;
|
|
111
|
-
return result;
|
|
112
|
-
}, {}), value.length),
|
|
113
|
-
[index_js_1.TypeDefInfo.Si]: (registry, value) => getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
|
|
114
|
-
[index_js_1.TypeDefInfo.Struct]: (_registry, value) => types_codec_1.Struct.with(getTypeClassMap(value), value.alias),
|
|
115
|
-
[index_js_1.TypeDefInfo.Tuple]: (_registry, value) => types_codec_1.Tuple.with(getTypeClassArray(value)),
|
|
116
|
-
[index_js_1.TypeDefInfo.UInt]: (_registry, value) => createInt(types_codec_1.UInt, value),
|
|
117
|
-
[index_js_1.TypeDefInfo.Vec]: (_registry, { sub }) => {
|
|
118
|
-
if (!sub || Array.isArray(sub)) {
|
|
119
|
-
throw new Error('Expected type information for vector');
|
|
120
|
-
}
|
|
121
|
-
return (sub.type === 'u8'
|
|
122
|
-
? types_codec_1.Bytes
|
|
123
|
-
: types_codec_1.Vec.with(getTypeDefType(sub)));
|
|
124
|
-
},
|
|
125
|
-
[index_js_1.TypeDefInfo.VecFixed]: (_registry, { displayName, length, sub }) => {
|
|
126
|
-
if (!(0, util_1.isNumber)(length) || !sub || Array.isArray(sub)) {
|
|
127
|
-
throw new Error('Expected length & type information for fixed vector');
|
|
128
|
-
}
|
|
129
|
-
return (sub.type === 'u8'
|
|
130
|
-
? types_codec_1.U8aFixed.with((length * 8), displayName)
|
|
131
|
-
: types_codec_1.VecFixed.with(getTypeDefType(sub), length));
|
|
132
|
-
},
|
|
133
|
-
[index_js_1.TypeDefInfo.WrapperKeepOpaque]: (_registry, value) => createWithSub(types_codec_1.WrapperKeepOpaque, value),
|
|
134
|
-
[index_js_1.TypeDefInfo.WrapperOpaque]: (_registry, value) => createWithSub(types_codec_1.WrapperOpaque, value)
|
|
135
|
-
};
|
|
136
|
-
function constructTypeClass(registry, typeDef) {
|
|
137
|
-
try {
|
|
138
|
-
const Type = infoMapping[typeDef.info](registry, typeDef);
|
|
139
|
-
if (!Type) {
|
|
140
|
-
throw new Error('No class created');
|
|
141
|
-
}
|
|
142
|
-
// don't clobber any existing
|
|
143
|
-
if (!Type.__fallbackType && typeDef.fallbackType) {
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
145
|
-
// @ts-ignore ...this is the only place we we actually assign this...
|
|
146
|
-
Type.__fallbackType = typeDef.fallbackType;
|
|
147
|
-
}
|
|
148
|
-
return Type;
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
throw new Error(`Unable to construct class from ${(0, util_1.stringify)(typeDef)}: ${error.message}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function getTypeClass(registry, typeDef) {
|
|
155
|
-
return registry.getUnsafe(typeDef.type, false, typeDef);
|
|
156
|
-
}
|
|
157
|
-
function createClassUnsafe(registry, type) {
|
|
158
|
-
return (
|
|
159
|
-
// just retrieve via name, no creation via typeDef
|
|
160
|
-
registry.getUnsafe(type) ||
|
|
161
|
-
// we don't have an existing type, create the class via typeDef
|
|
162
|
-
getTypeClass(registry, registry.isLookupType(type)
|
|
163
|
-
? registry.lookup.getTypeDef(type)
|
|
164
|
-
: (0, getTypeDef_js_1.getTypeDef)(type)));
|
|
165
|
-
}
|