UNPKG

@thisisagile/easy-mongo

Version:
65 lines (63 loc) 1.74 kB
import { stages } from "./chunk-WEJO6T5Q.mjs"; // src/MongoGateway.ts import { asJson, ifDefined, isDefined, isPresent, toArray } from "@thisisagile/easy"; var MongoGateway = class { constructor(collection, provider = collection.provider) { this.collection = collection; this.provider = provider; } all(options) { return this.provider.all(options).then((js) => js.map((j) => this.collection.in(j))); } byId(id) { return this.provider.byId(id).then((j) => ifDefined(j, this.collection.in(j))); } by(key, value, options) { return this.provider.by(key, value, options).then((js) => js.map((j) => this.collection.in(j))); } byIds(...ids) { return this.find(this.collection.id.isIn(...ids)); } find(q, options) { return this.provider.find(asJson(q), options).then((js) => js.map((j) => this.collection.in(j))); } search(q, options) { return this.find(this.collection.google(q), options); } filter(options) { return this.all(options); } exists(id) { return this.provider.byId(id).then((i) => isDefined(i)); } aggregate(...filters) { return this.provider.aggregate(toArray(...filters).filter(isPresent)); } count(...filters) { return this.aggregate(...filters, { $count: "total" }).then((d) => d.first()?.total ?? 0); } match(f) { return this.aggregate(stages.match.match(f)); } add(item) { return this.provider.add(this.collection.out(item)).then((j) => this.collection.in(j)); } update(item) { return this.provider.update(this.collection.out(item)).then((j) => this.collection.in(j)); } remove(id) { return this.provider.remove(id); } }; export { MongoGateway }; //# sourceMappingURL=chunk-GFBKWYDV.mjs.map