@openneuro/server 4.22.0-alpha.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openneuro/server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.23.0",
|
|
4
4
|
"description": "Core service for the OpenNeuro platform.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/server.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@elastic/elasticsearch": "7.15.0",
|
|
22
22
|
"@graphql-tools/schema": "^10.0.0",
|
|
23
23
|
"@keyv/redis": "^2.7.0",
|
|
24
|
-
"@openneuro/search": "^4.
|
|
24
|
+
"@openneuro/search": "^4.23.0",
|
|
25
25
|
"@passport-next/passport-google-oauth2": "^1.0.0",
|
|
26
26
|
"@sentry/node": "^4.5.3",
|
|
27
27
|
"base64url": "^3.0.0",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"passport-jwt": "^4.0.0",
|
|
53
53
|
"passport-oauth2-refresh": "^2.0.0",
|
|
54
54
|
"passport-orcid": "^0.0.3",
|
|
55
|
-
"react": "^
|
|
56
|
-
"react-dom": "^
|
|
55
|
+
"react": "^18.2.0",
|
|
56
|
+
"react-dom": "^18.2.0",
|
|
57
57
|
"redlock": "^4.0.0",
|
|
58
58
|
"request": "^2.83.0",
|
|
59
59
|
"semver": "^5.5.0",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "e86df78635d7ac6cfa03a2add5760b8539103583"
|
|
89
89
|
}
|
|
@@ -20,11 +20,12 @@ import { getDatasetWorker } from "../../libs/datalad-service"
|
|
|
20
20
|
import { getFileName } from "../../datalad/files"
|
|
21
21
|
import { onBrainlife } from "./brainlife"
|
|
22
22
|
import { derivatives } from "./derivatives"
|
|
23
|
+
import { promiseTimeout } from "../../utils/promiseTimeout"
|
|
23
24
|
import semver from "semver"
|
|
24
25
|
|
|
25
26
|
export const dataset = async (obj, { id }, { user, userInfo }) => {
|
|
26
27
|
await checkDatasetRead(id, user, userInfo)
|
|
27
|
-
return datalad.getDataset(id)
|
|
28
|
+
return promiseTimeout(datalad.getDataset(id), 30000)
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export const datasets = (parent, args, { user, userInfo }) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { promiseTimeout } from "../promiseTimeout"
|
|
2
|
+
|
|
3
|
+
describe("withTimeout", () => {
|
|
4
|
+
it("rejects with null when the promise exceeds timeout milliseconds", async () => {
|
|
5
|
+
const slowPromise = new Promise((resolve) =>
|
|
6
|
+
setTimeout(() => resolve("Slow Result"), 500)
|
|
7
|
+
)
|
|
8
|
+
expect(await promiseTimeout(slowPromise, 100)).toBeNull()
|
|
9
|
+
})
|
|
10
|
+
it("resolves when the promise returns before timeout", async () => {
|
|
11
|
+
const slowPromise = new Promise((resolve) =>
|
|
12
|
+
setTimeout(() => resolve("Fast Result"), 10)
|
|
13
|
+
)
|
|
14
|
+
expect(await promiseTimeout(slowPromise, 500)).toBe("Fast Result")
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PromiseTimeoutError } from "../types/promiseTimeoutError"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add a timeout to a promise and return null if timeout occurs before the promise resolves
|
|
5
|
+
* @param promise Promise to timeout
|
|
6
|
+
* @param timeout Timeout in milliseconds
|
|
7
|
+
*/
|
|
8
|
+
export async function promiseTimeout<T>(
|
|
9
|
+
promise: Promise<T>,
|
|
10
|
+
timeout: number,
|
|
11
|
+
): Promise<T | null> {
|
|
12
|
+
try {
|
|
13
|
+
const result = await Promise.race([
|
|
14
|
+
promise,
|
|
15
|
+
new Promise((_, reject) =>
|
|
16
|
+
setTimeout(
|
|
17
|
+
() => reject(new PromiseTimeoutError("Operation timed out")),
|
|
18
|
+
timeout,
|
|
19
|
+
)
|
|
20
|
+
),
|
|
21
|
+
])
|
|
22
|
+
// @ts-expect-error This does return the original promise except in failure cases where it returns the expected null
|
|
23
|
+
return result
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (error instanceof PromiseTimeoutError) {
|
|
26
|
+
return null
|
|
27
|
+
} else {
|
|
28
|
+
throw error // Re-throw other errors
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|