apps/gateway/src/routes/resources.ts
Metadata
- Purpose: Gateway HTTP route handlers and request/response behavior.
- Domain:
applications - Language:
ts - Bytes: 16032
- Lines: 445
- Content hash (short):
e7bae736 - Source (start): apps/gateway/src/routes/resources.ts:1
- Source (end): apps/gateway/src/routes/resources.ts:445
Indexed Symbols
parsePositiveInt(line 22, function) - Implements parse positive int for HTTP request handling.normalizeSortOrder(line 30, function) - Implements normalize sort order for HTTP request handling.normalizeSortField(line 34, function) - Implements normalize sort field for HTTP request handling.toComparableValue(line 38, function) - Implements to comparable value for HTTP request handling.withDefaultFields(line 55, function) - Implements with default fields for HTTP request handling.
Markdown Headings (if applicable)
No markdown headings detected.
Source Preview
import { randomUUID } from "node:crypto";
import type { FastifyPluginAsync } from "fastify";
import type { ZodTypeAny } from "zod";
import { coreResourceSchemas } from "@anchor/contracts";
import { createResource, deleteResource, getResource, listResources, upsertResource } from "../services/resource-repository.js";
import { getIdempotencyKey, getIdempotencyRouteScope } from "../utils/idempotency.js";
import { getWorkspaceIdFromHeaders } from "../utils/workspace.js";
import { ensureRoles } from "../utils/authorization.js";
type ResourceName = keyof typeof coreResourceSchemas;
type SortOrder = "asc" | "desc";
type ResourceListQuery = {
limit?: string;
offset?: string;
sortBy?: string;
sortOrder?: string;
q?: string;
};
const allowedSortFields = new Set(["createdAt", "updatedAt", "status", "name", "title", "priority", "severity", "dueDate"]);
function parsePositiveInt(value: string | undefined, fallback: number, maxValue: number): number {
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed <= 0) {
return fallback;