@dnv-plant/typescriptpws 1.0.27 → 1.0.38-alpha.1846913
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/index.ts +17 -4
- package/package.json +2 -2
- package/src/calculations/applicationTools.ts +368 -0
- package/src/calculations/discharge.ts +1817 -0
- package/src/calculations/dispersion.ts +511 -0
- package/src/calculations/dispersionView.ts +2544 -0
- package/src/calculations/fireball.ts +458 -0
- package/src/calculations/jetFire.ts +760 -0
- package/src/calculations/lateExplosion.ts +937 -0
- package/src/calculations/linkedRunners.ts +3724 -0
- package/src/calculations/poolFire.ts +458 -0
- package/src/calculations/properties.ts +382 -0
- package/src/calculations/radiation.ts +3521 -0
- package/src/calculations/standalones.ts +432 -0
- package/src/calculations/toxics.ts +469 -0
- package/src/calculations/utilities.ts +3320 -0
- package/src/constants.ts +2 -2
- package/src/entities.ts +2 -2
- package/src/entity-schemas.ts +2 -2
- package/src/enums.ts +2 -2
- package/src/materials.ts +2 -2
- package/src/utilities.ts +2 -2
- package/src/calculations.ts +0 -17774
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* This file has been auto-generated by a code generation tool.
|
|
3
|
+
* Version: 1.0.38
|
|
4
|
+
* Date/time: 24 Mar 2025 16:46:20
|
|
5
|
+
* Template: templates/typescriptpws/calculations.razor.
|
|
6
|
+
***********************************************************************/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import * as Enums from "../enums";
|
|
11
|
+
import * as Entities from "../entities";
|
|
12
|
+
import * as EntitySchemas from "../entity-schemas";
|
|
13
|
+
import { getAnalyticsApiTarget, getClientAliasId, postRequest } from "../utilities";
|
|
14
|
+
|
|
15
|
+
import Joi from "joi";
|
|
16
|
+
import { AxiosResponse } from "axios";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CalculationRequestBase {
|
|
20
|
+
/**
|
|
21
|
+
* Calculation request base class.
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
// Base class initialization code
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class CalculationBase {
|
|
29
|
+
resultCode?: Enums.ResultCode = Enums.ResultCode.SUCCESS;
|
|
30
|
+
messages: string[] = [];
|
|
31
|
+
calculationElapsedTime?: number = 0.0;
|
|
32
|
+
operationId?: string = "";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Post JSON to URL and time the call
|
|
36
|
+
*/
|
|
37
|
+
async postRequest(url: string, data: string): Promise<AxiosResponse> {
|
|
38
|
+
return postRequest(url, data);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Utility method to print the messages returned by the calculation.
|
|
43
|
+
*/
|
|
44
|
+
printMessages(): void {
|
|
45
|
+
if (this.messages && this.messages.length > 0) {
|
|
46
|
+
this.messages.forEach((message) => console.log(message));
|
|
47
|
+
} else {
|
|
48
|
+
console.log("No messages");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Utility method to handle a failed response.
|
|
54
|
+
*/
|
|
55
|
+
handleFailedResponse(response: AxiosResponse): void {
|
|
56
|
+
try {
|
|
57
|
+
const validatedFailedResponse = new CalculationFailedResponseSchema().validate(response.data);
|
|
58
|
+
|
|
59
|
+
this.resultCode = validatedFailedResponse.resultCode;
|
|
60
|
+
this.messages.push(...(validatedFailedResponse.messages ?? []));
|
|
61
|
+
this.calculationElapsedTime = validatedFailedResponse.calculationElapsedTime;
|
|
62
|
+
this.operationId = validatedFailedResponse.operationId;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
this.messages.push(`Failed to parse response: ${error.message}`);
|
|
66
|
+
} else {
|
|
67
|
+
this.messages.push("An unknown error occurred during response parsing.");
|
|
68
|
+
}
|
|
69
|
+
console.error("Failed to parse response:", error);
|
|
70
|
+
} finally {
|
|
71
|
+
this.messages.push(`${response.statusText} (Status code: ${response.status})`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class CalculationResponseBase {
|
|
77
|
+
resultCode?: Enums.ResultCode;
|
|
78
|
+
messages?: string[];
|
|
79
|
+
calculationElapsedTime?: number;
|
|
80
|
+
operationId?: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Calculation response base class.
|
|
84
|
+
*/
|
|
85
|
+
constructor(
|
|
86
|
+
resultCode?: Enums.ResultCode,
|
|
87
|
+
messages?: string[],
|
|
88
|
+
calculationElapsedTime?: number,
|
|
89
|
+
operationId?: string
|
|
90
|
+
) {
|
|
91
|
+
this.resultCode = resultCode;
|
|
92
|
+
this.messages = messages;
|
|
93
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
94
|
+
this.operationId = operationId;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class CalculationFailedResponse extends CalculationResponseBase {
|
|
99
|
+
/**
|
|
100
|
+
* Calculation failed response class.
|
|
101
|
+
*/
|
|
102
|
+
constructor(
|
|
103
|
+
resultCode?: Enums.ResultCode,
|
|
104
|
+
messages: string[] = [],
|
|
105
|
+
calculationElapsedTime: number = 0,
|
|
106
|
+
operationId: string = ""
|
|
107
|
+
) {
|
|
108
|
+
super(resultCode, messages, calculationElapsedTime, operationId);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class CalculationFailedResponseSchema {
|
|
113
|
+
schema: Joi.ObjectSchema;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Calculation failed response schema.
|
|
117
|
+
*/
|
|
118
|
+
constructor() {
|
|
119
|
+
this.schema = Joi.object({
|
|
120
|
+
resultCode: Joi.string()
|
|
121
|
+
.valid(...Object.values(Enums.ResultCode))
|
|
122
|
+
.required(),
|
|
123
|
+
messages: Joi.array().items(Joi.string()).required(),
|
|
124
|
+
calculationElapsedTime: Joi.number().required(),
|
|
125
|
+
operationId: Joi.string().required(),
|
|
126
|
+
}).unknown(true);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
validate(data: {
|
|
130
|
+
resultCode: Enums.ResultCode;
|
|
131
|
+
messages: string[];
|
|
132
|
+
calculationElapsedTime: number;
|
|
133
|
+
operationId: string;
|
|
134
|
+
}) {
|
|
135
|
+
const { error, value } = this.schema.validate(data);
|
|
136
|
+
if (error) throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
137
|
+
return this.makeCalculationFailedResponse(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
makeCalculationFailedResponse(data: {
|
|
141
|
+
resultCode: Enums.ResultCode;
|
|
142
|
+
messages: string[];
|
|
143
|
+
calculationElapsedTime: number;
|
|
144
|
+
operationId: string;
|
|
145
|
+
}) {
|
|
146
|
+
return new CalculationFailedResponse(data.resultCode, data.messages, data.calculationElapsedTime, data.operationId);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface LethalityDistanceCalculationRequestSchemaData {
|
|
151
|
+
material: Entities.Material;
|
|
152
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
153
|
+
weather: Entities.Weather;
|
|
154
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
155
|
+
dispersionRecordCount: number;
|
|
156
|
+
substrate: Entities.Substrate;
|
|
157
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
158
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
class LethalityDistanceCalculationRequest extends CalculationRequestBase {
|
|
162
|
+
material: Entities.Material;
|
|
163
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
164
|
+
weather: Entities.Weather;
|
|
165
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
166
|
+
dispersionRecordCount: number;
|
|
167
|
+
substrate: Entities.Substrate;
|
|
168
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
169
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* LethalityDistance calculation request class.
|
|
173
|
+
*
|
|
174
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
175
|
+
* @param {Entities.ScalarUdmOutputs} scalarUdmOutputs - Scalar dispersion results.
|
|
176
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
177
|
+
* @param {Entities.DispersionRecord[]} dispersionRecords - An array of Dispersion Records.
|
|
178
|
+
* @param {number} dispersionRecordCount - Number of Dispersion Records.
|
|
179
|
+
* @param {Entities.Substrate} substrate - A substrate entity.
|
|
180
|
+
* @param {Entities.DispersionOutputConfig} dispersionOutputConfig - A Dispersion Output Config entity.
|
|
181
|
+
* @param {Entities.DispersionParameters} dispersionParameters - A Dispersion Parameters entity.
|
|
182
|
+
*/
|
|
183
|
+
constructor(
|
|
184
|
+
material: Entities.Material,
|
|
185
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs,
|
|
186
|
+
weather: Entities.Weather,
|
|
187
|
+
dispersionRecords: Entities.DispersionRecord[],
|
|
188
|
+
dispersionRecordCount: number,
|
|
189
|
+
substrate: Entities.Substrate,
|
|
190
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig,
|
|
191
|
+
dispersionParameters: Entities.DispersionParameters
|
|
192
|
+
) {
|
|
193
|
+
super();
|
|
194
|
+
this.material = material;
|
|
195
|
+
this.scalarUdmOutputs = scalarUdmOutputs;
|
|
196
|
+
this.weather = weather;
|
|
197
|
+
this.dispersionRecords = dispersionRecords;
|
|
198
|
+
this.dispersionRecordCount = dispersionRecordCount;
|
|
199
|
+
this.substrate = substrate;
|
|
200
|
+
this.dispersionOutputConfig = dispersionOutputConfig;
|
|
201
|
+
this.dispersionParameters = dispersionParameters;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export class LethalityDistanceCalculationRequestSchema {
|
|
206
|
+
schema: Joi.ObjectSchema;
|
|
207
|
+
propertyTypes: Record<string, string>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Schema for the LethalityDistance calculation request.
|
|
211
|
+
*/
|
|
212
|
+
constructor() {
|
|
213
|
+
this.schema = Joi.object({
|
|
214
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
215
|
+
scalarUdmOutputs: new EntitySchemas.ScalarUdmOutputsSchema().schema,
|
|
216
|
+
weather: new EntitySchemas.WeatherSchema().schema,
|
|
217
|
+
dispersionRecords: Joi.array().items(new EntitySchemas.DispersionRecordSchema().schema).allow(null),
|
|
218
|
+
dispersionRecordCount: Joi.number().integer(),
|
|
219
|
+
substrate: new EntitySchemas.SubstrateSchema().schema,
|
|
220
|
+
dispersionOutputConfig: new EntitySchemas.DispersionOutputConfigSchema().schema,
|
|
221
|
+
dispersionParameters: new EntitySchemas.DispersionParametersSchema().schema,
|
|
222
|
+
}).unknown(true);
|
|
223
|
+
|
|
224
|
+
this.propertyTypes = {
|
|
225
|
+
material: "Entities.Material",
|
|
226
|
+
scalarUdmOutputs: "Entities.ScalarUdmOutputs",
|
|
227
|
+
weather: "Entities.Weather",
|
|
228
|
+
dispersionRecords: "Entities.DispersionRecord[]",
|
|
229
|
+
dispersionRecordCount: "number",
|
|
230
|
+
substrate: "Entities.Substrate",
|
|
231
|
+
dispersionOutputConfig: "Entities.DispersionOutputConfig",
|
|
232
|
+
dispersionParameters: "Entities.DispersionParameters",
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
validate(data: LethalityDistanceCalculationRequestSchemaData): LethalityDistanceCalculationRequest {
|
|
237
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
238
|
+
if (error) {
|
|
239
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
240
|
+
}
|
|
241
|
+
return this.makeCalculationRequest(value);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
makeCalculationRequest(data: LethalityDistanceCalculationRequestSchemaData): LethalityDistanceCalculationRequest {
|
|
245
|
+
return new LethalityDistanceCalculationRequest(
|
|
246
|
+
data.material,
|
|
247
|
+
data.scalarUdmOutputs,
|
|
248
|
+
data.weather,
|
|
249
|
+
data.dispersionRecords,
|
|
250
|
+
data.dispersionRecordCount,
|
|
251
|
+
data.substrate,
|
|
252
|
+
data.dispersionOutputConfig,
|
|
253
|
+
data.dispersionParameters
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export class LethalityDistanceCalculation extends CalculationBase {
|
|
259
|
+
material: Entities.Material;
|
|
260
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
261
|
+
weather: Entities.Weather;
|
|
262
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
263
|
+
dispersionRecordCount: number;
|
|
264
|
+
substrate: Entities.Substrate;
|
|
265
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
266
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
267
|
+
toxicRecords?: Entities.ToxicRecord[];
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Probability of death vs distance from a dispersing toxic cloud, down to the minimum probability of death. Integrates dose over time at each location and uses probit relations to convert to a probability of death. A successful dispersion calculation is required as inputfirst.
|
|
271
|
+
*
|
|
272
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
273
|
+
* @param {Entities.ScalarUdmOutputs} scalarUdmOutputs - Scalar dispersion results.
|
|
274
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
275
|
+
* @param {Entities.DispersionRecord[]} dispersionRecords - An array of Dispersion Records.
|
|
276
|
+
* @param {number} dispersionRecordCount - Number of Dispersion Records.
|
|
277
|
+
* @param {Entities.Substrate} substrate - A substrate entity.
|
|
278
|
+
* @param {Entities.DispersionOutputConfig} dispersionOutputConfig - A Dispersion Output Config entity.
|
|
279
|
+
* @param {Entities.DispersionParameters} dispersionParameters - A Dispersion Parameters entity.
|
|
280
|
+
*/
|
|
281
|
+
constructor(
|
|
282
|
+
material: Entities.Material,
|
|
283
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs,
|
|
284
|
+
weather: Entities.Weather,
|
|
285
|
+
dispersionRecords: Entities.DispersionRecord[],
|
|
286
|
+
dispersionRecordCount: number,
|
|
287
|
+
substrate: Entities.Substrate,
|
|
288
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig,
|
|
289
|
+
dispersionParameters: Entities.DispersionParameters
|
|
290
|
+
) {
|
|
291
|
+
super();
|
|
292
|
+
this.material = material;
|
|
293
|
+
this.scalarUdmOutputs = scalarUdmOutputs;
|
|
294
|
+
this.weather = weather;
|
|
295
|
+
this.dispersionRecords = dispersionRecords;
|
|
296
|
+
this.dispersionRecordCount = dispersionRecordCount;
|
|
297
|
+
this.substrate = substrate;
|
|
298
|
+
this.dispersionOutputConfig = dispersionOutputConfig;
|
|
299
|
+
this.dispersionParameters = dispersionParameters;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async run() {
|
|
303
|
+
try {
|
|
304
|
+
const request = new LethalityDistanceCalculationRequest(
|
|
305
|
+
this.material,
|
|
306
|
+
this.scalarUdmOutputs,
|
|
307
|
+
this.weather,
|
|
308
|
+
this.dispersionRecords,
|
|
309
|
+
this.dispersionRecordCount,
|
|
310
|
+
this.substrate,
|
|
311
|
+
this.dispersionOutputConfig,
|
|
312
|
+
this.dispersionParameters
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
const schema = new LethalityDistanceCalculationRequestSchema();
|
|
316
|
+
const validatedRequest = schema.validate(request);
|
|
317
|
+
|
|
318
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
319
|
+
const url = `${getAnalyticsApiTarget()}calculatelethalitydistance?clientId=${getClientAliasId()}`;
|
|
320
|
+
|
|
321
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
322
|
+
|
|
323
|
+
const response = await this.postRequest(url, requestJson);
|
|
324
|
+
|
|
325
|
+
if (response.status >= 200 && response.status < 300) {
|
|
326
|
+
const schema = new LethalityDistanceCalculationResponseSchema();
|
|
327
|
+
const validatedResponse = schema.validate(response.data);
|
|
328
|
+
|
|
329
|
+
this.resultCode = validatedResponse.resultCode;
|
|
330
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
331
|
+
this.toxicRecords = validatedResponse.toxicRecords;
|
|
332
|
+
this.resultCode = validatedResponse.resultCode;
|
|
333
|
+
this.messages = validatedResponse.messages ?? [];
|
|
334
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
335
|
+
this.operationId = validatedResponse.operationId;
|
|
336
|
+
} else {
|
|
337
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
this.handleFailedResponse(response);
|
|
341
|
+
}
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (error instanceof Error) {
|
|
344
|
+
this.messages.push(`Error: ${error.message}`);
|
|
345
|
+
} else {
|
|
346
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
347
|
+
}
|
|
348
|
+
console.error(error);
|
|
349
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return this.resultCode;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
toString() {
|
|
356
|
+
const parts = ["* LethalityDistance"];
|
|
357
|
+
|
|
358
|
+
parts.push("*** toxicRecords:");
|
|
359
|
+
parts.push(
|
|
360
|
+
this.toxicRecords && this.toxicRecords.length > 0
|
|
361
|
+
? this.toxicRecords.map((point) => `toxicRecordsElement: ${point}`).join("\n")
|
|
362
|
+
: "toxicRecords does not contain any elements"
|
|
363
|
+
);
|
|
364
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
365
|
+
parts.push("*** messages:");
|
|
366
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
367
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
368
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
369
|
+
|
|
370
|
+
return parts.join("\n");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export class LethalityDistanceCalculationResponse extends CalculationResponseBase {
|
|
375
|
+
toxicRecords: Entities.ToxicRecord[];
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* LethalityDistance calculation response class.
|
|
379
|
+
*
|
|
380
|
+
* @param {Entities.ToxicRecord[]} toxicRecords - An Array of Toxic Records.
|
|
381
|
+
*/
|
|
382
|
+
constructor(
|
|
383
|
+
toxicRecords: Entities.ToxicRecord[],
|
|
384
|
+
resultCode: Enums.ResultCode,
|
|
385
|
+
messages: string[],
|
|
386
|
+
calculationElapsedTime: number,
|
|
387
|
+
operationId: string
|
|
388
|
+
) {
|
|
389
|
+
super();
|
|
390
|
+
this.toxicRecords = toxicRecords;
|
|
391
|
+
this.resultCode = resultCode;
|
|
392
|
+
this.messages = messages;
|
|
393
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
394
|
+
this.operationId = operationId;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
398
|
+
if (data.toxicRecords && Array.isArray(data.toxicRecords)) {
|
|
399
|
+
this.toxicRecords = data.toxicRecords.map(
|
|
400
|
+
(item) => {
|
|
401
|
+
const record = new Entities.ToxicRecord();
|
|
402
|
+
record.initialiseFromDictionary(item);
|
|
403
|
+
return record;
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
408
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
409
|
+
}
|
|
410
|
+
this.messages = this.messages ?? [];
|
|
411
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
412
|
+
this.messages.push(...data.messages);
|
|
413
|
+
}
|
|
414
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
415
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
416
|
+
}
|
|
417
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
418
|
+
this.operationId = data.operationId as string;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface LethalityDistanceCalculationResponseSchemaData {
|
|
424
|
+
toxicRecords: Entities.ToxicRecord[];
|
|
425
|
+
resultCode: Enums.ResultCode;
|
|
426
|
+
messages: string[];
|
|
427
|
+
calculationElapsedTime: number;
|
|
428
|
+
operationId: string;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export class LethalityDistanceCalculationResponseSchema {
|
|
432
|
+
schema: Joi.ObjectSchema;
|
|
433
|
+
propertyTypes: Record<string, string>;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Schema for the LethalityDistance calculation response.
|
|
437
|
+
*/
|
|
438
|
+
constructor() {
|
|
439
|
+
this.schema = Joi.object({
|
|
440
|
+
toxicRecords: Joi.array().items(new EntitySchemas.ToxicRecordSchema().schema).allow(null),
|
|
441
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
442
|
+
messages: Joi.array().items(Joi.string()),
|
|
443
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
444
|
+
operationId: Joi.string().uuid().allow(null),
|
|
445
|
+
}).unknown(true);
|
|
446
|
+
|
|
447
|
+
this.propertyTypes = {
|
|
448
|
+
toxicRecords: "Entities.ToxicRecord[]",
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
validate(data: LethalityDistanceCalculationResponseSchemaData): LethalityDistanceCalculationResponse {
|
|
453
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
454
|
+
if (error) {
|
|
455
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
456
|
+
}
|
|
457
|
+
return this.makeCalculationResponse(value);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
makeCalculationResponse(data: LethalityDistanceCalculationResponseSchemaData): LethalityDistanceCalculationResponse {
|
|
461
|
+
return new LethalityDistanceCalculationResponse(
|
|
462
|
+
data.toxicRecords,
|
|
463
|
+
data.resultCode,
|
|
464
|
+
data.messages,
|
|
465
|
+
data.calculationElapsedTime,
|
|
466
|
+
data.operationId
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
}
|