Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const uri = this.getDataUrl(endpoint, stringQuery)
const reqOptions = {
method: useGet ? 'GET' : 'POST',
uri: uri,
json: true,
body: useGet ? undefined : body,
query: isMutation && getMutationQuery(options),
timeout,
token
}
return this._requestObservable(reqOptions).pipe(
filter(isResponse),
map(getBody),
map(res => {
if (!isMutation) {
return res
}
// Should we return documents?
const results = res.results || []
if (options.returnDocuments) {
return returnFirst ? results[0] && results[0].document : results.map(mut => mut.document)
}
// Return a reduced subset
const key = returnFirst ? 'documentId' : 'documentIds'
const ids = returnFirst ? results[0] && results[0].id : results.map(mut => mut.id)
return {
transactionId: res.transactionId,
results: results,
const uri = this.getDataUrl(endpoint, stringQuery)
const reqOptions = {
method: useGet ? 'GET' : 'POST',
uri: uri,
json: true,
body: useGet ? undefined : body,
query: isMutation && getMutationQuery(options),
timeout,
token
}
return this._requestObservable(reqOptions).pipe(
filter(isResponse),
map(getBody),
map(res => {
if (!isMutation) {
return res
}
// Should we return documents?
const results = res.results || []
if (options.returnDocuments) {
return returnFirst ? results[0] && results[0].document : results.map(mut => mut.document)
}
// Return a reduced subset
const key = returnFirst ? 'documentId' : 'documentIds'
const ids = returnFirst ? results[0] && results[0].id : results.map(mut => mut.id)
return {
transactionId: res.transactionId,
fetch(query, params, options = {}) {
const mapResponse = options.filterResponse === false ? res => res : res => res.result
const observable = this._dataRequest('query', {query, params}, options).pipe(map(mapResponse))
return this.isPromiseAPI() ? toPromise(observable) : observable
},
request(options) {
const observable = this._requestObservable(options).pipe(
filter(event => event.type === 'response'),
map(event => event.body)
)
return this.isPromiseAPI() ? toPromise(observable) : observable
}
})
getDocument(id) {
const options = {uri: this.getDataUrl('doc', id), json: true}
const observable = this._requestObservable(options).pipe(
filter(isResponse),
map(event => event.body.documents && event.body.documents[0])
)
return this.isPromiseAPI() ? toPromise(observable) : observable
},
query.sourceUrl = source.url
}
const observable = this.client._requestObservable({
method: 'POST',
timeout: options.timeout || 0,
uri: `/assets/${assetEndpoint}/${dataset}`,
headers: options.contentType ? {'Content-Type': options.contentType} : {},
query,
body
})
return this.client.isPromiseAPI()
? observable
.pipe(
filter(event => event.type === 'response'),
map(event => toDocument(event.body))
)
.toPromise()
: observable
},