Skip to main content

apps/gateway/src/services/idempotency-repository.ts

Metadata

Indexed Symbols

  • getIdempotencyRecord (line 8, function) - Implements get idempotency record for service-layer operations.
  • putIdempotencyRecord (line 36, function) - Implements put idempotency record for service-layer operations.
  • pruneExpiredIdempotencyRecords (line 54, function) - Implements prune expired idempotency records for service-layer operations.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import { query } from "./postgres.js";

export type IdempotencyRecord = {
statusCode: number;
payload: unknown;
};

export async function getIdempotencyRecord(
workspaceId: string,
key: string,
route: string,
method: string
): Promise<IdempotencyRecord | null> {
const result = await query<{ status_code: number; response: unknown }>(
`select status_code, response
from idempotency_records
where workspace_id = $1::uuid
and idempotency_key = $2
and route = $3
and method = $4
and expires_at > now()
limit 1`,
[workspaceId, key, route, method]
);