@onivoro/server-process 1.13.0 → 1.14.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/cjs/index.d.ts +8 -0
- package/cjs/index.js +19 -0
- package/cjs/lib/docker.d.ts +9 -0
- package/cjs/lib/docker.js +14 -0
- package/cjs/lib/exec-promise.d.ts +4 -0
- package/cjs/lib/exec-promise.js +17 -0
- package/cjs/lib/exec-rx-as-json.d.ts +3 -0
- package/cjs/lib/exec-rx-as-json.js +8 -0
- package/cjs/lib/exec-rx-as-lines.d.ts +3 -0
- package/cjs/lib/exec-rx-as-lines.js +9 -0
- package/cjs/lib/exec-rx.d.ts +5 -0
- package/cjs/lib/exec-rx.js +19 -0
- package/cjs/lib/exec-rx.spec.d.ts +1 -0
- package/cjs/lib/exec-rx.spec.js +21 -0
- package/cjs/lib/exit.d.ts +1 -0
- package/cjs/lib/exit.js +4 -0
- package/cjs/lib/listen.d.ts +5 -0
- package/cjs/lib/listen.js +11 -0
- package/cjs/lib/psql.d.ts +6 -0
- package/cjs/lib/psql.js +20 -0
- package/package.json +5 -3
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Docker } from './lib/docker';
|
|
2
|
+
export { execPromise } from './lib/exec-promise';
|
|
3
|
+
export { execRxAsJson } from './lib/exec-rx-as-json';
|
|
4
|
+
export { execRxAsLines } from './lib/exec-rx-as-lines';
|
|
5
|
+
export { execRx } from './lib/exec-rx';
|
|
6
|
+
export { exit } from './lib/exit';
|
|
7
|
+
export { listen } from './lib/listen';
|
|
8
|
+
export { PSql } from './lib/psql';
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PSql = exports.listen = exports.exit = exports.execRx = exports.execRxAsLines = exports.execRxAsJson = exports.execPromise = exports.Docker = void 0;
|
|
4
|
+
var docker_1 = require("./lib/docker");
|
|
5
|
+
Object.defineProperty(exports, "Docker", { enumerable: true, get: function () { return docker_1.Docker; } });
|
|
6
|
+
var exec_promise_1 = require("./lib/exec-promise");
|
|
7
|
+
Object.defineProperty(exports, "execPromise", { enumerable: true, get: function () { return exec_promise_1.execPromise; } });
|
|
8
|
+
var exec_rx_as_json_1 = require("./lib/exec-rx-as-json");
|
|
9
|
+
Object.defineProperty(exports, "execRxAsJson", { enumerable: true, get: function () { return exec_rx_as_json_1.execRxAsJson; } });
|
|
10
|
+
var exec_rx_as_lines_1 = require("./lib/exec-rx-as-lines");
|
|
11
|
+
Object.defineProperty(exports, "execRxAsLines", { enumerable: true, get: function () { return exec_rx_as_lines_1.execRxAsLines; } });
|
|
12
|
+
var exec_rx_1 = require("./lib/exec-rx");
|
|
13
|
+
Object.defineProperty(exports, "execRx", { enumerable: true, get: function () { return exec_rx_1.execRx; } });
|
|
14
|
+
var exit_1 = require("./lib/exit");
|
|
15
|
+
Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_1.exit; } });
|
|
16
|
+
var listen_1 = require("./lib/listen");
|
|
17
|
+
Object.defineProperty(exports, "listen", { enumerable: true, get: function () { return listen_1.listen; } });
|
|
18
|
+
var psql_1 = require("./lib/psql");
|
|
19
|
+
Object.defineProperty(exports, "PSql", { enumerable: true, get: function () { return psql_1.PSql; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ExecOptions } from "child_process";
|
|
3
|
+
import { BaseEncodingOptions } from "fs";
|
|
4
|
+
export declare class Docker {
|
|
5
|
+
readonly containerName: string;
|
|
6
|
+
readonly binaryName: string;
|
|
7
|
+
constructor(containerName: string, binaryName: string);
|
|
8
|
+
execRx(cmd: string, options?: BaseEncodingOptions & ExecOptions, emitStdErr?: boolean): import("rxjs").Observable<any>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Docker = void 0;
|
|
4
|
+
const exec_rx_1 = require("./exec-rx");
|
|
5
|
+
class Docker {
|
|
6
|
+
constructor(containerName, binaryName) {
|
|
7
|
+
this.containerName = containerName;
|
|
8
|
+
this.binaryName = binaryName;
|
|
9
|
+
}
|
|
10
|
+
execRx(cmd, options, emitStdErr = true) {
|
|
11
|
+
return exec_rx_1.execRx(`docker exec ${this.containerName} ${this.binaryName} ${cmd}`, options, emitStdErr);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Docker = Docker;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execPromise = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
function execPromise(cmd, options) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
child_process_1.exec(cmd, options, (err, stdout) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
reject(err);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
resolve(stdout.toString());
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.execPromise = execPromise;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execRxAsJson = void 0;
|
|
4
|
+
const operators_1 = require("rxjs/operators");
|
|
5
|
+
const exec_rx_1 = require("./exec-rx");
|
|
6
|
+
exports.execRxAsJson = (cmd, options, emitStdErr = true) => {
|
|
7
|
+
return exec_rx_1.execRx(cmd, options, emitStdErr).pipe(operators_1.map((s) => JSON.parse(s)));
|
|
8
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execRxAsLines = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const exec_rx_1 = require("./exec-rx");
|
|
7
|
+
exports.execRxAsLines = (cmd, options, emitStdErr = true) => {
|
|
8
|
+
return exec_rx_1.execRx(cmd, options, emitStdErr).pipe(operators_1.concatMap((s) => rxjs_1.from(s.split('\n'))));
|
|
9
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ExecOptions } from "child_process";
|
|
3
|
+
import { BaseEncodingOptions } from 'fs';
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
export declare function execRx(cmd: string, options?: BaseEncodingOptions & ExecOptions, emitStdErr?: boolean): Observable<any>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execRx = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
function execRx(cmd, options, emitStdErr = true) {
|
|
7
|
+
return new rxjs_1.Observable((observer) => {
|
|
8
|
+
child_process_1.exec(cmd, options, (err, stdout, stderr) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
observer.error(err);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
observer.next(`${stdout}${emitStdErr && ` ${stderr}`}`);
|
|
14
|
+
observer.complete();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.execRx = execRx;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exec_rx_1 = require("./exec-rx");
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
describe(exec_rx_1.execRx.name, () => {
|
|
7
|
+
describe('GIVEN command succeeds', () => {
|
|
8
|
+
it('returns the stdout', (done) => {
|
|
9
|
+
exec_rx_1.execRx(`cat ${__filename}`).subscribe((d) => {
|
|
10
|
+
expect(d).toEqual(expect.stringContaining('execRx worx!'));
|
|
11
|
+
done();
|
|
12
|
+
}, fail);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
describe('GIVEN command fails', () => {
|
|
16
|
+
it('emits error', (done) => {
|
|
17
|
+
exec_rx_1.execRx(`cat ${__filename + 'blah'}`).pipe(operators_1.catchError(() => rxjs_1.of(done())))
|
|
18
|
+
.subscribe();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const exit: (code: number) => () => never;
|
package/cjs/lib/exit.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listen = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const stdin = new rxjs_1.Subject();
|
|
6
|
+
const stdout = new rxjs_1.Subject();
|
|
7
|
+
exports.listen = () => {
|
|
8
|
+
process.stdin.on('data', d => stdin.next(d));
|
|
9
|
+
process.stdin.on('close', () => stdin.complete());
|
|
10
|
+
return { stdout, stdin };
|
|
11
|
+
};
|
package/cjs/lib/psql.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PSql = void 0;
|
|
4
|
+
const docker_1 = require("./docker");
|
|
5
|
+
const exec_rx_1 = require("./exec-rx");
|
|
6
|
+
const binaryName = 'psql';
|
|
7
|
+
class PSql {
|
|
8
|
+
constructor(containerName) {
|
|
9
|
+
this.containerName = containerName;
|
|
10
|
+
this.container = new docker_1.Docker(this.containerName, binaryName);
|
|
11
|
+
}
|
|
12
|
+
execRx(cmd, db, username) {
|
|
13
|
+
const dbOptions = db ? ['-d', db] : [];
|
|
14
|
+
const commonArgs = ['-qtAX', '-U', username, ...dbOptions, '-c'].join(' ') + cmd;
|
|
15
|
+
return this.containerName
|
|
16
|
+
? this.container.execRx(commonArgs)
|
|
17
|
+
: exec_rx_1.execRx([binaryName, commonArgs].join(' '));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PSql = PSql;
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onivoro/server-process",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "cjs/index.js",
|
|
6
|
+
"module": "index.js",
|
|
6
7
|
"repository": {
|
|
7
8
|
"url": "https://github.com/onivoro/server-process.git"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "jest",
|
|
11
12
|
"build": "tsc -p tsconfig.json",
|
|
12
|
-
"
|
|
13
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
14
|
+
"release": "rm -rf dist && npm run build && npm run build:cjs && npm version minor && cp package.json dist && cd dist && npm publish --access public"
|
|
13
15
|
},
|
|
14
16
|
"devDependencies": {
|
|
15
17
|
"@types/jest": "^26.0.14",
|