Skip to content

Commit

Permalink
feat: add related content to manuscript (#46)
Browse files Browse the repository at this point in the history
* feat: add related content to manuscript

This commit includes changes to support adding related content to the manuscript. It introduces a new type 'Complement' and updates the 'generateManuscript' function to include an optional 'complement' parameter. The 'docmap-parser' is updated to parse 'relatedContent' and the tests are updated to cover these changes.

* feat: Replace Complement with Insight in docmap

This commit replaces the Complement type with Insight in the docmap. It updates the generateManuscript function to use the new Insight type and modifies related tests. Also, this commit adds the generateInsight function and makes changes to the RelatedContentItem and the Manuscript types.

* feat: Update type definitions in docmap.ts

This commit adds optional 'title', 'description' and 'thumbnail' fields to the Manuscript type. It also removes 'title', 'url', 'description', and 'thumbnail' from the Insight type.
  • Loading branch information
nlisgo authored Mar 14, 2024
1 parent e2ef29b commit 83be3b9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/docmap-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Expression,
ExpressionType,
Input,
Insight,
Item,
JsonLDAddonFrame,
JsonLDFrameUrl,
Expand All @@ -20,7 +21,8 @@ import {
Participant,
PeerReview,
Preprint,
Publisher, Reply,
Publisher,
Reply,
RevisedPreprint,
Step,
UpdateSummary,
Expand Down Expand Up @@ -113,6 +115,14 @@ export const generateVersionOfRecord = (published: Date, content: WebPage[], doi
content,
});

export const generateInsight = (title: string, url: Url, description?: string, thumbnail?: Url): Insight => ({
type: ExpressionType.Insight,
title,
url,
description,
thumbnail,
});

export const generateContent = (type: ManifestationType, url: Url): Manifestation => ({
type,
url,
Expand All @@ -123,13 +133,14 @@ export const generateWebContent = (url: Url): WebPage => ({
url,
});

export const generateManuscript = (doi?: DOI, identifier?: string, volumeIdentifier?: string, electronicArticleIdentifier?: string, subjectDisciplines?: string[], published?: Date): Manuscript => ({
export const generateManuscript = (doi?: DOI, identifier?: string, volumeIdentifier?: string, electronicArticleIdentifier?: string, subjectDisciplines?: string[], complement?: Expression[], published?: Date): Manuscript => ({
type: 'manuscript',
doi,
identifier,
volumeIdentifier,
electronicArticleIdentifier,
subjectDisciplines,
complement,
published,
});

Expand Down
11 changes: 11 additions & 0 deletions src/docmap-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ describe('docmap-parser', () => {
});
});

it('parses relatedContent', () => {
const docmap = fixtures.preprintWithPartialManuscriptWithRelatedContent();
const parsedData = parseDocMap(docmap);

expect(parsedData.manuscript?.relatedContent).toEqual([{
type: 'insight',
title: 'Insight Title',
url: 'https://somewhere.org/insight',
}]);
});

it('parses publishedDate', () => {
const docmap = fixtures.preprintWithPartialManuscriptWithPublishedDate();
const parsedData = parseDocMap(docmap);
Expand Down
13 changes: 13 additions & 0 deletions src/docmap-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ type ReviewedPreprint = {
license?: string,
};

type RelatedContentItem = {
type: string,
title?: string,
url?: string,
description?: string,
thumbnail?: string,
};

export type VersionedReviewedPreprint = ReviewedPreprint & {
versionIdentifier: string,
};
Expand All @@ -92,6 +100,7 @@ export type Manuscript = {
eLocationId?: string,
publishedDate?: Date,
subjects?: string[],
relatedContent?: RelatedContentItem[],
};

export type ManuscriptData = {
Expand All @@ -110,6 +119,7 @@ const getManuscriptFromExpression = (expression: Expression): Manuscript | false
volume: expression.partOf.volumeIdentifier,
eLocationId: expression.partOf.electronicArticleIdentifier,
subjects: expression.partOf.subjectDisciplines,
relatedContent: expression.partOf.complement,
publishedDate: expression.partOf.published,
};
};
Expand Down Expand Up @@ -216,6 +226,9 @@ const findAndUpdateOrAddPreprintDescribedBy = (expression: Expression, preprintC
if (foundManuscriptData.subjects) {
existingManuscript.subjects = foundManuscriptData.subjects;
}
if (foundManuscriptData.relatedContent) {
existingManuscript.relatedContent = foundManuscriptData.relatedContent;
}
if (foundManuscriptData.publishedDate) {
existingManuscript.publishedDate = foundManuscriptData.publishedDate;
}
Expand Down
9 changes: 9 additions & 0 deletions src/docmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum ExpressionType {
AuthorResponse = 'author-response',
Reply = 'reply',
UpdateSummary = 'update-summary',
Insight = 'insight',
}

export enum ManifestationType {
Expand All @@ -40,6 +41,9 @@ export type Expression = {
content?: Manifestation[],
license?: string,
partOf?: Manuscript,
title?: string,
description?: string,
thumbnail?: Url,
};

export type Manifestation = {
Expand Down Expand Up @@ -81,6 +85,10 @@ export type VersionOfRecord = Expression & {
type: ExpressionType.VersionOfRecord,
};

export type Insight = Expression & {
type: ExpressionType.Insight,
};

export type WebPage = Manifestation & {
type: ManifestationType.WebPage,
};
Expand Down Expand Up @@ -135,6 +143,7 @@ export type Manuscript = {
volumeIdentifier?: string,
electronicArticleIdentifier?: string,
subjectDisciplines?: string[],
complement?: Expression[],
published?: Date,
};

Expand Down
10 changes: 9 additions & 1 deletion src/test-fixtures/docmapGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
generateUnderReviewAssertion,
generateWebContent,
generateManuscript,
generateInsight,
} from '../docmap-generator';

const publisher = {
Expand Down Expand Up @@ -64,8 +65,15 @@ export const fixtures = {
return generateDocMap('test', publisher, firstStep);
},

preprintWithPartialManuscriptWithRelatedContent: (): DocMap => {
const manuscript = generateManuscript('10.1101/123456', '123456', undefined, 'RP123456', undefined, [generateInsight('Insight Title', 'https://somewhere.org/insight')]);
const preprint = generatePreprint('preprint/article1', new Date('2022-03-01'), undefined, undefined, undefined, undefined, manuscript);
const firstStep = generateStep([], [generateAction([], [preprint])], []);
return generateDocMap('test', publisher, firstStep);
},

preprintWithPartialManuscriptWithPublishedDate: (): DocMap => {
const manuscript = generateManuscript('10.1101/123456', '123456', undefined, 'RP123456', undefined, new Date('2022-03-01'));
const manuscript = generateManuscript('10.1101/123456', '123456', undefined, 'RP123456', undefined, undefined, new Date('2022-03-01'));
const preprint = generatePreprint('preprint/article1', new Date('2022-03-01'), undefined, undefined, undefined, undefined, manuscript);
const firstStep = generateStep([], [generateAction([], [preprint])], []);
return generateDocMap('test', publisher, firstStep);
Expand Down

0 comments on commit 83be3b9

Please sign in to comment.