c7861be520
Once this is merged, oxlint is at a pretty sensible baseline. **Enable `no-unused-vars`, `typescript/consistent-type-imports`, and `import/no-duplicates` lint rules** Turns on three previously-disabled oxlint rules across the monorepo and fixes all violations: - **`no-unused-vars`** – enabled as an error with standard ignore patterns: unused function arguments are ignored by default (`args: "none"`), variables/caught errors/destructured array elements prefixed with `_` are allowed, and rest siblings are permitted. - **`typescript/consistent-type-imports`** – enforced as an error; all type-only imports now use the `import type` syntax. - **`import/no-duplicates`** – enforced as an error; duplicate import statements from the same module have been merged. The remaining commits clean up the violations found across the codebase: removing unused variables/imports/type aliases, adding `_` prefixes to intentionally unused bindings, fixing duplicate imports, and converting value imports to `import type` where appropriate.
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import type { Span } from "@opentelemetry/api";
|
|
import { SpanKind } from "@opentelemetry/api";
|
|
import type { RunStore } from "@internal/run-store";
|
|
import type { PrismaClientOrTransaction } from "~/db.server";
|
|
import { $replica, prisma } from "~/db.server";
|
|
import type { AuthenticatedEnvironment } from "~/services/apiAuth.server";
|
|
import { attributesFromAuthenticatedEnv, tracer } from "../tracer.server";
|
|
import type { RunEngine } from "../runEngine.server";
|
|
import { engine } from "../runEngine.server";
|
|
import { runStore as defaultRunStore } from "../runStore.server";
|
|
import { ServiceValidationError } from "./common.server";
|
|
|
|
export { ServiceValidationError };
|
|
|
|
export abstract class BaseService {
|
|
constructor(
|
|
protected readonly _prisma: PrismaClientOrTransaction = prisma,
|
|
protected readonly _replica: PrismaClientOrTransaction = $replica,
|
|
protected readonly runStore: RunStore = defaultRunStore
|
|
) {}
|
|
|
|
protected async traceWithEnv<T>(
|
|
trace: string,
|
|
env: AuthenticatedEnvironment,
|
|
fn: (span: Span) => Promise<T>
|
|
): Promise<T> {
|
|
return tracer.startActiveSpan(
|
|
`${this.constructor.name}.${trace}`,
|
|
{ attributes: attributesFromAuthenticatedEnv(env), kind: SpanKind.SERVER },
|
|
async (span) => {
|
|
try {
|
|
return await fn(span);
|
|
} catch (e) {
|
|
if (e instanceof ServiceValidationError) {
|
|
throw e;
|
|
}
|
|
|
|
if (e instanceof Error) {
|
|
span.recordException(e);
|
|
} else {
|
|
span.recordException(new Error(String(e)));
|
|
}
|
|
|
|
throw e;
|
|
} finally {
|
|
span.end();
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
export type WithRunEngineOptions<T> = T & {
|
|
prisma?: PrismaClientOrTransaction;
|
|
engine?: RunEngine;
|
|
};
|
|
|
|
export class WithRunEngine extends BaseService {
|
|
protected readonly _engine: RunEngine;
|
|
|
|
constructor(opts: { prisma?: PrismaClientOrTransaction; engine?: RunEngine } = {}) {
|
|
super(opts.prisma);
|
|
this._engine = opts.engine ?? engine;
|
|
}
|
|
}
|