Skip to content

Commit

Permalink
Types, fixing linting, fixing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCallis committed Dec 19, 2023
1 parent 301ef3b commit 06b6cca
Show file tree
Hide file tree
Showing 39 changed files with 797 additions and 412 deletions.
22 changes: 18 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"plugin:n/recommended",
"plugin:optimize-regex/all",
"plugin:ramda/recommended",
"plugin:security/recommended",
"plugin:sonarjs/recommended"
"plugin:security/recommended-legacy",
"plugin:sonarjs/recommended",
"plugin:@typescript-eslint/recommended-type-checked"
],
"plugins": [
"@typescript-eslint",
"anti-trojan-source",
"ava",
"import",
Expand All @@ -37,9 +39,20 @@
},
"parserOptions": {
"ecmaVersion": "latest",
"requireConfigFile": false
"requireConfigFile": false,
"project": ["./.tsconfig.json"]
},
"ignorePatterns": [
"temp.js",
"dist/*.ts",
"test/*.js"
],
"rules": {
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"anti-trojan-source/no-bidi": "error",
"import/no-extraneous-dependencies": [
"error", {
Expand Down Expand Up @@ -79,7 +92,8 @@
}
],
"no-underscore-dangle": 0,
"no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_", "caughtErrors": "none" }],
"no-unused-vars": 0,
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_", "caughtErrors": "none" }],
"object-curly-newline": 0,
"optimize-regex/optimize-regex": "warn",
"security/detect-non-literal-fs-filename": 0,
Expand Down
5 changes: 3 additions & 2 deletions .tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"include": [
"src/**/*"
"src/**/*",
"test/**/*"
],
"exclude": [
"node_modules",
"test"
"test/**/*.test.js"
],
"compilerOptions": {
"allowJs": true,
Expand Down
83 changes: 43 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,26 @@ Storage for Uttori documents using JSON files stored on the local file system.
**Kind**: global class
**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| config | <code>object</code> | | The configuration object. |
| config.contentDirectory | <code>string</code> | | The directory to store documents. |
| config.historyDirectory | <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. |
| [config.spacesDocument] | <code>number</code> | | The spaces parameter for JSON stringifying documents. |
| [config.spacesHistory] | <code>number</code> | | The spaces parameter for JSON stringifying history. |
| documents | <code>object</code> | | The collection of documents where the slug is the key and the value is the document. |
| Name | Type | Description |
| --- | --- | --- |
| config | [<code>StorageProviderConfig</code>](#StorageProviderConfig) | The configuration object. |
| documents | <code>Record.&lt;string, UttoriDocument&gt;</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)
* _instance_
* [.all()](#StorageProvider+all) ⇒ <code>Promise.&lt;object&gt;</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)
* [.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)
* [.documents](#StorageProvider+documents) : <code>Record.&lt;string, UttoriDocument&gt;</code>
* [.all](#StorageProvider+all) ⇒ <code>Promise.&lt;Record.&lt;string, UttoriDocument&gt;&gt;</code>
* [.getQuery](#StorageProvider+getQuery) ⇒ <code>Promise.&lt;(Array.&lt;UttoriDocument&gt;\|number)&gt;</code>
* [.get](#StorageProvider+get) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
* [.add](#StorageProvider+add)
* [.updateValid](#StorageProvider+updateValid)
* [.update](#StorageProvider+update)
* [.delete](#StorageProvider+delete)
* [.getHistory](#StorageProvider+getHistory) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.getRevision](#StorageProvider+getRevision) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
* [.updateHistory](#StorageProvider+updateHistory)
* _static_
* [.ensureDirectory(directory)](#StorageProvider.ensureDirectory)

Expand All @@ -151,24 +147,30 @@ Creates an instance of StorageProvider.
```js
const storageProvider = new StorageProvider({ contentDirectory: 'content', historyDirectory: 'history', spacesDocument: 2 });
```
<a name="StorageProvider+documents"></a>

### storageProvider.documents : <code>Record.&lt;string, UttoriDocument&gt;</code>
The collection of documents where the slug is the key and the value is the document.

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

### storageProvider.all() ⇒ <code>Promise.&lt;object&gt;</code>
### storageProvider.all ⇒ <code>Promise.&lt;Record.&lt;string, UttoriDocument&gt;&gt;</code>
Returns all documents.

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

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

| Param | Type | Description |
Expand All @@ -177,10 +179,10 @@ Returns all documents matching a given query.

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

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

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

| Param | Type | Description |
Expand All @@ -189,21 +191,21 @@ Returns a document for a given slug.

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

### storageProvider.add(document)
### storageProvider.add
Saves a document to the file system.

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

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

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

### storageProvider.updateValid(document, originalSlug)
### storageProvider.updateValid ℗
Updates a document and saves to the file system.

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

| Param | Type | Description |
Expand All @@ -213,10 +215,10 @@ Updates a document and saves to the file system.

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

### storageProvider.update(params)
### storageProvider.update
Updates a document and figures out how to save to the file system.

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

| Param | Type | Description |
| --- | --- | --- |
Expand All @@ -226,21 +228,21 @@ Updates a document and figures out how to save to the file system.

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

### storageProvider.delete(slug)
### storageProvider.delete
Removes a document from the file system.

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

| Param | Type | Description |
| --- | --- | --- |
| slug | <code>string</code> | The slug identifying the document. |

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

### storageProvider.getHistory(slug) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
### storageProvider.getHistory ⇒ <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)
**Kind**: instance property of [<code>StorageProvider</code>](#StorageProvider)
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - Promise object represents the returned history.

| Param | Type | Description |
Expand All @@ -249,10 +251,10 @@ Returns the history of edits for a given slug.

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

### storageProvider.getRevision(params) ⇒ <code>Promise.&lt;(UttoriDocument\|undefined)&gt;</code>
### storageProvider.getRevision ⇒ <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)
**Kind**: instance property 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 |
Expand All @@ -263,10 +265,10 @@ Returns a specifc revision from the history of edits for a given slug and revisi

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

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

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

| Param | Type | Description |
| --- | --- | --- |
Expand Down Expand Up @@ -313,6 +315,7 @@ Ensure a directory exists, and if not create it.
| [useCache] | <code>boolean</code> | Should we cache files in memory? |
| [spacesDocument] | <code>number</code> | The spaces parameter for JSON stringifying documents. |
| [spacesHistory] | <code>number</code> | The spaces parameter for JSON stringifying history. |
| [events] | <code>Record.&lt;string, Array.&lt;string&gt;&gt;</code> | The events to listen for. |


* * *
Expand Down
9 changes: 9 additions & 0 deletions dist/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Operator = '=' | '!=' | '<=' | '<' | '>=' | '>' | 'LIKE' | 'IN' | 'NOT_IN' | 'INCLUDES' | 'EXCLUDES' | 'IS_NULL' | 'IS_NOT_NULL' | 'BETWEEN' | 'AND' | 'OR';
export type Value = string | number | Array<string | number | AST> | [string | number, string | number];

export type SqlWhereParserAst = {
[key in Exclude<Operator, 'AND' | 'OR'>]?: Value;
} & {
AND?: SqlWhereParserAst[];
OR?: SqlWhereParserAst[];
};
7 changes: 4 additions & 3 deletions dist/fisher-yates-shuffle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ export default fyShuffle;
* Fisher-Yates Shuffle (aka Knuth Shuffle)
* The algorithm continually determines the next element by randomly drawing an element from the array until no elements remain.
* This modifies the passed in array, clone the array being passed in to return a new array.
* @param {Array} array - The array to randomize.
* @returns {Array} - The same array, randomized.
* @template T
* @param {T[]} array The array to randomize.
* @returns {T[]} The same array, randomized.
* @example <caption>fyShuffle(array)</caption>
* const shuffled_array = fyShuffle(sorted_array.slice(0));
* @see {@link https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle|Fisher-Yates Shuffle (aka Knuth Shuffle)}
* @see {@link https://bost.ocks.org/mike/shuffle/|Fisher–Yates Shuffle}
*/
declare function fyShuffle(array: any[]): any[];
declare function fyShuffle<T>(array: T[]): T[];
//# sourceMappingURL=fisher-yates-shuffle.d.ts.map
2 changes: 1 addition & 1 deletion dist/fisher-yates-shuffle.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions dist/operator.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default Operator;
/**
* A wrapper class around operators to distinguish them from regular tokens.
* @property {*} value - The value.
* @property {*} type - The type of operator.
* @property {number} precedence - Priority to sort the operators with.
* @property {string | symbol} value The value.
* @property {number | symbol} type The type of operator.
* @property {number} precedence Priority to sort the operators with.
* @example <caption>Init TokenizeThis</caption>
* const op = new Operator(value, type, precedence);
* @class
Expand All @@ -12,20 +12,23 @@ declare class Operator {
/**
* Returns a type for a given string.
* @param {string} type - The type to lookup.
* @returns {*} Either number of parameters or Unary Minus Symbol.
* @returns {number | symbol} Either number of parameters or Unary Minus Symbol.
* @static
*/
static type(type: string): any;
static type(type: string): number | symbol;
/**
* Creates an instance of Operator.
* @param {*} value - The value.
* @param {*} type - The type of operator.
* @param {number} precedence - Priority to sort the operators with.
* @param {string | symbol} value The value.
* @param {number | symbol} type The type of operator.
* @param {number} precedence Priority to sort the operators with.
* @class
*/
constructor(value: any, type: any, precedence: number);
value: any;
type: any;
constructor(value: string | symbol, type: number | symbol, precedence: number);
/** @type {string | symbol} The value. */
value: string | symbol;
/** @type {number | symbol} The type of operator. */
type: number | symbol;
/** @type {number} Priority to sort the operators with. */
precedence: number;
/**
* Returns the value as is for JSON.
Expand Down
2 changes: 1 addition & 1 deletion dist/operator.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/parse-query-to-ramda.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export default parseQueryToRamda;
/**
* Using default SQL tree output, iterate over that to convert to items to be checked group by group (AND, OR), prop by prop to filter functions.
* Both `+` and `-` should be done in a pre-parser step or before the query is constructed, or after results are returned.
* @param {object} ast The parsed output of SqlWhereParser to be filtered.
* @param {import('../dist/custom.d.ts').SqlWhereParserAst} ast The parsed output of SqlWhereParser to be filtered.
* @returns {Array} The collected set of Ramda filter functions.
* @example <caption>parseQueryToRamda(ast)</caption>
* const filters = parseQueryToRamda(ast);
* return R.filter(filters)(docs);
* ➜ [{ ... }, { ... }, ...]
*/
declare function parseQueryToRamda(ast: object): any[];
declare function parseQueryToRamda(ast: import('../dist/custom.d.ts').SqlWhereParserAst): any[];
//# sourceMappingURL=parse-query-to-ramda.d.ts.map
2 changes: 1 addition & 1 deletion dist/parse-query-to-ramda.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions dist/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ declare class Plugin {
static get configKey(): string;
/**
* The default configuration.
* @returns {object} The configuration.
* @returns {import('./storage-provider.js').StorageProviderConfig} The configuration.
* @example <caption>Plugin.defaultConfig()</caption>
* const config = { ...Plugin.defaultConfig(), ...context.config[Plugin.configKey] };
* @static
*/
static defaultConfig(): object;
static defaultConfig(): import('./storage-provider.js').StorageProviderConfig;
/**
* Register the plugin with a provided set of events on a provided Hook system.
* @param {object} context - A Uttori-like context.
* @param {object} context.hooks - An event system / hook system to use.
* @param {Function} context.hooks.on - An event registration function.
* @param {object} context.config - A provided configuration to use.
* @param {object} context.config.events - An object whose keys correspong to methods, and contents are events to listen for.
* @param {Record<string, import('./storage-provider.js').StorageProviderConfig>} context.config - A provided configuration to use.
* @example <caption>Plugin.register(context)</caption>
* const context = {
* hooks: {
Expand Down Expand Up @@ -59,9 +58,7 @@ declare class Plugin {
hooks: {
on: Function;
};
config: {
events: object;
};
config: Record<string, import('./storage-provider.js').StorageProviderConfig>;
}): void;
}
//# sourceMappingURL=plugin.d.ts.map
2 changes: 1 addition & 1 deletion dist/plugin.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 06b6cca

Please sign in to comment.