mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 21:21:29 +00:00
feat: fixed eslint and resolved all eslint issues
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||
import { Knex } from "knex";
|
||||
import { Tables } from "knex/types/tables";
|
||||
|
||||
@@ -15,22 +16,22 @@ export const withTransaction = <K extends object>(db: Knex, dal: K) => ({
|
||||
...dal
|
||||
});
|
||||
|
||||
export type TFindFilter<R extends {} = any> = Partial<R> & {
|
||||
export type TFindFilter<R extends object = object> = Partial<R> & {
|
||||
$in?: Partial<{ [k in keyof R]: R[k][] }>;
|
||||
};
|
||||
export const buildFindFilter =
|
||||
<R extends {} = any>({ $in, ...filter }: TFindFilter<R>) =>
|
||||
<R extends object = object>({ $in, ...filter }: TFindFilter<R>) =>
|
||||
(bd: Knex.QueryBuilder<R, R>) => {
|
||||
bd.where(filter);
|
||||
void bd.where(filter);
|
||||
if ($in) {
|
||||
Object.entries($in).forEach(([key, val]) => {
|
||||
bd.whereIn(key as any, val as any);
|
||||
void bd.whereIn(key as never, val as never);
|
||||
});
|
||||
}
|
||||
return bd;
|
||||
};
|
||||
|
||||
export type TFindOpt<R extends {} = any> = {
|
||||
export type TFindOpt<R extends object = object> = {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
sort?: Array<[keyof R, "asc" | "desc"] | [keyof R, "asc" | "desc", "first" | "last"]>;
|
||||
@@ -53,7 +54,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
findById: async (id: string, tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(tableName)
|
||||
.where({ id } as any)
|
||||
.where({ id } as never)
|
||||
.first("*");
|
||||
return result;
|
||||
} catch (error) {
|
||||
@@ -74,10 +75,10 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
) => {
|
||||
try {
|
||||
const query = (tx || db)(tableName).where(buildFindFilter(filter));
|
||||
if (limit) query.limit(limit);
|
||||
if (offset) query.offset(offset);
|
||||
if (limit) void query.limit(limit);
|
||||
if (offset) void query.offset(offset);
|
||||
if (sort) {
|
||||
query.orderBy(
|
||||
void query.orderBy(
|
||||
sort.map(([column, order, nulls]) => ({ column: column as string, order, nulls }))
|
||||
);
|
||||
}
|
||||
@@ -90,7 +91,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
create: async (data: Tables[Tname]["insert"], tx?: Knex) => {
|
||||
try {
|
||||
const [res] = await (tx || db)(tableName)
|
||||
.insert(data as any)
|
||||
.insert(data as never)
|
||||
.returning("*");
|
||||
return res;
|
||||
} catch (error) {
|
||||
@@ -101,7 +102,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
try {
|
||||
if (!data.length) return [];
|
||||
const res = await (tx || db)(tableName)
|
||||
.insert(data as any)
|
||||
.insert(data as never)
|
||||
.returning("*");
|
||||
return res;
|
||||
} catch (error) {
|
||||
@@ -111,8 +112,8 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
updateById: async (id: string, data: Tables[Tname]["update"], tx?: Knex) => {
|
||||
try {
|
||||
const [res] = await (tx || db)(tableName)
|
||||
.where({ id } as any)
|
||||
.update(data as any)
|
||||
.where({ id } as never)
|
||||
.update(data as never)
|
||||
.returning("*");
|
||||
return res;
|
||||
} catch (error) {
|
||||
@@ -127,7 +128,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
try {
|
||||
const res = await (tx || db)(tableName)
|
||||
.where(buildFindFilter(filter))
|
||||
.update(data as any)
|
||||
.update(data as never)
|
||||
.returning("*");
|
||||
return res;
|
||||
} catch (error) {
|
||||
@@ -137,7 +138,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
deleteById: async (id: string, tx?: Knex) => {
|
||||
try {
|
||||
const [res] = await (tx || db)(tableName)
|
||||
.where({ id } as any)
|
||||
.where({ id } as never)
|
||||
.delete()
|
||||
.returning("*");
|
||||
return res;
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
// TODO(akhilmhdh): make this better later
|
||||
|
||||
export const mergeOneToManyRelation = <
|
||||
T extends Record<string, any>,
|
||||
T extends Record<string, unknown>,
|
||||
Pk extends keyof T,
|
||||
P extends Record<string, any>,
|
||||
P extends Record<string, unknown>,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
||||
C extends any,
|
||||
Ck extends string = "child"
|
||||
>(
|
||||
@@ -22,7 +31,7 @@ export const mergeOneToManyRelation = <
|
||||
const parent = parentMapper(row) as any;
|
||||
parent[childKey] = [];
|
||||
groupedRecord.push(parent);
|
||||
prevPkId = pk;
|
||||
prevPkId = pk as string;
|
||||
prevPkIndex += 1;
|
||||
}
|
||||
groupedRecord[prevPkIndex][childKey].push(childMapper(row));
|
||||
@@ -41,6 +50,7 @@ export type TSqlPackRelationships<
|
||||
childrenMapper: C;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
||||
export type TChildMapper<T extends {}, U extends string = string, R extends unknown = unknown> = {
|
||||
key: keyof T;
|
||||
label: U;
|
||||
@@ -82,7 +92,7 @@ const sqlChildMapper = <
|
||||
const ck = `${prefix}-${label}-${doc[childPk]}`;
|
||||
const val = mapper(doc);
|
||||
if (!lookupTable.has(ck)) {
|
||||
if (typeof val !== "undefined" && val !== null) docsByPk[pk as keyof P][label].push(val);
|
||||
if (typeof val !== "undefined" && val !== null) docsByPk[pk][label].push(val);
|
||||
lookupTable.add(ck);
|
||||
}
|
||||
if (nestedMappers && val) {
|
||||
|
||||
Reference in New Issue
Block a user