@inweb/client 25.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +70 -0
  3. package/dist/client.js +21126 -0
  4. package/dist/client.js.map +1 -0
  5. package/dist/client.min.js +1 -0
  6. package/dist/client.module.js +7151 -0
  7. package/dist/client.module.js.map +1 -0
  8. package/lib/Api/Assembly.d.ts +339 -0
  9. package/lib/Api/ClashTest.d.ts +176 -0
  10. package/lib/Api/Client.d.ts +452 -0
  11. package/lib/Api/ClientEvents.d.ts +29 -0
  12. package/lib/Api/File.d.ts +568 -0
  13. package/lib/Api/HttpClient.d.ts +13 -0
  14. package/lib/Api/IAssembly.d.ts +14 -0
  15. package/lib/Api/IFile.d.ts +46 -0
  16. package/lib/Api/IHttpClient.d.ts +11 -0
  17. package/lib/Api/IUser.d.ts +11 -0
  18. package/lib/Api/Job.d.ts +142 -0
  19. package/lib/Api/Member.d.ts +85 -0
  20. package/lib/Api/Model.d.ts +147 -0
  21. package/lib/Api/Permission.d.ts +93 -0
  22. package/lib/Api/Project.d.ts +247 -0
  23. package/lib/Api/Role.d.ts +82 -0
  24. package/lib/Api/User.d.ts +197 -0
  25. package/lib/Api/impl/FetchError.d.ts +18 -0
  26. package/lib/Api/impl/Utils.d.ts +33 -0
  27. package/lib/Api/impl/http.d.ts +67 -0
  28. package/lib/ConvetMath.d.ts +29 -0
  29. package/lib/Viewer/CanvasEvents.d.ts +2 -0
  30. package/lib/Viewer/Commands/ApplyModelTransform.d.ts +2 -0
  31. package/lib/Viewer/Commands/ClearMarkup.d.ts +2 -0
  32. package/lib/Viewer/Commands/ClearSlices.d.ts +2 -0
  33. package/lib/Viewer/Commands/CreatePreview.d.ts +2 -0
  34. package/lib/Viewer/Commands/Explode.d.ts +2 -0
  35. package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +2 -0
  36. package/lib/Viewer/Commands/GetModels.d.ts +2 -0
  37. package/lib/Viewer/Commands/GetSelected.d.ts +2 -0
  38. package/lib/Viewer/Commands/HideSelected.d.ts +2 -0
  39. package/lib/Viewer/Commands/IsolateSelected.d.ts +2 -0
  40. package/lib/Viewer/Commands/RegenerateAll.d.ts +2 -0
  41. package/lib/Viewer/Commands/ResetView.d.ts +2 -0
  42. package/lib/Viewer/Commands/SelectModel.d.ts +2 -0
  43. package/lib/Viewer/Commands/SetActiveDragger.d.ts +2 -0
  44. package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +2 -0
  45. package/lib/Viewer/Commands/SetMarkupColor.d.ts +2 -0
  46. package/lib/Viewer/Commands/SetSelected.d.ts +2 -0
  47. package/lib/Viewer/Commands/ShowAll.d.ts +2 -0
  48. package/lib/Viewer/Commands/Unselect.d.ts +2 -0
  49. package/lib/Viewer/Commands/ZoomToExtents.d.ts +2 -0
  50. package/lib/Viewer/Commands/ZoomToObjects.d.ts +2 -0
  51. package/lib/Viewer/Commands/ZoomToSelected.d.ts +2 -0
  52. package/lib/Viewer/Commands.d.ts +3 -0
  53. package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +22 -0
  54. package/lib/Viewer/Draggers/Actions/PanAction.d.ts +18 -0
  55. package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +8 -0
  56. package/lib/Viewer/Draggers/Common/Geometry.d.ts +115 -0
  57. package/lib/Viewer/Draggers/Common/GestureManager.d.ts +41 -0
  58. package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +54 -0
  59. package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +30 -0
  60. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +31 -0
  61. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +20 -0
  62. package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +24 -0
  63. package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +27 -0
  64. package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +8 -0
  65. package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +8 -0
  66. package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +8 -0
  67. package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +15 -0
  68. package/lib/Viewer/Draggers/OdPanDragger.d.ts +12 -0
  69. package/lib/Viewer/Draggers/OdZoomDragger.d.ts +12 -0
  70. package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +11 -0
  71. package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +19 -0
  72. package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +14 -0
  73. package/lib/Viewer/Draggers/OdaLineDragger.d.ts +15 -0
  74. package/lib/Viewer/Draggers/OdaTextDragger.d.ts +16 -0
  75. package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +30 -0
  76. package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +19 -0
  77. package/lib/Viewer/EventEmitter2.d.ts +54 -0
  78. package/lib/Viewer/ICommands.d.ts +25 -0
  79. package/lib/Viewer/IEventEmitter2.d.ts +13 -0
  80. package/lib/Viewer/IViewer.d.ts +27 -0
  81. package/lib/Viewer/Loaders/BaseLoader.d.ts +11 -0
  82. package/lib/Viewer/Loaders/LoaderFactory.d.ts +10 -0
  83. package/lib/Viewer/Loaders/TCSLoader.d.ts +5 -0
  84. package/lib/Viewer/Loaders/UpdaterController.d.ts +15 -0
  85. package/lib/Viewer/Loaders/VsfXLoader.d.ts +5 -0
  86. package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +5 -0
  87. package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +12 -0
  88. package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +5 -0
  89. package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +15 -0
  90. package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +15 -0
  91. package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +11 -0
  92. package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +12 -0
  93. package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +15 -0
  94. package/lib/Viewer/Markup/Api/IMarkupText.d.ts +13 -0
  95. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +32 -0
  96. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -0
  97. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -0
  98. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +32 -0
  99. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -0
  100. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -0
  101. package/lib/Viewer/Markup/IMarkup.d.ts +38 -0
  102. package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +63 -0
  103. package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +19 -0
  104. package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +33 -0
  105. package/lib/Viewer/Markup/MarkupFactory.d.ts +7 -0
  106. package/lib/Viewer/Options.d.ts +228 -0
  107. package/lib/Viewer/OptionsEvents.d.ts +26 -0
  108. package/lib/Viewer/Viewer.d.ts +353 -0
  109. package/lib/Viewer/ViewerCommands.d.ts +23 -0
  110. package/lib/Viewer/ViewerEvents.d.ts +601 -0
  111. package/lib/Viewer/utils.d.ts +4 -0
  112. package/lib/index.d.ts +24 -0
  113. package/package.json +32 -0
  114. package/src/Api/Assembly.ts +678 -0
  115. package/src/Api/ClashTest.ts +290 -0
  116. package/src/Api/Client.ts +816 -0
  117. package/src/Api/ClientEvents.ts +31 -0
  118. package/src/Api/File.ts +962 -0
  119. package/src/Api/HttpClient.ts +73 -0
  120. package/src/Api/IAssembly.ts +37 -0
  121. package/src/Api/IFile.ts +74 -0
  122. package/src/Api/IHttpClient.ts +50 -0
  123. package/src/Api/IUser.ts +33 -0
  124. package/src/Api/Job.ts +253 -0
  125. package/src/Api/Member.ts +161 -0
  126. package/src/Api/Model.ts +259 -0
  127. package/src/Api/Permission.ts +173 -0
  128. package/src/Api/Project.ts +479 -0
  129. package/src/Api/Role.ts +158 -0
  130. package/src/Api/User.ts +357 -0
  131. package/src/Api/impl/FetchError.ts +48 -0
  132. package/src/Api/impl/Utils.ts +367 -0
  133. package/src/Api/impl/http.ts +92 -0
  134. package/src/ConvetMath.ts +372 -0
  135. package/src/Viewer/CanvasEvents.ts +41 -0
  136. package/src/Viewer/Commands/ApplyModelTransform.ts +70 -0
  137. package/src/Viewer/Commands/ClearMarkup.ts +28 -0
  138. package/src/Viewer/Commands/ClearSlices.ts +27 -0
  139. package/src/Viewer/Commands/CreatePreview.ts +33 -0
  140. package/src/Viewer/Commands/Explode.ts +38 -0
  141. package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -0
  142. package/src/Viewer/Commands/GetModels.ts +43 -0
  143. package/src/Viewer/Commands/GetSelected.ts +58 -0
  144. package/src/Viewer/Commands/HideSelected.ts +37 -0
  145. package/src/Viewer/Commands/IsolateSelected.ts +37 -0
  146. package/src/Viewer/Commands/RegenerateAll.ts +37 -0
  147. package/src/Viewer/Commands/ResetView.ts +43 -0
  148. package/src/Viewer/Commands/SelectModel.ts +52 -0
  149. package/src/Viewer/Commands/SetActiveDragger.ts +29 -0
  150. package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -0
  151. package/src/Viewer/Commands/SetMarkupColor.ts +29 -0
  152. package/src/Viewer/Commands/SetSelected.ts +47 -0
  153. package/src/Viewer/Commands/ShowAll.ts +37 -0
  154. package/src/Viewer/Commands/Unselect.ts +37 -0
  155. package/src/Viewer/Commands/ZoomToExtents.ts +43 -0
  156. package/src/Viewer/Commands/ZoomToObjects.ts +47 -0
  157. package/src/Viewer/Commands/ZoomToSelected.ts +39 -0
  158. package/src/Viewer/Commands.ts +81 -0
  159. package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -0
  160. package/src/Viewer/Draggers/Actions/PanAction.ts +102 -0
  161. package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -0
  162. package/src/Viewer/Draggers/Common/Geometry.ts +152 -0
  163. package/src/Viewer/Draggers/Common/GestureManager.ts +263 -0
  164. package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -0
  165. package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -0
  166. package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -0
  167. package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -0
  168. package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -0
  169. package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -0
  170. package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -0
  171. package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -0
  172. package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -0
  173. package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -0
  174. package/src/Viewer/Draggers/OdPanDragger.ts +62 -0
  175. package/src/Viewer/Draggers/OdZoomDragger.ts +59 -0
  176. package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -0
  177. package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -0
  178. package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -0
  179. package/src/Viewer/Draggers/OdaLineDragger.ts +80 -0
  180. package/src/Viewer/Draggers/OdaTextDragger.ts +118 -0
  181. package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -0
  182. package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -0
  183. package/src/Viewer/EventEmitter2.ts +116 -0
  184. package/src/Viewer/ICommands.ts +53 -0
  185. package/src/Viewer/IEventEmitter2.ts +36 -0
  186. package/src/Viewer/IViewer.ts +55 -0
  187. package/src/Viewer/Loaders/BaseLoader.ts +40 -0
  188. package/src/Viewer/Loaders/LoaderFactory.ts +44 -0
  189. package/src/Viewer/Loaders/TCSLoader.ts +82 -0
  190. package/src/Viewer/Loaders/UpdaterController.ts +36 -0
  191. package/src/Viewer/Loaders/VsfXLoader.ts +87 -0
  192. package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -0
  193. package/src/Viewer/Markup/Api/IMarkupArrow.ts +15 -0
  194. package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -0
  195. package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -0
  196. package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -0
  197. package/src/Viewer/Markup/Api/IMarkupLine.ts +10 -0
  198. package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -0
  199. package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -0
  200. package/src/Viewer/Markup/Api/IMarkupText.ts +12 -0
  201. package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +119 -0
  202. package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +113 -0
  203. package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +121 -0
  204. package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +99 -0
  205. package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +113 -0
  206. package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +104 -0
  207. package/src/Viewer/Markup/IMarkup.ts +39 -0
  208. package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +872 -0
  209. package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -0
  210. package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +273 -0
  211. package/src/Viewer/Markup/MarkupFactory.ts +32 -0
  212. package/src/Viewer/Options.ts +502 -0
  213. package/src/Viewer/OptionsEvents.ts +28 -0
  214. package/src/Viewer/Viewer.ts +1109 -0
  215. package/src/Viewer/ViewerCommands.ts +45 -0
  216. package/src/Viewer/ViewerEvents.ts +700 -0
  217. package/src/Viewer/utils.ts +74 -0
  218. package/src/index.ts +48 -0
@@ -0,0 +1,962 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2023, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { IHttpClient } from "./IHttpClient";
25
+ import { IFileStatus, IFileReferences, IFileVersionInfo } from "./IFile";
26
+ import { IShortUserDescription } from "./IUser";
27
+ import { Model } from "./Model";
28
+ import { Permission } from "./Permission";
29
+ import { Job } from "./Job";
30
+ import {
31
+ json,
32
+ text,
33
+ downloadProgress,
34
+ downloadPartOfFile,
35
+ waitFor,
36
+ parseArgs,
37
+ userFullName,
38
+ userInitials,
39
+ } from "./impl/Utils";
40
+
41
+ /**
42
+ * The class representing a `file` entity.
43
+ */
44
+ export class File {
45
+ private _data: any;
46
+ private _useVersion: number | undefined;
47
+ public httpClient: IHttpClient;
48
+ public path: string;
49
+
50
+ /**
51
+ * @param data - An object that implements file data storage.
52
+ * @param httpClient - Http client for API.
53
+ */
54
+ constructor(data: any, httpClient: IHttpClient) {
55
+ this.path = `/files/${data.id}`;
56
+ this.httpClient = httpClient;
57
+ this.data = data;
58
+ }
59
+
60
+ private appendVersionParam(relativePath: string): string {
61
+ if (this._useVersion === undefined) return relativePath;
62
+
63
+ const delimiter = relativePath.includes("?") ? "&" : "?";
64
+ return `${relativePath}${delimiter}version=${this._useVersion}`;
65
+ }
66
+
67
+ private internalGet(relativePath: string, signal?: AbortSignal) {
68
+ relativePath = this.appendVersionParam(relativePath);
69
+ return this.httpClient.get(`${this.path}${relativePath}`, signal);
70
+ }
71
+
72
+ private internalPost(
73
+ relativePath: string,
74
+ body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
75
+ ) {
76
+ relativePath = this.appendVersionParam(relativePath);
77
+ return this.httpClient.post(`${this.path}${relativePath}`, body);
78
+ }
79
+
80
+ private internalPut(
81
+ relativePath: string,
82
+ body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
83
+ ) {
84
+ relativePath = this.appendVersionParam(relativePath);
85
+ return this.httpClient.put(`${this.path}${relativePath}`, body);
86
+ }
87
+
88
+ private internalDelete(relativePath: string) {
89
+ relativePath = this.appendVersionParam(relativePath);
90
+ return this.httpClient.delete(`${this.path}${relativePath}`);
91
+ }
92
+
93
+ async partialDownloadResource(
94
+ dataId: string,
95
+ onProgress?: (progress: number, downloaded: Uint8Array) => void,
96
+ signal?: AbortSignal
97
+ ) {
98
+ let pathname = `${this.path}/downloads/${dataId}`;
99
+ pathname = this.appendVersionParam(pathname);
100
+
101
+ // TODO: replace with $get to handle fetch errors
102
+ const response = await fetch(`${this.httpClient.serverUrl}${pathname}`, {
103
+ headers: this.httpClient.headers,
104
+ signal,
105
+ });
106
+
107
+ // TODO: use ReadableStream pipeTo()
108
+ const contentLength = response.headers.get("Content-Length") ?? "";
109
+ const total = parseInt(contentLength, 10);
110
+ const reader = response.body.getReader();
111
+ let loaded = 0;
112
+ while (true) {
113
+ const { done, value } = await reader.read();
114
+ if (done) break;
115
+ loaded += value.byteLength;
116
+ if (typeof onProgress === "function") onProgress(loaded / total, value);
117
+ }
118
+ }
119
+
120
+ downloadFileRange(
121
+ requestId: number,
122
+ records: any | null,
123
+ dataId: string,
124
+ onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void,
125
+ signal?: AbortSignal
126
+ ) {
127
+ let pathname = `${this.path}/downloads/${dataId}?requestId=${requestId}`;
128
+ pathname = this.appendVersionParam(pathname);
129
+ return downloadPartOfFile(
130
+ requestId,
131
+ records,
132
+ `${this.httpClient.serverUrl}${pathname}`,
133
+ this.httpClient.headers,
134
+ onProgress,
135
+ signal
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Active version number of the file.
141
+ *
142
+ * @readonly
143
+ */
144
+ get activeVersion(): number {
145
+ return this.data.activeVersion;
146
+ }
147
+
148
+ /**
149
+ * File creation time (UTC) in the format specified in <a
150
+ * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
151
+ *
152
+ * @readonly
153
+ */
154
+ get created(): string {
155
+ return this.data.created;
156
+ }
157
+
158
+ /**
159
+ * File custom fields object, to store custom data.
160
+ *
161
+ * @readonly
162
+ */
163
+ get customFields(): any {
164
+ return this.data.customFields;
165
+ }
166
+
167
+ set customFields(value: any) {
168
+ this.data.customFields = value;
169
+ }
170
+
171
+ /**
172
+ * Raw file data received from the server.
173
+ *
174
+ * @readonly
175
+ */
176
+ get data(): any {
177
+ return this._data;
178
+ }
179
+
180
+ private set data(value: any) {
181
+ this._data = value;
182
+ this._data.previewUrl = value.preview ? `${this.httpClient.serverUrl}${this.path}/preview` : "";
183
+ // owner since 24.8
184
+ if (typeof this._data.owner === "string") this._data.owner = { userId: this._data.owner };
185
+ this._data.owner ??= {};
186
+ this._data.owner.avatarUrl = `${this.httpClient.serverUrl}/users/${this._data.owner.userId}/avatar`;
187
+ this._data.owner.fullName = userFullName(this._data.owner);
188
+ this._data.owner.initials = userInitials(this._data.owner.fullName);
189
+ // status since 24.9
190
+ this._data.status ??= {};
191
+ this._data.status.geometry ??= { state: this._data.geometryStatus ?? "none" };
192
+ this._data.status.properties ??= { state: this._data.propertiesStatus ?? "none" };
193
+ this._data.status.validation ??= { state: this._data.validationStatus ?? "none" };
194
+ // updatedBy since 24.10
195
+ this._data.updatedBy ??= {};
196
+ this._data.updatedBy.avatarUrl = `${this.httpClient.serverUrl}/users/${this._data.updatedBy.userId}/avatar`;
197
+ this._data.updatedBy.fullName = userFullName(this._data.updatedBy);
198
+ this._data.updatedBy.initials = userInitials(this._data.updatedBy.fullName);
199
+ // geometryGltf status since 24.12
200
+ this._data.status.geometryGltf ??= { state: "none" };
201
+ }
202
+
203
+ /**
204
+ * Returns a list of formats in which the active version of the file was exported. To export
205
+ * file to one of the supported formats create File Converter job using
206
+ * {@link File.createJob()}. To download exported file use {@link File.downloadResource()}.
207
+ *
208
+ * @readonly
209
+ */
210
+ get exports(): string[] {
211
+ return this.data.exports;
212
+ }
213
+
214
+ /**
215
+ * Geometry data type of the active file version. Can be one of:
216
+ *
217
+ * - `vsfx` - `VSFX`, file can be opened in `VisualizeJS` viewer.
218
+ * - `gltf` - `glTF`, file can be opened in `Three.js` viewer.
219
+ *
220
+ * Returns an empty string if geometry data has not yet been extracted. A files without
221
+ * geometry data can be exported to other formas, but cannot be opened in viewer.
222
+ */
223
+ get geometryType(): string {
224
+ if (this.status.geometryGltf.state === "done") return "gltf";
225
+ else if (this.status.geometry.state === "done") return "vsfx";
226
+ else return "";
227
+ }
228
+
229
+ /**
230
+ * Unique file ID.
231
+ *
232
+ * @readonly
233
+ */
234
+ get id(): string {
235
+ return this.data.id;
236
+ }
237
+
238
+ /**
239
+ * File name, including the extension.
240
+ */
241
+ get name(): string {
242
+ return this.data.name;
243
+ }
244
+
245
+ set name(value: string) {
246
+ this.data.name = value;
247
+ }
248
+
249
+ /**
250
+ * If the file is a version, then returns the ID of the original file. Otherwise, returns the file ID.
251
+ *
252
+ * @readonly
253
+ */
254
+ get originalFileId(): string {
255
+ return this.data.originalFileId;
256
+ }
257
+
258
+ /**
259
+ * File owner information.
260
+ *
261
+ * @property {string} userId - User ID.
262
+ * @property {string} userName - User name.
263
+ * @property {string} name - First name.
264
+ * @property {string} lastName - Last name.
265
+ * @property {string} fullName - Full name.
266
+ * @property {string} initials - Initials.
267
+ * @property {string} email - User email.
268
+ * @property {string} avatarUrl - User avatar image URL.
269
+ * @readonly
270
+ */
271
+ get owner(): IShortUserDescription {
272
+ return this.data.owner;
273
+ }
274
+
275
+ /**
276
+ * File preview image URL. Use {@link File#setPreview | setPreview()} to change preview image.
277
+ *
278
+ * @readonly
279
+ */
280
+ get previewUrl(): string {
281
+ return this.data.previewUrl;
282
+ }
283
+
284
+ /**
285
+ * The size of the active version of the file in bytes.
286
+ *
287
+ * @readonly
288
+ */
289
+ get size(): number {
290
+ return this.data.size;
291
+ }
292
+
293
+ /**
294
+ * Total size of all versions of the file in the storage in bytes.
295
+ *
296
+ * @readonly
297
+ */
298
+ get sizeTotal(): number {
299
+ return this.data.sizeTotal;
300
+ }
301
+
302
+ /**
303
+ * Data status of the active version of the file. Contains:
304
+ *
305
+ * - `geometry` - status of geometry data of `VSFX` type.
306
+ * - `geometryGltf` - status of geometry data of `glTF` type.
307
+ * - `properties` - status of properties.
308
+ * - `validation` - status of validation.
309
+ *
310
+ * Each status entity is a record with properties:
311
+ *
312
+ * - `state` - Data state. Can be `none`, `waiting`, `inprogress`, `done` or `failed`.
313
+ * - `jobId` - Unique ID of the data job.
314
+ *
315
+ * @readonly
316
+ */
317
+ get status(): IFileStatus {
318
+ return this.data.status;
319
+ }
320
+
321
+ /**
322
+ * File type, matches the file extension.
323
+ *
324
+ * @readonly
325
+ */
326
+ get type(): string {
327
+ return this.data.type;
328
+ }
329
+
330
+ /**
331
+ * File last update time (UTC) in the format specified in <a
332
+ * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
333
+ *
334
+ * @readonly
335
+ */
336
+ get updatedAt(): string {
337
+ return this.data.updatedAt;
338
+ }
339
+
340
+ /**
341
+ * Information about the user who made the last update.
342
+ *
343
+ * @property {string} userId - User ID.
344
+ * @property {string} userName - User name.
345
+ * @property {string} name - First name.
346
+ * @property {string} lastName - Last name.
347
+ * @property {string} fullName - Full name.
348
+ * @property {string} initials - Initials.
349
+ * @property {string} email - User email.
350
+ * @property {string} avatarUrl - User avatar image URL.
351
+ * @readonly
352
+ */
353
+ get updatedBy(): IShortUserDescription {
354
+ return this.data.updatedBy;
355
+ }
356
+
357
+ /**
358
+ * Zero-based file version number for version files. The original file has version `0`.
359
+ */
360
+
361
+ get version(): number {
362
+ return this.data.version;
363
+ }
364
+
365
+ /**
366
+ * List of the file versions.
367
+ *
368
+ * @readonly
369
+ */
370
+ get versions(): IFileVersionInfo[] {
371
+ return this.data.versions;
372
+ }
373
+
374
+ /**
375
+ * Refresh file data.
376
+ *
377
+ * @async
378
+ */
379
+ async checkout(): Promise<File> {
380
+ this.data = await json(this.internalGet(""));
381
+ return this;
382
+ }
383
+
384
+ /**
385
+ * Update file data on the server.
386
+ *
387
+ * @async
388
+ * @param data - Raw file data.
389
+ */
390
+ async update(data: any): Promise<File> {
391
+ this.data = await json(this.internalPut("", data));
392
+ return this;
393
+ }
394
+
395
+ /**
396
+ * Delete the file and all its versions from the server.
397
+ *
398
+ * @async
399
+ * @returns Returns the raw data of a deleted file.
400
+ */
401
+ delete(): Promise<any> {
402
+ return json(this.internalDelete(""));
403
+ }
404
+
405
+ /**
406
+ * Save file data changes to the server. Call this method to update file data on the server
407
+ * after any changes.
408
+ *
409
+ * @async
410
+ */
411
+ save(): Promise<File> {
412
+ return this.update(this.data);
413
+ }
414
+
415
+ /**
416
+ * Set or remove the file preview.
417
+ *
418
+ * @async
419
+ * @param image - Preview image. Can be a <a
420
+ * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
421
+ * target="_blank">Data URL</a> string, <a
422
+ * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"
423
+ * target="_blank">ArrayBuffer</a>, <a
424
+ * href="https://developer.mozilla.org/docs/Web/API/Blob/Blob" target="_blank">Blob</a> or
425
+ * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
426
+ * target="_blank">File</a> object. Setting the `image` to `null` will remove the preview.
427
+ */
428
+ async setPreview(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<File> {
429
+ if (image) {
430
+ this.data = await json(this.internalPost("/preview", image));
431
+ } else {
432
+ this.data = await json(this.internalDelete("/preview"));
433
+ }
434
+ return this;
435
+ }
436
+
437
+ /**
438
+ * Returns a list of models of the active version of the file.
439
+ *
440
+ * @async
441
+ */
442
+ getModels(): Promise<Model[]> {
443
+ return json(this.internalGet("/geometry")).then((array) => array.map((data) => new Model(data, this)));
444
+ }
445
+
446
+ // File does not support model transformation.
447
+
448
+ getModelTransformMatrix(handle: string): any {
449
+ return undefined;
450
+ }
451
+
452
+ setModelTransformMatrix(handle: string, transform: any): Promise<File> {
453
+ console.warn("File does not support model transformation");
454
+ return Promise.resolve(this);
455
+ }
456
+
457
+ /**
458
+ * Object properties.
459
+ *
460
+ * @typedef {any} Properties
461
+ * @property {string} handle - Object original handle.
462
+ * @property {string | any} * - Object property. Can be `any` for nested properties.
463
+ */
464
+
465
+ /**
466
+ * Returns the properties for an objects in the active version of the file.
467
+ *
468
+ * @async
469
+ * @param handles - Object original handle or handles array. Leave this parameter `undefined`
470
+ * to get properties for all objects in the file.
471
+ */
472
+ getProperties(handles?: string | string[]): Promise<any[]> {
473
+ return json(this.internalGet(handles !== undefined ? `/properties?handles=${handles}` : "/properties"));
474
+ }
475
+
476
+ /**
477
+ * Search pattern.
478
+ *
479
+ * @typedef {any} SearchPattern
480
+ * @property {string} key - Property name.
481
+ * @property {string} value - Property value.
482
+ */
483
+
484
+ /**
485
+ * Query operator. Operator name can be `$and`, `$or`, `$not`, `$eq`, `$regex`.
486
+ *
487
+ * @typedef {any} QueryOperator
488
+ * @property {string | SearchPattern[] | QueryOperator[]} * - Array of the query values or
489
+ * patterns for operator.
490
+ */
491
+
492
+ /**
493
+ * Returns the list of original handles for an objects in the active version of the file that
494
+ * match the specified patterns. Search patterns may be combined using query operators.
495
+ *
496
+ * @async
497
+ * @example <caption>Simple search pattern.</caption>
498
+ * searchPattern = {
499
+ * key: "Category",
500
+ * value: "OST_Stairs",
501
+ * };
502
+ *
503
+ * @example <caption>Search patterns combination.</caption>
504
+ * searchPattern = {
505
+ * $or: [
506
+ * {
507
+ * $and: [
508
+ * { key: "Category", value: "OST_GenericModel" },
509
+ * { key: "Level", value: "03 - Floor" },
510
+ * ],
511
+ * },
512
+ * { key: "Category", value: "OST_Stairs" },
513
+ * ],
514
+ * };
515
+ *
516
+ * @param {SearchPattern | QueryOperator} searchPattern - Search pattern or combination of
517
+ * the patterns, see example below.
518
+ * @returns {Promise<Properties[]>}
519
+ */
520
+
521
+ searchProperties(searchPattern: any): Promise<any[]> {
522
+ return json(this.internalPost("/properties/search", searchPattern));
523
+ }
524
+
525
+ /**
526
+ * Returns the cda.json for an active version of the file.
527
+ *
528
+ * @async
529
+ */
530
+ getCdaTree(): Promise<any[]> {
531
+ return json(this.internalGet(`/properties/tree`));
532
+ }
533
+
534
+ /**
535
+ * Returns a list of file viewpoints.
536
+ *
537
+ * @async
538
+ */
539
+ getViewpoints(): Promise<any[]> {
540
+ return json(this.internalGet("/viewpoints")).then((viewpoints) => viewpoints.result);
541
+ }
542
+
543
+ /**
544
+ * Add new file viewpoint. To create a new viewpoint use
545
+ * {@link Viewer#createViewpoint | Viewer.createViewpoint()}.
546
+ *
547
+ * @async
548
+ * @param viewpoint - Viewpoint.
549
+ */
550
+ saveViewpoint(viewpoint: any): Promise<any> {
551
+ return json(this.internalPost("/viewpoints", viewpoint));
552
+ }
553
+
554
+ /**
555
+ * Delete file viewpoint.
556
+ *
557
+ * @async
558
+ * @param guid - Viewpoint GUID.
559
+ * @returns Returns the raw data of a deleted viewpoint.
560
+ */
561
+ deleteViewpoint(guid: string): Promise<any> {
562
+ return json(this.internalDelete(`/viewpoints/${guid}`));
563
+ }
564
+
565
+ /**
566
+ * Returns viewpoint preview image as <a
567
+ * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
568
+ * target="_blank">Data URL</a>.
569
+ *
570
+ * @async
571
+ * @param guid - Viewpoint GUID.
572
+ */
573
+ getSnapshot(guid: string): Promise<string> {
574
+ return text(this.internalGet(`/viewpoints/${guid}/snapshot`));
575
+ }
576
+
577
+ /**
578
+ * Returns viewpoint preview data.
579
+ *
580
+ * @async
581
+ * @param guid - Viewpoint GUID.
582
+ * @param bitmapGuid - Bitmap GUID.
583
+ */
584
+ getSnapshotData(guid: string, bitmapGuid: string): Promise<string> {
585
+ return text(this.internalGet(`/viewpoints/${guid}/bitmaps/${bitmapGuid}`));
586
+ }
587
+
588
+ /**
589
+ * Download source of active version of the file.
590
+ *
591
+ * @async
592
+ * @param onProgress - Download progress callback.
593
+ * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
594
+ * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
595
+ * and abort it if desired.
596
+ */
597
+ download(onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer> {
598
+ return this.internalGet(`/downloads`, signal)
599
+ .then((response) => downloadProgress(response, onProgress))
600
+ .then((response) => response.arrayBuffer());
601
+ }
602
+
603
+ /**
604
+ * Download file resource data of the active version of the file, such as exported file.
605
+ *
606
+ * @example <caption>Export file to DWG.</caption>
607
+ * const job = await file.crateJob("dwg");
608
+ * await job.waitForDone();
609
+ * const resourceId = file.exports.find((x) => x.endsWith(".dwg"));
610
+ * const arrayBuffer = await file.downloadResource(resourceId);
611
+ * const blob = new Blob([arrayBuffer]);
612
+ * const fileName = file.name.replace(/\.[^.]+$/, "") + ".dwg";
613
+ * FileSaver.saveAs(blob, fileName);
614
+ *
615
+ * @param dataId - Resource ID.
616
+ * @param onProgress - Download progress callback.
617
+ * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
618
+ * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
619
+ * and abort it if desired.
620
+ */
621
+ downloadResource(
622
+ dataId: string,
623
+ onProgress?: (progress: number) => void,
624
+ signal?: AbortSignal
625
+ ): Promise<ArrayBuffer> {
626
+ return this.internalGet(`/downloads/${dataId}`, signal)
627
+ .then((response) => downloadProgress(response, onProgress))
628
+ .then((response) => response.arrayBuffer());
629
+ }
630
+
631
+ /**
632
+ * Returns a list of references to files used to correct rendering of the current file.
633
+ *
634
+ * @async
635
+ * @param [signal] - An <a
636
+ * href="https://developer.mozilla.org/docs/Web/API/AbortController">AbortController</a>
637
+ * signal object instance, which can be used to abort waiting as desired.
638
+ */
639
+ getReferences(signal?: AbortSignal): Promise<IFileReferences> {
640
+ return json(this.internalGet("/references", signal));
641
+ }
642
+
643
+ /**
644
+ * Set the file references.
645
+ *
646
+ * @async
647
+ * @param references - File references.
648
+ */
649
+ setReferences(references: IFileReferences): Promise<IFileReferences> {
650
+ return json(this.internalPut("/references", references));
651
+ }
652
+
653
+ /**
654
+ * Create a new job for the active version of the file.
655
+ *
656
+ * @async
657
+ * @param outputFormat - The job type. Can be one of:
658
+ *
659
+ * - `geometry` - Extract file geometry data into `VSFX`.
660
+ * - `geometryGltf` - Extract file geometry data into `glTF`.
661
+ * - `properties` - Extract file properties.
662
+ * - `validation` - Validate the file. Only for `IFC`.
663
+ * - `dwg`, `obj`, `gltf`, `glb`, `vsf`, `pdf`, `3dpdf` - Export file to the one of the
664
+ * supported format. Use {@link File.exports | File.exports()} to get the list of
665
+ * completed file exports. Use {@link File.downloadResource | File.downloadResource()}
666
+ * to download the exported file.
667
+ * - Other custom job name. Custom job runner must be registered in the job templates table
668
+ * before creating a job.
669
+ *
670
+ * @param parameters - Parameters for the job runner. Can be given as command line arguments
671
+ * for the File Converter tool in form "--arg=value".
672
+ */
673
+ createJob(outputFormat: string, parameters?: string | object): Promise<Job> {
674
+ const pathname = this.appendVersionParam("/jobs");
675
+ return this.httpClient
676
+ .post(pathname, {
677
+ fileId: this.id,
678
+ outputFormat,
679
+ parameters: parseArgs(parameters),
680
+ })
681
+ .then((response) => response.json())
682
+ .then((data) => new Job(data, this.httpClient));
683
+ }
684
+
685
+ /**
686
+ * Create job to extract geometry data of active version of the file. This is alias to
687
+ * {@link File.createJob | File.createJob("geometry")}.
688
+ *
689
+ * @async
690
+ * @param type - Geometry data type. Can be one of:
691
+ *
692
+ * - `vsfx` - `VSFX` (default), for opening a file in `VisualizeJS` viewer.
693
+ * - `gltf` - `glTF`, for opening a file in `Three.js` viewer.
694
+ *
695
+ * @param parameters - Parameters for the job runner. Can be given as command line arguments
696
+ * for the File Converter tool in form "--arg=value".
697
+ */
698
+ extractGeometry(type?: string, parameters?: string | object): Promise<Job> {
699
+ return this.createJob(type === "gltf" ? "geometryGltf" : "geometry", parameters);
700
+ }
701
+
702
+ /**
703
+ * Create job to extract properties of the active version of the file. This is alias to
704
+ * {@link File.createJob | File.createJob("properties")}.
705
+ *
706
+ * @async
707
+ * @param parameters - Parameters for the job runner. Can be given as command line arguments
708
+ * for the File Converter tool in form "--arg=value".
709
+ */
710
+ extractProperties(parameters?: string | object): Promise<Job> {
711
+ return this.createJob("properties", parameters);
712
+ }
713
+
714
+ /**
715
+ * Create a job to validate the active version of the file. This is alias to
716
+ * {@link File.createJob | File.createJob("validation")}.
717
+ *
718
+ * To get validation report use
719
+ * {@link File.downloadResource | File.downloadResource("validation_report.json")}.
720
+ *
721
+ * @async
722
+ * @param parameters - Parameters for the job runner. Can be given as command line arguments
723
+ * for the File Converter tool in form "--arg=value".
724
+ */
725
+ validate(parameters?: string | object): Promise<Job> {
726
+ return this.createJob("validation", parameters);
727
+ }
728
+
729
+ /**
730
+ * Wait for jobs of the active version of the file to be done. Job is done when it changes to
731
+ * `none`, `done` or `failed` status.
732
+ *
733
+ * @async
734
+ * @param {string | string[]} jobs - Job or job array to wait on. Can be `geometry`,
735
+ * `geometryGltf`, `properties`, `validation`, `dwg`, `obj`, `gltf`, `glb`, `vsf`, `pdf`,
736
+ * `3dpdf` or custom job name.
737
+ * @param {Boolean} [waitAll] - If this parameter is `true`, the function returns when all
738
+ * the specified jobs have done. If `false`, the function returns when any one of the jobs are done.
739
+ * @param {Object} [params] - An object containing waiting parameters.
740
+ * @param {Number} [params.timeout] - The time, in milliseconds that the function should wait
741
+ * jobs. If no one jobs are done during this time, the `TimeoutError` exception will be thrown.
742
+ * @param {Number} [params.interval] - The time, in milliseconds, the function should delay
743
+ * in between checking jobs status.
744
+ * @param {AbortSignal} [params.signal] - An <a
745
+ * href="https://developer.mozilla.org/docs/Web/API/AbortController">AbortController</a>
746
+ * signal object instance, which can be used to abort waiting as desired.
747
+ * @param {function} [params.onCheckout] - Waiting progress callback. Return `true` to cancel waiting.
748
+ * @returns {Promise<File>}
749
+ */
750
+ waitForDone(
751
+ jobs,
752
+ waitAll?: boolean,
753
+ params?: {
754
+ timeout?: number;
755
+ interval?: number;
756
+ signal?: AbortSignal;
757
+ onCheckout?: (file: File, ready: boolean) => boolean;
758
+ }
759
+ ): Promise<this> {
760
+ if (!Array.isArray(jobs)) jobs = [jobs];
761
+ if (waitAll === undefined) waitAll = true;
762
+
763
+ const checkDone = () =>
764
+ this.checkout().then((file) => {
765
+ const readyJobs = jobs.filter((x: string) =>
766
+ ["none", "done", "failed"].includes(file.status[x]?.state ?? "none")
767
+ );
768
+ const ready = waitAll ? readyJobs.length === jobs.length : readyJobs.length > 0;
769
+ const cancel = params?.onCheckout?.(file, ready);
770
+ return cancel || ready;
771
+ });
772
+
773
+ return waitFor(checkDone, params).then(() => this);
774
+ }
775
+
776
+ /**
777
+ * Returns a list of file permissions.
778
+ *
779
+ * @async
780
+ */
781
+ getPermissions(): Promise<Permission[]> {
782
+ return json(this.internalGet("/permissions")).then((array) =>
783
+ array.map((data) => new Permission(data, this.id, this.httpClient))
784
+ );
785
+ }
786
+
787
+ /**
788
+ * Returns the permission information.
789
+ *
790
+ * @async
791
+ * @param permissionId - Permission ID.
792
+ */
793
+ getPermission(permissionId: string): Promise<Permission> {
794
+ return json(this.internalGet(`/permissions/${permissionId}`)).then(
795
+ (data) => new Permission(data, this.id, this.httpClient)
796
+ );
797
+ }
798
+
799
+ /**
800
+ * Create a new file permission.
801
+ *
802
+ * @async
803
+ * @param actions - Actions are allowed to be performed on a file with this permission. See
804
+ * {@link Permission#actions | Permission.actions} for more details.
805
+ * @param grantedTo - A collection of principials that will get access to the file.
806
+ * @param public = false - Specifies whether all users have access to the file or not.
807
+ */
808
+ createPermission(actions: string | string[], grantedTo: any[], _public: boolean): Promise<Permission> {
809
+ return json(
810
+ this.internalPost("/permissions", {
811
+ actions: typeof actions === "string" ? [actions] : actions,
812
+ grantedTo,
813
+ public: _public,
814
+ })
815
+ ).then((data) => new Permission(data, this.id, this.httpClient));
816
+ }
817
+
818
+ /**
819
+ * Delete file permission.
820
+ *
821
+ * @async
822
+ * @param permissionId - Permission ID.
823
+ * @returns Returns the raw data of a deleted permission.
824
+ */
825
+ deletePermission(permissionId: string): Promise<any> {
826
+ return json(this.internalDelete(`/permissions/${permissionId}`));
827
+ }
828
+
829
+ /**
830
+ * Upload the new version of the file to the server and extract the geometry and properties as needed.
831
+ *
832
+ * @async
833
+ * @param file - Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
834
+ * target="_blank">File</a> object are generally retrieved from a <a
835
+ * href="https://developer.mozilla.org/docs/Web/API/FileList" target="_blank">FileList</a>
836
+ * object returned as a result of a user selecting files using the HTML `<input>` element.
837
+ * @param params - An object containing upload parameters.
838
+ * @param params.geometry=true - Create job to extract file geometry data. The geometry data
839
+ * type is the same as the original file.
840
+ * @param params.properties=false - Create job to extract file properties.
841
+ * @param params.waitForDone=false - Wait for geometry and properties jobs to complete.
842
+ * @param params.timeout - The time, in milliseconds that the function should wait jobs. If
843
+ * no one jobs are done during this time, the `TimeoutError` exception will be thrown.
844
+ * @param params.interval - The time, in milliseconds, the function should delay in between
845
+ * checking jobs status.
846
+ * @param params.signal - An <a
847
+ * href="https://developer.mozilla.org/docs/Web/API/AbortController">AbortController</a>
848
+ * signal object instance, which can be used to abort waiting as desired.
849
+ * @param params.onProgress - Upload progress callback.
850
+ */
851
+
852
+ async uploadVersion(
853
+ file: globalThis.File,
854
+ params: {
855
+ geometry?: boolean;
856
+ properties?: boolean;
857
+ waitForDone?: boolean;
858
+ timeout?: number;
859
+ interval?: number;
860
+ signal?: AbortSignal;
861
+ onProgress?: (progress: number, file: globalThis.File) => void;
862
+ } = {
863
+ waitForDone: false,
864
+ }
865
+ ): Promise<File> {
866
+ const result = await this.httpClient
867
+ .postFile(`${this.path}/versions`, file, (progress) => params.onProgress?.(progress, file))
868
+ .then((xhr: XMLHttpRequest) => JSON.parse(xhr.responseText))
869
+ .then((data) => new File(data, this.httpClient));
870
+
871
+ if (params.geometry === undefined && this.geometryType !== "") params.geometry = true;
872
+ if (params.properties === undefined && this.status.properties.state !== "none") params.properties = true;
873
+
874
+ const jobs: string[] = [];
875
+ if (params.geometry) jobs.push((await result.extractGeometry(this.geometryType)).outputFormat);
876
+ if (params.properties) jobs.push((await result.extractProperties()).outputFormat);
877
+ if (params.waitForDone && jobs.length > 0) await result.waitForDone(jobs, true, params);
878
+
879
+ await this.checkout();
880
+
881
+ return result;
882
+ }
883
+
884
+ /**
885
+ * Returns a list of version files.
886
+ *
887
+ * @async
888
+ */
889
+ getVersions(): Promise<File[]> {
890
+ return this.internalGet("/versions")
891
+ .then((response) => response.json())
892
+ .then((files) => files.map((data) => new File(data, this.httpClient)))
893
+ .then((files) => files.map((file) => (file.id == file.originalFileId ? file.useVersion(0) : file)));
894
+ }
895
+
896
+ /**
897
+ * Returns the version file.
898
+ *
899
+ * @async
900
+ * @param version - Desired version.
901
+ */
902
+ getVersion(version: number): Promise<File> {
903
+ return this.internalGet(`/versions/${version}`)
904
+ .then((response) => response.json())
905
+ .then((data) => new File(data, this.httpClient))
906
+ .then((file) => (file.id == file.originalFileId ? file.useVersion(0) : file));
907
+ }
908
+
909
+ /**
910
+ * Delete version file.
911
+ *
912
+ * @async
913
+ * @param version - Version to delete.
914
+ */
915
+ async deleteVersion(version: number): Promise<any> {
916
+ const response = await this.internalDelete(`/versions/${version}`);
917
+ const result = await response.json();
918
+
919
+ await this.checkout();
920
+
921
+ return result;
922
+ }
923
+
924
+ /**
925
+ * Replace the active version of the file with the selected version.
926
+ *
927
+ * @async
928
+ * @param version - Desired active version.
929
+ */
930
+
931
+ setActiveVersion(version: number): Promise<File> {
932
+ return this.update({ activeVersion: version });
933
+ }
934
+
935
+ /**
936
+ * Use given version instead of active version for current file on client side. This version
937
+ * change will affect the result:
938
+ *
939
+ * - getModels()
940
+ * - getProperties()
941
+ * - searchProperties()
942
+ * - getCdaTree()
943
+ * - download()
944
+ * - downloadResource()
945
+ * - createJob()
946
+ * - extractGeometry()
947
+ * - extractProperties()
948
+ * - validate()
949
+ * - waitForDone()
950
+ * - Viewer.open()
951
+ *
952
+ * Other clients will still continue to use the currently active version of the file. Use
953
+ * `undefined` to revert back to the active version.
954
+ *
955
+ * Note. You need to update the file data using [File.checkout()]{@link File#checkout} to
956
+ * match the size and status fields to the version you selected.
957
+ */
958
+ useVersion(version?: number): this {
959
+ this._useVersion = version;
960
+ return this;
961
+ }
962
+ }