How to use the @sanity/observable/operators/map.map function in @sanity/observable

To help you get started, we’ve selected a few @sanity/observable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / client / src / data / dataMethods.js View on Github external
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,
github sanity-io / sanity / packages / @sanity / client / src / data / dataMethods.js View on Github external
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,
github sanity-io / sanity / packages / @sanity / client / src / data / dataMethods.js View on Github external
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
  },
github sanity-io / sanity / packages / @sanity / client / src / sanityClient.js View on Github external
request(options) {
    const observable = this._requestObservable(options).pipe(
      filter(event => event.type === 'response'),
      map(event => event.body)
    )

    return this.isPromiseAPI() ? toPromise(observable) : observable
  }
})
github sanity-io / sanity / packages / @sanity / client / src / data / dataMethods.js View on Github external
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
  },
github sanity-io / sanity / packages / @sanity / client / src / assets / assetsClient.js View on Github external
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
  },

@sanity/observable

[deprecated] This package exists for legacy reasons only

MIT
Latest version published 4 years ago

Package Health Score

78 / 100
Full package analysis