proxy-pattern

Implement JavaScript and TypeScript Proxy handlers with get and set traps using Reflect.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill proxy-pattern-quanngynx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: proxy-pattern
Source: https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI/tree/main/servexa-warranty-ai/.agents/skills/proxy-pattern
Command: npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill proxy-pattern-quanngynx

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Proxy Pattern helps you manage and control how an application interacts with object properties by centralizing behavior for property reads, writes, and side effects like validation and logging.

Core Features & Use Cases

  • Property interception: Customize behavior for property access and assignment using get and set traps.
  • Validation and integrity checks: Enforce constraints (e.g., type checks, required fields) before allowing updates.
  • Controlled observability: Log meaningful messages when values are read or changed to support debugging and audit trails.

Use case: Protect a person-like data model so that age can only be set to numbers and name cannot be empty, while capturing every access and mutation for traceability.

Quick Start

Create a Proxy for your target object with get and set traps, and use Reflect.get and Reflect.set inside those handlers for safe property access and updates.

Frequently Asked Questions about proxy-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I intercept object property access and mutation in JavaScript for validation?

You can intercept object property access and mutation by defining a Proxy with get and set traps, using Reflect.get and Reflect.set inside the handlers to maintain correct property operations while enforcing validation rules.

What is the Proxy pattern used for in TypeScript?

The Proxy pattern in TypeScript centralizes control over object interactions, enabling property interception, type validation, and controlled observability like logging to support debugging and audit trails before updates occur.

How to log property changes and enforce type checks on JavaScript objects?

To log property changes and enforce type checks, create a Proxy handler with a set trap that validates incoming values, logs the mutation, and then applies the update using Reflect.set for safe and traceable execution.

Can I use Proxy and Reflect to prevent empty string assignments in JavaScript?

Yes, you can prevent empty string assignments by defining a set trap within a JavaScript Proxy that checks the incoming value and rejects the mutation if the string is empty, ensuring object integrity.

When should I use object interception instead of direct property assignment?

Use object interception when you need centralized behavior for property reads and writes, such as enforcing constraints, applying formatting, generating audit trails, or implementing access control around gets and sets.

What are the limitations of using Proxy traps for data validation?

Proxy traps validate object interactions at runtime but do not provide compile-time type safety; they require defining handlers for each trap and using Reflect correctly to avoid breaking default property operations.