Skip to content

Commit

Permalink
Support returning non-reviewed preprints and version-of-record types …
Browse files Browse the repository at this point in the history
…as preprints. (#72)
  • Loading branch information
nlisgo authored May 14, 2024
1 parent df933b0 commit 63a467e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// export types useful to use this as a library
export * from './types/docmap';
export {
VersionedPreprint,
VersionedReviewedPreprint,
ManuscriptData,
ReviewType,
Expand Down
39 changes: 31 additions & 8 deletions src/parser/docmap-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ManuscriptData,
ReviewType,
VersionedReviewedPreprint,
VersionedPreprint,
} from './docmap-parser';
import { fixtures } from '../test-fixtures/docmap-parser';

Expand Down Expand Up @@ -428,6 +429,22 @@ describe('docmap-parser', () => {
});
});

it('can parse a docmap with an inference of version of record from input/outputs', () => {
const parsedData = parseDocMap(fixtures.inferredVersionOfRecord());

expect(parsedData.versions.length).toStrictEqual(1);
expect(parsedData.versions[0]).toMatchObject<VersionedPreprint>({
doi: 'vor/article1',
id: 'vor/article1',
publishedDate: new Date('2024-05-09'),
url: 'https://version-of-record',
content: [
'https://doi.org/version-of-record',
],
versionIdentifier: '1',
});
});

it('inference of reviewed preprint from input/outputs', () => {
const parsedData = parseDocMap(fixtures.inferredReviewedPreprint());

Expand Down Expand Up @@ -535,12 +552,14 @@ describe('docmap-parser', () => {
const parsedData = parseDocMap(fixtures.preprintUrlAndContentDataInLaterSteps());

expect(parsedData.versions.length).toStrictEqual(1);
expect(parsedData.versions[0].preprint).toMatchObject({
publishedDate: new Date('2023-06-23'),
url: 'http://somewhere.org/preprint/article1',
content: [
's3://somewhere-org-storage-bucket/preprint/article1.meca',
],
expect(parsedData.versions[0]).toMatchObject({
preprint: {
publishedDate: new Date('2023-06-23'),
url: 'http://somewhere.org/preprint/article1',
content: [
's3://somewhere-org-storage-bucket/preprint/article1.meca',
],
},
});
});

Expand All @@ -549,8 +568,12 @@ describe('docmap-parser', () => {
it('extracts license url if in an expression', () => {
const parsedData = parseDocMap(fixtures.preprintRepublishedViaAssertion());

expect(parsedData.versions[0].preprint.license).toStrictEqual('http://creativecommons.org/licenses/by/4.0/');
expect(parsedData.versions[0].license).toStrictEqual('http://creativecommons.org/licenses/by/4.0/');
expect(parsedData.versions[0]).toMatchObject({
preprint: {
license: 'http://creativecommons.org/licenses/by/4.0/',
},
license: 'http://creativecommons.org/licenses/by/4.0/',
});
});

it('extracts partOf, if present', () => {
Expand Down
10 changes: 7 additions & 3 deletions src/parser/docmap-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ type RelatedContentItem = {
thumbnail?: string,
};

export type VersionedPreprint = Preprint & {
versionIdentifier: string,
};

export type VersionedReviewedPreprint = ReviewedPreprint & {
versionIdentifier: string,
};
Expand All @@ -106,7 +110,7 @@ export type Manuscript = {
export type ManuscriptData = {
id: string,
manuscript?: Manuscript,
versions: VersionedReviewedPreprint[],
versions: Array<VersionedReviewedPreprint | VersionedPreprint>,
};

const getManuscriptFromExpression = (expression: Expression): Manuscript | false => {
Expand Down Expand Up @@ -527,10 +531,10 @@ const parseDocMapJson = (docMapJson: string): DocMap => {
return docMapStruct as DocMap;
};

export const finaliseVersions = (preprints: Array<ReviewedPreprint>): { id: string, versions: VersionedReviewedPreprint[] } => {
export const finaliseVersions = (preprints: Array<ReviewedPreprint | Preprint>): { id: string, versions: Array<VersionedReviewedPreprint | VersionedPreprint> } => {
const versions = preprints.map((preprint, index) => ({
...preprint,
versionIdentifier: preprint.versionIdentifier ?? preprint.preprint.versionIdentifier ?? `${index + 1}`,
versionIdentifier: preprint.versionIdentifier ?? (('preprint' in preprint) ? preprint.preprint.versionIdentifier : null) ?? `${index + 1}`,
}));

const { id } = preprints.slice(-1)[0];
Expand Down

0 comments on commit 63a467e

Please sign in to comment.