2.4.0 • Published 4 years ago

uttori-storage-provider-json-file v2.4.0

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

view on npm npm module downloads Build Status Dependency Status Coverage Status

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

NameTypeDescription
configObjectThe configuration object.
documentsArray.<UttoriDocument>The collection of documents.

new StorageProvider(config)

Creates an instance of StorageProvider.

ParamTypeDefaultDescription
configObjectA configuration object.
config.content_dirstringThe directory to store documents.
config.history_dirstringThe directory to store document histories.
config.extensionstring"json"The file extension to use for file, name of the employee.
config.spaces_documentnumberThe spaces parameter for JSON stringifying documents.
config.spaces_historynumberThe spaces parameter for JSON stringifying history.

Example (Init StorageProvider)

const storageProvider = new StorageProvider({ content_dir: 'content', history_dir: 'history', spaces_document: 2 });

storageProvider.all() ⇒ Promise

Returns all documents.

Kind: instance method of StorageProvider
Returns: Promise - Promise object represents all documents.
Example

storageProvider.all();
➜ [{ slug: 'first-document', ... }, ...]

storageProvider.tags() ⇒ Promise

Returns all unique tags.

Kind: instance method of StorageProvider
Returns: Promise - Promise object represents all documents.
Example

storageProvider.tags();
➜ ['first-tag', ...]

storageProvider.getQuery(query) ⇒ Promise

Returns all documents matching a given query.

Kind: instance method of StorageProvider
Returns: Promise - Promise object represents all matching documents.

ParamTypeDescription
querystringThe conditions on which documents should be returned.

storageProvider.get(slug) ⇒ Promise

Returns a document for a given slug.

Kind: instance method of StorageProvider
Returns: Promise - Promise object represents the returned UttoriDocument.

ParamTypeDescription
slugstringThe slug of the document to be returned.

storageProvider.getHistory(slug) ⇒ Promise

Returns the history of edits for a given slug.

Kind: instance method of StorageProvider
Returns: Promise - Promise object represents the returned history.

ParamTypeDescription
slugstringThe slug of the document to get history for.

storageProvider.getRevision(slug, revision) ⇒ Promise

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.

ParamTypeDescription
slugstringThe slug of the document to be returned.
revisionnumberThe unix timestamp of the history to be returned.

storageProvider.add(document)

Saves a document to the file system.

Kind: instance method of StorageProvider

ParamTypeDescription
documentUttoriDocumentThe 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

ParamTypeDescription
documentUttoriDocumentThe document to be updated in the collection.
originalSlugstringThe 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

ParamTypeDescription
documentUttoriDocumentThe document to be updated in the collection.
originalSlugstringThe 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

ParamTypeDescription
slugstringThe 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

ParamTypeDescription
slugstringThe slug of the document to update history for.
contentstringThe revision of the document to be saved.
originalSlugstringThe 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

Contributors

License

2.4.0

4 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.4.0

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago