eas-cli 27.4.1 → 27.5.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/README.md +369 -198
- package/build/build/simulatorsLaunchHint.js +1 -1
- package/build/commands/simulator/availability.d.ts +1 -0
- package/build/commands/simulator/availability.js +3 -1
- package/build/commands/simulator/control/connection.d.ts +19 -0
- package/build/commands/simulator/control/connection.js +93 -0
- package/build/commands/simulator/control.d.ts +7 -0
- package/build/commands/simulator/control.js +249 -110
- package/build/commands/simulator/egress.d.ts +1 -0
- package/build/commands/simulator/egress.js +3 -1
- package/build/commands/simulator/events.d.ts +1 -0
- package/build/commands/simulator/events.js +3 -1
- package/build/commands/simulator/exec.d.ts +1 -0
- package/build/commands/simulator/exec.js +3 -1
- package/build/commands/simulator/get.d.ts +1 -0
- package/build/commands/simulator/get.js +3 -1
- package/build/commands/simulator/index.d.ts +2 -0
- package/build/commands/simulator/index.js +286 -76
- package/build/commands/simulator/list.d.ts +1 -0
- package/build/commands/simulator/list.js +3 -1
- package/build/commands/simulator/logs.d.ts +1 -0
- package/build/commands/simulator/logs.js +3 -1
- package/build/commands/simulator/stop.d.ts +1 -0
- package/build/commands/simulator/stop.js +3 -1
- package/build/commands/workflow/ssh.d.ts +0 -1
- package/build/commands/workflow/ssh.js +0 -1
- package/build/graphql/generated.d.ts +8 -0
- package/build/graphql/types/Actor.js +3 -0
- package/build/help.js +2 -1
- package/build/project/accountSelection.js +5 -8
- package/build/simulator/commandAliases.d.ts +10 -0
- package/build/simulator/commandAliases.js +24 -0
- package/build/simulator/controlActions.d.ts +32 -0
- package/build/simulator/controlActions.js +128 -0
- package/build/simulator/controlConfig.d.ts +43 -0
- package/build/simulator/controlConfig.js +156 -0
- package/build/simulator/controlConnection.d.ts +28 -0
- package/build/simulator/controlConnection.js +337 -0
- package/build/simulator/controlConnectionProtocol.d.ts +64 -0
- package/build/simulator/controlConnectionProtocol.js +155 -0
- package/build/simulator/controlConnectionWorker.d.ts +7 -0
- package/build/simulator/controlConnectionWorker.js +278 -0
- package/build/simulator/controlSession.d.ts +3 -0
- package/build/simulator/controlSession.js +28 -0
- package/build/simulator/hostActions.d.ts +22 -3
- package/build/simulator/hostActions.js +78 -19
- package/build/simulator/sessionConfig.d.ts +16 -0
- package/build/simulator/sessionConfig.js +36 -0
- package/build/simulator/startConfig.d.ts +7 -0
- package/build/simulator/startConfig.js +89 -0
- package/build/simulator/startSetup.d.ts +7 -0
- package/build/simulator/startSetup.js +17 -0
- package/build/user/User.d.ts +9 -1
- package/build/user/User.js +25 -3
- package/build/user/accountPermissions.js +3 -1
- package/oclif.manifest.json +1403 -1212
- package/package.json +8 -6
package/build/help.js
CHANGED
|
@@ -34,11 +34,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const core_1 = require("@oclif/core");
|
|
37
|
+
const commandAliases_1 = require("./simulator/commandAliases");
|
|
37
38
|
class EasHelp extends core_1.Help {
|
|
38
39
|
// eslint-disable-next-line async-protect/async-suffix -- oclif defines the method name.
|
|
39
40
|
async showHelp(argv) {
|
|
40
41
|
const [command, ...args] = argv;
|
|
41
|
-
if (
|
|
42
|
+
if ((0, commandAliases_1.isSimulatorCommandId)(command, 'control')) {
|
|
42
43
|
const { default: SimulatorControl } = await Promise.resolve().then(() => __importStar(require('./commands/simulator/control')));
|
|
43
44
|
let parsed;
|
|
44
45
|
try {
|
|
@@ -8,11 +8,8 @@ function getDisabledProps(account) {
|
|
|
8
8
|
}
|
|
9
9
|
function getAccountChoices(actor) {
|
|
10
10
|
const allAccounts = actor.accounts;
|
|
11
|
-
const sortedAccounts = actor.__typename === 'Robot'
|
|
12
|
-
? allAccounts
|
|
13
|
-
: [...allAccounts].sort((a, _b) => actor.__typename === 'User' ? (a.name === actor.username ? -1 : 1) : 0);
|
|
14
11
|
if (actor.__typename !== 'Robot') {
|
|
15
|
-
const personalAccount =
|
|
12
|
+
const personalAccount = (0, User_1.getPersonalAccount)(actor);
|
|
16
13
|
const personalAccountChoice = personalAccount
|
|
17
14
|
? {
|
|
18
15
|
title: personalAccount.name,
|
|
@@ -22,7 +19,7 @@ function getAccountChoices(actor) {
|
|
|
22
19
|
}
|
|
23
20
|
: undefined;
|
|
24
21
|
const userAccounts = allAccounts
|
|
25
|
-
?.filter(account => account.ownerUserActor && account.
|
|
22
|
+
?.filter(account => account.ownerUserActor && account.id !== personalAccount?.id)
|
|
26
23
|
.map(account => ({
|
|
27
24
|
title: account.name,
|
|
28
25
|
value: account,
|
|
@@ -30,7 +27,7 @@ function getAccountChoices(actor) {
|
|
|
30
27
|
...getDisabledProps(account),
|
|
31
28
|
}));
|
|
32
29
|
const organizationAccounts = allAccounts
|
|
33
|
-
?.filter(account => account.
|
|
30
|
+
?.filter(account => account.id !== personalAccount?.id && !account.ownerUserActor)
|
|
34
31
|
.map(account => ({
|
|
35
32
|
title: account.name,
|
|
36
33
|
value: account,
|
|
@@ -41,9 +38,9 @@ function getAccountChoices(actor) {
|
|
|
41
38
|
if (personalAccountChoice) {
|
|
42
39
|
choices = [personalAccountChoice];
|
|
43
40
|
}
|
|
44
|
-
return [...choices, ...userAccounts, ...organizationAccounts]
|
|
41
|
+
return [...choices, ...userAccounts, ...organizationAccounts];
|
|
45
42
|
}
|
|
46
|
-
return
|
|
43
|
+
return allAccounts.map(account => ({
|
|
47
44
|
title: account.name,
|
|
48
45
|
value: account,
|
|
49
46
|
...getDisabledProps(account),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Other topic names that run `eas simulator:*` commands, for example `eas sim:start` or
|
|
3
|
+
* `eas emulators:list`. Help and the README list the `sim` aliases. The other aliases are
|
|
4
|
+
* hidden, so that help lists each command at most twice.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SIMULATOR_TOPIC_ALIASES: string[];
|
|
7
|
+
export declare const SIMULATOR_HIDDEN_TOPIC_ALIASES: string[];
|
|
8
|
+
export declare function getSimulatorCommandAliases(name: string): string[];
|
|
9
|
+
export declare function getSimulatorCommandHiddenAliases(name: string): string[];
|
|
10
|
+
export declare function isSimulatorCommandId(id: string | undefined, name: string): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIMULATOR_HIDDEN_TOPIC_ALIASES = exports.SIMULATOR_TOPIC_ALIASES = void 0;
|
|
4
|
+
exports.getSimulatorCommandAliases = getSimulatorCommandAliases;
|
|
5
|
+
exports.getSimulatorCommandHiddenAliases = getSimulatorCommandHiddenAliases;
|
|
6
|
+
exports.isSimulatorCommandId = isSimulatorCommandId;
|
|
7
|
+
/**
|
|
8
|
+
* Other topic names that run `eas simulator:*` commands, for example `eas sim:start` or
|
|
9
|
+
* `eas emulators:list`. Help and the README list the `sim` aliases. The other aliases are
|
|
10
|
+
* hidden, so that help lists each command at most twice.
|
|
11
|
+
*/
|
|
12
|
+
exports.SIMULATOR_TOPIC_ALIASES = ['sim'];
|
|
13
|
+
exports.SIMULATOR_HIDDEN_TOPIC_ALIASES = ['simulators', 'emulator', 'emulators'];
|
|
14
|
+
function getSimulatorCommandAliases(name) {
|
|
15
|
+
return exports.SIMULATOR_TOPIC_ALIASES.map(topic => `${topic}:${name}`);
|
|
16
|
+
}
|
|
17
|
+
function getSimulatorCommandHiddenAliases(name) {
|
|
18
|
+
return exports.SIMULATOR_HIDDEN_TOPIC_ALIASES.map(topic => `${topic}:${name}`);
|
|
19
|
+
}
|
|
20
|
+
function isSimulatorCommandId(id, name) {
|
|
21
|
+
return (id === `simulator:${name}` ||
|
|
22
|
+
(id !== undefined &&
|
|
23
|
+
[...getSimulatorCommandAliases(name), ...getSimulatorCommandHiddenAliases(name)].includes(id)));
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
|
+
import { HostActionCatalog, HostActionCatalogEntry, HostActionConnection } from './hostActions';
|
|
3
|
+
export type ControlAction = {
|
|
4
|
+
action: string;
|
|
5
|
+
params: Record<string, unknown>;
|
|
6
|
+
outputPath?: string;
|
|
7
|
+
file?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ControlActionResult = {
|
|
10
|
+
output: string;
|
|
11
|
+
file: string | null;
|
|
12
|
+
};
|
|
13
|
+
export type PreparedControlAction = Readonly<{
|
|
14
|
+
action: string;
|
|
15
|
+
entry: HostActionCatalogEntry;
|
|
16
|
+
params: Readonly<Record<string, unknown>>;
|
|
17
|
+
outputPath?: string;
|
|
18
|
+
localFile?: Readonly<{
|
|
19
|
+
param: string;
|
|
20
|
+
path: string;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function resolveControlActionPath(value: string, baseDir?: string): string;
|
|
24
|
+
export declare function prepareControlActionAsync(catalog: HostActionCatalog, action: ControlAction, { localFileMode, baseDir, }?: {
|
|
25
|
+
localFileMode?: 'auto' | 'explicit';
|
|
26
|
+
baseDir?: string;
|
|
27
|
+
}): Promise<PreparedControlAction>;
|
|
28
|
+
export declare function assertLocalFileAsync(localPath: string, stats?: fs.Stats): Promise<void>;
|
|
29
|
+
export declare function executeControlActionAsync(connection: HostActionConnection, plan: PreparedControlAction, { validateParams }?: {
|
|
30
|
+
validateParams?: (params: Record<string, unknown>) => void;
|
|
31
|
+
}): Promise<ControlActionResult>;
|
|
32
|
+
export declare function parseControlActionOutput(output: string): unknown;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveControlActionPath = resolveControlActionPath;
|
|
4
|
+
exports.prepareControlActionAsync = prepareControlActionAsync;
|
|
5
|
+
exports.assertLocalFileAsync = assertLocalFileAsync;
|
|
6
|
+
exports.executeControlActionAsync = executeControlActionAsync;
|
|
7
|
+
exports.parseControlActionOutput = parseControlActionOutput;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
10
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const hostActions_1 = require("./hostActions");
|
|
12
|
+
function resolveControlActionPath(value, baseDir) {
|
|
13
|
+
if (!baseDir) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
const resolved = path_1.default.resolve(baseDir, value);
|
|
17
|
+
return value.endsWith('/') || value.endsWith(path_1.default.sep) ? `${resolved}${path_1.default.sep}` : resolved;
|
|
18
|
+
}
|
|
19
|
+
async function prepareControlActionAsync(catalog, action, { localFileMode = 'auto', baseDir, } = {}) {
|
|
20
|
+
const entry = Object.hasOwn(catalog, action.action) ? catalog[action.action] : undefined;
|
|
21
|
+
if (!entry) {
|
|
22
|
+
throw new Error(`Unknown simulator action "${action.action}". Run \`eas simulator:control --list\` to see the actions.`);
|
|
23
|
+
}
|
|
24
|
+
const params = { ...action.params };
|
|
25
|
+
const outputPath = action.outputPath
|
|
26
|
+
? resolveControlActionPath(action.outputPath, baseDir)
|
|
27
|
+
: action.outputPath;
|
|
28
|
+
await (0, hostActions_1.assertHostActionOutputAsync)(action.action, entry, outputPath);
|
|
29
|
+
let localFile;
|
|
30
|
+
const param = entry.upload;
|
|
31
|
+
const applies = Object.entries(entry.uploadWhen ?? {}).every(([name, expected]) => params[name] === expected);
|
|
32
|
+
if (action.file !== undefined) {
|
|
33
|
+
if (!param || !applies) {
|
|
34
|
+
throw new Error(`${action.action} does not accept a local file with these parameters.`);
|
|
35
|
+
}
|
|
36
|
+
if (Object.hasOwn(params, param)) {
|
|
37
|
+
throw new Error(`${param} and file cannot both be supplied for ${action.action}.`);
|
|
38
|
+
}
|
|
39
|
+
localFile = { param, path: resolveControlActionPath(action.file, baseDir) };
|
|
40
|
+
await assertLocalFileAsync(localFile.path);
|
|
41
|
+
}
|
|
42
|
+
else if (localFileMode === 'auto' && param && applies && typeof params[param] === 'string') {
|
|
43
|
+
const value = params[param];
|
|
44
|
+
if (value.startsWith('host:')) {
|
|
45
|
+
if (entry.uploadAs === 'id') {
|
|
46
|
+
throw new Error('This action requires a local file to upload; host: paths are not supported.');
|
|
47
|
+
}
|
|
48
|
+
const hostPath = value.slice('host:'.length);
|
|
49
|
+
if (!path_1.default.posix.isAbsolute(hostPath)) {
|
|
50
|
+
throw new Error(`A host: path must be absolute, for example host:/tmp/app.tar.gz. For a local filename beginning with host:, use ./${value}.`);
|
|
51
|
+
}
|
|
52
|
+
params[param] = hostPath;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const localPath = resolveControlActionPath(value, baseDir);
|
|
56
|
+
const stat = await fs.stat(localPath).catch((error) => {
|
|
57
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
if (!stat) {
|
|
63
|
+
throw new Error(`${value} does not exist on this computer. Pass a local file, or prefix an absolute simulator-host path with host:.`);
|
|
64
|
+
}
|
|
65
|
+
await assertLocalFileAsync(localPath, stat);
|
|
66
|
+
localFile = { param, path: localPath };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
action: action.action,
|
|
71
|
+
entry,
|
|
72
|
+
params,
|
|
73
|
+
outputPath,
|
|
74
|
+
...(localFile ? { localFile } : {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async function assertLocalFileAsync(localPath, stats) {
|
|
78
|
+
const stat = stats ?? (await fs.stat(localPath).catch(() => null));
|
|
79
|
+
if (!stat) {
|
|
80
|
+
throw new Error(`${localPath} does not exist on this computer.`);
|
|
81
|
+
}
|
|
82
|
+
if (stat.isDirectory()) {
|
|
83
|
+
throw new Error(`${localPath} is a folder. Pass the path of a file.`);
|
|
84
|
+
}
|
|
85
|
+
if (!stat.isFile()) {
|
|
86
|
+
throw new Error(`${localPath} is not a regular file.`);
|
|
87
|
+
}
|
|
88
|
+
if (stat.size === 0) {
|
|
89
|
+
throw new Error(`${localPath} is empty. Pass a file with content.`);
|
|
90
|
+
}
|
|
91
|
+
await fs.access(localPath, fs.constants.R_OK);
|
|
92
|
+
}
|
|
93
|
+
async function executeControlActionAsync(connection, plan, { validateParams } = {}) {
|
|
94
|
+
connection.signal.throwIfAborted();
|
|
95
|
+
const params = { ...plan.params };
|
|
96
|
+
let uploadId;
|
|
97
|
+
let succeeded = false;
|
|
98
|
+
try {
|
|
99
|
+
if (plan.localFile) {
|
|
100
|
+
const upload = await (0, hostActions_1.uploadFileAsync)(connection, plan.localFile.path);
|
|
101
|
+
uploadId = upload.uploadId;
|
|
102
|
+
params[plan.localFile.param] = plan.entry.uploadAs === 'id' ? upload.uploadId : upload.path;
|
|
103
|
+
}
|
|
104
|
+
connection.signal.throwIfAborted();
|
|
105
|
+
validateParams?.(params);
|
|
106
|
+
const result = await connection.requestAsync(plan.action, params);
|
|
107
|
+
if (result.exitCode !== 0) {
|
|
108
|
+
const detail = (result.stderr || result.stdout).trim() || `exit code ${result.exitCode}`;
|
|
109
|
+
throw new Error(`The simulator could not run ${plan.action}: ${detail}`);
|
|
110
|
+
}
|
|
111
|
+
succeeded = true;
|
|
112
|
+
const file = await (0, hostActions_1.saveHostActionOutputAsync)(connection, plan.entry, result.stdout, plan.outputPath);
|
|
113
|
+
return { output: file ? '' : result.stdout.trim(), file };
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
if (uploadId && (!plan.entry.keepUpload || !succeeded)) {
|
|
117
|
+
await connection.requestAsync('upload.remove', { uploadId }).catch(() => { });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function parseControlActionOutput(output) {
|
|
122
|
+
try {
|
|
123
|
+
return JSON.parse(output);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return output;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ControlActionResult, PreparedControlAction } from './controlActions';
|
|
2
|
+
import { HostActionCatalog, HostActionConnection } from './hostActions';
|
|
3
|
+
import { SimulatorSessionConfig } from './sessionConfig';
|
|
4
|
+
type ConfigAction = {
|
|
5
|
+
readonly plan: PreparedControlAction;
|
|
6
|
+
readonly validateParams: (params: Record<string, unknown>) => void;
|
|
7
|
+
};
|
|
8
|
+
export type PreparedControlConfig = {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
readonly udid: string;
|
|
11
|
+
readonly actions: readonly ConfigAction[];
|
|
12
|
+
};
|
|
13
|
+
export type ControlConfigResult = ControlActionResult & {
|
|
14
|
+
action: string;
|
|
15
|
+
};
|
|
16
|
+
export type ControlConfigProgress = {
|
|
17
|
+
step: number;
|
|
18
|
+
total: number;
|
|
19
|
+
action: string;
|
|
20
|
+
} & ({
|
|
21
|
+
status: 'running';
|
|
22
|
+
} | {
|
|
23
|
+
status: 'completed';
|
|
24
|
+
result: ControlConfigResult;
|
|
25
|
+
});
|
|
26
|
+
export declare class ControlConfigExecutionError extends Error {
|
|
27
|
+
readonly step: number;
|
|
28
|
+
readonly action: string;
|
|
29
|
+
readonly completed: readonly ControlConfigResult[];
|
|
30
|
+
constructor(step: number, action: string, completed: readonly ControlConfigResult[], cause: unknown);
|
|
31
|
+
}
|
|
32
|
+
export declare function prepareControlConfigAsync(catalog: HostActionCatalog, filePath: string, udid: string, input?: SimulatorSessionConfig): Promise<PreparedControlConfig>;
|
|
33
|
+
/** Check local inputs before requesting a paid session; runtime validation still uses the live catalog. */
|
|
34
|
+
export declare function preflightControlConfigFilesAsync(config: SimulatorSessionConfig): Promise<void>;
|
|
35
|
+
export declare function executeControlConfigAsync(connection: HostActionConnection, config: PreparedControlConfig, { onProgress }?: {
|
|
36
|
+
onProgress?: (progress: ControlConfigProgress) => void;
|
|
37
|
+
}): Promise<ControlConfigResult[]>;
|
|
38
|
+
export declare function serializeControlConfigResults(results: readonly ControlConfigResult[]): {
|
|
39
|
+
action: string;
|
|
40
|
+
output: unknown;
|
|
41
|
+
file: string | null;
|
|
42
|
+
}[];
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControlConfigExecutionError = void 0;
|
|
4
|
+
exports.prepareControlConfigAsync = prepareControlConfigAsync;
|
|
5
|
+
exports.preflightControlConfigFilesAsync = preflightControlConfigFilesAsync;
|
|
6
|
+
exports.executeControlConfigAsync = executeControlConfigAsync;
|
|
7
|
+
exports.serializeControlConfigResults = serializeControlConfigResults;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const _2020_1 = tslib_1.__importDefault(require("ajv/dist/2020"));
|
|
10
|
+
const ajv_formats_1 = tslib_1.__importDefault(require("ajv-formats"));
|
|
11
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const controlActions_1 = require("./controlActions");
|
|
14
|
+
const hostActions_1 = require("./hostActions");
|
|
15
|
+
const sessionConfig_1 = require("./sessionConfig");
|
|
16
|
+
class ControlConfigExecutionError extends Error {
|
|
17
|
+
step;
|
|
18
|
+
action;
|
|
19
|
+
completed;
|
|
20
|
+
constructor(step, action, completed, cause) {
|
|
21
|
+
super(`Config step ${step} (${action}) failed after ${completed.length} completed actions: ${errorMessage(cause)}`, { cause });
|
|
22
|
+
this.step = step;
|
|
23
|
+
this.action = action;
|
|
24
|
+
this.completed = completed;
|
|
25
|
+
this.name = 'ControlConfigExecutionError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ControlConfigExecutionError = ControlConfigExecutionError;
|
|
29
|
+
async function prepareControlConfigAsync(catalog, filePath, udid, input) {
|
|
30
|
+
const config = input ?? (await (0, sessionConfig_1.readSimulatorSessionConfigAsync)(filePath));
|
|
31
|
+
const absolutePath = config.path;
|
|
32
|
+
if (!config.actions?.length) {
|
|
33
|
+
throw new Error(`Invalid simulator configuration ${absolutePath}: actions must contain at least one action.`);
|
|
34
|
+
}
|
|
35
|
+
const ajv = (0, ajv_formats_1.default)(new _2020_1.default({ strict: false, allErrors: true }));
|
|
36
|
+
const actions = [];
|
|
37
|
+
for (const [index, action] of config.actions.entries()) {
|
|
38
|
+
try {
|
|
39
|
+
if (Object.hasOwn(action.params, 'udid')) {
|
|
40
|
+
throw new Error('The simulator is selected by the session; remove params.udid.');
|
|
41
|
+
}
|
|
42
|
+
const plan = await (0, controlActions_1.prepareControlActionAsync)(catalog, { ...action, outputPath: action.output }, { localFileMode: 'explicit', baseDir: path_1.default.dirname(absolutePath) });
|
|
43
|
+
if (plan.entry.output) {
|
|
44
|
+
if (!plan.outputPath) {
|
|
45
|
+
throw new Error('Set output to a file or directory for this action.');
|
|
46
|
+
}
|
|
47
|
+
await assertWritableOutputAsync(plan.outputPath);
|
|
48
|
+
}
|
|
49
|
+
assertUnambiguousFileSource(ajv, plan, udid);
|
|
50
|
+
const validate = ajv.compile(plan.entry);
|
|
51
|
+
const validateParams = (params) => {
|
|
52
|
+
if (!validate({ ...params, udid })) {
|
|
53
|
+
throw new Error(ajv.errorsText(validate.errors, { dataVar: 'params' }));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const params = { ...plan.params };
|
|
57
|
+
if (plan.localFile) {
|
|
58
|
+
const uploadId = (0, hostActions_1.createHostActionUploadId)(plan.localFile.path);
|
|
59
|
+
params[plan.localFile.param] =
|
|
60
|
+
plan.entry.uploadAs === 'id' ? uploadId : `/tmp/serve-sim-uploads/${uploadId}`;
|
|
61
|
+
}
|
|
62
|
+
validateParams(params);
|
|
63
|
+
actions.push({ plan, validateParams });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new Error(`Config step ${index + 1} (${action.action}): ${errorMessage(error)}`, {
|
|
67
|
+
cause: error,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { path: absolutePath, udid, actions };
|
|
72
|
+
}
|
|
73
|
+
/** Check local inputs before requesting a paid session; runtime validation still uses the live catalog. */
|
|
74
|
+
async function preflightControlConfigFilesAsync(config) {
|
|
75
|
+
for (const [index, action] of (config.actions ?? []).entries()) {
|
|
76
|
+
try {
|
|
77
|
+
if (Object.hasOwn(action.params, 'udid')) {
|
|
78
|
+
throw new Error('The simulator is selected by the session; remove params.udid.');
|
|
79
|
+
}
|
|
80
|
+
if (action.file) {
|
|
81
|
+
await (0, controlActions_1.assertLocalFileAsync)(path_1.default.resolve(path_1.default.dirname(config.path), action.file));
|
|
82
|
+
}
|
|
83
|
+
if (action.output) {
|
|
84
|
+
await assertWritableOutputAsync((0, controlActions_1.resolveControlActionPath)(action.output, path_1.default.dirname(config.path)));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new Error(`Config step ${index + 1} (${action.action}): ${errorMessage(error)}`, {
|
|
89
|
+
cause: error,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function assertWritableOutputAsync(outputPath) {
|
|
95
|
+
const stat = await fs.stat(outputPath).catch(() => null);
|
|
96
|
+
if ((outputPath.endsWith('/') || outputPath.endsWith(path_1.default.sep)) && !stat?.isDirectory()) {
|
|
97
|
+
throw new Error(`${outputPath} must be an existing directory.`);
|
|
98
|
+
}
|
|
99
|
+
if (stat && !stat.isFile() && !stat.isDirectory()) {
|
|
100
|
+
throw new Error(`${outputPath} must be a regular file or directory.`);
|
|
101
|
+
}
|
|
102
|
+
await fs.access(stat ? outputPath : path_1.default.dirname(outputPath), fs.constants.W_OK | (stat?.isFile() ? 0 : fs.constants.X_OK));
|
|
103
|
+
}
|
|
104
|
+
function declaresParameter(schema, name) {
|
|
105
|
+
if (typeof schema !== 'object' || schema === null || Array.isArray(schema)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const { properties, allOf } = schema;
|
|
109
|
+
return ((properties !== undefined && Object.hasOwn(properties, name)) ||
|
|
110
|
+
(Array.isArray(allOf) && allOf.some(child => declaresParameter(child, name))));
|
|
111
|
+
}
|
|
112
|
+
function assertUnambiguousFileSource(ajv, plan, udid) {
|
|
113
|
+
if (!plan.localFile) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const { anyOf, oneOf, ...common } = plan.entry;
|
|
117
|
+
for (const branch of anyOf ?? oneOf ?? []) {
|
|
118
|
+
if (declaresParameter(branch, plan.localFile.param)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const validate = ajv.compile({
|
|
122
|
+
...common,
|
|
123
|
+
allOf: [...(common.allOf ?? []), branch],
|
|
124
|
+
});
|
|
125
|
+
if (validate({ ...plan.params, udid })) {
|
|
126
|
+
throw new Error('file conflicts with another source in params. Supply only one file source.');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function executeControlConfigAsync(connection, config, { onProgress } = {}) {
|
|
131
|
+
if (config.udid !== connection.udid) {
|
|
132
|
+
throw new Error('The simulator changed after this configuration was checked. Import it again.');
|
|
133
|
+
}
|
|
134
|
+
const completed = [];
|
|
135
|
+
for (const [index, { plan, validateParams }] of config.actions.entries()) {
|
|
136
|
+
const progress = { step: index + 1, total: config.actions.length, action: plan.action };
|
|
137
|
+
onProgress?.({ ...progress, status: 'running' });
|
|
138
|
+
let result;
|
|
139
|
+
try {
|
|
140
|
+
result = await (0, controlActions_1.executeControlActionAsync)(connection, plan, { validateParams });
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
throw new ControlConfigExecutionError(index + 1, plan.action, completed, error);
|
|
144
|
+
}
|
|
145
|
+
const entry = { action: plan.action, ...result };
|
|
146
|
+
completed.push(entry);
|
|
147
|
+
onProgress?.({ ...progress, status: 'completed', result: entry });
|
|
148
|
+
}
|
|
149
|
+
return completed;
|
|
150
|
+
}
|
|
151
|
+
function errorMessage(error) {
|
|
152
|
+
return error instanceof Error ? error.message : String(error);
|
|
153
|
+
}
|
|
154
|
+
function serializeControlConfigResults(results) {
|
|
155
|
+
return results.map(result => ({ ...result, output: (0, controlActions_1.parseControlActionOutput)(result.output) }));
|
|
156
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConnectionOperation, ControlConnectionInfo } from './controlConnectionProtocol';
|
|
2
|
+
import { HostActionCatalog, HostActionConnection } from './hostActions';
|
|
3
|
+
import { PreviewApiAccess } from './utils';
|
|
4
|
+
import { LoggedInAuthenticationInfo } from '../user/SessionManager';
|
|
5
|
+
export type ControlConnectionIdentity = {
|
|
6
|
+
root: string;
|
|
7
|
+
socketPath: string;
|
|
8
|
+
credentialHash: string;
|
|
9
|
+
scope: string;
|
|
10
|
+
sessionStatePath?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ControlConnectionBootstrap = {
|
|
13
|
+
access: PreviewApiAccess;
|
|
14
|
+
session: Omit<ControlConnectionInfo['session'], 'device'>;
|
|
15
|
+
};
|
|
16
|
+
export type BorrowedControlConnection = {
|
|
17
|
+
connection: HostActionConnection;
|
|
18
|
+
catalog: HostActionCatalog;
|
|
19
|
+
info: ControlConnectionInfo;
|
|
20
|
+
};
|
|
21
|
+
export declare function assertControlKeepAliveSupported(): void;
|
|
22
|
+
export declare function createControlConnectionIdentityAsync(sessionId: string, projectDir: string, authentication: LoggedInAuthenticationInfo, root?: string): Promise<ControlConnectionIdentity>;
|
|
23
|
+
export declare function assertControlConnectionCredentialAsync(identity: ControlConnectionIdentity): Promise<void>;
|
|
24
|
+
export declare function ensureControlConnectionDirectoryAsync(root: string): Promise<void>;
|
|
25
|
+
export declare function withControlConnectionLockAsync<T>(identity: ControlConnectionIdentity, fn: () => Promise<T>): Promise<T>;
|
|
26
|
+
export declare function borrowControlConnectionAsync(identity: ControlConnectionIdentity): Promise<BorrowedControlConnection | null>;
|
|
27
|
+
export declare function inspectControlConnectionAsync(identity: ControlConnectionIdentity, operation?: ConnectionOperation): Promise<ControlConnectionInfo | null>;
|
|
28
|
+
export declare function openControlConnectionAsync(identity: ControlConnectionIdentity, load: () => Promise<ControlConnectionBootstrap>, idleTimeoutMs?: number, workerPath?: string): Promise<ControlConnectionInfo>;
|