profoundjs.registerAPI()
Â
This API is used to register a custom API that can optionally have access to the fields collection and the argument names of a Profound.js module from which it is called. To properly register the custom API, the call to profoundjs.registerAPI() should be made within the context of your server's start.js file.
The custom API is attached to the pjs object, which is exposed to every Profound.js module.
Parameter
API config - An object with the following properties:
name - The name of the function to register as an API.
transform - Pass Boolean true to have Profound.js modify the argument list during the module transformation process.Â
addArgNames - Pass Boolean true to include argument names when the argument list is transformed. This property is ignored if "transform" is not also set to true.
description - a text description of the API
When "transform" is used, the API will receive the following arguments:
fields collection - An Array representing each scope in the current call stack, with element zero being the most recent calling stack entry. The array has an extra element at the end which represents the global module scope. Each scope array entry contains an Array of Profound.js fields that have been defined by pjs.define() in the given scope.
control options - An Object containing properties/values that equate to RPG control specifications.
args - An Array containing the pre-transform arguments passed to the function.
argNames - An Array containing the name of each pre-transform argument. This argument is only passed if the "argNames" config property is also set to Boolean true.
Â
Example
start.js
#!/usr/bin/env node
// Load Profound.js
var profoundjs = require("./index.js");
// Register custom API
profoundjs.myAPI = function(fieldsArr, controlOptions, args, argNames) {
console.log(arguments);
}
profoundjs.registerAPI({
name: "myAPI",
transform: true,
addArgNames: true
});
// Process command line arguments
profoundjs.rlog = process.argv.includes("--rlog");
profoundjs.tlog = process.argv.includes("--tlog");
// Apply configuration
var config = require("./config.js");
profoundjs.applyConfig(config);
// Start Profound.js server
profoundjs.server.listen();
console.log('Profound.js server running at http://%s:%d/', config.host, config.port);
Â
test.js (Profound.js module in the modules directory)
function test() {
pjs.define("myfield", {type: "packed decimal", length: 7, decimals: 2, initValue: 12345 });
pjs.myAPI(myfield);
}
module.exports.run = test;
Â
Console output when test.js is executed
{
// fieldsArr
'0':
[ { _info: [Object],
__SQLCA__: [Object],
__SQLCAID__: [Object],
__SQLAID__: [Object],
__SQLCABC__: [Object],
__SQLABC__: [Object],
__SQLCODE__: [Object],
__SQLCOD__: [Object],
__SQLERRML__: [Object],
__SQLERL__: [Object],
__SQLERRMC__: [Object],
__SQLERM__: [Object],
__SQLERRP__: [Object],
__SQLERP__: [Object],
__SQLERR__: [Object],
__SQLERRD__: [Object],
__SQLWRN__: [Object],
__SQLWARN__: [Object],
__SQLSTATE__: [Object],
__SQLSTT__: [Object],
__flags__: [Object],
__myfield__: [Object] },
{ _info: [Object], _activated: true } ],
// controlOptions
'1': {},
// args
'2': [ 12345 ],
// argNames
'3': [ 'myfield' ]
Â
}
Â