@dnv-plant/typescriptpws 1.0.86 → 1.0.88
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/.vscode/launch.json +16 -0
- package/azure-test-folder-job.yml +2 -2
- package/index.ts +3 -3
- package/package.json +7 -6
- package/src/calculations/applicationTools.ts +29 -36
- package/src/calculations/discharge.ts +423 -321
- package/src/calculations/dispersion.ts +52 -84
- package/src/calculations/dispersionView.ts +311 -549
- package/src/calculations/fireball.ts +45 -69
- package/src/calculations/jetFire.ts +80 -129
- package/src/calculations/lateExplosion.ts +120 -210
- package/src/calculations/linkedRunners.ts +727 -1275
- package/src/calculations/poolFire.ts +45 -69
- package/src/calculations/properties.ts +32 -42
- package/src/calculations/radiation.ts +415 -714
- package/src/calculations/standalones.ts +39 -57
- package/src/calculations/toxics.ts +50 -78
- package/src/calculations/utilities.ts +357 -588
- package/src/constants.ts +9 -3
- package/src/entities.ts +3 -3
- package/src/entity-schemas.ts +3 -3
- package/src/enums.ts +4 -27
- package/src/materials.ts +236 -75
- package/src/utilities.ts +40 -9
- package/tsconfig.json +0 -100
- package/vitest.config.ts +9 -0
package/src/constants.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Editing it may lead to inconsistent results and limit DNV's ability to provide support.
|
|
7
7
|
* Please contact DNV if you believe changes are required.
|
|
8
8
|
*
|
|
9
|
-
* Version: 1.0.
|
|
10
|
-
* Date/time:
|
|
9
|
+
* Version: 1.0.89
|
|
10
|
+
* Date/time: 29 Jul 2025 17:59:09
|
|
11
11
|
* Template: templates/typescriptpws/constants.razor.
|
|
12
|
-
|
|
12
|
+
***********************************************************************/
|
|
13
13
|
|
|
14
14
|
export const ABS_TOL_RAD = 0.0000000001;
|
|
15
15
|
// Absolute tolerance for radiation calculations.
|
|
@@ -35,6 +35,9 @@ export const BESS_MAX_ANGLE = 90;
|
|
|
35
35
|
export const BESS_MAX_DURATION = 3600;
|
|
36
36
|
// Maximum duration of a BESS event (s).
|
|
37
37
|
|
|
38
|
+
export const BESS_MAX_INTERVAL = 1;
|
|
39
|
+
// Maximum value for a user specified confidence interval.
|
|
40
|
+
|
|
38
41
|
export const BESS_MIN_ANGLE = 0;
|
|
39
42
|
// Minimum release angle for a BESS event (deg.).
|
|
40
43
|
|
|
@@ -50,6 +53,9 @@ export const BESS_MIN_ENERGY = 0;
|
|
|
50
53
|
export const BESS_MIN_HEIGHT = 0;
|
|
51
54
|
// Minimum release height for a BESS event (m).
|
|
52
55
|
|
|
56
|
+
export const BESS_MIN_INTERVAL = 0.5;
|
|
57
|
+
// Minimum value for a user specified confidence interval.
|
|
58
|
+
|
|
53
59
|
export const BESS_MIN_TEMP = 273.15;
|
|
54
60
|
// Minimum gas temperature for a BESS event (K).
|
|
55
61
|
|
package/src/entities.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Editing it may lead to inconsistent results and limit DNV's ability to provide support.
|
|
7
7
|
* Please contact DNV if you believe changes are required.
|
|
8
8
|
*
|
|
9
|
-
* Version: 1.0.
|
|
10
|
-
* Date/time:
|
|
9
|
+
* Version: 1.0.89
|
|
10
|
+
* Date/time: 29 Jul 2025 17:59:10
|
|
11
11
|
* Template: templates/typescriptpws/entities.razor.
|
|
12
|
-
|
|
12
|
+
***********************************************************************/
|
|
13
13
|
|
|
14
14
|
import * as Enums from "./enums";
|
|
15
15
|
|
package/src/entity-schemas.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Editing it may lead to inconsistent results and limit DNV's ability to provide support.
|
|
7
7
|
* Please contact DNV if you believe changes are required.
|
|
8
8
|
*
|
|
9
|
-
* Version: 1.0.
|
|
10
|
-
* Date/time:
|
|
9
|
+
* Version: 1.0.89
|
|
10
|
+
* Date/time: 29 Jul 2025 17:59:11
|
|
11
11
|
* Template: templates/typescriptpws/entityschemas.razor.
|
|
12
|
-
|
|
12
|
+
***********************************************************************/
|
|
13
13
|
|
|
14
14
|
import * as Enums from "./enums";
|
|
15
15
|
import * as Entities from "./entities";
|
package/src/enums.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Editing it may lead to inconsistent results and limit DNV's ability to provide support.
|
|
7
7
|
* Please contact DNV if you believe changes are required.
|
|
8
8
|
*
|
|
9
|
-
* Version: 1.0.
|
|
10
|
-
* Date/time:
|
|
9
|
+
* Version: 1.0.89
|
|
10
|
+
* Date/time: 29 Jul 2025 17:59:10
|
|
11
11
|
* Template: templates/typescriptpws/enums.razor.
|
|
12
|
-
|
|
12
|
+
***********************************************************************/
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The Pasquill atmospheric stability classes, a common method for categorizing the amount of atmospheric turbulence present.
|
|
@@ -57,29 +57,6 @@ export enum BESSChemistry {
|
|
|
57
57
|
NMC = 2,
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
* Type of case being run.
|
|
62
|
-
*/
|
|
63
|
-
export enum CaseType {
|
|
64
|
-
/** A storage scenario which models a release of material due to rupture of a short length of pipework attached to a vessel or any kind of pressure reservoir. */
|
|
65
|
-
LINE_RUPTURE = 4,
|
|
66
|
-
|
|
67
|
-
/** A storage scenario which models a release of material from the vapour side of a vessel due to the lifting of a relief valve. */
|
|
68
|
-
RELIEF_VALVE = 3,
|
|
69
|
-
|
|
70
|
-
/** A tank roof fire, represented by a pool fire elevated at the height of the tank. */
|
|
71
|
-
TANK_FIRE = 2,
|
|
72
|
-
|
|
73
|
-
/** Case type has not been set. */
|
|
74
|
-
UNSET = -1,
|
|
75
|
-
|
|
76
|
-
/** An instanaeous release of the entire inventory of an associated vessel, intended to model an incident in which the vessel is destroyed by an impact, a crack, or some other failure which propagates very quickly. */
|
|
77
|
-
VESSEL_CATASTROPHIC_RUPTURE = 1,
|
|
78
|
-
|
|
79
|
-
/** A release of material through a hole in a vessel or pipe. */
|
|
80
|
-
VESSEL_LEAK = 0,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
60
|
/**
|
|
84
61
|
* Type of contour plot or grid.
|
|
85
62
|
*/
|
|
@@ -153,7 +130,7 @@ export enum FireType {
|
|
|
153
130
|
/** A large, intense ball of fire that rises and expands before dissipating. */
|
|
154
131
|
FIREBALL = 1,
|
|
155
132
|
|
|
156
|
-
/** A high-velocity burning jet
|
|
133
|
+
/** A high-velocity burning jet modeled using the Miller model, which represents the flame as two straight segments: the first follows the release direction, and the second bends due to buoyancy and wind effects. */
|
|
157
134
|
MULTI_POINT_SOURCE_JET = 10,
|
|
158
135
|
|
|
159
136
|
/** No fire occurs or modelled. */
|
package/src/materials.ts
CHANGED
|
@@ -6,12 +6,18 @@
|
|
|
6
6
|
* Editing it may lead to inconsistent results and limit DNV's ability to provide support.
|
|
7
7
|
* Please contact DNV if you believe changes are required.
|
|
8
8
|
*
|
|
9
|
-
* Version: 1.0.
|
|
10
|
-
* Date/time:
|
|
9
|
+
* Version: 1.0.89
|
|
10
|
+
* Date/time: 29 Jul 2025 17:59:09
|
|
11
11
|
* Template: templates/typescriptpws/materials.razor.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import {
|
|
12
|
+
***********************************************************************/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
getRequest,
|
|
16
|
+
postRequest,
|
|
17
|
+
putRequest,
|
|
18
|
+
getMaterialsApiTarget,
|
|
19
|
+
getClientAliasId,
|
|
20
|
+
} from "./utilities";
|
|
15
21
|
import { MaterialSchema, MaterialComponentDataSchema } from "./entity-schemas";
|
|
16
22
|
import { Material, MaterialComponentData } from "./entities";
|
|
17
23
|
|
|
@@ -28,10 +34,7 @@ export class MaterialInfo {
|
|
|
28
34
|
* @param {string} id - A unique identifier of the material.
|
|
29
35
|
* @param {string} name - The name of the material.
|
|
30
36
|
*/
|
|
31
|
-
constructor(
|
|
32
|
-
readonly id: string,
|
|
33
|
-
readonly name: string
|
|
34
|
-
) {}
|
|
37
|
+
constructor(readonly id: string, readonly name: string) {}
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export class MaterialCasIdInfo {
|
|
@@ -91,7 +94,11 @@ export class MaterialCasIdInfoSchema {
|
|
|
91
94
|
* @returns A MaterialCasIdInfo instance.
|
|
92
95
|
* @throws Error if validation fails.
|
|
93
96
|
*/
|
|
94
|
-
makeMaterialInfo(data: {
|
|
97
|
+
makeMaterialInfo(data: {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
casId: number;
|
|
101
|
+
}): MaterialCasIdInfo {
|
|
95
102
|
const { error, value } = this.schema.validate(data);
|
|
96
103
|
if (error) {
|
|
97
104
|
throw new Error(`Validation error: ${error.details[0].message}`);
|
|
@@ -150,28 +157,45 @@ export class MaterialEntityDescriptorSchema {
|
|
|
150
157
|
delete value.extendedProperties;
|
|
151
158
|
|
|
152
159
|
// Return a new instance of the MaterialEntityDescriptor class.
|
|
153
|
-
return new MaterialEntityDescriptor(
|
|
160
|
+
return new MaterialEntityDescriptor(
|
|
161
|
+
value.id,
|
|
162
|
+
value.displayName,
|
|
163
|
+
value.cas_id
|
|
164
|
+
);
|
|
154
165
|
}
|
|
155
166
|
}
|
|
156
167
|
|
|
157
|
-
async function getDataFromUrl<T>(
|
|
158
|
-
|
|
168
|
+
async function getDataFromUrl<T>(
|
|
169
|
+
url: string,
|
|
170
|
+
schemaClass: SchemaClass,
|
|
171
|
+
many: boolean = false,
|
|
172
|
+
controller?: AbortController
|
|
173
|
+
): Promise<T | T[]> {
|
|
174
|
+
const { data } = await getRequest(url, controller);
|
|
159
175
|
|
|
160
176
|
// Access the Joi schema from the schema class
|
|
161
|
-
const validationSchema = many
|
|
177
|
+
const validationSchema = many
|
|
178
|
+
? Joi.array().items(schemaClass.schema)
|
|
179
|
+
: schemaClass.schema;
|
|
162
180
|
|
|
163
181
|
// Validate the data
|
|
164
|
-
const { error, value } = validationSchema.validate(data, {
|
|
182
|
+
const { error, value } = validationSchema.validate(data, {
|
|
183
|
+
abortEarly: false,
|
|
184
|
+
});
|
|
165
185
|
|
|
166
186
|
if (error) {
|
|
167
|
-
const errorMessages = error.details
|
|
187
|
+
const errorMessages = error.details
|
|
188
|
+
.map((e: { message: any }) => e.message)
|
|
189
|
+
.join(", ");
|
|
168
190
|
throw new Error(`Error retrieving data: ${errorMessages}`);
|
|
169
191
|
}
|
|
170
192
|
|
|
171
193
|
return value;
|
|
172
194
|
}
|
|
173
195
|
|
|
174
|
-
export async function getAllCasIds(
|
|
196
|
+
export async function getAllCasIds(
|
|
197
|
+
controller?: AbortController
|
|
198
|
+
): Promise<MaterialCasIdInfo[]> {
|
|
175
199
|
try {
|
|
176
200
|
// Generate the URL
|
|
177
201
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -179,14 +203,23 @@ export async function getAllCasIds(): Promise<MaterialCasIdInfo[]> {
|
|
|
179
203
|
const url = `${apiTarget}cas?clientId=${clientAliasId}`;
|
|
180
204
|
|
|
181
205
|
// Fetch and validate the data
|
|
182
|
-
return getDataFromUrl(
|
|
206
|
+
return getDataFromUrl(
|
|
207
|
+
url,
|
|
208
|
+
new MaterialCasIdInfoSchema(),
|
|
209
|
+
true,
|
|
210
|
+
controller
|
|
211
|
+
) as Promise<MaterialCasIdInfo[]>;
|
|
183
212
|
} catch (error: unknown) {
|
|
184
|
-
const errorMessage =
|
|
213
|
+
const errorMessage =
|
|
214
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
185
215
|
throw new Error(`Error retrieving CAS IDs: ${errorMessage}`);
|
|
186
216
|
}
|
|
187
217
|
}
|
|
188
218
|
|
|
189
|
-
export async function getMaterialByCasId(
|
|
219
|
+
export async function getMaterialByCasId(
|
|
220
|
+
casId: number,
|
|
221
|
+
controller?: AbortController
|
|
222
|
+
): Promise<Material[]> {
|
|
190
223
|
try {
|
|
191
224
|
// Generate the URL
|
|
192
225
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -194,14 +227,25 @@ export async function getMaterialByCasId(casId: number): Promise<Material[]> {
|
|
|
194
227
|
const url = `${apiTarget}cas/${casId}?clientId=${clientAliasId}`;
|
|
195
228
|
|
|
196
229
|
// Fetch and validate the data
|
|
197
|
-
return getDataFromUrl(
|
|
230
|
+
return getDataFromUrl(
|
|
231
|
+
url,
|
|
232
|
+
new MaterialSchema(),
|
|
233
|
+
true,
|
|
234
|
+
controller
|
|
235
|
+
) as Promise<Material[]>;
|
|
198
236
|
} catch (error: unknown) {
|
|
199
|
-
const errorMessage =
|
|
200
|
-
|
|
237
|
+
const errorMessage =
|
|
238
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Error retrieving material with CAS ID ${casId}: ${errorMessage}`
|
|
241
|
+
);
|
|
201
242
|
}
|
|
202
243
|
}
|
|
203
244
|
|
|
204
|
-
export async function getComponents(
|
|
245
|
+
export async function getComponents(
|
|
246
|
+
source: number,
|
|
247
|
+
controller?: AbortController
|
|
248
|
+
): Promise<MaterialComponentData[]> {
|
|
205
249
|
try {
|
|
206
250
|
// Generate the URL
|
|
207
251
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -209,26 +253,41 @@ export async function getComponents(source: number): Promise<MaterialComponentDa
|
|
|
209
253
|
const url = `${apiTarget}components?clientId=${clientAliasId}&sources=${source}`;
|
|
210
254
|
|
|
211
255
|
// Fetch and validate the data
|
|
212
|
-
return getDataFromUrl(
|
|
256
|
+
return getDataFromUrl(
|
|
257
|
+
url,
|
|
258
|
+
new MaterialEntityDescriptorSchema(),
|
|
259
|
+
true,
|
|
260
|
+
controller
|
|
261
|
+
) as Promise<MaterialComponentData[]>;
|
|
213
262
|
} catch (error: unknown) {
|
|
214
|
-
const errorMessage =
|
|
263
|
+
const errorMessage =
|
|
264
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
215
265
|
throw new Error(`Error retrieving components: ${errorMessage}`);
|
|
216
266
|
}
|
|
217
267
|
}
|
|
218
268
|
|
|
219
|
-
export async function getDnvComponents(
|
|
220
|
-
|
|
269
|
+
export async function getDnvComponents(
|
|
270
|
+
controller?: AbortController
|
|
271
|
+
): Promise<MaterialComponentData[]> {
|
|
272
|
+
return getComponents(1, controller);
|
|
221
273
|
}
|
|
222
274
|
|
|
223
|
-
export async function getDipprComponents(
|
|
224
|
-
|
|
275
|
+
export async function getDipprComponents(
|
|
276
|
+
controller?: AbortController
|
|
277
|
+
): Promise<MaterialComponentData[]> {
|
|
278
|
+
return getComponents(2, controller);
|
|
225
279
|
}
|
|
226
280
|
|
|
227
|
-
export async function getUserComponents(
|
|
228
|
-
|
|
281
|
+
export async function getUserComponents(
|
|
282
|
+
controller?: AbortController
|
|
283
|
+
): Promise<MaterialComponentData[]> {
|
|
284
|
+
return getComponents(3, controller);
|
|
229
285
|
}
|
|
230
286
|
|
|
231
|
-
export async function getComponentById(
|
|
287
|
+
export async function getComponentById(
|
|
288
|
+
id: string,
|
|
289
|
+
controller?: AbortController
|
|
290
|
+
): Promise<MaterialComponentData> {
|
|
232
291
|
try {
|
|
233
292
|
// Generate the URL
|
|
234
293
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -236,44 +295,83 @@ export async function getComponentById(id: string): Promise<MaterialComponentDat
|
|
|
236
295
|
const url = `${apiTarget}components/id=${id}?clientId=${clientAliasId}`;
|
|
237
296
|
|
|
238
297
|
// Fetch and validate the data
|
|
239
|
-
return getDataFromUrl(
|
|
298
|
+
return getDataFromUrl(
|
|
299
|
+
url,
|
|
300
|
+
new MaterialComponentDataSchema(),
|
|
301
|
+
false,
|
|
302
|
+
controller
|
|
303
|
+
) as Promise<MaterialComponentData>;
|
|
240
304
|
} catch (error: unknown) {
|
|
241
|
-
const errorMessage =
|
|
242
|
-
|
|
305
|
+
const errorMessage =
|
|
306
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
307
|
+
throw new Error(
|
|
308
|
+
`Error retrieving component with ID ${id}: ${errorMessage}`
|
|
309
|
+
);
|
|
243
310
|
}
|
|
244
311
|
}
|
|
245
312
|
|
|
246
|
-
export async function getComponentByName(
|
|
313
|
+
export async function getComponentByName(
|
|
314
|
+
name: string,
|
|
315
|
+
controller?: AbortController
|
|
316
|
+
): Promise<MaterialComponentData> {
|
|
247
317
|
try {
|
|
248
318
|
// Generate the URL
|
|
249
319
|
const apiTarget = getMaterialsApiTarget();
|
|
250
320
|
const clientAliasId = getClientAliasId();
|
|
251
|
-
const url = `${apiTarget}components/name=${encodeURIComponent(
|
|
321
|
+
const url = `${apiTarget}components/name=${encodeURIComponent(
|
|
322
|
+
name
|
|
323
|
+
)}?clientId=${clientAliasId}`;
|
|
252
324
|
|
|
253
325
|
// Fetch and validate the data
|
|
254
|
-
return getDataFromUrl(
|
|
326
|
+
return getDataFromUrl(
|
|
327
|
+
url,
|
|
328
|
+
new MaterialComponentDataSchema(),
|
|
329
|
+
false,
|
|
330
|
+
controller
|
|
331
|
+
) as Promise<MaterialComponentData>;
|
|
255
332
|
} catch (error: unknown) {
|
|
256
|
-
const errorMessage =
|
|
257
|
-
|
|
333
|
+
const errorMessage =
|
|
334
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
335
|
+
throw new Error(
|
|
336
|
+
`Error retrieving component with name ${name}: ${errorMessage}`
|
|
337
|
+
);
|
|
258
338
|
}
|
|
259
339
|
}
|
|
260
340
|
|
|
261
|
-
export async function getComponentByCasId(
|
|
341
|
+
export async function getComponentByCasId(
|
|
342
|
+
casId: number,
|
|
343
|
+
controller?: AbortController
|
|
344
|
+
): Promise<MaterialComponentData> {
|
|
262
345
|
try {
|
|
263
346
|
// Generate the URL
|
|
264
347
|
const apiTarget = getMaterialsApiTarget();
|
|
265
348
|
const clientAliasId = getClientAliasId();
|
|
266
|
-
const url = `${apiTarget}components/casid=${encodeURIComponent(
|
|
349
|
+
const url = `${apiTarget}components/casid=${encodeURIComponent(
|
|
350
|
+
casId
|
|
351
|
+
)}?clientId=${clientAliasId}`;
|
|
267
352
|
|
|
268
353
|
// Fetch and validate the data
|
|
269
|
-
return getDataFromUrl(
|
|
354
|
+
return getDataFromUrl(
|
|
355
|
+
url,
|
|
356
|
+
new MaterialComponentDataSchema(),
|
|
357
|
+
false,
|
|
358
|
+
controller
|
|
359
|
+
) as Promise<MaterialComponentData>;
|
|
270
360
|
} catch (error: unknown) {
|
|
271
|
-
const errorMessage =
|
|
272
|
-
|
|
361
|
+
const errorMessage =
|
|
362
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Error retrieving component with CAS ID ${casId}: ${errorMessage}`
|
|
365
|
+
);
|
|
273
366
|
}
|
|
274
367
|
}
|
|
275
368
|
|
|
276
|
-
export async function storeDataAndGetResponse<T>(
|
|
369
|
+
export async function storeDataAndGetResponse<T>(
|
|
370
|
+
url: string,
|
|
371
|
+
data: any,
|
|
372
|
+
schemaClass: SchemaClass,
|
|
373
|
+
controller?: AbortController
|
|
374
|
+
): Promise<T> {
|
|
277
375
|
// Serialize the data using the schema
|
|
278
376
|
const { error: reqErr, value: payload } = schemaClass.schema.validate(data);
|
|
279
377
|
if (reqErr) {
|
|
@@ -282,7 +380,8 @@ export async function storeDataAndGetResponse<T>(url: string, data: any, schemaC
|
|
|
282
380
|
|
|
283
381
|
const { status: postStatus, headers } = await postRequest(
|
|
284
382
|
url,
|
|
285
|
-
JSON.stringify(payload)
|
|
383
|
+
JSON.stringify(payload),
|
|
384
|
+
controller
|
|
286
385
|
);
|
|
287
386
|
|
|
288
387
|
if (postStatus !== 201) {
|
|
@@ -294,18 +393,22 @@ export async function storeDataAndGetResponse<T>(url: string, data: any, schemaC
|
|
|
294
393
|
throw new Error("POST succeeded but no Location header returned");
|
|
295
394
|
}
|
|
296
395
|
|
|
297
|
-
const { data: fetched } = await getRequest(location);
|
|
396
|
+
const { data: fetched } = await getRequest(location, controller);
|
|
298
397
|
|
|
299
|
-
const { error: respErr, value: parsed } =
|
|
398
|
+
const { error: respErr, value: parsed } =
|
|
399
|
+
schemaClass.schema.validate(fetched);
|
|
300
400
|
if (respErr) {
|
|
301
|
-
throw new Error(
|
|
401
|
+
throw new Error(
|
|
402
|
+
`Validation error (response): ${respErr.details[0].message}`
|
|
403
|
+
);
|
|
302
404
|
}
|
|
303
405
|
|
|
304
406
|
return parsed as T;
|
|
305
407
|
}
|
|
306
408
|
|
|
307
409
|
export async function storeMaterialComponentData(
|
|
308
|
-
materialComponentData: MaterialComponentData
|
|
410
|
+
materialComponentData: MaterialComponentData,
|
|
411
|
+
controller?: AbortController
|
|
309
412
|
): Promise<MaterialComponentData> {
|
|
310
413
|
try {
|
|
311
414
|
// Generate the URL
|
|
@@ -314,15 +417,22 @@ export async function storeMaterialComponentData(
|
|
|
314
417
|
const url = `${apiTarget}components?clientId=${clientAliasId}`;
|
|
315
418
|
|
|
316
419
|
// Store the data and return the response
|
|
317
|
-
return storeDataAndGetResponse(
|
|
420
|
+
return storeDataAndGetResponse(
|
|
421
|
+
url,
|
|
422
|
+
materialComponentData,
|
|
423
|
+
new MaterialComponentDataSchema(),
|
|
424
|
+
controller
|
|
425
|
+
);
|
|
318
426
|
} catch (error: unknown) {
|
|
319
|
-
const errorMessage =
|
|
427
|
+
const errorMessage =
|
|
428
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
320
429
|
throw new Error(`Error storing material component data: ${errorMessage}`);
|
|
321
430
|
}
|
|
322
431
|
}
|
|
323
432
|
|
|
324
433
|
export async function storeMaterialComponentAndCreateMaterial(
|
|
325
|
-
materialComponentData: MaterialComponentData
|
|
434
|
+
materialComponentData: MaterialComponentData,
|
|
435
|
+
controller?: AbortController
|
|
326
436
|
): Promise<Material> {
|
|
327
437
|
try {
|
|
328
438
|
// Generate the URL
|
|
@@ -331,25 +441,44 @@ export async function storeMaterialComponentAndCreateMaterial(
|
|
|
331
441
|
const url = `${apiTarget}components/material?clientId=${clientAliasId}`;
|
|
332
442
|
|
|
333
443
|
// Store the data and return the response
|
|
334
|
-
return storeDataAndGetResponse(
|
|
444
|
+
return storeDataAndGetResponse(
|
|
445
|
+
url,
|
|
446
|
+
materialComponentData,
|
|
447
|
+
new MaterialSchema(),
|
|
448
|
+
controller
|
|
449
|
+
);
|
|
335
450
|
} catch (error: unknown) {
|
|
336
|
-
const errorMessage =
|
|
337
|
-
|
|
451
|
+
const errorMessage =
|
|
452
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
453
|
+
throw new Error(
|
|
454
|
+
`Error storing material component and creating material: ${errorMessage}`
|
|
455
|
+
);
|
|
338
456
|
}
|
|
339
457
|
}
|
|
340
458
|
|
|
341
|
-
export async function updateMaterialComponent(
|
|
459
|
+
export async function updateMaterialComponent(
|
|
460
|
+
data: MaterialComponentData,
|
|
461
|
+
controller?: AbortController
|
|
462
|
+
): Promise<boolean> {
|
|
342
463
|
const url = `${getMaterialsApiTarget()}components?clientId=${getClientAliasId()}`;
|
|
343
|
-
const { status, statusText } = await putRequest(
|
|
464
|
+
const { status, statusText } = await putRequest(
|
|
465
|
+
url,
|
|
466
|
+
JSON.stringify(data),
|
|
467
|
+
controller
|
|
468
|
+
);
|
|
344
469
|
|
|
345
470
|
// Check if the response status is 204 (no content)
|
|
346
471
|
if (status !== 204) {
|
|
347
|
-
throw new Error(
|
|
348
|
-
|
|
472
|
+
throw new Error(
|
|
473
|
+
`Failed to update material component: ${status} ${statusText}`
|
|
474
|
+
);
|
|
475
|
+
}
|
|
349
476
|
return true;
|
|
350
477
|
}
|
|
351
478
|
|
|
352
|
-
export async function getMaterials(
|
|
479
|
+
export async function getMaterials(
|
|
480
|
+
controller?: AbortController
|
|
481
|
+
): Promise<Material[]> {
|
|
353
482
|
try {
|
|
354
483
|
// Generate the URL
|
|
355
484
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -357,14 +486,23 @@ export async function getMaterials(): Promise<Material[]> {
|
|
|
357
486
|
const url = `${apiTarget}materials?clientId=${clientAliasId}`;
|
|
358
487
|
|
|
359
488
|
// Fetch and validate the data
|
|
360
|
-
return getDataFromUrl(
|
|
489
|
+
return getDataFromUrl(
|
|
490
|
+
url,
|
|
491
|
+
new MaterialSchema(),
|
|
492
|
+
true,
|
|
493
|
+
controller
|
|
494
|
+
) as Promise<Material[]>;
|
|
361
495
|
} catch (error: unknown) {
|
|
362
|
-
const errorMessage =
|
|
496
|
+
const errorMessage =
|
|
497
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
363
498
|
throw new Error(`Error retrieving materials: ${errorMessage}`);
|
|
364
499
|
}
|
|
365
500
|
}
|
|
366
501
|
|
|
367
|
-
export async function getMaterialById(
|
|
502
|
+
export async function getMaterialById(
|
|
503
|
+
id: string,
|
|
504
|
+
controller?: AbortController
|
|
505
|
+
): Promise<Material> {
|
|
368
506
|
try {
|
|
369
507
|
// Generate the URL
|
|
370
508
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -372,14 +510,23 @@ export async function getMaterialById(id: string): Promise<Material> {
|
|
|
372
510
|
const url = `${apiTarget}materials/id=${id}?clientId=${clientAliasId}`;
|
|
373
511
|
|
|
374
512
|
// Fetch and validate the data
|
|
375
|
-
return getDataFromUrl(
|
|
513
|
+
return getDataFromUrl(
|
|
514
|
+
url,
|
|
515
|
+
new MaterialSchema(),
|
|
516
|
+
false,
|
|
517
|
+
controller
|
|
518
|
+
) as Promise<Material>;
|
|
376
519
|
} catch (error: unknown) {
|
|
377
|
-
const errorMessage =
|
|
520
|
+
const errorMessage =
|
|
521
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
378
522
|
throw new Error(`Error retrieving material with ID ${id}: ${errorMessage}`);
|
|
379
523
|
}
|
|
380
524
|
}
|
|
381
525
|
|
|
382
|
-
export async function getMaterialByName(
|
|
526
|
+
export async function getMaterialByName(
|
|
527
|
+
name: string,
|
|
528
|
+
controller?: AbortController
|
|
529
|
+
): Promise<Material> {
|
|
383
530
|
try {
|
|
384
531
|
// Generate the URL
|
|
385
532
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -387,14 +534,22 @@ export async function getMaterialByName(name: string): Promise<Material> {
|
|
|
387
534
|
const url = `${apiTarget}materials/name=${name}?clientId=${clientAliasId}`;
|
|
388
535
|
|
|
389
536
|
// Fetch and validate the data
|
|
390
|
-
return getDataFromUrl(
|
|
537
|
+
return getDataFromUrl(
|
|
538
|
+
url,
|
|
539
|
+
new MaterialSchema(),
|
|
540
|
+
false,
|
|
541
|
+
controller
|
|
542
|
+
) as Promise<Material>;
|
|
391
543
|
} catch (error: unknown) {
|
|
392
|
-
const errorMessage =
|
|
393
|
-
|
|
544
|
+
const errorMessage =
|
|
545
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
546
|
+
throw new Error(
|
|
547
|
+
`Error retrieving material with name ${name}: ${errorMessage}`
|
|
548
|
+
);
|
|
394
549
|
}
|
|
395
550
|
}
|
|
396
551
|
|
|
397
|
-
export async function getMaterialNames() {
|
|
552
|
+
export async function getMaterialNames(controller?: AbortController) {
|
|
398
553
|
try {
|
|
399
554
|
// Generate the URL
|
|
400
555
|
const apiTarget = getMaterialsApiTarget();
|
|
@@ -402,9 +557,15 @@ export async function getMaterialNames() {
|
|
|
402
557
|
const url = `${apiTarget}materials/descriptors?clientId=${clientAliasId}`;
|
|
403
558
|
|
|
404
559
|
// Fetch and validate the data
|
|
405
|
-
return getDataFromUrl(
|
|
560
|
+
return getDataFromUrl(
|
|
561
|
+
url,
|
|
562
|
+
new MaterialInfoSchema(),
|
|
563
|
+
true,
|
|
564
|
+
controller
|
|
565
|
+
) as Promise<MaterialInfo[]>;
|
|
406
566
|
} catch (error: unknown) {
|
|
407
|
-
const errorMessage =
|
|
567
|
+
const errorMessage =
|
|
568
|
+
error instanceof Error ? error.message : "Unknown error";
|
|
408
569
|
throw new Error(`Error retrieving material names: ${errorMessage}`);
|
|
409
570
|
}
|
|
410
571
|
}
|