@zetwerk/zetwerk-inter-server-virtuals

1.0.5 • Public • Published

Zetwerk Inter Server Virtuals

npm version

This plugin will run at mongoose model level and create virtuals using the data from external servers based on the configurations passed to it.

Installation

Requires mongoose to run.

$ npm i @zetwerk/zetwerk-inter-server-virtuals --save

Once installed, import the plugin in the required model.

const interServerPlugin = require('@zetwerk/zetwerk-inter-server-virtuals');

Enable the plugin.

schema.plugin(interServerPlugin, config);

Configurations

Following configuration options are available

Option Description
key Name of the virtual key to be appended
localField Name of the field to be mapped in local (support dot notation access. eg: 'a.b.c')
foreignField Name of the field to be mapped in remote (support dot notation access. eg: 'a.b.c')
responseKey Optional, if not passsed, it will assume the response sent by remote API is an array of objects (support dot notation access. eg: 'a.b.c')
bulk.queryName Optional, only needed if your remote API support bulk operation
options Native NodeJS http request options

Example

Below given is a sample configuration object.

const config = {
    key: 'customerDetails',
    localField: 'customerId',
    foreignField: '_id',
    responseKey: 'data',
    bulk: {
        queryName: 'customerIds'
    },
    options: {
        protocol: 'http:',
        hostname: 'localhost',
        port: 6000,
        path: '/v1/customer',
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'authorizationtoken': '<AUTH_TOKEN>'
        }
    }
};

*options is the native NodeJS http options, so you can pass all the options supported by NodeJS http module.

Please see following link for all the available options: https://nodejs.org/api/http.html#http_http_request_options_callback

Package Sidebar

Install

npm i @zetwerk/zetwerk-inter-server-virtuals

Weekly Downloads

2

Version

1.0.5

License

ISC

Unpacked Size

6.54 kB

Total Files

3

Last publish

Collaborators

  • balaji1
  • omkarzetwerk
  • arpitsr
  • deepak-zetwerk