@dnv-plant/typescriptpws 1.0.77 → 1.0.78
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 +2 -2
- package/package.json +1 -1
- package/src/calculations/applicationTools.ts +22 -25
- package/src/calculations/discharge.ts +155 -176
- package/src/calculations/dispersion.ts +24 -27
- package/src/calculations/dispersionView.ts +151 -172
- package/src/calculations/fireball.ts +23 -26
- package/src/calculations/jetFire.ts +43 -49
- package/src/calculations/lateExplosion.ts +44 -50
- package/src/calculations/linkedRunners.ts +165 -177
- package/src/calculations/poolFire.ts +23 -26
- package/src/calculations/properties.ts +22 -25
- package/src/calculations/radiation.ts +228 -261
- package/src/calculations/standalones.ts +23 -26
- package/src/calculations/toxics.ts +22 -25
- package/src/calculations/utilities.ts +248 -284
- 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 +41 -73
- package/src/utilities.ts +36 -95
package/src/constants.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.78
|
|
4
|
+
* Date/time: 20 Jun 2025 16:35:06
|
|
5
5
|
* Template: templates/typescriptpws/constants.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
package/src/entities.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.78
|
|
4
|
+
* Date/time: 20 Jun 2025 16:35:07
|
|
5
5
|
* Template: templates/typescriptpws/entities.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
package/src/entity-schemas.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.78
|
|
4
|
+
* Date/time: 20 Jun 2025 16:35:08
|
|
5
5
|
* Template: templates/typescriptpws/entityschemas.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
package/src/enums.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.78
|
|
4
|
+
* Date/time: 20 Jun 2025 16:35:07
|
|
5
5
|
* Template: templates/typescriptpws/enums.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
package/src/materials.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.78
|
|
4
|
+
* Date/time: 20 Jun 2025 16:35:06
|
|
5
5
|
* Template: templates/typescriptpws/materials.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
|
@@ -149,30 +149,20 @@ export class MaterialEntityDescriptorSchema {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
async function getDataFromUrl<T>(url: string, schemaClass: SchemaClass, many: boolean = false): Promise<T | T[]> {
|
|
152
|
-
|
|
153
|
-
const response = await getRequest(url);
|
|
154
|
-
|
|
155
|
-
if (response.status !== 200) {
|
|
156
|
-
throw new Error(`Failed to get data: ${response.status} ${response.statusText}`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const data = response.data;
|
|
152
|
+
const { data} = await getRequest(url);
|
|
160
153
|
|
|
161
|
-
|
|
162
|
-
|
|
154
|
+
// Access the Joi schema from the schema class
|
|
155
|
+
const validationSchema = many ? Joi.array().items(schemaClass.schema) : schemaClass.schema;
|
|
163
156
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (error) {
|
|
168
|
-
const errorMessages = error.details.map((e: { message: any }) => e.message).join(", ");
|
|
169
|
-
throw new Error(`Error retrieving data: ${errorMessages}`);
|
|
170
|
-
}
|
|
157
|
+
// Validate the data
|
|
158
|
+
const { error, value } = validationSchema.validate(data, { abortEarly: false });
|
|
171
159
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
throw new Error(`Error retrieving data: ${
|
|
160
|
+
if (error) {
|
|
161
|
+
const errorMessages = error.details.map((e: { message: any }) => e.message).join(", ");
|
|
162
|
+
throw new Error(`Error retrieving data: ${errorMessages}`);
|
|
175
163
|
}
|
|
164
|
+
|
|
165
|
+
return value;
|
|
176
166
|
}
|
|
177
167
|
|
|
178
168
|
export async function getAllCasIds(): Promise<MaterialCasIdInfo[]> {
|
|
@@ -279,41 +269,33 @@ export async function getComponentByCasId(casId: number) {
|
|
|
279
269
|
|
|
280
270
|
export async function storeDataAndGetResponse<T>(url: string, data: any, schemaClass: SchemaClass): Promise<T> {
|
|
281
271
|
// Serialize the data using the schema
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
throw new Error(`Validation error: ${error.details[0].message}`);
|
|
272
|
+
const { error: reqErr, value: payload } = schemaClass.schema.validate(data);
|
|
273
|
+
if (reqErr) {
|
|
274
|
+
throw new Error(`Validation error (request): ${reqErr.details[0].message}`);
|
|
286
275
|
}
|
|
287
276
|
|
|
288
|
-
const
|
|
277
|
+
const { status: postStatus, headers } = await postRequest(
|
|
278
|
+
url,
|
|
279
|
+
JSON.stringify(payload)
|
|
280
|
+
);
|
|
289
281
|
|
|
290
|
-
|
|
291
|
-
|
|
282
|
+
if (postStatus !== 201) {
|
|
283
|
+
throw new Error(`Expected 201 from POST, got ${postStatus}`);
|
|
284
|
+
}
|
|
292
285
|
|
|
293
|
-
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
throw new Error("Failed to store data: no location header in response");
|
|
298
|
-
}
|
|
286
|
+
const location = headers.location ?? headers.Location; // header name can vary
|
|
287
|
+
if (!location) {
|
|
288
|
+
throw new Error("POST succeeded but no Location header returned");
|
|
289
|
+
}
|
|
299
290
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// Validate and parse the response data using the schema
|
|
306
|
-
const { error, value } = schemaClass.schema.validate(getResponse.data);
|
|
307
|
-
if (error) {
|
|
308
|
-
throw new Error(`Validation error: ${error.details[0].message}`);
|
|
309
|
-
}
|
|
310
|
-
return value;
|
|
311
|
-
} else {
|
|
312
|
-
throw new Error(`Failed to retrieve data: ${getResponse.status} ${getResponse.statusText}`);
|
|
313
|
-
}
|
|
314
|
-
} else {
|
|
315
|
-
throw new Error(`Failed to store data: ${postResponse.status} ${postResponse.statusText}`);
|
|
291
|
+
const { data: fetched } = await getRequest(location);
|
|
292
|
+
|
|
293
|
+
const { error: respErr, value: parsed } = schemaClass.schema.validate(fetched);
|
|
294
|
+
if (respErr) {
|
|
295
|
+
throw new Error(`Validation error (response): ${respErr.details[0].message}`);
|
|
316
296
|
}
|
|
297
|
+
|
|
298
|
+
return parsed as T;
|
|
317
299
|
}
|
|
318
300
|
|
|
319
301
|
export async function storeMaterialComponentData(
|
|
@@ -350,29 +332,15 @@ export async function storeMaterialComponentAndCreateMaterial(
|
|
|
350
332
|
}
|
|
351
333
|
}
|
|
352
334
|
|
|
353
|
-
export async function updateMaterialComponent(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const apiTarget = getMaterialsApiTarget();
|
|
357
|
-
const clientAliasId = getClientAliasId();
|
|
358
|
-
const url = `${apiTarget}components?clientId=${clientAliasId}`;
|
|
359
|
-
|
|
360
|
-
// Serialize the data
|
|
361
|
-
const jsonText = JSON.stringify(materialComponentData);
|
|
335
|
+
export async function updateMaterialComponent(data: MaterialComponentData): Promise<boolean> {
|
|
336
|
+
const url = `${getMaterialsApiTarget()}components?clientId=${getClientAliasId()}`;
|
|
337
|
+
const { status, statusText } = await putRequest(url, JSON.stringify(data));
|
|
362
338
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return true;
|
|
369
|
-
} else {
|
|
370
|
-
throw new Error(`Failed to update material component: ${response.status} ${response.statusText}`);
|
|
371
|
-
}
|
|
372
|
-
} catch (error: unknown) {
|
|
373
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
374
|
-
throw new Error(`Error updating material component: ${errorMessage}`);
|
|
375
|
-
}
|
|
339
|
+
// Check if the response status is 204 (no content)
|
|
340
|
+
if (status !== 204) {
|
|
341
|
+
throw new Error(`Failed to update material component: ${status} ${statusText}`);
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
376
344
|
}
|
|
377
345
|
|
|
378
346
|
export async function getMaterials(): Promise<Material[]> {
|
package/src/utilities.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.78
|
|
4
|
+
* Date/time: 20 Jun 2025 16:35:05
|
|
5
5
|
* Template: templates/typescriptpws/utilities.razor.
|
|
6
6
|
***********************************************************************/
|
|
7
7
|
|
|
@@ -56,108 +56,49 @@ function getHeaders(accessToken: string) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// Post JSON to URL and time the call
|
|
59
|
-
export async function postRequest(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
71
|
-
|
|
72
|
-
if (!hasExpired) {
|
|
73
|
-
const response = await axios.post(url, data, {
|
|
74
|
-
headers: getHeaders(accessToken),
|
|
75
|
-
});
|
|
76
|
-
return response;
|
|
77
|
-
} else {
|
|
78
|
-
console.log(`Your access token has expired: ${expiryDate}`);
|
|
79
|
-
throw new Error("Expired access token");
|
|
80
|
-
}
|
|
81
|
-
} catch (error: unknown) {
|
|
82
|
-
if (axios.isAxiosError(error)) {
|
|
83
|
-
console.error(
|
|
84
|
-
"Error during HTTP request:",
|
|
85
|
-
error.response?.data || error.message
|
|
86
|
-
);
|
|
87
|
-
throw error;
|
|
88
|
-
} else {
|
|
89
|
-
console.error("Unexpected error:", error);
|
|
90
|
-
throw new Error("Unexpected error occurred");
|
|
91
|
-
}
|
|
59
|
+
export async function postRequest<T>(url: string, data: string): Promise<AxiosResponse<T>> {
|
|
60
|
+
const accessToken = getAccessToken();
|
|
61
|
+
if (!accessToken) {
|
|
62
|
+
throw new Error("Access token not found");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
66
|
+
if (hasExpired) {
|
|
67
|
+
throw new Error(`Expired access token (${expiryDate})`);
|
|
92
68
|
}
|
|
69
|
+
|
|
70
|
+
return axios.post(url, data, { headers: getHeaders(accessToken) });
|
|
93
71
|
}
|
|
94
72
|
|
|
95
73
|
// Put JSON to URL and time the call
|
|
96
|
-
export async function putRequest(url: string, data: string) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!hasExpired) {
|
|
107
|
-
const response = await axios.put(url, data, {
|
|
108
|
-
headers: getHeaders(accessToken),
|
|
109
|
-
});
|
|
110
|
-
return response;
|
|
111
|
-
} else {
|
|
112
|
-
console.log(`Your access token has expired: ${expiryDate}`);
|
|
113
|
-
throw new Error("Expired access token");
|
|
114
|
-
}
|
|
115
|
-
} catch (error: unknown) {
|
|
116
|
-
if (axios.isAxiosError(error)) {
|
|
117
|
-
console.error(
|
|
118
|
-
"Error during HTTP request:",
|
|
119
|
-
error.response?.data || error.message
|
|
120
|
-
);
|
|
121
|
-
throw error;
|
|
122
|
-
} else {
|
|
123
|
-
console.error("Unexpected error:", error);
|
|
124
|
-
throw new Error("Unexpected error occurred");
|
|
125
|
-
}
|
|
74
|
+
export async function putRequest<T>(url: string, data: string): Promise<AxiosResponse<T>> {
|
|
75
|
+
const accessToken = getAccessToken();
|
|
76
|
+
if (!accessToken) {
|
|
77
|
+
throw new Error("Access token not found");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
81
|
+
if (hasExpired) {
|
|
82
|
+
throw new Error(`Expired access token (${expiryDate})`);
|
|
126
83
|
}
|
|
84
|
+
|
|
85
|
+
return axios.put(url, data, { headers: getHeaders(accessToken) });
|
|
127
86
|
}
|
|
128
87
|
|
|
129
88
|
// Get data from URL
|
|
130
|
-
export async function getRequest(url: string) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!accessToken) {
|
|
135
|
-
throw new Error("Access token not found");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
139
|
-
|
|
140
|
-
if (!hasExpired) {
|
|
141
|
-
const response = await axios.get(url, {
|
|
142
|
-
headers: getHeaders(accessToken),
|
|
143
|
-
});
|
|
144
|
-
return response;
|
|
145
|
-
} else {
|
|
146
|
-
console.log(`Your access token has expired: ${expiryDate}`);
|
|
147
|
-
throw new Error("Expired access token");
|
|
148
|
-
}
|
|
149
|
-
} catch (error: unknown) {
|
|
150
|
-
if (axios.isAxiosError(error)) {
|
|
151
|
-
console.error(
|
|
152
|
-
"Error during HTTP request:",
|
|
153
|
-
error.response?.data || error.message
|
|
154
|
-
);
|
|
155
|
-
throw error;
|
|
156
|
-
} else {
|
|
157
|
-
console.error("Unexpected error:", error);
|
|
158
|
-
throw new Error("Unexpected error occurred");
|
|
159
|
-
}
|
|
89
|
+
export async function getRequest<T>(url: string): Promise<AxiosResponse<T>> {
|
|
90
|
+
const accessToken = getAccessToken();
|
|
91
|
+
if (!accessToken) {
|
|
92
|
+
throw new Error("Access token not found");
|
|
160
93
|
}
|
|
94
|
+
|
|
95
|
+
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
96
|
+
if (hasExpired) {
|
|
97
|
+
console.log(`Your access token has expired: ${expiryDate}`);
|
|
98
|
+
throw new Error("Expired access token");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return axios.get(url, { headers: getHeaders(accessToken) });
|
|
161
102
|
}
|
|
162
103
|
|
|
163
104
|
// Get platform, expiry date and token expiration status
|