Skip to content

Latest commit

 

History

History
76 lines (61 loc) · 1.88 KB

README.md

File metadata and controls

76 lines (61 loc) · 1.88 KB

DataStream Logo
DataStreamJS

DataStream.org API helper. See API documentation for query string values and structure.

Install

npm install https://github.com/datastreamapp/datastreamjs

Use

This packages works in the browser and with NodeJS.

Example

import {
  setAPIKey,
  metadata,
  locations,
  records,
  observations
} from '@datastreamapp/datastreamjs'

setAPIKey('xxxxxxxxxx') // secrets should be injected securely

const observationsStream = await observations({
  $select:
    'DOI,ActivityType,ActivityMediaName,ActivityStartDate,ActivityStartTime,SampleCollectionEquipmentName,CharacteristicName,MethodSpeciation,ResultSampleFraction,ResultValue,ResultUnit,ResultValueType',
  $filter: `DOI eq '10.25976/xxxx-xx00'`,
  $top: 10000
})

for await (const observation of observationsStream) {
  // use record
}

Example: save to file

import { pipeline } from '@datastream/core'
import { csvFormatStream } from '@datastream/csv/format'
import { createWriteStream } from 'node:fs'

import {
  setAPIKey,
  metadata,
  locations,
  records,
  observations
} from '@datastreamapp/datastreamjs'

setAPIKey('xxxxxxxxxx') // secrets should be injected securely

const recordsStream = await records({
  $select:
    'DOI,ActivityType,ActivityMediaName,ActivityStartDate,ActivityStartTime,SampleCollectionEquipmentName,CharacteristicName,MethodSpeciation,ResultSampleFraction,ResultValue,ResultUnit,ResultValueType',
  $filter: `DOI eq '10.25976/xxxx-xx00'`,
  $top: 10000
})

await pipeline([
  recordsStream,
  csvFormatStream(),
  createWriteStream('/path/to/output.csv')
])