UNPKG

@itwin/imodels-client-management

Version:

iModels API client wrapper for applications that manage iModels.

136 lines 6.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChangesetOperations = void 0; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ const internal_1 = require("../../base/internal"); const types_1 = require("../../base/types"); const SharedFunctions_1 = require("../SharedFunctions"); class ChangesetOperations extends internal_1.OperationsBase { _iModelsClient; constructor(options, _iModelsClient) { super(options); this._iModelsClient = _iModelsClient; } /** * Gets Changesets for a specific iModel. This method returns Changesets in their minimal representation. The * returned iterator internally queries entities in pages. Wraps the * {@link https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-changesets/ Get iModel Changesets} * operation from iModels API. * @param {GetChangesetListParams} params parameters for this operation. See {@link GetChangesetListParams}. * @returns {EntityListIterator<MinimalChangeset>} iterator for Changeset list. See {@link EntityListIterator}, * {@link MinimalChangeset}. */ getMinimalList(params) { const entityCollectionAccessor = (response) => { const changesets = response.body.changesets; const mappedChangesets = changesets.map((changeset) => this.appendRelatedMinimalEntityCallbacks(params.authorization, changeset, params.headers)); return mappedChangesets; }; return new internal_1.EntityListIteratorImpl(async () => this.getEntityCollectionPage({ authorization: params.authorization, url: this._options.urlFormatter.getChangesetListUrl({ iModelId: params.iModelId, urlParams: params.urlParams, }), preferReturn: types_1.PreferReturn.Minimal, entityCollectionAccessor, headers: params.headers, })); } /** * Gets Changesets for a specific iModel. This method returns Changesets in their full representation. The returned * iterator internally queries entities in pages. Wraps the * {@link https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-changesets/ Get iModel Changesets} * operation from iModels API. * @param {GetChangesetListParams} params parameters for this operation. See {@link GetChangesetListParams}. * @returns {EntityListIterator<Changeset>} iterator for Changeset list. See {@link EntityListIterator}, * {@link Changeset}. */ getRepresentationList(params) { const entityCollectionAccessor = (response) => { const changesets = response.body.changesets; const mappedChangesets = changesets.map((changeset) => this.appendRelatedEntityCallbacks(params.authorization, changeset, params.headers)); return mappedChangesets; }; return new internal_1.EntityListIteratorImpl(async () => this.getEntityCollectionPage({ authorization: params.authorization, url: this._options.urlFormatter.getChangesetListUrl({ iModelId: params.iModelId, urlParams: params.urlParams, }), preferReturn: types_1.PreferReturn.Representation, entityCollectionAccessor, headers: params.headers, })); } /** * Gets a single Changeset identified by either index or id. This method returns a Changeset in its full representation. * Wraps the * {@link https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-changeset-details/ Get iModel Changeset} * operation from iModels API. * @param {GetSingleChangesetParams} params parameters for this operation. See {@link GetSingleChangesetParams}. * @returns {Promise<Changeset>} a Changeset with specified id or index. See {@link Changeset}. */ async getSingle(params) { const changeset = await this.querySingleInternal(params); return changeset; } async querySingleInternal(params) { const { authorization, iModelId, headers, ...changesetIdOrIndex } = params; const response = await this.sendGetRequest({ authorization, url: this._options.urlFormatter.getSingleChangesetUrl({ iModelId, ...changesetIdOrIndex, }), headers, }); const result = this.appendRelatedEntityCallbacks(params.authorization, response.body.changeset, params.headers); return result; } appendRelatedMinimalEntityCallbacks(authorization, changeset, headers) { const getCreator = async () => (0, SharedFunctions_1.getUser)(authorization, this._iModelsClient.users, this._options.urlFormatter, changeset._links.creator?.href, headers); const result = { ...changeset, getCreator, }; return result; } appendRelatedEntityCallbacks(authorization, changeset, headers) { const getNamedVersion = async () => this.getNamedVersion(authorization, changeset._links.namedVersion?.href, headers); const getCurrentOrPrecedingCheckpoint = async () => this.getCurrentOrPrecedingCheckpoint(authorization, changeset._links.currentOrPrecedingCheckpoint?.href, headers); const changesetWithMinimalCallbacks = this.appendRelatedMinimalEntityCallbacks(authorization, changeset, headers); const result = { ...changesetWithMinimalCallbacks, getNamedVersion, getCurrentOrPrecedingCheckpoint, }; return result; } async getNamedVersion(authorization, namedVersionLink, headers) { if (!namedVersionLink) return undefined; const { iModelId, namedVersionId } = this._options.urlFormatter.parseNamedVersionUrl(namedVersionLink); return this._iModelsClient.namedVersions.getSingle({ authorization, iModelId, namedVersionId, headers, }); } async getCurrentOrPrecedingCheckpoint(authorization, currentOrPrecedingCheckpointLink, headers) { if (!currentOrPrecedingCheckpointLink) return undefined; const entityIds = this._options.urlFormatter.parseCheckpointUrl(currentOrPrecedingCheckpointLink); return this._iModelsClient.checkpoints.getSingle({ authorization, ...entityIds, headers, }); } } exports.ChangesetOperations = ChangesetOperations; //# sourceMappingURL=ChangesetOperations.js.map