1
1
import { mapLimit } from 'async/mapLimit' ;
2
2
import { PlatformApiRestClient } from './PlatformApiRestClient' ;
3
3
4
- async function sleep ( amount ) { await new Promise ( ( r ) => setTimeout ( r , amount ) ) ; }
4
+ async function sleep ( amount ) { await new Promise ( r => setTimeout ( r , amount ) ) ; }
5
5
6
6
const DEFAULT_PARALLEL_PLATFORM_API_CALLS = process . env . PARALLEL_PLATFORM_API_CALLS || 20 ;
7
7
const DEFAULT_OBJECTS_PER_PAGE = process . env . DEFAULT_OBJECTS_PER_PAGE || 20 ;
@@ -40,7 +40,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
40
40
41
41
const objectCount = objectCountResponse . meta . total ;
42
42
const numPages = Math . ceil ( objectCount / Number ( objectsPerPage ) ) ;
43
- const pageRange = Array . from ( { length : numPages } , ( _x , i ) => i + 1 ) ;
43
+ const pageRange = Array . from ( { length : numPages } , ( _X , i ) => i + 1 ) ;
44
44
await mapLimit ( pageRange , parallelCalls , async ( pageNumber ) => {
45
45
const pageResult = await this . makeRequest ( {
46
46
url : `/flows?workspace_id=${ workspaceId } &page[size]=${ objectsPerPage } &page[number]=${ pageNumber } ` ,
@@ -71,7 +71,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
71
71
method : 'GET' ,
72
72
url : `/credentials?workspace_id=${ workspaceId } ` ,
73
73
} ) ;
74
- return credentialsResponse . data . map ( ( credential ) => ( {
74
+ return credentialsResponse . data . map ( credential => ( {
75
75
credentialId : credential . id ,
76
76
credentialName : credential . attributes . name . trim ( ) ,
77
77
componentId : credential . relationships . component . data . id ,
@@ -96,7 +96,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
96
96
method : 'GET' ,
97
97
url : `/components?contract_id=${ contractId } ` ,
98
98
} ) ;
99
- return componentsResponse . data . map ( ( component ) => ( {
99
+ return componentsResponse . data . map ( component => ( {
100
100
componentId : component . id ,
101
101
componentName : component . attributes . name ,
102
102
componentDevTeam : component . attributes . team_name ,
@@ -145,10 +145,10 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
145
145
const workspaces = await this . fetchWorkspaceList ( { } ) ;
146
146
if ( ! workspaceId ) {
147
147
const nonFlatFlows = await mapLimit ( workspaces , realSplitFactor ,
148
- async ( workspace ) => this . fetchAllFlowsForWorkspace ( {
149
- parallelCalls : parallelizationPerTask ,
150
- workspaceId : workspace . workspaceId ,
151
- } ) ) ;
148
+ async workspace => this . fetchAllFlowsForWorkspace ( {
149
+ parallelCalls : parallelizationPerTask ,
150
+ workspaceId : workspace . workspaceId ,
151
+ } ) ) ;
152
152
flows = nonFlatFlows . flat ( ) ;
153
153
} else {
154
154
flows = await this . fetchAllFlowsForWorkspace ( {
@@ -159,7 +159,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
159
159
160
160
return flows . map ( ( flow ) => {
161
161
const matchingWorkspaces = workspaces
162
- . filter ( ( workspace ) => workspace . workspaceId === flow . relationships . workspace . data . id ) ;
162
+ . filter ( workspace => workspace . workspaceId === flow . relationships . workspace . data . id ) ;
163
163
if ( matchingWorkspaces . length !== 1 ) {
164
164
throw new Error ( 'Failed to find matching workspace' ) ;
165
165
}
@@ -209,9 +209,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
209
209
} ) ;
210
210
const contract = contractRequest . data ;
211
211
this . workspaceList = [ {
212
+ contractId,
212
213
workspaceId : workspace . id ,
213
214
workspaceName : workspace . attributes . name ,
214
- contractId,
215
215
contractName : contract . attributes . name ,
216
216
contractDetails : contract ,
217
217
workspaceDetails : workspace ,
@@ -224,7 +224,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
224
224
url : '/contracts?page[size]=1' ,
225
225
} ) ;
226
226
const contractsCount = contractsRequest . meta . total ;
227
- const contractsPageRange = Array . from ( { length : contractsCount } , ( _x , i ) => i + 1 ) ;
227
+ const contractsPageRange = Array . from ( { length : contractsCount } , ( _X , i ) => i + 1 ) ;
228
228
const nonFlatContracts = await mapLimit (
229
229
contractsPageRange ,
230
230
parallelCalls ,
@@ -242,7 +242,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
242
242
/* eslint-disable-next-line no-param-reassign */
243
243
soFar [ contract . id ] = contract ;
244
244
return soFar ;
245
- } , { } ) ;
245
+ } , { } ) ;
246
246
247
247
const nonFlatWorkspaces = await mapLimit (
248
248
contracts ,
@@ -255,7 +255,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
255
255
} ) ;
256
256
const objectCount = workspacesCountResponse . meta . total ;
257
257
const numPages = Math . ceil ( objectCount / Number ( objectsPerPage ) ) ;
258
- const pageRange = Array . from ( { length : numPages } , ( _x , i ) => i + 1 ) ;
258
+ const pageRange = Array . from ( { length : numPages } , ( _X , i ) => i + 1 ) ;
259
259
260
260
return mapLimit (
261
261
pageRange ,
@@ -281,9 +281,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
281
281
this . workspaceList = workspaces . map ( ( workspace ) => {
282
282
const contractId = workspace . relationships . contract . data . id ;
283
283
return {
284
+ contractId,
284
285
workspaceId : workspace . id ,
285
286
workspaceName : workspace . attributes . name ,
286
- contractId,
287
287
contractName : contractsDictionary [ contractId ] . attributes . name ,
288
288
contractDetails : contractsDictionary [ contractId ] ,
289
289
workspaceDetails : workspace ,
@@ -310,9 +310,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
310
310
async fetchWorkspaceId ( workspaceUniqueCriteria ) {
311
311
const workspaces = await this . fetchWorkspaceList ( { } ) ;
312
312
313
- const matchingWorkspaces = workspaces . filter ( ( workspace ) => Object
313
+ const matchingWorkspaces = workspaces . filter ( workspace => Object
314
314
. keys ( workspaceUniqueCriteria . value )
315
- . every ( ( key ) => ( key . includes ( 'flow' ) ? true : workspaceUniqueCriteria . value [ key ] === workspace [ key ] ) ) ) ;
315
+ . every ( key => ( key . includes ( 'flow' ) ? true : workspaceUniqueCriteria . value [ key ] === workspace [ key ] ) ) ) ;
316
316
317
317
if ( matchingWorkspaces . length !== 1 ) {
318
318
this . emitter . logger . trace ( 'Found %d workspaces for criteria: %j, throwing error' , matchingWorkspaces . length , workspaceUniqueCriteria ) ;
@@ -374,9 +374,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
374
374
async fetchFlowId ( flowUniqueCriteria ) {
375
375
const flows = await this . fetchFlowList ( { } ) ;
376
376
377
- const matchingFlows = flows . filter ( ( flow ) => Object
377
+ const matchingFlows = flows . filter ( flow => Object
378
378
. keys ( flowUniqueCriteria . value )
379
- . every ( ( key ) => flowUniqueCriteria . value [ key ] === flow [ key ] ) ) ;
379
+ . every ( key => flowUniqueCriteria . value [ key ] === flow [ key ] ) ) ;
380
380
381
381
if ( matchingFlows . length === 0 ) {
382
382
return null ;
@@ -400,7 +400,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
400
400
// much faster and less load to API than fetchFlowId
401
401
async fetchFlowByNameAndWorkspaceId ( flowName , workspaceId ) {
402
402
const flowsForWS = await this . fetchAllFlowsForWorkspace ( { workspaceId } ) ;
403
- const matchingFlows = flowsForWS . filter ( ( wsFlow ) => wsFlow . attributes . name === flowName ) ;
403
+ const matchingFlows = flowsForWS . filter ( wsFlow => wsFlow . attributes . name === flowName ) ;
404
404
if ( matchingFlows . length !== 1 ) {
405
405
throw new Error ( `Found ${ matchingFlows . length } matching flow instead of 1` ) ;
406
406
}
@@ -470,18 +470,18 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
470
470
async startFlow ( flowId , options = { } ) {
471
471
return this . changeFlowState ( {
472
472
...options ,
473
+ flowId,
473
474
action : 'start' ,
474
475
desiredStatus : 'active' ,
475
- flowId,
476
476
} ) ;
477
477
}
478
478
479
479
async stopFlow ( flowId , options = { } ) {
480
480
return this . changeFlowState ( {
481
481
...options ,
482
+ flowId,
482
483
action : 'stop' ,
483
484
desiredStatus : 'inactive' ,
484
- flowId,
485
485
} ) ;
486
486
}
487
487
@@ -496,8 +496,8 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
496
496
// Enrich all data samples
497
497
if ( includeDataSamples ) {
498
498
const sampleIds = flow . attributes . graph . nodes
499
- . filter ( ( node ) => node . selected_data_samples )
500
- . map ( ( node ) => node . selected_data_samples )
499
+ . filter ( node => node . selected_data_samples )
500
+ . map ( node => node . selected_data_samples )
501
501
. flat ( ) ;
502
502
const samples = await mapLimit ( sampleIds , parallelCalls , async ( sampleId ) => {
503
503
let sampleRequest ;
@@ -519,17 +519,17 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
519
519
/* eslint-disable-next-line no-param-reassign */
520
520
soFar [ sample . sampleId ] = sample . sample ;
521
521
return soFar ;
522
- } , { } ) ;
522
+ } , { } ) ;
523
523
flow . attributes . graph . nodes
524
- . filter ( ( node ) => node . selected_data_samples )
524
+ . filter ( node => node . selected_data_samples )
525
525
. forEach ( ( node ) => {
526
526
/* eslint-disable-next-line no-param-reassign */
527
527
node . selected_data_samples = node . selected_data_samples
528
- . map ( ( sampleId ) => sampleDictionary [ sampleId ] ) ;
528
+ . map ( sampleId => sampleDictionary [ sampleId ] ) ;
529
529
} ) ;
530
530
} else {
531
531
flow . attributes . graph . nodes
532
- . filter ( ( node ) => node . selected_data_samples )
532
+ . filter ( node => node . selected_data_samples )
533
533
. forEach ( ( node ) => {
534
534
/* eslint-disable-next-line no-param-reassign */
535
535
delete node . selected_data_samples ;
@@ -548,7 +548,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
548
548
flow . attributes . graph . nodes . forEach ( ( node ) => {
549
549
if ( node . credentials_id ) {
550
550
const matchingCredentials = credentialsList
551
- . filter ( ( credential ) => credential . credentialId === node . credentials_id ) ;
551
+ . filter ( credential => credential . credentialId === node . credentials_id ) ;
552
552
if ( matchingCredentials . length !== 1 ) {
553
553
throw new Error ( 'Expected a single matching credential' ) ;
554
554
}
0 commit comments