Skip to content
Back to skills

Orpc Dedupe Middleware

ASecurity

Enhance oRPC middleware performance by avoiding redundant executions.

  • 8 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 12, 2026
devopsgitperformance

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add ali-master/skills --skill orpc-dedupe-middleware --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Orpc Dedupe Middleware?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Orpc Dedupe Middleware
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ali-master-orpc-dedupe-middleware/badge)](https://www.skillsdirectory.com/skills/ali-master-orpc-dedupe-middleware)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: oRPC Dedupe Middleware
description: Enhance oRPC middleware performance by avoiding redundant executions.
license: MIT
metadata:
  author: Ali Torki
  homepage: https://github.com/ali-master
  version: "1.0.0"
---

# Dedupe Middleware

Optimize middleware for fast and efficient repeated execution.

## Problem

When a procedure calls another procedure, overlapping middleware may run in both. Similarly, `.use(auth).router(router)` may run `auth` multiple times.

## Solution

Track middleware execution via `context` to prevent duplication:

```ts
const dbProvider = os
  .$context<{ db?: Awaited<ReturnType<typeof connectDb>> }>()
  .middleware(async ({ context, next }) => {
    const db = context.db ?? await connectDb()
    return next({ context: { db } })
  })
```

Now `dbProvider` can be safely applied multiple times without duplicating the connection:

```ts
const foo = os.use(dbProvider).handler(({ context }) => 'Hello World')

const bar = os.use(dbProvider).handler(({ context }) => {
  const result = call(foo, 'input', { context })
  return 'Hello World'
})

const router = os
  .use(dbProvider)
  .use(({ next }) => next())
  .router({ foo, bar })
```

## Built-in Dedupe

oRPC auto-dedupes middleware when the router's middlewares are a **subset** of the **leading** procedure middlewares and appear in the **same order**.

```ts
const router = os.use(logging).use(dbProvider).router({
  // ✅ Deduplicated:
  ping: os.use(logging).use(dbProvider).use(auth).handler(() => 'ping'),
  pong: os.use(logging).use(dbProvider).handler(() => 'pong'),

  // ⛔ Not deduplicated:
  diff_subset: os.use(logging).handler(() => 'ping'),
  diff_order: os.use(dbProvider).use(logging).handler(() => 'pong'),
  diff_leading: os.use(monitor).use(logging).use(dbProvider).handler(() => 'bar'),
})
```

### Configuration

Disable with `.$config`:

```ts
const base = os.$config({ dedupeLeadingMiddlewares: false })
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.