@contexture/export
Contexture Export is a set of contexture utilities to get all of the records from a given tree.
This is accomplished by inserting a node in the tree that gets the data for you over one or more iterations. To do this correctly and efficiently, the tree is wrapped in an AND
group (in case the root was an OR
) and recursively marked filterOnly
(to prevent getting results for any other nodes on the tree).
Usage
Simple usage
import { results } from '@contexture/export'
let service = Contexture({
})
let tree = {
schema: 'someCollection',
children: [
],
}
let report = results({ tree, service, pageSize: 10 })
let totalCount = await report.getTotalRecords()
let stream = createWriteStream('someFile.txt')
for await (let record of report) stream.write(record)
stream.end()
let array = []
for await (let record of report) array = array.concat(record)
import all from 'it-all'
let array = await all(report)
CSV Usage
Using our fast-csv wrapper, you can pass it a write stream, async iterable, and transforms based on contexture schemas
import _ from 'lodash/fp'
import { createWriteStream } from 'fs'
import { results, csv } from '@contexture/export'
let service = Contexture({})
let tree = { schema: 'someCollection', children: [] }
let schema = { field1: {} }
await csv(
stream: createWriteStream('./test/actualFile.csv'),
iterableData: results({ service, tree }),
transform: [
{key: 'name', label: 'THE,NAME', display: _.capitalize},
{key: 'value', label: 'Value', display: _.identity},
],
)
API