Skip to content

Commit

Permalink
Merge pull request #7 from alphauslabs/chore/move-log-inside-showDebug
Browse files Browse the repository at this point in the history
show log only when showDebug is true
  • Loading branch information
henry0hai authored Mar 25, 2024
2 parents c3d6ef7 + 9f21b81 commit ce8e6f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Use Node.js 8.x
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
registry-url: https://npm.pkg.github.com/
node-version: 8.x
Expand Down
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Typescript package for parsing grpc chunk data

First, add a `.npmrc` file with the following content:

```
```npmrc
@alphauslabs:registry=https://npm.pkg.github.com
```

Expand All @@ -17,7 +17,7 @@ Then install:

Import the **parseGrpcData** function in your file via the command

```
```ts
import { parseGrpcData } from '@alphauslabs/grpc-chunk-parser';
```

Expand All @@ -42,7 +42,7 @@ parseGrpcData has **5 parameters**:

## Example

```
```ts
import { parseGrpcData } from '@alphauslabs/grpc-chunk-parser';

parseGrpcData(
Expand All @@ -57,19 +57,19 @@ parseGrpcData(
}
},
{
limiter: 20, // Every 20 items received, the function in
// param 3 `onChunkReceive` will be called.
showDebug: true, // default false (optional)
limiter: 20, // Every 20 items received, the function in param 3 `onChunkReceive` will be called.
concatData: false,
objectPrefix: 'result.aws',
},
(data: any) => {
console.log('returned data', data);
},
(fullData: any) => {
console.log('On finish here', fullData)
console.log('On finish here', fullData);
},
(err: any) => {
console.log('Error here, err)
console.log('Error here, err');
}
);
```
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ export const parseGrpcData = async (
onError?: (e: any) => void
) => {
try {
console.time('parseGrpcData');

const { url, method, headers } = requestObject;
const { limiter = 1, concatData = false, showDebug = false } = dataObject ?? {};

let objectPrefix = dataObject?.objectPrefix ?? 'result';

const allData: DynamicObject[] = [];
const limiterData: DynamicObject[] = [];
const hasLimiter = limiter && limiter > 0;

if (showDebug) {
console.time('parseGrpcData');
}

const res: any = await fetch(url, {
method: method.toUpperCase(),
headers,
Expand Down Expand Up @@ -144,8 +149,8 @@ export const parseGrpcData = async (
if (showDebug) {
console.log("count: ", count);
console.log("failed count: ", failedCount);
console.timeEnd('parseGrpcData');
}
console.timeEnd('parseGrpcData');
onFinish(allData);
}
} catch (error) {
Expand Down

0 comments on commit ce8e6f4

Please sign in to comment.