@senx/warp10 / Modules / warp10 / Warp10
warp10.Warp10
- debug
- delete
- endpoint
- exec
- fetch
- formatGTS
- formatLabels
- getOptions
- headers
- meta
- send
- silent
- timeUnit
- timeout
- update
- formatValues
• new Warp10(params?)
Create new Warp 10 connector.
| 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);
• Private LOG: Logger
• Private _endpoint: undefined | URL
• Private Optional _headers: Object = {}
▪ [key: string]: string
• Private _timeUnit: undefined | TimeUnits
• Private _timeout: number = 0
• Private client: any
• Private url: undefined | string
▸ debug(debug): Warp10
| Name | Type |
|---|---|
debug |
boolean |
▸ delete(deleteToken, className, labels, start, end, deleteAll?): Promise<{ result: string }>
| 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' |
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));
▸ endpoint(endpoint): Warp10
| Name | Type |
|---|---|
endpoint |
undefined | string |
▸ exec(warpScript): Promise<{ meta: { elapsed: number ; fetched: number ; ops: number } ; result: any[] }>
Execute a WarpScript against a Warp 10 instance
| Name | Type | Description |
|---|---|---|
warpScript |
string |
WarpScript to execute |
Promise<{ meta: { elapsed: number ; fetched: number ; ops: number } ; result: any[] }>
Example
// Prints "[4]":
console.log(await w10.exec('2 2 +'))
▸ 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
| 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) |
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));
▸ Private formatGTS(gtsList): { attributes: any = gts.a; data: any[] ; labels: any = gts.l; name: any = gts.c }[]
| Name | Type |
|---|---|
gtsList |
any[] |
{ attributes: any = gts.a; data: any[] ; labels: any = gts.l; name: any = gts.c }[]
▸ Private formatLabels(labels): string
| Name | Type |
|---|---|
labels |
any |
string
▸ Private getOptions(path, method?, warpToken?): any
Build got request options from defined options
| Name | Type | Default value | Description |
|---|---|---|---|
path |
string |
undefined |
request path |
method |
string |
'GET' |
request method |
warpToken? |
string |
undefined |
the X-Warp10-Token, if any |
any
▸ headers(headers): Warp10
| Name | Type |
|---|---|
headers |
Object |
▸ meta(writeToken, meta): Promise<{ count: number ; response: string }>
Update Meta
| Name | Type | Description |
|---|---|---|
writeToken |
string |
Write token |
meta |
{ attributes: object ; className: string ; labels: object }[] |
Metadata key value map to update |
Promise<{ count: number ; response: string }>
Example
// write meta
console.log(await w10.meta(writeToken, [{
className: 'io.warp10.test',
labels: {key: 'value'},
attributes: {attr: 'value'}
}]));
▸ Private send(options, data?): Promise<any>
| Name | Type |
|---|---|
options |
RequestOptions | RequestOptions |
data? |
any |
Promise<any>
▸ silent(silent): Warp10
| Name | Type |
|---|---|
silent |
boolean |
▸ timeUnit(timeUnit): Warp10
| Name | Type |
|---|---|
timeUnit |
TimeUnits |
▸ timeout(to): Warp10
| Name | Type |
|---|---|
to |
number |
▸ update(writeToken, datapoints): Promise<{ count: number ; response: undefined | string }>
Update datapoints
| Name | Type | Description |
|---|---|---|
writeToken |
string |
Write token |
datapoints |
(string | DataPoint)[] |
Datapoints to update |
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 ]',
]));
▸ Static Private formatValues(value): string | number | boolean
| Name | Type |
|---|---|
value |
string | number | boolean |
string | number | boolean