From 0111ea28af7b9d41606578daa1f870f65ad46e5c Mon Sep 17 00:00:00 2001 From: talksik Date: Wed, 25 Mar 2026 13:13:46 -0700 Subject: [PATCH] refactor!: use consistent structure for particles Making the firestore subcollections the same name helps with creating indices and queries across subcollections of different depths. This also prevents the need for conditional logic for network root / top-level particles. --- js/src/lib/particle-path.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/js/src/lib/particle-path.ts b/js/src/lib/particle-path.ts index ba9412d..bcc2f58 100644 --- a/js/src/lib/particle-path.ts +++ b/js/src/lib/particle-path.ts @@ -35,13 +35,13 @@ export function parseParticlePath(path: ParticlePath): { * Convert a ParticlePath to the Firestore document path for that particle. * * Firestore structure: - * /net1 → networks/net1/particles (collection) - * /net1/p1 → networks/net1/particles/p1 (document) - * /net1/p1/p2 → networks/net1/particles/p1/children/p2 (document) + * /net1 → networks/net1/children (collection) + * /net1/p1 → networks/net1/children/p1 (document) + * /net1/p1/p2 → networks/net1/children/p1/children/p2 (document) */ export function toFirestoreDocPath(path: ParticlePath): string { const { networkId, segments } = parseParticlePath(path); - const base = `networks/${networkId}/particles`; + const base = `networks/${networkId}/children`; if (segments.length === 0) return base; const parts: string[] = [base, segments[0]]; @@ -54,9 +54,9 @@ export function toFirestoreDocPath(path: ParticlePath): string { /** * Convert a ParticlePath to the Firestore collection path for its children. * - * /net1 → networks/net1/particles (root particles) - * /net1/p1 → networks/net1/particles/p1/children - * /net1/p1/p2 → networks/net1/particles/p1/children/p2/children + * /net1 → networks/net1/children (root particles) + * /net1/p1 → networks/net1/children/p1/children + * /net1/p1/p2 → networks/net1/children/p1/children/p2/children */ export function toFirestoreChildrenPath(path: ParticlePath): string { const { segments } = parseParticlePath(path);