Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/groq-store

Package Overview
Dependencies
Maintainers
26
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/groq-store

Stream dataset to memory for in-memory querying

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25K
decreased by-1.92%
Maintainers
26
Weekly downloads
 
Created
Source

@sanity/groq-store

npm versionBuild Statusnpm bundle size

In-memory GROQ store. Streams all available documents from Sanity into an in-memory database and allows you to query them there.

Targets

  • Node.js >= 10
  • Modern browsers (Edge >= 14, Chrome, Safari, Firefox etc)

Caveats

  • Streams entire dataset to memory, so generally not recommended for large datasets
  • Does not work with tokens in browser (currently)

Installation

npm install --save @sanity/groq-store

Usage

import {groqStore, groq} from '@sanity/groq-store'

const store = groqStore({
  projectId: 'abc123',
  dataset: 'blog',

  // Keep dataset up to date with remote changes. Default: false
  listen: true,

  // "Replaces" published documents with drafts, if available.
  // Note that document IDs will not reflect draft status, currently
  overlayDrafts: true,

  // Optional token, if you want to receive drafts, or read data from private datasets
  // NOTE: Does _not_ work in browsers (yet)
  token: 'someAuthToken',

  // Optional limit on number of documents, to prevent using too much memory unexpectedly
  // Throws on the first operation (query, retrieval, subscription) if reaching this limit.
  documentLimit: 10000,
})

store.query(groq`*[_type == "author"]`).then((docs) => {
  console.log(docs)
})

store.getDocument('grrm').then((grrm) => {
  console.log(grrm)
})

store.getDocuments(['grrm', 'jrrt']).then(([grrm, jrrt]) => {
  console.log(grrm, jrrt)
})

const sub = store.subscribe(
  groq`*[_type == $type][] {name}`, // Query
  {type: 'author'}, // Params
  (err, result) => {
    if (err) {
      console.error('Oh no, an error:', err)
      return
    }

    console.log('Result:', result)
  }
)

// Later, to close subscription:
sub.unsubscribe()

// Later, to close listener:
store.close()

License

MIT © Sanity.io

Keywords

FAQs

Package last updated on 21 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc