ENUMS
Provides methods to clock, fetch, enumerate, stream, get, and regulate data. Also makes connections to required services: mysql, neo4j, txmail, rxmail.
Install
npm install @totemorg/enums
Start
npm run start
Manage
npm run startdbs # Start database servers
npm run start ? # Show start options
npm run verminor # Roll minor version
npm run vermajor # Roll major version
npm run redoc # Regen documentation
Usage
const { Copy, Each, Extend, Stream, Fetch, ... } = require("@totemorg/enums");
// or
import { Copy, Each, Extend, Stream, Fetch, ... } from "@totemorg/enums";
Program Reference
Open / Close
## Modules- ENUMS
-
Provides enumeration methods, clock, fetch, regulate, stream, fetch and get data. This module documented in accordance with jsdoc. Connections to MySQL and Neo4J databases.
- Array
- String
- Clock
-
Create a clock object with specified trace switch, every interval, on-off times, and start date. See the clock tick method for more information.
ENUMS
Provides enumeration methods, clock, fetch, regulate, stream, fetch and get data. This module documented in accordance with jsdoc. Connections to MySQL and Neo4J databases.
Requires: module:os
, module:cluster
, module:fs
, module:http
, module:https
, module:vm
, module:cp
, module:crypto
, module:stream
, module:mysql
, module:neo4j-driver
, module:nodemailer
, module:nodemailer-smtp-transport
Author: ACMESDS
ENUMS.Log
Dump message to the console.
Kind: static constant of ENUMS
Param | Type | Description |
---|---|---|
...args | Object |
Data to dump |
ENUMS.Regulate()
Regulate callbacks to cb(t,ctx) on events defined by a trigger spec:
spec = STEP / ONSTEPS / OFFSTEPS / START / END
where
subspec = NUMBER | NUMBER [s|m|h|d|y] | dd-mm-yr
The context ctx can define:
ctx.queue = "task queue" to share job status
ctx.batch = NUMBER of records returned in callback cb(t,recs)
ctx.client = "client name" to chage this request
ctx.source = "sql table" record source
ctx.fields = "field, ..." source fields
ctx.priority = NUMBER of seconds to monitor signoff-status if required by client
Kind: static method of ENUMS
ENUMS.Assert(test, err)
Assert a test.
Kind: static method of ENUMS
Param | Type | Description |
---|---|---|
test | Number |
Test to assert |
err | String |
Error message to throw if test not asserted |
ENUMS.neoThread(cb)
Provide a Neo4J connector to the callback.
Kind: static method of ENUMS
Param | Type | Description |
---|---|---|
cb | function |
Callback cb(connector) |
ENUMS.sqlThread(cb)
Provide a MySQL connector to the callback.
Kind: static method of ENUMS
Param | Type | Description |
---|---|---|
cb | function |
Callback cb(connector) |
ENUMS.Start(host, cbs)
Start a unit test using an optional $(cmd,ctx)
command processor or a CB()
callback provided in the ctx
context.
Inspect a KEY variable, file, or notebook or function with ?KEY
.
Kind: static method of ENUMS
Param | Type | Description |
---|---|---|
host | String |
Name of hosting module |
cbs | Object |
hash containing CB() callback or $(cmd,ctx) command processor |
ENUMS.Copy(src, tar, deep) ⇒ Object
Copy source hash src to target hash tar. If the copy is shallow (deep = false), a Copy({...}, {}) is equivalent to new Object({...}). In a deep copy, (e.g. deep = "."), src keys are treated as keys into the target thusly:
{
A: value, // sets target[A] = value
"A.B.C": value, // sets target[A][B][C] = value
"A.B.C.": { // appends X,Y to target[A][B][C]
X:value, Y:value, ...
},
OBJECT: [ // prototype OBJECT (Array,String,Date,Object) = method X,Y, ...
function X() {},
function Y() {},
... ]
}
Kind: static method of ENUMS
Returns: Object
- target hash
Param | Type | Description |
---|---|---|
src | Object |
source hash |
tar | Object |
target hash |
deep | String |
copy key |
ENUMS.Each(A, cb)
Enumerate Object A over its keys with callback cb(key,val).
Kind: static method of ENUMS
Param | Type | Description |
---|---|---|
A | Object |
source object |
cb | function |
callback (key,val) |
ENUMS.Fetch(ref, [cb], [cb])
Fetch (GET || PUT || POST || DELETE) information at a specified ref
url
PROTOCOL://HOST/FILE ? QUERY & FLAGS
SITEREF
by using a `data` callback || Array || Object || null where PROTOCOL is
http(s) = http (https) protocol
curl(s) = curl (curls uses certs/fetch.pfx to authenticate)
wget(s) = wget (wgets uses certs/fetch.pfx to authenticate)
mask = http access via rotated proxies
file = file or folder path can include wild cards
lexnex = Lexis-Nexis oauth access to documents
mysql = mysql database
neo4j = neo4j database
When a file path is "/"-terminated, a folder index is returned. File paths
may also contain wild-* cards.
Optional FLAGS
batch = NUMBER of records to fetch
offset = NUMBER of records to offset fetch
select ="FIELD, ..." to fetch
keys = [...] header keys in csv source
comma = "delim" for csv source
newline = "delim" for csv source
Kind: static method of ENUMS
Param | Type | Description |
---|---|---|
ref | String |
source URL |
[cb] |
string | array | function | null
|
callback or data |
[cb] | function |
optional callback when first cb is data |
Example
Fetch( ref, text => { // get request
})
Example
Fetch( ref, [ ... ], stat => { // post request with data hash list
})
Example
Fetch( ref, { ... }, stat => { // put request with data hash
})
Example
Fetch( ref, null, stat => { // delete request
})
ENUMS~siteLink
Fetch quick SITEREFs
https://www.programmableweb.com/search/military
ACLED
https://www.programmableweb.com/api/acled-rest-api-v25
ACCT teliy40602@plexfirm.com / ACLEDsnivel1
API https://developer.acleddata.com/rehd/cms/views/acled_api/documents/API-User-Guide.pdf
SITE https://developer.acleddata.com/
The Armed Conflict Location & Event Data Project (ACLED) is a real-time data and and crisis analysis and mapping project on political violence and protest across the world. ACLED's mission is to produce dis-aggregated, locally informed data and analysis globally in real time. An ACLED REST API enables users to retrieve data about actors, actor type, country, region and get data in JSON, XML, CSV or text. Filter data by date, area, pagination, etc.
Animetrics FIMS
https://www.programmableweb.com/api/animetrics-fims-cloud-rest-api
http://animetrics.com/fims-cloud
Aimed at the law enforcement, security and military intelligence industries, Animetrics' FaceR Identity Management Solution (FIMS) allows organizations to bring mobile security and video surveillance facial-biometrics applications into the field for use in real time. FIMS Cloud is used to centralize and access a user's cloud based photographic stores using facial recognition. FIMS Cloud organizes, searches and centralizes access to photographic stores using 1:many web service based verification engine. Access to the service is provided via a RESTful API. Public documentation is not available.
Navlost WXT Weather Tesseract
https://www.programmableweb.com/api/navlost-wxt-weather-tesseract
The WXT Weather Service provides atmospheric weather information through a REST architecture, HTTP requests, and JSON formats. It integrates METAR/TAF information, sun, and moon calculations, targeting aviation and energy applications. Advanced features include: -Upper atmosphere information (e.g., research, aviation, rocketry, military) -Automated, push-type notification of arbitrary weather-related events (alert service) -Calculation of arbitrary results derived from weather forecast information via a server-side scripting language. The default response type is application/json, although other formats may be supported. At the present time, there is partial support for comma-separated value (CSV) responses.
https://wxt.navlost.eu/api/v1/
https://wxt.navlost.eu/doc/api/
Kind: inner constant of ENUMS
ENUMS~maxFiles
Max files to Fetch when indexing a folder
Kind: inner constant of ENUMS
ENUMS~maxRetry
Fetch wget/curl maxRetry
Kind: inner constant of ENUMS
ENUMS~certs
Fetching certs
Kind: inner constant of ENUMS
ENUMS~Trace(msg, ...args)
Trace log message and args.
Kind: inner method of ENUMS
Param | Type | Description |
---|---|---|
msg | String |
Tracing message |
...args | Object |
Tracing arguments |
Array
-
Array
- ~Extend()
- ~stream(fetch, cb)
- ~any(cb) ⇒
- ~all(cb) ⇒
-
~get(index, ctx) ⇒
Object
Array~Extend()
Extend protototypes of a constructor.
Kind: inner method of Array
Array~stream(fetch, cb)
Serialize an Array to the callback cb(rec,info) or cb(null,stack) at end given a sync/async fetcher( rec, res ).
Kind: inner method of Array
Param | Type | Description |
---|---|---|
fetch | function |
Callback to fetch the data sent to the cb |
cb | function |
Callback to process the fetched data. |
Example
Serialize a list:
function fetcher( rec, info => {
});
[ rec, ...].serial( fetcher, (rec, fails) => {
if ( rec )
// rec = record being serialized
else
// done. fails = number of failed fetches
}
Example
### Serialize a string:
function fetcher( rec, ex => {
// regexp arguments rec.arg0, rec.arg1, rec.arg2, ...
// rec.ID = record number being processed
return "replaced string";
});
"string to search".serial( fetcher, regex, "placeholder key", str => {
// str = final string with all replacements made
});
Array~any(cb) ⇒
Kind: inner method of Array
Returns: this
Param | Type | Description |
---|---|---|
cb | function |
Callback(arg,idx) |
Array~all(cb) ⇒
Kind: inner method of Array
Returns: this
Param | Type | Description |
---|---|---|
cb | function |
Callback(arg,idx) |
Array~get(index, ctx) ⇒ Object
Index an array using a indexor:
string of the form "to=from & to=eval & to & ... & !where=eval"
hash of the form {to: from, ...}
callback of the form (idx,array) => { ... }
The "!where" clause returns only records having a nonzero eval.
Kind: inner method of Array
Returns: Object
- Indexed data
Param | Type | Description |
---|---|---|
index |
String | Object | function
|
Indexer |
ctx | Object |
Context of functions etc |
Example
[{x:1,y:2},{x:10,y:20}].get("u=x+1&v=sin(y)&!where=x>5",Math)
{ u: [ 11 ], v: [ 0.9129452507276277 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("x")
{ x: [ 1, 10 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("x&mydata=y")
{ mydata: [ 2, 20 ], x: [ 1, 10 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("mydata=[x,y]")
{ mydata: [ [ 1, 2 ], [ 10, 20 ] ] }
Example
[{x:1,y:2},{x:10,y:20}].get("mydata=x+1")
{ mydata: [ 2, 11 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("",{"!all":1})
{ x: [ 1, 10 ], y: [ 2, 20 ] }
Example
[{x:1,y:2},{x:10,y:20}].get("")
[ { x: 1, y: 2 }, { x: 10, y: 20 } ]
Example
[{x:1,y:2},{x:10,y:20}].get("u")
{ u: [ undefined, undefined ] }
Example
[[1,2,3],[10,20,30]].get("1&0")
{ '0': [ 1, 10 ], '1': [ 2, 20 ] }
String
String~stream()
Kind: inner method of String
String~replaceSync()
Kind: inner method of String
String~tag(el, at) ⇒ String
Tag url with specified attributes.
Kind: inner method of String
Returns: String
- tagged results
Param | Type | Description |
---|---|---|
el | String |
tag html element or one of "?&/:=" |
at | String |
tag attributes = {key: val, ...} |
String~parseEval($)
Parse "$.KEY" || "$[INDEX]" expressions given $ hash.
Kind: inner method of String
Param | Type | Description |
---|---|---|
$ | Object |
source hash |
String~parseJS(ctx)
Run JS against string in specified context.
Kind: inner method of String
Param | Type | Description |
---|---|---|
ctx | Object |
context hash |
String~parse$(query)
Return an EMAC "...${...}..." string using supplied context.
Kind: inner method of String
Param | Type | Description |
---|---|---|
query | Object |
context hash |
String~parseJSON(def)
Parse string into json or set to default value/callback if invalid json.
Kind: inner method of String
Param | Type | Description |
---|---|---|
def |
function | Object
|
default object or callback that returns default |
String~parsePath(query, index, flags, where) ⇒ Array
Parse a "PATH?PARM&PARM&..." url into the specified query, index, flags, or keys hash as directed by the PARM = ASKEY := REL || REL || _FLAG = VALUE where REL = X OP X || X, X = KEY || KEY$[IDX] || KEY$.KEY and returns [path,file,type].
Kind: inner method of String
Returns: Array
- [path,table,type,area,url]
Param | Type | Description |
---|---|---|
query | Object |
hash of query keys |
index | Object |
hash of sql-ized indexing keys |
flags | Object |
hash of flag keys |
where | Object |
hash of sql-ized conditional keys |
String~chunkFile(path, opts, {Function))
Chunk stream at path by splitting into newline-terminated records. Callback cb(record) until the limit is reached (until eof when !limit) with cb(null) at end.
Kind: inner method of String
Param | Type | Description |
---|---|---|
path | String |
source file |
opts | Object |
{newline,limit} options |
{Function) | cb Callback(record) |
String~parseFile(path, opts, cb)
Parse a csv/txt/json stream at the specified path dependings on if the keys is
[] then record keys are determined by the first header record;
[ 'key', 'key', ... ] then header keys were preset;
null then raw text records are returned;
function then use to parse records.
The file is chunked using the (newline,limit) chinkFile parameters.
Callsback cb(record) for each record with cb(null) at end.
Kind: inner method of String
Param | Type | Description |
---|---|---|
path | String |
source file |
opts | Object |
{keys,comma,newline,limit} options |
cb | function |
Callback(record |
String~streamFile(path, opts, cb)
Stream file at path containing comma delimited values. The file is split using the (keys,comma) file splitting parameters, and chunked using the (newline,comma) file chunking parameters. Callsback cb( [record,...] ) with the record batch or cb( null ) at end.
Kind: inner method of String
Param | Type | Description |
---|---|---|
path | String |
source file |
opts | Object |
{keys,comma,newline,limit,batch} options |
cb | function |
Callback( [record,...] |
String~trace(msg, req, res)
Trace message to console with optional request to place into syslogs
Kind: inner method of String
Param | Type | Description |
---|---|---|
msg | String |
message to trace |
req | Object |
request { sql, query, client, action, table } |
res | function |
response callback(msg) |
String~serial()
Serialize this String to the callback(results) given a sync/asyn fetcher(rec,res) where rec = {ID, arg0, arg1, ...} contains args produced by regex. Provide a unique placeholder key to back-substitute results.
Kind: inner method of String
Example
"junkabc;junkdef;"
.serial( (rec,cb) => cb("$"), /junk([^;]*);/g, "@tag", msg => console.log(msg) )
produces:
"$$"
String~get()
Fetch using supplied url.
Kind: inner method of String
Clock
Create a clock object with specified trace switch, every interval, on-off times, and start date. See the clock tick method for more information.
Param | Type | Description |
---|---|---|
trace | Boolean |
tracking switch |
every |
String | Float
|
tick interval |
on | Float |
on-time or 0 implies infinity |
off | Float |
off-time or 0 |
start | Date |
start date |
Contacting, Contributing, Following
Feel free to
- submit and status TOTEM issues
- contribute to TOTEM notebooks
- revise TOTEM requirements
- browse TOTEM holdings
- or follow TOTEM milestones
License
© 2012 ACMESDS