Skip to content

Commit

Permalink
feat(types): switch to strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Nov 2, 2021
1 parent eb5cc54 commit d99977e
Show file tree
Hide file tree
Showing 8 changed files with 2,313 additions and 4,207 deletions.
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Instantiate the FTP service
| [services.FTP_POOL] | <code>function</code> | The FTP pool configuration object as given to `generic-pool`. |
| [services.FTP_TIMEOUT] | <code>function</code> | The FTP service timeout as given to `basic-ftp` client constructor |
| [services.FTP_PASSWORD_ENV_NAME] | <code>function</code> | The environment variable name in which to pick-up the FTP password |
| [services.log] | <code>function</code> | A logging function |
| services.log | <code>function</code> | A logging function |
| [services.delay] | <code>function</code> | A service to manage delays |

**Example**
Expand Down
17 changes: 11 additions & 6 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
[//]: # ( )
# Architecture Notes

## Summary

1. [FTP Service](#1-ftp-service)
1. [Pool](#11-pool)
2. [Retry and error casting](#12-retry-and-error-casting)

## FTP Service

## 1. FTP Service

The `ftp` service creates easily usable FTP features
by exposing `list`, `put`, `get` and `delete`
methods and handling any unecessary complexity.

[See in context](./src/index.ts#L42-L47)
[See in context](./src/index.ts#L62-L67)



### Pool
### 1.1. Pool

The service uses a pool to allow several parallel connections
to a FTP server.

[See in context](./src/index.ts#L125-L129)
[See in context](./src/index.ts#L146-L150)



### Retry and error casting
### 1.2. Retry and error casting

One can configure the FTP service to retry several times
before abandonnating the requested operation.

[See in context](./src/index.ts#L324-L328)
[See in context](./src/index.ts#L354-L358)

7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/ftp-service/blob/master/LICENSE)
[![Coverage Status](https://coveralls.io/repos/github/nfroidure/ftp-service/badge.svg?branch=master)](https://coveralls.io/github/nfroidure/ftp-service?branch=master)
[![NPM version](https://badge.fury.io/js/ftp-service.svg)](https://npmjs.org/package/ftp-service)
[![Dependency Status](https://david-dm.org/nfroidure/ftp-service.svg)](https://david-dm.org/nfroidure/ftp-service)
[![devDependency Status](https://david-dm.org/nfroidure/ftp-service/dev-status.svg)](https://david-dm.org/nfroidure/ftp-service#info=devDependencies)
[![Package Quality](https://npm.packagequality.com/shield/ftp-service.svg)](https://packagequality.com/#?package=ftp-service)
[![Code Climate](https://codeclimate.com/github/nfroidure/ftp-service.svg)](https://codeclimate.com/github/nfroidure/ftp-service)


[//]: # (::contents:start)
Expand All @@ -40,7 +35,7 @@ Instantiate the FTP service
| [services.FTP_POOL] | <code>function</code> | The FTP pool configuration object as given to `generic-pool`. |
| [services.FTP_TIMEOUT] | <code>function</code> | The FTP service timeout as given to `basic-ftp` client constructor |
| [services.FTP_PASSWORD_ENV_NAME] | <code>function</code> | The environment variable name in which to pick-up the FTP password |
| [services.log] | <code>function</code> | A logging function |
| services.log | <code>function</code> | A logging function |
| [services.delay] | <code>function</code> | A service to manage delays |

**Example**
Expand Down
6,259 changes: 2,157 additions & 4,102 deletions package-lock.json

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,37 @@
},
"homepage": "https://github.com/nfroidure/ftp-service#readme",
"dependencies": {
"@types/generic-pool": "^3.1.9",
"@types/generic-pool": "^3.1.10",
"basic-ftp": "^4.6.6",
"common-services": "^9.0.1",
"generic-pool": "^3.7.8",
"knifecycle": "^11.1.1",
"common-services": "^10.0.0",
"generic-pool": "^3.8.2",
"knifecycle": "^12.0.1",
"yerror": "^6.0.1"
},
"devDependencies": {
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.15",
"@babel/eslint-parser": "^7.13.14",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-object-rest-spread": "^7.13.8",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
"@babel/register": "^7.13.14",
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"babel-plugin-knifecycle": "^5.0.1",
"commitizen": "^4.2.3",
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.0",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@babel/register": "^7.16.0",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"commitizen": "^4.2.4",
"conventional-changelog-cli": "^2.1.1",
"coveralls": "^3.1.0",
"coveralls": "^3.1.1",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.23.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"jsarch": "^4.0.1",
"jsdoc-to-markdown": "^7.0.1",
"eslint": "^8.1.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"jsarch": "^5.0.0",
"jsdoc-to-markdown": "^7.1.0",
"metapak": "^4.0.2",
"metapak-nfroidure": "11.0.7",
"prettier": "^2.2.1",
"metapak-nfroidure": "11.1.0",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"typescript": "^4.2.4"
},
Expand Down
44 changes: 33 additions & 11 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path';
import type { FTPConfig } from '.';

describe('FTP service', () => {
const ENV = {};
const CONFIG: FTPConfig = {
FTP: {
host: 'localhost',
Expand All @@ -15,7 +14,7 @@ describe('FTP service', () => {
FTP_TIMEOUT: 30000,
FTP_POOL: {
min: 0,
max: 2,
max: 1,
maxWaitingClients: 10,
evictionRunIntervalMillis: 20,
},
Expand All @@ -33,7 +32,8 @@ describe('FTP service', () => {
const delay = (await initDelayService({})).service;
const ftp = await initFTPService({
...CONFIG,
ENV,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },
delay,
log,
});
Expand All @@ -46,20 +46,23 @@ describe('FTP service', () => {
"logCalls": Array [],
}
`);

ftp.dispose && (await ftp.dispose());
});

test('should list files', async () => {
const delay = (await initDelayService({})).service;
const { service: ftp, dispose } = await initFTPService({
...CONFIG,
ENV,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD2',
ENV: { FTP_PASSWORD2: 'password' },
delay,
log,
});

const files = await ftp.list('/');

await dispose();
dispose && (await dispose());

expect({
files,
Expand All @@ -84,6 +87,10 @@ describe('FTP service', () => {
"debug",
"💾 - Shutting down the FTP pool.",
],
Array [
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
Expand All @@ -93,14 +100,15 @@ describe('FTP service', () => {
const delay = (await initDelayService({})).service;
const { service: ftp, dispose } = await initFTPService({
...CONFIG,
ENV,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },
delay,
log,
});

const fileContent = (await ftp.get('/testfile.txt')).toString();

await dispose();
dispose && (await dispose());

expect({
fileContent,
Expand All @@ -123,6 +131,10 @@ describe('FTP service', () => {
"debug",
"💾 - Shutting down the FTP pool.",
],
Array [
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
Expand All @@ -132,7 +144,8 @@ describe('FTP service', () => {
const delay = (await initDelayService({})).service;
const { service: ftp, dispose } = await initFTPService({
...CONFIG,
ENV,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: '' },
delay,
log,
});
Expand All @@ -155,7 +168,7 @@ describe('FTP service', () => {
});
});

await dispose();
dispose && (await dispose());

expect({
exists,
Expand Down Expand Up @@ -189,6 +202,10 @@ describe('FTP service', () => {
"debug",
"💾 - Shutting down the FTP pool.",
],
Array [
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
Expand All @@ -198,7 +215,8 @@ describe('FTP service', () => {
const delay = (await initDelayService({})).service;
const { service: ftp, dispose } = await initFTPService({
...CONFIG,
ENV,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },
delay,
log,
});
Expand All @@ -223,7 +241,7 @@ describe('FTP service', () => {
path.join(__dirname, '..', 'fixtures', 'testfile3.txt'),
);

await dispose();
dispose && (await dispose());

expect({
exists,
Expand All @@ -247,6 +265,10 @@ describe('FTP service', () => {
"debug",
"💾 - Shutting down the FTP pool.",
],
Array [
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
Expand Down

0 comments on commit d99977e

Please sign in to comment.