Skip to content

Commit 97e2a55

Browse files
committed
types
1 parent 9562e61 commit 97e2a55

9 files changed

Lines changed: 92 additions & 3 deletions

File tree

mini.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { ApiConfig, getDataset, getDatasetStorageDriver, getCollection } = require('./dist')
2+
3+
function requiredEnv(name) {
4+
const value = process.env[name]
5+
if (!value) {
6+
throw new Error(`Missing required environment variable: ${name}`)
7+
}
8+
return value
9+
}
10+
11+
async function main() {
12+
const DATAVERSE_API_URL = "http://localhost:8080/api"
13+
const DATAVERSE_API_KEY = "e79d640d-0cc1-465d-b5a1-1bc134d562e8"
14+
const DATASET_ID = "reviews"
15+
const DATASET_VERSION = process.env.DATASET_VERSION || 'latest'
16+
17+
ApiConfig.init("http://localhost:8080/api", ApiConfig.API_KEY, "e79d640d-0cc1-465d-b5a1-1bc134d562e8");
18+
19+
20+
getCollection.execute("reviews")
21+
.then(collection => {
22+
console.log('Collection allowed dataset types:', collection.allowedDatasetTypes);
23+
console.log('Collection:', collection);
24+
})
25+
.catch(error => {
26+
console.error('Error fetching collection:', {
27+
name: error?.name,
28+
message: error?.message,
29+
cause: error?.cause,
30+
stack: error?.stack,
31+
});
32+
});
33+
}
34+
35+
main().catch((error) => {
36+
console.error('Execution failed:')
37+
console.error(error?.message || error)
38+
process.exit(1)
39+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
],
1010
"scripts": {
1111
"build": "tsc",
12+
"mini": "node mini.js",
1213
"test": "jest -c jest.config.ts",
1314
"test:unit": "jest -c jest.config.unit.ts",
1415
"test:integration": "jest -c jest.config.integration.ts",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface AllowedDatasetType {
2+
name: string
3+
displayName: string
4+
description?: string
5+
}

src/collections/domain/models/Collection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DvObjectOwnerNode } from '../../../core'
22
import { CollectionContact } from './CollectionContact'
33
import { CollectionType } from './CollectionType'
4+
import { AllowedDatasetType } from './AllowedDatasetType'
45

56
export interface Collection {
67
id: number
@@ -13,6 +14,7 @@ export interface Collection {
1314
inputLevels?: CollectionInputLevel[]
1415
type: CollectionType
1516
contacts?: CollectionContact[]
17+
allowedDatasetTypes?: AllowedDatasetType[]
1618
isMetadataBlockRoot: boolean
1719
isFacetRoot: boolean
1820
childCount: number

src/collections/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ export { CollectionSearchCriteria } from './domain/models/CollectionSearchCriter
6666
export { FeaturedItem } from './domain/models/FeaturedItem'
6767
export { FeaturedItemsDTO } from './domain/dtos/FeaturedItemsDTO'
6868
export { CollectionSummary } from './domain/models/CollectionSummary'
69+
export { AllowedDatasetType } from './domain/models/AllowedDatasetType'

src/collections/infra/repositories/transformers/CollectionPayload.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface CollectionPayload {
1010
isPartOf: OwnerNodePayload
1111
inputLevels?: CollectionInputLevelPayload[]
1212
dataverseContacts?: CollectionContactPayload[]
13+
allowedDatasetTypes?: AllowedDatasetTypePayload[]
1314
dataverseType: string
1415
isMetadataBlockRoot: boolean
1516
isFacetRoot: boolean
@@ -26,3 +27,9 @@ export interface CollectionContactPayload {
2627
contactEmail: string
2728
displayOrder: number
2829
}
30+
31+
export interface AllowedDatasetTypePayload {
32+
name: string
33+
displayName: string
34+
description?: string
35+
}

src/collections/infra/repositories/transformers/collectionTransformers.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { AxiosResponse } from 'axios'
33
import {
44
CollectionContactPayload,
55
CollectionInputLevelPayload,
6-
CollectionPayload
6+
CollectionPayload,
7+
AllowedDatasetTypePayload
78
} from './CollectionPayload'
89
import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer'
910
import { CollectionFacet } from '../../../domain/models/CollectionFacet'
@@ -45,6 +46,7 @@ import {
4546
} from '../../../domain/models/MyDataCollectionItemSubset'
4647
import { PublicationStatus } from '../../../../core/domain/models/PublicationStatus'
4748
import { CollectionLinks } from '../../../domain/models/CollectionLinks'
49+
import { AllowedDatasetType } from '../../../domain/models/AllowedDatasetType'
4850

4951
export const transformCollectionResponseToCollection = (response: AxiosResponse): Collection => {
5052
const collectionPayload = response.data.data
@@ -82,6 +84,11 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
8284
}),
8385
...(collectionPayload.dataverseContacts && {
8486
contacts: transformContactsPayloadToContacts(collectionPayload.dataverseContacts)
87+
}),
88+
...(collectionPayload.allowedDatasetTypes && {
89+
allowedDatasetTypes: transformAllowedDatasetTypesPayloadToAllowedDatasetTypes(
90+
collectionPayload.allowedDatasetTypes
91+
)
8592
})
8693
}
8794
return collectionModel
@@ -252,3 +259,13 @@ const transformContactsPayloadToContacts = (
252259
displayOrder: contactPayload.displayOrder
253260
}))
254261
}
262+
263+
const transformAllowedDatasetTypesPayloadToAllowedDatasetTypes = (
264+
allowedDatasetTypesPayload: AllowedDatasetTypePayload[]
265+
): AllowedDatasetType[] => {
266+
return allowedDatasetTypesPayload.map((allowedDatasetType) => ({
267+
name: allowedDatasetType.name,
268+
displayName: allowedDatasetType.displayName,
269+
description: allowedDatasetType.description
270+
}))
271+
}

test/environment/setup.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ const API_KEY_USER_ENDPOINT = '/builtin-users/dataverseAdmin/api-token'
1515
const API_KEY_USER_PASSWORD = 'admin1'
1616

1717
export default async function setupTestEnvironment(): Promise<void> {
18-
await setupContainers()
18+
await setupContainers() //Set skipContainers to true to skip container setup and run tests against an already running instance
1919
await setupApiKey()
2020
}
2121

22-
async function setupContainers(): Promise<void> {
22+
async function setupContainers(skipContainers?: boolean): Promise<void> {
23+
if (skipContainers) {
24+
return
25+
}
2326
console.log('Cleaning up old container volumes...')
2427
fs.rmSync(`${__dirname}/docker-dev-volumes`, { recursive: true, force: true })
2528
console.log('Running test containers...')

test/testHelpers/collections/collectionHelper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export const createCollectionModel = (): Collection => {
4545
displayOrder: 0
4646
}
4747
],
48+
allowedDatasetTypes: [
49+
{
50+
name: 'review',
51+
displayName: 'Review',
52+
description: 'A review of a dataset compiled by the expert community.'
53+
}
54+
],
4855
isMetadataBlockRoot: true,
4956
isFacetRoot: true,
5057
childCount: 0
@@ -75,6 +82,13 @@ export const createCollectionPayload = (): CollectionPayload => {
7582
displayOrder: 0
7683
}
7784
],
85+
allowedDatasetTypes: [
86+
{
87+
name: 'review',
88+
displayName: 'Review',
89+
description: 'A review of a dataset compiled by the expert community.'
90+
}
91+
],
7892
isMetadataBlockRoot: true,
7993
isFacetRoot: true,
8094
childCount: 0

0 commit comments

Comments
 (0)