firebase / firebase/firebase-admin-node

[FR] Public API to Detect FieldValue.increment()

Abierto
#2,957 2 comentarios 0 reacciones 1 asignado Reclamado por @ehsannas Ver en GitHub
api: firestore type: feature request
Lenguaje dominante
TypeScript
Estrellas
1.7k
Forks
419
Merge medio
3 d 10 h
PR fusionados (30 d)
16

Descripción

The Firebase Admin Node SDK currently does not provide a public API to detect if a value is a `FieldValue.increment()` object. This forces developers to rely on internal implementation details like checking for `constructor.name === 'NumericIncrementTransform'`, which is fragile and may break with SDK updates.

## Current Workaround
```typescript
// Current approach relies on internal implementation
function hasFieldValueIncrement(value: unknown): boolean {
return (
typeof value === 'object' &&
value.constructor &&
value.constructor.name === 'NumericIncrementTransform'
);
}
```

## Problem
1. **Fragility**: The `NumericIncrementTransform` class name is an internal implementation detail
2. **No Stability Guarantee**: This approach may break in future SDK versions
3. **Lack of Documentation**: No official way to detect increment operations

## Requested Enhancement
Please provide a public API method to detect `FieldValue.increment()` objects, similar to how other Firebase features provide type guards.

### Suggested API
```typescript
import { FieldValue } from 'firebase-admin/firestore';

// Option 1: Static method on FieldValue
FieldValue.isIncrement(value: unknown): value is FieldValue

// Option 2: Dedicated type guard function
import { isIncrement } from 'firebase-admin/firestore';
isIncrement(value: unknown): value is FieldValue
```

## Use Case
This is needed for:
- Data validation pipelines that need to identify increment operations
- Custom diffing systems that handle FieldValue operations differently
- Development tools that analyze Firestore update patterns
- Testing utilities that need to verify increment operations

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.