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
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"@graphql-tools/schema": "^10.0.23",
"@ndla/licenses": "^9.0.3",
"cheerio": "^1.1.0",
"compression": "^1.7.4",
"dataloader": "^1.4.0",
"dotenv": "^6.2.0",
"compression": "^1.8.0",
"dataloader": "^2.2.3",
"dotenv": "^16.5.0",
"express": "^4.21.2",
"express-prom-bundle": "^7.0.0",
"graphql": "^16.11.0",
Expand All @@ -42,15 +42,15 @@
"he": "^1.2.0",
"lodash": "^4.17.21",
"lru-cache": "^7.0.0",
"marked": "^9.1.0",
"node-fetch": "2.6.7",
"open-graph-scraper": "^6.8.3",
"marked": "^15.0.12",
"node-fetch": "2.7.0",
"open-graph-scraper": "^6.10.0",
"openapi-fetch": "^0.13.5",
"prismjs": "^1.30.0",
"prom-client": "^15.1.3",
"punycode": "^2.3.1",
"query-string": "^6.2.0",
"sanitize-html": "^2.13.1",
"query-string": "^9.2.1",
"sanitize-html": "^2.17.0",
"source-map-support": "^0.5.21",
"winston": "^3.13.0"
},
Expand All @@ -64,29 +64,29 @@
"@ndla/types-backend": "^1.0.55",
"@ndla/types-embed": "^5.0.16-alpha.0",
"@ndla/types-taxonomy": "^1.0.34",
"@types/compression": "^1.7.2",
"@types/cors": "^2.8.4",
"@types/dotenv": "^6.1.0",
"@types/compression": "^1.8.1",
"@types/cors": "^2.8.19",
"@types/dotenv": "^8.2.3",
"@types/express": "^4.17.21",
"@types/graphql": "^14.2.3",
"@types/he": "^1.1.1",
"@types/lodash": "^4.14.118",
"@types/graphql": "^14.5.0",
"@types/he": "^1.2.3",
"@types/lodash": "^4.17.18",
"@types/node": "^22.15.0",
"@types/node-fetch": "^2.1.2",
"@types/node-fetch": "^2.6.12",
"@types/open-graph-scraper": "^4.8.5",
"@types/prismjs": "^1.26.0",
"@types/prismjs": "^1.26.5",
"@types/punycode": "^2.1.4",
"@types/query-string": "^6.1.1",
"@types/sanitize-html": "^2.11.0",
"@types/query-string": "^6.3.0",
"@types/sanitize-html": "^2.16.0",
"@types/source-map-support": "^0",
"@vercel/ncc": "^0.34.0",
"concurrently": "^9.1.0",
"eslint": "^9.16.0",
"eslint-config-ndla": "^6.0.0-alpha.0",
"prettier": "^3.1.0",
"typescript": "^5.8.2",
"typescript-eslint": "^8.17.0",
"vitest": "^3.2.3"
"prettier": "^3.5.3",
"typescript": "^5.8.3",
"typescript-eslint": "^8.34.1",
"vitest": "^3.2.4"
},
"packageManager": "[email protected]"
}
5 changes: 4 additions & 1 deletion src/api/articleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export async function fetchArticlesPage(
.then(resolveJsonOATS);
}

export async function fetchArticles(articleIds: string[], context: Context): Promise<(IArticleV2DTO | undefined)[]> {
export async function fetchArticles(
articleIds: readonly string[],
context: Context,
): Promise<(IArticleV2DTO | undefined)[]> {
const pageSize = 100;
const ids = articleIds.map((id) => parseInt(id)).filter((id) => isNaN(id) === false);
const numberOfPages = Math.ceil(ids.length / pageSize);
Expand Down
10 changes: 0 additions & 10 deletions src/api/folderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*
*/

import qs from "query-string";
import {
IMyNDLAUserDTO,
IFolderDTO,
Expand Down Expand Up @@ -41,15 +40,6 @@ import { createAuthClient, resolveJsonOATS, resolveOATS } from "../utils/openapi

const client = createAuthClient<openapi.paths>({ disableCache: true });

interface QueryParamsType {
[key: string]: any;
}

export const queryString = (params: QueryParamsType) => {
const stringified = qs.stringify(params);
return stringified.length ? `?${stringified}` : "";
};

export async function fetchFolders(
{ includeResources, includeSubfolders }: GQLQueryFoldersArgs,
_context: Context,
Expand Down
5 changes: 4 additions & 1 deletion src/api/folderResourceMetaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ const fetchAndTransformResourceMeta = async (
]);
return ids
.map((id) => {
const node = nodes.flatMap((x) => x).find((n) => !!n && n.contentUri === `urn:${nodeType}:${id}`);
const node = nodes
.filter((n): n is Node[] => !!n)
.flatMap((x) => x)
.find((n) => !!n && n.contentUri === `urn:${nodeType}:${id}`);
const element = elements.find((e) => e?.id === Number(id));
return element
? {
Expand Down
5 changes: 3 additions & 2 deletions src/api/learningpathApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ const client = createAuthClient<openapi.paths>();
const cachelessClient = createAuthClient<openapi.paths>({ disableCache: true });

export async function fetchLearningpaths(
learningpathIds: number[],
learningpathIds: readonly number[],
context: Context,
): Promise<Array<ILearningPathV2DTO | undefined>> {
const ids = learningpathIds.filter((id) => isNaN(id) === false);
const json = await client
.GET("/learningpath-api/v2/learningpaths/ids", {
params: {
query: {
ids: learningpathIds,
ids: ids,
language: context.language,
fallback: true,
},
Expand Down
5 changes: 4 additions & 1 deletion src/api/taxonomyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export async function fetchNode(
return await resolveJson(response);
}

export async function searchNodes(params: { contentUris: string[] }, context: Context): Promise<SearchResult<Node>> {
export async function searchNodes(
params: { contentUris: readonly string[] },
context: Context,
): Promise<SearchResult<Node>> {
const { contentUris } = params;
const query = qs.stringify({
language: context.language,
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/frontpageResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const resolvers = {
return context.loaders.articlesLoader.load(`${menu.articleId}`);
},
async hideLevel(menu: IFrontPageDTO | IMenuDTO): Promise<boolean> {
return "hideLevel" in menu ? menu.hideLevel ?? false : false;
return "hideLevel" in menu ? (menu.hideLevel ?? false) : false;
},
},

Expand Down
9 changes: 6 additions & 3 deletions src/resolvers/subjectResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,28 @@ export const resolvers = {
},
SubjectPage: {
async connectedTo(subjectpage: ISubjectPageDTO, _: any, context: ContextWithLoaders): Promise<GQLSubjectLink[]> {
return await context.loaders.nodeLoader.loadMany(
const connectedTo = await context.loaders.nodeLoader.loadMany(
subjectpage.connectedTo.map((id) => {
return { id };
}),
);
return connectedTo.filter((sub): sub is Node => !!sub);
},
async buildsOn(subjectpage: ISubjectPageDTO, _: any, context: ContextWithLoaders): Promise<GQLSubjectLink[]> {
return await context.loaders.nodeLoader.loadMany(
const buildsOn = await context.loaders.nodeLoader.loadMany(
subjectpage.buildsOn.map((id) => {
return { id };
}),
);
return buildsOn.filter((sub): sub is Node => !!sub);
},
async leadsTo(subjectpage: ISubjectPageDTO, _: any, context: ContextWithLoaders): Promise<GQLSubjectLink[]> {
return await context.loaders.nodeLoader.loadMany(
const leadsTo = await context.loaders.nodeLoader.loadMany(
subjectpage.leadsTo.map((id) => {
return { id };
}),
);
return leadsTo.filter((sub): sub is Node => !!sub);
},
},
SubjectPageVisualElement: {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/articleHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export async function filterMissingArticles<T extends GQLTaxonomyEntity | NodeCh

const entitiesWithContentUri = visibleEntities.filter((taxonomyEntity) => !!taxonomyEntity.contentUri);

const learningpathResources = entitiesWithContentUri.filter(
(taxonomyEntity) => taxonomyEntity.contentUri?.includes("urn:learningpath"),
const learningpathResources = entitiesWithContentUri.filter((taxonomyEntity) =>
taxonomyEntity.contentUri?.includes("urn:learningpath"),
);

const articleResources = entitiesWithContentUri.filter(
(taxonomyEntity) => taxonomyEntity.contentUri?.includes("urn:article"),
const articleResources = entitiesWithContentUri.filter((taxonomyEntity) =>
taxonomyEntity.contentUri?.includes("urn:article"),
);

const articles = await context.loaders.articlesLoader.loadMany(
Expand Down
Loading