interceptors

java
@MappedSuperclass
@FilterDef(
    name = "tenantFilter",
    parameters = @ParamDef(name = "tenantId", type = String.class)
)
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")

Enforce Multi-Tenant Row Isolation With Hibernate @Filter Enabled Per Request in Spring Boot

spring-boot hibernate jpa
by codesnips 4 tabs
typescript
import { Injectable, Scope } from '@nestjs/common';
import { DataSource, EntityManager, QueryRunner } from 'typeorm';

@Injectable({ scope: Scope.REQUEST })
export class TransactionContext {
  private queryRunner?: QueryRunner;

Request-Scoped TypeORM QueryRunner Provider for Transactional Writes in NestJS

nestjs typeorm transactions
by codesnips 3 tabs
typescript
import { SetMetadata } from '@nestjs/common';

export const CACHEABLE_KEY = 'cacheable:options';

export type VaryDimension = 'user' | 'tenant' | 'query';

Per-Route Response Caching in NestJS with a Custom CacheInterceptor and Cache Key Builder

nestjs caching interceptors
by codesnips 4 tabs
javascript
const STORAGE_KEY = "auth.refreshToken";

let accessToken = null;
let refreshToken = localStorage.getItem(STORAGE_KEY);

const listeners = new Set();

Transparent JWT Refresh With a Single-Flight Axios Response Interceptor

axios interceptors jwt
by codesnips 3 tabs
ruby
class EmailDedupService
  DEFAULT_TTL = 5.minutes.to_i

  def self.claim(fingerprint, ttl: DEFAULT_TTL)
    key = "email_dedup:#{fingerprint}"
    # Atomic set-if-absent with expiry; returns true only for the first caller.

Throttle Duplicate Emails in Rails with a Mailer Interceptor and Redis Dedup Service

rails actionmailer redis
by codesnips 3 tabs