@studyportals/domain-client 6.0.0-10 → 6.0.0-11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studyportals/domain-client",
3
- "version": "6.0.0-10",
3
+ "version": "6.0.0-11",
4
4
  "description": "Responsible for fetching data from the Domain API",
5
5
  "main": "index.js",
6
6
  "author": "StudyPortals B.V.",
@@ -7,7 +7,7 @@ export declare class DomainClient<T> {
7
7
  readonly seed: number;
8
8
  constructor(baseUrl: string, apiKey: string | undefined, model: string, version: string, isPublic: boolean, seed: number);
9
9
  doRequest(ids: number[]): Promise<T[]>;
10
- private decompressData;
10
+ private decompressModelData;
11
11
  private handleErrors;
12
12
  private buildUrl;
13
13
  private shouldAddPublicPrefix;
@@ -31,21 +31,20 @@ export class DomainClient {
31
31
  }
32
32
  const models = [];
33
33
  for (const id of ids) {
34
- let modelData = data.data[id];
34
+ const modelData = data.data[id];
35
+ if (!modelData) {
36
+ continue;
37
+ }
35
38
  if (typeof modelData === 'string') {
36
39
  try {
37
- const bytes = Uint8Array.from(Buffer.from(modelData, 'base64'));
38
- const decompressedBytes = await this.decompressData(bytes);
39
- modelData = JSON.parse(decoder.decode(decompressedBytes));
40
+ models.push(await this.decompressModelData(modelData));
41
+ continue;
40
42
  }
41
43
  catch (error) {
42
44
  console.error(error);
43
45
  continue;
44
46
  }
45
47
  }
46
- if (!modelData) {
47
- continue;
48
- }
49
48
  models.push(modelData);
50
49
  }
51
50
  return models;
@@ -58,11 +57,13 @@ export class DomainClient {
58
57
  throw new InternalServerException('Unable to fetch data from the API', error);
59
58
  }
60
59
  }
61
- async decompressData(compressedData) {
60
+ async decompressModelData(compressedData) {
61
+ const bytes = Uint8Array.from(Buffer.from(compressedData, 'base64'));
62
62
  const stream = new DecompressionStream('deflate');
63
- const response = new Response(compressedData);
64
- const decompressed = response.body?.pipeThrough(stream);
65
- return new Uint8Array(await new Response(decompressed).arrayBuffer());
63
+ const response = new Response(bytes);
64
+ const decompressedStream = response.body?.pipeThrough(stream);
65
+ const decompressedBytes = new Uint8Array(await new Response(decompressedStream).arrayBuffer());
66
+ return JSON.parse(decoder.decode(decompressedBytes));
66
67
  }
67
68
  handleErrors(response) {
68
69
  if (!response.status) {