Split generation scripts into @polkadot/typegen (#1875)
* Split generation scripts into @polkadot/typegen * Remove moved files * CC overrides * interfaces typo * Cleanup imports * Some import combinations * Updates * Generation updates * Cleanups, split js wrapper & ts logic * Rename jiggle 1 * Rename jiggle 2 * Style cleanups * Expose enry function for scripts * Typo * Update script copy & include locations * CC exclude location * Minor adjustments * argv parsing into main
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,3 @@
|
||||
# @polkadot/typegen
|
||||
|
||||
A collection of type generation scripts, allowing the input of metadata and definitions for the creation of TS outputs.
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "1.3.0-beta.5",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"polkadot-types-chain-info": "./scripts/polkadot-types-chain-info.js",
|
||||
"polkadot-types-from-chain": "./scripts/polkadot-types-from-chain.js",
|
||||
"polkadot-types-from-defs": "./scripts/polkadot-types-from-defs.js",
|
||||
"polkadot-types-internal-interfaces": "./scripts/polkadot-types-internal-interfaces.js",
|
||||
"polkadot-types-internal-metadata": "./scripts/polkadot-types-internal-metadata.js"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/polkadot-js/api.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Polkadot",
|
||||
"JsonRPC"
|
||||
],
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [
|
||||
"Jaco Greeff <jacogr@gmail.com>"
|
||||
],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/polkadot-js/api/issues"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.8.3",
|
||||
"@babel/register": "^7.8.3",
|
||||
"@babel/runtime": "^7.8.4",
|
||||
"@polkadot/api": "^1.3.0-beta.5",
|
||||
"@polkadot/jsonrpc": "^1.3.0-beta.5",
|
||||
"@polkadot/metadata": "^1.3.0-beta.5",
|
||||
"@polkadot/types": "^1.3.0-beta.5",
|
||||
"@polkadot/util": "^2.3.1",
|
||||
"websocket": "^1.0.31",
|
||||
"yargs": "^15.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/yargs": "^15.0.3"
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
let main;
|
||||
|
||||
try {
|
||||
main = require('../extractChain').default;
|
||||
} catch (error) {
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/api-derive(.*)': './packages/api-derive/src\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/api(.*)': './packages/api/src/\\1',
|
||||
'^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1',
|
||||
'^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1',
|
||||
'^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
main = require('../src/extractChain.ts').default;
|
||||
}
|
||||
|
||||
main();
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
let main;
|
||||
|
||||
try {
|
||||
main = require('../fromChain').default;
|
||||
} catch (error) {
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
main = require('../src/fromChain').default;
|
||||
}
|
||||
|
||||
main();
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
let main;
|
||||
|
||||
try {
|
||||
main = require('../fromDefs').default;
|
||||
} catch (error) {
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/typegen(.*)': './packages/typegen/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
main = require('../sr/fromDefs.ts').default;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
let main;
|
||||
|
||||
try {
|
||||
main = require('../interfacesTs').default;
|
||||
} catch (error) {
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
main = require('../src/interfacesTs.ts').default;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
let main;
|
||||
|
||||
try {
|
||||
main = require('../metadataMd').default;
|
||||
} catch (error) {
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
main = require('../src/metadataMd.ts').default;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -9,21 +9,8 @@ import process from 'process';
|
||||
import yargs from 'yargs';
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api/index';
|
||||
|
||||
// retrieve and parse arguments - we do this globally, since this is a single command
|
||||
const { argv: { ws } } = yargs
|
||||
.usage('Usage: [options]')
|
||||
.wrap(120)
|
||||
.options({
|
||||
ws: {
|
||||
default: 'ws://127.0.0.1:9944',
|
||||
description: 'The API endpoint to connect to, e.g. wss://poc3-rpc.polkadot.io',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
/** @internal */
|
||||
async function main (): Promise<void> {
|
||||
async function run (ws: string): Promise<void> {
|
||||
const provider = new WsProvider(ws);
|
||||
const api = await ApiPromise.create({ provider });
|
||||
const [chain, props] = await Promise.all([
|
||||
@@ -38,11 +25,26 @@ async function main (): Promise<void> {
|
||||
api.runtimeMetadata.getUniqTypes(false);
|
||||
}
|
||||
|
||||
main()
|
||||
.then((): void => {
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
console.error('FATAL:', error.message);
|
||||
process.exit(-1);
|
||||
});
|
||||
export default function main (): void {
|
||||
// retrieve and parse arguments - we do this globally, since this is a single command
|
||||
const { ws } = yargs
|
||||
.usage('Usage: [options]')
|
||||
.wrap(120)
|
||||
.options({
|
||||
ws: {
|
||||
default: 'ws://127.0.0.1:9944',
|
||||
description: 'The API endpoint to connect to, e.g. wss://poc3-rpc.polkadot.io',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
}).argv;
|
||||
|
||||
run(ws)
|
||||
.then((): void => {
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
console.error('FATAL:', error.message);
|
||||
process.exit(-1);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import generateConst from './generate/consts';
|
||||
import generateQuery from './generate/query';
|
||||
import generateTx from './generate/tx';
|
||||
|
||||
if (typeof WebSocket === 'undefined') {
|
||||
(global as any).WebSocket = require('websocket').w3cwebsocket;
|
||||
}
|
||||
|
||||
let websocket: any = null;
|
||||
|
||||
function generate (metaHex: string, pkg: string | undefined, output: string, isStrict?: boolean): void {
|
||||
console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
|
||||
|
||||
const extraTypes = pkg
|
||||
? { [pkg]: require(path.join(process.cwd(), output, 'definitions')) }
|
||||
: {};
|
||||
|
||||
generateConst(path.join(process.cwd(), output, 'augment.consts.ts'), metaHex, extraTypes, isStrict);
|
||||
generateQuery(path.join(process.cwd(), output, 'augment.query.ts'), metaHex, extraTypes, isStrict);
|
||||
generateTx(path.join(process.cwd(), output, 'augment.tx.ts'), metaHex, extraTypes, isStrict);
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function onSocketClose (event: any): void {
|
||||
console.error(`disconnected, code: '${event.code}' reason: '${event.reason}'`);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function onSocketError (event: any): void {
|
||||
console.error(event);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function onSocketOpen (): boolean {
|
||||
console.log('connected');
|
||||
|
||||
websocket.send('{"id":"1","jsonrpc":"2.0","method":"state_getMetadata","params":[]}');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default function main (): void {
|
||||
const { endpoint, output, package: pkg, strict: isStrict } = yargs.strict().options({
|
||||
endpoint: {
|
||||
description: 'The endpoint to connect to, e.g. wss://kusama-rpc.polkadot.io or relative file to JSON output',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
output: {
|
||||
description: 'The target directory to write the data to',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
package: {
|
||||
description: 'Optional package in output location (for extra definitions)',
|
||||
type: 'string'
|
||||
},
|
||||
strict: {
|
||||
description: 'Turns on stirct mode, not outputting genric versions',
|
||||
type: 'boolean'
|
||||
}
|
||||
}).argv;
|
||||
|
||||
if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
|
||||
websocket = new WebSocket(endpoint);
|
||||
websocket.onclose = onSocketClose;
|
||||
websocket.onerror = onSocketError;
|
||||
websocket.onopen = onSocketOpen;
|
||||
websocket.onmessage = (message: any): void => {
|
||||
generate(JSON.parse(message.data).result, pkg, output, isStrict);
|
||||
};
|
||||
} else {
|
||||
generate(require(path.join(process.cwd(), endpoint)).result, pkg, output, isStrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import * as substrateDefs from '@polkadot/types/interfaces/definitions';
|
||||
|
||||
import { generateInterfaceRegistry } from './generate/interfaceRegistry';
|
||||
import { generateTsDef } from './generate/tsDef';
|
||||
|
||||
export default function main (): void {
|
||||
const { input, package: pkg } = yargs.strict().options({
|
||||
input: {
|
||||
description: 'The directory to use for the user definitions',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
package: {
|
||||
description: 'The package name & path to use for the user types',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
}).argv;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const userDefs = require(path.join(process.cwd(), input, 'definitions.ts'));
|
||||
const userKeys = Object.keys(userDefs);
|
||||
const filteredBase = Object
|
||||
.entries(substrateDefs)
|
||||
.filter(([key]) => {
|
||||
if (userKeys.includes(key)) {
|
||||
console.warn(`Override found for ${key} in user types, ignoring in @polkadot/types`);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.reduce((defs: any, [key, value]) => {
|
||||
defs[key] = value;
|
||||
|
||||
return defs;
|
||||
}, {});
|
||||
|
||||
const allDefs = {
|
||||
'@polkadot/types/interfaces': filteredBase,
|
||||
[pkg]: userDefs
|
||||
};
|
||||
|
||||
generateTsDef(allDefs, path.join(process.cwd(), input), pkg);
|
||||
generateInterfaceRegistry(allDefs, path.join(process.cwd(), input, 'interfaceRegistry.ts'));
|
||||
}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ModuleMetadataLatest } from '../../interfaces/metadata';
|
||||
import * as defaultDefs from '../../interfaces/definitions';
|
||||
import { ModuleMetadataLatest } from '@polkadot/types/interfaces/metadata';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
|
||||
import staticData from '@polkadot/metadata/Metadata/static';
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { FOOTER, HEADER, TypeImports, createDocComments, createImportCode, createImports, indent, setImports, writeFile } from '../util';
|
||||
|
||||
// Generate types for one module
|
||||
+5
-4
@@ -1,10 +1,11 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Raw from '../../codec/Raw';
|
||||
import * as defaultDefinitions from '../../interfaces/definitions';
|
||||
import * as defaultPrimitives from '../../primitive';
|
||||
import Raw from '@polkadot/types/codec/Raw';
|
||||
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
|
||||
import * as defaultPrimitives from '@polkadot/types/primitive';
|
||||
|
||||
import { FOOTER, HEADER, createImportCode, createImports, getDerivedTypes, indent, setImports, writeFile } from '../util';
|
||||
|
||||
const primitiveClasses = {
|
||||
+5
-5
@@ -1,16 +1,16 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ModuleMetadataLatest, StorageEntryMetadataLatest } from '../../interfaces/metadata';
|
||||
import { Registry } from '../../types';
|
||||
import * as defaultDefs from '../../interfaces/definitions';
|
||||
import { ModuleMetadataLatest, StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
|
||||
import staticData from '@polkadot/metadata/Metadata/static';
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { stringLowerFirst } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { FOOTER, HEADER, TypeImports, createDocComments, createImportCode, createImports, formatType, getSimilarTypes, indent, setImports, writeFile } from '../util';
|
||||
|
||||
// If the StorageEntry returns T, output `Option<T>` if the modifier is optional
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import interfaces from '@polkadot/jsonrpc';
|
||||
import * as definitions from '../../interfaces/definitions';
|
||||
import { TypeRegistry } from '../../create';
|
||||
import * as definitions from '@polkadot/types/interfaces/definitions';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
|
||||
import { FOOTER, HEADER, createDocComments, createImportCode, createImports, getSimilarTypes, setImports, writeFile, indent } from '../util';
|
||||
|
||||
/** @internal */
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../../create/types';
|
||||
import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '@polkadot/types/create/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { getTypeDef } from '@polkadot/types/create';
|
||||
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
|
||||
import { isString, stringCamelCase, stringUpperFirst } from '@polkadot/util';
|
||||
|
||||
import { getTypeDef } from '../../create';
|
||||
import * as defaultDefinitions from '../../interfaces/definitions';
|
||||
import { FOOTER, HEADER, TypeImports, createImportCode, createImports, exportInterface, exportType, formatType, setImports, writeFile } from '../util';
|
||||
|
||||
interface Imports extends TypeImports {
|
||||
@@ -1,17 +1,17 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ModuleMetadataLatest } from '../../interfaces/metadata';
|
||||
import * as defaultDefs from '../../interfaces/definitions';
|
||||
import { Registry } from '../../types';
|
||||
import { ModuleMetadataLatest } from '@polkadot/types/interfaces/metadata';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import staticData from '@polkadot/metadata/Metadata/static';
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import { Text } from '@polkadot/types';
|
||||
import { Text } from '@polkadot/types/primitive';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { FOOTER, HEADER, TypeImports, createDocComments, createImportCode, createImports, formatType, getSimilarTypes, indent, setImports, writeFile } from '../util';
|
||||
|
||||
const MAPPED_NAMES: Record<string, string> = {
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { formatType } from './util/formatting';
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -9,11 +9,13 @@ import generateRpcTypes from './generate/rpc';
|
||||
import generateTsDef from './generate/tsDef';
|
||||
import generateTxTypes from './generate/tx';
|
||||
|
||||
generateInterfaceRegistry();
|
||||
export default function main (): void {
|
||||
generateInterfaceRegistry();
|
||||
|
||||
generateConstsTypes();
|
||||
generateQueryTypes();
|
||||
generateTxTypes();
|
||||
generateRpcTypes();
|
||||
generateConstsTypes();
|
||||
generateQueryTypes();
|
||||
generateTxTypes();
|
||||
generateRpcTypes();
|
||||
|
||||
generateTsDef();
|
||||
generateTsDef();
|
||||
}
|
||||
@@ -1,20 +1,32 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { MetadataLatest, ModuleMetadataLatest } from '../interfaces/metadata';
|
||||
import { MetadataLatest } from '@polkadot/types/interfaces/metadata';
|
||||
|
||||
import fs from 'fs';
|
||||
import interfaces from '@polkadot/jsonrpc';
|
||||
import Decorated from '@polkadot/metadata/Decorated';
|
||||
import rpcdata from '@polkadot/metadata/Metadata/static';
|
||||
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import Call from '@polkadot/types/primitive/Generic/Call';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { Vec } from '@polkadot/types/codec';
|
||||
import { Text } from '@polkadot/types/primitive';
|
||||
import { stringCamelCase, stringLowerFirst } from '@polkadot/util';
|
||||
|
||||
import { unwrapStorageType } from '../primitive/StorageKey';
|
||||
import Call from '../primitive/Generic/Call';
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Vec } from '../codec';
|
||||
import { Text } from '../primitive';
|
||||
interface Page {
|
||||
title: string;
|
||||
description: string;
|
||||
sections: {
|
||||
name: string;
|
||||
description?: string;
|
||||
items: {
|
||||
name: string;
|
||||
[bullet: string]: string | Vec<Text>;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
|
||||
const STATIC_TEXT = '\n\n(NOTE: These were generated from a static/snapshot view of a recent Substrate master node. Some items may not be available in older nodes, or in any customized implementations.)';
|
||||
|
||||
@@ -28,10 +40,12 @@ const DESC_STORAGE = `The following sections contain Storage methods are part of
|
||||
/** @internal */
|
||||
function documentationVecToMarkdown (docLines: Vec<Text>, indent = 0): string {
|
||||
const md = docLines
|
||||
.map(docLine => docLine && docLine.substring(1)) // trim the leading space
|
||||
.map((docLine) => docLine && docLine.substring(1)) // trim the leading space
|
||||
.reduce((md, docLine): string => // generate paragraphs
|
||||
!docLine.trim().length ? `${md}\n\n` // empty line
|
||||
: /^[*-]/.test(docLine.trimStart()) && !md.endsWith('\n\n') ? `${md}\n\n${docLine}` // line calling for a preceding linebreak
|
||||
!docLine.trim().length
|
||||
? `${md}\n\n` // empty line
|
||||
: /^[*-]/.test(docLine.trimStart()) && !md.endsWith('\n\n')
|
||||
? `${md}\n\n${docLine}` // line calling for a preceding linebreak
|
||||
: `${md}${docLine // line continuing the preceding line
|
||||
.replace(/^# <weight>$/g, '\\# \\<weight>\n\n')
|
||||
.replace(/^# <\/weight>$/g, '\n\n\\# \\</weight>')
|
||||
@@ -41,19 +55,6 @@ function documentationVecToMarkdown (docLines: Vec<Text>, indent = 0): string {
|
||||
return md && md.split('\n\n').map(line => `${' '.repeat(indent)}${line}`).join('\n\n');
|
||||
}
|
||||
|
||||
interface Page {
|
||||
title: string;
|
||||
description: string;
|
||||
sections: {
|
||||
name: string;
|
||||
description?: string;
|
||||
items: {
|
||||
name: string;
|
||||
[bullet: string]: string | Vec<Text>;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
|
||||
function renderPage (page: Page): string {
|
||||
let md = `## ${page.title}\n\n`;
|
||||
|
||||
@@ -85,16 +86,9 @@ function renderPage (page: Page): string {
|
||||
return md;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort object by their `.name`
|
||||
*/
|
||||
/** @internal */
|
||||
function sortByName<T extends { name: any }> (a: T, b: T): number {
|
||||
// ignore upper and lowercase
|
||||
const nameA = a.name.toString().toUpperCase();
|
||||
const nameB = b.name.toString().toUpperCase();
|
||||
|
||||
return nameA.localeCompare(nameB);
|
||||
// case insensitive (all-uppercase) sorting
|
||||
return a.name.toString().toUpperCase().localeCompare(b.name.toString().toUpperCase());
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -102,28 +96,32 @@ function addRpc (): string {
|
||||
return renderPage({
|
||||
title: 'JSON-RPC',
|
||||
description: DESC_RPC,
|
||||
sections: Object.keys(interfaces).sort().map(sectionName => {
|
||||
const section = interfaces[sectionName];
|
||||
sections: Object.keys(interfaces)
|
||||
.sort()
|
||||
.map((sectionName) => {
|
||||
const section = interfaces[sectionName];
|
||||
|
||||
return {
|
||||
name: sectionName,
|
||||
description: section.description,
|
||||
items: Object.keys(section.methods).sort().map(methodName => {
|
||||
const method = section.methods[methodName];
|
||||
const args = method.params.map(({ name, isOptional, type }): string => {
|
||||
return name + (isOptional ? '?' : '') + ': `' + type + '`';
|
||||
}).join(', ');
|
||||
const type = '`' + method.type + '`';
|
||||
return {
|
||||
name: sectionName,
|
||||
description: section.description,
|
||||
items: Object.keys(section.methods)
|
||||
.sort()
|
||||
.map((methodName) => {
|
||||
const method = section.methods[methodName];
|
||||
const args = method.params.map(({ name, isOptional, type }): string => {
|
||||
return name + (isOptional ? '?' : '') + ': `' + type + '`';
|
||||
}).join(', ');
|
||||
const type = '`' + method.type + '`';
|
||||
|
||||
return {
|
||||
name: `${methodName}(${args}): ${type}`,
|
||||
jsonrpc: `${sectionName}_${methodName}`,
|
||||
interface: `api.rpc.${sectionName}.${methodName}`,
|
||||
...(method.description && { summary: method.description })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
return {
|
||||
name: `${methodName}(${args}): ${type}`,
|
||||
jsonrpc: `${sectionName}_${methodName}`,
|
||||
interface: `api.rpc.${sectionName}.${methodName}`,
|
||||
...(method.description && { summary: method.description })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,56 +130,61 @@ function addConstants (metadata: MetadataLatest): string {
|
||||
return renderPage({
|
||||
title: 'Constants',
|
||||
description: DESC_CONSTANTS,
|
||||
sections: metadata.modules.sort(sortByName).filter(moduleMetadata => !moduleMetadata.constants.isEmpty).map(moduleMetadata => {
|
||||
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
|
||||
sections: metadata.modules
|
||||
.sort(sortByName)
|
||||
.filter((moduleMetadata) => !moduleMetadata.constants.isEmpty)
|
||||
.map((moduleMetadata) => {
|
||||
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
|
||||
|
||||
return {
|
||||
name: sectionName,
|
||||
items: moduleMetadata.constants.sort(sortByName).map(func => {
|
||||
const methodName = stringCamelCase(func.name.toString());
|
||||
return {
|
||||
name: sectionName,
|
||||
items: moduleMetadata.constants
|
||||
.sort(sortByName)
|
||||
.map((func) => {
|
||||
const methodName = stringCamelCase(func.name.toString());
|
||||
|
||||
return {
|
||||
name: `${methodName}: ` + '`' + func.type + '`',
|
||||
interface: `api.consts.${sectionName}.${methodName}`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
return {
|
||||
name: `${methodName}: ` + '`' + func.type + '`',
|
||||
interface: `api.consts.${sectionName}.${methodName}`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function addStorage (metadata: MetadataLatest): string {
|
||||
const moduleSections = metadata.modules.sort(sortByName)
|
||||
.filter(moduleMetadata => !moduleMetadata.storage.isNone)
|
||||
.map(moduleMetadata => {
|
||||
const moduleSections = metadata.modules
|
||||
.sort(sortByName)
|
||||
.filter((moduleMetadata) => !moduleMetadata.storage.isNone)
|
||||
.map((moduleMetadata) => {
|
||||
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
|
||||
|
||||
return {
|
||||
name: sectionName,
|
||||
items: moduleMetadata.storage.unwrap().items.sort(sortByName).map(func => {
|
||||
const arg =
|
||||
func.type.isMap
|
||||
items: moduleMetadata.storage.unwrap().items
|
||||
.sort(sortByName)
|
||||
.map((func) => {
|
||||
const arg = func.type.isMap
|
||||
? ('`' + func.type.asMap.key.toString() + '`')
|
||||
: func.type.isDoubleMap
|
||||
? ('`' + func.type.asDoubleMap.key1.toString() + ', ' + func.type.asDoubleMap.key2.toString() + '`')
|
||||
: '';
|
||||
const methodName = stringLowerFirst(func.name.toString());
|
||||
let result = unwrapStorageType(func.type);
|
||||
|
||||
const methodName = stringLowerFirst(func.name.toString());
|
||||
if (func.modifier.isOptional) {
|
||||
result = `Option<${result}>`;
|
||||
}
|
||||
|
||||
let result = unwrapStorageType(func.type);
|
||||
|
||||
if (func.modifier.isOptional) {
|
||||
result = `Option<${result}>`;
|
||||
}
|
||||
|
||||
return {
|
||||
name: `${methodName}(${arg}): ` + '`' + result + '`',
|
||||
interface: `api.query.${sectionName}.${methodName}`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
return {
|
||||
name: `${methodName}(${arg}): ` + '`' + result + '`',
|
||||
interface: `api.query.${sectionName}.${methodName}`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
@@ -200,23 +203,28 @@ function addExtrinsics (metadata: MetadataLatest): string {
|
||||
return renderPage({
|
||||
title: 'Extrinsics',
|
||||
description: DESC_EXTRINSICS,
|
||||
sections: metadata.modules.map((i): ModuleMetadataLatest => i).sort(sortByName).filter(meta => !meta.calls.isNone && meta.calls.unwrap().length).map(meta => {
|
||||
const sectionName = stringCamelCase(meta.name.toString());
|
||||
sections: metadata.modules
|
||||
.sort(sortByName)
|
||||
.filter((meta) => !meta.calls.isNone && meta.calls.unwrap().length)
|
||||
.map((meta) => {
|
||||
const sectionName = stringCamelCase(meta.name.toString());
|
||||
|
||||
return {
|
||||
name: sectionName,
|
||||
items: meta.calls.unwrap().sort(sortByName).map(func => {
|
||||
const methodName = stringCamelCase(func.name.toString());
|
||||
const args = Call.filterOrigin(func).map(({ name, type }): string => `${name}: ` + '`' + type + '`').join(', ');
|
||||
return {
|
||||
name: sectionName,
|
||||
items: meta.calls.unwrap()
|
||||
.sort(sortByName)
|
||||
.map((func) => {
|
||||
const methodName = stringCamelCase(func.name.toString());
|
||||
const args = Call.filterOrigin(func).map(({ name, type }): string => `${name}: ` + '`' + type + '`').join(', ');
|
||||
|
||||
return {
|
||||
name: `${methodName}(${args})`,
|
||||
interface: `api.tx.${sectionName}.${methodName}`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
return {
|
||||
name: `${methodName}(${args})`,
|
||||
interface: `api.tx.${sectionName}.${methodName}`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -225,22 +233,23 @@ function addEvents (metadata: MetadataLatest): string {
|
||||
return renderPage({
|
||||
title: 'Events',
|
||||
description: DESC_EVENTS,
|
||||
sections: metadata.modules.sort(sortByName).filter(meta => !meta.events.isNone && meta.events.unwrap().length).map(meta => {
|
||||
const sectionName = stringCamelCase(meta.name.toString());
|
||||
sections: metadata.modules
|
||||
.sort(sortByName)
|
||||
.filter((meta) => !meta.events.isNone && meta.events.unwrap().length)
|
||||
.map((meta) => ({
|
||||
name: stringCamelCase(meta.name.toString()),
|
||||
items: meta.events.unwrap()
|
||||
.sort(sortByName)
|
||||
.map((func) => {
|
||||
const methodName = func.name.toString();
|
||||
const args = func.args.map((type): string => '`' + type + '`').join(', ');
|
||||
|
||||
return {
|
||||
name: sectionName,
|
||||
items: meta.events.unwrap().sort(sortByName).map(func => {
|
||||
const methodName = func.name.toString();
|
||||
const args = func.args.map((type): string => '`' + type + '`').join(', ');
|
||||
|
||||
return {
|
||||
name: `${methodName}(${args})`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
return {
|
||||
name: `${methodName}(${args})`,
|
||||
...(func.documentation.length && { summary: func.documentation })
|
||||
};
|
||||
})
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
@@ -249,19 +258,18 @@ function addErrors (metadata: MetadataLatest): string {
|
||||
return renderPage({
|
||||
title: 'Errors',
|
||||
description: DESC_ERRORS,
|
||||
sections: metadata.modules.sort(sortByName).filter(moduleMetadata => !moduleMetadata.errors.isEmpty).map(moduleMetadata => {
|
||||
const sectionName = stringLowerFirst(moduleMetadata.name.toString());
|
||||
|
||||
return {
|
||||
name: sectionName,
|
||||
items: moduleMetadata.errors.sort(sortByName).map(error => {
|
||||
return {
|
||||
sections: metadata.modules
|
||||
.sort(sortByName)
|
||||
.filter((moduleMetadata) => !moduleMetadata.errors.isEmpty)
|
||||
.map((moduleMetadata) => ({
|
||||
name: stringLowerFirst(moduleMetadata.name.toString()),
|
||||
items: moduleMetadata.errors
|
||||
.sort(sortByName)
|
||||
.map((error) => ({
|
||||
name: error.name.toString(),
|
||||
...(error.documentation.length && { summary: error.documentation })
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
}))
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
@@ -281,43 +289,14 @@ function writeFile (name: string, ...chunks: any[]): void {
|
||||
writeStream.end();
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToRpcMd (): void {
|
||||
export default function main (): void {
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Decorated(registry, rpcdata).metadata.asLatest;
|
||||
|
||||
writeFile('docs/substrate/rpc.md', addRpc());
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToConstantsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/constants.md', addConstants(metadata));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToStorageMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/storage.md', addStorage(metadata));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToExtrinsicsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/extrinsics.md', addExtrinsics(metadata));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToEventsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/events.md', addEvents(metadata));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function writeToErrorsMd (metadata: MetadataLatest): void {
|
||||
writeFile('docs/substrate/errors.md', addErrors(metadata));
|
||||
}
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const decorated = new Decorated(registry, rpcdata);
|
||||
const latest = decorated.metadata.asLatest;
|
||||
|
||||
writeToRpcMd();
|
||||
writeToConstantsMd(latest);
|
||||
writeToStorageMd(latest);
|
||||
writeToExtrinsicsMd(latest);
|
||||
writeToEventsMd(latest);
|
||||
writeToErrorsMd(latest);
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Constructor } from '../../types';
|
||||
import { Constructor } from '@polkadot/types/types';
|
||||
|
||||
import UInt from '../../codec/UInt';
|
||||
import UInt from '@polkadot/types/codec/UInt';
|
||||
|
||||
// See if a class is child of another class
|
||||
// FIMXE This could go in util some day
|
||||
@@ -2,23 +2,24 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeDef, TypeDefInfo } from '../../create/types';
|
||||
import { Constructor, Registry } from '../../types';
|
||||
import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
|
||||
import { Constructor, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { stringLowerFirst } from '@polkadot/util';
|
||||
import { isChildClass, isCompactEncodable } from './class';
|
||||
import { ClassOf, ClassOfUnsafe, getTypeDef } from '../../create';
|
||||
import AbstractInt from '../../codec/AbstractInt';
|
||||
import Compact from '../../codec/Compact';
|
||||
import Enum from '../../codec/Enum';
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vec from '../../codec/Vec';
|
||||
import GenericAccountId from '../../primitive/Generic/AccountId';
|
||||
import GenericAddress from '../../primitive/Generic/Address';
|
||||
import Vote, { convictionNames as _voteConvictions } from '../../primitive/Generic/Vote';
|
||||
import Null from '../../primitive/Null';
|
||||
import * as primitiveClasses from '../../primitive';
|
||||
import { ClassOf, ClassOfUnsafe, getTypeDef } from '@polkadot/types/create';
|
||||
import AbstractInt from '@polkadot/types/codec/AbstractInt';
|
||||
import Compact from '@polkadot/types/codec/Compact';
|
||||
import Enum from '@polkadot/types/codec/Enum';
|
||||
import Option from '@polkadot/types/codec/Option';
|
||||
import Struct from '@polkadot/types/codec/Struct';
|
||||
import Vec from '@polkadot/types/codec/Vec';
|
||||
import GenericAccountId from '@polkadot/types/primitive/Generic/AccountId';
|
||||
import GenericAddress from '@polkadot/types/primitive/Generic/Address';
|
||||
import Vote, { convictionNames as _voteConvictions } from '@polkadot/types/primitive/Generic/Vote';
|
||||
import Null from '@polkadot/types/primitive/Null';
|
||||
import * as primitiveClasses from '@polkadot/types/primitive';
|
||||
|
||||
import { formatType } from './formatting';
|
||||
import { setImports, TypeImports } from './imports';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../../create/types';
|
||||
import { TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '@polkadot/types/create/types';
|
||||
|
||||
import { getTypeDef } from '@polkadot/types/create';
|
||||
import { paramsNotation } from '@polkadot/types/codec/utils';
|
||||
|
||||
import { getTypeDef } from '../../create';
|
||||
import { paramsNotation } from '../../codec/utils';
|
||||
import { setImports, TypeImports } from './imports';
|
||||
|
||||
export const HEADER = '// Auto-generated via `yarn polkadot-types-from-defs`, do not edit\n/* eslint-disable @typescript-eslint/no-empty-interface */\n\n';
|
||||
@@ -1,12 +1,12 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeDefInfo } from '../../create/types';
|
||||
import { TypeDefInfo } from '@polkadot/types/create/types';
|
||||
|
||||
import * as codecClasses from '../../codec';
|
||||
import { getTypeDef } from '../../create';
|
||||
import * as primitiveClasses from '../../primitive';
|
||||
import * as codecClasses from '@polkadot/types/codec';
|
||||
import { getTypeDef } from '@polkadot/types/create';
|
||||
import * as primitiveClasses from '@polkadot/types/primitive';
|
||||
|
||||
// these map all the codec and primitive types for import, see the TypeImports below. If
|
||||
// we have an unseen type, it is `undefined`/`false`, if we need to import it, it is `true`
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
"version": "1.3.0-beta.5",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"polkadot-types-from-chain": "./scripts/polkadot-types-from-chain.js",
|
||||
"polkadot-types-from-defs": "./scripts/polkadot-types-from-defs.js"
|
||||
},
|
||||
"keywords": [
|
||||
"Polkadot",
|
||||
"JsonRPC"
|
||||
@@ -30,23 +26,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.8.4",
|
||||
"@babel/register": "^7.8.3",
|
||||
"@babel/runtime": "^7.8.4",
|
||||
"@polkadot/api": "^1.3.0-beta.5",
|
||||
"@polkadot/metadata": "^1.3.0-beta.5",
|
||||
"@polkadot/util": "^2.3.1",
|
||||
"@polkadot/util-crypto": "^2.3.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^5.1.1",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.5.4",
|
||||
"websocket": "^1.0.31",
|
||||
"yargs": "^15.1.0"
|
||||
"rxjs": "^6.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.3.1",
|
||||
"@types/memoizee": "^0.4.3",
|
||||
"@types/yargs": "^15.0.3"
|
||||
"@types/memoizee": "^0.4.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,3 @@ try {
|
||||
export * from './codec';
|
||||
export * from './create';
|
||||
export * from './index.types';
|
||||
|
||||
// FIXME We actually don't want to do this (if needed, it certainly is not in the right place)
|
||||
export { formatType } from './scripts/util/formatting';
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
require('./MetadataMd.ts');
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/api-derive(.*)': './packages/api-derive/src\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/api(.*)': './packages/api/src/\\1',
|
||||
'^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1',
|
||||
'^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1',
|
||||
'^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
require('./extractChain.ts');
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/jsonrpc(.*)': './packages/jsonrpc/src\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
require('./interfacesTs.ts');
|
||||
@@ -1,97 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
if (typeof WebSocket === 'undefined') {
|
||||
global.WebSocket = require('websocket').w3cwebsocket;
|
||||
}
|
||||
|
||||
const path = require('path');
|
||||
const yargs = require('yargs');
|
||||
const { formatNumber } = require('@polkadot/util');
|
||||
const generateConst = require('./generate/consts').default;
|
||||
const generateQuery = require('./generate/query').default;
|
||||
const generateTx = require('./generate/tx').default;
|
||||
|
||||
const { endpoint, output, package, strict: isStrict } = yargs.strict().options({
|
||||
endpoint: {
|
||||
description: 'The endpoint to connect to, e.g. wss://kusama-rpc.polkadot.io or relative file to JSON output',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
output: {
|
||||
description: 'The target directory to write the data to',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
package: {
|
||||
description: 'Optional package in output location (for extra definitions)'
|
||||
},
|
||||
strinct: {
|
||||
description: 'Turns on stirct mode, not outputting genric versions',
|
||||
type: 'boolean'
|
||||
}
|
||||
}).argv;
|
||||
let websocket = null;
|
||||
|
||||
function generate (metaHex) {
|
||||
console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
|
||||
|
||||
const extraTypes = package
|
||||
? { [package]: require(path.join(process.cwd(), output, 'definitions')) }
|
||||
: {};
|
||||
|
||||
generateConst(path.join(process.cwd(), output, 'augment.consts.ts'), metaHex, extraTypes, isStrict);
|
||||
generateQuery(path.join(process.cwd(), output, 'augment.query.ts'), metaHex, extraTypes, isStrict);
|
||||
generateTx(path.join(process.cwd(), output, 'augment.tx.ts'), metaHex, extraTypes, isStrict);
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function onSocketClose (event) {
|
||||
console.error(`${endpoint} disconnected, code: '${event.code}' reason: '${event.reason}'`);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function onSocketError (event) {
|
||||
console.error(event);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function onSocketOpen () {
|
||||
console.log(`${endpoint} connected`);
|
||||
|
||||
websocket.send('{"id":"1","jsonrpc":"2.0","method":"state_getMetadata","params":[]}');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function onSocketMessage (message) {
|
||||
generate(JSON.parse(message.data).result);
|
||||
}
|
||||
|
||||
if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
|
||||
websocket = new WebSocket(endpoint);
|
||||
websocket.onclose = onSocketClose;
|
||||
websocket.onerror = onSocketError;
|
||||
websocket.onmessage = onSocketMessage;
|
||||
websocket.onopen = onSocketOpen;
|
||||
} else {
|
||||
generate(require(path.join(process.cwd(), endpoint)).result);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
require('@babel/register')({
|
||||
extensions: ['.js', '.ts'],
|
||||
plugins: [
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
]
|
||||
});
|
||||
|
||||
const path = require('path');
|
||||
const yargs = require('yargs');
|
||||
const substrateDefs = require('../interfaces/definitions');
|
||||
const { generateInterfaceRegistry } = require('./generateTypes/interfaceRegistry');
|
||||
const { generateTsDef } = require('./generateTypes/tsDef');
|
||||
|
||||
const { input, package } = yargs.strict().options({
|
||||
input: {
|
||||
description: 'The directory to use for the user definitions',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
package: {
|
||||
description: 'The package name & path to use for the user types',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
}).argv;
|
||||
|
||||
const userDefs = require(path.join(process.cwd(), input, 'definitions.ts'));
|
||||
const userKeys = Object.keys(userDefs);
|
||||
const filteredBase = Object
|
||||
.entries(substrateDefs)
|
||||
.filter(([key]) => {
|
||||
if (userKeys.includes(key)) {
|
||||
console.warn(`Override found for ${key} in user types, ignoring in @polkadot/types`);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.reduce((defs, [key, value]) => {
|
||||
defs[key] = value;
|
||||
|
||||
return defs;
|
||||
}, {});
|
||||
|
||||
const allDefs = {
|
||||
'@polkadot/types/interfaces': filteredBase,
|
||||
[package]: userDefs
|
||||
};
|
||||
|
||||
generateTsDef(allDefs, path.join(process.cwd(), input), package);
|
||||
generateInterfaceRegistry(allDefs, path.join(process.cwd(), input, 'interfaceRegistry.ts'));
|
||||
Reference in New Issue
Block a user