@inweb/client 25.3.18 → 25.3.20

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.
package/src/Api/File.ts CHANGED
@@ -54,22 +54,22 @@ export class File {
54
54
  return `${relativePath}${delimiter}version=${this._useVersion}`;
55
55
  }
56
56
 
57
- private internalGet(relativePath: string, signal?: AbortSignal) {
57
+ private internalGet(relativePath: string, signal?: AbortSignal): Promise<Response> {
58
58
  relativePath = this.appendVersionParam(relativePath);
59
59
  return this.httpClient.get(`${this.path}${relativePath}`, signal);
60
60
  }
61
61
 
62
- private internalPost(relativePath: string, body?: BodyInit | object) {
62
+ private internalPost(relativePath: string, body?: BodyInit | object): Promise<Response> {
63
63
  relativePath = this.appendVersionParam(relativePath);
64
64
  return this.httpClient.post(`${this.path}${relativePath}`, body);
65
65
  }
66
66
 
67
- private internalPut(relativePath: string, body?: BodyInit | object) {
67
+ private internalPut(relativePath: string, body?: BodyInit | object): Promise<Response> {
68
68
  relativePath = this.appendVersionParam(relativePath);
69
69
  return this.httpClient.put(`${this.path}${relativePath}`, body);
70
70
  }
71
71
 
72
- private internalDelete(relativePath: string) {
72
+ private internalDelete(relativePath: string): Promise<Response> {
73
73
  relativePath = this.appendVersionParam(relativePath);
74
74
  return this.httpClient.delete(`${this.path}${relativePath}`);
75
75
  }
@@ -314,7 +314,7 @@ export class File {
314
314
  *
315
315
  * @async
316
316
  */
317
- async checkout(): Promise<File> {
317
+ async checkout(): Promise<this> {
318
318
  const response = await this.internalGet("");
319
319
  this.data = await response.json();
320
320
  return this;
@@ -326,7 +326,7 @@ export class File {
326
326
  * @async
327
327
  * @param data - Raw file data.
328
328
  */
329
- async update(data: any): Promise<File> {
329
+ async update(data: any): Promise<this> {
330
330
  const response = await this.internalPut("", data);
331
331
  this.data = await response.json();
332
332
  return this;
@@ -348,7 +348,7 @@ export class File {
348
348
  *
349
349
  * @async
350
350
  */
351
- save(): Promise<File> {
351
+ save(): Promise<this> {
352
352
  return this.update(this.data);
353
353
  }
354
354
 
@@ -365,7 +365,7 @@ export class File {
365
365
  * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
366
366
  * target="_blank">File</a> object. Setting the `image` to `null` will remove the preview.
367
367
  */
368
- async setPreview(image: BodyInit | null): Promise<File> {
368
+ async setPreview(image: BodyInit | null): Promise<this> {
369
369
  const response = await (image ? this.internalPost("/preview", image) : this.internalDelete("/preview"));
370
370
  this.data = await response.json();
371
371
  return this;
@@ -388,7 +388,7 @@ export class File {
388
388
  return undefined;
389
389
  }
390
390
 
391
- setModelTransformMatrix(handle: string, transform: any): Promise<File> {
391
+ setModelTransformMatrix(handle: string, transform: any): Promise<this> {
392
392
  console.warn("File does not support model transformation");
393
393
  return Promise.resolve(this);
394
394
  }
@@ -587,14 +587,14 @@ export class File {
587
587
  */
588
588
  downloadResourceRange(
589
589
  dataId: string,
590
- ranges: Array<{ begin: number; end: number; requestId: number }>,
591
590
  requestId: number,
591
+ ranges: Array<{ begin: number; end: number; requestId: number }>,
592
592
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
593
593
  signal?: AbortSignal
594
594
  ): Promise<ArrayBuffer> {
595
595
  const relativePath = this.appendVersionParam(`/downloads/${dataId}?requestId=${requestId}`);
596
596
  return this.httpClient
597
- .downloadFileRange(`${this.path}${relativePath}`, ranges, onProgress, signal)
597
+ .downloadFileRange(`${this.path}${relativePath}`, requestId, ranges, onProgress, signal)
598
598
  .then((response) => response.arrayBuffer());
599
599
  }
600
600
 
@@ -622,7 +622,7 @@ export class File {
622
622
  onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void,
623
623
  signal?: AbortSignal
624
624
  ): Promise<void> {
625
- await this.downloadResourceRange(dataId, records, requestId, onProgress, signal);
625
+ await this.downloadResourceRange(dataId, requestId, records, onProgress, signal);
626
626
  }
627
627
 
628
628
  /**
@@ -745,7 +745,7 @@ export class File {
745
745
  * @returns {Promise<File>}
746
746
  */
747
747
  waitForDone(
748
- jobs,
748
+ jobs: string | string[],
749
749
  waitAll?: boolean,
750
750
  params?: {
751
751
  timeout?: number;
@@ -760,7 +760,7 @@ export class File {
760
760
  const checkDone = () =>
761
761
  this.checkout().then((file) => {
762
762
  const readyJobs = jobs.filter((x: string) =>
763
- ["none", "done", "failed"].includes(file.status[x]?.state ?? "none")
763
+ ["none", "done", "failed"].includes(file.status[x]?.state || "none")
764
764
  );
765
765
  const ready = waitAll ? readyJobs.length === jobs.length : readyJobs.length > 0;
766
766
  const cancel = params?.onCheckout?.(file, ready);
@@ -923,7 +923,7 @@ export class File {
923
923
  * @param version - Desired active version.
924
924
  */
925
925
 
926
- setActiveVersion(version: number): Promise<File> {
926
+ setActiveVersion(version: number): Promise<this> {
927
927
  return this.update({ activeVersion: version });
928
928
  }
929
929
 
@@ -27,8 +27,8 @@ import { $xmlhttp } from "./XMLHttp";
27
27
 
28
28
  export class HttpClient implements IHttpClient {
29
29
  serverUrl: string;
30
- headers: HeadersInit;
31
- signInUserId: string;
30
+ headers: HeadersInit = {};
31
+ signInUserId = "";
32
32
 
33
33
  constructor(serverUrl: string) {
34
34
  this.serverUrl = serverUrl;
@@ -90,7 +90,7 @@ export class HttpClient implements IHttpClient {
90
90
  ): Promise<Response> {
91
91
  const response = await this.get(relativePath, signal);
92
92
  const contentLength = response.headers.get("Content-Length");
93
- const total = parseInt(contentLength, 10) || 1;
93
+ const total = parseInt(contentLength || "", 10) || 1;
94
94
  return new Response(
95
95
  new ReadableStream({
96
96
  async start(controller) {
@@ -111,6 +111,7 @@ export class HttpClient implements IHttpClient {
111
111
 
112
112
  async downloadFileRange(
113
113
  relativePath: string,
114
+ requestId: number,
114
115
  ranges: Array<{ begin: number; end: number; requestId: number }>,
115
116
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
116
117
  signal?: AbortSignal
@@ -119,7 +120,7 @@ export class HttpClient implements IHttpClient {
119
120
  headers["Range"] = "bytes=" + ranges.map((x) => `${x.begin}-${x.end}`).join(",");
120
121
  const response = await $fetch(`${this.serverUrl}${relativePath}`, { method: "GET", headers, signal });
121
122
  const contentLength = response.headers.get("content-length");
122
- const total = parseInt(contentLength, 10) || 1;
123
+ const total = parseInt(contentLength || "", 10) || 1;
123
124
  return new Response(
124
125
  new ReadableStream({
125
126
  async start(controller) {
@@ -48,6 +48,7 @@ export interface IHttpClient {
48
48
 
49
49
  downloadFileRange(
50
50
  relativePath: string,
51
+ requestId: number,
51
52
  ranges: Array<{ begin: number; end: number; requestId: number }>,
52
53
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
53
54
  signal?: AbortSignal
package/src/Api/Job.ts CHANGED
@@ -41,15 +41,15 @@ export class Job {
41
41
  this.data = data;
42
42
  }
43
43
 
44
- protected internalGet() {
44
+ protected internalGet(): Promise<Response> {
45
45
  return this.httpClient.get(`/jobs/${this.data.id}`);
46
46
  }
47
47
 
48
- protected internalPut(body?: BodyInit | object) {
48
+ protected internalPut(body?: BodyInit | object): Promise<Response> {
49
49
  return this.httpClient.put(`/jobs/${this.data.id}`, body);
50
50
  }
51
51
 
52
- protected internalDelete() {
52
+ protected internalDelete(): Promise<Response> {
53
53
  return this.httpClient.delete(`/jobs/${this.data.id}`);
54
54
  }
55
55
 
@@ -183,7 +183,7 @@ export class Job {
183
183
  *
184
184
  * @async
185
185
  */
186
- async checkout(): Promise<Job> {
186
+ async checkout(): Promise<this> {
187
187
  const response = await this.internalGet();
188
188
  this.data = await response.json();
189
189
  return this;
@@ -195,7 +195,7 @@ export class Job {
195
195
  * @async
196
196
  * @param data - Raw job data.
197
197
  */
198
- async update(data: any): Promise<Job> {
198
+ async update(data: any): Promise<this> {
199
199
  const response = await this.internalPut(data);
200
200
  this.data = await response.json();
201
201
  return this;
@@ -242,7 +242,7 @@ export class Job {
242
242
  interval?: number;
243
243
  signal?: AbortSignal;
244
244
  onCheckout?: (job: Job, ready: boolean) => boolean;
245
- }): Promise<Job> {
245
+ }): Promise<this> {
246
246
  const checkDone = () =>
247
247
  this.checkout().then((job) => {
248
248
  const ready = ["done", "failed"].includes(job.status);
package/src/Api/Member.ts CHANGED
@@ -44,15 +44,15 @@ export class Member {
44
44
  this.data = data;
45
45
  }
46
46
 
47
- private internalGet() {
47
+ private internalGet(): Promise<Response> {
48
48
  return this.httpClient.get(`/projects/${this.projectId}/members/${this.id}`);
49
49
  }
50
50
 
51
- private internalPut(body?: BodyInit | object) {
51
+ private internalPut(body?: BodyInit | object): Promise<Response> {
52
52
  return this.httpClient.put(`/projects/${this.projectId}/members/${this.id}`, body);
53
53
  }
54
54
 
55
- private internalDelete() {
55
+ private internalDelete(): Promise<Response> {
56
56
  return this.httpClient.delete(`/projects/${this.projectId}/members/${this.id}`);
57
57
  }
58
58
 
@@ -123,7 +123,7 @@ export class Member {
123
123
  *
124
124
  * @async
125
125
  */
126
- async checkout(): Promise<Member> {
126
+ async checkout(): Promise<this> {
127
127
  const response = await this.internalGet();
128
128
  this.data = await response.json();
129
129
  return this;
@@ -135,7 +135,7 @@ export class Member {
135
135
  * @async
136
136
  * @param data - Raw member data.
137
137
  */
138
- async update(data: any): Promise<Member> {
138
+ async update(data: any): Promise<this> {
139
139
  const response = await this.internalPut(data);
140
140
  this.data = await response.json();
141
141
  return this;
@@ -157,7 +157,7 @@ export class Member {
157
157
  *
158
158
  * @async
159
159
  */
160
- save(): Promise<Member> {
160
+ save(): Promise<this> {
161
161
  return this.update(this.data);
162
162
  }
163
163
  }
package/src/Api/Model.ts CHANGED
@@ -279,12 +279,12 @@ export class Model {
279
279
  */
280
280
  downloadResourceRange(
281
281
  dataId: string,
282
- ranges: Array<{ begin: number; end: number; requestId: number }>,
283
282
  requestId: number,
283
+ ranges: Array<{ begin: number; end: number; requestId: number }>,
284
284
  onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
285
285
  signal?: AbortSignal
286
286
  ): Promise<ArrayBuffer> {
287
- return this._file.downloadResourceRange(dataId, ranges, requestId, onProgress, signal);
287
+ return this._file.downloadResourceRange(dataId, requestId, ranges, onProgress, signal);
288
288
  }
289
289
 
290
290
  /**
@@ -328,7 +328,7 @@ export class Model {
328
328
  }
329
329
  }
330
330
 
331
- await this.downloadResourceRange(dataId, ranges, requestId, onProgress, signal);
331
+ await this.downloadResourceRange(dataId, requestId, ranges, onProgress, signal);
332
332
  }
333
333
 
334
334
  /**
@@ -339,7 +339,7 @@ export class Model {
339
339
  * href="https://developer.mozilla.org/docs/Web/API/AbortController">AbortController</a>
340
340
  * signal object instance, which can be used to abort waiting as desired.
341
341
  */
342
- getReferences(signal?: AbortSignal) {
342
+ getReferences(signal?: AbortSignal): Promise<any> {
343
343
  return this._file.getReferences(signal);
344
344
  }
345
345
  }
@@ -43,15 +43,15 @@ export class Permission {
43
43
  this.data = data;
44
44
  }
45
45
 
46
- private internalGet() {
46
+ private internalGet(): Promise<Response> {
47
47
  return this.httpClient.get(`/files/${this.fileId}/permissions/${this.id}`);
48
48
  }
49
49
 
50
- private internalPut(body?: BodyInit | object) {
50
+ private internalPut(body?: BodyInit | object): Promise<Response> {
51
51
  return this.httpClient.put(`/files/${this.fileId}/permissions/${this.id}`, body);
52
52
  }
53
53
 
54
- private internalDelete() {
54
+ private internalDelete(): Promise<Response> {
55
55
  return this.httpClient.delete(`/files/${this.fileId}/permissions/${this.id}`);
56
56
  }
57
57
 
@@ -134,7 +134,7 @@ export class Permission {
134
134
  *
135
135
  * @async
136
136
  */
137
- async checkout(): Promise<Permission> {
137
+ async checkout(): Promise<this> {
138
138
  const response = await this.internalGet();
139
139
  this.data = await response.json();
140
140
  return this;
@@ -146,7 +146,7 @@ export class Permission {
146
146
  * @async
147
147
  * @param data - Raw permission data.
148
148
  */
149
- async update(data: any): Promise<Permission> {
149
+ async update(data: any): Promise<this> {
150
150
  const response = await this.internalPut(data);
151
151
  this.data = await response.json();
152
152
  return this;
@@ -168,7 +168,7 @@ export class Permission {
168
168
  *
169
169
  * @async
170
170
  */
171
- save(): Promise<Permission> {
171
+ save(): Promise<this> {
172
172
  return this.update(this.data);
173
173
  }
174
174
  }
@@ -43,19 +43,19 @@ export class Project {
43
43
  this.data = data;
44
44
  }
45
45
 
46
- protected internalGet(relativePath: string) {
46
+ protected internalGet(relativePath: string): Promise<Response> {
47
47
  return this.httpClient.get(`/projects/${this.id}${relativePath}`);
48
48
  }
49
49
 
50
- protected internalPost(relativePath: string, body?: BodyInit | object) {
50
+ protected internalPost(relativePath: string, body?: BodyInit | object): Promise<Response> {
51
51
  return this.httpClient.post(`/projects/${this.id}${relativePath}`, body);
52
52
  }
53
53
 
54
- protected internalPut(relativePath: string, body?: BodyInit | object) {
54
+ protected internalPut(relativePath: string, body?: BodyInit | object): Promise<Response> {
55
55
  return this.httpClient.put(`/projects/${this.id}${relativePath}`, body);
56
56
  }
57
57
 
58
- protected internalDelete(relativePath: string) {
58
+ protected internalDelete(relativePath: string): Promise<Response> {
59
59
  return this.httpClient.delete(`/projects/${this.id}${relativePath}`);
60
60
  }
61
61
 
@@ -242,7 +242,7 @@ export class Project {
242
242
  *
243
243
  * @async
244
244
  */
245
- async checkout(): Promise<Project> {
245
+ async checkout(): Promise<this> {
246
246
  const response = await this.internalGet("");
247
247
  this.data = await response.json();
248
248
  return this;
@@ -254,7 +254,7 @@ export class Project {
254
254
  * @async
255
255
  * @param data - Raw project data.
256
256
  */
257
- async update(data: any): Promise<Project> {
257
+ async update(data: any): Promise<this> {
258
258
  const response = await this.internalPut("", data);
259
259
  this.data = await response.json();
260
260
  return this;
@@ -285,7 +285,7 @@ export class Project {
285
285
  *
286
286
  * @async
287
287
  */
288
- save(): Promise<Project> {
288
+ save(): Promise<this> {
289
289
  return this.update(this.data);
290
290
  }
291
291
 
@@ -303,7 +303,7 @@ export class Project {
303
303
  * target="_blank">File</a> object. Setting the `image` to `null` will remove the preview.
304
304
  */
305
305
 
306
- async setPreview(image: BodyInit | null) {
306
+ async setPreview(image: BodyInit | null): Promise<any> {
307
307
  const response = await (image ? this.internalPost("/preview", image) : this.internalDelete("/preview"));
308
308
  this.data = await response.json();
309
309
  return this;
package/src/Api/Role.ts CHANGED
@@ -42,15 +42,15 @@ export class Role {
42
42
  this.data = data;
43
43
  }
44
44
 
45
- private internalGet() {
45
+ private internalGet(): Promise<Response> {
46
46
  return this.httpClient.get(`/projects/${this.projectId}/roles/${this.name}`);
47
47
  }
48
48
 
49
- private internalPut(body?: BodyInit | object) {
49
+ private internalPut(body?: BodyInit | object): Promise<Response> {
50
50
  return this.httpClient.put(`/projects/${this.projectId}/roles/${this.name}`, body);
51
51
  }
52
52
 
53
- private internalDelete() {
53
+ private internalDelete(): Promise<Response> {
54
54
  return this.httpClient.delete(`/projects/${this.projectId}/roles/${this.name}`);
55
55
  }
56
56
 
@@ -119,7 +119,7 @@ export class Role {
119
119
  *
120
120
  * @async
121
121
  */
122
- async checkout(): Promise<Role> {
122
+ async checkout(): Promise<this> {
123
123
  const response = await this.internalGet();
124
124
  this.data = await response.json();
125
125
  return this;
@@ -131,7 +131,7 @@ export class Role {
131
131
  * @async
132
132
  * @param data - Raw role data.
133
133
  */
134
- async update(data: any): Promise<Role> {
134
+ async update(data: any): Promise<this> {
135
135
  const response = await this.internalPut(data);
136
136
  this.data = await response.json();
137
137
  return this;
@@ -153,7 +153,7 @@ export class Role {
153
153
  *
154
154
  * @async
155
155
  */
156
- save(): Promise<Role> {
156
+ save(): Promise<this> {
157
157
  return this.update(this.data);
158
158
  }
159
159
  }
package/src/Api/User.ts CHANGED
@@ -257,7 +257,7 @@ export class User {
257
257
  * does not have administrator rights, hi can only checkout himself, otherwise an exception
258
258
  * will be thrown.
259
259
  */
260
- async checkout(): Promise<User> {
260
+ async checkout(): Promise<this> {
261
261
  if (this.id === this.httpClient.signInUserId) {
262
262
  const response = await this.httpClient.get("/user");
263
263
  const data = await response.json();
@@ -278,7 +278,7 @@ export class User {
278
278
  * @async
279
279
  * @param data - Raw user data.
280
280
  */
281
- async update(data: any) {
281
+ async update(data: any): Promise<this> {
282
282
  if (this.id === this.httpClient.signInUserId) {
283
283
  const response = await this.httpClient.put("/user", data);
284
284
  const newData = await response.json();
@@ -322,7 +322,7 @@ export class User {
322
322
  *
323
323
  * @async
324
324
  */
325
- save(): Promise<User> {
325
+ save(): Promise<this> {
326
326
  return this.update(this.data);
327
327
  }
328
328
 
@@ -341,7 +341,7 @@ export class User {
341
341
  * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
342
342
  * target="_blank">File</a> object. Setting the `image` to `null` will remove the avatar.
343
343
  */
344
- async setAvatar(image: BodyInit | null): Promise<User> {
344
+ async setAvatar(image: BodyInit | null): Promise<this> {
345
345
  if (image) {
346
346
  if (this.id === this.httpClient.signInUserId) {
347
347
  const response = await this.httpClient.post("/user/avatar", image);
package/src/Api/Utils.ts CHANGED
@@ -21,7 +21,7 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- function delay(ms: number, signal: AbortSignal) {
24
+ function delay(ms: number, signal: AbortSignal): Promise<boolean> {
25
25
  return new Promise((resolve) => {
26
26
  let timeoutId = 0;
27
27
 
@@ -49,9 +49,9 @@ export async function waitFor(
49
49
  timeoutError?: DOMException;
50
50
  result?: any;
51
51
  } = {}
52
- ) {
53
- const timeout = params.timeout ?? 600000;
54
- const interval = params.interval ?? 3000;
52
+ ): Promise<any> {
53
+ const timeout = params.timeout || 600000;
54
+ const interval = params.interval || 3000;
55
55
  const signal = params.signal ?? new AbortController().signal;
56
56
  const abortError = params.abortError ?? new DOMException("Aborted", "AbortError");
57
57
  const timeoutError = params.timeoutError ?? new DOMException("Timeout", "TimeoutError");
@@ -67,7 +67,7 @@ export async function waitFor(
67
67
  return Promise.reject(timeoutError);
68
68
  }
69
69
 
70
- export function parseArgs(args: string | object): object {
70
+ export function parseArgs(args?: string | object): object {
71
71
  if (typeof args === "string") {
72
72
  const firstArg = args.indexOf("--");
73
73
  if (firstArg !== -1) args = args.slice(firstArg);
@@ -83,7 +83,7 @@ export function parseArgs(args: string | object): object {
83
83
  .map((x) => x.concat([""]));
84
84
  return Object.fromEntries(argArray);
85
85
  }
86
- return args ?? {};
86
+ return args || {};
87
87
  }
88
88
 
89
89
  export function userFullName(firstName: string | any, lastName = "", userName = ""): string {
@@ -61,7 +61,7 @@ export function $xmlhttp(
61
61
  for (const key in params.headers) {
62
62
  xhr.setRequestHeader(key, params.headers[key]);
63
63
  }
64
- function calcProgress(event: ProgressEvent) {
64
+ function calcProgress(event: ProgressEvent): number {
65
65
  return event.lengthComputable ? event.loaded / event.total : 1;
66
66
  }
67
67
  xhr.upload.onprogress = (event) => params.uploadProgress && params.uploadProgress(calcProgress(event));
@@ -1,28 +0,0 @@
1
- /**
2
- * Convert world coordinates to screen normalized (-1, 1)
3
- *
4
- * @param viewMatrix Camera world matrix
5
- * @param projectionMatrix Camera projection matrix
6
- * @param worldPoint World point
7
- */
8
- export declare function worldToScreenNormalized(viewMatrix: Array<number>, projectionMatrix: Array<number>, worldPoint: [x: number, y: number, z: number]): [x: number, y: number, z: number];
9
- export declare function multiplyMatrices(a: Array<number>, b: Array<number>): Array<number>;
10
- /**
11
- * @param matrix
12
- * @returns Matrix
13
- */
14
- export declare function invertMatrix(matrix: Array<number>): Array<number>;
15
- /**
16
- * Convert world coordinates to screen (screenWidth, screenHeight)
17
- *
18
- * @param viewMatrix Camera world matrix
19
- * @param projectionMatrix Camera projection matrix
20
- * @param worldPoint World point
21
- * @param screenWidth Screen width
22
- * @param screenHeight Screen height
23
- */
24
- export declare function worldToScreen(viewMatrix: Array<number>, projectionMatrix: Array<number>, worldPoint: [x: number, y: number, z: number], screenWidth: number, screenHeight: number): number[];
25
- export declare function createOrthoProjectionMatrix(camera: any, width: any, height: any): number[];
26
- export declare function createViewMatrix(camera: any): any[];
27
- export declare function bcfWorldToScreenFromCamera(camera: any, canvas: HTMLCanvasElement, point: [x: number, y: number, z: number]): number[];
28
- export declare function matrixLookAt(matrix: any, eye: any, target: any, up: any): any;