Add module documentation
This commit is contained in:
parent
2f7f101b74
commit
bf0259ef3b
|
|
@ -1 +1,6 @@
|
|||
## Frontend Common
|
||||
|
||||
### Modules
|
||||
- [api](./api/README.md)
|
||||
- [fn](./fn/README.md)
|
||||
- [logger](./fn/README.md)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
|
@ -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)
|
||||
```
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
## logger
|
||||
|
||||
This module provides logging functionality.
|
||||
Loading…
Reference in New Issue