Skip to content

Commit bf6738f

Browse files
committed
fix: name fixes, types, configs
refs: #295
1 parent de5ecef commit bf6738f

File tree

7 files changed

+60
-54
lines changed

7 files changed

+60
-54
lines changed

api/src/core/adapters/comptoirDuLibre/getCDLExternalData.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Source } from "../../usecases/readWriteSillData";
55
import { comptoirDuLibreApi } from "../comptoirDuLibreApi";
66
import { ComptoirDuLibre } from "../../ports/ComptoirDuLibreApi";
77
import { SchemaOrganization } from "../dbApi/kysely/kysely.database";
8-
import { identifersUtils } from "../../utils";
8+
import { identifersUtils } from "../../../tools/identifiersTools";
99

1010
export const getCDLSoftwareExternalData: GetSoftwareExternalData = memoize(
1111
async ({
@@ -22,10 +22,13 @@ export const getCDLSoftwareExternalData: GetSoftwareExternalData = memoize(
2222
if (!comptoirSoftware) return undefined;
2323

2424
return formatCDLSoftwareToExternalData(comptoirSoftware, source);
25+
},
26+
{
27+
maxAge: 3 * 3600 * 1000
2528
}
2629
);
2730

28-
const cDLproviderToCMProdivers = (provider: ComptoirDuLibre.Provider): SchemaOrganization => {
31+
const cdlProviderToCMProdivers = (provider: ComptoirDuLibre.Provider): SchemaOrganization => {
2932
return {
3033
"@type": "Organization" as const,
3134
name: provider.name,
@@ -41,26 +44,26 @@ const cDLproviderToCMProdivers = (provider: ComptoirDuLibre.Provider): SchemaOrg
4144
};
4245

4346
const formatCDLSoftwareToExternalData = (
44-
cDLSoftwareItem: ComptoirDuLibre.Software,
47+
cdlSoftwareItem: ComptoirDuLibre.Software,
4548
source: Source
4649
): SoftwareExternalData => {
47-
const splittedCNLLUrl = !Array.isArray(cDLSoftwareItem.external_resources.cnll)
48-
? cDLSoftwareItem.external_resources.cnll.url.split("/")
50+
const splittedCNLLUrl = !Array.isArray(cdlSoftwareItem.external_resources.cnll)
51+
? cdlSoftwareItem.external_resources.cnll.url.split("/")
4952
: undefined;
5053

5154
return {
52-
externalId: cDLSoftwareItem.id.toString(),
55+
externalId: cdlSoftwareItem.id.toString(),
5356
sourceSlug: source.slug,
5457
developers: [],
55-
label: { "fr": cDLSoftwareItem.name },
58+
label: { "fr": cdlSoftwareItem.name },
5659
description: { "fr": "" },
5760
isLibreSoftware: true,
5861
//
5962
logoUrl: undefined, // Use scrapper ?
60-
websiteUrl: cDLSoftwareItem.external_resources.website ?? undefined,
61-
sourceUrl: cDLSoftwareItem.external_resources.repository ?? undefined,
63+
websiteUrl: cdlSoftwareItem.external_resources.website ?? undefined,
64+
sourceUrl: cdlSoftwareItem.external_resources.repository ?? undefined,
6265
documentationUrl: undefined,
63-
license: cDLSoftwareItem.licence,
66+
license: cdlSoftwareItem.licence,
6467
softwareVersion: undefined,
6568
keywords: [],
6669
programmingLanguages: [],
@@ -69,37 +72,37 @@ const formatCDLSoftwareToExternalData = (
6972
referencePublications: [],
7073
identifiers: [
7174
identifersUtils.makeCDLIdentifier({
72-
cdlId: cDLSoftwareItem.id.toString(),
73-
url: cDLSoftwareItem.url,
75+
cdlId: cdlSoftwareItem.id.toString(),
76+
url: cdlSoftwareItem.url,
7477
additionalType: "Software"
7578
}),
76-
...(!Array.isArray(cDLSoftwareItem.external_resources.cnll) && splittedCNLLUrl
79+
...(!Array.isArray(cdlSoftwareItem.external_resources.cnll) && splittedCNLLUrl
7780
? [
7881
identifersUtils.makeCNLLIdentifier({
7982
cNNLId: splittedCNLLUrl[splittedCNLLUrl.length - 1],
80-
url: cDLSoftwareItem.external_resources.cnll.url
83+
url: cdlSoftwareItem.external_resources.cnll.url
8184
})
8285
]
8386
: []),
84-
...(!Array.isArray(cDLSoftwareItem.external_resources.framalibre)
87+
...(!Array.isArray(cdlSoftwareItem.external_resources.framalibre)
8588
? [
8689
identifersUtils.makeFramaIndentifier({
87-
framaLibreId: cDLSoftwareItem.external_resources.framalibre.slug,
88-
url: cDLSoftwareItem.external_resources.framalibre.url,
90+
framaLibreId: cdlSoftwareItem.external_resources.framalibre.slug,
91+
url: cdlSoftwareItem.external_resources.framalibre.url,
8992
additionalType: "Software"
9093
})
9194
]
9295
: []),
93-
...(!Array.isArray(cDLSoftwareItem.external_resources.wikidata)
96+
...(!Array.isArray(cdlSoftwareItem.external_resources.wikidata)
9497
? [
9598
identifersUtils.makeWikidataIdentifier({
96-
wikidataId: cDLSoftwareItem.external_resources.wikidata.id,
97-
url: cDLSoftwareItem.external_resources.wikidata.url,
99+
wikidataId: cdlSoftwareItem.external_resources.wikidata.id,
100+
url: cdlSoftwareItem.external_resources.wikidata.url,
98101
additionalType: "Software"
99102
})
100103
]
101104
: [])
102105
],
103-
providers: cDLSoftwareItem.providers.map(prodiver => cDLproviderToCMProdivers(prodiver))
106+
providers: cdlSoftwareItem.providers.map(prodiver => cdlProviderToCMProdivers(prodiver))
104107
};
105108
};

api/src/core/adapters/comptoirDuLibre/getCDLSoftwareOptions.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ import { ComptoirDuLibre } from "../../ports/ComptoirDuLibreApi";
99

1010
export const rawCDLSoftwareToExternalOption =
1111
({ source }: { language: Language; source: Source }) =>
12-
(cDLSoftware: ComptoirDuLibre.Software): SoftwareExternalDataOption => {
12+
(cdlSoftware: ComptoirDuLibre.Software): SoftwareExternalDataOption => {
1313
return {
14-
externalId: cDLSoftware.id.toString(),
15-
label: cDLSoftware.name,
14+
externalId: cdlSoftware.id.toString(),
15+
label: cdlSoftware.name,
1616
description: "",
1717
isLibreSoftware: true,
1818
sourceSlug: source.slug
1919
};
2020
};
2121

22-
// HAL documentation is here : https://api.archives-ouvertes.fr/docs/search
23-
2422
export const getCDLSoftwareOptions: GetSoftwareExternalDataOptions = async ({ queryString, language, source }) => {
2523
if (source.kind !== "ComptoirDuLibre") throw new Error(`Not a Comptoir Du Libre source, was : ${source.kind}`);
2624

27-
const comptoirAPi = await comptoirDuLibreApi.getComptoirDuLibre();
28-
const comptoirSoftware = comptoirAPi.softwares.filter(softwareItem => softwareItem.name.includes(queryString));
25+
const { softwares: cdlAllSoftwarePackages } = await comptoirDuLibreApi.getComptoirDuLibre();
26+
const comptoirSoftwarePackage = cdlAllSoftwarePackages.filter(softwareItem =>
27+
softwareItem.name.includes(queryString)
28+
);
2929

30-
if (!comptoirSoftware) return [];
30+
if (!comptoirSoftwarePackage) return [];
3131

32-
return comptoirSoftware.map(rawCDLSoftwareToExternalOption({ language, source }));
32+
return comptoirSoftwarePackage.map(rawCDLSoftwareToExternalOption({ language, source }));
3333
};

api/src/core/adapters/comptoirDuLibreApi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export const comptoirDuLibreApi: ComptoirDuLibreApi = {
2929
};
3030
}
3131
},
32-
{ "promise": true }
32+
{
33+
"promise": true,
34+
maxAge: 3 * 3600 * 1000
35+
}
3336
),
3437
"getIconUrl": async ({ comptoirDuLibreId }) => {
3538
let imgSrc: string | undefined;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ export namespace PgComptoirDuLibre {
240240
external_resources: {
241241
website: string | null;
242242
repository: string | null;
243-
wikidata: WikidataIdentifier | any[];
244-
sill: SILLIdentifier | any[];
245-
wikipedia: WikipediaIdentifier | any[];
246-
cnll: CNLLIdentifier | any[];
247-
framalibre: FramaLibreIdentifier | any[];
243+
wikidata: WikidataIdentifier | never[];
244+
sill: SILLIdentifier | never[];
245+
wikipedia: WikipediaIdentifier | never[];
246+
cnll: CNLLIdentifier | never[];
247+
framalibre: FramaLibreIdentifier | never[];
248248
};
249249
providers: Provider[];
250250
users: User[];

api/src/core/ports/ComptoirDuLibreApi.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ export declare namespace ComptoirDuLibre {
4848
external_resources: {
4949
website: string | null;
5050
repository: string | null;
51-
wikidata: WikidataIdentifier | any[];
52-
sill: SILLIdentifier | any[];
53-
wikipedia: WikipediaIdentifier | any[];
54-
cnll: CNLLIdentifier | any[];
55-
framalibre: FramaLibreIdentifier | any[];
51+
wikidata: WikidataIdentifier | never[];
52+
sill: SILLIdentifier | never[];
53+
wikipedia: WikipediaIdentifier | never[];
54+
cnll: CNLLIdentifier | never[];
55+
framalibre: FramaLibreIdentifier | never[];
5656
};
5757
providers: Provider[];
5858
users: User[];
@@ -169,11 +169,11 @@ export const { zComptoirDuLibre } = (() => {
169169
"external_resources": z.object({
170170
"website": z.union([z.string(), z.null()]),
171171
"repository": z.union([z.string(), z.null()]),
172-
"wikidata": z.any(),
173-
"sill": z.any(),
174-
"wikipedia": z.any(),
175-
"cnll": z.any(),
176-
"framalibre": z.any()
172+
"wikidata": zWikidataIdentifier.or(z.array(z.never()).max(0)),
173+
"sill": zSILLIdentifier.or(z.array(z.never()).max(0)),
174+
"wikipedia": zWikipediaIdentifier.or(z.array(z.never()).max(0)),
175+
"cnll": zCNLLIdentifier.or(z.array(z.never()).max(0)),
176+
"framalibre": zFramaLibreIdentifier.or(z.array(z.never()).max(0))
177177
}),
178178
"providers": z.array(zProvider),
179179
"users": z.array(zUser)

api/src/tools/identifiersTools.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ArticleIdentifier, SchemaIdentifier, WebSite } from "../core/adapters/dbApi/kysely/kysely.database";
22

3-
const cNNLSource: WebSite = {
3+
const cnllSource: WebSite = {
44
"@type": "Website" as const,
55
name: "Union des entreprises du logiciel libre et du numérique ouvert",
66
url: new URL("https://cnll.fr"),
@@ -35,14 +35,14 @@ const wikidataSource: WebSite = {
3535
additionalType: "wikidata"
3636
};
3737

38-
const cDLSource: WebSite = {
38+
const cdlSource: WebSite = {
3939
"@type": "Website" as const,
4040
name: "Comptoir du libre",
4141
url: new URL("https://comptoir-du-libre.org"),
4242
additionalType: "ComptoirDuLibre"
4343
};
4444

45-
const sWHSource: WebSite = {
45+
const swhSource: WebSite = {
4646
"@type": "Website" as const,
4747
name: "Software Heritage instance",
4848
url: new URL("https://www.softwareheritage.org/"),
@@ -106,7 +106,7 @@ export const identifersUtils = {
106106
additionalType: "Organization",
107107
value: cdlId,
108108
url: url,
109-
subjectOf: cDLSource,
109+
subjectOf: cdlSource,
110110
...(additionalType ? { additionalType: additionalType } : {})
111111
};
112112
},
@@ -116,7 +116,7 @@ export const identifersUtils = {
116116
"@type": "PropertyValue" as const,
117117
value: cNNLId,
118118
url: url,
119-
subjectOf: cNNLSource,
119+
subjectOf: cnllSource,
120120
...(additionalType ? { additionalType: additionalType } : {})
121121
};
122122
},
@@ -153,7 +153,7 @@ export const identifersUtils = {
153153
"@type": "PropertyValue" as const,
154154
value: swhId,
155155
url: url,
156-
subjectOf: sWHSource,
156+
subjectOf: swhSource,
157157
...(additionalType ? { additionalType: additionalType } : {})
158158
};
159159
},

api/src/tools/test.helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Db } from "../core/ports/DbApi";
33
import { DeclarationFormData, InstanceFormData, SoftwareFormData, Source } from "../core/usecases/readWriteSillData";
44
import { Kysely } from "kysely";
55
import { Database } from "../core/adapters/dbApi/kysely/kysely.database";
6-
import { ExternalDataOrigin } from "../lib/ApiTypes";
6+
import { ExternalDataOriginKind } from "../lib/ApiTypes";
77

88
export const testPgUrl = "postgresql://sill:pg_password@localhost:5432/sill";
99

@@ -149,7 +149,7 @@ export const resetDB = async (db: Kysely<Database>) => {
149149
.insertInto("sources")
150150
.values({
151151
...testSource,
152-
kind: testSource.kind as ExternalDataOrigin
152+
kind: testSource.kind as ExternalDataOriginKind
153153
})
154154
.execute();
155155
};

0 commit comments

Comments
 (0)