Effection Logo

type alias Around

thefrontside/effection

type Around = [K in keyof Api] : Api[K] extends (args: infer TArgs) => infer TReturn ? Middleware<TArgs, TReturn> : Middleware<[], Api[K]>

The shape of middlewares can surround a particular {Api}

Members of an Api that are values are surrounded by no-arg functions.

Examples

Example 1

import type { Operation } from "effection";

interface DatabaseApiShape {
  query(sql: string): Operation<{ id: number; title: string }[]>;
  close(): Operation<void>;
}

let around: Partial<Around<DatabaseApiShape>> = {
  *query(args, next) {
    let [sql] = args;
    if (sql.includes("select")) {
      console.log("read query");
    }
    return yield* next(...args);
  },
  *close(args, next) {
    console.log("closing db connection");
    return yield* next(...args);
  },
};

Type Parameters

Api