@onivoro/server-process 24.14.0 → 24.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-process",
3
- "version": "24.14.0",
3
+ "version": "24.16.0",
4
4
  "type": "commonjs",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -10,5 +10,11 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "tslib": "^2.3.0"
13
- }
13
+ },
14
+ "files": [
15
+ "**/*.js",
16
+ "**/*.d.ts",
17
+ "**/*.js.map",
18
+ "README.md"
19
+ ]
14
20
  }
package/jest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'lib-server-process',
4
- preset: '../../../jest.preset.js',
5
- testEnvironment: 'node',
6
- transform: {
7
- '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8
- },
9
- moduleFileExtensions: ['ts', 'js', 'html'],
10
- coverageDirectory: '../../../coverage/libs/server/process',
11
- };
package/project.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "name": "lib-server-process",
3
- "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/server/process/src",
5
- "projectType": "library",
6
- "targets": {
7
- "build": {
8
- "executor": "@nx/js:tsc",
9
- "outputs": ["{options.outputPath}"],
10
- "options": {
11
- "outputPath": "dist/libs/server/process",
12
- "main": "libs/server/process/src/index.ts",
13
- "tsConfig": "libs/server/process/tsconfig.lib.json",
14
- "assets": [
15
- "libs/server/process/README.md",
16
- "libs/server/process/package.json"
17
- ],
18
- "declaration": true,
19
- "updateBuildableProjectPackageJsonDependencies": true,
20
- "rootDir": "libs/server/process/src"
21
- }
22
- },
23
- "publish": {
24
- "executor": "@nx/js:npm",
25
- "outputs": [],
26
- "dependsOn": ["build"],
27
- "options": {
28
- "packageRoot": "dist/libs/server/process"
29
- }
30
- }
31
- },
32
- "tags": []
33
- }
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
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';
9
- export { spawnPromise } from './lib/spawn-promise';
package/src/lib/docker.ts DELETED
@@ -1,14 +0,0 @@
1
- import { ExecOptions } from "child_process";
2
- import { EncodingOption } from "fs";
3
- import { execRx } from "./exec-rx";
4
-
5
- export class Docker {
6
- constructor(
7
- public readonly containerName: string,
8
- public readonly binaryName: string,
9
- ) { }
10
-
11
- execRx(cmd: string, options?: EncodingOption & ExecOptions, emitStdErr=true) {
12
- return execRx(`docker exec ${this.containerName} ${this.binaryName} ${cmd}`, options, emitStdErr);
13
- }
14
- }
@@ -1,17 +0,0 @@
1
- import { parse } from 'path';
2
- import { execPromise } from './exec-promise';
3
-
4
- describe('execPromise', () => {
5
- it('resolves with stdout', async () => {
6
- const result = await execPromise(`ls ${__dirname}`);
7
- expect(result).toContain(parse(__filename).base);
8
- });
9
-
10
- it('rejects with stderr', async () => {
11
- try {
12
- await execPromise(`ls 'no way jose'`);
13
- } catch (e) {
14
- expect(e.message.replace(/\n/g, ' ')).toContain('No such file or directory');
15
- }
16
- });
17
- });
@@ -1,14 +0,0 @@
1
- import { exec, ExecOptions } from "child_process";
2
- import { EncodingOption } from "fs";
3
-
4
- export function execPromise(cmd: string, options?: EncodingOption & ExecOptions): Promise<any> {
5
- return new Promise((resolve, reject) => {
6
- exec(cmd, options, (err, stdout) => {
7
- if (err) {
8
- reject(err);
9
- } else {
10
- resolve(stdout.toString());
11
- }
12
- });
13
- });
14
- }
@@ -1,9 +0,0 @@
1
- import { ExecOptions } from 'child_process';
2
- import { map } from 'rxjs/operators';
3
- import { execRx } from './exec-rx';
4
-
5
- export const execRxAsJson = (cmd: string, options?: ExecOptions, emitStdErr = true) => {
6
- return execRx(cmd, options, emitStdErr).pipe(
7
- map((s: string) => JSON.parse(s)),
8
- )
9
- };
@@ -1,10 +0,0 @@
1
- import { ExecOptions } from 'child_process';
2
- import { from } from 'rxjs';
3
- import { concatMap } from 'rxjs/operators';
4
- import { execRx } from './exec-rx';
5
-
6
- export const execRxAsLines = (cmd: string, options?: ExecOptions, emitStdErr = true) => {
7
- return execRx(cmd, options, emitStdErr).pipe(
8
- concatMap((s: string) => from(s.split('\n'))),
9
- )
10
- };
@@ -1,22 +0,0 @@
1
- import { execRx } from './exec-rx';
2
- import { of } from 'rxjs';
3
- import { catchError } from 'rxjs/operators';
4
-
5
- describe(execRx.name, () => {
6
- describe('GIVEN command succeeds', () => {
7
- it('returns the stdout', (done) => {
8
- execRx(`cat ${__filename}`).subscribe((d) => {
9
- expect(d).toEqual(expect.stringContaining('execRx worx!'));
10
- done();
11
- }, () => { throw new Error("fail") }
12
- );
13
- });
14
- });
15
-
16
- describe('GIVEN command fails', () => {
17
- it('emits error', (done) => {
18
- execRx(`cat ${__filename + 'blah'}`).pipe(catchError(() => of(done())))
19
- .subscribe();
20
- });
21
- });
22
- });
@@ -1,16 +0,0 @@
1
- import { exec, ExecOptions } from "child_process";
2
- import { EncodingOption } from "fs";
3
- import { Observable } from "rxjs";
4
-
5
- export function execRx(cmd: string, options?: EncodingOption & ExecOptions, emitStdErr=true): Observable<any> {
6
- return new Observable((observer) => {
7
- exec(cmd, options, (err, stdout, stderr) => {
8
- if (err) {
9
- observer.error(err);
10
- } else {
11
- observer.next(`${stdout}${emitStdErr && ` ${stderr}`}`);
12
- observer.complete();
13
- }
14
- });
15
- });
16
- }
package/src/lib/exit.ts DELETED
@@ -1 +0,0 @@
1
- export const exit = (code: number) => process.exit.bind(process, code);
package/src/lib/listen.ts DELETED
@@ -1,12 +0,0 @@
1
- import { Subject } from 'rxjs';
2
-
3
- const stdin = new Subject();
4
- const stdout = new Subject();
5
-
6
- export const listen = () => {
7
-
8
- process.stdin.on('data', d => stdin.next(d));
9
- process.stdin.on('close', () => stdin.complete());
10
-
11
- return { stdout, stdin };
12
- }
package/src/lib/psql.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Docker } from "./docker";
2
- import { execRx } from "./exec-rx";
3
-
4
- const binaryName = 'psql';
5
-
6
- export class PSql {
7
- constructor(public readonly containerName: string = '') { }
8
-
9
- execRx(cmd: string, db: string, username: string) {
10
- const dbOptions = db ? ['-d', db] : [];
11
- const commonArgs = ['-qtAX', '-U', username, ...dbOptions, '-c'].join(' ') + cmd;
12
- return this.containerName
13
- ? (new Docker(this.containerName, binaryName)).execRx(commonArgs)
14
- : execRx([binaryName, commonArgs].join(' '));
15
- }
16
- }
@@ -1,17 +0,0 @@
1
- import { parse } from 'path';
2
- import { spawnPromise } from './spawn-promise';
3
-
4
- describe('spawnPromise', () => {
5
- it('resolves with stdout', async () => {
6
- const result = await spawnPromise(`ls`, [__dirname]);
7
- expect(result).toContain(parse(__filename).base);
8
- });
9
-
10
- it('rejects with stderr', async () => {
11
- try {
12
- await spawnPromise(`ls`, ['no way jose']);
13
- } catch (e) {
14
- expect(e).toContain('No such file or directory');
15
- }
16
- });
17
- });
@@ -1,31 +0,0 @@
1
- import { spawn } from "child_process";
2
-
3
- const data = 'data';
4
-
5
- export function spawnPromise(program: string, args?: string[], options?: any) {
6
- return new Promise((res, rej) => {
7
- let stdout: string[] = [];
8
- let stderr: string[] = [];
9
-
10
- const proc = spawn(program, args, options);
11
-
12
- proc.stdout.on(data, (data) => {
13
- stdout.push(`${data}`);
14
- });
15
-
16
- proc.stderr.on(data, (data) => {
17
- stderr.push(`${data}`);
18
- });
19
-
20
- proc.on('close', (code) => {
21
- if (code) {
22
- rej(stderr.join(' '));
23
- } else {
24
- res(stdout.join(' '));
25
- }
26
-
27
- stdout = undefined as any;
28
- stderr = undefined as any;
29
- });
30
- });
31
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.server.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc"
5
- },
6
- "files": [],
7
- "include": [],
8
- "references": [
9
- {
10
- "path": "./tsconfig.lib.json"
11
- },
12
- {
13
- "path": "./tsconfig.spec.json"
14
- }
15
- ]
16
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "../../dist/libs/server/process",
6
- "declaration": true
7
- },
8
- "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
9
- "include": ["src/**/*.ts"]
10
- }
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "types": [
5
- "jest",
6
- "node"
7
- ]
8
- },
9
- "include": [
10
- "jest.config.ts",
11
- "**/*.test.ts",
12
- "**/*.spec.ts",
13
- "**/*.test.tsx",
14
- "**/*.spec.tsx",
15
- "**/*.test.js",
16
- "**/*.spec.js",
17
- "**/*.test.jsx",
18
- "**/*.spec.jsx",
19
- "**/*.d.ts"
20
- ]
21
- }