Socket
Socket
Sign inDemoInstall

@burninggarden/config

Package Overview
Dependencies
244
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.9 to 0.0.10

.prettierrc

27

.eslintrc.json
{
"env": {
"es6": true,
"node": true
"node": true,
"jest/globals": true
},

@@ -12,3 +13,3 @@ "extends": "eslint:recommended",

"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "jest", "prettier"],
"parserOptions": {

@@ -21,6 +22,8 @@ "ecmaVersion": 2018,

"indent": "off",
"no-undef": "off",
"no-unused-vars": "off",
"camelcase": "error",
"no-control-regex": "off",
"no-unused-vars": "off",
"prettier/prettier": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",

@@ -31,3 +34,2 @@ "@typescript-eslint/explicit-function-return-type": ["error", {

"@typescript-eslint/explicit-member-accessibility": "error",
"@typescript-eslint/generic-type-naming": "error",
"@typescript-eslint/indent": ["error", "tab"],

@@ -49,2 +51,7 @@ "@typescript-eslint/member-delimiter-style": ["error", {

"private-static-field",
"static-field",
"public-static-method",
"protected-static-method",
"private-static-method",
"static-method",
"public-instance-field",

@@ -56,8 +63,4 @@ "protected-instance-field",

"private-field",
"static-field",
"instance-field",
"field",
"public-static-method",
"protected-static-method",
"private-static-method",
"constructor",

@@ -70,3 +73,2 @@ "public-instance-method",

"private-method",
"static-method",
"instance-method",

@@ -83,4 +85,5 @@ "method"

"@typescript-eslint/no-type-alias": ["error", {
"allowCallbacks": "always",
"allowAliases": "in-unions"
"allowCallbacks": "always",
"allowAliases": "in-unions",
"allowMappedTypes": "always"
}],

@@ -87,0 +90,0 @@ "@typescript-eslint/no-unnecessary-type-assertion": "error",

{
"name": "@burninggarden/config",
"description": "A library for sharing config values across modules",
"version": "0.0.9",
"version": "0.0.10",
"private": false,

@@ -14,3 +14,3 @@ "author": "Burning Garden",

"@types/node": "10.9.4",
"typescript": "3.2.1"
"@types/jest": "^24.0.17"
},

@@ -21,4 +21,11 @@ "devDependencies": {

"eslint": "^5.15.3",
"tap": "14.2.2"
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^24.8.0",
"prettier": "2.0.1",
"typescript": "3.5.1"
},
"resolutions": {
"typescript-eslint-parser": "npm:@typescript-eslint/parser@1.10.2"
},
"scripts": {

@@ -29,4 +36,5 @@ "install": "./bin/install",

"preversion": "./bin/preversion",
"postversion": "./bin/postversion"
"postversion": "./bin/postversion",
"prepublishOnly": "./bin/prepublish"
}
}

@@ -1,5 +0,5 @@

import OS from 'os';
import Settings from 'interfaces/settings';
import {EnvironmentType} from '@burninggarden/enums';
import SettingsFactory from 'factories/settings';
import OS from 'os';
import Settings from 'interfaces/settings';
import { EnvironmentType } from '@burninggarden/enums';
import SettingsFactory from 'factories/settings';

@@ -9,5 +9,2 @@ let CACHED_INSTANCE: Config | null = null;

class Config {
private settings: Settings;
public static getInstance(): Config {

@@ -65,2 +62,4 @@ if (CACHED_INSTANCE === null) {

private settings: Settings | undefined;
public isDevelopment(): boolean {

@@ -78,2 +77,6 @@ return this.getEnvironmentType() === EnvironmentType.DEVELOPMENT;

public isBrowser(): boolean {
return typeof window !== 'undefined';
}
public getManagerPort(): number {

@@ -123,3 +126,3 @@ return 3000;

private getSettings(): Settings {
if (!this.settings) {
if (this.settings === undefined) {
this.settings = this.buildSettings();

@@ -132,12 +135,10 @@ }

private buildSettings(): Settings {
const
directoryPath = this.getHomeDirectoryPath(),
filepath = directoryPath + '/.burninggarden/settings.json',
factory = new SettingsFactory(filepath);
const directoryPath = this.getHomeDirectoryPath(),
filepath = directoryPath + '/.burninggarden/settings.json',
factory = new SettingsFactory(filepath);
return factory.buildSettings();
}
}
export default Config;

@@ -1,11 +0,10 @@

import FS from 'fs';
import Settings from 'interfaces/settings';
import MysqlSettings from 'interfaces/settings/mysql';
import {FileEncoding} from '@burninggarden/enums';
import FS from 'fs';
import Settings from 'interfaces/settings';
import MysqlSettings from 'interfaces/settings/mysql';
import { FileEncoding } from '@burninggarden/enums';
class SettingsFactory {
private filepath: string;
private fileContents: Settings | undefined;
private filepath : string;
private fileContents : Settings;
public constructor(filepath: string) {

@@ -18,3 +17,3 @@ this.filepath = filepath;

tempDirectoryPath: this.buildTempDirectoryPath(),
mysql: this.buildMysqlSettings()
mysql: this.buildMysqlSettings(),
};

@@ -38,4 +37,4 @@ }

password: 'balrog',
port: 3306,
...this.getFileContents().mysql
port: 3306,
...this.getFileContents().mysql,
};

@@ -45,3 +44,3 @@ }

private getFileContents(): Settings {
if (!this.fileContents) {
if (this.fileContents === undefined) {
this.fileContents = this.readFileContents();

@@ -68,5 +67,4 @@ }

}
}
export default SettingsFactory;

@@ -1,258 +0,221 @@

import OS from 'os';
import Tap from 'tap';
import Config from 'config';
import SettingsFactory from 'factories/settings';
import {EnvironmentType} from '@burninggarden/enums';
import OS from 'os';
import Config from 'config';
import SettingsFactory from 'factories/settings';
import { EnvironmentType } from '@burninggarden/enums';
import EnvironmentMocker from '@burninggarden/environment-mocker';
describe('Config', () => {
describe('.isDevelopment()', () => {
it('returns expected value when not in development environment', () => {
EnvironmentMocker.mock(EnvironmentType.PRODUCTION, () => {
expect(new Config().isDevelopment()).toBe(false);
});
});
Tap.test('.isDevelopment()', suite => {
suite.test('returns expected value when not in development environment', test => {
EnvironmentMocker.mock(EnvironmentType.PRODUCTION, () => {
test.notOk((new Config()).isDevelopment());
it('returns expected value when in development environment', () => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
expect(new Config().isDevelopment()).toBe(true);
});
});
test.end();
it('is aliased as static method', () => {
expect(Config.isDevelopment()).toBe(false);
});
});
suite.test('returns expected value when in development environment', test => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
test.ok((new Config()).isDevelopment());
describe('.isProduction()', () => {
it('returns expected value when not in production environment', () => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
expect(new Config().isProduction()).toBe(false);
});
});
test.end();
});
it('returns expected value when in production environment', () => {
EnvironmentMocker.mock(EnvironmentType.PRODUCTION, () => {
expect(new Config().isProduction()).toBe(true);
});
});
suite.test('is aliased as static method', test => {
test.equals(Config.isDevelopment(), (new Config()).isDevelopment());
test.end();
it('is aliased as static method', () => {
expect(Config.isProduction()).toBe(false);
});
});
suite.end();
});
describe('.isTest()', () => {
it('returns expected value when not in test environment', () => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
expect(new Config().isTest()).toBe(false);
});
});
Tap.test('.isProduction()', suite => {
suite.test('returns expected value when not in production environment', test => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
test.notOk((new Config()).isProduction());
it('returns expected value when in test environment', () => {
EnvironmentMocker.mock(EnvironmentType.TEST, () => {
expect(new Config().isTest()).toBe(true);
});
});
test.end();
});
suite.test('returns expected value when in production environment', test => {
EnvironmentMocker.mock(EnvironmentType.PRODUCTION, () => {
test.ok((new Config()).isProduction());
it('is aliased as static method', () => {
expect(Config.isTest()).toBe(true);
});
test.end();
});
suite.test('is aliased as static method', test => {
test.equals(Config.isProduction(), (new Config()).isProduction());
test.end();
});
describe('.getEnvironmentType()', () => {
it('returns expected environment type for production', () => {
EnvironmentMocker.mock(EnvironmentType.PRODUCTION, () => {
const environmentType = new Config().getEnvironmentType();
suite.end();
});
Tap.test('.isTest()', suite => {
suite.test('returns expected value when not in test environment', test => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
test.notOk((new Config()).isTest());
expect(environmentType).toStrictEqual(EnvironmentType.PRODUCTION);
});
});
test.end();
});
it('returns expected environment type for test', () => {
EnvironmentMocker.mock(EnvironmentType.TEST, () => {
const environmentType = new Config().getEnvironmentType();
suite.test('returns expected value when in test environment', test => {
EnvironmentMocker.mock(EnvironmentType.TEST, () => {
test.ok((new Config()).isTest());
expect(environmentType).toStrictEqual(EnvironmentType.TEST);
});
});
test.end();
});
it('returns expected environment type for development', () => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
const environmentType = new Config().getEnvironmentType();
suite.test('is aliased as static method', test => {
test.equals(Config.isTest(), (new Config()).isTest());
test.end();
});
expect(environmentType).toStrictEqual(EnvironmentType.DEVELOPMENT);
});
});
suite.end();
});
it('throws an exception for other environment values', () => {
const environment = 'nonsense';
Tap.test('.getEnvironmentType()', suite => {
suite.test('returns expected environment type for production', test => {
EnvironmentMocker.mock(EnvironmentType.PRODUCTION, () => {
const environmentType = (new Config()).getEnvironmentType();
EnvironmentMocker.mock(environment as EnvironmentType, () => {
const config = new Config();
test.equals(environmentType, EnvironmentType.PRODUCTION);
test.end();
expect(() => {
config.getEnvironmentType();
}).toThrow('Unsupported environment type: nonsense');
});
});
});
suite.test('returns expected environment type for test', test => {
EnvironmentMocker.mock(EnvironmentType.TEST, () => {
const environmentType = (new Config()).getEnvironmentType();
test.equals(environmentType, EnvironmentType.TEST);
test.end();
it('is aliased as static method', () => {
expect(Config.getEnvironmentType()).toStrictEqual(EnvironmentType.TEST);
});
});
suite.test('returns expected environment type for development', test => {
EnvironmentMocker.mock(EnvironmentType.DEVELOPMENT, () => {
const environmentType = (new Config()).getEnvironmentType();
describe('.getManagerPort()', () => {
it('returns expected port value', () => {
const port = new Config().getManagerPort();
test.equals(environmentType, EnvironmentType.DEVELOPMENT);
test.end();
expect(port).toStrictEqual(3000);
});
it('is aliased as static method', () => {
expect(Config.getManagerPort()).toStrictEqual(
new Config().getManagerPort()
);
});
});
suite.test('throws an exception for other environment values', test => {
const environment = 'nonsense';
describe('.getHttpsPort()', () => {
it('returns expected port value', () => {
const port = new Config().getHttpsPort();
EnvironmentMocker.mock(environment as EnvironmentType, () => {
const config = new Config()
expect(port).toStrictEqual(8080);
});
test.throws(() => {
config.getEnvironmentType();
}, /Unsupported environment type: nonsense/);
test.end();
it('is aliased as static method', () => {
expect(Config.getHttpsPort()).toStrictEqual(new Config().getHttpsPort());
});
});
suite.test('is aliased as static method', test => {
test.equals(
Config.getEnvironmentType(),
(new Config()).getEnvironmentType()
);
describe('.getProcessId()', () => {
it('returns expected pid value', () => {
const processId = new Config().getProcessId();
test.end();
});
expect(processId).toStrictEqual(process.pid);
});
suite.end();
});
Tap.test('.getManagerPort()', suite => {
suite.test('returns expected port value', test => {
const port = (new Config()).getManagerPort();
test.equals(port, 3000);
test.end();
it('is aliased as static method', () => {
expect(Config.getProcessId()).toStrictEqual(process.pid);
});
});
suite.test('is aliased as static method', test => {
test.equals(Config.getManagerPort(), (new Config()).getManagerPort());
test.end();
});
describe('.getUid()', () => {
it('returns expected uid value', () => {
const uid = new Config().getUid();
suite.end();
});
expect(uid).toStrictEqual(process.getuid());
});
Tap.test('.getHttpsPort()', suite => {
suite.test('returns expected port value', test => {
const port = (new Config()).getHttpsPort();
test.equals(port, 8080);
test.end();
it('is aliased as static method', () => {
expect(Config.getUid()).toStrictEqual(process.getuid());
});
});
suite.test('is aliased as static method', test => {
test.equals(Config.getHttpsPort(), (new Config()).getHttpsPort());
test.end();
});
describe('.getGid()', () => {
it('returns expected gid value', () => {
const gid = new Config().getGid();
suite.end();
});
expect(gid).toStrictEqual(process.getgid());
});
Tap.test('.getProcessId()', suite => {
suite.test('returns expected pid value', test => {
const processId = (new Config()).getProcessId();
test.equals(processId, process.pid);
test.end();
it('is aliased as static method', () => {
expect(Config.getGid()).toStrictEqual(new Config().getGid());
});
});
suite.test('is aliased as static method', test => {
test.equals(Config.getProcessId(), (new Config()).getProcessId());
test.end();
});
describe('.getTempDirectoryPath()', () => {
it('returns expected value', () => {
const config = new Config();
const homedir = config.getHomeDirectoryPath();
const settingsFilepath = homedir + '/.burninggarden/settings.json';
const settingsFactory = new SettingsFactory(settingsFilepath);
const settings = settingsFactory.buildSettings();
suite.end();
});
expect(config.getTempDirectoryPath()).toStrictEqual(
settings.tempDirectoryPath
);
});
Tap.test('.getUid()', suite => {
suite.test('returns expected uid value', test => {
const uid = (new Config()).getUid();
test.equals(uid, process.getuid());
test.end();
it('is aliased as a static method', () => {
expect(Config.getTempDirectoryPath()).toStrictEqual(
new Config().getTempDirectoryPath()
);
});
});
suite.test('is aliased as static method', test => {
test.equals(Config.getUid(), (new Config()).getUid());
test.end();
});
describe('.getHomeDirectoryPath()', () => {
it('returns expected gid value', () => {
const path = new Config().getHomeDirectoryPath();
suite.end();
});
expect(path).toStrictEqual(OS.homedir());
});
Tap.test('.getGid()', suite => {
suite.test('returns expected gid value', test => {
const gid = (new Config()).getGid();
test.equals(gid, process.getgid());
test.end();
it('is aliased as static method', () => {
expect(Config.getHomeDirectoryPath()).toStrictEqual(
new Config().getHomeDirectoryPath()
);
});
});
suite.test('is aliased as static method', test => {
test.equals(Config.getGid(), (new Config()).getGid());
test.end();
});
describe('.isBrowser()', () => {
it('returns true when window is defined', () => {
const config = new Config();
suite.end();
});
Object.assign(global, {
window: {},
});
Tap.test('.getTempDirectoryPath()', suite => {
suite.test('returns expected value', test => {
const config = new Config();
const homedir = config.getHomeDirectoryPath();
const settingsFilepath = homedir + '/.burninggarden/settings.json';
const settingsFactory = new SettingsFactory(settingsFilepath);
const settings = settingsFactory.buildSettings();
expect(config.isBrowser()).toBe(true);
test.equal(config.getTempDirectoryPath(), settings.tempDirectoryPath);
test.end();
});
Object.assign(global, {
window: undefined,
});
});
suite.test('is aliased as a static method', test => {
test.equals(
Config.getTempDirectoryPath(),
(new Config()).getTempDirectoryPath()
);
test.end();
});
it('returns false when window is not defined', () => {
const config = new Config();
suite.end();
});
Tap.test('.getHomeDirectoryPath()', suite => {
suite.test('returns expected gid value', test => {
const path = (new Config()).getHomeDirectoryPath();
test.equals(path, OS.homedir());
test.end();
expect(config.isBrowser()).toBe(false);
});
});
suite.test('is aliased as static method', test => {
test.equals(
Config.getHomeDirectoryPath(),
(new Config()).getHomeDirectoryPath()
);
test.end();
});
suite.end();
});
import FS from 'fs';
import Tap from 'tap';
import Settings from 'interfaces/settings';
import {FileEncoding} from '@burninggarden/enums';
import { FileEncoding } from '@burninggarden/enums';
import SettingsFactory from 'factories/settings';
Tap.test('.buildSettings()', suite => {
suite.test('returns the expected settings when the specified settings file exists', test => {
const filepath = '/tmp/bg-settings.json';
describe('SettingsFactory', () => {
describe('.buildSettings()', () => {
it('returns the expected settings when the specified settings file exists', () => {
const filepath = '/tmp/bg-settings.json';
const expectedSettings: Settings = {
tempDirectoryPath: '/weathertop',
mysql: {
username: 'gandalf',
hostname: 'https://google.com',
password: 'speak-friend-and-enter',
port: 1234
}
};
const expectedSettings: Settings = {
tempDirectoryPath: '/weathertop',
mysql: {
username: 'gandalf',
hostname: 'https://google.com',
password: 'speak-friend-and-enter',
port: 1234,
},
};
const contents = JSON.stringify(expectedSettings);
const contents = JSON.stringify(expectedSettings);
FS.writeFileSync(filepath, contents, FileEncoding.UTF8);
FS.writeFileSync(filepath, contents, FileEncoding.UTF8);
const factory = new SettingsFactory(filepath);
const actualSettings = factory.buildSettings();
const factory = new SettingsFactory(filepath);
const actualSettings = factory.buildSettings();
test.deepEqual(actualSettings, expectedSettings);
test.end();
});
expect(actualSettings).toEqual(expectedSettings);
});
suite.test('returns the expected settings when the specified settings file does not exist', test => {
const factory = new SettingsFactory('/non/existent/filepath.json');
const actualSettings = factory.buildSettings();
it('returns the expected settings when the specified settings file does not exist', () => {
const factory = new SettingsFactory('/non/existent/filepath.json');
const actualSettings = factory.buildSettings();
test.deepEqual(actualSettings, {
tempDirectoryPath: '/tmp',
mysql: {
username: 'bgdev',
hostname: 'localhost',
password: 'balrog',
port: 3306
}
expect(actualSettings).toEqual({
tempDirectoryPath: '/tmp',
mysql: {
username: 'bgdev',
hostname: 'localhost',
password: 'balrog',
port: 3306,
},
});
});
test.end();
});
suite.end();
});
{
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"strict": true,
"noUnusedLocals": true,
"compilerOptions": {
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"strictPropertyInitialization": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./src",

@@ -12,3 +15,7 @@ "target": "es2017",

"sourceMap": true,
"esModuleInterop": true
"esModuleInterop": true,
"lib": [
"esnext",
"dom"
]
},

@@ -15,0 +22,0 @@ "typeRoots": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc