mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 04:46:05 +00:00
fix repository's findOne to allow offset and sort – fixes module manager's config retrieval
This commit is contained in:
@@ -72,10 +72,10 @@ export class TypeInvalidError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export function stripMark(obj: any) {
|
||||
export function stripMark<O = any>(obj: O) {
|
||||
const newObj = cloneDeep(obj);
|
||||
mark(newObj, false);
|
||||
return newObj;
|
||||
return newObj as O;
|
||||
}
|
||||
|
||||
export function mark(obj: any, validated = true) {
|
||||
|
||||
@@ -162,8 +162,7 @@ export class Repository<DB = any, TB extends keyof DB = any> implements EmitsEve
|
||||
protected async performQuery(qb: RepositoryQB): Promise<RepositoryResponse> {
|
||||
const entity = this.entity;
|
||||
const compiled = qb.compile();
|
||||
/*const { sql, parameters } = qb.compile();
|
||||
console.log("many", sql, parameters);*/
|
||||
//console.log("performQuery", compiled.sql, compiled.parameters);
|
||||
|
||||
const start = performance.now();
|
||||
const selector = (as = "count") => this.conn.fn.countAll<number>().as(as);
|
||||
@@ -263,6 +262,7 @@ export class Repository<DB = any, TB extends keyof DB = any> implements EmitsEve
|
||||
qb = qb.orderBy(aliased(options.sort.by), options.sort.dir);
|
||||
}
|
||||
|
||||
//console.log("options", { _options, options, exclude_options });
|
||||
return { qb, options };
|
||||
}
|
||||
|
||||
@@ -286,14 +286,11 @@ export class Repository<DB = any, TB extends keyof DB = any> implements EmitsEve
|
||||
where: RepoQuery["where"],
|
||||
_options?: Partial<Omit<RepoQuery, "where" | "limit" | "offset">>
|
||||
): Promise<RepositoryResponse<DB[TB] | undefined>> {
|
||||
const { qb, options } = this.buildQuery(
|
||||
{
|
||||
..._options,
|
||||
where,
|
||||
limit: 1
|
||||
},
|
||||
["offset", "sort"]
|
||||
);
|
||||
const { qb, options } = this.buildQuery({
|
||||
..._options,
|
||||
where,
|
||||
limit: 1
|
||||
});
|
||||
|
||||
return this.single(qb, options) as any;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,15 @@ import { Diff } from "@sinclair/typebox/value";
|
||||
import { Guard } from "auth";
|
||||
import { BkndError, DebugLogger, Exception, isDebug } from "core";
|
||||
import { EventManager } from "core/events";
|
||||
import { Default, type Static, StringEnum, Type, objectEach, transformObject } from "core/utils";
|
||||
import {
|
||||
Default,
|
||||
type Static,
|
||||
StringEnum,
|
||||
Type,
|
||||
objectEach,
|
||||
stripMark,
|
||||
transformObject
|
||||
} from "core/utils";
|
||||
import {
|
||||
type Connection,
|
||||
EntityManager,
|
||||
@@ -130,7 +138,7 @@ export class ModuleManager {
|
||||
if ("version" in options.initial) {
|
||||
const { version, ...initialConfig } = options.initial;
|
||||
this._version = version;
|
||||
initial = initialConfig;
|
||||
initial = stripMark(initialConfig);
|
||||
|
||||
this._booted_with = "provided";
|
||||
} else {
|
||||
@@ -393,6 +401,7 @@ export class ModuleManager {
|
||||
this.logger.context("build").log("version", this.version());
|
||||
this.logger.log("booted with", this._booted_with);
|
||||
|
||||
// @todo: check this, because you could start without an initial config
|
||||
if (this.version() !== CURRENT_VERSION) {
|
||||
await this.syncConfigTable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user