Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
- Files: Added `getFileCitationByFormat` use case, repository method, and `FileCitationFormat` enum to support Dataverse file citation exports in `EndNote`, `RIS`, `BibTeX`, `CSL`, and `Internal` formats.
- Datasets: Added `getDatasetReviews` use case and repository method to support Dataverse endpoint `GET /datasets/{identifier}/reviews`, for retrieving review datasets associated with a dataset by persistent id or numeric id.
- Datasets: Added `exportDatasetMetadata` use case, repository method, and `ExportedDatasetMetadata` response type to support exporting dataset metadata by numeric id or persistent id through Dataverse endpoint `GET /datasets/export`.
- Datasets: Added `getDatasetVersions` use case.
- Collections: Added `allowedDatasetTypes` field to the [Collection](./src/collections/domain/models/Collection.ts) model. This field is optional and only populated the feature is enabled on the installation and configured on the collection.
- Collections: Added theme information when retrieving a collection using `getCollection`.

Expand Down
31 changes: 31 additions & 0 deletions docs/useCases.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The different use cases currently available in the package are classified below,
- [Get User Permissions on a Dataset](#get-user-permissions-on-a-dataset)
- [Get Differences between Two Dataset Versions](#get-differences-between-two-dataset-versions)
- [List All Datasets](#list-all-datasets)
- [Get Dataset Versions](#get-dataset-versions)
- [Get Dataset Versions Summaries](#get-dataset-versions-summaries)
- [Get Dataset Linked Collections](#get-dataset-linked-collections)
- [Get Dataset Available Categories](#get-dataset-available-categories)
Expand Down Expand Up @@ -1262,6 +1263,36 @@ Note that `collectionId` is an optional parameter to filter datasets by collecti

The `DatasetPreviewSubset`returned instance contains a property called `totalDatasetCount` which is necessary for pagination.

#### Get Dataset Versions

Returns the total count of versions and an array of [DatasetVersion](../src/datasets/domain/models/DatasetVersion.ts) that contains information about every specific version.

##### Example call:

```typescript
import { getDatasetVersions } from '@iqss/dataverse-client-javascript'

/* ... */

const datasetId = 'doi:10.77777/FK2/AAAAAA'

getDatasetVersions
.execute(datasetId)
.then((datasetVersions: DatasetVersionSubset) => {
/* ... */
})

/* ... */
```

_See [use case](../src/datasets/domain/useCases/GetDatasetVersions.ts) implementation_.

- The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.
- **limit**: (number) Limit for pagination.
- **offset**: (number) Offset for pagination.
- **excludeMetadataBlocks**: (boolean) Exclude metadata blocks (default: false).
- Note that the **excludeFiles** parameter, which is available on Dataverse's "List Versions of a Dataset" API, is not available here. The list of files can be retrieved using the separate use case [List Files in a Dataset](#list-files-in-a-dataset).

#### Get Dataset Versions Summaries

Returns the total count of versions and an array of [DatasetVersionSummaryInfo](../src/datasets/domain/models/DatasetVersionSummaryInfo.ts) that contains information about what changed in every specific version.
Expand Down
28 changes: 28 additions & 0 deletions src/datasets/domain/models/DatasetVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { DatasetLicense, DatasetMetadataBlocks, DatasetVersionState } from "./Dataset";
import { FilePayload } from "../../../files/infra/repositories/transformers/FilePayload";

Check failure on line 2 in src/datasets/domain/models/DatasetVersion.ts

View workflow job for this annotation

GitHub Actions / publish-gpr

'FilePayload' is declared but its value is never read.

export interface DatasetVersion {
id: number
datasetId: number
datasetPersistentId: string
alternativePersistentId?: string
datasetType: string
storageIdentifier: string
versionNumber?: number
versionMinorNumber?: number
internalVersionNumber: number
versionState: DatasetVersionState
latestVersionPublishingState: DatasetVersionState
lastUpdateTime: string
releaseTime?: string
createTime: string
publicationDate: string
citationDate: string
license: DatasetLicense
fileAccessRequest: boolean
metadataBlocks?: DatasetMetadataBlocks
}

export interface DatasetVersionSubset {
versions: DatasetVersion[]
}
7 changes: 7 additions & 0 deletions src/datasets/domain/repositories/IDatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MetadataBlock } from '../../../metadataBlocks'
import { DatasetVersionDiff } from '../models/DatasetVersionDiff'
import { DatasetDownloadCount } from '../models/DatasetDownloadCount'
import { DatasetVersionSummarySubset } from '../models/DatasetVersionSummaryInfo'
import { DatasetVersionSubset } from '../models/DatasetVersion'
import { DatasetLinkedCollection } from '../models/DatasetLinkedCollection'
import { CitationFormat } from '../models/CitationFormat'
import { FormattedCitation } from '../models/FormattedCitation'
Expand Down Expand Up @@ -77,6 +78,12 @@ export interface IDatasetsRepository {
limit?: number,
offset?: number
): Promise<DatasetVersionSummarySubset>
getDatasetVersions(
datasetId: number | string,
limit?: number,
offset?: number,
excludeMetadataBlocks?: boolean
): Promise<DatasetVersionSubset>
deleteDatasetDraft(datasetId: number | string): Promise<void>
linkDataset(datasetId: number | string, collectionIdOrAlias: number | string): Promise<void>
unlinkDataset(datasetId: number | string, collectionIdOrAlias: number | string): Promise<void>
Expand Down
30 changes: 30 additions & 0 deletions src/datasets/domain/useCases/GetDatasetVersions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { DatasetVersionSubset } from '../models/DatasetVersion'
import { IDatasetsRepository } from '../repositories/IDatasetsRepository'

export class GetDatasetVersions implements UseCase<DatasetVersionSubset> {
private datasetsRepository: IDatasetsRepository

constructor(datasetsRepository: IDatasetsRepository) {
this.datasetsRepository = datasetsRepository
}

/**
* Returns a list of versions for a given dataset including (optionally) metadata blocks and files.
* Draft versions will only be available to users who have permission to view unpublished drafts.
*
* @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
* @param {number} [limit] - Limit for pagination (optional).
* @param {number} [offset] - Offset for pagination (optional).
* @param {boolean} [excludeMetadataBlocks] - Exclude metadata blocks (optional, default: false).
* @returns {Promise<DatasetVersionSubset>} - A DatasetVersionSubset containing the versions and total count.
*/
async execute(
datasetId: number | string,
limit?: number,
offset?: number,
excludeMetadataBlocks?: boolean
): Promise<DatasetVersionSubset> {
return await this.datasetsRepository.getDatasetVersions(datasetId, limit, offset, excludeMetadataBlocks)
}
}
4 changes: 4 additions & 0 deletions src/datasets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { GetDatasetVersionDiff } from './domain/useCases/GetDatasetVersionDiff'
import { DeaccessionDataset } from './domain/useCases/DeaccessionDataset'
import { GetDatasetDownloadCount } from './domain/useCases/GetDatasetDownloadCount'
import { GetDatasetVersionsSummaries } from './domain/useCases/GetDatasetVersionsSummaries'
import { GetDatasetVersions } from './domain/useCases/GetDatasetVersions'
import { DeleteDatasetDraft } from './domain/useCases/DeleteDatasetDraft'
import { LinkDataset } from './domain/useCases/LinkDataset'
import { UnlinkDataset } from './domain/useCases/UnlinkDataset'
Expand Down Expand Up @@ -70,6 +71,7 @@ const updateDataset = new UpdateDataset(
const deaccessionDataset = new DeaccessionDataset(datasetsRepository)
const getDatasetDownloadCount = new GetDatasetDownloadCount(datasetsRepository)
const getDatasetVersionsSummaries = new GetDatasetVersionsSummaries(datasetsRepository)
const getDatasetVersions = new GetDatasetVersions(datasetsRepository)
const deleteDatasetDraft = new DeleteDatasetDraft(datasetsRepository)
const linkDataset = new LinkDataset(datasetsRepository)
const unlinkDataset = new UnlinkDataset(datasetsRepository)
Expand Down Expand Up @@ -107,6 +109,7 @@ export {
deaccessionDataset,
getDatasetDownloadCount,
getDatasetVersionsSummaries,
getDatasetVersions,
deleteDatasetDraft,
linkDataset,
unlinkDataset,
Expand Down Expand Up @@ -143,6 +146,7 @@ export {
TermsOfUse
} from './domain/models/Dataset'
export { DatasetPreview } from './domain/models/DatasetPreview'
export { DatasetVersion } from './domain/models/DatasetVersion'
export { DatasetVersionDiff } from './domain/models/DatasetVersionDiff'
export { DatasetPreviewSubset } from './domain/models/DatasetPreviewSubset'
export {
Expand Down
34 changes: 34 additions & 0 deletions src/datasets/infra/repositories/DatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { DatasetVersionDiff } from '../../domain/models/DatasetVersionDiff'
import { transformDatasetVersionDiffResponseToDatasetVersionDiff } from './transformers/datasetVersionDiffTransformers'
import { DatasetDownloadCount } from '../../domain/models/DatasetDownloadCount'
import { DatasetVersionSummarySubset } from '../../domain/models/DatasetVersionSummaryInfo'
import { DatasetVersionSubset } from '../../domain/models/DatasetVersion'
import { DatasetLinkedCollection } from '../../domain/models/DatasetLinkedCollection'
import { CitationFormat } from '../../domain/models/CitationFormat'
import { transformDatasetLinkedCollectionsResponseToDatasetLinkedCollection } from './transformers/datasetLinkedCollectionsTransformers'
Expand Down Expand Up @@ -372,6 +373,39 @@ export class DatasetsRepository extends ApiRepository implements IDatasetsReposi
})
}

public async getDatasetVersions(
datasetId: string | number,
limit?: number,
offset?: number,
excludeMetadataBlocks?: boolean
): Promise<DatasetVersionSubset> {
const queryParams = new URLSearchParams()

if (limit) {
queryParams.set('limit', limit.toString())
}

if (offset) {
queryParams.set('offset', offset.toString())
}

if (excludeMetadataBlocks !== undefined) {
queryParams.set('excludeMetadataBlocks', excludeMetadataBlocks.toString())
}

return this.doGet(
this.buildApiEndpoint(this.datasetsResourceName, 'versions', datasetId),
true,
queryParams
)
.then((response) => ({
versions: response.data.data
}))
.catch((error) => {
throw error
})
}

public async deleteDatasetDraft(datasetId: string | number): Promise<void> {
return this.doDelete(
this.buildApiEndpoint(this.datasetsResourceName, 'versions/:draft', datasetId)
Expand Down
Loading
Loading