@mentra/cloud-protocol 3.2.0-dev.235 → 3.2.0-dev.247
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/package.json +1 -1
- package/src/camera.ts +2 -68
- package/src/photo-compression.ts +11 -0
package/package.json
CHANGED
package/src/camera.ts
CHANGED
|
@@ -9,77 +9,11 @@
|
|
|
9
9
|
* Mirrors docs/issues/002-cloud-runtime/camera/spec.md.
|
|
10
10
|
*/
|
|
11
11
|
import { z } from "zod";
|
|
12
|
+
export type { PhotoCompression } from "./photo-compression";
|
|
12
13
|
|
|
13
14
|
// --- Managed photo ----------------------------------------------------------
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
export const photoSizeCanonicalSchema = z.enum(["low", "medium", "high", "max"]);
|
|
17
|
-
export type PhotoSizeTier = z.infer<typeof photoSizeCanonicalSchema>;
|
|
18
|
-
|
|
19
|
-
/** Accepted on the wire: canonical names plus legacy cloud aliases. */
|
|
20
|
-
const photoSizeInputSchema = z.enum([
|
|
21
|
-
"low",
|
|
22
|
-
"medium",
|
|
23
|
-
"high",
|
|
24
|
-
"max",
|
|
25
|
-
"small",
|
|
26
|
-
"large",
|
|
27
|
-
"full",
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Normalize a photo size string to the device-canonical tier.
|
|
32
|
-
* Legacy aliases: small→low, large→high, full→max.
|
|
33
|
-
*/
|
|
34
|
-
export function normalizePhotoSizeTier(value: string): PhotoSizeTier {
|
|
35
|
-
switch (value) {
|
|
36
|
-
case "small":
|
|
37
|
-
return "low";
|
|
38
|
-
case "large":
|
|
39
|
-
return "high";
|
|
40
|
-
case "full":
|
|
41
|
-
return "max";
|
|
42
|
-
case "low":
|
|
43
|
-
case "medium":
|
|
44
|
-
case "high":
|
|
45
|
-
case "max":
|
|
46
|
-
return value;
|
|
47
|
-
default:
|
|
48
|
-
throw new Error(`invalid photo size: ${value}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const photoCompressInputSchema = z.enum(["none", "low", "medium", "high", "heavy"]);
|
|
53
|
-
|
|
54
|
-
/** Normalize compression aliases to the cloud wire enum. */
|
|
55
|
-
export function normalizePhotoCompress(
|
|
56
|
-
value: string,
|
|
57
|
-
): "none" | "medium" | "heavy" {
|
|
58
|
-
switch (value) {
|
|
59
|
-
case "low":
|
|
60
|
-
case "medium":
|
|
61
|
-
return "medium";
|
|
62
|
-
case "high":
|
|
63
|
-
case "heavy":
|
|
64
|
-
return "heavy";
|
|
65
|
-
case "none":
|
|
66
|
-
return "none";
|
|
67
|
-
default:
|
|
68
|
-
throw new Error(`invalid photo compress: ${value}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const photoOptionsSchema = z.object({
|
|
73
|
-
size: photoSizeInputSchema
|
|
74
|
-
.optional()
|
|
75
|
-
.transform((value) => (value === undefined ? undefined : normalizePhotoSizeTier(value))),
|
|
76
|
-
compress: photoCompressInputSchema
|
|
77
|
-
.optional()
|
|
78
|
-
.transform((value) => (value === undefined ? undefined : normalizePhotoCompress(value))),
|
|
79
|
-
saveToGallery: z.boolean().optional(),
|
|
80
|
-
sound: z.boolean().optional(),
|
|
81
|
-
});
|
|
82
|
-
export type PhotoOptions = z.infer<typeof photoOptionsSchema>;
|
|
16
|
+
// Photo allocation has no request body. Capture options belong to the device.
|
|
83
17
|
|
|
84
18
|
/**
|
|
85
19
|
* The REST response to a photo request. The capture happens out of band (the
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Photo compression is identical on the wire and in every SDK; omitted means none. */
|
|
2
|
+
export const photoCompressionValues = ["none", "low", "medium", "high"] as const;
|
|
3
|
+
export type PhotoCompression = (typeof photoCompressionValues)[number];
|
|
4
|
+
|
|
5
|
+
/** Validate without coercing aliases, casing, null, or unknown values. */
|
|
6
|
+
export function parsePhotoCompression(value: unknown = "none"): PhotoCompression {
|
|
7
|
+
if (typeof value === "string" && photoCompressionValues.includes(value as PhotoCompression)) {
|
|
8
|
+
return value as PhotoCompression;
|
|
9
|
+
}
|
|
10
|
+
throw new TypeError(`Invalid photo compression ${JSON.stringify(value)}. Expected none, low, medium, or high.`);
|
|
11
|
+
}
|