Skip to content

Latest commit

 

History

History
496 lines (329 loc) · 10.5 KB

api.md

File metadata and controls

496 lines (329 loc) · 10.5 KB

Addon

setIniFileDirectory

Usage: usage/addon

setIniFileDirectory(iniFileDirectory: string)

reloadIniFile

Usage: usage/addon

reloadIniFile()

loadCryptoLibrary

Usage: usage/addon

loadCryptoLibrary(cryptoLibraryPath: string)

cancelClient

Usage: usage/addon

cancelClient(client: Client, callback?: Function): void | Promise<void>;

languageIsoToSap

Usage: usage/addon

languageIsoToSap(langIsoCode: string): string|Error

languageSapToIso

Usage: usage/addon

languageSapToIso(langSapCode: string): string|Error

setLogFilePath

Usage: usage/addon

setLogFilePath(langSapCode: string): string|Error

Client

Usage: usage/client

Properties

environment : Object, exposed at instance and class level

binding : Object, the Client binding object

id : Number, the client instance id

_id : String, "extended" client instance id, with connection handle, pool id (if managed) and "direct"/"managed" attribute

config: Object, Client configuration, exposing connectionParameters and clientOptions objects

connectionHandle: Number, the client connection handle

alive: Boolean, set to true if connection handle is not NULL (connection open)

pool_id: Number, set to non-zero value in managed clients

connectionInfo: Object exposing RFC Connection attributes, or Error object if the connection is closed

Constructor

The direct client is instantiated using connection parameters and optional client options:

constructor(
    connectionParameters: RfcConnectionParameters,
    clientOptions?: RfcClientOptions )

Another constructor is used by the Connection Pool only. The client instance is already created by Connection Pool and passed to Node.js for Node.js Client instance creation:

constructor(
    clientBinding: RfcClientBinding,
    clientOptions?: RfcClientOptions )

Example:

const Client = require("node-rfc").Client;

const direct_client = new Client({ dest: "QI3" }, { stateless: true });

The managed client is instantiated using the Connection Pool acquire() method.

Client API

Client API methods accept optional callback argument, for callback invocation pattern. When callback not provided, the Promise is returned.

setIniPath

Sets the directory in which to search for the sapnwrfc.ini file.

By default the sapnwrfc library searches for the sapnwrfc.ini in the current working directory of the process. If you want to keep it in a different directory, use this function to tell the sapnwrfc library about the new path.

After you have changed the directory, the NW RFC lib automatically loads the contents of the new sapnwrfc.ini file from that directory.

setIniPath(pathName: string, callback?: Function): void | Promise<void>

open

Open connection (direct client only):

connect(callback?: Function): void | Promise<Client> // for backwards compatibility, to be deprecated
open(callback?: Function): void | Promise<Client>

close

Close connection (direct client only):

close(callback?: Function): void | Promise<void>

cancel

Cancel connection:

cancel(callback?: Function): void | Promise<any>

ping

RFC ping the ABAP backend system, returning:

  • boolean true when successful
  • boolean false and RFC error object, when not
  • Error object when the connection is already closed
ping(callback?: Function): void | Promise<boolean>

resetServerContext

Reset server context, making the next call ABAP stateless, like after opening new connection:

resetServerContext(callback?: Function): void | Promise<void>

release

Release the client connection back to Pool (managed client only). No arguments required:

release(callback?: Function): void | Promise<void>

call

Invoke the ABAP RFM rfmName, providing RFM parameters rfmParams and optional callOptions:

call(
    rfmName: string,
    rfmParams: RfcObject,
    callOptions: RfcClientOptions = {}
): Promise<RfcObject>

invoke

The same as call, used in callback pattern:

invoke(
    rfmName: string,
    rfmParams: RfcObject,
    callback: Function,
    callOptions?: object
)

Connection Pool

Usage: usage/connection-pool

Properties

environment : Object, exposed at instance and class level

binding : Object, the Pool binding object

id : Number, the client instance id

config: Object, exposing Pool configuration, with connectionParameters clientOptions and poolOptions objects, which are available also as direct getters.

status : Object, exposing the number of ready and leased connections

Constructor

export interface RfcPoolConfiguration {
    connectionParameters: RfcConnectionParameters;
    clientOptions?: RfcClientOptions;
    poolOptions?: RfcPoolOptions;
}

constructor(poolConfiguration: RfcPoolConfiguration)

Example:

const Pool = require("node-rfc").Pool;
const pool = new Pool({
    connectionParameters: { dest: "MME" },
    clientOptions: { filter: 2, bcd: "number" },
    poolOptions: { low: 0, high: 4 },
});

Pool API

The result is returned as a promise, unless the optional callback argument provided.

acquire

Acquire one or more managed clients, each with own open connection.

acquire(callback?:Function)  // Acquire 1 client
acquire(1, callback?:Function) // Acquire 1 client
acquire(3, callback?:Function) // Acquire Array of 3 clients

Managed client:

const Pool = require("node-rfc").Pool;
const pool = new Pool({
        connectionParameters: { dest: "QI3},
        clientOptions: {stateless: true},   // optional
        poolOptions: {low: 0, high: 1}  // optional
    });

pool.acquire().then(managed_client => {
    console.log(managed_client.alive); // true
});

release

Release connections of one or more managed clients.

release(client1, callback?:Function)  // Release 1 client
acquire([client1], callback?:Function) // Release 1 client
acquire([client1, client2], callback?:Function) // Release Array of 2 clients

cancel

Cancel connection:

cancel(client, callback?: Function): void | Promise<any>

ready

Check if the number of ready connections is below the pool ready_low and open new connections if needed.

Optionally, the number connections can be provided, to be used instead of the ready_low.

pool.ready(); // check if pool ready_low connections are ready
pool.ready(5); // check if 5 connections are ready
pool.ready(5, callback); // check if 5 connections are ready and call the callback when they are
pool.ready(callback, 5); // check if 5 connections are ready and call the callback when they are
release(client1, callback?:Function)  // Release 1 client
acquire([client1], callback?:Function) // Release 1 client
acquire([client1, client2], callback?:Function) // Release Array of 2 clients

closeAll

:exclamation_mark: Internal use only.

Close all open connections, ready and leased. Not synchronized with client or pool mutexes, therefore not supported.

All open connections are anyway closed when Pool destructor called.

closeAll(callback?: Function) // close all ready and leased connections

Server

Usage: usage/server

Properites

Constructor

export type RfcServerConfiguration = {
    serverConnection: RfcConnectionParameters;
    clientConnection: RfcConnectionParameters;
    serverOptions?: RfcServerOptions;
};

export interface RfcServerBinding {
    new (serverConfiguration: RfcServerConfiguration): RfcServerBinding;
}

Server API

start

 start(callback?: Function): void | Promise<void>

Launch Server instance.

stop

stop(callback?: Function): void | Promise<void>

Stop Server instance.

addFunction

    addFunction(
        abapFunctionName: string,
        jsFunction: Function,
        callback?: Function
    ): void | Promise<void>

Register JavaScript function as ABAP function on Node.js server.

removeFunction

removeFunction(
    abapFunctionName: string,
    callback?: Function
): void | Promise<void>

Un-register JavaScript function on Node.js server.

Throughput

Usage: usage/throughput

Properties

status providing the monitoring statistics:

export interface RfcThroughputStatus {
    numberOfCalls: number;
    sentBytes: number;
    receivedBytes: number;
    applicationTime: number;
    totalTime: number;
    serializationTime: number;
    deserializationTime: number;
}

clients exposing a Set of monitored clients

handle exposing the internal Throughput object handle, assigned by SAP NWRFC SDK

Constructor

constructor(client?: Client | Array<Client>)

Throughput API

setOnConnection

Assign one or more clients to Throughput instance:

setOnConnection(client: Client | Array<Client>)

Example:

throughput.setOnConnection([client1, client2]);

removeFromConnection

The opposite of setOnConnection:

removeFromConnection(client: Client | Array<Client>)

reset

Reset Throughput counters:

reset();

destroy

Free the Throughput object, normally not needed becuse called in a destructor:

destroy();