Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v9.5.0 #4686

Merged
merged 28 commits into from
Oct 16, 2024
Merged

v9.5.0 #4686

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
57ce741
update mongo driver to v6.9.0
nick-funk Sep 30, 2024
71f6275
WIP: update query types
nick-funk Sep 30, 2024
b526cc6
WIP: more type updates across various server files
nick-funk Oct 1, 2024
a16db72
WIP: more type fixes and updates
nick-funk Oct 1, 2024
a6ebd6b
WIP: even more type fixes
nick-funk Oct 1, 2024
045bd49
replace `remove` with `delete`
nick-funk Oct 6, 2024
267dd6b
resolve types for `signingSecret` logic
nick-funk Oct 6, 2024
cbbb564
update tenant cache types
nick-funk Oct 6, 2024
222e71d
resolve types for metrics
nick-funk Oct 6, 2024
33c914a
fix `seenComments` types
nick-funk Oct 7, 2024
6e635a9
update types for site batch update in migration
nick-funk Oct 7, 2024
a6a8f38
create section and connection filter types for comment actions
nick-funk Oct 7, 2024
169eab4
fix merged moderation queue filter types
nick-funk Oct 7, 2024
de2bf8f
replace collection type on `updateRelatedCommentCounts`
nick-funk Oct 7, 2024
fb56ddf
fix comment count generics updates
nick-funk Oct 7, 2024
e14f392
Merge branch 'develop' into feat/update-mongo
nick-funk Oct 7, 2024
e2d2dfa
make update count type happy for story update
nick-funk Oct 7, 2024
0dd7841
add `SITE_NOT_FOUND` error code to common lib
nick-funk Oct 7, 2024
6010f68
force story types on merge mutator
nick-funk Oct 7, 2024
6c66630
patch text encode/decode global for affected tests
nick-funk Oct 7, 2024
34cbf94
Merge branch 'develop' into feat/update-mongo
nick-funk Oct 7, 2024
370106b
remove todo as it is resolved
nick-funk Oct 8, 2024
4ad39f5
use `countDocuments` over `count` in `countTenantSites`
nick-funk Oct 8, 2024
be604fd
Merge branch 'develop' into feat/update-mongo
nick-funk Oct 8, 2024
ee5e64a
Merge pull request #4680 from coralproject/feat/update-mongo
tessalt Oct 8, 2024
89c72bc
update verison no
tessalt Oct 10, 2024
f025976
Merge pull request #4685 from coralproject/release-9.5.0
tessalt Oct 16, 2024
4208938
Merge branch 'main' into develop
tessalt Oct 16, 2024
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
Prev Previous commit
Next Next commit
WIP: update query types
  • Loading branch information
nick-funk committed Sep 30, 2024
commit 71f6275983b864ba7374aea87a838ca55ea5ae46
12 changes: 6 additions & 6 deletions server/src/core/server/models/action/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export async function createAction(
};

// Extract the filter parameters.
const filter: FilterQuery<CommentAction> = {
const filter = {
tenantID,
...rest,
};
Expand Down Expand Up @@ -283,7 +283,7 @@ export async function createAction(

// False to return the updated document instead of the original document.
// This lets us detect if the document was updated or not.
returnOriginal: false,
returnDocument: "after",
});

// Check to see if this was a new action that was upserted, or one was found
Expand All @@ -294,12 +294,12 @@ export async function createAction(
// Because it's relevant that we know that the action was just created, or
// was just looked up, we need to return the action with an object that
// indicates if it was upserted.
const wasUpserted = result.value!.id === id;
const wasUpserted = result?.id === id;

// Return the action that was created/found with a boolean indicating if this
// action was just upserted (and therefore was newly created).
return {
action: result.value!,
action: result!,
wasUpserted,
};
}
Expand Down Expand Up @@ -494,8 +494,8 @@ export async function removeAction(
// Remove the action from the database, returning the action that was deleted.
const result = await mongo.commentActions().findOneAndDelete(filter);
return {
action: result.value,
wasRemoved: Boolean(result.ok && result.value),
action: result ?? undefined,
wasRemoved: Boolean(result),
};
}

Expand Down
14 changes: 7 additions & 7 deletions server/src/core/server/models/comment/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export async function pushChildCommentIDOntoParent(
$inc: { childCount: 1 },
},
{
returnOriginal: false,
returnDocument: "after",
}
);

Expand Down Expand Up @@ -379,7 +379,7 @@ export async function editComment(
update,
{
// True to return the original document instead of the updated document.
returnOriginal: true,
returnDocument: "before",
}
);
if (!result.value) {
Expand Down Expand Up @@ -854,7 +854,7 @@ export async function updateCommentEmbeddedAt(
{
// True to return the original document instead of the updated
// document.
returnOriginal: true,
returnDocument: "before",
}
);
if (!result.value) {
Expand Down Expand Up @@ -892,7 +892,7 @@ export async function updateCommentStatus(
{
// True to return the original document instead of the updated
// document.
returnOriginal: true,
returnDocument: "before",
}
);
if (!result.value) {
Expand Down Expand Up @@ -942,7 +942,7 @@ export async function updateCommentActionCounts(
arrayFilters: [{ "revision.id": revisionID }],
// False to return the updated document instead of the original
// document.
returnOriginal: false,
returnDocument: "after",
}
);
if (!result.value) {
Expand Down Expand Up @@ -1021,7 +1021,7 @@ export async function addCommentTag(
{
// False to return the updated document instead of the original
// document.
returnOriginal: false,
returnDocument: "after",
}
);
if (!result.value) {
Expand Down Expand Up @@ -1063,7 +1063,7 @@ export async function removeCommentTag(
{
// False to return the updated document instead of the original
// document.
returnOriginal: false,
returnDocument: "after",
}
);
if (!result.value) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/server/models/comment/counts/counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export async function updateRelatedCommentCounts<
{ $inc },
// False to return the updated document instead of the original
// document.
{ returnOriginal: false }
{ returnDocument: "after" }
);

return result.value || null;
Expand Down
10 changes: 5 additions & 5 deletions server/src/core/server/models/dsaReport/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export async function createDSAReportNote(
history: note,
},
},
{ returnOriginal: false }
{ returnDocument: "after" }
);

if (!updatedReport.value) {
Expand Down Expand Up @@ -384,7 +384,7 @@ export async function createDSAReportShare(
history: note,
},
},
{ returnOriginal: false }
{ returnDocument: "after" }
);

if (!updatedReport.value) {
Expand Down Expand Up @@ -422,7 +422,7 @@ export async function deleteDSAReportNote(
history: { id: { $eq: id } },
},
},
{ returnOriginal: false }
{ returnDocument: "after" }
);

if (!updatedReport.value) {
Expand Down Expand Up @@ -474,7 +474,7 @@ export async function changeDSAReportStatus(
},
$set: { status },
},
{ returnOriginal: false }
{ returnDocument: "after" }
);

if (!updatedReport.value) {
Expand Down Expand Up @@ -549,7 +549,7 @@ export async function makeDSAReportDecision(
status: GQLDSAReportStatus.COMPLETED,
},
},
{ returnOriginal: false }
{ returnDocument: "after" }
);

if (!updatedReport.value) {
Expand Down
29 changes: 18 additions & 11 deletions server/src/core/server/models/helpers/query.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import { isUndefined, omitBy } from "lodash";
import { Collection, Cursor, FilterQuery as MongoFilterQuery } from "mongodb";
import {
Collection,
Document,
Filter,
FindCursor,
SortDirection,
WithId,
} from "mongodb";

import { Writable } from "coral-common/common/lib/types";
import logger from "coral-server/logger";

/**
* FilterQuery<T> ensures that given the type T, that the FilterQuery will be a
* Writable, partial set of properties while also including MongoDB specific
* properties (like $lt, or $gte).
*/
export type FilterQuery<T> = MongoFilterQuery<Writable<Partial<T>>>;
export type FilterQuery<T> = Filter<T>;

/**
* Query is a convenience class used to wrap the existing MongoDB driver to
* provide easier complex query management.
*/
export default class Query<T> {
public filter: FilterQuery<T>;
public projection: FilterQuery<T>;
export default class Query<T extends Document> {
public filter: Filter<T>;
public projection: Filter<T>;

private collection: Collection<T>;
private skip?: number;
private limit?: number;
private sort?: object;
private sort?: { [key: string]: SortDirection };

constructor(collection: Collection<T>) {
this.collection = collection;
Expand All @@ -33,12 +39,12 @@ export default class Query<T> {
* where will merge the given filter into the existing query.
* @param filter the filter to merge into the existing query
*/
public where(filter: FilterQuery<T>): Query<T> {
public where(filter: Filter<T>): Query<T> {
this.filter = { ...this.filter, ...omitBy(filter, isUndefined) };
return this;
}

public project(projection: FilterQuery<T>): Query<T> {
public project(projection: Filter<T>): Query<T> {
this.projection = projection;
return this;
}
Expand All @@ -65,15 +71,16 @@ export default class Query<T> {
* orderBy will apply sorting to the query filter when executed.
* @param sort the sorting option for the documents
*/
public orderBy(sort: object): Query<T> {
public orderBy(sort: { [key: string]: SortDirection }): Query<T> {
// todo: merge sort's together
this.sort = { ...this.sort, ...sort };
return this;
}

/**
* exec will return a cursor to the query.
*/
public async exec(): Promise<Cursor<T>> {
public async exec(): Promise<FindCursor<WithId<T>>> {
logger.trace(
{
collection: this.collection.collectionName,
Expand Down
10 changes: 5 additions & 5 deletions server/src/core/server/models/migration/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export async function startMigration(
},
{
// False to return the updated document instead of the original document.
returnOriginal: false,
returnDocument: "after",
upsert: true,
}
);
if (!result.value) {
if (!result) {
throw new Error("an unexpected error occurred");
}

return result.value;
return result;
}

/**
Expand Down Expand Up @@ -71,11 +71,11 @@ async function updateMigrationState(
},
{
// False to return the updated document instead of the original document.
returnOriginal: false,
returnDocument: "after",
}
);

return result.value || null;
return result;
}

export async function finishMigration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function pushNewSigningSecret<T extends {}>({
const options: FindOneAndUpdateOption = {
// False to return the updated document instead of the original
// document.
returnOriginal: false,
returnDocument: "after",
};
if (id) {
options.arrayFilters = [
Expand Down Expand Up @@ -246,7 +246,7 @@ async function deprecateOldSigningSecrets<T extends {}>(
const options: FindOneAndUpdateOption = {
// False to return the updated document instead of the original
// document.
returnOriginal: false,
returnDocument: "after",
arrayFilters: [
// Select any signing secrets with the given ids.
{ "signingSecret.kid": { $in: secretKIDsToDeprecate } },
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/server/models/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export async function updateSite(
update,
// False to return the updated document instead of the original
// document.
{ returnOriginal: false }
{ returnDocument: "after" }
);
return result.value || null;
} catch (err) {
Expand Down
Loading