@onivoro/server-process 1.12.0 → 1.16.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.
Files changed (41) hide show
  1. package/{index.d.ts → cjs/index.d.ts} +0 -0
  2. package/cjs/index.js +19 -0
  3. package/{lib → cjs/lib}/docker.d.ts +0 -0
  4. package/cjs/lib/docker.js +14 -0
  5. package/{lib → cjs/lib}/exec-promise.d.ts +0 -0
  6. package/cjs/lib/exec-promise.js +17 -0
  7. package/{lib → cjs/lib}/exec-rx-as-json.d.ts +0 -0
  8. package/cjs/lib/exec-rx-as-json.js +8 -0
  9. package/{lib → cjs/lib}/exec-rx-as-lines.d.ts +0 -0
  10. package/cjs/lib/exec-rx-as-lines.js +9 -0
  11. package/{lib → cjs/lib}/exec-rx.d.ts +0 -0
  12. package/cjs/lib/exec-rx.js +19 -0
  13. package/{lib → cjs/lib}/exec-rx.spec.d.ts +0 -0
  14. package/cjs/lib/exec-rx.spec.js +21 -0
  15. package/{lib → cjs/lib}/exit.d.ts +0 -0
  16. package/cjs/lib/exit.js +4 -0
  17. package/{lib → cjs/lib}/listen.d.ts +0 -0
  18. package/cjs/lib/listen.js +11 -0
  19. package/{lib → cjs/lib}/psql.d.ts +0 -0
  20. package/cjs/lib/psql.js +20 -0
  21. package/{index.js → mjs/index.d.ts} +0 -0
  22. package/mjs/index.js +8 -0
  23. package/mjs/lib/docker.d.ts +9 -0
  24. package/{lib → mjs/lib}/docker.js +0 -0
  25. package/mjs/lib/exec-promise.d.ts +4 -0
  26. package/{lib → mjs/lib}/exec-promise.js +0 -0
  27. package/mjs/lib/exec-rx-as-json.d.ts +3 -0
  28. package/{lib → mjs/lib}/exec-rx-as-json.js +0 -0
  29. package/mjs/lib/exec-rx-as-lines.d.ts +3 -0
  30. package/{lib → mjs/lib}/exec-rx-as-lines.js +0 -0
  31. package/mjs/lib/exec-rx.d.ts +5 -0
  32. package/{lib → mjs/lib}/exec-rx.js +0 -0
  33. package/mjs/lib/exec-rx.spec.d.ts +1 -0
  34. package/{lib → mjs/lib}/exec-rx.spec.js +0 -0
  35. package/mjs/lib/exit.d.ts +1 -0
  36. package/{lib → mjs/lib}/exit.js +0 -0
  37. package/mjs/lib/listen.d.ts +5 -0
  38. package/{lib → mjs/lib}/listen.js +0 -0
  39. package/mjs/lib/psql.d.ts +6 -0
  40. package/{lib → mjs/lib}/psql.js +0 -0
  41. package/package.json +7 -4
File without changes
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; } });
File without changes
@@ -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;
File without changes
@@ -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;
File without changes
@@ -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
+ };
File without changes
@@ -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
+ };
File without changes
@@ -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;
File without changes
@@ -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
+ });
File without changes
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exit = void 0;
4
+ exports.exit = (code) => process.exit.bind(process, code);
File without changes
@@ -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
+ };
File without changes
@@ -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;
File without changes
package/mjs/index.js 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';
@@ -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
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import { ExecOptions } from "child_process";
3
+ import { BaseEncodingOptions } from 'fs';
4
+ export declare function execPromise(cmd: string, options?: BaseEncodingOptions & ExecOptions): Promise<any>;
File without changes
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { ExecOptions } from 'child_process';
3
+ export declare const execRxAsJson: (cmd: string, options?: ExecOptions | undefined, emitStdErr?: boolean) => import("rxjs").Observable<any>;
File without changes
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { ExecOptions } from 'child_process';
3
+ export declare const execRxAsLines: (cmd: string, options?: ExecOptions | undefined, emitStdErr?: boolean) => import("rxjs").Observable<string>;
File without changes
@@ -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>;
File without changes
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export declare const exit: (code: number) => () => never;
File without changes
@@ -0,0 +1,5 @@
1
+ import { Subject } from 'rxjs';
2
+ export declare const listen: () => {
3
+ stdout: Subject<unknown>;
4
+ stdin: Subject<unknown>;
5
+ };
File without changes
@@ -0,0 +1,6 @@
1
+ export declare class PSql {
2
+ readonly containerName: string;
3
+ private container;
4
+ constructor(containerName: string);
5
+ execRx(cmd: string, db: string, username: string): import("rxjs").Observable<any>;
6
+ }
File without changes
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@onivoro/server-process",
3
- "version": "1.12.0",
4
- "type": "module",
5
- "main": "index.js",
3
+ "version": "1.16.0",
6
4
  "repository": {
7
5
  "url": "https://github.com/onivoro/server-process.git"
8
6
  },
7
+ "exports": {
8
+ "import": "./mjs/index.js",
9
+ "require": "./cjs/index.js"
10
+ },
9
11
  "scripts": {
10
12
  "test": "jest",
11
13
  "build": "tsc -p tsconfig.json",
12
- "release": "rm -rf dist && npm run build && npm version minor && cp package.json dist && cd dist && npm publish --access public"
14
+ "build:cjs": "tsc -p tsconfig.cjs.json",
15
+ "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
16
  },
14
17
  "devDependencies": {
15
18
  "@types/jest": "^26.0.14",