@pezkuwi/typegen 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.
- package/build/LICENSE +201 -0
- package/build/README.md +3 -0
- package/build/augment.js +2 -0
- package/build/bundle.js +2 -0
- package/build/cjs/augment.d.ts +2 -0
- package/build/cjs/augment.js +4 -0
- package/build/cjs/bundle.d.ts +2 -0
- package/build/cjs/bundle.js +7 -0
- package/build/cjs/extractChain.js +44 -0
- package/build/cjs/fromChain.js +95 -0
- package/build/cjs/fromDefs.js +82 -0
- package/build/cjs/generate/consts.d.ts +5 -0
- package/build/cjs/generate/consts.js +91 -0
- package/build/cjs/generate/errors.d.ts +4 -0
- package/build/cjs/generate/errors.js +59 -0
- package/build/cjs/generate/events.d.ts +5 -0
- package/build/cjs/generate/events.js +139 -0
- package/build/cjs/generate/index.js +23 -0
- package/build/cjs/generate/interfaceRegistry.d.ts +4 -0
- package/build/cjs/generate/interfaceRegistry.js +64 -0
- package/build/cjs/generate/lookup.d.ts +4 -0
- package/build/cjs/generate/lookup.js +240 -0
- package/build/cjs/generate/query.d.ts +5 -0
- package/build/cjs/generate/query.js +140 -0
- package/build/cjs/generate/rpc.d.ts +6 -0
- package/build/cjs/generate/rpc.js +115 -0
- package/build/cjs/generate/runtime.d.ts +7 -0
- package/build/cjs/generate/runtime.js +233 -0
- package/build/cjs/generate/tsDef.d.ts +16 -0
- package/build/cjs/generate/tsDef.js +254 -0
- package/build/cjs/generate/tx.d.ts +5 -0
- package/build/cjs/generate/tx.js +121 -0
- package/build/cjs/generate/types.d.ts +12 -0
- package/build/cjs/generate/types.js +16 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/interfacesTs.js +28 -0
- package/build/cjs/metadataMd.js +652 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/util/assert.js +15 -0
- package/build/cjs/util/derived.js +128 -0
- package/build/cjs/util/docs.js +10 -0
- package/build/cjs/util/file.js +33 -0
- package/build/cjs/util/formatting.js +237 -0
- package/build/cjs/util/imports.js +126 -0
- package/build/cjs/util/index.js +39 -0
- package/build/cjs/util/initMeta.js +22 -0
- package/build/cjs/util/register.js +10 -0
- package/build/cjs/util/wsMeta.js +60 -0
- package/build/extractChain.d.ts +1 -0
- package/build/extractChain.js +40 -0
- package/build/fromChain.d.ts +1 -0
- package/build/fromChain.js +91 -0
- package/build/fromDefs.d.ts +1 -0
- package/build/fromDefs.js +78 -0
- package/build/generate/consts.d.ts +5 -0
- package/build/generate/consts.js +87 -0
- package/build/generate/errors.d.ts +4 -0
- package/build/generate/errors.js +55 -0
- package/build/generate/events.d.ts +5 -0
- package/build/generate/events.js +135 -0
- package/build/generate/index.d.ts +10 -0
- package/build/generate/index.js +10 -0
- package/build/generate/interfaceRegistry.d.ts +4 -0
- package/build/generate/interfaceRegistry.js +59 -0
- package/build/generate/lookup.d.ts +4 -0
- package/build/generate/lookup.js +235 -0
- package/build/generate/query.d.ts +5 -0
- package/build/generate/query.js +136 -0
- package/build/generate/rpc.d.ts +6 -0
- package/build/generate/rpc.js +110 -0
- package/build/generate/runtime.d.ts +7 -0
- package/build/generate/runtime.js +228 -0
- package/build/generate/tsDef.d.ts +16 -0
- package/build/generate/tsDef.js +246 -0
- package/build/generate/tx.d.ts +5 -0
- package/build/generate/tx.js +117 -0
- package/build/generate/types.d.ts +12 -0
- package/build/generate/types.js +13 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/interfacesTs.d.ts +1 -0
- package/build/interfacesTs.js +24 -0
- package/build/metadataMd.d.ts +1 -0
- package/build/metadataMd.js +648 -0
- package/build/package.json +548 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +6 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/scripts/pezkuwi-types-chain-info.mjs +7 -0
- package/build/scripts/pezkuwi-types-from-chain.mjs +7 -0
- package/build/scripts/pezkuwi-types-from-defs.mjs +7 -0
- package/build/scripts/pezkuwi-types-internal-interfaces.mjs +7 -0
- package/build/scripts/pezkuwi-types-internal-metadata.mjs +7 -0
- package/build/templates/calls.hbs +30 -0
- package/build/templates/consts.hbs +28 -0
- package/build/templates/docs.hbs +7 -0
- package/build/templates/errors.hbs +28 -0
- package/build/templates/events.hbs +28 -0
- package/build/templates/header.hbs +2 -0
- package/build/templates/interfaceRegistry.hbs +15 -0
- package/build/templates/lookup/defs-named.hbs +12 -0
- package/build/templates/lookup/defs.hbs +15 -0
- package/build/templates/lookup/index.hbs +3 -0
- package/build/templates/lookup/types.hbs +14 -0
- package/build/templates/query.hbs +29 -0
- package/build/templates/rpc.hbs +22 -0
- package/build/templates/tsDef/index.hbs +3 -0
- package/build/templates/tsDef/moduleTypes.hbs +10 -0
- package/build/templates/tsDef/types.hbs +7 -0
- package/build/templates/tx.hbs +30 -0
- package/build/util/assert.d.ts +2 -0
- package/build/util/assert.js +10 -0
- package/build/util/derived.d.ts +4 -0
- package/build/util/derived.js +125 -0
- package/build/util/docs.d.ts +1 -0
- package/build/util/docs.js +6 -0
- package/build/util/file.d.ts +2 -0
- package/build/util/file.js +28 -0
- package/build/util/formatting.d.ts +11 -0
- package/build/util/formatting.js +230 -0
- package/build/util/imports.d.ts +23 -0
- package/build/util/imports.js +121 -0
- package/build/util/index.d.ts +16 -0
- package/build/util/index.js +34 -0
- package/build/util/initMeta.d.ts +12 -0
- package/build/util/initMeta.js +19 -0
- package/build/util/register.d.ts +4 -0
- package/build/util/register.js +7 -0
- package/build/util/wsMeta.d.ts +4 -0
- package/build/util/wsMeta.js +55 -0
- package/build-tsc-cjs/packageDetect.js +8 -0
- package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
- package/build-tsc-esm/generate/consts.js +87 -0
- package/build-tsc-esm/generate/errors.js +55 -0
- package/build-tsc-esm/generate/events.js +135 -0
- package/build-tsc-esm/generate/interfaceRegistry.js +59 -0
- package/build-tsc-esm/generate/lookup.js +235 -0
- package/build-tsc-esm/generate/query.js +136 -0
- package/build-tsc-esm/generate/rpc.js +110 -0
- package/build-tsc-esm/generate/runtime.js +228 -0
- package/build-tsc-esm/generate/tsDef.js +246 -0
- package/build-tsc-esm/generate/tx.js +117 -0
- package/build-tsc-esm/generate/types.js +13 -0
- package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
- package/package.json +27 -27
- package/src/augment.ts +5 -0
- package/src/bundle.ts +5 -0
- package/src/extractChain.ts +54 -0
- package/src/fromChain.ts +123 -0
- package/src/fromDefs.ts +106 -0
- package/src/generate/consts.ts +112 -0
- package/src/generate/errors.ts +75 -0
- package/src/generate/events.ts +165 -0
- package/src/generate/index.ts +13 -0
- package/src/generate/interfaceRegistry.ts +85 -0
- package/src/generate/lookup.ts +322 -0
- package/src/generate/query.ts +169 -0
- package/src/generate/rpc.ts +158 -0
- package/src/generate/runtime.ts +293 -0
- package/src/generate/tsDef.ts +321 -0
- package/src/generate/tx.ts +152 -0
- package/src/generate/types.ts +26 -0
- package/src/index.ts +6 -0
- package/src/interfacesTs.ts +35 -0
- package/src/metadataMd.ts +844 -0
- package/src/packageDetect.ts +14 -0
- package/src/packageInfo.ts +6 -0
- package/src/templates/calls.hbs +30 -0
- package/src/templates/consts.hbs +28 -0
- package/src/templates/docs.hbs +7 -0
- package/src/templates/errors.hbs +28 -0
- package/src/templates/events.hbs +28 -0
- package/src/templates/header.hbs +2 -0
- package/src/templates/interfaceRegistry.hbs +15 -0
- package/src/templates/lookup/defs-named.hbs +12 -0
- package/src/templates/lookup/defs.hbs +15 -0
- package/src/templates/lookup/index.hbs +3 -0
- package/src/templates/lookup/types.hbs +14 -0
- package/src/templates/query.hbs +29 -0
- package/src/templates/rpc.hbs +22 -0
- package/src/templates/tsDef/index.hbs +3 -0
- package/src/templates/tsDef/moduleTypes.hbs +10 -0
- package/src/templates/tsDef/types.hbs +7 -0
- package/src/templates/tx.hbs +30 -0
- package/src/util/assert.ts +18 -0
- package/src/util/derived.spec.ts +58 -0
- package/src/util/derived.ts +133 -0
- package/src/util/docs.ts +13 -0
- package/src/util/file.ts +42 -0
- package/src/util/formatting.spec.ts +30 -0
- package/src/util/formatting.ts +322 -0
- package/src/util/imports.ts +164 -0
- package/src/util/index.ts +42 -0
- package/src/util/initMeta.ts +37 -0
- package/src/util/register.ts +12 -0
- package/src/util/wsMeta.ts +70 -0
- package/tsconfig.build.json +28 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.scripts.json +19 -0
- package/tsconfig.spec.json +17 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
- /package/{cjs → build}/augment.d.ts +0 -0
- /package/{cjs → build}/bundle.d.ts +0 -0
- /package/{extractChain.d.ts → build/cjs/extractChain.d.ts} +0 -0
- /package/{fromChain.d.ts → build/cjs/fromChain.d.ts} +0 -0
- /package/{fromDefs.d.ts → build/cjs/fromDefs.d.ts} +0 -0
- /package/{generate → build/cjs/generate}/index.d.ts +0 -0
- /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
- /package/{interfacesTs.d.ts → build/cjs/interfacesTs.d.ts} +0 -0
- /package/{metadataMd.d.ts → build/cjs/metadataMd.d.ts} +0 -0
- /package/{cjs → build/cjs}/package.json +0 -0
- /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
- /package/{cjs → build/cjs}/packageDetect.js +0 -0
- /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
- /package/{util → build/cjs/util}/assert.d.ts +0 -0
- /package/{util → build/cjs/util}/derived.d.ts +0 -0
- /package/{util → build/cjs/util}/docs.d.ts +0 -0
- /package/{util → build/cjs/util}/file.d.ts +0 -0
- /package/{util → build/cjs/util}/formatting.d.ts +0 -0
- /package/{util → build/cjs/util}/imports.d.ts +0 -0
- /package/{util → build/cjs/util}/index.d.ts +0 -0
- /package/{util → build/cjs/util}/initMeta.d.ts +0 -0
- /package/{util → build/cjs/util}/register.d.ts +0 -0
- /package/{util → build/cjs/util}/wsMeta.d.ts +0 -0
- /package/{augment.d.ts → build-tsc/augment.d.ts} +0 -0
- /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
- /package/{cjs → build-tsc}/extractChain.d.ts +0 -0
- /package/{cjs → build-tsc}/fromChain.d.ts +0 -0
- /package/{cjs → build-tsc}/fromDefs.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/consts.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/errors.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/events.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/index.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/interfaceRegistry.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/lookup.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/query.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/rpc.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/runtime.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/tsDef.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/tx.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/types.d.ts +0 -0
- /package/{cjs → build-tsc}/index.d.ts +0 -0
- /package/{cjs → build-tsc}/interfacesTs.d.ts +0 -0
- /package/{cjs → build-tsc}/metadataMd.d.ts +0 -0
- /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
- /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
- /package/{cjs → build-tsc}/util/assert.d.ts +0 -0
- /package/{cjs → build-tsc}/util/derived.d.ts +0 -0
- /package/{cjs → build-tsc}/util/docs.d.ts +0 -0
- /package/{cjs → build-tsc}/util/file.d.ts +0 -0
- /package/{cjs → build-tsc}/util/formatting.d.ts +0 -0
- /package/{cjs → build-tsc}/util/imports.d.ts +0 -0
- /package/{cjs → build-tsc}/util/index.d.ts +0 -0
- /package/{cjs → build-tsc}/util/initMeta.d.ts +0 -0
- /package/{cjs → build-tsc}/util/register.d.ts +0 -0
- /package/{cjs → build-tsc}/util/wsMeta.d.ts +0 -0
- /package/{cjs → build-tsc-cjs}/augment.js +0 -0
- /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
- /package/{cjs → build-tsc-cjs}/extractChain.js +0 -0
- /package/{cjs → build-tsc-cjs}/fromChain.js +0 -0
- /package/{cjs → build-tsc-cjs}/fromDefs.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/consts.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/errors.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/events.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/interfaceRegistry.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/lookup.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/query.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/rpc.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/runtime.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/tsDef.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/tx.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/types.js +0 -0
- /package/{cjs → build-tsc-cjs}/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/interfacesTs.js +0 -0
- /package/{cjs → build-tsc-cjs}/metadataMd.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/assert.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/derived.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/docs.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/file.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/formatting.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/imports.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/initMeta.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/register.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/wsMeta.js +0 -0
- /package/{augment.js → build-tsc-esm/augment.js} +0 -0
- /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
- /package/{extractChain.js → build-tsc-esm/extractChain.js} +0 -0
- /package/{fromChain.js → build-tsc-esm/fromChain.js} +0 -0
- /package/{fromDefs.js → build-tsc-esm/fromDefs.js} +0 -0
- /package/{generate → build-tsc-esm/generate}/index.js +0 -0
- /package/{index.js → build-tsc-esm/index.js} +0 -0
- /package/{interfacesTs.js → build-tsc-esm/interfacesTs.js} +0 -0
- /package/{metadataMd.js → build-tsc-esm/metadataMd.js} +0 -0
- /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
- /package/{util → build-tsc-esm/util}/assert.js +0 -0
- /package/{util → build-tsc-esm/util}/derived.js +0 -0
- /package/{util → build-tsc-esm/util}/docs.js +0 -0
- /package/{util → build-tsc-esm/util}/file.js +0 -0
- /package/{util → build-tsc-esm/util}/formatting.js +0 -0
- /package/{util → build-tsc-esm/util}/imports.js +0 -0
- /package/{util → build-tsc-esm/util}/index.js +0 -0
- /package/{util → build-tsc-esm/util}/initMeta.js +0 -0
- /package/{util → build-tsc-esm/util}/register.js +0 -0
- /package/{util → build-tsc-esm/util}/wsMeta.js +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSimilarTypes = getSimilarTypes;
|
|
4
|
+
const generic_1 = require("@pezkuwi/types/generic");
|
|
5
|
+
const definitions_1 = require("@pezkuwi/types/interfaces/democracy/definitions");
|
|
6
|
+
const types_codec_1 = require("@pezkuwi/types-codec");
|
|
7
|
+
const types_create_1 = require("@pezkuwi/types-create");
|
|
8
|
+
const util_1 = require("@pezkuwi/util");
|
|
9
|
+
const formatting_js_1 = require("./formatting.js");
|
|
10
|
+
const imports_js_1 = require("./imports.js");
|
|
11
|
+
function arrayToStrType(arr) {
|
|
12
|
+
return `${arr.map((c) => `'${c}'`).join(' | ')}`;
|
|
13
|
+
}
|
|
14
|
+
const voteConvictions = arrayToStrType(definitions_1.AllConvictions);
|
|
15
|
+
/** @internal */
|
|
16
|
+
function getSimilarTypes(registry, definitions, _type, imports) {
|
|
17
|
+
const typeParts = _type.split('::');
|
|
18
|
+
const type = typeParts[typeParts.length - 1];
|
|
19
|
+
const possibleTypes = [(0, formatting_js_1.formatType)(registry, definitions, type, imports)];
|
|
20
|
+
if (type === 'Extrinsic') {
|
|
21
|
+
(0, imports_js_1.setImports)(definitions, imports, ['IExtrinsic']);
|
|
22
|
+
return ['Extrinsic', 'IExtrinsic', 'string', 'Uint8Array'];
|
|
23
|
+
}
|
|
24
|
+
else if (type === 'Keys') {
|
|
25
|
+
// This one is weird... surely it should popup as a Tuple? (but either way better as defined hex)
|
|
26
|
+
return ['Keys', 'string', 'Uint8Array'];
|
|
27
|
+
}
|
|
28
|
+
else if (type === 'StorageKey') {
|
|
29
|
+
// TODO We can do better
|
|
30
|
+
return ['StorageKey', 'string', 'Uint8Array', 'any'];
|
|
31
|
+
}
|
|
32
|
+
else if (type === '()') {
|
|
33
|
+
return ['null'];
|
|
34
|
+
}
|
|
35
|
+
const Clazz = registry.createClass(type);
|
|
36
|
+
if ((0, util_1.isChildClass)(types_codec_1.Vec, Clazz)) {
|
|
37
|
+
const vecDef = (0, types_create_1.getTypeDef)(type);
|
|
38
|
+
const subDef = (vecDef.sub);
|
|
39
|
+
// this could be that we define a Vec type and refer to it by name
|
|
40
|
+
if (subDef) {
|
|
41
|
+
if (subDef.info === types_create_1.TypeDefInfo.Plain) {
|
|
42
|
+
possibleTypes.push(`(${getSimilarTypes(registry, definitions, subDef.type, imports).join(' | ')})[]`);
|
|
43
|
+
}
|
|
44
|
+
else if (subDef.info === types_create_1.TypeDefInfo.Tuple) {
|
|
45
|
+
const subs = subDef.sub.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
|
|
46
|
+
possibleTypes.push(`([${subs.join(', ')}])[]`);
|
|
47
|
+
}
|
|
48
|
+
else if (subDef.info === types_create_1.TypeDefInfo.Option || subDef.info === types_create_1.TypeDefInfo.Vec || subDef.info === types_create_1.TypeDefInfo.VecFixed) {
|
|
49
|
+
// TODO: Add possibleTypes so imports work
|
|
50
|
+
}
|
|
51
|
+
else if (subDef.info === types_create_1.TypeDefInfo.Struct) {
|
|
52
|
+
// TODO: Add possibleTypes so imports work
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new Error(`Unhandled subtype in Vec, ${(0, util_1.stringify)(subDef)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if ((0, util_1.isChildClass)(types_codec_1.Enum, Clazz)) {
|
|
60
|
+
const { defKeys, isBasic } = new Clazz(registry);
|
|
61
|
+
const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
|
|
62
|
+
if (isBasic) {
|
|
63
|
+
possibleTypes.push(arrayToStrType(keys), 'number');
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// TODO We don't really want any here, these should be expanded
|
|
67
|
+
possibleTypes.push(...keys.map((k) => `{ ${k}: any }`), 'string');
|
|
68
|
+
}
|
|
69
|
+
possibleTypes.push('Uint8Array');
|
|
70
|
+
}
|
|
71
|
+
else if ((0, util_1.isChildClass)(types_codec_1.AbstractInt, Clazz) || (0, util_1.isChildClass)(types_codec_1.Compact, Clazz)) {
|
|
72
|
+
possibleTypes.push('AnyNumber', 'Uint8Array');
|
|
73
|
+
}
|
|
74
|
+
else if ((0, util_1.isChildClass)(generic_1.GenericLookupSource, Clazz)) {
|
|
75
|
+
possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'LookupSource', 'string', 'Uint8Array');
|
|
76
|
+
}
|
|
77
|
+
else if ((0, util_1.isChildClass)(generic_1.GenericAccountId, Clazz)) {
|
|
78
|
+
possibleTypes.push('string', 'Uint8Array');
|
|
79
|
+
}
|
|
80
|
+
else if ((0, util_1.isChildClass)(generic_1.GenericCall, Clazz)) {
|
|
81
|
+
possibleTypes.push('IMethod', 'string', 'Uint8Array');
|
|
82
|
+
}
|
|
83
|
+
else if ((0, util_1.isChildClass)(types_codec_1.bool, Clazz)) {
|
|
84
|
+
possibleTypes.push('boolean', 'Uint8Array');
|
|
85
|
+
}
|
|
86
|
+
else if ((0, util_1.isChildClass)(types_codec_1.Null, Clazz)) {
|
|
87
|
+
possibleTypes.push('null');
|
|
88
|
+
}
|
|
89
|
+
else if ((0, util_1.isChildClass)(types_codec_1.Struct, Clazz)) {
|
|
90
|
+
const s = new Clazz(registry);
|
|
91
|
+
const obj = s.defKeys.map((key) => `${key}?: any`).join('; ');
|
|
92
|
+
possibleTypes.push(`{ ${obj} }`, 'string', 'Uint8Array');
|
|
93
|
+
}
|
|
94
|
+
else if ((0, util_1.isChildClass)(types_codec_1.Option, Clazz)) {
|
|
95
|
+
possibleTypes.push('null', 'Uint8Array');
|
|
96
|
+
const optDef = (0, types_create_1.getTypeDef)(type);
|
|
97
|
+
const subDef = (optDef.sub);
|
|
98
|
+
if (subDef) {
|
|
99
|
+
possibleTypes.push(...getSimilarTypes(registry, definitions, subDef.type, imports));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
possibleTypes.push('object', 'string');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if ((0, util_1.isChildClass)(generic_1.GenericVote, Clazz)) {
|
|
106
|
+
possibleTypes.push(`{ aye: boolean; conviction?: ${voteConvictions} | number }`, 'boolean', 'string', 'Uint8Array');
|
|
107
|
+
}
|
|
108
|
+
else if ((0, util_1.isChildClass)(types_codec_1.WrapperKeepOpaque, Clazz) || (0, util_1.isChildClass)(types_codec_1.WrapperOpaque, Clazz)) {
|
|
109
|
+
// TODO inspect container
|
|
110
|
+
possibleTypes.push('object', 'string', 'Uint8Array');
|
|
111
|
+
}
|
|
112
|
+
else if ((0, util_1.isChildClass)(Uint8Array, Clazz)) {
|
|
113
|
+
possibleTypes.push('string', 'Uint8Array');
|
|
114
|
+
}
|
|
115
|
+
else if ((0, util_1.isChildClass)(String, Clazz)) {
|
|
116
|
+
possibleTypes.push('string');
|
|
117
|
+
}
|
|
118
|
+
else if ((0, util_1.isChildClass)(types_codec_1.Tuple, Clazz)) {
|
|
119
|
+
const tupDef = (0, types_create_1.getTypeDef)(type);
|
|
120
|
+
const subDef = tupDef.sub;
|
|
121
|
+
// this could be that we define a Tuple type and refer to it by name
|
|
122
|
+
if (Array.isArray(subDef)) {
|
|
123
|
+
const subs = subDef.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
|
|
124
|
+
possibleTypes.push(`[${subs.join(', ')}]`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return [...new Set(possibleTypes)];
|
|
128
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__TYPEGEN_DUMMY_DOCS = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const handlebars_1 = tslib_1.__importDefault(require("handlebars"));
|
|
6
|
+
const file_js_1 = require("./file.js");
|
|
7
|
+
handlebars_1.default.registerPartial({
|
|
8
|
+
docs: handlebars_1.default.compile((0, file_js_1.readTemplate)('docs'))
|
|
9
|
+
});
|
|
10
|
+
exports.__TYPEGEN_DUMMY_DOCS = 'DUMMY_DOCS';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeFile = writeFile;
|
|
4
|
+
exports.readTemplate = readTemplate;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
9
|
+
const packageInfo_js_1 = require("../packageInfo.js");
|
|
10
|
+
function writeFile(dest, generator, noLog) {
|
|
11
|
+
!noLog && console.log(`${dest}\n\tGenerating`);
|
|
12
|
+
let generated = generator();
|
|
13
|
+
while (generated.includes('\n\n\n')) {
|
|
14
|
+
generated = generated.replace(/\n\n\n/g, '\n\n');
|
|
15
|
+
}
|
|
16
|
+
!noLog && console.log('\tWriting');
|
|
17
|
+
node_fs_1.default.writeFileSync(dest, generated, { flag: 'w' });
|
|
18
|
+
!noLog && console.log('');
|
|
19
|
+
}
|
|
20
|
+
function readTemplate(template) {
|
|
21
|
+
// Inside the api repo itself, it will be 'auto'
|
|
22
|
+
const rootDir = packageInfo_js_1.packageInfo.path === 'auto'
|
|
23
|
+
? node_path_1.default.join(node_process_1.default.cwd(), 'packages/typegen/src')
|
|
24
|
+
: packageInfo_js_1.packageInfo.path;
|
|
25
|
+
// NOTE With cjs in a subdir, search one lower as well
|
|
26
|
+
const file = ['./templates', '../templates']
|
|
27
|
+
.map((p) => node_path_1.default.join(rootDir, p, `${template}.hbs`))
|
|
28
|
+
.find((p) => node_fs_1.default.existsSync(p));
|
|
29
|
+
if (!file) {
|
|
30
|
+
throw new Error(`Unable to locate ${template}.hbs from ${rootDir}`);
|
|
31
|
+
}
|
|
32
|
+
return node_fs_1.default.readFileSync(file).toString();
|
|
33
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HEADER = void 0;
|
|
4
|
+
exports.exportInterface = exportInterface;
|
|
5
|
+
exports.formatType = formatType;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const handlebars_1 = tslib_1.__importDefault(require("handlebars"));
|
|
8
|
+
const typesCodec = tslib_1.__importStar(require("@pezkuwi/types-codec"));
|
|
9
|
+
const types_create_1 = require("@pezkuwi/types-create");
|
|
10
|
+
const util_1 = require("@pezkuwi/util");
|
|
11
|
+
const file_js_1 = require("./file.js");
|
|
12
|
+
const imports_js_1 = require("./imports.js");
|
|
13
|
+
function rebrandTypeName(typeName) {
|
|
14
|
+
return typeName
|
|
15
|
+
// Main projects
|
|
16
|
+
.replace(/Polkadot/g, 'Pezkuwi')
|
|
17
|
+
.replace(/Substrate/g, 'Bizinikiwi')
|
|
18
|
+
.replace(/Cumulus/g, 'Pezcumulus')
|
|
19
|
+
// Networks
|
|
20
|
+
.replace(/Kusama/g, 'Dicle')
|
|
21
|
+
.replace(/Westend/g, 'Zagros')
|
|
22
|
+
.replace(/Rococo/g, 'Pezkuwichain')
|
|
23
|
+
// Chain types
|
|
24
|
+
.replace(/Parachain/g, 'Teyrchain')
|
|
25
|
+
// Module prefixes (in PascalCase type names)
|
|
26
|
+
.replace(/Frame(?=[A-Z])/g, 'Pezframe')
|
|
27
|
+
.replace(/Pallet(?=[A-Z])/g, 'Pezpallet')
|
|
28
|
+
// Primitives prefixes (sp_ becomes Sp in type names)
|
|
29
|
+
.replace(/^Sp(?=[A-Z])/g, 'Pezsp')
|
|
30
|
+
.replace(/([^a-zA-Z])Sp(?=[A-Z])/g, '$1Pezsp')
|
|
31
|
+
// Client prefixes (sc_ becomes Sc in type names)
|
|
32
|
+
.replace(/^Sc(?=[A-Z])/g, 'Pezsc')
|
|
33
|
+
.replace(/([^a-zA-Z])Sc(?=[A-Z])/g, '$1Pezsc');
|
|
34
|
+
}
|
|
35
|
+
const NO_CODEC = ['Tuple', 'VecFixed'];
|
|
36
|
+
const ON_CODEC = Object.keys(typesCodec);
|
|
37
|
+
const ON_CODEC_TYPES = ['Codec', 'AnyJson', 'AnyFunction', 'AnyNumber', 'AnyString', 'AnyTuple', 'AnyU8a', 'ICompact', 'IEnum', 'IMap', 'INumber', 'IOption', 'IResult', 'ISet', 'IStruct', 'ITuple', 'IU8a', 'IVec', 'IMethod'];
|
|
38
|
+
const HEADER = (type) => `// Auto-generated via \`yarn pezkuwi-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
|
|
39
|
+
exports.HEADER = HEADER;
|
|
40
|
+
function extractImports({ imports, types }) {
|
|
41
|
+
const toplevel = [
|
|
42
|
+
...Object.keys(imports.codecTypes),
|
|
43
|
+
...Object.keys(imports.extrinsicTypes),
|
|
44
|
+
...Object.keys(imports.genericTypes),
|
|
45
|
+
...Object.keys(imports.metadataTypes),
|
|
46
|
+
...Object.keys(imports.primitiveTypes)
|
|
47
|
+
];
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
file: '@pezkuwi/types',
|
|
51
|
+
types: toplevel.filter((n) => !NO_CODEC.includes(n) && !ON_CODEC.includes(n))
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
file: '@pezkuwi/types/lookup',
|
|
55
|
+
types: Object.keys(imports.lookupTypes)
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
file: '@pezkuwi/types/types',
|
|
59
|
+
types: Object.keys(imports.typesTypes).filter((n) => !ON_CODEC_TYPES.includes(n))
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
file: '@pezkuwi/types-codec',
|
|
63
|
+
types: toplevel.filter((n) => !NO_CODEC.includes(n) && ON_CODEC.includes(n))
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
file: '@pezkuwi/types-codec/types',
|
|
67
|
+
types: Object.keys(imports.typesTypes).filter((n) => ON_CODEC_TYPES.includes(n))
|
|
68
|
+
},
|
|
69
|
+
...types
|
|
70
|
+
]
|
|
71
|
+
.filter(({ types }) => types.length)
|
|
72
|
+
.sort(({ file }, b) => file.localeCompare(b.file))
|
|
73
|
+
.map(({ file, types }) => `import type { ${types.sort().join(', ')} } from '${file}';`);
|
|
74
|
+
}
|
|
75
|
+
handlebars_1.default.registerPartial({
|
|
76
|
+
header: handlebars_1.default.compile((0, file_js_1.readTemplate)('header'))
|
|
77
|
+
});
|
|
78
|
+
handlebars_1.default.registerHelper({
|
|
79
|
+
importsAll() {
|
|
80
|
+
return extractImports(this)
|
|
81
|
+
.join('\n');
|
|
82
|
+
},
|
|
83
|
+
importsPackage() {
|
|
84
|
+
return extractImports(this)
|
|
85
|
+
.filter((l) => !l.includes("from '."))
|
|
86
|
+
.join('\n ');
|
|
87
|
+
},
|
|
88
|
+
importsRelative() {
|
|
89
|
+
return extractImports(this)
|
|
90
|
+
.filter((l) => l.includes("from '."))
|
|
91
|
+
.join('\n');
|
|
92
|
+
},
|
|
93
|
+
trim(options) {
|
|
94
|
+
return options.fn(this).trim();
|
|
95
|
+
},
|
|
96
|
+
upper(options) {
|
|
97
|
+
return options.fn(this).toUpperCase();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
/** @internal */
|
|
101
|
+
function exportInterface(lookupIndex = -1, name = '', base, body = '', withShortcut = false) {
|
|
102
|
+
// * @description extends [[${base}]]
|
|
103
|
+
const doc = withShortcut
|
|
104
|
+
? ''
|
|
105
|
+
: `/** @name ${name}${lookupIndex !== -1 ? ` (${lookupIndex})` : ''} */\n`;
|
|
106
|
+
return `${doc}${withShortcut ? '' : `export interface ${name} extends ${base} `}{${body.length ? '\n' : ''}${body}${withShortcut ? ' ' : ''}}`;
|
|
107
|
+
}
|
|
108
|
+
function singleParamNotation(registry, wrapper, typeDef, definitions, imports, withShortcut) {
|
|
109
|
+
const sub = typeDef.sub;
|
|
110
|
+
const lookupName = rebrandTypeName(sub.lookupName || '');
|
|
111
|
+
(0, imports_js_1.setImports)(definitions, imports, [wrapper, lookupName]);
|
|
112
|
+
return (0, types_create_1.paramsNotation)(wrapper, lookupName || formatType(registry, definitions, sub.type, imports, withShortcut));
|
|
113
|
+
}
|
|
114
|
+
function dualParamsNotation(registry, wrapper, typeDef, definitions, imports, withShortcut) {
|
|
115
|
+
const [a, b] = typeDef.sub;
|
|
116
|
+
const aLookupName = rebrandTypeName(a.lookupName || '');
|
|
117
|
+
const bLookupName = rebrandTypeName(b.lookupName || '');
|
|
118
|
+
(0, imports_js_1.setImports)(definitions, imports, [wrapper, aLookupName, bLookupName]);
|
|
119
|
+
return (0, types_create_1.paramsNotation)(wrapper, [
|
|
120
|
+
aLookupName || formatType(registry, definitions, a.type, imports, withShortcut),
|
|
121
|
+
bLookupName || formatType(registry, definitions, b.type, imports, withShortcut)
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
const formatters = {
|
|
125
|
+
[types_create_1.TypeDefInfo.Compact]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
126
|
+
return singleParamNotation(registry, 'Compact', typeDef, definitions, imports, withShortcut);
|
|
127
|
+
},
|
|
128
|
+
[types_create_1.TypeDefInfo.DoNotConstruct]: (_registry, _typeDef, definitions, imports, _withShortcut) => {
|
|
129
|
+
(0, imports_js_1.setImports)(definitions, imports, ['DoNotConstruct']);
|
|
130
|
+
return 'DoNotConstruct';
|
|
131
|
+
},
|
|
132
|
+
[types_create_1.TypeDefInfo.Enum]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
133
|
+
if (typeDef.lookupName) {
|
|
134
|
+
return rebrandTypeName(typeDef.lookupName);
|
|
135
|
+
}
|
|
136
|
+
throw new Error(`TypeDefInfo.Enum: Parameter formatting not implemented on ${(0, util_1.stringify)(typeDef)}`);
|
|
137
|
+
},
|
|
138
|
+
[types_create_1.TypeDefInfo.Int]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
139
|
+
throw new Error(`TypeDefInfo.Int: Parameter formatting not implemented on ${(0, util_1.stringify)(typeDef)}`);
|
|
140
|
+
},
|
|
141
|
+
[types_create_1.TypeDefInfo.UInt]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
142
|
+
throw new Error(`TypeDefInfo.UInt: Parameter formatting not implemented on ${(0, util_1.stringify)(typeDef)}`);
|
|
143
|
+
},
|
|
144
|
+
[types_create_1.TypeDefInfo.Null]: (_registry, _typeDef, definitions, imports, _withShortcut) => {
|
|
145
|
+
(0, imports_js_1.setImports)(definitions, imports, ['Null']);
|
|
146
|
+
return 'Null';
|
|
147
|
+
},
|
|
148
|
+
[types_create_1.TypeDefInfo.Option]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
149
|
+
return singleParamNotation(registry, 'Option', typeDef, definitions, imports, withShortcut);
|
|
150
|
+
},
|
|
151
|
+
[types_create_1.TypeDefInfo.Plain]: (_registry, typeDef, definitions, imports, _withShortcut) => {
|
|
152
|
+
(0, imports_js_1.setImports)(definitions, imports, [rebrandTypeName(typeDef.type)]);
|
|
153
|
+
return rebrandTypeName(typeDef.type);
|
|
154
|
+
},
|
|
155
|
+
[types_create_1.TypeDefInfo.Range]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
156
|
+
return singleParamNotation(registry, 'Range', typeDef, definitions, imports, withShortcut);
|
|
157
|
+
},
|
|
158
|
+
[types_create_1.TypeDefInfo.RangeInclusive]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
159
|
+
return singleParamNotation(registry, 'RangeInclusive', typeDef, definitions, imports, withShortcut);
|
|
160
|
+
},
|
|
161
|
+
[types_create_1.TypeDefInfo.Set]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
162
|
+
throw new Error(`TypeDefInfo.Set: Parameter formatting not implemented on ${(0, util_1.stringify)(typeDef)}`);
|
|
163
|
+
},
|
|
164
|
+
[types_create_1.TypeDefInfo.Si]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
165
|
+
return formatType(registry, definitions, registry.lookup.getTypeDef(typeDef.type), imports, withShortcut);
|
|
166
|
+
},
|
|
167
|
+
[types_create_1.TypeDefInfo.Struct]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
168
|
+
if (typeDef.lookupName) {
|
|
169
|
+
return rebrandTypeName(typeDef.lookupName);
|
|
170
|
+
}
|
|
171
|
+
const sub = typeDef.sub;
|
|
172
|
+
(0, imports_js_1.setImports)(definitions, imports, ['Struct', ...sub.map(({ lookupName }) => rebrandTypeName(lookupName || ''))]);
|
|
173
|
+
return `{${withShortcut ? ' ' : '\n'}${sub.map(({ lookupName, name, type }, index) => [
|
|
174
|
+
name || `unknown${index}`,
|
|
175
|
+
rebrandTypeName(lookupName || '') || formatType(registry, definitions, type, imports, withShortcut)
|
|
176
|
+
]).map(([k, t]) => `${withShortcut ? '' : ' readonly '}${k}: ${t};`).join(withShortcut ? ' ' : '\n')}${withShortcut ? ' ' : '\n '}} & Struct`;
|
|
177
|
+
},
|
|
178
|
+
[types_create_1.TypeDefInfo.Tuple]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
179
|
+
const sub = typeDef.sub;
|
|
180
|
+
(0, imports_js_1.setImports)(definitions, imports, ['ITuple', ...sub.map(({ lookupName }) => rebrandTypeName(lookupName || ''))]);
|
|
181
|
+
// `(a,b)` gets transformed into `ITuple<[a, b]>`
|
|
182
|
+
return (0, types_create_1.paramsNotation)('ITuple', `[${sub.map(({ lookupName, type }) => rebrandTypeName(lookupName || '') || formatType(registry, definitions, type, imports, withShortcut)).join(', ')}]`);
|
|
183
|
+
},
|
|
184
|
+
[types_create_1.TypeDefInfo.Vec]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
185
|
+
return singleParamNotation(registry, 'Vec', typeDef, definitions, imports, withShortcut);
|
|
186
|
+
},
|
|
187
|
+
[types_create_1.TypeDefInfo.VecFixed]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
188
|
+
const sub = typeDef.sub;
|
|
189
|
+
if (sub.type === 'u8') {
|
|
190
|
+
(0, imports_js_1.setImports)(definitions, imports, ['U8aFixed']);
|
|
191
|
+
return 'U8aFixed';
|
|
192
|
+
}
|
|
193
|
+
return singleParamNotation(registry, 'Vec', typeDef, definitions, imports, withShortcut);
|
|
194
|
+
},
|
|
195
|
+
[types_create_1.TypeDefInfo.BTreeMap]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
196
|
+
return dualParamsNotation(registry, 'BTreeMap', typeDef, definitions, imports, withShortcut);
|
|
197
|
+
},
|
|
198
|
+
[types_create_1.TypeDefInfo.BTreeSet]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
199
|
+
return singleParamNotation(registry, 'BTreeSet', typeDef, definitions, imports, withShortcut);
|
|
200
|
+
},
|
|
201
|
+
[types_create_1.TypeDefInfo.HashMap]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
202
|
+
return dualParamsNotation(registry, 'HashMap', typeDef, definitions, imports, withShortcut);
|
|
203
|
+
},
|
|
204
|
+
[types_create_1.TypeDefInfo.Linkage]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
205
|
+
return singleParamNotation(registry, 'Linkage', typeDef, definitions, imports, withShortcut);
|
|
206
|
+
},
|
|
207
|
+
[types_create_1.TypeDefInfo.Result]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
208
|
+
return dualParamsNotation(registry, 'Result', typeDef, definitions, imports, withShortcut);
|
|
209
|
+
},
|
|
210
|
+
[types_create_1.TypeDefInfo.WrapperKeepOpaque]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
211
|
+
return singleParamNotation(registry, 'WrapperKeepOpaque', typeDef, definitions, imports, withShortcut);
|
|
212
|
+
},
|
|
213
|
+
[types_create_1.TypeDefInfo.WrapperOpaque]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
214
|
+
return singleParamNotation(registry, 'WrapperOpaque', typeDef, definitions, imports, withShortcut);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Correctly format a given type
|
|
219
|
+
*/
|
|
220
|
+
/** @internal */
|
|
221
|
+
function formatType(registry, definitions, type, imports, withShortcut = false) {
|
|
222
|
+
let typeDef;
|
|
223
|
+
if ((0, util_1.isString)(type)) {
|
|
224
|
+
const _type = type.toString();
|
|
225
|
+
// If type is "unorthodox" (i.e. `{ something: any }` for an Enum input or `[a | b | c, d | e | f]` for a Tuple's similar types),
|
|
226
|
+
// we return it as-is
|
|
227
|
+
if (withShortcut && /(^{.+:.+})|^\([^,]+\)|^\(.+\)\[\]|^\[.+\]/.exec(_type) && !/\[\w+;\w+\]/.exec(_type)) {
|
|
228
|
+
return rebrandTypeName(_type);
|
|
229
|
+
}
|
|
230
|
+
typeDef = (0, types_create_1.getTypeDef)(type);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
typeDef = type;
|
|
234
|
+
}
|
|
235
|
+
(0, imports_js_1.setImports)(definitions, imports, [rebrandTypeName(typeDef.lookupName || typeDef.type)]);
|
|
236
|
+
return rebrandTypeName(formatters[typeDef.info](registry, typeDef, definitions, imports, withShortcut));
|
|
237
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setImports = setImports;
|
|
4
|
+
exports.createImports = createImports;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const codecClasses = tslib_1.__importStar(require("@pezkuwi/types/codec"));
|
|
7
|
+
const extrinsicClasses = tslib_1.__importStar(require("@pezkuwi/types/extrinsic"));
|
|
8
|
+
const genericClasses = tslib_1.__importStar(require("@pezkuwi/types/generic"));
|
|
9
|
+
const primitiveClasses = tslib_1.__importStar(require("@pezkuwi/types/primitive"));
|
|
10
|
+
const types_create_1 = require("@pezkuwi/types-create");
|
|
11
|
+
function splitAlternatives(type) {
|
|
12
|
+
const alternatives = [];
|
|
13
|
+
let beginOfAlternative = 1;
|
|
14
|
+
let level = 0;
|
|
15
|
+
// we assume that the string starts with '['
|
|
16
|
+
for (let i = 1, count = type.length; i < count; i++) {
|
|
17
|
+
if (level === 0) {
|
|
18
|
+
switch (type[i]) {
|
|
19
|
+
case ']':
|
|
20
|
+
case ',':
|
|
21
|
+
case '|':
|
|
22
|
+
alternatives.push(type.substring(beginOfAlternative, i).trim());
|
|
23
|
+
beginOfAlternative = i + 1;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
switch (type[i]) {
|
|
28
|
+
case '[':
|
|
29
|
+
case '(':
|
|
30
|
+
case '<':
|
|
31
|
+
level++;
|
|
32
|
+
break;
|
|
33
|
+
case ']':
|
|
34
|
+
case ')':
|
|
35
|
+
case '>':
|
|
36
|
+
level--;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return alternatives;
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
function setImports(allDefs, imports, types) {
|
|
44
|
+
const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, metadataTypes, primitiveTypes, typesTypes } = imports;
|
|
45
|
+
types.filter((t) => !!t).forEach((type) => {
|
|
46
|
+
if (ignoredTypes.includes(type)) {
|
|
47
|
+
// do nothing
|
|
48
|
+
}
|
|
49
|
+
else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'IMethod', 'ITuple'].includes(type)) {
|
|
50
|
+
typesTypes[type] = true;
|
|
51
|
+
}
|
|
52
|
+
else if (['Metadata', 'PortableRegistry'].includes(type)) {
|
|
53
|
+
metadataTypes[type] = true;
|
|
54
|
+
}
|
|
55
|
+
else if (codecClasses[type]) {
|
|
56
|
+
codecTypes[type] = true;
|
|
57
|
+
}
|
|
58
|
+
else if (extrinsicClasses[type]) {
|
|
59
|
+
extrinsicTypes[type] = true;
|
|
60
|
+
}
|
|
61
|
+
else if (genericClasses[type]) {
|
|
62
|
+
genericTypes[type] = true;
|
|
63
|
+
}
|
|
64
|
+
else if (primitiveClasses[type]) {
|
|
65
|
+
primitiveTypes[type] = true;
|
|
66
|
+
}
|
|
67
|
+
else if (type.startsWith('[') && type.includes('|')) {
|
|
68
|
+
const splitTypes = splitAlternatives(type);
|
|
69
|
+
setImports(allDefs, imports, splitTypes);
|
|
70
|
+
}
|
|
71
|
+
else if (type.includes('<') || type.includes('(') || type.includes('[')) {
|
|
72
|
+
// If the type is a bit special (tuple, fixed u8, nested type...), then we
|
|
73
|
+
// need to parse it with `getTypeDef`.
|
|
74
|
+
const typeDef = (0, types_create_1.getTypeDef)(type);
|
|
75
|
+
setImports(allDefs, imports, [types_create_1.TypeDefInfo[typeDef.info]]);
|
|
76
|
+
// TypeDef.sub is a `TypeDef | TypeDef[]`
|
|
77
|
+
if (Array.isArray(typeDef.sub)) {
|
|
78
|
+
typeDef.sub.forEach((subType) => setImports(allDefs, imports, [subType.lookupName || subType.type]));
|
|
79
|
+
}
|
|
80
|
+
else if (typeDef.sub && (typeDef.info !== types_create_1.TypeDefInfo.VecFixed || typeDef.sub.type !== 'u8')) {
|
|
81
|
+
// typeDef.sub is a TypeDef in this case
|
|
82
|
+
setImports(allDefs, imports, [typeDef.sub.lookupName || typeDef.sub.type]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// find this module inside the exports from the rest
|
|
87
|
+
const [moduleName] = Object.entries(allDefs).find(([, { types }]) => Object.keys(types).includes(type)) || [null];
|
|
88
|
+
if (moduleName) {
|
|
89
|
+
localTypes[moduleName][type] = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** @internal */
|
|
95
|
+
function createImports(importDefinitions, { types } = { types: {} }) {
|
|
96
|
+
const definitions = {};
|
|
97
|
+
const typeToModule = {};
|
|
98
|
+
Object.entries(importDefinitions).forEach(([packagePath, packageDef]) => {
|
|
99
|
+
Object.entries(packageDef).forEach(([name, moduleDef]) => {
|
|
100
|
+
const fullName = `${packagePath}/${name}`;
|
|
101
|
+
definitions[fullName] = moduleDef;
|
|
102
|
+
Object.keys(moduleDef.types).forEach((type) => {
|
|
103
|
+
if (typeToModule[type]) {
|
|
104
|
+
console.warn(`\t\tWARN: Overwriting duplicated type '${type}' ${typeToModule[type]} -> ${fullName}`);
|
|
105
|
+
}
|
|
106
|
+
typeToModule[type] = fullName;
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
codecTypes: {},
|
|
112
|
+
definitions,
|
|
113
|
+
extrinsicTypes: {},
|
|
114
|
+
genericTypes: {},
|
|
115
|
+
ignoredTypes: Object.keys(types),
|
|
116
|
+
localTypes: Object.keys(definitions).reduce((local, mod) => {
|
|
117
|
+
local[mod] = {};
|
|
118
|
+
return local;
|
|
119
|
+
}, {}),
|
|
120
|
+
lookupTypes: {},
|
|
121
|
+
metadataTypes: {},
|
|
122
|
+
primitiveTypes: {},
|
|
123
|
+
typeToModule,
|
|
124
|
+
typesTypes: {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareName = compareName;
|
|
4
|
+
exports.rebrandTypeName = rebrandTypeName;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
tslib_1.__exportStar(require("./assert.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./derived.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./docs.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./file.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./formatting.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./imports.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./initMeta.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./register.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./wsMeta.js"), exports);
|
|
15
|
+
function compareName(a, b) {
|
|
16
|
+
return a.name.toString().localeCompare(b.name.toString());
|
|
17
|
+
}
|
|
18
|
+
function rebrandTypeName(typeName) {
|
|
19
|
+
return typeName
|
|
20
|
+
// Main projects
|
|
21
|
+
.replace(/Polkadot/g, 'Pezkuwi')
|
|
22
|
+
.replace(/Substrate/g, 'Bizinikiwi')
|
|
23
|
+
.replace(/Cumulus/g, 'Pezcumulus')
|
|
24
|
+
// Networks
|
|
25
|
+
.replace(/Kusama/g, 'Dicle')
|
|
26
|
+
.replace(/Westend/g, 'Zagros')
|
|
27
|
+
.replace(/Rococo/g, 'Pezkuwichain')
|
|
28
|
+
// Chain types
|
|
29
|
+
.replace(/Parachain/g, 'Teyrchain')
|
|
30
|
+
// Module prefixes (in PascalCase type names)
|
|
31
|
+
.replace(/Frame(?=[A-Z])/g, 'Pezframe')
|
|
32
|
+
.replace(/Pallet(?=[A-Z])/g, 'Pezpallet')
|
|
33
|
+
// Primitives prefixes (sp_ becomes Sp in type names)
|
|
34
|
+
.replace(/^Sp(?=[A-Z])/g, 'Pezsp')
|
|
35
|
+
.replace(/([^a-zA-Z])Sp(?=[A-Z])/g, '$1Pezsp')
|
|
36
|
+
// Client prefixes (sc_ becomes Sc in type names)
|
|
37
|
+
.replace(/^Sc(?=[A-Z])/g, 'Pezsc')
|
|
38
|
+
.replace(/([^a-zA-Z])Sc(?=[A-Z])/g, '$1Pezsc');
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initMeta = initMeta;
|
|
4
|
+
const types_1 = require("@pezkuwi/types");
|
|
5
|
+
const register_js_1 = require("./register.js");
|
|
6
|
+
/**
|
|
7
|
+
* This helper method has been transitioned to work with V14, V15 and up.
|
|
8
|
+
*/
|
|
9
|
+
function initMeta(staticMeta, extraTypes = {}) {
|
|
10
|
+
const registry = new types_1.TypeRegistry();
|
|
11
|
+
(0, register_js_1.registerDefinitions)(registry, extraTypes);
|
|
12
|
+
let metadata;
|
|
13
|
+
try {
|
|
14
|
+
const opaqueMetadata = registry.createType('Option<OpaqueMetadata>', registry.createType('Raw', staticMeta).toU8a()).unwrap();
|
|
15
|
+
metadata = new types_1.Metadata(registry, opaqueMetadata.toHex());
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
metadata = new types_1.Metadata(registry, staticMeta);
|
|
19
|
+
}
|
|
20
|
+
registry.setMetadata(metadata);
|
|
21
|
+
return { metadata, registry };
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerDefinitions = registerDefinitions;
|
|
4
|
+
function registerDefinitions(registry, extras) {
|
|
5
|
+
Object.values(extras).forEach((def) => {
|
|
6
|
+
Object.values(def).forEach(({ types }) => {
|
|
7
|
+
registry.register(types);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
}
|