From d065b93dc0e583385a5d77a9a2e1113697190ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Sun, 6 Mar 2022 10:35:26 -0300 Subject: [PATCH] refactor: implement config class from utils (#11) * refactor: implement config class from utils * fix: remove @secjs/logger * ci: run test with NODE_TS=true * fix: update @secjs/env --- README.md | 2 +- package-lock.json | 215 +++--------------------------------- package.json | 10 +- src/Drivers/GCSDriver.ts | 9 +- src/Drivers/LocalDriver.ts | 3 +- src/Drivers/S3Driver.ts | 3 +- src/Storage.ts | 5 +- tests/build-storage.spec.ts | 3 - tests/storage-gcs.spec.ts | 3 - tests/storage-local.spec.ts | 7 +- tests/storage-s3.spec.ts | 3 - 11 files changed, 34 insertions(+), 229 deletions(-) diff --git a/README.md b/README.md index e6992ff..f16a11b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ The intention behind this repository is to always maintain a `Storage` class to > it keeps as dev dependency because one day `@secjs/core` will install everything once. ```bash -npm install @secjs/env @secjs/config @secjs/utils @secjs/logger @secjs/contracts @secjs/exceptions +npm install @secjs/env @secjs/utils @secjs/contracts @secjs/exceptions ``` > Then you can install the package using: diff --git a/package-lock.json b/package-lock.json index 8a587e8..31bc291 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@secjs/storage", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@secjs/storage", - "version": "1.0.3", + "version": "1.0.4", "license": "MIT", "dependencies": { "@google-cloud/storage": "^5.16.1", @@ -14,11 +14,9 @@ "mime-types": "2.1.34" }, "devDependencies": { - "@secjs/config": "1.0.7", - "@secjs/env": "1.2.5", + "@secjs/env": "1.3.0", "@secjs/exceptions": "1.0.4", - "@secjs/logger": "1.2.2", - "@secjs/utils": "1.6.9", + "@secjs/utils": "1.7.6", "@types/jest": "27.0.1", "@types/mime-types": "2.1.1", "@types/node": "14.17.0", @@ -1861,16 +1859,10 @@ } } }, - "node_modules/@secjs/config": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@secjs/config/-/config-1.0.7.tgz", - "integrity": "sha512-NfD/ElMpg+NUPuKk3dc6Rz6lCdIRJX6Hetmd71HrbV39/5QV0MsHHVpv2Fsmo7/7/it1/uhxE7dQ9Q2kPaH4fQ==", - "dev": true - }, "node_modules/@secjs/env": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@secjs/env/-/env-1.2.5.tgz", - "integrity": "sha512-1XHJYppTu5qOTf9Wjr/GLhHUDddDfV24Qwt1Bqco2BplupnGXulLXg0Ph9/uC4oZ8sfTkK6d9JRpH7eyINpu7A==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@secjs/env/-/env-1.3.0.tgz", + "integrity": "sha512-zhfXNfqfRrXfEhLrwORYCYAlr+V/bOWR4UyZligK3vjNR3wdNKTEIcLlok3n/2jwarYTyG80hQs3F0aQq6pvtw==", "dev": true, "dependencies": { "dotenv": "10.0.0" @@ -1882,107 +1874,10 @@ "integrity": "sha512-prj8eNUOqJtrEdUFX58gqvo1RsuKZJI6pJnUr/molkDEerhWEF4lAuR8gliQo+cA+LASAvCeJXDkTWR/xbodMQ==", "dev": true }, - "node_modules/@secjs/logger": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@secjs/logger/-/logger-1.2.2.tgz", - "integrity": "sha512-bDmMttraaKLmxEAPHoDs+kTZKrJUGf4BCNEqtQ0Yr9aL6O82PfdwahgZn6esxpPWrZW42Fi1Xo8UuNBTjFGjpg==", - "dev": true, - "dependencies": { - "chalk": "4.1.1", - "debug": "4.3.1" - } - }, - "node_modules/@secjs/logger/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@secjs/logger/node_modules/chalk": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", - "integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@secjs/logger/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@secjs/logger/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/@secjs/logger/node_modules/debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", - "dev": true, - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/@secjs/logger/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/@secjs/logger/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@secjs/utils": { - "version": "1.6.9", - "resolved": "https://registry.npmjs.org/@secjs/utils/-/utils-1.6.9.tgz", - "integrity": "sha512-e/IKeX0sF8YlTZnOJWMTuFYLGtSAGqx3Mxh2PKXbRrwA5OeCMOTzQMswGiaTNpL3YHeC34GtrfofukGApn0Teg==", + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@secjs/utils/-/utils-1.7.6.tgz", + "integrity": "sha512-EcfHNy5CGbQAhcMtCHi0aRyHBTNsnesR/p8ag3X4NsS8Wdbaj5p1dUMJVjOrgLatPBvNf2tzRWKiq4cs3xgEIQ==", "dev": true, "dependencies": { "bytes": "3.1.2", @@ -1990,6 +1885,7 @@ "change-case": "4.1.2", "http-status-codes": "2.2.0", "kind-of": "6.0.3", + "lodash": "4.17.21", "mime-types": "2.1.34", "ms": "2.1.3", "pluralize": "8.0.0", @@ -13460,16 +13356,10 @@ "any-observable": "^0.3.0" } }, - "@secjs/config": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@secjs/config/-/config-1.0.7.tgz", - "integrity": "sha512-NfD/ElMpg+NUPuKk3dc6Rz6lCdIRJX6Hetmd71HrbV39/5QV0MsHHVpv2Fsmo7/7/it1/uhxE7dQ9Q2kPaH4fQ==", - "dev": true - }, "@secjs/env": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@secjs/env/-/env-1.2.5.tgz", - "integrity": "sha512-1XHJYppTu5qOTf9Wjr/GLhHUDddDfV24Qwt1Bqco2BplupnGXulLXg0Ph9/uC4oZ8sfTkK6d9JRpH7eyINpu7A==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@secjs/env/-/env-1.3.0.tgz", + "integrity": "sha512-zhfXNfqfRrXfEhLrwORYCYAlr+V/bOWR4UyZligK3vjNR3wdNKTEIcLlok3n/2jwarYTyG80hQs3F0aQq6pvtw==", "dev": true, "requires": { "dotenv": "10.0.0" @@ -13481,80 +13371,10 @@ "integrity": "sha512-prj8eNUOqJtrEdUFX58gqvo1RsuKZJI6pJnUr/molkDEerhWEF4lAuR8gliQo+cA+LASAvCeJXDkTWR/xbodMQ==", "dev": true }, - "@secjs/logger": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@secjs/logger/-/logger-1.2.2.tgz", - "integrity": "sha512-bDmMttraaKLmxEAPHoDs+kTZKrJUGf4BCNEqtQ0Yr9aL6O82PfdwahgZn6esxpPWrZW42Fi1Xo8UuNBTjFGjpg==", - "dev": true, - "requires": { - "chalk": "4.1.1", - "debug": "4.3.1" - }, - "dependencies": { - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "chalk": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", - "integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", - "dev": true, - "requires": { - "ms": "2.1.2" - } - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true - }, - "supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "requires": { - "has-flag": "^4.0.0" - } - } - } - }, "@secjs/utils": { - "version": "1.6.9", - "resolved": "https://registry.npmjs.org/@secjs/utils/-/utils-1.6.9.tgz", - "integrity": "sha512-e/IKeX0sF8YlTZnOJWMTuFYLGtSAGqx3Mxh2PKXbRrwA5OeCMOTzQMswGiaTNpL3YHeC34GtrfofukGApn0Teg==", + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/@secjs/utils/-/utils-1.7.6.tgz", + "integrity": "sha512-EcfHNy5CGbQAhcMtCHi0aRyHBTNsnesR/p8ag3X4NsS8Wdbaj5p1dUMJVjOrgLatPBvNf2tzRWKiq4cs3xgEIQ==", "dev": true, "requires": { "bytes": "3.1.2", @@ -13562,6 +13382,7 @@ "change-case": "4.1.2", "http-status-codes": "2.2.0", "kind-of": "6.0.3", + "lodash": "4.17.21", "mime-types": "2.1.34", "ms": "2.1.3", "pluralize": "8.0.0", diff --git a/package.json b/package.json index b115c9b..3878b63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@secjs/storage", - "version": "1.0.3", + "version": "1.0.4", "description": "Handle your application files in Node.js", "license": "MIT", "author": "João Lenon ", @@ -9,7 +9,7 @@ "homepage": "https://github.com/secjs/SecJS#readme", "scripts": { "build": "tsc", - "test": "NODE_ENV= jest --verbose", + "test": "NODE_ENV= NODE_TS=true jest --verbose", "test:debug": "DEBUG=* jest --verbose", "lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix" }, @@ -20,11 +20,9 @@ "nodejs" ], "devDependencies": { - "@secjs/config": "1.0.7", - "@secjs/env": "1.2.5", + "@secjs/env": "1.3.0", "@secjs/exceptions": "1.0.4", - "@secjs/logger": "1.2.2", - "@secjs/utils": "1.6.9", + "@secjs/utils": "1.7.6", "@types/jest": "27.0.1", "@types/mime-types": "2.1.1", "@types/node": "14.17.0", diff --git a/src/Drivers/GCSDriver.ts b/src/Drivers/GCSDriver.ts index e9f1813..c298d52 100644 --- a/src/Drivers/GCSDriver.ts +++ b/src/Drivers/GCSDriver.ts @@ -7,14 +7,13 @@ * file that was distributed with this source code. */ -import { Config } from '@secjs/config' -import { File } from '@secjs/utils' +import { join } from 'path' +import { tmpdir } from 'os' +import { promises } from 'fs' +import { File, Config } from '@secjs/utils' import { Storage } from '@google-cloud/storage' import { InternalServerException } from '@secjs/exceptions' import { DriverContract } from '../Contracts/DriverContract' -import { promises } from 'fs' -import { join } from 'path' -import { tmpdir } from 'os' export class GCSDriver implements DriverContract { private gcsClient: Storage diff --git a/src/Drivers/LocalDriver.ts b/src/Drivers/LocalDriver.ts index 3314288..7153af3 100644 --- a/src/Drivers/LocalDriver.ts +++ b/src/Drivers/LocalDriver.ts @@ -8,8 +8,7 @@ */ import { promises } from 'fs' -import { File } from '@secjs/utils' -import { Config } from '@secjs/config' +import { File, Config } from '@secjs/utils' import { InternalServerException } from '@secjs/exceptions' import { DriverContract } from '../Contracts/DriverContract' diff --git a/src/Drivers/S3Driver.ts b/src/Drivers/S3Driver.ts index 8e820d5..d779c87 100644 --- a/src/Drivers/S3Driver.ts +++ b/src/Drivers/S3Driver.ts @@ -8,8 +8,7 @@ */ import { S3 } from 'aws-sdk' -import { File } from '@secjs/utils' -import { Config } from '@secjs/config' +import { File, Config } from '@secjs/utils' import { InternalServerException } from '@secjs/exceptions' import { DriverContract } from '../Contracts/DriverContract' diff --git a/src/Storage.ts b/src/Storage.ts index d18bb78..7824d6e 100644 --- a/src/Storage.ts +++ b/src/Storage.ts @@ -14,9 +14,8 @@ import { import { tmpdir } from 'os' import { promises } from 'fs' -import { File } from '@secjs/utils' -import { Config } from '@secjs/config' import { isAbsolute, join } from 'path' +import { File, Config, Path } from '@secjs/utils' import { Drivers } from './Drivers/Drivers' import { DriverContract } from './Contracts/DriverContract' @@ -62,6 +61,8 @@ export class Storage { } constructor(runtimeConfig: any = {}) { + new Config().safeLoad(Path.config('filesystem')) + this.runtimeConfig = runtimeConfig this.driver = this.createDriverInstance() } diff --git a/tests/build-storage.spec.ts b/tests/build-storage.spec.ts index 170e0a1..c5280ee 100644 --- a/tests/build-storage.spec.ts +++ b/tests/build-storage.spec.ts @@ -1,5 +1,4 @@ import { existsSync } from 'fs' -import { Config } from '@secjs/config' import { Storage } from '../src/Storage' import { Folder, Path } from '@secjs/utils' import { LocalDriver } from '../src/Drivers/LocalDriver' @@ -10,8 +9,6 @@ describe('\n Build Drive Storage Class', () => { const bigContent = Buffer.alloc(Math.max(0, 1024 * 1024 * 200 - 2), 'l') beforeEach(async () => { - await new Config().load() - storage = new Storage() }) diff --git a/tests/storage-gcs.spec.ts b/tests/storage-gcs.spec.ts index 1d30657..de53537 100644 --- a/tests/storage-gcs.spec.ts +++ b/tests/storage-gcs.spec.ts @@ -1,6 +1,5 @@ import { join } from 'path' import { tmpdir } from 'os' -import { Config } from '@secjs/config' import { Storage } from '../src/Storage' import { promises, readdirSync } from 'fs' @@ -11,8 +10,6 @@ describe('\n Storage GCS Class', () => { const bigContent = Buffer.alloc(Math.max(0, 1024 * 1024 - 2), 'l') beforeEach(async () => { - await new Config().load() - storage = new Storage().disk('gcs') }) diff --git a/tests/storage-local.spec.ts b/tests/storage-local.spec.ts index 1785998..7b18b8b 100644 --- a/tests/storage-local.spec.ts +++ b/tests/storage-local.spec.ts @@ -1,9 +1,8 @@ -import { Config } from '@secjs/config' +import { tmpdir } from 'os' +import { join } from 'path' import { Storage } from '../src/Storage' import { Folder, Path, sleep } from '@secjs/utils' import { existsSync, promises, readdirSync } from 'fs' -import { join } from 'path' -import { tmpdir } from 'os' describe('\n Storage Local Class', () => { let storage: Storage = null @@ -11,8 +10,6 @@ describe('\n Storage Local Class', () => { const bigContent = Buffer.alloc(Math.max(0, 1024 * 1024 * 200 - 2), 'l') beforeEach(async () => { - await new Config().load() - storage = new Storage() }) diff --git a/tests/storage-s3.spec.ts b/tests/storage-s3.spec.ts index 5b71ab5..4dd952b 100644 --- a/tests/storage-s3.spec.ts +++ b/tests/storage-s3.spec.ts @@ -1,6 +1,5 @@ import { join } from 'path' import { tmpdir } from 'os' -import { Config } from '@secjs/config' import { Storage } from '../src/Storage' import { promises, readdirSync } from 'fs' @@ -11,8 +10,6 @@ describe('\n Storage S3 Class', () => { const bigContent = Buffer.alloc(Math.max(0, 1024 * 1024 - 2), 'l') beforeEach(async () => { - await new Config().load() - storage = new Storage().disk('s3') })