@mark1russell7/room-view 0.2.4 → 0.3.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 +36 -34
- package/build/{anchors-Ba3OUmhF.js → check-DI_B57qy.js} +10 -233
- package/build/check-DI_B57qy.js.map +1 -0
- package/build/index.d.ts +4 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -5
- package/build/index.js.map +1 -1
- package/build/{layers-B5nL_lVW.js → layers-CDNFVXds.js} +161 -5
- package/build/layers-CDNFVXds.js.map +1 -0
- package/build/{layers-BO_MMtQJ.d.ts → layers-CYZwt1bH.d.ts} +34 -9
- package/build/layers-CYZwt1bH.d.ts.map +1 -0
- package/build/{level-CXCIX08K.js → level-BERjgyrT.js} +11 -37
- package/build/level-BERjgyrT.js.map +1 -0
- package/build/{level-Cjcf3u20.d.ts → level-m-mJ_3Ok.d.ts} +11 -19
- package/build/level-m-mJ_3Ok.d.ts.map +1 -0
- package/build/marks.d.ts +2 -2
- package/build/marks.js +1 -2
- package/build/marks.js.map +1 -1
- package/build/sample.d.ts +4 -4
- package/build/sample.d.ts.map +1 -1
- package/build/sample.js +21 -217
- package/build/sample.js.map +1 -1
- package/build/schema.d.ts +59 -9
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +250 -91
- package/build/schema.js.map +1 -1
- package/build/{solids-S_j17vFJ.d.ts → solids-OiTlb_Pm.d.ts} +9 -54
- package/build/solids-OiTlb_Pm.d.ts.map +1 -0
- package/build/three.d.ts +8 -16
- package/build/three.d.ts.map +1 -1
- package/build/three.js +12 -106
- package/build/three.js.map +1 -1
- package/package.json +1 -1
- package/build/anchors-Ba3OUmhF.js.map +0 -1
- package/build/layers-B5nL_lVW.js.map +0 -1
- package/build/layers-BO_MMtQJ.d.ts.map +0 -1
- package/build/level-CXCIX08K.js.map +0 -1
- package/build/level-Cjcf3u20.d.ts.map +0 -1
- package/build/loads-CtHa4EHo.js +0 -103
- package/build/loads-CtHa4EHo.js.map +0 -1
- package/build/loads-Diy6-Ekz.d.ts +0 -73
- package/build/loads-Diy6-Ekz.d.ts.map +0 -1
- package/build/solids-S_j17vFJ.d.ts.map +0 -1
package/build/schema.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { _ as WALL_SIDES, g as WALL_FACES, h as SCENE_SCHEMA, m as ROOM_SCHEMA, p as OPENING_KINDS, t as FILE_KINDS, v as isLayerName } from "./layers-CDNFVXds.js";
|
|
2
|
+
import { c as SQUARE_TURNS, i as LEVEL_SCHEMA, u as SURVEY_SCHEMA } from "./level-BERjgyrT.js";
|
|
3
|
+
import { k as LENGTH_UNITS } from "./check-DI_B57qy.js";
|
|
4
|
+
import * as z from "zod/mini";
|
|
5
|
+
import en from "zod/v4/locales/en.js";
|
|
5
6
|
// src/schema.ts
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
/** The parse context of each read of this entry and of each add-on: the faults have the English messages of zod. */
|
|
8
|
+
const READ_CONTEXT = { error: en().localeError };
|
|
9
|
+
const id = z.string().check(z.minLength(1));
|
|
10
|
+
const planPoint = z.readonly(z.tuple([z.number(), z.number()]));
|
|
11
|
+
const point3 = z.readonly(z.tuple([
|
|
9
12
|
z.number(),
|
|
10
13
|
z.number(),
|
|
11
14
|
z.number()
|
|
12
|
-
])
|
|
15
|
+
]));
|
|
13
16
|
/**
|
|
14
17
|
* The schema of an anchor. It examines the form of the record, and it refuses a field that the surface of the anchor does not have.
|
|
15
18
|
* The schema of an add-on uses it for the anchor of each record. `checkAnchor` examines the meaning of an anchor with a correct form.
|
|
@@ -25,27 +28,27 @@ const anchorSchema = z.discriminatedUnion("on", [
|
|
|
25
28
|
z.strictObject({
|
|
26
29
|
on: z.literal("floor"),
|
|
27
30
|
at: planPoint,
|
|
28
|
-
floor:
|
|
31
|
+
floor: z.optional(id)
|
|
29
32
|
}),
|
|
30
33
|
z.strictObject({
|
|
31
34
|
on: z.literal("ceiling"),
|
|
32
35
|
at: planPoint,
|
|
33
|
-
floor:
|
|
36
|
+
floor: z.optional(id)
|
|
34
37
|
}),
|
|
35
38
|
z.strictObject({
|
|
36
39
|
on: z.literal("object"),
|
|
37
40
|
object: id,
|
|
38
|
-
at:
|
|
39
|
-
out:
|
|
41
|
+
at: z.optional(point3),
|
|
42
|
+
out: z.optional(point3)
|
|
40
43
|
})
|
|
41
44
|
]);
|
|
42
45
|
const wall = z.strictObject({
|
|
43
46
|
id,
|
|
44
47
|
from: planPoint,
|
|
45
48
|
to: planPoint,
|
|
46
|
-
thickness: z.
|
|
47
|
-
height: z.
|
|
48
|
-
side: z.enum(WALL_SIDES)
|
|
49
|
+
thickness: z.optional(z.number()),
|
|
50
|
+
height: z.optional(z.number()),
|
|
51
|
+
side: z.optional(z.enum(WALL_SIDES))
|
|
49
52
|
});
|
|
50
53
|
const opening = z.strictObject({
|
|
51
54
|
id,
|
|
@@ -53,28 +56,13 @@ const opening = z.strictObject({
|
|
|
53
56
|
kind: z.enum(OPENING_KINDS),
|
|
54
57
|
offset: z.number(),
|
|
55
58
|
width: z.number(),
|
|
56
|
-
sill: z.
|
|
59
|
+
sill: z.optional(z.number()),
|
|
57
60
|
height: z.number()
|
|
58
61
|
});
|
|
59
62
|
const floor = z.strictObject({
|
|
60
63
|
id,
|
|
61
|
-
name: z.
|
|
62
|
-
ring: z.array(planPoint)
|
|
63
|
-
});
|
|
64
|
-
const outlet = z.strictObject({
|
|
65
|
-
id,
|
|
66
|
-
wall: id,
|
|
67
|
-
face: z.enum(WALL_FACES),
|
|
68
|
-
offset: z.number(),
|
|
69
|
-
height: z.number(),
|
|
70
|
-
circuit: id.optional()
|
|
71
|
-
});
|
|
72
|
-
const circuit = z.strictObject({
|
|
73
|
-
id,
|
|
74
|
-
name: z.string().optional(),
|
|
75
|
-
breaker: z.number().optional(),
|
|
76
|
-
voltage: z.number().optional(),
|
|
77
|
-
limit: z.number()
|
|
64
|
+
name: z.optional(z.string()),
|
|
65
|
+
ring: z.readonly(z.array(planPoint))
|
|
78
66
|
});
|
|
79
67
|
/**
|
|
80
68
|
* The schema of a room record. It examines the form of the record: the fields, their types and the finite numbers.
|
|
@@ -82,54 +70,43 @@ const circuit = z.strictObject({
|
|
|
82
70
|
*/
|
|
83
71
|
const roomSchema = z.strictObject({
|
|
84
72
|
schema: z.literal(ROOM_SCHEMA),
|
|
85
|
-
name: z.
|
|
73
|
+
name: z.optional(z.string()),
|
|
86
74
|
unit: z.enum(LENGTH_UNITS),
|
|
87
75
|
height: z.number(),
|
|
88
76
|
wallThickness: z.number(),
|
|
89
|
-
walls: z.array(wall)
|
|
90
|
-
openings: z.
|
|
91
|
-
floors: z.
|
|
92
|
-
outlets: z.array(outlet).readonly().optional(),
|
|
93
|
-
circuits: z.array(circuit).readonly().optional()
|
|
77
|
+
walls: z.readonly(z.array(wall)),
|
|
78
|
+
openings: z.optional(z.readonly(z.array(opening))),
|
|
79
|
+
floors: z.optional(z.readonly(z.array(floor)))
|
|
94
80
|
});
|
|
95
81
|
const placedObject = z.strictObject({
|
|
96
82
|
id,
|
|
97
|
-
kind:
|
|
98
|
-
name: z.
|
|
99
|
-
size:
|
|
100
|
-
z.number(),
|
|
101
|
-
z.number(),
|
|
102
|
-
z.number()
|
|
103
|
-
]).readonly(),
|
|
83
|
+
kind: id,
|
|
84
|
+
name: z.optional(z.string()),
|
|
85
|
+
size: point3,
|
|
104
86
|
at: planPoint,
|
|
105
|
-
lift: z.
|
|
106
|
-
turn: z.
|
|
107
|
-
parent:
|
|
108
|
-
outlet: id.optional()
|
|
109
|
-
});
|
|
110
|
-
const circuitLoad = z.strictObject({
|
|
111
|
-
circuit: id,
|
|
112
|
-
watts: z.number()
|
|
87
|
+
lift: z.optional(z.number()),
|
|
88
|
+
turn: z.optional(z.number()),
|
|
89
|
+
parent: z.optional(id)
|
|
113
90
|
});
|
|
114
|
-
const
|
|
91
|
+
const layerName = z.string().check(z.refine(isLayerName, "A layer name is a word, a slash and a version, for example electrical/1."));
|
|
92
|
+
const layers = z.optional(z.readonly(z.record(layerName, z.unknown())));
|
|
115
93
|
/**
|
|
116
94
|
* The schema of a scene record. It examines the form of the record, and it refuses a field that the format does not have.
|
|
117
95
|
* `checkScene` examines the meaning of a record with a correct form.
|
|
118
96
|
*/
|
|
119
97
|
const sceneSchema = z.strictObject({
|
|
120
98
|
schema: z.literal(SCENE_SCHEMA),
|
|
121
|
-
name: z.
|
|
99
|
+
name: z.optional(z.string()),
|
|
122
100
|
room: roomSchema,
|
|
123
|
-
objects: z.
|
|
124
|
-
loads: z.array(circuitLoad).readonly().optional(),
|
|
101
|
+
objects: z.optional(z.readonly(z.array(placedObject))),
|
|
125
102
|
layers
|
|
126
103
|
});
|
|
127
104
|
const surveySide = z.strictObject({
|
|
128
105
|
id,
|
|
129
106
|
length: z.number(),
|
|
130
107
|
turn: z.union([z.enum(SQUARE_TURNS), z.number()]),
|
|
131
|
-
thickness: z.
|
|
132
|
-
height: z.
|
|
108
|
+
thickness: z.optional(z.number()),
|
|
109
|
+
height: z.optional(z.number())
|
|
133
110
|
});
|
|
134
111
|
const surveyCheck = z.strictObject({
|
|
135
112
|
id,
|
|
@@ -137,26 +114,18 @@ const surveyCheck = z.strictObject({
|
|
|
137
114
|
to: id,
|
|
138
115
|
length: z.number()
|
|
139
116
|
});
|
|
140
|
-
const surveyOutlet = z.strictObject({
|
|
141
|
-
id,
|
|
142
|
-
wall: id,
|
|
143
|
-
offset: z.number(),
|
|
144
|
-
height: z.number(),
|
|
145
|
-
circuit: id.optional()
|
|
146
|
-
});
|
|
147
117
|
const surveyObject = z.strictObject({
|
|
148
118
|
id,
|
|
149
|
-
kind:
|
|
150
|
-
name: z.
|
|
151
|
-
wall:
|
|
152
|
-
on:
|
|
119
|
+
kind: id,
|
|
120
|
+
name: z.optional(z.string()),
|
|
121
|
+
wall: z.optional(id),
|
|
122
|
+
on: z.optional(id),
|
|
153
123
|
offset: z.number(),
|
|
154
124
|
width: z.number(),
|
|
155
125
|
depth: z.number(),
|
|
156
126
|
height: z.number(),
|
|
157
|
-
gap: z.
|
|
158
|
-
lift: z.
|
|
159
|
-
outlet: id.optional()
|
|
127
|
+
gap: z.optional(z.number()),
|
|
128
|
+
lift: z.optional(z.number())
|
|
160
129
|
});
|
|
161
130
|
/**
|
|
162
131
|
* The schema of a survey record. It examines the form of the record, and it refuses a field that the format does not have.
|
|
@@ -164,18 +133,16 @@ const surveyObject = z.strictObject({
|
|
|
164
133
|
*/
|
|
165
134
|
const surveySchema = z.strictObject({
|
|
166
135
|
schema: z.literal(SURVEY_SCHEMA),
|
|
167
|
-
name: z.
|
|
136
|
+
name: z.optional(z.string()),
|
|
168
137
|
unit: z.enum(LENGTH_UNITS),
|
|
169
138
|
height: z.number(),
|
|
170
139
|
wallThickness: z.number(),
|
|
171
|
-
sides: z.array(surveySide)
|
|
172
|
-
start:
|
|
173
|
-
heading: z.
|
|
174
|
-
checks: z.
|
|
175
|
-
openings: z.
|
|
176
|
-
|
|
177
|
-
circuits: z.array(circuit).readonly().optional(),
|
|
178
|
-
objects: z.array(surveyObject).readonly().optional(),
|
|
140
|
+
sides: z.readonly(z.array(surveySide)),
|
|
141
|
+
start: z.optional(planPoint),
|
|
142
|
+
heading: z.optional(z.number()),
|
|
143
|
+
checks: z.optional(z.readonly(z.array(surveyCheck))),
|
|
144
|
+
openings: z.optional(z.readonly(z.array(opening))),
|
|
145
|
+
objects: z.optional(z.readonly(z.array(surveyObject))),
|
|
179
146
|
layers
|
|
180
147
|
});
|
|
181
148
|
const connectionEnd = z.strictObject({
|
|
@@ -188,21 +155,213 @@ const connectionEnd = z.strictObject({
|
|
|
188
155
|
*/
|
|
189
156
|
const levelSchema = z.strictObject({
|
|
190
157
|
schema: z.literal(LEVEL_SCHEMA),
|
|
191
|
-
name: z.
|
|
158
|
+
name: z.optional(z.string()),
|
|
192
159
|
unit: z.enum(LENGTH_UNITS),
|
|
193
|
-
rooms: z.array(z.strictObject({
|
|
160
|
+
rooms: z.readonly(z.array(z.strictObject({
|
|
194
161
|
id,
|
|
195
162
|
survey: surveySchema
|
|
196
|
-
}))
|
|
197
|
-
connections: z.array(z.strictObject({
|
|
163
|
+
}))),
|
|
164
|
+
connections: z.optional(z.readonly(z.array(z.strictObject({
|
|
198
165
|
id,
|
|
199
166
|
from: connectionEnd,
|
|
200
167
|
to: connectionEnd,
|
|
201
|
-
thickness: z.
|
|
202
|
-
}))
|
|
203
|
-
circuits: z.array(circuit).readonly().optional(),
|
|
168
|
+
thickness: z.optional(z.number())
|
|
169
|
+
})))),
|
|
204
170
|
layers
|
|
205
171
|
});
|
|
206
|
-
|
|
172
|
+
/** These are the codes of the findings of `readRecord`. */
|
|
173
|
+
const READ_CODES = ["read-both"];
|
|
174
|
+
const KIND_NAMES = {
|
|
175
|
+
room: ROOM_SCHEMA,
|
|
176
|
+
scene: SCENE_SCHEMA,
|
|
177
|
+
survey: SURVEY_SCHEMA,
|
|
178
|
+
level: LEVEL_SCHEMA
|
|
179
|
+
};
|
|
180
|
+
/** This function tells if a value is a JSON object. */
|
|
181
|
+
function isJson(value) {
|
|
182
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
183
|
+
}
|
|
184
|
+
/** This function gives the schema name of version 2 for a nested record of version 1. A different name stays, so the read tells its fault. */
|
|
185
|
+
function newName(record, kind) {
|
|
186
|
+
return record["schema"] === `${kind}/1` ? KIND_NAMES[kind] : record["schema"];
|
|
187
|
+
}
|
|
188
|
+
/** This function gives the faults of a zod read. Each fault names its place in the record, for example `rooms.0.survey.sides`. */
|
|
189
|
+
function faultsOf(error) {
|
|
190
|
+
return error.issues.map((issue) => `${issue.path.length === 0 ? "The record" : `"${issue.path.map(String).join(".")}"`}: ${issue.message}`);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* This function reads the JSON of a record of the core in version 1 or in version 2. The record is a room, a scene, a survey or a level.
|
|
194
|
+
* The result is the record in version 2. The schemas of this entry examine its form.
|
|
195
|
+
*
|
|
196
|
+
* A record of version 1 kept the records of some topics in fields of its own. For each add-on of the list with the read `v1`:
|
|
197
|
+
*
|
|
198
|
+
* - The read removes the fields of the add-on from the record, from each object and from each nested record.
|
|
199
|
+
* - The function `read` of the add-on gives the layer of these fields. For a scene, this layer has the records of its room too.
|
|
200
|
+
* For a level, the level record and the survey of each room get a layer.
|
|
201
|
+
* - A record that has the layer and the old fields keeps the layer. The finding `read-both` tells it.
|
|
202
|
+
*
|
|
203
|
+
* A field of version 1 that no add-on of the list removes is a fault of the form. A room record has no layers.
|
|
204
|
+
* Thus a `room/1` with old records gives a `scene/2` with the room and the layers, and a `room/1` with none gives a `room/2`.
|
|
205
|
+
*/
|
|
206
|
+
function readRecord(value, addOns = []) {
|
|
207
|
+
if (!isJson(value)) return {
|
|
208
|
+
ok: false,
|
|
209
|
+
errors: ["The record is not a JSON object."]
|
|
210
|
+
};
|
|
211
|
+
const name = value["schema"];
|
|
212
|
+
const kind = FILE_KINDS.find((each) => KIND_NAMES[each] === name);
|
|
213
|
+
if (kind !== void 0) return parsed(kind, value, 2, []);
|
|
214
|
+
const old = FILE_KINDS.find((each) => `${each}/1` === name);
|
|
215
|
+
if (old === void 0) return {
|
|
216
|
+
ok: false,
|
|
217
|
+
errors: [`The record has no known format: "schema" is ${JSON.stringify(name) ?? "missing"}.`]
|
|
218
|
+
};
|
|
219
|
+
const readers = addOns.filter((addOn) => addOn.v1 !== void 0);
|
|
220
|
+
const findings = [];
|
|
221
|
+
const errors = [];
|
|
222
|
+
const without = (record, of) => {
|
|
223
|
+
const gone = new Set(readers.flatMap((addOn) => addOn.v1?.fields[of] ?? []));
|
|
224
|
+
return Object.fromEntries(Object.entries(record).filter(([key]) => !gone.has(key)));
|
|
225
|
+
};
|
|
226
|
+
const objectsOf = (record) => {
|
|
227
|
+
const objects = record["objects"];
|
|
228
|
+
if (Array.isArray(objects)) record["objects"] = objects.map((object) => isJson(object) ? without(object, "object") : object);
|
|
229
|
+
};
|
|
230
|
+
const withLayers = (record, raw, of, room) => {
|
|
231
|
+
const given = isJson(raw["layers"]) ? raw["layers"] : {};
|
|
232
|
+
const layers = { ...given };
|
|
233
|
+
for (const addOn of readers) {
|
|
234
|
+
const read = addOn.v1?.read(raw, of);
|
|
235
|
+
if (read === void 0) continue;
|
|
236
|
+
if (!read.ok) {
|
|
237
|
+
errors.push(...read.errors);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (Object.hasOwn(given, addOn.schema)) {
|
|
241
|
+
findings.push({
|
|
242
|
+
level: "warning",
|
|
243
|
+
code: "read-both",
|
|
244
|
+
layer: addOn.schema,
|
|
245
|
+
...room === void 0 ? {} : { room },
|
|
246
|
+
message: `The record has the layer "${addOn.schema}" and its old fields. The layer stays, and the old fields go.`
|
|
247
|
+
});
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
layers[addOn.schema] = read.layer;
|
|
251
|
+
}
|
|
252
|
+
if (Object.keys(layers).length > 0) record["layers"] = layers;
|
|
253
|
+
};
|
|
254
|
+
const surveyOf = (raw, room) => {
|
|
255
|
+
const record = {
|
|
256
|
+
...without(raw, "survey"),
|
|
257
|
+
schema: newName(raw, "survey")
|
|
258
|
+
};
|
|
259
|
+
objectsOf(record);
|
|
260
|
+
withLayers(record, raw, "survey", room);
|
|
261
|
+
return record;
|
|
262
|
+
};
|
|
263
|
+
const roomOf = (raw) => isJson(raw) ? {
|
|
264
|
+
...without(raw, "room"),
|
|
265
|
+
schema: newName(raw, "room")
|
|
266
|
+
} : raw;
|
|
267
|
+
let next;
|
|
268
|
+
let made = old;
|
|
269
|
+
if (old === "survey") next = surveyOf(value);
|
|
270
|
+
else if (old === "level") {
|
|
271
|
+
const level = {
|
|
272
|
+
...without(value, "level"),
|
|
273
|
+
schema: LEVEL_SCHEMA
|
|
274
|
+
};
|
|
275
|
+
const rooms = value["rooms"];
|
|
276
|
+
if (Array.isArray(rooms)) level["rooms"] = rooms.map((room) => {
|
|
277
|
+
if (!isJson(room) || !isJson(room["survey"])) return room;
|
|
278
|
+
return {
|
|
279
|
+
...room,
|
|
280
|
+
survey: surveyOf(room["survey"], typeof room["id"] === "string" ? room["id"] : void 0)
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
withLayers(level, value, "level");
|
|
284
|
+
next = level;
|
|
285
|
+
} else if (old === "scene") {
|
|
286
|
+
const scene = {
|
|
287
|
+
...without(value, "scene"),
|
|
288
|
+
schema: SCENE_SCHEMA,
|
|
289
|
+
room: roomOf(value["room"])
|
|
290
|
+
};
|
|
291
|
+
objectsOf(scene);
|
|
292
|
+
withLayers(scene, value, "scene");
|
|
293
|
+
next = scene;
|
|
294
|
+
} else {
|
|
295
|
+
const scene = {
|
|
296
|
+
schema: SCENE_SCHEMA,
|
|
297
|
+
room: roomOf(value)
|
|
298
|
+
};
|
|
299
|
+
withLayers(scene, value, "room");
|
|
300
|
+
if (scene["layers"] === void 0) next = scene["room"];
|
|
301
|
+
else {
|
|
302
|
+
next = scene;
|
|
303
|
+
made = "scene";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (errors.length > 0) return {
|
|
307
|
+
ok: false,
|
|
308
|
+
errors
|
|
309
|
+
};
|
|
310
|
+
return parsed(made, next, 1, findings);
|
|
311
|
+
}
|
|
312
|
+
/** This function reads a record of version 2 with the schema of its kind. */
|
|
313
|
+
function parsed(kind, value, version, findings) {
|
|
314
|
+
if (kind === "room") {
|
|
315
|
+
const read = roomSchema.safeParse(value, READ_CONTEXT);
|
|
316
|
+
return read.success ? {
|
|
317
|
+
ok: true,
|
|
318
|
+
kind,
|
|
319
|
+
record: read.data,
|
|
320
|
+
version,
|
|
321
|
+
findings
|
|
322
|
+
} : {
|
|
323
|
+
ok: false,
|
|
324
|
+
errors: faultsOf(read.error)
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
if (kind === "scene") {
|
|
328
|
+
const read = sceneSchema.safeParse(value, READ_CONTEXT);
|
|
329
|
+
return read.success ? {
|
|
330
|
+
ok: true,
|
|
331
|
+
kind,
|
|
332
|
+
record: read.data,
|
|
333
|
+
version,
|
|
334
|
+
findings
|
|
335
|
+
} : {
|
|
336
|
+
ok: false,
|
|
337
|
+
errors: faultsOf(read.error)
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (kind === "survey") {
|
|
341
|
+
const read = surveySchema.safeParse(value, READ_CONTEXT);
|
|
342
|
+
return read.success ? {
|
|
343
|
+
ok: true,
|
|
344
|
+
kind,
|
|
345
|
+
record: read.data,
|
|
346
|
+
version,
|
|
347
|
+
findings
|
|
348
|
+
} : {
|
|
349
|
+
ok: false,
|
|
350
|
+
errors: faultsOf(read.error)
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
const read = levelSchema.safeParse(value, READ_CONTEXT);
|
|
354
|
+
return read.success ? {
|
|
355
|
+
ok: true,
|
|
356
|
+
kind,
|
|
357
|
+
record: read.data,
|
|
358
|
+
version,
|
|
359
|
+
findings
|
|
360
|
+
} : {
|
|
361
|
+
ok: false,
|
|
362
|
+
errors: faultsOf(read.error)
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
export { READ_CODES, READ_CONTEXT, anchorSchema, levelSchema, readRecord, roomSchema, sceneSchema, surveySchema };
|
|
207
366
|
|
|
208
367
|
//# sourceMappingURL=schema.js.map
|
package/build/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { Anchor } from \"./anchors.ts\";\nimport { LEVEL_SCHEMA, type Level } from \"./level.ts\";\nimport { isLayerName, OPENING_KINDS, ROOM_SCHEMA, SCENE_SCHEMA, WALL_FACES, WALL_SIDES, type Room, type Scene } from \"./room.ts\";\nimport { SQUARE_TURNS, SURVEY_SCHEMA, type Survey } from \"./survey.ts\";\nimport { LENGTH_UNITS } from \"./units.ts\";\n\nconst id = z.string().min(1);\nconst planPoint = z.tuple([z.number(), z.number()]).readonly();\n\nconst point3 = z.tuple([z.number(), z.number(), z.number()]).readonly();\n\n/**\n * The schema of an anchor. It examines the form of the record, and it refuses a field that the surface of the anchor does not have.\n * The schema of an add-on uses it for the anchor of each record. `checkAnchor` examines the meaning of an anchor with a correct form.\n */\nexport const anchorSchema: z.ZodType<Anchor> = z.discriminatedUnion(\"on\", [\n z.strictObject({ on: z.literal(\"wall\"), wall: id, face: z.enum(WALL_FACES), offset: z.number(), height: z.number() }),\n z.strictObject({ on: z.literal(\"floor\"), at: planPoint, floor: id.optional() }),\n z.strictObject({ on: z.literal(\"ceiling\"), at: planPoint, floor: id.optional() }),\n z.strictObject({ on: z.literal(\"object\"), object: id, at: point3.optional(), out: point3.optional() }),\n]);\n\nconst wall = z.strictObject({\n id,\n from: planPoint,\n to: planPoint,\n thickness: z.number().optional(),\n height: z.number().optional(),\n side: z.enum(WALL_SIDES).optional(),\n});\n\nconst opening = z.strictObject({\n id,\n wall: id,\n kind: z.enum(OPENING_KINDS),\n offset: z.number(),\n width: z.number(),\n sill: z.number().optional(),\n height: z.number(),\n});\n\nconst floor = z.strictObject({\n id,\n name: z.string().optional(),\n ring: z.array(planPoint).readonly(),\n});\n\nconst outlet = z.strictObject({\n id,\n wall: id,\n face: z.enum(WALL_FACES),\n offset: z.number(),\n height: z.number(),\n circuit: id.optional(),\n});\n\nconst circuit = z.strictObject({\n id,\n name: z.string().optional(),\n breaker: z.number().optional(),\n voltage: z.number().optional(),\n limit: z.number(),\n});\n\n/**\n * The schema of a room record. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkRoom` examines the meaning of a record with a correct form.\n */\nexport const roomSchema: z.ZodType<Room> = z.strictObject({\n schema: z.literal(ROOM_SCHEMA),\n name: z.string().optional(),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n walls: z.array(wall).readonly(),\n openings: z.array(opening).readonly().optional(),\n floors: z.array(floor).readonly().optional(),\n outlets: z.array(outlet).readonly().optional(),\n circuits: z.array(circuit).readonly().optional(),\n});\n\nconst placedObject = z.strictObject({\n id,\n kind: z.string().min(1),\n name: z.string().optional(),\n size: z.tuple([z.number(), z.number(), z.number()]).readonly(),\n at: planPoint,\n lift: z.number().optional(),\n turn: z.number().optional(),\n parent: id.optional(),\n outlet: id.optional(),\n});\n\nconst circuitLoad = z.strictObject({\n circuit: id,\n watts: z.number(),\n});\n\n// The layers of a scene, of a survey or of a level. The core does not read a layer, so it keeps each value. The add-on of a layer examines its form.\nconst layers = z.record(z.string().refine(isLayerName, \"A layer name is a word, a slash and a version, for example electrical/1.\"), z.unknown()).readonly().optional();\n\n/**\n * The schema of a scene record. It examines the form of the record, and it refuses a field that the format does not have.\n * `checkScene` examines the meaning of a record with a correct form.\n */\nexport const sceneSchema: z.ZodType<Scene> = z.strictObject({\n schema: z.literal(SCENE_SCHEMA),\n name: z.string().optional(),\n room: roomSchema,\n objects: z.array(placedObject).readonly().optional(),\n loads: z.array(circuitLoad).readonly().optional(),\n layers,\n});\n\nconst surveySide = z.strictObject({\n id,\n length: z.number(),\n turn: z.union([z.enum(SQUARE_TURNS), z.number()]),\n thickness: z.number().optional(),\n height: z.number().optional(),\n});\n\nconst surveyCheck = z.strictObject({\n id,\n from: id,\n to: id,\n length: z.number(),\n});\n\nconst surveyOutlet = z.strictObject({\n id,\n wall: id,\n offset: z.number(),\n height: z.number(),\n circuit: id.optional(),\n});\n\nconst surveyObject = z.strictObject({\n id,\n kind: z.string().min(1),\n name: z.string().optional(),\n wall: id.optional(),\n on: id.optional(),\n offset: z.number(),\n width: z.number(),\n depth: z.number(),\n height: z.number(),\n gap: z.number().optional(),\n lift: z.number().optional(),\n outlet: id.optional(),\n});\n\n/**\n * The schema of a survey record. It examines the form of the record, and it refuses a field that the format does not have.\n * `expandSurvey` makes the room record of a survey with a correct form, and `checkRoom` examines that room record.\n */\nexport const surveySchema: z.ZodType<Survey> = z.strictObject({\n schema: z.literal(SURVEY_SCHEMA),\n name: z.string().optional(),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n sides: z.array(surveySide).readonly(),\n start: planPoint.optional(),\n heading: z.number().optional(),\n checks: z.array(surveyCheck).readonly().optional(),\n openings: z.array(opening).readonly().optional(),\n outlets: z.array(surveyOutlet).readonly().optional(),\n circuits: z.array(circuit).readonly().optional(),\n objects: z.array(surveyObject).readonly().optional(),\n layers,\n});\n\nconst connectionEnd = z.strictObject({\n room: id,\n opening: id,\n});\n\n/**\n * The schema of a level record. It examines the form of the record and of each survey, and it refuses a field that the format does not have.\n * `expandLevel` makes the room record of a level with a correct form, and `checkRoom` examines that room record.\n */\nexport const levelSchema: z.ZodType<Level> = z.strictObject({\n schema: z.literal(LEVEL_SCHEMA),\n name: z.string().optional(),\n unit: z.enum(LENGTH_UNITS),\n rooms: z.array(z.strictObject({ id, survey: surveySchema })).readonly(),\n connections: z\n .array(z.strictObject({ id, from: connectionEnd, to: connectionEnd, thickness: z.number().optional() }))\n .readonly()\n .optional(),\n circuits: z.array(circuit).readonly().optional(),\n layers,\n});\n"],"mappings":";;;;;AAOA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC3B,MAAM,YAAY,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;AAE7D,MAAM,SAAS,EAAE,MAAM;CAAC,EAAE,OAAO;CAAG,EAAE,OAAO;CAAG,EAAE,OAAO;AAAC,CAAC,CAAC,CAAC,SAAS;;;;;AAMtE,MAAa,eAAkC,EAAE,mBAAmB,MAAM;CACxE,EAAE,aAAa;EAAE,IAAI,EAAE,QAAQ,MAAM;EAAG,MAAM;EAAI,MAAM,EAAE,KAAK,UAAU;EAAG,QAAQ,EAAE,OAAO;EAAG,QAAQ,EAAE,OAAO;CAAE,CAAC;CACpH,EAAE,aAAa;EAAE,IAAI,EAA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AAU,CAAC,CAAC,SAAS;CACpC,OAAO,UAAU,SAAS;CAC1B,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,QAAQ,EAAE,MAAM,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACjD,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC/C,SAAS,EAAE,MAAM,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACnD,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC/C,SAAS,EAAE,MAAM,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACnD;AACF,CAAC;AAED,MAAM,gBAAgB,EAAE,aAAa;CACnC,MAAM;CACN,SAAS;AACX,CAAC;;;;;AAMD,MAAa,cAAgC,EAAE,aAAa;CAC1D,QAAQ,EAAE,QAAQ,YAAY;CAC9B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,MAAM,EAAE,KAAK,YAAY;CACzB,OAAO,EAAE,MAAM,EAAE,aAAa;EAAE;EAAI,QAAQ;CAAa,CAAC,CAAC,CAAC,CAAC,SAAS;CACtE,aAAa,EACV,MAAM,EAAE,aAAa;EAAE;EAAI,MAAM;EAAe,IAAI;EAAe,WAAW,EAAE,OAAO,CAAC,CAAC,SAAS;CAAE,CAAC,CAAC,CAAC,CACvG,SAAS,CAAC,CACV,SAAS;CACZ,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC/C;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import * as z from \"zod/mini\";\nimport en from \"zod/v4/locales/en.js\";\nimport type { Anchor } from \"./anchors.ts\";\nimport type { FindingLevel } from \"./check.ts\";\nimport { FILE_KINDS, type AddOn, type FileKind } from \"./layers.ts\";\nimport { LEVEL_SCHEMA, type Level } from \"./level.ts\";\nimport { isLayerName, OPENING_KINDS, ROOM_SCHEMA, SCENE_SCHEMA, WALL_FACES, WALL_SIDES, type Room, type Scene } from \"./room.ts\";\nimport { SQUARE_TURNS, SURVEY_SCHEMA, type Survey } from \"./survey.ts\";\nimport { LENGTH_UNITS } from \"./units.ts\";\n\n// The schemas use `zod/mini`: a page gets only the parts of zod that the schemas use.\n// `zod/mini` has no messages, so each read gives the English messages of zod with `READ_CONTEXT`. It changes no setting of zod.\n\n/** The parse context of each read of this entry and of each add-on: the faults have the English messages of zod. */\nexport const READ_CONTEXT: z.core.ParseContext<z.core.$ZodIssue> = { error: en().localeError };\n\nconst id = z.string().check(z.minLength(1));\nconst planPoint = z.readonly(z.tuple([z.number(), z.number()]));\n\nconst point3 = z.readonly(z.tuple([z.number(), z.number(), z.number()]));\n\n/**\n * The schema of an anchor. It examines the form of the record, and it refuses a field that the surface of the anchor does not have.\n * The schema of an add-on uses it for the anchor of each record. `checkAnchor` examines the meaning of an anchor with a correct form.\n */\nexport const anchorSchema: z.ZodMiniType<Anchor> = z.discriminatedUnion(\"on\", [\n z.strictObject({ on: z.literal(\"wall\"), wall: id, face: z.enum(WALL_FACES), offset: z.number(), height: z.number() }),\n z.strictObject({ on: z.literal(\"floor\"), at: planPoint, floor: z.optional(id) }),\n z.strictObject({ on: z.literal(\"ceiling\"), at: planPoint, floor: z.optional(id) }),\n z.strictObject({ on: z.literal(\"object\"), object: id, at: z.optional(point3), out: z.optional(point3) }),\n]);\n\nconst wall = z.strictObject({\n id,\n from: planPoint,\n to: planPoint,\n thickness: z.optional(z.number()),\n height: z.optional(z.number()),\n side: z.optional(z.enum(WALL_SIDES)),\n});\n\nconst opening = z.strictObject({\n id,\n wall: id,\n kind: z.enum(OPENING_KINDS),\n offset: z.number(),\n width: z.number(),\n sill: z.optional(z.number()),\n height: z.number(),\n});\n\nconst floor = z.strictObject({\n id,\n name: z.optional(z.string()),\n ring: z.readonly(z.array(planPoint)),\n});\n\n/**\n * The schema of a room record. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkRoom` examines the meaning of a record with a correct form.\n */\nexport const roomSchema: z.ZodMiniType<Room> = z.strictObject({\n schema: z.literal(ROOM_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n walls: z.readonly(z.array(wall)),\n openings: z.optional(z.readonly(z.array(opening))),\n floors: z.optional(z.readonly(z.array(floor))),\n});\n\nconst placedObject = z.strictObject({\n id,\n kind: id,\n name: z.optional(z.string()),\n size: point3,\n at: planPoint,\n lift: z.optional(z.number()),\n turn: z.optional(z.number()),\n parent: z.optional(id),\n});\n\n// The layers of a scene, of a survey or of a level. The core does not read a layer, so it keeps each value. The add-on of a layer examines its form.\nconst layerName = z.string().check(z.refine(isLayerName, \"A layer name is a word, a slash and a version, for example electrical/1.\"));\nconst layers = z.optional(z.readonly(z.record(layerName, z.unknown())));\n\n/**\n * The schema of a scene record. It examines the form of the record, and it refuses a field that the format does not have.\n * `checkScene` examines the meaning of a record with a correct form.\n */\nexport const sceneSchema: z.ZodMiniType<Scene> = z.strictObject({\n schema: z.literal(SCENE_SCHEMA),\n name: z.optional(z.string()),\n room: roomSchema,\n objects: z.optional(z.readonly(z.array(placedObject))),\n layers,\n});\n\nconst surveySide = z.strictObject({\n id,\n length: z.number(),\n turn: z.union([z.enum(SQUARE_TURNS), z.number()]),\n thickness: z.optional(z.number()),\n height: z.optional(z.number()),\n});\n\nconst surveyCheck = z.strictObject({\n id,\n from: id,\n to: id,\n length: z.number(),\n});\n\nconst surveyObject = z.strictObject({\n id,\n kind: id,\n name: z.optional(z.string()),\n wall: z.optional(id),\n on: z.optional(id),\n offset: z.number(),\n width: z.number(),\n depth: z.number(),\n height: z.number(),\n gap: z.optional(z.number()),\n lift: z.optional(z.number()),\n});\n\n/**\n * The schema of a survey record. It examines the form of the record, and it refuses a field that the format does not have.\n * `expandSurvey` makes the room record of a survey with a correct form, and `checkRoom` examines that room record.\n */\nexport const surveySchema: z.ZodMiniType<Survey> = z.strictObject({\n schema: z.literal(SURVEY_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n height: z.number(),\n wallThickness: z.number(),\n sides: z.readonly(z.array(surveySide)),\n start: z.optional(planPoint),\n heading: z.optional(z.number()),\n checks: z.optional(z.readonly(z.array(surveyCheck))),\n openings: z.optional(z.readonly(z.array(opening))),\n objects: z.optional(z.readonly(z.array(surveyObject))),\n layers,\n});\n\nconst connectionEnd = z.strictObject({\n room: id,\n opening: id,\n});\n\n/**\n * The schema of a level record. It examines the form of the record and of each survey, and it refuses a field that the format does not have.\n * `expandLevel` makes the room record of a level with a correct form, and `checkRoom` examines that room record.\n */\nexport const levelSchema: z.ZodMiniType<Level> = z.strictObject({\n schema: z.literal(LEVEL_SCHEMA),\n name: z.optional(z.string()),\n unit: z.enum(LENGTH_UNITS),\n rooms: z.readonly(z.array(z.strictObject({ id, survey: surveySchema }))),\n connections: z.optional(z.readonly(z.array(z.strictObject({ id, from: connectionEnd, to: connectionEnd, thickness: z.optional(z.number()) })))),\n layers,\n});\n\n/** The record of each kind, in version 2. */\nexport interface KindRecords {\n readonly room: Room;\n readonly scene: Scene;\n readonly survey: Survey;\n readonly level: Level;\n}\n\n/** These are the codes of the findings of `readRecord`. */\nexport const READ_CODES: readonly [\"read-both\"] = [\"read-both\"];\n\n/** A finding of the read of a record of version 1. The read keeps the record, so a finding is not an error. */\nexport interface ReadFinding {\n readonly level: FindingLevel;\n /** A code of `READ_CODES`. */\n readonly code: string;\n /** The key of the layer in the record. */\n readonly layer: string;\n /** The `id` of the room of a level with the finding. A finding of the record has none. */\n readonly room?: string | undefined;\n /** The finding in plain words. */\n readonly message: string;\n}\n\n/** The result of `readRecord`: the record in version 2, its kind and its version in the file, or the faults of its form. */\nexport type RecordRead =\n | {\n readonly [Kind in FileKind]: {\n readonly ok: true;\n readonly kind: Kind;\n readonly record: KindRecords[Kind];\n /** The version of the format in the file. */\n readonly version: 1 | 2;\n readonly findings: readonly ReadFinding[];\n };\n }[FileKind]\n | { readonly ok: false; readonly errors: readonly string[] };\n\nconst KIND_NAMES: { readonly [Kind in FileKind]: string } = { room: ROOM_SCHEMA, scene: SCENE_SCHEMA, survey: SURVEY_SCHEMA, level: LEVEL_SCHEMA };\n\ntype Json = Readonly<Record<string, unknown>>;\n\n/** This function tells if a value is a JSON object. */\nfunction isJson(value: unknown): value is Json {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** This function gives the schema name of version 2 for a nested record of version 1. A different name stays, so the read tells its fault. */\nfunction newName(record: Json, kind: FileKind): unknown {\n return record[\"schema\"] === `${kind}/1` ? KIND_NAMES[kind] : record[\"schema\"];\n}\n\n/** This function gives the faults of a zod read. Each fault names its place in the record, for example `rooms.0.survey.sides`. */\nfunction faultsOf(error: z.core.$ZodError): readonly string[] {\n return error.issues.map((issue) => `${issue.path.length === 0 ? \"The record\" : `\"${issue.path.map(String).join(\".\")}\"`}: ${issue.message}`);\n}\n\n/**\n * This function reads the JSON of a record of the core in version 1 or in version 2. The record is a room, a scene, a survey or a level.\n * The result is the record in version 2. The schemas of this entry examine its form.\n *\n * A record of version 1 kept the records of some topics in fields of its own. For each add-on of the list with the read `v1`:\n *\n * - The read removes the fields of the add-on from the record, from each object and from each nested record.\n * - The function `read` of the add-on gives the layer of these fields. For a scene, this layer has the records of its room too.\n * For a level, the level record and the survey of each room get a layer.\n * - A record that has the layer and the old fields keeps the layer. The finding `read-both` tells it.\n *\n * A field of version 1 that no add-on of the list removes is a fault of the form. A room record has no layers.\n * Thus a `room/1` with old records gives a `scene/2` with the room and the layers, and a `room/1` with none gives a `room/2`.\n */\nexport function readRecord(value: unknown, addOns: readonly AddOn<unknown>[] = []): RecordRead {\n if (!isJson(value)) return { ok: false, errors: [\"The record is not a JSON object.\"] };\n const name = value[\"schema\"];\n const kind = FILE_KINDS.find((each) => KIND_NAMES[each] === name);\n if (kind !== undefined) return parsed(kind, value, 2, []);\n const old = FILE_KINDS.find((each) => `${each}/1` === name);\n if (old === undefined) return { ok: false, errors: [`The record has no known format: \"schema\" is ${JSON.stringify(name) ?? \"missing\"}.`] };\n const readers = addOns.filter((addOn) => addOn.v1 !== undefined);\n const findings: ReadFinding[] = [];\n const errors: string[] = [];\n const without = (record: Json, of: FileKind | \"object\"): Record<string, unknown> => {\n const gone = new Set(readers.flatMap((addOn) => addOn.v1?.fields[of] ?? []));\n return Object.fromEntries(Object.entries(record).filter(([key]) => !gone.has(key)));\n };\n const objectsOf = (record: Record<string, unknown>): void => {\n const objects = record[\"objects\"];\n if (Array.isArray(objects)) record[\"objects\"] = objects.map((object: unknown) => (isJson(object) ? without(object, \"object\") : object));\n };\n // The layers of the old fields of one record. A layer that the record has already stays.\n const withLayers = (record: Record<string, unknown>, raw: Json, of: FileKind, room?: string): void => {\n const given = isJson(raw[\"layers\"]) ? raw[\"layers\"] : {};\n const layers: Record<string, unknown> = { ...given };\n for (const addOn of readers) {\n const read = addOn.v1?.read(raw, of);\n if (read === undefined) continue;\n if (!read.ok) {\n errors.push(...read.errors);\n continue;\n }\n if (Object.hasOwn(given, addOn.schema)) {\n findings.push({\n level: \"warning\",\n code: \"read-both\",\n layer: addOn.schema,\n ...(room === undefined ? {} : { room }),\n message: `The record has the layer \"${addOn.schema}\" and its old fields. The layer stays, and the old fields go.`,\n });\n continue;\n }\n layers[addOn.schema] = read.layer;\n }\n if (Object.keys(layers).length > 0) record[\"layers\"] = layers;\n };\n const surveyOf = (raw: Json, room?: string): Record<string, unknown> => {\n const record = { ...without(raw, \"survey\"), schema: newName(raw, \"survey\") };\n objectsOf(record);\n withLayers(record, raw, \"survey\", room);\n return record;\n };\n const roomOf = (raw: unknown): unknown => (isJson(raw) ? { ...without(raw, \"room\"), schema: newName(raw, \"room\") } : raw);\n let next: unknown;\n let made: FileKind = old;\n if (old === \"survey\") next = surveyOf(value);\n else if (old === \"level\") {\n const level: Record<string, unknown> = { ...without(value, \"level\"), schema: LEVEL_SCHEMA };\n const rooms = value[\"rooms\"];\n if (Array.isArray(rooms)) {\n level[\"rooms\"] = rooms.map((room: unknown) => {\n if (!isJson(room) || !isJson(room[\"survey\"])) return room;\n return { ...room, survey: surveyOf(room[\"survey\"], typeof room[\"id\"] === \"string\" ? room[\"id\"] : undefined) };\n });\n }\n withLayers(level, value, \"level\");\n next = level;\n } else if (old === \"scene\") {\n const scene: Record<string, unknown> = { ...without(value, \"scene\"), schema: SCENE_SCHEMA, room: roomOf(value[\"room\"]) };\n objectsOf(scene);\n withLayers(scene, value, \"scene\");\n next = scene;\n } else {\n // A room record has no layers, so the layers of its old fields need a scene.\n const scene: Record<string, unknown> = { schema: SCENE_SCHEMA, room: roomOf(value) };\n withLayers(scene, value, \"room\");\n if (scene[\"layers\"] === undefined) next = scene[\"room\"];\n else {\n next = scene;\n made = \"scene\";\n }\n }\n if (errors.length > 0) return { ok: false, errors };\n return parsed(made, next, 1, findings);\n}\n\n/** This function reads a record of version 2 with the schema of its kind. */\nfunction parsed(kind: FileKind, value: unknown, version: 1 | 2, findings: readonly ReadFinding[]): RecordRead {\n if (kind === \"room\") {\n const read = roomSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n if (kind === \"scene\") {\n const read = sceneSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n if (kind === \"survey\") {\n const read = surveySchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n }\n const read = levelSchema.safeParse(value, READ_CONTEXT);\n return read.success ? { ok: true, kind, record: read.data, version, findings } : { ok: false, errors: faultsOf(read.error) };\n}\n"],"mappings":";;;;;;;AAcA,MAAa,eAAsD,EAAE,OAAO,GAAG,CAAC,CAAC,YAAY;AAE7F,MAAM,KAAK,EAAE,OA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,MAAM;OAC3C;GACH,OAAO;GACP,OAAO;EACT;CACF;CACA,IAAI,OAAO,SAAS,GAAG,OAAO;EAAE,IAAI;EAAO;CAAO;CAClD,OAAO,OAAO,MAAM,MAAM,GAAG,QAAQ;AACvC;;AAGA,SAAS,OAAO,MAAgB,OAAgB,SAAgB,UAA8C;CAC5G,IAAI,SAAS,QAAQ;EACnB,MAAM,OAAO,WAAW,UAAU,OAAO,YAAY;EACrD,OAAO,KAAK,UAAU;GAAE,IAAI;GAAM;GAAM,QAAQ,KAAK;GAAM;GAAS;EAAS,IAAI;GAAE,IAAI;GAAO,QAAQ,SAAS,KAAK,KAAK;EAAE;CAC7H;CACA,IAAI,SAAS,SAAS;EACpB,MAAM,OAAO,YAAY,UAAU,OAAO,YAAY;EACtD,OAAO,KAAK,UAAU;GAAE,IAAI;GAAM;GAAM,QAAQ,KAAK;GAAM;GAAS;EAAS,IAAI;GAAE,IAAI;GAAO,QAAQ,SAAS,KAAK,KAAK;EAAE;CAC7H;CACA,IAAI,SAAS,UAAU;EACrB,MAAM,OAAO,aAAa,UAAU,OAAO,YAAY;EACvD,OAAO,KAAK,UAAU;GAAE,IAAI;GAAM;GAAM,QAAQ,KAAK;GAAM;GAAS;EAAS,IAAI;GAAE,IAAI;GAAO,QAAQ,SAAS,KAAK,KAAK;EAAE;CAC7H;CACA,MAAM,OAAO,YAAY,UAAU,OAAO,YAAY;CACtD,OAAO,KAAK,UAAU;EAAE,IAAI;EAAM;EAAM,QAAQ,KAAK;EAAM;EAAS;CAAS,IAAI;EAAE,IAAI;EAAO,QAAQ,SAAS,KAAK,KAAK;CAAE;AAC7H"}
|
|
@@ -17,9 +17,9 @@ declare function lengthsInRange(...meters: readonly number[]): boolean;
|
|
|
17
17
|
/** A point of the plan: `[x, y]`. The plan is the view from above, and the z axis points up. */
|
|
18
18
|
type PlanPoint = readonly [number, number];
|
|
19
19
|
/** The name of the format of a room record. */
|
|
20
|
-
declare const ROOM_SCHEMA = "room/
|
|
20
|
+
declare const ROOM_SCHEMA = "room/2";
|
|
21
21
|
/** The name of the format of a scene record. */
|
|
22
|
-
declare const SCENE_SCHEMA = "scene/
|
|
22
|
+
declare const SCENE_SCHEMA = "scene/2";
|
|
23
23
|
/**
|
|
24
24
|
* This function tells if a text is the name of a layer: a word, a slash and a version, for example `electrical/1`.
|
|
25
25
|
* The word has lowercase letters, digits and hyphens. Thus a layer name has no colon, and `recordName` gives each record one name.
|
|
@@ -74,35 +74,7 @@ interface Floor {
|
|
|
74
74
|
readonly name?: string | undefined;
|
|
75
75
|
readonly ring: Ring;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
78
|
-
interface Outlet {
|
|
79
|
-
readonly id: string;
|
|
80
|
-
/** The `id` of the wall. */
|
|
81
|
-
readonly wall: string;
|
|
82
|
-
/** The face of the wall that has the outlet. */
|
|
83
|
-
readonly face: WallFace;
|
|
84
|
-
/** The distance along the line of the wall, from `from` to the center of the outlet. */
|
|
85
|
-
readonly offset: number;
|
|
86
|
-
/** The height of the center of the outlet above the floor. */
|
|
87
|
-
readonly height: number;
|
|
88
|
-
/** The `id` of the circuit of the outlet. */
|
|
89
|
-
readonly circuit?: string | undefined;
|
|
90
|
-
}
|
|
91
|
-
/** A circuit: it gives power to outlets, and it has a limit. */
|
|
92
|
-
interface Circuit {
|
|
93
|
-
readonly id: string;
|
|
94
|
-
readonly name?: string | undefined;
|
|
95
|
-
/** The rating of the breaker of the circuit, in amperes, for example 15. The record keeps it as a fact. The limit does not change with it. */
|
|
96
|
-
readonly breaker?: number | undefined;
|
|
97
|
-
/** The voltage of the circuit, in volts, for example 120. The record keeps it as a fact. The limit does not change with it. */
|
|
98
|
-
readonly voltage?: number | undefined;
|
|
99
|
-
/**
|
|
100
|
-
* The largest continuous load, in watts.
|
|
101
|
-
* For example, a breaker of 15 A at 120 V carries 1800 W, and 80% of that for a continuous load is 1440 W.
|
|
102
|
-
*/
|
|
103
|
-
readonly limit: number;
|
|
104
|
-
}
|
|
105
|
-
/** A room: the walls, the openings, the floors, the outlets and the circuits of one room or one apartment. */
|
|
77
|
+
/** A room: the walls, the openings and the floors of one room or one apartment. */
|
|
106
78
|
interface Room {
|
|
107
79
|
readonly schema: typeof ROOM_SCHEMA;
|
|
108
80
|
readonly name?: string | undefined;
|
|
@@ -115,8 +87,6 @@ interface Room {
|
|
|
115
87
|
readonly walls: readonly Wall[];
|
|
116
88
|
readonly openings?: readonly Opening[] | undefined;
|
|
117
89
|
readonly floors?: readonly Floor[] | undefined;
|
|
118
|
-
readonly outlets?: readonly Outlet[] | undefined;
|
|
119
|
-
readonly circuits?: readonly Circuit[] | undefined;
|
|
120
90
|
}
|
|
121
91
|
/**
|
|
122
92
|
* A placed object: a box in the room, for example a desk, a rack or a computer.
|
|
@@ -137,22 +107,13 @@ interface PlacedObject {
|
|
|
137
107
|
readonly turn?: number | undefined;
|
|
138
108
|
/** The `id` of the object that holds this object. */
|
|
139
109
|
readonly parent?: string | undefined;
|
|
140
|
-
/** The `id` of the outlet that gives power to the object. */
|
|
141
|
-
readonly outlet?: string | undefined;
|
|
142
110
|
}
|
|
143
|
-
/** A
|
|
144
|
-
interface CircuitLoad {
|
|
145
|
-
/** The `id` of the circuit. */
|
|
146
|
-
readonly circuit: string;
|
|
147
|
-
readonly watts: number;
|
|
148
|
-
}
|
|
149
|
-
/** A scene: one room with its placed objects and the loads of its circuits. Two scenes of one room can be compared. */
|
|
111
|
+
/** A scene: one room with its placed objects and the records of its add-ons. Two scenes of one room can be compared. */
|
|
150
112
|
interface Scene {
|
|
151
113
|
readonly schema: typeof SCENE_SCHEMA;
|
|
152
114
|
readonly name?: string | undefined;
|
|
153
115
|
readonly room: Room;
|
|
154
116
|
readonly objects?: readonly PlacedObject[] | undefined;
|
|
155
|
-
readonly loads?: readonly CircuitLoad[] | undefined;
|
|
156
117
|
/**
|
|
157
118
|
* The records of each add-on, by the name of its layer, for example `electrical/1`. `isLayerName` tells the form of a name.
|
|
158
119
|
* The core keeps each layer and does not read it. `checkLayers` examines the layers with a list of add-ons.
|
|
@@ -230,7 +191,7 @@ declare const MITER_LIMIT = 4;
|
|
|
230
191
|
*/
|
|
231
192
|
declare function wallFootprints(frames: readonly WallFrame[], options?: JoinOptions): readonly WallFootprint[];
|
|
232
193
|
/** These are the kinds of a solid. */
|
|
233
|
-
declare const SOLID_KINDS: readonly ["floor", "wall", "glass", "
|
|
194
|
+
declare const SOLID_KINDS: readonly ["floor", "wall", "glass", "object"];
|
|
234
195
|
/** A kind of solid. */
|
|
235
196
|
type SolidKind = (typeof SOLID_KINDS)[number];
|
|
236
197
|
/** A prism: an outline in the plan, from the height `z` up by `d`. The unit is the meter. */
|
|
@@ -256,7 +217,7 @@ interface Solid {
|
|
|
256
217
|
/** The name of the solid. Each solid of a model has a different name. */
|
|
257
218
|
readonly id: string;
|
|
258
219
|
readonly kind: SolidKind;
|
|
259
|
-
/** The `id` of the record that the solid comes from: a wall, a floor, an opening
|
|
220
|
+
/** The `id` of the record that the solid comes from: a wall, a floor, an opening or a placed object. */
|
|
260
221
|
readonly source: string;
|
|
261
222
|
readonly shape: SolidShape;
|
|
262
223
|
}
|
|
@@ -271,12 +232,6 @@ interface SolidOptions {
|
|
|
271
232
|
declare const FLOOR_DEPTH = .1;
|
|
272
233
|
/** The thickness of the glass of a window, in meters. */
|
|
273
234
|
declare const GLASS_THICKNESS = .02;
|
|
274
|
-
/** The size of the plate of an outlet, in meters. The plate of a duplex outlet in North America is 70 mm by 115 mm. */
|
|
275
|
-
declare const OUTLET_PLATE: {
|
|
276
|
-
readonly width: number;
|
|
277
|
-
readonly height: number;
|
|
278
|
-
readonly depth: number;
|
|
279
|
-
};
|
|
280
235
|
/**
|
|
281
236
|
* The transform from the room, where the z axis points up, to a space where the y axis points up.
|
|
282
237
|
* The glTF format and three.js have the y axis up. The x axis stays, and the y axis of the plan becomes the negative z axis.
|
|
@@ -284,7 +239,7 @@ declare const OUTLET_PLATE: {
|
|
|
284
239
|
declare const TO_Y_UP: Transform3;
|
|
285
240
|
/**
|
|
286
241
|
* This function gives the 3D model of a room as a list of solids.
|
|
287
|
-
* The solids are the floors, the walls with their openings
|
|
242
|
+
* The solids are the floors, the walls with their openings and the glass of the windows. The marks of the layers show the records of the add-ons.
|
|
288
243
|
*
|
|
289
244
|
* The function does not stop for a record with a fault. It skips each part that it cannot make.
|
|
290
245
|
* One example is a wall with no length. A second example is an opening on a wall that the room does not have.
|
|
@@ -309,5 +264,5 @@ declare function solidCorners(solid: Solid): readonly Point3[];
|
|
|
309
264
|
declare function boundsOfSolids(solids: readonly Solid[]): Box3 | undefined;
|
|
310
265
|
/** This function gives the volume of a solid in cubic meters. */
|
|
311
266
|
declare function solidVolume(solid: Solid): number;
|
|
312
|
-
export {
|
|
313
|
-
//# sourceMappingURL=solids-
|
|
267
|
+
export { OpeningKind as A, WallFace as B, wallFrames as C, Floor as D, wallTransform as E, SCENE_SCHEMA as F, LengthUnit as G, isLayerName as H, Scene as I, unitsPer as J, lengthsInRange as K, WALL_FACES as L, PlanPoint as M, ROOM_SCHEMA as N, OPENING_KINDS as O, Room as P, WALL_SIDES as R, WallFrame as S, wallPoint as T, LARGEST_LENGTH as U, WallSide as V, LENGTH_UNITS as W, JOIN_TOLERANCE as _, SOLID_KINDS as a, WallFootprint as b, SolidOptions as c, boundsOfSolids as d, objectTransforms as f, solidVolume as g, solidCorners as h, Prism as i, PlacedObject as j, Opening as k, SolidShape as l, sceneSolids as m, GLASS_THICKNESS as n, Solid as o, roomSolids as p, metersPer as q, PlacedBox as r, SolidKind as s, FLOOR_DEPTH as t, TO_Y_UP as u, JoinOptions as v, wallHasOutline as w, wallFootprints as x, MITER_LIMIT as y, Wall as z };
|
|
268
|
+
//# sourceMappingURL=solids-OiTlb_Pm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solids-OiTlb_Pm.d.ts","names":[],"sources":["../src/units.ts","../src/room.ts","../src/frames.ts","../src/joins.ts","../src/solids.ts"],"mappings":";;cAGa;;KA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