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