koopjs / koop-core

Core library for KoopJS (deprecated)
Other
16 stars 19 forks source link

Add transformation ability #65

Closed efbenson closed 4 years ago

efbenson commented 5 years ago

It would be nice to not have to fork a provider if you wanted to append or transform data. For example, if my provider is the AGOL provider and I want to take a layer's results from AGOL on the fly and enrich the data (change some values or add additional fields) it would nice to have a place in the koop layer that exposes the results of the provider with a way for you to mutate it before its sent out vs having to extend the provider for every use case.

Ideally there would be an option for the winnow query to be run against the transformed dataset to apply the query against the transformed data (to filter it further)

haoliangyu commented 4 years ago

You can try v3.17.0 for the new provider options now:

// supply the options when registering the provider
koop.register(myProvider, {
  before: (req, callback) => {
    // do something with the req
    callback()
  },
  after: (req, data, callback) => {
    // tranform the data
    callback(null, data)
  }
})

See #98 for more details.