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

Update Mongoose to v7 #1902

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
239 changes: 214 additions & 25 deletions backend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"lodash-es": "^4.17.21",
"mjml": "^4.15.3",
"mongodb": "^6.13.0",
"mongoose": "^6.13.8",
"mongoose": "7.8.6",
"mongoose-delete": "^1.0.2",
"morgan": "^1.10.0",
"nanoid": "^5.0.9",
Expand Down
11 changes: 6 additions & 5 deletions backend/src/models/AccessRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

export interface AccessRequestMetadata {
overview: {
Expand Down Expand Up @@ -33,9 +33,10 @@ export interface AccessRequestInterface {
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type AccessRequestDoc = AccessRequestInterface & Document<any, any, AccessRequestInterface>

const AccessRequestSchema = new Schema<AccessRequestInterface>(
export type AccessRequestDoc = AccessRequestInterface & SoftDeleteDocument

const AccessRequestSchema = new Schema<AccessRequestDoc>(
{
id: { type: String, unique: true, required: true },
modelId: { type: String, required: true },
Expand All @@ -58,6 +59,6 @@ AccessRequestSchema.plugin(MongooseDelete, {
deletedAt: true,
})

const AccessRequestModel = model<AccessRequestInterface>('v2_Access_Request', AccessRequestSchema)
const AccessRequestModel = model<AccessRequestDoc>('v2_Access_Request', AccessRequestSchema)

export default AccessRequestModel
10 changes: 5 additions & 5 deletions backend/src/models/File.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, ObjectId, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, ObjectId, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

import { FileScanResult, ScanState } from '../connectors/fileScanning/Base.js'

Expand Down Expand Up @@ -28,9 +28,9 @@ export interface FileInterface {
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type FileInterfaceDoc = FileInterface & Document<any, any, FileInterface>
export type FileInterfaceDoc = FileInterface & SoftDeleteDocument

const FileSchema = new Schema<FileInterface>(
const FileSchema = new Schema<FileInterfaceDoc>(
{
modelId: { type: String, required: true },

Expand Down Expand Up @@ -68,6 +68,6 @@ FileSchema.plugin(MongooseDelete, {
deletedAt: true,
})

const FileModel = model<FileInterface>('v2_File', FileSchema)
const FileModel = model<FileInterfaceDoc>('v2_File', FileSchema)

export default FileModel
10 changes: 5 additions & 5 deletions backend/src/models/Model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

export const EntryVisibility = {
Private: 'private',
Expand Down Expand Up @@ -68,9 +68,9 @@ export interface ModelInterface {
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type ModelDoc = ModelInterface & Document<any, any, ModelInterface>
export type ModelDoc = ModelInterface & SoftDeleteDocument

const ModelSchema = new Schema<ModelInterface>(
const ModelSchema = new Schema<ModelDoc>(
{
id: { type: String, required: true, unique: true, index: true },

Expand Down Expand Up @@ -113,6 +113,6 @@ ModelSchema.plugin(MongooseDelete, {
})
ModelSchema.index({ '$**': 'text' }, { weights: { name: 10, description: 5 } })

const ModelModel = model<ModelInterface>('v2_Model', ModelSchema)
const ModelModel = model<ModelDoc>('v2_Model', ModelSchema)

export default ModelModel
10 changes: 5 additions & 5 deletions backend/src/models/Release.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

import { semverObjectToString, semverStringToObject } from '../services/release.js'

Expand Down Expand Up @@ -35,7 +35,7 @@ export interface ImageRef {
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type ReleaseDoc = ReleaseInterface & Document<any, any, ReleaseInterface>
export type ReleaseDoc = ReleaseInterface & SoftDeleteDocument

export interface SemverObject {
major: number
Expand All @@ -44,7 +44,7 @@ export interface SemverObject {
metadata?: string
}

const ReleaseSchema = new Schema<ReleaseInterface & { semver: string | SemverObject }>(
const ReleaseSchema = new Schema<ReleaseDoc & { semver: string | SemverObject }>(
{
modelId: { type: String, required: true },
modelCardVersion: { type: Number, required: true },
Expand Down Expand Up @@ -94,6 +94,6 @@ ReleaseSchema.plugin(MongooseDelete, {
})
ReleaseSchema.index({ modelId: 1, semver: 1 }, { unique: true })

const ReleaseModel = model<ReleaseInterface>('v2_Release', ReleaseSchema)
const ReleaseModel = model<ReleaseDoc>('v2_Release', ReleaseSchema)

export default ReleaseModel
10 changes: 5 additions & 5 deletions backend/src/models/Response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

export const Decision = {
RequestChanges: 'request_changes',
Expand Down Expand Up @@ -44,9 +44,9 @@ export type ReactionKindKeys = (typeof ReactionKind)[keyof typeof ReactionKind]
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type ResponseDoc = ResponseInterface & Document<any, any, ResponseInterface>
export type ResponseDoc = ResponseInterface & SoftDeleteDocument

const ResponseSchema = new Schema<ResponseInterface>(
const ResponseSchema = new Schema<ResponseDoc>(
{
entity: { type: String, required: true },
kind: { type: String, enum: Object.values(ResponseKind), required: true },
Expand Down Expand Up @@ -75,6 +75,6 @@ ResponseSchema.plugin(MongooseDelete, {
deletedAt: true,
})

const ResponseModel = model<ResponseInterface>('v2_response', ResponseSchema)
const ResponseModel = model<ResponseDoc>('v2_response', ResponseSchema)

export default ResponseModel
10 changes: 5 additions & 5 deletions backend/src/models/Review.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

import { ReviewKind, ReviewKindKeys } from '../types/enums.js'

Expand All @@ -21,9 +21,9 @@ export interface ReviewInterface {
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type ReviewDoc = ReviewInterface & Document<any, any, ReviewInterface>
export type ReviewDoc = ReviewInterface & SoftDeleteDocument

const ReviewSchema = new Schema<ReviewInterface>(
const ReviewSchema = new Schema<ReviewDoc>(
{
semver: {
type: String,
Expand Down Expand Up @@ -67,6 +67,6 @@ ReviewSchema.plugin(MongooseDelete, {
deletedAt: true,
})

const ReviewModel = model<ReviewInterface>('v2_Review', ReviewSchema)
const ReviewModel = model<ReviewDoc>('v2_Review', ReviewSchema)

export default ReviewModel
10 changes: 5 additions & 5 deletions backend/src/models/Token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bcrypt from 'bcryptjs'
import { createHash } from 'crypto'
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

export const TokenScope = {
All: 'all',
Expand Down Expand Up @@ -73,9 +73,9 @@ export interface TokenInterface {
// The doc type includes all values in the plain interface, as well as all the
// properties and functions that Mongoose provides. If a function takes in an
// object from Mongoose it should use this interface
export type TokenDoc = TokenInterface & Document<any, any, TokenInterface>
export type TokenDoc = TokenInterface & SoftDeleteDocument

const TokenSchema = new Schema<TokenInterface>(
const TokenSchema = new Schema<TokenDoc>(
{
user: { type: String, required: true },
description: { type: String, required: true },
Expand Down Expand Up @@ -154,6 +154,6 @@ TokenSchema.methods.compareToken = function compareToken(candidateToken: string)

TokenSchema.plugin(MongooseDelete, { overrideMethods: 'all', deletedAt: true })

const TokenModel = model<TokenInterface>('v2_Token', TokenSchema)
const TokenModel = model<TokenDoc>('v2_Token', TokenSchema)

export default TokenModel
10 changes: 5 additions & 5 deletions backend/src/models/Webhook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Document, model, Schema } from 'mongoose'
import MongooseDelete from 'mongoose-delete'
import { model, Schema } from 'mongoose'
import MongooseDelete, { SoftDeleteDocument } from 'mongoose-delete'

export const WebhookEvent = {
CreateRelease: 'createRelease',
Expand All @@ -20,9 +20,9 @@ export interface WebhookInterface {
active?: boolean
}

export type WebhookDoc = WebhookInterface & Document<any, any, WebhookInterface>
export type WebhookDoc = WebhookInterface & SoftDeleteDocument

const WebhookSchema = new Schema<WebhookInterface>(
const WebhookSchema = new Schema<WebhookDoc>(
{
id: { type: String, required: true, unique: true, index: true },
modelId: { type: String, required: true },
Expand All @@ -48,6 +48,6 @@ WebhookSchema.plugin(MongooseDelete, {
deletedAt: true,
})

const WebhookModel = model<WebhookInterface>('v2_Webhook', WebhookSchema)
const WebhookModel = model<WebhookDoc>('v3_Webhook', WebhookSchema)

export default WebhookModel
2 changes: 1 addition & 1 deletion backend/src/services/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function deleteSchemaById(user: UserInterface, schemaId: string): P
})
}

await schema.delete()
await schema.deleteOne()

return schema.id
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function removeToken(user: UserInterface, accessKey: string) {
throw Forbidden('Only the token owner can remove the token', { accessKey })
}

await token.remove()
await token.delete()

return { success: true }
}
Expand Down
Loading