@speedkit/cli 2.22.0 → 2.23.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/CHANGELOG.md +11 -0
- package/README.md +12 -34
- package/dist/commands/prewarm.d.ts +5 -26
- package/dist/commands/prewarm.js +23 -103
- package/dist/models/cli-parameters.d.ts +4 -1
- package/dist/models/cli-parameters.js +3 -0
- package/dist/services/cli/cli-service-factory.d.ts +3 -0
- package/dist/services/cli/cli-service-factory.js +9 -1
- package/dist/services/cli/cli-service-model.d.ts +19 -11
- package/dist/services/cli/cli-service-model.js +8 -1
- package/dist/services/cli/cli-service.d.ts +20 -13
- package/dist/services/cli/cli-service.js +102 -66
- package/dist/services/config-api/client.d.ts +7 -9
- package/dist/services/config-api/client.js +26 -30
- package/dist/services/prewarm/assets/asset-api-client.d.ts +13 -0
- package/dist/services/prewarm/assets/asset-api-client.js +58 -0
- package/dist/services/prewarm/assets/asset-item.d.ts +14 -0
- package/dist/services/prewarm/assets/asset-item.js +29 -0
- package/dist/services/prewarm/assets/asset-list.d.ts +14 -0
- package/dist/services/prewarm/assets/asset-list.js +43 -0
- package/dist/services/prewarm/csv-reader.d.ts +5 -0
- package/dist/services/prewarm/csv-reader.js +34 -0
- package/dist/services/prewarm/error/invalid-origin-error.d.ts +2 -0
- package/dist/services/prewarm/error/invalid-origin-error.js +6 -0
- package/dist/services/prewarm/error/read-csv-error.d.ts +8 -0
- package/dist/services/prewarm/error/read-csv-error.js +18 -0
- package/dist/services/prewarm/index.d.ts +3 -0
- package/dist/services/prewarm/index.js +6 -0
- package/dist/services/prewarm/pre-warm-factory.d.ts +8 -0
- package/dist/services/prewarm/pre-warm-factory.js +40 -0
- package/dist/services/prewarm/pre-warm-model.d.ts +38 -0
- package/dist/services/prewarm/pre-warm-model.js +38 -0
- package/dist/services/prewarm/pre-warm-service.d.ts +21 -0
- package/dist/services/prewarm/pre-warm-service.js +154 -0
- package/oclif.manifest.json +24 -63
- package/package.json +1 -1
- package/dist/commands/pop-prewarm.d.ts +0 -17
- package/dist/commands/pop-prewarm.js +0 -90
- package/dist/services/cli/hooks.d.ts +0 -11
- package/dist/services/cli/hooks.js +0 -33
|
@@ -2,68 +2,79 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CliService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk")); // interactive prompts
|
|
7
7
|
const core_1 = require("@oclif/core");
|
|
8
8
|
const cli_service_model_1 = require("./cli-service-model");
|
|
9
9
|
class CliService {
|
|
10
|
-
|
|
10
|
+
quiet;
|
|
11
11
|
style = chalk_1.default;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
buffer = [];
|
|
13
|
+
progressBar;
|
|
14
|
+
constructor(quiet = false) {
|
|
15
|
+
this.quiet = quiet;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
code(code, buffered = false) {
|
|
18
|
+
code = ` ${code} `;
|
|
17
19
|
if (buffered) {
|
|
18
|
-
this.buffer.push(this.style.white(
|
|
20
|
+
this.buffer.push(this.style.bgBlack.white(code));
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
|
-
core_1.ux.
|
|
23
|
+
core_1.ux.log(this.style.bgBlack.white(code));
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
codeStyle(code) {
|
|
26
|
+
const padding = " ";
|
|
27
|
+
return this.style.bgGray.rgb(230, 126, 0)(`${padding}${code}${padding}`);
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
comment(message, buffered = false) {
|
|
27
30
|
if (buffered) {
|
|
28
|
-
this.buffer.push(this.style.
|
|
31
|
+
this.buffer.push(this.style.grey.italic(message));
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
|
-
this.write(this.style.
|
|
34
|
+
this.write(this.style.grey.italic(message));
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
return;
|
|
36
|
+
async confirm(message, defaultAnswer = true) {
|
|
37
|
+
if (this.quiet) {
|
|
38
|
+
return defaultAnswer;
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
return (0, prompts_1.confirm)({
|
|
41
|
+
default: defaultAnswer,
|
|
42
|
+
message: this.getFormattedMessage(message),
|
|
43
|
+
});
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
this.buffer.push(this.style.red(message));
|
|
45
|
+
endAction(status) {
|
|
46
|
+
if (this.quiet) {
|
|
43
47
|
return;
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
switch (status) {
|
|
50
|
+
case cli_service_model_1.CliActionStatus.COMPLETED: {
|
|
51
|
+
core_1.ux.action.stop(this.style.green(cli_service_model_1.CliActionStatus.COMPLETED));
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case cli_service_model_1.CliActionStatus.FAILED: {
|
|
55
|
+
core_1.ux.action.stop(this.style.red(cli_service_model_1.CliActionStatus.FAILED));
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case cli_service_model_1.CliActionStatus.SKIPPED: {
|
|
59
|
+
core_1.ux.action.stop(this.style.yellow(cli_service_model_1.CliActionStatus.SKIPPED));
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
core_1.ux.action.stop();
|
|
64
|
+
}
|
|
51
65
|
}
|
|
52
|
-
this.write(this.style.grey.italic(message));
|
|
53
66
|
}
|
|
54
|
-
|
|
55
|
-
code
|
|
56
|
-
if (buffered) {
|
|
57
|
-
this.buffer.push(this.style.bgBlack.white(code));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
core_1.ux.log(this.style.bgBlack.white(code));
|
|
67
|
+
exit(code = 0) {
|
|
68
|
+
core_1.ux.exit(code);
|
|
61
69
|
}
|
|
62
70
|
async prompt(message, options) {
|
|
63
|
-
|
|
71
|
+
if (this.quiet) {
|
|
72
|
+
return options?.defaultAnswer || "";
|
|
73
|
+
}
|
|
74
|
+
const { defaultAnswer, validator } = options;
|
|
64
75
|
return (0, prompts_1.input)({
|
|
65
|
-
message: this.getFormattedMessage(message),
|
|
66
76
|
default: defaultAnswer,
|
|
77
|
+
message: this.getFormattedMessage(message),
|
|
67
78
|
validate: (input) => {
|
|
68
79
|
if (typeof validator !== "function")
|
|
69
80
|
return true;
|
|
@@ -75,50 +86,75 @@ class CliService {
|
|
|
75
86
|
},
|
|
76
87
|
});
|
|
77
88
|
}
|
|
78
|
-
async confirm(message, defaultAnswer = true) {
|
|
79
|
-
return (0, prompts_1.confirm)({
|
|
80
|
-
message: this.getFormattedMessage(message),
|
|
81
|
-
default: defaultAnswer,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
89
|
async select(message, choices) {
|
|
85
90
|
return (0, prompts_1.select)({
|
|
86
|
-
message: this.getFormattedMessage(message),
|
|
87
91
|
choices,
|
|
92
|
+
message: this.getFormattedMessage(message),
|
|
88
93
|
});
|
|
89
94
|
}
|
|
95
|
+
spacer() {
|
|
96
|
+
core_1.ux.info("");
|
|
97
|
+
}
|
|
90
98
|
startAction(message) {
|
|
99
|
+
if (this.quiet) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
91
102
|
core_1.ux.action.start(message);
|
|
92
103
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
core_1.ux.action.stop(this.style.green(cli_service_model_1.CliActionStatus.COMPLETED));
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case cli_service_model_1.CliActionStatus.FAILED: {
|
|
100
|
-
core_1.ux.action.stop(this.style.red(cli_service_model_1.CliActionStatus.FAILED));
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case cli_service_model_1.CliActionStatus.SKIPPED: {
|
|
104
|
-
core_1.ux.action.stop(this.style.yellow(cli_service_model_1.CliActionStatus.SKIPPED));
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
default: {
|
|
108
|
-
core_1.ux.action.stop();
|
|
109
|
-
}
|
|
104
|
+
startProgress(total, start = 0, payload, config) {
|
|
105
|
+
if (this.quiet) {
|
|
106
|
+
return;
|
|
110
107
|
}
|
|
108
|
+
this.progressBar = core_1.ux.progress(config);
|
|
109
|
+
this.progressBar.start(total, start, payload);
|
|
110
|
+
}
|
|
111
|
+
stopProgress() {
|
|
112
|
+
if (this.quiet) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.progressBar.stop();
|
|
116
|
+
}
|
|
117
|
+
table(data, columns, options) {
|
|
118
|
+
core_1.ux.table(data, columns, options);
|
|
119
|
+
}
|
|
120
|
+
updateProgress(current, payload) {
|
|
121
|
+
if (this.quiet) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.progressBar.update(current, payload);
|
|
125
|
+
}
|
|
126
|
+
write(message, buffered = false) {
|
|
127
|
+
if (buffered) {
|
|
128
|
+
this.buffer.push(this.style.white(message));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
core_1.ux.info(message);
|
|
111
132
|
}
|
|
112
133
|
writeBuffer() {
|
|
113
134
|
core_1.ux.log(this.buffer.join(`\n`));
|
|
114
135
|
core_1.ux.log();
|
|
115
136
|
this.buffer = [];
|
|
116
137
|
}
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
writeError(message, buffered = false) {
|
|
139
|
+
if (buffered) {
|
|
140
|
+
this.buffer.push(this.style.red(message));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.write(this.style.red(message));
|
|
119
144
|
}
|
|
120
|
-
|
|
121
|
-
|
|
145
|
+
writeSuccess(message, buffered = false) {
|
|
146
|
+
if (buffered) {
|
|
147
|
+
this.buffer.push(this.style.green(message));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.write(this.style.green(message));
|
|
151
|
+
}
|
|
152
|
+
writeWarning(message, buffered = false) {
|
|
153
|
+
if (buffered) {
|
|
154
|
+
this.buffer.push(this.style.yellow(message));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.write(this.style.yellow(message));
|
|
122
158
|
}
|
|
123
159
|
getFormattedMessage(questionText) {
|
|
124
160
|
return `${this.style.bold(questionText)}`;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EntityManager } from "baqend";
|
|
2
2
|
import EntityManagerFactory from "./factory/entity-manager-factory";
|
|
3
|
+
import RequestExtensionInterface from "./interface/request-extension-interface";
|
|
3
4
|
export default class Client {
|
|
4
|
-
private readonly entityManagerFactory;
|
|
5
|
-
private readonly app;
|
|
6
5
|
private readonly agent;
|
|
6
|
+
private readonly app;
|
|
7
|
+
private readonly entityManagerFactory;
|
|
7
8
|
constructor(app: string, entityManagerFactory: EntityManagerFactory);
|
|
8
|
-
|
|
9
|
+
createRequest(requestExtension: RequestExtensionInterface): Promise<RequestInit>;
|
|
10
|
+
getEntityManager(): Promise<EntityManager>;
|
|
9
11
|
getModule(moduleName: string): Promise<string>;
|
|
12
|
+
send(url: string, requestExtension?: RequestExtensionInterface): Promise<any>;
|
|
10
13
|
setModule(moduleName: string, moduleCode: string): Promise<string>;
|
|
11
|
-
/**
|
|
12
|
-
* @param requestExtension
|
|
13
|
-
*/
|
|
14
|
-
createRequest(requestExtension: RequestExtensionInterface): Promise<NonNullable<unknown>>;
|
|
15
|
-
private getEntityManager;
|
|
16
14
|
}
|
|
@@ -1,57 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const node_https_1 = require("node:https");
|
|
5
|
-
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
6
4
|
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
|
|
5
|
+
const node_https_1 = require("node:https");
|
|
7
6
|
const race_1 = require("../../helpers/race");
|
|
8
7
|
const REQUEST_TIMEOUT = 10_000;
|
|
9
8
|
const CONTENT_TYPE = "application/json;charset=UTF-8";
|
|
10
9
|
class Client {
|
|
11
|
-
entityManagerFactory;
|
|
12
|
-
app;
|
|
13
10
|
agent;
|
|
11
|
+
app;
|
|
12
|
+
entityManagerFactory;
|
|
14
13
|
constructor(app, entityManagerFactory) {
|
|
15
14
|
this.app = app;
|
|
16
15
|
this.entityManagerFactory = entityManagerFactory;
|
|
17
|
-
this.agent = new node_https_1.Agent({
|
|
18
|
-
}
|
|
19
|
-
async send(url, requestExtension = {}) {
|
|
20
|
-
const response = await (0, node_fetch_1.default)(url, await this.createRequest(requestExtension));
|
|
21
|
-
if (response.status !== 200) {
|
|
22
|
-
const json = await response.json();
|
|
23
|
-
throw new Error(json.message);
|
|
24
|
-
}
|
|
25
|
-
return await response.json();
|
|
26
|
-
}
|
|
27
|
-
async getModule(moduleName) {
|
|
28
|
-
const entityManager = await this.getEntityManager();
|
|
29
|
-
return await entityManager.code.loadCode(moduleName, "module");
|
|
30
|
-
}
|
|
31
|
-
async setModule(moduleName, moduleCode) {
|
|
32
|
-
const entityManager = await this.getEntityManager();
|
|
33
|
-
return await entityManager.code.saveCode(moduleName, "module", moduleCode);
|
|
16
|
+
this.agent = new node_https_1.Agent({ keepAlive: true, rejectUnauthorized: false });
|
|
34
17
|
}
|
|
35
|
-
/**
|
|
36
|
-
* @param requestExtension
|
|
37
|
-
*/
|
|
38
18
|
async createRequest(requestExtension) {
|
|
39
19
|
const entityManager = await this.getEntityManager();
|
|
40
20
|
const baseRequest = {
|
|
41
|
-
method: "GET",
|
|
42
21
|
headers: {
|
|
22
|
+
"Content-Type": CONTENT_TYPE,
|
|
43
23
|
Host: `${this.app}.app.baqend.com`,
|
|
44
24
|
authorization: `BAT ${entityManager.token}`,
|
|
45
|
-
"Content-Type": CONTENT_TYPE,
|
|
46
25
|
},
|
|
26
|
+
method: "GET",
|
|
47
27
|
timeout: REQUEST_TIMEOUT,
|
|
48
28
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
29
|
+
// @ts-expect-error agent seems not to be part of type RequestInit
|
|
30
|
+
return { ...(0, deepmerge_1.default)(baseRequest, requestExtension), agent: this.agent };
|
|
52
31
|
}
|
|
53
32
|
async getEntityManager() {
|
|
54
|
-
return
|
|
33
|
+
return (0, race_1.race)(this.entityManagerFactory.getEntityManager(this.app));
|
|
34
|
+
}
|
|
35
|
+
async getModule(moduleName) {
|
|
36
|
+
const entityManager = await this.getEntityManager();
|
|
37
|
+
return entityManager.code.loadCode(moduleName, "module");
|
|
38
|
+
}
|
|
39
|
+
async send(url, requestExtension = {}) {
|
|
40
|
+
const requestInit = await this.createRequest(requestExtension);
|
|
41
|
+
const response = await fetch(url, requestInit);
|
|
42
|
+
if (response.status !== 200) {
|
|
43
|
+
const message = await response.json();
|
|
44
|
+
throw new Error(message);
|
|
45
|
+
}
|
|
46
|
+
return response.json();
|
|
47
|
+
}
|
|
48
|
+
async setModule(moduleName, moduleCode) {
|
|
49
|
+
const entityManager = await this.getEntityManager();
|
|
50
|
+
return entityManager.code.saveCode(moduleName, "module", moduleCode);
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
exports.default = Client;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class AssetApiClient {
|
|
2
|
+
private authenticationToken;
|
|
3
|
+
private app;
|
|
4
|
+
private sortParameters;
|
|
5
|
+
private agent;
|
|
6
|
+
private rateLimit;
|
|
7
|
+
constructor(authenticationToken: string, app: string, sortParameters: boolean);
|
|
8
|
+
fetchURL(url: string, variation: string): Promise<Response>;
|
|
9
|
+
getRateLimit(): number;
|
|
10
|
+
reduceMaxRequestsPerSecond(): void;
|
|
11
|
+
private isValidUrl;
|
|
12
|
+
private setRateLimit;
|
|
13
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetApiClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_https_1 = require("node:https");
|
|
6
|
+
const node_url_1 = require("node:url");
|
|
7
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
8
|
+
const __1 = require("../");
|
|
9
|
+
const normalize_1 = require("../../../helpers/normalize");
|
|
10
|
+
const invalid_origin_error_1 = require("../error/invalid-origin-error");
|
|
11
|
+
class AssetApiClient {
|
|
12
|
+
authenticationToken;
|
|
13
|
+
app;
|
|
14
|
+
sortParameters;
|
|
15
|
+
agent = new node_https_1.Agent({
|
|
16
|
+
keepAlive: true,
|
|
17
|
+
rejectUnauthorized: false,
|
|
18
|
+
});
|
|
19
|
+
rateLimit = __1.DEFAULT_MAX_REQUESTS_PER_SECOND;
|
|
20
|
+
constructor(authenticationToken, app, sortParameters) {
|
|
21
|
+
this.authenticationToken = authenticationToken;
|
|
22
|
+
this.app = app;
|
|
23
|
+
this.sortParameters = sortParameters;
|
|
24
|
+
}
|
|
25
|
+
async fetchURL(url, variation) {
|
|
26
|
+
this.isValidUrl(url);
|
|
27
|
+
const assetUrl = new node_url_1.URL((0, normalize_1.normalize)(url, this.sortParameters));
|
|
28
|
+
if (variation !== "DEFAULT" && variation !== "DESKTOP") {
|
|
29
|
+
assetUrl.searchParams.set("bqvariation", variation.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
assetUrl.searchParams.set("bqpass", "1");
|
|
32
|
+
return (0, node_fetch_1.default)(`https://${this.app}.app.baqend.com/v1/asset/${assetUrl.toString()}`, {
|
|
33
|
+
agent: this.agent,
|
|
34
|
+
headers: {
|
|
35
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
36
|
+
Origin: assetUrl.origin,
|
|
37
|
+
authorization: `BAT ${this.authenticationToken}`,
|
|
38
|
+
},
|
|
39
|
+
method: "HEAD",
|
|
40
|
+
timeout: __1.FETCH_TIMEOUT,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getRateLimit() {
|
|
44
|
+
return this.rateLimit;
|
|
45
|
+
}
|
|
46
|
+
reduceMaxRequestsPerSecond() {
|
|
47
|
+
this.setRateLimit(this.rateLimit * __1.RATE_LIMIT_MULTIPLICATOR);
|
|
48
|
+
}
|
|
49
|
+
isValidUrl(url) {
|
|
50
|
+
if (!node_url_1.URL.canParse(url)) {
|
|
51
|
+
throw new invalid_origin_error_1.InvalidOriginError(`Invalid url`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
setRateLimit(limit) {
|
|
55
|
+
this.rateLimit = limit > 1 ? Math.floor(limit) : 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AssetApiClient = AssetApiClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssetItemInterface, ItemStatus } from "../";
|
|
2
|
+
import { AssetApiClient } from "./asset-api-client";
|
|
3
|
+
export declare class AssetItem implements AssetItemInterface {
|
|
4
|
+
readonly url: string;
|
|
5
|
+
readonly variation: string;
|
|
6
|
+
readonly callback: (client: AssetApiClient, entry: AssetItemInterface) => Promise<void>;
|
|
7
|
+
error?: Error;
|
|
8
|
+
status: ItemStatus;
|
|
9
|
+
constructor(url: string, variation: string, callback: (client: AssetApiClient, entry: AssetItemInterface) => Promise<void>);
|
|
10
|
+
done(): void;
|
|
11
|
+
failed(): void;
|
|
12
|
+
retry(): void;
|
|
13
|
+
setError(error: Error): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetItem = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
class AssetItem {
|
|
6
|
+
url;
|
|
7
|
+
variation;
|
|
8
|
+
callback;
|
|
9
|
+
error = null;
|
|
10
|
+
status = __1.ItemStatus.NEW;
|
|
11
|
+
constructor(url, variation, callback) {
|
|
12
|
+
this.url = url;
|
|
13
|
+
this.variation = variation;
|
|
14
|
+
this.callback = callback;
|
|
15
|
+
}
|
|
16
|
+
done() {
|
|
17
|
+
this.status = __1.ItemStatus.DONE;
|
|
18
|
+
}
|
|
19
|
+
failed() {
|
|
20
|
+
this.status = __1.ItemStatus.ERROR;
|
|
21
|
+
}
|
|
22
|
+
retry() {
|
|
23
|
+
this.status = __1.ItemStatus.RETRY;
|
|
24
|
+
}
|
|
25
|
+
setError(error) {
|
|
26
|
+
this.error = error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AssetItem = AssetItem;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssetItemInterface, ItemStatus } from "../";
|
|
2
|
+
export declare class AssetList {
|
|
3
|
+
private variations;
|
|
4
|
+
private elements;
|
|
5
|
+
constructor(variations: string[]);
|
|
6
|
+
addItem(item: AssetItemInterface): void;
|
|
7
|
+
getBatch(offset: number, limit: number): AssetItemInterface[];
|
|
8
|
+
getByStatus(status: ItemStatus): AssetItemInterface[];
|
|
9
|
+
getErrorCount(): number;
|
|
10
|
+
getErrors(): Error[];
|
|
11
|
+
getLength(): number;
|
|
12
|
+
getRetryCount(): number;
|
|
13
|
+
getSuccessCount(): number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetList = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
class AssetList {
|
|
6
|
+
variations;
|
|
7
|
+
elements = [];
|
|
8
|
+
constructor(variations) {
|
|
9
|
+
this.variations = variations;
|
|
10
|
+
}
|
|
11
|
+
addItem(item) {
|
|
12
|
+
this.elements.push(item);
|
|
13
|
+
}
|
|
14
|
+
getBatch(offset, limit) {
|
|
15
|
+
let batchLimit = offset + limit;
|
|
16
|
+
if (offset >= this.elements.length) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
if (batchLimit >= this.elements.length) {
|
|
20
|
+
batchLimit = this.elements.length;
|
|
21
|
+
}
|
|
22
|
+
return this.elements.slice(offset, batchLimit);
|
|
23
|
+
}
|
|
24
|
+
getByStatus(status) {
|
|
25
|
+
return this.elements.filter((element) => element.status === status);
|
|
26
|
+
}
|
|
27
|
+
getErrorCount() {
|
|
28
|
+
return this.getByStatus(__1.ItemStatus.ERROR).length;
|
|
29
|
+
}
|
|
30
|
+
getErrors() {
|
|
31
|
+
return this.getByStatus(__1.ItemStatus.ERROR).map((element) => element.error);
|
|
32
|
+
}
|
|
33
|
+
getLength() {
|
|
34
|
+
return this.elements.length;
|
|
35
|
+
}
|
|
36
|
+
getRetryCount() {
|
|
37
|
+
return this.getByStatus(__1.ItemStatus.RETRY).length;
|
|
38
|
+
}
|
|
39
|
+
getSuccessCount() {
|
|
40
|
+
return this.getByStatus(__1.ItemStatus.DONE).length;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.AssetList = AssetList;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CsvReader = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const read_csv_error_1 = require("./error/read-csv-error");
|
|
8
|
+
const ENCODING = "utf8";
|
|
9
|
+
const LINE_BREAK = /\r?\n/;
|
|
10
|
+
class CsvReader {
|
|
11
|
+
readPath(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
const entries = this.getEntries(filePath);
|
|
14
|
+
return this.cleanUpEntries(entries);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
throw new read_csv_error_1.ReadCsvError(error.message, [
|
|
18
|
+
"check arguments for correct filePath",
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
cleanUpEntries(entries) {
|
|
23
|
+
return entries
|
|
24
|
+
.map((entry) => {
|
|
25
|
+
return /^"[^"]+"/.test(entry) ? entry.slice(1, -1) : entry;
|
|
26
|
+
})
|
|
27
|
+
.filter(Boolean);
|
|
28
|
+
}
|
|
29
|
+
getEntries(filePath) {
|
|
30
|
+
const fileContent = node_fs_1.default.readFileSync(node_path_1.default.resolve(filePath), ENCODING);
|
|
31
|
+
return fileContent.split(LINE_BREAK);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.CsvReader = CsvReader;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PrettyPrintableError } from "@oclif/core/lib/errors";
|
|
2
|
+
export declare class ReadCsvError extends Error implements PrettyPrintableError {
|
|
3
|
+
readonly message: string;
|
|
4
|
+
readonly suggestions?: string[];
|
|
5
|
+
readonly ref?: string;
|
|
6
|
+
readonly code = "SK_CLI_CSV_READ";
|
|
7
|
+
constructor(message: string, suggestions?: string[], ref?: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadCsvError = void 0;
|
|
4
|
+
class ReadCsvError extends Error {
|
|
5
|
+
message;
|
|
6
|
+
suggestions;
|
|
7
|
+
ref;
|
|
8
|
+
code = "SK_CLI_CSV_READ";
|
|
9
|
+
constructor(message, suggestions,
|
|
10
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
11
|
+
ref) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.message = message;
|
|
14
|
+
this.suggestions = suggestions;
|
|
15
|
+
this.ref = ref;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ReadCsvError = ReadCsvError;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./pre-warm-service"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./pre-warm-factory"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./pre-warm-model"), exports);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreWarmFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const cli_1 = require("../cli");
|
|
6
|
+
const config_api_context_1 = tslib_1.__importDefault(require("../config-api/context/config-api-context"));
|
|
7
|
+
const config_api_service_factory_1 = tslib_1.__importDefault(require("../config-api/factory/config-api-service-factory"));
|
|
8
|
+
const _1 = require("./");
|
|
9
|
+
const asset_api_client_1 = require("./assets/asset-api-client");
|
|
10
|
+
const csv_reader_1 = require("./csv-reader");
|
|
11
|
+
class PreWarmFactory {
|
|
12
|
+
context;
|
|
13
|
+
constructor(context) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
}
|
|
16
|
+
async getService() {
|
|
17
|
+
const cli = new cli_1.CliServiceFactory(new cli_1.CliContext(this.context.quiet)).getService();
|
|
18
|
+
const configApi = new config_api_service_factory_1.default(new config_api_context_1.default(this.context.app)).getService();
|
|
19
|
+
const entityManager = await configApi.client.getEntityManager();
|
|
20
|
+
const csvReader = new csv_reader_1.CsvReader();
|
|
21
|
+
const assetApiClient = new asset_api_client_1.AssetApiClient(entityManager.token, this.context.app, this.context.keepParameterSorting);
|
|
22
|
+
const urls = this.getUrls(csvReader);
|
|
23
|
+
const variations = this.getVariations(csvReader);
|
|
24
|
+
return new _1.PreWarmService(assetApiClient, cli, urls, variations);
|
|
25
|
+
}
|
|
26
|
+
getUrls(csvReader) {
|
|
27
|
+
return csvReader.readPath(this.context.path);
|
|
28
|
+
}
|
|
29
|
+
getVariations(csvReader) {
|
|
30
|
+
let variations = _1.DEFAULT_VARIATION;
|
|
31
|
+
if (this.context.variation) {
|
|
32
|
+
variations = this.context.variation.split(_1.VARIATION_SEPARATOR);
|
|
33
|
+
}
|
|
34
|
+
if (this.context.variationPath) {
|
|
35
|
+
variations = csvReader.readPath(this.context.variationPath);
|
|
36
|
+
}
|
|
37
|
+
return variations;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.PreWarmFactory = PreWarmFactory;
|