@swmmrs/swmmrs 0.1.0 → 0.2.0
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/README.md +264 -264
- package/dist/README.md +264 -264
- package/dist/serial/README.md +264 -264
- package/dist/serial/swmmrs_bg.wasm +0 -0
- package/dist/swmmrs.d.ts +4 -4
- package/dist/swmmrs.js +13 -13
- package/dist/swmmrs_bg.wasm +0 -0
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +53 -33
- package/src/swmmrs/client.ts +76 -76
- package/src/swmmrs/enums.ts +73 -73
- package/src/swmmrs/exceptions.ts +120 -120
- package/src/swmmrs/index.ts +79 -79
- package/src/swmmrs/objects/amm.ts +113 -113
- package/src/swmmrs/objects/collections.ts +153 -153
- package/src/swmmrs/objects/definitions.ts +246 -246
- package/src/swmmrs/objects/lids.ts +487 -487
- package/src/swmmrs/objects/links.ts +626 -626
- package/src/swmmrs/objects/nodes.ts +504 -504
- package/src/swmmrs/objects/options.ts +114 -114
- package/src/swmmrs/objects/rtk.ts +79 -79
- package/src/swmmrs/objects/subcatchments.ts +650 -650
- package/src/swmmrs/output.ts +798 -798
- package/src/swmmrs/protocol.ts +62 -62
- package/src/swmmrs/runtime.ts +188 -188
- package/src/swmmrs/scenarios.ts +40 -40
- package/src/swmmrs/simulation.ts +406 -406
- package/src/swmmrs/snapshots.ts +199 -199
- package/src/swmmrs/worker.ts +233 -233
- package/worker-node.js +142 -142
- package/worker.js +1 -1
package/package.json
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@swmmrs/swmmrs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"repository": {
|
|
5
|
-
"type": "git",
|
|
6
|
-
"url": "git+https://github.com/swmm-rs/swmmrs.git",
|
|
7
|
-
"directory": "js"
|
|
8
|
-
},
|
|
9
|
-
"type": "module",
|
|
10
|
-
"engines": {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@swmmrs/swmmrs",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/swmm-rs/swmmrs.git",
|
|
7
|
+
"directory": "js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"import": "./index.js"
|
|
17
|
+
},
|
|
18
|
+
"./worker.js": "./worker.js",
|
|
19
|
+
"./worker-node.js": "./worker-node.js"
|
|
20
|
+
},
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"index.js",
|
|
24
|
+
"index.d.ts",
|
|
25
|
+
"worker.js",
|
|
26
|
+
"worker-node.js",
|
|
27
|
+
"lib/swmmrs",
|
|
28
|
+
"src/swmmrs",
|
|
29
|
+
"dist/swmmrs.js",
|
|
30
|
+
"dist/swmmrs.d.ts",
|
|
31
|
+
"dist/swmmrs_bg.wasm",
|
|
32
|
+
"dist/snippets/**/*.js",
|
|
33
|
+
"dist/serial/swmmrs.js",
|
|
34
|
+
"dist/serial/swmmrs.d.ts",
|
|
35
|
+
"dist/serial/swmmrs_bg.wasm",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "npm run build:wasm && npm run build:ts",
|
|
40
|
+
"build:wasm": "./build.sh",
|
|
41
|
+
"build:ts": "tsc -p tsconfig.json",
|
|
42
|
+
"typecheck": "npm run build:wasm -- --dev && npm run build:ts && tsc -p tests/typing/tsconfig.json",
|
|
43
|
+
"test": "npm run build:wasm -- --dev && npm run build:ts && playwright test",
|
|
44
|
+
"test:parity": "node --test tests/parity.mjs",
|
|
45
|
+
"test:package": "node tests/package.mjs",
|
|
46
|
+
"test:docs": "node tests/docs.mjs",
|
|
47
|
+
"start": "node serve.js"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@playwright/test": "1.63.0",
|
|
51
|
+
"typescript": "7.0.2"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/swmmrs/client.ts
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { fromWorkerError, LifecycleError, WorkerError } from "./exceptions.js";
|
|
2
|
-
import type { Args, Call, Method, Response, Result } from "./protocol.js";
|
|
3
|
-
|
|
4
|
-
type Pending = { resolve: (value: unknown) => void; reject: (reason: unknown) => void };
|
|
5
|
-
|
|
6
|
-
/** Private transport for the worker shipped with this package. */
|
|
7
|
-
export class WorkerClient {
|
|
8
|
-
readonly #worker: Worker;
|
|
9
|
-
readonly #pending = new Map<number, Pending>();
|
|
10
|
-
#nextId = 0;
|
|
11
|
-
#failure: Error | undefined;
|
|
12
|
-
#closing: Promise<void> | undefined;
|
|
13
|
-
|
|
14
|
-
constructor(worker: Worker) {
|
|
15
|
-
this.#worker = worker;
|
|
16
|
-
worker.onerror = (event) => {
|
|
17
|
-
event.preventDefault();
|
|
18
|
-
this.stop(new WorkerError({ message: event.message || "SWMM worker failed" }));
|
|
19
|
-
};
|
|
20
|
-
worker.onmessageerror = () => this.stop(new WorkerError({ message: "Cannot read SWMM worker response" }));
|
|
21
|
-
worker.onmessage = ({ data }: MessageEvent<Response>) => {
|
|
22
|
-
const pending = this.#pending.get(data.id);
|
|
23
|
-
if (!pending) return;
|
|
24
|
-
this.#pending.delete(data.id);
|
|
25
|
-
if (data.ok) pending.resolve(freezeRecord(data.result));
|
|
26
|
-
else {
|
|
27
|
-
const error = fromWorkerError(data.error);
|
|
28
|
-
pending.reject(error);
|
|
29
|
-
if (data.fatal) this.stop(error);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
assertOpen(): void {
|
|
35
|
-
if (this.#failure) throw this.#failure;
|
|
36
|
-
if (this.#closing) throw new LifecycleError({ message: "Simulation is closing", operation: "close" });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
readonly call: Call = <K extends Method>(method: K, ...args: Args<K>): Promise<Result<K>> => {
|
|
40
|
-
try { this.assertOpen(); } catch (error) { return Promise.reject(error); }
|
|
41
|
-
const id = this.#nextId++;
|
|
42
|
-
return new Promise<Result<K>>((resolve, reject) => {
|
|
43
|
-
// The bundled worker implements the same Operations contract. This is the
|
|
44
|
-
// only type erasure needed to correlate request IDs with response values.
|
|
45
|
-
this.#pending.set(id, { resolve: (value) => resolve(value as Result<K>), reject });
|
|
46
|
-
try { this.#worker.postMessage({ id, method, args }); }
|
|
47
|
-
catch (error) {
|
|
48
|
-
this.#pending.delete(id);
|
|
49
|
-
reject(error);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
stop(error: Error): void {
|
|
55
|
-
this.#failure ??= error;
|
|
56
|
-
try { this.#worker.terminate(); } catch { /* The worker may already have exited. */ }
|
|
57
|
-
for (const pending of this.#pending.values()) pending.reject(this.#failure);
|
|
58
|
-
this.#pending.clear();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
close(): Promise<void> {
|
|
62
|
-
this.#closing ??= this.call("close").finally(() =>
|
|
63
|
-
this.stop(new LifecycleError({ message: "Simulation is closed", operation: "close" })),
|
|
64
|
-
);
|
|
65
|
-
return this.#closing;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Freeze copied domain records; output bytes remain caller-owned typed arrays. */
|
|
70
|
-
function freezeRecord<T>(value: T): T {
|
|
71
|
-
if (value && typeof value === "object" && !ArrayBuffer.isView(value)) {
|
|
72
|
-
for (const item of Object.values(value)) freezeRecord(item);
|
|
73
|
-
Object.freeze(value);
|
|
74
|
-
}
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
1
|
+
import { fromWorkerError, LifecycleError, WorkerError } from "./exceptions.js";
|
|
2
|
+
import type { Args, Call, Method, Response, Result } from "./protocol.js";
|
|
3
|
+
|
|
4
|
+
type Pending = { resolve: (value: unknown) => void; reject: (reason: unknown) => void };
|
|
5
|
+
|
|
6
|
+
/** Private transport for the worker shipped with this package. */
|
|
7
|
+
export class WorkerClient {
|
|
8
|
+
readonly #worker: Worker;
|
|
9
|
+
readonly #pending = new Map<number, Pending>();
|
|
10
|
+
#nextId = 0;
|
|
11
|
+
#failure: Error | undefined;
|
|
12
|
+
#closing: Promise<void> | undefined;
|
|
13
|
+
|
|
14
|
+
constructor(worker: Worker) {
|
|
15
|
+
this.#worker = worker;
|
|
16
|
+
worker.onerror = (event) => {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
this.stop(new WorkerError({ message: event.message || "SWMM worker failed" }));
|
|
19
|
+
};
|
|
20
|
+
worker.onmessageerror = () => this.stop(new WorkerError({ message: "Cannot read SWMM worker response" }));
|
|
21
|
+
worker.onmessage = ({ data }: MessageEvent<Response>) => {
|
|
22
|
+
const pending = this.#pending.get(data.id);
|
|
23
|
+
if (!pending) return;
|
|
24
|
+
this.#pending.delete(data.id);
|
|
25
|
+
if (data.ok) pending.resolve(freezeRecord(data.result));
|
|
26
|
+
else {
|
|
27
|
+
const error = fromWorkerError(data.error);
|
|
28
|
+
pending.reject(error);
|
|
29
|
+
if (data.fatal) this.stop(error);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
assertOpen(): void {
|
|
35
|
+
if (this.#failure) throw this.#failure;
|
|
36
|
+
if (this.#closing) throw new LifecycleError({ message: "Simulation is closing", operation: "close" });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
readonly call: Call = <K extends Method>(method: K, ...args: Args<K>): Promise<Result<K>> => {
|
|
40
|
+
try { this.assertOpen(); } catch (error) { return Promise.reject(error); }
|
|
41
|
+
const id = this.#nextId++;
|
|
42
|
+
return new Promise<Result<K>>((resolve, reject) => {
|
|
43
|
+
// The bundled worker implements the same Operations contract. This is the
|
|
44
|
+
// only type erasure needed to correlate request IDs with response values.
|
|
45
|
+
this.#pending.set(id, { resolve: (value) => resolve(value as Result<K>), reject });
|
|
46
|
+
try { this.#worker.postMessage({ id, method, args }); }
|
|
47
|
+
catch (error) {
|
|
48
|
+
this.#pending.delete(id);
|
|
49
|
+
reject(error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
stop(error: Error): void {
|
|
55
|
+
this.#failure ??= error;
|
|
56
|
+
try { this.#worker.terminate(); } catch { /* The worker may already have exited. */ }
|
|
57
|
+
for (const pending of this.#pending.values()) pending.reject(this.#failure);
|
|
58
|
+
this.#pending.clear();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
close(): Promise<void> {
|
|
62
|
+
this.#closing ??= this.call("close").finally(() =>
|
|
63
|
+
this.stop(new LifecycleError({ message: "Simulation is closed", operation: "close" })),
|
|
64
|
+
);
|
|
65
|
+
return this.#closing;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Freeze copied domain records; output bytes remain caller-owned typed arrays. */
|
|
70
|
+
function freezeRecord<T>(value: T): T {
|
|
71
|
+
if (value && typeof value === "object" && !ArrayBuffer.isView(value)) {
|
|
72
|
+
for (const item of Object.values(value)) freezeRecord(item);
|
|
73
|
+
Object.freeze(value);
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
}
|
package/src/swmmrs/enums.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
/** Owner lifecycle state. A type-only union, not a runtime enum. */
|
|
2
|
-
export type SimulationState = "open" | "running" | "complete" | "ended" | "failed" | "closed";
|
|
3
|
-
/** Project flow units: ft³/s, US gal/min, million US gal/day, m³/s, L/s, or million L/day. */
|
|
4
|
-
export type FlowUnits = "Cfs" | "Gpm" | "Mgd" | "Cms" | "Lps" | "Mld";
|
|
5
|
-
/** No routing, steady flow, kinematic wave, extended kinematic wave, or Dynamic Wave. */
|
|
6
|
-
export type RoutingModel = "NoRouting" | "Sf" | "Kw" | "Ekw" | "Dw";
|
|
7
|
-
/** Configured node kind. A type-only string union, not a JavaScript enum object. */
|
|
8
|
-
export type NodeKind = "Junction" | "Outfall" | "Storage" | "Divider";
|
|
9
|
-
/** Configured hydraulic link family; handles do not have public subtype subclasses. */
|
|
10
|
-
export type LinkKind = "Conduit" | "Pump" | "Orifice" | "Weir" | "Outlet";
|
|
11
|
-
/** Model calendar time, YYYY-MM-DDTHH:mm:ss, with no timezone. */
|
|
12
|
-
export type ModelTime = string;
|
|
13
|
-
/** Model unit system: US customary or SI. */
|
|
14
|
-
export type UnitSystem = "us" | "si";
|
|
15
|
-
/** Legacy EPA ellipse interpretation or true-ellipse geometry. */
|
|
16
|
-
export type CustomEllipseModel = "epa_legacy" | "true_ellipse";
|
|
17
|
-
/** EXTRAN surcharge treatment or the slot method. */
|
|
18
|
-
export type SurchargeMethod = "extran" | "slot";
|
|
19
|
-
/** Dynamic Wave inertial-term damping. */
|
|
20
|
-
export type InertiaDamping = "none" | "partial" | "full";
|
|
21
|
-
/** Criterion for limiting flow to the normal-flow value. */
|
|
22
|
-
export type NormalFlowLimit = "slope" | "froude" | "both" | "neither";
|
|
23
|
-
/** Side or bottom orifice orientation. */
|
|
24
|
-
export type OrificeKind = "side" | "bottom";
|
|
25
|
-
/** Supported weir geometries. */
|
|
26
|
-
export type WeirKind = "transverse" | "sideflow" | "v_notch" | "trapezoidal" | "roadway";
|
|
27
|
-
/** Roadway-weir surface used by its discharge relationship. */
|
|
28
|
-
export type RoadSurface = "unspecified" | "paved" | "gravel";
|
|
29
|
-
/** Outlet rating uses upstream depth or hydraulic head difference. */
|
|
30
|
-
export type OutletHeadBasis = "depth" | "head";
|
|
31
|
-
/** Native standard cross-section shape names; geometry interpretation depends on the shape. */
|
|
32
|
-
export type StandardCrossSectionShape =
|
|
33
|
-
| "dummy" | "circular" | "filled_circular" | "rect_closed" | "rect_open"
|
|
34
|
-
| "trapezoidal" | "triangular" | "parabolic" | "power_function" | "rect_triangular"
|
|
35
|
-
| "rect_round" | "modified_basket" | "horizontal_ellipse" | "vertical_ellipse"
|
|
36
|
-
| "arch" | "egg_shaped" | "horseshoe" | "gothic" | "catenary" | "semi_elliptical"
|
|
37
|
-
| "basket_handle" | "semi_circular" | "force_main";
|
|
38
|
-
/** Supported Horton, Green-Ampt, and curve-number infiltration models. */
|
|
39
|
-
export type InfilKind = "horton" | "modified_horton" | "green_ampt" | "modified_green_ampt" | "curve_number";
|
|
40
|
-
/** Receiving object family for a subcatchment outlet. */
|
|
41
|
-
export type OutKind = "node" | "subcatchment";
|
|
42
|
-
/** Seven hydraulic flow classes, in the same order used by link statistics duration arrays. */
|
|
43
|
-
export type FlowClass = "dry" | "upstream_dry" | "downstream_dry" | "subcritical" | "supercritical" | "upstream_critical" | "downstream_critical";
|
|
44
|
-
/** Known semantic solver categories. Numeric native codes remain available on errors. */
|
|
45
|
-
export type SolverErrorCode =
|
|
46
|
-
| "memory" | "kinwave" | "ode_solver" | "timestep" | "subcatch_outlet"
|
|
47
|
-
| "aquifer_params" | "ground_elev" | "length" | "elev_drop" | "roughness" | "barrels"
|
|
48
|
-
| "slope" | "no_xsect" | "xsect" | "no_curve" | "pump_limits" | "loop" | "multi_outlet"
|
|
49
|
-
| "dummy_link" | "divider" | "divider_link" | "weir_divider" | "node_depth" | "regulator"
|
|
50
|
-
| "storage_volume" | "outfall" | "regulator_shape" | "no_outlets" | "unithyd_times"
|
|
51
|
-
| "unithyd_ratios" | "rdii_area" | "rain_file_conflict" | "rain_gage_format"
|
|
52
|
-
| "rain_gage_tseries" | "rain_gage_interval" | "cyclic_treatment" | "curve_sequence"
|
|
53
|
-
| "timeseries_sequence" | "snowmelt_params" | "snowpack_params" | "lid_type"
|
|
54
|
-
| "lid_layer" | "lid_params" | "lid_areas" | "lid_capture_area" | "start_date"
|
|
55
|
-
| "report_date" | "report_step" | "input" | "line_length" | "items" | "keyword"
|
|
56
|
-
| "dup_name" | "name" | "number" | "datetime" | "rule" | "transect_unknown"
|
|
57
|
-
| "transect_sequence" | "transect_too_few" | "transect_too_many" | "transect_manning"
|
|
58
|
-
| "transect_overbank" | "transect_no_depth" | "math_expr" | "infil_params" | "file_name"
|
|
59
|
-
| "inp_file" | "rpt_file" | "out_file" | "out_size" | "out_write" | "out_read"
|
|
60
|
-
| "rain_file_scratch" | "rain_file_open" | "rain_file_data" | "rain_file_sequence"
|
|
61
|
-
| "rain_file_format" | "rain_iface_format" | "rain_file_gage" | "runoff_file_open"
|
|
62
|
-
| "runoff_file_format" | "runoff_file_end" | "runoff_file_read" | "hotstart_file_open"
|
|
63
|
-
| "hotstart_file_format" | "hotstart_file_read" | "no_climate_file" | "climate_file_open"
|
|
64
|
-
| "climate_file_read" | "climate_end_of_file" | "rdii_file_scratch" | "rdii_file_open"
|
|
65
|
-
| "rdii_file_format" | "routing_file_open" | "routing_file_format" | "routing_file_nomatch"
|
|
66
|
-
| "routing_file_names" | "table_file_open" | "table_file_read" | "checkpoint_invalid"
|
|
67
|
-
| "checkpoint_unsupported_feature" | "checkpoint_integrity" | "checkpoint_external_dependency"
|
|
68
|
-
| "checkpoint_sidecar_validation" | "checkpoint_rebuild" | "checkpoint_compatibility"
|
|
69
|
-
| "checkpoint_decode" | "checkpoint_source_identity" | "checkpoint_destination_open"
|
|
70
|
-
| "checkpoint_destination_validation" | "checkpoint_source_flush" | "checkpoint_source_preflight"
|
|
71
|
-
| "checkpoint_sidecar_copy" | "checkpoint_rain_resource" | "checkpoint_sidecar_absent"
|
|
72
|
-
| "checkpoint_rdii_resource" | "checkpoint_routing_interface" | "checkpoint_runoff_interface"
|
|
73
|
-
| "checkpoint_read" | "checkpoint_append_role" | "system";
|
|
1
|
+
/** Owner lifecycle state. A type-only union, not a runtime enum. */
|
|
2
|
+
export type SimulationState = "open" | "running" | "complete" | "ended" | "failed" | "closed";
|
|
3
|
+
/** Project flow units: ft³/s, US gal/min, million US gal/day, m³/s, L/s, or million L/day. */
|
|
4
|
+
export type FlowUnits = "Cfs" | "Gpm" | "Mgd" | "Cms" | "Lps" | "Mld";
|
|
5
|
+
/** No routing, steady flow, kinematic wave, extended kinematic wave, or Dynamic Wave. */
|
|
6
|
+
export type RoutingModel = "NoRouting" | "Sf" | "Kw" | "Ekw" | "Dw";
|
|
7
|
+
/** Configured node kind. A type-only string union, not a JavaScript enum object. */
|
|
8
|
+
export type NodeKind = "Junction" | "Outfall" | "Storage" | "Divider";
|
|
9
|
+
/** Configured hydraulic link family; handles do not have public subtype subclasses. */
|
|
10
|
+
export type LinkKind = "Conduit" | "Pump" | "Orifice" | "Weir" | "Outlet";
|
|
11
|
+
/** Model calendar time, YYYY-MM-DDTHH:mm:ss, with no timezone. */
|
|
12
|
+
export type ModelTime = string;
|
|
13
|
+
/** Model unit system: US customary or SI. */
|
|
14
|
+
export type UnitSystem = "us" | "si";
|
|
15
|
+
/** Legacy EPA ellipse interpretation or true-ellipse geometry. */
|
|
16
|
+
export type CustomEllipseModel = "epa_legacy" | "true_ellipse";
|
|
17
|
+
/** EXTRAN surcharge treatment or the slot method. */
|
|
18
|
+
export type SurchargeMethod = "extran" | "slot";
|
|
19
|
+
/** Dynamic Wave inertial-term damping. */
|
|
20
|
+
export type InertiaDamping = "none" | "partial" | "full";
|
|
21
|
+
/** Criterion for limiting flow to the normal-flow value. */
|
|
22
|
+
export type NormalFlowLimit = "slope" | "froude" | "both" | "neither";
|
|
23
|
+
/** Side or bottom orifice orientation. */
|
|
24
|
+
export type OrificeKind = "side" | "bottom";
|
|
25
|
+
/** Supported weir geometries. */
|
|
26
|
+
export type WeirKind = "transverse" | "sideflow" | "v_notch" | "trapezoidal" | "roadway";
|
|
27
|
+
/** Roadway-weir surface used by its discharge relationship. */
|
|
28
|
+
export type RoadSurface = "unspecified" | "paved" | "gravel";
|
|
29
|
+
/** Outlet rating uses upstream depth or hydraulic head difference. */
|
|
30
|
+
export type OutletHeadBasis = "depth" | "head";
|
|
31
|
+
/** Native standard cross-section shape names; geometry interpretation depends on the shape. */
|
|
32
|
+
export type StandardCrossSectionShape =
|
|
33
|
+
| "dummy" | "circular" | "filled_circular" | "rect_closed" | "rect_open"
|
|
34
|
+
| "trapezoidal" | "triangular" | "parabolic" | "power_function" | "rect_triangular"
|
|
35
|
+
| "rect_round" | "modified_basket" | "horizontal_ellipse" | "vertical_ellipse"
|
|
36
|
+
| "arch" | "egg_shaped" | "horseshoe" | "gothic" | "catenary" | "semi_elliptical"
|
|
37
|
+
| "basket_handle" | "semi_circular" | "force_main";
|
|
38
|
+
/** Supported Horton, Green-Ampt, and curve-number infiltration models. */
|
|
39
|
+
export type InfilKind = "horton" | "modified_horton" | "green_ampt" | "modified_green_ampt" | "curve_number";
|
|
40
|
+
/** Receiving object family for a subcatchment outlet. */
|
|
41
|
+
export type OutKind = "node" | "subcatchment";
|
|
42
|
+
/** Seven hydraulic flow classes, in the same order used by link statistics duration arrays. */
|
|
43
|
+
export type FlowClass = "dry" | "upstream_dry" | "downstream_dry" | "subcritical" | "supercritical" | "upstream_critical" | "downstream_critical";
|
|
44
|
+
/** Known semantic solver categories. Numeric native codes remain available on errors. */
|
|
45
|
+
export type SolverErrorCode =
|
|
46
|
+
| "memory" | "kinwave" | "ode_solver" | "timestep" | "subcatch_outlet"
|
|
47
|
+
| "aquifer_params" | "ground_elev" | "length" | "elev_drop" | "roughness" | "barrels"
|
|
48
|
+
| "slope" | "no_xsect" | "xsect" | "no_curve" | "pump_limits" | "loop" | "multi_outlet"
|
|
49
|
+
| "dummy_link" | "divider" | "divider_link" | "weir_divider" | "node_depth" | "regulator"
|
|
50
|
+
| "storage_volume" | "outfall" | "regulator_shape" | "no_outlets" | "unithyd_times"
|
|
51
|
+
| "unithyd_ratios" | "rdii_area" | "rain_file_conflict" | "rain_gage_format"
|
|
52
|
+
| "rain_gage_tseries" | "rain_gage_interval" | "cyclic_treatment" | "curve_sequence"
|
|
53
|
+
| "timeseries_sequence" | "snowmelt_params" | "snowpack_params" | "lid_type"
|
|
54
|
+
| "lid_layer" | "lid_params" | "lid_areas" | "lid_capture_area" | "start_date"
|
|
55
|
+
| "report_date" | "report_step" | "input" | "line_length" | "items" | "keyword"
|
|
56
|
+
| "dup_name" | "name" | "number" | "datetime" | "rule" | "transect_unknown"
|
|
57
|
+
| "transect_sequence" | "transect_too_few" | "transect_too_many" | "transect_manning"
|
|
58
|
+
| "transect_overbank" | "transect_no_depth" | "math_expr" | "infil_params" | "file_name"
|
|
59
|
+
| "inp_file" | "rpt_file" | "out_file" | "out_size" | "out_write" | "out_read"
|
|
60
|
+
| "rain_file_scratch" | "rain_file_open" | "rain_file_data" | "rain_file_sequence"
|
|
61
|
+
| "rain_file_format" | "rain_iface_format" | "rain_file_gage" | "runoff_file_open"
|
|
62
|
+
| "runoff_file_format" | "runoff_file_end" | "runoff_file_read" | "hotstart_file_open"
|
|
63
|
+
| "hotstart_file_format" | "hotstart_file_read" | "no_climate_file" | "climate_file_open"
|
|
64
|
+
| "climate_file_read" | "climate_end_of_file" | "rdii_file_scratch" | "rdii_file_open"
|
|
65
|
+
| "rdii_file_format" | "routing_file_open" | "routing_file_format" | "routing_file_nomatch"
|
|
66
|
+
| "routing_file_names" | "table_file_open" | "table_file_read" | "checkpoint_invalid"
|
|
67
|
+
| "checkpoint_unsupported_feature" | "checkpoint_integrity" | "checkpoint_external_dependency"
|
|
68
|
+
| "checkpoint_sidecar_validation" | "checkpoint_rebuild" | "checkpoint_compatibility"
|
|
69
|
+
| "checkpoint_decode" | "checkpoint_source_identity" | "checkpoint_destination_open"
|
|
70
|
+
| "checkpoint_destination_validation" | "checkpoint_source_flush" | "checkpoint_source_preflight"
|
|
71
|
+
| "checkpoint_sidecar_copy" | "checkpoint_rain_resource" | "checkpoint_sidecar_absent"
|
|
72
|
+
| "checkpoint_rdii_resource" | "checkpoint_routing_interface" | "checkpoint_runoff_interface"
|
|
73
|
+
| "checkpoint_read" | "checkpoint_append_role" | "system";
|
package/src/swmmrs/exceptions.ts
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
/** Native identity attached to a configuration diagnostic, not a lookup handle. */
|
|
2
|
-
export interface ConfigurationObjectIdentity {
|
|
3
|
-
/** Native object-family name. */
|
|
4
|
-
readonly objectType: string;
|
|
5
|
-
/** Canonical object ID. */
|
|
6
|
-
readonly id: string;
|
|
7
|
-
/** Native configured-order index for diagnostics. */
|
|
8
|
-
readonly index: number;
|
|
9
|
-
}
|
|
10
|
-
/** One rejected configuration rule; the complete patch remains unapplied. */
|
|
11
|
-
export interface ConfigurationDiagnostic {
|
|
12
|
-
/** Object whose declaration failed validation. */
|
|
13
|
-
readonly object: ConfigurationObjectIdentity;
|
|
14
|
-
/** Property path identifying the rejected value. */
|
|
15
|
-
readonly propertyPath: string;
|
|
16
|
-
/** Stable native validation-rule identifier. */
|
|
17
|
-
readonly ruleCode: string;
|
|
18
|
-
/** Human-readable explanation. */
|
|
19
|
-
readonly message: string;
|
|
20
|
-
/** Other object involved in the conflict, or null. */
|
|
21
|
-
readonly conflictingObject: ConfigurationObjectIdentity | null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Details retained when an error crosses the worker boundary. */
|
|
25
|
-
export interface ErrorDetails {
|
|
26
|
-
/** Required human-readable error text. */
|
|
27
|
-
message: string;
|
|
28
|
-
/** Native numeric code, when supplied. */
|
|
29
|
-
code?: number | undefined;
|
|
30
|
-
/** Operation that failed. */
|
|
31
|
-
operation?: string | undefined;
|
|
32
|
-
/** Additional native detail. */
|
|
33
|
-
detail?: string | undefined;
|
|
34
|
-
/** Semantic category, preserving unknown future values. */
|
|
35
|
-
semanticCode?: string | undefined;
|
|
36
|
-
/** Native failure category. */
|
|
37
|
-
category?: string | undefined;
|
|
38
|
-
/** Configuration diagnostics; presence takes precedence over numeric-code mapping. */
|
|
39
|
-
diagnostics?: readonly ConfigurationDiagnostic[] | undefined;
|
|
40
|
-
/** Partial report text, when available. */
|
|
41
|
-
report?: string | undefined;
|
|
42
|
-
/** Serialized secondary cleanup failure, when supplied by the worker. */
|
|
43
|
-
cleanupError?: string | undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Base runtime exception for binding and solver failures; supports `instanceof`.
|
|
47
|
-
* Ordinary Error message, name, and stack are retained. Standalone output failures
|
|
48
|
-
* use `OutputError`, not this hierarchy.
|
|
49
|
-
*/
|
|
50
|
-
export class SwmmError extends Error {
|
|
51
|
-
/** Native numeric failure code, when available. */
|
|
52
|
-
readonly code: number | undefined;
|
|
53
|
-
/** Failed public operation, when available. */
|
|
54
|
-
readonly operation: string | undefined;
|
|
55
|
-
/** Additional native failure detail. */
|
|
56
|
-
readonly detail: string | undefined;
|
|
57
|
-
/** Preserves unknown future categories rather than discarding them. */
|
|
58
|
-
readonly semanticCode: string | undefined;
|
|
59
|
-
/** Native error category. */
|
|
60
|
-
readonly category: string | undefined;
|
|
61
|
-
/** Partial report text, when available. */
|
|
62
|
-
readonly report: string | undefined;
|
|
63
|
-
/** Secondary cleanup failure retained after a primary run failure. */
|
|
64
|
-
cleanupError: unknown;
|
|
65
|
-
|
|
66
|
-
/** Construct an error with serialized or caller-supplied details.
|
|
67
|
-
* @param details - Message and optional structured failure metadata.
|
|
68
|
-
*/
|
|
69
|
-
constructor(details: ErrorDetails) {
|
|
70
|
-
super(details.message);
|
|
71
|
-
this.name = new.target.name;
|
|
72
|
-
this.code = details.code;
|
|
73
|
-
this.operation = details.operation;
|
|
74
|
-
this.detail = details.detail;
|
|
75
|
-
this.semanticCode = details.semanticCode;
|
|
76
|
-
this.category = details.category;
|
|
77
|
-
this.report = details.report;
|
|
78
|
-
this.cleanupError = details.cleanupError;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/** Native failure without a more specific binding category, including unmapped future codes. */
|
|
82
|
-
export class SolverError extends SwmmError {}
|
|
83
|
-
/** Invalid phase, closed owner, or competing advancement. Native codes: 501, 502, 503, 2001, 2002, 2013. */
|
|
84
|
-
export class LifecycleError extends SwmmError {}
|
|
85
|
-
/** Retained owner-bound view no longer matches the live owner. */
|
|
86
|
-
export class StaleViewError extends LifecycleError {}
|
|
87
|
-
/** Invalid value or read. Native codes: 504, 507, 508, 509, 2003, 2006, 2010, 2012. */
|
|
88
|
-
export class ValidationError extends SwmmError {}
|
|
89
|
-
/** Configuration rejected with object-level diagnostics; takes precedence over code-based categorization. */
|
|
90
|
-
export class ConfigurationError extends ValidationError {
|
|
91
|
-
/** Frozen diagnostic array with frozen object identities. */
|
|
92
|
-
readonly diagnostics: readonly ConfigurationDiagnostic[];
|
|
93
|
-
/** Construct a configuration failure and defensively freeze its diagnostics.
|
|
94
|
-
* @param details - Error metadata and optional diagnostic list (defaults to empty).
|
|
95
|
-
*/
|
|
96
|
-
constructor(details: ErrorDetails) {
|
|
97
|
-
super(details);
|
|
98
|
-
this.diagnostics = Object.freeze((details.diagnostics ?? []).map(diagnostic => Object.freeze({
|
|
99
|
-
...diagnostic,
|
|
100
|
-
object: Object.freeze({ ...diagnostic.object }),
|
|
101
|
-
conflictingObject: diagnostic.conflictingObject === null ? null : Object.freeze({ ...diagnostic.conflictingObject }),
|
|
102
|
-
})));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/** Unknown object/definition ID. Native codes: 505, 506, 2000, 2004, 2005, 2007, 2008, 2009. */
|
|
106
|
-
export class ObjectNotFoundError extends SwmmError {}
|
|
107
|
-
/** Worker startup, communication, or runtime prerequisite failure. */
|
|
108
|
-
export class WorkerError extends SwmmError {}
|
|
109
|
-
/** Internal native simulation failure, mapped from code 9999. */
|
|
110
|
-
export class InternalSimulationError extends WorkerError {}
|
|
111
|
-
|
|
112
|
-
/** @internal */
|
|
113
|
-
export function fromWorkerError(details: ErrorDetails): SwmmError {
|
|
114
|
-
if (details.diagnostics !== undefined) return new ConfigurationError(details);
|
|
115
|
-
if ([501, 502, 503, 2001, 2002, 2013].includes(details.code ?? -1)) return new LifecycleError(details);
|
|
116
|
-
if ([505, 506, 2000, 2004, 2005, 2007, 2008, 2009].includes(details.code ?? -1)) return new ObjectNotFoundError(details);
|
|
117
|
-
if ([504, 507, 508, 509, 2003, 2006, 2010, 2012].includes(details.code ?? -1)) return new ValidationError(details);
|
|
118
|
-
if (details.code === 9999) return new InternalSimulationError(details);
|
|
119
|
-
return new SolverError(details);
|
|
120
|
-
}
|
|
1
|
+
/** Native identity attached to a configuration diagnostic, not a lookup handle. */
|
|
2
|
+
export interface ConfigurationObjectIdentity {
|
|
3
|
+
/** Native object-family name. */
|
|
4
|
+
readonly objectType: string;
|
|
5
|
+
/** Canonical object ID. */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** Native configured-order index for diagnostics. */
|
|
8
|
+
readonly index: number;
|
|
9
|
+
}
|
|
10
|
+
/** One rejected configuration rule; the complete patch remains unapplied. */
|
|
11
|
+
export interface ConfigurationDiagnostic {
|
|
12
|
+
/** Object whose declaration failed validation. */
|
|
13
|
+
readonly object: ConfigurationObjectIdentity;
|
|
14
|
+
/** Property path identifying the rejected value. */
|
|
15
|
+
readonly propertyPath: string;
|
|
16
|
+
/** Stable native validation-rule identifier. */
|
|
17
|
+
readonly ruleCode: string;
|
|
18
|
+
/** Human-readable explanation. */
|
|
19
|
+
readonly message: string;
|
|
20
|
+
/** Other object involved in the conflict, or null. */
|
|
21
|
+
readonly conflictingObject: ConfigurationObjectIdentity | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Details retained when an error crosses the worker boundary. */
|
|
25
|
+
export interface ErrorDetails {
|
|
26
|
+
/** Required human-readable error text. */
|
|
27
|
+
message: string;
|
|
28
|
+
/** Native numeric code, when supplied. */
|
|
29
|
+
code?: number | undefined;
|
|
30
|
+
/** Operation that failed. */
|
|
31
|
+
operation?: string | undefined;
|
|
32
|
+
/** Additional native detail. */
|
|
33
|
+
detail?: string | undefined;
|
|
34
|
+
/** Semantic category, preserving unknown future values. */
|
|
35
|
+
semanticCode?: string | undefined;
|
|
36
|
+
/** Native failure category. */
|
|
37
|
+
category?: string | undefined;
|
|
38
|
+
/** Configuration diagnostics; presence takes precedence over numeric-code mapping. */
|
|
39
|
+
diagnostics?: readonly ConfigurationDiagnostic[] | undefined;
|
|
40
|
+
/** Partial report text, when available. */
|
|
41
|
+
report?: string | undefined;
|
|
42
|
+
/** Serialized secondary cleanup failure, when supplied by the worker. */
|
|
43
|
+
cleanupError?: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Base runtime exception for binding and solver failures; supports `instanceof`.
|
|
47
|
+
* Ordinary Error message, name, and stack are retained. Standalone output failures
|
|
48
|
+
* use `OutputError`, not this hierarchy.
|
|
49
|
+
*/
|
|
50
|
+
export class SwmmError extends Error {
|
|
51
|
+
/** Native numeric failure code, when available. */
|
|
52
|
+
readonly code: number | undefined;
|
|
53
|
+
/** Failed public operation, when available. */
|
|
54
|
+
readonly operation: string | undefined;
|
|
55
|
+
/** Additional native failure detail. */
|
|
56
|
+
readonly detail: string | undefined;
|
|
57
|
+
/** Preserves unknown future categories rather than discarding them. */
|
|
58
|
+
readonly semanticCode: string | undefined;
|
|
59
|
+
/** Native error category. */
|
|
60
|
+
readonly category: string | undefined;
|
|
61
|
+
/** Partial report text, when available. */
|
|
62
|
+
readonly report: string | undefined;
|
|
63
|
+
/** Secondary cleanup failure retained after a primary run failure. */
|
|
64
|
+
cleanupError: unknown;
|
|
65
|
+
|
|
66
|
+
/** Construct an error with serialized or caller-supplied details.
|
|
67
|
+
* @param details - Message and optional structured failure metadata.
|
|
68
|
+
*/
|
|
69
|
+
constructor(details: ErrorDetails) {
|
|
70
|
+
super(details.message);
|
|
71
|
+
this.name = new.target.name;
|
|
72
|
+
this.code = details.code;
|
|
73
|
+
this.operation = details.operation;
|
|
74
|
+
this.detail = details.detail;
|
|
75
|
+
this.semanticCode = details.semanticCode;
|
|
76
|
+
this.category = details.category;
|
|
77
|
+
this.report = details.report;
|
|
78
|
+
this.cleanupError = details.cleanupError;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Native failure without a more specific binding category, including unmapped future codes. */
|
|
82
|
+
export class SolverError extends SwmmError {}
|
|
83
|
+
/** Invalid phase, closed owner, or competing advancement. Native codes: 501, 502, 503, 2001, 2002, 2013. */
|
|
84
|
+
export class LifecycleError extends SwmmError {}
|
|
85
|
+
/** Retained owner-bound view no longer matches the live owner. */
|
|
86
|
+
export class StaleViewError extends LifecycleError {}
|
|
87
|
+
/** Invalid value or read. Native codes: 504, 507, 508, 509, 2003, 2006, 2010, 2012. */
|
|
88
|
+
export class ValidationError extends SwmmError {}
|
|
89
|
+
/** Configuration rejected with object-level diagnostics; takes precedence over code-based categorization. */
|
|
90
|
+
export class ConfigurationError extends ValidationError {
|
|
91
|
+
/** Frozen diagnostic array with frozen object identities. */
|
|
92
|
+
readonly diagnostics: readonly ConfigurationDiagnostic[];
|
|
93
|
+
/** Construct a configuration failure and defensively freeze its diagnostics.
|
|
94
|
+
* @param details - Error metadata and optional diagnostic list (defaults to empty).
|
|
95
|
+
*/
|
|
96
|
+
constructor(details: ErrorDetails) {
|
|
97
|
+
super(details);
|
|
98
|
+
this.diagnostics = Object.freeze((details.diagnostics ?? []).map(diagnostic => Object.freeze({
|
|
99
|
+
...diagnostic,
|
|
100
|
+
object: Object.freeze({ ...diagnostic.object }),
|
|
101
|
+
conflictingObject: diagnostic.conflictingObject === null ? null : Object.freeze({ ...diagnostic.conflictingObject }),
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Unknown object/definition ID. Native codes: 505, 506, 2000, 2004, 2005, 2007, 2008, 2009. */
|
|
106
|
+
export class ObjectNotFoundError extends SwmmError {}
|
|
107
|
+
/** Worker startup, communication, or runtime prerequisite failure. */
|
|
108
|
+
export class WorkerError extends SwmmError {}
|
|
109
|
+
/** Internal native simulation failure, mapped from code 9999. */
|
|
110
|
+
export class InternalSimulationError extends WorkerError {}
|
|
111
|
+
|
|
112
|
+
/** @internal */
|
|
113
|
+
export function fromWorkerError(details: ErrorDetails): SwmmError {
|
|
114
|
+
if (details.diagnostics !== undefined) return new ConfigurationError(details);
|
|
115
|
+
if ([501, 502, 503, 2001, 2002, 2013].includes(details.code ?? -1)) return new LifecycleError(details);
|
|
116
|
+
if ([505, 506, 2000, 2004, 2005, 2007, 2008, 2009].includes(details.code ?? -1)) return new ObjectNotFoundError(details);
|
|
117
|
+
if ([504, 507, 508, 509, 2003, 2006, 2010, 2012].includes(details.code ?? -1)) return new ValidationError(details);
|
|
118
|
+
if (details.code === 9999) return new InternalSimulationError(details);
|
|
119
|
+
return new SolverError(details);
|
|
120
|
+
}
|