3.12.0 • Published 6 months ago

@totemorg/enums v3.12.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

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

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

ParamTypeDescription
...argsObjectData 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

ParamTypeDescription
testNumberTest to assert
errStringError message to throw if test not asserted

ENUMS.neoThread(cb)

Provide a Neo4J connector to the callback.

Kind: static method of ENUMS

ParamTypeDescription
cbfunctionCallback cb(connector)

ENUMS.sqlThread(cb)

Provide a MySQL connector to the callback.

Kind: static method of ENUMS

ParamTypeDescription
cbfunctionCallback 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

ParamTypeDescription
hostStringName of hosting module
cbsObjecthash 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

ParamTypeDescription
srcObjectsource hash
tarObjecttarget hash
deepStringcopy key

ENUMS.Each(A, cb)

Enumerate Object A over its keys with callback cb(key,val).

Kind: static method of ENUMS

ParamTypeDescription
AObjectsource object
cbfunctioncallback (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

ParamTypeDescription
refStringsource URL
cbstring | array | function | nullcallback or data
cbfunctionoptional 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

ParamTypeDescription
msgStringTracing message
...argsObjectTracing arguments

Array

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

ParamTypeDescription
fetchfunctionCallback to fetch the data sent to the cb
cbfunctionCallback 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

ParamTypeDescription
cbfunctionCallback(arg,idx)

Array~all(cb) ⇒

Kind: inner method of Array
Returns: this

ParamTypeDescription
cbfunctionCallback(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

ParamTypeDescription
indexString | Object | functionIndexer
ctxObjectContext 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

ParamTypeDescription
elStringtag html element or one of "?&/:="
atStringtag attributes = {key: val, ...}

String~parseEval($)

Parse "$.KEY" || "$INDEX" expressions given $ hash.

Kind: inner method of String

ParamTypeDescription
$Objectsource hash

String~parseJS(ctx)

Run JS against string in specified context.

Kind: inner method of String

ParamTypeDescription
ctxObjectcontext hash

String~parse$(query)

Return an EMAC "...${...}..." string using supplied context.

Kind: inner method of String

ParamTypeDescription
queryObjectcontext hash

String~parseJSON(def)

Parse string into json or set to default value/callback if invalid json.

Kind: inner method of String

ParamTypeDescription
deffunction | Objectdefault 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

ParamTypeDescription
queryObjecthash of query keys
indexObjecthash of sql-ized indexing keys
flagsObjecthash of flag keys
whereObjecthash 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

ParamTypeDescription
pathStringsource file
optsObject{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

ParamTypeDescription
pathStringsource file
optsObject{keys,comma,newline,limit} options
cbfunctionCallback(recordnull)

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

ParamTypeDescription
pathStringsource file
optsObject{keys,comma,newline,limit,batch} options
cbfunctionCallback( record,...null )

String~trace(msg, req, res)

Trace message to console with optional request to place into syslogs

Kind: inner method of String

ParamTypeDescription
msgStringmessage to trace
reqObjectrequest { sql, query, client, action, table }
resfunctionresponse 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.

ParamTypeDescription
traceBooleantracking switch
everyString | Floattick interval
onFloaton-time or 0 implies infinity
offFloatoff-time or 0
startDatestart date

Contacting, Contributing, Following

Feel free to

License

MIT


© 2012 ACMESDS

3.9.0

6 months ago

3.11.0

6 months ago

3.8.0

6 months ago

3.10.0

6 months ago

3.7.0

6 months ago

3.6.0

6 months ago

3.12.0

6 months ago

3.5.0

7 months ago

3.4.0

12 months ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

1.36.0

1 year ago

1.37.0

1 year ago

1.34.0

1 year ago

1.35.0

1 year ago

1.29.0

1 year ago

1.38.0

1 year ago

1.39.0

1 year ago

1.32.0

1 year ago

1.33.0

1 year ago

1.30.0

1 year ago

1.31.0

1 year ago

1.28.0

1 year ago

1.27.0

2 years ago

1.26.0

2 years ago

1.25.0

2 years ago

1.24.0

2 years ago

1.23.0

2 years ago

1.21.0

2 years ago