Skip to content

Commit

Permalink
Merge pull request #247 from saplingjs/dependabot/npm_and_yarn/xo-0.42.0
Browse files Browse the repository at this point in the history
Bump xo from 0.39.1 to 0.42.0
  • Loading branch information
groenroos authored Aug 3, 2021
2 parents f7a29ff + b813151 commit 304b88e
Show file tree
Hide file tree
Showing 38 changed files with 491 additions and 1,695 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: [ master ]

jobs:
test:
name: Run tests and linter
lint:
name: Run linter
runs-on: ubuntu-latest

steps:
Expand All @@ -23,6 +23,19 @@ jobs:
- name: Run linter
run: npm run lint

test-node-16:
name: Test Node.js v16
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install dependencies
run: npm ci

- name: Run test
run: npm run test:report

Expand Down
9 changes: 3 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* Initialises a Sapling instance and handles incoming requests
*/

'use strict';


/* System dependencies */
import async from 'async';

Expand Down Expand Up @@ -38,7 +35,7 @@ class App {

/* Define an admin session for big ops */
this.adminSession = {
user: { role: 'admin' }
user: { role: 'admin' },
};

/* Load utility functions */
Expand Down Expand Up @@ -83,7 +80,7 @@ class App {
async callback => {
if (options.loadViews !== false) {
for (const route in this.controller) {
if ({}.hasOwnProperty.call(this.controller, route)) {
if (Object.prototype.hasOwnProperty.call(this.controller, route)) {
await (await import('./core/initRoute.js')).default.call(this, route, this.controller[route]);
}
}
Expand All @@ -98,7 +95,7 @@ class App {
new Response(this, request, response, null, false);
});
callback();
}
},
], error => {
if (error) {
console.error('Error starting Sapling');
Expand Down
8 changes: 2 additions & 6 deletions core/initRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Initialise route
*/

'use strict';


/* Dependencies */
import { console } from '../lib/Cluster.js';
import Response from '../lib/Response.js';
Expand All @@ -22,14 +19,13 @@ export default async function initRoute(route, view) {
console.log('Loaded route', `${route}`);

/* Create a handler for incoming requests */
const handler = async (request, response) => {
const handler = async (request, response) =>
/* Run a hook, if it exists */
return await this.runHook('get', route, request, response, null, async () => {
await this.runHook('get', route, request, response, null, async () => {
const html = await this.templating.renderView(view, {}, request);

return html instanceof SaplingError ? new Response(this, request, response, html) : new Response(this, request, response, null, html);
});
};

/* Listen on both GET and POST with the same handler */
this.server.get(route, handler);
Expand Down
21 changes: 9 additions & 12 deletions core/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
* Load configuration
*/

'use strict';


/* Dependencies */
import fs from 'node:fs';
import path from 'node:path';
import yargs from 'yargs';
/* eslint-disable-next-line node/file-extension-in-import */
import { hideBin } from 'yargs/helpers';
import fs from 'fs';
import path from 'path';
import _ from 'underscore';

import { console } from '../lib/Cluster.js';
Expand Down Expand Up @@ -43,30 +40,30 @@ export default async function loadConfig(next) {
limit: 100,
production: 'auto',
db: {
driver: 'Memory'
driver: 'Memory',
},
render: {
driver: 'HTML'
driver: 'HTML',
},
sessionStore: {
type: null,
options: {}
options: {},
},
mail: {
host: process.env.MAIL_HOST || '',
port: process.env.MAIL_PORT || 465,
secure: this.utils.trueBoolean(process.env.MAIL_TLS) || true,
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS
}
pass: process.env.MAIL_PASS,
},
},
upload: {
type: 'local',
destination: 'public/uploads'
destination: 'public/uploads',
},
port: argv.port || this.opts.port || 3000,
url: ''
url: '',
};

this.config = {};
Expand Down
7 changes: 2 additions & 5 deletions core/loadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
* Load controller
*/

'use strict';


/* Dependencies */
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import { console } from '../lib/Cluster.js';
import Templating from '../lib/Templating.js';
Expand Down
7 changes: 2 additions & 5 deletions core/loadCustomTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Load custom tags
*/

'use strict';


/**
* Setup custom tags into the template parser to
* return data from the storage engine.
Expand Down Expand Up @@ -43,9 +40,9 @@ export default async function loadCustomTags(next) {
return await this.storage.get({
url,
permission: { role: permission },
session
session,
});
}
},
});

if (next) {
Expand Down
15 changes: 5 additions & 10 deletions core/loadHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
* Load hooks
*/

'use strict';


/* Dependencies */
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import { console } from '../lib/Cluster.js';
import Response from '../lib/Response.js';
Expand Down Expand Up @@ -54,12 +51,10 @@ export default async function loadHooks(next) {
/* Initialise hook if it doesn't exist in the controller */
if (!(route in this.controller) && !route.startsWith('/data') && !route.startsWith('data')) {
/* Listen on */
this.server[method](route, async (request, response) => {
this.server[method](route, async (request, response) =>
/* Run a hook, if it exists */
return await this.runHook(method, route, request, response, null, () => {
return new Response(this, request, response, null);
});
});
await this.runHook(method, route, request, response, null, () => new Response(this, request, response, null)),
);

/* Save the route for later */
this.routeStack[method].push(route);
Expand Down
9 changes: 3 additions & 6 deletions core/loadModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
* Load model
*/

'use strict';


/* Dependencies */
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import { console } from '../lib/Cluster.js';
import SaplingError from '../lib/SaplingError.js';
Expand Down Expand Up @@ -79,7 +76,7 @@ export default async function loadModel(next) {
name: this.name,
schema: this.structure,
config: this.config,
dir: this.dir
dir: this.dir,
});

if (next) {
Expand Down
3 changes: 0 additions & 3 deletions core/loadModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Load modules
*/

'use strict';


/* Dependencies */
import Notifications from '../lib/Notifications.js';
import Uploads from '../lib/Uploads.js';
Expand Down
7 changes: 2 additions & 5 deletions core/loadPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
* Load permissions
*/

'use strict';


/* Dependencies */
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import { console } from '../lib/Cluster.js';
import Response from '../lib/Response.js';
Expand Down
3 changes: 0 additions & 3 deletions core/loadRest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Load REST
*/

'use strict';


/* Dependencies */
import Response from '../lib/Response.js';
import SaplingError from '../lib/SaplingError.js';
Expand Down
13 changes: 5 additions & 8 deletions core/loadServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
* Load server
*/

'use strict';


/* Dependencies */
import path from 'path';
import Cluster from '../lib/Cluster.js';
import Response from '../lib/Response.js';
import SaplingError from '../lib/SaplingError.js';
import path from 'node:path';

import express from 'express';
import session from 'express-session';
Expand All @@ -18,6 +12,9 @@ import bodyParser from 'body-parser';
import logger from 'morgan';
import compression from 'compression';
import csrf from 'csurf';
import SaplingError from '../lib/SaplingError.js';
import Response from '../lib/Response.js';
import Cluster from '../lib/Cluster.js';


/**
Expand Down Expand Up @@ -56,7 +53,7 @@ export default function loadServer({ reload, listen }, next) {
secret,
resave: false,
saveUninitialized: true,
cookie: { maxAge: null }
cookie: { maxAge: null },
};

/* If we've defined a type, load it */
Expand Down
5 changes: 1 addition & 4 deletions core/parseMethodRouteKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Parse method-route key
*/

'use strict';


/* Dependencies */
import SaplingError from '../lib/SaplingError.js';

Expand All @@ -18,7 +15,7 @@ import SaplingError from '../lib/SaplingError.js';
export default function parseMethodRouteKey(key) {
const object = {
method: false,
route: false
route: false,
};

/* Format expected: "GET /url/here" */
Expand Down
3 changes: 0 additions & 3 deletions core/runHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Run hook
*/

'use strict';


/* Dependencies */
import routeMatcher from 'path-match';

Expand Down
11 changes: 3 additions & 8 deletions drivers/db/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
* object in app memory, and gets wiped when the server dies.
*/

'use strict';


/* Dependencies */
import _ from 'underscore';
import Interface from './Interface.js';

import SaplingError from '../../lib/SaplingError.js';
import Utils from '../../lib/Utils.js';
import Interface from './Interface.js';


/**
Expand Down Expand Up @@ -69,9 +66,7 @@ export default class Memory extends Interface {

/* If there are any conditions */
if (Object.keys(conditions).length > 0) {
records = records.filter(record => {
return this.isMatch(record, conditions);
});
records = records.filter(record => this.isMatch(record, conditions));
}

return records;
Expand Down Expand Up @@ -216,7 +211,7 @@ export default class Memory extends Interface {

if (collection in this.uniques && Object.keys(data).some(r => this.uniques[collection].includes(r))) {
for (const field of this.uniques[collection]) {
if (this.memory[collection].filter(item => item[field] === data[field] && (id ? item._id !== id : true)).length > 0) {
if (this.memory[collection].some(item => item[field] === data[field] && (id ? item._id !== id : true))) {
matches.push(field);
}
}
Expand Down
Loading

0 comments on commit 304b88e

Please sign in to comment.