zerobucket 0.4.0 → 0.5.0

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 CHANGED
@@ -10,8 +10,9 @@ This is the Node.js/TypeScript sibling of the [Python package](https://pypi.org/
10
10
  **It uses the exact same table**, so a Node service and a Python service can share one database
11
11
  and read each other's images.
12
12
 
13
- > **Status: early (0.4.x).** PostgreSQL **and SQLite**, each in classic and dedup modes, with S3-compatible
14
- > object-storage tiering. MySQL, a CLI and HEIC are on the roadmap (see [What's not here yet](#whats-not-here-yet)).
13
+ > **Status: early (0.5.x).** PostgreSQL **and SQLite**, each in classic and dedup modes, with S3-compatible
14
+ > object-storage tiering and a `zerobucket` command line tool. MySQL and HEIC are on the roadmap
15
+ > (see [What's not here yet](#whats-not-here-yet)).
15
16
 
16
17
  ## Install
17
18
 
@@ -176,6 +177,37 @@ await images.put(pdfBuf, { validator: new PDFValidator() }); // any ContentValid
176
177
  Optimize strips metadata, applies EXIF orientation first, never upscales, and re-validates its own
177
178
  output. Implement `ContentValidator` (`validate(data, { maxBytes })`) to store other content types.
178
179
 
180
+ ## Command line
181
+
182
+ The package installs a `zerobucket` command (`npx zerobucket ...`, or install globally with `npm i -g zerobucket`).
183
+ It has the same commands, flags, messages and exit codes as the Python package's CLI, and additionally works with
184
+ **SQLite** and **dedup mode**, and understands images that were tiered to object storage.
185
+
186
+ ```bash
187
+ export ZEROBUCKET_DATABASE_URL=postgresql://user:pass@localhost/mydb # or: --database-url URL
188
+ # SQLite instead: export ZEROBUCKET_SQLITE_PATH=./images.db # or: --sqlite PATH
189
+
190
+ zerobucket init # create the schema (add --dedup for the dedup tables)
191
+ zerobucket info # image count, sizes, on-disk size, breakdown by format (+ dedup savings / tiered count)
192
+ zerobucket verify # re-checksum every image; exit 1 and list the ids if anything is corrupted
193
+ zerobucket verify --sample 200 # ...or just a random sample (good for a nightly cron job)
194
+ zerobucket tier IMAGE_ID --bucket my-images # move one image to S3
195
+ zerobucket tier --older-than 90 --min-size 500000 --bucket my-images --dry-run # preview a bulk move
196
+ zerobucket tier --all --limit 1000 --bucket my-images --endpoint-url https://<acct>.r2.cloudflarestorage.com
197
+ zerobucket migrate --to-dedup # PostgreSQL: copy classic images into the dedup tables (non-destructive, re-runnable)
198
+ ```
199
+
200
+ - **Exit codes:** `0` success, `1` problems found or an operation failed, `2` usage or connection error. That makes
201
+ `zerobucket verify && deploy` and cron/CI checks work as you would hope.
202
+ - `info` and `verify` never create anything: looking at a database that does not exist (or has no schema yet) reports it
203
+ and exits 1 instead of silently creating an empty one.
204
+ - `verify` checksums one image at a time (memory stays flat on big tables). Images tiered to object storage are
205
+ skipped with a note unless you also pass `--bucket` (and credentials), in which case they are downloaded and verified too.
206
+ - `tier` processes images one at a time and reports each failure; a failed upload leaves that image untouched in the database.
207
+ Credentials come from the AWS SDK's standard chain, or `--aws-access-key-id` / `--aws-secret-access-key`.
208
+ - `tier` is not available with `--dedup`. `tier`, and `verify --bucket`, need `@aws-sdk/client-s3`; every other command works without it.
209
+ - The same operations are available from code: `new ZeroBucket({...}).tierToObjectStorage(id)`, `migrateClassicToDedup()`, etc.
210
+
179
211
  ## Reliability and observability
180
212
 
181
213
  - Pooling: `poolMinSize` (1), `poolMaxSize` (5), `poolTimeoutMs` (10000), or pass your own `pool`
@@ -301,27 +333,28 @@ same corpus of valid and corrupt files identically.
301
333
 
302
334
  ## Differences from the Python package
303
335
 
304
- | | Python | npm |
305
- | ---------------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
306
- | API | sync + async clients | one async client |
307
- | Malformed id (`"abc"`) | `StorageError` from Postgres | treated as not found (`ImageNotFoundError`, no DB round trip), friendlier for `/images/:id` routes |
308
- | `optimize` | Pillow; EXIF stripped, not applied | sharp; EXIF **applied then stripped**; transparency → **white** for JPEG |
309
- | `putMany` inserts | pipelined | one transaction, statements run sequentially |
310
- | Formats | JPEG, PNG, WebP, HEIC (extra) | JPEG, PNG, WebP (HEIC not yet) |
311
- | Event duration | `duration_seconds` | `durationMs` |
312
- | `migrateClassicToDedup` | loads the whole table into memory; fails if re-run or if any row is tiered | batched, safe to re-run, refuses tiered rows with a clear message |
313
- | Dedup `putMany` / `deleteMany` locking | arbitrary order (overlapping batches can deadlock) | sorted checksum order (cannot deadlock) |
314
- | SQLite API | synchronous `SQLiteBackend` + separate async backend | one async client; the sync driver runs on the event loop, lock waits are async (never block it) |
315
- | SQLite `onOperation` / busy retry | none | `onOperation` events and async `SQLITE_BUSY` retry (`busyTimeoutMs`) |
316
- | SQLite stream deleted mid-read | sync adapter keeps reading a WAL snapshot (async adapter raises) | raises `StorageError`, like Postgres; use `connection` in a transaction for a snapshot |
317
- | `connection=` without an open transaction | multi-statement ops rely on the driver's implicit transaction | always atomic (own transaction or savepoint) |
318
- | `delete(id, connection=...)` on a tiered image | deletes the S3 object immediately | leaves the object until you delete it after commit (a rolled-back transaction can never lose data) |
319
- | S3 delete failure after `delete()` | raises after the row is gone | never fails the delete; reported via `onOperation` |
320
- | Options | snake_case kwargs | camelCase options object |
336
+ | | Python | npm |
337
+ | ---------------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
338
+ | API | sync + async clients | one async client |
339
+ | Malformed id (`"abc"`) | `StorageError` from Postgres | treated as not found (`ImageNotFoundError`, no DB round trip), friendlier for `/images/:id` routes |
340
+ | `optimize` | Pillow; EXIF stripped, not applied | sharp; EXIF **applied then stripped**; transparency → **white** for JPEG |
341
+ | `putMany` inserts | pipelined | one transaction, statements run sequentially |
342
+ | Formats | JPEG, PNG, WebP, HEIC (extra) | JPEG, PNG, WebP (HEIC not yet) |
343
+ | Event duration | `duration_seconds` | `durationMs` |
344
+ | `migrateClassicToDedup` | loads the whole table into memory; fails if re-run or if any row is tiered | batched, safe to re-run, refuses tiered rows with a clear message |
345
+ | Dedup `putMany` / `deleteMany` locking | arbitrary order (overlapping batches can deadlock) | sorted checksum order (cannot deadlock) |
346
+ | SQLite API | synchronous `SQLiteBackend` + separate async backend | one async client; the sync driver runs on the event loop, lock waits are async (never block it) |
347
+ | SQLite `onOperation` / busy retry | none | `onOperation` events and async `SQLITE_BUSY` retry (`busyTimeoutMs`) |
348
+ | SQLite stream deleted mid-read | sync adapter keeps reading a WAL snapshot (async adapter raises) | raises `StorageError`, like Postgres; use `connection` in a transaction for a snapshot |
349
+ | CLI | PostgreSQL, classic mode only; `verify` crashes on tiered rows | PostgreSQL **and** SQLite, classic **and** dedup; `info`/`verify` understand tiered rows; `migrate --to-dedup` |
350
+ | `connection=` without an open transaction | multi-statement ops rely on the driver's implicit transaction | always atomic (own transaction or savepoint) |
351
+ | `delete(id, connection=...)` on a tiered image | deletes the S3 object immediately | leaves the object until you delete it after commit (a rolled-back transaction can never lose data) |
352
+ | S3 delete failure after `delete()` | raises after the row is gone | never fails the delete; reported via `onOperation` |
353
+ | Options | snake_case kwargs | camelCase options object |
321
354
 
322
355
  ## What's not here yet
323
356
 
324
- Planned, in order: **MySQL/MariaDB**, the `zerobucket` **CLI**, and **HEIC**.
357
+ Planned, in order: **MySQL/MariaDB** and **HEIC**.
325
358
  Tiering and dedup cannot be combined (same rule as the Python package).
326
359
 
327
360
  ## Runtime notes