@seatmap-fyi/map-domain 0.0.0-stage → 0.1.0-alpha.1
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/dist/case-fold-data.d.ts +1 -0
- package/dist/case-fold-data.js +4 -0
- package/dist/catalog.d.ts +15 -0
- package/dist/catalog.js +35 -0
- package/dist/geometry/boundary.d.ts +22 -0
- package/dist/geometry/boundary.js +69 -0
- package/dist/geometry/curve-warnings.d.ts +15 -0
- package/dist/geometry/curve-warnings.js +46 -0
- package/dist/geometry/ellipse.d.ts +5 -0
- package/dist/geometry/ellipse.js +74 -0
- package/dist/geometry/geometry.d.ts +37 -0
- package/dist/geometry/geometry.js +219 -0
- package/dist/geometry/primitives.d.ts +12 -0
- package/dist/geometry/primitives.js +35 -0
- package/dist/geometry/seating-layout.d.ts +43 -0
- package/dist/geometry/seating-layout.js +132 -0
- package/dist/geometry/venue-outline.d.ts +21 -0
- package/dist/geometry/venue-outline.js +120 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.js +61 -0
- package/dist/issues.d.ts +46 -0
- package/dist/issues.js +55 -0
- package/dist/labels.d.ts +3 -0
- package/dist/labels.js +45 -0
- package/dist/reference.d.ts +29 -0
- package/dist/reference.js +51 -0
- package/dist/schema.d.ts +1629 -0
- package/dist/schema.js +560 -0
- package/dist/types.d.ts +313 -0
- package/dist/types.js +91 -0
- package/dist/validation.d.ts +27 -0
- package/dist/validation.js +267 -0
- package/package.json +84 -4
- package/src/unicode-license.txt +39 -0
- package/README.md +0 -3
package/dist/schema.js
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { DocumentLimits, NumberingScheme, LabelDirection, RowLabelPosition, SeatingKind, CurveMode, DecorationKind, LabelAlignment, RowAlignment, SectionOutlineRole, AreaKind, ShapeKind, VenueGlyph, } from "./types.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { issue, IssueCode } from "./issues.js";
|
|
4
|
+
import { footprint, generateGroup, project, worldMatrices, } from "./geometry/geometry.js";
|
|
5
|
+
const uuid = z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
8
|
+
const finite = z.number().finite();
|
|
9
|
+
const coordinate = finite.min(-10000).max(10000);
|
|
10
|
+
const dimension = finite.min(0.001).max(10000);
|
|
11
|
+
const nonNegative = finite.min(0).max(10000);
|
|
12
|
+
const angle = finite.min(-180).lt(180);
|
|
13
|
+
const text = (limit, multiline = false) => z
|
|
14
|
+
.string()
|
|
15
|
+
.refine((v) => Array.from(v).length <= limit &&
|
|
16
|
+
!/[\u0000-\u001f\u007f-\u009f]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(multiline ? v.replace(/\n/g, "") : v), "Text exceeds its limit or contains unsupported control/surrogate characters.")
|
|
17
|
+
.meta({
|
|
18
|
+
maxLength: limit,
|
|
19
|
+
description: multiline
|
|
20
|
+
? "Unicode code-point length; LF is permitted. Other control characters and unpaired surrogates are rejected."
|
|
21
|
+
: "Unicode code-point length; control characters and unpaired surrogates are rejected.",
|
|
22
|
+
});
|
|
23
|
+
const name = text(120)
|
|
24
|
+
.refine((v) => v.trim().length > 0 && v === v.trim(), "Use a trimmed, nonempty name.")
|
|
25
|
+
.meta({
|
|
26
|
+
minLength: 1,
|
|
27
|
+
description: "Nonempty, trimmed name; at most 120 Unicode code points. Control characters and unpaired surrogates are rejected.",
|
|
28
|
+
});
|
|
29
|
+
const label = text(80);
|
|
30
|
+
const point = z.strictObject({ x: coordinate, y: coordinate });
|
|
31
|
+
const size = z.strictObject({ width: dimension, height: dimension });
|
|
32
|
+
const transform = z.strictObject({
|
|
33
|
+
positionM: point,
|
|
34
|
+
rotationDeg: angle,
|
|
35
|
+
flipX: z.boolean().optional(),
|
|
36
|
+
flipY: z.boolean().optional(),
|
|
37
|
+
});
|
|
38
|
+
const ring = z
|
|
39
|
+
.array(point)
|
|
40
|
+
.min(3)
|
|
41
|
+
.max(10000)
|
|
42
|
+
.refine((v) => v[0].x !== v[v.length - 1].x || v[0].y !== v[v.length - 1].y, "Rings close implicitly; do not repeat the first vertex.")
|
|
43
|
+
.describe("Implicitly closed ring; the last vertex must not repeat the first.");
|
|
44
|
+
const polygon = z.strictObject({
|
|
45
|
+
outer: ring,
|
|
46
|
+
holes: z.array(ring).max(10000),
|
|
47
|
+
});
|
|
48
|
+
const paint = z.strictObject({
|
|
49
|
+
color: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
|
50
|
+
opacity: finite.min(0).max(1),
|
|
51
|
+
});
|
|
52
|
+
const sequence = z
|
|
53
|
+
.strictObject({
|
|
54
|
+
scheme: z.enum(NumberingScheme),
|
|
55
|
+
startAt: finite.int().min(1).max(1e9),
|
|
56
|
+
direction: z.enum(LabelDirection),
|
|
57
|
+
prefix: text(32).optional(),
|
|
58
|
+
suffix: text(32).optional(),
|
|
59
|
+
})
|
|
60
|
+
.refine((v) => v.scheme !== NumberingScheme.Odd || v.startAt % 2 === 1, "Odd numbering must start at an odd integer.")
|
|
61
|
+
.refine((v) => v.scheme !== NumberingScheme.Even || v.startAt % 2 === 0, "Even numbering must start at an even integer.")
|
|
62
|
+
.describe("Odd/even numbering requires a matching odd/even startAt value.");
|
|
63
|
+
const labelStyle = z.strictObject({
|
|
64
|
+
visible: z.boolean(),
|
|
65
|
+
fontSizeM: dimension,
|
|
66
|
+
});
|
|
67
|
+
const seat = z.strictObject({
|
|
68
|
+
id: uuid,
|
|
69
|
+
labelOverride: label.optional(),
|
|
70
|
+
attributes: z
|
|
71
|
+
.strictObject({
|
|
72
|
+
accessible: z.boolean().optional(),
|
|
73
|
+
restrictedView: z.boolean().optional(),
|
|
74
|
+
hearingAssistance: z.boolean().optional(),
|
|
75
|
+
semiAmbulatory: z.boolean().optional(),
|
|
76
|
+
companionForSeatId: uuid.optional(),
|
|
77
|
+
})
|
|
78
|
+
.optional(),
|
|
79
|
+
override: z
|
|
80
|
+
.strictObject({
|
|
81
|
+
offsetM: point.optional(),
|
|
82
|
+
rotationDeltaDeg: angle.optional(),
|
|
83
|
+
sizeM: size.optional(),
|
|
84
|
+
})
|
|
85
|
+
.optional(),
|
|
86
|
+
});
|
|
87
|
+
const row = z.strictObject({
|
|
88
|
+
id: uuid,
|
|
89
|
+
labelOverride: label.optional(),
|
|
90
|
+
offsetM: point.optional(),
|
|
91
|
+
seatSequenceOverride: sequence.optional(),
|
|
92
|
+
seats: z.array(seat).min(1).max(DocumentLimits.PhysicalSeats),
|
|
93
|
+
});
|
|
94
|
+
const drawable = {
|
|
95
|
+
id: uuid,
|
|
96
|
+
parentId: uuid.nullable(),
|
|
97
|
+
transform,
|
|
98
|
+
zIndex: finite.int().min(-2147483648).max(2147483647),
|
|
99
|
+
};
|
|
100
|
+
const groupBase = {
|
|
101
|
+
...drawable,
|
|
102
|
+
name,
|
|
103
|
+
sectionId: uuid.nullable(),
|
|
104
|
+
seatSizeM: size,
|
|
105
|
+
boundary: polygon.optional(),
|
|
106
|
+
seatLabelStyle: labelStyle,
|
|
107
|
+
};
|
|
108
|
+
const rowsLabels = z.strictObject({
|
|
109
|
+
rows: sequence,
|
|
110
|
+
seats: sequence,
|
|
111
|
+
rowStyle: z.strictObject({
|
|
112
|
+
visible: z.boolean(),
|
|
113
|
+
fontSizeM: dimension,
|
|
114
|
+
position: z.enum(RowLabelPosition),
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
const tableLabels = z.strictObject({
|
|
118
|
+
table: label,
|
|
119
|
+
chairs: sequence,
|
|
120
|
+
tableStyle: labelStyle,
|
|
121
|
+
});
|
|
122
|
+
export const groupSchema = z.discriminatedUnion("kind", [
|
|
123
|
+
z.strictObject({
|
|
124
|
+
...groupBase,
|
|
125
|
+
kind: z.literal(SeatingKind.Straight),
|
|
126
|
+
recipe: z.strictObject({
|
|
127
|
+
seatPitchM: dimension,
|
|
128
|
+
rowPitchM: dimension,
|
|
129
|
+
rowAlignment: z.enum(RowAlignment).optional(),
|
|
130
|
+
}),
|
|
131
|
+
labels: rowsLabels,
|
|
132
|
+
rows: z.array(row).min(1).max(DocumentLimits.PhysicalSeats),
|
|
133
|
+
}),
|
|
134
|
+
z.strictObject({
|
|
135
|
+
...groupBase,
|
|
136
|
+
kind: z.literal(SeatingKind.Curved),
|
|
137
|
+
recipe: z.strictObject({
|
|
138
|
+
innerRadiusM: dimension,
|
|
139
|
+
axisRatio: finite.min(0.01).max(100).optional(),
|
|
140
|
+
rowPitchM: dimension,
|
|
141
|
+
placement: z.discriminatedUnion("kind", [
|
|
142
|
+
z.strictObject({
|
|
143
|
+
kind: z.literal(CurveMode.Sweep),
|
|
144
|
+
startAngleDeg: angle,
|
|
145
|
+
sweepAngleDeg: finite
|
|
146
|
+
.min(-360)
|
|
147
|
+
.max(360)
|
|
148
|
+
.refine((v) => v !== 0),
|
|
149
|
+
}),
|
|
150
|
+
z.strictObject({
|
|
151
|
+
kind: z.literal(CurveMode.Pitch),
|
|
152
|
+
centerAngleDeg: angle,
|
|
153
|
+
seatPitchM: dimension,
|
|
154
|
+
}),
|
|
155
|
+
]),
|
|
156
|
+
}),
|
|
157
|
+
labels: rowsLabels,
|
|
158
|
+
rows: z.array(row).min(1).max(DocumentLimits.PhysicalSeats),
|
|
159
|
+
}),
|
|
160
|
+
z
|
|
161
|
+
.strictObject({
|
|
162
|
+
...groupBase,
|
|
163
|
+
kind: z.literal(SeatingKind.Rectangular),
|
|
164
|
+
recipe: z.strictObject({
|
|
165
|
+
widthM: dimension,
|
|
166
|
+
depthM: dimension,
|
|
167
|
+
chairGapM: nonNegative,
|
|
168
|
+
chairPitchM: dimension.optional(),
|
|
169
|
+
}),
|
|
170
|
+
labels: tableLabels,
|
|
171
|
+
chairsBySide: z.strictObject({
|
|
172
|
+
top: z.array(seat).max(DocumentLimits.PhysicalSeats),
|
|
173
|
+
right: z.array(seat).max(DocumentLimits.PhysicalSeats),
|
|
174
|
+
bottom: z.array(seat).max(DocumentLimits.PhysicalSeats),
|
|
175
|
+
left: z.array(seat).max(DocumentLimits.PhysicalSeats),
|
|
176
|
+
}),
|
|
177
|
+
})
|
|
178
|
+
.refine((v) => Object.values(v.chairsBySide).some((s) => s.length > 0), "A table needs at least one chair."),
|
|
179
|
+
z.strictObject({
|
|
180
|
+
...groupBase,
|
|
181
|
+
kind: z.literal(SeatingKind.Round),
|
|
182
|
+
recipe: z.strictObject({
|
|
183
|
+
diameterM: dimension,
|
|
184
|
+
chairGapM: nonNegative,
|
|
185
|
+
startAngleDeg: angle,
|
|
186
|
+
}),
|
|
187
|
+
labels: tableLabels,
|
|
188
|
+
chairs: z.array(seat).min(1).max(DocumentLimits.PhysicalSeats),
|
|
189
|
+
}),
|
|
190
|
+
]);
|
|
191
|
+
export const decorationStyleSchema = z.strictObject({
|
|
192
|
+
fill: paint.optional(),
|
|
193
|
+
stroke: paint.optional(),
|
|
194
|
+
strokeWidthM: nonNegative.optional(),
|
|
195
|
+
});
|
|
196
|
+
const decorationBase = {
|
|
197
|
+
...drawable,
|
|
198
|
+
style: decorationStyleSchema.optional(),
|
|
199
|
+
};
|
|
200
|
+
const decoration = z.discriminatedUnion("kind", [
|
|
201
|
+
z.strictObject({
|
|
202
|
+
...decorationBase,
|
|
203
|
+
kind: z.literal(DecorationKind.Text),
|
|
204
|
+
text: text(10000),
|
|
205
|
+
fontSizeM: dimension,
|
|
206
|
+
align: z.enum(LabelAlignment),
|
|
207
|
+
}),
|
|
208
|
+
z
|
|
209
|
+
.strictObject({
|
|
210
|
+
...decorationBase,
|
|
211
|
+
kind: z.literal(DecorationKind.Rectangle),
|
|
212
|
+
sizeM: size,
|
|
213
|
+
cornerRadiusM: nonNegative,
|
|
214
|
+
})
|
|
215
|
+
.refine((v) => v.cornerRadiusM <= Math.min(v.sizeM.width, v.sizeM.height) / 2),
|
|
216
|
+
z.strictObject({
|
|
217
|
+
...decorationBase,
|
|
218
|
+
kind: z.literal(DecorationKind.Circle),
|
|
219
|
+
radiusM: dimension,
|
|
220
|
+
}),
|
|
221
|
+
z.strictObject({
|
|
222
|
+
...decorationBase,
|
|
223
|
+
kind: z.literal(DecorationKind.Line),
|
|
224
|
+
pointsM: z.array(point).min(2).max(10000),
|
|
225
|
+
}),
|
|
226
|
+
z.strictObject({
|
|
227
|
+
...decorationBase,
|
|
228
|
+
kind: z.literal(DecorationKind.Polygon),
|
|
229
|
+
boundary: polygon,
|
|
230
|
+
}),
|
|
231
|
+
z.strictObject({
|
|
232
|
+
...decorationBase,
|
|
233
|
+
kind: z.literal(DecorationKind.Icon),
|
|
234
|
+
iconId: z.enum(VenueGlyph),
|
|
235
|
+
sizeM: size,
|
|
236
|
+
}),
|
|
237
|
+
z.strictObject({
|
|
238
|
+
...decorationBase,
|
|
239
|
+
kind: z.literal(DecorationKind.Image),
|
|
240
|
+
assetId: uuid,
|
|
241
|
+
sizeM: size,
|
|
242
|
+
opacity: finite.min(0).max(1),
|
|
243
|
+
}),
|
|
244
|
+
]);
|
|
245
|
+
const area = z.strictObject({
|
|
246
|
+
...drawable,
|
|
247
|
+
kind: z.literal(AreaKind.GeneralAdmission),
|
|
248
|
+
sectionId: uuid.nullable(),
|
|
249
|
+
label,
|
|
250
|
+
labelStyle,
|
|
251
|
+
capacity: finite.int().min(1).max(2147483647),
|
|
252
|
+
shape: z.discriminatedUnion("kind", [
|
|
253
|
+
z
|
|
254
|
+
.strictObject({
|
|
255
|
+
kind: z.literal(ShapeKind.Rectangle),
|
|
256
|
+
widthM: dimension,
|
|
257
|
+
heightM: dimension,
|
|
258
|
+
cornerRadiusM: nonNegative,
|
|
259
|
+
})
|
|
260
|
+
.refine((v) => v.cornerRadiusM <= Math.min(v.widthM, v.heightM) / 2),
|
|
261
|
+
z.strictObject({ kind: z.literal(ShapeKind.Polygon), boundary: polygon }),
|
|
262
|
+
]),
|
|
263
|
+
});
|
|
264
|
+
export const documentSchema = z.strictObject({
|
|
265
|
+
schemaVersion: z.literal(1),
|
|
266
|
+
mapId: uuid,
|
|
267
|
+
name,
|
|
268
|
+
coordinateSystem: z.strictObject({
|
|
269
|
+
unit: z.literal("metre"),
|
|
270
|
+
xAxis: z.literal("right"),
|
|
271
|
+
yAxis: z.literal("down"),
|
|
272
|
+
rotation: z.literal("clockwise"),
|
|
273
|
+
}),
|
|
274
|
+
background: paint,
|
|
275
|
+
sections: z
|
|
276
|
+
.array(z.strictObject({
|
|
277
|
+
id: uuid,
|
|
278
|
+
label,
|
|
279
|
+
displayLabel: text(80, true).optional(),
|
|
280
|
+
outline: polygon.optional(),
|
|
281
|
+
outlineRole: z.enum(SectionOutlineRole).optional(),
|
|
282
|
+
style: decorationStyleSchema.optional(),
|
|
283
|
+
labelPlacement: z
|
|
284
|
+
.strictObject({
|
|
285
|
+
positionM: point,
|
|
286
|
+
rotationDeg: angle,
|
|
287
|
+
align: z.enum(LabelAlignment),
|
|
288
|
+
})
|
|
289
|
+
.optional(),
|
|
290
|
+
labelStyle,
|
|
291
|
+
}))
|
|
292
|
+
.max(1024),
|
|
293
|
+
collections: z.array(z.strictObject({ ...drawable, name })).max(10000),
|
|
294
|
+
seatingGroups: z.array(groupSchema).max(DocumentLimits.PhysicalSeats),
|
|
295
|
+
areas: z.array(area).max(10000),
|
|
296
|
+
decorations: z.array(decoration).max(10000),
|
|
297
|
+
assets: z
|
|
298
|
+
.array(z.strictObject({
|
|
299
|
+
id: uuid,
|
|
300
|
+
mimeType: z.enum([
|
|
301
|
+
"image/png",
|
|
302
|
+
"image/jpeg",
|
|
303
|
+
"image/webp",
|
|
304
|
+
"image/svg+xml",
|
|
305
|
+
]),
|
|
306
|
+
}))
|
|
307
|
+
.max(256),
|
|
308
|
+
});
|
|
309
|
+
// Validate only the edited authority. Untouched structure was validated at import.
|
|
310
|
+
export const areaSchema = area;
|
|
311
|
+
export const decorationSchema = decoration;
|
|
312
|
+
export const collectionSchema = documentSchema.shape.collections.element;
|
|
313
|
+
export const assetSchema = documentSchema.shape.assets.element;
|
|
314
|
+
export const paintSchema = paint;
|
|
315
|
+
export const transformSchema = transform;
|
|
316
|
+
export const mapNameSchema = name;
|
|
317
|
+
export const sectionSchema = documentSchema.shape.sections.element;
|
|
318
|
+
export const uuidSchema = uuid;
|
|
319
|
+
export const dimensionSchema = dimension;
|
|
320
|
+
export const coordinateSchema = coordinate;
|
|
321
|
+
export const rotationSchema = angle;
|
|
322
|
+
export const positiveCountSchema = finite
|
|
323
|
+
.int()
|
|
324
|
+
.min(1)
|
|
325
|
+
.max(DocumentLimits.PhysicalSeats);
|
|
326
|
+
export const labelSequenceSchema = sequence;
|
|
327
|
+
export const inventoryLabelSchema = label;
|
|
328
|
+
export const attributesSchema = seat.shape.attributes;
|
|
329
|
+
export const seatOverrideSchema = seat.shape.override;
|
|
330
|
+
export function validateRecipe(group) {
|
|
331
|
+
const schema = groupSchema.options.find((option) => option.shape.kind.value === group.kind);
|
|
332
|
+
return schema.shape.recipe.safeParse(group.recipe);
|
|
333
|
+
}
|
|
334
|
+
export function validateSequences(group) {
|
|
335
|
+
const schema = groupSchema.options.find((option) => option.shape.kind.value === group.kind);
|
|
336
|
+
return schema.shape.labels.safeParse(group.labels);
|
|
337
|
+
}
|
|
338
|
+
export var DocumentParseStatus;
|
|
339
|
+
(function (DocumentParseStatus) {
|
|
340
|
+
DocumentParseStatus["Accepted"] = "accepted";
|
|
341
|
+
DocumentParseStatus["Rejected"] = "rejected";
|
|
342
|
+
})(DocumentParseStatus || (DocumentParseStatus = {}));
|
|
343
|
+
export function groupSeatCount(group) {
|
|
344
|
+
return group.kind === SeatingKind.Straight ||
|
|
345
|
+
group.kind === SeatingKind.Curved
|
|
346
|
+
? group.rows.reduce((n, r) => n + r.seats.length, 0)
|
|
347
|
+
: group.kind === SeatingKind.Round
|
|
348
|
+
? group.chairs.length
|
|
349
|
+
: Object.values(group.chairsBySide).reduce((n, s) => n + s.length, 0);
|
|
350
|
+
}
|
|
351
|
+
export function* seatSlots(group) {
|
|
352
|
+
if (group.kind === SeatingKind.Straight || group.kind === SeatingKind.Curved)
|
|
353
|
+
for (const row of group.rows)
|
|
354
|
+
yield* row.seats;
|
|
355
|
+
else if (group.kind === SeatingKind.Round)
|
|
356
|
+
yield* group.chairs;
|
|
357
|
+
else
|
|
358
|
+
for (const side of ["top", "right", "bottom", "left"])
|
|
359
|
+
yield* group.chairsBySide[side];
|
|
360
|
+
}
|
|
361
|
+
export function capacity(document) {
|
|
362
|
+
return {
|
|
363
|
+
physicalSeats: document.seatingGroups.reduce((n, g) => n + groupSeatCount(g), 0),
|
|
364
|
+
gaQuantity: document.areas.reduce((n, a) => n + a.capacity, 0),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
export function structuralIssues(document, changedGroups) {
|
|
368
|
+
const errors = [];
|
|
369
|
+
const ids = new Set([document.mapId]);
|
|
370
|
+
const add = (id) => {
|
|
371
|
+
if (ids.has(id))
|
|
372
|
+
errors.push(issue(IssueCode.DuplicateId, "Physical identities must be unique.", [
|
|
373
|
+
id,
|
|
374
|
+
]));
|
|
375
|
+
ids.add(id);
|
|
376
|
+
};
|
|
377
|
+
const sections = new Set(document.sections.map((s) => s.id));
|
|
378
|
+
const parents = new Map(document.collections.map((c) => [c.id, c]));
|
|
379
|
+
let vertices = 0;
|
|
380
|
+
const visitPolygon = (p) => {
|
|
381
|
+
if (p)
|
|
382
|
+
vertices += p.outer.length + p.holes.reduce((n, h) => n + h.length, 0);
|
|
383
|
+
};
|
|
384
|
+
for (const s of document.sections) {
|
|
385
|
+
add(s.id);
|
|
386
|
+
visitPolygon(s.outline);
|
|
387
|
+
}
|
|
388
|
+
for (const a of document.assets)
|
|
389
|
+
add(a.id);
|
|
390
|
+
for (const object of [
|
|
391
|
+
...document.collections,
|
|
392
|
+
...document.seatingGroups,
|
|
393
|
+
...document.areas,
|
|
394
|
+
...document.decorations,
|
|
395
|
+
]) {
|
|
396
|
+
add(object.id);
|
|
397
|
+
if ("sectionId" in object &&
|
|
398
|
+
object.sectionId !== null &&
|
|
399
|
+
!sections.has(object.sectionId))
|
|
400
|
+
errors.push(issue(IssueCode.UnknownSection, "Section reference does not exist.", [
|
|
401
|
+
object.id,
|
|
402
|
+
]));
|
|
403
|
+
const visited = new Set([object.id]);
|
|
404
|
+
let parent = object.parentId;
|
|
405
|
+
let depth = 0;
|
|
406
|
+
while (parent) {
|
|
407
|
+
if (visited.has(parent) || !parents.has(parent) || ++depth > 64) {
|
|
408
|
+
errors.push(issue(IssueCode.InvalidParent, "Parent must be an existing acyclic collection, within depth 64.", [object.id]));
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
visited.add(parent);
|
|
412
|
+
parent = parents.get(parent).parentId;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
for (const g of document.seatingGroups) {
|
|
416
|
+
visitPolygon(g.boundary);
|
|
417
|
+
if (g.kind === SeatingKind.Straight || g.kind === SeatingKind.Curved)
|
|
418
|
+
for (const r of g.rows) {
|
|
419
|
+
add(r.id);
|
|
420
|
+
for (const s of r.seats)
|
|
421
|
+
add(s.id);
|
|
422
|
+
}
|
|
423
|
+
else
|
|
424
|
+
for (const s of generateGroup(g))
|
|
425
|
+
add(s.id);
|
|
426
|
+
}
|
|
427
|
+
for (const a of document.areas)
|
|
428
|
+
if (a.shape.kind === ShapeKind.Polygon)
|
|
429
|
+
visitPolygon(a.shape.boundary);
|
|
430
|
+
for (const d of document.decorations)
|
|
431
|
+
if (d.kind === DecorationKind.Line)
|
|
432
|
+
vertices += d.pointsM.length;
|
|
433
|
+
else if (d.kind === DecorationKind.Polygon)
|
|
434
|
+
visitPolygon(d.boundary);
|
|
435
|
+
const counts = capacity(document);
|
|
436
|
+
if (counts.physicalSeats > DocumentLimits.PhysicalSeats ||
|
|
437
|
+
!Number.isSafeInteger(counts.gaQuantity + counts.physicalSeats) ||
|
|
438
|
+
vertices > 100000)
|
|
439
|
+
errors.push(issue(IssueCode.Limit, "Document exceeds its inventory, capacity or vertex safety limit.", [document.mapId]));
|
|
440
|
+
if (errors.length)
|
|
441
|
+
return errors;
|
|
442
|
+
const matrices = worldMatrices(document);
|
|
443
|
+
const within = (p) => Number.isFinite(p.x) &&
|
|
444
|
+
Number.isFinite(p.y) &&
|
|
445
|
+
Math.abs(p.x) <= 10000 &&
|
|
446
|
+
Math.abs(p.y) <= 10000;
|
|
447
|
+
for (const g of document.seatingGroups) {
|
|
448
|
+
if (changedGroups && !changedGroups.has(g.id))
|
|
449
|
+
continue;
|
|
450
|
+
const matrix = matrices.get(g.id);
|
|
451
|
+
if (Array.from(generateGroup(g)).some((s) => footprint(s, matrix).some((p) => !within(p))))
|
|
452
|
+
errors.push(issue(IssueCode.WorldBounds, "Derived seat footprints exceed the physical coordinate safety bounds.", [g.id]));
|
|
453
|
+
}
|
|
454
|
+
for (const d of [...document.decorations, ...document.areas]) {
|
|
455
|
+
const matrix = matrices.get(d.id);
|
|
456
|
+
let points = [{ x: 0, y: 0 }];
|
|
457
|
+
if (d.kind === DecorationKind.Line)
|
|
458
|
+
points = d.pointsM;
|
|
459
|
+
else if (d.kind === DecorationKind.Polygon)
|
|
460
|
+
points = [...d.boundary.outer, ...d.boundary.holes.flat()];
|
|
461
|
+
else if (d.kind === AreaKind.GeneralAdmission &&
|
|
462
|
+
d.shape.kind === ShapeKind.Polygon)
|
|
463
|
+
points = [...d.shape.boundary.outer, ...d.shape.boundary.holes.flat()];
|
|
464
|
+
else {
|
|
465
|
+
const w = d.kind === DecorationKind.Circle
|
|
466
|
+
? d.radiusM * 2
|
|
467
|
+
: d.kind === AreaKind.GeneralAdmission &&
|
|
468
|
+
d.shape.kind === ShapeKind.Rectangle
|
|
469
|
+
? d.shape.widthM
|
|
470
|
+
: "sizeM" in d
|
|
471
|
+
? d.sizeM.width
|
|
472
|
+
: 0;
|
|
473
|
+
const h = d.kind === DecorationKind.Circle
|
|
474
|
+
? d.radiusM * 2
|
|
475
|
+
: d.kind === AreaKind.GeneralAdmission &&
|
|
476
|
+
d.shape.kind === ShapeKind.Rectangle
|
|
477
|
+
? d.shape.heightM
|
|
478
|
+
: "sizeM" in d
|
|
479
|
+
? d.sizeM.height
|
|
480
|
+
: 0;
|
|
481
|
+
points = [
|
|
482
|
+
{ x: -w / 2, y: -h / 2 },
|
|
483
|
+
{ x: w / 2, y: -h / 2 },
|
|
484
|
+
{ x: w / 2, y: h / 2 },
|
|
485
|
+
{ x: -w / 2, y: h / 2 },
|
|
486
|
+
];
|
|
487
|
+
}
|
|
488
|
+
if (points.some((p) => !within(project(matrix, p))))
|
|
489
|
+
errors.push(issue(IssueCode.WorldBounds, "Derived object geometry exceeds its safety bounds.", [d.id]));
|
|
490
|
+
}
|
|
491
|
+
return errors;
|
|
492
|
+
}
|
|
493
|
+
export function parsePhysicalDocument(input) {
|
|
494
|
+
let raw = input;
|
|
495
|
+
try {
|
|
496
|
+
if (typeof raw !== "string" &&
|
|
497
|
+
new TextEncoder().encode(JSON.stringify(raw)).byteLength >
|
|
498
|
+
DocumentLimits.JsonBytes)
|
|
499
|
+
return {
|
|
500
|
+
status: DocumentParseStatus.Rejected,
|
|
501
|
+
issues: [issue(IssueCode.Limit, "Document exceeds 64MiB.", [])],
|
|
502
|
+
};
|
|
503
|
+
if (typeof raw === "string") {
|
|
504
|
+
if (new TextEncoder().encode(raw).byteLength > DocumentLimits.JsonBytes)
|
|
505
|
+
return {
|
|
506
|
+
status: DocumentParseStatus.Rejected,
|
|
507
|
+
issues: [issue(IssueCode.Limit, "Document exceeds 64MiB.", [])],
|
|
508
|
+
};
|
|
509
|
+
raw = JSON.parse(raw);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
catch {
|
|
513
|
+
return {
|
|
514
|
+
status: DocumentParseStatus.Rejected,
|
|
515
|
+
issues: [
|
|
516
|
+
issue(IssueCode.InvalidJson, "Document is not readable JSON.", []),
|
|
517
|
+
],
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
const result = documentSchema.safeParse(raw);
|
|
521
|
+
if (!result.success)
|
|
522
|
+
return {
|
|
523
|
+
status: DocumentParseStatus.Rejected,
|
|
524
|
+
issues: result.error.issues
|
|
525
|
+
.slice(0, 50)
|
|
526
|
+
.map((e) => issue(e.path[0] === "schemaVersion"
|
|
527
|
+
? IssueCode.UnsupportedVersion
|
|
528
|
+
: IssueCode.InvalidStructure, e.message, [], e.path.map(String).join("."))),
|
|
529
|
+
};
|
|
530
|
+
const document = result.data;
|
|
531
|
+
const errors = structuralIssues(document);
|
|
532
|
+
return errors.length
|
|
533
|
+
? { status: DocumentParseStatus.Rejected, issues: errors }
|
|
534
|
+
: { status: DocumentParseStatus.Accepted, document };
|
|
535
|
+
}
|
|
536
|
+
/** Prepared entity schemas have already passed. Recheck global references and only changed world geometry. */
|
|
537
|
+
export function validatePreparedDocument(document, changedGroups) {
|
|
538
|
+
const { seatingGroups, ...metadata } = document;
|
|
539
|
+
const result = documentSchema
|
|
540
|
+
.omit({ seatingGroups: true })
|
|
541
|
+
.safeParse(metadata);
|
|
542
|
+
if (!result.success)
|
|
543
|
+
return result.error.issues
|
|
544
|
+
.slice(0, 50)
|
|
545
|
+
.map((error) => issue(IssueCode.InvalidStructure, error.message, [], error.path.map(String).join(".")));
|
|
546
|
+
if (seatingGroups.length > DocumentLimits.PhysicalSeats)
|
|
547
|
+
return [
|
|
548
|
+
issue(IssueCode.Limit, "Too many seating owners.", [document.mapId]),
|
|
549
|
+
];
|
|
550
|
+
return structuralIssues(document, changedGroups);
|
|
551
|
+
}
|
|
552
|
+
export function serializePhysicalDocument(document) {
|
|
553
|
+
return JSON.stringify(document, (_, value) => {
|
|
554
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
555
|
+
return value;
|
|
556
|
+
const entries = Object.entries(value);
|
|
557
|
+
entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
558
|
+
return Object.fromEntries(entries);
|
|
559
|
+
});
|
|
560
|
+
}
|