Skip to content

Commit

Permalink
fix: remove pino and fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabb-c committed Mar 15, 2023
1 parent 9fef245 commit 1824ad6
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 399 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ A lightweight Node.js wrapper for the PokéAPI with built-in types. An easy way

## Features

- [Built-in typings](https://pokenode-ts-docs-gabb-c.vercel.app/docs/typings/berry-typings)
- [Axios with auto-cache requests](https://pokenode-ts-docs-gabb-c.vercel.app/docs/guides/cache)
- [Logging configuration](https://pokenode-ts-docs-gabb-c.vercel.app/docs/guides/logs)

## Installation

```bash
npm i pokenode-ts
# or
yarn add pokenode-ts # Recommended
```
- [Built-in typings](https://pokenode-ts.vercel.app/typings/pokemon-typings)
- [Axios with auto-cache requests](https://pokenode-ts.vercel.app/guides/cache)
- [Logging](https://pokenode-ts.vercel.app/guides/logging)

## Basic Example

Using a client, like [PokemonClient](https://pokenode-ts-docs-gabb-c.vercel.app/docs/clients/pokemon-client):
Using a client, like [PokemonClient](https://pokenode-ts.vercel.app/clients/pokemon-client):

```js
import { PokemonClient } from 'pokenode-ts';
Expand Down Expand Up @@ -50,7 +42,7 @@ import { MainClient } from 'pokenode-ts';

## Documentation

Check out our [Documentation page](https://pokenode-ts-docs-gabb-c.vercel.app/)!
Check out our [Documentation page](https://pokenode-ts.vercel.app/)!

## Security

Expand Down
16 changes: 4 additions & 12 deletions docs/src/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@
## Installation

Install pokenode-ts with your favorite package manager:
:::code-group

:::code-group
```bash [NPM]
npm i pokenode-ts
npm i axios axios-cache-interceptor pokenode-ts
```

```bash [Yarn]
yarn add pokenode-ts
yarn add axios axios-cache-interceptor pokenode-ts
```

```bash [Pnpm]
pnpm i pokenode-ts
pnpm i axios axios-cache-interceptor pokenode-ts
```

```html [Browser]
<script
src="https://cdn.jsdelivr.net/npm/pokenode-ts/lib/index.global.js"
crossorigin="anonymous"
></script>
```

:::

## Basic Example
Expand Down
118 changes: 10 additions & 108 deletions docs/src/guides/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,26 @@

## Logs

Every client in Pokenode-ts can display logs from requests and responses thanks to [Pino.js](https://github.com/pinojs/pino), a super fast all natural json logger.
Every client in Pokenode-ts can display logs from requests and responses.

## Basic Logging

To enable basic plain json logs just pass the `logOptions` with `enabled: true`:
To enable logs just pass `logs: true`:

```js
import { BerryClient } from 'pokenode-ts';

const api = new BerryClient({ logOptions: { enabled: true } }); // Enable logs
const api = new BerryClient({ logs: true }); // Enable logs
```

Will output:

```json
// Axios request log
{"level":30,"time":1622569877122,"pid":13379,"hostname":"mypc","msg":"[ Request Config ] GET | /berry/cheri | Cached"}
```log
// success
[ Request Config ] GET | /berry/cheri
[ Response ] STATUS 200 | CACHED
// Axios Response Data log
{"level":30,"time":1622569877219,"pid":13379,"hostname":"mypc","firmness":{"name":"soft","url":"https://pokeapi.co/api/v2/berry-firmness/2/"},"flavors":[{"flavor":{"name":"spicy","url":"https://pokeapi.co/api/v2/berry-flavor/1/"},"potency":10},{"flavor":{"name":"dry","url":"https://pokeapi.co/api/v2/berry-flavor/2/"},"potency":0},{"flavor":{"name":"sweet","url":"https://pokeapi.co/api/v2/berry-flavor/3/"},"potency":0},{"flavor":{"name":"bitter","url":"https://pokeapi.co/api/v2/berry-flavor/4/"},"potency":0},{"flavor":{"name":"sour","url":"https://pokeapi.co/api/v2/berry-flavor/5/"},"potency":0}],"growth_time":3,"id":1,"item":{"name":"cheri-berry","url":"https://pokeapi.co/api/v2/item/126/"},"max_harvest":5,"name":"cheri","natural_gift_power":60,"natural_gift_type":{"name":"fire","url":"https://pokeapi.co/api/v2/type/10/"},"size":20,"smoothness":25,"soil_dryness":15}
// error
[ Request Config ] GET | /berry/cheri
[ Response Error ] CODE ERR_BAD_REQUEST | Request failed with status code 404
```

## Pretty logging

:::tip
By default, Pino log lines are newline delimited JSON (NDJSON). This is perfect for production usage and long term storage. It's not so great for development environments. Thus, Pino logs can be prettified by using a Pino prettifier module like [pino-pretty](https://github.com/pinojs/pino-pretty).
:::

To enable pretty printing:

```js
import { BerryClient } from 'pokenode-ts';

const api = new BerryClient({
logOptions: {
enabled: true,
transport: {
target: 'pino-pretty'
},
},
});

// Enable pretty logs (recommended for development)
```

Will output:

```
// Axios Request Config log
INFO [1622554026120] (26906 on yourpc): [ Request Config ] GET | /berry/1
```

```json
// Axios Response Data log

{
"firmness": {
"name": "soft",
"url": "https://pokeapi.co/api/v2/berry-firmness/2/"
},
"flavors": [
{
"flavor": {
"name": "spicy",
"url": "https://pokeapi.co/api/v2/berry-flavor/1/"
},
"potency": 10
},
{
"flavor": {
"name": "dry",
"url": "https://pokeapi.co/api/v2/berry-flavor/2/"
},
"potency": 0
},
{
"flavor": {
"name": "sweet",
"url": "https://pokeapi.co/api/v2/berry-flavor/3/"
},
"potency": 0
},
{
"flavor": {
"name": "bitter",
"url": "https://pokeapi.co/api/v2/berry-flavor/4/"
},
"potency": 0
},
{
"flavor": {
"name": "sour",
"url": "https://pokeapi.co/api/v2/berry-flavor/5/"
},
"potency": 0
}
],
"growth_time": 3,
"id": 1,
"item": {
"name": "cheri-berry",
"url": "https://pokeapi.co/api/v2/item/126/"
},
"max_harvest": 5,
"name": "cheri",
"natural_gift_power": 60,
"natural_gift_type": {
"name": "fire",
"url": "https://pokeapi.co/api/v2/type/10/"
},
"size": 20,
"smoothness": 25,
"soil_dryness": 15
}
```

:::tip
For more information, check out [Pino.js documentation](https://getpino.io/#/).
:::
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ features:
title: Request Cache
details: Axios auto-cache feature can make your app requests blazing fast! You can store request results to prevent unneeded network requests.
- icon: 🌲
title: Low Overhead Logs
details: Manipulate your app logs with Pino.js, a super fast, all natural json logger.
title: Logs
details: Display logs for development
---
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"pokemon",
"pokedex"
],
"homepage": "https://pokenode-ts-docs-gabb-c.vercel.app/",
"homepage": "https://pokenode-ts.vercel.app/",
"bugs": {
"url": "https://github.com/Gabb-c/pokenode-ts/issues"
},
Expand All @@ -29,6 +29,16 @@
"files": [
"lib"
],
"sideEffects": false,
"exports": {
".": {
"import": "./lib/index.mjs",
"require": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./package.json": "./package.json",
"./*": "./*"
},
"scripts": {
"build": "tsup --config tsup.config.ts",
"size": "pnpm build --silent && size-limit",
Expand Down Expand Up @@ -83,8 +93,6 @@
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"lint-staged": "^13.2.0",
"pino": "^8.11.0",
"pino-pretty": "^10.0.0",
"prettier": "^2.8.4",
"rimraf": "^4.4.0",
"semantic-release": "^20.1.1",
Expand All @@ -96,11 +104,9 @@
"vitest": "^0.29.2",
"vue": "^3.2.47"
},
"dependencies": {
"peerDependencies": {
"axios": "^1.3.3",
"axios-cache-interceptor": "^1.0.1",
"pino": "^8.10.0",
"pino-pretty": "^9.3.0"
"axios-cache-interceptor": "^1.0.1"
},
"engines": {
"node": ">=14"
Expand Down

0 comments on commit 1824ad6

Please sign in to comment.