@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 +1 -1
- package/src/domain-client.d.ts +1 -1
- package/src/domain-client.js +12 -11
package/package.json
CHANGED
package/src/domain-client.d.ts
CHANGED
|
@@ -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
|
|
10
|
+
private decompressModelData;
|
|
11
11
|
private handleErrors;
|
|
12
12
|
private buildUrl;
|
|
13
13
|
private shouldAddPublicPrefix;
|
package/src/domain-client.js
CHANGED
|
@@ -31,21 +31,20 @@ export class DomainClient {
|
|
|
31
31
|
}
|
|
32
32
|
const models = [];
|
|
33
33
|
for (const id of ids) {
|
|
34
|
-
|
|
34
|
+
const modelData = data.data[id];
|
|
35
|
+
if (!modelData) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
35
38
|
if (typeof modelData === 'string') {
|
|
36
39
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
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(
|
|
64
|
-
const
|
|
65
|
-
|
|
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) {
|