Skip to content

Commit

Permalink
Merge 8a1fea3 into 6dd9bb3
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCallis committed Jun 15, 2020
2 parents 6dd9bb3 + 8a1fea3 commit b13198a
Show file tree
Hide file tree
Showing 22 changed files with 3,924 additions and 2,626 deletions.
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
"extends": [
"airbnb",
"plugin:ava/recommended",
"plugin:jsdoc/recommended",
"plugin:node/recommended",
"plugin:optimize-regex/all",
"plugin:ramda/recommended",
"plugin:security/recommended",
"plugin:unicorn/recommended"
],
"plugins": [
"ava",
"jsdoc",
"no-inferred-method-name",
"node",
"optimize-regex",
Expand All @@ -28,7 +31,7 @@
"expect": true
},
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2020
},
"rules": {
"ava/no-only-test": 0,
Expand All @@ -53,10 +56,14 @@
"global-require": 0,
"max-len": 0,
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-inferred-method-name/no-inferred-method-name": "error",
"no-param-reassign": 0,
"no-plusplus": 0,
"no-restricted-syntax": 0,
"no-underscore-dangle": 0,
"no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_", "caughtErrors": "none" }]
"no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_", "caughtErrors": "none" }],
"consistent-return": ["warn", { "treatUndefinedAsUnspecified": false }],
"object-curly-newline": 0,
"unicorn/no-useless-undefined": 0
}
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm.hbs
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12.9.1
v12.18.0
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "8"
- "10"
- "12"
- "14"

install:
- npm ci
Expand Down
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
// Variables: https://code.visualstudio.com/docs/editor/variables-reference
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Test File",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"debug",
"--break",
"${file}"
],
"port": 9229,
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "Storage: JSON File Tests",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"--serial",
"--files=test/**/*.test.js"
],
"port": 9229,
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**/*.js"
]
}
]
}
53 changes: 0 additions & 53 deletions README.hbs

This file was deleted.

134 changes: 100 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[![view on npm](http://img.shields.io/npm/v/uttori-storage-provider-json-file.svg)](https://www.npmjs.org/package/uttori-storage-provider-json-file)
[![npm module downloads](http://img.shields.io/npm/dt/uttori-storage-provider-json-file.svg)](https://www.npmjs.org/package/uttori-storage-provider-json-file)
[![view on npm](http://img.shields.io/npm/v/@uttori/storage-provider-json-file.svg)](https://www.npmjs.org/package/@uttori/storage-provider-json-file)
[![npm module downloads](http://img.shields.io/npm/dt/@uttori/storage-provider-json-file.svg)](https://www.npmjs.org/package/@uttori/storage-provider-json-file)
[![Build Status](https://travis-ci.org/uttori/uttori-storage-provider-json-file.svg?branch=master)](https://travis-ci.org/uttori/uttori-storage-provider-json-file)
[![Dependency Status](https://david-dm.org/uttori/uttori-storage-provider-json-file.svg)](https://david-dm.org/uttori/uttori-storage-provider-json-file)
[![Coverage Status](https://coveralls.io/repos/uttori/uttori-storage-provider-json-file/badge.svg?branch=master)](https://coveralls.io/r/uttori/uttori-storage-provider-json-file?branch=master)

# Uttori Storage Provider - JSON File

Uttori storage provider using JSON files on disk.
Uttori Storage Provider using JSON files on disk.

This repo exports both a Uttori Plugin compliant `Plugin` class as well as the underlying `StorageProvider` class.

## Install

Expand All @@ -18,18 +20,75 @@ npm install --save uttori-storage-provider-json-file

```js
{
content_dir: '',
history_dir: '',
content_directory: '',
history_directory: '',
extension: 'json',
spaces_document: null,
spaces_history: null,
// Registration Events
events: {
add: ['storage-add'],
delete: ['storage-delete'],
get: ['storage-get'],
getHistory: ['storage-get-history'],
getRevision: ['storage-get-revision'],
query: ['storage-query'],
update: ['storage-update'],
validateConfig: ['validate-config'],
},
}
```

* * *

# Example

```js
const { StorageProvider } = require('uttori-storage-provider-json-file');
const s = new StorageProvider({
content_directory: 'example/content',
history_directory: 'example/history',
extension: 'json',
spaces_document: null,
spaces_history: null,
});
await s.add({
title: 'Example Title',
slug: 'example-title',
content: '## Example Title',
html: '',
updateDate: 1459310452001,
createDate: 1459310452001,
tags: ['Example Tag'],
customData: {
keyA: 'value-a',
keyB: 'value-b',
keyC: 'value-c',
},
});
const results = await s.getQuery('SELECT tags FROM documents WHERE slug IS_NOT_NULL ORDER BY slug ASC LIMIT 1');
➜ results === [
{ tags: ['Example Tag'] },
]
```

# API Reference

## Classes

<dl>
<dt><a href="#StorageProvider">StorageProvider</a></dt>
<dd><p>Storage for Uttori documents using JSON files stored on the local file system.</p>
</dd>
</dl>

## Typedefs

<dl>
<dt><a href="#UttoriDocument">UttoriDocument</a></dt>
<dd></dd>
</dl>

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

## StorageProvider
Expand All @@ -38,16 +97,20 @@ Storage for Uttori documents using JSON files stored on the local file system.
**Kind**: global class
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| config | <code>Object</code> | The configuration object. |
| documents | <code>Array.&lt;UttoriDocument&gt;</code> | The collection of documents. |
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| config | <code>object</code> | | The configuration object. |
| config.content_directory | <code>string</code> | | The directory to store documents. |
| config.history_directory | <code>string</code> | | The directory to store document histories. |
| 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. |


* [StorageProvider](#StorageProvider)
* [new StorageProvider(config)](#new_StorageProvider_new)
* [.all()](#StorageProvider+all) ⇒ <code>Promise</code>
* [.tags()](#StorageProvider+tags) ⇒ <code>Promise</code>
* [.getQuery(query)](#StorageProvider+getQuery) ⇒ <code>Promise</code>
* [.get(slug)](#StorageProvider+get) ⇒ <code>Promise</code>
* [.getHistory(slug)](#StorageProvider+getHistory) ⇒ <code>Promise</code>
Expand All @@ -57,7 +120,7 @@ Storage for Uttori documents using JSON files stored on the local file system.
* [.update(document, originalSlug)](#StorageProvider+update)
* [.delete(slug)](#StorageProvider+delete)
* [.refresh()](#StorageProvider+refresh)
* [.updateHistory(slug, content, originalSlug)](#StorageProvider+updateHistory)
* [.updateHistory(slug, content, [originalSlug])](#StorageProvider+updateHistory)

<a name="new_StorageProvider_new"></a>

Expand All @@ -67,16 +130,16 @@ Creates an instance of StorageProvider.

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| 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 | <code>object</code> | | A configuration object. |
| config.content_directory | <code>string</code> | | The directory to store documents. |
| config.history_directory | <code>string</code> | | The directory to store document histories. |
| [config.extension] | <code>string</code> | <code>&quot;json&quot;</code> | The file extension to use for file, name of the employee. |
| [config.spaces_document] | <code>number</code> | <code></code> | The spaces parameter for JSON stringifying documents. |
| [config.spaces_history] | <code>number</code> | <code></code> | The spaces parameter for JSON stringifying history. |
| [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. |

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

Expand All @@ -90,18 +153,6 @@ Returns all documents.
storageProvider.all();
➜ [{ slug: 'first-document', ... }, ...]
```
<a name="StorageProvider+tags"></a>

### storageProvider.tags() ⇒ <code>Promise</code>
Returns all unique tags.

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

### storageProvider.getQuery(query) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -160,7 +211,7 @@ Saves a document to the file system.

| Param | Type | Description |
| --- | --- | --- |
| document | <code>UttoriDocument</code> | The document to be added to the collection. |
| document | [<code>UttoriDocument</code>](#UttoriDocument) | The document to be added to the collection. |

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

Expand All @@ -172,7 +223,7 @@ Updates a document and saves to the file system.

| Param | Type | Description |
| --- | --- | --- |
| document | <code>UttoriDocument</code> | The document to be updated in the collection. |
| document | [<code>UttoriDocument</code>](#UttoriDocument) | The document to be updated in the collection. |
| originalSlug | <code>string</code> | The original slug identifying the document, or the slug if it has not changed. |

<a name="StorageProvider+update"></a>
Expand All @@ -184,7 +235,7 @@ Updates a document and figures out how to save to the file system.

| Param | Type | Description |
| --- | --- | --- |
| document | <code>UttoriDocument</code> | The document to be updated in the collection. |
| document | [<code>UttoriDocument</code>](#UttoriDocument) | The document to be updated in the collection. |
| originalSlug | <code>string</code> | The original slug identifying the document, or the slug if it has not changed. |

<a name="StorageProvider+delete"></a>
Expand All @@ -206,7 +257,7 @@ Reloads all documents from the file system into the cache.
**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
<a name="StorageProvider+updateHistory"></a>

### storageProvider.updateHistory(slug, content, originalSlug)
### storageProvider.updateHistory(slug, content, [originalSlug])
Updates History for a given slug, renaming the store file and history folder as needed.

**Kind**: instance method of [<code>StorageProvider</code>](#StorageProvider)
Expand All @@ -215,7 +266,22 @@ Updates History for a given slug, renaming the store file and history folder as
| --- | --- | --- |
| slug | <code>string</code> | The slug of the document to update history for. |
| 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. |
| [originalSlug] | <code>string</code> | The original slug identifying the document, or the slug if it has not changed. |

<a name="UttoriDocument"></a>

## UttoriDocument
**Kind**: global typedef
**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| slug | <code>string</code> | | The unique identifier for the document. |
| [title] | <code>string</code> | <code>&quot;&#x27;&#x27;&quot;</code> | The unique identifier for the document. |
| [createDate] | <code>number</code> \| <code>Date</code> | | The creation date of the document. |
| [updateDate] | <code>number</code> \| <code>Date</code> | | The last date the document was updated. |
| [tags] | <code>Array.&lt;string&gt;</code> | <code>[]</code> | The unique identifier for the document. |
| [customData] | <code>object</code> | <code>{}</code> | Any extra meta data for the document. |


* * *
Expand Down

0 comments on commit b13198a

Please sign in to comment.