Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCallis committed Sep 3, 2019
1 parent b78b697 commit 08f0a74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 416 deletions.
214 changes: 6 additions & 208 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ npm install --save uttori-storage-provider-json-file
{
content_dir: '',
history_dir: '',
data_dir: '',
extension: 'json',
spaces_document: null,
spaces_data: null,
spaces_history: null,
}
```
Expand All @@ -50,29 +48,15 @@ Storage for Uttori documents using JSON files stored on the local file system.
* [new StorageProvider(config)](#new_StorageProvider_new)
* [.all()](#StorageProvider+all) ⇒ <code>Promise</code>
* [.tags()](#StorageProvider+tags) ⇒ <code>Promise</code>
* [.getTaggedDocuments(tag, [limit], fields)](#StorageProvider+getTaggedDocuments) ⇒ <code>Promise</code>
* [.getRelatedDocuments(document, limit, fields)](#StorageProvider+getRelatedDocuments) ⇒ <code>Promise</code>
* [.getRecentDocuments(limit, fields)](#StorageProvider+getRecentDocuments) ⇒ <code>Promise</code>
* [.getPopularDocuments(limit, fields)](#StorageProvider+getPopularDocuments) ⇒ <code>Promise</code>
* [.getRandomDocuments(limit, fields)](#StorageProvider+getRandomDocuments) ⇒ <code>Promise</code>
* [.augmentDocuments(documents, _fields)](#StorageProvider+augmentDocuments) ⇒ <code>Promise</code>
* [.getQuery(query)](#StorageProvider+getQuery) ⇒ <code>Promise</code>
* [.get(slug)](#StorageProvider+get) ⇒ <code>Promise</code>
* [.getHistory(slug)](#StorageProvider+getHistory) ⇒ <code>Promise</code>
* [.getRevision(slug, revision)](#StorageProvider+getRevision) ⇒ <code>Promise</code>
* [.add(document)](#StorageProvider+add)
* [.updateValid(document, originalSlug)](#StorageProvider+updateValid)
* [.update(document, originalSlug)](#StorageProvider+update)
* [.delete(slug)](#StorageProvider+delete)
* [.storeObject(name, data)](#StorageProvider+storeObject)
* [.updateObject(name, key, value)](#StorageProvider+updateObject)
* [.incrementObject(name, key, [amount])](#StorageProvider+incrementObject)
* [.decrementObject(name, key, [amount])](#StorageProvider+decrementObject)
* [.readObject(name, fallback)](#StorageProvider+readObject) ⇒ <code>Promise.&lt;Object&gt;</code>
* [.readObjectValue(name, key, fallback)](#StorageProvider+readObjectValue) ⇒ <code>Promise.&lt;Object&gt;</code>
* [.refresh()](#StorageProvider+refresh)
* [.deleteFile(folder, name)](#StorageProvider+deleteFile)
* [.readFile(folder, name)](#StorageProvider+readFile) ⇒ <code>Object</code>
* [.readFolder(folder)](#StorageProvider+readFolder) ⇒ <code>Array.&lt;string&gt;</code>
* [.updateHistory(slug, content, originalSlug)](#StorageProvider+updateHistory)

<a name="new_StorageProvider_new"></a>
Expand All @@ -86,16 +70,13 @@ Creates an instance of StorageProvider.
| config | <code>Object</code> | | A configuration object. |
| config.content_dir | <code>string</code> | | The directory to store documents. |
| config.history_dir | <code>string</code> | | The directory to store document histories. |
| config.data_dir | <code>string</code> | | The directory to store objects. |
| [config.extension] | <code>string</code> | <code>&quot;json&quot;</code> | The file extension to use for file, name of the employee. |
| [config.analytics_file] | <code>string</code> | <code>&quot;visits&quot;</code> | The name of the file to store page views. |
| [config.spaces_document] | <code>number</code> | <code></code> | The spaces parameter for JSON stringifying documents. |
| [config.spaces_data] | <code>number</code> | <code></code> | The spaces parameter for JSON stringifying data. |
| [config.spaces_history] | <code>number</code> | <code></code> | The spaces parameter for JSON stringifying history. |

**Example** *(Init StorageProvider)*
```js
const storageProvider = new StorageProvider({ content_dir: 'content', history_dir: 'history', data_dir: 'data', spaces_document: 2 });
const storageProvider = new StorageProvider({ content_dir: 'content', history_dir: 'history', spaces_document: 2 });
```
<a name="StorageProvider+all"></a>

Expand All @@ -121,85 +102,17 @@ Returns all unique tags.
storageProvider.tags();
➜ ['first-tag', ...]
```
<a name="StorageProvider+getTaggedDocuments"></a>
<a name="StorageProvider+getQuery"></a>

### storageProvider.getTaggedDocuments(tag, [limit], fields) ⇒ <code>Promise</code>
Returns all documents matching a given tag.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all matching documents.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| tag | <code>string</code> | | The tag to compare against other documents. |
| [limit] | <code>number</code> | <code>1000</code> | The maximum number of documents to return. |
| fields | <code>Array.&lt;string&gt;</code> | | Unused: the fields to return on the documents. |

<a name="StorageProvider+getRelatedDocuments"></a>

### storageProvider.getRelatedDocuments(document, limit, fields) ⇒ <code>Promise</code>
Returns a given number of documents related to a given document by comparing tags.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all matching documents.

| Param | Type | Description |
| --- | --- | --- |
| document | <code>UttoriDocument</code> | The document to compare against other documents. |
| limit | <code>number</code> | The maximum number of documents to return. |
| fields | <code>Array.&lt;string&gt;</code> | Unused: the fields to return on the documents. |

<a name="StorageProvider+getRecentDocuments"></a>

### storageProvider.getRecentDocuments(limit, fields) ⇒ <code>Promise</code>
Returns a given number of documents sorted by most recently updated.
### storageProvider.getQuery(query) ⇒ <code>Promise</code>
Returns all documents matching a given query.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all matching documents.

| Param | Type | Description |
| --- | --- | --- |
| limit | <code>number</code> | The maximum number of documents to return. |
| fields | <code>Array.&lt;string&gt;</code> | Unused: the fields to return on the documents. |

<a name="StorageProvider+getPopularDocuments"></a>

### storageProvider.getPopularDocuments(limit, fields) ⇒ <code>Promise</code>
Returns a given number of documents sorted by most visited.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all matching documents.

| Param | Type | Description |
| --- | --- | --- |
| limit | <code>number</code> | The maximum number of documents to return. |
| fields | <code>Array.&lt;string&gt;</code> | Unused: the fields to return on the documents. |

<a name="StorageProvider+getRandomDocuments"></a>

### storageProvider.getRandomDocuments(limit, fields) ⇒ <code>Promise</code>
Returns a given number of randomly selected documents.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all matching documents.

| Param | Type | Description |
| --- | --- | --- |
| limit | <code>number</code> | The maximum number of documents to return. |
| fields | <code>Array.&lt;string&gt;</code> | Unused: the fields to return on the documents. |

<a name="StorageProvider+augmentDocuments"></a>

### storageProvider.augmentDocuments(documents, _fields) ⇒ <code>Promise</code>
Ensures a given set of fields are presenton on a given set of documents.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all augmented documents.

| Param | Type | Description |
| --- | --- | --- |
| documents | <code>Array.&lt;UttoriDocument&gt;</code> | The documents to ensure fields are set on. |
| _fields | <code>Array.&lt;string&gt;</code> | Unused: the fields to return on the documents. |
| query | <code>string</code> | The conditions on which documents should be returned. |

<a name="StorageProvider+get"></a>

Expand Down Expand Up @@ -285,127 +198,12 @@ Removes a document from the file system.
| --- | --- | --- |
| slug | <code>string</code> | The slug identifying the document. |

<a name="StorageProvider+storeObject"></a>

### storageProvider.storeObject(name, data)
Saves a JSON object to the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)

| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | The name of the file to be saved. |
| data | <code>string</code> \| <code>Object</code> | The JSON data for the file to be saved. |

<a name="StorageProvider+updateObject"></a>

### storageProvider.updateObject(name, key, value)
Updates a value in a JSON object on the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)

| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | The name of the file to be updated. |
| key | <code>string</code> | The key of the value to be updated. |
| value | <code>Array</code> \| <code>number</code> \| <code>string</code> \| <code>Object</code> | The JSON data for the file to be saved. |

<a name="StorageProvider+incrementObject"></a>

### storageProvider.incrementObject(name, key, [amount])
Increment a value by a given amount in a JSON object on the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| name | <code>string</code> | | The name of the file to be updated. |
| key | <code>string</code> | | The key of the value to be updated. |
| [amount] | <code>number</code> | <code>1</code> | The value to be added. |

<a name="StorageProvider+decrementObject"></a>

### storageProvider.decrementObject(name, key, [amount])
Decrement a value by a given amount in a JSON object on the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| name | <code>string</code> | | The name of the file to be updated. |
| key | <code>string</code> | | The key of the value to be updated. |
| [amount] | <code>number</code> | <code>1</code> | The value to be subtracted. |

<a name="StorageProvider+readObject"></a>

### storageProvider.readObject(name, fallback) ⇒ <code>Promise.&lt;Object&gt;</code>
Reads a JSON object on the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise.&lt;Object&gt;</code> - Promise object represents the returned object.

| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | The name of the file to be read. |
| fallback | <code>Object</code> | The backup value to use if no value is found. |

<a name="StorageProvider+readObjectValue"></a>

### storageProvider.readObjectValue(name, key, fallback) ⇒ <code>Promise.&lt;Object&gt;</code>
Reads a specific value from a JSON object on the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise.&lt;Object&gt;</code> - Promise object represents the returned object.

| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | The name of the file to get the value from. |
| key | <code>string</code> | The key of the value to be returned. |
| fallback | <code>Object</code> | The backup value to use if no value is found. |

<a name="StorageProvider+refresh"></a>

### storageProvider.refresh()
Reloads all documents from the file system into the cache.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
<a name="StorageProvider+deleteFile"></a>

### storageProvider.deleteFile(folder, name)
Deletes a file from the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)

| Param | Type | Description |
| --- | --- | --- |
| folder | <code>string</code> | The folder of the file to be deleted. |
| name | <code>string</code> | The name of the file to be deleted. |

<a name="StorageProvider+readFile"></a>

### storageProvider.readFile(folder, name) ⇒ <code>Object</code>
Reads a file from the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Object</code> - - The parsed JSON file contents.

| Param | Type | Description |
| --- | --- | --- |
| folder | <code>string</code> | The folder of the file to be read. |
| name | <code>string</code> | The name of the file to be read. |

<a name="StorageProvider+readFolder"></a>

### storageProvider.readFolder(folder) ⇒ <code>Array.&lt;string&gt;</code>
Reads a folder from the file system.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Array.&lt;string&gt;</code> - - The file paths found in the folder.

| Param | Type | Description |
| --- | --- | --- |
| folder | <code>string</code> | The folder to be read. |

<a name="StorageProvider+updateHistory"></a>

### storageProvider.updateHistory(slug, content, originalSlug)
Expand Down
Loading

0 comments on commit 08f0a74

Please sign in to comment.