Skip to content

Commit

Permalink
Merge 3cd604a into a4fa59f
Browse files Browse the repository at this point in the history
  • Loading branch information
milosbugarinovic committed Nov 21, 2021
2 parents a4fa59f + 3cd604a commit d7b7063
Show file tree
Hide file tree
Showing 245 changed files with 24,969 additions and 11,084 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
lib
node_modules
resource
test
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint", "eslint-plugin-import", "import"],
"plugins": ["@typescript-eslint", "eslint-plugin-import", "import", "no-only-tests"],
"root": true,
"rules": {
"no-only-tests/no-only-tests": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"@typescript-eslint/naming-convention": [
Expand Down
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ This project is intended to be used in typescript project to validate and add ty

- [Install](#install)
- [Usage](#usage)
- [Diagram](#diagram)
- [MshNodeEnv options](#mshnodeenv-options)
- [Location Strategy](#location-strategy)
- [EnvironmentLocation](#environmentlocation)
- [DockerSecretsLocation](#dockersecretslocation)
* [EnvironmentLocation](#environmentlocation)
* [DockerSecretsLocation](#dockersecretslocation)
- [Naming Strategy](#naming-strategy)
- [SimpleName](#simplename)
- [PrefixName](#prefixname)
- [SuffixName](#suffixname)
* [SimpleName](#simplename)
* [PrefixName](#prefixname)
* [SuffixName](#suffixname)
- [Logger Strategy](#logger-strategy)

<!-- tocstop -->
Expand All @@ -32,28 +33,32 @@ This project is intended to be used in typescript project to validate and add ty
## Usage

```typescript
import MshNodeEnv from '@beecode/msh-node-env'
import { MshNodeEnv } from '@beecode/msh-node-env'
import { cacheUtil } from '@beecode/msh-node-util/lib/cache-util'

const env = MshNodeEnv()

export const config = Object.freeze({
export const config = cacheUtil.singleton(() => Object.freeze({
someRequiredString: env('SOME_REQUIRED_STRING').string.required,
strWithDefaultValue: env('STR_WITH_DEFAULT_VALUE').string.default('default-value').required,
optionalString: env('OPTIONAL_STRING').string.optional,
defKeyName: env('ANY_KEY_NAME').string.required,
someNumberValue: env('SOME_NUMBER_VALUE').number.required,
someBooleanValue: env('SOME_BOOLEAN_VALUE').boolean.required,
someJsonValue: env('SOME_JSON_VALUE').json().required,
})
}))
```

## Diagram

![vision-diagram](resource/doc/vision/vision.svg)

## MshNodeEnv options

| Name | Default | Description |
| ---------------------------------------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [locationStrategy](#location-strategy)[] | [ new SimpleEnvLookup() ] | [Optional] Define how are we getting env values. Available: [EnvironmentLocation](#environmentlocation), [DockerSecretsLocation](#dockersecretslocation) |
| [namingStrategy](#naming-strategy)[] | [ new SimpleName() ] | [Optional] Define how are we checking for env names. Available: [SimpleName](#simplename), [PrefixName](#prefixname), [SuffixName](#suffixname) |
| [loggerStrategy](#logger-strategy) | new NoLogger() | [Optional] Define how the logging is provided. Available: [NoLogger](#nologger), [ConsoleLogger](#consolelogger) |

## Location Strategy

Expand All @@ -73,7 +78,8 @@ We are looking in docker swarm secrets.
Usage:

```typescript
import MshNodeEnv, { location } from '@beecode/msh-node-env'
import { MshNodeEnv } from '@beecode/msh-node-env'
import { DockerSecretsLocation } from '@beecode/msh-node-env/lib/location/docker-secrets-location'

const env = MshNodeEnv({ locationStrategy: [new location.DockerSecretsLocation()] })
```
Expand All @@ -95,9 +101,10 @@ If we wanted to change the database name for just one container, we can use [Pre
isolation, and we can set name of the container as prefix.

```typescript
import MshNodeEnv, { naming } from '@beecode/msh-node-env'
import { MshNodeEnv } from '@beecode/msh-node-env'
import { PrefixName } from '@beecode/msh-node-env/lib/naming/prefix-name'

const env = MshNodeEnv({ namingStrategy: [new naming.PrefixName({ prefix: 'SOME_APP' })] })
const env = MshNodeEnv({ namingStrategy: [new PrefixName('SOME_APP_')] })
```

Then we can add another env value prefixed with that container name.
Expand All @@ -121,9 +128,10 @@ Prefix strategy is adding prefix to the existing name. There are two arguments a
Usage:

```typescript
import MshNodeEnv, { naming } from '@beecode/msh-node-env'
import { MshNodeEnv } from '@beecode/msh-node-env'
import { PrefixName } from '@beecode/msh-node-env/lib/naming/prefix-name'

const env = MshNodeEnv({ namingStrategy: [new naming.PrefixName({ prefix: 'FOO' }), new naming.PrefixName({ prefix: 'BAR' })] })
const env = MshNodeEnv({ namingStrategy: [new PrefixName('FOO_'), new PrefixName('BAR_')] })
const test = env('TEST').string.required // env look up in this order 1) BAR_FOO_TEST, 2) FOO_TEST, 3) TEST
```

Expand All @@ -134,9 +142,10 @@ Suffix strategy is adding suffix to the existing name. there are two arguments a
Usage:

```typescript
import MshNodeEnv, { naming } from '@beecode/msh-node-env'
import { MshNodeEnv } from '@beecode/msh-node-env'
import { SuffixName } from '@beecode/msh-node-env/lib/naming/suffix-name'

const env = MshNodeEnv({ namingStrategy: [new naming.SuffixName({ prefix: 'FOO' }), new naming.SuffixName({ prefix: 'BAR' })] })
const env = MshNodeEnv({ namingStrategy: [new SuffixName('_FOO'), new SuffixName('_BAR')] })
const test = env('TEST').string.required // env look up in this order 1) TEST_FOO_BAR, 2) TEST_FOO, 3) TEST
```

Expand All @@ -148,8 +157,11 @@ For more details read the msh-node-log readme
Usage:

```typescript
import MshNodeEnv from '@beecode/msh-node-env'
import { ConsoleLogger, LogLevel } from '@beecode/msh-node-log'
import { MshNodeEnv } from '@beecode/msh-node-env'
import { LogLevelType } from '@beecode/msh-node-log'
import { ConsoleLogger } from '@beecode/msh-node-log/lib/console-logger'

const env = MshNodeEnv({ loggerStrategy: new ConsoleLogger(LogLevel.INFO) })
NodeEnvLogger(new ConsoleLogger(LogLevel.DEBUG))

const env = MshNodeEnv()
```
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ comment:
ignore:
- "src/test/**/*"
- "src/**/*.test.ts"
- "src/**/*.contract.ts"
- "src/**/__mocks__/**/*"
9 changes: 9 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"collectCoverage": true,
"collectCoverageFrom": ["src/**/*.ts", "!src/**/*.{contract,d}.ts"],
"preset": "ts-jest",
"roots": ["./src"],
"setupFilesAfterEnv": ["jest-extended/all"],
"testEnvironment": "node",
"testPathIgnorePatterns": ["/node_modules/", "/test/"]
}
6 changes: 6 additions & 0 deletions lib/convert/__mocks__/mock-convert-strategy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference types="jest" />
import { ConvertStrategy } from '../convert-strategy';
export declare class MockConvertStrategy<T = any> implements ConvertStrategy<T> {
convert: jest.Mock<T | undefined, [string]>;
}
//# sourceMappingURL=mock-convert-strategy.d.ts.map
1 change: 1 addition & 0 deletions lib/convert/__mocks__/mock-convert-strategy.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/convert/__mocks__/mock-convert-strategy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/convert/__mocks__/mock-convert-strategy.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions lib/convert/base-convert.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/convert/base-convert.d.ts.map

This file was deleted.

27 changes: 0 additions & 27 deletions lib/convert/base-convert.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/convert/base-convert.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions lib/convert/base-convert.test.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/convert/base-convert.test.d.ts.map

This file was deleted.

42 changes: 0 additions & 42 deletions lib/convert/base-convert.test.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/convert/base-convert.test.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions lib/convert/base64-to-string.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConvertStrategy } from '.';
import { ConvertStrategy } from './convert-strategy';
export declare class Base64ToString implements ConvertStrategy<string> {
convert(str: string): string | undefined;
convert(str?: string): string | undefined;
}
//# sourceMappingURL=base64-to-string.d.ts.map
2 changes: 1 addition & 1 deletion lib/convert/base64-to-string.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/convert/base64-to-string.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/convert/base64-to-string.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7b7063

Please sign in to comment.