README
Uttori Storage Provider - JSON File
Uttori storage provider using JSON files on disk.
Install
npm install --save uttori-storage-provider-json-file
Config
{
content_dir: '',
history_dir: '',
extension: 'json',
spaces_document: null,
spaces_history: null,
}
API Reference
StorageProvider
Storage for Uttori documents using JSON files stored on the local file system.
Kind: global class
Properties
Name | Type | Description |
---|---|---|
config | Object |
The configuration object. |
documents | Array.<UttoriDocument> |
The collection of documents. |
- StorageProvider
- new StorageProvider(config)
- .all() ⇒
Promise
- .tags() ⇒
Promise
- .getQuery(query) ⇒
Promise
- .get(slug) ⇒
Promise
- .getHistory(slug) ⇒
Promise
- .getRevision(slug, revision) ⇒
Promise
- .add(document)
- .updateValid(document, originalSlug) ℗
- .update(document, originalSlug)
- .delete(slug)
- .refresh()
- .updateHistory(slug, content, originalSlug)
new StorageProvider(config)
Creates an instance of StorageProvider.
Param | Type | Default | Description |
---|---|---|---|
config | Object |
A configuration object. | |
config.content_dir | string |
The directory to store documents. | |
config.history_dir | string |
The directory to store document histories. | |
[config.extension] | string |
"json" |
The file extension to use for file, name of the employee. |
[config.spaces_document] | number |
|
The spaces parameter for JSON stringifying documents. |
[config.spaces_history] | number |
|
The spaces parameter for JSON stringifying history. |
Example (Init StorageProvider)
const storageProvider = new StorageProvider({ content_dir: 'content', history_dir: 'history', spaces_document: 2 });
Promise
storageProvider.all() ⇒ Returns all documents.
Kind: instance method of StorageProvider
Returns: Promise
- Promise object represents all documents.
Example
storageProvider.all();
➜ [{ slug: 'first-document', ... }, ...]
Promise
storageProvider.tags() ⇒ Returns all unique tags.
Kind: instance method of StorageProvider
Returns: Promise
- Promise object represents all documents.
Example
storageProvider.tags();
➜ ['first-tag', ...]
Promise
storageProvider.getQuery(query) ⇒ Returns all documents matching a given query.
Kind: instance method of StorageProvider
Returns: Promise
- Promise object represents all matching documents.
Param | Type | Description |
---|---|---|
query | string |
The conditions on which documents should be returned. |
Promise
storageProvider.get(slug) ⇒ Returns a document for a given slug.
Kind: instance method of StorageProvider
Returns: Promise
- Promise object represents the returned UttoriDocument.
Param | Type | Description |
---|---|---|
slug | string |
The slug of the document to be returned. |
Promise
storageProvider.getHistory(slug) ⇒ Returns the history of edits for a given slug.
Kind: instance method of StorageProvider
Returns: Promise
- Promise object represents the returned history.
Param | Type | Description |
---|---|---|
slug | string |
The slug of the document to get history for. |
Promise
storageProvider.getRevision(slug, revision) ⇒ Returns a specifc revision from the history of edits for a given slug and revision timestamp.
Kind: instance method of StorageProvider
Returns: Promise
- Promise object represents the returned revision of the document.
Param | Type | Description |
---|---|---|
slug | string |
The slug of the document to be returned. |
revision | number |
The unix timestamp of the history to be returned. |
storageProvider.add(document)
Saves a document to the file system.
Kind: instance method of StorageProvider
Param | Type | Description |
---|---|---|
document | UttoriDocument |
The document to be added to the collection. |
storageProvider.updateValid(document, originalSlug) ℗
Updates a document and saves to the file system.
Kind: instance method of StorageProvider
Access: private
Param | Type | Description |
---|---|---|
document | UttoriDocument |
The document to be updated in the collection. |
originalSlug | string |
The original slug identifying the document, or the slug if it has not changed. |
storageProvider.update(document, originalSlug)
Updates a document and figures out how to save to the file system.
Kind: instance method of StorageProvider
Param | Type | Description |
---|---|---|
document | UttoriDocument |
The document to be updated in the collection. |
originalSlug | string |
The original slug identifying the document, or the slug if it has not changed. |
storageProvider.delete(slug)
Removes a document from the file system.
Kind: instance method of StorageProvider
Param | Type | Description |
---|---|---|
slug | string |
The slug identifying the document. |
storageProvider.refresh()
Reloads all documents from the file system into the cache.
Kind: instance method of StorageProvider
storageProvider.updateHistory(slug, content, originalSlug)
Updates History for a given slug, renaming the store file and history folder as needed.
Kind: instance method of StorageProvider
Param | Type | Description |
---|---|---|
slug | string |
The slug of the document to update history for. |
content | string |
The revision of the document to be saved. |
originalSlug | string |
The original slug identifying the document, or the slug if it has not changed. |
Tests
To run the test suite, first install the dependencies, then run npm test
:
npm install
npm test
DEBUG=Uttori* npm test