Skip to content

Commit 61bc6ae

Browse files
committed
refactor(api-type): change identifier type
refs: #296 # Conflicts: # api/src/core/utils.ts
1 parent 49152b7 commit 61bc6ae

File tree

7 files changed

+214
-164
lines changed

7 files changed

+214
-164
lines changed

api/src/core/adapters/dbApi/kysely/kysely.database.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export type ArticleIdentifierOrigin = "doi" | "arxiv" | "HAL";
1414

1515
// from https://schema.org/PropertyValue
1616
export interface ArticleIdentifier extends SchemaIdentifier {
17-
subjectOf: WebSite<ArticleIdentifierOrigin>;
17+
subjectOf: WebSite;
1818
additionalType: "Article";
1919
}
2020

2121
export type OrganizationIdentifierOrigin = "wikidata" | "HAL";
2222
export interface OrganizationIdentifer extends SchemaIdentifier {
23-
subjectOf: WebSite<OrganizationIdentifierOrigin>;
23+
subjectOf: WebSite;
2424
additionalType: "Organization";
2525
}
2626

@@ -43,12 +43,12 @@ export type SchemaPerson = {
4343
};
4444

4545
// from https://schema.org/WebSite
46-
export type WebSite<T> = {
46+
export type WebSite = {
4747
"@type": "Website";
4848
name: string; // Name of the website or database
4949
description?: string;
5050
url: URL; // Name of the website or database
51-
additionalType?: T; // Type of the database
51+
additionalType?: string; // Type of the database
5252
};
5353

5454
// from https://schema.org/identifier & https://schema.org/PropertyValue
@@ -58,7 +58,7 @@ export type SchemaIdentifier = {
5858
value: string; // Value of the property
5959
url?: string | URL; // Url to direct access to the element on the database
6060
valueReference?: string; // Value of the instance / database
61-
subjectOf?: WebSite<any>; // Value of the instance / database
61+
subjectOf?: WebSite; // Value of the instance / database
6262
additionalType?: string; // Organization | Article | Person | ...
6363
};
6464

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SILL } from "../../../../types/SILL";
21
import { GetScholarlyArticle } from "../../../ports/GetScholarlyArticle";
2+
import { identifersUtils } from "../../../utils";
33
import { crossRef } from "./api";
44

55
export const getScholarlyArticle: GetScholarlyArticle = async doi => {
@@ -15,16 +15,7 @@ export const getScholarlyArticle: GetScholarlyArticle = async doi => {
1515
return {
1616
"@id": workData.message.DOI,
1717
"@type": "ScholarlyArticle",
18-
identifiers: [
19-
{
20-
"@type": "PropertyValue",
21-
name: "DOI id",
22-
url: new URL(`https://doi.org/${doi}`),
23-
value: workData.message.DOI,
24-
additionalType: "Article",
25-
subjectOf: SILL.doiSource
26-
}
27-
],
18+
identifiers: [identifersUtils.makeArticleDOIIdentifier({ doi: workData.message.DOI })],
2819
headline: workData.message.title[0]
2920
};
3021
};

api/src/core/adapters/hal/getHalSoftwareExternalData.ts

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import memoize from "memoizee";
22
import { JSDOM } from "jsdom";
3-
import { SILL } from "../../../types/SILL";
43
import { GetSoftwareExternalData, SoftwareExternalData } from "../../ports/GetSoftwareExternalData";
54
import { Source } from "../../usecases/readWriteSillData";
65
import { halAPIGateway } from "./HalAPI";
76
import { HAL } from "./HalAPI/types/HAL";
87
import { crossRefSource } from "./CrossRef";
98
import { getScholarlyArticle } from "./getScholarlyArticle";
10-
import {
11-
SchemaIdentifier,
12-
SchemaOrganization,
13-
SchemaPerson,
14-
ScholarlyArticle,
15-
WebSite
16-
} from "../dbApi/kysely/kysely.database";
9+
import { SchemaIdentifier, SchemaOrganization, SchemaPerson, ScholarlyArticle } from "../dbApi/kysely/kysely.database";
10+
import { identifersUtils } from "../../utils";
1711

1812
const buildParentOrganizationTree = async (
1913
structureIdArray: number[] | string[] | undefined
@@ -76,27 +70,6 @@ const resolveStructId = (parsedXMLLabel: JSDOM, structAcronym: string) => {
7670
return Number(org[0].getAttribute("xml:id")?.split("-")[1]);
7771
};
7872

79-
const HALSource: WebSite<SILL.SourceKind> = {
80-
"@type": "Website" as const,
81-
name: "HAL instance",
82-
url: new URL("https://hal.science"),
83-
additionalType: "HAL"
84-
};
85-
86-
const SWHSource: WebSite<SILL.SourceKind> = {
87-
"@type": "Website" as const,
88-
name: "Software Heritage instance",
89-
url: new URL("https://www.softwareheritage.org/"),
90-
additionalType: "SWH"
91-
};
92-
93-
const DOISource: WebSite<SILL.SourceKind> = {
94-
"@type": "Website" as const,
95-
name: "DOI instance",
96-
url: new URL("https://www.doi.org"),
97-
additionalType: "doi"
98-
};
99-
10073
export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
10174
async ({
10275
externalId,
@@ -131,7 +104,7 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
131104
const authors = await Promise.all(
132105
codemetaSoftware.author.map(async role => {
133106
const author = role.author;
134-
const id = author?.["@id"]?.[0];
107+
const id = author?.["@id"]?.[0] ?? "fuck that shit";
135108
const affiliation = author.affiliation;
136109

137110
if (!id) throw new Error("Could find the author id");
@@ -189,19 +162,30 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
189162
);
190163

191164
const identifiers: SchemaIdentifier[] =
192-
codemetaSoftware?.identifier?.map(halIdentifier => {
165+
codemetaSoftware?.identifier?.map(identifierItem => {
193166
const base = {
194167
"@type": "PropertyValue" as const,
195-
value: halIdentifier.value,
196-
url: new URL(halIdentifier.propertyID)
168+
value: identifierItem.value,
169+
url: new URL(identifierItem.propertyID)
197170
};
198-
switch (halIdentifier["@type"]) {
171+
switch (identifierItem["@type"]) {
199172
case "hal":
200-
return { ...base, subjectOf: HALSource };
173+
return identifersUtils.makeHALIdentifier({
174+
halId: identifierItem.value,
175+
additionalType: "Software",
176+
url: identifierItem.propertyID
177+
});
201178
case "swhid":
202-
return { ...base, subjectOf: SWHSource };
179+
return identifersUtils.makeSWHIdentifier({
180+
swhId: identifierItem.value,
181+
additionalType: "Software",
182+
url: identifierItem.propertyID
183+
});
203184
case "doi":
204-
return { ...base, subjectOf: DOISource };
185+
return identifersUtils.makeDOIIdentifier({
186+
doi: identifierItem.value,
187+
additionalType: "Software"
188+
});
205189
case "bibcode":
206190
case "cern":
207191
case "prodinra":
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SILL } from "../../../types/SILL";
21
import { GetScholarlyArticle } from "../../ports/GetScholarlyArticle";
2+
import { identifersUtils } from "../../utils";
33
import { halAPIGateway } from "./HalAPI";
44

55
export const getScholarlyArticle: GetScholarlyArticle = async halDocId => {
@@ -15,16 +15,7 @@ export const getScholarlyArticle: GetScholarlyArticle = async halDocId => {
1515
return {
1616
"@id": halDocId,
1717
"@type": "ScholarlyArticle",
18-
identifiers: [
19-
{
20-
"@type": "PropertyValue",
21-
name: "DOI id",
22-
url: new URL(`https://hal.science/${halDocId}`),
23-
value: halDocId,
24-
additionalType: "Article",
25-
subjectOf: SILL.halSource
26-
}
27-
],
18+
identifiers: [identifersUtils.makeHALArticleIdentifier({ halId: halDocId })],
2819
headline: articleData.en_title_s?.[0] ?? articleData.fr_title_s?.[0] ?? articleData.title_s[0]
2920
};
3021
};

api/src/core/adapters/wikidata/getWikidataSoftware.ts

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import {
2323
wikidataTimeToJSDate,
2424
WikidataTime
2525
} from "../../../tools/WikidataEntity";
26-
import { SILL } from "../../../types/SILL";
2726
import { Source } from "../../usecases/readWriteSillData";
28-
import { SchemaIdentifier, SchemaOrganization, SchemaPerson } from "../dbApi/kysely/kysely.database";
27+
import { SchemaOrganization, SchemaPerson } from "../dbApi/kysely/kysely.database";
28+
import { identifersUtils } from "../../utils";
2929

3030
const { resolveLocalizedString } = createResolveLocalizedString({
3131
"currentLanguage": id<Language>("en"),
@@ -120,16 +120,6 @@ export const getWikidataSoftware: GetSoftwareExternalData = memoize(
120120

121121
const framaLibreId = getClaimDataValue<"string">("P4107")[0];
122122

123-
const makeFramaIndentifer = (framaLibreId: string): SchemaIdentifier => {
124-
return {
125-
"@type": "PropertyValue",
126-
name: "ID of FramaLibre",
127-
value: framaLibreId,
128-
url: new URL(framaLibreId),
129-
subjectOf: SILL.framaLibreSource
130-
};
131-
};
132-
133123
return {
134124
externalId,
135125
sourceSlug: source.slug,
@@ -256,13 +246,10 @@ export const getWikidataSoftware: GetSoftwareExternalData = memoize(
256246
"@type": "Person",
257247
name,
258248
identifiers: [
259-
{
260-
value: entity.id,
261-
"@type": "PropertyValue",
262-
url: `https://www.wikidata.org/wiki/${entity.id}`,
263-
subjectOf: SILL.wikidataSource,
264-
name: "Wikidata Id"
265-
}
249+
identifersUtils.makeWikidataIdentifier({
250+
wikidataId: entity.id,
251+
additionalType: "Person"
252+
})
266253
],
267254
url: `https://www.wikidata.org/wiki/${entity.id}`
268255
};
@@ -272,14 +259,10 @@ export const getWikidataSoftware: GetSoftwareExternalData = memoize(
272259
"@type": "Organization",
273260
name,
274261
identifiers: [
275-
{
276-
value: entity.id,
277-
"@type": "PropertyValue",
278-
url: `https://www.wikidata.org/wiki/${entity.id}`,
279-
subjectOf: SILL.wikidataSource,
280-
name: "Wikidata Id",
262+
identifersUtils.makeWikidataIdentifier({
263+
wikidataId: entity.id,
281264
additionalType: "Organization"
282-
}
265+
})
283266
],
284267
url: `https://www.wikidata.org/wiki/${entity.id}`
285268
};
@@ -301,7 +284,13 @@ export const getWikidataSoftware: GetSoftwareExternalData = memoize(
301284
applicationCategories: undefined, // doesn't exit on wiki data
302285
referencePublications: undefined, // doesn't exit on wiki data
303286
publicationTime: publicationTimeDate,
304-
identifiers: framaLibreId?.includes("https") ? [makeFramaIndentifer(framaLibreId)] : []
287+
identifiers: [
288+
...(framaLibreId
289+
? [identifersUtils.makeFramaIndentifier({ framaLibreId, additionalType: "Software" })]
290+
: []),
291+
identifersUtils.makeWikidataIdentifier({ wikidataId: externalId, additionalType: "Software" })
292+
],
293+
providers: []
305294
};
306295
},
307296
{

0 commit comments

Comments
 (0)