Utilities
A few of the module's pure helpers can be imported by your app, so a status bar or a sidebar formats and groups things the same way the built-in components do.
import { formatBytes, formatUptime, isProtectedCollection } from '@sfxcode/nuxt-ui-mongocamp/utils'They are not auto-imported — an explicit import cannot clash with a function of the same name in your app. None of them needs Nuxt or Vue, and none sends a request, so they also work in server code and in tests.
Formatting
| Helper | Result |
|---|---|
formatBytes(bytes) | '1.5 KB', '12 MB'; '0 B' for zero, a negative number or anything that is not a number |
formatUptime(seconds) | The two biggest units: '3d 4h', '5h 12m', '42s'; '-' when unknown |
formatCount(value) | Thousands separated by a space, independent of the locale: '1 234 567'; '-' when unknown |
connectionUsage(current, available) | Share of connections in use, 0–100 (current against current + available); null when either is unknown |
const stats = await useMongocampSystem().getStats()
formatUptime(stats.uptimeSeconds)
connectionUsage(stats.connections?.current, stats.connections?.available)See useMongocampSystem for the exact shape of getStats().
Collection names
| Helper | Result |
|---|---|
isBucketMemberCollection(name) | true for <bucket>.files and <bucket>.chunks, the two halves of a GridFS bucket |
bucketNameOf(name) | 'images' for images.files / images.chunks; null for any other collection |
groupCollectionNames(names) | { collections, buckets, system } — ordinary collections, bucket names and mc_* collections, each sorted and without duplicates |
isProtectedCollection(name) | true for MongoCamp's own mc_* collections and for bucket halves — the collections the module never offers to clear, drop, copy or rename |
Splitting a collection list the way the playground's sidebar does:
import { groupCollectionNames } from '@sfxcode/nuxt-ui-mongocamp/utils'
const names = await useMongocampAdmin().listCollections()
const { collections, buckets, system } = groupCollectionNames(names)For a list that several components share, useMongocampCollectionNames loads it once and returns the same three groups.
Connection
| Helper | Result |
|---|---|
isNetworkFailure(error) | true when a request failed without any answer from the server — a network error, timeout or abort, from the generated MongoCamp client, $fetch/ofetch or plain fetch. An error carrying an HTTP status (401, 404, 500, ...) is an answer and always false |
The same test decides what useMongocampConnection().report(error) counts as lost connection — use it in an app's own data layer to tell "the server said no" from "there is no server right now".
Documents
| Helper | Result |
|---|---|
idOf(value) | A document id as text, as the server's relaxed Extended JSON returns it: the hex of { $oid }, the value of { $numberLong } / { $numberInt } / { $string }, a plain string or number as it is; undefined for anything else (an object or binary id) |
import { idOf } from '@sfxcode/nuxt-ui-mongocamp/utils'
const { rows } = await useMongocampFetchAll().fetchAllDocuments('orders')
const ids = rows.map(row => idOf(row._id))What is not exported
Only the helpers on this page are public API. The module has many more files under runtime/utils — they are internal and can change in any release, so do not import them by a deep path.