@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.
Files changed (57) hide show
  1. package/build/index.js +95 -0
  2. package/build/index.js.map +1 -0
  3. package/build/lib/process/__tests__/unit.test.js +191 -0
  4. package/build/lib/process/__tests__/unit.test.js.map +1 -0
  5. package/build/lib/process/api.js +206 -0
  6. package/build/lib/process/api.js.map +1 -0
  7. package/build/lib/process/constants.js +5 -0
  8. package/build/lib/process/constants.js.map +1 -0
  9. package/build/{src/lib → lib}/process/hex.js +4 -2
  10. package/build/lib/process/hex.js.map +1 -0
  11. package/build/lib/process/index.js +304 -0
  12. package/build/lib/process/index.js.map +1 -0
  13. package/build/{src/lib → lib}/types/error.js +9 -6
  14. package/build/lib/types/error.js.map +1 -0
  15. package/build/lib/types/polkadot.d.js +2 -0
  16. package/build/lib/types/polkadot.d.js.map +1 -0
  17. package/build/lib/types/process.d.js +2 -0
  18. package/build/lib/types/process.d.js.map +1 -0
  19. package/build/lib/types/validation.js +179 -0
  20. package/build/lib/types/validation.js.map +1 -0
  21. package/build/lib/utils/polkadot.js +26 -0
  22. package/build/lib/utils/polkadot.js.map +1 -0
  23. package/build/version.js +5 -0
  24. package/build/version.js.map +1 -0
  25. package/package.json +12 -10
  26. package/build/package.json +0 -65
  27. package/build/src/index.d.ts +0 -2
  28. package/build/src/index.js +0 -127
  29. package/build/src/lib/process/_tests_/unit.test.d.ts +0 -1
  30. package/build/src/lib/process/_tests_/unit.test.js +0 -112
  31. package/build/src/lib/process/api.d.ts +0 -10
  32. package/build/src/lib/process/api.js +0 -193
  33. package/build/src/lib/process/constants.d.ts +0 -3
  34. package/build/src/lib/process/constants.js +0 -3
  35. package/build/src/lib/process/hex.d.ts +0 -2
  36. package/build/src/lib/process/index.d.ts +0 -22
  37. package/build/src/lib/process/index.js +0 -311
  38. package/build/src/lib/types/error.d.ts +0 -14
  39. package/build/src/lib/types/validation.d.ts +0 -3592
  40. package/build/src/lib/types/validation.js +0 -128
  41. package/build/src/lib/utils/polkadot.d.ts +0 -6
  42. package/build/src/lib/utils/polkadot.js +0 -28
  43. package/build/src/version.d.ts +0 -2
  44. package/build/src/version.js +0 -3
  45. package/build/tests/fixtures/processes.d.ts +0 -281
  46. package/build/tests/fixtures/processes.js +0 -1066
  47. package/build/tests/fixtures/programs.d.ts +0 -14
  48. package/build/tests/fixtures/programs.js +0 -211
  49. package/build/tests/helpers/containers.d.ts +0 -7
  50. package/build/tests/helpers/containers.js +0 -40
  51. package/build/tests/helpers/substrateHelper.d.ts +0 -2
  52. package/build/tests/helpers/substrateHelper.js +0 -100
  53. package/build/tests/integration/command-functions.test.d.ts +0 -1
  54. package/build/tests/integration/command-functions.test.js +0 -414
  55. package/build/tests/integration/without-manual-seal.test.d.ts +0 -1
  56. package/build/tests/integration/without-manual-seal.test.js +0 -52
  57. package/build/tsconfig.tsbuildinfo +0 -1
package/build/index.js ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env -S node --no-warnings
2
+ import fs from 'fs/promises';
3
+ import chalk from 'chalk';
4
+ import { Command } from 'commander';
5
+ import { loadProcesses, disableProcess, listTransforming } from './lib/process/index.js';
6
+ import { getAll } from './lib/process/api.js';
7
+ import cliVersion from './version.js';
8
+ const unwrap = (res)=>{
9
+ if (res.type === 'ok') return res.result;
10
+ else throw res.error;
11
+ };
12
+ const { log, dir } = console;
13
+ const program = new Command();
14
+ const { red: r, blue: b } = {
15
+ red: (txt)=>chalk.redBright(txt),
16
+ blue: (txt)=>chalk.blueBright(txt)
17
+ };
18
+ const mapOptions = (options)=>({
19
+ API_HOST: options.host,
20
+ API_PORT: parseInt(options.port),
21
+ USER_URI: options.user
22
+ });
23
+ // TODO nice to have, a local config file for substrate host details e.g. name, port, address
24
+ // so no need to parse every time calling a command, or ability to set
25
+ program.name('process management').description('a command line interface for managing chain processes').version(cliVersion, '-v, --version', 'output current version').helpOption('--help', 'display help for command') //override -h
26
+ ;
27
+ program.command('list').description('A command for listing all active process flows').option('-v, --verbose', 'Returns all information about the transation, default - false').option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost').option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944').option('--raw', 'print processes with hex values and extra keys such as "createdAtHash"').option('--active', 'returns only active process flows').option('--disabled', 'returns only disabled process flows').action(async (options)=>{
28
+ if (options.print) log(`
29
+ retrieving all process flows from a chain...
30
+ options: ${b(JSON.stringify(options))}
31
+ `);
32
+ try {
33
+ const res = await getAll(mapOptions(options));
34
+ const transformed = listTransforming(res, options);
35
+ dir(transformed, {
36
+ depth: null
37
+ });
38
+ process.exit(0);
39
+ } catch (err) {
40
+ log(err);
41
+ process.exit(1);
42
+ }
43
+ });
44
+ program.command('create').description('A command for persisting process flows onto the chain').option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false').option('--verbose', 'Returns all information about the transation, default - false').option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost').option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944').requiredOption('-f, --file <file>', 'path to file containing process flows to loads').requiredOption('-u, --user <user>', 'specify substrate blockchain user URI').action(async (options)=>{
45
+ if (options.print) log(`
46
+ attempting to create a process...
47
+ options: ${b(JSON.stringify(options))}
48
+ `);
49
+ const { dryRun, verbose } = options;
50
+ try {
51
+ const data = (await fs.readFile(options.file)).toString('utf8');
52
+ const loadResult = await loadProcesses({
53
+ data,
54
+ dryRun,
55
+ options: mapOptions(options),
56
+ verbose
57
+ });
58
+ dir(loadResult.message, {
59
+ depth: null
60
+ });
61
+ dir(unwrap(loadResult), {
62
+ depth: null
63
+ });
64
+ process.exit(0);
65
+ } catch (err) {
66
+ log(err);
67
+ process.exit(1);
68
+ }
69
+ });
70
+ program.command('disable').description('A command for disabling an existing process flows. Required process ID and version').option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false').option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - "localhost"', 'localhost').option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944').requiredOption('-u, --user <user>', 'specify substrate blockchain user URI').argument('<id>', 'a valid process id that you would like to disable').argument('<version>', 'a version number of a process').action(async (id, version, options)=>{
71
+ if (options.print) log(`attempting to disable:\nID:${b(id)}\nVersion:${b(version)}`);
72
+ try {
73
+ const { dryRun } = options;
74
+ const res = unwrap(await disableProcess(id, parseInt(version), dryRun, mapOptions(options)));
75
+ dir(res, {
76
+ depth: null
77
+ });
78
+ process.exit(0);
79
+ } catch (err) {
80
+ log(err);
81
+ process.exit(1);
82
+ }
83
+ });
84
+ program.parse();
85
+ if (!program.option) {
86
+ program.help();
87
+ }
88
+ program.on('command:*', function() {
89
+ log(`
90
+ ${r('Invalid command: %s\nSee --help for a list of available commands.')}
91
+ ${program.args.join(' ')}`);
92
+ process.exit(127);
93
+ });
94
+
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env -S node --no-warnings\n\nimport fs from 'fs/promises'\n\nimport chalk from 'chalk'\nimport { Command } from 'commander'\n\nimport { loadProcesses, disableProcess, listTransforming } from './lib/process/index.js'\nimport { getAll } from './lib/process/api.js'\nimport cliVersion from './version.js'\n\nconst unwrap = <T, E>(res: Process.Result<T, E>): T => {\n if (res.type === 'ok') return res.result\n else throw res.error\n}\n\nconst { log, dir } = console\nconst program = new Command()\nconst { red: r, blue: b } = {\n red: (txt: string) => chalk.redBright(txt),\n blue: (txt: string) => chalk.blueBright(txt),\n}\n\nconst mapOptions = (options: Process.CLIOptions): Polkadot.Options => ({\n API_HOST: options.host,\n API_PORT: parseInt(options.port),\n USER_URI: options.user,\n})\n\n// TODO nice to have, a local config file for substrate host details e.g. name, port, address\n// so no need to parse every time calling a command, or ability to set\nprogram\n .name('process management')\n .description('a command line interface for managing chain processes')\n .version(cliVersion, '-v, --version', 'output current version')\n .helpOption('--help', 'display help for command') //override -h\n\nprogram\n .command('list')\n .description('A command for listing all active process flows')\n .option('-v, --verbose', 'Returns all information about the transation, default - false')\n .option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - \"localhost\"', 'localhost')\n .option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')\n .option('--raw', 'print processes with hex values and extra keys such as \"createdAtHash\"')\n .option('--active', 'returns only active process flows')\n .option('--disabled', 'returns only disabled process flows')\n .action(async (options: Process.CLIOptions) => {\n if (options.print)\n log(`\n retrieving all process flows from a chain...\n options: ${b(JSON.stringify(options))}\n `)\n try {\n const res: Process.RawPayload[] = await getAll(mapOptions(options))\n\n const transformed = listTransforming(res, options)\n dir(transformed, { depth: null })\n\n process.exit(0)\n } catch (err) {\n log(err)\n process.exit(1)\n }\n })\n\nprogram\n .command('create')\n .description('A command for persisting process flows onto the chain')\n .option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')\n .option('--verbose', 'Returns all information about the transation, default - false')\n .option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - \"localhost\"', 'localhost')\n .option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')\n .requiredOption('-f, --file <file>', 'path to file containing process flows to loads')\n .requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')\n .action(async (options: Process.CLIOptions) => {\n if (options.print)\n log(`\n attempting to create a process...\n options: ${b(JSON.stringify(options))}\n `)\n const { dryRun, verbose } = options\n try {\n const data = (await fs.readFile(options.file)).toString('utf8')\n const loadResult = await loadProcesses({ data, dryRun, options: mapOptions(options), verbose })\n dir(loadResult.message, { depth: null })\n dir(unwrap(loadResult), { depth: null })\n process.exit(0)\n } catch (err) {\n log(err)\n process.exit(1)\n }\n })\n\nprogram\n .command('disable')\n .description('A command for disabling an existing process flows. Required process ID and version')\n .option('--dryRun', 'to validate process and response locally before persisting on the chain, default - false')\n .option('-h, --host <host>', 'substrate blockchain host address or FQDM, default - \"localhost\"', 'localhost')\n .option('-p, --port <port>', 'specify host port number if it is not a default, default - 9944', '9944')\n .requiredOption('-u, --user <user>', 'specify substrate blockchain user URI')\n .argument('<id>', 'a valid process id that you would like to disable')\n .argument('<version>', 'a version number of a process')\n .action(async (id: string, version: string, options: Process.CLIOptions) => {\n if (options.print) log(`attempting to disable:\\nID:${b(id)}\\nVersion:${b(version)}`)\n try {\n const { dryRun } = options\n const res = unwrap(await disableProcess(id, parseInt(version), dryRun, mapOptions(options)))\n dir(res, { depth: null })\n\n process.exit(0)\n } catch (err) {\n log(err)\n process.exit(1)\n }\n })\n\nprogram.parse()\nif (!program.option) {\n program.help()\n}\n\nprogram.on('command:*', function () {\n log(`\n ${r('Invalid command: %s\\nSee --help for a list of available commands.')}\n ${program.args.join(' ')}`)\n process.exit(127)\n})\n"],"names":["fs","chalk","Command","loadProcesses","disableProcess","listTransforming","getAll","cliVersion","unwrap","res","type","result","error","log","dir","console","program","red","r","blue","b","txt","redBright","blueBright","mapOptions","options","API_HOST","host","API_PORT","parseInt","port","USER_URI","user","name","description","version","helpOption","command","option","action","print","JSON","stringify","transformed","depth","process","exit","err","requiredOption","dryRun","verbose","data","readFile","file","toString","loadResult","message","argument","id","parse","help","on","args","join"],"mappings":";AAEA,OAAOA,QAAQ,cAAa;AAE5B,OAAOC,WAAW,QAAO;AACzB,SAASC,OAAO,QAAQ,YAAW;AAEnC,SAASC,aAAa,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,yBAAwB;AACxF,SAASC,MAAM,QAAQ,uBAAsB;AAC7C,OAAOC,gBAAgB,eAAc;AAErC,MAAMC,SAAS,CAAOC;IACpB,IAAIA,IAAIC,IAAI,KAAK,MAAM,OAAOD,IAAIE,MAAM;SACnC,MAAMF,IAAIG,KAAK;AACtB;AAEA,MAAM,EAAEC,GAAG,EAAEC,GAAG,EAAE,GAAGC;AACrB,MAAMC,UAAU,IAAId;AACpB,MAAM,EAAEe,KAAKC,CAAC,EAAEC,MAAMC,CAAC,EAAE,GAAG;IAC1BH,KAAK,CAACI,MAAgBpB,M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9B,QAAQ2C,KAAK;AACb,IAAI,CAAC3C,QAAQsB,MAAM,EAAE;IACnBtB,QAAQ4C,IAAI;AACd;AAEA5C,QAAQ6C,EAAE,CAAC,aAAa;IACtBhD,IAAI,CAAC;IACH,EAAEK,EAAE,qEAAqE;IACzE,EAAEF,QAAQ8C,IAAI,CAACC,IAAI,CAAC,MAAM;IAC5BlB,QAAQC,IAAI,CAAC;AACf"}
@@ -0,0 +1,191 @@
1
+ import { expect } from 'chai';
2
+ import { utf8ToHex, hexToUtf8 } from '../hex.js';
3
+ import { listTransforming, handleVerbose } from '../index.js';
4
+ import sample from '../../../../test/fixtures/processes.js';
5
+ const defaultPolkadot = {
6
+ port: '9044',
7
+ user: 'alice',
8
+ host: 'localhost',
9
+ file: './exampleProcess.json'
10
+ };
11
+ describe('utf8ToHex', ()=>{
12
+ it('converts a utf8 string to hexadecimal', ()=>{
13
+ expect(utf8ToHex('test123')).to.equal('0x74657374313233');
14
+ });
15
+ });
16
+ describe('hexToUtf8', ()=>{
17
+ it('converts a prefixed string to hex', ()=>{
18
+ expect(hexToUtf8('0x74657374313233')).to.equal('test123');
19
+ });
20
+ });
21
+ describe('listTranforming', ()=>{
22
+ it('returns all transformed processes without a program (--verbose=false)', async ()=>{
23
+ const enriched = {
24
+ ...sample[0],
25
+ name: '123',
26
+ status: 'Enabled',
27
+ createdAtHash: 'abc',
28
+ initialU8aLength: '32'
29
+ };
30
+ const res = listTransforming([
31
+ enriched
32
+ ], {
33
+ ...defaultPolkadot,
34
+ verbose: false
35
+ });
36
+ expect(res[0]).to.deep.contain({
37
+ name: '123',
38
+ status: 'Enabled',
39
+ version: 1
40
+ });
41
+ });
42
+ it('returns all transformed processes with a program (--verbose=true)', async ()=>{
43
+ const enriched = {
44
+ ...sample[0],
45
+ name: '123',
46
+ status: 'Disabled',
47
+ createdAtHash: 'abc',
48
+ initialU8aLength: '32'
49
+ };
50
+ const res = listTransforming([
51
+ enriched
52
+ ], {
53
+ ...defaultPolkadot,
54
+ verbose: true
55
+ });
56
+ expect(res[0]).to.deep.contain({
57
+ name: '123',
58
+ status: 'Disabled',
59
+ version: 1
60
+ });
61
+ });
62
+ it('returns all options active', async ()=>{
63
+ const enriched = {
64
+ ...sample[0],
65
+ name: '123',
66
+ status: 'Enabled',
67
+ createdAtHash: 'abc',
68
+ initialU8aLength: '32'
69
+ };
70
+ const res = listTransforming([
71
+ enriched
72
+ ], {
73
+ ...defaultPolkadot,
74
+ active: true
75
+ });
76
+ expect(res[0]).to.deep.contain({
77
+ name: '123',
78
+ status: 'Enabled',
79
+ version: 1
80
+ });
81
+ });
82
+ it('returns all options disabled but with active true', async ()=>{
83
+ const enriched = {
84
+ ...sample[0],
85
+ name: '123',
86
+ status: 'Disabled',
87
+ createdAtHash: 'abc',
88
+ initialU8aLength: '32'
89
+ };
90
+ const res = listTransforming([
91
+ enriched
92
+ ], {
93
+ ...defaultPolkadot,
94
+ active: true
95
+ });
96
+ expect(res[0]).to.equal(undefined);
97
+ });
98
+ it('returns all options disabled', async ()=>{
99
+ const enriched = {
100
+ ...sample[0],
101
+ name: '123',
102
+ status: 'Disabled',
103
+ createdAtHash: 'abc',
104
+ initialU8aLength: '32'
105
+ };
106
+ const res = listTransforming([
107
+ enriched
108
+ ], {
109
+ ...defaultPolkadot
110
+ });
111
+ expect(res[0]).to.deep.contain({
112
+ name: '123',
113
+ status: 'Disabled',
114
+ version: 1
115
+ });
116
+ });
117
+ it('returns all options active with status enabled', async ()=>{
118
+ const enriched = {
119
+ ...sample[0],
120
+ name: '123',
121
+ status: 'Disabled',
122
+ createdAtHash: 'abc',
123
+ initialU8aLength: '32'
124
+ };
125
+ const res = listTransforming([
126
+ enriched
127
+ ], {
128
+ ...defaultPolkadot,
129
+ active: false
130
+ });
131
+ expect(res[0]).to.deep.contain({
132
+ name: '123',
133
+ status: 'Disabled',
134
+ version: 1
135
+ });
136
+ });
137
+ it('returns additional properties with raw', async ()=>{
138
+ const enriched = {
139
+ ...sample[0],
140
+ name: '123',
141
+ status: 'Disabled',
142
+ createdAtHash: 'abc',
143
+ initialU8aLength: '32'
144
+ };
145
+ const res = listTransforming([
146
+ enriched
147
+ ], {
148
+ ...defaultPolkadot,
149
+ active: false,
150
+ raw: true
151
+ });
152
+ expect(res[0]).to.deep.contain({
153
+ name: '0x313233',
154
+ status: 'Disabled',
155
+ version: 1,
156
+ createdAtHash: 'abc',
157
+ initialU8aLength: '32'
158
+ });
159
+ });
160
+ });
161
+ describe('handleVerbose', function() {
162
+ it('should remove program when verbose == false', function() {
163
+ const result = handleVerbose({
164
+ name: 'test',
165
+ status: 'Enabled',
166
+ version: 1,
167
+ program: []
168
+ }, false);
169
+ expect(result).to.deep.equal({
170
+ name: 'test',
171
+ status: 'Enabled',
172
+ version: 1
173
+ });
174
+ });
175
+ it('should include program when verbose == false', function() {
176
+ const result = handleVerbose({
177
+ name: 'test',
178
+ status: 'Enabled',
179
+ version: 1,
180
+ program: []
181
+ }, true);
182
+ expect(result).to.deep.equal({
183
+ name: 'test',
184
+ status: 'Enabled',
185
+ version: 1,
186
+ program: []
187
+ });
188
+ });
189
+ });
190
+
191
+ //# sourceMappingURL=unit.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/lib/process/__tests__/unit.test.ts"],"sourcesContent":["import { expect } from 'chai'\n\nimport { utf8ToHex, hexToUtf8 } from '../hex.js'\nimport { listTransforming, handleVerbose } from '../index.js'\n\nimport sample from '../../../../test/fixtures/processes.js'\n\nconst defaultPolkadot: Process.CLIOptions = {\n port: '9044',\n user: 'alice',\n host: 'localhost',\n file: './exampleProcess.json',\n}\n\ndescribe('utf8ToHex', () => {\n it('converts a utf8 string to hexadecimal', () => {\n expect(utf8ToHex('test123')).to.equal('0x74657374313233')\n })\n})\n\ndescribe('hexToUtf8', () => {\n it('converts a prefixed string to hex', () => {\n expect(hexToUtf8('0x74657374313233')).to.equal('test123')\n })\n})\n\ndescribe('listTranforming', () => {\n it('returns all transformed processes without a program (--verbose=false)', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Enabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot, verbose: false })\n\n expect(res[0]).to.deep.contain({\n name: '123',\n status: 'Enabled',\n version: 1,\n })\n })\n\n it('returns all transformed processes with a program (--verbose=true)', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Disabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot, verbose: true })\n\n expect(res[0]).to.deep.contain({\n name: '123',\n status: 'Disabled',\n version: 1,\n })\n })\n\n it('returns all options active', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Enabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot, active: true })\n\n expect(res[0]).to.deep.contain({\n name: '123',\n status: 'Enabled',\n version: 1,\n })\n })\n\n it('returns all options disabled but with active true', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Disabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot, active: true })\n\n expect(res[0]).to.equal(undefined)\n })\n\n it('returns all options disabled', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Disabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot })\n\n expect(res[0]).to.deep.contain({\n name: '123',\n status: 'Disabled',\n version: 1,\n })\n })\n\n it('returns all options active with status enabled', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Disabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot, active: false })\n\n expect(res[0]).to.deep.contain({\n name: '123',\n status: 'Disabled',\n version: 1,\n })\n })\n\n it('returns additional properties with raw', async () => {\n const enriched: Process.RawPayload = {\n ...sample[0],\n name: '123',\n status: 'Disabled',\n createdAtHash: 'abc',\n initialU8aLength: '32',\n }\n\n const res = listTransforming([enriched], { ...defaultPolkadot, active: false, raw: true })\n\n expect(res[0]).to.deep.contain({\n name: '0x313233',\n status: 'Disabled',\n version: 1,\n createdAtHash: 'abc',\n initialU8aLength: '32',\n })\n })\n})\n\ndescribe('handleVerbose', function () {\n it('should remove program when verbose == false', function () {\n const result = handleVerbose(\n {\n name: 'test',\n status: 'Enabled',\n version: 1,\n program: [],\n },\n false\n )\n expect(result).to.deep.equal({ name: 'test', status: 'Enabled', version: 1 })\n })\n\n it('should include program when verbose == false', function () {\n const result = handleVerbose(\n {\n name: 'test',\n status: 'Enabled',\n version: 1,\n program: [],\n },\n true\n )\n expect(result).to.deep.equal({ name: 'test', status: 'Enabled', version: 1, program: [] })\n })\n})\n"],"names":["expect","utf8ToHex","hexToUtf8","listTransforming","handleVerbose","sample","defaultPolkadot","port","user","host","file","describe","it","to","equal","enriched","name","status","createdAtHash","initialU8aLength","res","verbose","deep","contain","version","active","undefined","raw","result","program"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAM;AAE7B,SAASC,SAAS,EAAEC,SAAS,QAAQ,YAAW;AAChD,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,cAAa;AAE7D,OAAOC,YAAY,yCAAwC;AAE3D,MAAMC,kBAAsC;IAC1CC,MAAM;IACNC,MAAM;IACNC,MAAM;IACNC,MAAM;AACR;AAEAC,SAAS,aAAa;IACpBC,GAAG,yCAAyC;QAC1CZ,OAAOC,UAAU,YAAYY,EAAE,CAACC,KAAK,CAAC;IACxC;AACF;AAEAH,SAAS,aAAa;IACpBC,GAAG,qCAAqC;QACtCZ,OAAOE,UAAU,qBAAqBW,EAAE,CAACC,KAAK,CAAC;IACjD;AACF;AAEAH,SAAS,mBAAmB;IAC1BC,GAAG,yEAAyE;QAC1E,MAAMG,WA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YACNC,QAAQ;YACRO,SAAS;YACTK,SAAS,EAAE;QACb,GACA;QAEF7B,OAAO4B,QAAQf,EAAE,CAACS,IAAI,CAACR,KAAK,CAAC;YAAEE,MAAM;YAAQC,QAAQ;YAAWO,SAAS;QAAE;IAC7E;IAEAZ,GAAG,gDAAgD;QACjD,MAAMgB,SAASxB,cACb;YACEY,MAAM;YACNC,QAAQ;YACRO,SAAS;YACTK,SAAS,EAAE;QACb,GACA;QAEF7B,OAAO4B,QAAQf,EAAE,CAACS,IAAI,CAACR,KAAK,CAAC;YAAEE,MAAM;YAAQC,QAAQ;YAAWO,SAAS;YAAGK,SAAS,EAAE;QAAC;IAC1F;AACF"}
@@ -0,0 +1,206 @@
1
+ function _ts_add_disposable_resource(env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() {
16
+ try {
17
+ inner.call(this);
18
+ } catch (e) {
19
+ return Promise.reject(e);
20
+ }
21
+ };
22
+ env.stack.push({
23
+ value: value,
24
+ dispose: dispose,
25
+ async: async
26
+ });
27
+ } else if (async) {
28
+ env.stack.push({
29
+ async: true
30
+ });
31
+ }
32
+ return value;
33
+ }
34
+ function _ts_dispose_resources(env) {
35
+ var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
36
+ var e = new Error(message);
37
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
38
+ };
39
+ return (_ts_dispose_resources = function _ts_dispose_resources(env) {
40
+ function fail(e) {
41
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
42
+ env.hasError = true;
43
+ }
44
+ var r, s = 0;
45
+ function next() {
46
+ while(r = env.stack.pop()){
47
+ try {
48
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
49
+ if (r.dispose) {
50
+ var result = r.dispose.call(r.value);
51
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
52
+ fail(e);
53
+ return next();
54
+ });
55
+ } else s |= 1;
56
+ } catch (e) {
57
+ fail(e);
58
+ }
59
+ }
60
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
61
+ if (env.hasError) throw env.error;
62
+ }
63
+ return next();
64
+ })(env);
65
+ }
66
+ import { ProgramError } from '../types/error.js';
67
+ import * as api from '../utils/polkadot.js';
68
+ import { hexToUtf8 } from './hex.js';
69
+ // TODO - refactor to validate payload?
70
+ // for some reason reduce did not work with Process.Program or ProgramStep[] type due to symbol.iterator
71
+ const isProgramValid = (program, out = {
72
+ ops: 0,
73
+ restrictions: -1
74
+ })=>{
75
+ program.forEach((step)=>{
76
+ out = Object.hasOwn(step, 'Op') ? {
77
+ ...out,
78
+ ops: out.ops + 1
79
+ } : {
80
+ ...out,
81
+ restrictions: out.restrictions + 1
82
+ };
83
+ });
84
+ return out.ops === out.restrictions;
85
+ };
86
+ let lastSubmittedNonce = -1;
87
+ export function resetLastSubmittedNonce() {
88
+ lastSubmittedNonce = -1;
89
+ }
90
+ // TODO refactor since api.ts other should be a util
91
+ // since createNodeApi, set's all routes we could use in process.index.ts
92
+ export const createProcessTransaction = async (polkadot, processId, program, options)=>{
93
+ const sudo = polkadot.keyring.addFromUri(options.USER_URI);
94
+ const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock;
95
+ if (!isProgramValid(program)) throw new ProgramError('invalid program');
96
+ let resolve = ()=>{};
97
+ let reject = ()=>{};
98
+ const result = new Promise((res, rej)=>{
99
+ resolve = res;
100
+ reject = rej;
101
+ });
102
+ try {
103
+ const nextTxPoolNonce = (await polkadot.api.rpc.system.accountNextIndex(sudo.publicKey)).toNumber();
104
+ const nonce = Math.max(nextTxPoolNonce, lastSubmittedNonce + 1);
105
+ lastSubmittedNonce = nonce;
106
+ const unsub = await polkadot.api.tx.sudo.sudo(polkadot.api.tx.processValidation.createProcess(processId, program)).signAndSend(sudo, {
107
+ nonce
108
+ }, (result)=>{
109
+ if (result.status.isFinalized) {
110
+ const { event } = result.events.find(({ event: { method } })=>method === 'ProcessCreated');
111
+ const data = event.data;
112
+ const newProcess = {
113
+ name: data[0].toHuman(),
114
+ version: data[1].toNumber(),
115
+ status: 'Enabled',
116
+ program
117
+ };
118
+ unsub();
119
+ resolve(newProcess);
120
+ }
121
+ });
122
+ if (supportsManualSeal) {
123
+ await polkadot.api.rpc.engine.createBlock(true, true);
124
+ }
125
+ } catch (err) {
126
+ reject(err);
127
+ }
128
+ return {
129
+ waitForFinal: result
130
+ };
131
+ };
132
+ export const disableProcessTransaction = async (polkadot, processId, version, options)=>{
133
+ const sudo = polkadot.keyring.addFromUri(options.USER_URI);
134
+ const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock;
135
+ return new Promise(async (resolve, reject)=>{
136
+ try {
137
+ const nextTxPoolNonce = (await polkadot.api.rpc.system.accountNextIndex(sudo.publicKey)).toNumber();
138
+ const nonce = Math.max(nextTxPoolNonce, lastSubmittedNonce + 1);
139
+ lastSubmittedNonce = nonce;
140
+ const unsub = await polkadot.api.tx.sudo.sudo(polkadot.api.tx.processValidation.disableProcess(processId, version)).signAndSend(sudo, {
141
+ nonce
142
+ }, (result)=>{
143
+ if (result.status.isFinalized) {
144
+ const { event } = result.events.find(({ event: { method } })=>method === 'ProcessDisabled');
145
+ const data = event.data;
146
+ const disabledProcess = {
147
+ name: data[0].toHuman(),
148
+ version: data[1].toNumber(),
149
+ status: 'Disabled'
150
+ };
151
+ unsub();
152
+ resolve(disabledProcess);
153
+ }
154
+ });
155
+ if (supportsManualSeal) {
156
+ await polkadot.api.rpc.engine.createBlock(true, true);
157
+ }
158
+ } catch (err) {
159
+ reject(err);
160
+ }
161
+ });
162
+ };
163
+ export const getAll = async (options)=>{
164
+ const env = {
165
+ stack: [],
166
+ error: void 0,
167
+ hasError: false
168
+ };
169
+ try {
170
+ const polkadot = _ts_add_disposable_resource(env, await api.createNodeApi(options), true);
171
+ const processesRaw = await polkadot.api.query.processValidation.processModel.entries();
172
+ return processesRaw.map(([idRaw, data])=>{
173
+ const id = idRaw.toHuman();
174
+ return {
175
+ name: id[0],
176
+ version: parseInt(id[1]),
177
+ status: data.status.toString(),
178
+ program: data.program.toJSON(),
179
+ createdAtHash: data.createdAtHash.toHuman(),
180
+ initialU8aLength: data.initialU8aLength
181
+ };
182
+ });
183
+ } catch (e) {
184
+ env.error = e;
185
+ env.hasError = true;
186
+ } finally{
187
+ const result = _ts_dispose_resources(env);
188
+ if (result) await result;
189
+ }
190
+ };
191
+ export const getVersion = async (polkadot, processId)=>{
192
+ const id = await polkadot.api.query.processValidation.versionModel(processId);
193
+ return Number(id.toString());
194
+ };
195
+ export const getProcess = async (polkadot, processId, version)=>{
196
+ const result = await polkadot.api.query.processValidation.processModel(processId, version);
197
+ const data = Object(result.toHuman());
198
+ return {
199
+ name: hexToUtf8(processId),
200
+ version,
201
+ status: data.status,
202
+ program: data.program
203
+ };
204
+ };
205
+
206
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/process/api.ts"],"sourcesContent":["import { ProgramError } from '../types/error.js'\nimport * as api from '../utils/polkadot.js'\nimport { hexToUtf8 } from './hex.js'\n\n// TODO - refactor to validate payload?\n// for some reason reduce did not work with Process.Program or ProgramStep[] type due to symbol.iterator\nconst isProgramValid = (program: Process.Program, out = { ops: 0, restrictions: -1 }): Boolean => {\n program.forEach((step: Process.ProgramStep) => {\n out = Object.hasOwn(step, 'Op') ? { ...out, ops: out.ops + 1 } : { ...out, restrictions: out.restrictions + 1 }\n })\n\n return out.ops === out.restrictions\n}\n\nlet lastSubmittedNonce: number = -1\nexport function resetLastSubmittedNonce() {\n lastSubmittedNonce = -1\n}\n\n// TODO refactor since api.ts other should be a util\n// since createNodeApi, set's all routes we could use in process.index.ts\nexport const createProcessTransaction = async (\n polkadot: Polkadot.Polkadot,\n processId: Process.Hex,\n program: Process.Program,\n options: Polkadot.Options\n): Promise<{ waitForFinal: Promise<Process.Payload> }> => {\n const sudo = polkadot.keyring.addFromUri(options.USER_URI)\n const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock\n\n if (!isProgramValid(program)) throw new ProgramError('invalid program')\n\n let resolve: (value: Process.Payload) => void = () => {}\n let reject: (reason: any) => void = () => {}\n const result: Promise<Process.Payload> = new Promise((res, rej) => {\n resolve = res\n reject = rej\n })\n\n try {\n const nextTxPoolNonce = (await polkadot.api.rpc.system.accountNextIndex(sudo.publicKey)).toNumber()\n const nonce = Math.max(nextTxPoolNonce, lastSubmittedNonce + 1)\n lastSubmittedNonce = nonce\n\n const unsub = await polkadot.api.tx.sudo\n .sudo(polkadot.api.tx.processValidation.createProcess(processId, program))\n .signAndSend(sudo, { nonce }, (result: any) => {\n if (result.status.isFinalized) {\n const { event } = result.events.find(\n ({ event: { method } }: { event: { method: string } }) => method === 'ProcessCreated'\n )\n\n const data = event.data\n const newProcess: Process.Payload = {\n name: data[0].toHuman(),\n version: data[1].toNumber(),\n status: 'Enabled',\n program,\n }\n unsub()\n resolve(newProcess)\n }\n })\n if (supportsManualSeal) {\n await polkadot.api.rpc.engine.createBlock(true, true)\n }\n } catch (err) {\n reject(err)\n }\n\n return {\n waitForFinal: result,\n }\n}\n\nexport const disableProcessTransaction = async (\n polkadot: Polkadot.Polkadot,\n processId: Process.Hex,\n version: number,\n options: Polkadot.Options\n): Promise<Process.Payload> => {\n const sudo = polkadot.keyring.addFromUri(options.USER_URI)\n const supportsManualSeal = !!polkadot.api.rpc.engine.createBlock\n\n return new Promise(async (resolve, reject) => {\n try {\n const nextTxPoolNonce = (await polkadot.api.rpc.system.accountNextIndex(sudo.publicKey)).toNumber()\n const nonce = Math.max(nextTxPoolNonce, lastSubmittedNonce + 1)\n lastSubmittedNonce = nonce\n\n const unsub = await polkadot.api.tx.sudo\n .sudo(polkadot.api.tx.processValidation.disableProcess(processId, version))\n .signAndSend(sudo, { nonce }, (result: any) => {\n if (result.status.isFinalized) {\n const { event } = result.events.find(\n ({ event: { method } }: { event: { method: string } }) => method === 'ProcessDisabled'\n )\n\n const data = event.data\n const disabledProcess: Process.Payload = {\n name: data[0].toHuman(),\n version: data[1].toNumber(),\n status: 'Disabled',\n }\n\n unsub()\n resolve(disabledProcess)\n }\n })\n if (supportsManualSeal) {\n await polkadot.api.rpc.engine.createBlock(true, true)\n }\n } catch (err) {\n reject(err)\n }\n })\n}\n\n// TODO sort types for all functions if time allows\n// validate ids?\ntype GetAllFn = (options: Polkadot.Options) => Promise<Process.RawPayload[]>\n\nexport const getAll: GetAllFn = async (options) => {\n await using polkadot = await api.createNodeApi(options)\n const processesRaw = await polkadot.api.query.processValidation.processModel.entries()\n return processesRaw.map(([idRaw, data]: any) => {\n const id = idRaw.toHuman()\n return {\n name: id[0],\n version: parseInt(id[1]),\n status: data.status.toString(),\n program: data.program.toJSON(),\n createdAtHash: data.createdAtHash.toHuman(),\n initialU8aLength: data.initialU8aLength,\n }\n })\n}\n\nexport const getVersion = async (polkadot: Polkadot.Polkadot, processId: Process.Hex): Promise<number> => {\n const id = await polkadot.api.query.processValidation.versionModel(processId)\n return Number(id.toString())\n}\n\nexport const getProcess = async (\n polkadot: Polkadot.Polkadot,\n processId: Process.Hex,\n version: number\n): Promise<Process.Payload> => {\n const result = await polkadot.api.query.processValidation.processModel(processId, version)\n const data = Object(result.toHuman())\n return {\n name: hexToUtf8(processId),\n version,\n status: data.status,\n program: data.program,\n }\n}\n"],"names":["ProgramError","api","hexToUtf8","isProgramValid","program","out","ops","restrictions","forEach","step","Object","hasOwn","lastSubmittedNonce","resetLastSubmittedNonce","createProcessTransaction","polkadot","processId","options","sudo","keyring","addFromUri","USER_URI","supportsManualSeal","rpc","engine","createBlock","resolve","reject","result","Promise","res","rej","nextTxPoolNonce","system","accountNextIndex","publicKey","toNumber","nonce","Math","max","unsub","tx","processValidation","createProcess","signAndSend","status","isFinalized","event","events","find","method","data","newProcess","name","toHuman","version","err","waitForFinal","disableProcessTransaction","disableProcess","disabledProcess","getAll","createNodeApi","processesRaw","query","processModel","entries","map","idRaw","id","parseInt","toString","toJSON","createdAtHash","initialU8aLength","getVersion","versionModel","Number","getProcess"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,YAAYC,SAAS,uBAAsB;AAC3C,SAASC,SAAS,QAAQ,WAAU;AAEpC,uCAAuC;AACvC,wGAAwG;AACxG,MAAMC,iBAAiB,CAACC,SAA0BC,MAAM;IAAEC,KAAK;IAAGC,cAAc,CAAC;AAAE,CAAC;IAClFH,QAAQI,OAAO,CAAC,CAACC;QACfJ,MAAMK,OAAOC,MAAM,CAACF,MAAM,QAAQ;YAAE,GAAGJ,GAAG;YAAEC,KAAKD,IAAIC,GAAG,GAAG;QAAE,IAAI;YAAE,GAAGD,GAAG;YAAEE,cAAcF,IAAIE,YAAY,GAAG;QAAE;IAChH;IAEA,OAAOF,IAAIC,GAAG,KAAKD,IAAIE,YAAY;AACrC;AAEA,IAAIK,qBAA6B,CAAC;AAClC,OAAO,SAASC;IACdD,qBAAqB,CAAC;AACxB;AAEA,oDAAoD;AACpD,yEAAyE;AACzE,OAAO,MAAME,2BAA2B,OACtCC,UACAC,WACAZ,SACAa;IAEA,MAAMC,OAAOH,SAASI,OAAO,CAACC,UAAU,CAACH,QAAQI,QAAQ;IACzD,MAAMC,qBAAqB,CAAC,CAACP,SAASd,GAAG,CAACsB,GAAG,CAACC,MAAM,CAACC,WAAW;IA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,SAAmB,OAAO5C;;;;;;;cACzBF,4CAAW,MAAMd,IAAI6D,aAAa,CAAC7C;QAC/C,MAAM8C,eAAe,MAAMhD,SAASd,GAAG,CAAC+D,KAAK,CAACtB,iBAAiB,CAACuB,YAAY,CAACC,OAAO;QACpF,OAAOH,aAAaI,GAAG,CAAC,CAAC,CAACC,OAAOjB,KAAU;YACzC,MAAMkB,KAAKD,MAAMd,OAAO;YACxB,OAAO;gBACLD,MAAMgB,EAAE,CAAC,EAAE;gBACXd,SAASe,SAASD,EAAE,CAAC,EAAE;gBACvBxB,QAAQM,KAAKN,MAAM,CAAC0B,QAAQ;gBAC5BnE,SAAS+C,KAAK/C,OAAO,CAACoE,MAAM;gBAC5BC,eAAetB,KAAKsB,aAAa,CAACnB,OAAO;gBACzCoB,kBAAkBvB,KAAKuB,gBAAgB;YACzC;QACF;;;;;;;;AACF,EAAC;AAED,OAAO,MAAMC,aAAa,OAAO5D,UAA6BC;IAC5D,MAAMqD,KAAK,MAAMtD,SAASd,GAAG,CAAC+D,KAAK,CAACtB,iBAAiB,CAACkC,YAAY,CAAC5D;IACnE,OAAO6D,OAAOR,GAAGE,QAAQ;AAC3B,EAAC;AAED,OAAO,MAAMO,aAAa,OACxB/D,UACAC,WACAuC;IAEA,MAAM3B,SAAS,MAAMb,SAASd,GAAG,CAAC+D,KAAK,CAACtB,iBAAiB,CAACuB,YAAY,CAACjD,WAAWuC;IAClF,MAAMJ,OAAOzC,OAAOkB,OAAO0B,OAAO;IAClC,OAAO;QACLD,MAAMnD,UAAUc;QAChBuC;QACAV,QAAQM,KAAKN,MAAM;QACnBzC,SAAS+C,KAAK/C,OAAO;IACvB;AACF,EAAC"}
@@ -0,0 +1,5 @@
1
+ export class Constants {
2
+ static PROCESS_ID_LENGTH = 32;
3
+ }
4
+
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/process/constants.ts"],"sourcesContent":["export abstract class Constants {\n static readonly PROCESS_ID_LENGTH: number = 32\n}\n"],"names":["Constants","PROCESS_ID_LENGTH"],"mappings":"AAAA,OAAO,MAAeA;IACpB,OAAgBC,oBAA4B,GAAE;AAChD"}
@@ -1,9 +1,11 @@
1
- export const utf8ToHex = (str) => {
1
+ export const utf8ToHex = (str)=>{
2
2
  const buffer = Buffer.from(str, 'utf8');
3
3
  const bufferHex = buffer.toString('hex');
4
4
  return `0x${bufferHex}`;
5
5
  };
6
- export const hexToUtf8 = (str) => {
6
+ export const hexToUtf8 = (str)=>{
7
7
  const stripped = str.substring(2);
8
8
  return Buffer.from(stripped, 'hex').toString('utf8');
9
9
  };
10
+
11
+ //# sourceMappingURL=hex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/process/hex.ts"],"sourcesContent":["export const utf8ToHex = (str: string): Process.Hex => {\n const buffer = Buffer.from(str, 'utf8')\n const bufferHex = buffer.toString('hex')\n return `0x${bufferHex}`\n}\n\nexport const hexToUtf8 = (str: Process.Hex) => {\n const stripped = str.substring(2)\n return Buffer.from(stripped, 'hex').toString('utf8')\n}\n"],"names":["utf8ToHex","str","buffer","Buffer","from","bufferHex","toString","hexToUtf8","stripped","substring"],"mappings":"AAAA,OAAO,MAAMA,YAAY,CAACC;IACxB,MAAMC,SAASC,OAAOC,IAAI,CAACH,KAAK;IAChC,MAAMI,YAAYH,OAAOI,QAAQ,CAAC;IAClC,OAAO,CAAC,EAAE,EAAED,WAAW;AACzB,EAAC;AAED,OAAO,MAAME,YAAY,CAACN;IACxB,MAAMO,WAAWP,IAAIQ,SAAS,CAAC;IAC/B,OAAON,OAAOC,IAAI,CAACI,UAAU,OAAOF,QAAQ,CAAC;AAC/C,EAAC"}