Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Dup

Manav Rathi61d35159fa2d
diff --git a/web/packages/new/photos/services/embedding.ts b/web/packages/new/photos/services/embedding.ts
index 977d396e20..ef01b81b35 100644
--- a/web/packages/new/photos/services/embedding.ts
+++ b/web/packages/new/photos/services/embedding.ts
@@ -175,9 +175,74 @@ const faceEmbeddingSyncTime = () =>
const saveFaceEmbeddingSyncTime = (t: number) =>
localStorage.setItem("faceEmbeddingSyncTime", `${t}`);
-// const getFaceEmbeddings = async () => {
-
-// }
+/**
+ * Zod schemas for the {@link FaceIndex} types.
+ *
+ * [Note: Duplicated between Zod schemas and TS type]
+ *
+ * Usually we define a Zod schema, and then infer the corresponding TypeScript
+ * type for it using `z.infer`. This works great except now the docstrings don't
+ * show up: The doc strings get added to the Zod schema, but usually the code
+ * using the parsed data will reference the TypeScript type, and the docstrings
+ * added to the fields in the Zod schema won't show up.
+ *
+ * We usually live with this infelicity, since the alternative is code
+ * duplication: Define the TypeScript type (putting the docstrings therein)
+ * _and_ also a corresponding Zod schema. The duplication happens because it is
+ * not possible to go the other way (TS type => Zod schema).
+ *
+ * However, in some cases having when the TypeScript type under consideration is
+ * used pervasely in our code, having a standalone TypeScript type with attached
+ * docstrings, is worth the code duplication.
+ *
+ * Note that this'll just be syntactic duplication - if the two definitions get
+ * out of sync in the shape of the types they represent, the TypeScript compiler
+ * will flag it for us.
+ */
+const FaceIndex = z
+ .object({
+ fileID: z.number(),
+ width: z.number(),
+ height: z.number(),
+ faceEmbedding: z
+ .object({
+ version: z.number(),
+ client: z.string(),
+ faces: z.array(
+ z
+ .object({
+ faceID: z.string(),
+ detection: z
+ .object({
+ box: z
+ .object({
+ x: z.number(),
+ y: z.number(),
+ width: z.number(),
+ height: z.number(),
+ })
+ .passthrough(),
+ landmarks: z.array(
+ z
+ .object({
+ x: z.number(),
+ y: z.number(),
+ })
+ .passthrough(),
+ ),
+ })
+ .passthrough(),
+ score: z.number(),
+ blur: z.number(),
+ embedding: z.array(z.number()),
+ })
+ .passthrough(),
+ ),
+ })
+ .passthrough(),
+ })
+ // Retain fields we might not (currently) understand.
+ .passthrough();
/**
* The maximum number of items to fetch in a single GET /embeddings/diff