@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
173 lines (171 loc) • 4.22 kB
JavaScript
import {
choose
} from "./chunk-XAIHCZT4.mjs";
import {
List,
isList,
toList
} from "./chunk-A7C3XND3.mjs";
import {
isA
} from "./chunk-ZHXKBOK2.mjs";
import {
ofConstruct
} from "./chunk-ZPNFXK7Y.mjs";
import {
isNumber
} from "./chunk-DEJ7A5PY.mjs";
// src/types/PageList.ts
var toFilter = (field, value) => toShortFilter(field, field, value);
var toShortFilter = (field, shortField, value) => ({
field,
shortField,
values: [{ value }]
});
var PageList = class extends List {
_options;
get options() {
return this._options;
}
get take() {
return this._options?.take ?? 250;
}
get skip() {
return this._options?.skip ?? 0;
}
get total() {
return this._options?.total;
}
get sorts() {
return this._options?.sorts;
}
get filters() {
return this._options?.filters;
}
get meta() {
return {
take: this.take,
skip: this.skip,
total: this.total,
sorts: this.sorts,
filters: this.filters
};
}
get ids() {
return this.mapDefined((i) => i.id);
}
asc(p) {
return toPageList(super.asc(p), this);
}
desc(p) {
return toPageList(super.desc(p), this);
}
diff(others) {
return toPageList(super.diff(others), this);
}
diffByKey(others, key) {
return toPageList(super.diffByKey(others, key), this);
}
symmetricDiff(others) {
return toPageList(super.symmetricDiff(others), this);
}
symmetricDiffByKey(others, key) {
return toPageList(super.symmetricDiffByKey(others, key), this);
}
intersect(others) {
return toPageList(super.intersect(others), this);
}
intersectByKey(others, key) {
return toPageList(super.intersectByKey(others, key), this);
}
map(f, params) {
const items = super.map(f, params);
return toPageList(items, this);
}
flatMap(f, params) {
return toPageList(super.flatMap(f, params), this);
}
mapDefined(f, params) {
return toPageList(super.mapDefined(f, params), this);
}
mapAsync(f) {
return super.mapAsync(f).then((r) => toPageList(r, this));
}
areEqual(...items) {
return this.isSubSetOf(...items) && toList(...items).isSubSetOf(...this);
}
distinct() {
return toPageList(super.distinct(), this);
}
distinctByKey(key) {
return toPageList(super.distinctByKey(key), this);
}
distinctByValue() {
return toPageList(super.distinctByValue(), this);
}
filter(p, params) {
return toPageList(super.filter(p, params), this);
}
accumulate(...keys) {
return toPageList(super.accumulate(...keys), this);
}
concat(...items) {
return toPageList(super.concat(...items), this);
}
reverse() {
return toPageList(super.reverse(), this);
}
splice(start, deleteCount, ...items) {
return toPageList(super.splice(start, deleteCount, ...items), this);
}
remove(item) {
return toPageList(super.remove(item), this);
}
replace(key, item) {
return toPageList(super.replace(key, item), this);
}
switch(item) {
return toPageList(super.switch(item), this);
}
defined() {
return toPageList(super.defined(), this);
}
orElse(...alt) {
return toPageList(super.orElse(...alt), this);
}
slice(start, end) {
return toPageList(super.slice(start, end), this);
}
//we needed to add U because of a Typescript issue with generics
update(p, val) {
return toPageList(super.update(p, val), this);
}
updateFirst(p, val) {
return toPageList(super.updateFirst(p, val), this);
}
updateFirstById(id, val) {
return toPageList(super.updateFirstById(id, val), this);
}
updateById(id, val) {
return toPageList(super.updateById(id, val), this);
}
setPageOptions(options) {
this._options = options;
return this;
}
};
var isPageList = (l) => isList(l) && isA(l, "total");
var toPageList = (items = [], options) => choose(items).case(
(i) => i.length === 1 && isNumber(i[0]),
(i) => new PageList().add(...i)
).else((i) => new PageList(...i)).setPageOptions(options);
var asPageList = (c, items = toPageList()) => items.map((i) => ofConstruct(c, i));
export {
toFilter,
toShortFilter,
PageList,
isPageList,
toPageList,
asPageList
};
//# sourceMappingURL=chunk-TORB7XB3.mjs.map