Skip to content

Commit 35db4d1

Browse files
authored
Expand management apis (#345)
* Move some of the lock and briefcase operations to management client
1 parent 72ef6b2 commit 35db4d1

30 files changed

Lines changed: 842 additions & 593 deletions

File tree

clients/imodels-client-authoring/src/IModelsClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class IModelsClient extends ManagementIModelsClient {
114114
}
115115

116116
/** Lock operations. See {@link LockOperations}. */
117-
public get locks(): LockOperations<OperationOptions> {
117+
public override get locks(): LockOperations<OperationOptions> {
118118
return new LockOperations(this._operationsOptions);
119119
}
120120

clients/imodels-client-authoring/src/base/internal/ApiResponseInterfaces.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,7 @@
22
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
5-
import { CollectionResponse } from "@itwin/imodels-client-management";
6-
7-
import { BaselineFile, Lock } from "../types";
8-
9-
export interface LocksResponse extends CollectionResponse {
10-
locks: Lock[];
11-
}
12-
13-
export interface LockResponse {
14-
lock: Lock;
15-
}
16-
17-
export interface ReleaseLocksChunkResponse {
18-
isLastChunk: boolean;
19-
}
5+
import { BaselineFile } from "../types";
206

217
export interface BaselineFileResponse {
228
baselineFile: BaselineFile;

clients/imodels-client-authoring/src/base/types/apiEntities/LockInterfaces.ts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,9 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
/** Supported Lock levels. */
7-
export enum LockLevel {
8-
/** Objects are not locked. This level is used for releasing already acquired locks. */
9-
None = "none",
10-
/** Multiple Briefcases can acquire a shared lock on the same object. */
11-
Shared = "shared",
12-
/** Only one Briefcase can acquire an exclusive lock on a given object at a time. */
13-
Exclusive = "exclusive",
14-
}
15-
16-
/** A group of locked objects that have the same lock level. */
17-
export interface LockedObjects {
18-
/** Lock level that the objects are locked with. See {@link LockLevel}. */
19-
lockLevel: LockLevel;
20-
/** Locked object ids. */
21-
objectIds: string[];
22-
}
23-
24-
/** Full representation of a Lock. */
25-
export interface Lock {
26-
/** Id of the Briefcase that locks the specified objects. */
27-
briefcaseId: number;
28-
/** Ids of the locked objects grouped by their lock level. See {@link LockedObjects}. */
29-
lockedObjects: LockedObjects[];
30-
}
31-
32-
/** Result of a release Locks chunk operation. */
33-
export interface ReleaseLocksChunkResult {
34-
/** Indicates whether this was the last chunk of Locks to release. */
35-
isLastChunk: boolean;
36-
}
6+
/** @deprecated Import {@link Lock} directly from `@itwin/imodels-client-management` instead. */
7+
export type { Lock } from "@itwin/imodels-client-management";
8+
/** @deprecated Import {@link LockLevel} directly from `@itwin/imodels-client-management` instead. */
9+
export { LockLevel } from "@itwin/imodels-client-management";
10+
/** @deprecated Import {@link LockedObjects} directly from `@itwin/imodels-client-management` instead. */
11+
export type { LockedObjects } from "@itwin/imodels-client-management";

clients/imodels-client-authoring/src/operations/IModelsApiUrlFormatter.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55
import { IModelsApiUrlFormatter as ManamegentIModelsApiUrlFormatter } from "@itwin/imodels-client-management";
66

7-
import { GetLockListUrlParams } from "./lock/LockOperationParams";
8-
97
export class IModelsApiUrlFormatter extends ManamegentIModelsApiUrlFormatter {
108
public getBaselineUrl(params: { iModelId: string }): string {
119
return `${this.baseUrl}/${params.iModelId}/baselinefile`;
1210
}
13-
14-
public getLockListUrl(params: {
15-
iModelId: string;
16-
urlParams?: GetLockListUrlParams;
17-
}): string {
18-
return `${this.baseUrl}/${params.iModelId}/locks${this.formQueryString({
19-
...params.urlParams,
20-
})}`;
21-
}
22-
23-
public getReleaseLocksChunkUrl(params: { iModelId: string }): string {
24-
return `${this.baseUrl}/${params.iModelId}/locks/release-chunk`;
25-
}
2611
}

clients/imodels-client-authoring/src/operations/OperationParamExports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ export * from "./changeset/ChangesetOperationParams";
99
export * from "./changeset-extended-data/ChangesetExtendedDataOperationsParams";
1010
export * from "./changeset-group/ChangesetGroupOperationParams";
1111
export * from "./lock/LockOperationParams";
12+
13+
/** @deprecated Import {@link GetLockListParams} directly from `@itwin/imodels-client-management` instead. */
14+
export type { GetLockListParams } from "@itwin/imodels-client-management";
15+
/** @deprecated Import {@link GetLockListUrlParams} directly from `@itwin/imodels-client-management` instead. */
16+
export type { GetLockListUrlParams } from "@itwin/imodels-client-management";
17+
/** @deprecated Import {@link LockLevelFilter} directly from `@itwin/imodels-client-management` instead. */
18+
export type { LockLevelFilter } from "@itwin/imodels-client-management";
19+
/** @deprecated Import {@link ReleaseBriefcaseParams} directly from `@itwin/imodels-client-management` instead. */
20+
export type { ReleaseBriefcaseParams } from "@itwin/imodels-client-management";

clients/imodels-client-authoring/src/operations/briefcase/BriefcaseOperationParams.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,3 @@ export interface AcquireBriefcaseParams extends IModelScopedOperationParams {
1515
/** Properties of the new Briefcase. */
1616
briefcaseProperties?: BriefcaseProperties;
1717
}
18-
19-
/** Parameters for release Briefcase operation. */
20-
export interface ReleaseBriefcaseParams extends IModelScopedOperationParams {
21-
/** Id of the Briefcase to release. */
22-
briefcaseId: number;
23-
}

clients/imodels-client-authoring/src/operations/briefcase/BriefcaseOperations.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { OperationOptions } from "../OperationOptions";
1313
import {
1414
AcquireBriefcaseParams,
1515
BriefcaseProperties,
16-
ReleaseBriefcaseParams,
1716
} from "./BriefcaseOperationParams";
1817

1918
export class BriefcaseOperations<
@@ -47,24 +46,6 @@ export class BriefcaseOperations<
4746
return result;
4847
}
4948

50-
/**
51-
* Releases the specified Briefcase. Wraps the
52-
* {@link https://developer.bentley.com/apis/imodels-v2/operations/release-imodel-briefcase/ Release iModel Briefcase}
53-
* operation from iModels API.
54-
* @param {ReleaseBriefcaseParams} params parameters for this operation. See {@link ReleaseBriefcaseParams}.
55-
* @returns {Promise<void>} a promise that resolves after operation completes.
56-
*/
57-
public async release(params: ReleaseBriefcaseParams): Promise<void> {
58-
await this.sendDeleteRequest({
59-
authorization: params.authorization,
60-
url: this._options.urlFormatter.getSingleBriefcaseUrl({
61-
iModelId: params.iModelId,
62-
briefcaseId: params.briefcaseId,
63-
}),
64-
headers: params.headers,
65-
});
66-
}
67-
6849
private getAcquireBriefcaseRequestBody(
6950
briefcaseProperties: BriefcaseProperties | undefined
7051
): object | undefined {

clients/imodels-client-authoring/src/operations/lock/LockOperationParams.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,9 @@
22
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
5-
import {
6-
CollectionRequestParams,
7-
IModelScopedOperationParams,
8-
} from "@itwin/imodels-client-management";
5+
import { IModelScopedOperationParams } from "@itwin/imodels-client-management";
96

10-
import { LockLevel, LockedObjects } from "../../base/types";
11-
12-
/** Valid values for Lock filtering by their level. */
13-
export type LockLevelFilter = LockLevel.Shared | LockLevel.Exclusive;
14-
15-
/** Url parameters supported in Lock list query. */
16-
export interface GetLockListUrlParams extends CollectionRequestParams {
17-
/** Filters Locks by a specific Briefcase. */
18-
briefcaseId?: number;
19-
/** Filters Locks by their level. See {@link LockLevelFilter}. */
20-
lockLevel?: LockLevelFilter;
21-
}
22-
23-
/** Parameters for get Lock list operation. */
24-
export interface GetLockListParams extends IModelScopedOperationParams {
25-
/** Parameters that will be appended to the entity list request url that will narrow down the results. */
26-
urlParams?: GetLockListUrlParams;
27-
}
7+
import { LockedObjects } from "../../base/types";
288

299
/** Parameters for update Lock operation. */
3010
export interface UpdateLockParams extends IModelScopedOperationParams {
@@ -39,14 +19,3 @@ export interface UpdateLockParams extends IModelScopedOperationParams {
3919
/** Ids of the locked objects grouped by their lock level. See {@link LockedObjects}. */
4020
lockedObjects: LockedObjects[];
4121
}
42-
43-
/** Parameters for release Locks chunk operation. */
44-
export interface ReleaseLocksChunkParams extends IModelScopedOperationParams {
45-
/** Id of the Briefcase to release Locks for. */
46-
briefcaseId: number;
47-
/**
48-
* Id of the latest Changeset in which the locked object was updated. If this value points to an older Changeset than
49-
* the value saved on the server, the server value will not be updated. It means the lock was abandoned.
50-
*/
51-
changesetId?: string;
52-
}

clients/imodels-client-authoring/src/operations/lock/LockOperations.ts

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,18 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55
import {
6-
EntityListIterator,
7-
EntityListIteratorImpl,
8-
OperationsBase,
6+
Lock,
7+
LockResponse,
8+
LockOperations as ManagementLockOperations,
99
} from "@itwin/imodels-client-management";
1010

11-
import {
12-
LockResponse,
13-
LocksResponse,
14-
ReleaseLocksChunkResponse,
15-
} from "../../base/internal";
16-
import { Lock, ReleaseLocksChunkResult } from "../../base/types";
1711
import { OperationOptions } from "../OperationOptions";
1812

19-
import {
20-
GetLockListParams,
21-
UpdateLockParams,
22-
ReleaseLocksChunkParams,
23-
} from "./LockOperationParams";
13+
import { UpdateLockParams } from "./LockOperationParams";
2414

2515
export class LockOperations<
2616
TOptions extends OperationOptions
27-
> extends OperationsBase<TOptions> {
28-
/**
29-
* Gets Locks for a specific iModel. This method returns Locks in their full representation. The returned iterator
30-
* internally queries entities in pages. Wraps the
31-
* {@link https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-locks/ Get iModel Locks} operation from
32-
* iModels API.
33-
* @param {GetLockListParams} params parameters for this operation. See {@link GetLockListParams}.
34-
* @returns {EntityListIterator<Lock>} iterator for Lock list. See {@link EntityListIterator}, {@link Lock}.
35-
*/
36-
public getList(params: GetLockListParams): EntityListIterator<Lock> {
37-
return new EntityListIteratorImpl(async () =>
38-
this.getEntityCollectionPage<Lock, LocksResponse>({
39-
authorization: params.authorization,
40-
url: this._options.urlFormatter.getLockListUrl({
41-
iModelId: params.iModelId,
42-
urlParams: params.urlParams,
43-
}),
44-
entityCollectionAccessor: (response) => response.body.locks,
45-
headers: params.headers,
46-
})
47-
);
48-
}
49-
17+
> extends ManagementLockOperations<TOptions> {
5018
/**
5119
* Updates Lock for a specific Briefcase. This operation is used to acquire new locks and change the lock level for
5220
* already existing ones. Wraps the {@link https://developer.bentley.com/apis/imodels-v2/operations/update-imodel-locks/
@@ -67,41 +35,11 @@ export class LockOperations<
6735
return updateLockResponse.body.lock;
6836
}
6937

70-
/**
71-
* Releases Locks chunk for a specific Briefcase. This operation is used to release or abandon existing Locks.
72-
* Wraps the {@link https://developer.bentley.com/apis/imodels-v2/operations/release-imodel-locks-chunk/
73-
* Release iModel Locks Chunk} operation from iModels API.
74-
* @param {ReleaseLocksChunkParams} params parameters for this operation. See {@link ReleaseLocksChunkParams}.
75-
* @returns {Promise<ReleaseLocksChunkResult>} result indicating if this was the last chunk. See {@link ReleaseLocksChunkResult}.
76-
*/
77-
public async releaseLocksChunk(
78-
params: ReleaseLocksChunkParams
79-
): Promise<ReleaseLocksChunkResult> {
80-
const releaseLocksChunkBody = this.getReleaseLocksChunkBody(params);
81-
const releaseLocksChunkResponse =
82-
await this.sendPostRequest<ReleaseLocksChunkResponse>({
83-
authorization: params.authorization,
84-
url: this._options.urlFormatter.getReleaseLocksChunkUrl({
85-
iModelId: params.iModelId,
86-
}),
87-
body: releaseLocksChunkBody,
88-
headers: params.headers,
89-
});
90-
return releaseLocksChunkResponse.body;
91-
}
92-
9338
private getUpdateLockBody(params: UpdateLockParams): object {
9439
return {
9540
briefcaseId: params.briefcaseId,
9641
changesetId: params.changesetId,
9742
lockedObjects: params.lockedObjects,
9843
};
9944
}
100-
101-
private getReleaseLocksChunkBody(params: ReleaseLocksChunkParams): object {
102-
return {
103-
briefcaseId: params.briefcaseId,
104-
changesetId: params.changesetId,
105-
};
106-
}
10745
}

clients/imodels-client-management/src/IModelsClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ChangesetOperations,
2323
FavoriteIModelOperations,
2424
IModelOperations,
25+
LockOperations,
2526
NamedVersionOperations,
2627
OperationOperations,
2728
RecentIModelOperations,
@@ -147,6 +148,11 @@ export class IModelsClient {
147148
return new RecentIModelOperations(this._operationsOptions);
148149
}
149150

151+
/** Lock operations. See {@link LockOperations}. */
152+
public get locks(): LockOperations<OperationOptions> {
153+
return new LockOperations(this._operationsOptions);
154+
}
155+
150156
private static fillManagementClientConfiguration(
151157
options: IModelsClientOptions | undefined
152158
): RecursiveRequired<IModelsClientOptions> {

0 commit comments

Comments
 (0)