throw new ValidationError("Format should be a proper object");
}
for (const key in format) {
if (!(key in this.collection.fields)) {
throw new ValidationError(
`Invalid field name in filter: ${key}`
);
}
}
return format as FormatParam<T>;
}
// this method should only be used when dealing with user input. Otherwise use the `format` method, as it's type safe and any issues should arise during the build process
safeFormat(format: unknown): this {
this.validateFormatParam(format);
return this.format(format as FormatParam<T>);
}
format(format?: FormatParam<T>): this {
if (this._format) {
throw new Error("Already formatted!");
}
if (format) {
this._format = format;
}
return this;
}
static parsePaginationParams(
params: Partial<PaginationParams>
): Partial<PaginationParams> {
return Object.fromEntries(
Object.entries(params).map(([key, value]) => [
key,
typeof value === "string" ? parseInt(value) : value,