hyper logo

hyper 

 Beta  

hyper
services

Build any application by taking advantage of hyper's single API entry point and composable application services.

// connect to your Hyper Application using hyper-connect
import { connect } from "hyper-connect";
const hyper = connect(process.env.HYPER);
hyper services

Data Service

API powered data access

import { connect } from "hyper-connect";
import { cuid } from "cuid";
const hyper = connect(process.env.HYPER);

export async function addMovies(movies) {
  movies = movies.map((movie) => ({
    _id: `movie-${cuid()}`,
    ...movie,
    type: "movie",
  }));
  await hyper.data.bulk(movies);
  return movies;
}

export async function addMovie(movie) {
  movie = { _id: `movie-${cuid()}`, ...movie, type: "movie" };
  await hyper.data.add(movie);
  return movie;
}

export async function findMovies(rating) {
  const { docs: movies } = await hyper.data.query(
    {
      rating: {
        $gte: rating,
      },
    },
    { useIndex: "custom-idx" }
  );
  return movies;
}

Cache Service

API powered cache

import { connect } from "hyper-connect";
import { cuid } from "cuid";
const hyper = connect(process.env.HYPER);

export async function addMovies(movies) {
  movies = movies.map((movie) => ({
    _id: `movie-${cuid()}`,
    ...movie,
    type: "movie",
  }));
  await hyper.data.bulk(movies);
  return movies;
}

export async function addMovie(movie) {
  movie = { _id: `movie-${cuid()}`, ...movie, type: "movie" };
  await hyper.data.add(movie);
  return movie;
}

export async function findMovies(rating) {
  const { docs: movies } = await hyper.data.query(
    {
      rating: {
        $gte: rating,
      },
    },
    { useIndex: "custom-idx" }
  );
  return movies;
}

Storage Service

API powered buckets

import { connect } from "hyper-connect";
const hyper = connect(process.env.HYPER);

export async function updateAvatar(userId, stream) {
  await hyper.storage.upload(`${userId}-avatar.png`, stream);
  return stream;
}

export async function getAvatar(userId) {
  const stream = await hyper.storage.download(`${userId}-avatar.png`);
  return stream;
}

Queue Service

API powered persistent queues

import { connect, createHyperVerify } from "hyper-connect";
const hyper = connect(process.env.HYPER);

export async function handleSignup(userId) {
  await hyper.queue.enqueue({ type: "START_SIGNUP_EMAIL_CAMPAIGN", userId });
  await hyper.queue.enqueue({ type: "UPDATE_CRM", userId });
}

export async function retryFailedJobs() {
  const { jobs: errored } = await hyper.queue.errors();
  const jobs = errored.map(({ job }) => job);
  await Promise.all(jobs.map((job) => hyper.queue.enqueue(job)));
  return jobs;
}

export async function findQueuedJobs() {
  const { jobs: queued } = await hyper.queue.queued();
  return queued.map(({ job }) => job);
}

// Your Queue Target Worker
const verifySignature = createHyperVerify(process.env.QUEUE_SECRET, "5m");
export async function checkAndProcessJob(signature, payload) {
  const { ok } = verifySignature(signature, payload);
  if (!ok) return { ok: false, status: 403, msg: "signature mismatch" };
  await processJob(payload);
}