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

[Deps] Update to Mongoose 6 #170

Merged
merged 10 commits into from
Jun 15, 2024
Merged

Commits on Jun 11, 2024

  1. npm install mongoose@6

    The goal is to get to v8, the current version. But [1] advises to go
    major version by major version instead of making an abrupt jump.
    
    mongoose@6 needs mongodb@4, but this requirement is already satisfied.
    
    [1]: https://mongoosejs.com/docs/migrating_to_6.html
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    8a39bfc View commit details
    Browse the repository at this point in the history
  2. [Mongoose] Fix Card.findOne typing

    Resolves this build error:
    
    ```log
    src/models/CardsMongoDB.ts:86:23 - error TS2769: No overload matches this call.
      Overload 1 of 3, '(filter?: FilterQuery<ICardRaw> | undefined, projection?: ProjectionType<ICardRaw> | null | undefined, options?: QueryOptions<ICardRaw> | null | undefined, callback?: Callback<...> | undefined): Query<...>', gave the following error.
        Argument of type 'Partial<ICard>' is not assignable to parameter of type 'FilterQuery<ICardRaw>'.
          Type 'Partial<ICard>' is not assignable to type 'RootQuerySelector<ICardRaw>'.
            Types of property '$where' are incompatible.
              Type 'Record<string, unknown> | undefined' is not assignable to type 'string | Function | undefined'.
                Type 'Record<string, unknown>' is not assignable to type 'string | Function | undefined'.
                  Type 'Record<string, unknown>' is missing the following properties from type 'Function': apply, call, bind, prototype, and 5 more.
      Overload 2 of 3, '(filter?: FilterQuery<ICardRaw> | undefined, projection?: ProjectionType<ICardRaw> | null | undefined, callback?: Callback<(Document<unknown, any, ICardRaw> & Omit<...>) | null> | undefined): Query<...>', gave the following error.
        Argument of type 'Partial<ICard>' is not assignable to parameter of type 'FilterQuery<ICardRaw>'.
      Overload 3 of 3, '(filter?: FilterQuery<ICardRaw> | undefined, callback?: Callback<(Document<unknown, any, ICardRaw> & Omit<ICardRaw & Required<{ _id: string; }>, never>) | null> | undefined): Query<...>', gave the following error.
        Argument of type 'Partial<ICard>' is not assignable to parameter of type 'FilterQuery<ICardRaw>'.
    
    86   return Card.findOne(query).select(projection).exec();
                             ~~~~~
    ```
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    0a8624d View commit details
    Browse the repository at this point in the history
  3. [Mongoose] Stronger typing for Card.sort object

    Fixes this build error:
    
    ```log
    src/models/CardsMongoDB.ts:260:11 - error TS2345: Argument of type 'object' is not assignable to parameter of type 'string | { [key: string]: SortOrder | { $meta: "textScore"; }; } | [string, SortOrder][] | null | undefined'.
    
    260     .sort(queryObject.sortCriteria)
                  ~~~~~~~~~~~~~~~~~~~~~~~~
    ```
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    f5ba28c View commit details
    Browse the repository at this point in the history
  4. [Mongoose] Pass unique: true instead of `unique: [true, "x must be …

    …unique"]`
    
    Fixes these errors:
    
    ```log
    src/models/mongoose_models/Token.ts:19:5 - error TS2322: Type '{ type: StringConstructor; required: true; unique: (string | true)[]; }' is not assignable to type 'SchemaDefinitionProperty<string> | undefined'.
      Types of property 'unique' are incompatible.
        Type '(string | true)[]' is not assignable to type 'number | boolean | undefined'.
    
    19     token_id: {
           ~~~~~~~~
    
    src/models/mongoose_models/UserSchema.ts:28:5 - error TS2322: Type '{ type: StringConstructor; required: true; unique: (string | true)[]; immutable: true; match: RegExp; }' is not assignable to type 'SchemaDefinitionProperty<string> | undefined'.
      Types of property 'unique' are incompatible.
        Type '(string | true)[]' is not assignable to type 'number | boolean | undefined'.
    
    28     username: {
           ~~~~~~~~
    ```
    
    AFAICT, the custom string doesn't seem like it was ever supported in v5 [1].
    
    [1]: https://mongoosejs.com/docs/5.x/docs/validation.html#the-unique-option-is-not-a-validator
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    09a4cbd View commit details
    Browse the repository at this point in the history
  5. [Mongoose] Fix Metadata.findOne typing

    ```log
    src/models/MetadataMongoDB.ts:117:46 - error TS2769: No overload matches this call.
      Overload 1 of 3, '(filter?: FilterQuery<IMetadataRaw> | undefined, projection?: ProjectionType<IMetadataRaw> | null | undefined, options?: QueryOptions<...> | ... 1 more ... | undefined, callback?: Callback<...> | undefined): Query<...>', gave the following error.
        Argument of type 'Partial<IMetadata>' is not assignable to parameter of type 'FilterQuery<IMetadataRaw>'.
          Type 'Partial<IMetadata>' is not assignable to type 'RootQuerySelector<IMetadataRaw>'.
            Types of property '$where' are incompatible.
              Type 'Record<string, unknown> | undefined' is not assignable to type 'string | Function | undefined'.
      Overload 2 of 3, '(filter?: FilterQuery<IMetadataRaw> | undefined, projection?: ProjectionType<IMetadataRaw> | null | undefined, callback?: Callback<...> | undefined): Query<...>', gave the following error.
        Argument of type 'Partial<IMetadata>' is not assignable to parameter of type 'FilterQuery<IMetadataRaw>'.
      Overload 3 of 3, '(filter?: FilterQuery<IMetadataRaw> | undefined, callback?: Callback<(Document<unknown, any, IMetadataRaw> & Omit<IMetadataRaw & { ...; }, never>) | null> | undefined): Query<...>', gave the following error.
        Argument of type 'Partial<IMetadata>' is not assignable to parameter of type 'FilterQuery<IMetadataRaw>'.
    
    117   const metadataDoc = await Metadata.findOne(metadataQuery).exec();
                                                     ~~~~~~~~~~~~~
    ```
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    5dbb4c7 View commit details
    Browse the repository at this point in the history
  6. [ES] npm install mongodb@4

    This package already existed but as a dependency of Mongoose. This
    commit brings it to the top-level dependencies so that we can take
    advantage of MongoDB's TS types. [1]
    
    We had not used @types/mongodb, so removing that package isn't
    applicable to us.
    
    [1]: https://github.com/mongodb/node-mongodb-native/blob/4.0/docs/CHANGES_4.0.0.md#typescript
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    46a3e14 View commit details
    Browse the repository at this point in the history
  7. [Mongo] Fix return typing for Metadata.deleteMany

    ```log
    src/models/MetadataMongoDB.ts:204:3 - error TS2322: Type 'Promise<DeleteResult>' is not assignable to type 'Promise<void>'.
      Type 'DeleteResult' is not assignable to type 'void'.
    
    204   return Metadata.deleteMany({ createdById: payload.userIDInApp }).exec();
          ~~~~~~
    ```
    
    [1]: https://mongoosejs.com/docs/6.x/docs/migrating_to_6.html#mongodb-driver-40
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    3dc965a View commit details
    Browse the repository at this point in the history
  8. [Mongoose] Fix typings for IStreak

    ```log
    src/models/mongoose_models/MetadataCardSchema.ts:47:5 - error TS2322: Type '{ type: MapConstructor; default: { cardIDs: never[]; length: number; dailyTarget: number; timeStamp: () => number; }; }' is not assignable to type 'SchemaDefinitionProperty<IStreak> | undefined'.
      Type '{ type: MapConstructor; default: { cardIDs: never[]; length: number; dailyTarget: number; timeStamp: () => number; }; }' is not assignable to type 'undefined'.
    
    47     streak: {
           ~~~~~~
    ```
    dchege711 committed Jun 11, 2024
    Configuration menu
    Copy the full SHA
    bd571b4 View commit details
    Browse the repository at this point in the history

Commits on Jun 15, 2024

  1. [Mongo] Fix typings for setting IStreakRaw

    ```log
    src/models/DailyTasks.ts:57:29 - error TS2345: Argument of type '{ updateOne: { filter?: FilterQuery<IMetadata> | undefined; update?: UpdateQuery<IMetadata> | undefined; }; }[]' is not assignable to parameter of type 'AnyBulkWriteOperation<IMetadataRaw>[]'.
      Type '{ updateOne: { filter?: FilterQuery<IMetadata> | undefined; update?: UpdateQuery<IMetadata> | undefined; }; }' is not assignable to type 'AnyBulkWriteOperation<IMetadataRaw>'.
        Type '{ updateOne: { filter?: FilterQuery<IMetadata> | undefined; update?: UpdateQuery<IMetadata> | undefined; }; }' is not assignable to type '{ updateOne: UpdateOneModel<IMetadataRaw>; }'.
          The types of 'updateOne.filter' are incompatible between these types.
            Type 'FilterQuery<IMetadata> | undefined' is not assignable to type 'Filter<IMetadataRaw>'.
              Type 'undefined' is not assignable to type 'Filter<IMetadataRaw>'.
    
    57   return Metadata.bulkWrite(bulkWriteOps);
                                   ~~~~~~~~~~~~
    ```
    dchege711 committed Jun 15, 2024
    Configuration menu
    Copy the full SHA
    b581365 View commit details
    Browse the repository at this point in the history
  2. [Mongoose] Fix calls to connect

    `useNewUrlParser` is `true` by default and should not be specified in client code. [1]
    
    `poolSize` has been replaced with `maxPoolSize` which defaults to `100`. [2]
    
    [1]: https://mongoosejs.com/docs/migrating_to_6.html#no-more-deprecation-warning-options
    [2]: https://mongoosejs.com/docs/migrating_to_6.html#mongodb-driver-40
    dchege711 committed Jun 15, 2024
    Configuration menu
    Copy the full SHA
    8c140dd View commit details
    Browse the repository at this point in the history