generated from thaitype/npm-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
41 changed files
with
7,919 additions
and
136 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,74 @@ | ||
--- | ||
'@thaitype/data-viewer-server': major | ||
--- | ||
|
||
Release first stable version | ||
|
||
## Breaking Changes | ||
|
||
- Type changed from `ServerOptions` to `DataViewerOptions` | ||
- Moved `logger?: LoggerOptions;` from `DataViewerOptions` to `StartOptions` with new option name `loggerOption?: LoggerOptions;` for `start` method | ||
- Used `logger?: Logger;` in `DataViewerOptions` for custom logger | ||
- Moved `port` from `DataViewerOptions` to `start` method (with type `StartOptions`) | ||
`DataViewerOptions` is now dataViewer.addOption | ||
- `TableComponent` interface `data` property is allow `(Record<string, unknown> | object)[];` type. | ||
|
||
## New Features | ||
|
||
## **Create Data Container** | ||
|
||
Sometimes, you may want to create a data container and add data to it later. | ||
|
||
```ts | ||
export function myReport(){ | ||
const container = new Container(); | ||
container.addHeader('My Header'); | ||
return container.get(); | ||
} | ||
|
||
dataViewer.addContainer(myReport()); | ||
dataViewer.start(); | ||
``` | ||
|
||
## Support Custom Server | ||
|
||
You can use the `registerMiddleware` method to integrate with your existing server. | ||
|
||
```ts | ||
const getUsers = async () => (await fetch('https://jsonplaceholder.typicode.com/users')).json(); | ||
|
||
const dataViewer = new DataViewer({ | ||
path: '/viewer', | ||
}); | ||
|
||
dataViewer.addHeader('User Table'); | ||
dataViewer.addTable(await getUsers()); | ||
|
||
const app = express(); | ||
dataViewer.registerMiddleware(app); | ||
|
||
app.listen(3000, async () => console.log(`Already servered on http://localhost:3000/viewer`)); | ||
``` | ||
|
||
## Support Custom Logger | ||
|
||
You can use the `logger` option to integrate with your existing log, | ||
this example uses [pino](https://github.com/pinojs/pino) log | ||
|
||
```ts | ||
import pino from 'pino'; | ||
const logger = pino(); | ||
|
||
const stringLogger = { | ||
log: (message: string) => logger.info(message), | ||
debug: (message: string) => logger.debug(message), | ||
info: (message: string) => logger.info(message), | ||
warn: (message: string) => logger.warn(message), | ||
error: (message: string) => logger.error(message), | ||
}; | ||
|
||
const dataViewer = new DataViewer({ | ||
path: '/viewer', | ||
logger: stringLogger, | ||
}).start(); | ||
``` |
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,35 @@ | ||
name: Test E2E | ||
on: | ||
pull_request: | ||
branches: | ||
- 'main' | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
project-path: | ||
- 'end-to-end/test-cjs' | ||
- 'end-to-end/test-esm' | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'pnpm' | ||
cache-dependency-path: ${{ matrix.project-path }}/pnpm-lock.yaml | ||
|
||
- run: pnpm install --frozen-lockfile | ||
working-directory: ${{ matrix.project-path }} | ||
|
||
- run: pnpm run test | ||
working-directory: ${{ matrix.project-path }} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Build | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
|
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 |
---|---|---|
|
@@ -127,4 +127,6 @@ dist | |
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
.pnp.* | ||
|
||
.tmp |
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
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,11 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
root: true, | ||
ignorePatterns: ["**.test.ts"], | ||
rules: { | ||
'@typescript-eslint/consistent-type-imports': 'error', | ||
} | ||
}; |
Oops, something went wrong.