feat: fixed eslint and resolved all eslint issues

This commit is contained in:
Akhil Mohan
2024-01-30 22:30:42 +05:30
parent 7c4dd5000f
commit 5855cc660a
147 changed files with 1165 additions and 938 deletions
+5 -2
View File
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { buildMongoQueryMatcher, MongoAbility } from "@casl/ability";
import { FieldCondition, FieldInstruction, JsInterpreter } from "@ucast/mongo2js";
import picomatch from "picomatch";
@@ -12,7 +13,7 @@ const $glob: FieldInstruction<string> = {
};
const glob: JsInterpreter<FieldCondition<string>> = (node, object, context) => {
const secretPath = context.get(object, node.field);
const secretPath = context.get(object, node.field) as string;
const permissionSecretGlobPath = node.value;
return picomatch.isMatch(secretPath, permissionSecretGlobPath, { strictSlashes: false });
};
@@ -23,7 +24,9 @@ export const conditionsMatcher = buildMongoQueryMatcher({ $glob }, { glob });
* Extracts and formats permissions from a CASL Ability object or a raw permission set.
*/
const extractPermissions = (ability: MongoAbility) =>
ability.rules.map((permission) => `${permission.action}_${permission.subject}`);
ability.rules.map(
(permission) => `${permission.action as string}_${permission.subject as string}`
);
/**
* Compares two sets of permissions to determine if the first set is at least as privileged as the second set.
+7 -2
View File
@@ -56,7 +56,12 @@ const envSchema = z
CLIENT_SECRET_GITHUB_LOGIN: zpStr(z.string().optional()),
CLIENT_ID_GITLAB_LOGIN: zpStr(z.string().optional()),
CLIENT_SECRET_GITLAB_LOGIN: zpStr(z.string().optional()),
CLIENT_GITLAB_LOGIN_URL: zpStr(z.string().optional().default(process.env.URL_GITLAB_LOGIN ?? GITLAB_URL)), // fallback since URL_GITLAB_LOGIN has been renamed
CLIENT_GITLAB_LOGIN_URL: zpStr(
z
.string()
.optional()
.default(process.env.URL_GITLAB_LOGIN ?? GITLAB_URL)
), // fallback since URL_GITLAB_LOGIN has been renamed
// integration client secrets
// heroku
CLIENT_ID_HEROKU: zpStr(z.string().optional()),
@@ -121,7 +126,7 @@ export const initEnvConfig = (logger: Logger) => {
logger.error(parsedEnv.error.issues);
process.exit(-1);
}
envCfg = Object.freeze(parsedEnv.data);
return envCfg;
};
+1
View File
@@ -5,6 +5,7 @@ export const request = axios.create();
axiosRetry(request, {
retries: 3,
// eslint-disable-next-line
retryDelay: axiosRetry.exponentialDelay,
retryCondition: (err) => axiosRetry.isNetworkError(err) || axiosRetry.isRetryableError(err)
});
+1 -1
View File
@@ -223,7 +223,7 @@ export const infisicalSymmetricEncypt = (data: string) => {
throw new Error("Missing both encryption keys");
};
export const infisicalSymmetricDecrypt = <T extends any = string>({
export const infisicalSymmetricDecrypt = <T = string>({
keyEncoding,
ciphertext,
tag,
+1 -1
View File
@@ -29,7 +29,7 @@ export const unique = <T, K extends string | number | symbol>(
): T[] => {
const valueMap = array.reduce(
(acc, item) => {
const key = toKey ? toKey(item) : (item as any as string | number | symbol);
const key = toKey ? toKey(item) : (item as unknown as string | number | symbol);
if (acc[key]) return acc;
acc[key] = item;
return acc;
+2 -2
View File
@@ -21,9 +21,9 @@ export const pick = <T extends object, TKeys extends keyof T>(
* object. Optional second argument shakes out values
* by custom evaluation.
*/
export const shake = <RemovedKeys extends string, T = {}>(
export const shake = <RemovedKeys extends string, T = object>(
obj: T,
filter: (value: any) => boolean = (x) => x === undefined || x === null
filter: (value: unknown) => boolean = (x) => x === undefined || x === null
): Omit<T, RemovedKeys> => {
if (!obj) return {} as T;
const keys = Object.keys(obj) as (keyof T)[];
+16 -15
View File
@@ -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;
+14 -4
View File
@@ -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) {
+1 -1
View File
@@ -1 +1 @@
export { initLogger,logger } from "./logger";
export { initLogger, logger } from "./logger";
+6 -4
View File
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// logger follows a singleton pattern
// easier to use it that's all.
import pino, { Logger } from "pino";
@@ -14,10 +15,10 @@ const logLevelToSeverityLookup: Record<string, string> = {
// eslint-disable-next-line import/no-mutable-exports
export let logger: Readonly<Logger>;
// akhilmhdh:
// The logger is not placed in the main app config to avoid a circular dependency.
// The config requires the logger to display errors when an invalid environment is supplied.
// On the other hand, the logger needs the config to obtain credentials for AWS or other transports.
// akhilmhdh:
// The logger is not placed in the main app config to avoid a circular dependency.
// The config requires the logger to display errors when an invalid environment is supplied.
// On the other hand, the logger needs the config to obtain credentials for AWS or other transports.
// By keeping the logger separate, it becomes an independent package.
const loggerConfig = z.object({
@@ -66,6 +67,7 @@ export const initLogger = async () => {
})
}
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
transport
);
return logger;
+1 -1
View File
@@ -1,4 +1,4 @@
import { z,ZodTypeAny } from "zod";
import { z, ZodTypeAny } from "zod";
// this is a patched zod string to remove empty string to undefined
export const zpStr = <T extends ZodTypeAny>(