@restorecommerce/gql-bot 0.2.1 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/lib/client.d.ts +1 -1
- package/lib/client.js +9 -4
- package/lib/job_processor.d.ts +1 -0
- package/lib/job_processor.js +4 -31
- package/lib/job_processor_gql.js +6 -5
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +29 -1
- package/package.json +6 -6
- package/src/client.ts +6 -2
- package/src/job_processor.ts +3 -32
- package/src/job_processor_gql.ts +5 -4
- package/src/utils.ts +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.2.4](https://github.com/restorecommerce/libs/compare/@restorecommerce/gql-bot@0.2.3...@restorecommerce/gql-bot@0.2.4) (2022-06-20)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @restorecommerce/gql-bot
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.2.3](https://github.com/restorecommerce/libs/compare/@restorecommerce/gql-bot@0.2.2...@restorecommerce/gql-bot@0.2.3) (2022-06-20)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **gql-bot:** correctly handle null objects ([e7e44ef](https://github.com/restorecommerce/libs/commit/e7e44ef95585d423ddee7d41b6cc196ad1668284))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [0.2.2](https://github.com/restorecommerce/libs/compare/@restorecommerce/gql-bot@0.2.1...@restorecommerce/gql-bot@0.2.2) (2022-06-20)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **gql-bot:** resume if errors are skipped ([7f01a84](https://github.com/restorecommerce/libs/commit/7f01a84f19a81360b94d8dc9421cb572d0fb3cd5))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## [0.2.1](https://github.com/restorecommerce/libs/compare/@restorecommerce/gql-bot@0.2.0...@restorecommerce/gql-bot@0.2.1) (2022-06-20)
|
|
7
37
|
|
|
8
38
|
|
package/lib/client.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export declare class Client {
|
|
|
5
5
|
constructor(opts: any);
|
|
6
6
|
_buildURLs(): any;
|
|
7
7
|
_normalizeUrl(source?: any): string;
|
|
8
|
-
post(source: any, job?: any, verbose?: boolean, ignoreSelfSigned?: boolean): Promise<any>;
|
|
8
|
+
post(source: any, job?: any, verbose?: boolean, ignoreErrors?: boolean, ignoreSelfSigned?: boolean): Promise<any>;
|
|
9
9
|
}
|
package/lib/client.js
CHANGED
|
@@ -19,6 +19,7 @@ const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
|
|
|
19
19
|
const node_fetch_1 = require("node-fetch"); // required for apollo-link-http
|
|
20
20
|
const apollo_link_http_1 = require("apollo-link-http");
|
|
21
21
|
const https = require("https");
|
|
22
|
+
const utils_1 = require("./utils");
|
|
22
23
|
const _checkVariableMutation = (mutation) => {
|
|
23
24
|
const mutationName = mutation.slice(mutation.indexOf(' '), mutation.indexOf('($'));
|
|
24
25
|
if (mutationName.indexOf('$') > 0) {
|
|
@@ -45,7 +46,7 @@ const _createQueryVariables = (inputVarName, queryVarKey, varValue) => {
|
|
|
45
46
|
};
|
|
46
47
|
};
|
|
47
48
|
const checkError = (data) => {
|
|
48
|
-
if (typeof data === 'object') {
|
|
49
|
+
if (typeof data === 'object' && data !== null) {
|
|
49
50
|
if (Array.isArray(data)) {
|
|
50
51
|
const result = data.map(value => {
|
|
51
52
|
const inner = checkError(value);
|
|
@@ -133,7 +134,7 @@ class Client {
|
|
|
133
134
|
}
|
|
134
135
|
return url.resolve(this.entryBaseUrl, extendURL);
|
|
135
136
|
}
|
|
136
|
-
post(source, job, verbose = false, ignoreSelfSigned = false) {
|
|
137
|
+
post(source, job, verbose = false, ignoreErrors = false, ignoreSelfSigned = false) {
|
|
137
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
139
|
const normalUrl = this._normalizeUrl();
|
|
139
140
|
let mutation;
|
|
@@ -177,14 +178,14 @@ class Client {
|
|
|
177
178
|
agent: new https.Agent({ rejectUnauthorized: false }),
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
|
-
let apolloLink = apollo_link_http_1.createHttpLink(apolloLinkOpts);
|
|
181
|
+
let apolloLink = (0, apollo_link_http_1.createHttpLink)(apolloLinkOpts);
|
|
181
182
|
const apolloCache = new apollo_cache_inmemory_1.InMemoryCache();
|
|
182
183
|
const apolloClient = new apollo_client_1.ApolloClient({
|
|
183
184
|
cache: apolloCache,
|
|
184
185
|
link: apolloLink
|
|
185
186
|
});
|
|
186
187
|
const response = yield apolloClient.mutate({
|
|
187
|
-
mutation: graphql_tag_1.default `${mutation}`,
|
|
188
|
+
mutation: (0, graphql_tag_1.default) `${mutation}`,
|
|
188
189
|
variables
|
|
189
190
|
});
|
|
190
191
|
const error = checkError(response);
|
|
@@ -196,6 +197,10 @@ class Client {
|
|
|
196
197
|
response
|
|
197
198
|
}));
|
|
198
199
|
}
|
|
200
|
+
else if (ignoreErrors) {
|
|
201
|
+
const processed = (0, utils_1.processResponse)(response);
|
|
202
|
+
console.error(JSON.stringify(processed));
|
|
203
|
+
}
|
|
199
204
|
throw new Error(JSON.stringify(error));
|
|
200
205
|
}
|
|
201
206
|
return response;
|
package/lib/job_processor.d.ts
CHANGED
package/lib/job_processor.js
CHANGED
|
@@ -18,33 +18,6 @@ const readdirp = require("readdirp");
|
|
|
18
18
|
const path = require("path");
|
|
19
19
|
const events_1 = require("events");
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
|
-
const unwrap = (data) => {
|
|
22
|
-
let result = data;
|
|
23
|
-
while (typeof result === 'object' && Object.keys(result).length == 1) {
|
|
24
|
-
result = result[Object.keys(result)[0]];
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
const removeType = (data) => {
|
|
29
|
-
if (typeof data === 'object') {
|
|
30
|
-
if (Array.isArray(data)) {
|
|
31
|
-
data = data.map(removeType);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
delete data['__typename'];
|
|
35
|
-
Object.keys(data).forEach(k => data[k] = removeType(data[k]));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
const processResponse = (body) => {
|
|
41
|
-
const result = [];
|
|
42
|
-
for (const response of Array.isArray(body) ? body : [body]) {
|
|
43
|
-
const clean = unwrap(removeType(response));
|
|
44
|
-
result.push(clean);
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
21
|
class ReadArrayStream extends stream_1.Readable {
|
|
49
22
|
constructor(opts, array) {
|
|
50
23
|
super(opts);
|
|
@@ -106,13 +79,13 @@ class JobProcessor {
|
|
|
106
79
|
const concurrency = this.jobInfo.options.concurrency;
|
|
107
80
|
this.taskStream = ps.map({ concurrent: concurrency }, (task) => {
|
|
108
81
|
return this.jobInfo.options.processor.process(task, verbose, ignoreErrors, ignoreSelfSigned).then((body) => {
|
|
109
|
-
const logColor = utils_1.stringToChalk(task.name);
|
|
82
|
+
const logColor = (0, utils_1.stringToChalk)(task.name);
|
|
110
83
|
if (verbose) {
|
|
111
|
-
const processed = processResponse(body);
|
|
112
|
-
console.log(`[${logColor(task.name)}] Completed
|
|
84
|
+
const processed = (0, utils_1.processResponse)(body);
|
|
85
|
+
console.log(`[${logColor(task.name)}] Completed`, JSON.stringify(processed));
|
|
113
86
|
}
|
|
114
87
|
else {
|
|
115
|
-
console.log(`[${logColor(task.name)}] Completed
|
|
88
|
+
console.log(`[${logColor(task.name)}] Completed`);
|
|
116
89
|
}
|
|
117
90
|
task.inputTask.processing--;
|
|
118
91
|
task.progress.value = 100; // task complete
|
package/lib/job_processor_gql.js
CHANGED
|
@@ -35,7 +35,7 @@ class GraphQLProcessor {
|
|
|
35
35
|
let yamlStream = new yaml_document_stream_1.YamlStreamReadTransformer();
|
|
36
36
|
let jobPath = task.path;
|
|
37
37
|
let data = false;
|
|
38
|
-
const logColor = utils_1.stringToChalk(task.name);
|
|
38
|
+
const logColor = (0, utils_1.stringToChalk)(task.name);
|
|
39
39
|
switch (task.operation) {
|
|
40
40
|
case 'sync': { // synchronous operation
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
@@ -68,7 +68,7 @@ class GraphQLProcessor {
|
|
|
68
68
|
counter = 0;
|
|
69
69
|
let batchText = '';
|
|
70
70
|
if (batchsize > 0) {
|
|
71
|
-
const from = batchCounter * batchsize;
|
|
71
|
+
const from = batchCounter * batchsize + 1;
|
|
72
72
|
const to = from + (docArr.length - 1);
|
|
73
73
|
batchText = from == to ? ` (${from})` : ` (${from} - ${to})`;
|
|
74
74
|
}
|
|
@@ -89,11 +89,12 @@ class GraphQLProcessor {
|
|
|
89
89
|
// 'yamlStream' readable stream.
|
|
90
90
|
yamlStream.on('pause', () => __awaiter(this, void 0, void 0, function* () {
|
|
91
91
|
try {
|
|
92
|
-
resultArr.push(yield this.client.post(docArr, task, verbose, ignoreSelfSigned));
|
|
92
|
+
resultArr.push(yield this.client.post(docArr, task, verbose, ignoreErrors, ignoreSelfSigned));
|
|
93
93
|
yamlStream.resume();
|
|
94
94
|
}
|
|
95
95
|
catch (e) {
|
|
96
96
|
!ignoreErrors && reject(e);
|
|
97
|
+
ignoreErrors && yamlStream.resume();
|
|
97
98
|
}
|
|
98
99
|
}));
|
|
99
100
|
let runOnResume;
|
|
@@ -113,14 +114,14 @@ class GraphQLProcessor {
|
|
|
113
114
|
if (docArr && !_.isEmpty(docArr)) {
|
|
114
115
|
let batchText = '';
|
|
115
116
|
if (batchsize > 0) {
|
|
116
|
-
const from = batchCounter * batchsize;
|
|
117
|
+
const from = batchCounter * batchsize + 1;
|
|
117
118
|
const to = from + (docArr.length - 1);
|
|
118
119
|
batchText = from == to ? ` (${from})` : ` (${from} - ${to})`;
|
|
119
120
|
}
|
|
120
121
|
batchCounter++;
|
|
121
122
|
console.log(`[${logColor(task.name)}] Processing batch: ${batchCounter}${batchText}`);
|
|
122
123
|
try {
|
|
123
|
-
resultArr.push(yield this.client.post(docArr, task, verbose, ignoreSelfSigned));
|
|
124
|
+
resultArr.push(yield this.client.post(docArr, task, verbose, ignoreErrors, ignoreSelfSigned));
|
|
124
125
|
}
|
|
125
126
|
catch (e) {
|
|
126
127
|
!ignoreErrors && reject(e);
|
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringToChalk = void 0;
|
|
3
|
+
exports.processResponse = exports.stringToChalk = void 0;
|
|
4
4
|
const color_hash_1 = require("color-hash");
|
|
5
5
|
const chalk = require("chalk");
|
|
6
6
|
const colorHash = new color_hash_1.default({
|
|
@@ -10,3 +10,31 @@ const stringToChalk = (str) => {
|
|
|
10
10
|
return chalk.hex(colorHash.hex(str));
|
|
11
11
|
};
|
|
12
12
|
exports.stringToChalk = stringToChalk;
|
|
13
|
+
const unwrap = (data) => {
|
|
14
|
+
let result = data;
|
|
15
|
+
while (typeof result === 'object' && Object.keys(result).length == 1) {
|
|
16
|
+
result = result[Object.keys(result)[0]];
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
const removeType = (data) => {
|
|
21
|
+
if (typeof data === 'object' && data !== null) {
|
|
22
|
+
if (Array.isArray(data)) {
|
|
23
|
+
data = data.map(removeType);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
delete data['__typename'];
|
|
27
|
+
Object.keys(data).forEach(k => data[k] = removeType(data[k]));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
32
|
+
const processResponse = (body) => {
|
|
33
|
+
const result = [];
|
|
34
|
+
for (const response of Array.isArray(body) ? body : [body]) {
|
|
35
|
+
const clean = unwrap(removeType(response));
|
|
36
|
+
result.push(clean);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
exports.processResponse = processResponse;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@restorecommerce/gql-bot",
|
|
3
3
|
"description": "GraphQL Client Automated Task Processor",
|
|
4
4
|
"main": "lib/index",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.4",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/restorecommerce/libs.git"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"chalk": "^4.1.2",
|
|
23
23
|
"color-hash": "^2.0.1",
|
|
24
24
|
"graphql": "^15.5.0",
|
|
25
|
-
"graphql-tag": "^2.
|
|
25
|
+
"graphql-tag": "^2.12.6",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
28
|
"node-fetch": "^2.6.0",
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"@types/node": "^14.14.41",
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
39
39
|
"@typescript-eslint/parser": "^4.22.0",
|
|
40
|
-
"coveralls": "^3.1.
|
|
40
|
+
"coveralls": "^3.1.1",
|
|
41
41
|
"eslint": "^7.24.0",
|
|
42
42
|
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
|
|
43
43
|
"mocha": "^8.3.2",
|
|
44
|
-
"nock": "^13.
|
|
44
|
+
"nock": "^13.2.7",
|
|
45
45
|
"npm-run-all": "^4.1.5",
|
|
46
46
|
"nyc": "^15.1.0",
|
|
47
47
|
"should": "^13.2.3",
|
|
48
48
|
"ts-node": "^10.5.0",
|
|
49
|
-
"typescript": "^4.
|
|
49
|
+
"typescript": "^4.7.4"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"pretest": "npm run lint",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "4dd7fcfeb6b9be52a91beb8b6353fbe69c17cc44"
|
|
75
75
|
}
|
package/src/client.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory';
|
|
|
7
7
|
import fetch from 'node-fetch'; // required for apollo-link-http
|
|
8
8
|
import { createHttpLink, HttpLink } from 'apollo-link-http';
|
|
9
9
|
import * as https from 'https';
|
|
10
|
+
import { processResponse } from './utils';
|
|
10
11
|
|
|
11
12
|
const _checkVariableMutation = (mutation: string): Boolean => {
|
|
12
13
|
const mutationName = mutation.slice(mutation.indexOf(' '),
|
|
@@ -38,7 +39,7 @@ const _createQueryVariables = (inputVarName: string, queryVarKey: string, varVal
|
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
const checkError = (data: any): any => {
|
|
41
|
-
if (typeof data === 'object') {
|
|
42
|
+
if (typeof data === 'object' && data !== null) {
|
|
42
43
|
if (Array.isArray(data)) {
|
|
43
44
|
const result = data.map(value => {
|
|
44
45
|
const inner = checkError(value);
|
|
@@ -139,7 +140,7 @@ export class Client {
|
|
|
139
140
|
return url.resolve(this.entryBaseUrl, extendURL);
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
async post(source: any, job?: any, verbose = false, ignoreSelfSigned = false): Promise<any> {
|
|
143
|
+
async post(source: any, job?: any, verbose = false, ignoreErrors = false, ignoreSelfSigned = false): Promise<any> {
|
|
143
144
|
const normalUrl = this._normalizeUrl();
|
|
144
145
|
|
|
145
146
|
let mutation;
|
|
@@ -209,6 +210,9 @@ export class Client {
|
|
|
209
210
|
variables,
|
|
210
211
|
response
|
|
211
212
|
}));
|
|
213
|
+
} else if (ignoreErrors) {
|
|
214
|
+
const processed = processResponse(response);
|
|
215
|
+
console.error(JSON.stringify(processed));
|
|
212
216
|
}
|
|
213
217
|
throw new Error(JSON.stringify(error));
|
|
214
218
|
}
|
package/src/job_processor.ts
CHANGED
|
@@ -5,36 +5,7 @@ import * as through2 from 'through2';
|
|
|
5
5
|
import * as readdirp from 'readdirp';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
|
-
import { stringToChalk } from './utils';
|
|
9
|
-
|
|
10
|
-
const unwrap = (data: any): any => {
|
|
11
|
-
let result = data;
|
|
12
|
-
while (typeof result === 'object' && Object.keys(result).length == 1) {
|
|
13
|
-
result = result[Object.keys(result)[0]];
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const removeType = (data: any): any => {
|
|
19
|
-
if (typeof data === 'object') {
|
|
20
|
-
if (Array.isArray(data)) {
|
|
21
|
-
data = data.map(removeType);
|
|
22
|
-
} else {
|
|
23
|
-
delete data['__typename'];
|
|
24
|
-
Object.keys(data).forEach(k => data[k] = removeType(data[k]));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return data;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const processResponse = (body: any | any[]): any => {
|
|
31
|
-
const result = [];
|
|
32
|
-
for (const response of Array.isArray(body) ? body : [body]) {
|
|
33
|
-
const clean = unwrap(removeType(response));
|
|
34
|
-
result.push(clean);
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
8
|
+
import { stringToChalk, processResponse } from './utils';
|
|
38
9
|
|
|
39
10
|
export class ReadArrayStream extends Readable {
|
|
40
11
|
array: any[];
|
|
@@ -112,9 +83,9 @@ export class JobProcessor {
|
|
|
112
83
|
|
|
113
84
|
if (verbose) {
|
|
114
85
|
const processed = processResponse(body);
|
|
115
|
-
console.log(`[${logColor(task.name)}] Completed
|
|
86
|
+
console.log(`[${logColor(task.name)}] Completed`, JSON.stringify(processed));
|
|
116
87
|
} else {
|
|
117
|
-
console.log(`[${logColor(task.name)}] Completed
|
|
88
|
+
console.log(`[${logColor(task.name)}] Completed`);
|
|
118
89
|
}
|
|
119
90
|
|
|
120
91
|
task.inputTask.processing--;
|
package/src/job_processor_gql.ts
CHANGED
|
@@ -64,7 +64,7 @@ export class GraphQLProcessor {
|
|
|
64
64
|
counter = 0;
|
|
65
65
|
let batchText = '';
|
|
66
66
|
if (batchsize > 0) {
|
|
67
|
-
const from = batchCounter * batchsize;
|
|
67
|
+
const from = batchCounter * batchsize + 1;
|
|
68
68
|
const to = from + (docArr.length - 1);
|
|
69
69
|
batchText = from == to ? ` (${from})` : ` (${from} - ${to})`;
|
|
70
70
|
}
|
|
@@ -85,10 +85,11 @@ export class GraphQLProcessor {
|
|
|
85
85
|
// 'yamlStream' readable stream.
|
|
86
86
|
yamlStream.on('pause', async () => {
|
|
87
87
|
try {
|
|
88
|
-
resultArr.push(await this.client.post(docArr, task, verbose, ignoreSelfSigned));
|
|
88
|
+
resultArr.push(await this.client.post(docArr, task, verbose, ignoreErrors, ignoreSelfSigned));
|
|
89
89
|
yamlStream.resume();
|
|
90
90
|
} catch (e) {
|
|
91
91
|
!ignoreErrors && reject(e);
|
|
92
|
+
ignoreErrors && yamlStream.resume();
|
|
92
93
|
}
|
|
93
94
|
});
|
|
94
95
|
|
|
@@ -111,14 +112,14 @@ export class GraphQLProcessor {
|
|
|
111
112
|
if (docArr && !_.isEmpty(docArr)) {
|
|
112
113
|
let batchText = '';
|
|
113
114
|
if (batchsize > 0) {
|
|
114
|
-
const from = batchCounter * batchsize;
|
|
115
|
+
const from = batchCounter * batchsize + 1;
|
|
115
116
|
const to = from + (docArr.length - 1);
|
|
116
117
|
batchText = from == to ? ` (${from})` : ` (${from} - ${to})`;
|
|
117
118
|
}
|
|
118
119
|
batchCounter++;
|
|
119
120
|
console.log(`[${logColor(task.name)}] Processing batch: ${batchCounter}${batchText}`);
|
|
120
121
|
try {
|
|
121
|
-
resultArr.push(await this.client.post(docArr, task, verbose, ignoreSelfSigned));
|
|
122
|
+
resultArr.push(await this.client.post(docArr, task, verbose, ignoreErrors, ignoreSelfSigned));
|
|
122
123
|
} catch (e) {
|
|
123
124
|
!ignoreErrors && reject(e);
|
|
124
125
|
}
|
package/src/utils.ts
CHANGED
|
@@ -8,3 +8,32 @@ const colorHash = new ColorHash({
|
|
|
8
8
|
export const stringToChalk = (str) => {
|
|
9
9
|
return chalk.hex(colorHash.hex(str));
|
|
10
10
|
};
|
|
11
|
+
|
|
12
|
+
const unwrap = (data: any): any => {
|
|
13
|
+
let result = data;
|
|
14
|
+
while (typeof result === 'object' && Object.keys(result).length == 1) {
|
|
15
|
+
result = result[Object.keys(result)[0]];
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const removeType = (data: any): any => {
|
|
21
|
+
if (typeof data === 'object' && data !== null) {
|
|
22
|
+
if (Array.isArray(data)) {
|
|
23
|
+
data = data.map(removeType);
|
|
24
|
+
} else {
|
|
25
|
+
delete data['__typename'];
|
|
26
|
+
Object.keys(data).forEach(k => data[k] = removeType(data[k]));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const processResponse = (body: any | any[]): any => {
|
|
33
|
+
const result = [];
|
|
34
|
+
for (const response of Array.isArray(body) ? body : [body]) {
|
|
35
|
+
const clean = unwrap(removeType(response));
|
|
36
|
+
result.push(clean);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
};
|