@polkadot-api/cli 0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/bin/main.js +339 -0
- package/bin/main.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Josep M Sobrepere
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Polkadot API CLI
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
Add a chain by using the add command
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
polkadot-api add ksm -n ksmcc3 -p
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
In this example, `ksm` is the key to be used to reference this chain, `-n ksmcc3` is to source from the "well-known chain" Kusama, and `-p` is to persist the metadata into a file so that it doesn't need to be re-fetched.
|
|
12
|
+
|
|
13
|
+
Then you can run the CLI without arguments to generate the descriptor files
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
polkadot-api
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Files are generated by default into the `src/codegen` folder, but this can be customized on the `polkadot-api add` step. See the reference below for more information.
|
|
20
|
+
|
|
21
|
+
## General Usage
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
polkadot-api --help
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
Usage: polkadot-api [options] [command]
|
|
29
|
+
|
|
30
|
+
Polkadot API CLI
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
-h, --help display help for command
|
|
34
|
+
|
|
35
|
+
Commands:
|
|
36
|
+
generate [options] Generate file descriptors
|
|
37
|
+
add [options] <key> [dest] Add a new chain spec to the list
|
|
38
|
+
update [options] [keys] Update the metadata files
|
|
39
|
+
remove [options] <key> Remove a chain spec to the list
|
|
40
|
+
help [command] display help for command
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Configuration file
|
|
44
|
+
|
|
45
|
+
By default, the Polkadot API configuration file is `polkadot-api.json`, located at the project's root folder. This file contains a record of the added chains, their sources, and the destination folders for each one of them.
|
|
46
|
+
|
|
47
|
+
All the arguments of the CLI accept an option `--config {file}` to use a different configuration file.
|
|
48
|
+
|
|
49
|
+
Optionally you can have this configuration in the `package.json` file, which will be added under the `polkadot-api` subpath.
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
### Generate
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
Usage: polkadot-api generate [options]
|
|
57
|
+
|
|
58
|
+
Generate descriptor files
|
|
59
|
+
|
|
60
|
+
Options:
|
|
61
|
+
--config <filename> Source for the config file
|
|
62
|
+
-k, --key <key> Key of the descriptor to generate
|
|
63
|
+
-h, --help display help for command
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
By default, it generates the descriptor files for all of the chains defined in the config file. To generate only the ones for a specific chain, use the `-k, --key` parameter.
|
|
67
|
+
|
|
68
|
+
### Add
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
Usage: polkadot-api add [options] <key> [dest]
|
|
72
|
+
|
|
73
|
+
Add a new chain spec to the list
|
|
74
|
+
|
|
75
|
+
Arguments:
|
|
76
|
+
key Key identifier for the chain spec
|
|
77
|
+
dest Destination folder for the generated code. Defaults to src/codegen
|
|
78
|
+
|
|
79
|
+
Options:
|
|
80
|
+
--config <filename> Source for the config file
|
|
81
|
+
-f, --file <filename> Source from metadata encoded file
|
|
82
|
+
-w, --wsUrl <URL> Source from websocket url
|
|
83
|
+
-c, --chainSpec <filename> Source from chain spec file
|
|
84
|
+
-n, --name <name> Source from a well-known chain
|
|
85
|
+
-p, --persist Persist the metadata into the file {name}.scale
|
|
86
|
+
-h, --help display help for command
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This command requires one of the options to specify a source:
|
|
90
|
+
|
|
91
|
+
- From a SCALE-encoded metadata file: `-f, --file`
|
|
92
|
+
- From a Websocket URL: `-w, --wsUrl`
|
|
93
|
+
- From a chainSpect: `-c, --chainSpec`
|
|
94
|
+
- From a well-known chain (as of this writing: polkadot, ksmcc3, rococo_v2_2 or westend2): `-n, --name`
|
|
95
|
+
|
|
96
|
+
For the external sources (`-w`, `-c` and `-n`), there's the option `-p, --persist` which stores the chain metadata into a SCALE-encoded metadata file. This is useful if you want to keep the chain metadata on version control and have it more stable. Otherwise, every time the code is generated, it will re-fetch the metadata from the remote source.
|
|
97
|
+
|
|
98
|
+
### Update
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
Usage: polkadot-api update [options] [keys]
|
|
102
|
+
|
|
103
|
+
Update the metadata files
|
|
104
|
+
|
|
105
|
+
Arguments:
|
|
106
|
+
keys Keys of the metadata files to update, separated by commas. Leave empty for all
|
|
107
|
+
|
|
108
|
+
Options:
|
|
109
|
+
--config <filename> Source for the config file
|
|
110
|
+
-h, --help display help for command
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
For the chains with both an external source (added with `-w`, `-c` or `-n`) and a persisted file it re-fetches the metadata and updates the encoded metadata file.
|
|
114
|
+
|
|
115
|
+
### Remove
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
Usage: polkadot-api remove [options] <key>
|
|
119
|
+
|
|
120
|
+
Remove a chain spec from the list
|
|
121
|
+
|
|
122
|
+
Arguments:
|
|
123
|
+
key Key identifier for the chain spec
|
|
124
|
+
|
|
125
|
+
Options:
|
|
126
|
+
--config <filename> Source for the config file
|
|
127
|
+
-h, --help display help for command
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Removes the specified chain spec from the list. Equivalent as manually removing the entry from the config file.
|
package/bin/main.js
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/main.ts
|
|
4
|
+
import { Option, program } from "@commander-js/extra-typings";
|
|
5
|
+
import { WellKnownChain } from "@substrate/connect";
|
|
6
|
+
|
|
7
|
+
// src/metadata.ts
|
|
8
|
+
import { createClient } from "@polkadot-api/substrate-client";
|
|
9
|
+
import * as fs from "node:fs/promises";
|
|
10
|
+
import { v15 } from "@polkadot-api/substrate-bindings";
|
|
11
|
+
import { WebSocketProvider } from "@polkadot-api/ws-provider/node";
|
|
12
|
+
|
|
13
|
+
// src/smolldot-worker.ts
|
|
14
|
+
var PROVIDER_WORKER_CODE = `
|
|
15
|
+
const { parentPort, workerData } = require("node:worker_threads")
|
|
16
|
+
const { getScProvider } = require("@polkadot-api/sc-provider")
|
|
17
|
+
const { WellKnownChain } = require("@substrate/connect")
|
|
18
|
+
const wellKnownChains = new Set(Object.values(WellKnownChain))
|
|
19
|
+
const isWellKnownChain = (input) => wellKnownChains.has(input)
|
|
20
|
+
|
|
21
|
+
if (!parentPort) {
|
|
22
|
+
throw new Error("no parent port")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const chain = workerData
|
|
26
|
+
const scProvider = getScProvider()
|
|
27
|
+
const getProvider = isWellKnownChain(chain)
|
|
28
|
+
? scProvider(chain).relayChain
|
|
29
|
+
: (() => {
|
|
30
|
+
const parsedSpec = JSON.parse(chain)
|
|
31
|
+
if (parsedSpec.relay_chain) {
|
|
32
|
+
if (!isWellKnownChain(parsedSpec.relay_chain)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Relay chain " + parsedSpec.relay_chain + " is not well-known",
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
const provider = scProvider(parsedSpec.relay_chain)
|
|
38
|
+
return provider.addParachain(chain)
|
|
39
|
+
} else {
|
|
40
|
+
return scProvider(chain).relayChain
|
|
41
|
+
}
|
|
42
|
+
})()
|
|
43
|
+
|
|
44
|
+
const provider = getProvider((msg) => parentPort.postMessage(msg))
|
|
45
|
+
parentPort.on("message", (msg) => {
|
|
46
|
+
switch (msg.type) {
|
|
47
|
+
case "send":
|
|
48
|
+
provider.send(msg.value)
|
|
49
|
+
break
|
|
50
|
+
case "disconnect":
|
|
51
|
+
provider.disconnect()
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
// src/metadata.ts
|
|
57
|
+
import { Worker } from "node:worker_threads";
|
|
58
|
+
import { getObservableClient } from "@polkadot-api/client";
|
|
59
|
+
import { filter, firstValueFrom } from "rxjs";
|
|
60
|
+
import { dirname } from "path";
|
|
61
|
+
var getMetadataCall = async (provider) => {
|
|
62
|
+
const client = getObservableClient(createClient(provider));
|
|
63
|
+
const { metadata$, unfollow } = client.chainHead$();
|
|
64
|
+
const metadata = await firstValueFrom(metadata$.pipe(filter(Boolean)));
|
|
65
|
+
unfollow();
|
|
66
|
+
client.destroy();
|
|
67
|
+
return metadata;
|
|
68
|
+
};
|
|
69
|
+
var getMetadataFromProvider = async (chain) => {
|
|
70
|
+
const provider = (onMsg) => {
|
|
71
|
+
let worker = new Worker(PROVIDER_WORKER_CODE, {
|
|
72
|
+
eval: true,
|
|
73
|
+
workerData: chain,
|
|
74
|
+
stderr: true,
|
|
75
|
+
stdout: true
|
|
76
|
+
});
|
|
77
|
+
worker.on("message", onMsg);
|
|
78
|
+
return {
|
|
79
|
+
send: (msg) => worker?.postMessage({ type: "send", value: msg }),
|
|
80
|
+
disconnect: () => {
|
|
81
|
+
if (!worker)
|
|
82
|
+
return;
|
|
83
|
+
worker.postMessage({ type: "disconnect" });
|
|
84
|
+
worker.removeAllListeners();
|
|
85
|
+
worker.terminate();
|
|
86
|
+
worker = null;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
return getMetadataCall(provider);
|
|
91
|
+
};
|
|
92
|
+
var getMetadataFromWsURL = async (wsURL) => getMetadataCall(WebSocketProvider(wsURL));
|
|
93
|
+
async function getMetadata(entry) {
|
|
94
|
+
if (entry.metadata) {
|
|
95
|
+
const data = await fs.readFile(entry.metadata);
|
|
96
|
+
return v15.dec(data);
|
|
97
|
+
}
|
|
98
|
+
if ("chain" in entry) {
|
|
99
|
+
return getMetadataFromProvider(entry.chain);
|
|
100
|
+
}
|
|
101
|
+
if ("chainSpec" in entry) {
|
|
102
|
+
const chainSpec = await fs.readFile(entry.chainSpec, "utf8");
|
|
103
|
+
return getMetadataFromProvider(chainSpec);
|
|
104
|
+
}
|
|
105
|
+
if ("wsUrl" in entry) {
|
|
106
|
+
return getMetadataFromWsURL(entry.wsUrl);
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
async function writeMetadataToDisk(metadata, outFile) {
|
|
111
|
+
const encoded = v15.enc(metadata);
|
|
112
|
+
await fs.mkdir(dirname(outFile), { recursive: true });
|
|
113
|
+
await fs.writeFile(outFile, encoded);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/papiConfig.ts
|
|
117
|
+
import fsExists from "fs.promises.exists";
|
|
118
|
+
import { readPackage } from "read-pkg";
|
|
119
|
+
import { updatePackage } from "write-pkg";
|
|
120
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
121
|
+
var papiCfgDefaultFile = "polkadot-api.json";
|
|
122
|
+
var packageJsonKey = "polkadot-api";
|
|
123
|
+
async function readPapiConfig(configFile) {
|
|
124
|
+
if (configFile)
|
|
125
|
+
return readFromFile(configFile);
|
|
126
|
+
const configFromDefaultFile = await readFromFile(papiCfgDefaultFile);
|
|
127
|
+
if (configFromDefaultFile)
|
|
128
|
+
return configFromDefaultFile;
|
|
129
|
+
return readFromFile("package.json");
|
|
130
|
+
}
|
|
131
|
+
async function writePapiConfig(configFile, config2) {
|
|
132
|
+
if (configFile)
|
|
133
|
+
return writeToFile(configFile, config2);
|
|
134
|
+
const defaultCfgExists = await fsExists(papiCfgDefaultFile);
|
|
135
|
+
if (defaultCfgExists)
|
|
136
|
+
return writeToFile(papiCfgDefaultFile, config2);
|
|
137
|
+
const packageCfg = await readFromFile("package.json");
|
|
138
|
+
if (packageCfg) {
|
|
139
|
+
return writeToFile("package.json", config2);
|
|
140
|
+
}
|
|
141
|
+
return writeToFile(papiCfgDefaultFile, config2);
|
|
142
|
+
}
|
|
143
|
+
async function readFromFile(file) {
|
|
144
|
+
const fileExists = await fsExists(file);
|
|
145
|
+
if (!fileExists)
|
|
146
|
+
return null;
|
|
147
|
+
if (file === "package.json") {
|
|
148
|
+
const packageJson = await readPackage();
|
|
149
|
+
return packageJson[packageJsonKey] ?? null;
|
|
150
|
+
}
|
|
151
|
+
return JSON.parse(await readFile2(file, "utf8"));
|
|
152
|
+
}
|
|
153
|
+
async function writeToFile(file, config2) {
|
|
154
|
+
if (file === "package.json") {
|
|
155
|
+
await updatePackage({
|
|
156
|
+
[packageJsonKey]: null
|
|
157
|
+
});
|
|
158
|
+
return updatePackage({
|
|
159
|
+
[packageJsonKey]: config2
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return writeFile2(file, JSON.stringify(config2, null, 2));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/commands/add.ts
|
|
166
|
+
import ora from "ora";
|
|
167
|
+
async function add(key, outputFolder = "src/codegen", options) {
|
|
168
|
+
const entries = await readPapiConfig(options.config) ?? {};
|
|
169
|
+
if (key in entries) {
|
|
170
|
+
console.warn(`Replacing existing ${key} config`);
|
|
171
|
+
}
|
|
172
|
+
if (options.file) {
|
|
173
|
+
entries[key] = {
|
|
174
|
+
metadata: options.file,
|
|
175
|
+
outputFolder
|
|
176
|
+
};
|
|
177
|
+
} else {
|
|
178
|
+
const entry = entryFromOptions(outputFolder, options);
|
|
179
|
+
entries[key] = entry;
|
|
180
|
+
if (options.persist) {
|
|
181
|
+
const spinner = ora(`Loading metadata`).start();
|
|
182
|
+
const metadata = await getMetadata(entry);
|
|
183
|
+
spinner.text = "Writing metadata";
|
|
184
|
+
const filename = `${key}.scale`;
|
|
185
|
+
await writeMetadataToDisk(metadata, filename);
|
|
186
|
+
spinner.succeed(`Metadata saved as ${filename}`);
|
|
187
|
+
entry.metadata = filename;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
await writePapiConfig(options.config, entries);
|
|
191
|
+
return console.log(`Saved new spec "${key}"`);
|
|
192
|
+
}
|
|
193
|
+
var entryFromOptions = (outputFolder, options) => {
|
|
194
|
+
if (options.wsUrl) {
|
|
195
|
+
return {
|
|
196
|
+
outputFolder,
|
|
197
|
+
wsUrl: options.wsUrl
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (options.chainSpec) {
|
|
201
|
+
return {
|
|
202
|
+
outputFolder,
|
|
203
|
+
chainSpec: options.chainSpec
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (options.name) {
|
|
207
|
+
return {
|
|
208
|
+
outputFolder,
|
|
209
|
+
chain: options.name
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
throw new Error(
|
|
213
|
+
"add command needs one source, specified by options -f -w -c or -n"
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/commands/generate.ts
|
|
218
|
+
import { getDescriptors } from "@polkadot-api/codegen";
|
|
219
|
+
import fsExists2 from "fs.promises.exists";
|
|
220
|
+
import fs2 from "fs/promises";
|
|
221
|
+
import path from "path";
|
|
222
|
+
import tsc from "tsc-prog";
|
|
223
|
+
async function generate(opts) {
|
|
224
|
+
const sources = await getSources(opts);
|
|
225
|
+
if (Object.keys(sources).length == 0) {
|
|
226
|
+
console.log("No chains defined in config file");
|
|
227
|
+
}
|
|
228
|
+
for (const [key, source] of Object.entries(sources)) {
|
|
229
|
+
console.log(`Reading "${key}" metadata`);
|
|
230
|
+
const metadata = await getMetadata(source);
|
|
231
|
+
console.log(`Generating "${key}" code`);
|
|
232
|
+
await outputCodegen(metadata, source.outputFolder, key);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function getSources(opts) {
|
|
236
|
+
const config2 = await readPapiConfig(opts.config);
|
|
237
|
+
if (!config2) {
|
|
238
|
+
throw new Error("Can't find the Polkadot-API configuration");
|
|
239
|
+
}
|
|
240
|
+
if (opts.key) {
|
|
241
|
+
if (!config2[opts.key]) {
|
|
242
|
+
throw new Error(`Key ${opts.key} not set in polkadot-api config`);
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
[opts.key]: config2[opts.key]
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return config2;
|
|
249
|
+
}
|
|
250
|
+
async function outputCodegen(metadata, outputFolder, key) {
|
|
251
|
+
const code = getDescriptors(metadata, "", "@polkadot-api/client");
|
|
252
|
+
await fs2.mkdir(outputFolder, { recursive: true });
|
|
253
|
+
await createDtsFile(key, outputFolder, code);
|
|
254
|
+
}
|
|
255
|
+
var createDtsFile = async (key, dest, code) => {
|
|
256
|
+
const tscFileName = path.join(dest, key);
|
|
257
|
+
if (await fsExists2(`${tscFileName}.ts`))
|
|
258
|
+
await fs2.rm(`${tscFileName}.ts`);
|
|
259
|
+
await fs2.writeFile(`${tscFileName}.ts`, code);
|
|
260
|
+
tsc.build({
|
|
261
|
+
basePath: dest,
|
|
262
|
+
compilerOptions: {
|
|
263
|
+
skipLibCheck: true,
|
|
264
|
+
emitDeclarationOnly: true,
|
|
265
|
+
declaration: true,
|
|
266
|
+
target: "esnext",
|
|
267
|
+
module: "esnext",
|
|
268
|
+
moduleResolution: "node"
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/commands/remove.ts
|
|
274
|
+
async function remove(key, options) {
|
|
275
|
+
const entries = await readPapiConfig(options.config) ?? {};
|
|
276
|
+
if (!(key in entries)) {
|
|
277
|
+
throw new Error(`Key ${key} not set in polkadot-api config`);
|
|
278
|
+
}
|
|
279
|
+
const entry = entries[key];
|
|
280
|
+
delete entries[key];
|
|
281
|
+
await writePapiConfig(options.config, entries);
|
|
282
|
+
console.log(`Removed chain "${key}" from config`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/commands/update.ts
|
|
286
|
+
import ora2 from "ora";
|
|
287
|
+
async function update(keysInput, options) {
|
|
288
|
+
const entries = await readPapiConfig(options.config) ?? {};
|
|
289
|
+
const keys = keysInput === void 0 ? Object.keys(entries) : keysInput.split(",");
|
|
290
|
+
for (let key of keys) {
|
|
291
|
+
if (!(key in entries)) {
|
|
292
|
+
throw new Error(`Key ${key} not set in polkadot-api config`);
|
|
293
|
+
}
|
|
294
|
+
const spinner = ora2(`Updating ${key}`).start();
|
|
295
|
+
const { metadata: filename, ...entry } = entries[key];
|
|
296
|
+
if (!filename) {
|
|
297
|
+
if (keysInput !== void 0) {
|
|
298
|
+
console.warn(`Key ${key} doesn't have a metadata file to update`);
|
|
299
|
+
}
|
|
300
|
+
spinner.stop();
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const metadata = await getMetadata(entry);
|
|
304
|
+
if (!metadata) {
|
|
305
|
+
if (keysInput !== void 0) {
|
|
306
|
+
console.warn(
|
|
307
|
+
`Key ${key} doesn't have any external source to update from`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
spinner.stop();
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
spinner.text = `Writing ${key} metadata`;
|
|
314
|
+
await writeMetadataToDisk(metadata, filename);
|
|
315
|
+
spinner.succeed(`${key} metadata updated`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/main.ts
|
|
320
|
+
program.name("polkadot-api").description("Polkadot API CLI");
|
|
321
|
+
var config = new Option("--config <filename>", "Source for the config file");
|
|
322
|
+
program.command("generate", {
|
|
323
|
+
isDefault: true
|
|
324
|
+
}).description("Generate descriptor files").addOption(config).option("-k, --key <key>", "Key of the descriptor to generate").action(generate);
|
|
325
|
+
program.command("add").description("Add a new chain spec to the list").argument("<key>", "Key identifier for the chain spec").argument(
|
|
326
|
+
"[dest]",
|
|
327
|
+
"Destination folder for the generated code. Defaults to src/codegen"
|
|
328
|
+
).addOption(config).option("-f, --file <filename>", "Source from metadata encoded file").option("-w, --wsUrl <URL>", "Source from websocket url").option("-c, --chainSpec <filename>", "Source from chain spec file").addOption(
|
|
329
|
+
new Option("-n, --name <name>", "Source from a well-known chain").choices(
|
|
330
|
+
Object.keys(WellKnownChain)
|
|
331
|
+
)
|
|
332
|
+
).option("-p, --persist", "Persist the metadata into the file {key}.scale").action(add);
|
|
333
|
+
program.command("update").description("Update the metadata files").argument(
|
|
334
|
+
"[keys]",
|
|
335
|
+
"Keys of the metadata files to update, separated by commas. Leave empty for all"
|
|
336
|
+
).addOption(config).action(update);
|
|
337
|
+
program.command("remove").description("Remove a chain spec from the list").argument("<key>", "Key identifier for the chain spec").addOption(config).action(remove);
|
|
338
|
+
program.parse();
|
|
339
|
+
//# sourceMappingURL=main.js.map
|
package/bin/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/main.ts","../src/metadata.ts","../src/smolldot-worker.ts","../src/papiConfig.ts","../src/commands/add.ts","../src/commands/generate.ts","../src/commands/remove.ts","../src/commands/update.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Option, program } from \"@commander-js/extra-typings\"\nimport { WellKnownChain } from \"@substrate/connect\"\nimport { add, generate, remove, update } from \"./commands\"\n\nprogram.name(\"polkadot-api\").description(\"Polkadot API CLI\")\n\nconst config = new Option(\"--config <filename>\", \"Source for the config file\")\n\nprogram\n .command(\"generate\", {\n isDefault: true,\n })\n .description(\"Generate descriptor files\")\n .addOption(config)\n .option(\"-k, --key <key>\", \"Key of the descriptor to generate\")\n .action(generate)\n\nprogram\n .command(\"add\")\n .description(\"Add a new chain spec to the list\")\n .argument(\"<key>\", \"Key identifier for the chain spec\")\n .argument(\n \"[dest]\",\n \"Destination folder for the generated code. Defaults to src/codegen\",\n )\n .addOption(config)\n .option(\"-f, --file <filename>\", \"Source from metadata encoded file\")\n .option(\"-w, --wsUrl <URL>\", \"Source from websocket url\")\n .option(\"-c, --chainSpec <filename>\", \"Source from chain spec file\")\n .addOption(\n new Option(\"-n, --name <name>\", \"Source from a well-known chain\").choices(\n Object.keys(WellKnownChain) as WellKnownChain[],\n ),\n )\n .option(\"-p, --persist\", \"Persist the metadata into the file {key}.scale\")\n .action(add)\n\nprogram\n .command(\"update\")\n .description(\"Update the metadata files\")\n .argument(\n \"[keys]\",\n \"Keys of the metadata files to update, separated by commas. Leave empty for all\",\n )\n .addOption(config)\n .action(update)\n\nprogram\n .command(\"remove\")\n .description(\"Remove a chain spec from the list\")\n .argument(\"<key>\", \"Key identifier for the chain spec\")\n .addOption(config)\n .action(remove)\n\nprogram.parse()\n","import { WellKnownChain } from \"@substrate/connect\"\nimport { createClient } from \"@polkadot-api/substrate-client\"\nimport type { ConnectProvider } from \"@polkadot-api/json-rpc-provider\"\nimport * as fs from \"node:fs/promises\"\nimport { V15, v15 } from \"@polkadot-api/substrate-bindings\"\nimport { WebSocketProvider } from \"@polkadot-api/ws-provider/node\"\nimport { PROVIDER_WORKER_CODE } from \"./smolldot-worker\"\nimport { Worker } from \"node:worker_threads\"\nimport { getObservableClient } from \"@polkadot-api/client\"\nimport { filter, firstValueFrom } from \"rxjs\"\nimport { EntryConfig } from \"./papiConfig\"\nimport { dirname } from \"path\"\n\nconst getMetadataCall = async (provider: ConnectProvider) => {\n const client = getObservableClient(createClient(provider))\n const { metadata$, unfollow } = client.chainHead$()\n const metadata = await firstValueFrom(metadata$.pipe(filter(Boolean)))\n\n unfollow()\n client.destroy()\n\n return metadata\n}\n\nconst getMetadataFromProvider = async (chain: WellKnownChain | string) => {\n const provider: ConnectProvider = (onMsg) => {\n let worker: Worker | null = new Worker(PROVIDER_WORKER_CODE, {\n eval: true,\n workerData: chain,\n stderr: true,\n stdout: true,\n })\n worker.on(\"message\", onMsg)\n\n return {\n send: (msg) => worker?.postMessage({ type: \"send\", value: msg }),\n disconnect: () => {\n if (!worker) return\n\n worker.postMessage({ type: \"disconnect\" })\n worker.removeAllListeners()\n worker.terminate()\n worker = null\n },\n }\n }\n\n return getMetadataCall(provider)\n}\n\nconst getMetadataFromWsURL = async (wsURL: string) =>\n getMetadataCall(WebSocketProvider(wsURL))\n\nexport async function getMetadata(entry: EntryConfig): Promise<V15 | null> {\n // metadata file always prevails over other entries.\n // cli's update will update the metadata file when the user requests it.\n if (entry.metadata) {\n const data = await fs.readFile(entry.metadata)\n return v15.dec(data)\n }\n\n if (\"chain\" in entry) {\n return getMetadataFromProvider(entry.chain)\n }\n\n if (\"chainSpec\" in entry) {\n const chainSpec = await fs.readFile(entry.chainSpec, \"utf8\")\n return getMetadataFromProvider(chainSpec)\n }\n\n if (\"wsUrl\" in entry) {\n return getMetadataFromWsURL(entry.wsUrl)\n }\n\n return null\n}\n\nexport async function writeMetadataToDisk(metadata: V15, outFile: string) {\n const encoded = v15.enc(metadata)\n\n await fs.mkdir(dirname(outFile), { recursive: true })\n await fs.writeFile(outFile, encoded)\n}\n","export const PROVIDER_WORKER_CODE = `\nconst { parentPort, workerData } = require(\"node:worker_threads\")\nconst { getScProvider } = require(\"@polkadot-api/sc-provider\")\nconst { WellKnownChain } = require(\"@substrate/connect\")\nconst wellKnownChains = new Set(Object.values(WellKnownChain))\nconst isWellKnownChain = (input) => wellKnownChains.has(input)\n\nif (!parentPort) {\n throw new Error(\"no parent port\")\n}\n\nconst chain = workerData\nconst scProvider = getScProvider()\nconst getProvider = isWellKnownChain(chain)\n ? scProvider(chain).relayChain\n : (() => {\n const parsedSpec = JSON.parse(chain)\n if (parsedSpec.relay_chain) {\n if (!isWellKnownChain(parsedSpec.relay_chain)) {\n throw new Error(\n \"Relay chain \" + parsedSpec.relay_chain + \" is not well-known\",\n )\n }\n const provider = scProvider(parsedSpec.relay_chain)\n return provider.addParachain(chain)\n } else {\n return scProvider(chain).relayChain\n }\n })()\n\nconst provider = getProvider((msg) => parentPort.postMessage(msg))\nparentPort.on(\"message\", (msg) => {\n switch (msg.type) {\n case \"send\":\n provider.send(msg.value)\n break\n case \"disconnect\":\n provider.disconnect()\n }\n})\n`\n","import { WellKnownChain } from \"@substrate/connect\"\nimport fsExists from \"fs.promises.exists\"\nimport { readPackage } from \"read-pkg\"\nimport { updatePackage, writePackage } from \"write-pkg\"\nimport { readFile, writeFile } from \"node:fs/promises\"\n\nexport type EntryConfig = {\n outputFolder: string\n} & (\n | {\n metadata: string\n }\n | {\n chainSpec: string\n metadata?: string\n }\n | {\n wsUrl: string\n metadata?: string\n }\n | {\n chain: WellKnownChain\n metadata?: string\n }\n)\nexport type PapiConfig = Record<string, EntryConfig>\n\nconst papiCfgDefaultFile = \"polkadot-api.json\"\nconst packageJsonKey = \"polkadot-api\"\n\nexport async function readPapiConfig(\n configFile: string | undefined,\n): Promise<PapiConfig | null> {\n if (configFile) return readFromFile(configFile)\n\n const configFromDefaultFile = await readFromFile(papiCfgDefaultFile)\n if (configFromDefaultFile) return configFromDefaultFile\n\n return readFromFile(\"package.json\")\n}\n\n/**\n * Writes config to configFile.\n * If configFile is not specified, it writes to the default path, by this priority order:\n * 1. default config file (polkadot-api.json)\n * 2. package.json\n * If no pre-existing config exists, then it creates a polkadot-api.json file.\n */\nexport async function writePapiConfig(\n configFile: string | undefined,\n config: PapiConfig,\n) {\n if (configFile) return writeToFile(configFile, config)\n\n const defaultCfgExists = await fsExists(papiCfgDefaultFile)\n if (defaultCfgExists) return writeToFile(papiCfgDefaultFile, config)\n\n const packageCfg = await readFromFile(\"package.json\")\n if (packageCfg) {\n return writeToFile(\"package.json\", config)\n }\n\n return writeToFile(papiCfgDefaultFile, config)\n}\n\nasync function readFromFile(file: string) {\n const fileExists = await fsExists(file)\n if (!fileExists) return null\n\n if (file === \"package.json\") {\n const packageJson = await readPackage()\n return packageJson[packageJsonKey] ?? null\n }\n return JSON.parse(await readFile(file, \"utf8\"))\n}\n\nasync function writeToFile(file: string, config: PapiConfig) {\n if (file === \"package.json\") {\n // updatePackage preserves existing values, we have to clear them to make removes work.\n await updatePackage({\n [packageJsonKey]: null,\n })\n return updatePackage({\n [packageJsonKey]: config,\n })\n }\n return writeFile(file, JSON.stringify(config, null, 2))\n}\n","import { getMetadata, writeMetadataToDisk } from \"@/metadata\"\nimport { EntryConfig, readPapiConfig, writePapiConfig } from \"@/papiConfig\"\nimport { WellKnownChain } from \"@substrate/connect\"\nimport ora from \"ora\"\nimport { CommonOptions } from \"./commonOptions\"\n\nexport interface AddOptions extends CommonOptions {\n file?: string\n wsUrl?: string\n chainSpec?: string\n name?: WellKnownChain\n persist?: boolean\n}\n\nexport async function add(\n key: string,\n outputFolder = \"src/codegen\",\n options: AddOptions,\n) {\n const entries = (await readPapiConfig(options.config)) ?? {}\n if (key in entries) {\n console.warn(`Replacing existing ${key} config`)\n }\n\n if (options.file) {\n entries[key] = {\n metadata: options.file,\n outputFolder,\n }\n } else {\n const entry = entryFromOptions(outputFolder, options)\n entries[key] = entry\n\n if (options.persist) {\n const spinner = ora(`Loading metadata`).start()\n const metadata = await getMetadata(entry)\n\n spinner.text = \"Writing metadata\"\n const filename = `${key}.scale`\n await writeMetadataToDisk(metadata!, filename)\n\n spinner.succeed(`Metadata saved as ${filename}`)\n entry.metadata = filename\n }\n }\n\n await writePapiConfig(options.config, entries)\n return console.log(`Saved new spec \"${key}\"`)\n}\n\nconst entryFromOptions = (\n outputFolder: string,\n options: AddOptions,\n): EntryConfig => {\n if (options.wsUrl) {\n return {\n outputFolder,\n wsUrl: options.wsUrl,\n }\n }\n if (options.chainSpec) {\n return {\n outputFolder,\n chainSpec: options.chainSpec,\n }\n }\n if (options.name) {\n return {\n outputFolder,\n chain: options.name as WellKnownChain,\n }\n }\n\n throw new Error(\n \"add command needs one source, specified by options -f -w -c or -n\",\n )\n}\n","import { getMetadata } from \"@/metadata\"\nimport { EntryConfig, readPapiConfig } from \"@/papiConfig\"\nimport { getDescriptors } from \"@polkadot-api/codegen\"\nimport { V15 } from \"@polkadot-api/metadata-builders\"\nimport fsExists from \"fs.promises.exists\"\nimport fs from \"fs/promises\"\nimport path from \"path\"\nimport tsc from \"tsc-prog\"\nimport { CommonOptions } from \"./commonOptions\"\n\nexport interface GenerateOptions extends CommonOptions {\n key?: string\n}\n\nexport async function generate(opts: GenerateOptions) {\n const sources = await getSources(opts)\n\n if (Object.keys(sources).length == 0) {\n console.log(\"No chains defined in config file\")\n }\n\n for (const [key, source] of Object.entries(sources)) {\n console.log(`Reading \"${key}\" metadata`)\n const metadata = await getMetadata(source)\n\n console.log(`Generating \"${key}\" code`)\n await outputCodegen(metadata!, source.outputFolder, key)\n }\n}\n\nasync function getSources(\n opts: GenerateOptions,\n): Promise<Record<string, EntryConfig>> {\n const config = await readPapiConfig(opts.config)\n if (!config) {\n throw new Error(\"Can't find the Polkadot-API configuration\")\n }\n\n if (opts.key) {\n if (!config[opts.key]) {\n throw new Error(`Key ${opts.key} not set in polkadot-api config`)\n }\n return {\n [opts.key]: config[opts.key],\n }\n }\n\n return config\n}\n\nasync function outputCodegen(metadata: V15, outputFolder: string, key: string) {\n const code = getDescriptors(metadata, \"\", \"@polkadot-api/client\")\n await fs.mkdir(outputFolder, { recursive: true })\n await createDtsFile(key, outputFolder, code)\n}\n\nconst createDtsFile = async (key: string, dest: string, code: string) => {\n const tscFileName = path.join(dest, key)\n\n if (await fsExists(`${tscFileName}.ts`)) await fs.rm(`${tscFileName}.ts`)\n\n await fs.writeFile(`${tscFileName}.ts`, code)\n\n tsc.build({\n basePath: dest,\n compilerOptions: {\n skipLibCheck: true,\n emitDeclarationOnly: true,\n declaration: true,\n target: \"esnext\",\n module: \"esnext\",\n moduleResolution: \"node\",\n },\n })\n}\n","import { readPapiConfig, writePapiConfig } from \"@/papiConfig\"\nimport { CommonOptions } from \"./commonOptions\"\n\nexport async function remove(key: string, options: CommonOptions) {\n const entries = (await readPapiConfig(options.config)) ?? {}\n\n if (!(key in entries)) {\n throw new Error(`Key ${key} not set in polkadot-api config`)\n }\n\n const entry = entries[key]\n delete entries[key]\n\n await writePapiConfig(options.config, entries)\n console.log(`Removed chain \"${key}\" from config`)\n}\n","import { getMetadata, writeMetadataToDisk } from \"@/metadata\"\nimport { EntryConfig, readPapiConfig } from \"@/papiConfig\"\nimport ora from \"ora\"\nimport { CommonOptions } from \"./commonOptions\"\n\nexport async function update(\n keysInput: string | undefined,\n options: CommonOptions,\n) {\n const entries = (await readPapiConfig(options.config)) ?? {}\n const keys =\n keysInput === undefined ? Object.keys(entries) : keysInput.split(\",\")\n\n for (let key of keys) {\n if (!(key in entries)) {\n throw new Error(`Key ${key} not set in polkadot-api config`)\n }\n\n const spinner = ora(`Updating ${key}`).start()\n\n // Exclude metadata file from the entry, otherwise getMetadata would load from the file\n const { metadata: filename, ...entry } = entries[key]\n if (!filename) {\n if (keysInput !== undefined) {\n console.warn(`Key ${key} doesn't have a metadata file to update`)\n }\n\n spinner.stop()\n continue\n }\n\n const metadata = await getMetadata(entry as EntryConfig)\n // For those without other sources than metadata file, we get a null.\n if (!metadata) {\n if (keysInput !== undefined) {\n console.warn(\n `Key ${key} doesn't have any external source to update from`,\n )\n }\n spinner.stop()\n continue\n }\n\n spinner.text = `Writing ${key} metadata`\n await writeMetadataToDisk(metadata, filename)\n\n spinner.succeed(`${key} metadata updated`)\n }\n}\n"],"mappings":";;;AAEA,SAAS,QAAQ,eAAe;AAChC,SAAS,sBAAsB;;;ACF/B,SAAS,oBAAoB;AAE7B,YAAY,QAAQ;AACpB,SAAc,WAAW;AACzB,SAAS,yBAAyB;;;ACL3B,IAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ADOpC,SAAS,cAAc;AACvB,SAAS,2BAA2B;AACpC,SAAS,QAAQ,sBAAsB;AAEvC,SAAS,eAAe;AAExB,IAAM,kBAAkB,OAAO,aAA8B;AAC3D,QAAM,SAAS,oBAAoB,aAAa,QAAQ,CAAC;AACzD,QAAM,EAAE,WAAW,SAAS,IAAI,OAAO,WAAW;AAClD,QAAM,WAAW,MAAM,eAAe,UAAU,KAAK,OAAO,OAAO,CAAC,CAAC;AAErE,WAAS;AACT,SAAO,QAAQ;AAEf,SAAO;AACT;AAEA,IAAM,0BAA0B,OAAO,UAAmC;AACxE,QAAM,WAA4B,CAAC,UAAU;AAC3C,QAAI,SAAwB,IAAI,OAAO,sBAAsB;AAAA,MAC3D,MAAM;AAAA,MACN,YAAY;AAAA,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AAQ,KAAK,EACb,YAAY,kCAAkC,EAC9C,SAAS,SAAS,mCAAmC,EACrD;AAAA,EACC;AAAA,EACA;AACF,EACC,UAAU,MAAM,EAChB,OAAO,yBAAyB,mCAAmC,EACnE,OAAO,qBAAqB,2BAA2B,EACvD,OAAO,8BAA8B,6BAA6B,EAClE;AAAA,EACC,IAAI,OAAO,qBAAqB,gCAAgC,EAAE;AAAA,IAChE,OAAO,KAAK,cAAc;AAAA,EAC5B;AACF,EACC,OAAO,iBAAiB,gDAAgD,EACxE,OAAO,GAAG;AAEb,QACG,QAAQ,QAAQ,EAChB,YAAY,2BAA2B,EACvC;AAAA,EACC;AAAA,EACA;AACF,EACC,UAAU,MAAM,EAChB,OAAO,MAAM;AAEhB,QACG,QAAQ,QAAQ,EAChB,YAAY,mCAAmC,EAC/C,SAAS,SAAS,mCAAmC,EACrD,UAAU,MAAM,EAChB,OAAO,MAAM;AAEhB,QAAQ,MAAM;","names":["readFile","writeFile","config","fsExists","fs","config","ora"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polkadot-api/cli",
|
|
3
|
+
"version": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
4
|
+
"author": "Ryan Lee (https://github.com/ryanleecode)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"sideEffects": true,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"papi": "./bin/main.js",
|
|
10
|
+
"polkadot-api": "./bin/main.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"/bin"
|
|
14
|
+
],
|
|
15
|
+
"prettier": {
|
|
16
|
+
"printWidth": 80,
|
|
17
|
+
"semi": false,
|
|
18
|
+
"trailingComma": "all"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@commander-js/extra-typings": "^12.0.1",
|
|
22
|
+
"@substrate/connect": "^0.7.32",
|
|
23
|
+
"@types/node": "^20.9.0",
|
|
24
|
+
"commander": "^11.0.0",
|
|
25
|
+
"fs.promises.exists": "^1.1.4",
|
|
26
|
+
"ora": "^7.0.1",
|
|
27
|
+
"read-pkg": "^8.1.0",
|
|
28
|
+
"rxjs": "^7.8.1",
|
|
29
|
+
"scale-ts": "^1.4.2",
|
|
30
|
+
"tsc-prog": "^2.3.0",
|
|
31
|
+
"typescript": "^5.3.2",
|
|
32
|
+
"write-pkg": "^6.0.0",
|
|
33
|
+
"ws": "^8.14.2",
|
|
34
|
+
"@polkadot-api/client": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
35
|
+
"@polkadot-api/codegen": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
36
|
+
"@polkadot-api/json-rpc-provider": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
37
|
+
"@polkadot-api/json-rpc-provider-proxy": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
38
|
+
"@polkadot-api/metadata-builders": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
39
|
+
"@polkadot-api/sc-provider": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
40
|
+
"@polkadot-api/substrate-bindings": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
41
|
+
"@polkadot-api/utils": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
42
|
+
"@polkadot-api/substrate-client": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0",
|
|
43
|
+
"@polkadot-api/ws-provider": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/ws": "^8.5.10",
|
|
47
|
+
"clet": "^1.0.1",
|
|
48
|
+
"@polkadot-api/json-rpc-provider": "0.0.1-0027dd301d1d5a078e9c770a18e27aed76a66f50.1.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc --noEmit && tsup-node src/main.ts --clean --out-dir bin --sourcemap --platform node --format esm",
|
|
52
|
+
"start": "pnpm build && node --enable-source-maps bin/main.js",
|
|
53
|
+
"test": "echo 'no tests'",
|
|
54
|
+
"lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"",
|
|
55
|
+
"format": "prettier --write README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\""
|
|
56
|
+
}
|
|
57
|
+
}
|