From 52400758bf5920fb7f2c42006f4c88dc9b1da2fa Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Fri, 27 Oct 2023 12:55:56 -0700 Subject: [PATCH 01/13] chore(server): Cleanup unused persistent directory --- packages/openneuro-server/src/persistent/datasets/.gitignore | 3 --- packages/openneuro-server/src/persistent/temp/.gitignore | 3 --- 2 files changed, 6 deletions(-) delete mode 100644 packages/openneuro-server/src/persistent/datasets/.gitignore delete mode 100644 packages/openneuro-server/src/persistent/temp/.gitignore diff --git a/packages/openneuro-server/src/persistent/datasets/.gitignore b/packages/openneuro-server/src/persistent/datasets/.gitignore deleted file mode 100644 index acfe97a3e6..0000000000 --- a/packages/openneuro-server/src/persistent/datasets/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Ignore everything in this directory except this file -* -!.gitignore \ No newline at end of file diff --git a/packages/openneuro-server/src/persistent/temp/.gitignore b/packages/openneuro-server/src/persistent/temp/.gitignore deleted file mode 100644 index acfe97a3e6..0000000000 --- a/packages/openneuro-server/src/persistent/temp/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Ignore everything in this directory except this file -* -!.gitignore \ No newline at end of file From e3dc8165b19e5b63e326ba8d0cdef23971c58876 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Fri, 27 Oct 2023 12:56:26 -0700 Subject: [PATCH 02/13] chore(server): Migrate elasticsearch client to typescript --- .../src/elasticsearch/{elastic-client.js => elastic-client.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/openneuro-server/src/elasticsearch/{elastic-client.js => elastic-client.ts} (100%) diff --git a/packages/openneuro-server/src/elasticsearch/elastic-client.js b/packages/openneuro-server/src/elasticsearch/elastic-client.ts similarity index 100% rename from packages/openneuro-server/src/elasticsearch/elastic-client.js rename to packages/openneuro-server/src/elasticsearch/elastic-client.ts From f0480bbee74e829fe64d231868bc91a574031d2b Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Fri, 27 Oct 2023 12:56:48 -0700 Subject: [PATCH 03/13] chore(server): Migrate top level files to typescript --- packages/openneuro-server/src/{config.js => config.ts} | 0 packages/openneuro-server/src/{routes.js => routes.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename packages/openneuro-server/src/{config.js => config.ts} (100%) rename packages/openneuro-server/src/{routes.js => routes.ts} (100%) diff --git a/packages/openneuro-server/src/config.js b/packages/openneuro-server/src/config.ts similarity index 100% rename from packages/openneuro-server/src/config.js rename to packages/openneuro-server/src/config.ts diff --git a/packages/openneuro-server/src/routes.js b/packages/openneuro-server/src/routes.ts similarity index 100% rename from packages/openneuro-server/src/routes.js rename to packages/openneuro-server/src/routes.ts From 08dd5bbc760853f6fc50413e2ad2fb0f227bfa93 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 10:32:53 -0700 Subject: [PATCH 04/13] chore(server): Remove unused server util scripts --- .../src/graphql/resolvers/user.js | 2 - packages/openneuro-server/src/libs/request.js | 155 ------------------ packages/openneuro-server/src/libs/scitran.js | 25 --- .../src/libs/testing-utils.js | 17 -- 4 files changed, 199 deletions(-) delete mode 100644 packages/openneuro-server/src/libs/request.js delete mode 100644 packages/openneuro-server/src/libs/scitran.js delete mode 100644 packages/openneuro-server/src/libs/testing-utils.js diff --git a/packages/openneuro-server/src/graphql/resolvers/user.js b/packages/openneuro-server/src/graphql/resolvers/user.js index d092262345..7f1d8a5883 100644 --- a/packages/openneuro-server/src/graphql/resolvers/user.js +++ b/packages/openneuro-server/src/graphql/resolvers/user.js @@ -1,7 +1,5 @@ /** * User resolvers - * - * These are passthroughs to SciTran until we have authentication working internally */ import User from '../../models/user' diff --git a/packages/openneuro-server/src/libs/request.js b/packages/openneuro-server/src/libs/request.js deleted file mode 100644 index 714d703bc3..0000000000 --- a/packages/openneuro-server/src/libs/request.js +++ /dev/null @@ -1,155 +0,0 @@ -import request from 'request' - -/** - * Parse Options - * - * Normalizes request options. - */ -function parseOptions(req, options) { - if (options.query) { - req.qs = options.query - } - if (options.body) { - req.json = options.body - } - if (options.hasOwnProperty('encoding')) { - req.encoding = options.encoding - } - if (options.headers) { - for (const key in options.headers) { - req.headers[key] = options.headers[key] - } - } - return req -} - -/** - * Handle Request - * - * Processes all requests before they fire. - */ -function handleRequest(url, options, callback) { - let req = { - url: url, - headers: {}, - qs: {}, - json: {}, - } - - req = parseOptions(req, options) - callback(req) -} - -/** - * Handle Response - * - * Process all responses before they return - * to the callback. - */ -function handleResponse(err, res, callback) { - callback(err, res) -} - -/** - * Request - * - * A wrapper of npm 'request' to allow for - * genericizing request and response manipulations. - */ -export default { - get(url, options, callback) { - handleRequest(url, options, req => { - request.get(req, (err, res) => { - handleResponse(err, res, callback) - }) - }) - }, - - /** - * GET CACHE - * - * Functions the same as request but takes a - * cache function, checks to see if the response is - * already cached. If so, responds with the cached data. - * If not, stores the response in the cache before responding. - */ - getCache(url, cache, options, callback) { - handleRequest(url, options, req => { - cache.get(req, (err, res1) => { - if (res1) { - handleResponse(err, res1, callback) - } else { - request.get(req, (err, res2) => { - if (err) { - handleResponse(err, res2, callback) - } else { - const data = res2.body - cache.store(data, () => { - handleResponse(err, res2, callback) - }) - } - }) - } - }) - }) - }, - - postCache(url, cache, options, callback) { - handleRequest(url, options, req => { - request.post(req, (err, res) => { - if (err) { - handleResponse(err, res, callback) - } else { - const data = req.json - cache.store(data, () => { - handleResponse(err, res, callback) - }) - } - }) - }) - }, - - /** - * GET PROXY - * - * Functions the same as a get request but takes a - * response object instead of a callback and pipes - * the request response to the response object. - */ - getProxy(url, options, res) { - handleRequest(url, options, req => { - request - .get(req) - .on('data', resp => { - if (options.status) { - resp.statusCode = options.status - } - }) - .pipe(res) - }) - }, - - post(url, options, callback) { - handleRequest(url, options, req => { - request.post(req, (err, res) => { - handleResponse(err, res, callback) - }) - }) - }, - - put(url, options, callback) { - handleRequest(url, options, req => { - request.put(req, (err, res) => { - handleResponse(err, res, callback) - }) - }) - }, - - del(url, options, callback) { - handleRequest(url, options, req => { - request.del(req, (err, res) => { - handleResponse(err, res, callback) - }) - }) - }, -} diff --git a/packages/openneuro-server/src/libs/scitran.js b/packages/openneuro-server/src/libs/scitran.js deleted file mode 100644 index c7ede29540..0000000000 --- a/packages/openneuro-server/src/libs/scitran.js +++ /dev/null @@ -1,25 +0,0 @@ -import User from '../models/user' - -/** - * Scitran - * - * A library for interactions with the - * scitran API. - */ -export default { - /** - * Get User - */ - getUser(userId, callback) { - // Updated to use internal authentication - User.findOne({ id: userId }) - .then(user => { - // Mock the SciTran response - const userResponse = { body: { ...user, _id: user.id } } - callback(null, { body: userResponse }) - }) - .catch(err => { - callback(err) - }) - }, -} diff --git a/packages/openneuro-server/src/libs/testing-utils.js b/packages/openneuro-server/src/libs/testing-utils.js deleted file mode 100644 index 54e105ff56..0000000000 --- a/packages/openneuro-server/src/libs/testing-utils.js +++ /dev/null @@ -1,17 +0,0 @@ -import http from 'http' - -export default { - ok(res) { - if (res.status !== 200) { - const b = http.STATUS_CODES[res.status] - return new Error( - 'expected 200, got ' + - res.status + - ' "' + - b + - '" with message: ' + - res.text, - ) - } - }, -} From 16a66713627c303268bafa73e2c7d15a47ad68b3 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 10:47:33 -0700 Subject: [PATCH 05/13] chore(server): Migrate top level libs to TypeScript --- packages/openneuro-server/src/libs/{apikey.js => apikey.ts} | 2 +- packages/openneuro-server/src/libs/authentication/passport.js | 4 ++-- packages/openneuro-server/src/libs/{bidsId.js => bidsId.ts} | 0 packages/openneuro-server/src/libs/{counter.js => counter.ts} | 0 .../src/libs/{datalad-service.js => datalad-service.ts} | 0 packages/openneuro-server/src/libs/{dataset.js => dataset.ts} | 0 .../src/libs/{notifications.js => notifications.ts} | 0 packages/openneuro-server/src/libs/{orcid.js => orcid.ts} | 0 packages/openneuro-server/src/libs/{redis.js => redis.ts} | 0 9 files changed, 3 insertions(+), 3 deletions(-) rename packages/openneuro-server/src/libs/{apikey.js => apikey.ts} (91%) rename packages/openneuro-server/src/libs/{bidsId.js => bidsId.ts} (100%) rename packages/openneuro-server/src/libs/{counter.js => counter.ts} (100%) rename packages/openneuro-server/src/libs/{datalad-service.js => datalad-service.ts} (100%) rename packages/openneuro-server/src/libs/{dataset.js => dataset.ts} (100%) rename packages/openneuro-server/src/libs/{notifications.js => notifications.ts} (100%) rename packages/openneuro-server/src/libs/{orcid.js => orcid.ts} (100%) rename packages/openneuro-server/src/libs/{redis.js => redis.ts} (100%) diff --git a/packages/openneuro-server/src/libs/apikey.js b/packages/openneuro-server/src/libs/apikey.ts similarity index 91% rename from packages/openneuro-server/src/libs/apikey.js rename to packages/openneuro-server/src/libs/apikey.ts index 888adf7010..cc2719027a 100644 --- a/packages/openneuro-server/src/libs/apikey.js +++ b/packages/openneuro-server/src/libs/apikey.ts @@ -1,5 +1,5 @@ import Key from '../models/key' -import { addJWT } from '../libs/authentication/jwt' +import { addJWT } from './authentication/jwt' import config from '../config' export const apiKeyFactory = user => { diff --git a/packages/openneuro-server/src/libs/authentication/passport.js b/packages/openneuro-server/src/libs/authentication/passport.js index 6eaf3fe06b..4c01151006 100644 --- a/packages/openneuro-server/src/libs/authentication/passport.js +++ b/packages/openneuro-server/src/libs/authentication/passport.js @@ -3,11 +3,11 @@ import refresh from 'passport-oauth2-refresh' import { Strategy as JwtStrategy } from 'passport-jwt' import { Strategy as GoogleStrategy } from 'passport-google-oauth20' import { Strategy as ORCIDStrategy } from 'passport-orcid' -import config from '../../config.js' +import config from '../../config' import User from '../../models/user' import { encrypt } from './crypto' import { addJWT, jwtFromRequest } from './jwt' -import orcid from '../orcid.js' +import orcid from '../orcid' const PROVIDERS = { GOOGLE: 'google', diff --git a/packages/openneuro-server/src/libs/bidsId.js b/packages/openneuro-server/src/libs/bidsId.ts similarity index 100% rename from packages/openneuro-server/src/libs/bidsId.js rename to packages/openneuro-server/src/libs/bidsId.ts diff --git a/packages/openneuro-server/src/libs/counter.js b/packages/openneuro-server/src/libs/counter.ts similarity index 100% rename from packages/openneuro-server/src/libs/counter.js rename to packages/openneuro-server/src/libs/counter.ts diff --git a/packages/openneuro-server/src/libs/datalad-service.js b/packages/openneuro-server/src/libs/datalad-service.ts similarity index 100% rename from packages/openneuro-server/src/libs/datalad-service.js rename to packages/openneuro-server/src/libs/datalad-service.ts diff --git a/packages/openneuro-server/src/libs/dataset.js b/packages/openneuro-server/src/libs/dataset.ts similarity index 100% rename from packages/openneuro-server/src/libs/dataset.js rename to packages/openneuro-server/src/libs/dataset.ts diff --git a/packages/openneuro-server/src/libs/notifications.js b/packages/openneuro-server/src/libs/notifications.ts similarity index 100% rename from packages/openneuro-server/src/libs/notifications.js rename to packages/openneuro-server/src/libs/notifications.ts diff --git a/packages/openneuro-server/src/libs/orcid.js b/packages/openneuro-server/src/libs/orcid.ts similarity index 100% rename from packages/openneuro-server/src/libs/orcid.js rename to packages/openneuro-server/src/libs/orcid.ts diff --git a/packages/openneuro-server/src/libs/redis.js b/packages/openneuro-server/src/libs/redis.ts similarity index 100% rename from packages/openneuro-server/src/libs/redis.js rename to packages/openneuro-server/src/libs/redis.ts From 1ca85116d007ab78c2e9598a11aaf16ed21d611e Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 10:50:22 -0700 Subject: [PATCH 06/13] chore(server): Cleanup SciTran support for hex encoded datasetIds --- .../src/libs/authentication/states.js | 5 +- packages/openneuro-server/src/libs/bidsId.ts | 68 ------------------- .../src/libs/notifications.ts | 36 +++++----- 3 files changed, 17 insertions(+), 92 deletions(-) delete mode 100644 packages/openneuro-server/src/libs/bidsId.ts diff --git a/packages/openneuro-server/src/libs/authentication/states.js b/packages/openneuro-server/src/libs/authentication/states.js index df6403ae2b..07b9985d26 100644 --- a/packages/openneuro-server/src/libs/authentication/states.js +++ b/packages/openneuro-server/src/libs/authentication/states.js @@ -3,7 +3,6 @@ import Dataset from '../../models/dataset' import Permission from '../../models/permission' import Comment from '../../models/comment' -import bidsId from '../bidsId' import mongoose from 'mongoose' const ObjectID = mongoose.Schema.Types.ObjectId @@ -61,12 +60,10 @@ export const superuser = (req, res, next) => { * the request object. */ export const datasetAccess = (req, res, next) => { - let datasetId = req.params.datasetId + const datasetId = req.params.datasetId ? req.params.datasetId : req.query.datasetId - datasetId = bidsId.decodeId(datasetId) // handle old dataset request methods that encode ids - // check to make sure that the dataset exists return Dataset.findOne({ id: datasetId }) .exec() diff --git a/packages/openneuro-server/src/libs/bidsId.ts b/packages/openneuro-server/src/libs/bidsId.ts deleted file mode 100644 index 2288e502ab..0000000000 --- a/packages/openneuro-server/src/libs/bidsId.ts +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Hex - * - * Utils for dealing with hex encoding - */ -export default { - hexToASCII(hexString) { - const hex = hexString.toString() - let str = '' - for (let n = 0; n < hex.length; n += 2) { - str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)) - } - return str - }, - - hexFromASCII(string) { - return string - .split('') - .map(c => { - return ('0' + c.charCodeAt(0).toString(16)).slice(-2) - }) - .join('') - }, - - encodeId(id) { - if (/ds\d{6}/.test(id)) { - return this.hexFromASCII(' ' + id) - } else if (/\d{6}-\d{5}/.test(id)) { - return this.hexFromASCII(id) - } else { - return id - } - }, - - decodeId(id) { - const decodedId = this.hexToASCII(id) - if (/\s{4}ds\d{6}/.test(decodedId)) { - return decodedId.slice(4) - } else if (/\d{6}-\d{5}/.test(decodedId)) { - return decodedId.slice(7) - } - return id - }, - - decode(id) { - const decodedId = this.hexToASCII(id) - let datasetId = null - let tag = null - // decodes the two different formats of storing dataset + snapshot tag - if (/\s{4}ds\d{6}/.test(decodedId)) { - datasetId = decodedId.slice(4) - } else if (/\d{6}-\d{5}/.test(decodedId)) { - tag = decodedId.slice(7) - datasetId = 'ds' + decodedId.slice(0, 6) - } else { - // handles all these old dataset ids that start with 57 or 58 - if (id.startsWith('57') || id.startsWith('58')) { - datasetId = id - } else { - // if the id is of the proper length but has no ds, add ds. - // otherwise, add it is short and needs a 0 as well - const beginning = id.length == 6 ? 'ds' : 'ds0' - datasetId = beginning + id - } - } - return { datasetId, tag } - }, -} diff --git a/packages/openneuro-server/src/libs/notifications.ts b/packages/openneuro-server/src/libs/notifications.ts index bb56e929c8..9a7dd1640a 100644 --- a/packages/openneuro-server/src/libs/notifications.ts +++ b/packages/openneuro-server/src/libs/notifications.ts @@ -6,17 +6,16 @@ import User from '../models/user' import Subscription from '../models/subscription' import { format } from 'date-fns' import url from 'url' -import bidsId from './bidsId' import { convertFromRaw, EditorState } from 'draft-js' import { stateToHTML } from 'draft-js-export-html' -import { getDatasetWorker } from '../libs/datalad-service' -import { commentCreated } from '../libs/email/templates/comment-created' -import { datasetDeleted } from '../libs/email/templates/dataset-deleted' -import { ownerUnsubscribed } from '../libs/email/templates/owner-unsubscribed' -import { snapshotCreated } from '../libs/email/templates/snapshot-created' -import { snapshotReminder } from '../libs/email/templates/snapshot-reminder' -import { datasetImportEmail } from '../libs/email/templates/dataset-imported' -import { datasetImportFailed } from '../libs/email/templates/dataset-import-failed' +import { getDatasetWorker } from './datalad-service' +import { commentCreated } from './email/templates/comment-created' +import { datasetDeleted } from './email/templates/dataset-deleted' +import { ownerUnsubscribed } from './email/templates/owner-unsubscribed' +import { snapshotCreated } from './email/templates/snapshot-created' +import { snapshotReminder } from './email/templates/snapshot-reminder' +import { datasetImportEmail } from './email/templates/dataset-imported' +import { datasetImportFailed } from './email/templates/dataset-import-failed' // public api --------------------------------------------- @@ -75,7 +74,7 @@ const notifications = { html: snapshotCreated({ name: user.name, datasetLabel: datasetLabel, - datasetId: bidsId.decodeId(datasetId), + datasetId: datasetId, versionNumber: tag, changelog: changelog, siteUrl: @@ -146,7 +145,7 @@ const notifications = { subject: 'Comment Created', html: commentCreated({ name: user.name, - datasetName: bidsId.decodeId(datasetId), + datasetName: datasetId, datasetLabel: datasetLabel, commentUserId: userId, commentId: commentId, @@ -176,10 +175,7 @@ const notifications = { * them that a the dataset has been deleted. */ datasetDeleted(datasetId) { - console.log( - 'datasetDeleted notification sent with datasetName:', - bidsId.decodeId(datasetId), - ) + console.log('datasetDeleted notification sent with datasetName:', datasetId) // get all users that are subscribed to the dataset Subscription.find({ datasetId: datasetId }) @@ -205,7 +201,7 @@ const notifications = { subject: 'Dataset Deleted', html: datasetDeleted({ name: user.name, - datasetName: bidsId.decodeId(datasetId), + datasetName: datasetId, siteUrl: url.parse(config.url).protocol + '//' + @@ -230,7 +226,7 @@ const notifications = { ownerUnsubscribed(datasetId) { console.log( 'ownerUnsubscribed notification sent with datasetName:', - bidsId.decodeId(datasetId), + datasetId, ) // get all users that are subscribed to the dataset @@ -257,7 +253,7 @@ const notifications = { subject: 'Owner Unsubscribed', html: ownerUnsubscribed({ name: user.name, - datasetName: bidsId.decodeId(datasetId), + datasetName: datasetId, siteUrl: url.parse(config.url).protocol + '//' + @@ -282,7 +278,7 @@ const notifications = { async snapshotReminder(datasetId) { console.log( 'snapshotReminder notification sent with datasetName:', - bidsId.decodeId(datasetId), + datasetId, ) // get all users that are subscribed to the dataset @@ -309,7 +305,7 @@ const notifications = { subject: 'Snapshot Reminder', html: snapshotReminder({ name: user.name, - datasetName: bidsId.decodeId(datasetId), + datasetName: datasetId, siteUrl: url.parse(config.url).protocol + '//' + From 82a2cbf81039304c8f2371c8f1da6a03dc2b5e59 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 10:53:25 -0700 Subject: [PATCH 07/13] chore(server): Migrate authentication lib to TypeScript --- .../openneuro-server/src/datalad/dataset.js | 2 +- .../authentication/{crypto.js => crypto.ts} | 0 .../src/libs/authentication/globus.js | 11 ---------- .../authentication/{google.js => google.ts} | 5 ++--- .../authentication/{orcid.js => orcid.ts} | 0 .../{passport.js => passport.ts} | 21 ++++++++++++++++--- .../authentication/{states.js => states.ts} | 0 .../{verifyUser.js => verifyUser.ts} | 0 packages/openneuro-server/src/routes.ts | 8 +++---- 9 files changed, 25 insertions(+), 22 deletions(-) rename packages/openneuro-server/src/libs/authentication/{crypto.js => crypto.ts} (100%) delete mode 100644 packages/openneuro-server/src/libs/authentication/globus.js rename packages/openneuro-server/src/libs/authentication/{google.js => google.ts} (81%) rename packages/openneuro-server/src/libs/authentication/{orcid.js => orcid.ts} (100%) rename packages/openneuro-server/src/libs/authentication/{passport.js => passport.ts} (92%) rename packages/openneuro-server/src/libs/authentication/{states.js => states.ts} (100%) rename packages/openneuro-server/src/libs/authentication/{verifyUser.js => verifyUser.ts} (100%) diff --git a/packages/openneuro-server/src/datalad/dataset.js b/packages/openneuro-server/src/datalad/dataset.js index 328edfb01f..3a565fcbe3 100644 --- a/packages/openneuro-server/src/datalad/dataset.js +++ b/packages/openneuro-server/src/datalad/dataset.js @@ -14,7 +14,7 @@ import { redis } from '../libs/redis' import CacheItem, { CacheType } from '../cache/item' import { updateDatasetRevision } from './draft.js' import { fileUrl, getFileName, encodeFilePath, filesUrl } from './files' -import { getAccessionNumber } from '../libs/dataset.js' +import { getAccessionNumber } from '../libs/dataset' import Dataset from '../models/dataset' import Metadata from '../models/metadata' import Permission from '../models/permission' diff --git a/packages/openneuro-server/src/libs/authentication/crypto.js b/packages/openneuro-server/src/libs/authentication/crypto.ts similarity index 100% rename from packages/openneuro-server/src/libs/authentication/crypto.js rename to packages/openneuro-server/src/libs/authentication/crypto.ts diff --git a/packages/openneuro-server/src/libs/authentication/globus.js b/packages/openneuro-server/src/libs/authentication/globus.js deleted file mode 100644 index 2032fdbc31..0000000000 --- a/packages/openneuro-server/src/libs/authentication/globus.js +++ /dev/null @@ -1,11 +0,0 @@ -import passport from 'passport' - -export const requestAuth = passport.authenticate('globus', { - scope: ['profile', 'email', 'openid'], - session: false, -}) - -export const authCallback = passport.authenticate('globus', { - failureRedirect: '/', - session: false, -}) diff --git a/packages/openneuro-server/src/libs/authentication/google.js b/packages/openneuro-server/src/libs/authentication/google.ts similarity index 81% rename from packages/openneuro-server/src/libs/authentication/google.js rename to packages/openneuro-server/src/libs/authentication/google.ts index 597b212763..9c52205d98 100644 --- a/packages/openneuro-server/src/libs/authentication/google.js +++ b/packages/openneuro-server/src/libs/authentication/google.ts @@ -1,6 +1,6 @@ import passport from 'passport' -export const requestAuth = (req, res, next) => ( +export const requestAuth = (req, res, next) => passport.authenticate('google', { scope: [ 'https://www.googleapis.com/auth/userinfo.email', @@ -9,9 +9,8 @@ export const requestAuth = (req, res, next) => ( session: false, accessType: 'offline', prompt: 'consent', - state: req.query.redirectPath || null + state: req.query.redirectPath || null, })(req, res, next) -) export const authCallback = passport.authenticate('google', { failureRedirect: '/', diff --git a/packages/openneuro-server/src/libs/authentication/orcid.js b/packages/openneuro-server/src/libs/authentication/orcid.ts similarity index 100% rename from packages/openneuro-server/src/libs/authentication/orcid.js rename to packages/openneuro-server/src/libs/authentication/orcid.ts diff --git a/packages/openneuro-server/src/libs/authentication/passport.js b/packages/openneuro-server/src/libs/authentication/passport.ts similarity index 92% rename from packages/openneuro-server/src/libs/authentication/passport.js rename to packages/openneuro-server/src/libs/authentication/passport.ts index 4c01151006..3e91d9e1eb 100644 --- a/packages/openneuro-server/src/libs/authentication/passport.js +++ b/packages/openneuro-server/src/libs/authentication/passport.ts @@ -14,7 +14,16 @@ const PROVIDERS = { ORCID: 'orcid', } -const loadProfile = profile => { +interface OauthProfile { + email: string + name: string + provider: string + providerId: string + orcid?: string + refresh?: string +} + +const loadProfile = (profile): OauthProfile | Error => { if (profile.provider === PROVIDERS.GOOGLE) { // Get the account email from Google profile const primaryEmail = profile.emails @@ -25,6 +34,7 @@ const loadProfile = profile => { name: profile.displayName, provider: profile.provider, providerId: profile.id, + refresh: undefined, } } else if (profile.provider === PROVIDERS.ORCID) { return { @@ -33,6 +43,7 @@ const loadProfile = profile => { provider: profile.provider, providerId: profile.orcid, orcid: profile.orcid, + refresh: undefined, } } else { // Some unknown profile type @@ -55,8 +66,12 @@ export const verifyGoogleUser = (accessToken, refreshToken, profile, done) => { profileUpdate, { upsert: true, new: true, setDefaultsOnInsert: true }, ) - .then(user => done(null, addJWT(config)(user.toObject()))) - .catch(err => done(err, null)) + .then(user => { + done(null, addJWT(config)(user.toObject())) + }) + .catch(err => { + done(err, null) + }) } else { done(profileUpdate, null) } diff --git a/packages/openneuro-server/src/libs/authentication/states.js b/packages/openneuro-server/src/libs/authentication/states.ts similarity index 100% rename from packages/openneuro-server/src/libs/authentication/states.js rename to packages/openneuro-server/src/libs/authentication/states.ts diff --git a/packages/openneuro-server/src/libs/authentication/verifyUser.js b/packages/openneuro-server/src/libs/authentication/verifyUser.ts similarity index 100% rename from packages/openneuro-server/src/libs/authentication/verifyUser.js rename to packages/openneuro-server/src/libs/authentication/verifyUser.ts diff --git a/packages/openneuro-server/src/routes.ts b/packages/openneuro-server/src/routes.ts index 4760e59046..9d75671f98 100644 --- a/packages/openneuro-server/src/routes.ts +++ b/packages/openneuro-server/src/routes.ts @@ -6,11 +6,11 @@ import * as datalad from './handlers/datalad' import * as comments from './handlers/comments' import { clientConfig } from './handlers/config.js' import * as subscriptions from './handlers/subscriptions' -import verifyUser from './libs/authentication/verifyUser.js' -import * as google from './libs/authentication/google.js' -import * as orcid from './libs/authentication/orcid.js' +import verifyUser from './libs/authentication/verifyUser' +import * as google from './libs/authentication/google' +import * as orcid from './libs/authentication/orcid' import * as jwt from './libs/authentication/jwt' -import * as auth from './libs/authentication/states.js' +import * as auth from './libs/authentication/states' import * as doi from './handlers/doi' import { sitemapHandler } from './handlers/sitemap.js' import { reviewerHandler } from './handlers/reviewer' From f2201ac6ac8e0a9da73860864266b4c2255fb8ac Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 10:59:06 -0700 Subject: [PATCH 08/13] chore(server): Migrate DOI library to TypeScript --- .../src/libs/doi/__tests__/{doi.spec.js => doi.spec.ts} | 1 + packages/openneuro-server/src/libs/doi/{index.js => index.ts} | 0 2 files changed, 1 insertion(+) rename packages/openneuro-server/src/libs/doi/__tests__/{doi.spec.js => doi.spec.ts} (95%) rename packages/openneuro-server/src/libs/doi/{index.js => index.ts} (100%) diff --git a/packages/openneuro-server/src/libs/doi/__tests__/doi.spec.js b/packages/openneuro-server/src/libs/doi/__tests__/doi.spec.ts similarity index 95% rename from packages/openneuro-server/src/libs/doi/__tests__/doi.spec.js rename to packages/openneuro-server/src/libs/doi/__tests__/doi.spec.ts index d96ae049ec..b61386f902 100644 --- a/packages/openneuro-server/src/libs/doi/__tests__/doi.spec.js +++ b/packages/openneuro-server/src/libs/doi/__tests__/doi.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { template, formatBasicAuth } from '../index.js' vi.mock('ioredis') diff --git a/packages/openneuro-server/src/libs/doi/index.js b/packages/openneuro-server/src/libs/doi/index.ts similarity index 100% rename from packages/openneuro-server/src/libs/doi/index.js rename to packages/openneuro-server/src/libs/doi/index.ts From 1413fd7972f4977549a64c70d59a203127fc2c48 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 11:00:05 -0700 Subject: [PATCH 09/13] chore(server): Migrate tests to TypeScript --- .../src/libs/__tests__/{apikey.spec.js => apikey.spec.ts} | 1 + .../{datalad-service.spec.js => datalad-service.spec.ts} | 1 + .../src/libs/__tests__/{dataset.spec.js => dataset.spec.ts} | 0 3 files changed, 2 insertions(+) rename packages/openneuro-server/src/libs/__tests__/{apikey.spec.js => apikey.spec.ts} (95%) rename packages/openneuro-server/src/libs/__tests__/{datalad-service.spec.js => datalad-service.spec.ts} (97%) rename packages/openneuro-server/src/libs/__tests__/{dataset.spec.js => dataset.spec.ts} (100%) diff --git a/packages/openneuro-server/src/libs/__tests__/apikey.spec.js b/packages/openneuro-server/src/libs/__tests__/apikey.spec.ts similarity index 95% rename from packages/openneuro-server/src/libs/__tests__/apikey.spec.js rename to packages/openneuro-server/src/libs/__tests__/apikey.spec.ts index 0acfbf5d07..41d389878f 100644 --- a/packages/openneuro-server/src/libs/__tests__/apikey.spec.js +++ b/packages/openneuro-server/src/libs/__tests__/apikey.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import jwt from 'jsonwebtoken' import { apiKeyFactory } from '../apikey.js' import config from '../../config.js' diff --git a/packages/openneuro-server/src/libs/__tests__/datalad-service.spec.js b/packages/openneuro-server/src/libs/__tests__/datalad-service.spec.ts similarity index 97% rename from packages/openneuro-server/src/libs/__tests__/datalad-service.spec.js rename to packages/openneuro-server/src/libs/__tests__/datalad-service.spec.ts index 217c22dcce..3769aaebcb 100644 --- a/packages/openneuro-server/src/libs/__tests__/datalad-service.spec.js +++ b/packages/openneuro-server/src/libs/__tests__/datalad-service.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { hashDatasetToRange } from '../datalad-service' vi.mock('ioredis') diff --git a/packages/openneuro-server/src/libs/__tests__/dataset.spec.js b/packages/openneuro-server/src/libs/__tests__/dataset.spec.ts similarity index 100% rename from packages/openneuro-server/src/libs/__tests__/dataset.spec.js rename to packages/openneuro-server/src/libs/__tests__/dataset.spec.ts From a6d2f88683f2ed43520c69ab9b5a740955477742 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 11:13:18 -0700 Subject: [PATCH 10/13] chore(server): Migrate worker APIs to TypeScript --- .../{changelog.spec.js => changelog.spec.ts} | 1 + .../__tests__/{dataset.spec.js => dataset.spec.ts} | 0 .../{description.spec.js => description.spec.ts} | 4 ++++ .../__tests__/{files.spec.js => files.spec.ts} | 2 ++ .../{pagination.spec.js => pagination.spec.ts} | 0 .../{snapshots.spec.js => snapshots.spec.ts} | 2 +- .../src/datalad/{analytics.js => analytics.ts} | 0 .../src/datalad/{changelog.js => changelog.ts} | 0 .../src/datalad/{dataset.js => dataset.ts} | 7 ++++--- .../src/datalad/{description.js => description.ts} | 0 .../src/datalad/{draft.js => draft.ts} | 0 .../src/datalad/{pagination.js => pagination.ts} | 0 .../src/datalad/{readme.js => readme.ts} | 0 .../src/datalad/{reexporter.js => reexporter.ts} | 0 .../src/datalad/{snapshots.js => snapshots.ts} | 11 +++++++---- .../src/datalad/{upload.js => upload.ts} | 0 16 files changed, 19 insertions(+), 8 deletions(-) rename packages/openneuro-server/src/datalad/__tests__/{changelog.spec.js => changelog.spec.ts} (99%) rename packages/openneuro-server/src/datalad/__tests__/{dataset.spec.js => dataset.spec.ts} (100%) rename packages/openneuro-server/src/datalad/__tests__/{description.spec.js => description.spec.ts} (96%) rename packages/openneuro-server/src/datalad/__tests__/{files.spec.js => files.spec.ts} (96%) rename packages/openneuro-server/src/datalad/__tests__/{pagination.spec.js => pagination.spec.ts} (100%) rename packages/openneuro-server/src/datalad/__tests__/{snapshots.spec.js => snapshots.spec.ts} (95%) rename packages/openneuro-server/src/datalad/{analytics.js => analytics.ts} (100%) rename packages/openneuro-server/src/datalad/{changelog.js => changelog.ts} (100%) rename packages/openneuro-server/src/datalad/{dataset.js => dataset.ts} (98%) rename packages/openneuro-server/src/datalad/{description.js => description.ts} (100%) rename packages/openneuro-server/src/datalad/{draft.js => draft.ts} (100%) rename packages/openneuro-server/src/datalad/{pagination.js => pagination.ts} (100%) rename packages/openneuro-server/src/datalad/{readme.js => readme.ts} (100%) rename packages/openneuro-server/src/datalad/{reexporter.js => reexporter.ts} (100%) rename packages/openneuro-server/src/datalad/{snapshots.js => snapshots.ts} (96%) rename packages/openneuro-server/src/datalad/{upload.js => upload.ts} (100%) diff --git a/packages/openneuro-server/src/datalad/__tests__/changelog.spec.js b/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts similarity index 99% rename from packages/openneuro-server/src/datalad/__tests__/changelog.spec.js rename to packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts index ae0dd0c2f5..6ef842bd98 100644 --- a/packages/openneuro-server/src/datalad/__tests__/changelog.spec.js +++ b/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import * as changelog from '../changelog.js' vi.mock('ioredis') diff --git a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.js b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts similarity index 100% rename from packages/openneuro-server/src/datalad/__tests__/dataset.spec.js rename to packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts diff --git a/packages/openneuro-server/src/datalad/__tests__/description.spec.js b/packages/openneuro-server/src/datalad/__tests__/description.spec.ts similarity index 96% rename from packages/openneuro-server/src/datalad/__tests__/description.spec.js rename to packages/openneuro-server/src/datalad/__tests__/description.spec.ts index a0487a5afb..2aada727e7 100644 --- a/packages/openneuro-server/src/datalad/__tests__/description.spec.js +++ b/packages/openneuro-server/src/datalad/__tests__/description.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { getDescriptionObject, repairDescriptionTypes, @@ -92,6 +93,7 @@ describe('datalad dataset descriptions', () => { global.fetch = vi.fn() }) it('returns the parsed dataset_description.json object', async () => { + // @ts-expect-error Fetch mock includes mockResolvedValue fetch.mockResolvedValue({ json: () => Promise.resolve({ Name: 'Balloon Analog Risk-taking Task' }), @@ -105,6 +107,7 @@ describe('datalad dataset descriptions', () => { }) it('handles a corrupted response', async () => { global.fetch = vi.fn() + // @ts-expect-error Fetch mock includes mockResolvedValue fetch.mockResolvedValue({ json: () => Promise.reject('JSON could not be parsed'), headers: { @@ -120,6 +123,7 @@ describe('datalad dataset descriptions', () => { }) it('throws an error when nothing is returned', async () => { global.fetch = vi.fn() + // @ts-expect-error Fetch mock includes mockResolvedValue fetch.mockResolvedValue({ json: () => Promise.reject('JSON could not be parsed'), headers: { diff --git a/packages/openneuro-server/src/datalad/__tests__/files.spec.js b/packages/openneuro-server/src/datalad/__tests__/files.spec.ts similarity index 96% rename from packages/openneuro-server/src/datalad/__tests__/files.spec.js rename to packages/openneuro-server/src/datalad/__tests__/files.spec.ts index d9e97ff481..9cd108e212 100644 --- a/packages/openneuro-server/src/datalad/__tests__/files.spec.js +++ b/packages/openneuro-server/src/datalad/__tests__/files.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { encodeFilePath, decodeFilePath, @@ -69,6 +70,7 @@ describe('datalad files', () => { size: 1945682, }, ] + // @ts-expect-error Test is mocking this expect(computeTotalSize(mockFileSizes)).toBe(1957206) }) }) diff --git a/packages/openneuro-server/src/datalad/__tests__/pagination.spec.js b/packages/openneuro-server/src/datalad/__tests__/pagination.spec.ts similarity index 100% rename from packages/openneuro-server/src/datalad/__tests__/pagination.spec.js rename to packages/openneuro-server/src/datalad/__tests__/pagination.spec.ts diff --git a/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.js b/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts similarity index 95% rename from packages/openneuro-server/src/datalad/__tests__/snapshots.spec.js rename to packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts index 9a15dce97b..b401606cd0 100644 --- a/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.js +++ b/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts @@ -3,7 +3,7 @@ vi.mock('ioredis') import request from 'superagent' import { createDataset } from '../dataset.js' import { createSnapshot } from '../snapshots.js' -import { getDatasetWorker } from '../../libs/datalad-service' +import { getDatasetWorker } from '../../libs/datalad-service.js' import { connect } from 'mongoose' // Mock requests to Datalad service diff --git a/packages/openneuro-server/src/datalad/analytics.js b/packages/openneuro-server/src/datalad/analytics.ts similarity index 100% rename from packages/openneuro-server/src/datalad/analytics.js rename to packages/openneuro-server/src/datalad/analytics.ts diff --git a/packages/openneuro-server/src/datalad/changelog.js b/packages/openneuro-server/src/datalad/changelog.ts similarity index 100% rename from packages/openneuro-server/src/datalad/changelog.js rename to packages/openneuro-server/src/datalad/changelog.ts diff --git a/packages/openneuro-server/src/datalad/dataset.js b/packages/openneuro-server/src/datalad/dataset.ts similarity index 98% rename from packages/openneuro-server/src/datalad/dataset.js rename to packages/openneuro-server/src/datalad/dataset.ts index 3a565fcbe3..96703118bf 100644 --- a/packages/openneuro-server/src/datalad/dataset.js +++ b/packages/openneuro-server/src/datalad/dataset.ts @@ -7,12 +7,13 @@ import request from 'superagent' import requestNode from 'request' import objectHash from 'object-hash' import { Readable } from 'stream' +import * as Mongoose from 'mongoose' import config from '../config' import * as subscriptions from '../handlers/subscriptions.js' import { generateDataladCookie } from '../libs/authentication/jwt' import { redis } from '../libs/redis' import CacheItem, { CacheType } from '../cache/item' -import { updateDatasetRevision } from './draft.js' +import { updateDatasetRevision } from './draft' import { fileUrl, getFileName, encodeFilePath, filesUrl } from './files' import { getAccessionNumber } from '../libs/dataset' import Dataset from '../models/dataset' @@ -119,7 +120,7 @@ export const cacheDatasetConnection = options => connectionArguments => { * @param {object} match MongoDB $match aggregate * @returns {Array} Array of MongoDB aggregate pipelines */ -const aggregateArraySetup = match => [{ $match: match }] +const aggregateArraySetup = (match): Mongoose.Expression => [{ $match: match }] /** * Add any filter steps based on the filterBy options provided @@ -157,7 +158,7 @@ export const datasetsFilter = options => match => { ) return aggregates } - const filterMatch = {} + const filterMatch: Mongoose.Expression = {} if ('filterBy' in options) { const filters = options.filterBy if ( diff --git a/packages/openneuro-server/src/datalad/description.js b/packages/openneuro-server/src/datalad/description.ts similarity index 100% rename from packages/openneuro-server/src/datalad/description.js rename to packages/openneuro-server/src/datalad/description.ts diff --git a/packages/openneuro-server/src/datalad/draft.js b/packages/openneuro-server/src/datalad/draft.ts similarity index 100% rename from packages/openneuro-server/src/datalad/draft.js rename to packages/openneuro-server/src/datalad/draft.ts diff --git a/packages/openneuro-server/src/datalad/pagination.js b/packages/openneuro-server/src/datalad/pagination.ts similarity index 100% rename from packages/openneuro-server/src/datalad/pagination.js rename to packages/openneuro-server/src/datalad/pagination.ts diff --git a/packages/openneuro-server/src/datalad/readme.js b/packages/openneuro-server/src/datalad/readme.ts similarity index 100% rename from packages/openneuro-server/src/datalad/readme.js rename to packages/openneuro-server/src/datalad/readme.ts diff --git a/packages/openneuro-server/src/datalad/reexporter.js b/packages/openneuro-server/src/datalad/reexporter.ts similarity index 100% rename from packages/openneuro-server/src/datalad/reexporter.js rename to packages/openneuro-server/src/datalad/reexporter.ts diff --git a/packages/openneuro-server/src/datalad/snapshots.js b/packages/openneuro-server/src/datalad/snapshots.ts similarity index 96% rename from packages/openneuro-server/src/datalad/snapshots.js rename to packages/openneuro-server/src/datalad/snapshots.ts index 144b21ca41..4ac02dcae8 100644 --- a/packages/openneuro-server/src/datalad/snapshots.js +++ b/packages/openneuro-server/src/datalad/snapshots.ts @@ -16,8 +16,8 @@ import { getFiles } from './files' import { generateDataladCookie } from '../libs/authentication/jwt' import notifications from '../libs/notifications' import Dataset from '../models/dataset' -import Snapshot from '../models/snapshot' -import { updateDatasetRevision } from './draft.js' +import Snapshot, { SnapshotDocument } from '../models/snapshot' +import { updateDatasetRevision } from './draft' import { getDatasetWorker } from '../libs/datalad-service' import { join } from 'path' @@ -94,7 +94,7 @@ const postSnapshot = async ( * @param {string} datasetId Dataset accession number * @returns {Promise} */ -export const getSnapshots = datasetId => { +export const getSnapshots = (datasetId): Promise => { const url = `${getDatasetWorker(datasetId)}/datasets/${datasetId}/snapshots` return request .get(url) @@ -194,7 +194,10 @@ export const deleteSnapshot = (datasetId, tag) => { * @param {string} commitRef Tag name to retrieve * @returns {Promise} */ -export const getSnapshot = (datasetId, commitRef) => { +export const getSnapshot = ( + datasetId, + commitRef, +): Promise => { const url = `${getDatasetWorker( datasetId, )}/datasets/${datasetId}/snapshots/${commitRef}` diff --git a/packages/openneuro-server/src/datalad/upload.js b/packages/openneuro-server/src/datalad/upload.ts similarity index 100% rename from packages/openneuro-server/src/datalad/upload.js rename to packages/openneuro-server/src/datalad/upload.ts From cb211d141bb589032bf095f7b025165114d616f5 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 11:25:57 -0700 Subject: [PATCH 11/13] chore(server): Fix mocks and tests for server TypeScript fixes --- .../src/__mocks__/{config.js => config.ts} | 0 .../src/datalad/__tests__/changelog.spec.ts | 2 +- .../src/datalad/__tests__/dataset.spec.ts | 4 ++-- .../src/datalad/__tests__/description.spec.ts | 2 +- .../src/datalad/__tests__/files.spec.ts | 2 +- .../src/datalad/__tests__/snapshots.spec.ts | 2 +- .../openneuro-server/src/datalad/snapshots.ts | 4 ++-- .../src/elasticsearch/elastic-client.ts | 2 +- .../src/elasticsearch/reindex-dataset.ts | 2 +- .../openneuro-server/src/graphql/permissions.js | 2 +- .../resolvers/__tests__/dataset-search.spec.js | 2 +- .../graphql/resolvers/__tests__/dataset.spec.js | 4 ++-- .../resolvers/__tests__/snapshots.spec.js | 4 ++-- .../src/graphql/resolvers/comment.js | 2 +- .../src/graphql/resolvers/dataset.js | 9 ++++----- .../src/graphql/resolvers/description.js | 4 ++-- .../src/graphql/resolvers/history.js | 2 +- .../src/graphql/resolvers/readme.js | 4 ++-- .../src/graphql/resolvers/snapshots.js | 2 +- .../src/graphql/resolvers/validation.js | 2 +- .../openneuro-server/src/handlers/sitemap.js | 2 +- .../src/libs/__tests__/apikey.spec.ts | 4 ++-- .../libs/authentication/__tests__/jwt.spec.js | 2 +- .../src/libs/authentication/jwt.ts | 2 +- .../__tests__/__snapshots__/doi.spec.ts.snap | 17 +++++++++++++++++ .../src/libs/email/__tests__/index.spec.ts | 2 +- 26 files changed, 51 insertions(+), 35 deletions(-) rename packages/openneuro-server/src/__mocks__/{config.js => config.ts} (100%) create mode 100644 packages/openneuro-server/src/libs/doi/__tests__/__snapshots__/doi.spec.ts.snap diff --git a/packages/openneuro-server/src/__mocks__/config.js b/packages/openneuro-server/src/__mocks__/config.ts similarity index 100% rename from packages/openneuro-server/src/__mocks__/config.js rename to packages/openneuro-server/src/__mocks__/config.ts diff --git a/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts b/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts index 6ef842bd98..596788e74c 100644 --- a/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts @@ -2,7 +2,7 @@ import { vi } from 'vitest' import * as changelog from '../changelog.js' vi.mock('ioredis') -vi.mock('../../config.js') +vi.mock('../../config.ts') describe('changelog editing tools', () => { describe('findVersion()', () => { diff --git a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts index db02cf6eff..e87274f99a 100644 --- a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts @@ -1,14 +1,14 @@ import { vi } from 'vitest' import request from 'superagent' import { createDataset, datasetsFilter, testBlacklist } from '../dataset.js' -import { getDatasetWorker } from '../../libs/datalad-service' +import { getDatasetWorker } from '../../libs/datalad-service.js' import { connect } from 'mongoose' // Mock requests to Datalad service vi.mock('superagent') vi.mock('ioredis') vi.mock('../../libs/redis.js') -vi.mock('../../config.js') +vi.mock('../../config.ts') vi.mock('../../libs/notifications.js') describe('dataset model operations', () => { diff --git a/packages/openneuro-server/src/datalad/__tests__/description.spec.ts b/packages/openneuro-server/src/datalad/__tests__/description.spec.ts index 2aada727e7..9999b7ba8d 100644 --- a/packages/openneuro-server/src/datalad/__tests__/description.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/description.spec.ts @@ -7,7 +7,7 @@ import { // Mock requests to Datalad service vi.mock('ioredis') -vi.mock('../../config.js') +vi.mock('../../config.ts') describe('datalad dataset descriptions', () => { describe('appendSeniorAuthor', () => { diff --git a/packages/openneuro-server/src/datalad/__tests__/files.spec.ts b/packages/openneuro-server/src/datalad/__tests__/files.spec.ts index 9cd108e212..ae6168a65c 100644 --- a/packages/openneuro-server/src/datalad/__tests__/files.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/files.spec.ts @@ -7,7 +7,7 @@ import { } from '../files' vi.mock('ioredis') -vi.mock('../../config.js') +vi.mock('../../config.ts') const filename = 'sub-01/anat/sub-01_T1w.nii.gz' diff --git a/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts b/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts index b401606cd0..c9278c618a 100644 --- a/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts @@ -20,7 +20,7 @@ vi.mock('../../libs/redis.js', () => ({ vi.mock('../draft.js', () => ({ updateDatasetRevision: () => () => Promise.resolve(), })) -vi.mock('../../config.js') +vi.mock('../../config.ts') vi.mock('../../libs/notifications.js') describe('snapshot model operations', () => { diff --git a/packages/openneuro-server/src/datalad/snapshots.ts b/packages/openneuro-server/src/datalad/snapshots.ts index 4ac02dcae8..76f82da920 100644 --- a/packages/openneuro-server/src/datalad/snapshots.ts +++ b/packages/openneuro-server/src/datalad/snapshots.ts @@ -5,13 +5,13 @@ import request from 'superagent' import { reindexDataset } from '../elasticsearch/reindex-dataset' import { redis, redlock } from '../libs/redis' import CacheItem, { CacheType } from '../cache/item' -import config from '../config.js' +import config from '../config' import { updateDatasetName, snapshotCreationComparison, } from '../graphql/resolvers/dataset.js' import { description } from '../graphql/resolvers/description.js' -import doiLib from '../libs/doi/index.js' +import doiLib from '../libs/doi/index' import { getFiles } from './files' import { generateDataladCookie } from '../libs/authentication/jwt' import notifications from '../libs/notifications' diff --git a/packages/openneuro-server/src/elasticsearch/elastic-client.ts b/packages/openneuro-server/src/elasticsearch/elastic-client.ts index 50aab96950..75837ff7ab 100644 --- a/packages/openneuro-server/src/elasticsearch/elastic-client.ts +++ b/packages/openneuro-server/src/elasticsearch/elastic-client.ts @@ -1,4 +1,4 @@ -import config from '../config.js' +import config from '../config' import { Client } from '@elastic/elasticsearch' const elasticConfig = { diff --git a/packages/openneuro-server/src/elasticsearch/reindex-dataset.ts b/packages/openneuro-server/src/elasticsearch/reindex-dataset.ts index b8f3bbfbff..e91f9f1ce4 100644 --- a/packages/openneuro-server/src/elasticsearch/reindex-dataset.ts +++ b/packages/openneuro-server/src/elasticsearch/reindex-dataset.ts @@ -1,4 +1,4 @@ -import config from '../config.js' +import config from '../config' import { indexDataset, queryForIndex, indexingToken } from '@openneuro/search' import { elasticClient } from './elastic-client' import { diff --git a/packages/openneuro-server/src/graphql/permissions.js b/packages/openneuro-server/src/graphql/permissions.js index 8cd22631f8..7c2e90fdfc 100644 --- a/packages/openneuro-server/src/graphql/permissions.js +++ b/packages/openneuro-server/src/graphql/permissions.js @@ -1,4 +1,4 @@ -import config from '../config.js' +import config from '../config' import { GraphQLError } from 'graphql' import Permission from '../models/permission' import Dataset from '../models/dataset' diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js index 321d596f06..d0af78d86b 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js @@ -6,7 +6,7 @@ import { vi.mock('ioredis') vi.mock('../../../elasticsearch/elastic-client.js') -vi.mock('../../../config.js') +vi.mock('../../../config.ts') describe('dataset search resolvers', () => { describe('encodeCursor()', () => { diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js index c9d35551f5..79b1e206a9 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js @@ -5,8 +5,8 @@ import * as ds from '../dataset' vi.mock('superagent') vi.mock('ioredis') -vi.mock('../../../config.js') -vi.mock('../../../libs/notifications.js') +vi.mock('../../../config.ts') +vi.mock('../../../libs/notifications.ts') describe('dataset resolvers', () => { beforeAll(() => { diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js index 89370d890e..ec0bfccc5c 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js @@ -1,7 +1,7 @@ -import { matchKnownObjects, filterLatestSnapshot } from '../snapshots.js' +import { matchKnownObjects, filterLatestSnapshot } from '../snapshots' vi.mock('ioredis') -vi.mock('../../../config.js') +vi.mock('../../../config.ts') describe('snapshot resolvers', () => { describe('matchKnownObjects()', () => { diff --git a/packages/openneuro-server/src/graphql/resolvers/comment.js b/packages/openneuro-server/src/graphql/resolvers/comment.js index 7a1dcea25a..b17fb2a31f 100644 --- a/packages/openneuro-server/src/graphql/resolvers/comment.js +++ b/packages/openneuro-server/src/graphql/resolvers/comment.js @@ -1,5 +1,5 @@ import Comment from '../../models/comment' -import notifications from '../../libs/notifications.js' +import notifications from '../../libs/notifications' import { user } from './user.js' import { checkAdmin } from '../permissions' diff --git a/packages/openneuro-server/src/graphql/resolvers/dataset.js b/packages/openneuro-server/src/graphql/resolvers/dataset.js index c773449f0e..e76c2055e6 100644 --- a/packages/openneuro-server/src/graphql/resolvers/dataset.js +++ b/packages/openneuro-server/src/graphql/resolvers/dataset.js @@ -1,4 +1,4 @@ -import * as datalad from '../../datalad/dataset.js' +import * as datalad from '../../datalad/dataset' import { removeDatasetSearchDocument } from '../../graphql/resolvers/dataset-search.js' import { snapshots, latestSnapshot } from './snapshots.js' import { description } from './description.js' @@ -12,12 +12,11 @@ import { permissions } from './permissions' import { datasetComments } from './comment.js' import { metadata } from './metadata' import { history } from './history.js' -import * as dataladAnalytics from '../../datalad/analytics.js' +import * as dataladAnalytics from '../../datalad/analytics' import DatasetModel from '../../models/dataset' import Deletion from '../../models/deletion' import { reviewers } from './reviewer' -import { getDatasetWorker } from '../../libs/datalad-service.js' -import { getDraftHead } from '../../datalad/dataset.js' +import { getDatasetWorker } from '../../libs/datalad-service' import { getFileName } from '../../datalad/files' import { onBrainlife } from './brainlife' import { derivatives } from './derivatives' @@ -278,7 +277,7 @@ const Dataset = { uploader: ds => user(ds, { id: ds.uploader }), draft: async obj => ({ id: obj.id, - revision: await getDraftHead(obj.id), + revision: await datalad.getDraftHead(obj.id), modified: obj.modified, }), snapshots, diff --git a/packages/openneuro-server/src/graphql/resolvers/description.js b/packages/openneuro-server/src/graphql/resolvers/description.js index 8f75f88f56..56ae3fd938 100644 --- a/packages/openneuro-server/src/graphql/resolvers/description.js +++ b/packages/openneuro-server/src/graphql/resolvers/description.js @@ -1,9 +1,9 @@ /** * Resolver implementation for dataset_description.json */ -import { setDescription } from '../../datalad/description.js' +import { setDescription } from '../../datalad/description' import { checkDatasetWrite } from '../permissions.js' -export { description } from '../../datalad/description.js' +export { description } from '../../datalad/description' export const updateDescription = ( obj, diff --git a/packages/openneuro-server/src/graphql/resolvers/history.js b/packages/openneuro-server/src/graphql/resolvers/history.js index ce38daaf32..9e5ed2efe2 100644 --- a/packages/openneuro-server/src/graphql/resolvers/history.js +++ b/packages/openneuro-server/src/graphql/resolvers/history.js @@ -1,4 +1,4 @@ -import { getDatasetWorker } from '../../libs/datalad-service.js' +import { getDatasetWorker } from '../../libs/datalad-service' export const history = async obj => { const datasetId = obj.id diff --git a/packages/openneuro-server/src/graphql/resolvers/readme.js b/packages/openneuro-server/src/graphql/resolvers/readme.js index 4023661624..d152002ffb 100644 --- a/packages/openneuro-server/src/graphql/resolvers/readme.js +++ b/packages/openneuro-server/src/graphql/resolvers/readme.js @@ -2,9 +2,9 @@ * Resolver implementation for README files * This stub is here in case draft.readme or snapshot.readme needs future extension */ -import { setReadme } from '../../datalad/readme.js' +import { setReadme } from '../../datalad/readme' import { checkDatasetWrite } from '../permissions.js' -export { readme } from '../../datalad/readme.js' +export { readme } from '../../datalad/readme' export const updateReadme = (obj, { datasetId, value }, { user, userInfo }) => { return checkDatasetWrite(datasetId, user, userInfo).then(() => { diff --git a/packages/openneuro-server/src/graphql/resolvers/snapshots.js b/packages/openneuro-server/src/graphql/resolvers/snapshots.js index 0cf9929fea..0bfd46a46c 100644 --- a/packages/openneuro-server/src/graphql/resolvers/snapshots.js +++ b/packages/openneuro-server/src/graphql/resolvers/snapshots.js @@ -1,4 +1,4 @@ -import * as datalad from '../../datalad/snapshots.js' +import * as datalad from '../../datalad/snapshots' import { dataset, analytics, snapshotCreationComparison } from './dataset.js' import { onBrainlife } from './brainlife' import { checkDatasetRead, checkDatasetWrite } from '../permissions.js' diff --git a/packages/openneuro-server/src/graphql/resolvers/validation.js b/packages/openneuro-server/src/graphql/resolvers/validation.js index ebbff5f553..e776a5f3dc 100644 --- a/packages/openneuro-server/src/graphql/resolvers/validation.js +++ b/packages/openneuro-server/src/graphql/resolvers/validation.js @@ -3,7 +3,7 @@ import { generateDataladCookie } from '../../libs/authentication/jwt' import { getDatasetWorker } from '../../libs/datalad-service' import Issue from '../../models/issue' import publishDraftUpdate from '../utils/publish-draft-update.js' -import { redlock } from '../../libs/redis.js' +import { redlock } from '../../libs/redis' /** * Save issues data returned by the datalad service diff --git a/packages/openneuro-server/src/handlers/sitemap.js b/packages/openneuro-server/src/handlers/sitemap.js index 25b3dbcb2e..8b66c7f572 100644 --- a/packages/openneuro-server/src/handlers/sitemap.js +++ b/packages/openneuro-server/src/handlers/sitemap.js @@ -1,5 +1,5 @@ import sitemap from 'sitemap' -import config from '../config.js' +import config from '../config' import Dataset from '../models/dataset' // Static URLs - manual for now, could be generated from routes diff --git a/packages/openneuro-server/src/libs/__tests__/apikey.spec.ts b/packages/openneuro-server/src/libs/__tests__/apikey.spec.ts index 41d389878f..43c79004a9 100644 --- a/packages/openneuro-server/src/libs/__tests__/apikey.spec.ts +++ b/packages/openneuro-server/src/libs/__tests__/apikey.spec.ts @@ -1,10 +1,10 @@ import { vi } from 'vitest' import jwt from 'jsonwebtoken' import { apiKeyFactory } from '../apikey.js' -import config from '../../config.js' +import config from '../../config' vi.mock('ioredis') -vi.mock('../../config.js') +vi.mock('../../config.ts') const userMock = { id: '1337', diff --git a/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js b/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js index 80ab80b420..deb3dc5cdc 100644 --- a/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js +++ b/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js @@ -2,7 +2,7 @@ import User from '../../../models/user' import { addJWT } from '../jwt' vi.mock('ioredis') -vi.mock('../../../config.js') +vi.mock('../../../config.ts') vi.unmock('mongoose') describe('jwt auth', () => { diff --git a/packages/openneuro-server/src/libs/authentication/jwt.ts b/packages/openneuro-server/src/libs/authentication/jwt.ts index d7aa30a7b6..b48633ebd8 100644 --- a/packages/openneuro-server/src/libs/authentication/jwt.ts +++ b/packages/openneuro-server/src/libs/authentication/jwt.ts @@ -3,7 +3,7 @@ import refresh from 'passport-oauth2-refresh' import jwt from 'jsonwebtoken' import { decrypt } from './crypto' import User from '../../models/user' -import config from '../../config.js' +import config from '../../config' interface OpenNeuroTokenProfile { sub: string diff --git a/packages/openneuro-server/src/libs/doi/__tests__/__snapshots__/doi.spec.ts.snap b/packages/openneuro-server/src/libs/doi/__tests__/__snapshots__/doi.spec.ts.snap new file mode 100644 index 0000000000..13ebf07cd5 --- /dev/null +++ b/packages/openneuro-server/src/libs/doi/__tests__/__snapshots__/doi.spec.ts.snap @@ -0,0 +1,17 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`DOI minting utils > template() > accepts expected arguments 1`] = ` +" + + 12345 + + A. UserB. User + + + Test Dataset + + Openneuro + 1999 + fMRI +" +`; diff --git a/packages/openneuro-server/src/libs/email/__tests__/index.spec.ts b/packages/openneuro-server/src/libs/email/__tests__/index.spec.ts index b7b40910c3..ce49661cd6 100644 --- a/packages/openneuro-server/src/libs/email/__tests__/index.spec.ts +++ b/packages/openneuro-server/src/libs/email/__tests__/index.spec.ts @@ -2,7 +2,7 @@ import { vi } from 'vitest' import { mailjetFormat } from '../index' vi.mock('ioredis') -vi.mock('../../../config.js') +vi.mock('../../../config.ts') describe('Mailjet formatter', () => { it('formats a message', () => { From 61f06e74a3e633fa321666a5b71536f04ad78319 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 11:37:33 -0700 Subject: [PATCH 12/13] chore(server): Migrate Express handlers to TypeScript --- .../src/datalad/__tests__/dataset.spec.ts | 2 +- .../src/datalad/__tests__/snapshots.spec.ts | 10 +++++----- packages/openneuro-server/src/datalad/changelog.ts | 2 +- packages/openneuro-server/src/datalad/snapshots.ts | 4 ++-- .../openneuro-server/src/graphql/resolvers/publish.js | 2 +- .../src/handlers/{comments.js => comments.ts} | 0 .../src/handlers/{config.js => config.ts} | 0 .../src/handlers/{datalad.js => datalad.ts} | 0 .../openneuro-server/src/handlers/{doi.js => doi.ts} | 0 .../src/handlers/{sitemap.js => sitemap.ts} | 0 .../handlers/{subscriptions.js => subscriptions.ts} | 0 .../src/handlers/{users.js => users.ts} | 0 .../src/libs/__tests__/dataset.spec.ts | 4 ++-- 13 files changed, 12 insertions(+), 12 deletions(-) rename packages/openneuro-server/src/handlers/{comments.js => comments.ts} (100%) rename packages/openneuro-server/src/handlers/{config.js => config.ts} (100%) rename packages/openneuro-server/src/handlers/{datalad.js => datalad.ts} (100%) rename packages/openneuro-server/src/handlers/{doi.js => doi.ts} (100%) rename packages/openneuro-server/src/handlers/{sitemap.js => sitemap.ts} (100%) rename packages/openneuro-server/src/handlers/{subscriptions.js => subscriptions.ts} (100%) rename packages/openneuro-server/src/handlers/{users.js => users.ts} (100%) diff --git a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts index e87274f99a..148ed4197a 100644 --- a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts @@ -1,6 +1,6 @@ import { vi } from 'vitest' import request from 'superagent' -import { createDataset, datasetsFilter, testBlacklist } from '../dataset.js' +import { createDataset, datasetsFilter, testBlacklist } from '../dataset' import { getDatasetWorker } from '../../libs/datalad-service.js' import { connect } from 'mongoose' diff --git a/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts b/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts index c9278c618a..e9346878f5 100644 --- a/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/snapshots.spec.ts @@ -1,9 +1,9 @@ import { vi } from 'vitest' vi.mock('ioredis') import request from 'superagent' -import { createDataset } from '../dataset.js' -import { createSnapshot } from '../snapshots.js' -import { getDatasetWorker } from '../../libs/datalad-service.js' +import { createDataset } from '../dataset' +import { createSnapshot } from '../snapshots' +import { getDatasetWorker } from '../../libs/datalad-service' import { connect } from 'mongoose' // Mock requests to Datalad service @@ -17,11 +17,11 @@ vi.mock('../../libs/redis.js', () => ({ }, })) // Mock draft files calls -vi.mock('../draft.js', () => ({ +vi.mock('../draft.ts', () => ({ updateDatasetRevision: () => () => Promise.resolve(), })) vi.mock('../../config.ts') -vi.mock('../../libs/notifications.js') +vi.mock('../../libs/notifications.ts') describe('snapshot model operations', () => { describe('createSnapshot()', () => { diff --git a/packages/openneuro-server/src/datalad/changelog.ts b/packages/openneuro-server/src/datalad/changelog.ts index 17ba7e95a8..b0cbb6044e 100644 --- a/packages/openneuro-server/src/datalad/changelog.ts +++ b/packages/openneuro-server/src/datalad/changelog.ts @@ -1,5 +1,5 @@ import format from 'date-fns/format' -import { addFileString, commitFiles } from './dataset.js' +import { addFileString, commitFiles } from './dataset' import { getDatasetWorker } from '../libs/datalad-service' /** diff --git a/packages/openneuro-server/src/datalad/snapshots.ts b/packages/openneuro-server/src/datalad/snapshots.ts index 76f82da920..e0872d5837 100644 --- a/packages/openneuro-server/src/datalad/snapshots.ts +++ b/packages/openneuro-server/src/datalad/snapshots.ts @@ -9,8 +9,8 @@ import config from '../config' import { updateDatasetName, snapshotCreationComparison, -} from '../graphql/resolvers/dataset.js' -import { description } from '../graphql/resolvers/description.js' +} from '../graphql/resolvers/dataset' +import { description } from '../graphql/resolvers/description' import doiLib from '../libs/doi/index' import { getFiles } from './files' import { generateDataladCookie } from '../libs/authentication/jwt' diff --git a/packages/openneuro-server/src/graphql/resolvers/publish.js b/packages/openneuro-server/src/graphql/resolvers/publish.js index 0c4372b223..9801bebbf5 100644 --- a/packages/openneuro-server/src/graphql/resolvers/publish.js +++ b/packages/openneuro-server/src/graphql/resolvers/publish.js @@ -1,6 +1,6 @@ import config from '../../config' import request from 'superagent' -import { updatePublic } from '../../datalad/dataset.js' +import { updatePublic } from '../../datalad/dataset' import { checkDatasetWrite } from '../permissions.js' import { generateDataladCookie } from '../../libs/authentication/jwt' import { getDatasetWorker } from '../../libs/datalad-service' diff --git a/packages/openneuro-server/src/handlers/comments.js b/packages/openneuro-server/src/handlers/comments.ts similarity index 100% rename from packages/openneuro-server/src/handlers/comments.js rename to packages/openneuro-server/src/handlers/comments.ts diff --git a/packages/openneuro-server/src/handlers/config.js b/packages/openneuro-server/src/handlers/config.ts similarity index 100% rename from packages/openneuro-server/src/handlers/config.js rename to packages/openneuro-server/src/handlers/config.ts diff --git a/packages/openneuro-server/src/handlers/datalad.js b/packages/openneuro-server/src/handlers/datalad.ts similarity index 100% rename from packages/openneuro-server/src/handlers/datalad.js rename to packages/openneuro-server/src/handlers/datalad.ts diff --git a/packages/openneuro-server/src/handlers/doi.js b/packages/openneuro-server/src/handlers/doi.ts similarity index 100% rename from packages/openneuro-server/src/handlers/doi.js rename to packages/openneuro-server/src/handlers/doi.ts diff --git a/packages/openneuro-server/src/handlers/sitemap.js b/packages/openneuro-server/src/handlers/sitemap.ts similarity index 100% rename from packages/openneuro-server/src/handlers/sitemap.js rename to packages/openneuro-server/src/handlers/sitemap.ts diff --git a/packages/openneuro-server/src/handlers/subscriptions.js b/packages/openneuro-server/src/handlers/subscriptions.ts similarity index 100% rename from packages/openneuro-server/src/handlers/subscriptions.js rename to packages/openneuro-server/src/handlers/subscriptions.ts diff --git a/packages/openneuro-server/src/handlers/users.js b/packages/openneuro-server/src/handlers/users.ts similarity index 100% rename from packages/openneuro-server/src/handlers/users.js rename to packages/openneuro-server/src/handlers/users.ts diff --git a/packages/openneuro-server/src/libs/__tests__/dataset.spec.ts b/packages/openneuro-server/src/libs/__tests__/dataset.spec.ts index ae112434c2..f3589b865b 100644 --- a/packages/openneuro-server/src/libs/__tests__/dataset.spec.ts +++ b/packages/openneuro-server/src/libs/__tests__/dataset.spec.ts @@ -1,10 +1,10 @@ import { vi } from 'vitest' import { connect } from 'mongoose' -import { getAccessionNumber } from '../dataset.js' +import { getAccessionNumber } from '../dataset' vi.mock('ioredis') -describe('libs/dataset.js', () => { +describe('libs/dataset', () => { describe('getAccessionNumber', () => { beforeAll(() => { connect(globalThis.__MONGO_URI__) From 359570e6e0e05807b428015cdb3c9618f060dd1a Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Wed, 1 Nov 2023 16:42:24 -0700 Subject: [PATCH 13/13] chore(server): Migrate resolvers to TypeScript --- packages/openneuro-server/src/app.ts | 6 +++--- .../src/datalad/__tests__/changelog.spec.ts | 2 +- .../src/datalad/__tests__/dataset.spec.ts | 6 +++--- .../src/datalad/__tests__/description.spec.ts | 2 +- packages/openneuro-server/src/datalad/dataset.ts | 2 +- .../openneuro-server/src/datalad/description.ts | 4 ++-- packages/openneuro-server/src/datalad/draft.ts | 5 +---- .../__snapshots__/permissions.spec.ts.snap | 5 +++++ .../__tests__/{comment.spec.js => comment.spec.ts} | 0 .../{permissions.spec.js => permissions.spec.ts} | 10 ++++++++-- .../src/graphql/{permissions.js => permissions.ts} | 0 packages/openneuro-server/src/graphql/pubsub.js | 5 ----- ...ataset-search.spec.js => dataset-search.spec.ts} | 4 +++- .../__tests__/{dataset.spec.js => dataset.spec.ts} | 6 +++--- .../{permssions.spec.js => permssions.spec.ts} | 3 ++- .../{snapshots.spec.js => snapshots.spec.ts} | 1 + .../__tests__/{user.spec.js => user.spec.ts} | 1 + .../graphql/resolvers/{comment.js => comment.ts} | 0 .../{dataset-search.js => dataset-search.ts} | 2 ++ .../graphql/resolvers/{dataset.js => dataset.ts} | 12 ++++++------ .../src/graphql/resolvers/derivatives.ts | 2 +- .../resolvers/{description.js => description.ts} | 2 +- .../src/graphql/resolvers/{draft.js => draft.ts} | 0 .../resolvers/{flaggedFiles.js => flaggedFiles.ts} | 0 .../src/graphql/resolvers/{follow.js => follow.ts} | 0 .../graphql/resolvers/{history.js => history.ts} | 0 .../src/graphql/resolvers/{index.js => index.ts} | 0 .../src/graphql/resolvers/{issues.js => issues.ts} | 0 .../graphql/resolvers/{mutation.js => mutation.ts} | 0 .../resolvers/{newsletter.js => newsletter.ts} | 0 .../graphql/resolvers/{publish.js => publish.ts} | 0 .../src/graphql/resolvers/{query.js => query.ts} | 0 .../src/graphql/resolvers/{readme.js => readme.ts} | 2 +- .../resolvers/{reexporter.js => reexporter.ts} | 0 .../src/graphql/resolvers/{reset.js => reset.ts} | 0 .../resolvers/{snapshots.js => snapshots.ts} | 4 ++-- .../src/graphql/resolvers/{stars.js => stars.ts} | 0 .../src/graphql/resolvers/{upload.js => upload.ts} | 0 .../src/graphql/resolvers/{user.js => user.ts} | 0 .../resolvers/{validation.js => validation.ts} | 6 +----- .../src/graphql/{schema.js => schema.ts} | 0 .../src/graphql/utils/{file.js => file.ts} | 0 .../src/graphql/utils/publish-draft-update.js | 13 ------------- .../{notifications.js => notifications.ts} | 0 .../__tests__/{jwt.spec.js => jwt.spec.ts} | 1 + packages/openneuro-server/src/routes.ts | 4 ++-- 46 files changed, 52 insertions(+), 58 deletions(-) create mode 100644 packages/openneuro-server/src/graphql/__tests__/__snapshots__/permissions.spec.ts.snap rename packages/openneuro-server/src/graphql/__tests__/{comment.spec.js => comment.spec.ts} (100%) rename packages/openneuro-server/src/graphql/__tests__/{permissions.spec.js => permissions.spec.ts} (93%) rename packages/openneuro-server/src/graphql/{permissions.js => permissions.ts} (100%) delete mode 100644 packages/openneuro-server/src/graphql/pubsub.js rename packages/openneuro-server/src/graphql/resolvers/__tests__/{dataset-search.spec.js => dataset-search.spec.ts} (94%) rename packages/openneuro-server/src/graphql/resolvers/__tests__/{dataset.spec.js => dataset.spec.ts} (96%) rename packages/openneuro-server/src/graphql/resolvers/__tests__/{permssions.spec.js => permssions.spec.ts} (89%) rename packages/openneuro-server/src/graphql/resolvers/__tests__/{snapshots.spec.js => snapshots.spec.ts} (98%) rename packages/openneuro-server/src/graphql/resolvers/__tests__/{user.spec.js => user.spec.ts} (93%) rename packages/openneuro-server/src/graphql/resolvers/{comment.js => comment.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{dataset-search.js => dataset-search.ts} (99%) rename packages/openneuro-server/src/graphql/resolvers/{dataset.js => dataset.ts} (95%) rename packages/openneuro-server/src/graphql/resolvers/{description.js => description.ts} (90%) rename packages/openneuro-server/src/graphql/resolvers/{draft.js => draft.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{flaggedFiles.js => flaggedFiles.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{follow.js => follow.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{history.js => history.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{index.js => index.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{issues.js => issues.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{mutation.js => mutation.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{newsletter.js => newsletter.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{publish.js => publish.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{query.js => query.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{readme.js => readme.ts} (89%) rename packages/openneuro-server/src/graphql/resolvers/{reexporter.js => reexporter.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{reset.js => reset.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{snapshots.js => snapshots.ts} (99%) rename packages/openneuro-server/src/graphql/resolvers/{stars.js => stars.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{upload.js => upload.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{user.js => user.ts} (100%) rename packages/openneuro-server/src/graphql/resolvers/{validation.js => validation.ts} (90%) rename packages/openneuro-server/src/graphql/{schema.js => schema.ts} (100%) rename packages/openneuro-server/src/graphql/utils/{file.js => file.ts} (100%) delete mode 100644 packages/openneuro-server/src/graphql/utils/publish-draft-update.js rename packages/openneuro-server/src/libs/__mocks__/{notifications.js => notifications.ts} (100%) rename packages/openneuro-server/src/libs/authentication/__tests__/{jwt.spec.js => jwt.spec.ts} (94%) diff --git a/packages/openneuro-server/src/app.ts b/packages/openneuro-server/src/app.ts index fdc29e8762..23df857d3e 100644 --- a/packages/openneuro-server/src/app.ts +++ b/packages/openneuro-server/src/app.ts @@ -21,9 +21,9 @@ import Keyv from 'keyv' import KeyvRedis from '@keyv/redis' import cookieParser from 'cookie-parser' import * as jwt from './libs/authentication/jwt' -import * as auth from './libs/authentication/states.js' -import { sitemapHandler } from './handlers/sitemap.js' -import { setupPassportAuth } from './libs/authentication/passport.js' +import * as auth from './libs/authentication/states' +import { sitemapHandler } from './handlers/sitemap' +import { setupPassportAuth } from './libs/authentication/passport' import { redis } from './libs/redis' import { version } from './lerna.json' export { Express } from 'express-serve-static-core' diff --git a/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts b/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts index 596788e74c..8c9c8cdc83 100644 --- a/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/changelog.spec.ts @@ -1,5 +1,5 @@ import { vi } from 'vitest' -import * as changelog from '../changelog.js' +import * as changelog from '../changelog' vi.mock('ioredis') vi.mock('../../config.ts') diff --git a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts index 148ed4197a..7818ba67ad 100644 --- a/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/dataset.spec.ts @@ -1,15 +1,15 @@ import { vi } from 'vitest' import request from 'superagent' import { createDataset, datasetsFilter, testBlacklist } from '../dataset' -import { getDatasetWorker } from '../../libs/datalad-service.js' +import { getDatasetWorker } from '../../libs/datalad-service' import { connect } from 'mongoose' // Mock requests to Datalad service vi.mock('superagent') vi.mock('ioredis') -vi.mock('../../libs/redis.js') +vi.mock('../../libs/redis') vi.mock('../../config.ts') -vi.mock('../../libs/notifications.js') +vi.mock('../../libs/notifications') describe('dataset model operations', () => { describe('createDataset()', () => { diff --git a/packages/openneuro-server/src/datalad/__tests__/description.spec.ts b/packages/openneuro-server/src/datalad/__tests__/description.spec.ts index 9999b7ba8d..ce69816373 100644 --- a/packages/openneuro-server/src/datalad/__tests__/description.spec.ts +++ b/packages/openneuro-server/src/datalad/__tests__/description.spec.ts @@ -3,7 +3,7 @@ import { getDescriptionObject, repairDescriptionTypes, appendSeniorAuthor, -} from '../description.js' +} from '../description' // Mock requests to Datalad service vi.mock('ioredis') diff --git a/packages/openneuro-server/src/datalad/dataset.ts b/packages/openneuro-server/src/datalad/dataset.ts index 96703118bf..337235c9c7 100644 --- a/packages/openneuro-server/src/datalad/dataset.ts +++ b/packages/openneuro-server/src/datalad/dataset.ts @@ -9,7 +9,7 @@ import objectHash from 'object-hash' import { Readable } from 'stream' import * as Mongoose from 'mongoose' import config from '../config' -import * as subscriptions from '../handlers/subscriptions.js' +import * as subscriptions from '../handlers/subscriptions' import { generateDataladCookie } from '../libs/authentication/jwt' import { redis } from '../libs/redis' import CacheItem, { CacheType } from '../cache/item' diff --git a/packages/openneuro-server/src/datalad/description.ts b/packages/openneuro-server/src/datalad/description.ts index 71a00fad18..50b1fbc188 100644 --- a/packages/openneuro-server/src/datalad/description.ts +++ b/packages/openneuro-server/src/datalad/description.ts @@ -3,8 +3,8 @@ */ import config from '../config' import request from 'superagent' -import { redis } from '../libs/redis.js' -import { commitFiles } from './dataset.js' +import { redis } from '../libs/redis' +import { commitFiles } from './dataset' import { fileUrl } from './files' import { generateDataladCookie } from '../libs/authentication/jwt' import { getDatasetWorker } from '../libs/datalad-service' diff --git a/packages/openneuro-server/src/datalad/draft.ts b/packages/openneuro-server/src/datalad/draft.ts index 60b2aeace5..dbea634a65 100644 --- a/packages/openneuro-server/src/datalad/draft.ts +++ b/packages/openneuro-server/src/datalad/draft.ts @@ -3,7 +3,6 @@ */ import request from 'superagent' import Dataset from '../models/dataset' -import publishDraftUpdate from '../graphql/utils/publish-draft-update.js' import { getDatasetWorker } from '../libs/datalad-service' export const getDraftRevision = async datasetId => { @@ -19,9 +18,7 @@ export const updateDatasetRevision = (datasetId, gitRef) => { /** * Update the revision modified time in a draft on changes */ - return Dataset.updateOne({ id: datasetId }, { modified: new Date() }) - .exec() - .then(() => publishDraftUpdate(datasetId, gitRef)) + return Dataset.updateOne({ id: datasetId }, { modified: new Date() }).exec() } /** diff --git a/packages/openneuro-server/src/graphql/__tests__/__snapshots__/permissions.spec.ts.snap b/packages/openneuro-server/src/graphql/__tests__/__snapshots__/permissions.spec.ts.snap new file mode 100644 index 0000000000..2dfa4adb8e --- /dev/null +++ b/packages/openneuro-server/src/graphql/__tests__/__snapshots__/permissions.spec.ts.snap @@ -0,0 +1,5 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`resolver permissions helpers > checkDatasetAdmin() > resolves to false for anonymous users 1`] = `"You do not have admin access to this dataset."`; + +exports[`resolver permissions helpers > checkDatasetWrite() > resolves to false for anonymous users 1`] = `"You do not have access to modify this dataset."`; diff --git a/packages/openneuro-server/src/graphql/__tests__/comment.spec.js b/packages/openneuro-server/src/graphql/__tests__/comment.spec.ts similarity index 100% rename from packages/openneuro-server/src/graphql/__tests__/comment.spec.js rename to packages/openneuro-server/src/graphql/__tests__/comment.spec.ts diff --git a/packages/openneuro-server/src/graphql/__tests__/permissions.spec.js b/packages/openneuro-server/src/graphql/__tests__/permissions.spec.ts similarity index 93% rename from packages/openneuro-server/src/graphql/__tests__/permissions.spec.js rename to packages/openneuro-server/src/graphql/__tests__/permissions.spec.ts index c55620d076..54f9badd08 100644 --- a/packages/openneuro-server/src/graphql/__tests__/permissions.spec.js +++ b/packages/openneuro-server/src/graphql/__tests__/permissions.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { datasetReadQuery, checkPermissionLevel, @@ -95,12 +96,17 @@ describe('resolver permissions helpers', () => { describe('checkDatasetAdmin()', () => { it('resolves to false for anonymous users', () => { return expect( - checkDatasetAdmin('ds000001', null, null, false), + checkDatasetAdmin('ds000001', null, null, { checkExists: false }), ).rejects.toThrowErrorMatchingSnapshot() }) it('resolves to true for admins', () => { return expect( - checkDatasetAdmin('ds000001', '1234', { admin: true }, false), + checkDatasetAdmin( + 'ds000001', + '1234', + { admin: true }, + { checkExists: false }, + ), ).resolves.toBe(true) }) }) diff --git a/packages/openneuro-server/src/graphql/permissions.js b/packages/openneuro-server/src/graphql/permissions.ts similarity index 100% rename from packages/openneuro-server/src/graphql/permissions.js rename to packages/openneuro-server/src/graphql/permissions.ts diff --git a/packages/openneuro-server/src/graphql/pubsub.js b/packages/openneuro-server/src/graphql/pubsub.js deleted file mode 100644 index ec5b6390fc..0000000000 --- a/packages/openneuro-server/src/graphql/pubsub.js +++ /dev/null @@ -1,5 +0,0 @@ -async function* asyncIterator(_) { - yield null -} - -export default { publish: (_, __) => {}, asyncIterator } diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.ts similarity index 94% rename from packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js rename to packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.ts index d0af78d86b..b5e58ad25b 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset-search.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { encodeCursor, decodeCursor, @@ -5,7 +6,7 @@ import { } from '../dataset-search' vi.mock('ioredis') -vi.mock('../../../elasticsearch/elastic-client.js') +vi.mock('../../../elasticsearch/elastic-client.ts') vi.mock('../../../config.ts') describe('dataset search resolvers', () => { @@ -46,6 +47,7 @@ describe('dataset search resolvers', () => { hasPreviousPage: false, }, } + // @ts-expect-error Mock version does not use all arguments const connection = await elasticRelayConnection(emptyApiResponse, { dataset: vi.fn(), }) diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.ts similarity index 96% rename from packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js rename to packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.ts index 79b1e206a9..1b078b6bee 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/dataset.spec.ts @@ -40,9 +40,9 @@ describe('dataset resolvers', () => { }) it('sorts array of objects by the "created" property as strings', () => { const testArray = [ - { id: 2, created: '2018-11-20T00:05:43.473Z' }, - { id: 1, created: '2018-11-19T00:05:43.473Z' }, - { id: 3, created: '2018-11-23T00:05:43.473Z' }, + { id: 2, created: '2018-11-20T00:05:43.473Z', tag: '2.0.0' }, + { id: 1, created: '2018-11-19T00:05:43.473Z', tag: '1.0.0' }, + { id: 3, created: '2018-11-23T00:05:43.473Z', tag: '3.0.0' }, ] const sorted = testArray.sort(ds.snapshotCreationComparison) expect(sorted[0].id).toBe(1) diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/permssions.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/permssions.spec.ts similarity index 89% rename from packages/openneuro-server/src/graphql/resolvers/__tests__/permssions.spec.js rename to packages/openneuro-server/src/graphql/resolvers/__tests__/permssions.spec.ts index 1a838afb25..afbcf05912 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/permssions.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/permssions.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { updatePermissions } from '../permissions' vi.mock('ioredis') @@ -22,7 +23,7 @@ describe('permissions resolvers', () => { await updatePermissions( {}, { datasetId: 'ds01234', userEmail: 'fake@test.com' }, - {}, + { user: '1234', userInfo: { id: '1234' } }, ) } catch (err) { error = err diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.ts similarity index 98% rename from packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js rename to packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.ts index ec0bfccc5c..9e8043cacc 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/snapshots.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { matchKnownObjects, filterLatestSnapshot } from '../snapshots' vi.mock('ioredis') diff --git a/packages/openneuro-server/src/graphql/resolvers/__tests__/user.spec.js b/packages/openneuro-server/src/graphql/resolvers/__tests__/user.spec.ts similarity index 93% rename from packages/openneuro-server/src/graphql/resolvers/__tests__/user.spec.js rename to packages/openneuro-server/src/graphql/resolvers/__tests__/user.spec.ts index 6c53cd6d75..c98d951a20 100644 --- a/packages/openneuro-server/src/graphql/resolvers/__tests__/user.spec.js +++ b/packages/openneuro-server/src/graphql/resolvers/__tests__/user.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import { users } from '../user.js' vi.mock('ioredis') diff --git a/packages/openneuro-server/src/graphql/resolvers/comment.js b/packages/openneuro-server/src/graphql/resolvers/comment.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/comment.js rename to packages/openneuro-server/src/graphql/resolvers/comment.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/dataset-search.js b/packages/openneuro-server/src/graphql/resolvers/dataset-search.ts similarity index 99% rename from packages/openneuro-server/src/graphql/resolvers/dataset-search.js rename to packages/openneuro-server/src/graphql/resolvers/dataset-search.ts index 5e1cd9100c..210986e886 100644 --- a/packages/openneuro-server/src/graphql/resolvers/dataset-search.js +++ b/packages/openneuro-server/src/graphql/resolvers/dataset-search.ts @@ -89,6 +89,7 @@ export const datasetSearchConnection = async ( const searchId = hashObject({ q }) const requestBody = { sort: [{ _score: 'asc', id: 'desc' }], + search_after: undefined, } if (after) { try { @@ -228,6 +229,7 @@ export const advancedDatasetSearchConnection = async ( query: allDatasets ? query : await parseQuery(query, datasetType, datasetStatus, user), + search_after: undefined, } if (after) { try { diff --git a/packages/openneuro-server/src/graphql/resolvers/dataset.js b/packages/openneuro-server/src/graphql/resolvers/dataset.ts similarity index 95% rename from packages/openneuro-server/src/graphql/resolvers/dataset.js rename to packages/openneuro-server/src/graphql/resolvers/dataset.ts index e76c2055e6..f7a67a9bdc 100644 --- a/packages/openneuro-server/src/graphql/resolvers/dataset.js +++ b/packages/openneuro-server/src/graphql/resolvers/dataset.ts @@ -1,17 +1,17 @@ import * as datalad from '../../datalad/dataset' -import { removeDatasetSearchDocument } from '../../graphql/resolvers/dataset-search.js' -import { snapshots, latestSnapshot } from './snapshots.js' -import { description } from './description.js' +import { removeDatasetSearchDocument } from './dataset-search' +import { snapshots, latestSnapshot } from './snapshots' +import { description } from './description' import { checkDatasetRead, checkDatasetWrite, checkDatasetAdmin, } from '../permissions' -import { user } from './user.js' +import { user } from './user' import { permissions } from './permissions' -import { datasetComments } from './comment.js' +import { datasetComments } from './comment' import { metadata } from './metadata' -import { history } from './history.js' +import { history } from './history' import * as dataladAnalytics from '../../datalad/analytics' import DatasetModel from '../../models/dataset' import Deletion from '../../models/deletion' diff --git a/packages/openneuro-server/src/graphql/resolvers/derivatives.ts b/packages/openneuro-server/src/graphql/resolvers/derivatives.ts index cd4852907d..59b7fccde3 100644 --- a/packages/openneuro-server/src/graphql/resolvers/derivatives.ts +++ b/packages/openneuro-server/src/graphql/resolvers/derivatives.ts @@ -49,7 +49,7 @@ export const githubDerivative = async ( } } -interface DatasetDerivatives { +export interface DatasetDerivatives { name: string local: boolean s3Url: URL diff --git a/packages/openneuro-server/src/graphql/resolvers/description.js b/packages/openneuro-server/src/graphql/resolvers/description.ts similarity index 90% rename from packages/openneuro-server/src/graphql/resolvers/description.js rename to packages/openneuro-server/src/graphql/resolvers/description.ts index 56ae3fd938..b47377baf1 100644 --- a/packages/openneuro-server/src/graphql/resolvers/description.js +++ b/packages/openneuro-server/src/graphql/resolvers/description.ts @@ -2,7 +2,7 @@ * Resolver implementation for dataset_description.json */ import { setDescription } from '../../datalad/description' -import { checkDatasetWrite } from '../permissions.js' +import { checkDatasetWrite } from '../permissions' export { description } from '../../datalad/description' export const updateDescription = ( diff --git a/packages/openneuro-server/src/graphql/resolvers/draft.js b/packages/openneuro-server/src/graphql/resolvers/draft.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/draft.js rename to packages/openneuro-server/src/graphql/resolvers/draft.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/flaggedFiles.js b/packages/openneuro-server/src/graphql/resolvers/flaggedFiles.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/flaggedFiles.js rename to packages/openneuro-server/src/graphql/resolvers/flaggedFiles.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/follow.js b/packages/openneuro-server/src/graphql/resolvers/follow.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/follow.js rename to packages/openneuro-server/src/graphql/resolvers/follow.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/history.js b/packages/openneuro-server/src/graphql/resolvers/history.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/history.js rename to packages/openneuro-server/src/graphql/resolvers/history.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/index.js b/packages/openneuro-server/src/graphql/resolvers/index.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/index.js rename to packages/openneuro-server/src/graphql/resolvers/index.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/issues.js b/packages/openneuro-server/src/graphql/resolvers/issues.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/issues.js rename to packages/openneuro-server/src/graphql/resolvers/issues.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/mutation.js b/packages/openneuro-server/src/graphql/resolvers/mutation.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/mutation.js rename to packages/openneuro-server/src/graphql/resolvers/mutation.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/newsletter.js b/packages/openneuro-server/src/graphql/resolvers/newsletter.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/newsletter.js rename to packages/openneuro-server/src/graphql/resolvers/newsletter.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/publish.js b/packages/openneuro-server/src/graphql/resolvers/publish.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/publish.js rename to packages/openneuro-server/src/graphql/resolvers/publish.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/query.js b/packages/openneuro-server/src/graphql/resolvers/query.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/query.js rename to packages/openneuro-server/src/graphql/resolvers/query.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/readme.js b/packages/openneuro-server/src/graphql/resolvers/readme.ts similarity index 89% rename from packages/openneuro-server/src/graphql/resolvers/readme.js rename to packages/openneuro-server/src/graphql/resolvers/readme.ts index d152002ffb..57881c8499 100644 --- a/packages/openneuro-server/src/graphql/resolvers/readme.js +++ b/packages/openneuro-server/src/graphql/resolvers/readme.ts @@ -3,7 +3,7 @@ * This stub is here in case draft.readme or snapshot.readme needs future extension */ import { setReadme } from '../../datalad/readme' -import { checkDatasetWrite } from '../permissions.js' +import { checkDatasetWrite } from '../permissions' export { readme } from '../../datalad/readme' export const updateReadme = (obj, { datasetId, value }, { user, userInfo }) => { diff --git a/packages/openneuro-server/src/graphql/resolvers/reexporter.js b/packages/openneuro-server/src/graphql/resolvers/reexporter.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/reexporter.js rename to packages/openneuro-server/src/graphql/resolvers/reexporter.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/reset.js b/packages/openneuro-server/src/graphql/resolvers/reset.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/reset.js rename to packages/openneuro-server/src/graphql/resolvers/reset.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/snapshots.js b/packages/openneuro-server/src/graphql/resolvers/snapshots.ts similarity index 99% rename from packages/openneuro-server/src/graphql/resolvers/snapshots.js rename to packages/openneuro-server/src/graphql/resolvers/snapshots.ts index 0bfd46a46c..59fe8d86da 100644 --- a/packages/openneuro-server/src/graphql/resolvers/snapshots.js +++ b/packages/openneuro-server/src/graphql/resolvers/snapshots.ts @@ -1,7 +1,7 @@ import * as datalad from '../../datalad/snapshots' import { dataset, analytics, snapshotCreationComparison } from './dataset.js' import { onBrainlife } from './brainlife' -import { checkDatasetRead, checkDatasetWrite } from '../permissions.js' +import { checkDatasetRead, checkDatasetWrite } from '../permissions' import { readme } from './readme.js' import { description } from './description.js' import { summary } from './summary' @@ -9,7 +9,7 @@ import { snapshotIssues } from './issues.js' import { getFiles } from '../../datalad/files' import Summary from '../../models/summary' import DatasetModel from '../../models/dataset' -import { filterRemovedAnnexObjects } from '../utils/file.js' +import { filterRemovedAnnexObjects } from '../utils/file' import DeprecatedSnapshot from '../../models/deprecatedSnapshot' import { redis } from '../../libs/redis' import CacheItem, { CacheType } from '../../cache/item' diff --git a/packages/openneuro-server/src/graphql/resolvers/stars.js b/packages/openneuro-server/src/graphql/resolvers/stars.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/stars.js rename to packages/openneuro-server/src/graphql/resolvers/stars.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/upload.js b/packages/openneuro-server/src/graphql/resolvers/upload.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/upload.js rename to packages/openneuro-server/src/graphql/resolvers/upload.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/user.js b/packages/openneuro-server/src/graphql/resolvers/user.ts similarity index 100% rename from packages/openneuro-server/src/graphql/resolvers/user.js rename to packages/openneuro-server/src/graphql/resolvers/user.ts diff --git a/packages/openneuro-server/src/graphql/resolvers/validation.js b/packages/openneuro-server/src/graphql/resolvers/validation.ts similarity index 90% rename from packages/openneuro-server/src/graphql/resolvers/validation.js rename to packages/openneuro-server/src/graphql/resolvers/validation.ts index e776a5f3dc..f1f91702e5 100644 --- a/packages/openneuro-server/src/graphql/resolvers/validation.js +++ b/packages/openneuro-server/src/graphql/resolvers/validation.ts @@ -2,7 +2,6 @@ import config from '../../config' import { generateDataladCookie } from '../../libs/authentication/jwt' import { getDatasetWorker } from '../../libs/datalad-service' import Issue from '../../models/issue' -import publishDraftUpdate from '../utils/publish-draft-update.js' import { redlock } from '../../libs/redis' /** @@ -23,10 +22,7 @@ export const updateValidation = (obj, args) => { }, ) .exec() - .then(() => { - publishDraftUpdate(args.validation.datasetId, args.validation.id) - return true - }) + .then(() => true) } export const validationUrl = (datasetId, ref) => { diff --git a/packages/openneuro-server/src/graphql/schema.js b/packages/openneuro-server/src/graphql/schema.ts similarity index 100% rename from packages/openneuro-server/src/graphql/schema.js rename to packages/openneuro-server/src/graphql/schema.ts diff --git a/packages/openneuro-server/src/graphql/utils/file.js b/packages/openneuro-server/src/graphql/utils/file.ts similarity index 100% rename from packages/openneuro-server/src/graphql/utils/file.js rename to packages/openneuro-server/src/graphql/utils/file.ts diff --git a/packages/openneuro-server/src/graphql/utils/publish-draft-update.js b/packages/openneuro-server/src/graphql/utils/publish-draft-update.js deleted file mode 100644 index dc47999a3d..0000000000 --- a/packages/openneuro-server/src/graphql/utils/publish-draft-update.js +++ /dev/null @@ -1,13 +0,0 @@ -import pubsub from '../pubsub' - -export default (datasetId, revision) => { - pubsub.publish('draftUpdated', { - datasetId: datasetId, - draftUpdated: { - __typename: 'Dataset', - id: datasetId, - head: revision, - modified: new Date(), // Set date to now - }, - }) -} diff --git a/packages/openneuro-server/src/libs/__mocks__/notifications.js b/packages/openneuro-server/src/libs/__mocks__/notifications.ts similarity index 100% rename from packages/openneuro-server/src/libs/__mocks__/notifications.js rename to packages/openneuro-server/src/libs/__mocks__/notifications.ts diff --git a/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js b/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.ts similarity index 94% rename from packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js rename to packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.ts index deb3dc5cdc..f4c0d405c8 100644 --- a/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.js +++ b/packages/openneuro-server/src/libs/authentication/__tests__/jwt.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest' import User from '../../../models/user' import { addJWT } from '../jwt' diff --git a/packages/openneuro-server/src/routes.ts b/packages/openneuro-server/src/routes.ts index 9d75671f98..413691b88d 100644 --- a/packages/openneuro-server/src/routes.ts +++ b/packages/openneuro-server/src/routes.ts @@ -4,7 +4,7 @@ import express from 'express' import * as users from './handlers/users' import * as datalad from './handlers/datalad' import * as comments from './handlers/comments' -import { clientConfig } from './handlers/config.js' +import { clientConfig } from './handlers/config' import * as subscriptions from './handlers/subscriptions' import verifyUser from './libs/authentication/verifyUser' import * as google from './libs/authentication/google' @@ -12,7 +12,7 @@ import * as orcid from './libs/authentication/orcid' import * as jwt from './libs/authentication/jwt' import * as auth from './libs/authentication/states' import * as doi from './handlers/doi' -import { sitemapHandler } from './handlers/sitemap.js' +import { sitemapHandler } from './handlers/sitemap' import { reviewerHandler } from './handlers/reviewer' const noCache = (req, res, next) => {