-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9765abb
Showing
69 changed files
with
5,532 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{md}] | ||
indent_size = 2 | ||
|
||
[*.{js,ts}] | ||
indent_size = 4 | ||
|
||
[package.json] | ||
indent_size = 2 | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
env: { | ||
es6: true, | ||
}, | ||
extends: ['@herp-inc'], | ||
parser: '@typescript-eslint/parser', | ||
overrides: [ | ||
{ | ||
extends: ['@herp-inc/eslint-config-jest'], | ||
files: ['*.test.ts'], | ||
}, | ||
], | ||
parserOptions: { | ||
sourceType: 'module', | ||
project: './tsconfig.json', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- '**' | ||
tags-ignore: | ||
- '**' | ||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 'lts/*' | ||
- name: Install dependencies | ||
run: | | ||
yarn install --frozen-lockfile | ||
- name: Run Prettier | ||
run: | | ||
yarn prettier --check --ignore-unknown . | ||
- name: Typecheck | ||
run: | | ||
yarn tsc --noEmit | ||
- name: Run ESLint | ||
run: | | ||
yarn eslint ./src | ||
- name: Run tests | ||
run: | | ||
yarn jest ./src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "all", | ||
"overrides": [ | ||
{ | ||
"files": ["*.js", "*.ts"], | ||
"options": { | ||
"tabWidth": 4 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
all: sdist | ||
|
||
format: install | ||
yarn prettier --write . | ||
|
||
lint: install | ||
yarn eslint ./src | ||
|
||
install: | ||
yarn install | ||
|
||
sdist: | ||
nix-build | ||
|
||
test: install | ||
yarn jest ./src --watch | ||
|
||
typecheck: install | ||
yarn tsc --noEmit --watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# `@herp-inc/environmen-ts` [![npm](https://img.shields.io/npm/v/@herp-inc/environmen-ts)](https://www.npmjs.com/package/@herp-inc/environmen-ts) | ||
|
||
A composable environment variable decoder library | ||
|
||
## Installation | ||
|
||
Note that the following packages are peer dependencies of this library, which need to be installed separately. | ||
|
||
| Package | Version | | ||
| ---------------------------------------------- | --------- | | ||
| [`fp-ts`](https://www.npmjs.com/package/fp-ts) | `^2.11.0` | | ||
|
||
```sh | ||
$ yarn add @herp-inc/environmen-ts | ||
``` | ||
|
||
## Example | ||
|
||
```typescript | ||
import { | ||
defaultTo, | ||
Environment, | ||
EnvironmentError, | ||
hex, | ||
keyOf, | ||
optional, | ||
port, | ||
required, | ||
} from '@herp-inc/environmen-ts'; | ||
import * as E from 'fp-ts/Either'; | ||
import { pipe } from 'fp-ts/function'; | ||
import * as RE from 'fp-ts/ReaderEither'; | ||
|
||
type LogLevel = 'debug' | 'info' | 'warn' | 'error'; | ||
type Config = { | ||
logLevel: LogLevel; | ||
port: number; | ||
secretKeyBase: Buffer; | ||
}; | ||
|
||
const portD = required('PORT', port()); | ||
|
||
const logLevelD = pipe( | ||
optional( | ||
'LOG_LEVEL', | ||
keyOf({ | ||
debug: null, | ||
info: null, | ||
warn: null, | ||
error: null, | ||
}), | ||
), | ||
defaultTo<LogLevel>(() => 'info'), | ||
); | ||
|
||
const secretKeyBaseD = required('SECRET_KEY_BASE', hex({ length: 32 }), { | ||
// You can optionally mark a variable to be sensitive so that it will not be logged. | ||
sensitive: true, | ||
}); | ||
|
||
const configD = pipe( | ||
RE.Do, | ||
RE.bind('port', () => portD), | ||
RE.bind('logLevel', () => logLevelD), | ||
RE.bind('secretKeyBase', () => secretKeyBaseD), | ||
); | ||
|
||
const env = new Environment(process.env); | ||
|
||
const config: E.Either<EnvironmentError, Config> = configD(env); | ||
|
||
// Check out what's found and what's missing. | ||
for (const log of env.logs()) { | ||
logger.info(log); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
let | ||
packageJSON = pkgs.lib.importJSON ./package.json; | ||
in | ||
|
||
pkgs.stdenv.mkDerivation rec { | ||
name = "herp-inc-environmen-ts"; | ||
version = packageJSON.version; | ||
|
||
src = pkgs.nix-gitignore.gitignoreSource [] ./.; | ||
|
||
buildInputs = [ | ||
pkgs.nodejs-slim | ||
pkgs.yarn | ||
]; | ||
|
||
buildPhase='' | ||
HOME=$TMP yarn install --frozen-lockfile | ||
yarn rollup --config ./rollup.config.js | ||
cp ./package.json ./README.md ./dist | ||
cd ./dist | ||
yarn pack | ||
cd .. | ||
mv ./dist/*.tgz ./ | ||
''; | ||
|
||
dontInstall = true; | ||
|
||
doDist = true; | ||
tarballs = "herp-inc-environmen-ts-v${version}.tgz"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
globals: { | ||
'ts-jest': { | ||
isolatedModules: true, | ||
}, | ||
}, | ||
preset: 'ts-jest', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@herp-inc/environmen-ts", | ||
"description": "A composable environment variable decoder library", | ||
"version": "0.1.0", | ||
"keywords": [ | ||
"fp-ts", | ||
"environment variables" | ||
], | ||
"main": "cjs/index.js", | ||
"module": "mjs/index.js", | ||
"types": "cjs/index.d.ts", | ||
"sideEffects": false, | ||
"repository": "https://github.com/herp-inc/environmen-ts", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@herp-inc/eslint-config": "0.11.0", | ||
"@herp-inc/eslint-config-jest": "0.3.0", | ||
"@rollup/plugin-typescript": "8.3.0", | ||
"@types/jest": "27.0.3", | ||
"@typescript-eslint/eslint-plugin": "5.7.0", | ||
"@typescript-eslint/parser": "5.7.0", | ||
"eslint": "8.5.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-import-resolver-typescript": "2.5.0", | ||
"eslint-plugin-import": "2.25.3", | ||
"eslint-plugin-jest": "25.3.0", | ||
"fast-check": "2.20.0", | ||
"fp-ts": "2.11.5", | ||
"jest": "27.4.5", | ||
"prettier": "2.5.1", | ||
"rollup": "2.61.1", | ||
"ts-jest": "27.1.2", | ||
"typescript": "4.5.4" | ||
}, | ||
"peerDependencies": { | ||
"fp-ts": "^2.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["github>herp-inc/renovate.json"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
|
||
export default [ | ||
{ | ||
input: 'src/index.ts', | ||
output: { | ||
dir: 'dist/cjs', | ||
format: 'cjs', | ||
}, | ||
plugins: [ | ||
typescript({ | ||
exclude: ['**/*.test.ts'], | ||
outDir: 'dist/cjs', | ||
}), | ||
], | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: { | ||
dir: 'dist/esm', | ||
format: 'esm', | ||
}, | ||
plugins: [ | ||
typescript({ | ||
exclude: ['**/*.test.ts'], | ||
outDir: 'dist/esm', | ||
}), | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type * as RE from 'fp-ts/ReaderEither'; | ||
|
||
import type { Environment } from '../Environment'; | ||
import type { EnvironmentError } from '../EnvironmentError'; | ||
|
||
type Decoder<A> = RE.ReaderEither<Environment, EnvironmentError, A>; | ||
|
||
export type { Decoder }; |
Oops, something went wrong.