@hyper63/port-cache

1.1.4 • Public • Published

Cache Port

The cache port takes an adapter and environment, then parses the adapter and wraps function validations around each function.

Your adapter or composed adapter should implement all specified functions:

export default (env) => ({
  createStore,
  destroyStore,
  createDoc,
  getDoc,
  updateDoc,
  deleteDoc,
  listDocs,
});

You can create a test for your adapter with the port like so:

import { default as test } from "tape";
import { default as cache } from "@hyper63/ports-cache";
import { default as redis } from "@hyper63/adapters-redis";

test("certify adapter", async (t) => {
  t.plan(3);
  const instance = cache(redis, { url: "redis://redis:6379" });
  const store = "default";
  t.ok((await instance.createStore("default")).ok);
  t.ok(
    (
      await instance.createDoc({
        store: "default",
        key: "hello",
        value: { foo: "bar" },
      })
    ).ok
  );
  t.deepEqual((await instance.getDoc({ store: "default", key: "hello" })).doc, {
    foo: "bar",
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i @hyper63/port-cache

Weekly Downloads

3

Version

1.1.4

License

Apache-2.0

Unpacked Size

5.88 kB

Total Files

4

Last publish

Collaborators

  • hyper63