@pezkuwi/typegen 16.5.5 → 16.5.6
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/LICENSE +201 -0
- package/augment.js +2 -0
- package/bundle.js +2 -0
- package/cjs/augment.d.ts +2 -0
- package/cjs/augment.js +4 -0
- package/cjs/bundle.d.ts +2 -0
- package/cjs/bundle.js +7 -0
- package/cjs/extractChain.js +44 -0
- package/cjs/fromChain.js +95 -0
- package/cjs/fromDefs.js +82 -0
- package/cjs/generate/consts.js +91 -0
- package/cjs/generate/errors.js +59 -0
- package/cjs/generate/events.js +139 -0
- package/cjs/generate/index.js +23 -0
- package/cjs/generate/interfaceRegistry.js +64 -0
- package/cjs/generate/lookup.js +240 -0
- package/cjs/generate/query.js +140 -0
- package/cjs/generate/rpc.js +115 -0
- package/cjs/generate/runtime.js +233 -0
- package/{build → cjs}/generate/tsDef.d.ts +1 -1
- package/cjs/generate/tsDef.js +254 -0
- package/cjs/generate/tx.js +121 -0
- package/cjs/generate/types.js +16 -0
- package/cjs/index.js +5 -0
- package/cjs/interfacesTs.js +28 -0
- package/cjs/metadataMd.js +652 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.js +8 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/util/assert.js +15 -0
- package/cjs/util/derived.js +128 -0
- package/cjs/util/docs.js +10 -0
- package/cjs/util/file.js +33 -0
- package/{build → cjs}/util/formatting.d.ts +1 -1
- package/cjs/util/formatting.js +237 -0
- package/cjs/util/imports.js +126 -0
- package/{build → cjs}/util/index.d.ts +1 -0
- package/cjs/util/index.js +39 -0
- package/cjs/util/initMeta.js +22 -0
- package/cjs/util/register.js +10 -0
- package/cjs/util/wsMeta.js +60 -0
- package/extractChain.d.ts +1 -0
- package/extractChain.js +40 -0
- package/fromChain.d.ts +1 -0
- package/fromChain.js +91 -0
- package/fromDefs.d.ts +1 -0
- package/fromDefs.js +78 -0
- package/generate/consts.d.ts +5 -0
- package/generate/consts.js +87 -0
- package/generate/errors.d.ts +4 -0
- package/generate/errors.js +55 -0
- package/generate/events.d.ts +5 -0
- package/generate/events.js +135 -0
- package/{src/generate/index.ts → generate/index.d.ts} +0 -3
- package/generate/index.js +10 -0
- package/generate/interfaceRegistry.d.ts +4 -0
- package/generate/interfaceRegistry.js +59 -0
- package/generate/lookup.d.ts +4 -0
- package/generate/lookup.js +235 -0
- package/generate/query.d.ts +5 -0
- package/generate/query.js +136 -0
- package/generate/rpc.d.ts +6 -0
- package/generate/rpc.js +110 -0
- package/generate/runtime.d.ts +7 -0
- package/generate/runtime.js +228 -0
- package/generate/tsDef.d.ts +16 -0
- package/generate/tsDef.js +246 -0
- package/generate/tx.d.ts +5 -0
- package/generate/tx.js +117 -0
- package/generate/types.d.ts +12 -0
- package/generate/types.js +13 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/interfacesTs.d.ts +1 -0
- package/interfacesTs.js +24 -0
- package/metadataMd.d.ts +1 -0
- package/metadataMd.js +648 -0
- package/package.json +520 -24
- package/packageDetect.d.ts +1 -0
- package/{src/packageDetect.ts → packageDetect.js} +0 -8
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/scripts/{polkadot-types-chain-info.mjs → pezkuwi-types-chain-info.mjs} +1 -1
- package/scripts/{polkadot-types-from-chain.mjs → pezkuwi-types-from-chain.mjs} +1 -1
- package/scripts/{polkadot-types-from-defs.mjs → pezkuwi-types-from-defs.mjs} +1 -1
- package/{build/scripts/polkadot-types-internal-interfaces.mjs → scripts/pezkuwi-types-internal-interfaces.mjs} +1 -1
- package/{build/scripts/polkadot-types-internal-metadata.mjs → scripts/pezkuwi-types-internal-metadata.mjs} +1 -1
- package/{src/templates → templates}/calls.hbs +2 -2
- package/{src/templates → templates}/consts.hbs +2 -2
- package/{src/templates → templates}/errors.hbs +2 -2
- package/{src/templates → templates}/events.hbs +2 -2
- package/{src/templates → templates}/interfaceRegistry.hbs +2 -2
- package/{src/templates → templates}/lookup/types.hbs +2 -2
- package/{src/templates → templates}/query.hbs +2 -2
- package/{src/templates → templates}/rpc.hbs +2 -2
- package/{src/templates → templates}/tx.hbs +2 -2
- package/util/assert.d.ts +2 -0
- package/util/assert.js +10 -0
- package/util/derived.d.ts +4 -0
- package/util/derived.js +125 -0
- package/util/docs.d.ts +1 -0
- package/util/docs.js +6 -0
- package/util/file.d.ts +2 -0
- package/util/file.js +28 -0
- package/util/formatting.d.ts +11 -0
- package/util/formatting.js +230 -0
- package/util/imports.d.ts +23 -0
- package/util/imports.js +121 -0
- package/{src/util/index.ts → util/index.d.ts} +6 -8
- package/util/index.js +34 -0
- package/util/initMeta.d.ts +12 -0
- package/util/initMeta.js +19 -0
- package/util/register.d.ts +4 -0
- package/util/register.js +7 -0
- package/util/wsMeta.d.ts +4 -0
- package/util/wsMeta.js +55 -0
- package/build/scripts/polkadot-types-chain-info.mjs +0 -7
- package/build/scripts/polkadot-types-from-chain.mjs +0 -7
- package/build/scripts/polkadot-types-from-defs.mjs +0 -7
- package/scripts/polkadot-types-internal-interfaces.mjs +0 -7
- package/scripts/polkadot-types-internal-metadata.mjs +0 -7
- 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/interfaceRegistry.ts +0 -85
- package/src/generate/lookup.ts +0 -294
- package/src/generate/query.ts +0 -169
- package/src/generate/rpc.ts +0 -158
- package/src/generate/runtime.ts +0 -284
- 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/packageInfo.ts +0 -6
- 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 -295
- package/src/util/imports.ts +0 -164
- 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/{build/augment.d.ts → augment.d.ts} +0 -0
- /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
- /package/{build → cjs}/extractChain.d.ts +0 -0
- /package/{build → cjs}/fromChain.d.ts +0 -0
- /package/{build → cjs}/fromDefs.d.ts +0 -0
- /package/{build → cjs}/generate/consts.d.ts +0 -0
- /package/{build → cjs}/generate/errors.d.ts +0 -0
- /package/{build → cjs}/generate/events.d.ts +0 -0
- /package/{build → cjs}/generate/index.d.ts +0 -0
- /package/{build → cjs}/generate/interfaceRegistry.d.ts +0 -0
- /package/{build → cjs}/generate/lookup.d.ts +0 -0
- /package/{build → cjs}/generate/query.d.ts +0 -0
- /package/{build → cjs}/generate/rpc.d.ts +0 -0
- /package/{build → cjs}/generate/runtime.d.ts +0 -0
- /package/{build → cjs}/generate/tx.d.ts +0 -0
- /package/{build → cjs}/generate/types.d.ts +0 -0
- /package/{build → cjs}/index.d.ts +0 -0
- /package/{build → cjs}/interfacesTs.d.ts +0 -0
- /package/{build → cjs}/metadataMd.d.ts +0 -0
- /package/{build → cjs}/packageDetect.d.ts +0 -0
- /package/{build → cjs}/packageInfo.d.ts +0 -0
- /package/{build → cjs}/util/assert.d.ts +0 -0
- /package/{build → cjs}/util/derived.d.ts +0 -0
- /package/{build → cjs}/util/docs.d.ts +0 -0
- /package/{build → cjs}/util/file.d.ts +0 -0
- /package/{build → cjs}/util/imports.d.ts +0 -0
- /package/{build → cjs}/util/initMeta.d.ts +0 -0
- /package/{build → cjs}/util/register.d.ts +0 -0
- /package/{build → cjs}/util/wsMeta.d.ts +0 -0
- /package/{src/templates → templates}/docs.hbs +0 -0
- /package/{src/templates → templates}/header.hbs +0 -0
- /package/{src/templates → templates}/lookup/defs-named.hbs +0 -0
- /package/{src/templates → templates}/lookup/defs.hbs +0 -0
- /package/{src/templates → templates}/lookup/index.hbs +0 -0
- /package/{src/templates → templates}/tsDef/index.hbs +0 -0
- /package/{src/templates → templates}/tsDef/moduleTypes.hbs +0 -0
- /package/{src/templates → templates}/tsDef/types.hbs +0 -0
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/api-base/types/errors';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
9
9
|
export type __AugmentedError<ApiType extends ApiTypes> = AugmentedError<ApiType>;
|
|
10
10
|
|
|
11
|
-
declare module '@
|
|
11
|
+
declare module '@pezkuwi/api-base/types/errors' {
|
|
12
12
|
interface AugmentedErrors<ApiType extends ApiTypes> {
|
|
13
13
|
{{#each modules}}
|
|
14
14
|
{{{name}}}: {
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/api-base/types/events';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
9
9
|
export type __AugmentedEvent<ApiType extends ApiTypes> = AugmentedEvent<ApiType>;
|
|
10
10
|
|
|
11
|
-
declare module '@
|
|
11
|
+
declare module '@pezkuwi/api-base/types/events' {
|
|
12
12
|
interface AugmentedEvents<ApiType extends ApiTypes> {
|
|
13
13
|
{{#each modules}}
|
|
14
14
|
{{{name}}}: {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/types/types/registry';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
9
|
-
declare module '@
|
|
9
|
+
declare module '@pezkuwi/types/types/registry' {
|
|
10
10
|
interface InterfaceTypes {
|
|
11
11
|
{{#each items}}
|
|
12
12
|
{{{this}}}: {{{this}}};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/types/lookup';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
9
|
-
declare module '@
|
|
9
|
+
declare module '@pezkuwi/types/lookup' {
|
|
10
10
|
{{#each items}}
|
|
11
11
|
{{{this}}}
|
|
12
12
|
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/api-base/types/storage';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
9
9
|
export type __AugmentedQuery<ApiType extends ApiTypes> = AugmentedQuery<ApiType, () => unknown>;
|
|
10
10
|
export type __QueryableStorageEntry<ApiType extends ApiTypes> = QueryableStorageEntry<ApiType>;
|
|
11
11
|
|
|
12
|
-
declare module '@
|
|
12
|
+
declare module '@pezkuwi/api-base/types/storage' {
|
|
13
13
|
interface AugmentedQueries<ApiType extends ApiTypes> {
|
|
14
14
|
{{#each modules}}
|
|
15
15
|
{{{name}}}: {
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/rpc-core/types/jsonrpc';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
9
9
|
export type __AugmentedRpc = AugmentedRpc<() => unknown>;
|
|
10
10
|
|
|
11
|
-
declare module '@
|
|
11
|
+
declare module '@pezkuwi/rpc-core/types/jsonrpc' {
|
|
12
12
|
interface RpcInterface {
|
|
13
13
|
{{#each modules}}
|
|
14
14
|
{{{name}}}: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// import type lookup before we augment - in some environments
|
|
4
4
|
// this is required to allow for ambient/previous definitions
|
|
5
|
-
import '@
|
|
5
|
+
import '@pezkuwi/api-base/types/submittable';
|
|
6
6
|
|
|
7
7
|
{{{ importsAll }}}
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ export type __AugmentedSubmittable = AugmentedSubmittable<() => unknown>;
|
|
|
10
10
|
export type __SubmittableExtrinsic<ApiType extends ApiTypes> = SubmittableExtrinsic<ApiType>;
|
|
11
11
|
export type __SubmittableExtrinsicFunction<ApiType extends ApiTypes> = SubmittableExtrinsicFunction<ApiType>;
|
|
12
12
|
|
|
13
|
-
declare module '@
|
|
13
|
+
declare module '@pezkuwi/api-base/types/submittable' {
|
|
14
14
|
interface AugmentedSubmittables<ApiType extends ApiTypes> {
|
|
15
15
|
{{#each modules}}
|
|
16
16
|
{{{name}}}: {
|
package/util/assert.d.ts
ADDED
package/util/assert.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { assert } from '@pezkuwi/util';
|
|
3
|
+
export function assertDir(path) {
|
|
4
|
+
assert(fs.existsSync(path) && fs.lstatSync(path).isDirectory(), `${path} is not a directory`);
|
|
5
|
+
return path;
|
|
6
|
+
}
|
|
7
|
+
export function assertFile(path) {
|
|
8
|
+
assert(fs.existsSync(path) && fs.lstatSync(path).isFile(), `${path} is not a file`);
|
|
9
|
+
return path;
|
|
10
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Registry } from '@pezkuwi/types/types';
|
|
2
|
+
import type { ModuleTypes, TypeImports } from './imports.js';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare function getSimilarTypes(registry: Registry, definitions: Record<string, ModuleTypes>, _type: string, imports: TypeImports): string[];
|
package/util/derived.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
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/util/docs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const __TYPEGEN_DUMMY_DOCS = "DUMMY_DOCS";
|
package/util/docs.js
ADDED
package/util/file.d.ts
ADDED
package/util/file.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { packageInfo } from '../packageInfo.js';
|
|
5
|
+
export function writeFile(dest, generator, noLog) {
|
|
6
|
+
!noLog && console.log(`${dest}\n\tGenerating`);
|
|
7
|
+
let generated = generator();
|
|
8
|
+
while (generated.includes('\n\n\n')) {
|
|
9
|
+
generated = generated.replace(/\n\n\n/g, '\n\n');
|
|
10
|
+
}
|
|
11
|
+
!noLog && console.log('\tWriting');
|
|
12
|
+
fs.writeFileSync(dest, generated, { flag: 'w' });
|
|
13
|
+
!noLog && console.log('');
|
|
14
|
+
}
|
|
15
|
+
export function readTemplate(template) {
|
|
16
|
+
// Inside the api repo itself, it will be 'auto'
|
|
17
|
+
const rootDir = packageInfo.path === 'auto'
|
|
18
|
+
? path.join(process.cwd(), 'packages/typegen/src')
|
|
19
|
+
: packageInfo.path;
|
|
20
|
+
// NOTE With cjs in a subdir, search one lower as well
|
|
21
|
+
const file = ['./templates', '../templates']
|
|
22
|
+
.map((p) => path.join(rootDir, p, `${template}.hbs`))
|
|
23
|
+
.find((p) => fs.existsSync(p));
|
|
24
|
+
if (!file) {
|
|
25
|
+
throw new Error(`Unable to locate ${template}.hbs from ${rootDir}`);
|
|
26
|
+
}
|
|
27
|
+
return fs.readFileSync(file).toString();
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyString, Registry } from '@pezkuwi/types/types';
|
|
2
|
+
import type { TypeDef } from '@pezkuwi/types-create/types';
|
|
3
|
+
import type { ModuleTypes, TypeImports } from './imports.js';
|
|
4
|
+
export declare const HEADER: (type: "chain" | "defs") => string;
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare function exportInterface(lookupIndex: number | undefined, name: string | undefined, base: string, body?: string, withShortcut?: boolean): string;
|
|
7
|
+
/**
|
|
8
|
+
* Correctly format a given type
|
|
9
|
+
*/
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function formatType(registry: Registry, definitions: Record<string, ModuleTypes>, type: AnyString | TypeDef, imports: TypeImports, withShortcut?: boolean): string;
|
|
@@ -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 {};
|