@tskmgr/client 0.0.10 → 0.1.0
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/package.json +8 -4
- package/src/index.d.ts +3 -0
- package/src/index.js +5 -2
- package/src/index.js.map +1 -1
- package/src/lib/client-example.d.ts +2 -0
- package/src/lib/client-example.js +51 -28
- package/src/lib/client-example.js.map +1 -1
- package/src/lib/client-factory.d.ts +2 -1
- package/src/lib/client-factory.js.map +1 -1
- package/src/lib/client-options.d.ts +12 -0
- package/src/lib/client-options.js +3 -0
- package/src/lib/client-options.js.map +1 -0
- package/src/lib/client.d.ts +16 -39
- package/src/lib/client.js +76 -87
- package/src/lib/client.js.map +1 -1
- package/src/lib/run-tasks-result.d.ts +9 -0
- package/src/lib/run-tasks-result.js +14 -0
- package/src/lib/run-tasks-result.js.map +1 -0
- package/src/lib/task-result.d.ts +10 -0
- package/src/lib/task-result.js +3 -0
- package/src/lib/task-result.js.map +1 -0
- package/src/lib/utils.d.ts +17 -0
- package/src/lib/utils.js +68 -0
- package/src/lib/utils.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tskmgr/client",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"node-fetch": "^2.6.7",
|
|
7
|
-
"
|
|
7
|
+
"systeminformation": "^5.16.6"
|
|
8
8
|
},
|
|
9
9
|
"main": "./src/index.js",
|
|
10
|
-
"
|
|
11
|
-
"peerDependencies": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@tskmgr/common": "0.0.1",
|
|
13
|
+
"uuid": "^9.0.0",
|
|
14
|
+
"tslib": "^2.0.0"
|
|
15
|
+
}
|
|
12
16
|
}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./lib/client"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/client-options"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/client-factory"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/run-tasks-result"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/task-result"), exports);
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/client/src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/client/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,+DAAqC;AACrC,+DAAqC;AAErC,iEAAuC;AACvC,4DAAkC"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* IntelliJ debug:
|
|
3
3
|
* Node parameters: --require ts-node/register --require tsconfig-paths/register
|
|
4
4
|
* Environment variables: TS_NODE_PROJECT=libs/client/tsconfig.lib.json
|
|
5
|
+
*
|
|
5
6
|
* Start API: nx serve api
|
|
7
|
+
* Command: nx reset && TS_NODE_PROJECT=libs/client/tsconfig.lib.json node --require ts-node/register --require tsconfig-paths/register libs/client/src/lib/client-example.ts
|
|
6
8
|
*/
|
|
7
9
|
export {};
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* IntelliJ debug:
|
|
4
4
|
* Node parameters: --require ts-node/register --require tsconfig-paths/register
|
|
5
5
|
* Environment variables: TS_NODE_PROJECT=libs/client/tsconfig.lib.json
|
|
6
|
+
*
|
|
6
7
|
* Start API: nx serve api
|
|
8
|
+
* Command: nx reset && TS_NODE_PROJECT=libs/client/tsconfig.lib.json node --require ts-node/register --require tsconfig-paths/register libs/client/src/lib/client-example.ts
|
|
7
9
|
*/
|
|
8
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
11
|
const tslib_1 = require("tslib");
|
|
@@ -12,41 +14,54 @@ const common_1 = require("@tskmgr/common");
|
|
|
12
14
|
const client_factory_1 = require("./client-factory");
|
|
13
15
|
const uuid_1 = require("uuid");
|
|
14
16
|
delete process.env.TS_NODE_PROJECT;
|
|
15
|
-
const
|
|
17
|
+
const debug = false;
|
|
18
|
+
const options = { parallel: 1, dataCallback, errorCallback };
|
|
16
19
|
const client = client_factory_1.ClientFactory.createNew('http://localhost:3333', 'RUNNER_1', options);
|
|
17
|
-
|
|
20
|
+
let exitCode = 0;
|
|
21
|
+
let run;
|
|
22
|
+
(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
18
23
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
name: nxTask.target.project,
|
|
22
|
-
type: nxTask.target.target,
|
|
23
|
-
command: nxTask.command,
|
|
24
|
-
options: { shell: true },
|
|
25
|
-
priority: common_1.TaskPriority.Longest,
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
const newRun = yield client.createRun({
|
|
24
|
+
// 1. Create the new run
|
|
25
|
+
run = yield client.createRun({
|
|
29
26
|
name: (0, uuid_1.v4)(),
|
|
30
27
|
type: '123',
|
|
31
|
-
pullRequestName: '123',
|
|
32
28
|
prioritization: [common_1.TaskPriority.Longest],
|
|
33
29
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
log(run);
|
|
31
|
+
// 2. Leader should create some tasks to run
|
|
32
|
+
const res = yield client.setLeader(run.id);
|
|
33
|
+
if (res.leader) {
|
|
34
|
+
const tasks = getNxTasks().map((nxTask) => {
|
|
35
|
+
return {
|
|
36
|
+
name: nxTask.target.project,
|
|
37
|
+
type: nxTask.target.target,
|
|
38
|
+
command: nxTask.command,
|
|
39
|
+
options: { shell: true },
|
|
40
|
+
priority: common_1.TaskPriority.Longest,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const createdTasks = yield client.createTasks(run.id, { tasks });
|
|
44
|
+
log(createdTasks);
|
|
45
|
+
const closeRun = yield client.closeRun(run.id);
|
|
46
|
+
log(closeRun);
|
|
41
47
|
}
|
|
42
|
-
|
|
48
|
+
// 3. Execute tasks
|
|
49
|
+
const result = yield client.runTasks(run.id);
|
|
43
50
|
if (result.failed) {
|
|
44
|
-
|
|
51
|
+
// if failFast set to false, runTasks will complete without throwing errors.
|
|
52
|
+
exitCode = 1;
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
catch (e) {
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
log(e);
|
|
57
|
+
exitCode = 1;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
// 4. See results
|
|
61
|
+
console.log('--------------------------------------------------');
|
|
62
|
+
console.log(` tskmgr run: http://localhost:4200/runs/${run.id}`);
|
|
63
|
+
console.log('--------------------------------------------------');
|
|
64
|
+
process.exit(exitCode);
|
|
50
65
|
}
|
|
51
66
|
}))();
|
|
52
67
|
function getNxTasks() {
|
|
@@ -59,13 +74,21 @@ function getNxTasks() {
|
|
|
59
74
|
return tasks;
|
|
60
75
|
}
|
|
61
76
|
function dataCallback(task, data, cached) {
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
if (data.startsWith(`> nx run ${task.name}:${task.type}`) &&
|
|
77
|
+
// > nx run frontend:lint [existing outputs match the cache, left as is]
|
|
78
|
+
// > nx run client:lint [local cache]
|
|
79
|
+
if ((data.startsWith(`> nx run ${task.name}:${task.type}`) &&
|
|
80
|
+
data.endsWith('[existing outputs match the cache, left as is]')) ||
|
|
81
|
+
data.endsWith('[local cache]')) {
|
|
65
82
|
cached();
|
|
66
83
|
}
|
|
84
|
+
console.log(`[stdout] ${data}`);
|
|
67
85
|
}
|
|
68
86
|
function errorCallback(task, data) {
|
|
69
|
-
console.log(data);
|
|
87
|
+
console.log(`[stderr] ${data}`);
|
|
88
|
+
}
|
|
89
|
+
function log(message) {
|
|
90
|
+
if (debug) {
|
|
91
|
+
console.log(message);
|
|
92
|
+
}
|
|
70
93
|
}
|
|
71
94
|
//# sourceMappingURL=client-example.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-example.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-example.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"client-example.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-example.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,iDAAyC;AACzC,2CAAwE;AAExE,qDAAiD;AACjD,+BAAkC;AAElC,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;AAEnC,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,OAAO,GAAkB,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AAC5E,MAAM,MAAM,GAAG,8BAAa,CAAC,SAAS,CAAC,uBAAuB,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAErF,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,IAAI,GAAQ,CAAC;AAEb,CAAC,GAAS,EAAE;IACV,IAAI;QACF,wBAAwB;QACxB,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YAC3B,IAAI,EAAE,IAAA,SAAI,GAAE;YACZ,IAAI,EAAE,KAAK;YACX,cAAc,EAAE,CAAC,qBAAY,CAAC,OAAO,CAAC;SACvC,CAAC,CAAC;QACH,GAAG,CAAC,GAAG,CAAC,CAAC;QAET,4CAA4C;QAC5C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3C,IAAI,GAA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S,UAAU;IACjB,MAAM,KAAK,GAAa;QACtB,oEAAoE;QACpE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAQ,EAAC,2CAA2C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;QACrF,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAQ,EAAC,2CAA2C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;QACrF,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAQ,EAAC,4CAA4C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;KACvF,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,IAAU,EAAE,IAAY,EAAE,MAAkB;IAChE,yEAAyE;IACzE,sCAAsC;IACtC,IACE,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,gDAAgD,CAAC,CAAC;QAClE,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAC9B;QACA,MAAM,EAAE,CAAC;KACV;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,aAAa,CAAC,IAAU,EAAE,IAAY;IAC7C,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,GAAG,CAAC,OAAY;IACvB,IAAI,KAAK,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KACtB;AACH,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Client
|
|
1
|
+
import { Client } from './client';
|
|
2
|
+
import { ClientOptions } from './client-options';
|
|
2
3
|
export declare class ClientFactory {
|
|
3
4
|
static createNew(baseUrl: string, //
|
|
4
5
|
runnerId: string, options?: ClientOptions): Client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-factory.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-factory.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"client-factory.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-factory.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAElC,2CAAwC;AAExC,MAAa,aAAa;IACjB,MAAM,CAAC,SAAS,CACrB,OAAe,EAAE,EAAE;IACnB,QAAgB,EAChB,OAAuB;QAEvB,OAAO,IAAI,eAAM,CACf,eAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE;QAC1B,QAAQ,kCACH,eAAM,CAAC,cAAc,GAAK,OAAO,EACvC,CAAC;IACJ,CAAC;CACF;AAZD,sCAYC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Task } from '@tskmgr/common';
|
|
3
|
+
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
parallel?: number;
|
|
6
|
+
dataCallback?: (task: Task, data: string, cached: () => void) => void;
|
|
7
|
+
errorCallback?: (task: Task, data: string) => void;
|
|
8
|
+
pollingDelayMs?: number;
|
|
9
|
+
retryDelayMs?: number;
|
|
10
|
+
retryCount?: number;
|
|
11
|
+
spawnOptions?: SpawnOptionsWithoutStdio;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-options.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-options.ts"],"names":[],"mappings":""}
|
package/src/lib/client.d.ts
CHANGED
|
@@ -1,47 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface ClientOptions {
|
|
5
|
-
parallel?: number;
|
|
6
|
-
dataCallback?: (task: Task, data: string, cached: () => void) => void;
|
|
7
|
-
errorCallback?: (task: Task, data: string) => void;
|
|
8
|
-
pollingDelayMs?: number;
|
|
9
|
-
retryDelayMs?: number;
|
|
10
|
-
retryCount?: number;
|
|
11
|
-
spawnOptions?: SpawnOptionsWithoutStdio;
|
|
12
|
-
}
|
|
1
|
+
import { ApiUrl, Run, CompleteTaskDto, CreateRunRequestDto, CreateTasksDto, StartTaskDto, StartTaskResponseDto, Task, File as File_, SetLeaderResponseDto, CreateFileRequestDto } from '@tskmgr/common';
|
|
2
|
+
import { RunTasksResult } from './run-tasks-result';
|
|
3
|
+
import { ClientOptions } from './client-options';
|
|
13
4
|
export declare class Client {
|
|
14
5
|
private readonly apiUrl;
|
|
15
6
|
private readonly runnerId;
|
|
16
7
|
private readonly options;
|
|
17
8
|
static readonly DefaultOptions: ClientOptions;
|
|
18
|
-
constructor(apiUrl: ApiUrl,
|
|
19
|
-
runnerId: string, options: ClientOptions);
|
|
9
|
+
constructor(apiUrl: ApiUrl, runnerId: string, options: ClientOptions);
|
|
20
10
|
createRun(params: CreateRunRequestDto): Promise<Run>;
|
|
21
|
-
closeRun(runId:
|
|
22
|
-
abortRun(runId:
|
|
23
|
-
failRun(runId:
|
|
24
|
-
setLeader(runId:
|
|
25
|
-
createTasks(runId:
|
|
26
|
-
startTask(runId:
|
|
27
|
-
runTasks(runId:
|
|
28
|
-
completeTask(taskId:
|
|
29
|
-
failTask(taskId:
|
|
11
|
+
closeRun(runId: number): Promise<Run>;
|
|
12
|
+
abortRun(runId: number): Promise<Run>;
|
|
13
|
+
failRun(runId: number): Promise<Run>;
|
|
14
|
+
setLeader(runId: number): Promise<SetLeaderResponseDto>;
|
|
15
|
+
createTasks(runId: number, params: CreateTasksDto): Promise<Task[]>;
|
|
16
|
+
startTask(runId: number, params: StartTaskDto): Promise<StartTaskResponseDto>;
|
|
17
|
+
runTasks(runId: number): Promise<RunTasksResult>;
|
|
18
|
+
completeTask(taskId: number, params: CompleteTaskDto): Promise<Task>;
|
|
19
|
+
failTask(taskId: number): Promise<Task>;
|
|
20
|
+
uploadRunFile(runId: number, path: string, params: CreateFileRequestDto): Promise<File_>;
|
|
21
|
+
uploadTaskFile(taskId: number, path: string, params: CreateFileRequestDto): Promise<File_>;
|
|
22
|
+
private uploadFile;
|
|
30
23
|
private defaultTaskRunner;
|
|
31
24
|
}
|
|
32
|
-
export declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio, dataCallback?: (data: string) => void, errorCallback?: (data: string) => void): Promise<ChildProcess>;
|
|
33
|
-
export interface TaskResult {
|
|
34
|
-
run: Run;
|
|
35
|
-
task: Task;
|
|
36
|
-
childProcess: ChildProcess;
|
|
37
|
-
hasCompleted: boolean;
|
|
38
|
-
error?: Error;
|
|
39
|
-
}
|
|
40
|
-
export declare class RunTasksResult {
|
|
41
|
-
readonly tasks: TaskResult[];
|
|
42
|
-
readonly completedTasks: TaskResult[];
|
|
43
|
-
readonly failedTasks: TaskResult[];
|
|
44
|
-
readonly completed: boolean;
|
|
45
|
-
readonly failed: boolean;
|
|
46
|
-
constructor(tasks: TaskResult[]);
|
|
47
|
-
}
|
package/src/lib/client.js
CHANGED
|
@@ -1,130 +1,158 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Client = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
6
|
-
const child_process_1 = require("child_process");
|
|
7
5
|
const node_fetch_1 = require("node-fetch");
|
|
8
|
-
const
|
|
6
|
+
const FormData = require("form-data");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const run_tasks_result_1 = require("./run-tasks-result");
|
|
9
|
+
const fs_1 = require("fs");
|
|
9
10
|
class Client {
|
|
10
|
-
constructor(apiUrl,
|
|
11
|
-
runnerId, options) {
|
|
11
|
+
constructor(apiUrl, runnerId, options) {
|
|
12
12
|
this.apiUrl = apiUrl;
|
|
13
13
|
this.runnerId = runnerId;
|
|
14
14
|
this.options = options;
|
|
15
15
|
}
|
|
16
16
|
createRun(params) {
|
|
17
|
-
return
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.createRunUrl(), {
|
|
19
19
|
headers: { 'Content-Type': 'application/json' },
|
|
20
20
|
method: 'POST',
|
|
21
21
|
body: JSON.stringify(params),
|
|
22
22
|
});
|
|
23
|
-
return yield checkStatus(res).json();
|
|
23
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
closeRun(runId) {
|
|
27
|
-
return
|
|
27
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.closeRunUrl(runId), {
|
|
29
29
|
headers: { 'Content-Type': 'application/json' },
|
|
30
30
|
method: 'PUT',
|
|
31
31
|
});
|
|
32
|
-
return yield checkStatus(res).json();
|
|
32
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
abortRun(runId) {
|
|
36
|
-
return
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.abortRunUrl(runId), {
|
|
38
38
|
headers: { 'Content-Type': 'application/json' },
|
|
39
39
|
method: 'PUT',
|
|
40
40
|
});
|
|
41
|
-
return yield checkStatus(res).json();
|
|
41
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
failRun(runId) {
|
|
45
|
-
return
|
|
45
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
46
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.failRunUrl(runId), {
|
|
47
47
|
headers: { 'Content-Type': 'application/json' },
|
|
48
48
|
method: 'PUT',
|
|
49
49
|
});
|
|
50
|
-
return yield checkStatus(res).json();
|
|
50
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
setLeader(runId) {
|
|
54
|
-
return
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
55
|
const params = { runnerId: this.runnerId };
|
|
56
56
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.setLeaderUrl(runId), {
|
|
57
57
|
headers: { 'Content-Type': 'application/json' },
|
|
58
58
|
method: 'PUT',
|
|
59
59
|
body: JSON.stringify(params),
|
|
60
60
|
});
|
|
61
|
-
return yield checkStatus(res).json();
|
|
61
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
createTasks(runId, params) {
|
|
65
|
-
return
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
66
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.createTasksUrl(runId), {
|
|
67
67
|
headers: { 'Content-Type': 'application/json' },
|
|
68
68
|
method: 'POST',
|
|
69
69
|
body: JSON.stringify(params),
|
|
70
70
|
});
|
|
71
|
-
return yield checkStatus(res).json();
|
|
71
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
startTask(runId, params) {
|
|
75
|
-
return
|
|
75
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
76
76
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.startTaskUrl(runId), {
|
|
77
77
|
headers: { 'Content-Type': 'application/json' },
|
|
78
78
|
method: 'PUT',
|
|
79
79
|
body: JSON.stringify(params),
|
|
80
80
|
});
|
|
81
|
-
return yield checkStatus(res).json();
|
|
81
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
runTasks(runId) {
|
|
85
|
-
return
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
86
|
const taskRunners = [];
|
|
87
87
|
for (let i = 0; i < this.options.parallel; i++) {
|
|
88
88
|
taskRunners.push(this.defaultTaskRunner(runId));
|
|
89
89
|
}
|
|
90
90
|
const taskResults = yield Promise.all(taskRunners);
|
|
91
|
-
return new RunTasksResult(taskResults.flatMap((x) => x));
|
|
91
|
+
return new run_tasks_result_1.RunTasksResult(taskResults.flatMap((x) => x));
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
completeTask(taskId, params) {
|
|
95
|
-
return
|
|
95
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
96
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.completeTaskUrl(taskId), {
|
|
97
97
|
headers: { 'Content-Type': 'application/json' },
|
|
98
98
|
method: 'PUT',
|
|
99
99
|
body: JSON.stringify(params),
|
|
100
100
|
});
|
|
101
|
-
return yield checkStatus(res).json();
|
|
101
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
failTask(taskId) {
|
|
105
|
-
return
|
|
105
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
106
106
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.failTaskUrl(taskId), {
|
|
107
107
|
headers: { 'Content-Type': 'application/json' },
|
|
108
108
|
method: 'PUT',
|
|
109
109
|
});
|
|
110
|
-
return yield checkStatus(res).json();
|
|
110
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
uploadRunFile(runId, path, params) {
|
|
114
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
return this.uploadFile(this.apiUrl.createFileRunUrl(runId), path, params);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
uploadTaskFile(taskId, path, params) {
|
|
119
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return this.uploadFile(this.apiUrl.createFileTaskUrl(taskId), path, params);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
uploadFile(url, path, params) {
|
|
124
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
// https://github.com/node-fetch/node-fetch/tree/2.x#post-with-form-data-detect-multipart
|
|
126
|
+
// https://github.com/form-data/form-data#readme
|
|
127
|
+
const formData = new FormData();
|
|
128
|
+
formData.append('file', (0, fs_1.createReadStream)(path));
|
|
129
|
+
if (params.type) {
|
|
130
|
+
formData.append('type', params.type);
|
|
131
|
+
}
|
|
132
|
+
if (params.description) {
|
|
133
|
+
formData.append('description', params.description);
|
|
134
|
+
}
|
|
135
|
+
const res = yield (0, node_fetch_1.default)(url, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
body: formData,
|
|
138
|
+
});
|
|
139
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
111
140
|
});
|
|
112
141
|
}
|
|
113
142
|
defaultTaskRunner(runId) {
|
|
114
|
-
return
|
|
143
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
115
144
|
const taskResults = [];
|
|
116
145
|
let _continue = true;
|
|
117
146
|
while (_continue) {
|
|
118
147
|
const response = yield this.startTask(runId, { runnerId: this.runnerId });
|
|
119
148
|
if (!response.continue) {
|
|
120
149
|
_continue = false;
|
|
121
|
-
}
|
|
122
|
-
if (!response.continue && !response.task) {
|
|
123
150
|
continue;
|
|
124
151
|
}
|
|
125
152
|
if (!response.task) {
|
|
153
|
+
// TODO: this should output only once per runner
|
|
126
154
|
console.log(`polling for a new task in: ${this.options.pollingDelayMs} ms`);
|
|
127
|
-
yield delay(this.options.pollingDelayMs);
|
|
155
|
+
yield (0, utils_1.delay)(this.options.pollingDelayMs);
|
|
128
156
|
continue;
|
|
129
157
|
}
|
|
130
158
|
const { run, task } = response;
|
|
@@ -132,6 +160,8 @@ class Client {
|
|
|
132
160
|
let hasCompleted = true;
|
|
133
161
|
let childProcess;
|
|
134
162
|
let error;
|
|
163
|
+
const taskLogFilename = (0, utils_1.getTaskLogFilename)(task.id);
|
|
164
|
+
const writeStream = (0, fs_1.createWriteStream)(taskLogFilename);
|
|
135
165
|
const dataHandler = (data) => {
|
|
136
166
|
this.options.dataCallback(task, data, () => (cached = true));
|
|
137
167
|
};
|
|
@@ -139,23 +169,34 @@ class Client {
|
|
|
139
169
|
this.options.errorCallback(task, data);
|
|
140
170
|
};
|
|
141
171
|
try {
|
|
142
|
-
childProcess = yield spawnAsync(task.command, task.arguments, Object.assign(Object.assign({}, task.options), this.options.spawnOptions),
|
|
172
|
+
childProcess = yield (0, utils_1.spawnAsync)(task.command, task.arguments, Object.assign(Object.assign({}, task.options), this.options.spawnOptions), {
|
|
173
|
+
writeStream,
|
|
174
|
+
dataCallback: dataHandler,
|
|
175
|
+
errorCallback: errorHandler,
|
|
176
|
+
});
|
|
143
177
|
}
|
|
144
178
|
catch (err) {
|
|
145
179
|
error = err;
|
|
146
180
|
hasCompleted = false;
|
|
147
181
|
if (run.failFast) {
|
|
182
|
+
// TODO: should abort all running tasks by current client
|
|
148
183
|
throw err;
|
|
149
184
|
}
|
|
150
185
|
}
|
|
151
186
|
finally {
|
|
152
187
|
taskResults.push({ run, task, childProcess, hasCompleted, error });
|
|
153
188
|
if (hasCompleted) {
|
|
154
|
-
yield this.completeTask(task.
|
|
189
|
+
yield this.completeTask(task.id, { cached });
|
|
155
190
|
}
|
|
156
191
|
else {
|
|
157
|
-
yield this.failTask(task.
|
|
192
|
+
yield this.failTask(task.id);
|
|
158
193
|
}
|
|
194
|
+
writeStream.close();
|
|
195
|
+
yield this.uploadTaskFile(task.id, taskLogFilename, {
|
|
196
|
+
type: 'log',
|
|
197
|
+
description: `Log for task ${task.id}`,
|
|
198
|
+
});
|
|
199
|
+
(0, fs_1.unlinkSync)(taskLogFilename);
|
|
159
200
|
}
|
|
160
201
|
}
|
|
161
202
|
return taskResults;
|
|
@@ -165,64 +206,12 @@ class Client {
|
|
|
165
206
|
exports.Client = Client;
|
|
166
207
|
Client.DefaultOptions = {
|
|
167
208
|
parallel: 1,
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
168
210
|
dataCallback: (task, data, cached) => { },
|
|
211
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
169
212
|
errorCallback: (task, data) => { },
|
|
170
213
|
pollingDelayMs: 1000,
|
|
171
214
|
retryDelayMs: 5000,
|
|
172
215
|
retryCount: 2,
|
|
173
216
|
};
|
|
174
|
-
function delay(ms) {
|
|
175
|
-
return new Promise((resolve) => {
|
|
176
|
-
setTimeout(resolve, ms);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function spawnAsync(command, args, options, dataCallback, errorCallback) {
|
|
180
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
181
|
-
return new Promise((resolve, reject) => {
|
|
182
|
-
const childProcess = (0, child_process_1.spawn)(command, args, options);
|
|
183
|
-
const readlineStdout = (0, readline_1.createInterface)({ input: childProcess.stdout });
|
|
184
|
-
const readlineStderr = (0, readline_1.createInterface)({ input: childProcess.stderr });
|
|
185
|
-
readlineStdout.on('line', dataCallback);
|
|
186
|
-
readlineStderr.on('line', errorCallback);
|
|
187
|
-
childProcess.on('close', (code) => {
|
|
188
|
-
if (code === 0) {
|
|
189
|
-
resolve(childProcess);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
reject(childProcess);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
childProcess.on('error', (err) => {
|
|
196
|
-
reject(childProcess); // TODO: try to return error message
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
exports.spawnAsync = spawnAsync;
|
|
202
|
-
class HTTPResponseError extends Error {
|
|
203
|
-
constructor(response) {
|
|
204
|
-
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
205
|
-
this.response = response;
|
|
206
|
-
this.response = response;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const checkStatus = (response) => {
|
|
210
|
-
if (response.ok) {
|
|
211
|
-
// response.status >= 200 && response.status < 300
|
|
212
|
-
return response;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
throw new HTTPResponseError(response);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
class RunTasksResult {
|
|
219
|
-
constructor(tasks) {
|
|
220
|
-
this.tasks = tasks;
|
|
221
|
-
this.completedTasks = tasks.filter((x) => x.hasCompleted);
|
|
222
|
-
this.failedTasks = tasks.filter((x) => !x.hasCompleted);
|
|
223
|
-
this.completed = this.failedTasks.length === 0;
|
|
224
|
-
this.failed = this.failedTasks.length > 0;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
exports.RunTasksResult = RunTasksResult;
|
|
228
217
|
//# sourceMappingURL=client.js.map
|
package/src/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client.ts"],"names":[],"mappings":";;;;AAeA,2CAA+B;AAC/B,sCAAsC;AACtC,mCAA6E;AAC7E,yDAAoD;AAGpD,2BAAqE;AAErE,MAAa,MAAM;IAYjB,YACmB,MAAc,EACd,QAAgB,EAChB,OAAsB;QAFtB,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,YAAO,GAAP,OAAO,CAAe;IACtC,CAAC;IAES,SAAS,CAAC,MAA2B;;YAChD,MAAM,GAAG,GAAG,MAAM,IAAA,oBAAK,EAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE;gBAClD,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,C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AE;wBAChB,yDAAyD;wBACzD,MAAM,GAAG,CAAC;qBACX;iBACF;wBAAS;oBACR,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;oBAEnE,IAAI,YAAY,EAAE;wBAChB,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;qBAC9C;yBAAM;wBACL,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;qBAC9B;oBAED,WAAW,CAAC,KAAK,EAAE,CAAC;oBACpB,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,eAAe,EAAE;wBAClD,IAAI,EAAE,KAAK;wBACX,WAAW,EAAE,gBAAgB,IAAI,CAAC,EAAE,EAAE;qBACvC,CAAC,CAAC;oBACH,IAAA,eAAU,EAAC,eAAe,CAAC,CAAC;iBAC7B;aACF;YAED,OAAO,WAAW,CAAC;QACrB,CAAC;KAAA;;AAhOH,wBAiOC;AAhOwB,qBAAc,GAAkB;IACrD,QAAQ,EAAE,CAAC;IACX,gEAAgE;IAChE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAE,CAAC;IACxC,gEAAgE;IAChE,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAE,CAAC;IACjC,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,CAAC;CACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TaskResult } from './task-result';
|
|
2
|
+
export declare class RunTasksResult {
|
|
3
|
+
readonly tasks: TaskResult[];
|
|
4
|
+
readonly completedTasks: TaskResult[];
|
|
5
|
+
readonly failedTasks: TaskResult[];
|
|
6
|
+
readonly completed: boolean;
|
|
7
|
+
readonly failed: boolean;
|
|
8
|
+
constructor(tasks: TaskResult[]);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunTasksResult = void 0;
|
|
4
|
+
class RunTasksResult {
|
|
5
|
+
constructor(tasks) {
|
|
6
|
+
this.tasks = tasks;
|
|
7
|
+
this.completedTasks = tasks.filter((x) => x.hasCompleted);
|
|
8
|
+
this.failedTasks = tasks.filter((x) => !x.hasCompleted);
|
|
9
|
+
this.completed = this.failedTasks.length === 0;
|
|
10
|
+
this.failed = this.failedTasks.length > 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.RunTasksResult = RunTasksResult;
|
|
14
|
+
//# sourceMappingURL=run-tasks-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-tasks-result.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/run-tasks-result.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IAOzB,YAA4B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;QAC7C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAExD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5C,CAAC;CACF;AAdD,wCAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-result.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/task-result.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process';
|
|
4
|
+
import { WriteStream } from 'fs';
|
|
5
|
+
export interface SpawnAsyncOptions {
|
|
6
|
+
writeStream?: WriteStream;
|
|
7
|
+
dataCallback?: (data: string) => void;
|
|
8
|
+
errorCallback?: (data: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio, logging?: SpawnAsyncOptions): Promise<ChildProcess>;
|
|
11
|
+
export declare function delay(ms: number): Promise<void>;
|
|
12
|
+
export declare function getTaskLogFilename(taskId: number): string;
|
|
13
|
+
export declare class HTTPResponseError extends Error {
|
|
14
|
+
readonly response: any;
|
|
15
|
+
constructor(response: any);
|
|
16
|
+
}
|
|
17
|
+
export declare const checkStatus: (response: any) => any;
|
package/src/lib/utils.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkStatus = exports.HTTPResponseError = exports.getTaskLogFilename = exports.delay = exports.spawnAsync = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const readline_1 = require("readline");
|
|
7
|
+
const os_1 = require("os");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
function spawnAsync(command, args, options, logging) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const childProcess = (0, child_process_1.spawn)(command, args, options);
|
|
13
|
+
if (logging.writeStream) {
|
|
14
|
+
childProcess.stdout.pipe(logging.writeStream);
|
|
15
|
+
childProcess.stderr.pipe(logging.writeStream);
|
|
16
|
+
}
|
|
17
|
+
if (logging.dataCallback) {
|
|
18
|
+
const readlineStdout = (0, readline_1.createInterface)({ input: childProcess.stdout });
|
|
19
|
+
readlineStdout.on('line', logging.dataCallback);
|
|
20
|
+
}
|
|
21
|
+
if (logging.errorCallback) {
|
|
22
|
+
const readlineStderr = (0, readline_1.createInterface)({ input: childProcess.stderr });
|
|
23
|
+
readlineStderr.on('line', logging.errorCallback);
|
|
24
|
+
}
|
|
25
|
+
childProcess.on('close', (code) => {
|
|
26
|
+
if (code === 0) {
|
|
27
|
+
resolve(childProcess);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
reject(childProcess);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
childProcess.on('error', (err) => {
|
|
34
|
+
reject(childProcess); // TODO: try to return error message
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.spawnAsync = spawnAsync;
|
|
40
|
+
function delay(ms) {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
setTimeout(resolve, ms);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.delay = delay;
|
|
46
|
+
function getTaskLogFilename(taskId) {
|
|
47
|
+
return (0, path_1.join)((0, os_1.tmpdir)(), `task-${taskId}.log`);
|
|
48
|
+
}
|
|
49
|
+
exports.getTaskLogFilename = getTaskLogFilename;
|
|
50
|
+
class HTTPResponseError extends Error {
|
|
51
|
+
constructor(response) {
|
|
52
|
+
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
53
|
+
this.response = response;
|
|
54
|
+
this.response = response;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.HTTPResponseError = HTTPResponseError;
|
|
58
|
+
const checkStatus = (response) => {
|
|
59
|
+
if (response.ok) {
|
|
60
|
+
// response.status >= 200 && response.status < 300
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new HTTPResponseError(response);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.checkStatus = checkStatus;
|
|
68
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/utils.ts"],"names":[],"mappings":";;;;AAAA,iDAA8E;AAC9E,uCAA2C;AAE3C,2BAA4B;AAC5B,+BAA4B;AAQ5B,SAAsB,UAAU,CAC9B,OAAe,EACf,IAA4B,EAC5B,OAAkC,EAClC,OAA2B;;QAE3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,YAAY,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAEnD,IAAI,OAAO,CAAC,WAAW,EAAE;gBACvB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gBAC9C,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;aAC/C;YAED,IAAI,OAAO,CAAC,YAAY,EAAE;gBACxB,MAAM,cAAc,GAAG,IAAA,0BAAe,EAAC,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;gBACvE,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;aACjD;YAED,IAAI,OAAO,CAAC,aAAa,EAAE;gBACzB,MAAM,cAAc,GAAG,IAAA,0BAAe,EAAC,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;gBACvE,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;aAClD;YAED,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChC,IAAI,IAAI,KAAK,CAAC,EAAE;oBACd,OAAO,CAAC,YAAY,CAAC,CAAC;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