Skip to content

Commit

Permalink
Sequential + bson versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovepixelart committed May 9, 2024
1 parent ffc9994 commit 4041200
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 66 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
max-parallel: 1
matrix:
node-version: [16.x, 18.x]
mongoose-version: [mongoose@6.12.2, mongoose@7.6.4, mongoose@latest]
mongoose-version: [[mongoose@6.12.2, bson@^4.7.2], [mongoose@7.6.4, bson@^5.5.0], [mongoose@latest, bson@^6.5.0]]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -55,8 +55,8 @@ jobs:
- name: Installing dependencies
run: npm ci

- name: Installing ${{ matrix.mongoose-version }}
run: npm i ${{ matrix.mongoose-version }}
- name: Installing ${{ matrix.mongoose-version[0] }} {{ matrix.mongoose-version[1] }}
run: npm i ${{ matrix.mongoose-version[0] }} ${{ matrix.mongoose-version[1] }}

- name: Coverage
run: npm run test
Expand All @@ -67,6 +67,7 @@ jobs:
REDIS_PORT: 6379

sonar:
needs: tests
name: Coverage & Sonar
runs-on: ubuntu-latest

Expand Down
58 changes: 1 addition & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import mongoose from 'mongoose'
export const isMongooseLessThan7 = satisfies(mongoose.version, '<7')

export const convertToObject = (value: unknown): unknown => {
if (value != null && typeof value === 'object' && !Array.isArray(value) && value.toObject) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return value.toObject()
}
if (Array.isArray(value)) {
return value.map((doc) => convertToObject(doc))
if (isMongooseLessThan7) {
if (value != null && typeof value === 'object' && !Array.isArray(value) && value.toObject) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return value.toObject()
}
if (Array.isArray(value)) {
return value.map((doc) => convertToObject(doc))
}
}

return value
Expand Down

0 comments on commit 4041200

Please sign in to comment.