@pezkuwi/types-create 16.5.5
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/README.md +3 -0
- package/build/bundle.d.ts +3 -0
- package/build/create/class.d.ts +5 -0
- package/build/create/index.d.ts +2 -0
- package/build/create/type.d.ts +3 -0
- package/build/exports.d.ts +2 -0
- package/build/index.d.ts +2 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/types/augmentRegistry.d.ts +11 -0
- package/build/types/index.d.ts +4 -0
- package/build/types/lookup.d.ts +14 -0
- package/build/types/types.d.ts +43 -0
- package/build/util/encodeTypes.d.ts +11 -0
- package/build/util/getTypeDef.d.ts +8 -0
- package/build/util/index.d.ts +4 -0
- package/build/util/typeSplit.d.ts +1 -0
- package/build/util/xcm.d.ts +2 -0
- package/package.json +31 -0
- package/src/bundle.ts +9 -0
- package/src/create/class.ts +257 -0
- package/src/create/index.ts +5 -0
- package/src/create/type.ts +94 -0
- package/src/exports.ts +6 -0
- package/src/index.ts +6 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +12 -0
- package/src/packageInfo.ts +6 -0
- package/src/types/augmentRegistry.ts +19 -0
- package/src/types/index.ts +11 -0
- package/src/types/lookup.ts +21 -0
- package/src/types/types.ts +47 -0
- package/src/util/encodeTypes.spec.ts +217 -0
- package/src/util/encodeTypes.ts +205 -0
- package/src/util/getTypeDef.spec.ts +704 -0
- package/src/util/getTypeDef.ts +279 -0
- package/src/util/index.ts +7 -0
- package/src/util/typeSplit.spec.ts +50 -0
- package/src/util/typeSplit.ts +56 -0
- package/src/util/xcm.ts +12 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +17 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/types-create authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export enum TypeDefInfo {
|
|
5
|
+
BTreeMap,
|
|
6
|
+
BTreeSet,
|
|
7
|
+
Compact,
|
|
8
|
+
DoNotConstruct,
|
|
9
|
+
Enum,
|
|
10
|
+
HashMap,
|
|
11
|
+
Int,
|
|
12
|
+
Linkage,
|
|
13
|
+
Null,
|
|
14
|
+
Option,
|
|
15
|
+
Plain,
|
|
16
|
+
Range,
|
|
17
|
+
RangeInclusive,
|
|
18
|
+
Result,
|
|
19
|
+
Set,
|
|
20
|
+
Si,
|
|
21
|
+
Struct,
|
|
22
|
+
Tuple,
|
|
23
|
+
UInt,
|
|
24
|
+
Vec,
|
|
25
|
+
VecFixed,
|
|
26
|
+
WrapperKeepOpaque,
|
|
27
|
+
WrapperOpaque
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TypeDef {
|
|
31
|
+
alias?: Map<string, string> | undefined;
|
|
32
|
+
displayName?: string | undefined;
|
|
33
|
+
docs?: string[] | undefined;
|
|
34
|
+
fallbackType?: string | undefined;
|
|
35
|
+
info: TypeDefInfo;
|
|
36
|
+
index?: number;
|
|
37
|
+
isFromSi?: boolean;
|
|
38
|
+
length?: number;
|
|
39
|
+
lookupIndex?: number;
|
|
40
|
+
lookupName?: string | undefined;
|
|
41
|
+
lookupNameRoot?: string | undefined;
|
|
42
|
+
name?: string | undefined;
|
|
43
|
+
namespace?: string | undefined;
|
|
44
|
+
sub?: TypeDef | TypeDef[];
|
|
45
|
+
type: string;
|
|
46
|
+
typeName?: string | undefined;
|
|
47
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/types authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import { TypeRegistry } from '@pezkuwi/types';
|
|
7
|
+
import { encodeTypeDef, TypeDefInfo } from '@pezkuwi/types-create';
|
|
8
|
+
|
|
9
|
+
describe('encodeTypeDef', (): void => {
|
|
10
|
+
const registry = new TypeRegistry();
|
|
11
|
+
|
|
12
|
+
it('correctly encodes a complex struct', (): void => {
|
|
13
|
+
expect(
|
|
14
|
+
JSON.parse(encodeTypeDef(registry, {
|
|
15
|
+
info: TypeDefInfo.Struct,
|
|
16
|
+
sub: [
|
|
17
|
+
{
|
|
18
|
+
info: TypeDefInfo.Plain,
|
|
19
|
+
name: 'a',
|
|
20
|
+
type: 'u32'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
info: TypeDefInfo.Struct,
|
|
24
|
+
name: 'b',
|
|
25
|
+
sub: [
|
|
26
|
+
{
|
|
27
|
+
info: TypeDefInfo.Plain,
|
|
28
|
+
name: 'c',
|
|
29
|
+
type: 'u32'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
info: TypeDefInfo.Vec,
|
|
33
|
+
name: 'd',
|
|
34
|
+
sub: {
|
|
35
|
+
info: TypeDefInfo.Plain,
|
|
36
|
+
type: 'u32'
|
|
37
|
+
},
|
|
38
|
+
type: ''
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
type: ''
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
type: ''
|
|
45
|
+
}))
|
|
46
|
+
).toEqual({
|
|
47
|
+
a: 'u32',
|
|
48
|
+
b: '{"c":"u32","d":"Vec<u32>"}'
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('correctly encodes a complex struct (named)', (): void => {
|
|
53
|
+
expect(
|
|
54
|
+
JSON.parse(encodeTypeDef(registry, {
|
|
55
|
+
info: TypeDefInfo.Struct,
|
|
56
|
+
sub: [
|
|
57
|
+
{
|
|
58
|
+
info: TypeDefInfo.Plain,
|
|
59
|
+
name: 'a',
|
|
60
|
+
type: 'u32'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
info: TypeDefInfo.Struct,
|
|
64
|
+
name: 'b',
|
|
65
|
+
sub: [
|
|
66
|
+
{
|
|
67
|
+
info: TypeDefInfo.Plain,
|
|
68
|
+
name: 'c',
|
|
69
|
+
type: 'u32'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
displayName: 'Something',
|
|
73
|
+
info: TypeDefInfo.Vec,
|
|
74
|
+
name: 'd',
|
|
75
|
+
sub: {
|
|
76
|
+
info: TypeDefInfo.Plain,
|
|
77
|
+
type: 'u32'
|
|
78
|
+
},
|
|
79
|
+
type: ''
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
type: ''
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
type: ''
|
|
86
|
+
}))
|
|
87
|
+
).toEqual({
|
|
88
|
+
a: 'u32',
|
|
89
|
+
b: '{"c":"u32","d":"Something"}'
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('correctly encodes a complex enum', (): void => {
|
|
94
|
+
expect(
|
|
95
|
+
JSON.parse(encodeTypeDef(registry, {
|
|
96
|
+
info: TypeDefInfo.Enum,
|
|
97
|
+
sub: [
|
|
98
|
+
{
|
|
99
|
+
info: TypeDefInfo.Plain,
|
|
100
|
+
name: 'a',
|
|
101
|
+
type: 'u32'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
info: TypeDefInfo.Struct,
|
|
105
|
+
name: 'b',
|
|
106
|
+
sub: [
|
|
107
|
+
{
|
|
108
|
+
info: TypeDefInfo.Plain,
|
|
109
|
+
name: 'c',
|
|
110
|
+
type: 'u32'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
info: TypeDefInfo.Vec,
|
|
114
|
+
name: 'd',
|
|
115
|
+
sub: {
|
|
116
|
+
info: TypeDefInfo.Plain,
|
|
117
|
+
type: 'u32'
|
|
118
|
+
},
|
|
119
|
+
type: ''
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
type: ''
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
info: TypeDefInfo.Enum,
|
|
126
|
+
name: 'f',
|
|
127
|
+
sub: [
|
|
128
|
+
{
|
|
129
|
+
info: TypeDefInfo.Plain,
|
|
130
|
+
name: 'g',
|
|
131
|
+
type: 'Null'
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
info: TypeDefInfo.Plain,
|
|
135
|
+
name: 'h',
|
|
136
|
+
type: 'Null'
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
type: ''
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
type: ''
|
|
143
|
+
}))
|
|
144
|
+
).toEqual({
|
|
145
|
+
_enum: {
|
|
146
|
+
a: 'u32',
|
|
147
|
+
b: '{"c":"u32","d":"Vec<u32>"}',
|
|
148
|
+
f: '{"_enum":["g","h"]}'
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('correctly encodes a complex enum (named)', (): void => {
|
|
154
|
+
expect(
|
|
155
|
+
JSON.parse(encodeTypeDef(registry, {
|
|
156
|
+
info: TypeDefInfo.Enum,
|
|
157
|
+
sub: [
|
|
158
|
+
{
|
|
159
|
+
info: TypeDefInfo.Plain,
|
|
160
|
+
name: 'a',
|
|
161
|
+
type: 'u32'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
displayName: 'Something',
|
|
165
|
+
info: TypeDefInfo.Struct,
|
|
166
|
+
name: 'b',
|
|
167
|
+
sub: [
|
|
168
|
+
{
|
|
169
|
+
info: TypeDefInfo.Plain,
|
|
170
|
+
name: 'c',
|
|
171
|
+
type: 'u32'
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
info: TypeDefInfo.Vec,
|
|
175
|
+
name: 'd',
|
|
176
|
+
sub: {
|
|
177
|
+
info: TypeDefInfo.Plain,
|
|
178
|
+
type: 'u32'
|
|
179
|
+
},
|
|
180
|
+
type: ''
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
type: ''
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
displayName: 'Option',
|
|
187
|
+
info: TypeDefInfo.Option,
|
|
188
|
+
name: 'e',
|
|
189
|
+
sub: {
|
|
190
|
+
displayName: 'Result',
|
|
191
|
+
info: TypeDefInfo.Result,
|
|
192
|
+
sub: [
|
|
193
|
+
{
|
|
194
|
+
info: TypeDefInfo.Null,
|
|
195
|
+
type: ''
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
info: TypeDefInfo.Plain,
|
|
199
|
+
type: 'u32'
|
|
200
|
+
}
|
|
201
|
+
],
|
|
202
|
+
type: ''
|
|
203
|
+
},
|
|
204
|
+
type: ''
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
type: ''
|
|
208
|
+
}))
|
|
209
|
+
).toEqual({
|
|
210
|
+
_enum: {
|
|
211
|
+
a: 'u32',
|
|
212
|
+
b: 'Something',
|
|
213
|
+
e: 'Option<Result<Null, u32>>'
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/types-create authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Registry } from '@pezkuwi/types-codec/types';
|
|
5
|
+
import type { TypeDef } from '@pezkuwi/types-create/types';
|
|
6
|
+
|
|
7
|
+
import { isNumber, isUndefined, objectSpread, stringify } from '@pezkuwi/util';
|
|
8
|
+
|
|
9
|
+
import { TypeDefInfo } from '../types/index.js';
|
|
10
|
+
|
|
11
|
+
interface ToString { toString: () => string }
|
|
12
|
+
|
|
13
|
+
const stringIdentity = <T extends ToString> (value: T): string => value.toString();
|
|
14
|
+
|
|
15
|
+
const INFO_WRAP = ['BTreeMap', 'BTreeSet', 'Compact', 'HashMap', 'Option', 'Result', 'Vec'];
|
|
16
|
+
|
|
17
|
+
export function paramsNotation <T extends ToString> (outer: string, inner?: T | T[], transform: (_: T) => string = stringIdentity): string {
|
|
18
|
+
return `${outer}${
|
|
19
|
+
inner
|
|
20
|
+
? `<${(Array.isArray(inner) ? inner : [inner]).map(transform).join(', ')}>`
|
|
21
|
+
: ''
|
|
22
|
+
}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function encodeWithParams (registry: Registry, typeDef: TypeDef, outer: string): string {
|
|
26
|
+
const { info, sub } = typeDef;
|
|
27
|
+
|
|
28
|
+
switch (info) {
|
|
29
|
+
case TypeDefInfo.BTreeMap:
|
|
30
|
+
case TypeDefInfo.BTreeSet:
|
|
31
|
+
case TypeDefInfo.Compact:
|
|
32
|
+
case TypeDefInfo.HashMap:
|
|
33
|
+
case TypeDefInfo.Linkage:
|
|
34
|
+
case TypeDefInfo.Option:
|
|
35
|
+
case TypeDefInfo.Range:
|
|
36
|
+
case TypeDefInfo.RangeInclusive:
|
|
37
|
+
case TypeDefInfo.Result:
|
|
38
|
+
case TypeDefInfo.Vec:
|
|
39
|
+
case TypeDefInfo.WrapperKeepOpaque:
|
|
40
|
+
case TypeDefInfo.WrapperOpaque:
|
|
41
|
+
return paramsNotation(outer, sub, (p) => encodeTypeDef(registry, p));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error(`Unable to encode ${stringify(typeDef)} with params`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function encodeSubTypes (registry: Registry, sub: TypeDef[], asEnum?: boolean, extra?: Record<string, unknown>): string {
|
|
48
|
+
const names = sub.map(({ name }) => name);
|
|
49
|
+
|
|
50
|
+
if (!names.every((n) => !!n)) {
|
|
51
|
+
throw new Error(`Subtypes does not have consistent names, ${names.join(', ')}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const inner: Record<string, string> = objectSpread({}, extra);
|
|
55
|
+
|
|
56
|
+
for (let i = 0, count = sub.length; i < count; i++) {
|
|
57
|
+
const def = sub[i];
|
|
58
|
+
|
|
59
|
+
if (!def.name) {
|
|
60
|
+
throw new Error(`No name found in ${stringify(def)}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
inner[def.name] = encodeTypeDef(registry, def);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return stringify(
|
|
67
|
+
asEnum
|
|
68
|
+
? { _enum: inner }
|
|
69
|
+
: inner
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// We setup a record here to ensure we have comprehensive coverage (any item not covered will result
|
|
74
|
+
// in a compile-time error with the missing index)
|
|
75
|
+
const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => string> = {
|
|
76
|
+
[TypeDefInfo.BTreeMap]: (registry: Registry, typeDef: TypeDef) =>
|
|
77
|
+
encodeWithParams(registry, typeDef, 'BTreeMap'),
|
|
78
|
+
|
|
79
|
+
[TypeDefInfo.BTreeSet]: (registry: Registry, typeDef: TypeDef) =>
|
|
80
|
+
encodeWithParams(registry, typeDef, 'BTreeSet'),
|
|
81
|
+
|
|
82
|
+
[TypeDefInfo.Compact]: (registry: Registry, typeDef: TypeDef) =>
|
|
83
|
+
encodeWithParams(registry, typeDef, 'Compact'),
|
|
84
|
+
|
|
85
|
+
[TypeDefInfo.DoNotConstruct]: (registry: Registry, { displayName, lookupIndex, lookupName }: TypeDef) =>
|
|
86
|
+
`DoNotConstruct<${lookupName || displayName || (isUndefined(lookupIndex) ? 'Unknown' : registry.createLookupType(lookupIndex))}>`,
|
|
87
|
+
|
|
88
|
+
[TypeDefInfo.Enum]: (registry: Registry, { sub }: TypeDef): string => {
|
|
89
|
+
if (!Array.isArray(sub)) {
|
|
90
|
+
throw new Error('Unable to encode Enum type');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// c-like enums have all Null entries
|
|
94
|
+
// TODO We need to take the disciminant into account and auto-add empty entries
|
|
95
|
+
return sub.every(({ type }) => type === 'Null')
|
|
96
|
+
? stringify({ _enum: sub.map(({ name }, index) => `${name || `Empty${index}`}`) })
|
|
97
|
+
: encodeSubTypes(registry, sub, true);
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
[TypeDefInfo.HashMap]: (registry: Registry, typeDef: TypeDef) =>
|
|
101
|
+
encodeWithParams(registry, typeDef, 'HashMap'),
|
|
102
|
+
|
|
103
|
+
[TypeDefInfo.Int]: (_registry: Registry, { length = 32 }: TypeDef) =>
|
|
104
|
+
`Int<${length}>`,
|
|
105
|
+
|
|
106
|
+
[TypeDefInfo.Linkage]: (registry: Registry, typeDef: TypeDef) =>
|
|
107
|
+
encodeWithParams(registry, typeDef, 'Linkage'),
|
|
108
|
+
|
|
109
|
+
[TypeDefInfo.Null]: (_registry: Registry, _typeDef: TypeDef) =>
|
|
110
|
+
'Null',
|
|
111
|
+
|
|
112
|
+
[TypeDefInfo.Option]: (registry: Registry, typeDef: TypeDef) =>
|
|
113
|
+
encodeWithParams(registry, typeDef, 'Option'),
|
|
114
|
+
|
|
115
|
+
[TypeDefInfo.Plain]: (_registry: Registry, { displayName, type }: TypeDef) =>
|
|
116
|
+
displayName || type,
|
|
117
|
+
|
|
118
|
+
[TypeDefInfo.Range]: (registry: Registry, typeDef: TypeDef) =>
|
|
119
|
+
encodeWithParams(registry, typeDef, 'Range'),
|
|
120
|
+
|
|
121
|
+
[TypeDefInfo.RangeInclusive]: (registry: Registry, typeDef: TypeDef) =>
|
|
122
|
+
encodeWithParams(registry, typeDef, 'RangeInclusive'),
|
|
123
|
+
|
|
124
|
+
[TypeDefInfo.Result]: (registry: Registry, typeDef: TypeDef) =>
|
|
125
|
+
encodeWithParams(registry, typeDef, 'Result'),
|
|
126
|
+
|
|
127
|
+
[TypeDefInfo.Set]: (_registry: Registry, { length = 8, sub }: TypeDef): string => {
|
|
128
|
+
if (!Array.isArray(sub)) {
|
|
129
|
+
throw new Error('Unable to encode Set type');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return stringify({
|
|
133
|
+
_set: sub.reduce((all, { index, name }, count) =>
|
|
134
|
+
objectSpread(all, { [`${name || `Unknown${index || count}`}`]: index || count }),
|
|
135
|
+
{ _bitLength: length || 8 })
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
[TypeDefInfo.Si]: (_registry: Registry, { lookupName, type }: TypeDef) =>
|
|
140
|
+
lookupName || type,
|
|
141
|
+
|
|
142
|
+
[TypeDefInfo.Struct]: (registry: Registry, { alias, sub }: TypeDef): string => {
|
|
143
|
+
if (!Array.isArray(sub)) {
|
|
144
|
+
throw new Error('Unable to encode Struct type');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return encodeSubTypes(registry, sub, false, alias
|
|
148
|
+
? {
|
|
149
|
+
_alias: [...alias.entries()].reduce<Record<string, string>>((all, [k, v]) =>
|
|
150
|
+
objectSpread(all, { [k]: v }), {}
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
: {}
|
|
154
|
+
);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
[TypeDefInfo.Tuple]: (registry: Registry, { sub }: TypeDef): string => {
|
|
158
|
+
if (!Array.isArray(sub)) {
|
|
159
|
+
throw new Error('Unable to encode Tuple type');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return `(${sub.map((type) => encodeTypeDef(registry, type)).join(',')})`;
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
[TypeDefInfo.UInt]: (_registry: Registry, { length = 32 }: TypeDef) =>
|
|
166
|
+
`UInt<${length}>`,
|
|
167
|
+
|
|
168
|
+
[TypeDefInfo.Vec]: (registry: Registry, typeDef: TypeDef) =>
|
|
169
|
+
encodeWithParams(registry, typeDef, 'Vec'),
|
|
170
|
+
|
|
171
|
+
[TypeDefInfo.VecFixed]: (_registry: Registry, { length, sub }: TypeDef): string => {
|
|
172
|
+
if (!isNumber(length) || !sub || Array.isArray(sub)) {
|
|
173
|
+
throw new Error('Unable to encode VecFixed type');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return `[${sub.type};${length}]`;
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
[TypeDefInfo.WrapperKeepOpaque]: (registry: Registry, typeDef: TypeDef) =>
|
|
180
|
+
encodeWithParams(registry, typeDef, 'WrapperKeepOpaque'),
|
|
181
|
+
|
|
182
|
+
[TypeDefInfo.WrapperOpaque]: (registry: Registry, typeDef: TypeDef) =>
|
|
183
|
+
encodeWithParams(registry, typeDef, 'WrapperOpaque')
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
function encodeType (registry: Registry, typeDef: TypeDef, withLookup = true): string {
|
|
187
|
+
return withLookup && typeDef.lookupName
|
|
188
|
+
? typeDef.lookupName
|
|
189
|
+
: encoders[typeDef.info](registry, typeDef);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function encodeTypeDef (registry: Registry, typeDef: TypeDef): string {
|
|
193
|
+
// In the case of contracts we do have the unfortunate situation where the displayName would
|
|
194
|
+
// refer to "Option" when it is an option. For these, string it out, only using when actually
|
|
195
|
+
// not a top-level element to be used
|
|
196
|
+
return (typeDef.displayName && !INFO_WRAP.some((i) => typeDef.displayName === i))
|
|
197
|
+
? typeDef.displayName
|
|
198
|
+
: encodeType(registry, typeDef);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function withTypeString (registry: Registry, typeDef: Omit<TypeDef, 'type'> & { type?: string }): TypeDef {
|
|
202
|
+
return objectSpread({}, typeDef, {
|
|
203
|
+
type: encodeType(registry, typeDef as TypeDef, false)
|
|
204
|
+
});
|
|
205
|
+
}
|