@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
46 lines (44 loc) • 1.29 kB
JavaScript
import {
Api
} from "./chunk-F2JDRSD6.mjs";
import {
Gateway
} from "./chunk-7ULNXC33.mjs";
import {
toPageList
} from "./chunk-TORB7XB3.mjs";
import {
use
} from "./chunk-ZPNFXK7Y.mjs";
// src/services/ApiGateway.ts
var ApiGateway = class extends Gateway {
constructor(api = new Api()) {
super();
this.api = api;
}
get(uri, options) {
return this.api.get(uri, options).then((r) => use(r.body.data, (d) => toPageList(d?.items, { total: d?.totalItems, ...d?.meta })));
}
getOne(uri, options) {
return this.get(uri, options).then((r) => r.first());
}
post(uri, item, options) {
return this.api.post(uri, item, options).then((r) => r.body.data?.items.first() ?? {});
}
postSearch(uri, options) {
return this.api.post(uri, options).then((r) => use(r.body.data, (d) => toPageList(d?.items, { total: d?.totalItems, ...d?.meta })));
}
patch(uri, item, options) {
return this.api.patch(uri, item, options).then((r) => r.body.data?.items.first() ?? {});
}
put(uri, item, options) {
return this.api.put(uri, item, options).then((r) => r.body.data?.items.first() ?? {});
}
delete(uri, options) {
return this.api.delete(uri, options).then(() => true);
}
};
export {
ApiGateway
};
//# sourceMappingURL=chunk-4BO6ABZK.mjs.map