Skip to content

Latest commit

 

History

History
547 lines (328 loc) · 12.4 KB

warp10.Warp10.md

File metadata and controls

547 lines (328 loc) · 12.4 KB

@senx/warp10 / Modules / warp10 / Warp10

Class: Warp10

warp10.Warp10

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Warp10(params?)

Create new Warp 10 connector.

Parameters

Name Type Description
params? Object { endpoint: string; debug?: boolean; silent?: boolean, timeUnit: TimeUnits } endpoint - Warp 10 endpoint, without /api/v0 at the end. debug - Enable debug silent - Do not produce logs timeUnit - Platform timeUnit
params.debug? boolean -
params.endpoint? string -
params.headers? Object -
params.silent? boolean -
params.timeUnit? TimeUnits -
params.timeout? number -

See

TimeUnits headers - custom HTTP headers timeout - http Timeout

Example

// standard constructor
const w10 = new Warp10({endpoint: 'https://sandbox.senx.io'});
// builder pattern
const w10 = new Warp10().endpoint('https://sandbox.senx.io').timeUnit(TimeUnits.US);

Defined in

warp10.ts:63

Properties

LOG

Private LOG: Logger

Defined in

warp10.ts:38


_endpoint

Private _endpoint: undefined | URL

Defined in

warp10.ts:39


_headers

Private Optional _headers: Object = {}

Index signature

▪ [key: string]: string

Defined in

warp10.ts:41


_timeUnit

Private _timeUnit: undefined | TimeUnits

Defined in

warp10.ts:40


_timeout

Private _timeout: number = 0

Defined in

warp10.ts:42


client

Private client: any

Defined in

warp10.ts:37


url

Private url: undefined | string

Defined in

warp10.ts:36

Methods

debug

debug(debug): Warp10

Parameters

Name Type
debug boolean

Returns

Warp10

Defined in

warp10.ts:95


delete

delete(deleteToken, className, labels, start, end, deleteAll?): Promise<{ result: string }>

Parameters

Name Type Default value Description
deleteToken string undefined Delete token
className string undefined ClassName, could be a regexp starting with '~' (ie: '~io.warp10.*' )
labels object undefined Labels key value map. Could be a regexp starting with '~' (ie: { 'myLabel': '~sensor_.*' } )
start string undefined ISO8601 UTC Date
end string undefined ISO8601 UTC Date
deleteAll boolean false Default is 'false'

Returns

Promise<{ result: string }>

Example

// delete data between 2 dates
console.log(await w10.delete(deleteToken, '~io.warp10.test*', {key: 'value'}, '2019-11-11T12:34:43.388409Z', '2019-11-21T12:34:43.388409Z'));

// delete all
console.log(await w10.delete(deleteToken, '~io.warp10.test*', {key: 'value'}, '', '', true));

Defined in

warp10.ts:320


endpoint

endpoint(endpoint): Warp10

Parameters

Name Type
endpoint undefined | string

Returns

Warp10

Defined in

warp10.ts:81


exec

exec(warpScript): Promise<{ meta: { elapsed: number ; fetched: number ; ops: number } ; result: any[] }>

Execute a WarpScript against a Warp 10 instance

Parameters

Name Type Description
warpScript string WarpScript to execute

Returns

Promise<{ meta: { elapsed: number ; fetched: number ; ops: number } ; result: any[] }>

Example

 // Prints "[4]":
 console.log(await w10.exec('2 2 +'))

Defined in

warp10.ts:193


fetch

fetch(readToken, className, labels, start, stop, format?, dedup?): Promise<{ meta: { elapsed: number ; fetched: number ; ops: number } ; result: any[] }>

Fetch data against a Warp 10 instance

Parameters

Name Type Default value Description
readToken string undefined Read token
className string undefined ClassName, could be a regexp starting with '~' (ie: '~io.warp10.*' )
labels object undefined Labels key value map. Could be a regexp starting with '~' (ie: { 'myLabel': '~sensor_.*' } )
start string undefined ISO8601 UTC Date
stop any undefined ISO8601 UTC Date if 'start' is a ISO8601 date. Timespan (in platform timeunit format) if 'start' is a timestamp
format "raw" | "text" | "json" | "fulltext" | "tsv" | "fulltsv" | "pack" | "formatted" 'formatted' Output format: text' | 'fulltext' | 'json' | 'tsv' | 'fulltsv' | 'pack' | 'raw' | 'formatted', default is 'formatted'
dedup boolean true Deduplicates data (default is true)

Returns

Promise<{ meta: { elapsed: number ; fetched: number ; ops: number } ; result: any[] }>

Example

// fetch raw data between 2 dates
console.log(await w10.fetch(readToken, '~io.warp10.*', {}, '2019-11-11T12:34:43.388409Z', '2019-11-21T12:34:43.388409Z', 'json'));

// Fetch data with a time span
console.log(await w10.fetch(readToken, '~.*', {}, '2019-11-21T12:34:43.388409Z', 86400000000 * 5));

Defined in

warp10.ts:225


formatGTS

Private formatGTS(gtsList): { attributes: any = gts.a; data: any[] ; labels: any = gts.l; name: any = gts.c }[]

Parameters

Name Type
gtsList any[]

Returns

{ attributes: any = gts.a; data: any[] ; labels: any = gts.l; name: any = gts.c }[]

Defined in

warp10.ts:373


formatLabels

Private formatLabels(labels): string

Parameters

Name Type
labels any

Returns

string

Defined in

warp10.ts:365


getOptions

Private getOptions(path, method?, warpToken?): any

Build got request options from defined options

Parameters

Name Type Default value Description
path string undefined request path
method string 'GET' request method
warpToken? string undefined the X-Warp10-Token, if any

Returns

any

Defined in

warp10.ts:164


headers

headers(headers): Warp10

Parameters

Name Type
headers Object

Returns

Warp10

Defined in

warp10.ts:90


meta

meta(writeToken, meta): Promise<{ count: number ; response: string }>

Update Meta

Parameters

Name Type Description
writeToken string Write token
meta { attributes: object ; className: string ; labels: object }[] Metadata key value map to update

Returns

Promise<{ count: number ; response: string }>

Example

// write meta
  console.log(await w10.meta(writeToken, [{
    className: 'io.warp10.test',
    labels: {key: 'value'},
    attributes: {attr: 'value'}
  }]));

Defined in

warp10.ts:356


send

Private send(options, data?): Promise<any>

Parameters

Name Type
options RequestOptions | RequestOptions
data? any

Returns

Promise<any>

Defined in

warp10.ts:117


silent

silent(silent): Warp10

Parameters

Name Type
silent boolean

Returns

Warp10

Defined in

warp10.ts:100


timeUnit

timeUnit(timeUnit): Warp10

Parameters

Name Type
timeUnit TimeUnits

Returns

Warp10

Defined in

warp10.ts:105


timeout

timeout(to): Warp10

Parameters

Name Type
to number

Returns

Warp10

Defined in

warp10.ts:110


update

update(writeToken, datapoints): Promise<{ count: number ; response: undefined | string }>

Update datapoints

Parameters

Name Type Description
writeToken string Write token
datapoints (string | DataPoint)[] Datapoints to update

Returns

Promise<{ count: number ; response: undefined | string }>

Example

console.log(await w10.update(writeToken, [
   {timestamp: moment.utc().valueOf() * 1000, className: 'io.warp10.test', labels: {key: 'value'}, value: 54},
   '1380475081000000// io.warp10.test{key=value} T',
   '1566893344654882/48.81:-4.147/124 io.warp10.test{key=value} [8.2 151 152 1568189745655509/40.6:-74/14 ]',
 ]));

Defined in

warp10.ts:281


formatValues

Static Private formatValues(value): string | number | boolean

Parameters

Name Type
value string | number | boolean

Returns

string | number | boolean

Defined in

warp10.ts:369