@pezkuwi/types-create 16.5.16 → 16.5.18

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/build/LICENSE +201 -0
  2. package/build/README.md +3 -0
  3. package/build/bundle.js +3 -0
  4. package/build/cjs/bundle.d.ts +3 -0
  5. package/build/cjs/bundle.js +9 -0
  6. package/build/cjs/create/class.js +165 -0
  7. package/build/cjs/create/index.js +5 -0
  8. package/build/cjs/create/type.js +66 -0
  9. package/build/cjs/exports.js +5 -0
  10. package/build/cjs/index.js +5 -0
  11. package/build/cjs/packageInfo.js +4 -0
  12. package/build/cjs/types/augmentRegistry.js +3 -0
  13. package/build/cjs/types/index.js +6 -0
  14. package/build/cjs/types/lookup.js +2 -0
  15. package/build/cjs/types/types.js +29 -0
  16. package/build/cjs/util/encodeTypes.js +128 -0
  17. package/build/cjs/util/getTypeDef.js +195 -0
  18. package/build/cjs/util/index.js +7 -0
  19. package/build/cjs/util/typeSplit.js +60 -0
  20. package/build/cjs/util/xcm.js +9 -0
  21. package/build/create/class.d.ts +5 -0
  22. package/build/create/class.js +160 -0
  23. package/build/create/index.d.ts +2 -0
  24. package/build/create/index.js +2 -0
  25. package/build/create/type.d.ts +3 -0
  26. package/build/create/type.js +63 -0
  27. package/build/exports.d.ts +2 -0
  28. package/build/exports.js +2 -0
  29. package/build/index.d.ts +2 -0
  30. package/build/index.js +2 -0
  31. package/build/package.json +291 -0
  32. package/build/packageDetect.d.ts +1 -0
  33. package/build/packageDetect.js +4 -0
  34. package/build/packageInfo.d.ts +6 -0
  35. package/build/packageInfo.js +1 -0
  36. package/build/types/augmentRegistry.d.ts +11 -0
  37. package/build/types/augmentRegistry.js +1 -0
  38. package/build/types/index.d.ts +4 -0
  39. package/build/types/index.js +3 -0
  40. package/build/types/lookup.d.ts +14 -0
  41. package/build/types/lookup.js +1 -0
  42. package/build/types/types.d.ts +43 -0
  43. package/build/types/types.js +26 -0
  44. package/build/util/encodeTypes.d.ts +11 -0
  45. package/build/util/encodeTypes.js +123 -0
  46. package/build/util/getTypeDef.d.ts +8 -0
  47. package/build/util/getTypeDef.js +192 -0
  48. package/build/util/index.d.ts +4 -0
  49. package/build/util/index.js +4 -0
  50. package/build/util/typeSplit.d.ts +1 -0
  51. package/build/util/typeSplit.js +57 -0
  52. package/build/util/xcm.d.ts +2 -0
  53. package/build/util/xcm.js +5 -0
  54. package/build-deno/README.md +3 -0
  55. package/build-deno/bundle.ts +5 -0
  56. package/build-deno/create/class.ts +252 -0
  57. package/build-deno/create/index.ts +3 -0
  58. package/build-deno/create/type.ts +85 -0
  59. package/build-deno/exports.ts +3 -0
  60. package/build-deno/index.ts +4 -0
  61. package/build-deno/mod.ts +2 -0
  62. package/build-deno/packageDetect.ts +8 -0
  63. package/build-deno/packageInfo.ts +3 -0
  64. package/build-deno/types/augmentRegistry.ts +15 -0
  65. package/build-deno/types/index.ts +7 -0
  66. package/build-deno/types/lookup.ts +16 -0
  67. package/build-deno/types/types.ts +45 -0
  68. package/build-deno/util/encodeTypes.ts +201 -0
  69. package/build-deno/util/getTypeDef.ts +267 -0
  70. package/build-deno/util/index.ts +5 -0
  71. package/build-deno/util/typeSplit.ts +53 -0
  72. package/build-deno/util/xcm.ts +10 -0
  73. package/build-tsc-cjs/packageDetect.js +6 -0
  74. package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
  75. package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
  76. package/package.json +11 -11
  77. package/src/bundle.ts +9 -0
  78. package/src/create/class.ts +257 -0
  79. package/src/create/index.ts +5 -0
  80. package/src/create/type.ts +94 -0
  81. package/src/exports.ts +6 -0
  82. package/src/index.ts +6 -0
  83. package/src/mod.ts +4 -0
  84. package/src/packageDetect.ts +12 -0
  85. package/src/packageInfo.ts +6 -0
  86. package/src/types/augmentRegistry.ts +19 -0
  87. package/src/types/index.ts +11 -0
  88. package/src/types/lookup.ts +21 -0
  89. package/src/types/types.ts +47 -0
  90. package/src/util/encodeTypes.spec.ts +217 -0
  91. package/src/util/encodeTypes.ts +205 -0
  92. package/src/util/getTypeDef.spec.ts +704 -0
  93. package/src/util/getTypeDef.ts +279 -0
  94. package/src/util/index.ts +7 -0
  95. package/src/util/typeSplit.spec.ts +50 -0
  96. package/src/util/typeSplit.ts +56 -0
  97. package/src/util/xcm.ts +12 -0
  98. package/tsconfig.build.json +15 -0
  99. package/tsconfig.build.tsbuildinfo +1 -0
  100. package/tsconfig.spec.json +17 -0
  101. package/tsconfig.spec.tsbuildinfo +1 -0
  102. /package/{cjs → build}/bundle.d.ts +0 -0
  103. /package/{create → build/cjs/create}/class.d.ts +0 -0
  104. /package/{create → build/cjs/create}/index.d.ts +0 -0
  105. /package/{create → build/cjs/create}/type.d.ts +0 -0
  106. /package/{exports.d.ts → build/cjs/exports.d.ts} +0 -0
  107. /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
  108. /package/{cjs → build/cjs}/package.json +0 -0
  109. /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
  110. /package/{cjs → build/cjs}/packageDetect.js +0 -0
  111. /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
  112. /package/{types → build/cjs/types}/augmentRegistry.d.ts +0 -0
  113. /package/{types → build/cjs/types}/index.d.ts +0 -0
  114. /package/{types → build/cjs/types}/lookup.d.ts +0 -0
  115. /package/{types → build/cjs/types}/types.d.ts +0 -0
  116. /package/{util → build/cjs/util}/encodeTypes.d.ts +0 -0
  117. /package/{util → build/cjs/util}/getTypeDef.d.ts +0 -0
  118. /package/{util → build/cjs/util}/index.d.ts +0 -0
  119. /package/{util → build/cjs/util}/typeSplit.d.ts +0 -0
  120. /package/{util → build/cjs/util}/xcm.d.ts +0 -0
  121. /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
  122. /package/{cjs → build-tsc}/create/class.d.ts +0 -0
  123. /package/{cjs → build-tsc}/create/index.d.ts +0 -0
  124. /package/{cjs → build-tsc}/create/type.d.ts +0 -0
  125. /package/{cjs → build-tsc}/exports.d.ts +0 -0
  126. /package/{cjs → build-tsc}/index.d.ts +0 -0
  127. /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
  128. /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
  129. /package/{cjs → build-tsc}/types/augmentRegistry.d.ts +0 -0
  130. /package/{cjs → build-tsc}/types/index.d.ts +0 -0
  131. /package/{cjs → build-tsc}/types/lookup.d.ts +0 -0
  132. /package/{cjs → build-tsc}/types/types.d.ts +0 -0
  133. /package/{cjs → build-tsc}/util/encodeTypes.d.ts +0 -0
  134. /package/{cjs → build-tsc}/util/getTypeDef.d.ts +0 -0
  135. /package/{cjs → build-tsc}/util/index.d.ts +0 -0
  136. /package/{cjs → build-tsc}/util/typeSplit.d.ts +0 -0
  137. /package/{cjs → build-tsc}/util/xcm.d.ts +0 -0
  138. /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
  139. /package/{cjs → build-tsc-cjs}/create/class.js +0 -0
  140. /package/{cjs → build-tsc-cjs}/create/index.js +0 -0
  141. /package/{cjs → build-tsc-cjs}/create/type.js +0 -0
  142. /package/{cjs → build-tsc-cjs}/exports.js +0 -0
  143. /package/{cjs → build-tsc-cjs}/index.js +0 -0
  144. /package/{cjs → build-tsc-cjs}/types/augmentRegistry.js +0 -0
  145. /package/{cjs → build-tsc-cjs}/types/index.js +0 -0
  146. /package/{cjs → build-tsc-cjs}/types/lookup.js +0 -0
  147. /package/{cjs → build-tsc-cjs}/types/types.js +0 -0
  148. /package/{cjs → build-tsc-cjs}/util/encodeTypes.js +0 -0
  149. /package/{cjs → build-tsc-cjs}/util/getTypeDef.js +0 -0
  150. /package/{cjs → build-tsc-cjs}/util/index.js +0 -0
  151. /package/{cjs → build-tsc-cjs}/util/typeSplit.js +0 -0
  152. /package/{cjs → build-tsc-cjs}/util/xcm.js +0 -0
  153. /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
  154. /package/{create → build-tsc-esm/create}/class.js +0 -0
  155. /package/{create → build-tsc-esm/create}/index.js +0 -0
  156. /package/{create → build-tsc-esm/create}/type.js +0 -0
  157. /package/{exports.js → build-tsc-esm/exports.js} +0 -0
  158. /package/{index.js → build-tsc-esm/index.js} +0 -0
  159. /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
  160. /package/{types → build-tsc-esm/types}/augmentRegistry.js +0 -0
  161. /package/{types → build-tsc-esm/types}/index.js +0 -0
  162. /package/{types → build-tsc-esm/types}/lookup.js +0 -0
  163. /package/{types → build-tsc-esm/types}/types.js +0 -0
  164. /package/{util → build-tsc-esm/util}/encodeTypes.js +0 -0
  165. /package/{util → build-tsc-esm/util}/getTypeDef.js +0 -0
  166. /package/{util → build-tsc-esm/util}/index.js +0 -0
  167. /package/{util → build-tsc-esm/util}/typeSplit.js +0 -0
  168. /package/{util → build-tsc-esm/util}/xcm.js +0 -0
@@ -0,0 +1,291 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
4
+ "description": "Type creator helpers",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-api/tree/master/packages/types-create#readme",
9
+ "license": "Apache-2.0",
10
+ "name": "@pezkuwi/types-create",
11
+ "repository": {
12
+ "directory": "packages/types-create",
13
+ "type": "git",
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-api.git"
15
+ },
16
+ "sideEffects": [
17
+ "./packageDetect.js",
18
+ "./cjs/packageDetect.js"
19
+ ],
20
+ "type": "module",
21
+ "version": "16.5.18",
22
+ "main": "./cjs/index.js",
23
+ "module": "./cjs/index.js",
24
+ "types": "./cjs/index.d.ts",
25
+ "exports": {
26
+ "./cjs/package.json": "./cjs/package.json",
27
+ "./cjs/*": "./cjs/*.js",
28
+ ".": {
29
+ "module": {
30
+ "types": "./index.d.ts",
31
+ "default": "./index.js"
32
+ },
33
+ "require": {
34
+ "types": "./cjs/index.d.ts",
35
+ "default": "./cjs/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./index.d.ts",
39
+ "default": "./index.js"
40
+ }
41
+ },
42
+ "./bundle": {
43
+ "module": {
44
+ "types": "./bundle.d.ts",
45
+ "default": "./bundle.js"
46
+ },
47
+ "require": {
48
+ "types": "./cjs/bundle.d.ts",
49
+ "default": "./cjs/bundle.js"
50
+ },
51
+ "default": {
52
+ "types": "./bundle.d.ts",
53
+ "default": "./bundle.js"
54
+ }
55
+ },
56
+ "./create": {
57
+ "module": {
58
+ "types": "./create/index.d.ts",
59
+ "default": "./create/index.js"
60
+ },
61
+ "require": {
62
+ "types": "./cjs/create/index.d.ts",
63
+ "default": "./cjs/create/index.js"
64
+ },
65
+ "default": {
66
+ "types": "./create/index.d.ts",
67
+ "default": "./create/index.js"
68
+ }
69
+ },
70
+ "./create/class": {
71
+ "module": {
72
+ "types": "./create/class.d.ts",
73
+ "default": "./create/class.js"
74
+ },
75
+ "require": {
76
+ "types": "./cjs/create/class.d.ts",
77
+ "default": "./cjs/create/class.js"
78
+ },
79
+ "default": {
80
+ "types": "./create/class.d.ts",
81
+ "default": "./create/class.js"
82
+ }
83
+ },
84
+ "./create/type": {
85
+ "module": {
86
+ "types": "./create/type.d.ts",
87
+ "default": "./create/type.js"
88
+ },
89
+ "require": {
90
+ "types": "./cjs/create/type.d.ts",
91
+ "default": "./cjs/create/type.js"
92
+ },
93
+ "default": {
94
+ "types": "./create/type.d.ts",
95
+ "default": "./create/type.js"
96
+ }
97
+ },
98
+ "./exports": {
99
+ "module": {
100
+ "types": "./exports.d.ts",
101
+ "default": "./exports.js"
102
+ },
103
+ "require": {
104
+ "types": "./cjs/exports.d.ts",
105
+ "default": "./cjs/exports.js"
106
+ },
107
+ "default": {
108
+ "types": "./exports.d.ts",
109
+ "default": "./exports.js"
110
+ }
111
+ },
112
+ "./package.json": {
113
+ "require": "./cjs/package.json",
114
+ "default": "./package.json"
115
+ },
116
+ "./packageDetect": {
117
+ "module": {
118
+ "types": "./packageDetect.d.ts",
119
+ "default": "./packageDetect.js"
120
+ },
121
+ "require": {
122
+ "types": "./cjs/packageDetect.d.ts",
123
+ "default": "./cjs/packageDetect.js"
124
+ },
125
+ "default": {
126
+ "types": "./packageDetect.d.ts",
127
+ "default": "./packageDetect.js"
128
+ }
129
+ },
130
+ "./packageInfo.js": {
131
+ "module": {
132
+ "types": "./packageInfo.d.ts",
133
+ "default": "./packageInfo.js"
134
+ },
135
+ "require": {
136
+ "types": "./cjs/packageInfo.d.ts",
137
+ "default": "./cjs/packageInfo.js"
138
+ },
139
+ "default": {
140
+ "types": "./packageInfo.d.ts",
141
+ "default": "./packageInfo.js"
142
+ }
143
+ },
144
+ "./packageInfo": {
145
+ "module": {
146
+ "types": "./packageInfo.d.ts",
147
+ "default": "./packageInfo.js"
148
+ },
149
+ "require": {
150
+ "types": "./cjs/packageInfo.d.ts",
151
+ "default": "./cjs/packageInfo.js"
152
+ },
153
+ "default": {
154
+ "types": "./packageInfo.d.ts",
155
+ "default": "./packageInfo.js"
156
+ }
157
+ },
158
+ "./types": {
159
+ "module": {
160
+ "types": "./types/index.d.ts",
161
+ "default": "./types/index.js"
162
+ },
163
+ "require": {
164
+ "types": "./cjs/types/index.d.ts",
165
+ "default": "./cjs/types/index.js"
166
+ },
167
+ "default": {
168
+ "types": "./types/index.d.ts",
169
+ "default": "./types/index.js"
170
+ }
171
+ },
172
+ "./types/augmentRegistry": {
173
+ "module": {
174
+ "types": "./types/augmentRegistry.d.ts",
175
+ "default": "./types/augmentRegistry.js"
176
+ },
177
+ "require": {
178
+ "types": "./cjs/types/augmentRegistry.d.ts",
179
+ "default": "./cjs/types/augmentRegistry.js"
180
+ },
181
+ "default": {
182
+ "types": "./types/augmentRegistry.d.ts",
183
+ "default": "./types/augmentRegistry.js"
184
+ }
185
+ },
186
+ "./types/lookup": {
187
+ "module": {
188
+ "types": "./types/lookup.d.ts",
189
+ "default": "./types/lookup.js"
190
+ },
191
+ "require": {
192
+ "types": "./cjs/types/lookup.d.ts",
193
+ "default": "./cjs/types/lookup.js"
194
+ },
195
+ "default": {
196
+ "types": "./types/lookup.d.ts",
197
+ "default": "./types/lookup.js"
198
+ }
199
+ },
200
+ "./types/types": {
201
+ "module": {
202
+ "types": "./types/types.d.ts",
203
+ "default": "./types/types.js"
204
+ },
205
+ "require": {
206
+ "types": "./cjs/types/types.d.ts",
207
+ "default": "./cjs/types/types.js"
208
+ },
209
+ "default": {
210
+ "types": "./types/types.d.ts",
211
+ "default": "./types/types.js"
212
+ }
213
+ },
214
+ "./util": {
215
+ "module": {
216
+ "types": "./util/index.d.ts",
217
+ "default": "./util/index.js"
218
+ },
219
+ "require": {
220
+ "types": "./cjs/util/index.d.ts",
221
+ "default": "./cjs/util/index.js"
222
+ },
223
+ "default": {
224
+ "types": "./util/index.d.ts",
225
+ "default": "./util/index.js"
226
+ }
227
+ },
228
+ "./util/encodeTypes": {
229
+ "module": {
230
+ "types": "./util/encodeTypes.d.ts",
231
+ "default": "./util/encodeTypes.js"
232
+ },
233
+ "require": {
234
+ "types": "./cjs/util/encodeTypes.d.ts",
235
+ "default": "./cjs/util/encodeTypes.js"
236
+ },
237
+ "default": {
238
+ "types": "./util/encodeTypes.d.ts",
239
+ "default": "./util/encodeTypes.js"
240
+ }
241
+ },
242
+ "./util/getTypeDef": {
243
+ "module": {
244
+ "types": "./util/getTypeDef.d.ts",
245
+ "default": "./util/getTypeDef.js"
246
+ },
247
+ "require": {
248
+ "types": "./cjs/util/getTypeDef.d.ts",
249
+ "default": "./cjs/util/getTypeDef.js"
250
+ },
251
+ "default": {
252
+ "types": "./util/getTypeDef.d.ts",
253
+ "default": "./util/getTypeDef.js"
254
+ }
255
+ },
256
+ "./util/typeSplit": {
257
+ "module": {
258
+ "types": "./util/typeSplit.d.ts",
259
+ "default": "./util/typeSplit.js"
260
+ },
261
+ "require": {
262
+ "types": "./cjs/util/typeSplit.d.ts",
263
+ "default": "./cjs/util/typeSplit.js"
264
+ },
265
+ "default": {
266
+ "types": "./util/typeSplit.d.ts",
267
+ "default": "./util/typeSplit.js"
268
+ }
269
+ },
270
+ "./util/xcm": {
271
+ "module": {
272
+ "types": "./util/xcm.d.ts",
273
+ "default": "./util/xcm.js"
274
+ },
275
+ "require": {
276
+ "types": "./cjs/util/xcm.d.ts",
277
+ "default": "./cjs/util/xcm.js"
278
+ },
279
+ "default": {
280
+ "types": "./util/xcm.d.ts",
281
+ "default": "./util/xcm.js"
282
+ }
283
+ }
284
+ },
285
+ "dependencies": {
286
+ "@pezkuwi/types": "16.5.9",
287
+ "@pezkuwi/types-codec": "16.5.9",
288
+ "@pezkuwi/util": "14.0.11",
289
+ "tslib": "^2.8.1"
290
+ }
291
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { packageInfo as codecInfo } from '@pezkuwi/types-codec/packageInfo';
2
+ import { detectPackage } from '@pezkuwi/util';
3
+ import { packageInfo } from './packageInfo.js';
4
+ detectPackage(packageInfo, null, [codecInfo]);
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1 @@
1
+ export const packageInfo = { name: '@pezkuwi/types-create', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '16.5.18' };
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1 @@
1
+ import '@pezkuwi/types-codec/types/registry';
@@ -0,0 +1,4 @@
1
+ import './augmentRegistry.js';
2
+ export type { CodecCreateOptions as CreateOptions } from '@pezkuwi/types-codec/types';
3
+ export * from './lookup.js';
4
+ export * from './types.js';
@@ -0,0 +1,3 @@
1
+ import './augmentRegistry.js';
2
+ export * from './lookup.js';
3
+ export * from './types.js';
@@ -0,0 +1,14 @@
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 {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
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
+ }
@@ -0,0 +1,26 @@
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 = {}));
@@ -0,0 +1,11 @@
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 {};
@@ -0,0 +1,123 @@
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
+ }
@@ -0,0 +1,8 @@
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 {};