@pezkuwi/typegen 16.5.18 → 16.5.31
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-tsc-cjs → cjs}/generate/lookup.js +39 -10
- package/{build/cjs → cjs}/packageInfo.js +1 -1
- package/{build-tsc-cjs → cjs}/util/derived.js +15 -0
- package/{build-tsc-cjs → cjs}/util/formatting.js +5 -0
- package/generate/lookup.js +39 -10
- package/package.json +27 -27
- package/{build-tsc-esm/packageInfo.js → packageInfo.js} +1 -1
- package/{build/util → util}/derived.js +16 -1
- package/{build-tsc-esm/util → util}/formatting.js +5 -0
- package/build/LICENSE +0 -201
- package/build/README.md +0 -3
- package/build/augment.js +0 -2
- package/build/bundle.js +0 -2
- package/build/cjs/augment.d.ts +0 -2
- package/build/cjs/augment.js +0 -4
- package/build/cjs/bundle.d.ts +0 -2
- package/build/cjs/bundle.js +0 -7
- package/build/cjs/extractChain.js +0 -44
- package/build/cjs/fromChain.js +0 -95
- package/build/cjs/fromDefs.js +0 -82
- package/build/cjs/generate/consts.d.ts +0 -5
- package/build/cjs/generate/consts.js +0 -91
- package/build/cjs/generate/errors.d.ts +0 -4
- package/build/cjs/generate/errors.js +0 -59
- package/build/cjs/generate/events.d.ts +0 -5
- package/build/cjs/generate/events.js +0 -139
- package/build/cjs/generate/index.js +0 -23
- package/build/cjs/generate/interfaceRegistry.d.ts +0 -4
- package/build/cjs/generate/interfaceRegistry.js +0 -64
- package/build/cjs/generate/lookup.d.ts +0 -4
- package/build/cjs/generate/lookup.js +0 -240
- package/build/cjs/generate/query.d.ts +0 -5
- package/build/cjs/generate/query.js +0 -140
- package/build/cjs/generate/rpc.d.ts +0 -6
- package/build/cjs/generate/rpc.js +0 -115
- package/build/cjs/generate/runtime.d.ts +0 -7
- package/build/cjs/generate/runtime.js +0 -233
- package/build/cjs/generate/tsDef.d.ts +0 -16
- package/build/cjs/generate/tsDef.js +0 -254
- package/build/cjs/generate/tx.d.ts +0 -5
- package/build/cjs/generate/tx.js +0 -121
- package/build/cjs/generate/types.d.ts +0 -12
- package/build/cjs/generate/types.js +0 -16
- package/build/cjs/index.js +0 -5
- package/build/cjs/interfacesTs.js +0 -28
- package/build/cjs/metadataMd.js +0 -652
- package/build/cjs/util/assert.js +0 -15
- package/build/cjs/util/derived.js +0 -128
- package/build/cjs/util/docs.js +0 -10
- package/build/cjs/util/file.js +0 -33
- package/build/cjs/util/formatting.js +0 -237
- package/build/cjs/util/imports.js +0 -126
- package/build/cjs/util/index.js +0 -39
- package/build/cjs/util/initMeta.js +0 -22
- package/build/cjs/util/register.js +0 -10
- package/build/cjs/util/wsMeta.js +0 -60
- package/build/extractChain.d.ts +0 -1
- package/build/extractChain.js +0 -40
- package/build/fromChain.d.ts +0 -1
- package/build/fromChain.js +0 -91
- package/build/fromDefs.d.ts +0 -1
- package/build/fromDefs.js +0 -78
- package/build/generate/consts.d.ts +0 -5
- package/build/generate/consts.js +0 -87
- package/build/generate/errors.d.ts +0 -4
- package/build/generate/errors.js +0 -55
- package/build/generate/events.d.ts +0 -5
- package/build/generate/events.js +0 -135
- package/build/generate/index.d.ts +0 -10
- package/build/generate/index.js +0 -10
- package/build/generate/interfaceRegistry.d.ts +0 -4
- package/build/generate/interfaceRegistry.js +0 -59
- package/build/generate/lookup.d.ts +0 -4
- package/build/generate/lookup.js +0 -235
- package/build/generate/query.d.ts +0 -5
- package/build/generate/query.js +0 -136
- package/build/generate/rpc.d.ts +0 -6
- package/build/generate/rpc.js +0 -110
- package/build/generate/runtime.d.ts +0 -7
- package/build/generate/runtime.js +0 -228
- package/build/generate/tsDef.d.ts +0 -16
- package/build/generate/tsDef.js +0 -246
- package/build/generate/tx.d.ts +0 -5
- package/build/generate/tx.js +0 -117
- package/build/generate/types.d.ts +0 -12
- package/build/generate/types.js +0 -13
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -2
- package/build/interfacesTs.d.ts +0 -1
- package/build/interfacesTs.js +0 -24
- package/build/metadataMd.d.ts +0 -1
- package/build/metadataMd.js +0 -648
- package/build/package.json +0 -548
- package/build/packageDetect.d.ts +0 -1
- package/build/packageDetect.js +0 -6
- package/build/packageInfo.d.ts +0 -6
- package/build/packageInfo.js +0 -1
- package/build/scripts/pezkuwi-types-chain-info.mjs +0 -7
- package/build/scripts/pezkuwi-types-from-chain.mjs +0 -7
- package/build/scripts/pezkuwi-types-from-defs.mjs +0 -7
- package/build/scripts/pezkuwi-types-internal-interfaces.mjs +0 -7
- package/build/scripts/pezkuwi-types-internal-metadata.mjs +0 -7
- package/build/templates/calls.hbs +0 -30
- package/build/templates/consts.hbs +0 -28
- package/build/templates/docs.hbs +0 -7
- package/build/templates/errors.hbs +0 -28
- package/build/templates/events.hbs +0 -28
- package/build/templates/header.hbs +0 -2
- package/build/templates/interfaceRegistry.hbs +0 -15
- package/build/templates/lookup/defs-named.hbs +0 -12
- package/build/templates/lookup/defs.hbs +0 -15
- package/build/templates/lookup/index.hbs +0 -3
- package/build/templates/lookup/types.hbs +0 -14
- package/build/templates/query.hbs +0 -29
- package/build/templates/rpc.hbs +0 -22
- package/build/templates/tsDef/index.hbs +0 -3
- package/build/templates/tsDef/moduleTypes.hbs +0 -10
- package/build/templates/tsDef/types.hbs +0 -7
- package/build/templates/tx.hbs +0 -30
- package/build/util/assert.d.ts +0 -2
- package/build/util/assert.js +0 -10
- package/build/util/derived.d.ts +0 -4
- package/build/util/docs.d.ts +0 -1
- package/build/util/docs.js +0 -6
- package/build/util/file.d.ts +0 -2
- package/build/util/file.js +0 -28
- package/build/util/formatting.d.ts +0 -11
- package/build/util/formatting.js +0 -230
- package/build/util/imports.d.ts +0 -23
- package/build/util/imports.js +0 -121
- package/build/util/index.d.ts +0 -16
- package/build/util/index.js +0 -34
- package/build/util/initMeta.d.ts +0 -12
- package/build/util/initMeta.js +0 -19
- package/build/util/register.d.ts +0 -4
- package/build/util/register.js +0 -7
- package/build/util/wsMeta.d.ts +0 -4
- package/build/util/wsMeta.js +0 -55
- package/build-tsc-cjs/packageDetect.js +0 -8
- package/build-tsc-cjs/packageInfo.js +0 -4
- package/build-tsc-esm/generate/consts.js +0 -87
- package/build-tsc-esm/generate/errors.js +0 -55
- package/build-tsc-esm/generate/events.js +0 -135
- package/build-tsc-esm/generate/interfaceRegistry.js +0 -59
- package/build-tsc-esm/generate/lookup.js +0 -235
- package/build-tsc-esm/generate/query.js +0 -136
- package/build-tsc-esm/generate/rpc.js +0 -110
- package/build-tsc-esm/generate/runtime.js +0 -228
- package/build-tsc-esm/generate/tsDef.js +0 -246
- package/build-tsc-esm/generate/tx.js +0 -117
- package/build-tsc-esm/generate/types.js +0 -13
- package/build-tsc-esm/util/derived.js +0 -125
- package/src/augment.ts +0 -5
- package/src/bundle.ts +0 -5
- package/src/extractChain.ts +0 -54
- package/src/fromChain.ts +0 -123
- package/src/fromDefs.ts +0 -106
- package/src/generate/consts.ts +0 -112
- package/src/generate/errors.ts +0 -75
- package/src/generate/events.ts +0 -165
- package/src/generate/index.ts +0 -13
- package/src/generate/interfaceRegistry.ts +0 -85
- package/src/generate/lookup.ts +0 -322
- package/src/generate/query.ts +0 -169
- package/src/generate/rpc.ts +0 -158
- package/src/generate/runtime.ts +0 -293
- package/src/generate/tsDef.ts +0 -321
- package/src/generate/tx.ts +0 -152
- package/src/generate/types.ts +0 -26
- package/src/index.ts +0 -6
- package/src/interfacesTs.ts +0 -35
- package/src/metadataMd.ts +0 -844
- package/src/packageDetect.ts +0 -14
- package/src/packageInfo.ts +0 -6
- package/src/templates/calls.hbs +0 -30
- package/src/templates/consts.hbs +0 -28
- package/src/templates/docs.hbs +0 -7
- package/src/templates/errors.hbs +0 -28
- package/src/templates/events.hbs +0 -28
- package/src/templates/header.hbs +0 -2
- package/src/templates/interfaceRegistry.hbs +0 -15
- package/src/templates/lookup/defs-named.hbs +0 -12
- package/src/templates/lookup/defs.hbs +0 -15
- package/src/templates/lookup/index.hbs +0 -3
- package/src/templates/lookup/types.hbs +0 -14
- package/src/templates/query.hbs +0 -29
- package/src/templates/rpc.hbs +0 -22
- package/src/templates/tsDef/index.hbs +0 -3
- package/src/templates/tsDef/moduleTypes.hbs +0 -10
- package/src/templates/tsDef/types.hbs +0 -7
- package/src/templates/tx.hbs +0 -30
- package/src/util/assert.ts +0 -18
- package/src/util/derived.spec.ts +0 -58
- package/src/util/derived.ts +0 -133
- package/src/util/docs.ts +0 -13
- package/src/util/file.ts +0 -42
- package/src/util/formatting.spec.ts +0 -30
- package/src/util/formatting.ts +0 -322
- package/src/util/imports.ts +0 -164
- package/src/util/index.ts +0 -42
- package/src/util/initMeta.ts +0 -37
- package/src/util/register.ts +0 -12
- package/src/util/wsMeta.ts +0 -70
- package/tsconfig.build.json +0 -28
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.scripts.json +0 -19
- package/tsconfig.spec.json +0 -17
- package/tsconfig.spec.tsbuildinfo +0 -1
- /package/{build-tsc/augment.d.ts → augment.d.ts} +0 -0
- /package/{build-tsc-esm/augment.js → augment.js} +0 -0
- /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
- /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
- /package/{build → cjs}/augment.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/augment.js +0 -0
- /package/{build → cjs}/bundle.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
- /package/{build-tsc → cjs}/extractChain.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/extractChain.js +0 -0
- /package/{build-tsc → cjs}/fromChain.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/fromChain.js +0 -0
- /package/{build-tsc → cjs}/fromDefs.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/fromDefs.js +0 -0
- /package/{build-tsc → cjs}/generate/consts.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/consts.js +0 -0
- /package/{build-tsc → cjs}/generate/errors.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/errors.js +0 -0
- /package/{build-tsc → cjs}/generate/events.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/events.js +0 -0
- /package/{build-tsc → cjs}/generate/index.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/index.js +0 -0
- /package/{build-tsc → cjs}/generate/interfaceRegistry.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/interfaceRegistry.js +0 -0
- /package/{build-tsc → cjs}/generate/lookup.d.ts +0 -0
- /package/{build-tsc → cjs}/generate/query.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/query.js +0 -0
- /package/{build-tsc → cjs}/generate/rpc.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/rpc.js +0 -0
- /package/{build-tsc → cjs}/generate/runtime.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/runtime.js +0 -0
- /package/{build-tsc → cjs}/generate/tsDef.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/tsDef.js +0 -0
- /package/{build-tsc → cjs}/generate/tx.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/tx.js +0 -0
- /package/{build-tsc → cjs}/generate/types.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/generate/types.js +0 -0
- /package/{build-tsc → cjs}/index.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/index.js +0 -0
- /package/{build-tsc → cjs}/interfacesTs.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/interfacesTs.js +0 -0
- /package/{build-tsc → cjs}/metadataMd.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/metadataMd.js +0 -0
- /package/{build/cjs → cjs}/package.json +0 -0
- /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
- /package/{build/cjs → cjs}/packageDetect.js +0 -0
- /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
- /package/{build-tsc → cjs}/util/assert.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/assert.js +0 -0
- /package/{build-tsc → cjs}/util/derived.d.ts +0 -0
- /package/{build-tsc → cjs}/util/docs.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/docs.js +0 -0
- /package/{build-tsc → cjs}/util/file.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/file.js +0 -0
- /package/{build-tsc → cjs}/util/formatting.d.ts +0 -0
- /package/{build-tsc → cjs}/util/imports.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/imports.js +0 -0
- /package/{build-tsc → cjs}/util/index.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/index.js +0 -0
- /package/{build-tsc → cjs}/util/initMeta.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/initMeta.js +0 -0
- /package/{build-tsc → cjs}/util/register.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/register.js +0 -0
- /package/{build-tsc → cjs}/util/wsMeta.d.ts +0 -0
- /package/{build-tsc-cjs → cjs}/util/wsMeta.js +0 -0
- /package/{build/cjs/extractChain.d.ts → extractChain.d.ts} +0 -0
- /package/{build-tsc-esm/extractChain.js → extractChain.js} +0 -0
- /package/{build/cjs/fromChain.d.ts → fromChain.d.ts} +0 -0
- /package/{build-tsc-esm/fromChain.js → fromChain.js} +0 -0
- /package/{build/cjs/fromDefs.d.ts → fromDefs.d.ts} +0 -0
- /package/{build-tsc-esm/fromDefs.js → fromDefs.js} +0 -0
- /package/{build/cjs/generate → generate}/index.d.ts +0 -0
- /package/{build-tsc-esm/generate → generate}/index.js +0 -0
- /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
- /package/{build-tsc-esm/index.js → index.js} +0 -0
- /package/{build/cjs/interfacesTs.d.ts → interfacesTs.d.ts} +0 -0
- /package/{build-tsc-esm/interfacesTs.js → interfacesTs.js} +0 -0
- /package/{build/cjs/metadataMd.d.ts → metadataMd.d.ts} +0 -0
- /package/{build-tsc-esm/metadataMd.js → metadataMd.js} +0 -0
- /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
- /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
- /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
- /package/{build/cjs/util → util}/assert.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/assert.js +0 -0
- /package/{build/cjs/util → util}/derived.d.ts +0 -0
- /package/{build/cjs/util → util}/docs.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/docs.js +0 -0
- /package/{build/cjs/util → util}/file.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/file.js +0 -0
- /package/{build/cjs/util → util}/formatting.d.ts +0 -0
- /package/{build/cjs/util → util}/imports.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/imports.js +0 -0
- /package/{build/cjs/util → util}/index.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/index.js +0 -0
- /package/{build/cjs/util → util}/initMeta.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/initMeta.js +0 -0
- /package/{build/cjs/util → util}/register.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/register.js +0 -0
- /package/{build/cjs/util → util}/wsMeta.d.ts +0 -0
- /package/{build-tsc-esm/util → util}/wsMeta.js +0 -0
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { GenericAccountId, GenericCall, GenericLookupSource, GenericVote } from '@pezkuwi/types/generic';
|
|
2
|
-
import { AllConvictions } from '@pezkuwi/types/interfaces/democracy/definitions';
|
|
3
|
-
import { AbstractInt, bool, Compact, Enum, Null, Option, Struct, Tuple, Vec, WrapperKeepOpaque, WrapperOpaque } from '@pezkuwi/types-codec';
|
|
4
|
-
import { getTypeDef, TypeDefInfo } from '@pezkuwi/types-create';
|
|
5
|
-
import { isChildClass, stringify } from '@pezkuwi/util';
|
|
6
|
-
import { formatType } from './formatting.js';
|
|
7
|
-
import { setImports } from './imports.js';
|
|
8
|
-
function arrayToStrType(arr) {
|
|
9
|
-
return `${arr.map((c) => `'${c}'`).join(' | ')}`;
|
|
10
|
-
}
|
|
11
|
-
const voteConvictions = arrayToStrType(AllConvictions);
|
|
12
|
-
/** @internal */
|
|
13
|
-
export function getSimilarTypes(registry, definitions, _type, imports) {
|
|
14
|
-
const typeParts = _type.split('::');
|
|
15
|
-
const type = typeParts[typeParts.length - 1];
|
|
16
|
-
const possibleTypes = [formatType(registry, definitions, type, imports)];
|
|
17
|
-
if (type === 'Extrinsic') {
|
|
18
|
-
setImports(definitions, imports, ['IExtrinsic']);
|
|
19
|
-
return ['Extrinsic', 'IExtrinsic', 'string', 'Uint8Array'];
|
|
20
|
-
}
|
|
21
|
-
else if (type === 'Keys') {
|
|
22
|
-
// This one is weird... surely it should popup as a Tuple? (but either way better as defined hex)
|
|
23
|
-
return ['Keys', 'string', 'Uint8Array'];
|
|
24
|
-
}
|
|
25
|
-
else if (type === 'StorageKey') {
|
|
26
|
-
// TODO We can do better
|
|
27
|
-
return ['StorageKey', 'string', 'Uint8Array', 'any'];
|
|
28
|
-
}
|
|
29
|
-
else if (type === '()') {
|
|
30
|
-
return ['null'];
|
|
31
|
-
}
|
|
32
|
-
const Clazz = registry.createClass(type);
|
|
33
|
-
if (isChildClass(Vec, Clazz)) {
|
|
34
|
-
const vecDef = getTypeDef(type);
|
|
35
|
-
const subDef = (vecDef.sub);
|
|
36
|
-
// this could be that we define a Vec type and refer to it by name
|
|
37
|
-
if (subDef) {
|
|
38
|
-
if (subDef.info === TypeDefInfo.Plain) {
|
|
39
|
-
possibleTypes.push(`(${getSimilarTypes(registry, definitions, subDef.type, imports).join(' | ')})[]`);
|
|
40
|
-
}
|
|
41
|
-
else if (subDef.info === TypeDefInfo.Tuple) {
|
|
42
|
-
const subs = subDef.sub.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
|
|
43
|
-
possibleTypes.push(`([${subs.join(', ')}])[]`);
|
|
44
|
-
}
|
|
45
|
-
else if (subDef.info === TypeDefInfo.Option || subDef.info === TypeDefInfo.Vec || subDef.info === TypeDefInfo.VecFixed) {
|
|
46
|
-
// TODO: Add possibleTypes so imports work
|
|
47
|
-
}
|
|
48
|
-
else if (subDef.info === TypeDefInfo.Struct) {
|
|
49
|
-
// TODO: Add possibleTypes so imports work
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
throw new Error(`Unhandled subtype in Vec, ${stringify(subDef)}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (isChildClass(Enum, Clazz)) {
|
|
57
|
-
const { defKeys, isBasic } = new Clazz(registry);
|
|
58
|
-
const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
|
|
59
|
-
if (isBasic) {
|
|
60
|
-
possibleTypes.push(arrayToStrType(keys), 'number');
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// TODO We don't really want any here, these should be expanded
|
|
64
|
-
possibleTypes.push(...keys.map((k) => `{ ${k}: any }`), 'string');
|
|
65
|
-
}
|
|
66
|
-
possibleTypes.push('Uint8Array');
|
|
67
|
-
}
|
|
68
|
-
else if (isChildClass(AbstractInt, Clazz) || isChildClass(Compact, Clazz)) {
|
|
69
|
-
possibleTypes.push('AnyNumber', 'Uint8Array');
|
|
70
|
-
}
|
|
71
|
-
else if (isChildClass(GenericLookupSource, Clazz)) {
|
|
72
|
-
possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'LookupSource', 'string', 'Uint8Array');
|
|
73
|
-
}
|
|
74
|
-
else if (isChildClass(GenericAccountId, Clazz)) {
|
|
75
|
-
possibleTypes.push('string', 'Uint8Array');
|
|
76
|
-
}
|
|
77
|
-
else if (isChildClass(GenericCall, Clazz)) {
|
|
78
|
-
possibleTypes.push('IMethod', 'string', 'Uint8Array');
|
|
79
|
-
}
|
|
80
|
-
else if (isChildClass(bool, Clazz)) {
|
|
81
|
-
possibleTypes.push('boolean', 'Uint8Array');
|
|
82
|
-
}
|
|
83
|
-
else if (isChildClass(Null, Clazz)) {
|
|
84
|
-
possibleTypes.push('null');
|
|
85
|
-
}
|
|
86
|
-
else if (isChildClass(Struct, Clazz)) {
|
|
87
|
-
const s = new Clazz(registry);
|
|
88
|
-
const obj = s.defKeys.map((key) => `${key}?: any`).join('; ');
|
|
89
|
-
possibleTypes.push(`{ ${obj} }`, 'string', 'Uint8Array');
|
|
90
|
-
}
|
|
91
|
-
else if (isChildClass(Option, Clazz)) {
|
|
92
|
-
possibleTypes.push('null', 'Uint8Array');
|
|
93
|
-
const optDef = getTypeDef(type);
|
|
94
|
-
const subDef = (optDef.sub);
|
|
95
|
-
if (subDef) {
|
|
96
|
-
possibleTypes.push(...getSimilarTypes(registry, definitions, subDef.type, imports));
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
possibleTypes.push('object', 'string');
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (isChildClass(GenericVote, Clazz)) {
|
|
103
|
-
possibleTypes.push(`{ aye: boolean; conviction?: ${voteConvictions} | number }`, 'boolean', 'string', 'Uint8Array');
|
|
104
|
-
}
|
|
105
|
-
else if (isChildClass(WrapperKeepOpaque, Clazz) || isChildClass(WrapperOpaque, Clazz)) {
|
|
106
|
-
// TODO inspect container
|
|
107
|
-
possibleTypes.push('object', 'string', 'Uint8Array');
|
|
108
|
-
}
|
|
109
|
-
else if (isChildClass(Uint8Array, Clazz)) {
|
|
110
|
-
possibleTypes.push('string', 'Uint8Array');
|
|
111
|
-
}
|
|
112
|
-
else if (isChildClass(String, Clazz)) {
|
|
113
|
-
possibleTypes.push('string');
|
|
114
|
-
}
|
|
115
|
-
else if (isChildClass(Tuple, Clazz)) {
|
|
116
|
-
const tupDef = getTypeDef(type);
|
|
117
|
-
const subDef = tupDef.sub;
|
|
118
|
-
// this could be that we define a Tuple type and refer to it by name
|
|
119
|
-
if (Array.isArray(subDef)) {
|
|
120
|
-
const subs = subDef.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
|
|
121
|
-
possibleTypes.push(`[${subs.join(', ')}]`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return [...new Set(possibleTypes)];
|
|
125
|
-
}
|
package/src/augment.ts
DELETED
package/src/bundle.ts
DELETED
package/src/extractChain.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
// Connects to the local chain and outputs a re-usable calls-only chain definition in the form
|
|
5
|
-
// export default { chain: 'Development', genesisHash: '0x27b6d5e0f4fdce1c4d20b82406f193acacce0c19e0d2c0e7ca47725c2572a06a', ss58Format: 42, tokenDecimals: 0, tokenSymbol: 'UNIT'; metaCalls: 'bWV0...4AAA==' };
|
|
6
|
-
|
|
7
|
-
import process from 'node:process';
|
|
8
|
-
import yargs from 'yargs';
|
|
9
|
-
import { hideBin } from 'yargs/helpers';
|
|
10
|
-
|
|
11
|
-
import { ApiPromise, WsProvider } from '@pezkuwi/api';
|
|
12
|
-
|
|
13
|
-
/** @internal */
|
|
14
|
-
async function run (ws: string): Promise<void> {
|
|
15
|
-
const provider = new WsProvider(ws);
|
|
16
|
-
const api = await ApiPromise.create({ provider, throwOnConnect: true });
|
|
17
|
-
const [chain, props] = await Promise.all([
|
|
18
|
-
api.rpc.system.chain(),
|
|
19
|
-
api.rpc.system.properties()
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
// output the chain info, for easy re-use
|
|
23
|
-
console.error(`// Generated via 'yarn run chain:info ${ws}'\n\nexport default {\n chain: '${chain.toString()}',\n genesisHash: '${api.genesisHash.toHex()}',\n specVersion: ${api.runtimeVersion.specVersion.toNumber()},\n ss58Format: ${props.ss58Format.unwrapOr(42).toString()},\n tokenDecimals: ${props.tokenDecimals.unwrapOr(0).toString()},\n tokenSymbol: '${props.tokenSymbol.unwrapOr('UNIT').toString()}',\n metaCalls: '${Buffer.from(api.runtimeMetadata.asCallsOnly.toU8a()).toString('base64')}'\n};`);
|
|
24
|
-
|
|
25
|
-
// show any missing types
|
|
26
|
-
api.runtimeMetadata.getUniqTypes(false);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface ArgV { ws: string }
|
|
30
|
-
|
|
31
|
-
export function main (): void {
|
|
32
|
-
// retrieve and parse arguments - we do this globally, since this is a single command
|
|
33
|
-
const { ws } = yargs(hideBin(process.argv))
|
|
34
|
-
.usage('Usage: [options]')
|
|
35
|
-
.wrap(120)
|
|
36
|
-
.strict()
|
|
37
|
-
.options({
|
|
38
|
-
ws: {
|
|
39
|
-
default: 'ws://127.0.0.1:9944',
|
|
40
|
-
description: 'The API endpoint to connect to, e.g. wss://dicle-rpc.pezkuwi.io',
|
|
41
|
-
required: true,
|
|
42
|
-
type: 'string'
|
|
43
|
-
}
|
|
44
|
-
}).argv as ArgV;
|
|
45
|
-
|
|
46
|
-
run(ws)
|
|
47
|
-
.then((): void => {
|
|
48
|
-
process.exit(0);
|
|
49
|
-
})
|
|
50
|
-
.catch((error: Error) => {
|
|
51
|
-
console.error('FATAL:', error.message);
|
|
52
|
-
process.exit(-1);
|
|
53
|
-
});
|
|
54
|
-
}
|
package/src/fromChain.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { Definitions, DefinitionsTypes } from '@pezkuwi/types/types';
|
|
5
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
6
|
-
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import yargs from 'yargs';
|
|
10
|
-
import { hideBin } from 'yargs/helpers';
|
|
11
|
-
|
|
12
|
-
import { formatNumber, isHex } from '@pezkuwi/util';
|
|
13
|
-
|
|
14
|
-
import { generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultQuery, generateDefaultRpc, generateDefaultRuntime, generateDefaultTx } from './generate/index.js';
|
|
15
|
-
import { assertDir, assertFile, getMetadataViaWs, HEADER, writeFile } from './util/index.js';
|
|
16
|
-
|
|
17
|
-
async function generate (metaHex: HexString, pkg: string | undefined, output: string, isStrict?: boolean): Promise<void> {
|
|
18
|
-
console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
|
|
19
|
-
|
|
20
|
-
const outputPath = assertDir(path.join(process.cwd(), output));
|
|
21
|
-
let extraTypes: Record<string, any> = {};
|
|
22
|
-
let customLookupDefinitions: Definitions = { rpc: {}, types: {} };
|
|
23
|
-
|
|
24
|
-
if (pkg) {
|
|
25
|
-
try {
|
|
26
|
-
const defCont = await import(
|
|
27
|
-
assertFile(path.join(outputPath, 'definitions.ts'))
|
|
28
|
-
) as Record<string, any>;
|
|
29
|
-
|
|
30
|
-
extraTypes = {
|
|
31
|
-
[pkg]: defCont
|
|
32
|
-
};
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error('ERROR: No custom definitions found:', (error as Error).message);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const lookCont = await import(
|
|
40
|
-
assertFile(path.join(outputPath, 'lookup.ts'))
|
|
41
|
-
) as { default: DefinitionsTypes };
|
|
42
|
-
|
|
43
|
-
customLookupDefinitions = {
|
|
44
|
-
rpc: {},
|
|
45
|
-
types: lookCont.default
|
|
46
|
-
};
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error('ERROR: No lookup definitions found:', (error as Error).message);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
generateDefaultConsts(path.join(outputPath, 'augment-api-consts.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
|
|
52
|
-
generateDefaultErrors(path.join(outputPath, 'augment-api-errors.ts'), metaHex, extraTypes, isStrict);
|
|
53
|
-
generateDefaultEvents(path.join(outputPath, 'augment-api-events.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
|
|
54
|
-
generateDefaultQuery(path.join(outputPath, 'augment-api-query.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
|
|
55
|
-
generateDefaultRpc(path.join(outputPath, 'augment-api-rpc.ts'), extraTypes);
|
|
56
|
-
generateDefaultRuntime(path.join(outputPath, 'augment-api-runtime.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
|
|
57
|
-
generateDefaultTx(path.join(outputPath, 'augment-api-tx.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
|
|
58
|
-
|
|
59
|
-
writeFile(path.join(outputPath, 'augment-api.ts'), (): string =>
|
|
60
|
-
[
|
|
61
|
-
HEADER('chain'),
|
|
62
|
-
...[
|
|
63
|
-
...['consts', 'errors', 'events', 'query', 'tx', 'rpc', 'runtime']
|
|
64
|
-
.filter((key) => !!key)
|
|
65
|
-
.map((key) => `./augment-api-${key}.js`)
|
|
66
|
-
].map((path) => `import '${path}';\n`)
|
|
67
|
-
].join('')
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
process.exit(0);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface ArgV { endpoint: string; output: string; package?: string; strict?: boolean }
|
|
74
|
-
|
|
75
|
-
async function mainPromise (): Promise<void> {
|
|
76
|
-
const { endpoint, output, package: pkg, strict: isStrict } = yargs(hideBin(process.argv)).strict().options({
|
|
77
|
-
endpoint: {
|
|
78
|
-
description: 'The endpoint to connect to (e.g. wss://dicle-rpc.pezkuwi.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
|
|
79
|
-
required: true,
|
|
80
|
-
type: 'string'
|
|
81
|
-
},
|
|
82
|
-
output: {
|
|
83
|
-
description: 'The target directory to write the data to',
|
|
84
|
-
required: true,
|
|
85
|
-
type: 'string'
|
|
86
|
-
},
|
|
87
|
-
package: {
|
|
88
|
-
description: 'Optional package in output location (for extra definitions)',
|
|
89
|
-
type: 'string'
|
|
90
|
-
},
|
|
91
|
-
strict: {
|
|
92
|
-
description: 'Turns on strict mode, no output of catch-all generic versions',
|
|
93
|
-
type: 'boolean'
|
|
94
|
-
}
|
|
95
|
-
}).argv as ArgV;
|
|
96
|
-
|
|
97
|
-
let metaHex: HexString;
|
|
98
|
-
|
|
99
|
-
if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
|
|
100
|
-
metaHex = await getMetadataViaWs(endpoint);
|
|
101
|
-
} else {
|
|
102
|
-
metaHex = (
|
|
103
|
-
JSON.parse(
|
|
104
|
-
fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
|
|
105
|
-
) as { result: HexString }
|
|
106
|
-
).result;
|
|
107
|
-
|
|
108
|
-
if (!isHex(metaHex)) {
|
|
109
|
-
throw new Error('Invalid metadata file');
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
await generate(metaHex, pkg, output, isStrict);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function main (): void {
|
|
117
|
-
mainPromise().catch((error) => {
|
|
118
|
-
console.error();
|
|
119
|
-
console.error(error);
|
|
120
|
-
console.error();
|
|
121
|
-
process.exit(1);
|
|
122
|
-
});
|
|
123
|
-
}
|
package/src/fromDefs.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
-
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import yargs from 'yargs';
|
|
9
|
-
import { hideBin } from 'yargs/helpers';
|
|
10
|
-
|
|
11
|
-
import * as bizinikiwiDefs from '@pezkuwi/types/interfaces/definitions';
|
|
12
|
-
import { isHex } from '@pezkuwi/util';
|
|
13
|
-
|
|
14
|
-
import { generateDefaultLookup } from './generate/index.js';
|
|
15
|
-
import { generateInterfaceTypes } from './generate/interfaceRegistry.js';
|
|
16
|
-
import { generateTsDef } from './generate/tsDef.js';
|
|
17
|
-
import { assertDir, assertFile, getMetadataViaWs } from './util/index.js';
|
|
18
|
-
|
|
19
|
-
interface ArgV { input: string; package: string; endpoint?: string; }
|
|
20
|
-
|
|
21
|
-
async function mainPromise (): Promise<void> {
|
|
22
|
-
const { endpoint, input, package: pkg } = yargs(hideBin(process.argv)).strict().options({
|
|
23
|
-
endpoint: {
|
|
24
|
-
description: 'The endpoint to connect to (e.g. wss://dicle-rpc.pezkuwi.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
|
|
25
|
-
type: 'string'
|
|
26
|
-
},
|
|
27
|
-
input: {
|
|
28
|
-
description: 'The directory to use for the user definitions',
|
|
29
|
-
required: true,
|
|
30
|
-
type: 'string'
|
|
31
|
-
},
|
|
32
|
-
package: {
|
|
33
|
-
description: 'The package name & path to use for the user types',
|
|
34
|
-
required: true,
|
|
35
|
-
type: 'string'
|
|
36
|
-
}
|
|
37
|
-
}).argv as ArgV;
|
|
38
|
-
|
|
39
|
-
const inputPath = assertDir(path.join(process.cwd(), input));
|
|
40
|
-
let userDefs: Record<string, any> = {};
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const defCont = await import(
|
|
44
|
-
assertFile(path.join(inputPath, 'definitions.ts'))
|
|
45
|
-
) as Record<string, any>;
|
|
46
|
-
|
|
47
|
-
userDefs = defCont;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('ERROR: Unable to load user definitions:', (error as Error).message);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const userKeys = Object.keys(userDefs);
|
|
53
|
-
const filteredBase = Object
|
|
54
|
-
.entries(bizinikiwiDefs as Record<string, unknown>)
|
|
55
|
-
.filter(([key]) => {
|
|
56
|
-
if (userKeys.includes(key)) {
|
|
57
|
-
console.warn(`Override found for ${key} in user types, ignoring in @pezkuwi/types`);
|
|
58
|
-
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return true;
|
|
63
|
-
})
|
|
64
|
-
.reduce((defs: Record<string, any>, [key, value]) => {
|
|
65
|
-
defs[key] = value;
|
|
66
|
-
|
|
67
|
-
return defs;
|
|
68
|
-
}, {});
|
|
69
|
-
|
|
70
|
-
const allDefs = {
|
|
71
|
-
'@pezkuwi/types/interfaces': filteredBase,
|
|
72
|
-
[pkg]: userDefs
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
generateTsDef(allDefs, inputPath, pkg);
|
|
76
|
-
generateInterfaceTypes(allDefs, path.join(inputPath, 'augment-types.ts'));
|
|
77
|
-
|
|
78
|
-
if (endpoint) {
|
|
79
|
-
let metaHex: HexString;
|
|
80
|
-
|
|
81
|
-
if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
|
|
82
|
-
metaHex = await getMetadataViaWs(endpoint);
|
|
83
|
-
} else {
|
|
84
|
-
metaHex = (
|
|
85
|
-
JSON.parse(
|
|
86
|
-
fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
|
|
87
|
-
) as { result: HexString }
|
|
88
|
-
).result;
|
|
89
|
-
|
|
90
|
-
if (!isHex(metaHex)) {
|
|
91
|
-
throw new Error('Invalid metadata file');
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
generateDefaultLookup(inputPath, metaHex);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function main (): void {
|
|
100
|
-
mainPromise().catch((error) => {
|
|
101
|
-
console.error();
|
|
102
|
-
console.error(error);
|
|
103
|
-
console.error();
|
|
104
|
-
process.exit(1);
|
|
105
|
-
});
|
|
106
|
-
}
|
package/src/generate/consts.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
|
|
5
|
-
import type { Definitions } from '@pezkuwi/types/types';
|
|
6
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
7
|
-
|
|
8
|
-
import Handlebars from 'handlebars';
|
|
9
|
-
|
|
10
|
-
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
11
|
-
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
12
|
-
import { stringCamelCase } from '@pezkuwi/util';
|
|
13
|
-
|
|
14
|
-
import { compareName, createImports, formatType, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
|
|
15
|
-
import { ignoreUnusedLookups } from './lookup.js';
|
|
16
|
-
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
17
|
-
|
|
18
|
-
const generateForMetaTemplate = Handlebars.compile(readTemplate('consts'));
|
|
19
|
-
|
|
20
|
-
/** @internal */
|
|
21
|
-
function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
|
|
22
|
-
writeFile(dest, (): string => {
|
|
23
|
-
const allTypes = {
|
|
24
|
-
'@pezkuwi/types-augment': {
|
|
25
|
-
lookup: {
|
|
26
|
-
...lookupDefinitions,
|
|
27
|
-
...customLookupDefinitions
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
'@pezkuwi/types/interfaces': defaultDefs,
|
|
31
|
-
...extraTypes
|
|
32
|
-
};
|
|
33
|
-
const imports = createImports(allTypes);
|
|
34
|
-
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
35
|
-
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
36
|
-
}, {});
|
|
37
|
-
const { lookup, pallets, registry } = meta.asLatest;
|
|
38
|
-
const usedTypes = new Set<string>([]);
|
|
39
|
-
|
|
40
|
-
const modules = pallets
|
|
41
|
-
.filter(({ constants }) => constants.length > 0)
|
|
42
|
-
.map(({ constants, name }) => {
|
|
43
|
-
if (!isStrict) {
|
|
44
|
-
setImports(allDefs, imports, ['Codec']);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const items = constants
|
|
48
|
-
.map(({ deprecationInfo, docs, name, type }) => {
|
|
49
|
-
const typeDef = lookup.getTypeDef(type);
|
|
50
|
-
const returnType = rebrandTypeName(typeDef.lookupName || '') || formatType(registry, allDefs, typeDef, imports);
|
|
51
|
-
|
|
52
|
-
if (!deprecationInfo.isNotDeprecated) {
|
|
53
|
-
const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name), 'Constant');
|
|
54
|
-
|
|
55
|
-
const items = docs.length
|
|
56
|
-
? ['', deprecationNotice]
|
|
57
|
-
: [deprecationNotice];
|
|
58
|
-
|
|
59
|
-
docs.push(...items.map((text) => registry.createType('Text', text)));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Add the type to the list of used types
|
|
63
|
-
if (!(imports.primitiveTypes[returnType])) {
|
|
64
|
-
usedTypes.add(returnType);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setImports(allDefs, imports, [returnType]);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
docs,
|
|
71
|
-
name: stringCamelCase(name),
|
|
72
|
-
type: returnType
|
|
73
|
-
};
|
|
74
|
-
})
|
|
75
|
-
.sort(compareName);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
items,
|
|
79
|
-
name: stringCamelCase(name)
|
|
80
|
-
};
|
|
81
|
-
})
|
|
82
|
-
.sort(compareName);
|
|
83
|
-
|
|
84
|
-
// filter out the unused lookup types from imports
|
|
85
|
-
ignoreUnusedLookups([...usedTypes], imports);
|
|
86
|
-
|
|
87
|
-
return generateForMetaTemplate({
|
|
88
|
-
headerType: 'chain',
|
|
89
|
-
imports,
|
|
90
|
-
isStrict,
|
|
91
|
-
modules,
|
|
92
|
-
types: [
|
|
93
|
-
...Object.keys(imports.localTypes).sort().map<{ file: string; types: string[] }>((packagePath) => ({
|
|
94
|
-
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
95
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
96
|
-
})),
|
|
97
|
-
{
|
|
98
|
-
file: '@pezkuwi/api-base/types',
|
|
99
|
-
types: ['ApiTypes', 'AugmentedConst']
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Call `generateForMeta()` with current static metadata
|
|
107
|
-
/** @internal */
|
|
108
|
-
export function generateDefaultConsts (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
|
|
109
|
-
const { metadata } = initMeta(data, extraTypes);
|
|
110
|
-
|
|
111
|
-
return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
112
|
-
}
|
package/src/generate/errors.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { VariantDeprecationInfoV16 } from '@pezkuwi/types/interfaces';
|
|
5
|
-
import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
|
|
6
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
7
|
-
|
|
8
|
-
import Handlebars from 'handlebars';
|
|
9
|
-
|
|
10
|
-
import { stringCamelCase } from '@pezkuwi/util';
|
|
11
|
-
|
|
12
|
-
import { compareName, createImports, initMeta, readTemplate, writeFile } from '../util/index.js';
|
|
13
|
-
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
14
|
-
|
|
15
|
-
const generateForMetaTemplate = Handlebars.compile(readTemplate('errors'));
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void {
|
|
19
|
-
writeFile(dest, (): string => {
|
|
20
|
-
const imports = createImports({});
|
|
21
|
-
const { lookup, pallets } = meta.asLatest;
|
|
22
|
-
const modules = pallets
|
|
23
|
-
.filter(({ errors }) => errors.isSome)
|
|
24
|
-
.map((data) => {
|
|
25
|
-
const name = data.name;
|
|
26
|
-
const errors = data.errors.unwrap();
|
|
27
|
-
const deprecationInfo = errors.deprecationInfo.toJSON();
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
items: lookup.getSiType(errors.type).def.asVariant.variants
|
|
31
|
-
.map(({ docs, index, name }) => {
|
|
32
|
-
const rawStatus = deprecationInfo?.[index.toNumber()];
|
|
33
|
-
|
|
34
|
-
if (rawStatus) {
|
|
35
|
-
const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
|
|
36
|
-
|
|
37
|
-
const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString());
|
|
38
|
-
const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
|
|
39
|
-
|
|
40
|
-
docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
docs,
|
|
45
|
-
name: name.toString()
|
|
46
|
-
};
|
|
47
|
-
})
|
|
48
|
-
.sort(compareName),
|
|
49
|
-
name: stringCamelCase(name)
|
|
50
|
-
};
|
|
51
|
-
})
|
|
52
|
-
.sort(compareName);
|
|
53
|
-
|
|
54
|
-
return generateForMetaTemplate({
|
|
55
|
-
headerType: 'chain',
|
|
56
|
-
imports,
|
|
57
|
-
isStrict,
|
|
58
|
-
modules,
|
|
59
|
-
types: [
|
|
60
|
-
{
|
|
61
|
-
file: '@pezkuwi/api-base/types',
|
|
62
|
-
types: ['ApiTypes', 'AugmentedError']
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Call `generateForMeta()` with current static metadata
|
|
70
|
-
/** @internal */
|
|
71
|
-
export function generateDefaultErrors (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false): void {
|
|
72
|
-
const { metadata } = initMeta(data, extraTypes);
|
|
73
|
-
|
|
74
|
-
return generateForMeta(metadata, dest, isStrict);
|
|
75
|
-
}
|