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

elda-ai-memory

v1.0.3

Published

Methods for external memory storage

Downloads

11

Readme

elda-ai Memory

Methods for external memory storage.

In the structure of elda-ai memory is considered as long term storage of information.

Development

Running tests:

npm install
npm test

API

Configure

When you require elda-ai-memory, it returns a function that can be used to configure a memory interface.

The stub configuration is:

var config = {
  type: 'none';
};

Where as a configuration using git is:

var config =  {
  type: 'git',
  remote: '[email protected]:elda-ai/memory-training.git',
  local: process.cwd() + '/memory',
  user: {
    name: 'elda-ai',
    email: '[email protected]'
  }
};

Pass the config into the memory function to return a promise. The promise resolves to a usable instance. During this step, files are downloaded from the remote and stored locally; this may take several seconds depending on the size of the remote.

var memory = require('elda-ai-memory');
memory(config).then(function(instance) {
  /* ... do stuff with instance ... */
});
  • If there is an error with the supplied config, it should fail fast with a rejected promise.
  • External memory is treated as a local copy which upon which you can read and write. Later store can be used to push changes, and destroy used to clean up the local copy.

Read

External memory is expected to be made up of files. These files can be read from the local copy using a relative path to the root of the external files.

var memory = require('elda-ai-memory');
memory(config).then(function(instance) {
  return instance.read('file/name.json').then(function(contents) {
    console.log('Read from file:', contents);
  });
});

Write

Files can be created and updated by using write. Writing will only update the local copy until store is called.

var memory = require('elda-ai-memory');
memory(config).then(function(instance) {
  // Write a file
  var data = JSON.stringify({data: "some data"});
  return instance.write('file/new.json', data).then(function(name) {
    console.log('Wrote to file:', name);
  });
});

Delete

Files can be deleted from the local memory. Deleted files will only affect the remote when store is called.

var memory = require('elda-ai-memory');
memory(config).then(function(instance) {
  // Delete a file
  return instance.delete('file/to/delete.json').then(function(name) {
    console.log('Deleted file:', name);
  });
});

Store

Store pushes any local changes to the remote location with a message.

var memory = require('elda-ai-memory');
memory(config).then(function(instance) {
  // Store local changes back to server
  var message = 'New files added';
  return instance.store(message).then(function() {
    console.log('Files stored in external memory:', message);
  });
});

Destroy

Destroy removes all local files stored on the machine relating to the remote.

var memory = require('elda-ai-memory');
memory(config).then(function(instance) {
  // Destroy local copy of files
  return instance.destroy().then(function() {
    console.log('Local files removed');
  });
});

Git configuration

This configuration assumes you have the command line version of git installed on the machine, and that you have correct access rights to the remote repository.

Worked example:

var memory = require('elda-ai-memory');
var config =  {
  type: 'git',
  remote: '[email protected]:elda-ai/memory-training.git',
  local: process.cwd() + '/memory',
  user: {
    name: 'elda-ai',
    email: '[email protected]'
  }
};

// Retrieve files from external memory
memory(config).then(function(instance) {

  function readAFile() {
    // Read a file
    return instance.read('file/name.json').then(function(contents) {
      console.log('Read from file:', contents);
    });
  }

  function writeAFile() {
    // Write a file
    var data = JSON.stringify({data: "some data"});
    return instance.write('file/new.json', data).then(function(name) {
      console.log('Wrote to file:', name);
    });
  }

  function deleteAFile() {
    // Delete a file
    return instance.delete('file/to/delete.json').then(function(name) {
      console.log('Deleted file:', name);
    });
  }

  function storeChanges() {
    // Store local changes back to server
    var message = 'New files added';
    return instance.store(message).then(function() {
      console.log('Files stored in external memory:', message);
    });
  }

  function destroyLocalCopy() {
    // Destroy local copy of files
    return instance.destroy().then(function() {
      console.log('Local files removed');
    });
  }

  return readExample()
    .then(readAFile)
    .then(writeAFile)
    .then(deleteAFile)
    .then(storeChanges)
    .then(destroyLocalCopy);
});