@shapediver/viewer.session-engine.session-engine 2.7.10 → 2.8.1
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/implementation/OutputLoader.d.ts.map +1 -1
- package/dist/implementation/OutputLoader.js +2 -3
- package/dist/implementation/OutputLoader.js.map +1 -1
- package/dist/implementation/SessionEngine.d.ts +2 -0
- package/dist/implementation/SessionEngine.d.ts.map +1 -1
- package/dist/implementation/SessionEngine.js +263 -321
- package/dist/implementation/SessionEngine.js.map +1 -1
- package/dist/implementation/dto/Export.d.ts.map +1 -1
- package/dist/implementation/dto/Export.js +7 -10
- package/dist/implementation/dto/Export.js.map +1 -1
- package/dist/implementation/dto/FileParameter.d.ts.map +1 -1
- package/dist/implementation/dto/FileParameter.js +5 -8
- package/dist/implementation/dto/FileParameter.js.map +1 -1
- package/dist/implementation/dto/Output.d.ts.map +1 -1
- package/dist/implementation/dto/Output.js +4 -5
- package/dist/implementation/dto/Output.js.map +1 -1
- package/dist/implementation/dto/Parameter.d.ts.map +1 -1
- package/dist/implementation/dto/Parameter.js +32 -53
- package/dist/implementation/dto/Parameter.js.map +1 -1
- package/package.json +9 -10
- package/src/implementation/OutputLoader.ts +2 -3
- package/src/implementation/SessionEngine.ts +101 -143
- package/src/implementation/dto/Export.ts +8 -10
- package/src/implementation/dto/FileParameter.ts +6 -9
- package/src/implementation/dto/Output.ts +5 -6
- package/src/implementation/dto/Parameter.ts +33 -54
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ShapeDiverResponseExport, ShapeDiverResponseExportContent, ShapeDiverResponseExportDefinitionType, ShapeDiverResponseExportResult, ShapeDiverResponseModelComputationStatus, ShapeDiverResponseParameterGroup } from "@shapediver/sdk.geometry-api-sdk-v2";
|
|
2
|
-
import {
|
|
3
|
-
import { EventEngine, EVENTTYPE, InputValidator, Logger, LOGGING_TOPIC, ShapeDiverBackendError, ShapeDiverViewerError, UuidGenerator } from "@shapediver/viewer.shared.services";
|
|
2
|
+
import { EventEngine, EVENTTYPE, InputValidator, Logger, ShapeDiverBackendError, ShapeDiverViewerError, UuidGenerator } from "@shapediver/viewer.shared.services";
|
|
4
3
|
import { ITaskEvent, TASK_TYPE } from "@shapediver/viewer.shared.types";
|
|
5
4
|
import { IExport } from "../../interfaces/dto/IExport";
|
|
6
5
|
import { SessionEngine } from "../SessionEngine";
|
|
@@ -8,14 +7,14 @@ import { SessionEngine } from "../SessionEngine";
|
|
|
8
7
|
export class Export implements IExport {
|
|
9
8
|
// #region Properties (24)
|
|
10
9
|
|
|
11
|
-
readonly #eventEngine: EventEngine =
|
|
10
|
+
readonly #eventEngine: EventEngine = EventEngine.instance;
|
|
12
11
|
readonly #id: string;
|
|
13
|
-
readonly #inputValidator: InputValidator =
|
|
14
|
-
readonly #logger: Logger =
|
|
12
|
+
readonly #inputValidator: InputValidator = InputValidator.instance;
|
|
13
|
+
readonly #logger: Logger = Logger.instance;
|
|
15
14
|
readonly #name: string;
|
|
16
15
|
readonly #sessionEngine: SessionEngine;
|
|
17
16
|
readonly #type: ShapeDiverResponseExportDefinitionType;
|
|
18
|
-
readonly #uuidGenerator: UuidGenerator =
|
|
17
|
+
readonly #uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
19
18
|
|
|
20
19
|
#content?: ShapeDiverResponseExportContent[];
|
|
21
20
|
#delay?: number;
|
|
@@ -157,14 +156,14 @@ export class Export implements IExport {
|
|
|
157
156
|
const event: ITaskEvent = { type: TASK_TYPE.EXPORT_REQUEST, id: eventId, progress: 0, status: 'Requesting export' };
|
|
158
157
|
this.#eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, event);
|
|
159
158
|
|
|
160
|
-
this.#logger.debugLow(
|
|
159
|
+
this.#logger.debugLow(`Export(${this.#id}).request: Sending export request.`);
|
|
161
160
|
const currentParameters = this.#sessionEngine.parameterValues;
|
|
162
161
|
const exportParameters: { [key: string]: string } = {}
|
|
163
162
|
|
|
164
163
|
for (let parameter in currentParameters)
|
|
165
164
|
exportParameters[parameter] = parameters[parameter] || parameters[parameter] === '' ? parameters[parameter] : currentParameters[parameter];
|
|
166
165
|
|
|
167
|
-
this.#logger.info(
|
|
166
|
+
this.#logger.info(`Export(${this.#id}).request: Sending export request with parameters ${JSON.stringify(exportParameters)}.`);
|
|
168
167
|
|
|
169
168
|
const exportDef = await this.#sessionEngine.requestExport(this.id, exportParameters, this.#maxWaitTime);
|
|
170
169
|
this.updateExportDefinition(exportDef);
|
|
@@ -177,8 +176,7 @@ export class Export implements IExport {
|
|
|
177
176
|
const eventEnd: ITaskEvent = { type: TASK_TYPE.EXPORT_REQUEST, id: eventId, progress: 1, status: 'Export request failed' };
|
|
178
177
|
this.#eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventEnd);
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
throw this.#logger.handleError(LOGGING_TOPIC.EXPORT, `Export(${this.#id}).request`, e);
|
|
179
|
+
throw e;
|
|
182
180
|
}
|
|
183
181
|
}
|
|
184
182
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ShapeDiverResponseParameter } from "@shapediver/sdk.geometry-api-sdk-v2";
|
|
2
|
-
import { Logger,
|
|
3
|
-
import { container } from "tsyringe";
|
|
2
|
+
import { Logger, ShapeDiverViewerSessionError, UuidGenerator } from "@shapediver/viewer.shared.services";
|
|
4
3
|
import { IFileParameter } from "../../interfaces/dto/IFileParameter";
|
|
5
4
|
import { Parameter } from "./Parameter";
|
|
6
5
|
import * as MimeTypeUtils from "@shapediver/viewer.utils.mime-type"
|
|
@@ -9,9 +8,9 @@ import { SessionEngine } from "../SessionEngine";
|
|
|
9
8
|
export class FileParameter extends Parameter<File | Blob | string> implements IFileParameter {
|
|
10
9
|
// #region Properties (5)
|
|
11
10
|
|
|
12
|
-
readonly #logger: Logger =
|
|
11
|
+
readonly #logger: Logger = Logger.instance;
|
|
13
12
|
readonly #sessionEngine: SessionEngine;
|
|
14
|
-
readonly #uuidGenerator: UuidGenerator =
|
|
13
|
+
readonly #uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
15
14
|
|
|
16
15
|
// #endregion Properties (5)
|
|
17
16
|
|
|
@@ -57,12 +56,10 @@ export class FileParameter extends Parameter<File | Blob | string> implements IF
|
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
if (!allowedType)
|
|
61
|
-
|
|
62
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).upload`, error);
|
|
63
|
-
}
|
|
59
|
+
if (!allowedType)
|
|
60
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.id}).upload: Error uploading FileParameter, type of data (${data.type}) is not a valid type. Has to be ${this.format}.`);
|
|
64
61
|
|
|
65
|
-
this.#logger.debug(
|
|
62
|
+
this.#logger.debug(`Parameter(${this.id}).upload: Uploading FileParameter.`);
|
|
66
63
|
|
|
67
64
|
return await this.#sessionEngine.uploadFile(this.id, data, type!)
|
|
68
65
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ShapeDiverResponseModelComputationStatus, ShapeDiverResponseOutput } from "@shapediver/sdk.geometry-api-sdk-v2";
|
|
2
|
-
import { container } from "tsyringe";
|
|
3
2
|
import { ITreeNode, TreeNode } from "@shapediver/viewer.shared.node-tree";
|
|
4
|
-
import { InputValidator, UuidGenerator,
|
|
3
|
+
import { InputValidator, UuidGenerator, ShapeDiverViewerError, ShapeDiverBackendError, Logger } from "@shapediver/viewer.shared.services";
|
|
5
4
|
import { IOutput, ShapeDiverResponseOutputContent, ShapeDiverResponseOutputChunk } from "../../interfaces/dto/IOutput";
|
|
6
5
|
import { SessionEngine } from "../SessionEngine";
|
|
7
6
|
|
|
@@ -9,11 +8,11 @@ export class Output implements IOutput {
|
|
|
9
8
|
// #region Properties (23)
|
|
10
9
|
|
|
11
10
|
readonly #id: string;
|
|
12
|
-
readonly #inputValidator: InputValidator =
|
|
13
|
-
readonly #logger: Logger =
|
|
11
|
+
readonly #inputValidator: InputValidator = InputValidator.instance;
|
|
12
|
+
readonly #logger: Logger = Logger.instance;
|
|
14
13
|
readonly #name: string;
|
|
15
14
|
readonly #sessionEngine: SessionEngine;
|
|
16
|
-
readonly #uuidGenerator: UuidGenerator =
|
|
15
|
+
readonly #uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
17
16
|
|
|
18
17
|
#bbmax?: number[];
|
|
19
18
|
#bbmin?: number[];
|
|
@@ -204,7 +203,7 @@ export class Output implements IOutput {
|
|
|
204
203
|
this.#chunks = outputDef.chunks;
|
|
205
204
|
this.#msg = outputDef.msg;
|
|
206
205
|
if (this.#msg !== undefined)
|
|
207
|
-
this.#logger.warn(
|
|
206
|
+
this.#logger.warn(`Output(${this.id}): ${this.#msg}`);
|
|
208
207
|
this.#bbmin = outputDef.bbmin;
|
|
209
208
|
this.#bbmax = outputDef.bbmax;
|
|
210
209
|
this.#status_computation = outputDef.status_computation;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ShapeDiverResponseParameterStructure, ShapeDiverResponseParameterGroup, ShapeDiverResponseParameter } from "@shapediver/api.geometry-api-dto-v2";
|
|
2
|
-
import { Converter, InputValidator, Logger,
|
|
3
|
-
import { container } from "tsyringe";
|
|
2
|
+
import { Converter, InputValidator, Logger, ShapeDiverViewerSessionError } from "@shapediver/viewer.shared.services";
|
|
4
3
|
import { IParameter } from "../../interfaces/dto/IParameter";
|
|
5
4
|
import { ISessionEngine, PARAMETER_TYPE, PARAMETER_VISUALIZATION } from "../../interfaces/ISessionEngine";
|
|
6
5
|
import * as MimeTypeUtils from "@shapediver/viewer.utils.mime-type"
|
|
@@ -10,7 +9,7 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
10
9
|
// #region Properties (24)
|
|
11
10
|
|
|
12
11
|
readonly #choices?: string[];
|
|
13
|
-
readonly #converter: Converter =
|
|
12
|
+
readonly #converter: Converter = Converter.instance;
|
|
14
13
|
readonly #decimalplaces?: number;
|
|
15
14
|
readonly #defaultValue: T | string;
|
|
16
15
|
readonly #defval: string;
|
|
@@ -18,8 +17,8 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
18
17
|
readonly #format?: string[];
|
|
19
18
|
readonly #group?: ShapeDiverResponseParameterGroup;
|
|
20
19
|
readonly #id: string;
|
|
21
|
-
readonly #inputValidator: InputValidator =
|
|
22
|
-
readonly #logger: Logger =
|
|
20
|
+
readonly #inputValidator: InputValidator = InputValidator.instance;
|
|
21
|
+
readonly #logger: Logger = Logger.instance;
|
|
23
22
|
readonly #max?: number;
|
|
24
23
|
readonly #min?: number;
|
|
25
24
|
readonly #name: string;
|
|
@@ -201,77 +200,61 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
201
200
|
switch (true) {
|
|
202
201
|
case this.type === PARAMETER_TYPE.BOOL:
|
|
203
202
|
if (typeof value === 'string') {
|
|
204
|
-
if (!(value === 'true' || value === 'false'))
|
|
205
|
-
|
|
206
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
207
|
-
}
|
|
203
|
+
if (!(value === 'true' || value === 'false'))
|
|
204
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} is a string that is neither true or false.`);
|
|
208
205
|
} else {
|
|
209
|
-
this.#inputValidator.validateAndError(
|
|
206
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, value, 'boolean');
|
|
210
207
|
}
|
|
211
208
|
break;
|
|
212
209
|
case this.type === PARAMETER_TYPE.COLOR:
|
|
213
|
-
this.#inputValidator.validateAndError(
|
|
210
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, value, 'color');
|
|
214
211
|
break;
|
|
215
212
|
case this.type === PARAMETER_TYPE.FILE:
|
|
216
|
-
this.#inputValidator.validateAndError(
|
|
213
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, value, 'file');
|
|
217
214
|
break;
|
|
218
215
|
case this.type === PARAMETER_TYPE.EVEN || this.type === PARAMETER_TYPE.FLOAT || this.type === PARAMETER_TYPE.INT || this.type === PARAMETER_TYPE.ODD:
|
|
219
216
|
let temp: number = value;
|
|
220
217
|
if (typeof value === 'string')
|
|
221
218
|
temp = +value;
|
|
222
|
-
this.#inputValidator.validateAndError(
|
|
219
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, temp, 'number');
|
|
223
220
|
if (this.type === PARAMETER_TYPE.EVEN) {
|
|
224
|
-
if (temp % 2 !== 0)
|
|
225
|
-
|
|
226
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
227
|
-
}
|
|
221
|
+
if (temp % 2 !== 0)
|
|
222
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} is not even.`);
|
|
228
223
|
} else if (this.type === PARAMETER_TYPE.ODD) {
|
|
229
|
-
if (temp % 2 === 0)
|
|
230
|
-
|
|
231
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
232
|
-
}
|
|
224
|
+
if (temp % 2 === 0)
|
|
225
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} is not odd.`);
|
|
233
226
|
} else if (this.type === PARAMETER_TYPE.INT) {
|
|
234
|
-
if (!Number.isInteger(temp))
|
|
235
|
-
|
|
236
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
237
|
-
}
|
|
227
|
+
if (!Number.isInteger(temp))
|
|
228
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} is not an integer.`);
|
|
238
229
|
}
|
|
239
230
|
if (this.min || this.min === 0)
|
|
240
|
-
if (temp < this.min)
|
|
241
|
-
|
|
242
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
243
|
-
}
|
|
231
|
+
if (temp < this.min)
|
|
232
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} is smaller than the minimum ${this.min}.`);
|
|
244
233
|
|
|
245
234
|
if (this.max || this.max === 0)
|
|
246
|
-
if (temp > this.max)
|
|
247
|
-
|
|
248
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
249
|
-
}
|
|
235
|
+
if (temp > this.max)
|
|
236
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} is larger than the maximum ${this.max}.`);
|
|
250
237
|
|
|
251
238
|
if (this.decimalplaces || this.decimalplaces === 0) {
|
|
252
239
|
const numStr = temp + '';
|
|
253
240
|
let decimalplaces = 0;
|
|
254
241
|
if (numStr.includes('.'))
|
|
255
242
|
decimalplaces = numStr.split('.')[1].length;
|
|
256
|
-
if (this.decimalplaces < decimalplaces)
|
|
257
|
-
|
|
258
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
259
|
-
}
|
|
243
|
+
if (this.decimalplaces < decimalplaces)
|
|
244
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${value} has not the correct number of decimalplaces (${this.decimalplaces}).`);
|
|
260
245
|
}
|
|
261
246
|
|
|
262
247
|
break;
|
|
263
248
|
case this.type === PARAMETER_TYPE.STRINGLIST:
|
|
264
|
-
this.#inputValidator.validateAndError(
|
|
249
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, value, 'string');
|
|
265
250
|
const choicesChecker = (v: string) => {
|
|
266
251
|
// has to be a single value that is
|
|
267
252
|
// 1. convertible to number
|
|
268
253
|
// 2. between 0 and choices.length -1
|
|
269
254
|
const temp = +v;
|
|
270
|
-
this.#inputValidator.validateAndError(
|
|
271
|
-
if (temp < 0 || temp > this.choices!.length - 1)
|
|
272
|
-
|
|
273
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
274
|
-
}
|
|
255
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, temp, 'number');
|
|
256
|
+
if (temp < 0 || temp > this.choices!.length - 1)
|
|
257
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${v} is not within the range of the defined number choices.`);
|
|
275
258
|
}
|
|
276
259
|
|
|
277
260
|
if (this.visualization === PARAMETER_VISUALIZATION.CHECKLIST) {
|
|
@@ -279,10 +262,8 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
279
262
|
if (value.includes(',')) {
|
|
280
263
|
const values: string[] = value.split(',');
|
|
281
264
|
for (let i = 0; i < values.length; i++) {
|
|
282
|
-
if (values.filter(item => item === values[i]).length !== 1)
|
|
283
|
-
|
|
284
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error, false);
|
|
285
|
-
}
|
|
265
|
+
if (values.filter(item => item === values[i]).length !== 1)
|
|
266
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).isValid: The value ${values[i]} exists multiple times, but should only exist once.`);
|
|
286
267
|
choicesChecker(values[i]);
|
|
287
268
|
}
|
|
288
269
|
} else {
|
|
@@ -290,7 +271,7 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
290
271
|
let temp: number = value;
|
|
291
272
|
if (typeof value === 'string')
|
|
292
273
|
temp = +value;
|
|
293
|
-
this.#inputValidator.validateAndError(
|
|
274
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, temp, 'number');
|
|
294
275
|
choicesChecker(value);
|
|
295
276
|
}
|
|
296
277
|
} else {
|
|
@@ -298,12 +279,12 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
298
279
|
let temp: number = value;
|
|
299
280
|
if (typeof value === 'string')
|
|
300
281
|
temp = +value;
|
|
301
|
-
this.#inputValidator.validateAndError(
|
|
282
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, temp, 'number');
|
|
302
283
|
choicesChecker(value);
|
|
303
284
|
}
|
|
304
285
|
break;
|
|
305
286
|
default:
|
|
306
|
-
this.#inputValidator.validateAndError(
|
|
287
|
+
this.#inputValidator.validateAndError(`Parameter(${this.#id}).isValid`, value, 'string');
|
|
307
288
|
break;
|
|
308
289
|
}
|
|
309
290
|
return true;
|
|
@@ -324,10 +305,8 @@ export class Parameter<T> implements IParameter<T> {
|
|
|
324
305
|
case this.type === PARAMETER_TYPE.COLOR:
|
|
325
306
|
return this.#converter.toHex8Color(this.value);
|
|
326
307
|
case this.type === PARAMETER_TYPE.FILE:
|
|
327
|
-
if (typeof this.value !== 'string')
|
|
328
|
-
|
|
329
|
-
throw this.#logger.handleError(LOGGING_TOPIC.PARAMETER, `Parameter(${this.id}).value`, error);
|
|
330
|
-
}
|
|
308
|
+
if (typeof this.value !== 'string')
|
|
309
|
+
throw new ShapeDiverViewerSessionError(`Parameter(${this.#id}).stringify: Error in stringify. Cannot stringify FileParameter that has not been uploaded yet.`);
|
|
331
310
|
return <string>this.value;
|
|
332
311
|
case this.type === PARAMETER_TYPE.EVEN || this.type === PARAMETER_TYPE.FLOAT || this.type === PARAMETER_TYPE.INT || this.type === PARAMETER_TYPE.ODD:
|
|
333
312
|
if(typeof this.value === 'string') {
|