npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

datastore-api

v6.0.1

Published

Simplified, more consitent API for Google Cloud Datastore

Downloads

324

Readme

version license downloads

datastore-api

Simplified, more consistent API for Google Cloud Datastore.

Dstore implements a slightly more accessible version of the Google Cloud Datastore: Node.js Client

@google-cloud/datastore is a strange beast: The documentation is auto generated missing some core methods and completely shy of documenting any advanced concepts.

Also the typings are strange and overly broad.

Dstore tries to abstract away most surprises the datastore provides to you but als tries to stay as API compatible as possible to @google-cloud/datastore.

Main differences:

  • Everything asynchronous is Promise-based - no callbacks.
  • get always returns a single DstoreEntry.
  • getMulti always returns an Array.
  • set is called with (key, value) and always returns the complete Key of the entity being written.
  • allocateOneId returns a single numeric string encoded unique datastore id without the need of fancy unpacking.
  • runInTransaction allows you to provide a function to be executed inside an transaction without the need of passing around the transaction object. This is modelled after Python 2.7 ndb's @ndb.transactional feature. This is implemented via node's AsyncLocalStorage.
  • keySerialize is synchronous. 🦄
  • Starting your code with the environment variable DEBUG='ds:api' allows you to trace API calls.

Find the full documentation here. In there also some of the idiosyncrasies of using the Datastore are explained.

See the API documentation for Details, Github for source.

Major issues

  • The Javascript-Datastore Bindings use nanosecond-Timestamp Information stored in the Datasore and rounds it to milliseconds. Python at least retains microseconds.
  • the old get_entity_group_version() / getEntityGroupVersion() API has been retired. You can still for key query { path: [key.path[0], {'kind': '__entity_group__', 'id': 1}]} to get a __version__ property. The reliability of this data on FireStore is unknown.
  • Googles Javascript API decided to use [Symbol(KEY)] to represent the Key in an entity. This results in all kinds of confusion when serializing to JSON, e.g. for caching. This library adds the property _keyStr which will be transparently used to regenerate [Symbol(KEY)] when needed.
  • Many functions are somewhat polymorphic where the shape of the return value depends on the function parameters, e.g. if the API was called with a key or a list of keys. You are encouraged to alvais provide a list of parameters instead a single parameter, e.g. get([key]) instead of get(key).
  • insert() and save() sometimes return the key being written and sometimes not. So you might or might not get some data in insertResponse?.[0].mutationResults?.[0]?.key?.path - urgs.
  • Google avoids BigInt. So key.id is (usually but not always) returned as a String but you have to provide a Number to the API.

Metrics

Datastore-API is instrumented with prom-client. Metrics are all prefixed with dstore_.

In an express based Application you can make them available like this:

import promClient from 'prom-client';

server.get('/metrics', async (req, res) => {
  try {
    res.set('Content-Type', promClient.register.contentType);
    res.end(await promClient.register.metrics());
  } catch (ex) {
    res.status(500).end(ex);
  }
});

See also

child_process.execSync(`rm -Rf ./dsData`)
const port = await getPort({ port: 8081 })
emulator = new Emulator({ debug: false, port, storeOnDisk: true , clean: false, dataDir: './dsData'})

Then inspect datastore output with something like this:

/opt/homebrew/share/google-cloud-sdk/platform/cloud-datastore-emulator/cloud_datastore_emulator start --host=localhost --port=8081 --store_on_disk=True ./dsData & npx dsadmin --project=huwawi2