stable
csv
RFC 4180 CSV export of a single collection, with a symmetric reader for round-trip import.
@noy-db/as-csv·pnpm add @noy-db/as-csvDecrypts records from one collection and formats them as RFC 4180 CSV.
What it does
as-csv is the reference implementation of the plaintext-tier
shape — every other record formatter in the family (as-json, as-xml,
as-sql, …) follows the same entry-point + authorization-gate structure.
Strings containing ,, ", \r, or \n are quoted; embedded quotes are
doubled. null/undefined become empty fields, Date renders as ISO
8601, and objects/arrays are JSON.stringify'd. A symmetric
decoder parses a CSV back into an import plan.
Usage
import { asCsv } from '@noy-db/as-csv'
const csv = await vault.export(asCsv(), { collections: ['invoices'] })
// id,client,amount,status
// inv-1,Globex,1500,paid
// inv-2,"Acme, Inc.",2400,draft
import { asCsv } from '@noy-db/as-csv'
const plan = await vault.import(asCsv(), csv, { collection: 'invoices' })
// → ImportPlan { plan: VaultDiff, policy: 'merge', apply() }
await plan.apply()
Every call checks vault.assertCanExport('plaintext', 'csv') before
decrypting anything — see the family gate.
See also
- as-* family
- json — structured, schema-aware alternative
- xlsx — multi-sheet spreadsheet with dictionary labels