@toa.io/bridges.bash 0.24.0-alpha.22
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/package.json +26 -0
- package/readme.md +16 -0
- package/source/Algorithm.ts +34 -0
- package/source/Factory.ts +12 -0
- package/source/const.ts +2 -0
- package/source/define.ts +36 -0
- package/source/index.ts +2 -0
- package/transpiled/Algorithm.d.ts +8 -0
- package/transpiled/Algorithm.js +33 -0
- package/transpiled/Algorithm.js.map +1 -0
- package/transpiled/Factory.d.ts +4 -0
- package/transpiled/Factory.js +14 -0
- package/transpiled/Factory.js.map +1 -0
- package/transpiled/const.d.ts +2 -0
- package/transpiled/const.js +6 -0
- package/transpiled/const.js.map +1 -0
- package/transpiled/define.d.ts +3 -0
- package/transpiled/define.js +54 -0
- package/transpiled/define.js.map +1 -0
- package/transpiled/index.d.ts +2 -0
- package/transpiled/index.js +30 -0
- package/transpiled/index.js.map +1 -0
- package/tsconfig.json +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@toa.io/bridges.bash",
|
|
3
|
+
"version": "0.24.0-alpha.22",
|
|
4
|
+
"description": "Toa Bash Bridge",
|
|
5
|
+
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/toa-io/toa#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/toa-io/toa.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/toa-io/toa/issues"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"main": "transpiled/index.js",
|
|
18
|
+
"types": "transpiled/index.d.ts",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"transpile": "tsc"
|
|
21
|
+
},
|
|
22
|
+
"jest": {
|
|
23
|
+
"preset": "ts-jest",
|
|
24
|
+
"testEnvironment": "node"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Bash bridge
|
|
2
|
+
|
|
3
|
+
Allows implementing operations in Bash.
|
|
4
|
+
|
|
5
|
+
Input must be an object which properties will be passed to the script as named arguments with values
|
|
6
|
+
converted to strings.
|
|
7
|
+
Output is a string being the standard output of the script.
|
|
8
|
+
|
|
9
|
+
If the script exits with a non-zero status code,
|
|
10
|
+
the operation will return an `Error` with the message being the standard error output of the script.
|
|
11
|
+
|
|
12
|
+
Operations cannot have access to the state or context. Basically,
|
|
13
|
+
only [computations](/documentation/design.md#special-types) are possible.
|
|
14
|
+
|
|
15
|
+
> While theoretically this bridge may find some use, it is mainly a demonstration of language
|
|
16
|
+
> interoperability.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import util from 'node:util'
|
|
2
|
+
import process from 'node:child_process'
|
|
3
|
+
import { Connector } from '@toa.io/core'
|
|
4
|
+
import type { bridges, Reply } from '@toa.io/core'
|
|
5
|
+
|
|
6
|
+
const exec = util.promisify(process.exec)
|
|
7
|
+
|
|
8
|
+
export class Algorithm extends Connector implements bridges.Algorithm {
|
|
9
|
+
private readonly path: string
|
|
10
|
+
|
|
11
|
+
public constructor (path: string) {
|
|
12
|
+
super()
|
|
13
|
+
this.path = path
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public async mount (): Promise<void> {
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async execute (input: object): Promise<Reply> {
|
|
21
|
+
const args = Object.entries(input).map(([key, value]) => `--${key} ${value}`).join(' ')
|
|
22
|
+
const command = `${this.path}${args === '' ? '' : ` ${args}`}`
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const result = await exec(command)
|
|
26
|
+
|
|
27
|
+
return { output: result.stdout.trim() }
|
|
28
|
+
} catch (error: any) {
|
|
29
|
+
const message: string | undefined = error.stderr?.trim()
|
|
30
|
+
|
|
31
|
+
return { output: new Error(message) }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { Algorithm } from './Algorithm'
|
|
3
|
+
import { DIR, EXT } from './const'
|
|
4
|
+
import type { bridges } from '@toa.io/core'
|
|
5
|
+
|
|
6
|
+
export class Factory implements bridges.Factory {
|
|
7
|
+
public algorithm (root: string, name: string): bridges.Algorithm {
|
|
8
|
+
const path = join(root, DIR, name + EXT)
|
|
9
|
+
|
|
10
|
+
return new Algorithm(path)
|
|
11
|
+
}
|
|
12
|
+
}
|
package/source/const.ts
ADDED
package/source/define.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises'
|
|
2
|
+
import { join, extname } from 'node:path'
|
|
3
|
+
import { DIR, EXT } from './const'
|
|
4
|
+
import type { component } from '@toa.io/norm'
|
|
5
|
+
|
|
6
|
+
export async function operations (root: string): Promise<component.Operations> {
|
|
7
|
+
const path = join(root, DIR)
|
|
8
|
+
const names = await list(path)
|
|
9
|
+
|
|
10
|
+
const promises = names
|
|
11
|
+
.map(async (name) => operation(root, name))
|
|
12
|
+
|
|
13
|
+
const operations = await Promise.all(promises)
|
|
14
|
+
|
|
15
|
+
return operations.reduce<component.Operations>((acc, operation, index) => {
|
|
16
|
+
acc[names[index]] = operation
|
|
17
|
+
|
|
18
|
+
return acc
|
|
19
|
+
}, {})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function operation (root: string, name: string): Promise<component.Operation> {
|
|
23
|
+
const path = join(root, DIR, name + EXT)
|
|
24
|
+
|
|
25
|
+
await fs.access(path, fs.constants.F_OK)
|
|
26
|
+
|
|
27
|
+
return { type: 'computation' }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function list (path: string): Promise<string[]> {
|
|
31
|
+
const files = await fs.readdir(path)
|
|
32
|
+
|
|
33
|
+
return files
|
|
34
|
+
.filter((file) => extname(file) === EXT)
|
|
35
|
+
.map((file) => file.slice(0, -EXT.length))
|
|
36
|
+
}
|
package/source/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Connector } from '@toa.io/core';
|
|
2
|
+
import type { bridges, Reply } from '@toa.io/core';
|
|
3
|
+
export declare class Algorithm extends Connector implements bridges.Algorithm {
|
|
4
|
+
private readonly path;
|
|
5
|
+
constructor(path: string);
|
|
6
|
+
mount(): Promise<void>;
|
|
7
|
+
execute(input: object): Promise<Reply>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Algorithm = void 0;
|
|
7
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
8
|
+
const node_child_process_1 = __importDefault(require("node:child_process"));
|
|
9
|
+
const core_1 = require("@toa.io/core");
|
|
10
|
+
const exec = node_util_1.default.promisify(node_child_process_1.default.exec);
|
|
11
|
+
class Algorithm extends core_1.Connector {
|
|
12
|
+
path;
|
|
13
|
+
constructor(path) {
|
|
14
|
+
super();
|
|
15
|
+
this.path = path;
|
|
16
|
+
}
|
|
17
|
+
async mount() {
|
|
18
|
+
}
|
|
19
|
+
async execute(input) {
|
|
20
|
+
const args = Object.entries(input).map(([key, value]) => `--${key} ${value}`).join(' ');
|
|
21
|
+
const command = `${this.path}${args === '' ? '' : ` ${args}`}`;
|
|
22
|
+
try {
|
|
23
|
+
const result = await exec(command);
|
|
24
|
+
return { output: result.stdout.trim() };
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const message = error.stderr?.trim();
|
|
28
|
+
return { output: new Error(message) };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Algorithm = Algorithm;
|
|
33
|
+
//# sourceMappingURL=Algorithm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Algorithm.js","sourceRoot":"","sources":["../source/Algorithm.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,4EAAwC;AACxC,uCAAwC;AAGxC,MAAM,IAAI,GAAG,mBAAI,CAAC,SAAS,CAAC,4BAAO,CAAC,IAAI,CAAC,CAAA;AAEzC,MAAa,SAAU,SAAQ,gBAAS;IACrB,IAAI,CAAQ;IAE7B,YAAoB,IAAY;QAC9B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,KAAK;IAElB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,KAAa;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACvF,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,CAAA;QAE9D,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAA;YAElC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAA;QACzC,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,OAAO,GAAuB,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,CAAA;YAExD,OAAO,EAAE,MAAM,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAA;QACvC,CAAC;IACH,CAAC;CACF;AA1BD,8BA0BC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Factory = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const Algorithm_1 = require("./Algorithm");
|
|
6
|
+
const const_1 = require("./const");
|
|
7
|
+
class Factory {
|
|
8
|
+
algorithm(root, name) {
|
|
9
|
+
const path = (0, node_path_1.join)(root, const_1.DIR, name + const_1.EXT);
|
|
10
|
+
return new Algorithm_1.Algorithm(path);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Factory = Factory;
|
|
14
|
+
//# sourceMappingURL=Factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;AAAA,yCAAgC;AAChC,2CAAuC;AACvC,mCAAkC;AAGlC,MAAa,OAAO;IACX,SAAS,CAAE,IAAY,EAAE,IAAY;QAC1C,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,IAAI,EAAE,WAAG,EAAE,IAAI,GAAG,WAAG,CAAC,CAAA;QAExC,OAAO,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;CACF;AAND,0BAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../source/const.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG,YAAY,CAAA;AAClB,QAAA,GAAG,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.operation = exports.operations = void 0;
|
|
27
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
28
|
+
const node_path_1 = require("node:path");
|
|
29
|
+
const const_1 = require("./const");
|
|
30
|
+
async function operations(root) {
|
|
31
|
+
const path = (0, node_path_1.join)(root, const_1.DIR);
|
|
32
|
+
const names = await list(path);
|
|
33
|
+
const promises = names
|
|
34
|
+
.map(async (name) => operation(root, name));
|
|
35
|
+
const operations = await Promise.all(promises);
|
|
36
|
+
return operations.reduce((acc, operation, index) => {
|
|
37
|
+
acc[names[index]] = operation;
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
}
|
|
41
|
+
exports.operations = operations;
|
|
42
|
+
async function operation(root, name) {
|
|
43
|
+
const path = (0, node_path_1.join)(root, const_1.DIR, name + const_1.EXT);
|
|
44
|
+
await fs.access(path, fs.constants.F_OK);
|
|
45
|
+
return { type: 'computation' };
|
|
46
|
+
}
|
|
47
|
+
exports.operation = operation;
|
|
48
|
+
async function list(path) {
|
|
49
|
+
const files = await fs.readdir(path);
|
|
50
|
+
return files
|
|
51
|
+
.filter((file) => (0, node_path_1.extname)(file) === const_1.EXT)
|
|
52
|
+
.map((file) => file.slice(0, -const_1.EXT.length));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../source/define.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsC;AACtC,yCAAyC;AACzC,mCAAkC;AAG3B,KAAK,UAAU,UAAU,CAAE,IAAY;IAC5C,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,IAAI,EAAE,WAAG,CAAC,CAAA;IAC5B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAA;IAE9B,MAAM,QAAQ,GAAG,KAAK;SACnB,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAE7C,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAE9C,OAAO,UAAU,CAAC,MAAM,CAAuB,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE;QACvE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,CAAA;QAE7B,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC;AAdD,gCAcC;AAEM,KAAK,UAAU,SAAS,CAAE,IAAY,EAAE,IAAY;IACzD,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,IAAI,EAAE,WAAG,EAAE,IAAI,GAAG,WAAG,CAAC,CAAA;IAExC,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAExC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;AAChC,CAAC;AAND,8BAMC;AAED,KAAK,UAAU,IAAI,CAAE,IAAY;IAC/B,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpC,OAAO,KAAK;SACT,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,KAAK,WAAG,CAAC;SACvC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,WAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.define = exports.Factory = void 0;
|
|
27
|
+
var Factory_1 = require("./Factory");
|
|
28
|
+
Object.defineProperty(exports, "Factory", { enumerable: true, get: function () { return Factory_1.Factory; } });
|
|
29
|
+
exports.define = __importStar(require("./define"));
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,mDAAkC"}
|