UNPKG

@itwin/imodels-client-management

Version:

iModels API client wrapper for applications that manage iModels.

99 lines 5.04 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { EntityListIteratorImpl, OperationsBase, } from "../../base/internal"; import { PreferReturn, } from "../../base/types"; import { assertLink, getUser } from "../SharedFunctions"; export class BriefcaseOperations extends OperationsBase { _iModelsClient; constructor(options, _iModelsClient) { super(options); this._iModelsClient = _iModelsClient; } /** * Gets Briefcases of a specific iModel. This method returns Briefcases 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-briefcases/ Get iModel Briefcases} * operation from iModels API. * @param {GetBriefcaseListParams} params parameters for this operation. See {@link GetBriefcaseListParams}. * @returns {EntityListIterator<MinimalBriefcase>} iterator for Briefcase list. See {@link EntityListIterator}, * {@link MinimalBriefcase}. */ getMinimalList(params) { return new EntityListIteratorImpl(async () => this.getEntityCollectionPage({ authorization: params.authorization, url: this._options.urlFormatter.getBriefcaseListUrl({ iModelId: params.iModelId, urlParams: params.urlParams, }), preferReturn: PreferReturn.Minimal, entityCollectionAccessor: (response) => response.body.briefcases, headers: params.headers, })); } /** * Gets Briefcases of a specific iModel. This method returns Briefcases 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-briefcases/ Get iModel Briefcases} * operation from iModels API. * @param {GetBriefcaseListParams} params parameters for this operation. See {@link GetBriefcaseListParams}. * @returns {EntityListIterator<Briefcase>} iterator for Briefcase list. See {@link EntityListIterator}, {@link Briefcase}. */ getRepresentationList(params) { const entityCollectionAccessor = (response) => { const briefcases = response.body.briefcases; const mappedBriefcases = briefcases.map((briefcase) => this.appendRelatedEntityCallbacks(params.authorization, briefcase, params.headers)); return mappedBriefcases; }; return new EntityListIteratorImpl(async () => this.getEntityCollectionPage({ authorization: params.authorization, url: this._options.urlFormatter.getBriefcaseListUrl({ iModelId: params.iModelId, urlParams: params.urlParams, }), preferReturn: PreferReturn.Representation, entityCollectionAccessor, headers: params.headers, })); } /** * Gets a single Briefcase by its id. This method returns a Briefcase in its full representation. Wraps the * {@link https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-briefcase-details/ Get iModel Briefcase} * operation from iModels API. * @param {GetSingleBriefcaseParams} params parameters for this operation. See {@link GetSingleBriefcaseParams}. * @returns {Promise<Briefcase>} an Briefcase with specified id. See {@link iModel}. */ async getSingle(params) { const response = await this.sendGetRequest({ authorization: params.authorization, url: this._options.urlFormatter.getSingleBriefcaseUrl({ iModelId: params.iModelId, briefcaseId: params.briefcaseId, }), headers: params.headers, }); const result = this.appendRelatedEntityCallbacks(params.authorization, response.body.briefcase, params.headers); return result; } appendRelatedEntityCallbacks(authorization, briefcase, headers) { const getOwner = async () => getUser(authorization, this._iModelsClient.users, this._options.urlFormatter, briefcase._links.owner?.href, headers); const checkpointLink = briefcase._links.checkpoint; assertLink(checkpointLink); const getCheckpoint = async () => { const response = await this.sendGetRequest({ authorization, url: checkpointLink.href, headers, }); return response.body.checkpoint; }; const result = { ...briefcase, getOwner, getCheckpoint, }; return result; } } //# sourceMappingURL=BriefcaseOperations.js.map