@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/src/generate/events.ts
DELETED
|
@@ -1,165 +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 { Definitions } from '@pezkuwi/types/types';
|
|
7
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
8
|
-
|
|
9
|
-
import Handlebars from 'handlebars';
|
|
10
|
-
|
|
11
|
-
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
12
|
-
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
13
|
-
import { stringCamelCase } from '@pezkuwi/util';
|
|
14
|
-
|
|
15
|
-
import { compareName, createImports, formatType, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
|
|
16
|
-
import { ignoreUnusedLookups } from './lookup.js';
|
|
17
|
-
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
18
|
-
|
|
19
|
-
const generateForMetaTemplate = Handlebars.compile(readTemplate('events'));
|
|
20
|
-
|
|
21
|
-
// For babel itself we need some extra aliasing
|
|
22
|
-
// Also avoid reserved words to prevent generating invalid TS
|
|
23
|
-
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
|
|
24
|
-
const ALIAS = [
|
|
25
|
-
'symbol',
|
|
26
|
-
'break',
|
|
27
|
-
'case',
|
|
28
|
-
'catch',
|
|
29
|
-
'class',
|
|
30
|
-
'const',
|
|
31
|
-
'continue',
|
|
32
|
-
'debugger',
|
|
33
|
-
'default',
|
|
34
|
-
'delete',
|
|
35
|
-
'do',
|
|
36
|
-
'else',
|
|
37
|
-
'export',
|
|
38
|
-
'extends',
|
|
39
|
-
'false',
|
|
40
|
-
'finally',
|
|
41
|
-
'for',
|
|
42
|
-
'function',
|
|
43
|
-
'if',
|
|
44
|
-
'import',
|
|
45
|
-
'in',
|
|
46
|
-
'instanceof',
|
|
47
|
-
'new',
|
|
48
|
-
'null',
|
|
49
|
-
'return',
|
|
50
|
-
'static',
|
|
51
|
-
'super',
|
|
52
|
-
'switch',
|
|
53
|
-
'this',
|
|
54
|
-
'throw',
|
|
55
|
-
'true',
|
|
56
|
-
'try',
|
|
57
|
-
'typeof',
|
|
58
|
-
'var',
|
|
59
|
-
'void',
|
|
60
|
-
'while',
|
|
61
|
-
'with',
|
|
62
|
-
'yield'
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
/** @internal */
|
|
66
|
-
function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
|
|
67
|
-
writeFile(dest, (): string => {
|
|
68
|
-
const allTypes = {
|
|
69
|
-
'@pezkuwi/types-augment': {
|
|
70
|
-
lookup: {
|
|
71
|
-
...lookupDefinitions,
|
|
72
|
-
...customLookupDefinitions
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
'@pezkuwi/types/interfaces': defaultDefs,
|
|
76
|
-
...extraTypes
|
|
77
|
-
};
|
|
78
|
-
const imports = createImports(allTypes);
|
|
79
|
-
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
80
|
-
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
81
|
-
}, {});
|
|
82
|
-
const { lookup, pallets, registry } = meta.asLatest;
|
|
83
|
-
const usedTypes = new Set<string>([]);
|
|
84
|
-
const modules = pallets
|
|
85
|
-
.filter(({ events }) => events.isSome)
|
|
86
|
-
.map((data) => {
|
|
87
|
-
const name = data.name;
|
|
88
|
-
const events = data.events.unwrap();
|
|
89
|
-
const deprecationInfo = events.deprecationInfo.toJSON();
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
items: lookup.getSiType(events.type).def.asVariant.variants
|
|
93
|
-
.map(({ docs, fields, index, name }) => {
|
|
94
|
-
const rawStatus = deprecationInfo?.[index.toNumber()];
|
|
95
|
-
|
|
96
|
-
if (rawStatus) {
|
|
97
|
-
const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
|
|
98
|
-
const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString());
|
|
99
|
-
const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
|
|
100
|
-
|
|
101
|
-
docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const args = fields
|
|
105
|
-
.map(({ type }) => lookup.getTypeDef(type))
|
|
106
|
-
.map((typeDef) => {
|
|
107
|
-
const arg = rebrandTypeName(typeDef.lookupName || '') || formatType(registry, allDefs, typeDef, imports);
|
|
108
|
-
|
|
109
|
-
// Add the type to the list of used types
|
|
110
|
-
if (!(imports.primitiveTypes[arg])) {
|
|
111
|
-
usedTypes.add(arg);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return arg;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const names = fields
|
|
118
|
-
.map(({ name }) => registry.lookup.sanitizeField(name)[0])
|
|
119
|
-
.filter((n): n is string => !!n);
|
|
120
|
-
|
|
121
|
-
setImports(allDefs, imports, args);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
docs,
|
|
125
|
-
name: name.toString(),
|
|
126
|
-
type: names.length !== 0 && names.length === args.length
|
|
127
|
-
? `[${names.map((n, i) => `${ALIAS.includes(n) ? `${n}_` : n}: ${args[i]}`).join(', ')}], { ${names.map((n, i) => `${n}: ${args[i]}`).join(', ')} }`
|
|
128
|
-
: `[${args.join(', ')}]`
|
|
129
|
-
};
|
|
130
|
-
})
|
|
131
|
-
.sort(compareName),
|
|
132
|
-
name: stringCamelCase(name)
|
|
133
|
-
};
|
|
134
|
-
})
|
|
135
|
-
.sort(compareName);
|
|
136
|
-
|
|
137
|
-
// filter out the unused lookup types from imports
|
|
138
|
-
ignoreUnusedLookups([...usedTypes], imports);
|
|
139
|
-
|
|
140
|
-
return generateForMetaTemplate({
|
|
141
|
-
headerType: 'chain',
|
|
142
|
-
imports,
|
|
143
|
-
isStrict,
|
|
144
|
-
modules,
|
|
145
|
-
types: [
|
|
146
|
-
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
147
|
-
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
148
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
149
|
-
})),
|
|
150
|
-
{
|
|
151
|
-
file: '@pezkuwi/api-base/types',
|
|
152
|
-
types: ['ApiTypes', 'AugmentedEvent']
|
|
153
|
-
}
|
|
154
|
-
]
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Call `generateForMeta()` with current static metadata
|
|
160
|
-
/** @internal */
|
|
161
|
-
export function generateDefaultEvents (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
|
|
162
|
-
const { metadata } = initMeta(data, extraTypes);
|
|
163
|
-
|
|
164
|
-
return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
165
|
-
}
|
package/src/generate/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
export { generateDefaultConsts } from './consts.js';
|
|
5
|
-
export { generateDefaultErrors } from './errors.js';
|
|
6
|
-
export { generateDefaultEvents } from './events.js';
|
|
7
|
-
export { generateDefaultInterface } from './interfaceRegistry.js';
|
|
8
|
-
export { generateDefaultLookup } from './lookup.js';
|
|
9
|
-
export { generateDefaultQuery } from './query.js';
|
|
10
|
-
export { generateDefaultRpc } from './rpc.js';
|
|
11
|
-
export { generateDefaultRuntime } from './runtime.js';
|
|
12
|
-
export { generateDefaultTsDef } from './tsDef.js';
|
|
13
|
-
export { generateDefaultTx } from './tx.js';
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { ModuleTypes } from '../util/imports.js';
|
|
5
|
-
|
|
6
|
-
import Handlebars from 'handlebars';
|
|
7
|
-
|
|
8
|
-
import { Json, Raw } from '@pezkuwi/types/codec';
|
|
9
|
-
import { TypeRegistry } from '@pezkuwi/types/create';
|
|
10
|
-
import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
|
|
11
|
-
import * as defaultPrimitives from '@pezkuwi/types/primitive';
|
|
12
|
-
|
|
13
|
-
import { createImports, readTemplate, setImports, writeFile } from '../util/index.js';
|
|
14
|
-
|
|
15
|
-
const primitiveClasses = {
|
|
16
|
-
...defaultPrimitives,
|
|
17
|
-
Json,
|
|
18
|
-
Raw
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const generateInterfaceTypesTemplate = Handlebars.compile(readTemplate('interfaceRegistry'));
|
|
22
|
-
|
|
23
|
-
/** @internal */
|
|
24
|
-
export function generateInterfaceTypes (importDefinitions: Record<string, Record<string, ModuleTypes>>, dest: string): void {
|
|
25
|
-
const registry = new TypeRegistry();
|
|
26
|
-
|
|
27
|
-
writeFile(dest, (): string => {
|
|
28
|
-
Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {});
|
|
29
|
-
|
|
30
|
-
const imports = createImports(importDefinitions);
|
|
31
|
-
const definitions = imports.definitions;
|
|
32
|
-
const items: string[] = [];
|
|
33
|
-
|
|
34
|
-
// first we create imports for our known classes from the API
|
|
35
|
-
Object
|
|
36
|
-
.keys(primitiveClasses)
|
|
37
|
-
.filter((name) => !name.includes('Generic'))
|
|
38
|
-
.forEach((primitiveName): void => {
|
|
39
|
-
setImports(definitions, imports, [primitiveName]);
|
|
40
|
-
|
|
41
|
-
items.push(primitiveName);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const existingTypes: Record<string, boolean> = {};
|
|
45
|
-
|
|
46
|
-
// ensure we have everything registered since we will get the definition
|
|
47
|
-
// form the available types (so any unknown should show after this)
|
|
48
|
-
Object.values(definitions).forEach(({ types }) => {
|
|
49
|
-
registry.register(types as Record<string, string>);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// create imports for everything that we have available
|
|
53
|
-
Object.values(definitions).forEach(({ types }) => {
|
|
54
|
-
setImports(definitions, imports, Object.keys(types));
|
|
55
|
-
|
|
56
|
-
const uniqueTypes = Object.keys(types).filter((type) => !existingTypes[type]);
|
|
57
|
-
|
|
58
|
-
uniqueTypes.forEach((type): void => {
|
|
59
|
-
existingTypes[type] = true;
|
|
60
|
-
|
|
61
|
-
items.push(type);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return generateInterfaceTypesTemplate({
|
|
66
|
-
headerType: 'defs',
|
|
67
|
-
imports,
|
|
68
|
-
items: items.sort((a, b) => a.localeCompare(b)),
|
|
69
|
-
types: [
|
|
70
|
-
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
71
|
-
file: packagePath,
|
|
72
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
73
|
-
}))
|
|
74
|
-
]
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Generate `packages/types/src/interfaceRegistry.ts`, the registry of all interfaces
|
|
80
|
-
export function generateDefaultInterface (): void {
|
|
81
|
-
generateInterfaceTypes(
|
|
82
|
-
{ '@pezkuwi/types/interfaces': defaultDefinitions },
|
|
83
|
-
'packages/types-augment/src/registry/interfaces.ts'
|
|
84
|
-
);
|
|
85
|
-
}
|
package/src/generate/lookup.ts
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { PortableType, SiLookupTypeId, SiPath, SiTypeParameter } from '@pezkuwi/types/interfaces';
|
|
5
|
-
import type { PortableRegistry } from '@pezkuwi/types/metadata';
|
|
6
|
-
import type { Registry } from '@pezkuwi/types/types';
|
|
7
|
-
import type { TypeDef } from '@pezkuwi/types-create/types';
|
|
8
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
9
|
-
|
|
10
|
-
import Handlebars from 'handlebars';
|
|
11
|
-
import path from 'node:path';
|
|
12
|
-
|
|
13
|
-
import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
|
|
14
|
-
import staticAhDicle from '@pezkuwi/types-support/metadata/v15/asset-hub-dicle-hex';
|
|
15
|
-
import staticAhPezkuwi from '@pezkuwi/types-support/metadata/v15/asset-hub-pezkuwi-hex';
|
|
16
|
-
import staticBizinikiwi from '@pezkuwi/types-support/metadata/v15/bizinikiwi-hex';
|
|
17
|
-
import staticDicle from '@pezkuwi/types-support/metadata/v15/dicle-hex';
|
|
18
|
-
import staticPezkuwi from '@pezkuwi/types-support/metadata/v15/pezkuwi-hex';
|
|
19
|
-
import { isString, stringify } from '@pezkuwi/util';
|
|
20
|
-
|
|
21
|
-
import { createImports, exportInterface, initMeta, readTemplate, rebrandTypeName, type TypeImports, writeFile } from '../util/index.js';
|
|
22
|
-
import { typeEncoders } from './tsDef.js';
|
|
23
|
-
|
|
24
|
-
// Deep rebrand TypeDef including all nested sub types
|
|
25
|
-
// isTopLevel indicates whether this is a top-level type (should set name from lookupName) or a sub type (preserve name)
|
|
26
|
-
function deepRebrandTypeDef (typeDef: TypeDef, isTopLevel = true): TypeDef {
|
|
27
|
-
const rebrandedLookupName = typeDef.lookupName ? rebrandTypeName(typeDef.lookupName) : typeDef.lookupName;
|
|
28
|
-
|
|
29
|
-
const rebranded: TypeDef = {
|
|
30
|
-
...typeDef,
|
|
31
|
-
type: rebrandTypeName(typeDef.type),
|
|
32
|
-
// For top-level types: set name from lookupName (mimics original: typeDef.name = typeDef.lookupName)
|
|
33
|
-
// For sub types (enum variants, struct fields): preserve the original name (field/variant name)
|
|
34
|
-
name: isTopLevel ? (rebrandedLookupName || typeDef.name) : typeDef.name,
|
|
35
|
-
lookupName: rebrandedLookupName,
|
|
36
|
-
lookupNameRoot: typeDef.lookupNameRoot ? rebrandTypeName(typeDef.lookupNameRoot) : typeDef.lookupNameRoot
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// Recursively rebrand sub types (mark as not top-level)
|
|
40
|
-
if (typeDef.sub) {
|
|
41
|
-
if (Array.isArray(typeDef.sub)) {
|
|
42
|
-
rebranded.sub = typeDef.sub.map((s) => deepRebrandTypeDef(s, false));
|
|
43
|
-
} else {
|
|
44
|
-
rebranded.sub = deepRebrandTypeDef(typeDef.sub, false);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return rebranded;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Record<string, >
|
|
52
|
-
interface ParsedDef {
|
|
53
|
-
_set: Record<string, number>;
|
|
54
|
-
|
|
55
|
-
[key: string]: string | Record<string, string> | Record<string, number>;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const WITH_TYPEDEF = false;
|
|
59
|
-
|
|
60
|
-
const generateLookupDefsTmpl = Handlebars.compile(readTemplate('lookup/defs'));
|
|
61
|
-
const generateLookupDefsNamedTmpl = Handlebars.compile(readTemplate('lookup/defs-named'));
|
|
62
|
-
const generateLookupIndexTmpl = Handlebars.compile(readTemplate('lookup/index'));
|
|
63
|
-
const generateLookupTypesTmpl = Handlebars.compile(readTemplate('lookup/types'));
|
|
64
|
-
const generateRegistryTmpl = Handlebars.compile(readTemplate('interfaceRegistry'));
|
|
65
|
-
|
|
66
|
-
function generateParamType (registry: Registry, { name, type }: SiTypeParameter): string {
|
|
67
|
-
if (type.isSome) {
|
|
68
|
-
const link = registry.lookup.types[type.unwrap().toNumber()];
|
|
69
|
-
|
|
70
|
-
if (link.type.path.length) {
|
|
71
|
-
return generateTypeDocs(registry, null, link.type.path, link.type.params);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return name.toString();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function generateTypeDocs (registry: Registry, id: SiLookupTypeId | null, path: SiPath, params: SiTypeParameter[]): string {
|
|
79
|
-
return `${id ? `${registry.createLookupType(id)}${path.length ? ': ' : ''}` : ''}${path.map((p) => p.toString()).join('::')}${params.length ? `<${params.map((p) => generateParamType(registry, p)).join(', ')}>` : ''}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function formatObject (lines: string[]): string[] {
|
|
83
|
-
const max = lines.length - 1;
|
|
84
|
-
|
|
85
|
-
return [
|
|
86
|
-
'{',
|
|
87
|
-
...lines.map((l, index) =>
|
|
88
|
-
(l.endsWith(',') || l.endsWith('{') || index === max || lines[index + 1].endsWith('}') || lines[index + 1].endsWith('}'))
|
|
89
|
-
? l
|
|
90
|
-
: `${l},`
|
|
91
|
-
),
|
|
92
|
-
'}'
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function expandSet (parsed: Record<string, number>): string[] {
|
|
97
|
-
return formatObject(
|
|
98
|
-
Object.entries(parsed).reduce<string[]>((all, [k, v]) => {
|
|
99
|
-
all.push(`${k}: ${v}`);
|
|
100
|
-
|
|
101
|
-
return all;
|
|
102
|
-
}, [])
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function expandObject (parsed: ParsedDef): string[] {
|
|
107
|
-
if (parsed._set) {
|
|
108
|
-
return expandSet(parsed._set);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return formatObject(
|
|
112
|
-
Object.entries(parsed).reduce<string[]>((all, [k, v]) => {
|
|
113
|
-
const inner = isString(v)
|
|
114
|
-
? expandType(v)
|
|
115
|
-
: Array.isArray(v)
|
|
116
|
-
? [`[${(v as string[]).map((e) => `'${e}'`).join(', ')}]`]
|
|
117
|
-
: expandObject(v as ParsedDef);
|
|
118
|
-
|
|
119
|
-
inner.forEach((l, index): void => {
|
|
120
|
-
all.push(`${
|
|
121
|
-
index === 0
|
|
122
|
-
? `${k}: ${l}`
|
|
123
|
-
: `${l}`
|
|
124
|
-
}`);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return all;
|
|
128
|
-
}, [])
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function expandType (encoded: string): string[] {
|
|
133
|
-
if (!encoded.startsWith('{')) {
|
|
134
|
-
return [`'${rebrandTypeName(encoded)}'`];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return expandObject(JSON.parse(encoded) as ParsedDef);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function expandDefToString ({ lookupNameRoot, type }: TypeDef, indent: number): string {
|
|
141
|
-
if (lookupNameRoot) {
|
|
142
|
-
return `'${rebrandTypeName(lookupNameRoot)}'`;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const lines = expandType(type);
|
|
146
|
-
let inc = 0;
|
|
147
|
-
|
|
148
|
-
return lines.map((l, index) => {
|
|
149
|
-
let r: string;
|
|
150
|
-
|
|
151
|
-
if (l.endsWith('{')) {
|
|
152
|
-
r = index === 0
|
|
153
|
-
? l
|
|
154
|
-
: `${' '.padStart(indent + inc)}${l}`;
|
|
155
|
-
inc += 2;
|
|
156
|
-
} else {
|
|
157
|
-
if (l.endsWith('},') || l.endsWith('}')) {
|
|
158
|
-
inc -= 2;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
r = index === 0
|
|
162
|
-
? l
|
|
163
|
-
: `${' '.padStart(indent + inc)}${l}`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return r;
|
|
167
|
-
}).join('\n');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function getFilteredTypes (lookup: PortableRegistry, exclude: string[] = []): [PortableType, TypeDef][] {
|
|
171
|
-
const named = lookup.types.filter(({ id }) => !!lookup.getTypeDef(id).lookupName);
|
|
172
|
-
const names = named.map(({ id }) => lookup.getName(id));
|
|
173
|
-
|
|
174
|
-
return named
|
|
175
|
-
.filter((_, index) =>
|
|
176
|
-
!names.some((n, iindex) =>
|
|
177
|
-
index > iindex &&
|
|
178
|
-
n === names[index]
|
|
179
|
-
)
|
|
180
|
-
)
|
|
181
|
-
.map((p): [PortableType, TypeDef] => [p, lookup.getTypeDef(p.id)])
|
|
182
|
-
.filter(([, typeDef]) => !exclude.includes(typeDef.lookupName || '<invalid>'));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function generateLookupDefs (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath?: string): void {
|
|
186
|
-
writeFile(path.join(destDir, `${subPath || 'definitions'}.ts`), (): string => {
|
|
187
|
-
const all = filtered.map(([{ id, type: { params, path } }, typeDef]) => {
|
|
188
|
-
const typeLookup = registry.createLookupType(id);
|
|
189
|
-
const def = expandDefToString(typeDef, subPath ? 2 : 4);
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
docs: [
|
|
193
|
-
generateTypeDocs(registry, id, path, params),
|
|
194
|
-
WITH_TYPEDEF
|
|
195
|
-
? `@typeDef ${stringify(typeDef)}`
|
|
196
|
-
: null
|
|
197
|
-
].filter((d): d is string => !!d),
|
|
198
|
-
type: { def, typeLookup, typeName: typeDef.lookupName ? rebrandTypeName(typeDef.lookupName) : undefined }
|
|
199
|
-
};
|
|
200
|
-
});
|
|
201
|
-
const max = all.length - 1;
|
|
202
|
-
|
|
203
|
-
return (subPath ? generateLookupDefsNamedTmpl : generateLookupDefsTmpl)({
|
|
204
|
-
defs: all.map(({ docs, type }, i) => {
|
|
205
|
-
const { def, typeLookup, typeName } = type;
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
defs: [
|
|
209
|
-
[typeName || typeLookup, `${def}${i !== max ? ',' : ''}`]
|
|
210
|
-
].map(([n, t]) => `${n}: ${t}`),
|
|
211
|
-
docs
|
|
212
|
-
};
|
|
213
|
-
}),
|
|
214
|
-
headerType: 'defs'
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function generateLookupTypes (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath?: string): void {
|
|
220
|
-
const imports = {
|
|
221
|
-
...createImports(
|
|
222
|
-
{ '@pezkuwi/types/interfaces': defaultDefinitions },
|
|
223
|
-
{ types: {} }
|
|
224
|
-
),
|
|
225
|
-
interfaces: []
|
|
226
|
-
};
|
|
227
|
-
const items = filtered
|
|
228
|
-
.map(([, typeDef]) => {
|
|
229
|
-
// Deep rebrand the type names (including nested sub types) before generating interfaces
|
|
230
|
-
const rebranded = deepRebrandTypeDef(typeDef);
|
|
231
|
-
|
|
232
|
-
return rebranded.lookupNameRoot && rebranded.lookupName
|
|
233
|
-
? exportInterface(rebranded.lookupIndex, rebranded.lookupName, rebranded.lookupNameRoot)
|
|
234
|
-
: typeEncoders[rebranded.info](registry, imports.definitions, rebranded, imports);
|
|
235
|
-
})
|
|
236
|
-
.filter((t): t is string => !!t)
|
|
237
|
-
.map((t) => t.replace(/\nexport /, '\n'));
|
|
238
|
-
|
|
239
|
-
writeFile(path.join(destDir, `types${subPath ? `-${subPath}` : ''}.ts`), () => generateLookupTypesTmpl({
|
|
240
|
-
headerType: 'defs',
|
|
241
|
-
imports,
|
|
242
|
-
items: items.map((l) =>
|
|
243
|
-
l
|
|
244
|
-
.split('\n')
|
|
245
|
-
.map((l) => l.length ? ` ${l}` : '')
|
|
246
|
-
.join('\n')
|
|
247
|
-
),
|
|
248
|
-
types: [
|
|
249
|
-
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
250
|
-
file: packagePath,
|
|
251
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
252
|
-
}))
|
|
253
|
-
]
|
|
254
|
-
}), true);
|
|
255
|
-
writeFile(path.join(destDir, 'index.ts'), () => generateLookupIndexTmpl({ headerType: 'defs' }), true);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function generateRegistry (_registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath: string): void {
|
|
259
|
-
writeFile(path.join(destDir, `${subPath}.ts`), (): string => {
|
|
260
|
-
const items = filtered
|
|
261
|
-
.map(([, { lookupName }]) => lookupName ? rebrandTypeName(lookupName) : lookupName)
|
|
262
|
-
.filter((n): n is string => !!n)
|
|
263
|
-
.sort()
|
|
264
|
-
.reduce((all: string[], n) => all.includes(n) ? all : all.concat(n), []);
|
|
265
|
-
const imports = createImports({}, { types: {} });
|
|
266
|
-
|
|
267
|
-
imports.lookupTypes = items.reduce((all, n) => ({ ...all, [n]: true }), {});
|
|
268
|
-
|
|
269
|
-
return generateRegistryTmpl({
|
|
270
|
-
headerType: 'defs',
|
|
271
|
-
imports,
|
|
272
|
-
items,
|
|
273
|
-
types: []
|
|
274
|
-
});
|
|
275
|
-
}, true);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function generateLookup (destDir: string, entries: [string, HexString][]): void {
|
|
279
|
-
entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
|
|
280
|
-
const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
|
|
281
|
-
const filtered = getFilteredTypes(lookup, exclude);
|
|
282
|
-
|
|
283
|
-
generateLookupDefs(registry, filtered, destDir, subPath);
|
|
284
|
-
generateLookupTypes(registry, filtered, destDir, subPath);
|
|
285
|
-
generateRegistry(registry, filtered, destDir, subPath === 'lookup' ? 'registry' : `../registry/${subPath}`);
|
|
286
|
-
|
|
287
|
-
return exclude.concat(
|
|
288
|
-
...filtered
|
|
289
|
-
.map(([, typeDef]) => typeDef.lookupName)
|
|
290
|
-
.filter((n): n is string => !!n)
|
|
291
|
-
);
|
|
292
|
-
}, []);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Generate `packages/types/src/lookup/*s`, the registry of all lookup types
|
|
296
|
-
export function generateDefaultLookup (destDir = 'packages/types-augment/src/lookup', staticData?: HexString): void {
|
|
297
|
-
generateLookup(
|
|
298
|
-
destDir,
|
|
299
|
-
staticData
|
|
300
|
-
? [['lookup', staticData]]
|
|
301
|
-
: [
|
|
302
|
-
['bizinikiwi', staticBizinikiwi],
|
|
303
|
-
['pezkuwi', staticPezkuwi],
|
|
304
|
-
['dicle', staticDicle],
|
|
305
|
-
['assetHubPezkuwi', staticAhPezkuwi],
|
|
306
|
-
['assetHubDicle', staticAhDicle]
|
|
307
|
-
]
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Based on a list of types, it filters out the lookup types that are not needed.
|
|
312
|
-
export function ignoreUnusedLookups (usedTypes: string[], imports: TypeImports) {
|
|
313
|
-
const usedStringified = usedTypes.toString();
|
|
314
|
-
|
|
315
|
-
const [lookupKey, typeDefinitions] = Object.entries(imports.localTypes).find(([typeModule, _]) => typeModule.includes('/lookup')) || ['', {}];
|
|
316
|
-
|
|
317
|
-
Object.keys(typeDefinitions).forEach((typeDef) => {
|
|
318
|
-
if (!(usedStringified.includes(typeDef))) {
|
|
319
|
-
delete (imports.localTypes[lookupKey])[typeDef];
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|