Skip to content

Commit

Permalink
Merge pull request #345 from cofacts/upgrade-dep-prettier
Browse files Browse the repository at this point in the history
Upgrade dependencies and prettier
  • Loading branch information
MrOrz committed Mar 26, 2023
2 parents 0bc402e + 75f9360 commit 9a40a19
Show file tree
Hide file tree
Showing 58 changed files with 32,143 additions and 25,586 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 16

- run: 'npm i'

Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
},
'@storybook/addon-svelte-csf',
],
webpackFinal: async config => {
webpackFinal: async (config) => {
// Enable project root import paths like 'src/lib/sharedUtils'
// Ref: https://stackoverflow.com/a/65772747/1582110
config.resolve.modules.push(path.resolve(__dirname, '../'));
Expand Down
57,005 changes: 31,823 additions & 25,182 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@storybook/addon-actions": "^6.2.9",
"@storybook/addon-essentials": "^6.2.9",
"@storybook/addon-links": "^6.2.9",
"@storybook/addon-svelte-csf": "^1.1.0",
"@storybook/addon-svelte-csf": "^2.0.11",
"@storybook/svelte": "^6.2.9",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
Expand All @@ -115,7 +115,7 @@
"normalize.css": "^8.0.1",
"npm-run-all": "^4.1.5",
"optimize-css-assets-webpack-plugin": "^6.0.0",
"prettier": "=1.13.0",
"prettier": "^2.8.6",
"style-loader": "^1.1.3",
"svelte": "^3.38.2",
"svelte-loader": "github:sveltejs/svelte-loader",
Expand Down
6 changes: 3 additions & 3 deletions scripts/authGoogleDrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ function getNewToken(oauth2Client) {
input: process.stdin,
output: process.stdout,
});
rl.question('Enter the code from that page here: ', function(code) {
rl.question('Enter the code from that page here: ', function (code) {
rl.close();
oauth2Client.getToken(code, function(err, token) {
oauth2Client.getToken(code, function (err, token) {
if (err) {
console.log('Error while trying to retrieve access token', err);
return;
Expand All @@ -71,7 +71,7 @@ function storeToken(token) {
fs.appendFile(
ENV_FILE_PATH,
`GOOGLE_CREDENTIALS=${JSON.stringify({ token, secrets })}`,
function(err) {
function (err) {
if (err) {
console.log('Error while trying to store access token', err);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const loginRouter = Router()
})
.get('/line_notify', passport.authenticate('line_notify'));

const handlePassportCallback = strategy => (ctx, next) =>
const handlePassportCallback = (strategy) => (ctx, next) =>
passport.authenticate(strategy, (err, accessToken) => {
if (err) {
err.status = 401;
Expand Down
6 changes: 2 additions & 4 deletions src/database/backtrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { parseToJson } from '@cofacts/line-bot-log-parser';
*/

async function main(logFilePath) {
const parse = async path => {
const parse = async (path) => {
const status = {
processedLog: 0,
writtenUserSettings: 0,
Expand Down Expand Up @@ -87,7 +87,5 @@ async function main(logFilePath) {

if (require.main === module) {
const path = '../rumors-line-bot-logs';
main(path)
.then(console.log)
.catch(console.error);
main(path).then(console.log).catch(console.error);
}
32 changes: 17 additions & 15 deletions src/database/models/__tests__/userArticleLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ describe('userArticleLink', () => {

await UserArticleLink.create({ userId, articleId });

const updatedDate = await UserArticleLink.createOrUpdateByUserIdAndArticleId(
userId,
articleId,
{
lastViewedAt: new Date(FIXED_DATE + 60 * 1000),
}
);
const updatedDate =
await UserArticleLink.createOrUpdateByUserIdAndArticleId(
userId,
articleId,
{
lastViewedAt: new Date(FIXED_DATE + 60 * 1000),
}
);

delete updatedDate._id;
expect(updatedDate).toMatchSnapshot();
Expand All @@ -80,13 +81,14 @@ describe('userArticleLink', () => {
const userId = 'userId-3';
const articleId = 'articleId-3';

const updatedData = await UserArticleLink.createOrUpdateByUserIdAndArticleId(
userId,
articleId,
{
lastViewedAt: new Date(FIXED_DATE + 60 * 1000),
}
);
const updatedData =
await UserArticleLink.createOrUpdateByUserIdAndArticleId(
userId,
articleId,
{
lastViewedAt: new Date(FIXED_DATE + 60 * 1000),
}
);

delete updatedData._id;
expect(updatedData).toMatchSnapshot();
Expand Down Expand Up @@ -132,7 +134,7 @@ describe('userArticleLink', () => {

const result = await UserArticleLink.findByArticleIds(['a2', 'a1']);

result.forEach(x => delete x._id);
result.forEach((x) => delete x._id);
expect(result).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion src/database/models/__tests__/userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('userSettings', () => {
'userId-3',
'userId-5',
]);
result.forEach(setting => delete setting._id);
result.forEach((setting) => delete setting._id);
expect(result).toMatchSnapshot();
});
});
16 changes: 10 additions & 6 deletions src/database/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default class Base {
* @returns {Promise<import('mongodb').Collection>}
*/
static get client() {
return mongoClient.getInstance().then(e => e.collection(this.collection));
return mongoClient.getInstance().then((e) => e.collection(this.collection));
}

static async collectionExists() {
return mongoClient
.getInstance()
.then(e => e.db.listCollections({ name: this.collection }).hasNext());
.then((e) => e.db.listCollections({ name: this.collection }).hasNext());
}

/**
Expand Down Expand Up @@ -73,9 +73,13 @@ export default class Base {
update['$setOnInsert'] = $setOnInsert;
}

return (await (await this.client).findOneAndUpdate(query, update, {
upsert: true,
returnOriginal: false,
})).value;
return (
await (
await this.client
).findOneAndUpdate(query, update, {
upsert: true,
returnOriginal: false,
})
).value;
}
}
6 changes: 3 additions & 3 deletions src/database/models/schemaValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const ClassTable = {
};

ajv.addKeyword('instanceOf', {
compile: function(className) {
compile: function (className) {
var Class = ClassTable[className];
return function(data) {
return function (data) {
return data instanceof Class;
};
},
});

export function compile(schemaName) {
return data => {
return (data) => {
const validate = ajv.compile(SCHEMAS[schemaName]);
const valid = validate(data);
return { valid, errors: validate.errors };
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/__tests__/insights.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ it('MessagingAPIDate throws error on invalid date', async () => {
`);

const valueResult = await gql`
query($date: MessagingAPIDate!) {
query ($date: MessagingAPIDate!) {
insights {
messageDelivery(date: $date) {
status
Expand Down Expand Up @@ -216,7 +216,7 @@ it('demographic returns demographic data', async () => {
}));

const result = await gql`
query($date: MessagingAPIDate!) {
query ($date: MessagingAPIDate!) {
insights {
demographic(date: $date) {
available
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/__tests__/setViewed.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { gql } from '../testUtils';

it('context rejects anonymous users', async () => {
const result = await gql`
mutation($articleId: String!) {
mutation ($articleId: String!) {
setViewed(articleId: $articleId) {
articleId
}
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('finds', () => {
it('creates user article link with current date', () =>
expect(
gql`
mutation($articleId: String!) {
mutation ($articleId: String!) {
setViewed(articleId: $articleId) {
articleId
lastViewedAt
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/__tests__/userArticleLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('finds', () => {
it('filters by before', () =>
expect(
gql`
query($after: Cursor) {
query ($after: Cursor) {
userArticleLinks(after: $after) {
edges {
cursor
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/cofactsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const cofactsSchema = wrapSchema({
})
),
executor,
transforms: [new RenameTypes(name => `CofactsAPI${name}`)],
transforms: [new RenameTypes((name) => `CofactsAPI${name}`)],
});

export default cofactsSchema;
2 changes: 1 addition & 1 deletion src/graphql/directives/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AuthDirective extends SchemaDirectiveVisitor {
field.resolve = (...args) => {
const [, , context] = args;

check.forEach(checkedField => {
check.forEach((checkedField) => {
if (!context[checkedField]) {
throw new AuthenticationError('Invalid authentication header');
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const schema = stitchSchemas({
CofactsAPIArticle: {
fieldName: 'GetArticle',
selectionSet: '{ id }',
args: articleObj => ({ id: articleObj.id }),
args: (articleObj) => ({ id: articleObj.id }),
},
},
},
Expand Down
10 changes: 4 additions & 6 deletions src/graphql/linebotSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ const lineSchema = makeExecutableSchema({
resolvers: fs
.readdirSync(path.join(__dirname, 'resolvers'))
.reduce((resolvers, fileName) => {
resolvers[
fileName.replace(/\.js$/, '')
] = require(`./resolvers/${fileName}`).default;
resolvers[fileName.replace(/\.js$/, '')] =
require(`./resolvers/${fileName}`).default;
return resolvers;
}, {}),
schemaDirectives: fs
.readdirSync(path.join(__dirname, 'directives'))
.reduce((directives, fileName) => {
directives[
fileName.replace(/\.js$/, '')
] = require(`./directives/${fileName}`).default;
directives[fileName.replace(/\.js$/, '')] =
require(`./directives/${fileName}`).default;
return directives;
}, {}),
resolverValidationOptions: {
Expand Down
6 changes: 3 additions & 3 deletions src/graphql/utils/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export async function processConnection(model, args) {
filter: args.filter || {},
};

const _totalCount = await (await model.client).countDocuments(
normalizedArgs.filter
);
const _totalCount = await (
await model.client
).countDocuments(normalizedArgs.filter);

// setup parent object for the field resolvers
const parent = {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ app.use(session({}, app));
app.use(passport.initialize());
app.use(passport.session());

router.get('/', ctx => {
router.get('/', (ctx) => {
ctx.body = JSON.stringify({ version });
});

Expand Down
6 changes: 3 additions & 3 deletions src/lib/__mocks__/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function gqlMock() {
* @param {*} returnValue the mock value that gql()()'s returned promise will resolve to.
* @returns nothing
*/
gqlMock.__push = function(returnValue) {
gqlMock.__push = function (returnValue) {
mockResultQueue.push(returnValue);
};

Expand All @@ -25,14 +25,14 @@ gqlMock.__push = function(returnValue) {
* Invoking this in afterEach() will ensure 1 failed test would not leave side effects to other
* tests.
*/
gqlMock.__reset = function() {
gqlMock.__reset = function () {
mockResultQueue.length = 0;
};

/**
* @returns {Boolean} if the mock response has been depleted
*/
gqlMock.__finished = function() {
gqlMock.__finished = function () {
return mockResultQueue.length === 0;
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ it('handles syntax error', async () => {
{
foo
}
`().catch(err => err);
`().catch((err) => err);

expect(result).toMatchInlineSnapshot(`[Error: GraphQL Error: Syntax error]`);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/detectDialogflowIntent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const credentials = {
// https://googleapis.dev/nodejs/dialogflow/latest/v2beta1.SessionsClient.html
const sessionClient = new dialogflow.SessionsClient({ credentials });

export default async function(input) {
export default async function (input) {
if (!projectId || !credentials.client_email || !credentials.private_key) {
console.log(
'[Dialogflow] Skip detecting intent, one of env variables not set.'
Expand Down
Loading

0 comments on commit 9a40a19

Please sign in to comment.