mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 04:46:05 +00:00
feat: enhance query handling by ignoring undefined values
- Updated query conversion logic to skip undefined values, improving robustness. - Added tests to validate that undefined values are correctly ignored in query specifications.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { test, describe, expect } from "bun:test";
|
||||
import * as q from "./query";
|
||||
import { parse as $parse, type ParseOptions } from "bknd/utils";
|
||||
import type { PrimaryFieldType } from "modules";
|
||||
import type { Generated } from "kysely";
|
||||
|
||||
const parse = (v: unknown, o: ParseOptions = {}) =>
|
||||
$parse(q.repoQuery, v, {
|
||||
@@ -186,4 +188,35 @@ describe("server/query", () => {
|
||||
decode({ with: { images: {}, comments: {} } }, output);
|
||||
}
|
||||
});
|
||||
|
||||
test("types", () => {
|
||||
const id = 1 as PrimaryFieldType;
|
||||
const id2 = "1" as unknown as Generated<string>;
|
||||
|
||||
const c: q.RepoQueryIn = {
|
||||
where: {
|
||||
// @ts-expect-error only primitives are allowed for $eq
|
||||
something: [],
|
||||
// this gets ignored
|
||||
another: undefined,
|
||||
// @ts-expect-error null is not a valid value
|
||||
null_is_okay: null,
|
||||
some_id: id,
|
||||
another_id: id2,
|
||||
},
|
||||
};
|
||||
|
||||
const d: q.RepoQuery = {
|
||||
where: {
|
||||
// @ts-expect-error only primitives are allowed for $eq
|
||||
something: [],
|
||||
// this gets ignored
|
||||
another: undefined,
|
||||
// @ts-expect-error null is not a valid value
|
||||
null_is_okay: null,
|
||||
some_id: id,
|
||||
another_id: id2,
|
||||
},
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user