type PickMatching<T, V> = {
[K in keyof T as T[K] extends V ? K : never]: T[K];
};
// biome-ignore lint/complexity/noBannedTypes: it's okay here as it is only a picker
type ExtractMethods<T> = PickMatching<T, Function>;
export class FDGLService extends WorkerEntrypoint<Env> {
#reports: Reports;
constructor(ctx: ExecutionContext, env: Env) {
super(ctx, env);
const customEnv: CustomEnv = {
...env,
d1_db: env.DB,
DB: new Kysely<DB>({
dialect: new D1Dialect({ database: env.DB }),
plugins: [new SerializePlugin()],
}),
};
this.#reports = new Reports(customEnv);
}
get reports() {
// biome-ignore format: its nicer in one line
return {
getReport: this.#reports.getReport.bind(this.#reports),
getReports: this.#reports.getReports.bind(this.#reports),
createReport: this.#reports.createReport.bind(this.#reports),
revokeReport: this.#reports.revokeReport.bind(this.#reports)
} satisfies ExtractMethods<Reports>
}
}