@dnv-plant/typescriptpws 1.0.27 → 1.0.38
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 +1 -1
- 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,458 @@
|
|
|
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 PoolFireCalculationRequestSchemaData {
|
|
151
|
+
material: Entities.Material;
|
|
152
|
+
poolRecords: Entities.PoolRecord[];
|
|
153
|
+
poolRecordCount: number;
|
|
154
|
+
weather: Entities.Weather;
|
|
155
|
+
substrate: Entities.Substrate;
|
|
156
|
+
flammableParameters: Entities.FlammableParameters;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
class PoolFireCalculationRequest extends CalculationRequestBase {
|
|
160
|
+
material: Entities.Material;
|
|
161
|
+
poolRecords: Entities.PoolRecord[];
|
|
162
|
+
poolRecordCount: number;
|
|
163
|
+
weather: Entities.Weather;
|
|
164
|
+
substrate: Entities.Substrate;
|
|
165
|
+
flammableParameters: Entities.FlammableParameters;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* PoolFire calculation request class.
|
|
169
|
+
*
|
|
170
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
171
|
+
* @param {Entities.PoolRecord[]} poolRecords - An array of Pool Records.
|
|
172
|
+
* @param {number} poolRecordCount - Number of Pool Records.
|
|
173
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
174
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
175
|
+
* @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
|
|
176
|
+
*/
|
|
177
|
+
constructor(
|
|
178
|
+
material: Entities.Material,
|
|
179
|
+
poolRecords: Entities.PoolRecord[],
|
|
180
|
+
poolRecordCount: number,
|
|
181
|
+
weather: Entities.Weather,
|
|
182
|
+
substrate: Entities.Substrate,
|
|
183
|
+
flammableParameters: Entities.FlammableParameters
|
|
184
|
+
) {
|
|
185
|
+
super();
|
|
186
|
+
this.material = material;
|
|
187
|
+
this.poolRecords = poolRecords;
|
|
188
|
+
this.poolRecordCount = poolRecordCount;
|
|
189
|
+
this.weather = weather;
|
|
190
|
+
this.substrate = substrate;
|
|
191
|
+
this.flammableParameters = flammableParameters;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export class PoolFireCalculationRequestSchema {
|
|
196
|
+
schema: Joi.ObjectSchema;
|
|
197
|
+
propertyTypes: Record<string, string>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Schema for the PoolFire calculation request.
|
|
201
|
+
*/
|
|
202
|
+
constructor() {
|
|
203
|
+
this.schema = Joi.object({
|
|
204
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
205
|
+
poolRecords: Joi.array().items(new EntitySchemas.PoolRecordSchema().schema).allow(null),
|
|
206
|
+
poolRecordCount: Joi.number().integer(),
|
|
207
|
+
weather: new EntitySchemas.WeatherSchema().schema,
|
|
208
|
+
substrate: new EntitySchemas.SubstrateSchema().schema,
|
|
209
|
+
flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
|
|
210
|
+
}).unknown(true);
|
|
211
|
+
|
|
212
|
+
this.propertyTypes = {
|
|
213
|
+
material: "Entities.Material",
|
|
214
|
+
poolRecords: "Entities.PoolRecord[]",
|
|
215
|
+
poolRecordCount: "number",
|
|
216
|
+
weather: "Entities.Weather",
|
|
217
|
+
substrate: "Entities.Substrate",
|
|
218
|
+
flammableParameters: "Entities.FlammableParameters",
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
validate(data: PoolFireCalculationRequestSchemaData): PoolFireCalculationRequest {
|
|
223
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
224
|
+
if (error) {
|
|
225
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
226
|
+
}
|
|
227
|
+
return this.makeCalculationRequest(value);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
makeCalculationRequest(data: PoolFireCalculationRequestSchemaData): PoolFireCalculationRequest {
|
|
231
|
+
return new PoolFireCalculationRequest(
|
|
232
|
+
data.material,
|
|
233
|
+
data.poolRecords,
|
|
234
|
+
data.poolRecordCount,
|
|
235
|
+
data.weather,
|
|
236
|
+
data.substrate,
|
|
237
|
+
data.flammableParameters
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export class PoolFireCalculation extends CalculationBase {
|
|
243
|
+
material: Entities.Material;
|
|
244
|
+
poolRecords: Entities.PoolRecord[];
|
|
245
|
+
poolRecordCount: number;
|
|
246
|
+
weather: Entities.Weather;
|
|
247
|
+
substrate: Entities.Substrate;
|
|
248
|
+
flammableParameters: Entities.FlammableParameters;
|
|
249
|
+
poolFireFlameResult?: Entities.PoolFireFlameResult;
|
|
250
|
+
flameRecords?: Entities.FlameRecord[];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Determines the flame produced from an ignited flammable pool.
|
|
254
|
+
*
|
|
255
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
256
|
+
* @param {Entities.PoolRecord[]} poolRecords - An array of Pool Records.
|
|
257
|
+
* @param {number} poolRecordCount - Number of Pool Records.
|
|
258
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
259
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
260
|
+
* @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
|
|
261
|
+
*/
|
|
262
|
+
constructor(
|
|
263
|
+
material: Entities.Material,
|
|
264
|
+
poolRecords: Entities.PoolRecord[],
|
|
265
|
+
poolRecordCount: number,
|
|
266
|
+
weather: Entities.Weather,
|
|
267
|
+
substrate: Entities.Substrate,
|
|
268
|
+
flammableParameters: Entities.FlammableParameters
|
|
269
|
+
) {
|
|
270
|
+
super();
|
|
271
|
+
this.material = material;
|
|
272
|
+
this.poolRecords = poolRecords;
|
|
273
|
+
this.poolRecordCount = poolRecordCount;
|
|
274
|
+
this.weather = weather;
|
|
275
|
+
this.substrate = substrate;
|
|
276
|
+
this.flammableParameters = flammableParameters;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async run() {
|
|
280
|
+
try {
|
|
281
|
+
const request = new PoolFireCalculationRequest(
|
|
282
|
+
this.material,
|
|
283
|
+
this.poolRecords,
|
|
284
|
+
this.poolRecordCount,
|
|
285
|
+
this.weather,
|
|
286
|
+
this.substrate,
|
|
287
|
+
this.flammableParameters
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const schema = new PoolFireCalculationRequestSchema();
|
|
291
|
+
const validatedRequest = schema.validate(request);
|
|
292
|
+
|
|
293
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
294
|
+
const url = `${getAnalyticsApiTarget()}calculatepoolfire?clientId=${getClientAliasId()}`;
|
|
295
|
+
|
|
296
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
297
|
+
|
|
298
|
+
const response = await this.postRequest(url, requestJson);
|
|
299
|
+
|
|
300
|
+
if (response.status >= 200 && response.status < 300) {
|
|
301
|
+
const schema = new PoolFireCalculationResponseSchema();
|
|
302
|
+
const validatedResponse = schema.validate(response.data);
|
|
303
|
+
|
|
304
|
+
this.resultCode = validatedResponse.resultCode;
|
|
305
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
306
|
+
this.poolFireFlameResult = validatedResponse.poolFireFlameResult;
|
|
307
|
+
this.flameRecords = validatedResponse.flameRecords;
|
|
308
|
+
this.resultCode = validatedResponse.resultCode;
|
|
309
|
+
this.messages = validatedResponse.messages ?? [];
|
|
310
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
311
|
+
this.operationId = validatedResponse.operationId;
|
|
312
|
+
} else {
|
|
313
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
this.handleFailedResponse(response);
|
|
317
|
+
}
|
|
318
|
+
} catch (error) {
|
|
319
|
+
if (error instanceof Error) {
|
|
320
|
+
this.messages.push(`Error: ${error.message}`);
|
|
321
|
+
} else {
|
|
322
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
323
|
+
}
|
|
324
|
+
console.error(error);
|
|
325
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return this.resultCode;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
toString() {
|
|
332
|
+
const parts = ["* PoolFire"];
|
|
333
|
+
|
|
334
|
+
parts.push(`poolFireFlameResult: ${String(this.poolFireFlameResult)}`);
|
|
335
|
+
parts.push("*** flameRecords:");
|
|
336
|
+
parts.push(
|
|
337
|
+
this.flameRecords && this.flameRecords.length > 0
|
|
338
|
+
? this.flameRecords.map((point) => `flameRecordsElement: ${point}`).join("\n")
|
|
339
|
+
: "flameRecords does not contain any elements"
|
|
340
|
+
);
|
|
341
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
342
|
+
parts.push("*** messages:");
|
|
343
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
344
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
345
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
346
|
+
|
|
347
|
+
return parts.join("\n");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export class PoolFireCalculationResponse extends CalculationResponseBase {
|
|
352
|
+
poolFireFlameResult: Entities.PoolFireFlameResult;
|
|
353
|
+
flameRecords: Entities.FlameRecord[];
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* PoolFire calculation response class.
|
|
357
|
+
*
|
|
358
|
+
* @param {Entities.PoolFireFlameResult} poolFireFlameResult - Scalar flame results.
|
|
359
|
+
* @param {Entities.FlameRecord[]} flameRecords - An array of pool fire Flame Records.
|
|
360
|
+
*/
|
|
361
|
+
constructor(
|
|
362
|
+
poolFireFlameResult: Entities.PoolFireFlameResult,
|
|
363
|
+
flameRecords: Entities.FlameRecord[],
|
|
364
|
+
resultCode: Enums.ResultCode,
|
|
365
|
+
messages: string[],
|
|
366
|
+
calculationElapsedTime: number,
|
|
367
|
+
operationId: string
|
|
368
|
+
) {
|
|
369
|
+
super();
|
|
370
|
+
this.poolFireFlameResult = poolFireFlameResult;
|
|
371
|
+
this.flameRecords = flameRecords;
|
|
372
|
+
this.resultCode = resultCode;
|
|
373
|
+
this.messages = messages;
|
|
374
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
375
|
+
this.operationId = operationId;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
379
|
+
if (data.poolFireFlameResult) {
|
|
380
|
+
this.poolFireFlameResult = new Entities.PoolFireFlameResult();
|
|
381
|
+
this.poolFireFlameResult.initialiseFromDictionary(data.poolFireFlameResult as { [key: string]: unknown });
|
|
382
|
+
}
|
|
383
|
+
if (data.flameRecords && Array.isArray(data.flameRecords)) {
|
|
384
|
+
this.flameRecords = data.flameRecords.map(
|
|
385
|
+
(item) => {
|
|
386
|
+
const record = new Entities.FlameRecord();
|
|
387
|
+
record.initialiseFromDictionary(item);
|
|
388
|
+
return record;
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
393
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
394
|
+
}
|
|
395
|
+
this.messages = this.messages ?? [];
|
|
396
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
397
|
+
this.messages.push(...data.messages);
|
|
398
|
+
}
|
|
399
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
400
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
401
|
+
}
|
|
402
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
403
|
+
this.operationId = data.operationId as string;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export interface PoolFireCalculationResponseSchemaData {
|
|
409
|
+
poolFireFlameResult: Entities.PoolFireFlameResult;
|
|
410
|
+
flameRecords: Entities.FlameRecord[];
|
|
411
|
+
resultCode: Enums.ResultCode;
|
|
412
|
+
messages: string[];
|
|
413
|
+
calculationElapsedTime: number;
|
|
414
|
+
operationId: string;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export class PoolFireCalculationResponseSchema {
|
|
418
|
+
schema: Joi.ObjectSchema;
|
|
419
|
+
propertyTypes: Record<string, string>;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Schema for the PoolFire calculation response.
|
|
423
|
+
*/
|
|
424
|
+
constructor() {
|
|
425
|
+
this.schema = Joi.object({
|
|
426
|
+
poolFireFlameResult: new EntitySchemas.PoolFireFlameResultSchema().schema,
|
|
427
|
+
flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
|
|
428
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
429
|
+
messages: Joi.array().items(Joi.string()),
|
|
430
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
431
|
+
operationId: Joi.string().uuid().allow(null),
|
|
432
|
+
}).unknown(true);
|
|
433
|
+
|
|
434
|
+
this.propertyTypes = {
|
|
435
|
+
poolFireFlameResult: "Entities.PoolFireFlameResult",
|
|
436
|
+
flameRecords: "Entities.FlameRecord[]",
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
validate(data: PoolFireCalculationResponseSchemaData): PoolFireCalculationResponse {
|
|
441
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
442
|
+
if (error) {
|
|
443
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
444
|
+
}
|
|
445
|
+
return this.makeCalculationResponse(value);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
makeCalculationResponse(data: PoolFireCalculationResponseSchemaData): PoolFireCalculationResponse {
|
|
449
|
+
return new PoolFireCalculationResponse(
|
|
450
|
+
data.poolFireFlameResult,
|
|
451
|
+
data.flameRecords,
|
|
452
|
+
data.resultCode,
|
|
453
|
+
data.messages,
|
|
454
|
+
data.calculationElapsedTime,
|
|
455
|
+
data.operationId
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
}
|