@openneuro/server 4.14.1 → 4.14.2-alpha.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.14.1",
3
+ "version": "4.14.2-alpha.0",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "@apollo/client": "3.7.2",
19
19
  "@elastic/elasticsearch": "7.15.0",
20
- "@openneuro/search": "^4.14.1",
20
+ "@openneuro/search": "^4.14.2-alpha.0",
21
21
  "@passport-next/passport-google-oauth2": "^1.0.0",
22
22
  "@sentry/node": "^4.5.3",
23
23
  "apollo-server": "2.25.4",
@@ -92,5 +92,5 @@
92
92
  "publishConfig": {
93
93
  "access": "public"
94
94
  },
95
- "gitHead": "594ef5282269b36a749327f39bc39253dbdec83f"
95
+ "gitHead": "17f642273df2fdd5bbfd490d0eb9a51109b0ea4f"
96
96
  }
@@ -1,7 +1,6 @@
1
1
  import request from 'superagent'
2
2
  import {
3
3
  getDescriptionObject,
4
- defaultDescription,
5
4
  repairDescriptionTypes,
6
5
  appendSeniorAuthor,
7
6
  } from '../description.js'
@@ -96,9 +95,7 @@ describe('datalad dataset descriptions', () => {
96
95
  body: { Name: 'Balloon Analog Risk-taking Task' },
97
96
  type: 'application/json',
98
97
  })
99
- const description = await getDescriptionObject('ds000001')([
100
- { filename: 'dataset_description.json', id: '12345' },
101
- ])
98
+ const description = await getDescriptionObject('ds000001', '1.0.0')
102
99
  expect(description).toEqual({ Name: 'Balloon Analog Risk-taking Task' })
103
100
  })
104
101
  it('handles a corrupted response', async () => {
@@ -106,15 +103,11 @@ describe('datalad dataset descriptions', () => {
106
103
  request.__setMockResponse({
107
104
  body: Buffer.from('0x5f3759df', 'hex'),
108
105
  })
109
- const description = await getDescriptionObject('ds000001')([
110
- { filename: 'dataset_description.json', id: '12345' },
111
- ])
112
- expect(description).toEqual(defaultDescription)
106
+ const description = await getDescriptionObject('ds000001', '1.0.0')
107
+ expect(description).toEqual({ Name: 'ds000001', BIDSVersion: '1.8.0' })
113
108
  })
114
109
  it('works without a dataset_description.json being present', async () => {
115
- const description = await getDescriptionObject('ds000001')([
116
- { filename: 'LICENSE', id: '12345' },
117
- ])
118
- expect(description).toEqual(defaultDescription)
110
+ const description = await getDescriptionObject('ds000001', '1.0.0')
111
+ expect(description).toEqual({ Name: 'ds000001', BIDSVersion: '1.8.0' })
119
112
  })
120
113
  })
@@ -5,39 +5,33 @@ import config from '../config'
5
5
  import request from 'superagent'
6
6
  import { redis } from '../libs/redis.js'
7
7
  import { commitFiles } from './dataset.js'
8
- import { fileUrl, getFiles } from './files.js'
8
+ import { fileUrl } from './files.js'
9
9
  import { generateDataladCookie } from '../libs/authentication/jwt'
10
10
  import { getDatasetWorker } from '../libs/datalad-service'
11
11
  import CacheItem, { CacheType } from '../cache/item'
12
12
  import { datasetOrSnapshot } from '../utils/datasetOrSnapshot'
13
13
 
14
- export const defaultDescription = {
15
- Name: 'Unnamed Dataset',
16
- BIDSVersion: '1.1.1',
17
- }
18
-
19
14
  /**
20
15
  * Find dataset_description.json id and fetch description object
21
16
  * @param {string} datasetId
22
- * @returns {(files: [Record<string, unknown>]) => Promise<Record<string, unknown>>} Promise resolving to dataset_description.json contents or defaults
17
+ * @returns {Promise<Record<string, unknown>>} Promise resolving to dataset_description.json contents or defaults
23
18
  */
24
- export const getDescriptionObject = datasetId => files => {
25
- const file = files.find(f => f.filename === 'dataset_description.json')
26
- if (file) {
27
- return request
28
- .get(fileUrl(datasetId, '', 'dataset_description.json'))
29
- .then(({ body, type }) => {
30
- // Guard against non-JSON responses
31
- if (type === 'application/json') return body
32
- else throw new Error('dataset_description.json is not JSON')
33
- })
34
- .catch(() => {
35
- // dataset_description does not exist or is not JSON, return default fields
36
- return defaultDescription
37
- })
38
- } else {
39
- return Promise.resolve(defaultDescription)
19
+ export const getDescriptionObject = (datasetId, revision) => {
20
+ const defaultDescription = {
21
+ Name: datasetId,
22
+ BIDSVersion: '1.8.0',
40
23
  }
24
+ return request
25
+ .get(fileUrl(datasetId, '', 'dataset_description.json', revision))
26
+ .then(({ body, type }) => {
27
+ // Guard against non-JSON responses
28
+ if (type === 'application/json') return body
29
+ else throw new Error('dataset_description.json is not JSON')
30
+ })
31
+ .catch(() => {
32
+ // dataset_description does not exist or is not JSON, return default fields
33
+ return defaultDescription
34
+ })
41
35
  }
42
36
 
43
37
  export const descriptionCacheKey = (datasetId, revision) => {
@@ -126,9 +120,9 @@ export const description = obj => {
126
120
  ])
127
121
  return cache
128
122
  .get(() => {
129
- return getFiles(datasetId, revision)
130
- .then(getDescriptionObject(datasetId))
131
- .then(uncachedDescription => ({ id: revision, ...uncachedDescription }))
123
+ return getDescriptionObject(datasetId, revision).then(
124
+ uncachedDescription => ({ id: revision, ...uncachedDescription }),
125
+ )
132
126
  })
133
127
  .then(description => repairDescriptionTypes(description))
134
128
  .then(description => appendSeniorAuthor(description))
@@ -34,13 +34,19 @@ export const getFileName = (path, filename) => {
34
34
  * @param {String} datasetId
35
35
  * @param {String} path - Relative path for the file
36
36
  * @param {String} filename
37
+ * @param {String} [revision] - Git hash of commit or tree owning this file
37
38
  */
38
- export const fileUrl = (datasetId, path, filename) => {
39
+ export const fileUrl = (datasetId, path, filename, revision) => {
39
40
  const fileName = getFileName(path, filename)
40
- const url = `http://${getDatasetWorker(
41
- datasetId,
42
- )}/datasets/${datasetId}/files/${fileName}`
43
- return url
41
+ if (revision) {
42
+ return `http://${getDatasetWorker(
43
+ datasetId,
44
+ )}/datasets/${datasetId}/snapshots/${revision}/files/${fileName}`
45
+ } else {
46
+ return `http://${getDatasetWorker(
47
+ datasetId,
48
+ )}/datasets/${datasetId}/files/${fileName}`
49
+ }
44
50
  }
45
51
 
46
52
  /**