Add module documentation

This commit is contained in:
Vasili Karaev 2021-08-05 12:33:24 +03:00
parent 2f7f101b74
commit bf0259ef3b
4 changed files with 101 additions and 0 deletions

View File

@ -1 +1,6 @@
## Frontend Common
### Modules
- [api](./api/README.md)
- [fn](./fn/README.md)
- [logger](./fn/README.md)

56
api/README.md Normal file
View File

@ -0,0 +1,56 @@
## api
This module helps define callable API methods.
### Usage example
```typescript
import { ApiMethodFactory, HttpMethod } from 'lib/api'
const { make } = new ApiMethodFactory({ apiPrefix: '/api' })
interface User {
id: string
name: string
email: string
}
interface UserRequest {
id: string
}
interface UserListRequest {
limit: number
offset: number
}
type UserResponse = User
type UserListResponse = User[]
type _ = unknown
const API = {
user: {
get: make<UserResponse, UserRequest>('/users/%(id)s', HttpMethod.GET, {
path: ['id'],
}),
list: make<UserListResponse, UserListRequest>('/users', HttpMethod.GET, {
query: ['limit', 'offset'],
}),
delete: make<_, UserRequest>('/users/%(id)s', HttpMethod.DELETE, {
path: ['id'],
}),
},
}
const run = async () => {
const users = await API.user.list({ limit: 10, offset: 0 })
users.forEach(async (user) => {
await API.user.delete({
id: user.id,
})
})
}
```

37
fn/README.md Normal file
View File

@ -0,0 +1,37 @@
## fn
This module contains various ramda combinations/extensions.
### Available functions:
- `thread` - sequentially applies transforms from the array to the first argument.
**Example usage**:
```typescript
import * as R from 'ramda'
import * as F from 'lib/fn'
const a = F.thread(5, [
R.add(3),
R.multiply(2),
R.dec,
])
a === 15 // true
// equivalent to:
const transform = R.pipe(
R.add(3),
R.multiply(2),
R.dec,
)
const b = transform(5)
// or
const c = R.pipe(
R.add(3),
R.multiply(2),
R.dec,
)(5)
```

3
logger/README.md Normal file
View File

@ -0,0 +1,3 @@
## logger
This module provides logging functionality.