Typescript package for parsing grpc chunk data
First, add a .npmrc
file with the following content:
@redjohnzarra:registry=https://npm.pkg.github.com
Then install:
npm i -S @redjohnzarra/grpc-chunk-parser
Import the parseGrpcData function in your file via the command
import { parseGrpcData } from '@redjohnzarra/grpc-chunk-parser';
Then call it like you would a normal function
parseGrpcData(**PARAMS_HERE**)
parseGrpcData has 5 parameters:
- requestObject -
required
- object - request object has 4 properties:- url -
required
- string - the grpc http endpoint - method -
required
- string - http method, currently 'POST' or 'GET' - headers -
required
- object - request headers - body -
required
- object - request body
- url -
- dataObject -
required
(you can pass an empty object) - object - has the following 3 available properties:- limiter -
optional
- integer - number of items to be returned in each chunk (chunk pagesize) - concatData -
optional
- boolean - indicator if data to be returned is every chunk or all the data up to the current limit - objectPrefix -
optional
- string - for returning the object on a specific object path
- limiter -
- onChunkReceive -
optional
- function - returns the chunk data on each chunk received, (or on specific limit/pagesize defined in the 2nd param) - onFinish -
optional
- function - function called when all chunks have been returned, returns the full data - onError -
optional
- function - returns the error if an error is encountered during the request
import { parseGrpcData } from '@redjohnzarra/grpc-chunk-parser';
parseGrpcData(
{
url: "SAMPLE_URL_HERE",
method: 'POST',
headers: {
// request header object
},
body: {
// request body object
}
},
{
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)
},
(err: any) => {
console.log('Error here, err)
}
);