UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

60 lines (58 loc) 1.38 kB
import { ApiGateway } from "./chunk-2GYEWYBU.mjs"; import { Api } from "./chunk-VOZBRY56.mjs"; import { HttpStatus } from "./chunk-RPZ2XDQQ.mjs"; import { toArray } from "./chunk-KCY4RPFR.mjs"; import { isDefined } from "./chunk-AAND4MKF.mjs"; // src/services/RouteGateway.ts var RouteGateway = class extends ApiGateway { constructor(route, routeId, api = new Api()) { super(api); this.route = route; this.routeId = routeId; this.api = api; } all(options) { return this.get(this.route().expand(options ?? {}), options); } byId(id) { return this.getOne(this.routeId().id(id)); } byIds(...ids) { return this.get(this.route().ids(toArray(...ids))); } search(q, options) { return this.get(this.route().expand({ ...options, q })); } exists(id) { return this.byId(id).then((r) => isDefined(r)).catch((r) => HttpStatus.NotFound.equals(r.status) ? false : Promise.reject(r)); } add(item) { return this.post(this.route(), item); } filter(options) { return this.postSearch(this.route().expand(options ?? {})); } update(item) { return this.patch(this.routeId().id(item.id), item); } upsert(item) { return this.put(this.routeId().id(item.id), item); } remove(id) { return this.delete(this.routeId().id(id)); } }; export { RouteGateway }; //# sourceMappingURL=chunk-DWSZUI3N.mjs.map