File tree Expand file tree Collapse file tree 6 files changed +21
-52
lines changed
Expand file tree Collapse file tree 6 files changed +21
-52
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { createLogger, type Logger } from "../logging";
88import type { ClientConfig , ProxyCheckOptions } from "../types" ;
99import { DEFAULTS } from "../types/constants" ;
1010import { ClientConfigSchema , ProxyCheckOptionsSchema } from "../types/schemas" ;
11+ import { stripUndefined } from "../utils/object" ;
1112
1213/**
1314 * Query parameters interface
@@ -236,18 +237,6 @@ export class ConfigManager {
236237 }
237238}
238239
239- /**
240- * Helper to remove undefined values from an object for exactOptionalPropertyTypes
241- */
242- function stripUndefined < T extends Record < string , unknown > > ( obj : T ) : T {
243- const result = { } as T ;
244- for ( const [ key , value ] of Object . entries ( obj ) ) {
245- if ( value !== undefined ) {
246- result [ key as keyof T ] = value as T [ keyof T ] ;
247- }
248- }
249- return result ;
250- }
251240
252241/**
253242 * Validate and merge ProxyCheck options
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { ProxyCheckValidationError } from "../errors";
1313import type { AddressCheckResult , CheckResponse , ProxyCheckOptions } from "../types" ;
1414import { API_ENDPOINTS } from "../types/constants" ;
1515import { ProxyCheckOptionsSchema } from "../types/schemas" ;
16+ import { stripUndefined } from "../utils/object" ;
1617import { BaseService } from "./base" ;
1718
1819/**
@@ -216,21 +217,12 @@ export class CheckService extends BaseService {
216217 private validateOptions ( options : ProxyCheckOptions ) : ProxyCheckOptions {
217218 try {
218219 const parsed = ProxyCheckOptionsSchema . parse ( options ) as any ;
219- return this . stripUndefined ( parsed ) as ProxyCheckOptions ;
220+ return stripUndefined ( parsed ) as ProxyCheckOptions ;
220221 } catch ( _error ) {
221222 throw new ProxyCheckValidationError ( "Invalid options provided" , "options" , options ) ;
222223 }
223224 }
224225
225- private stripUndefined < T extends Record < string , unknown > > ( obj : T ) : T {
226- const result = { } as T ;
227- for ( const [ key , value ] of Object . entries ( obj ) ) {
228- if ( value !== undefined ) {
229- result [ key as keyof T ] = value as T [ keyof T ] ;
230- }
231- }
232- return result ;
233- }
234226
235227 /**
236228 * Add blocking logic for single address checks
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { ProxyCheckValidationError } from "../errors";
66import type { ListOptions , ListResponse } from "../types" ;
77import { API_ENDPOINTS } from "../types/constants" ;
88import { ListOptionsSchema } from "../types/schemas" ;
9+ import { stripUndefined } from "../utils/object" ;
910import { BaseService } from "./base" ;
1011
1112/**
@@ -229,19 +230,10 @@ export class ListingService extends BaseService {
229230 private validateOptions ( options : ListOptions ) : ListOptions {
230231 try {
231232 const parsed = ListOptionsSchema . parse ( options ) as any ;
232- return this . stripUndefined ( parsed ) as ListOptions ;
233+ return stripUndefined ( parsed ) as ListOptions ;
233234 } catch ( _error ) {
234235 throw new ProxyCheckValidationError ( "Invalid list options provided" , "options" , options ) ;
235236 }
236237 }
237238
238- private stripUndefined < T extends Record < string , unknown > > ( obj : T ) : T {
239- const result = { } as T ;
240- for ( const [ key , value ] of Object . entries ( obj ) ) {
241- if ( value !== undefined ) {
242- result [ key as keyof T ] = value as T [ keyof T ] ;
243- }
244- }
245- return result ;
246- }
247239}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { ProxyCheckValidationError } from "../errors";
66import type { RuleOptions , RuleResponse } from "../types" ;
77import { API_ENDPOINTS } from "../types/constants" ;
88import { RuleOptionsSchema } from "../types/schemas" ;
9+ import { stripUndefined } from "../utils/object" ;
910import { BaseService } from "./base" ;
1011
1112/**
@@ -225,19 +226,10 @@ export class RulesService extends BaseService {
225226 private validateOptions ( options : RuleOptions ) : RuleOptions {
226227 try {
227228 const parsed = RuleOptionsSchema . parse ( options ) as any ;
228- return this . stripUndefined ( parsed ) as RuleOptions ;
229+ return stripUndefined ( parsed ) as RuleOptions ;
229230 } catch ( _error ) {
230231 throw new ProxyCheckValidationError ( "Invalid rule options provided" , "options" , options ) ;
231232 }
232233 }
233234
234- private stripUndefined < T extends Record < string , unknown > > ( obj : T ) : T {
235- const result = { } as T ;
236- for ( const [ key , value ] of Object . entries ( obj ) ) {
237- if ( value !== undefined ) {
238- result [ key as keyof T ] = value as T [ keyof T ] ;
239- }
240- }
241- return result ;
242- }
243235}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { ProxyCheckValidationError } from "../errors";
66import type { StatsOptions , StatsResponse } from "../types" ;
77import { API_ENDPOINTS } from "../types/constants" ;
88import { StatsOptionsSchema } from "../types/schemas" ;
9+ import { stripUndefined } from "../utils/object" ;
910import { BaseService } from "./base" ;
1011
1112/**
@@ -205,19 +206,10 @@ export class StatsService extends BaseService {
205206 private validateOptions ( options : StatsOptions ) : StatsOptions {
206207 try {
207208 const parsed = StatsOptionsSchema . parse ( options ) as any ;
208- return this . stripUndefined ( parsed ) as StatsOptions ;
209+ return stripUndefined ( parsed ) as StatsOptions ;
209210 } catch ( _error ) {
210211 throw new ProxyCheckValidationError ( "Invalid stats options provided" , "options" , options ) ;
211212 }
212213 }
213214
214- private stripUndefined < T extends Record < string , unknown > > ( obj : T ) : T {
215- const result = { } as T ;
216- for ( const [ key , value ] of Object . entries ( obj ) ) {
217- if ( value !== undefined ) {
218- result [ key as keyof T ] = value as T [ keyof T ] ;
219- }
220- }
221- return result ;
222- }
223215}
Original file line number Diff line number Diff line change 1+ /**
2+ * Helper to remove undefined values from an object for exactOptionalPropertyTypes
3+ */
4+ export function stripUndefined < T extends Record < string , unknown > > ( obj : T ) : T {
5+ const result = { } as T ;
6+ for ( const [ key , value ] of Object . entries ( obj ) ) {
7+ if ( value !== undefined ) {
8+ result [ key as keyof T ] = value as T [ keyof T ] ;
9+ }
10+ }
11+ return result ;
12+ }
You can’t perform that action at this time.
0 commit comments