UNPKG

@httpc/kit

Version:

httpc toolbox for building function-based API with minimal code and end-to-end type safety

11 lines (10 loc) 518 B
import assert from "assert"; import { useInjected } from "../di"; export function useTransaction(...args) { const func = args.pop(); assert(typeof func === "function", "last argument must be a function"); assert(args.length > 0, "you mys specify at least a service"); const data = useInjected("IDbService"); const instances = args.map(x => typeof x === "object" ? x : useInjected(x)); return data.startTransaction(data => func(...instances.map(x => x.inTransaction?.(data) || x))); }