Skip to content

Commit

Permalink
Switch memory cache data type, no auto fields for tags, customData, r…
Browse files Browse the repository at this point in the history
…ace condition fix in tests
  • Loading branch information
MatthewCallis committed Mar 2, 2021
1 parent 3bd3319 commit e59eff1
Show file tree
Hide file tree
Showing 16 changed files with 2,559 additions and 1,185 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_", "caughtErrors": "none" }],
"consistent-return": ["warn", { "treatUndefinedAsUnspecified": false }],
"object-curly-newline": 0,
"unicorn/no-useless-undefined": 0
"unicorn/no-useless-undefined": 0,
"sonarjs/cognitive-complexity": 0
}
}
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## [4.1.0](https://github.com/uttori/uttori-storage-provider-json-file/compare/v4.0.0...v4.1.0) - 2021-02-28

- 🛠 Switch memory cache data type (Array ➜ Object)
- 🛠 Fix return types
- 🛠 Remove auto adding `tags`, `customData` fields
- 🛠 Fix history race condition where writes with identical timestamps would lead to out of order history
- 🧰 Add option to disable in memory cache and always read from file
- 🎁 Update dev dependencies

## [4.0.0](https://github.com/uttori/uttori-storage-provider-json-file/compare/v3.4.3...v4.0.0) - 2021-01-16

- 🧰 Add ESM Support
- 🧰 Add explicit exports
- 🧰 Add support for `COUNT(*)` as stand alone `SELECT` field for returning counts.
- 🧰 Add support for `COUNT(*)` as stand alone `SELECT` field for returning counts
- 🎁 Update dev dependencies

## [3.4.3](https://github.com/uttori/uttori-storage-provider-json-file/compare/v3.4.2...v3.4.3) - 2020-11-15
Expand Down
91 changes: 48 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ const results = s.getQuery('SELECT COUNT(*) FROM documents WHERE slug IS_NOT_NUL
</dd>
</dl>

## Functions

<dl>
<dt><a href="#debug">debug()</a> : <code>function</code></dt>
<dd></dd>
</dl>

## Typedefs

<dl>
Expand All @@ -121,21 +128,20 @@ Storage for Uttori documents using JSON files stored on the local file system.
| [config.extension] | <code>string</code> | <code>&quot;&#x27;json&#x27;&quot;</code> | The file extension to use for file, name of the employee. |
| [config.spaces_document] | <code>number</code> | | The spaces parameter for JSON stringifying documents. |
| [config.spaces_history] | <code>number</code> | | The spaces parameter for JSON stringifying history. |
| documents | [<code>Array.&lt;UttoriDocument&gt;</code>](#UttoriDocument) | | The collection of documents. |
| documents | <code>object</code> | | The collection of documents where the slug is the key and the value is the document. |


* [StorageProvider](#StorageProvider)
* [new StorageProvider(config)](#new_StorageProvider_new)
* [.all()](#StorageProvider+all) ⇒ <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(params)](#StorageProvider+getRevision) ⇒ <code>Promise</code>
* [.all()](#StorageProvider+all) ⇒ <code>object</code>
* [.getQuery(query)](#StorageProvider+getQuery) ⇒ <code>Promise.&lt;(Array.&lt;UttoriDocument&gt;\|number)&gt;</code>
* [.get(slug)](#StorageProvider+get) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
* [.add(document)](#StorageProvider+add)
* [.updateValid(document, originalSlug)](#StorageProvider+updateValid)
* [.update(params)](#StorageProvider+update)
* [.delete(slug)](#StorageProvider+delete)
* [.refresh()](#StorageProvider+refresh)
* [.getHistory(slug)](#StorageProvider+getHistory) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.getRevision(params)](#StorageProvider+getRevision) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
* [.updateHistory(slug, content, [originalSlug])](#StorageProvider+updateHistory)

<a name="new_StorageProvider_new"></a>
Expand All @@ -152,6 +158,7 @@ Creates an instance of StorageProvider.
| [config.extension] | <code>string</code> | <code>&quot;json&quot;</code> | The file extension to use for file, name of the employee. |
| [config.update_timestamps] | <code>boolean</code> | <code>true</code> | Should update times be marked at the time of edit. |
| [config.use_history] | <code>boolean</code> | <code>true</code> | Should history entries be created. |
| [config.use_cache] | <code>boolean</code> | <code>true</code> | Should we cache files in memory? |
| [config.spaces_document] | <code>number</code> | | The spaces parameter for JSON stringifying documents. |
| [config.spaces_history] | <code>number</code> | | The spaces parameter for JSON stringifying history. |

Expand All @@ -161,66 +168,40 @@ const storageProvider = new StorageProvider({ content_directory: 'content', hist
```
<a name="StorageProvider+all"></a>

### storageProvider.all() ⇒ <code>Promise</code>
### storageProvider.all() ⇒ <code>object</code>
Returns all documents.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents all documents.
**Returns**: <code>object</code> - All documents.
**Example**
```js
storageProvider.all();
[{ slug: 'first-document', ... }, ...]
{ first-document: { slug: 'first-document', ... }, ...}
```
<a name="StorageProvider+getQuery"></a>

### storageProvider.getQuery(query) ⇒ <code>Promise</code>
### storageProvider.getQuery(query) ⇒ <code>Promise.&lt;(Array.&lt;UttoriDocument&gt;\|number)&gt;</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.
**Returns**: <code>Promise.&lt;(Array.&lt;UttoriDocument&gt;\|number)&gt;</code> - Promise object represents all matching documents.

| Param | Type | Description |
| --- | --- | --- |
| query | <code>string</code> | The conditions on which documents should be returned. |

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

### storageProvider.get(slug) ⇒ <code>Promise</code>
### storageProvider.get(slug) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
Returns a document for a given slug.

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

| Param | Type | Description |
| --- | --- | --- |
| slug | <code>string</code> | The slug of the document to be returned. |

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

### storageProvider.getHistory(slug) ⇒ <code>Promise</code>
Returns the history of edits for a given slug.

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

| Param | Type | Description |
| --- | --- | --- |
| slug | <code>string</code> | The slug of the document to get history for. |

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

### storageProvider.getRevision(params) ⇒ <code>Promise</code>
Returns a specifc revision from the history of edits for a given slug and revision timestamp.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise</code> - Promise object represents the returned revision of the document.

| Param | Type | Description |
| --- | --- | --- |
| params | <code>object</code> | The params object. |
| params.slug | <code>string</code> | The slug of the document to be returned. |
| params.revision | <code>number</code> | The unix timestamp of the history to be returned. |

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

### storageProvider.add(document)
Expand Down Expand Up @@ -269,12 +250,32 @@ Removes a document from the file system.
| --- | --- | --- |
| slug | <code>string</code> | The slug identifying the document. |

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

### storageProvider.getHistory(slug) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
Returns the history of edits for a given slug.

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

| Param | Type | Description |
| --- | --- | --- |
| slug | <code>string</code> | The slug of the document to get history for. |

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

### storageProvider.refresh()
Reloads all documents from the file system into the cache.
### storageProvider.getRevision(params) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
Returns a specifc revision from the history of edits for a given slug and revision timestamp.

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

| Param | Type | Description |
| --- | --- | --- |
| params | <code>object</code> | The params object. |
| params.slug | <code>string</code> | The slug of the document to be returned. |
| params.revision | <code>string</code> \| <code>number</code> | The unix timestamp of the history to be returned. |

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

### storageProvider.updateHistory(slug, content, [originalSlug])
Expand All @@ -288,6 +289,10 @@ Updates History for a given slug, renaming the store file and history folder as
| content | <code>string</code> | The revision of the document to be saved. |
| [originalSlug] | <code>string</code> | The original slug identifying the document, or the slug if it has not changed. |

<a name="debug"></a>

## debug() : <code>function</code>
**Kind**: global function
<a name="UttoriDocument"></a>

## UttoriDocument
Expand Down
19 changes: 19 additions & 0 deletions docs/plugin.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## Classes

<dl>
<dt><a href="#Plugin">Plugin</a></dt>
<dd><p>Uttori Storage Provider - JSON File</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#debug">debug()</a> : <code>function</code></dt>
<dd></dd>
</dl>

<a name="Plugin"></a>

## Plugin
Expand Down Expand Up @@ -71,3 +86,7 @@ const context = {
};
Plugin.register(context);
```
<a name="debug"></a>

## debug() : <code>function</code>
**Kind**: global function
18 changes: 16 additions & 2 deletions docs/query-tools.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
## Functions

<dl>
<dt><a href="#debug">debug()</a> : <code>function</code></dt>
<dd></dd>
<dt><a href="#processQuery">processQuery(query, objects)</a> ⇒ <code>Array.&lt;object&gt;</code> | <code>number</code></dt>
<dd><p>Processes a query string.</p>
</dd>
</dl>

<a name="debug"></a>

## debug() : <code>function</code>
**Kind**: global function
<a name="processQuery"></a>

## processQuery(query, objects) ⇒ <code>Array.&lt;object&gt;</code>
## processQuery(query, objects) ⇒ <code>Array.&lt;object&gt;</code> \| <code>number</code>
Processes a query string.

**Kind**: global function
**Returns**: <code>Array.&lt;object&gt;</code> - Returns an array of all matched documents.
**Returns**: <code>Array.&lt;object&gt;</code> \| <code>number</code> - Returns an array of all matched documents, or a count.

| Param | Type | Description |
| --- | --- | --- |
Expand Down
Loading

0 comments on commit e59eff1

Please sign in to comment.