mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-21 08:28:22 +00:00
feat(infisical-pg): completed secret approval policy and services for approval requests
This commit is contained in:
@@ -15,6 +15,21 @@ export const withTransaction = <K extends object>(db: Knex, dal: K) => ({
|
||||
...dal
|
||||
});
|
||||
|
||||
export type TFindFilter<R extends {} = any> = Partial<R> & {
|
||||
$in?: Partial<{ [K in keyof R]: R[K][] }>;
|
||||
};
|
||||
export const buildFindFilter =
|
||||
<R extends {} = any>({ $in, ...filter }: TFindFilter<R>) =>
|
||||
(bd: Knex.QueryBuilder<R, R>) => {
|
||||
bd.where(filter);
|
||||
if ($in) {
|
||||
Object.entries($in).forEach(([key, val]) => {
|
||||
bd.whereIn(key as any, val as any);
|
||||
});
|
||||
}
|
||||
return bd;
|
||||
};
|
||||
|
||||
// What is ormify
|
||||
// It is to inject typical operations like find, findOne, update, delete, create
|
||||
// This will avoid writing most common ones each time
|
||||
@@ -45,9 +60,10 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(
|
||||
throw new DatabaseError({ error, name: "Find one" });
|
||||
}
|
||||
},
|
||||
find: (filter: Partial<Tables[Tname]["base"]>, tx?: Knex) => {
|
||||
find: async (filter: TFindFilter<Tables[Tname]["base"]>, tx?: Knex) => {
|
||||
try {
|
||||
return (tx || db)(tableName).where(filter);
|
||||
const res = await (tx || db)(tableName).where(buildFindFilter(filter));
|
||||
return res;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find one" });
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ export const mergeOneToManyRelation = <
|
||||
T extends Record<string, any>,
|
||||
Pk extends keyof T,
|
||||
P extends Record<string, any>,
|
||||
C extends Record<string, any>,
|
||||
C extends any,
|
||||
Ck extends string = "child"
|
||||
>(
|
||||
data: T[],
|
||||
@@ -29,3 +29,61 @@ export const mergeOneToManyRelation = <
|
||||
}
|
||||
return groupedRecord;
|
||||
};
|
||||
|
||||
export type TSqlPackRelationships<
|
||||
T extends Record<string, any>,
|
||||
P extends Record<string, any>,
|
||||
C extends TChildMapper<T>[]
|
||||
> = {
|
||||
data: T[];
|
||||
key: keyof T;
|
||||
parentMapper: (arg: T) => P;
|
||||
childrenMapper: C;
|
||||
};
|
||||
|
||||
export type TChildMapper<T extends {}, U extends string = string, R extends unknown = unknown> = {
|
||||
key: keyof T;
|
||||
label: U;
|
||||
mapper: (arg: T) => R;
|
||||
};
|
||||
|
||||
type MappedRecord<T extends TChildMapper<any>> = {
|
||||
[K in T["label"]]: ReturnType<Extract<T, { label: K }>["mapper"]>[];
|
||||
};
|
||||
|
||||
export const sqlNestRelationships = <
|
||||
T extends Record<string, any> = {},
|
||||
P extends Record<string, any> = {},
|
||||
C extends TChildMapper<T>[] = TChildMapper<T>[]
|
||||
>({
|
||||
data,
|
||||
key,
|
||||
parentMapper,
|
||||
childrenMapper
|
||||
}: TSqlPackRelationships<T, P, C>) => {
|
||||
const parentLookup = new Set<string>();
|
||||
const childLookUp = new Set<string>();
|
||||
const recordsOrder: string[] = [];
|
||||
|
||||
type Cm = MappedRecord<(typeof childrenMapper)[number]>;
|
||||
|
||||
const recordsGroupedByPk: Record<string, P & Cm> = {};
|
||||
data.forEach((el) => {
|
||||
const pk = el[key];
|
||||
if (!parentLookup.has(pk)) {
|
||||
recordsGroupedByPk[pk] = parentMapper(el) as P & Cm;
|
||||
recordsOrder.push(pk);
|
||||
parentLookup.add(pk);
|
||||
}
|
||||
childrenMapper.forEach(({ label, mapper, key: cKey }) => {
|
||||
const ck = `${pk}-${label}-${el[cKey]}`;
|
||||
if (!childLookUp.has(ck)) {
|
||||
if (!recordsGroupedByPk[pk][label]) recordsGroupedByPk[pk][label as keyof Cm] = [] as any;
|
||||
const val = mapper(el);
|
||||
if (typeof val !== "undefined") recordsGroupedByPk[pk][label].push(val);
|
||||
childLookUp.add(ck);
|
||||
}
|
||||
});
|
||||
});
|
||||
return recordsOrder.map((pkId) => recordsGroupedByPk[pkId]);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { customAlphabet } from "nanoid";
|
||||
|
||||
const SLUG_ALPHABETS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
export const alphaNumericNanoId = customAlphabet(SLUG_ALPHABETS, 10);
|
||||
@@ -0,0 +1,7 @@
|
||||
import path from "node:path";
|
||||
|
||||
export function containsGlobPatterns(secretPath: string) {
|
||||
const globChars = ["*", "?", "[", "]", "{", "}", "**"];
|
||||
const normalizedPath = path.normalize(secretPath);
|
||||
return globChars.some((char) => normalizedPath.includes(char));
|
||||
}
|
||||
Reference in New Issue
Block a user