Skip to content

Commit

Permalink
Add OpenAF channel format support for input and output
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaguiar committed Feb 28, 2024
1 parent 66710e0 commit 45f4037
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ List of data input types that can be auto-detected (through the file extension o
| base64 | A base64 text format |
| db | A JDBC query to a database |
| md | A Markdown format |
| ch | An OpenAF channel format |
| mdtable | A Markdown table format |
| jsonschema | Given a JSON schema format tries to generate sample data for it |
| lines | A given string/text to be processed line by line |
Expand Down Expand Up @@ -115,6 +116,7 @@ List of available formats to use with the _output_ option:
| html | An HTML format |
| db | Output to a JDBC database |
| md | A Markdown format |
| ch | An OpenAF channel format |
| mdtable | A Markdown table format (only for list outputs) |
| openmetrics | Converts a map or list to OpenMetrics format |
| base64 | A base64 text format |
Expand Down Expand Up @@ -195,6 +197,20 @@ List of options to use when _input=db_ (SQL query):
---

## 🧾 CH input options

List of options to use when _input=ch_:

| Option | Type | Description |
|--------|------|-------------|
| inch | String | A JSON/SLON configuration string with type and options/url |
| inchall | Boolean | A boolean flag to determine if the input map will be used for a getAll query |

> Example of options provided in JSON: inch="{type:'mvs',options:{file:'data.db'}}"
> Example of optiosn provided in SLON: inch="(type: remote, url: 'http://some.host:1234/chname')"
---

## 🧾 CSV input/output options

List of options to use with the _inputcsv_ input option (when input type=csv) and/or the _csv_ output option (when output=csv). Both expect the corresponding options to be provided in single JSON or SLON value (see below for example):
Expand Down Expand Up @@ -283,6 +299,21 @@ List of options to use when _output=db_:
---

## 🧾 CH output options

List of options to use when _output=ch_:

| Option | Type | Description |
|--------|------|-------------|
| ch | String | A JSON/SLON configuration string with type and options/url |
| chkey | String | A comma delimited list of map keys to build a key from each array value |
| chunset | Boolean | If true the input data will be used to unset data on the output channel instead of set |

> Example of options provided in JSON: ch="{type:'mvs',options:{file:'data.db'}}"
> Example of optiosn provided in SLON: ch="(type: remote, url: 'http://some.host:1234/chname')"
---

## 🧾 XLS output options

List of options to use when _output=xls_:
Expand Down
23 changes: 23 additions & 0 deletions src/include/inputFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,29 @@ var _inputFns = new Map([
_$o(r, options)
}
}],
["ch", (r, options) => {
_showTmpMsg()
if (isUnDef(params.inch)) _exit(-1, "inch is not defined.")
params.inch = _fromJSSLON(params.inch)
if (isMap(params.inch)) {
if (isUnDef(params.inch.type)) _exit(-1, "inch.type is not defined.")
if (params.inch.type == "remote") {
$ch("oafp::indata").createRemote(params.inch.url)
} else {
$ch("oafp::indata").create(params.inch.type, params.inch.options)
}

var _r = _fromJSSLON(r)
if (toBoolean(params.inchall) || r.trim().length == 0) {
_$o($ch("oafp::indata").getAll(isMap(_r) ? _r : __), options)
} else {
_$o($ch("oafp::indata").get(isMap(_r) ? _r : __), options)
}
$ch("oafp::indata").destroy()
} else {
_exit(-1, "inch is not a valid map.")
}
}],
["db", (r, options) => {
if (isString(r)) {
_showTmpMsg()
Expand Down
24 changes: 24 additions & 0 deletions src/include/outputFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ var _outputFns = new Map([
print(af.fromBytes2String(af.toBase64Bytes(_o)))
}
}],
["ch", (r, options) => {
if (isUnDef(params.ch)) _exit(-1, "For output=ch you need to provide a ch=\"(type: ...)\"")
if (isUnDef(params.chkey)) _exit(-1, "For output=ch you need to provide a chkey=\"key1, key2\"")

var _r = (isMap(r) ? [ r ] : r)
params.ch = _fromJSSLON(params.ch)
if (isMap(params.ch)) {
if (isUnDef(params.ch.type)) _exit(-1, "ch.type is not defined.")
if (params.ch.type == "remote") {
$ch("oafp::outdata").createRemote(params.ch.url)
} else {
$ch("oafp::outdata").create(params.ch.type, params.ch.options)
}

if (toBoolean(params.chunset)) {
$ch("oafp::outdata").unsetAll(params.chkey.split(",").map(r => r.trim()), _r)
} else {
$ch("oafp::outdata").setAll(params.chkey.split(",").map(r => r.trim()), _r)
}
$ch("oafp::outdata").destroy()
} else {
_exit(-1, "Invalid ch parameter")
}
}],
["db", (r, options) => {
if (!isArray(r) || r.length < 1) _exit(-1, "db is only supported for filled arrays/lists")
params.dbtable = _$(params.dbtable, "outdbtable").isString().default("data")
Expand Down

0 comments on commit 45f4037

Please sign in to comment.