Reference
Generated from the JSDoc in src/, so it matches the code. For how the pieces fit together, see How it works & Configuration.
- Plugin: register it with Eleventy, or build a store directly.
- Store functions: read, write, & list blobs.
- Utilities: the date formatter & the duration parser.
- Options: every option, its type, & its default.
Plugin
netlifyDataStorePlugin(eleventyConfig, pluginOptions?)
Eleventy plugin. Hangs a configured data store on eleventyConfig &
returns it, & registers a date filter for meta.generatedAt.
The plugin never reads Eleventy's data directory: content comes from Netlify Blobs, cached locally between builds.
Parameters
| Name | Type |
|---|---|
eleventyConfig
|
object |
pluginOptions
(optional)
|
DataStoreOptions |
Returns
ReturnType<typeof createDataStore>
createDataStore(options?)
Creates a read/write API bound to one set of options. Use this directly
from a _data/*.js file or a Netlify Function; the Eleventy plugin below
is a thin wrapper around it.
Parameters
| Name | Type |
|---|---|
options
(optional)
|
DataStoreOptions |
Store functions
Returned by createDataStore() & by addPlugin, bound to the options passed at registration.
readBlob(name, storeName?)
Reads a {meta, ...content} envelope by name.
The local cache answers first while the entry is inside its TTL;
otherwise the Netlify Blobs store does, & the result is cached for the
next build. When the store cannot be reached & a stale entry exists,
it is served with meta.stale set unless staleIfError is disabled.
Every failure resolves to an envelope carrying meta.error rather than
throwing, so a template renders a fallback instead of failing the build.
Parameters
| Name | Type |
|---|---|
name
|
string |
storeName
(optional)
|
string |
Returns
Promise<object>
writeBlob(name, data, storeName?)
Writes a {meta, ...content} envelope to the Netlify Blobs store &
refreshes the local cache so a following read sees it immediately.
Like reads, writes never throw: the response shape carries the outcome.
Parameters
| Name | Type |
|---|---|
name
|
string |
data
|
object |
storeName
(optional)
|
string |
Returns
Promise<{statusCode: number, body: string}>
listData(storeName?)
Lists the blob keys held in a store. Always returns an array: failures log & resolve to an empty list.
Parameters
| Name | Type |
|---|---|
storeName
(optional)
|
string |
Returns
Promise<string[]>
Utilities
Exported from the package root. The plugin registers a bound formatGeneratedAt as a filter, which takes only the value.
formatGeneratedAt(value, options?)
Formats an envelope's meta.generatedAt timestamp for display.
Returns an empty string for missing or unparseable input so a template
can render it unconditionally.
Parameters
| Name | Type |
|---|---|
value
|
string|number|Date |
options
(optional)
|
{locale?: string, dateFormat?: Intl.DateTimeFormatOptions} |
Returns
string
parseDuration(value)
Parses an eleventy-fetch-style duration into milliseconds.
"*" never expires; 0 always does.
Parameters
| Name | Type |
|---|---|
value
|
string|number |
Returns
number
Options
Passed to addPlugin or createDataStore. Every option is optional.
| Option | Type | Default | Description |
|---|---|---|---|
storeName |
string |
"content" |
Default Netlify Blobs store. |
cacheDir |
string |
".netlify/blobs-cache" |
Local, uncommitted cache. |
ttl |
string|number |
"1h" |
How long a cache entry stays fresh; "*" never expires, 0 always refetches. |
staleIfError |
boolean |
true |
Serve an expired entry when the store cannot be reached. |
siteID |
string |
Defaults to process.env.NETLIFY_SITE_ID. |
|
token |
string |
Defaults to process.env.NETLIFY_TOKEN. |
|
quiet |
boolean |
false |
Suppress per-read logging. |
locale |
string |
"en-GB" |
Locale for formatGeneratedAt. |
dateFormat |
Intl.DateTimeFormatOptions |
Options for formatGeneratedAt. |
|
filterName |
string|false |
"generatedAt" |
Filter to register; false to skip. |
getStore |
Function |
Store factory; defaults to getStore from @netlify/blobs. A custom factory skips the credential check. |
|
logger |
object |
Eleventy's logger; supplied automatically by addPlugin. |