Skip to content

Commit ee5e64a

Browse files
authored
Merge pull request #4680 from coralproject/feat/update-mongo
Update Mongo driver to `v6.9.0`
2 parents 8fc3e53 + be604fd commit ee5e64a

File tree

81 files changed

+842
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+842
-607
lines changed

common/lib/errors.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,10 @@ export enum ERROR_CODES {
472472
* priming of comments for the story in the data caches `commentCache` returns an undefined
473473
* result. This usually means something went very wrong loading from Redis or Mongo.
474474
*/
475-
UNABLE_TO_PRIME_CACHED_COMMENTS_FOR_STORY = "UNABLE_TO_PRIME_CACHED_COMMENTS_FOR_STORY"
475+
UNABLE_TO_PRIME_CACHED_COMMENTS_FOR_STORY = "UNABLE_TO_PRIME_CACHED_COMMENTS_FOR_STORY",
476+
/**
477+
* SITE_NOT_FOUND is returned when the site being looked up via an ID does not
478+
* exist in the database or when a siteID has been deleted from a document.
479+
*/
480+
SITE_NOT_FOUND = "SITE_NOT_FOUND",
476481
}

server/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"metascraper-description": "^5.22.5",
127127
"metascraper-image": "^5.22.5",
128128
"metascraper-title": "^5.22.5",
129-
"mongodb": "^3.5.9",
129+
"mongodb": "^6.9.0",
130130
"mongodb-core": "^3.2.7",
131131
"ms": "^2.1.2",
132132
"node-fetch": "^2.6.1",
@@ -201,7 +201,6 @@
201201
"@types/luxon": "^1.22.0",
202202
"@types/marked": "^0.7.3",
203203
"@types/mini-css-extract-plugin": "^1.4.3",
204-
"@types/mongodb": "3.1.22",
205204
"@types/ms": "^0.7.31",
206205
"@types/node": "^12.12.34",
207206
"@types/node-fetch": "^2.5.5",
@@ -363,11 +362,6 @@
363362
"Newer versions has problems with using nunjucks.",
364363
"Update when the following issue is resolved:",
365364
"https://github.com/tj/consolidate.js/issues/244"
366-
],
367-
"@types/mongodb@3.1.22": [
368-
"Newer versions has problems with optional fields when querying with null",
369-
"Update when the following issue is resolved:",
370-
"https://github.com/DefinitelyTyped/DefinitelyTyped/issues/47686"
371365
]
372366
},
373367
"graphql-schema-linter": {

server/pnpm-lock.yaml

Lines changed: 79 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/core/server/app/middleware/csp.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { patchTextUtil } from "coral-server/test/textEncoder";
2+
patchTextUtil();
3+
14
import { generateFrameOptions } from "coral-server/app/middleware/csp";
25
import { Request } from "coral-server/types/express";
36

server/src/core/server/app/middleware/csp.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AppOptions } from "coral-server/app";
66
import { getOrigin, prefixSchemeIfRequired } from "coral-server/app/url";
77
import { Config } from "coral-server/config";
88
import { MongoContext } from "coral-server/data/context";
9+
import { SiteNotFoundError } from "coral-server/errors";
910
import {
1011
retrieveSite,
1112
retrieveSiteByOrigin,
@@ -50,6 +51,10 @@ async function retrieveSiteFromQuery(
5051
return null;
5152
}
5253

54+
if (!story.siteID) {
55+
throw new SiteNotFoundError(null, storyID);
56+
}
57+
5358
// If the site can't be found based on it's allowed origins and the story
5459
// URL (which is a allowed list), then we know it isn't allowed.
5560
return retrieveSite(mongo, tenant.id, story.siteID);

server/src/core/server/app/middleware/passport/strategies/verifiers/jwt.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { patchTextUtil } from "coral-server/test/textEncoder";
2+
patchTextUtil();
3+
14
import jwt from "jsonwebtoken";
25
import { DateTime } from "luxon";
36

server/src/core/server/app/middleware/passport/strategies/verifiers/sso.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { patchTextUtil } from "coral-server/test/textEncoder";
2+
patchTextUtil();
3+
14
import {
25
SSOTokenSchema,
36
SSOUserProfileSchema,

server/src/core/server/app/middleware/tenant.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { v1 as uuid } from "uuid";
22

33
import { MongoContext } from "coral-server/data/context";
4-
import { TenantNotFoundError } from "coral-server/errors";
4+
import { SiteNotFoundError, TenantNotFoundError } from "coral-server/errors";
55
import logger from "coral-server/logger";
66
import {
77
retrieveSite,
@@ -110,6 +110,10 @@ async function retrieveSiteFromQuery(
110110
return null;
111111
}
112112

113+
if (!story.siteID) {
114+
throw new SiteNotFoundError(null, storyID);
115+
}
116+
113117
// If the site can't be found based on it's allowed origins and the story
114118
// URL (which is a allowed list), then we know it isn't allowed.
115119
return retrieveSite(mongo, tenant.id, story.siteID);

server/src/core/server/data/cache/commentCache.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const createRedis = (): AugmentedRedis => {
2424

2525
const createMongo = async (): Promise<MongoContext> => {
2626
const uri = "mongodb://127.0.0.1:27017/coral";
27-
const live = await createMongoDB(uri);
28-
const archive = await createMongoDB(uri);
27+
const live = (await createMongoDB(uri)).db;
28+
const archive = (await createMongoDB(uri)).db;
2929

3030
const context = new MongoContextImpl(live, archive);
3131

server/src/core/server/data/cache/commentCache.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export class CommentCache implements IDataCache {
127127
: this.mongo.comments();
128128

129129
const comments = await collection
130-
.find({ tenantID, storyID, status: { $in: ["APPROVED", "NONE"] } })
130+
.find({
131+
tenantID,
132+
storyID,
133+
status: { $in: [GQLCOMMENT_STATUS.APPROVED, GQLCOMMENT_STATUS.NONE] },
134+
})
131135
.toArray();
132136
if (!comments || comments.length === 0) {
133137
return [];
@@ -350,20 +354,20 @@ export class CommentCache implements IDataCache {
350354
tenantID: string,
351355
storyID: string,
352356
parentID?: string | null,
353-
isArchived?: boolean
357+
isArchived?: boolean | null
354358
): Promise<Array<Readonly<Comment>>> {
355359
const filter = parentID
356360
? {
357361
tenantID,
358362
storyID,
359363
parentID,
360-
status: { $in: ["APPROVED", "NONE"] },
364+
status: { $in: [GQLCOMMENT_STATUS.APPROVED, GQLCOMMENT_STATUS.NONE] },
361365
}
362366
: {
363367
tenantID,
364368
storyID,
365369
parentID: null,
366-
status: { $in: ["APPROVED", "NONE"] },
370+
status: { $in: [GQLCOMMENT_STATUS.APPROVED, GQLCOMMENT_STATUS.NONE] },
367371
};
368372

369373
const collection = isArchived

0 commit comments

Comments
 (0)