class DeadlineError extends Error {
constructor(message = 'request deadline exceeded') {
super(message);
this.name = 'DeadlineError';
this.code = 'DEADLINE_EXCEEDED';
}
CREATE TABLE idempotency_keys (
id BIGSERIAL PRIMARY KEY,
idempotency_key TEXT NOT NULL,
request_path TEXT NOT NULL,
request_fingerprint TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'in_progress',
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["source"]
async copy() {
import { useCallback, useEffect, useState } from 'react';
function parseSearch(search) {
const params = new URLSearchParams(search);
const out = {};
for (const [key, value] of params.entries()) out[key] = value;
import { useCallback, useEffect, useRef, useState } from 'react';
export function usePaginatedFetch(fetchPage, { pageSize = 20 } = {}) {
const [items, setItems] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
import { StreamActions } from "@hotwired/turbo"
StreamActions.highlight = function () {
const className = this.getAttribute("data-highlight-class") || "flash-highlight"
const duration = parseInt(this.getAttribute("data-highlight-duration"), 10) || 1500
class TokenBucket {
constructor(capacity, refillPerSecond) {
this.capacity = capacity;
this.refillPerMs = refillPerSecond / 1000;
this.tokens = capacity;
this.lastRefill = Date.now();
const { WebSocketServer } = require('ws');
const crypto = require('crypto');
const wss = new WebSocketServer({ port: 8080 });
function broadcast(payload, except) {
const jwt = require('jsonwebtoken');
const ACCESS_SECRET = process.env.JWT_ACCESS_SECRET;
const REFRESH_SECRET = process.env.JWT_REFRESH_SECRET;
const ISSUER = 'api.example.com';
const AUDIENCE = 'example-web';
function createReadiness() {
let ready = true;
function markUnready() {
ready = false;
}
import { useEffect, useState } from "react";
export function useDebouncedValue(value, delay = 300) {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
// ES6 Class syntax
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}