@inweb/client 25.3.17 → 25.3.18

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 (43) hide show
  1. package/dist/client.js +698 -527
  2. package/dist/client.js.map +1 -1
  3. package/dist/client.min.js +1 -1
  4. package/dist/client.module.js +473 -484
  5. package/dist/client.module.js.map +1 -1
  6. package/lib/Api/Assembly.d.ts +32 -8
  7. package/lib/Api/ClashTest.d.ts +1 -1
  8. package/lib/Api/Client.d.ts +2 -3
  9. package/lib/Api/Fetch.d.ts +6 -0
  10. package/lib/Api/{impl/FetchError.d.ts → FetchError.d.ts} +2 -0
  11. package/lib/Api/File.d.ts +34 -10
  12. package/lib/Api/HttpClient.d.ts +9 -3
  13. package/lib/Api/IHttpClient.d.ts +10 -4
  14. package/lib/Api/Job.d.ts +1 -1
  15. package/lib/Api/Model.d.ts +33 -9
  16. package/lib/Api/Project.d.ts +3 -3
  17. package/lib/Api/User.d.ts +1 -1
  18. package/lib/Api/Utils.d.ts +11 -0
  19. package/lib/Api/XMLHttp.d.ts +7 -0
  20. package/lib/index.d.ts +1 -1
  21. package/package.json +1 -1
  22. package/src/Api/Assembly.ts +76 -70
  23. package/src/Api/ClashTest.ts +10 -19
  24. package/src/Api/Client.ts +92 -56
  25. package/src/Api/Fetch.ts +84 -0
  26. package/src/Api/{impl/http.ts → FetchError.ts} +33 -1
  27. package/src/Api/File.ts +112 -117
  28. package/src/Api/HttpClient.ts +107 -20
  29. package/src/Api/IHttpClient.ts +17 -12
  30. package/src/Api/Job.ts +7 -5
  31. package/src/Api/Member.ts +7 -5
  32. package/src/Api/Model.ts +61 -14
  33. package/src/Api/Permission.ts +6 -5
  34. package/src/Api/Project.ts +93 -88
  35. package/src/Api/Role.ts +6 -5
  36. package/src/Api/User.ts +28 -17
  37. package/src/Api/Utils.ts +104 -0
  38. package/src/Api/XMLHttp.ts +72 -0
  39. package/src/index.ts +1 -1
  40. package/lib/Api/impl/Utils.d.ts +0 -32
  41. package/lib/Api/impl/http.d.ts +0 -66
  42. package/src/Api/impl/FetchError.ts +0 -48
  43. package/src/Api/impl/Utils.ts +0 -367
@@ -18,11 +18,9 @@ export declare class Assembly {
18
18
  constructor(data: any, httpClient: IHttpClient);
19
19
  appendVersionParam(relativePath: string): string;
20
20
  protected internalGet(relativePath: string, signal?: AbortSignal): Promise<Response>;
21
- protected internalPost(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
22
- protected internalPut(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
21
+ protected internalPost(relativePath: string, body?: BodyInit | object): Promise<Response>;
22
+ protected internalPut(relativePath: string, body?: BodyInit | object): Promise<Response>;
23
23
  protected internalDelete(relativePath: string): Promise<Response>;
24
- partialDownloadResource(dataId: string, onProgress?: (progress: number, downloaded: Uint8Array) => void, signal?: AbortSignal): Promise<void>;
25
- downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
26
24
  get activeVersion(): number;
27
25
  /**
28
26
  * List of unique files from which the assembly was created.
@@ -134,7 +132,7 @@ export declare class Assembly {
134
132
  * @async
135
133
  */
136
134
  save(): Promise<Assembly>;
137
- setPreview(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<Awaited<this>>;
135
+ setPreview(image: BodyInit | null): Promise<Awaited<this>>;
138
136
  /**
139
137
  * Returns list of assembly models.
140
138
  *
@@ -219,16 +217,42 @@ export declare class Assembly {
219
217
  getSnapshot(guid: any): Promise<any>;
220
218
  getSnapshotData(guid: any, bitmapGuid: any): Promise<string>;
221
219
  /**
222
- * Download assembly resource data, such as geometry data.
220
+ * Download assembly resource file. Resource files are files that contain model scene
221
+ * descriptions, or geometry data.
223
222
  *
224
223
  * @async
225
- * @param dataId - Resource ID.
224
+ * @param dataId - Resource file name.
226
225
  * @param onProgress - Download progress callback.
227
226
  * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
228
227
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
229
228
  * and abort it if desired.
230
229
  */
231
- downloadResource(dataId: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
230
+ downloadResource(dataId: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
231
+ /**
232
+ * Download a part of assembly resource file. Resource files are files that contain model
233
+ * scene descriptions, or geometry data.
234
+ *
235
+ * @param dataId - Resource file name.
236
+ * @param ranges - A range of resource file contents to download.
237
+ * @param requestId - Request ID for download progress callback.
238
+ * @param onProgress - Download progress callback.
239
+ * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
240
+ * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
241
+ * and abort it if desired.
242
+ */
243
+ downloadResourceRange(dataId: string, ranges: Array<{
244
+ begin: number;
245
+ end: number;
246
+ requestId: number;
247
+ }>, requestId: number, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
248
+ /**
249
+ * Deprecated since `25.3`. Use {@link Assembly.downloadResource()} instead.
250
+ */
251
+ partialDownloadResource(dataId: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
252
+ /**
253
+ * Deprecated since `25.3`. Use {@link Assembly.downloadResourceRange()} instead.
254
+ */
255
+ downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
232
256
  getReferences(signal?: AbortSignal): Promise<{
233
257
  fileId: string;
234
258
  references: any[];
@@ -14,7 +14,7 @@ export declare class ClashTest {
14
14
  */
15
15
  constructor(data: any, basePath: string, httpClient: IHttpClient);
16
16
  protected internalGet(relativePath: string): Promise<any>;
17
- protected internalPut(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<any>;
17
+ protected internalPut(relativePath: string, body?: BodyInit | object): Promise<any>;
18
18
  protected internalDelete(relativePath: string): Promise<any>;
19
19
  /**
20
20
  * The type of the clashes that the test detects:
@@ -24,14 +24,13 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
24
24
  url?: string;
25
25
  });
26
26
  /**
27
- * Open Cloud Server URL. Use {@link Client#configure | configure()} to change server URL.
27
+ * Open Cloud Server URL. Use {@link Client.configure()} to change server URL.
28
28
  *
29
29
  * @readonly
30
30
  */
31
31
  get serverUrl(): string;
32
32
  /**
33
- * Deprecated since `25.3`. Use [Viewer.options]{@link Viewer#options} instead to change
34
- * Viewer parameters.
33
+ * Deprecated since `25.3`. Use {@link Viewer.options()} instead to change Viewer parameters.
35
34
  */
36
35
  get options(): any;
37
36
  /**
@@ -0,0 +1,6 @@
1
+ export declare function $fetch(url: string, params?: {
2
+ method: "GET" | "POST" | "PUT" | "DELETE";
3
+ headers?: HeadersInit;
4
+ body?: BodyInit | object;
5
+ signal?: AbortSignal;
6
+ }): Promise<Response>;
@@ -1,3 +1,5 @@
1
+ export declare function statusText(status: number): string;
2
+ export declare function error400(text: string, _default?: string): any;
1
3
  /**
2
4
  * The `FetchError` object indicates an error when request to Open Cloud Server could not be
3
5
  * performed. A `FetchError` is typically (but not exclusively) thrown when a network error
package/lib/Api/File.d.ts CHANGED
@@ -22,8 +22,6 @@ export declare class File {
22
22
  private internalPost;
23
23
  private internalPut;
24
24
  private internalDelete;
25
- partialDownloadResource(dataId: string, onProgress?: (progress: number, downloaded: Uint8Array) => void, signal?: AbortSignal): Promise<void>;
26
- downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
27
25
  /**
28
26
  * Active version number of the file.
29
27
  *
@@ -52,8 +50,8 @@ export declare class File {
52
50
  get data(): any;
53
51
  private set data(value);
54
52
  /**
55
- * Returns a list of formats in which the active version of the file was exported. To export
56
- * file to one of the supported formats create File Converter job using
53
+ * Returns a list of files in different formats in which the active version of the file was
54
+ * exported. To export file to one of the supported formats create File Converter job using
57
55
  * {@link File.createJob()}. To download exported file use {@link File.downloadResource()}.
58
56
  *
59
57
  * @readonly
@@ -211,7 +209,7 @@ export declare class File {
211
209
  * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
212
210
  * target="_blank">File</a> object. Setting the `image` to `null` will remove the preview.
213
211
  */
214
- setPreview(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<File>;
212
+ setPreview(image: BodyInit | null): Promise<File>;
215
213
  /**
216
214
  * Returns a list of models of the active version of the file.
217
215
  *
@@ -334,24 +332,50 @@ export declare class File {
334
332
  */
335
333
  download(onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
336
334
  /**
337
- * Download file resource data of the active version of the file, such as exported file.
335
+ * Download a resource file of the active version of the file. Resource files are files that
336
+ * contain model scene descriptions, or geometry data, or exported files.
338
337
  *
339
338
  * @example <caption>Export file to DWG.</caption>
340
339
  * const job = await file.crateJob("dwg");
341
340
  * await job.waitForDone();
342
- * const resourceId = file.exports.find((x) => x.endsWith(".dwg"));
343
- * const arrayBuffer = await file.downloadResource(resourceId);
341
+ * const dwgFileName = file.exports.find((x) => x.endsWith(".dwg"));
342
+ * const arrayBuffer = await file.downloadResource(dwgFileName);
344
343
  * const blob = new Blob([arrayBuffer]);
345
344
  * const fileName = file.name.replace(/\.[^.]+$/, "") + ".dwg";
346
345
  * FileSaver.saveAs(blob, fileName);
347
346
  *
348
- * @param dataId - Resource ID.
347
+ * @param dataId - Resource file name.
349
348
  * @param onProgress - Download progress callback.
350
349
  * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
351
350
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
352
351
  * and abort it if desired.
353
352
  */
354
- downloadResource(dataId: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
353
+ downloadResource(dataId: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
354
+ /**
355
+ * Download a part of resource file of the active version of the file. Resource files are
356
+ * files that contain model scene descriptions, or geometry data, or exported files.
357
+ *
358
+ * @param dataId - Resource file name.
359
+ * @param ranges - A range of resource file contents to download.
360
+ * @param requestId - Request ID for download progress callback.
361
+ * @param onProgress - Download progress callback.
362
+ * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
363
+ * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
364
+ * and abort it if desired.
365
+ */
366
+ downloadResourceRange(dataId: string, ranges: Array<{
367
+ begin: number;
368
+ end: number;
369
+ requestId: number;
370
+ }>, requestId: number, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
371
+ /**
372
+ * Deprecated since `25.3`. Use {@link File.downloadResource()} instead.
373
+ */
374
+ partialDownloadResource(dataId: string, onProgress?: (progress: number, downloaded: Uint8Array) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
375
+ /**
376
+ * Deprecated since `25.3`. Use {@link File.downloadResourceRange()} instead.
377
+ */
378
+ downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
355
379
  /**
356
380
  * Returns a list of references to files used to correct rendering of the current file.
357
381
  *
@@ -5,8 +5,14 @@ export declare class HttpClient implements IHttpClient {
5
5
  signInUserId: string;
6
6
  constructor(serverUrl: string);
7
7
  get(relativePath: string, signal?: AbortSignal): Promise<Response>;
8
- post(relativePath: string, body?: string | object | ArrayBuffer | Blob | globalThis.File | FormData): Promise<Response>;
9
- put(relativePath: string, body?: string | object | ArrayBuffer | Blob | globalThis.File | FormData): Promise<Response>;
8
+ post(relativePath: string, body?: BodyInit | object): Promise<Response>;
9
+ put(relativePath: string, body?: BodyInit | object): Promise<Response>;
10
10
  delete(relativePath: string): Promise<Response>;
11
- postFile(relativePath: string, file: globalThis.File, onProgress?: (progress: number) => void): Promise<XMLHttpRequest>;
11
+ uploadFile(relativePath: string, file: File, onProgress?: (progress: number) => void): Promise<XMLHttpRequest>;
12
+ downloadFile(relativePath: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<Response>;
13
+ downloadFileRange(relativePath: string, ranges: Array<{
14
+ begin: number;
15
+ end: number;
16
+ requestId: number;
17
+ }>, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<Response>;
12
18
  }
@@ -2,9 +2,15 @@ export interface IHttpClient {
2
2
  serverUrl: string;
3
3
  headers: HeadersInit;
4
4
  signInUserId: string;
5
- get(relativePath: any, signal?: AbortSignal): Promise<Response>;
6
- post(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
7
- put(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
5
+ get(relativePath: string, signal?: AbortSignal): Promise<Response>;
6
+ post(relativePath: string, body?: BodyInit | object): Promise<Response>;
7
+ put(relativePath: string, body?: BodyInit | object): Promise<Response>;
8
8
  delete(relativePath: string): Promise<Response>;
9
- postFile(relativePath: string, file: globalThis.File, onProgress?: (progress: number) => void): Promise<XMLHttpRequest>;
9
+ uploadFile(relativePath: string, file: globalThis.File, onProgress?: (progress: number) => void): Promise<XMLHttpRequest>;
10
+ downloadFile(relativePath: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<Response>;
11
+ downloadFileRange(relativePath: string, ranges: Array<{
12
+ begin: number;
13
+ end: number;
14
+ requestId: number;
15
+ }>, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<Response>;
10
16
  }
package/lib/Api/Job.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare class Job {
12
12
  */
13
13
  constructor(data: any, httpClient: IHttpClient);
14
14
  protected internalGet(): Promise<Response>;
15
- protected internalPut(body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
15
+ protected internalPut(body?: BodyInit | object): Promise<Response>;
16
16
  protected internalDelete(): Promise<Response>;
17
17
  /**
18
18
  * The ID of the assembly the job is working on (internal).
@@ -29,8 +29,8 @@ export declare class Model {
29
29
  get data(): any;
30
30
  private set data(value);
31
31
  /**
32
- * Scene description file resource ID. Use {@link Model#downloadResource | downloadResource()}
33
- * to download scene description file.
32
+ * Scene description resource file name. Use {@link Model.downloadResource()} to download
33
+ * scene description file.
34
34
  *
35
35
  * @readonly
36
36
  */
@@ -54,8 +54,8 @@ export declare class Model {
54
54
  */
55
55
  get fileId(): string;
56
56
  /**
57
- * The list of resource IDs for geometry data files. Use
58
- * {@link Model#downloadResource | downloadResource()} to download geometry data files.
57
+ * The list of geometry data resource files. Use {@link Model.downloadResource()} to download
58
+ * geometry data files.
59
59
  *
60
60
  * @readonly
61
61
  */
@@ -146,18 +146,42 @@ export declare class Model {
146
146
  */
147
147
  getSnapshotData(guid: string, bitmapGuid: string): Promise<string>;
148
148
  /**
149
- * Downloads model resource, such as scene description file or geometry data files.
149
+ * Download model resource file. Resource files are files that contain model scene
150
+ * descriptions, or geometry data.
150
151
  *
151
152
  * @async
152
- * @param resourceId - Resource ID.
153
+ * @param dataId - Resource file name.
153
154
  * @param onProgress - Download progress callback.
154
155
  * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
155
156
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
156
157
  * and abort it if desired.
157
158
  */
158
- downloadResource(dataId: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
159
- partialDownloadResource(dataId: string, onProgress?: (progress: number, downloaded: Uint8Array) => void, signal?: AbortSignal): Promise<void>;
160
- downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
159
+ downloadResource(dataId: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
160
+ /**
161
+ * Download a part of model resource file. Resource files are files that contain model scene
162
+ * descriptions, or geometry data.
163
+ *
164
+ * @param dataId - Resource file name.
165
+ * @param ranges - A range of resource file contents to download.
166
+ * @param requestId - Request ID for download progress callback.
167
+ * @param onProgress - Download progress callback.
168
+ * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
169
+ * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
170
+ * and abort it if desired.
171
+ */
172
+ downloadResourceRange(dataId: string, ranges: Array<{
173
+ begin: number;
174
+ end: number;
175
+ requestId: number;
176
+ }>, requestId: number, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
177
+ /**
178
+ * Deprecated since `25.3`. Use {@link Model.downloadResource()} instead.
179
+ */
180
+ partialDownloadResource(dataId: string, onProgress?: (progress: number, chunk: Uint8Array) => void, signal?: AbortSignal): Promise<ArrayBuffer>;
181
+ /**
182
+ * Deprecated since `25.3`. Use {@link Model.downloadResourceRange()} instead.
183
+ */
184
+ downloadFileRange(requestId: number, records: any | null, dataId: string, onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void, signal?: AbortSignal): Promise<void>;
161
185
  /**
162
186
  * Returns a list of references to files used to extract geometry data.
163
187
  *
@@ -14,8 +14,8 @@ export declare class Project {
14
14
  */
15
15
  constructor(data: any, httpClient: IHttpClient);
16
16
  protected internalGet(relativePath: string): Promise<Response>;
17
- protected internalPost(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
18
- protected internalPut(relativePath: string, body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null): Promise<Response>;
17
+ protected internalPost(relativePath: string, body?: BodyInit | object): Promise<Response>;
18
+ protected internalPut(relativePath: string, body?: BodyInit | object): Promise<Response>;
19
19
  protected internalDelete(relativePath: string): Promise<Response>;
20
20
  /**
21
21
  * Project features the user has access to.
@@ -162,7 +162,7 @@ export declare class Project {
162
162
  * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
163
163
  * target="_blank">File</a> object. Setting the `image` to `null` will remove the preview.
164
164
  */
165
- setPreview(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<this>;
165
+ setPreview(image: BodyInit | null): Promise<this>;
166
166
  /**
167
167
  * Returns a list of project roles. Project {@link Member | members} have different abilities
168
168
  * depending on the role they have in a project.
package/lib/Api/User.d.ts CHANGED
@@ -192,5 +192,5 @@ export declare class User {
192
192
  * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
193
193
  * target="_blank">File</a> object. Setting the `image` to `null` will remove the avatar.
194
194
  */
195
- setAvatar(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<User>;
195
+ setAvatar(image: BodyInit | null): Promise<User>;
196
196
  }
@@ -0,0 +1,11 @@
1
+ export declare function waitFor(func: (params: any) => Promise<boolean>, params?: {
2
+ timeout?: number;
3
+ interval?: number;
4
+ signal?: AbortSignal;
5
+ abortError?: DOMException;
6
+ timeoutError?: DOMException;
7
+ result?: any;
8
+ }): Promise<any>;
9
+ export declare function parseArgs(args: string | object): object;
10
+ export declare function userFullName(firstName: string | any, lastName?: string, userName?: string): string;
11
+ export declare function userInitials(fullName?: string): string;
@@ -0,0 +1,7 @@
1
+ export declare function $xmlhttp(url: string, params?: {
2
+ method: "GET" | "POST" | "PUT" | "DELETE";
3
+ headers?: HeadersInit;
4
+ body?: XMLHttpRequestBodyInit;
5
+ uploadProgress?: (progress: number) => void;
6
+ downloadProgress?: (progress: number) => void;
7
+ }): Promise<XMLHttpRequest>;
package/lib/index.d.ts CHANGED
@@ -10,5 +10,5 @@ export { Permission } from "./Api/Permission";
10
10
  export { Project } from "./Api/Project";
11
11
  export { Role } from "./Api/Role";
12
12
  export { User } from "./Api/User";
13
- export { parseArgs, userFullName, userInitials, waitFor } from "./Api/impl/Utils";
13
+ export { parseArgs, userFullName, userInitials, waitFor } from "./Api/Utils";
14
14
  export declare const version = "CLIENT_JS_VERSION";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/client",
3
- "version": "25.3.17",
3
+ "version": "25.3.18",
4
4
  "description": "JavaScript REST API client for the Open Cloud Server",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,8 +26,8 @@ import { IAssociatedFileData, IAssemblyVersionInfo } from "./IAssembly";
26
26
  import { IShortUserDescription } from "./IUser";
27
27
  import { Model } from "./Model";
28
28
  import { ClashTest } from "./ClashTest";
29
- import { json, downloadProgress, downloadPartOfFile, waitFor, userFullName, userInitials } from "./impl/Utils";
30
- import { FetchError } from "./impl/FetchError";
29
+ import { waitFor, userFullName, userInitials } from "./Utils";
30
+ import { FetchError } from "./FetchError";
31
31
 
32
32
  /**
33
33
  * The class representing a `assembly` entity.
@@ -50,7 +50,6 @@ export class Assembly {
50
50
 
51
51
  public appendVersionParam(relativePath: string): string {
52
52
  if (this._useVersion === undefined) return relativePath;
53
-
54
53
  const delimiter = relativePath.includes("?") ? "&" : "?";
55
54
  return `${relativePath}${delimiter}version=${this._useVersion}`;
56
55
  }
@@ -60,18 +59,12 @@ export class Assembly {
60
59
  return this.httpClient.get(`${this.path}${relativePath}`, signal);
61
60
  }
62
61
 
63
- protected internalPost(
64
- relativePath: string,
65
- body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
66
- ) {
62
+ protected internalPost(relativePath: string, body?: BodyInit | object) {
67
63
  relativePath = this.appendVersionParam(relativePath);
68
64
  return this.httpClient.post(`${this.path}${relativePath}`, body);
69
65
  }
70
66
 
71
- protected internalPut(
72
- relativePath: string,
73
- body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
74
- ) {
67
+ protected internalPut(relativePath: string, body?: BodyInit | object) {
75
68
  relativePath = this.appendVersionParam(relativePath);
76
69
  return this.httpClient.put(`${this.path}${relativePath}`, body);
77
70
  }
@@ -81,52 +74,6 @@ export class Assembly {
81
74
  return this.httpClient.delete(`${this.path}${relativePath}`);
82
75
  }
83
76
 
84
- async partialDownloadResource(
85
- dataId: string,
86
- onProgress?: (progress: number, downloaded: Uint8Array) => void,
87
- signal?: AbortSignal
88
- ): Promise<void> {
89
- let pathname = `${this.path}/downloads/${dataId}`;
90
- pathname = this.appendVersionParam(pathname);
91
-
92
- // TODO: replace with $get to handle fetch errors
93
- const response = await fetch(`${this.httpClient.serverUrl}${pathname}`, {
94
- headers: this.httpClient.headers,
95
- signal,
96
- });
97
-
98
- // TODO: use ReadableStream pipeTo()
99
- const contentLength = response.headers.get("Content-Length") ?? "";
100
- const total = parseInt(contentLength, 10);
101
- const reader = response.body.getReader();
102
- let loaded = 0;
103
- while (true) {
104
- const { done, value } = await reader.read();
105
- if (done) break;
106
- loaded += value.byteLength;
107
- if (typeof onProgress === "function") onProgress(loaded / total, value);
108
- }
109
- }
110
-
111
- downloadFileRange(
112
- requestId: number,
113
- records: any | null,
114
- dataId: string,
115
- onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void,
116
- signal?: AbortSignal
117
- ): Promise<void> {
118
- let pathname = `${this.path}/downloads/${dataId}?requestId=${requestId}`;
119
- pathname = this.appendVersionParam(pathname);
120
- return downloadPartOfFile(
121
- requestId,
122
- records,
123
- `${this.httpClient.serverUrl}${pathname}`,
124
- this.httpClient.headers,
125
- onProgress,
126
- signal
127
- );
128
- }
129
-
130
77
  // Reserved for future use
131
78
 
132
79
  get activeVersion(): number {
@@ -285,7 +232,8 @@ export class Assembly {
285
232
  * @async
286
233
  */
287
234
  async checkout(): Promise<Assembly> {
288
- this.data = await json(this.internalGet(""));
235
+ const response = await this.internalGet("");
236
+ this.data = await response.json();
289
237
  return this;
290
238
  }
291
239
 
@@ -296,7 +244,8 @@ export class Assembly {
296
244
  * @param data - Raw assembly data.
297
245
  */
298
246
  async update(data: any): Promise<Assembly> {
299
- this.data = await json(this.internalPut("", data));
247
+ const response = await this.internalPut("", data);
248
+ this.data = await response.json();
300
249
  return this;
301
250
  }
302
251
 
@@ -307,7 +256,7 @@ export class Assembly {
307
256
  * @returns Returns the raw data of a deleted assembly.
308
257
  */
309
258
  delete(): Promise<any> {
310
- return json(this.internalDelete(""));
259
+ return this.internalDelete("").then((response) => response.json());
311
260
  }
312
261
 
313
262
  /**
@@ -322,7 +271,7 @@ export class Assembly {
322
271
 
323
272
  // Reserved for future use
324
273
 
325
- setPreview(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null) {
274
+ setPreview(image: BodyInit | null) {
326
275
  console.warn("Assembly does not support preview");
327
276
  return Promise.resolve(this);
328
277
  }
@@ -333,7 +282,9 @@ export class Assembly {
333
282
  * @async
334
283
  */
335
284
  getModels(): Promise<Model[]> {
336
- return json(this.internalGet("/geometry")).then((array) => array.map((data) => new Model(data, this)));
285
+ return this.internalGet("/geometry")
286
+ .then((response) => response.json())
287
+ .then((array) => array.map((data: any) => new Model(data, this)));
337
288
  }
338
289
 
339
290
  /**
@@ -384,7 +335,8 @@ export class Assembly {
384
335
  * @returns {Promise<any>}
385
336
  */
386
337
  getProperties(handles?: string | string[]): Promise<any[]> {
387
- return json(this.internalGet(handles !== undefined ? `/properties?handles=${handles}` : "/properties"));
338
+ const relativePath = handles !== undefined ? `/properties?handles=${handles}` : "/properties";
339
+ return this.internalGet(relativePath).then((response) => response.json());
388
340
  }
389
341
 
390
342
  /**
@@ -414,7 +366,7 @@ export class Assembly {
414
366
  * @param searchPattern - Search pattern or combination of the patterns, see example below.
415
367
  */
416
368
  searchProperties(searchPattern: any): Promise<any[]> {
417
- return json(this.internalPost("/properties/search", searchPattern));
369
+ return this.internalPost("/properties/search", searchPattern).then((response) => response.json());
418
370
  }
419
371
 
420
372
  /**
@@ -423,7 +375,7 @@ export class Assembly {
423
375
  * @async
424
376
  */
425
377
  getCdaTree(): Promise<any[]> {
426
- return json(this.internalGet(`/properties/tree`));
378
+ return this.internalGet(`/properties/tree`).then((response) => response.json());
427
379
  }
428
380
 
429
381
  // Reserved for future use
@@ -454,10 +406,11 @@ export class Assembly {
454
406
  }
455
407
 
456
408
  /**
457
- * Download assembly resource data, such as geometry data.
409
+ * Download assembly resource file. Resource files are files that contain model scene
410
+ * descriptions, or geometry data.
458
411
  *
459
412
  * @async
460
- * @param dataId - Resource ID.
413
+ * @param dataId - Resource file name.
461
414
  * @param onProgress - Download progress callback.
462
415
  * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
463
416
  * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
@@ -465,14 +418,67 @@ export class Assembly {
465
418
  */
466
419
  downloadResource(
467
420
  dataId: string,
468
- onProgress?: (progress: number) => void,
421
+ onProgress?: (progress: number, chunk: Uint8Array) => void,
469
422
  signal?: AbortSignal
470
423
  ): Promise<ArrayBuffer> {
471
- return this.internalGet(`/downloads/${dataId}`, signal)
472
- .then((response) => downloadProgress(response, onProgress))
424
+ const relativePath = this.appendVersionParam(`/downloads/${dataId}`);
425
+ return this.httpClient
426
+ .downloadFile(`${this.path}${relativePath}`, onProgress, signal)
473
427
  .then((response) => response.arrayBuffer());
474
428
  }
475
429
 
430
+ /**
431
+ * Download a part of assembly resource file. Resource files are files that contain model
432
+ * scene descriptions, or geometry data.
433
+ *
434
+ * @param dataId - Resource file name.
435
+ * @param ranges - A range of resource file contents to download.
436
+ * @param requestId - Request ID for download progress callback.
437
+ * @param onProgress - Download progress callback.
438
+ * @param signal - An <a href="https://developer.mozilla.org/docs/Web/API/AbortSignal" target
439
+ * ="_blank">AbortSignal</a> object instance. Allows to communicate with a fetch request
440
+ * and abort it if desired.
441
+ */
442
+ downloadResourceRange(
443
+ dataId: string,
444
+ ranges: Array<{ begin: number; end: number; requestId: number }>,
445
+ requestId: number,
446
+ onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
447
+ signal?: AbortSignal
448
+ ): Promise<ArrayBuffer> {
449
+ const relativePath = this.appendVersionParam(`/downloads/${dataId}?requestId=${requestId}`);
450
+ return this.httpClient
451
+ .downloadFileRange(`${this.path}${relativePath}`, ranges, onProgress, signal)
452
+ .then((response) => response.arrayBuffer());
453
+ }
454
+
455
+ /**
456
+ * Deprecated since `25.3`. Use {@link Assembly.downloadResource()} instead.
457
+ */
458
+ partialDownloadResource(
459
+ dataId: string,
460
+ onProgress?: (progress: number, chunk: Uint8Array) => void,
461
+ signal?: AbortSignal
462
+ ): Promise<ArrayBuffer> {
463
+ console.warn(
464
+ "Assembly.partialDownloadResource() has been deprecated since 25.3 and will be removed in a future release, use Assembly.downloadResource() instead."
465
+ );
466
+ return this.downloadResource(dataId, onProgress, signal);
467
+ }
468
+
469
+ /**
470
+ * Deprecated since `25.3`. Use {@link Assembly.downloadResourceRange()} instead.
471
+ */
472
+ async downloadFileRange(
473
+ requestId: number,
474
+ records: any | null,
475
+ dataId: string,
476
+ onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
477
+ signal?: AbortSignal
478
+ ): Promise<void> {
479
+ await this.downloadResourceRange(dataId, records, requestId, onProgress, signal);
480
+ }
481
+
476
482
  // Reserved for future use
477
483
 
478
484
  getReferences(signal?: AbortSignal) {