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, ): CollectorQueryOptions => { if (!opts) { return {}; } return opts; }; export const buildCollectorFindManyArgs = < SelectShape extends object, IncludeShape extends object, >( opts?: CollectorQueryOptions, ) => { 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> = {}; selectedKeys.forEach((key) => { select[key] = true; }); return { select }; } if (includedKeys?.length) { const include: Partial> = {}; includedKeys.forEach((key) => { include[key] = true; }); return { include }; } return {}; };