Skip to content

Commit

Permalink
feat(fp-ts): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
raveclassic committed Apr 12, 2022
1 parent 2fdf80a commit 5266ecb
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ So, the goals of this project are to:
The project is split into several packages, and you can find documentation for them in the corresponding readme files.

- [@injectable-ts/core](./packages/core/README.md) - the main package containing building blocks for the IoC/DI
- [@injectable-ts/fp-ts](./packages/fp-ts/README.md) - bindings for [fp-ts](https://github.com/gcanti/fp-ts/) library
- [@injectable-ts/react](./packages/react/README.md) - bindings for React for better integration with the core
- more coming soon

Expand Down
37 changes: 37 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"private": true,
"workspaces": [
"./packages/core",
"./packages/fp-ts",
"./packages/react"
],
"engines": {
Expand Down
21 changes: 21 additions & 0 deletions packages/fp-ts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"parserOptions": {
"project": ["packages/fp-ts/tsconfig.*?.json"]
},
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions packages/fp-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# fp-ts

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build fp-ts` to build the library.

## Running unit tests

Run `nx test fp-ts` to execute the unit tests via [Jest](https://jestjs.io).
14 changes: 14 additions & 0 deletions packages/fp-ts/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'fp-ts',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/fp-ts',
}
14 changes: 14 additions & 0 deletions packages/fp-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@injectable-ts/fp-ts",
"version": "0.0.1",
"type": "commonjs",
"dependencies": {
"@injectable-ts/core": "^0.0.1"
},
"peerDependencies": {
"fp-ts": "^2.11.9"
},
"devDependencies": {
"fp-ts": "^2.11.9"
}
}
32 changes: 32 additions & 0 deletions packages/fp-ts/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"root": "packages/fp-ts",
"sourceRoot": "packages/fp-ts/src",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/fp-ts",
"main": "packages/fp-ts/src/index.ts",
"tsConfig": "packages/fp-ts/tsconfig.lib.json",
"assets": ["packages/fp-ts/*.md"]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/fp-ts/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/packages/fp-ts"],
"options": {
"jestConfig": "packages/fp-ts/jest.config.js",
"passWithNoTests": true
}
}
},
"tags": []
}
10 changes: 10 additions & 0 deletions packages/fp-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export {
ap,
chain,
map,
chainFirst,
apFirst,
flatten,
apSecond,
MonadInjectable,
} from './instance'
23 changes: 23 additions & 0 deletions packages/fp-ts/src/instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Injectable, UnknownDependencyTree } from '@injectable-ts/core'
import { pipeable } from 'fp-ts/lib/pipeable'
import { Monad1 } from 'fp-ts/lib/Monad'

export const URI = '@injectable-ts/fp-ts//Injectable'
export type URI = typeof URI

declare module 'fp-ts/lib/HKT' {
interface URItoKind<A> {
readonly [URI]: Injectable<UnknownDependencyTree, A>
}
}

export const MonadInjectable: Monad1<URI> = {
URI,
of: (a) => () => a,
map: (fa, f) => (e) => f(fa(e)),
chain: (fa, f) => (e) => f(fa(e))(e),
ap: (fab, fa) => (e) => fab(e)(fa(e)),
}

export const { chain, ap, map, apFirst, chainFirst, apSecond, flatten } =
pipeable(MonadInjectable)
22 changes: 22 additions & 0 deletions packages/fp-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions packages/fp-ts/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
},
"include": ["**/*.ts"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
}
9 changes: 9 additions & 0 deletions packages/fp-ts/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"jsx": "react",
"paths": {
"@injectable-ts/core": ["packages/core/src/index.ts"],
"@injectable-ts/fp-ts": ["packages/fp-ts/src/index.ts"],
"@injectable-ts/react": ["packages/react/src/index.ts"]
}
},
Expand Down
1 change: 1 addition & 0 deletions workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": 2,
"projects": {
"core": "packages/core",
"fp-ts": "packages/fp-ts",
"react": "packages/react"
}
}

0 comments on commit 5266ecb

Please sign in to comment.