@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,230 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
import * as typesCodec from '@pezkuwi/types-codec';
|
|
3
|
+
import { getTypeDef, paramsNotation, TypeDefInfo } from '@pezkuwi/types-create';
|
|
4
|
+
import { isString, stringify } from '@pezkuwi/util';
|
|
5
|
+
import { readTemplate } from './file.js';
|
|
6
|
+
import { setImports } from './imports.js';
|
|
7
|
+
function rebrandTypeName(typeName) {
|
|
8
|
+
return typeName
|
|
9
|
+
// Main projects
|
|
10
|
+
.replace(/Polkadot/g, 'Pezkuwi')
|
|
11
|
+
.replace(/Substrate/g, 'Bizinikiwi')
|
|
12
|
+
.replace(/Cumulus/g, 'Pezcumulus')
|
|
13
|
+
// Networks
|
|
14
|
+
.replace(/Kusama/g, 'Dicle')
|
|
15
|
+
.replace(/Westend/g, 'Zagros')
|
|
16
|
+
.replace(/Rococo/g, 'Pezkuwichain')
|
|
17
|
+
// Chain types
|
|
18
|
+
.replace(/Parachain/g, 'Teyrchain')
|
|
19
|
+
// Module prefixes (in PascalCase type names)
|
|
20
|
+
.replace(/Frame(?=[A-Z])/g, 'Pezframe')
|
|
21
|
+
.replace(/Pallet(?=[A-Z])/g, 'Pezpallet')
|
|
22
|
+
// Primitives prefixes (sp_ becomes Sp in type names)
|
|
23
|
+
.replace(/^Sp(?=[A-Z])/g, 'Pezsp')
|
|
24
|
+
.replace(/([^a-zA-Z])Sp(?=[A-Z])/g, '$1Pezsp')
|
|
25
|
+
// Client prefixes (sc_ becomes Sc in type names)
|
|
26
|
+
.replace(/^Sc(?=[A-Z])/g, 'Pezsc')
|
|
27
|
+
.replace(/([^a-zA-Z])Sc(?=[A-Z])/g, '$1Pezsc');
|
|
28
|
+
}
|
|
29
|
+
const NO_CODEC = ['Tuple', 'VecFixed'];
|
|
30
|
+
const ON_CODEC = Object.keys(typesCodec);
|
|
31
|
+
const ON_CODEC_TYPES = ['Codec', 'AnyJson', 'AnyFunction', 'AnyNumber', 'AnyString', 'AnyTuple', 'AnyU8a', 'ICompact', 'IEnum', 'IMap', 'INumber', 'IOption', 'IResult', 'ISet', 'IStruct', 'ITuple', 'IU8a', 'IVec', 'IMethod'];
|
|
32
|
+
export const HEADER = (type) => `// Auto-generated via \`yarn pezkuwi-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
|
|
33
|
+
function extractImports({ imports, types }) {
|
|
34
|
+
const toplevel = [
|
|
35
|
+
...Object.keys(imports.codecTypes),
|
|
36
|
+
...Object.keys(imports.extrinsicTypes),
|
|
37
|
+
...Object.keys(imports.genericTypes),
|
|
38
|
+
...Object.keys(imports.metadataTypes),
|
|
39
|
+
...Object.keys(imports.primitiveTypes)
|
|
40
|
+
];
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
file: '@pezkuwi/types',
|
|
44
|
+
types: toplevel.filter((n) => !NO_CODEC.includes(n) && !ON_CODEC.includes(n))
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
file: '@pezkuwi/types/lookup',
|
|
48
|
+
types: Object.keys(imports.lookupTypes)
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
file: '@pezkuwi/types/types',
|
|
52
|
+
types: Object.keys(imports.typesTypes).filter((n) => !ON_CODEC_TYPES.includes(n))
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
file: '@pezkuwi/types-codec',
|
|
56
|
+
types: toplevel.filter((n) => !NO_CODEC.includes(n) && ON_CODEC.includes(n))
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
file: '@pezkuwi/types-codec/types',
|
|
60
|
+
types: Object.keys(imports.typesTypes).filter((n) => ON_CODEC_TYPES.includes(n))
|
|
61
|
+
},
|
|
62
|
+
...types
|
|
63
|
+
]
|
|
64
|
+
.filter(({ types }) => types.length)
|
|
65
|
+
.sort(({ file }, b) => file.localeCompare(b.file))
|
|
66
|
+
.map(({ file, types }) => `import type { ${types.sort().join(', ')} } from '${file}';`);
|
|
67
|
+
}
|
|
68
|
+
Handlebars.registerPartial({
|
|
69
|
+
header: Handlebars.compile(readTemplate('header'))
|
|
70
|
+
});
|
|
71
|
+
Handlebars.registerHelper({
|
|
72
|
+
importsAll() {
|
|
73
|
+
return extractImports(this)
|
|
74
|
+
.join('\n');
|
|
75
|
+
},
|
|
76
|
+
importsPackage() {
|
|
77
|
+
return extractImports(this)
|
|
78
|
+
.filter((l) => !l.includes("from '."))
|
|
79
|
+
.join('\n ');
|
|
80
|
+
},
|
|
81
|
+
importsRelative() {
|
|
82
|
+
return extractImports(this)
|
|
83
|
+
.filter((l) => l.includes("from '."))
|
|
84
|
+
.join('\n');
|
|
85
|
+
},
|
|
86
|
+
trim(options) {
|
|
87
|
+
return options.fn(this).trim();
|
|
88
|
+
},
|
|
89
|
+
upper(options) {
|
|
90
|
+
return options.fn(this).toUpperCase();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
/** @internal */
|
|
94
|
+
export function exportInterface(lookupIndex = -1, name = '', base, body = '', withShortcut = false) {
|
|
95
|
+
// * @description extends [[${base}]]
|
|
96
|
+
const doc = withShortcut
|
|
97
|
+
? ''
|
|
98
|
+
: `/** @name ${name}${lookupIndex !== -1 ? ` (${lookupIndex})` : ''} */\n`;
|
|
99
|
+
return `${doc}${withShortcut ? '' : `export interface ${name} extends ${base} `}{${body.length ? '\n' : ''}${body}${withShortcut ? ' ' : ''}}`;
|
|
100
|
+
}
|
|
101
|
+
function singleParamNotation(registry, wrapper, typeDef, definitions, imports, withShortcut) {
|
|
102
|
+
const sub = typeDef.sub;
|
|
103
|
+
const lookupName = rebrandTypeName(sub.lookupName || '');
|
|
104
|
+
setImports(definitions, imports, [wrapper, lookupName]);
|
|
105
|
+
return paramsNotation(wrapper, lookupName || formatType(registry, definitions, sub.type, imports, withShortcut));
|
|
106
|
+
}
|
|
107
|
+
function dualParamsNotation(registry, wrapper, typeDef, definitions, imports, withShortcut) {
|
|
108
|
+
const [a, b] = typeDef.sub;
|
|
109
|
+
const aLookupName = rebrandTypeName(a.lookupName || '');
|
|
110
|
+
const bLookupName = rebrandTypeName(b.lookupName || '');
|
|
111
|
+
setImports(definitions, imports, [wrapper, aLookupName, bLookupName]);
|
|
112
|
+
return paramsNotation(wrapper, [
|
|
113
|
+
aLookupName || formatType(registry, definitions, a.type, imports, withShortcut),
|
|
114
|
+
bLookupName || formatType(registry, definitions, b.type, imports, withShortcut)
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
const formatters = {
|
|
118
|
+
[TypeDefInfo.Compact]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
119
|
+
return singleParamNotation(registry, 'Compact', typeDef, definitions, imports, withShortcut);
|
|
120
|
+
},
|
|
121
|
+
[TypeDefInfo.DoNotConstruct]: (_registry, _typeDef, definitions, imports, _withShortcut) => {
|
|
122
|
+
setImports(definitions, imports, ['DoNotConstruct']);
|
|
123
|
+
return 'DoNotConstruct';
|
|
124
|
+
},
|
|
125
|
+
[TypeDefInfo.Enum]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
126
|
+
if (typeDef.lookupName) {
|
|
127
|
+
return rebrandTypeName(typeDef.lookupName);
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`TypeDefInfo.Enum: Parameter formatting not implemented on ${stringify(typeDef)}`);
|
|
130
|
+
},
|
|
131
|
+
[TypeDefInfo.Int]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
132
|
+
throw new Error(`TypeDefInfo.Int: Parameter formatting not implemented on ${stringify(typeDef)}`);
|
|
133
|
+
},
|
|
134
|
+
[TypeDefInfo.UInt]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
135
|
+
throw new Error(`TypeDefInfo.UInt: Parameter formatting not implemented on ${stringify(typeDef)}`);
|
|
136
|
+
},
|
|
137
|
+
[TypeDefInfo.Null]: (_registry, _typeDef, definitions, imports, _withShortcut) => {
|
|
138
|
+
setImports(definitions, imports, ['Null']);
|
|
139
|
+
return 'Null';
|
|
140
|
+
},
|
|
141
|
+
[TypeDefInfo.Option]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
142
|
+
return singleParamNotation(registry, 'Option', typeDef, definitions, imports, withShortcut);
|
|
143
|
+
},
|
|
144
|
+
[TypeDefInfo.Plain]: (_registry, typeDef, definitions, imports, _withShortcut) => {
|
|
145
|
+
setImports(definitions, imports, [rebrandTypeName(typeDef.type)]);
|
|
146
|
+
return rebrandTypeName(typeDef.type);
|
|
147
|
+
},
|
|
148
|
+
[TypeDefInfo.Range]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
149
|
+
return singleParamNotation(registry, 'Range', typeDef, definitions, imports, withShortcut);
|
|
150
|
+
},
|
|
151
|
+
[TypeDefInfo.RangeInclusive]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
152
|
+
return singleParamNotation(registry, 'RangeInclusive', typeDef, definitions, imports, withShortcut);
|
|
153
|
+
},
|
|
154
|
+
[TypeDefInfo.Set]: (_registry, typeDef, _definitions, _imports, _withShortcut) => {
|
|
155
|
+
throw new Error(`TypeDefInfo.Set: Parameter formatting not implemented on ${stringify(typeDef)}`);
|
|
156
|
+
},
|
|
157
|
+
[TypeDefInfo.Si]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
158
|
+
return formatType(registry, definitions, registry.lookup.getTypeDef(typeDef.type), imports, withShortcut);
|
|
159
|
+
},
|
|
160
|
+
[TypeDefInfo.Struct]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
161
|
+
if (typeDef.lookupName) {
|
|
162
|
+
return rebrandTypeName(typeDef.lookupName);
|
|
163
|
+
}
|
|
164
|
+
const sub = typeDef.sub;
|
|
165
|
+
setImports(definitions, imports, ['Struct', ...sub.map(({ lookupName }) => rebrandTypeName(lookupName || ''))]);
|
|
166
|
+
return `{${withShortcut ? ' ' : '\n'}${sub.map(({ lookupName, name, type }, index) => [
|
|
167
|
+
name || `unknown${index}`,
|
|
168
|
+
rebrandTypeName(lookupName || '') || formatType(registry, definitions, type, imports, withShortcut)
|
|
169
|
+
]).map(([k, t]) => `${withShortcut ? '' : ' readonly '}${k}: ${t};`).join(withShortcut ? ' ' : '\n')}${withShortcut ? ' ' : '\n '}} & Struct`;
|
|
170
|
+
},
|
|
171
|
+
[TypeDefInfo.Tuple]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
172
|
+
const sub = typeDef.sub;
|
|
173
|
+
setImports(definitions, imports, ['ITuple', ...sub.map(({ lookupName }) => rebrandTypeName(lookupName || ''))]);
|
|
174
|
+
// `(a,b)` gets transformed into `ITuple<[a, b]>`
|
|
175
|
+
return paramsNotation('ITuple', `[${sub.map(({ lookupName, type }) => rebrandTypeName(lookupName || '') || formatType(registry, definitions, type, imports, withShortcut)).join(', ')}]`);
|
|
176
|
+
},
|
|
177
|
+
[TypeDefInfo.Vec]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
178
|
+
return singleParamNotation(registry, 'Vec', typeDef, definitions, imports, withShortcut);
|
|
179
|
+
},
|
|
180
|
+
[TypeDefInfo.VecFixed]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
181
|
+
const sub = typeDef.sub;
|
|
182
|
+
if (sub.type === 'u8') {
|
|
183
|
+
setImports(definitions, imports, ['U8aFixed']);
|
|
184
|
+
return 'U8aFixed';
|
|
185
|
+
}
|
|
186
|
+
return singleParamNotation(registry, 'Vec', typeDef, definitions, imports, withShortcut);
|
|
187
|
+
},
|
|
188
|
+
[TypeDefInfo.BTreeMap]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
189
|
+
return dualParamsNotation(registry, 'BTreeMap', typeDef, definitions, imports, withShortcut);
|
|
190
|
+
},
|
|
191
|
+
[TypeDefInfo.BTreeSet]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
192
|
+
return singleParamNotation(registry, 'BTreeSet', typeDef, definitions, imports, withShortcut);
|
|
193
|
+
},
|
|
194
|
+
[TypeDefInfo.HashMap]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
195
|
+
return dualParamsNotation(registry, 'HashMap', typeDef, definitions, imports, withShortcut);
|
|
196
|
+
},
|
|
197
|
+
[TypeDefInfo.Linkage]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
198
|
+
return singleParamNotation(registry, 'Linkage', typeDef, definitions, imports, withShortcut);
|
|
199
|
+
},
|
|
200
|
+
[TypeDefInfo.Result]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
201
|
+
return dualParamsNotation(registry, 'Result', typeDef, definitions, imports, withShortcut);
|
|
202
|
+
},
|
|
203
|
+
[TypeDefInfo.WrapperKeepOpaque]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
204
|
+
return singleParamNotation(registry, 'WrapperKeepOpaque', typeDef, definitions, imports, withShortcut);
|
|
205
|
+
},
|
|
206
|
+
[TypeDefInfo.WrapperOpaque]: (registry, typeDef, definitions, imports, withShortcut) => {
|
|
207
|
+
return singleParamNotation(registry, 'WrapperOpaque', typeDef, definitions, imports, withShortcut);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Correctly format a given type
|
|
212
|
+
*/
|
|
213
|
+
/** @internal */
|
|
214
|
+
export function formatType(registry, definitions, type, imports, withShortcut = false) {
|
|
215
|
+
let typeDef;
|
|
216
|
+
if (isString(type)) {
|
|
217
|
+
const _type = type.toString();
|
|
218
|
+
// 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),
|
|
219
|
+
// we return it as-is
|
|
220
|
+
if (withShortcut && /(^{.+:.+})|^\([^,]+\)|^\(.+\)\[\]|^\[.+\]/.exec(_type) && !/\[\w+;\w+\]/.exec(_type)) {
|
|
221
|
+
return rebrandTypeName(_type);
|
|
222
|
+
}
|
|
223
|
+
typeDef = getTypeDef(type);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
typeDef = type;
|
|
227
|
+
}
|
|
228
|
+
setImports(definitions, imports, [rebrandTypeName(typeDef.lookupName || typeDef.type)]);
|
|
229
|
+
return rebrandTypeName(formatters[typeDef.info](registry, typeDef, definitions, imports, withShortcut));
|
|
230
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ModuleTypes {
|
|
2
|
+
types: Record<string, unknown>;
|
|
3
|
+
}
|
|
4
|
+
type TypeExist = Record<string, boolean>;
|
|
5
|
+
type TypeExistMap = Record<string, TypeExist>;
|
|
6
|
+
export interface TypeImports {
|
|
7
|
+
codecTypes: TypeExist;
|
|
8
|
+
extrinsicTypes: TypeExist;
|
|
9
|
+
genericTypes: TypeExist;
|
|
10
|
+
ignoredTypes: string[];
|
|
11
|
+
localTypes: TypeExistMap;
|
|
12
|
+
lookupTypes: TypeExistMap;
|
|
13
|
+
primitiveTypes: TypeExist;
|
|
14
|
+
metadataTypes: TypeExist;
|
|
15
|
+
typesTypes: TypeExist;
|
|
16
|
+
definitions: Record<string, ModuleTypes>;
|
|
17
|
+
typeToModule: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
export declare function setImports(allDefs: Record<string, ModuleTypes>, imports: TypeImports, types: (string | null | undefined)[]): void;
|
|
21
|
+
/** @internal */
|
|
22
|
+
export declare function createImports(importDefinitions: Record<string, Record<string, ModuleTypes>>, { types }?: ModuleTypes): TypeImports;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as codecClasses from '@pezkuwi/types/codec';
|
|
2
|
+
import * as extrinsicClasses from '@pezkuwi/types/extrinsic';
|
|
3
|
+
import * as genericClasses from '@pezkuwi/types/generic';
|
|
4
|
+
import * as primitiveClasses from '@pezkuwi/types/primitive';
|
|
5
|
+
import { getTypeDef, TypeDefInfo } from '@pezkuwi/types-create';
|
|
6
|
+
function splitAlternatives(type) {
|
|
7
|
+
const alternatives = [];
|
|
8
|
+
let beginOfAlternative = 1;
|
|
9
|
+
let level = 0;
|
|
10
|
+
// we assume that the string starts with '['
|
|
11
|
+
for (let i = 1, count = type.length; i < count; i++) {
|
|
12
|
+
if (level === 0) {
|
|
13
|
+
switch (type[i]) {
|
|
14
|
+
case ']':
|
|
15
|
+
case ',':
|
|
16
|
+
case '|':
|
|
17
|
+
alternatives.push(type.substring(beginOfAlternative, i).trim());
|
|
18
|
+
beginOfAlternative = i + 1;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
switch (type[i]) {
|
|
23
|
+
case '[':
|
|
24
|
+
case '(':
|
|
25
|
+
case '<':
|
|
26
|
+
level++;
|
|
27
|
+
break;
|
|
28
|
+
case ']':
|
|
29
|
+
case ')':
|
|
30
|
+
case '>':
|
|
31
|
+
level--;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return alternatives;
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
export function setImports(allDefs, imports, types) {
|
|
39
|
+
const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, metadataTypes, primitiveTypes, typesTypes } = imports;
|
|
40
|
+
types.filter((t) => !!t).forEach((type) => {
|
|
41
|
+
if (ignoredTypes.includes(type)) {
|
|
42
|
+
// do nothing
|
|
43
|
+
}
|
|
44
|
+
else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'IMethod', 'ITuple'].includes(type)) {
|
|
45
|
+
typesTypes[type] = true;
|
|
46
|
+
}
|
|
47
|
+
else if (['Metadata', 'PortableRegistry'].includes(type)) {
|
|
48
|
+
metadataTypes[type] = true;
|
|
49
|
+
}
|
|
50
|
+
else if (codecClasses[type]) {
|
|
51
|
+
codecTypes[type] = true;
|
|
52
|
+
}
|
|
53
|
+
else if (extrinsicClasses[type]) {
|
|
54
|
+
extrinsicTypes[type] = true;
|
|
55
|
+
}
|
|
56
|
+
else if (genericClasses[type]) {
|
|
57
|
+
genericTypes[type] = true;
|
|
58
|
+
}
|
|
59
|
+
else if (primitiveClasses[type]) {
|
|
60
|
+
primitiveTypes[type] = true;
|
|
61
|
+
}
|
|
62
|
+
else if (type.startsWith('[') && type.includes('|')) {
|
|
63
|
+
const splitTypes = splitAlternatives(type);
|
|
64
|
+
setImports(allDefs, imports, splitTypes);
|
|
65
|
+
}
|
|
66
|
+
else if (type.includes('<') || type.includes('(') || type.includes('[')) {
|
|
67
|
+
// If the type is a bit special (tuple, fixed u8, nested type...), then we
|
|
68
|
+
// need to parse it with `getTypeDef`.
|
|
69
|
+
const typeDef = getTypeDef(type);
|
|
70
|
+
setImports(allDefs, imports, [TypeDefInfo[typeDef.info]]);
|
|
71
|
+
// TypeDef.sub is a `TypeDef | TypeDef[]`
|
|
72
|
+
if (Array.isArray(typeDef.sub)) {
|
|
73
|
+
typeDef.sub.forEach((subType) => setImports(allDefs, imports, [subType.lookupName || subType.type]));
|
|
74
|
+
}
|
|
75
|
+
else if (typeDef.sub && (typeDef.info !== TypeDefInfo.VecFixed || typeDef.sub.type !== 'u8')) {
|
|
76
|
+
// typeDef.sub is a TypeDef in this case
|
|
77
|
+
setImports(allDefs, imports, [typeDef.sub.lookupName || typeDef.sub.type]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// find this module inside the exports from the rest
|
|
82
|
+
const [moduleName] = Object.entries(allDefs).find(([, { types }]) => Object.keys(types).includes(type)) || [null];
|
|
83
|
+
if (moduleName) {
|
|
84
|
+
localTypes[moduleName][type] = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** @internal */
|
|
90
|
+
export function createImports(importDefinitions, { types } = { types: {} }) {
|
|
91
|
+
const definitions = {};
|
|
92
|
+
const typeToModule = {};
|
|
93
|
+
Object.entries(importDefinitions).forEach(([packagePath, packageDef]) => {
|
|
94
|
+
Object.entries(packageDef).forEach(([name, moduleDef]) => {
|
|
95
|
+
const fullName = `${packagePath}/${name}`;
|
|
96
|
+
definitions[fullName] = moduleDef;
|
|
97
|
+
Object.keys(moduleDef.types).forEach((type) => {
|
|
98
|
+
if (typeToModule[type]) {
|
|
99
|
+
console.warn(`\t\tWARN: Overwriting duplicated type '${type}' ${typeToModule[type]} -> ${fullName}`);
|
|
100
|
+
}
|
|
101
|
+
typeToModule[type] = fullName;
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
codecTypes: {},
|
|
107
|
+
definitions,
|
|
108
|
+
extrinsicTypes: {},
|
|
109
|
+
genericTypes: {},
|
|
110
|
+
ignoredTypes: Object.keys(types),
|
|
111
|
+
localTypes: Object.keys(definitions).reduce((local, mod) => {
|
|
112
|
+
local[mod] = {};
|
|
113
|
+
return local;
|
|
114
|
+
}, {}),
|
|
115
|
+
lookupTypes: {},
|
|
116
|
+
metadataTypes: {},
|
|
117
|
+
primitiveTypes: {},
|
|
118
|
+
typeToModule,
|
|
119
|
+
typesTypes: {}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './assert.js';
|
|
2
|
+
export * from './derived.js';
|
|
3
|
+
export * from './docs.js';
|
|
4
|
+
export * from './file.js';
|
|
5
|
+
export * from './formatting.js';
|
|
6
|
+
export * from './imports.js';
|
|
7
|
+
export * from './initMeta.js';
|
|
8
|
+
export * from './register.js';
|
|
9
|
+
export * from './wsMeta.js';
|
|
10
|
+
interface Cmp {
|
|
11
|
+
name: {
|
|
12
|
+
toString(): string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare function compareName(a: Cmp, b: Cmp): number;
|
|
16
|
+
export declare function rebrandTypeName(typeName: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from './assert.js';
|
|
2
|
+
export * from './derived.js';
|
|
3
|
+
export * from './docs.js';
|
|
4
|
+
export * from './file.js';
|
|
5
|
+
export * from './formatting.js';
|
|
6
|
+
export * from './imports.js';
|
|
7
|
+
export * from './initMeta.js';
|
|
8
|
+
export * from './register.js';
|
|
9
|
+
export * from './wsMeta.js';
|
|
10
|
+
export function compareName(a, b) {
|
|
11
|
+
return a.name.toString().localeCompare(b.name.toString());
|
|
12
|
+
}
|
|
13
|
+
export 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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { ExtraTypes } from '../generate/types.js';
|
|
3
|
+
import { Metadata, TypeRegistry } from '@pezkuwi/types';
|
|
4
|
+
interface Result {
|
|
5
|
+
metadata: Metadata;
|
|
6
|
+
registry: TypeRegistry;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This helper method has been transitioned to work with V14, V15 and up.
|
|
10
|
+
*/
|
|
11
|
+
export declare function initMeta(staticMeta: HexString, extraTypes?: ExtraTypes): Result;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Metadata, TypeRegistry } from '@pezkuwi/types';
|
|
2
|
+
import { registerDefinitions } from './register.js';
|
|
3
|
+
/**
|
|
4
|
+
* This helper method has been transitioned to work with V14, V15 and up.
|
|
5
|
+
*/
|
|
6
|
+
export function initMeta(staticMeta, extraTypes = {}) {
|
|
7
|
+
const registry = new TypeRegistry();
|
|
8
|
+
registerDefinitions(registry, extraTypes);
|
|
9
|
+
let metadata;
|
|
10
|
+
try {
|
|
11
|
+
const opaqueMetadata = registry.createType('Option<OpaqueMetadata>', registry.createType('Raw', staticMeta).toU8a()).unwrap();
|
|
12
|
+
metadata = new Metadata(registry, opaqueMetadata.toHex());
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
metadata = new Metadata(registry, staticMeta);
|
|
16
|
+
}
|
|
17
|
+
registry.setMetadata(metadata);
|
|
18
|
+
return { metadata, registry };
|
|
19
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
export declare function getMetadataViaWs(endpoint: string, metadataVer?: number): Promise<HexString>;
|
|
3
|
+
export declare function getRpcMethodsViaWs(endpoint: string): Promise<string[]>;
|
|
4
|
+
export declare function getRuntimeVersionViaWs(endpoint: string): Promise<[apiHash: string, apiVersion: number][]>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { promiseTracker } from '@pezkuwi/api/promise/decorateMethod';
|
|
2
|
+
import { TypeRegistry } from '@pezkuwi/types';
|
|
3
|
+
import { stringify, u8aToHex } from '@pezkuwi/util';
|
|
4
|
+
import { WebSocket } from '@pezkuwi/x-ws';
|
|
5
|
+
async function getWsData(endpoint, method, params) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const tracker = promiseTracker(resolve, reject);
|
|
8
|
+
try {
|
|
9
|
+
const websocket = new WebSocket(endpoint);
|
|
10
|
+
websocket.onclose = (event) => {
|
|
11
|
+
if (event.code !== 1000) {
|
|
12
|
+
tracker.reject(new Error(`disconnected, code: '${event.code}' reason: '${event.reason}'`));
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
websocket.onerror = (event) => {
|
|
16
|
+
tracker.reject(new Error(`WebSocket error:: ${stringify(event)}`));
|
|
17
|
+
};
|
|
18
|
+
websocket.onopen = () => {
|
|
19
|
+
console.log('connected');
|
|
20
|
+
params
|
|
21
|
+
? websocket.send(`{"id":"1","jsonrpc":"2.0","method":"${method}","params":[${params.map((param) => `"${param}"`).join(',')}]}`)
|
|
22
|
+
: websocket.send(`{"id":"1","jsonrpc":"2.0","method":"${method}","params":[]}`);
|
|
23
|
+
};
|
|
24
|
+
websocket.onmessage = (message) => {
|
|
25
|
+
try {
|
|
26
|
+
tracker.resolve(JSON.parse(message.data).result);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
tracker.reject(error);
|
|
30
|
+
}
|
|
31
|
+
websocket.close();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
tracker.reject(error);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export async function getMetadataViaWs(endpoint, metadataVer) {
|
|
40
|
+
const registry = new TypeRegistry();
|
|
41
|
+
if (metadataVer) {
|
|
42
|
+
return await getWsData(endpoint, 'state_call', ['Metadata_metadata_at_version', u8aToHex(registry.createType('u32', metadataVer).toU8a())]);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return await getWsData(endpoint, 'state_getMetadata');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function getRpcMethodsViaWs(endpoint) {
|
|
49
|
+
const result = await getWsData(endpoint, 'rpc_methods');
|
|
50
|
+
return result.methods;
|
|
51
|
+
}
|
|
52
|
+
export async function getRuntimeVersionViaWs(endpoint) {
|
|
53
|
+
const result = await getWsData(endpoint, 'state_getRuntimeVersion');
|
|
54
|
+
return result.apis;
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const packageInfo_1 = require("@pezkuwi/api/packageInfo");
|
|
4
|
+
const packageInfo_2 = require("@pezkuwi/rpc-provider/packageInfo");
|
|
5
|
+
const packageInfo_3 = require("@pezkuwi/types/packageInfo");
|
|
6
|
+
const util_1 = require("@pezkuwi/util");
|
|
7
|
+
const packageInfo_js_1 = require("./packageInfo.js");
|
|
8
|
+
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_1.packageInfo, packageInfo_2.packageInfo, packageInfo_3.packageInfo]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.packageInfo = void 0;
|
|
4
|
-
exports.packageInfo = { name: '@pezkuwi/typegen', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '16.5.
|
|
4
|
+
exports.packageInfo = { name: '@pezkuwi/typegen', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '16.5.18' };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
3
|
+
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
4
|
+
import { stringCamelCase } from '@pezkuwi/util';
|
|
5
|
+
import { compareName, createImports, formatType, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
|
|
6
|
+
import { ignoreUnusedLookups } from './lookup.js';
|
|
7
|
+
import { getDeprecationNotice } from './types.js';
|
|
8
|
+
const generateForMetaTemplate = Handlebars.compile(readTemplate('consts'));
|
|
9
|
+
/** @internal */
|
|
10
|
+
function generateForMeta(meta, dest, extraTypes, isStrict, customLookupDefinitions) {
|
|
11
|
+
writeFile(dest, () => {
|
|
12
|
+
const allTypes = {
|
|
13
|
+
'@pezkuwi/types-augment': {
|
|
14
|
+
lookup: {
|
|
15
|
+
...lookupDefinitions,
|
|
16
|
+
...customLookupDefinitions
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
'@pezkuwi/types/interfaces': defaultDefs,
|
|
20
|
+
...extraTypes
|
|
21
|
+
};
|
|
22
|
+
const imports = createImports(allTypes);
|
|
23
|
+
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
24
|
+
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
25
|
+
}, {});
|
|
26
|
+
const { lookup, pallets, registry } = meta.asLatest;
|
|
27
|
+
const usedTypes = new Set([]);
|
|
28
|
+
const modules = pallets
|
|
29
|
+
.filter(({ constants }) => constants.length > 0)
|
|
30
|
+
.map(({ constants, name }) => {
|
|
31
|
+
if (!isStrict) {
|
|
32
|
+
setImports(allDefs, imports, ['Codec']);
|
|
33
|
+
}
|
|
34
|
+
const items = constants
|
|
35
|
+
.map(({ deprecationInfo, docs, name, type }) => {
|
|
36
|
+
const typeDef = lookup.getTypeDef(type);
|
|
37
|
+
const returnType = rebrandTypeName(typeDef.lookupName || '') || formatType(registry, allDefs, typeDef, imports);
|
|
38
|
+
if (!deprecationInfo.isNotDeprecated) {
|
|
39
|
+
const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name), 'Constant');
|
|
40
|
+
const items = docs.length
|
|
41
|
+
? ['', deprecationNotice]
|
|
42
|
+
: [deprecationNotice];
|
|
43
|
+
docs.push(...items.map((text) => registry.createType('Text', text)));
|
|
44
|
+
}
|
|
45
|
+
// Add the type to the list of used types
|
|
46
|
+
if (!(imports.primitiveTypes[returnType])) {
|
|
47
|
+
usedTypes.add(returnType);
|
|
48
|
+
}
|
|
49
|
+
setImports(allDefs, imports, [returnType]);
|
|
50
|
+
return {
|
|
51
|
+
docs,
|
|
52
|
+
name: stringCamelCase(name),
|
|
53
|
+
type: returnType
|
|
54
|
+
};
|
|
55
|
+
})
|
|
56
|
+
.sort(compareName);
|
|
57
|
+
return {
|
|
58
|
+
items,
|
|
59
|
+
name: stringCamelCase(name)
|
|
60
|
+
};
|
|
61
|
+
})
|
|
62
|
+
.sort(compareName);
|
|
63
|
+
// filter out the unused lookup types from imports
|
|
64
|
+
ignoreUnusedLookups([...usedTypes], imports);
|
|
65
|
+
return generateForMetaTemplate({
|
|
66
|
+
headerType: 'chain',
|
|
67
|
+
imports,
|
|
68
|
+
isStrict,
|
|
69
|
+
modules,
|
|
70
|
+
types: [
|
|
71
|
+
...Object.keys(imports.localTypes).sort().map((packagePath) => ({
|
|
72
|
+
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
73
|
+
types: Object.keys(imports.localTypes[packagePath])
|
|
74
|
+
})),
|
|
75
|
+
{
|
|
76
|
+
file: '@pezkuwi/api-base/types',
|
|
77
|
+
types: ['ApiTypes', 'AugmentedConst']
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** @internal */
|
|
84
|
+
export function generateDefaultConsts(dest, data, extraTypes = {}, isStrict = false, customLookupDefinitions) {
|
|
85
|
+
const { metadata } = initMeta(data, extraTypes);
|
|
86
|
+
return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
87
|
+
}
|