@shapediver/sdk.geometry-api-sdk-v2 1.8.3 → 1.9.0
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/dist/ShapeDiverErrors.d.ts.map +1 -1
- package/dist/ShapeDiverErrors.js +1 -1
- package/dist/ShapeDiverErrors.js.map +1 -1
- package/dist/ShapeDiverSdk.d.ts.map +1 -1
- package/dist/ShapeDiverSdk.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/ShapeDiverAnalyticsApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverAnalyticsApi.js +3 -1
- package/dist/resources/ShapeDiverAnalyticsApi.js.map +1 -1
- package/dist/resources/ShapeDiverArSceneApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverArSceneApi.js.map +1 -1
- package/dist/resources/ShapeDiverAssetApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverAssetApi.js.map +1 -1
- package/dist/resources/ShapeDiverExportApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverExportApi.js.map +1 -1
- package/dist/resources/ShapeDiverFileApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverFileApi.js +10 -7
- package/dist/resources/ShapeDiverFileApi.js.map +1 -1
- package/dist/resources/ShapeDiverGltfApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverGltfApi.js +4 -1
- package/dist/resources/ShapeDiverGltfApi.js.map +1 -1
- package/dist/resources/ShapeDiverModelApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverModelApi.js +52 -15
- package/dist/resources/ShapeDiverModelApi.js.map +1 -1
- package/dist/resources/ShapeDiverOutputApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverOutputApi.js +12 -4
- package/dist/resources/ShapeDiverOutputApi.js.map +1 -1
- package/dist/resources/ShapeDiverSdtfApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverSdtfApi.js +9 -3
- package/dist/resources/ShapeDiverSdtfApi.js.map +1 -1
- package/dist/resources/ShapeDiverSessionApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverSessionApi.js +3 -1
- package/dist/resources/ShapeDiverSessionApi.js.map +1 -1
- package/dist/resources/ShapeDiverSystemApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverSystemApi.js +18 -6
- package/dist/resources/ShapeDiverSystemApi.js.map +1 -1
- package/dist/resources/ShapeDiverTextureApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverTextureApi.js +3 -1
- package/dist/resources/ShapeDiverTextureApi.js.map +1 -1
- package/dist/resources/ShapeDiverUtilsApi.d.ts +3 -5
- package/dist/resources/ShapeDiverUtilsApi.d.ts.map +1 -1
- package/dist/resources/ShapeDiverUtilsApi.js +31 -15
- package/dist/resources/ShapeDiverUtilsApi.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +9 -9
- package/dist/utils/utils.js.map +1 -1
- package/package.json +4 -2
- package/src/ShapeDiverErrors.ts +24 -23
- package/src/ShapeDiverSdk.ts +110 -109
- package/src/index.ts +15 -16
- package/src/resources/ShapeDiverAnalyticsApi.ts +30 -18
- package/src/resources/ShapeDiverArSceneApi.ts +68 -69
- package/src/resources/ShapeDiverAssetApi.ts +207 -183
- package/src/resources/ShapeDiverExportApi.ts +92 -77
- package/src/resources/ShapeDiverFileApi.ts +136 -108
- package/src/resources/ShapeDiverGltfApi.ts +41 -30
- package/src/resources/ShapeDiverModelApi.ts +351 -240
- package/src/resources/ShapeDiverOutputApi.ts +92 -56
- package/src/resources/ShapeDiverSdtfApi.ts +88 -54
- package/src/resources/ShapeDiverSessionApi.ts +104 -82
- package/src/resources/ShapeDiverSystemApi.ts +106 -70
- package/src/resources/ShapeDiverTextureApi.ts +24 -18
- package/src/resources/ShapeDiverUtilsApi.ts +290 -231
- package/src/utils/utils.ts +61 -53
|
@@ -1,255 +1,314 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
ShapeDiverRequestCache,
|
|
3
|
+
ShapeDiverRequestCustomization,
|
|
4
|
+
ShapeDiverRequestExport,
|
|
5
|
+
ShapeDiverResponseDto,
|
|
6
|
+
ShapeDiverResponseAssetUploadHeaders,
|
|
7
|
+
ShapeDiverResponseExport,
|
|
8
|
+
ShapeDiverResponseOutput,
|
|
9
|
+
} from "@shapediver/api.geometry-api-dto-v2";
|
|
9
10
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "@shapediver/sdk.geometry-api-sdk-core"
|
|
15
|
-
import { ShapeDiverSdk } from "../ShapeDiverSdk"
|
|
16
|
-
import { sendRequest, sleep } from "../utils/utils"
|
|
11
|
+
BaseResourceApi,
|
|
12
|
+
ShapeDiverError,
|
|
13
|
+
ShapeDiverSdkApi,
|
|
14
|
+
ShapeDiverSdkApiResponseType,
|
|
15
|
+
} from "@shapediver/sdk.geometry-api-sdk-core";
|
|
16
|
+
import { ShapeDiverSdk } from "../ShapeDiverSdk";
|
|
17
|
+
import { sendRequest, sleep } from "../utils/utils";
|
|
18
|
+
|
|
19
|
+
const contentDisposition = require("content-disposition");
|
|
17
20
|
|
|
18
21
|
// TypeScript wrapper for a response type that depend on an input type
|
|
19
22
|
type ShapeDiverSdkUtilsDownloadType<T extends ShapeDiverSdkApiResponseType> =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
T extends ShapeDiverSdkApiResponseType.
|
|
23
|
-
|
|
23
|
+
T extends ShapeDiverSdkApiResponseType.TEXT
|
|
24
|
+
? string
|
|
25
|
+
: T extends ShapeDiverSdkApiResponseType.JSON
|
|
26
|
+
? Record<string, any>
|
|
27
|
+
: T extends ShapeDiverSdkApiResponseType.DATA
|
|
28
|
+
? ArrayBuffer
|
|
29
|
+
: never;
|
|
24
30
|
|
|
25
31
|
export class ShapeDiverUtilsApi extends BaseResourceApi {
|
|
32
|
+
constructor(api: ShapeDiverSdkApi) {
|
|
33
|
+
super(api);
|
|
34
|
+
}
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Upload the given file to the specified URL.
|
|
38
|
+
*
|
|
39
|
+
* @param url - The target URL of the upload request.
|
|
40
|
+
* @param data - The data that should be uploaded.
|
|
41
|
+
* @param contentType - Indicate the original media type of the resource.
|
|
42
|
+
* @param filename - The name of the file to be uploaded. When a filename has been specified in
|
|
43
|
+
* the request-upload call, then the same filename has to be specified for the upload as well.
|
|
44
|
+
*/
|
|
45
|
+
async upload(
|
|
46
|
+
url: string,
|
|
47
|
+
data: ArrayBuffer | Record<string, any> | string,
|
|
48
|
+
contentType: string,
|
|
49
|
+
filename?: string,
|
|
50
|
+
): Promise<any> {
|
|
51
|
+
return await sendRequest(async () =>
|
|
52
|
+
this.api.put<any>(url, data, {
|
|
53
|
+
contentType: contentType,
|
|
54
|
+
contentDisposition: filename ? contentDisposition(filename) : undefined,
|
|
55
|
+
responseType: ShapeDiverSdkApiResponseType.JSON,
|
|
56
|
+
disableAuthorization: true,
|
|
57
|
+
disableCustomHeaders: true,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
30
61
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
62
|
+
/**
|
|
63
|
+
* Upload the given asset to the specified ShapeDiver URL.
|
|
64
|
+
*
|
|
65
|
+
* @param url - The ShapeDiver URL of the upload request.
|
|
66
|
+
* @param data - The data that should be uploaded.
|
|
67
|
+
* @param headers - The headers object that was returned from the request-upload call.
|
|
68
|
+
*/
|
|
69
|
+
async uploadAsset(
|
|
70
|
+
url: string,
|
|
71
|
+
data: ArrayBuffer | Record<string, any> | string,
|
|
72
|
+
headers: ShapeDiverResponseAssetUploadHeaders,
|
|
73
|
+
): Promise<any> {
|
|
74
|
+
return await sendRequest(async () =>
|
|
75
|
+
this.api.put<any>(url, data, {
|
|
76
|
+
contentType: headers.contentType,
|
|
77
|
+
contentDisposition: headers.contentDisposition,
|
|
78
|
+
responseType: ShapeDiverSdkApiResponseType.JSON,
|
|
79
|
+
disableAuthorization: true,
|
|
80
|
+
disableCustomHeaders: true,
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
54
84
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Download from the given URL.
|
|
87
|
+
*
|
|
88
|
+
* @param url - The target URL of the download request.
|
|
89
|
+
* @param responseType - Indicates the type of data that the server should respond with if possible.
|
|
90
|
+
* @returns Array of size 2: [0] = response headers, [1] = response data
|
|
91
|
+
*/
|
|
92
|
+
async download<T extends ShapeDiverSdkApiResponseType>(
|
|
93
|
+
url: string,
|
|
94
|
+
responseType: T,
|
|
95
|
+
): Promise<[Record<string, any>, ShapeDiverSdkUtilsDownloadType<T>]> {
|
|
96
|
+
return await sendRequest(async () =>
|
|
97
|
+
this.api.get<any>(url, {
|
|
98
|
+
contentType: "application/json",
|
|
99
|
+
responseType: responseType,
|
|
100
|
+
disableAuthorization: true,
|
|
101
|
+
disableCustomHeaders: true,
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
73
105
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
maxWaitMsec = (maxWaitMsec < 0) ? maxWaitMsec : Math.max(0, maxWaitMsec - waitMsec)
|
|
96
|
-
|
|
97
|
-
return ShapeDiverUtilsApi.waitForCustomizationResult(sdk, sessionId, dto, maxWaitMsec)
|
|
98
|
-
}
|
|
106
|
+
/**
|
|
107
|
+
* Submit a customization request and wait for the result to be finished.
|
|
108
|
+
*
|
|
109
|
+
* @param sdk
|
|
110
|
+
* @param sessionId
|
|
111
|
+
* @param body
|
|
112
|
+
* @param maxWaitMsec - Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
113
|
+
* @throws {@link ShapeDiverError} in case a maximum duration has been specified and is exceeded.
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
async submitAndWaitForCustomization(
|
|
117
|
+
sdk: ShapeDiverSdk,
|
|
118
|
+
sessionId: string,
|
|
119
|
+
body: ShapeDiverRequestCustomization,
|
|
120
|
+
maxWaitMsec = -1,
|
|
121
|
+
): Promise<ShapeDiverResponseDto> {
|
|
122
|
+
const startMsec = Date.now();
|
|
123
|
+
const dto = await sendRequest(async () =>
|
|
124
|
+
sdk.output.customize(sessionId, body),
|
|
125
|
+
);
|
|
126
|
+
const waitMsec = Date.now() - startMsec;
|
|
99
127
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
// Reduce the total max waiting time by the amount the customization-request took
|
|
129
|
+
maxWaitMsec =
|
|
130
|
+
maxWaitMsec < 0 ? maxWaitMsec : Math.max(0, maxWaitMsec - waitMsec);
|
|
131
|
+
|
|
132
|
+
return ShapeDiverUtilsApi.waitForCustomizationResult(
|
|
133
|
+
sdk,
|
|
134
|
+
sessionId,
|
|
135
|
+
dto,
|
|
136
|
+
maxWaitMsec,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Submit an export request and wait for the result to be finished.
|
|
142
|
+
*
|
|
143
|
+
* @param sdk
|
|
144
|
+
* @param sessionId
|
|
145
|
+
* @param body
|
|
146
|
+
* @param maxWaitMsec - Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
147
|
+
* @throws {@link ShapeDiverError} in case a maximum duration has been specified and is exceeded.
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
async submitAndWaitForExport(
|
|
151
|
+
sdk: ShapeDiverSdk,
|
|
152
|
+
sessionId: string,
|
|
153
|
+
body: ShapeDiverRequestExport,
|
|
154
|
+
maxWaitMsec = -1,
|
|
155
|
+
): Promise<ShapeDiverResponseDto> {
|
|
156
|
+
const startMsec = Date.now();
|
|
157
|
+
const dto = await sendRequest(async () =>
|
|
158
|
+
sdk.export.compute(sessionId, body),
|
|
159
|
+
);
|
|
160
|
+
const waitMsec = Date.now() - startMsec;
|
|
161
|
+
|
|
162
|
+
// Reduce the total max waiting time by the amount the compute-request took
|
|
163
|
+
maxWaitMsec =
|
|
164
|
+
maxWaitMsec < 0 ? maxWaitMsec : Math.max(0, maxWaitMsec - waitMsec);
|
|
165
|
+
|
|
166
|
+
return ShapeDiverUtilsApi.waitForExportResult(
|
|
167
|
+
sdk,
|
|
168
|
+
sessionId,
|
|
169
|
+
body,
|
|
170
|
+
dto,
|
|
171
|
+
maxWaitMsec,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Given a DTO resulting from a customization request, wait for the results to be finished.
|
|
177
|
+
*
|
|
178
|
+
* @param sdk
|
|
179
|
+
* @param sessionId
|
|
180
|
+
* @param dto
|
|
181
|
+
* @param maxWaitMsec - Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
182
|
+
* @returns
|
|
183
|
+
*/
|
|
184
|
+
private static async waitForCustomizationResult(
|
|
185
|
+
sdk: ShapeDiverSdk,
|
|
186
|
+
sessionId: string,
|
|
187
|
+
dto: ShapeDiverResponseDto,
|
|
188
|
+
maxWaitMsec = -1,
|
|
189
|
+
): Promise<ShapeDiverResponseDto> {
|
|
190
|
+
if (!dto.outputs) return dto;
|
|
125
191
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
let delay = ShapeDiverUtilsApi.getMaxOutputDelay(dto)
|
|
150
|
-
const startMsec = Date.now()
|
|
151
|
-
|
|
152
|
-
while (delay > 0) {
|
|
153
|
-
// Check whether maxWaitMsec has been reached
|
|
154
|
-
if (maxWaitMsec >= 0) {
|
|
155
|
-
const waitMsec = Date.now() - startMsec
|
|
156
|
-
if (waitMsec >= maxWaitMsec) {
|
|
157
|
-
throw new ShapeDiverError(`Maximum wait time of ${maxWaitMsec} ms reached`)
|
|
158
|
-
}
|
|
159
|
-
if (waitMsec + delay > maxWaitMsec) {
|
|
160
|
-
delay = maxWaitMsec - waitMsec
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
await sleep(delay)
|
|
165
|
-
|
|
166
|
-
// Send cache request
|
|
167
|
-
dto = await sendRequest(async () => sdk.output.getCache(sessionId, outputVersions))
|
|
168
|
-
delay = ShapeDiverUtilsApi.getMaxOutputDelay(dto)
|
|
192
|
+
// Build new cache request
|
|
193
|
+
const outputVersions: ShapeDiverRequestCache = {};
|
|
194
|
+
Object.keys(dto.outputs).forEach(
|
|
195
|
+
(id) =>
|
|
196
|
+
(outputVersions[id] = (
|
|
197
|
+
dto.outputs![id] as ShapeDiverResponseOutput
|
|
198
|
+
).version),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
let delay = ShapeDiverUtilsApi.getMaxOutputDelay(dto);
|
|
202
|
+
const startMsec = Date.now();
|
|
203
|
+
|
|
204
|
+
while (delay > 0) {
|
|
205
|
+
// Check whether maxWaitMsec has been reached
|
|
206
|
+
if (maxWaitMsec >= 0) {
|
|
207
|
+
const waitMsec = Date.now() - startMsec;
|
|
208
|
+
if (waitMsec >= maxWaitMsec) {
|
|
209
|
+
throw new ShapeDiverError(
|
|
210
|
+
`Maximum wait time of ${maxWaitMsec} ms reached`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (waitMsec + delay > maxWaitMsec) {
|
|
214
|
+
delay = maxWaitMsec - waitMsec;
|
|
169
215
|
}
|
|
216
|
+
}
|
|
170
217
|
|
|
171
|
-
|
|
218
|
+
await sleep(delay);
|
|
219
|
+
|
|
220
|
+
// Send cache request
|
|
221
|
+
dto = await sendRequest(async () =>
|
|
222
|
+
sdk.output.getCache(sessionId, outputVersions),
|
|
223
|
+
);
|
|
224
|
+
delay = ShapeDiverUtilsApi.getMaxOutputDelay(dto);
|
|
172
225
|
}
|
|
173
226
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
await sleep(delay)
|
|
208
|
-
|
|
209
|
-
// Send cache request
|
|
210
|
-
dto = await sendRequest(async () => sdk.export.getCache(sessionId, body))
|
|
211
|
-
delay = ShapeDiverUtilsApi.getMaxExportDelay(dto, body)
|
|
227
|
+
return dto;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Given a DTO resulting from an export request, wait for the result to be finished.
|
|
232
|
+
*
|
|
233
|
+
* @param sdk
|
|
234
|
+
* @param sessionId
|
|
235
|
+
* @param dto
|
|
236
|
+
* @param exportIds
|
|
237
|
+
* @param outputIds
|
|
238
|
+
* @param maxWaitMsec - Maximum duration to wait for result (in milliseconds), pass value < 0 to disable limit.
|
|
239
|
+
* @returns
|
|
240
|
+
*/
|
|
241
|
+
private static async waitForExportResult(
|
|
242
|
+
sdk: ShapeDiverSdk,
|
|
243
|
+
sessionId: string,
|
|
244
|
+
body: ShapeDiverRequestExport,
|
|
245
|
+
dto: ShapeDiverResponseDto,
|
|
246
|
+
maxWaitMsec = -1,
|
|
247
|
+
): Promise<ShapeDiverResponseDto> {
|
|
248
|
+
let delay = ShapeDiverUtilsApi.getMaxExportDelay(dto, body);
|
|
249
|
+
const startMsec = Date.now();
|
|
250
|
+
|
|
251
|
+
while (delay > 0) {
|
|
252
|
+
// Check whether maxWaitMsec has been reached
|
|
253
|
+
if (maxWaitMsec >= 0) {
|
|
254
|
+
const waitMsec = Date.now() - startMsec;
|
|
255
|
+
if (waitMsec >= maxWaitMsec) {
|
|
256
|
+
throw new ShapeDiverError(
|
|
257
|
+
`Maximum wait time of ${maxWaitMsec} ms reached`,
|
|
258
|
+
);
|
|
212
259
|
}
|
|
260
|
+
if (waitMsec + delay > maxWaitMsec) {
|
|
261
|
+
delay = maxWaitMsec - waitMsec;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
213
264
|
|
|
214
|
-
|
|
215
|
-
}
|
|
265
|
+
await sleep(delay);
|
|
216
266
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
* @returns maximum delay, -1 in case no delay was reported
|
|
221
|
-
*/
|
|
222
|
-
private static getMaxOutputDelay(dto: ShapeDiverResponseDto): number {
|
|
223
|
-
return Math.max(
|
|
224
|
-
...Object.values(dto.outputs!)
|
|
225
|
-
.map(output => output as ShapeDiverResponseOutput)
|
|
226
|
-
.map(output => output.delay ?? -1),
|
|
227
|
-
)
|
|
267
|
+
// Send cache request
|
|
268
|
+
dto = await sendRequest(async () => sdk.export.getCache(sessionId, body));
|
|
269
|
+
delay = ShapeDiverUtilsApi.getMaxExportDelay(dto, body);
|
|
228
270
|
}
|
|
229
271
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
272
|
+
return dto;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get the maximum delay that was reported for output versions.
|
|
277
|
+
*
|
|
278
|
+
* @returns maximum delay, -1 in case no delay was reported
|
|
279
|
+
*/
|
|
280
|
+
private static getMaxOutputDelay(dto: ShapeDiverResponseDto): number {
|
|
281
|
+
return Math.max(
|
|
282
|
+
...Object.values(dto.outputs!)
|
|
283
|
+
.map((output) => output as ShapeDiverResponseOutput)
|
|
284
|
+
.map((output) => output.delay ?? -1),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Get the maximum delay that was reported for the exports. If outputs have been reported as
|
|
290
|
+
* well, their delay time is included too.
|
|
291
|
+
*
|
|
292
|
+
* @returns delay, -1 in case no delay was reported
|
|
293
|
+
*/
|
|
294
|
+
private static getMaxExportDelay(
|
|
295
|
+
dto: ShapeDiverResponseDto,
|
|
296
|
+
body: ShapeDiverRequestExport,
|
|
297
|
+
): number {
|
|
298
|
+
const exports = Array.isArray(body.exports)
|
|
299
|
+
? body.exports
|
|
300
|
+
: [body.exports.id];
|
|
301
|
+
const outputs = body.outputs ?? [];
|
|
254
302
|
|
|
303
|
+
return Math.max(
|
|
304
|
+
...Object.values(dto.exports ?? {})
|
|
305
|
+
.filter((e) => exports.includes(e.id))
|
|
306
|
+
.map((e) => e as ShapeDiverResponseExport)
|
|
307
|
+
.map((e) => e.delay ?? -1),
|
|
308
|
+
...Object.values(dto.outputs ?? {})
|
|
309
|
+
.filter((o) => outputs.includes(o.id))
|
|
310
|
+
.map((o) => o as ShapeDiverResponseOutput)
|
|
311
|
+
.map((o) => o.delay ?? -1),
|
|
312
|
+
);
|
|
313
|
+
}
|
|
255
314
|
}
|