@cross-deck/buckets 0.2.0 → 0.2.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/README.md +35 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,6 +80,39 @@ haven't named yet. Buckets counted them at the database driver, not in your code
|
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
83
|
+
## Server *and* browser — install where you read
|
|
84
|
+
|
|
85
|
+
A collector counts reads **where it runs.** With Firestore, your app often reads
|
|
86
|
+
from **two** places: your **server** (the snippet above) and your users'
|
|
87
|
+
**browsers** — live `onSnapshot` listeners and direct `getDocs`/`getDoc` calls
|
|
88
|
+
that bill straight to your project and *never touch your server*. A server-only
|
|
89
|
+
collector can't see those, the same way `@cross-deck/node` can't see a browser
|
|
90
|
+
event. So Buckets ships a collector for each surface.
|
|
91
|
+
|
|
92
|
+
**Browser** — swap one import and add one line:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { initBucketsWeb, bucket } from "@cross-deck/buckets/web";
|
|
96
|
+
// was: import { getDocs, onSnapshot } from "firebase/firestore"
|
|
97
|
+
import { getDocs, onSnapshot } from "@cross-deck/buckets/web";
|
|
98
|
+
|
|
99
|
+
initBucketsWeb({ apiKey: "cd_pk_…" }); // your PUBLISHABLE key — safe in client code
|
|
100
|
+
|
|
101
|
+
bucket("live-feed", () => onSnapshot(liveQuery, render)); // every fire counted
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Each listener fire is counted as the documents it delivers — exactly what Firebase
|
|
105
|
+
bills — labelled and reported up the **same pipe**, so your dashboard shows
|
|
106
|
+
**server and browser reads side by side.** Install one, or both. The promise is
|
|
107
|
+
precise: **Buckets captures every read that flows through a collector** — put one
|
|
108
|
+
on each surface you read from, and you see all of it.
|
|
109
|
+
|
|
110
|
+
> We learned this the hard way dogfooding on our own dashboard: 94% of our reads
|
|
111
|
+
> were browser-side and a server-only install was blind to them. The browser
|
|
112
|
+
> collector is the fix — and the reason "install where you read" is the whole model.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
83
116
|
## What you get
|
|
84
117
|
|
|
85
118
|
A small, cheap, daily document per app — the **rollup**. This is the entire output,
|
|
@@ -349,7 +382,8 @@ reconciles against your provider's invoice instead of drifting from it.
|
|
|
349
382
|
|
|
350
383
|
| Datastore | Status |
|
|
351
384
|
|---|---|
|
|
352
|
-
| **
|
|
385
|
+
| **Firestore — server** (`firebase-admin`) | ✅ Supported |
|
|
386
|
+
| **Firestore — browser** (`firebase` JS SDK) | ✅ Supported — `@cross-deck/buckets/web` |
|
|
353
387
|
| Postgres · DynamoDB · MongoDB | 🔜 Adapter interface is public — contributions welcome |
|
|
354
388
|
|
|
355
389
|
The trap *pattern* generalises to any driver with interceptable read methods, and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cross-deck/buckets",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Know exactly what every database read costs you — and who caused it. A tiny, never-throws read-cost collector for Firestore, server AND browser.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crossdeck",
|