eas-cli
Version:
EAS command line tool
68 lines (67 loc) • 3.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectBranch = void 0;
const utils_1 = require("../../eas-update/utils");
const BranchQuery_1 = require("../../graphql/queries/BranchQuery");
const relay_1 = require("../../utils/relay");
/**
* Select a branch for the project.
*
* @constructor
* @param {function} options.filterPredicate - A predicate to filter the branches that are shown to the user. It takes a branchInfo object as a parameter and returns a boolean.
* @param {string} options.printedType - The type of branch printed to the user. Defaults to 'branch'.
* @param {number} options.pageSize - The number of branches to show per page. Defaults to 100.
* @param {function} options.beforeEachFilterQuery Optional. If a filter predicate was specified, this callback function will be called before each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @param {function} options.afterEachFilterQuery Optional. If a filter predicate was specified, this callback function will be called after each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @args willFetchAgain If the query will fetch again to get a complete page.
*/
class SelectBranch {
options;
constructor(options = {}) {
this.options = options;
}
async queryAsync(ctx, queryParams) {
const { graphqlClient, app } = ctx;
const { projectId } = app;
return await BranchQuery_1.BranchQuery.listBranchesBasicInfoPaginatedOnAppAsync(graphqlClient, {
appId: projectId,
...queryParams,
});
}
async filterQueryAsync(ctx, queryParams, filterPredicate) {
const queryAsync = async (queryParams) => await this.queryAsync(ctx, queryParams);
return await relay_1.FilterPagination.getPageAsync({
queryParams,
queryAsync,
filterPredicate,
beforeEachQuery: this.options.beforeEachFilterQuery,
afterEachQuery: this.options.afterEachFilterQuery,
});
}
async runAsync(ctx) {
const { nonInteractive } = ctx;
const { filterPredicate } = this.options;
const printedType = this.options.printedType ?? 'branch';
const pageSize = this.options.pageSize ?? 100;
if (nonInteractive) {
throw new utils_1.NonInteractiveError(`${printedType} selection cannot be run in non-interactive mode.`);
}
const queryAsync = async (queryParams) => filterPredicate
? await this.filterQueryAsync(ctx, queryParams, filterPredicate)
: await this.queryAsync(ctx, queryParams);
const getTitleAsync = async (branchInfo) => branchInfo.name;
return await (0, relay_1.selectPaginatedAsync)({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
}
}
exports.SelectBranch = SelectBranch;
;