Key-Value Store

Proc includes flexible key-value store for your documents, collections, and simple values. Use it to create keys, set them to expire, and transform values in place.

You can interact with the key-value store through procs defined in the keyv package.

something went wrong :(
Setting the value of a key
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.keyv.set.call(
  bucket: "yd826b4c", value: "foo"
)
client.keyv.set.call(
  undefined, yd826b4c
);
curl "https://proc.run/keyv/set?bucket=yd826b4c" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain" \
--data "foo"
 

true

Keys are organized into buckets, each key pointing to a simple value like a string, or a complex value like an array or hash. Once created, keys can be retrieved, deleted, or transformed in place.

something went wrong :(
Getting the value of a key
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.keyv.set.call(
  bucket: "c7413e72", value: "foo"
)

client.keyv.get.call(
  bucket: "c7413e72"
)
client.keyv.set.call(
  undefined, c7413e72
);

client.keyv.get.call(
  undefined, c7413e72
);
curl "https://proc.run/keyv/set?bucket=c7413e72" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain" \
--data "foo"

curl "https://proc.run/keyv/get?bucket=c7413e72" --silent --request POST \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain"
 

foo

something went wrong :(
Deleting a key
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.keyv.set.call(
  bucket: "ta74ffc1", value: "foo"
)

client.keyv.delete.call(
  bucket: "ta74ffc1"
)

client.keyv.get.call(
  bucket: "ta74ffc1"
)
client.keyv.set.call(
  undefined, ta74ffc1
);

client.keyv.delete.call(
  undefined, ta74ffc1
);

client.keyv.get.call(
  undefined, ta74ffc1
);
curl "https://proc.run/keyv/set?bucket=ta74ffc1" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain" \
--data "foo"

curl "https://proc.run/keyv/delete?bucket=ta74ffc1" --silent --request POST \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain"

curl "https://proc.run/keyv/get?bucket=ta74ffc1" --silent --request POST \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain"
 

something went wrong :(
Transforming the value of a key
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.keyv.set.call(
  bucket: "w7253d54", value: "foo"
)

client.keyv.transform.call(bucket: "w7253d54") {
  client.type.string.reverse
}

client.keyv.get.call(
  bucket: "w7253d54"
)
client.keyv.set.call(
  undefined, w7253d54
);

client.keyv.transform.call(undefined, w7253d54, () => {
  return client.type.string.reverse;
});

client.keyv.get.call(
  undefined, w7253d54
);
curl "https://proc.run/keyv/set?bucket=w7253d54" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain" \
--data "foo"

curl "https://proc.run/keyv/transform?bucket=w7253d54" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "bucket", ["%%", "w7253d54", ["()", "type.string.reverse"]]]]'

curl "https://proc.run/keyv/get?bucket=w7253d54" --silent --request POST \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain"
 

oof

Value Types

Each key is created with one of the following value types: boolean, integer, number, string, array, hash, or nil. If a type is not provided when defining the key, the type will be inferred from the provided value. Set the value type explicitly by passing the type argument to keyv.set or keyv.create. The given value will be coerced into the defined type.

something went wrong :(
Setting a key with a defined type
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.keyv.set.call(
  bucket: "d6318324", value: "42", type: "integer"
)

client.keyv.get.call(
  bucket: "d6318324"
)
client.keyv.set.call(
  undefined, d6318324
);

client.keyv.get.call(
  undefined, d6318324
);
curl "https://proc.run/keyv/set?bucket=d6318324&type=integer" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain" \
--data "1"

curl "https://proc.run/keyv/get?bucket=d6318324" --silent --request POST \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain"
 

42

Expiring Keys

Keys are long-lived and do not expire by default. To define a key with an expiration, pass the ttl or expiry argument when calling keyv.set or keyv.create. Expiries can be set for or removed from existing keys with keyv.expire or keyv.persist respectively.

something went wrong :(
Setting a key that lives for 60 seconds
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.keyv.set.call(
  bucket: "d35d700c", value: "foo", ttl: 60
)
client.keyv.set.call(
  undefined, d35d700c
);
curl "https://proc.run/keyv/set?bucket=d35d700c&ttl=60" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: text/plain" \
--data "foo"
 

true

Keys are permanently deleted from the key-value store once expired.

Security Model

The keyv package extends authorization abilities with access control to specific buckets key prefixes. This model provides a convenient way to control read and write access to specific datasets.

something went wrong :(
Granting read-only access to a bucket
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.auth.create.call(
  abilities: ["keyv.get(bucket: tc978689)"]
)
client.auth.create.call(undefined, {
  abilities: ["keyv.get(bucket: tc978689)"]
});
curl https://proc.run/auth/create --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "abilities", ["keyv.get(bucket: tc978689)"]]]'
something went wrong :(
Granting write-only access to a bucket
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.auth.create.call(
  abilities: ["keyv.set(bucket: pcf3eb04)"]
)
client.auth.create.call(undefined, {
  abilities: ["keyv.set(bucket: pcf3eb04)"]
});
curl https://proc.run/auth/create --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "abilities", ["keyv.set(bucket: pcf3eb04)"]]]'
something went wrong :(
Granting full access to a bucket
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.auth.create.call(
  abilities: ["keyv(bucket: m55b4473)"]
)
client.auth.create.call(undefined, {
  abilities: ["keyv(bucket: m55b4473)"]
});
curl https://proc.run/auth/create --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "abilities", ["keyv(bucket: m55b4473)"]]]'

Segmenting data with key prefixes makes it possible to control access to more specific values. For example, you can easily create an authorization that allows a user to access any data but only change their own data.

something went wrong :(
Granting access by user id
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.auth.create.call(
  abilities: ["keyv(bucket: n1f2be85, prefix: user:1)"]
)
client.auth.create.call(undefined, {
  abilities: ["keyv(bucket: n1f2be85, prefix: user:1)"]
});
curl https://proc.run/auth/create --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "abilities", ["keyv(bucket: n1f2be85, prefix: user:1)"]]]'

Requirements for Buckets, Keys, & Values

Buckets and keys must be alphanumeric, with exceptions for the following characters: _, -, :. Buckets are limited to a length of 64 characters. Keys are limited to a length of 128 characters. Values are limited to 512KiB in size.

Bucket names must be unique in context of an account.


Stuck? Want to chat about an idea? Join the community on Discord.