@digicatapult/sqnc-process-management 2.2.131 → 2.2.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +95 -0
- package/build/index.js.map +1 -0
- package/build/lib/process/__tests__/unit.test.js +191 -0
- package/build/lib/process/__tests__/unit.test.js.map +1 -0
- package/build/lib/process/api.js +206 -0
- package/build/lib/process/api.js.map +1 -0
- package/build/lib/process/constants.js +5 -0
- package/build/lib/process/constants.js.map +1 -0
- package/build/{src/lib → lib}/process/hex.js +4 -2
- package/build/lib/process/hex.js.map +1 -0
- package/build/lib/process/index.js +304 -0
- package/build/lib/process/index.js.map +1 -0
- package/build/{src/lib → lib}/types/error.js +9 -6
- package/build/lib/types/error.js.map +1 -0
- package/build/lib/types/polkadot.d.js +2 -0
- package/build/lib/types/polkadot.d.js.map +1 -0
- package/build/lib/types/process.d.js +2 -0
- package/build/lib/types/process.d.js.map +1 -0
- package/build/lib/types/validation.js +179 -0
- package/build/lib/types/validation.js.map +1 -0
- package/build/lib/utils/polkadot.js +26 -0
- package/build/lib/utils/polkadot.js.map +1 -0
- package/build/version.js +5 -0
- package/build/version.js.map +1 -0
- package/package.json +12 -10
- package/build/package.json +0 -65
- package/build/src/index.d.ts +0 -2
- package/build/src/index.js +0 -127
- package/build/src/lib/process/_tests_/unit.test.d.ts +0 -1
- package/build/src/lib/process/_tests_/unit.test.js +0 -112
- package/build/src/lib/process/api.d.ts +0 -10
- package/build/src/lib/process/api.js +0 -193
- package/build/src/lib/process/constants.d.ts +0 -3
- package/build/src/lib/process/constants.js +0 -3
- package/build/src/lib/process/hex.d.ts +0 -2
- package/build/src/lib/process/index.d.ts +0 -22
- package/build/src/lib/process/index.js +0 -311
- package/build/src/lib/types/error.d.ts +0 -14
- package/build/src/lib/types/validation.d.ts +0 -3592
- package/build/src/lib/types/validation.js +0 -128
- package/build/src/lib/utils/polkadot.d.ts +0 -6
- package/build/src/lib/utils/polkadot.js +0 -28
- package/build/src/version.d.ts +0 -2
- package/build/src/version.js +0 -3
- package/build/tests/fixtures/processes.d.ts +0 -281
- package/build/tests/fixtures/processes.js +0 -1066
- package/build/tests/fixtures/programs.d.ts +0 -14
- package/build/tests/fixtures/programs.js +0 -211
- package/build/tests/helpers/containers.d.ts +0 -7
- package/build/tests/helpers/containers.js +0 -40
- package/build/tests/helpers/substrateHelper.d.ts +0 -2
- package/build/tests/helpers/substrateHelper.js +0 -100
- package/build/tests/integration/command-functions.test.d.ts +0 -1
- package/build/tests/integration/command-functions.test.js +0 -414
- package/build/tests/integration/without-manual-seal.test.d.ts +0 -1
- package/build/tests/integration/without-manual-seal.test.js +0 -52
- package/build/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digicatapult/sqnc-process-management",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.132",
|
|
4
4
|
"description": "SQNC Process Management Flow",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"start": "node --
|
|
11
|
+
"start": "SWCRC=true NODE_ENV=production node --import @swc-node/register/esm-register --enable-source-maps src/index.ts",
|
|
12
12
|
"local": "npm i -g && process-management",
|
|
13
|
-
"dev": "nodemon --watch 'src/**/*.ts' --exec node --
|
|
13
|
+
"dev": "NODE_ENV=dev nodemon --watch 'src/**/*.ts' --exec node --import @swc-node/register/esm-register --enable-source-maps src/index.ts",
|
|
14
14
|
"lint": "eslint .",
|
|
15
|
-
"build": "
|
|
15
|
+
"build": "swc ./src -d ./build --strip-leading-paths --copy-files",
|
|
16
16
|
"depcheck": "depcheck",
|
|
17
|
-
"test": "
|
|
18
|
-
"test:unit": "
|
|
17
|
+
"test": "SWCRC=true NODE_ENV=test node --enable-source-maps ./node_modules/.bin/mocha --config ./test/mocharc.json test/**/*.test.ts",
|
|
18
|
+
"test:unit": "SWCRC=true NODE_ENV=test node --enable-source-maps ./node_modules/.bin/mocha --config ./test/mocharc.json src/**/*.test.ts --exit",
|
|
19
19
|
"prettier": "npx prettier --write ."
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@eslint/eslintrc": "^3.2.0",
|
|
40
40
|
"@eslint/js": "^9.15.0",
|
|
41
|
+
"@swc-node/register": "^1.10.9",
|
|
42
|
+
"@swc/cli": "^0.5.1",
|
|
43
|
+
"@swc/core": "^1.9.2",
|
|
44
|
+
"@swc/helpers": "^0.5.15",
|
|
41
45
|
"@types/chai": "^5.0.1",
|
|
42
46
|
"@types/mocha": "^10.0.10",
|
|
43
47
|
"@types/node": "^18.19.64",
|
|
@@ -51,15 +55,13 @@
|
|
|
51
55
|
"mocha": "^10.8.2",
|
|
52
56
|
"nodemon": "^3.1.7",
|
|
53
57
|
"prettier": "^3.3.3",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"ts-node": "^10.9.2"
|
|
58
|
+
"reflect-metadata": "^0.2.2",
|
|
59
|
+
"testcontainers": "^10.14.0"
|
|
57
60
|
},
|
|
58
61
|
"dependencies": {
|
|
59
62
|
"@polkadot/api": "^14.3.1",
|
|
60
63
|
"chalk": "^5.3.0",
|
|
61
64
|
"commander": "^12.1.0",
|
|
62
|
-
"typescript": "^5.6.3",
|
|
63
65
|
"zod": "^3.23.8"
|
|
64
66
|
}
|
|
65
67
|
}
|
package/build/package.json
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@digicatapult/sqnc-process-management",
|
|
3
|
-
"version": "2.2.131",
|
|
4
|
-
"description": "SQNC Process Management Flow",
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"process-management": "./build/src/index.js"
|
|
8
|
-
},
|
|
9
|
-
"type": "module",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"start": "node --loader ts-node/esm src/index.ts",
|
|
12
|
-
"local": "npm i -g && process-management",
|
|
13
|
-
"dev": "nodemon --watch 'src/**/*.ts' --exec node --loader ts-node/esm src/index.ts",
|
|
14
|
-
"lint": "eslint .",
|
|
15
|
-
"build": "tsc --build",
|
|
16
|
-
"depcheck": "depcheck",
|
|
17
|
-
"test": "ts-mocha --config ./tests/mocharc.json -n loader=ts-node/esm -p tsconfig.json tests/**/*.test.ts --exit",
|
|
18
|
-
"test:unit": "ts-mocha --config ./tests/mocharc.json -n loader=ts-node/esm -p tsconfig.json src/**/*.test.ts --exit",
|
|
19
|
-
"prettier": "npx prettier --write ."
|
|
20
|
-
},
|
|
21
|
-
"repository": {
|
|
22
|
-
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/digicatapult/sqnc-process-management.git"
|
|
24
|
-
},
|
|
25
|
-
"files": [
|
|
26
|
-
"/build"
|
|
27
|
-
],
|
|
28
|
-
"engines": {
|
|
29
|
-
"node": ">=20.x.x",
|
|
30
|
-
"npm": ">=10.x.x"
|
|
31
|
-
},
|
|
32
|
-
"author": "Digital Catapult",
|
|
33
|
-
"license": "Apache-2.0",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/digicatapult/sqnc-process-management/issues"
|
|
36
|
-
},
|
|
37
|
-
"homepage": "https://github.com/digicatapult/sqnc-process-management#readme",
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@eslint/eslintrc": "^3.2.0",
|
|
40
|
-
"@eslint/js": "^9.15.0",
|
|
41
|
-
"@types/chai": "^5.0.1",
|
|
42
|
-
"@types/mocha": "^10.0.10",
|
|
43
|
-
"@types/node": "^18.19.64",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
45
|
-
"@typescript-eslint/parser": "^8.15.0",
|
|
46
|
-
"chai": "^5.1.2",
|
|
47
|
-
"depcheck": "^1.4.7",
|
|
48
|
-
"eslint": "^9.15.0",
|
|
49
|
-
"eslint-config-prettier": "^9.1.0",
|
|
50
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
51
|
-
"mocha": "^10.8.2",
|
|
52
|
-
"nodemon": "^3.1.7",
|
|
53
|
-
"prettier": "^3.3.3",
|
|
54
|
-
"testcontainers": "^10.14.0",
|
|
55
|
-
"ts-mocha": "^10.0.0",
|
|
56
|
-
"ts-node": "^10.9.2"
|
|
57
|
-
},
|
|
58
|
-
"dependencies": {
|
|
59
|
-
"@polkadot/api": "^14.3.1",
|
|
60
|
-
"chalk": "^5.3.0",
|
|
61
|
-
"commander": "^12.1.0",
|
|
62
|
-
"typescript": "^5.6.3",
|
|
63
|
-
"zod": "^3.23.8"
|
|
64
|
-
}
|
|
65
|
-
}
|
package/build/src/index.d.ts
DELETED
package/build/src/index.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
import fs from 'fs/promises';
|
|
12
|
-
import chalk from 'chalk';
|
|
13
|
-
import { Command } from 'commander';
|
|
14
|
-
import { loadProcesses, disableProcess, listTransforming } from './lib/process/index.js';
|
|
15
|
-
import { getAll } from './lib/process/api.js';
|
|
16
|
-
import cliVersion from './version.js';
|
|
17
|
-
const unwrap = (res) => {
|
|
18
|
-
if (res.type === 'ok')
|
|
19
|
-
return res.result;
|
|
20
|
-
else
|
|
21
|
-
throw res.error;
|
|
22
|
-
};
|
|
23
|
-
const { log, dir } = console;
|
|
24
|
-
const program = new Command();
|
|
25
|
-
const { red: r, blue: b } = {
|
|
26
|
-
red: (txt) => chalk.redBright(txt),
|
|
27
|
-
blue: (txt) => chalk.blueBright(txt),
|
|
28
|
-
};
|
|
29
|
-
const mapOptions = (options) => ({
|
|
30
|
-
API_HOST: options.host,
|
|
31
|
-
API_PORT: parseInt(options.port),
|
|
32
|
-
USER_URI: options.user,
|
|
33
|
-
});
|
|
34
|
-
// TODO nice to have, a local config file for substrate host details e.g. name, port, address
|
|
35
|
-
// so no need to parse every time calling a command, or ability to set
|
|
36
|
-
program
|
|
37
|
-
.name('process management')
|
|
38
|
-
.description('a command line interface for managing chain processes')
|
|
39
|
-
.version(cliVersion, '-v, --version', 'output current version')
|
|
40
|
-
.helpOption('--help', 'display help for command'); //override -h
|
|
41
|
-
program
|
|
42
|
-
.command('list')
|
|
43
|
-
.description('A command for listing all active process flows')
|
|
44
|
-
.option('-v, --verbose', 'Returns all information about the transation, default - false')
|
|
45
|
-
.option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
|
|
46
|
-
.option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
|
|
47
|
-
.option('--raw', 'print processes with hex values and extra keys such as "createdAtHash"')
|
|
48
|
-
.option('--active', 'returns only active process flows')
|
|
49
|
-
.option('--disabled', 'returns only disabled process flows')
|
|
50
|
-
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
if (options.print)
|
|
52
|
-
log(`
|
|
53
|
-
retrieving all process flows from a chain...
|
|
54
|
-
options: ${b(JSON.stringify(options))}
|
|
55
|
-
`);
|
|
56
|
-
try {
|
|
57
|
-
const res = yield getAll(mapOptions(options));
|
|
58
|
-
const transformed = listTransforming(res, options);
|
|
59
|
-
dir(transformed, { depth: null });
|
|
60
|
-
process.exit(0);
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
log(err);
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
program
|
|
68
|
-
.command('create')
|
|
69
|
-
.description('A command for persisting process flows onto the chain')
|
|
70
|
-
.option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')
|
|
71
|
-
.option('--verbose', 'Returns all information about the transation, default - false')
|
|
72
|
-
.option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
|
|
73
|
-
.option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
|
|
74
|
-
.requiredOption('-f, --file <file>', 'path to file containing process flows to loads')
|
|
75
|
-
.requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
|
|
76
|
-
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
-
if (options.print)
|
|
78
|
-
log(`
|
|
79
|
-
attempting to create a process...
|
|
80
|
-
options: ${b(JSON.stringify(options))}
|
|
81
|
-
`);
|
|
82
|
-
const { dryRun, verbose } = options;
|
|
83
|
-
try {
|
|
84
|
-
const data = (yield fs.readFile(options.file)).toString('utf8');
|
|
85
|
-
const loadResult = yield loadProcesses({ data, dryRun, options: mapOptions(options), verbose });
|
|
86
|
-
dir(loadResult.message, { depth: null });
|
|
87
|
-
dir(unwrap(loadResult), { depth: null });
|
|
88
|
-
process.exit(0);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
log(err);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}));
|
|
95
|
-
program
|
|
96
|
-
.command('disable')
|
|
97
|
-
.description('A command for disabling an existing process flows. Required process ID and version')
|
|
98
|
-
.option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')
|
|
99
|
-
.option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost')
|
|
100
|
-
.option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')
|
|
101
|
-
.requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')
|
|
102
|
-
.argument('<id>', 'a valid process id that you would like to disable')
|
|
103
|
-
.argument('<version>', 'a version number of a process')
|
|
104
|
-
.action((id, version, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
if (options.print)
|
|
106
|
-
log(`attempting to disable:\nID:${b(id)}\nVersion:${b(version)}`);
|
|
107
|
-
try {
|
|
108
|
-
const { dryRun } = options;
|
|
109
|
-
const res = unwrap(yield disableProcess(id, parseInt(version), dryRun, mapOptions(options)));
|
|
110
|
-
dir(res, { depth: null });
|
|
111
|
-
process.exit(0);
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
log(err);
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
}));
|
|
118
|
-
program.parse();
|
|
119
|
-
if (!program.option) {
|
|
120
|
-
program.help();
|
|
121
|
-
}
|
|
122
|
-
program.on('command:*', function () {
|
|
123
|
-
log(`
|
|
124
|
-
${r('Invalid command: %s\nSee --help for a list of available commands.')}
|
|
125
|
-
${program.args.join(' ')}`);
|
|
126
|
-
process.exit(127);
|
|
127
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { expect } from 'chai';
|
|
11
|
-
import { utf8ToHex, hexToUtf8 } from '../hex.js';
|
|
12
|
-
import { listTransforming, handleVerbose } from '../index.js';
|
|
13
|
-
import sample from '../../../../tests/fixtures/processes.js';
|
|
14
|
-
const defaultPolkadot = {
|
|
15
|
-
port: '9044',
|
|
16
|
-
user: 'alice',
|
|
17
|
-
host: 'localhost',
|
|
18
|
-
file: './exampleProcess.json',
|
|
19
|
-
};
|
|
20
|
-
describe('utf8ToHex', () => {
|
|
21
|
-
it('converts a utf8 string to hexadecimal', () => {
|
|
22
|
-
expect(utf8ToHex('test123')).to.equal('0x74657374313233');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe('hexToUtf8', () => {
|
|
26
|
-
it('converts a prefixed string to hex', () => {
|
|
27
|
-
expect(hexToUtf8('0x74657374313233')).to.equal('test123');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe('listTranforming', () => {
|
|
31
|
-
it('returns all transformed processes without a program (--verbose=false)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Enabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
33
|
-
const res = listTransforming([enriched], Object.assign(Object.assign({}, defaultPolkadot), { verbose: false }));
|
|
34
|
-
expect(res[0]).to.deep.contain({
|
|
35
|
-
name: '123',
|
|
36
|
-
status: 'Enabled',
|
|
37
|
-
version: 1,
|
|
38
|
-
});
|
|
39
|
-
}));
|
|
40
|
-
it('returns all transformed processes with a program (--verbose=true)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Disabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
42
|
-
const res = listTransforming([enriched], Object.assign(Object.assign({}, defaultPolkadot), { verbose: true }));
|
|
43
|
-
expect(res[0]).to.deep.contain({
|
|
44
|
-
name: '123',
|
|
45
|
-
status: 'Disabled',
|
|
46
|
-
version: 1,
|
|
47
|
-
});
|
|
48
|
-
}));
|
|
49
|
-
it('returns all options active', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Enabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
51
|
-
const res = listTransforming([enriched], Object.assign(Object.assign({}, defaultPolkadot), { active: true }));
|
|
52
|
-
expect(res[0]).to.deep.contain({
|
|
53
|
-
name: '123',
|
|
54
|
-
status: 'Enabled',
|
|
55
|
-
version: 1,
|
|
56
|
-
});
|
|
57
|
-
}));
|
|
58
|
-
it('returns all options disabled but with active true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Disabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
60
|
-
const res = listTransforming([enriched], Object.assign(Object.assign({}, defaultPolkadot), { active: true }));
|
|
61
|
-
expect(res[0]).to.equal(undefined);
|
|
62
|
-
}));
|
|
63
|
-
it('returns all options disabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Disabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
65
|
-
const res = listTransforming([enriched], Object.assign({}, defaultPolkadot));
|
|
66
|
-
expect(res[0]).to.deep.contain({
|
|
67
|
-
name: '123',
|
|
68
|
-
status: 'Disabled',
|
|
69
|
-
version: 1,
|
|
70
|
-
});
|
|
71
|
-
}));
|
|
72
|
-
it('returns all options active with status enabled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Disabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
74
|
-
const res = listTransforming([enriched], Object.assign(Object.assign({}, defaultPolkadot), { active: false }));
|
|
75
|
-
expect(res[0]).to.deep.contain({
|
|
76
|
-
name: '123',
|
|
77
|
-
status: 'Disabled',
|
|
78
|
-
version: 1,
|
|
79
|
-
});
|
|
80
|
-
}));
|
|
81
|
-
it('returns additional properties with raw', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
-
const enriched = Object.assign(Object.assign({}, sample[0]), { name: '123', status: 'Disabled', createdAtHash: 'abc', initialU8aLength: '32' });
|
|
83
|
-
const res = listTransforming([enriched], Object.assign(Object.assign({}, defaultPolkadot), { active: false, raw: true }));
|
|
84
|
-
expect(res[0]).to.deep.contain({
|
|
85
|
-
name: '0x313233',
|
|
86
|
-
status: 'Disabled',
|
|
87
|
-
version: 1,
|
|
88
|
-
createdAtHash: 'abc',
|
|
89
|
-
initialU8aLength: '32',
|
|
90
|
-
});
|
|
91
|
-
}));
|
|
92
|
-
});
|
|
93
|
-
describe('handleVerbose', function () {
|
|
94
|
-
it('should remove program when verbose == false', function () {
|
|
95
|
-
const result = handleVerbose({
|
|
96
|
-
name: 'test',
|
|
97
|
-
status: 'Enabled',
|
|
98
|
-
version: 1,
|
|
99
|
-
program: [],
|
|
100
|
-
}, false);
|
|
101
|
-
expect(result).to.deep.equal({ name: 'test', status: 'Enabled', version: 1 });
|
|
102
|
-
});
|
|
103
|
-
it('should include program when verbose == false', function () {
|
|
104
|
-
const result = handleVerbose({
|
|
105
|
-
name: 'test',
|
|
106
|
-
status: 'Enabled',
|
|
107
|
-
version: 1,
|
|
108
|
-
program: [],
|
|
109
|
-
}, true);
|
|
110
|
-
expect(result).to.deep.equal({ name: 'test', status: 'Enabled', version: 1, program: [] });
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function resetLastSubmittedNonce(): void;
|
|
2
|
-
export declare const createProcessTransaction: (polkadot: Polkadot.Polkadot, processId: Process.Hex, program: Process.Program, options: Polkadot.Options) => Promise<{
|
|
3
|
-
waitForFinal: Promise<Process.Payload>;
|
|
4
|
-
}>;
|
|
5
|
-
export declare const disableProcessTransaction: (polkadot: Polkadot.Polkadot, processId: Process.Hex, version: number, options: Polkadot.Options) => Promise<Process.Payload>;
|
|
6
|
-
type GetAllFn = (options: Polkadot.Options) => Promise<Process.RawPayload[]>;
|
|
7
|
-
export declare const getAll: GetAllFn;
|
|
8
|
-
export declare const getVersion: (polkadot: Polkadot.Polkadot, processId: Process.Hex) => Promise<number>;
|
|
9
|
-
export declare const getProcess: (polkadot: Polkadot.Polkadot, processId: Process.Hex, version: number) => Promise<Process.Payload>;
|
|
10
|
-
export {};
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
11
|
-
if (value !== null && value !== void 0) {
|
|
12
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
13
|
-
var dispose, inner;
|
|
14
|
-
if (async) {
|
|
15
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
16
|
-
dispose = value[Symbol.asyncDispose];
|
|
17
|
-
}
|
|
18
|
-
if (dispose === void 0) {
|
|
19
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
20
|
-
dispose = value[Symbol.dispose];
|
|
21
|
-
if (async) inner = dispose;
|
|
22
|
-
}
|
|
23
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
24
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
25
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
26
|
-
}
|
|
27
|
-
else if (async) {
|
|
28
|
-
env.stack.push({ async: true });
|
|
29
|
-
}
|
|
30
|
-
return value;
|
|
31
|
-
};
|
|
32
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
33
|
-
return function (env) {
|
|
34
|
-
function fail(e) {
|
|
35
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
36
|
-
env.hasError = true;
|
|
37
|
-
}
|
|
38
|
-
var r, s = 0;
|
|
39
|
-
function next() {
|
|
40
|
-
while (r = env.stack.pop()) {
|
|
41
|
-
try {
|
|
42
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
43
|
-
if (r.dispose) {
|
|
44
|
-
var result = r.dispose.call(r.value);
|
|
45
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
46
|
-
}
|
|
47
|
-
else s |= 1;
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
fail(e);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
54
|
-
if (env.hasError) throw env.error;
|
|
55
|
-
}
|
|
56
|
-
return next();
|
|
57
|
-
};
|
|
58
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
59
|
-
var e = new Error(message);
|
|
60
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
61
|
-
});
|
|
62
|
-
import { ProgramError } from '../types/error.js';
|
|
63
|
-
import * as api from '../utils/polkadot.js';
|
|
64
|
-
import { hexToUtf8 } from './hex.js';
|
|
65
|
-
// TODO - refactor to validate payload?
|
|
66
|
-
// for some reason reduce did not work with Process.Program or ProgramStep[] type due to symbol.iterator
|
|
67
|
-
const isProgramValid = (program, out = { ops: 0, restrictions: -1 }) => {
|
|
68
|
-
program.forEach((step) => {
|
|
69
|
-
out = Object.hasOwn(step, 'Op') ? Object.assign(Object.assign({}, out), { ops: out.ops + 1 }) : Object.assign(Object.assign({}, out), { restrictions: out.restrictions + 1 });
|
|
70
|
-
});
|
|
71
|
-
return out.ops === out.restrictions;
|
|
72
|
-
};
|
|
73
|
-
let lastSubmittedNonce = -1;
|
|
74
|
-
export function resetLastSubmittedNonce() {
|
|
75
|
-
lastSubmittedNonce = -1;
|
|
76
|
-
}
|
|
77
|
-
// TODO refactor since api.ts other should be a util
|
|
78
|
-
// since createNodeApi, set's all routes we could use in process.index.ts
|
|
79
|
-
export const createProcessTransaction = (polkadot, processId, program, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
-
const sudo = polkadot.keyring.addFromUri(options.USER_URI);
|
|
81
|
-
const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock;
|
|
82
|
-
if (!isProgramValid(program))
|
|
83
|
-
throw new ProgramError('invalid program');
|
|
84
|
-
let resolve = () => { };
|
|
85
|
-
let reject = () => { };
|
|
86
|
-
const result = new Promise((res, rej) => {
|
|
87
|
-
resolve = res;
|
|
88
|
-
reject = rej;
|
|
89
|
-
});
|
|
90
|
-
try {
|
|
91
|
-
const nextTxPoolNonce = (yield polkadot.api.rpc.system.accountNextIndex(sudo.publicKey)).toNumber();
|
|
92
|
-
const nonce = Math.max(nextTxPoolNonce, lastSubmittedNonce + 1);
|
|
93
|
-
lastSubmittedNonce = nonce;
|
|
94
|
-
const unsub = yield polkadot.api.tx.sudo
|
|
95
|
-
.sudo(polkadot.api.tx.processValidation.createProcess(processId, program))
|
|
96
|
-
.signAndSend(sudo, { nonce }, (result) => {
|
|
97
|
-
if (result.status.isFinalized) {
|
|
98
|
-
const { event } = result.events.find(({ event: { method } }) => method === 'ProcessCreated');
|
|
99
|
-
const data = event.data;
|
|
100
|
-
const newProcess = {
|
|
101
|
-
name: data[0].toHuman(),
|
|
102
|
-
version: data[1].toNumber(),
|
|
103
|
-
status: 'Enabled',
|
|
104
|
-
program,
|
|
105
|
-
};
|
|
106
|
-
unsub();
|
|
107
|
-
resolve(newProcess);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
if (supportsManualSeal) {
|
|
111
|
-
yield polkadot.api.rpc.engine.createBlock(true, true);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
reject(err);
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
waitForFinal: result,
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
export const disableProcessTransaction = (polkadot, processId, version, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
const sudo = polkadot.keyring.addFromUri(options.USER_URI);
|
|
123
|
-
const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock;
|
|
124
|
-
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
-
try {
|
|
126
|
-
const nextTxPoolNonce = (yield polkadot.api.rpc.system.accountNextIndex(sudo.publicKey)).toNumber();
|
|
127
|
-
const nonce = Math.max(nextTxPoolNonce, lastSubmittedNonce + 1);
|
|
128
|
-
lastSubmittedNonce = nonce;
|
|
129
|
-
const unsub = yield polkadot.api.tx.sudo
|
|
130
|
-
.sudo(polkadot.api.tx.processValidation.disableProcess(processId, version))
|
|
131
|
-
.signAndSend(sudo, { nonce }, (result) => {
|
|
132
|
-
if (result.status.isFinalized) {
|
|
133
|
-
const { event } = result.events.find(({ event: { method } }) => method === 'ProcessDisabled');
|
|
134
|
-
const data = event.data;
|
|
135
|
-
const disabledProcess = {
|
|
136
|
-
name: data[0].toHuman(),
|
|
137
|
-
version: data[1].toNumber(),
|
|
138
|
-
status: 'Disabled',
|
|
139
|
-
};
|
|
140
|
-
unsub();
|
|
141
|
-
resolve(disabledProcess);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
if (supportsManualSeal) {
|
|
145
|
-
yield polkadot.api.rpc.engine.createBlock(true, true);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
reject(err);
|
|
150
|
-
}
|
|
151
|
-
}));
|
|
152
|
-
});
|
|
153
|
-
export const getAll = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
155
|
-
try {
|
|
156
|
-
const polkadot = __addDisposableResource(env_1, yield api.createNodeApi(options), true);
|
|
157
|
-
const processesRaw = yield polkadot.api.query.processValidation.processModel.entries();
|
|
158
|
-
return processesRaw.map(([idRaw, data]) => {
|
|
159
|
-
const id = idRaw.toHuman();
|
|
160
|
-
return {
|
|
161
|
-
name: id[0],
|
|
162
|
-
version: parseInt(id[1]),
|
|
163
|
-
status: data.status.toString(),
|
|
164
|
-
program: data.program.toJSON(),
|
|
165
|
-
createdAtHash: data.createdAtHash.toHuman(),
|
|
166
|
-
initialU8aLength: data.initialU8aLength,
|
|
167
|
-
};
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
catch (e_1) {
|
|
171
|
-
env_1.error = e_1;
|
|
172
|
-
env_1.hasError = true;
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
const result_1 = __disposeResources(env_1);
|
|
176
|
-
if (result_1)
|
|
177
|
-
yield result_1;
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
export const getVersion = (polkadot, processId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
-
const id = yield polkadot.api.query.processValidation.versionModel(processId);
|
|
182
|
-
return Number(id.toString());
|
|
183
|
-
});
|
|
184
|
-
export const getProcess = (polkadot, processId, version) => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
-
const result = yield polkadot.api.query.processValidation.processModel(processId, version);
|
|
186
|
-
const data = Object(result.toHuman());
|
|
187
|
-
return {
|
|
188
|
-
name: hexToUtf8(processId),
|
|
189
|
-
version,
|
|
190
|
-
status: data.status,
|
|
191
|
-
program: data.program,
|
|
192
|
-
};
|
|
193
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { CliInputParseError } from '../types/error.js';
|
|
2
|
-
export declare const defaultOptions: Polkadot.Options;
|
|
3
|
-
export declare const sanitizeInput: (data: string) => Process.Result<{
|
|
4
|
-
name: string;
|
|
5
|
-
}[], CliInputParseError>;
|
|
6
|
-
export declare const loadProcesses: ({ data, options, dryRun, verbose, }: {
|
|
7
|
-
data: string;
|
|
8
|
-
options: Polkadot.Options;
|
|
9
|
-
dryRun?: boolean;
|
|
10
|
-
verbose?: boolean;
|
|
11
|
-
}) => Promise<Process.Response>;
|
|
12
|
-
export declare const listTransforming: (res: Process.RawPayload[], options: Process.CLIOptions) => {
|
|
13
|
-
program?: any;
|
|
14
|
-
name: string;
|
|
15
|
-
version: number;
|
|
16
|
-
status: "Enabled" | "Disabled" | "Enabled (dry-run)" | "Disabled (dry-run)";
|
|
17
|
-
}[];
|
|
18
|
-
export declare const handleVerbose: (res: Process.Payload, verbose: boolean) => Process.Payload;
|
|
19
|
-
export declare const createProcess: (processRaw: Process.CliProcessInput, dryRun: boolean | undefined, polkadot: Polkadot.Polkadot, options?: Polkadot.Options, verbose?: boolean) => Promise<{
|
|
20
|
-
waitForFinalised: Promise<Process.ProcessResponse>;
|
|
21
|
-
}>;
|
|
22
|
-
export declare const disableProcess: (name: string, processVersion: number, dryRun?: boolean, options?: Polkadot.Options) => Promise<Process.ProcessResponse>;
|