@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
package/index.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
/***********************************************************************
|
|
2
2
|
* This file has been auto-generated by a code generation tool.
|
|
3
|
-
* Version: 1.0.
|
|
4
|
-
* Date/time:
|
|
3
|
+
* Version: 1.0.38
|
|
4
|
+
* Date/time: 24 Mar 2025 16:46:20
|
|
5
5
|
* Template: templates/typescriptpws/index.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
|
8
|
-
export * from "./src/calculations";
|
|
9
8
|
export * from "./src/constants";
|
|
10
9
|
export * from "./src/entities";
|
|
11
10
|
export * from "./src/entity-schemas";
|
|
12
11
|
export * from "./src/enums";
|
|
13
12
|
export * from "./src/materials";
|
|
14
|
-
export * from "./src/utilities";
|
|
13
|
+
export * from "./src/utilities";
|
|
14
|
+
export * from "./src/calculations/discharge";
|
|
15
|
+
export * from "./src/calculations/dispersion";
|
|
16
|
+
export * from "./src/calculations/dispersionView";
|
|
17
|
+
export * from "./src/calculations/fireball";
|
|
18
|
+
export * from "./src/calculations/jetFire";
|
|
19
|
+
export * from "./src/calculations/lateExplosion";
|
|
20
|
+
export * from "./src/calculations/linkedRunners";
|
|
21
|
+
export * from "./src/calculations/poolFire";
|
|
22
|
+
export * from "./src/calculations/properties";
|
|
23
|
+
export * from "./src/calculations/radiation";
|
|
24
|
+
export * from "./src/calculations/standalones";
|
|
25
|
+
export * from "./src/calculations/toxics";
|
|
26
|
+
export * from "./src/calculations/applicationTools";
|
|
27
|
+
export * from "./src/calculations/utilities";
|
package/package.json
CHANGED
|
@@ -0,0 +1,368 @@
|
|
|
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 MixtureConstantPropertiesCalculationRequestSchemaData {
|
|
151
|
+
material: Entities.Material;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
class MixtureConstantPropertiesCalculationRequest extends CalculationRequestBase {
|
|
155
|
+
material: Entities.Material;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* MixtureConstantProperties calculation request class.
|
|
159
|
+
*
|
|
160
|
+
* @param {Entities.Material} material - A Material entity representing a mixture.
|
|
161
|
+
*/
|
|
162
|
+
constructor(
|
|
163
|
+
material: Entities.Material
|
|
164
|
+
) {
|
|
165
|
+
super();
|
|
166
|
+
this.material = material;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class MixtureConstantPropertiesCalculationRequestSchema {
|
|
171
|
+
schema: Joi.ObjectSchema;
|
|
172
|
+
propertyTypes: Record<string, string>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Schema for the MixtureConstantProperties calculation request.
|
|
176
|
+
*/
|
|
177
|
+
constructor() {
|
|
178
|
+
this.schema = Joi.object({
|
|
179
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
180
|
+
}).unknown(true);
|
|
181
|
+
|
|
182
|
+
this.propertyTypes = {
|
|
183
|
+
material: "Entities.Material",
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
validate(data: MixtureConstantPropertiesCalculationRequestSchemaData): MixtureConstantPropertiesCalculationRequest {
|
|
188
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
189
|
+
if (error) {
|
|
190
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
191
|
+
}
|
|
192
|
+
return this.makeCalculationRequest(value);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
makeCalculationRequest(data: MixtureConstantPropertiesCalculationRequestSchemaData): MixtureConstantPropertiesCalculationRequest {
|
|
196
|
+
return new MixtureConstantPropertiesCalculationRequest(
|
|
197
|
+
data.material
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export class MixtureConstantPropertiesCalculation extends CalculationBase {
|
|
203
|
+
material: Entities.Material;
|
|
204
|
+
mixConstantPropResult?: Entities.MixtureConstantPropertiesResult;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Calculates constant fluid properties for a mixture.
|
|
208
|
+
*
|
|
209
|
+
* @param {Entities.Material} material - A Material entity representing a mixture.
|
|
210
|
+
*/
|
|
211
|
+
constructor(
|
|
212
|
+
material: Entities.Material
|
|
213
|
+
) {
|
|
214
|
+
super();
|
|
215
|
+
this.material = material;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async run() {
|
|
219
|
+
try {
|
|
220
|
+
const request = new MixtureConstantPropertiesCalculationRequest(
|
|
221
|
+
this.material
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const schema = new MixtureConstantPropertiesCalculationRequestSchema();
|
|
225
|
+
const validatedRequest = schema.validate(request);
|
|
226
|
+
|
|
227
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
228
|
+
const url = `${getAnalyticsApiTarget()}constantmixtureproperties?clientId=${getClientAliasId()}`;
|
|
229
|
+
|
|
230
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
231
|
+
|
|
232
|
+
const response = await this.postRequest(url, requestJson);
|
|
233
|
+
|
|
234
|
+
if (response.status >= 200 && response.status < 300) {
|
|
235
|
+
const schema = new MixtureConstantPropertiesCalculationResponseSchema();
|
|
236
|
+
const validatedResponse = schema.validate(response.data);
|
|
237
|
+
|
|
238
|
+
this.resultCode = validatedResponse.resultCode;
|
|
239
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
240
|
+
this.mixConstantPropResult = validatedResponse.mixConstantPropResult;
|
|
241
|
+
this.resultCode = validatedResponse.resultCode;
|
|
242
|
+
this.messages = validatedResponse.messages ?? [];
|
|
243
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
244
|
+
this.operationId = validatedResponse.operationId;
|
|
245
|
+
} else {
|
|
246
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
this.handleFailedResponse(response);
|
|
250
|
+
}
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (error instanceof Error) {
|
|
253
|
+
this.messages.push(`Error: ${error.message}`);
|
|
254
|
+
} else {
|
|
255
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
256
|
+
}
|
|
257
|
+
console.error(error);
|
|
258
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return this.resultCode;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
toString() {
|
|
265
|
+
const parts = ["* MixtureConstantProperties"];
|
|
266
|
+
|
|
267
|
+
parts.push(`mixConstantPropResult: ${String(this.mixConstantPropResult)}`);
|
|
268
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
269
|
+
parts.push("*** messages:");
|
|
270
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
271
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
272
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
273
|
+
|
|
274
|
+
return parts.join("\n");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export class MixtureConstantPropertiesCalculationResponse extends CalculationResponseBase {
|
|
279
|
+
mixConstantPropResult: Entities.MixtureConstantPropertiesResult;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* MixtureConstantProperties calculation response class.
|
|
283
|
+
*
|
|
284
|
+
* @param {Entities.MixtureConstantPropertiesResult} mixConstantPropResult - Constant properties of the mixture.
|
|
285
|
+
*/
|
|
286
|
+
constructor(
|
|
287
|
+
mixConstantPropResult: Entities.MixtureConstantPropertiesResult,
|
|
288
|
+
resultCode: Enums.ResultCode,
|
|
289
|
+
messages: string[],
|
|
290
|
+
calculationElapsedTime: number,
|
|
291
|
+
operationId: string
|
|
292
|
+
) {
|
|
293
|
+
super();
|
|
294
|
+
this.mixConstantPropResult = mixConstantPropResult;
|
|
295
|
+
this.resultCode = resultCode;
|
|
296
|
+
this.messages = messages;
|
|
297
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
298
|
+
this.operationId = operationId;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
302
|
+
if (data.mixConstantPropResult) {
|
|
303
|
+
this.mixConstantPropResult = new Entities.MixtureConstantPropertiesResult();
|
|
304
|
+
this.mixConstantPropResult.initialiseFromDictionary(data.mixConstantPropResult as { [key: string]: unknown });
|
|
305
|
+
}
|
|
306
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
307
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
308
|
+
}
|
|
309
|
+
this.messages = this.messages ?? [];
|
|
310
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
311
|
+
this.messages.push(...data.messages);
|
|
312
|
+
}
|
|
313
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
314
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
315
|
+
}
|
|
316
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
317
|
+
this.operationId = data.operationId as string;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface MixtureConstantPropertiesCalculationResponseSchemaData {
|
|
323
|
+
mixConstantPropResult: Entities.MixtureConstantPropertiesResult;
|
|
324
|
+
resultCode: Enums.ResultCode;
|
|
325
|
+
messages: string[];
|
|
326
|
+
calculationElapsedTime: number;
|
|
327
|
+
operationId: string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export class MixtureConstantPropertiesCalculationResponseSchema {
|
|
331
|
+
schema: Joi.ObjectSchema;
|
|
332
|
+
propertyTypes: Record<string, string>;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Schema for the MixtureConstantProperties calculation response.
|
|
336
|
+
*/
|
|
337
|
+
constructor() {
|
|
338
|
+
this.schema = Joi.object({
|
|
339
|
+
mixConstantPropResult: new EntitySchemas.MixtureConstantPropertiesResultSchema().schema,
|
|
340
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
341
|
+
messages: Joi.array().items(Joi.string()),
|
|
342
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
343
|
+
operationId: Joi.string().uuid().allow(null),
|
|
344
|
+
}).unknown(true);
|
|
345
|
+
|
|
346
|
+
this.propertyTypes = {
|
|
347
|
+
mixConstantPropResult: "Entities.MixtureConstantPropertiesResult",
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
validate(data: MixtureConstantPropertiesCalculationResponseSchemaData): MixtureConstantPropertiesCalculationResponse {
|
|
352
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
353
|
+
if (error) {
|
|
354
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
355
|
+
}
|
|
356
|
+
return this.makeCalculationResponse(value);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
makeCalculationResponse(data: MixtureConstantPropertiesCalculationResponseSchemaData): MixtureConstantPropertiesCalculationResponse {
|
|
360
|
+
return new MixtureConstantPropertiesCalculationResponse(
|
|
361
|
+
data.mixConstantPropResult,
|
|
362
|
+
data.resultCode,
|
|
363
|
+
data.messages,
|
|
364
|
+
data.calculationElapsedTime,
|
|
365
|
+
data.operationId
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|