Skip to content

Configuration ​

Every option has a working default except the connection.

js
createShorty({
  connection: mongoose,
  resolveUser,
});

Database ​

OptionDefault
connectionthe global mongooseMongoose instance or connection
modelNameLinkSet this when a collision is plausible — see below
collectionderived from modelNameExplicit collection name
userRefUserThe model your stored user ids point at
model—A compiled model, bypassing the factory entirely

Why modelName matters ​

Mongoose keeps compiled models in a registry on the connection, and claiming a name twice throws OverwriteModelError. A library cannot own a global name unconditionally, so shorty reuses an already-compiled model when the name is taken.

The tradeoff is the whole reason this option exists: if that existing model isn't ours, queries fail confusingly rather than loudly. If your app already has a model called Link, set modelName and stop thinking about it.

Limits ​

OptionDefault
listLimit200Hard cap on public list reads
adminListLimit500Hard cap on admin list reads

These are caps, not defaults you can exceed. A caller asking for more gets the cap, and the response reports the limit actually applied. An unbounded read against a collection whose size your customers control is an outage.

Adapters ​

OptionDefault
resolveUserreads req.authUserId / req.userUser adapter, shorthand form
userAdapter—Same, object form. Passing both throws.
loggerno-op{ debug, info, warn, error } — all optional
trackno-opOptional analytics seam

track is an optional peer, not a dependency ​

If you run our telemetry package, wire it in:

js
createShorty({ track: telemetry.track });

If you don't, leave it out and nothing is recorded. Installing this package must never drag in an analytics engine and a second Mongo collection — that is the rule for every cross-package seam here.

Released under the MIT License.