0.0.1 • Published 5 months ago

@dozerjs/node v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Overview

This repository is a typescript wrapper over gRPC APIs that are automatically generated when you run Dozer.

Installation

yarn add @dozerjs/node

AuthClient

getAuthToken(filter: string): Promise<string>

Generate a user token with custom access more detail

import { AuthClient } from '@dozerjs/node';

const client = new AuthClient({
  authToken: MASTER_TOKEN
});
const token = await client.authToken(JSON.stringify({
  Custom: {
    stock: {
      $filter: {},
    },
  }
}));

CommonClient

getEndpoints(): Promise<string[]>

Get a name list of all endpoints

import { CommonClient } from '@dozerjs/node';
const client = new CommonClient();
const endpoints = await client.getEndpoint();

getFields(endpoint: string): Promise<FieldDefinition.AsObject[]>

Get fields defination for the endpoint

import { CommonClient } from '@dozerjs/node';
const client = new CommonClient();
const fields = await client.getFields('stock')

count(endpoint: string, query?: DozerQUery): Promise<FieldDefinition.AsObject[]>

Count query returns number of records in particular source.

import { CommonClient } from '@dozerjs/node';
const client = new CommonClient();
const count = await client.getCount('stock');

query<T>(endpoint: string, query?: DozerQUery): Promise<[FieldDefinition.AsObject[], DozerRecord<T>[]]>

Query method is used to fetch records from cache more detail

import { CommonClient } from '@dozerjs/node';
const client = new CommonClient();
const [fields, records] = await client.query('stock');

onEvent(options: DozerOnEventOption[]>

Create a gRPC stream to monitor real-time store modifications for multiple endpoints.

import { CommonClient, RecordMapper } from '@dozerjs/node';
import { EventType, Operation } from '@dozerjs/node/gen/types_pb';
const client = new CommonClient();

const options = [
  endpoint: 'stock',
  eventType: EventType.ALL
];

const fieldsMap = options.reduce((map, option) => {
  map[option.endpoint] = client.getFields(option.endpoint).then((fields) => new RecordMapper(fields));
  return map;
}, {});

const stream = client.onEvent(options);

stream.on('data', (operation: Operation) => {
  fieldsMap[operation.getEndpointName()].then((mapper) => {
    const data = {};
    data['endpoint'] = operation.getEndpointName();
    data['typ'] = operation.getTyp();
    if (operation.getOld()) {
      data['old'] = mapper.mapRecord(operation.getOld());
    }
    if (operation.getNew()) {
      data['new'] = mapper.mapRecord(operation.getNew());
    }
    console.log(JSON.stringify(data));
  });
});

HealthClient

healthCheck(): Promise<HealthCheckResponse.ServingStatus>

import { HealthClient } from '@dozerjs/node';

const client = new HealthClient();
const status = await client.healthCheck();

healthWatch(): grpc.ClientReadableStream<HealthCheckResponse.ServingStatus>

import { HealthClient } from '@dozerjs/node';

const client = new HealthClient();
const stream = client.healthWatch();

stream.on('data', (status: HealthCheckResponse.ServingStatus) => {
  console.log('health', status);
})

IngestClient

ingest(): Promise<IngestResponse>

Ingest dat on Dozer pushing data to a gRPC endpoint in a streaming fashion more detail

import { IngestClient } from '@dozerjs/node';
import { OperationType } from '@dozerjs/node/gen/types_pb';
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';

const client = new IngestClient();
const request = new IngestRequest();

request.setSchemaName('produce');
request.setTyp(OperationType.INSERT);
request.addNew(new Value().setStringValue('hats'));
request.addNew(new Value().setIntValue(Math.ceil(Math.random() * 10)));
request.addNew(new Value().setTimestampValue(Timestamp.fromDate(new Date())));
client.ingest(request);

ingest_stream(): Promise<IngestResponse>

Ingest dat on Dozer pushing data to a gRPC endpoint in a streaming fashion more detail

import { IngestClient } from '@dozerjs/node';
import { OperationType } from '@dozerjs/node/gen/types_pb';
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';

const client = new IngestClient();
const stream = client.ingest_stream();

const request = new IngestRequest();

request.setSchemaName('produce');
request.setTyp(OperationType.INSERT);
request.addNew(new Value().setStringValue('hats'));
request.addNew(new Value().setIntValue(Math.ceil(Math.random() * 10)));
request.addNew(new Value().setTimestampValue(Timestamp.fromDate(new Date())));
stream.write(request);

stream.end();
0.0.1

5 months ago