Skip to content

Commit 7dd06de

Browse files
committed
Corrected typos; Corrected PlatformApiLogicClient.ts according to tslint
1 parent fc45ed3 commit 7dd06de

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const Client = new NtlmRestClient(emitter, cfg);
140140
### PlatformApiRestClient
141141
[PlatformApiRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/PlatformApiRestClient.ts)
142142
class extends [BasicAuthRestClient](#BasicAuthRestClient) class.
143-
Implements method for checking of response correctness (like containment of status code, correct JSON content type of headers end other expected response fields).
143+
The method inside this class checks for the status code 200, if not, then throws an error. And also checks that the response came with the correct data in the JSON format and the other expected response headers.
144144

145145
#### constructor(emitter, cfg)
146146
- emitter - EIO emitting context.
@@ -172,9 +172,9 @@ const Client = new PlatformApiLogicClient(emitter, cfg);
172172
- fetchWorkspaceList(options) - Fetch a list of all workspaces across all contracts for a user
173173
- fetchWorkspaceId(workspaceUniqueCriteria) - Given a set of unique criteria, find the workspace that matches
174174
- removeNonWritableProperties(flow, includeDataSamples) - Given a flow, remove the properties of the flow that are regularly changed by the system such as last executed time
175-
- fetchFlowId(flowUniqueCriteria) - Fetch flow bu it's unique criteria
176-
- fetchFlowById(id) - Fetch flow bu it's id
177-
- fetchFlowByNameAndWorkspaceId(flowName, workspaceId) -
175+
- fetchFlowId(flowUniqueCriteria) - Fetch flow by it's unique criteria
176+
- fetchFlowById(id) - Fetch flow by it's id
177+
- fetchFlowByNameAndWorkspaceId(flowName, workspaceId) - Fetch flow by flow name and workspace id
178178
- changeFlowState(options) - Given a flow, change the flow to a given state (running, stopped, etc)
179179
- startFlow(flowId, options = {}) - sets the flow to active running state
180180
- stopFlow(flowId, options = {}) - sets the flow to inactive stopped state

lib/authentication/PlatformApiLogicClient.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mapLimit } from 'async/mapLimit';
22
import { PlatformApiRestClient } from './PlatformApiRestClient';
33

4-
async function sleep(amount) { await new Promise((r) => setTimeout(r, amount)); }
4+
async function sleep(amount) { await new Promise(r => setTimeout(r, amount)); }
55

66
const DEFAULT_PARALLEL_PLATFORM_API_CALLS = process.env.PARALLEL_PLATFORM_API_CALLS || 20;
77
const DEFAULT_OBJECTS_PER_PAGE = process.env.DEFAULT_OBJECTS_PER_PAGE || 20;
@@ -40,7 +40,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
4040

4141
const objectCount = objectCountResponse.meta.total;
4242
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);
4444
await mapLimit(pageRange, parallelCalls, async (pageNumber) => {
4545
const pageResult = await this.makeRequest({
4646
url: `/flows?workspace_id=${workspaceId}&page[size]=${objectsPerPage}&page[number]=${pageNumber}`,
@@ -71,7 +71,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
7171
method: 'GET',
7272
url: `/credentials?workspace_id=${workspaceId}`,
7373
});
74-
return credentialsResponse.data.map((credential) => ({
74+
return credentialsResponse.data.map(credential => ({
7575
credentialId: credential.id,
7676
credentialName: credential.attributes.name.trim(),
7777
componentId: credential.relationships.component.data.id,
@@ -96,7 +96,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
9696
method: 'GET',
9797
url: `/components?contract_id=${contractId}`,
9898
});
99-
return componentsResponse.data.map((component) => ({
99+
return componentsResponse.data.map(component => ({
100100
componentId: component.id,
101101
componentName: component.attributes.name,
102102
componentDevTeam: component.attributes.team_name,
@@ -145,10 +145,10 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
145145
const workspaces = await this.fetchWorkspaceList({});
146146
if (!workspaceId) {
147147
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+
}));
152152
flows = nonFlatFlows.flat();
153153
} else {
154154
flows = await this.fetchAllFlowsForWorkspace({
@@ -159,7 +159,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
159159

160160
return flows.map((flow) => {
161161
const matchingWorkspaces = workspaces
162-
.filter((workspace) => workspace.workspaceId === flow.relationships.workspace.data.id);
162+
.filter(workspace => workspace.workspaceId === flow.relationships.workspace.data.id);
163163
if (matchingWorkspaces.length !== 1) {
164164
throw new Error('Failed to find matching workspace');
165165
}
@@ -209,9 +209,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
209209
});
210210
const contract = contractRequest.data;
211211
this.workspaceList = [{
212+
contractId,
212213
workspaceId: workspace.id,
213214
workspaceName: workspace.attributes.name,
214-
contractId,
215215
contractName: contract.attributes.name,
216216
contractDetails: contract,
217217
workspaceDetails: workspace,
@@ -224,7 +224,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
224224
url: '/contracts?page[size]=1',
225225
});
226226
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);
228228
const nonFlatContracts = await mapLimit(
229229
contractsPageRange,
230230
parallelCalls,
@@ -242,7 +242,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
242242
/* eslint-disable-next-line no-param-reassign */
243243
soFar[contract.id] = contract;
244244
return soFar;
245-
}, {});
245+
}, {});
246246

247247
const nonFlatWorkspaces = await mapLimit(
248248
contracts,
@@ -255,7 +255,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
255255
});
256256
const objectCount = workspacesCountResponse.meta.total;
257257
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);
259259

260260
return mapLimit(
261261
pageRange,
@@ -281,9 +281,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
281281
this.workspaceList = workspaces.map((workspace) => {
282282
const contractId = workspace.relationships.contract.data.id;
283283
return {
284+
contractId,
284285
workspaceId: workspace.id,
285286
workspaceName: workspace.attributes.name,
286-
contractId,
287287
contractName: contractsDictionary[contractId].attributes.name,
288288
contractDetails: contractsDictionary[contractId],
289289
workspaceDetails: workspace,
@@ -310,9 +310,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
310310
async fetchWorkspaceId(workspaceUniqueCriteria) {
311311
const workspaces = await this.fetchWorkspaceList({});
312312

313-
const matchingWorkspaces = workspaces.filter((workspace) => Object
313+
const matchingWorkspaces = workspaces.filter(workspace => Object
314314
.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])));
316316

317317
if (matchingWorkspaces.length !== 1) {
318318
this.emitter.logger.trace('Found %d workspaces for criteria: %j, throwing error', matchingWorkspaces.length, workspaceUniqueCriteria);
@@ -374,9 +374,9 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
374374
async fetchFlowId(flowUniqueCriteria) {
375375
const flows = await this.fetchFlowList({});
376376

377-
const matchingFlows = flows.filter((flow) => Object
377+
const matchingFlows = flows.filter(flow => Object
378378
.keys(flowUniqueCriteria.value)
379-
.every((key) => flowUniqueCriteria.value[key] === flow[key]));
379+
.every(key => flowUniqueCriteria.value[key] === flow[key]));
380380

381381
if (matchingFlows.length === 0) {
382382
return null;
@@ -400,7 +400,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
400400
// much faster and less load to API than fetchFlowId
401401
async fetchFlowByNameAndWorkspaceId(flowName, workspaceId) {
402402
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);
404404
if (matchingFlows.length !== 1) {
405405
throw new Error(`Found ${matchingFlows.length} matching flow instead of 1`);
406406
}
@@ -470,18 +470,18 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
470470
async startFlow(flowId, options = {}) {
471471
return this.changeFlowState({
472472
...options,
473+
flowId,
473474
action: 'start',
474475
desiredStatus: 'active',
475-
flowId,
476476
});
477477
}
478478

479479
async stopFlow(flowId, options = {}) {
480480
return this.changeFlowState({
481481
...options,
482+
flowId,
482483
action: 'stop',
483484
desiredStatus: 'inactive',
484-
flowId,
485485
});
486486
}
487487

@@ -496,8 +496,8 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
496496
// Enrich all data samples
497497
if (includeDataSamples) {
498498
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)
501501
.flat();
502502
const samples = await mapLimit(sampleIds, parallelCalls, async (sampleId) => {
503503
let sampleRequest;
@@ -519,17 +519,17 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
519519
/* eslint-disable-next-line no-param-reassign */
520520
soFar[sample.sampleId] = sample.sample;
521521
return soFar;
522-
}, {});
522+
}, {});
523523
flow.attributes.graph.nodes
524-
.filter((node) => node.selected_data_samples)
524+
.filter(node => node.selected_data_samples)
525525
.forEach((node) => {
526526
/* eslint-disable-next-line no-param-reassign */
527527
node.selected_data_samples = node.selected_data_samples
528-
.map((sampleId) => sampleDictionary[sampleId]);
528+
.map(sampleId => sampleDictionary[sampleId]);
529529
});
530530
} else {
531531
flow.attributes.graph.nodes
532-
.filter((node) => node.selected_data_samples)
532+
.filter(node => node.selected_data_samples)
533533
.forEach((node) => {
534534
/* eslint-disable-next-line no-param-reassign */
535535
delete node.selected_data_samples;
@@ -548,7 +548,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
548548
flow.attributes.graph.nodes.forEach((node) => {
549549
if (node.credentials_id) {
550550
const matchingCredentials = credentialsList
551-
.filter((credential) => credential.credentialId === node.credentials_id);
551+
.filter(credential => credential.credentialId === node.credentials_id);
552552
if (matchingCredentials.length !== 1) {
553553
throw new Error('Expected a single matching credential');
554554
}

tslint.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,5 @@
1212
240
1313
]
1414
},
15-
"rulesDirectory": [],
16-
"linterOptions": {
17-
"exclude": [
18-
"lib/authentication/PlatformApiLogicClient.ts"
19-
]
20-
}
15+
"rulesDirectory": []
2116
}

0 commit comments

Comments
 (0)