bdy 1.25.22-dev → 1.25.22-master
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/distTs/package.json +1 -1
- package/distTs/src/command/sandbox/fetch/add.js +62 -0
- package/distTs/src/command/sandbox/fetch/delete.js +33 -0
- package/distTs/src/command/sandbox/fetch/get.js +51 -0
- package/distTs/src/command/sandbox/fetch/list.js +50 -0
- package/distTs/src/command/sandbox/fetch/refetch.js +27 -0
- package/distTs/src/command/sandbox/fetch.js +28 -0
- package/distTs/src/command/sandbox/fetchSource.js +90 -0
- package/package.json +1 -1
package/distTs/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cliError_1 = __importDefault(require("../../../cliError"));
|
|
7
|
+
const utils_1 = require("../../../utils");
|
|
8
|
+
const texts_1 = require("../../../texts");
|
|
9
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
10
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
11
|
+
const sandbox_1 = require("../../../types/sandbox");
|
|
12
|
+
const fetchSource_1 = require("../fetchSource");
|
|
13
|
+
const commandSandboxFetchAdd = (0, utils_1.newCommand)('add', texts_1.DESC_COMMAND_SANDBOX_FETCH_ADD, {
|
|
14
|
+
requiredScopes: [utils_1.REST_API_SCOPE.SANDBOX_WRITE],
|
|
15
|
+
examples: texts_1.EXAMPLE_SANDBOX_FETCH_ADD,
|
|
16
|
+
});
|
|
17
|
+
commandSandboxFetchAdd.alias('create');
|
|
18
|
+
(0, utils_1.sandboxScopeOptions)(commandSandboxFetchAdd);
|
|
19
|
+
commandSandboxFetchAdd.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
20
|
+
commandSandboxFetchAdd.option('--ref <ref>', texts_1.OPTION_SANDBOX_FETCH_REF);
|
|
21
|
+
commandSandboxFetchAdd.option('--repository <url>', texts_1.OPTION_SANDBOX_FETCH_REPOSITORY);
|
|
22
|
+
commandSandboxFetchAdd.option('--path <directory>', texts_1.OPTION_SANDBOX_FETCH_PATH);
|
|
23
|
+
commandSandboxFetchAdd.option('--artifact <name:version>', texts_1.OPTION_SANDBOX_FETCH_ARTIFACT);
|
|
24
|
+
commandSandboxFetchAdd.option('--source-path <path>', texts_1.OPTION_SANDBOX_FETCH_SOURCE_PATH);
|
|
25
|
+
commandSandboxFetchAdd.option('--build <command>', texts_1.OPTION_SANDBOX_FETCH_BUILD);
|
|
26
|
+
commandSandboxFetchAdd.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
27
|
+
commandSandboxFetchAdd.action(async (identifier, options) => {
|
|
28
|
+
if (options.artifact && (options.repository || options.ref)) {
|
|
29
|
+
output_1.default.exitError(new cliError_1.default('usage_error', texts_1.ERR_SANDBOX_FETCH_MIX_ARTIFACT));
|
|
30
|
+
}
|
|
31
|
+
if (options.sourcePath && !options.artifact) {
|
|
32
|
+
output_1.default.exitError(new cliError_1.default('usage_error', texts_1.ERR_SANDBOX_FETCH_SOURCE_PATH));
|
|
33
|
+
}
|
|
34
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
35
|
+
const client = input_1.default.restApiTokenClient();
|
|
36
|
+
const sandboxId = await input_1.default.sandboxId(client, workspace, options, identifier);
|
|
37
|
+
let type = sandbox_1.SANDBOX_FETCH.PROJECT_REPO;
|
|
38
|
+
if (options.artifact)
|
|
39
|
+
type = sandbox_1.SANDBOX_FETCH.ARTIFACT;
|
|
40
|
+
else if (options.repository)
|
|
41
|
+
type = sandbox_1.SANDBOX_FETCH.PUBLIC_REPO;
|
|
42
|
+
const body = { type };
|
|
43
|
+
if (options.repository)
|
|
44
|
+
body.repository = options.repository;
|
|
45
|
+
if (options.ref)
|
|
46
|
+
body.ref = options.ref;
|
|
47
|
+
if (options.path)
|
|
48
|
+
body.path = options.path;
|
|
49
|
+
if (options.artifact)
|
|
50
|
+
body.artifact = options.artifact;
|
|
51
|
+
if (options.sourcePath)
|
|
52
|
+
body.source_path = options.sourcePath;
|
|
53
|
+
if (options.build)
|
|
54
|
+
body.build_command = options.build;
|
|
55
|
+
const fetch = await client.addSandboxFetch(workspace, sandboxId, body);
|
|
56
|
+
// a fetch added to a stopped sandbox stays STALE until it is refetched
|
|
57
|
+
const path = (0, fetchSource_1.sandboxFetchPath)(fetch);
|
|
58
|
+
output_1.default.exitResult(options.format === 'json', fetch, fetch.status === sandbox_1.SANDBOX_FETCH_STATUS.STALE
|
|
59
|
+
? (0, texts_1.TXT_SANDBOX_FETCH_ADDED_STALE)(identifier, path)
|
|
60
|
+
: (0, texts_1.TXT_SANDBOX_FETCH_ADDED)(path));
|
|
61
|
+
});
|
|
62
|
+
exports.default = commandSandboxFetchAdd;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const fetchSource_1 = require("../fetchSource");
|
|
11
|
+
const commandSandboxFetchDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_SANDBOX_FETCH_DELETE, {
|
|
12
|
+
requiredScopes: [utils_1.REST_API_SCOPE.SANDBOX_WRITE],
|
|
13
|
+
examples: texts_1.EXAMPLE_SANDBOX_FETCH_DELETE,
|
|
14
|
+
});
|
|
15
|
+
commandSandboxFetchDelete.alias('rm');
|
|
16
|
+
(0, utils_1.sandboxScopeOptions)(commandSandboxFetchDelete);
|
|
17
|
+
commandSandboxFetchDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
|
|
18
|
+
commandSandboxFetchDelete.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
19
|
+
commandSandboxFetchDelete.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
20
|
+
commandSandboxFetchDelete.argument('<fetch>', texts_1.OPTION_SANDBOX_FETCH_ARG);
|
|
21
|
+
commandSandboxFetchDelete.action(async (identifier, fetchRef, options) => {
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const client = input_1.default.restApiTokenClient();
|
|
24
|
+
const sandboxId = await input_1.default.sandboxId(client, workspace, options, identifier);
|
|
25
|
+
const fetch = await (0, fetchSource_1.resolveSandboxFetch)(client, workspace, sandboxId, fetchRef);
|
|
26
|
+
const json = options.format === 'json';
|
|
27
|
+
const confirmed = await output_1.default.confirmDestructive(options.force, (0, texts_1.TXT_SANDBOX_FETCH_DELETE_CONFIRM)(identifier, (0, fetchSource_1.sandboxFetchPath)(fetch)), json);
|
|
28
|
+
if (!confirmed)
|
|
29
|
+
output_1.default.exitResult(json, { deleted: null });
|
|
30
|
+
await client.deleteSandboxFetch(workspace, sandboxId, fetch.id);
|
|
31
|
+
output_1.default.exitResult(json, { deleted: fetch }, (0, texts_1.TXT_SANDBOX_FETCH_DELETED)((0, fetchSource_1.sandboxFetchPath)(fetch)));
|
|
32
|
+
});
|
|
33
|
+
exports.default = commandSandboxFetchDelete;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const sandbox_1 = require("../../../types/sandbox");
|
|
11
|
+
const fetchSource_1 = require("../fetchSource");
|
|
12
|
+
const commandSandboxFetchGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_SANDBOX_FETCH_GET, {
|
|
13
|
+
requiredScopes: [utils_1.REST_API_SCOPE.SANDBOX_READ],
|
|
14
|
+
examples: texts_1.EXAMPLE_SANDBOX_FETCH_GET,
|
|
15
|
+
});
|
|
16
|
+
(0, utils_1.sandboxScopeOptions)(commandSandboxFetchGet);
|
|
17
|
+
commandSandboxFetchGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
18
|
+
commandSandboxFetchGet.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
19
|
+
commandSandboxFetchGet.argument('<fetch>', texts_1.OPTION_SANDBOX_FETCH_ARG);
|
|
20
|
+
commandSandboxFetchGet.action(async (identifier, fetchRef, options) => {
|
|
21
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
22
|
+
const client = input_1.default.restApiTokenClient();
|
|
23
|
+
const sandboxId = await input_1.default.sandboxId(client, workspace, options, identifier);
|
|
24
|
+
const found = await (0, fetchSource_1.resolveSandboxFetch)(client, workspace, sandboxId, fetchRef);
|
|
25
|
+
// the single fetch endpoint is the one that measures behind/outdated
|
|
26
|
+
const f = await client.getSandboxFetch(workspace, sandboxId, found.id);
|
|
27
|
+
if (options.format === 'json') {
|
|
28
|
+
output_1.default.json(f);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const isArtifact = f.type === sandbox_1.SANDBOX_FETCH.ARTIFACT;
|
|
32
|
+
const data = [
|
|
33
|
+
['Field', 'Value'],
|
|
34
|
+
['ID', f.id || '-'],
|
|
35
|
+
['Type', f.type || '-'],
|
|
36
|
+
['Path', (0, fetchSource_1.sandboxFetchPath)(f)],
|
|
37
|
+
['Source', (0, fetchSource_1.sandboxFetchSource)(f)],
|
|
38
|
+
[isArtifact ? 'Version' : 'Ref', (0, fetchSource_1.sandboxFetchRefOrVersion)(f)],
|
|
39
|
+
['Build command', f.build_command || '-'],
|
|
40
|
+
['Status', f.status || '-'],
|
|
41
|
+
['Revision', f.current_revision || '-'],
|
|
42
|
+
['Behind', (0, fetchSource_1.sandboxFetchBehind)(f)],
|
|
43
|
+
['Fetched', f.fetched_date || '-'],
|
|
44
|
+
];
|
|
45
|
+
if (f.error_message)
|
|
46
|
+
data.push(['Error', f.error_message]);
|
|
47
|
+
output_1.default.table(data);
|
|
48
|
+
}
|
|
49
|
+
output_1.default.exitNormal();
|
|
50
|
+
});
|
|
51
|
+
exports.default = commandSandboxFetchGet;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const fetchSource_1 = require("../fetchSource");
|
|
11
|
+
const commandSandboxFetchList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_SANDBOX_FETCH_LIST, {
|
|
12
|
+
requiredScopes: [utils_1.REST_API_SCOPE.SANDBOX_READ],
|
|
13
|
+
examples: texts_1.EXAMPLE_SANDBOX_FETCH_LIST,
|
|
14
|
+
});
|
|
15
|
+
commandSandboxFetchList.alias('ls');
|
|
16
|
+
(0, utils_1.sandboxScopeOptions)(commandSandboxFetchList);
|
|
17
|
+
commandSandboxFetchList.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
18
|
+
commandSandboxFetchList.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
19
|
+
commandSandboxFetchList.action(async (identifier, options) => {
|
|
20
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
21
|
+
const client = input_1.default.restApiTokenClient();
|
|
22
|
+
const sandboxId = await input_1.default.sandboxId(client, workspace, options, identifier);
|
|
23
|
+
const response = await client.listSandboxFetches(workspace, sandboxId);
|
|
24
|
+
const fetches = response.fetches || [];
|
|
25
|
+
if (options.format === 'json') {
|
|
26
|
+
output_1.default.json(fetches);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (fetches.length === 0) {
|
|
30
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_FETCHES_NOT_FOUND);
|
|
31
|
+
}
|
|
32
|
+
const data = [
|
|
33
|
+
['ID', 'Path', 'Source', 'Ref/Version', 'Status', 'Revision', 'Behind'],
|
|
34
|
+
];
|
|
35
|
+
for (const f of fetches) {
|
|
36
|
+
data.push([
|
|
37
|
+
f.id || '-',
|
|
38
|
+
(0, fetchSource_1.sandboxFetchPath)(f),
|
|
39
|
+
(0, fetchSource_1.sandboxFetchSource)(f),
|
|
40
|
+
(0, fetchSource_1.sandboxFetchRefOrVersion)(f),
|
|
41
|
+
f.status || '-',
|
|
42
|
+
(0, fetchSource_1.sandboxFetchRevision)(f),
|
|
43
|
+
(0, fetchSource_1.sandboxFetchBehind)(f),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
output_1.default.table(data);
|
|
47
|
+
}
|
|
48
|
+
output_1.default.exitNormal();
|
|
49
|
+
});
|
|
50
|
+
exports.default = commandSandboxFetchList;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const fetchSource_1 = require("../fetchSource");
|
|
11
|
+
const commandSandboxFetchRefetch = (0, utils_1.newCommand)('refetch', texts_1.DESC_COMMAND_SANDBOX_FETCH_REFETCH, {
|
|
12
|
+
requiredScopes: [utils_1.REST_API_SCOPE.SANDBOX_WRITE],
|
|
13
|
+
examples: texts_1.EXAMPLE_SANDBOX_FETCH_REFETCH,
|
|
14
|
+
});
|
|
15
|
+
(0, utils_1.sandboxScopeOptions)(commandSandboxFetchRefetch);
|
|
16
|
+
commandSandboxFetchRefetch.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
17
|
+
commandSandboxFetchRefetch.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxFetchRefetch.argument('<fetch>', texts_1.OPTION_SANDBOX_FETCH_ARG);
|
|
19
|
+
commandSandboxFetchRefetch.action(async (identifier, fetchRef, options) => {
|
|
20
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
21
|
+
const client = input_1.default.restApiTokenClient();
|
|
22
|
+
const sandboxId = await input_1.default.sandboxId(client, workspace, options, identifier);
|
|
23
|
+
const found = await (0, fetchSource_1.resolveSandboxFetch)(client, workspace, sandboxId, fetchRef);
|
|
24
|
+
const fetch = await client.refetchSandboxFetch(workspace, sandboxId, found.id);
|
|
25
|
+
output_1.default.exitResult(options.format === 'json', fetch, (0, texts_1.TXT_SANDBOX_FETCH_REFETCHED)((0, fetchSource_1.sandboxFetchPath)(fetch)));
|
|
26
|
+
});
|
|
27
|
+
exports.default = commandSandboxFetchRefetch;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const list_1 = __importDefault(require("./fetch/list"));
|
|
9
|
+
const get_1 = __importDefault(require("./fetch/get"));
|
|
10
|
+
const add_1 = __importDefault(require("./fetch/add"));
|
|
11
|
+
const delete_1 = __importDefault(require("./fetch/delete"));
|
|
12
|
+
const refetch_1 = __importDefault(require("./fetch/refetch"));
|
|
13
|
+
const commandSandboxFetch = (0, utils_1.newCommand)('fetch', texts_1.DESC_COMMAND_SANDBOX_FETCH, {
|
|
14
|
+
examples: [
|
|
15
|
+
...texts_1.EXAMPLE_SANDBOX_FETCH_LIST,
|
|
16
|
+
...texts_1.EXAMPLE_SANDBOX_FETCH_GET,
|
|
17
|
+
...texts_1.EXAMPLE_SANDBOX_FETCH_ADD,
|
|
18
|
+
...texts_1.EXAMPLE_SANDBOX_FETCH_DELETE,
|
|
19
|
+
...texts_1.EXAMPLE_SANDBOX_FETCH_REFETCH,
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
commandSandboxFetch.alias('f');
|
|
23
|
+
commandSandboxFetch.addCommand(list_1.default);
|
|
24
|
+
commandSandboxFetch.addCommand(get_1.default);
|
|
25
|
+
commandSandboxFetch.addCommand(add_1.default);
|
|
26
|
+
commandSandboxFetch.addCommand(delete_1.default);
|
|
27
|
+
commandSandboxFetch.addCommand(refetch_1.default);
|
|
28
|
+
exports.default = commandSandboxFetch;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findSandboxFetch = exports.resolveSandboxFetch = exports.sandboxFetchPath = exports.sandboxFetchRevision = exports.sandboxFetchRefOrVersion = exports.sandboxFetchBehind = exports.sandboxFetchSource = exports.SANDBOX_FETCH_DEFAULT = void 0;
|
|
7
|
+
const cliError_1 = __importDefault(require("../../cliError"));
|
|
8
|
+
const texts_1 = require("../../texts");
|
|
9
|
+
const sandbox_1 = require("../../types/sandbox");
|
|
10
|
+
exports.SANDBOX_FETCH_DEFAULT = ':default';
|
|
11
|
+
// Where the files come from: the project repository, a public repository URL or
|
|
12
|
+
// the artifact (with the path inside it when only part of it is fetched)
|
|
13
|
+
const sandboxFetchSource = (f) => {
|
|
14
|
+
if (f.type === sandbox_1.SANDBOX_FETCH.ARTIFACT) {
|
|
15
|
+
const artifact = f.artifact || '-';
|
|
16
|
+
return f.source_path ? `${artifact} (${f.source_path})` : artifact;
|
|
17
|
+
}
|
|
18
|
+
if (f.type === sandbox_1.SANDBOX_FETCH.PUBLIC_REPO)
|
|
19
|
+
return f.repository || '-';
|
|
20
|
+
return 'project repository';
|
|
21
|
+
};
|
|
22
|
+
exports.sandboxFetchSource = sandboxFetchSource;
|
|
23
|
+
// How far the fetched files are from what the fetch points at. Repositories count
|
|
24
|
+
// commits behind the ref, artifacts only know whether the version moved on. Null
|
|
25
|
+
// means the API could not measure it (e.g. an unreachable public repository).
|
|
26
|
+
const sandboxFetchBehind = (f) => {
|
|
27
|
+
if (f.type === sandbox_1.SANDBOX_FETCH.ARTIFACT) {
|
|
28
|
+
if (f.outdated === true)
|
|
29
|
+
return 'outdated';
|
|
30
|
+
if (f.outdated === false)
|
|
31
|
+
return 'up to date';
|
|
32
|
+
return '-';
|
|
33
|
+
}
|
|
34
|
+
if (typeof f.behind !== 'number')
|
|
35
|
+
return '-';
|
|
36
|
+
if (f.behind === 0)
|
|
37
|
+
return 'up to date';
|
|
38
|
+
return `${f.behind} behind`;
|
|
39
|
+
};
|
|
40
|
+
exports.sandboxFetchBehind = sandboxFetchBehind;
|
|
41
|
+
// The ref of a repository fetch, the version of an artifact fetch (name:version)
|
|
42
|
+
const sandboxFetchRefOrVersion = (f) => {
|
|
43
|
+
if (f.type === sandbox_1.SANDBOX_FETCH.ARTIFACT) {
|
|
44
|
+
const artifact = f.artifact || '';
|
|
45
|
+
const idx = artifact.lastIndexOf(':');
|
|
46
|
+
return idx > 0 ? artifact.substring(idx + 1) : '-';
|
|
47
|
+
}
|
|
48
|
+
return f.ref || '-';
|
|
49
|
+
};
|
|
50
|
+
exports.sandboxFetchRefOrVersion = sandboxFetchRefOrVersion;
|
|
51
|
+
const sandboxFetchRevision = (f) => f.current_revision ? f.current_revision.substring(0, 7) : '-';
|
|
52
|
+
exports.sandboxFetchRevision = sandboxFetchRevision;
|
|
53
|
+
// How a fetch is named in messages: its target directory, ":default" for the
|
|
54
|
+
// fetch into the app directory (the API keeps its path empty)
|
|
55
|
+
const sandboxFetchPath = (f) => f.path || exports.SANDBOX_FETCH_DEFAULT;
|
|
56
|
+
exports.sandboxFetchPath = sandboxFetchPath;
|
|
57
|
+
const trimSlash = (p) => (p || '').replace(/\/+$/, '');
|
|
58
|
+
// The API ID or an explicitly set target directory, no app directory needed
|
|
59
|
+
const matchSandboxFetch = (fetches, ref) => fetches.find((f) => f.id === ref) ||
|
|
60
|
+
fetches.find((f) => !!f.path && trimSlash(f.path) === trimSlash(ref));
|
|
61
|
+
// Lists the sandbox fetches and picks one. The sandbox itself is read only when
|
|
62
|
+
// the ref may name the app directory: ":default", or the directory given
|
|
63
|
+
// explicitly for the fetch into it, which keeps an empty path
|
|
64
|
+
const resolveSandboxFetch = async (client, workspace, sandboxId, ref) => {
|
|
65
|
+
const response = await client.listSandboxFetches(workspace, sandboxId);
|
|
66
|
+
const fetches = response.fetches || [];
|
|
67
|
+
let appDir;
|
|
68
|
+
if (!matchSandboxFetch(fetches, ref)) {
|
|
69
|
+
const sandbox = await client.getSandbox(workspace, sandboxId);
|
|
70
|
+
appDir = sandbox.app_dir;
|
|
71
|
+
}
|
|
72
|
+
return (0, exports.findSandboxFetch)(fetches, ref, appDir);
|
|
73
|
+
};
|
|
74
|
+
exports.resolveSandboxFetch = resolveSandboxFetch;
|
|
75
|
+
// A fetch is identified by its target directory, ":default" (or the app directory
|
|
76
|
+
// itself) names the one into the app directory. The API ID is accepted too, so
|
|
77
|
+
// output of `list --format json` can be fed back directly.
|
|
78
|
+
const findSandboxFetch = (fetches, ref, appDir) => {
|
|
79
|
+
let found = matchSandboxFetch(fetches, ref);
|
|
80
|
+
if (!found &&
|
|
81
|
+
(ref === exports.SANDBOX_FETCH_DEFAULT ||
|
|
82
|
+
(!!appDir && trimSlash(ref) === trimSlash(appDir)))) {
|
|
83
|
+
found = fetches.find((f) => !f.path || (!!appDir && trimSlash(f.path) === trimSlash(appDir)));
|
|
84
|
+
}
|
|
85
|
+
if (!found) {
|
|
86
|
+
throw new cliError_1.default('not_found', texts_1.ERR_SANDBOX_FETCH_NOT_FOUND, texts_1.HINT_SANDBOX_FETCH_LIST);
|
|
87
|
+
}
|
|
88
|
+
return found;
|
|
89
|
+
};
|
|
90
|
+
exports.findSandboxFetch = findSandboxFetch;
|