diff --git a/js/src/api/types.ts b/js/src/api/types.ts index 629e144..1583c24 100644 --- a/js/src/api/types.ts +++ b/js/src/api/types.ts @@ -127,7 +127,10 @@ const ParticleBaseSchema = z.object({ id: z.string(), created_at: z.coerce.date(), created_by_email: z.string().email(), - updated_at: z.coerce.date().optional() + updated_at: z.coerce.date().optional(), + // e.g. ["human:aron@acme.com", "human:john@acme.com"] - visible only to Aron and John + // e.g. ["network:123"] - visible to everyone in the network + visible_to: z.array(z.string()) }); export const ParticleSchema = z.discriminatedUnion("type", [ diff --git a/js/src/hooks/use-create-particle.ts b/js/src/hooks/use-create-particle.ts index f86a915..d6df5b0 100644 --- a/js/src/hooks/use-create-particle.ts +++ b/js/src/hooks/use-create-particle.ts @@ -7,6 +7,7 @@ interface CreateParticleParams { type: T; properties: ParticlePropertiesMap[T]; createdByEmail: string; + visibleTo: string[]; } export function useCreateParticle() { @@ -17,6 +18,7 @@ export function useCreateParticle() { params.type, params.properties, params.createdByEmail, + params.visibleTo, ), }); } diff --git a/js/src/lib/firestore-particles.ts b/js/src/lib/firestore-particles.ts index ccb298a..961860b 100644 --- a/js/src/lib/firestore-particles.ts +++ b/js/src/lib/firestore-particles.ts @@ -41,6 +41,7 @@ const particleConverter: FirestoreDataConverter = { created_at: (raw.created_at as Timestamp).toDate(), created_by_email: raw.created_by_email, updated_at: raw.updated_at ? (raw.updated_at as Timestamp).toDate() : undefined, + visible_to: raw.visible_to, }); }, }; @@ -91,6 +92,7 @@ export async function createParticle( type: T, properties: ParticlePropertiesMap[T], createdByEmail: string, + visibleTo: string[], ): Promise { const particle: Particle = ParticleSchema.parse({ id: "", // ignored by toFirestore, but needed to satisfy the type @@ -99,6 +101,7 @@ export async function createParticle( created_at: new Date(), created_by_email: createdByEmail, updated_at: null, + visible_to: visibleTo, }); const ref = await addDoc(typedCollection(collectionPath), particle); return ref.id; @@ -108,6 +111,7 @@ export async function createParticle( export async function updateParticle( docPath: string, properties: Partial, + visibleTo?: string[], ): Promise { const particleRef = typedDoc(docPath); // Take the partial and create a new object with dot notation @@ -119,5 +123,6 @@ export async function updateParticle( await updateDoc(particleRef, { ...updatedProperties, updated_at: serverTimestamp(), + ...(visibleTo ? { visible_to: visibleTo } : {}), }); }