@pezkuwi/types-create 16.5.20 → 16.5.22

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,217 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/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
- });
@@ -1,205 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/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
- }