refactor(api): started implementing all of the tables needed for full data synchronization
BREAKING CHANGE: refer to body
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
export type CollectorQueryOptions<
|
||||
SelectShape extends object,
|
||||
IncludeShape extends object,
|
||||
> = {
|
||||
select?: (keyof SelectShape)[];
|
||||
include?: (keyof IncludeShape)[];
|
||||
};
|
||||
|
||||
const normalizeCollectorQuery = <
|
||||
SelectShape extends object,
|
||||
IncludeShape extends object,
|
||||
>(
|
||||
opts?: CollectorQueryOptions<SelectShape, IncludeShape>,
|
||||
): CollectorQueryOptions<SelectShape, IncludeShape> => {
|
||||
if (!opts) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return opts;
|
||||
};
|
||||
|
||||
export const buildCollectorFindManyArgs = <
|
||||
SelectShape extends object,
|
||||
IncludeShape extends object,
|
||||
>(
|
||||
opts?: CollectorQueryOptions<SelectShape, IncludeShape>,
|
||||
) => {
|
||||
const { select: selectedKeys, include: includedKeys } =
|
||||
normalizeCollectorQuery(opts);
|
||||
|
||||
if (selectedKeys?.length && includedKeys?.length) {
|
||||
throw new Error("Use either opts.select or opts.include, not both.");
|
||||
}
|
||||
|
||||
if (selectedKeys?.length) {
|
||||
const select: Partial<Record<keyof SelectShape, boolean>> = {};
|
||||
selectedKeys.forEach((key) => {
|
||||
select[key] = true;
|
||||
});
|
||||
|
||||
return { select };
|
||||
}
|
||||
|
||||
if (includedKeys?.length) {
|
||||
const include: Partial<Record<keyof IncludeShape, boolean>> = {};
|
||||
includedKeys.forEach((key) => {
|
||||
include[key] = true;
|
||||
});
|
||||
|
||||
return { include };
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
Reference in New Issue
Block a user