@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
57 lines (55 loc) • 1.4 kB
JavaScript
import {
ApiGateway
} from "./chunk-4BO6ABZK.mjs";
import {
Api
} from "./chunk-F2JDRSD6.mjs";
import {
HttpStatus
} from "./chunk-UGUAZFM4.mjs";
import {
toArray
} from "./chunk-CO2AFYVD.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(), options);
}
byId(id, options) {
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().query(q), options);
}
exists(id, options) {
return this.get(this.routeId().id(id)).then((r) => r.length === 1).catch((r) => HttpStatus.NotFound.equals(r.status) ? false : Promise.reject(r));
}
add(item, options) {
return this.post(this.route(), item, options);
}
filter(options) {
return this.postSearch(this.route(), options);
}
update(item, options) {
return this.patch(this.routeId().id(item.id), item, options);
}
upsert(item, options) {
return this.put(this.routeId().id(item.id), item, options);
}
remove(id, options) {
return this.delete(this.routeId().id(id), options);
}
};
export {
RouteGateway
};
//# sourceMappingURL=chunk-3DGMN2JU.mjs.map