-
Notifications
You must be signed in to change notification settings - Fork 208
/
IModelVersion.ts
104 lines (88 loc) · 3.72 KB
/
IModelVersion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module iModels
*/
import { ChangesetId } from "./ChangesetProps";
/** Properties for IModelVersion
* @public
*/
export type IModelVersionProps =
{ first: true, latest?: never, afterChangeSetId?: never, versionName?: never } |
{ latest: true, first?: never, afterChangeSetId?: never, versionName?: never } |
{ afterChangeSetId: string, first?: never, latest?: never, versionName?: never } |
{ versionName: string, first?: never, latest?: never, afterChangeSetId?: never };
/** Option to specify the version of the iModel to be acquired and used
* @public
*/
export class IModelVersion {
private _first?: boolean;
private _latest?: boolean;
private _afterChangeSetId?: string;
private _versionName?: string;
private constructor() { }
/** Describes the first version of the iModel */
public static first(): IModelVersion {
const version = new IModelVersion();
version._first = true;
return version;
}
/** Describes the latest version of the iModel */
public static latest(): IModelVersion {
const version = new IModelVersion();
version._latest = true;
return version;
}
/** Describes a version of the iModel by the last change set that needs
* to be applied or merged to the iModel.
* Note that all ChangeSets up to and and including the specified ChangeSet
* needs to be applied.
* If the changesetId is an empty string, it is assumed to be the first version
* before any change sets have been applied.
*/
public static asOfChangeSet(changesetId: string): IModelVersion {
const version = new IModelVersion();
if (changesetId === "") {
version._first = true;
return version;
}
version._afterChangeSetId = changesetId;
return version;
}
/** Describes a version of the iModel with the specified version name */
public static named(versionName: string): IModelVersion {
const version = new IModelVersion();
version._versionName = versionName;
return version;
}
public toJSON(): IModelVersionProps {
return this._versionName ? { versionName: this._versionName } :
this._afterChangeSetId ? { afterChangeSetId: this._afterChangeSetId } :
this._first ? { first: this._first } :
{ latest: true };
}
/** Creates a version from an IModelVersionProps */
public static fromJSON(json: IModelVersionProps): IModelVersion {
const version = new IModelVersion();
version._first = json.first;
version._afterChangeSetId = json.afterChangeSetId;
version._latest = json.latest;
version._versionName = json.versionName;
return version;
}
/** Returns true if this describes the first version */
public get isFirst(): boolean { return !!this._first; }
/** Returns true if this describes the latest version */
public get isLatest(): boolean { return !!this._latest; }
/** Returns the last change set id to be applied to the iModel
* to get to this specified version. @see asOfChangeSet().
* Note that this method does not attempt to resolve the change set
* if this describes the first version, last version, named version, etc.
* @see evaluateChangeSet() for those use cases.
*/
public getAsOfChangeSet(): ChangesetId | undefined { return this._afterChangeSetId; }
/** Returns the name of the version if this describes a named version. @see named() */
public getName(): string | undefined { return this._versionName; }
}