@@ -6,7 +6,11 @@ function extractArrayData(payload) {
66 if ( ! payload || ! payload . success ) return null ;
77 const data = payload . success . data ;
88 if ( Array . isArray ( data ) ) return data ;
9- if ( data && data . type === "FeatureCollection" && Array . isArray ( data . features ) ) {
9+ if (
10+ data &&
11+ data . type === "FeatureCollection" &&
12+ Array . isArray ( data . features )
13+ ) {
1014 return data . features ;
1115 }
1216 return null ;
@@ -17,7 +21,8 @@ function extractArrayData(payload) {
1721// Returns the object to scan for keys (GeoJSON Feature.properties if present)
1822function surfaceForIdScan ( item ) {
1923 if ( ! item ) return null ;
20- if ( item . properties && typeof item . properties === "object" ) return item . properties ;
24+ if ( item . properties && typeof item . properties === "object" )
25+ return item . properties ;
2126 return item ;
2227}
2328
@@ -26,7 +31,7 @@ function firstStarIdKey(item) {
2631 const base = surfaceForIdScan ( item ) ;
2732 if ( ! base || typeof base !== "object" ) return null ;
2833 for ( const k of Object . keys ( base ) ) {
29- if ( / _ i d $ / i. test ( k ) ) return k ; // first *_id encountered wins
34+ if ( / _ i d $ / i. test ( k ) ) return k ; // first *_id encountered wins
3035 }
3136 if ( Object . prototype . hasOwnProperty . call ( base , "id" ) ) return "id" ;
3237 return null ;
@@ -38,9 +43,12 @@ function arrayExposesKey(arr, key, sampleSize = 50) {
3843 for ( let i = 0 ; i < n ; i ++ ) {
3944 const it = arr [ i ] ;
4045 if ( ! it ) continue ;
41- const props = it . properties && typeof it . properties === "object" ? it . properties : null ;
42- if ( ( props && Object . prototype . hasOwnProperty . call ( props , key ) ) ||
43- Object . prototype . hasOwnProperty . call ( it , key ) ) {
46+ const props =
47+ it . properties && typeof it . properties === "object" ? it . properties : null ;
48+ if (
49+ ( props && Object . prototype . hasOwnProperty . call ( props , key ) ) ||
50+ Object . prototype . hasOwnProperty . call ( it , key )
51+ ) {
4452 return true ;
4553 }
4654 }
@@ -61,15 +69,17 @@ function chooseCommonIdKey(localArr, prodArr) {
6169 return null ;
6270}
6371
64-
6572// Build a set of unique IDs from an array given a chosen id key.
6673// Supports both flat objects and GeoJSON Feature properties.
6774function uniqueIds ( arr , idKey ) {
6875 const out = new Set ( ) ;
6976 for ( const item of arr ) {
7077 if ( ! item ) continue ;
7178 // Prefer .properties[idKey] if available (GeoJSON Feature)
72- const props = item . properties && typeof item . properties === "object" ? item . properties : null ;
79+ const props =
80+ item . properties && typeof item . properties === "object"
81+ ? item . properties
82+ : null ;
7383 if ( props && Object . prototype . hasOwnProperty . call ( props , idKey ) ) {
7484 out . add ( props [ idKey ] ) ;
7585 continue ;
@@ -86,8 +96,6 @@ function uniqueIds(arr, idKey) {
8696 return out ;
8797}
8898
89-
90-
9199module . exports = {
92100 aSuccessfulRequest : function ( res : {
93101 statusCode : number ;
@@ -288,7 +296,6 @@ module.exports = {
288296 ) ;
289297 } ,
290298
291-
292299 async compareWithProduction ( queryParams = "" , localResponse ) {
293300 const prodUrl = `https://www.macrostrat.org/api/v2${ queryParams } ` ;
294301 const { data : prodData } = await axios . get ( prodUrl ) ;
@@ -300,26 +307,31 @@ module.exports = {
300307
301308 // Lenient path for array-like payloads
302309 const localArr = extractArrayData ( localResponse . body ) ;
303- const prodArr = extractArrayData ( prodData ) ;
304-
305- if ( Array . isArray ( localArr ) && Array . isArray ( prodArr ) && localArr . length && prodArr . length ) {
310+ const prodArr = extractArrayData ( prodData ) ;
311+
312+ if (
313+ Array . isArray ( localArr ) &&
314+ Array . isArray ( prodArr ) &&
315+ localArr . length &&
316+ prodArr . length
317+ ) {
306318 // Auto-detect a shared *_id (or "id") to compare by counts
307319 const idKey = chooseCommonIdKey ( localArr , prodArr ) ;
308320
309321 if ( idKey ) {
310322 console . info ( `[compareWithProduction] Using id key: ${ idKey } ` ) ;
311323 const localIds = uniqueIds ( localArr , idKey ) ;
312- const prodIds = uniqueIds ( prodArr , idKey ) ;
324+ const prodIds = uniqueIds ( prodArr , idKey ) ;
313325 const localCount = localIds . size ;
314- const prodCount = prodIds . size ;
326+ const prodCount = prodIds . size ;
315327
316328 if ( localCount !== prodCount ) {
317329 console . warn (
318330 [
319331 `⚠️ ${ idKey } count mismatch for endpoint: ${ queryParams } ` ,
320332 ` - Dev (current host) ${ idKey } count: ${ localCount } ` ,
321333 ` - Prod (host_prod) ${ idKey } count: ${ prodCount } ` ,
322- ] . join ( "\n" )
334+ ] . join ( "\n" ) ,
323335 ) ;
324336
325337 return ;
@@ -332,8 +344,8 @@ module.exports = {
332344 // Strict mismatch error with helpful diff
333345 throw new Error (
334346 `Mismatch for endpoint: ${ queryParams } \n` +
335- `Local: ${ JSON . stringify ( localResponse . body , null , 2 ) } \n` +
336- `Production: ${ JSON . stringify ( prodData , null , 2 ) } `
347+ `Local: ${ JSON . stringify ( localResponse . body , null , 2 ) } \n` +
348+ `Production: ${ JSON . stringify ( prodData , null , 2 ) } ` ,
337349 ) ;
338350 } ,
339351} ;
0 commit comments