import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
export function startTracing() {
const exporter = new OTLPTraceExporter({
import { ReactNode } from 'react'
interface CardProps {
children: ReactNode
className?: string
}
import { Pool } from 'pg';
export const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: Number(process.env.PG_POOL_MAX ?? 10),
idleTimeoutMillis: 30_000,
export function Skeleton({ height = 16 }: { height?: number }) {
return <div style={{ height, background: '#eee', borderRadius: 6 }} aria-hidden="true" />;
}
export function reportWebVitals(metric: { name: string; value: number; id: string }) {
if (Math.random() > 0.05) return;
navigator.sendBeacon(
'/api/vitals',
JSON.stringify({ name: metric.name, value: metric.value, id: metric.id, path: location.pathname })
);
import { useEffect, useState } from 'react';
export function useDebouncedValue<T>(value: T, delayMs: number) {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
import { useForm } from 'react-hook-form'
import { PostFormData } from '@/types'
interface PostFormProps {
initialData?: Partial<PostFormData>
onSubmit: (data: PostFormData) => Promise<void>
const allow = new Map<string, string>();
// allow.set('sha256:abc...', 'query GetSnip($id: ID!) { snip(id: $id) { id title } }')
export function resolvePersistedQuery(hash: string, query?: string) {
if (query) return query; // migration period
const q = allow.get(hash);
import crypto from 'node:crypto';
import type { RequestHandler } from 'express';
export const ensureCsrfCookie: RequestHandler = (_req, res, next) => {
const token = crypto.randomBytes(16).toString('hex');
res.cookie('csrf_token', token, { sameSite: 'lax', secure: true });
import { useInfiniteQuery } from '@tanstack/react-query'
import api from '@/services/api'
import { Post, PaginatedResponse } from '@/types'
export function useInfinitePosts() {
return useInfiniteQuery({
import client from 'prom-client';
import type { RequestHandler } from 'express';
export const httpDuration = new client.Histogram({
name: 'http_request_duration_seconds',
help: 'HTTP request duration in seconds',