@welldot/core 0.1.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/LICENSE ADDED
@@ -0,0 +1,179 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or otherwise designated in writing by the copyright owner as
57
+ "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and incorporated
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or as an addendum to
115
+ the NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the Work,
121
+ provided such statement does not conflict with the terms of this License.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer only
163
+ conditions consistent with this License.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ Copyright (c) 2024 Rafael Neto
168
+
169
+ Licensed under the Apache License, Version 2.0 (the "License");
170
+ you may not use this file except in compliance with the License.
171
+ You may obtain a copy of the License at
172
+
173
+ http://www.apache.org/licenses/LICENSE-2.0
174
+
175
+ Unless required by applicable law or agreed to in writing, software
176
+ distributed under the License is distributed on an "AS IS" BASIS,
177
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178
+ See the License for the specific language governing permissions and
179
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # @welldot/core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@welldot/core.svg)](https://www.npmjs.com/package/@welldot/core)
4
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-3178c6.svg)](https://www.typescriptlang.org/)
6
+
7
+ TypeScript types, Zod validators, and serialization utilities for the `.well` open format — a JSON-based standard for representing water well data.
8
+
9
+ ## What is `.well`?
10
+
11
+ `.well` is an open file format for encoding the complete static record of a water well as a single, self-describing JSON document. A `.well` file contains:
12
+
13
+ - **Constructive data** — borehole geometry, casing strings, screens, reducers, gravel packs, and cement pads
14
+ - **Geologic data** — lithological column, discrete fractures, and cave zones
15
+ - **Administrative metadata** — name, driller, construction date, geographic coordinates, and elevation
16
+
17
+ The format is designed for three use cases: visualization of technical well profiles, registration with regulatory bodies, and hydrogeological research.
18
+
19
+ See the [full format specification](./well-specifications.md) for the complete schema reference and design rationale.
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ # npm
25
+ npm install @welldot/core
26
+
27
+ # pnpm
28
+ pnpm add @welldot/core
29
+
30
+ # yarn
31
+ yarn add @welldot/core
32
+ ```
33
+
34
+ **Requirements:** Node.js >= 18. [`zod`](https://zod.dev) is bundled as a dependency.
35
+
36
+ ## Quick Start
37
+
38
+ ```typescript
39
+ import type { Well, BoreHole, Lithology } from '@welldot/core';
40
+ import {
41
+ WellSchema,
42
+ parseWell,
43
+ serializeWell,
44
+ deserializeWell,
45
+ isWellEmpty,
46
+ } from '@welldot/core';
47
+
48
+ // Parse and validate a .well JSON string — throws ZodError on invalid input
49
+ const well = parseWell(rawJsonString);
50
+
51
+ // Validate an existing object with the Zod schema directly
52
+ const result = WellSchema.safeParse(unknownData);
53
+
54
+ // Serialize a Well object to a versioned JSON string
55
+ const jsonString = serializeWell(well);
56
+
57
+ // Deserialize — handles versioned format and legacy formats
58
+ const restored = deserializeWell(jsonString);
59
+
60
+ // Check if a well contains any data
61
+ const empty = isWellEmpty(well);
62
+ ```
63
+
64
+ ## API Reference
65
+
66
+ ### Types
67
+
68
+ All types are exported as TypeScript type-only exports (zero runtime cost).
69
+
70
+ | Type | Description |
71
+ |------|-------------|
72
+ | `Well` | Complete static record of a water well |
73
+ | `BoreHole` | A drilled interval with diameter and optional drilling method |
74
+ | `WellCase` | Steel or plastic casing installed in the borehole |
75
+ | `Reduction` | Transition piece between different casing diameters |
76
+ | `WellScreen` | Slotted screen section for water intake |
77
+ | `SurfaceCase` | Protective casing near the surface |
78
+ | `HoleFill` | Annular fill material (`gravel_pack` or `seal`) |
79
+ | `CementPad` | Concrete wellhead pad dimensions |
80
+ | `Lithology` | Geological description of a depth interval |
81
+ | `Fracture` | A discrete fracture or fracture zone |
82
+ | `Cave` | A cavity or void zone |
83
+ | `Constructive` | Grouped type: borehole + casings + screens + fills |
84
+ | `Geologic` | Grouped type: lithology + fractures + caves |
85
+ | `Units` | `{ length: 'm' \| 'ft'; diameter: 'mm' \| 'inches' }` |
86
+ | `LengthUnits` | `'m' \| 'ft'` |
87
+ | `DiameterUnits` | `'mm' \| 'inches'` |
88
+ | `UnitsTypes` | `'metric' \| 'imperial'` |
89
+
90
+ ### Validators
91
+
92
+ Each schema validates its corresponding type at runtime. All schemas are Zod objects and compose with standard Zod methods (`.parse`, `.safeParse`, `.extend`, etc.).
93
+
94
+ | Export | Validates |
95
+ |--------|-----------|
96
+ | `WellSchema` | `Well` (the complete document) |
97
+ | `BoreHoleSchema` | `BoreHole` |
98
+ | `WellCaseSchema` | `WellCase` |
99
+ | `ReductionSchema` | `Reduction` |
100
+ | `WellScreenSchema` | `WellScreen` |
101
+ | `SurfaceCaseSchema` | `SurfaceCase` |
102
+ | `HoleFillSchema` | `HoleFill` |
103
+ | `CementPadSchema` | `CementPad` |
104
+ | `LithologySchema` | `Lithology` |
105
+ | `FractureSchema` | `Fracture` |
106
+ | `CaveSchema` | `Cave` |
107
+
108
+ ### Functions
109
+
110
+ #### `parseWell(json: string): Well`
111
+
112
+ Parses a raw JSON string and validates it against `WellSchema`. Throws a `ZodError` on validation failure. Does not handle legacy formats — use `deserializeWell` for that.
113
+
114
+ #### `serializeWell(well: Well): string`
115
+
116
+ Serializes a `Well` object to a versioned `.well` JSON string (`"version": 1`). Omits `undefined` optional fields.
117
+
118
+ #### `deserializeWell(jsonString: string): Well | null`
119
+
120
+ Parses and normalizes a JSON string into a `Well`. Handles multiple formats:
121
+
122
+ - Current versioned format (`"version": 1`)
123
+ - Legacy formats with `constructive` / `geologic` sub-objects
124
+ - Legacy `diam_pol` inch diameters → `diameter` mm conversion (`× 25.4`)
125
+ - Typo `bole_hole` → `bore_hole` compatibility
126
+
127
+ Returns `null` if the parsed data is empty.
128
+
129
+ #### `isWellEmpty(well: Well | null | undefined): boolean`
130
+
131
+ Returns `true` when all constructive and geologic arrays are empty. Accepts `null` and `undefined` (both treated as empty).
132
+
133
+ ## `.well` Format Overview
134
+
135
+ All depths are in **meters** from ground level (0 = surface). All diameters are in **millimeters**. Geographic coordinates use WGS84 decimal degrees. The MIME type is `application/vnd.well+json`.
136
+
137
+ A minimal `.well` document:
138
+
139
+ ```json
140
+ {
141
+ "version": 1,
142
+ "well_type": "tubular",
143
+ "name": "PP-01",
144
+ "lat": -1.4558,
145
+ "lng": -48.5039,
146
+ "elevation": 12.5,
147
+ "bore_hole": [{ "from": 0, "to": 80, "diameter": 250, "drilling_method": "rotary" }],
148
+ "well_case": [{ "from": 0, "to": 60, "type": "steel", "diameter": 200 }],
149
+ "reduction": [],
150
+ "well_screen": [{ "from": 60, "to": 80, "type": "wire_wound", "diameter": 150, "screen_slot_mm": 0.5 }],
151
+ "surface_case": [{ "from": 0, "to": 3, "diameter": 300 }],
152
+ "hole_fill": [{ "from": 60, "to": 80, "type": "gravel_pack", "diameter": 250, "description": "2-4mm gravel" }],
153
+ "cement_pad": { "type": "square", "width": 1.0, "thickness": 0.15, "length": 1.0 },
154
+ "lithology": [],
155
+ "fractures": [],
156
+ "caves": []
157
+ }
158
+ ```
159
+
160
+ For the complete schema reference, field vocabulary, design rationale, and versioning policy see the [`.well` format specification](./well-specifications.md).
161
+
162
+ ## Contributing
163
+
164
+ Issues and pull requests are welcome. The source lives in `packages/core` within the [well-profiler monorepo](https://github.com/rafaeelneto/well-profiler).
165
+
166
+ ```bash
167
+ git clone https://github.com/rafaeelneto/well-profiler.git
168
+ cd well-profiler
169
+ pnpm install
170
+ cd packages/core
171
+ pnpm build
172
+ pnpm test
173
+ ```
174
+
175
+ ## License
176
+
177
+ [Apache 2.0](./LICENSE) — see `LICENSE` for the full text.
178
+
179
+ The broader well-profiler application is licensed separately under [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/).
package/dist/index.cjs ADDED
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BoreHoleSchema: () => BoreHoleSchema,
24
+ CaveSchema: () => CaveSchema,
25
+ CementPadSchema: () => CementPadSchema,
26
+ FractureSchema: () => FractureSchema,
27
+ HoleFillSchema: () => HoleFillSchema,
28
+ LithologySchema: () => LithologySchema,
29
+ ReductionSchema: () => ReductionSchema,
30
+ SurfaceCaseSchema: () => SurfaceCaseSchema,
31
+ WellCaseSchema: () => WellCaseSchema,
32
+ WellSchema: () => WellSchema,
33
+ WellScreenSchema: () => WellScreenSchema,
34
+ checkIfProfileIsEmpty: () => checkIfProfileIsEmpty,
35
+ convertProfileFromJSON: () => convertProfileFromJSON,
36
+ parseWell: () => parseWell,
37
+ profileToWell: () => profileToWell
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/validators/well.validators.ts
42
+ var import_zod = require("zod");
43
+ var BoreHoleSchema = import_zod.z.object({
44
+ from: import_zod.z.number(),
45
+ to: import_zod.z.number(),
46
+ diameter: import_zod.z.number(),
47
+ drilling_method: import_zod.z.string().optional()
48
+ });
49
+ var WellCaseSchema = import_zod.z.object({
50
+ from: import_zod.z.number(),
51
+ to: import_zod.z.number(),
52
+ type: import_zod.z.string(),
53
+ diameter: import_zod.z.number()
54
+ });
55
+ var ReductionSchema = import_zod.z.object({
56
+ from: import_zod.z.number(),
57
+ to: import_zod.z.number(),
58
+ diam_from: import_zod.z.number(),
59
+ diam_to: import_zod.z.number(),
60
+ type: import_zod.z.string()
61
+ });
62
+ var WellScreenSchema = import_zod.z.object({
63
+ from: import_zod.z.number(),
64
+ to: import_zod.z.number(),
65
+ type: import_zod.z.string(),
66
+ diameter: import_zod.z.number(),
67
+ screen_slot_mm: import_zod.z.number()
68
+ });
69
+ var HoleFillSchema = import_zod.z.object({
70
+ from: import_zod.z.number(),
71
+ to: import_zod.z.number(),
72
+ type: import_zod.z.enum(["gravel_pack", "seal"]),
73
+ diameter: import_zod.z.number(),
74
+ description: import_zod.z.string()
75
+ });
76
+ var SurfaceCaseSchema = import_zod.z.object({
77
+ from: import_zod.z.number(),
78
+ to: import_zod.z.number(),
79
+ diameter: import_zod.z.number()
80
+ });
81
+ var CementPadSchema = import_zod.z.object({
82
+ type: import_zod.z.string(),
83
+ width: import_zod.z.number(),
84
+ thickness: import_zod.z.number(),
85
+ length: import_zod.z.number()
86
+ });
87
+ var LithologySchema = import_zod.z.object({
88
+ from: import_zod.z.number(),
89
+ to: import_zod.z.number(),
90
+ description: import_zod.z.string(),
91
+ color: import_zod.z.string(),
92
+ fgdc_texture: import_zod.z.string(),
93
+ geologic_unit: import_zod.z.string(),
94
+ aquifer_unit: import_zod.z.string()
95
+ });
96
+ var FractureSchema = import_zod.z.object({
97
+ depth: import_zod.z.number(),
98
+ water_intake: import_zod.z.boolean(),
99
+ description: import_zod.z.string(),
100
+ swarm: import_zod.z.boolean(),
101
+ azimuth: import_zod.z.number(),
102
+ dip: import_zod.z.number()
103
+ });
104
+ var CaveSchema = import_zod.z.object({
105
+ from: import_zod.z.number(),
106
+ to: import_zod.z.number(),
107
+ water_intake: import_zod.z.boolean(),
108
+ description: import_zod.z.string()
109
+ });
110
+ var WellSchema = import_zod.z.object({
111
+ well_type: import_zod.z.string().optional(),
112
+ name: import_zod.z.string().optional(),
113
+ well_driller: import_zod.z.string().optional(),
114
+ construction_date: import_zod.z.string().optional(),
115
+ lat: import_zod.z.number().optional(),
116
+ lng: import_zod.z.number().optional(),
117
+ elevation: import_zod.z.number().optional(),
118
+ obs: import_zod.z.string().optional(),
119
+ bore_hole: import_zod.z.array(BoreHoleSchema),
120
+ well_case: import_zod.z.array(WellCaseSchema),
121
+ reduction: import_zod.z.array(ReductionSchema),
122
+ well_screen: import_zod.z.array(WellScreenSchema),
123
+ surface_case: import_zod.z.array(SurfaceCaseSchema),
124
+ hole_fill: import_zod.z.array(HoleFillSchema),
125
+ cement_pad: CementPadSchema,
126
+ lithology: import_zod.z.array(LithologySchema),
127
+ fractures: import_zod.z.array(FractureSchema),
128
+ caves: import_zod.z.array(CaveSchema)
129
+ });
130
+ function parseWell(json) {
131
+ const raw = JSON.parse(json);
132
+ return WellSchema.parse(raw);
133
+ }
134
+
135
+ // src/utils/well.utils.ts
136
+ var WELL_FORMAT_VERSION = 1;
137
+ var INCHES_TO_MM = 25.4;
138
+ var EMPTY_WELL = {
139
+ bore_hole: [],
140
+ well_case: [],
141
+ reduction: [],
142
+ well_screen: [],
143
+ surface_case: [],
144
+ hole_fill: [],
145
+ cement_pad: { type: "", width: 0, thickness: 0, length: 0 },
146
+ lithology: [],
147
+ fractures: [],
148
+ caves: []
149
+ };
150
+ function createEmptyWell() {
151
+ return JSON.parse(JSON.stringify(EMPTY_WELL));
152
+ }
153
+ function normalizeLithology(items) {
154
+ return items.map((item) => ({ aquifer_unit: "", ...item }));
155
+ }
156
+ function decodeV1Well(raw) {
157
+ return {
158
+ ...createEmptyWell(),
159
+ ...raw.well_type !== void 0 && { well_type: raw.well_type },
160
+ ...raw.name !== void 0 && { name: raw.name },
161
+ ...raw.well_driller !== void 0 && {
162
+ well_driller: raw.well_driller
163
+ },
164
+ ...raw.construction_date !== void 0 && {
165
+ construction_date: raw.construction_date
166
+ },
167
+ ...raw.lat !== void 0 && { lat: raw.lat },
168
+ ...raw.lng !== void 0 && { lng: raw.lng },
169
+ ...raw.elevation !== void 0 && { elevation: raw.elevation },
170
+ ...raw.obs !== void 0 && { obs: raw.obs },
171
+ bore_hole: raw.bore_hole ?? [],
172
+ well_case: raw.well_case ?? [],
173
+ reduction: raw.reduction ?? [],
174
+ well_screen: raw.well_screen ?? [],
175
+ surface_case: raw.surface_case ?? [],
176
+ hole_fill: raw.hole_fill ?? [],
177
+ ...raw.cement_pad ? { cement_pad: raw.cement_pad } : {},
178
+ lithology: normalizeLithology(raw.lithology ?? []),
179
+ fractures: raw.fractures ?? [],
180
+ caves: raw.caves ?? []
181
+ };
182
+ }
183
+ function convertLegacyDiameters(items) {
184
+ if (!items?.length) return items ?? [];
185
+ if (!items.some((item) => item.diam_pol !== void 0)) return items;
186
+ return items.map(({ diam_pol, ...rest }) => ({
187
+ ...rest,
188
+ diameter: (diam_pol || 0) * INCHES_TO_MM
189
+ }));
190
+ }
191
+ function normalizeConstructive(src) {
192
+ const boreHoleData = src.bole_hole ?? src.bore_hole ?? [];
193
+ return {
194
+ bore_hole: convertLegacyDiameters(boreHoleData),
195
+ hole_fill: convertLegacyDiameters(
196
+ src.hole_fill ?? []
197
+ ),
198
+ surface_case: convertLegacyDiameters(
199
+ src.surface_case ?? []
200
+ ),
201
+ well_case: convertLegacyDiameters(
202
+ src.well_case ?? []
203
+ ),
204
+ well_screen: convertLegacyDiameters(
205
+ src.well_screen ?? []
206
+ ),
207
+ reduction: src.reduction ?? [],
208
+ ...src.cement_pad ? { cement_pad: src.cement_pad } : {}
209
+ };
210
+ }
211
+ function normalizeGeologic(raw) {
212
+ const lithologySource = raw.lithology ?? raw.geologic ?? [];
213
+ return {
214
+ lithology: normalizeLithology(lithologySource),
215
+ fractures: raw.fractures ?? [],
216
+ caves: raw.caves ?? []
217
+ };
218
+ }
219
+ function serializeWell(well) {
220
+ const payload = {
221
+ version: WELL_FORMAT_VERSION,
222
+ ...well.well_type !== void 0 && { well_type: well.well_type },
223
+ ...well.name !== void 0 && { name: well.name },
224
+ ...well.well_driller !== void 0 && { well_driller: well.well_driller },
225
+ ...well.construction_date !== void 0 && {
226
+ construction_date: well.construction_date
227
+ },
228
+ ...well.lat !== void 0 && { lat: well.lat },
229
+ ...well.lng !== void 0 && { lng: well.lng },
230
+ ...well.elevation !== void 0 && { elevation: well.elevation },
231
+ ...well.obs !== void 0 && { obs: well.obs },
232
+ bore_hole: well.bore_hole,
233
+ well_case: well.well_case,
234
+ reduction: well.reduction,
235
+ well_screen: well.well_screen,
236
+ surface_case: well.surface_case,
237
+ hole_fill: well.hole_fill,
238
+ ...well.cement_pad && { cement_pad: well.cement_pad },
239
+ lithology: well.lithology,
240
+ fractures: well.fractures,
241
+ caves: well.caves
242
+ };
243
+ return JSON.stringify(payload);
244
+ }
245
+ function isWellEmpty(well) {
246
+ if (!well) return true;
247
+ const raw = well;
248
+ if (raw.constructive || raw.geologic) return false;
249
+ return well.lithology?.length === 0 && well.fractures?.length === 0 && well.caves?.length === 0 && well.bore_hole?.length === 0 && well.hole_fill?.length === 0 && well.well_case?.length === 0 && well.well_screen?.length === 0;
250
+ }
251
+ function deserializeWell(jsonString) {
252
+ let raw;
253
+ try {
254
+ raw = JSON.parse(jsonString);
255
+ } catch {
256
+ throw new Error("Invalid profile format");
257
+ }
258
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
259
+ throw new Error("Invalid profile format");
260
+ }
261
+ if (typeof raw.version === "number") {
262
+ if (raw.version !== 1)
263
+ throw new Error(`Unsupported .well format version: ${raw.version}`);
264
+ return decodeV1Well(raw);
265
+ }
266
+ if (isWellEmpty(raw)) return null;
267
+ const constructiveSource = raw.constructive ?? raw;
268
+ const metadata = {
269
+ ...raw.well_type !== void 0 && { well_type: raw.well_type },
270
+ ...raw.name !== void 0 && { name: raw.name },
271
+ ...raw.well_driller !== void 0 && {
272
+ well_driller: raw.well_driller
273
+ },
274
+ ...raw.construction_date !== void 0 && {
275
+ construction_date: raw.construction_date
276
+ },
277
+ ...raw.lat !== void 0 && { lat: raw.lat },
278
+ ...raw.lng !== void 0 && { lng: raw.lng },
279
+ ...raw.elevation !== void 0 && { elevation: raw.elevation },
280
+ ...raw.obs !== void 0 && { obs: raw.obs }
281
+ };
282
+ return {
283
+ ...createEmptyWell(),
284
+ ...metadata,
285
+ ...normalizeConstructive(constructiveSource),
286
+ ...normalizeGeologic(raw)
287
+ };
288
+ }
289
+ var profileToWell = serializeWell;
290
+ var checkIfProfileIsEmpty = isWellEmpty;
291
+ var convertProfileFromJSON = deserializeWell;
292
+ // Annotate the CommonJS export names for ESM import in node:
293
+ 0 && (module.exports = {
294
+ BoreHoleSchema,
295
+ CaveSchema,
296
+ CementPadSchema,
297
+ FractureSchema,
298
+ HoleFillSchema,
299
+ LithologySchema,
300
+ ReductionSchema,
301
+ SurfaceCaseSchema,
302
+ WellCaseSchema,
303
+ WellSchema,
304
+ WellScreenSchema,
305
+ checkIfProfileIsEmpty,
306
+ convertProfileFromJSON,
307
+ parseWell,
308
+ profileToWell
309
+ });
310
+ //# sourceMappingURL=index.cjs.map