-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate from npm mongo client to jsr
- Loading branch information
Showing
18 changed files
with
74 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,43 @@ | ||
import { MongoClient } from 'npm/mongodb'; | ||
import { MongoClient } from 'mongo'; | ||
import { logger } from '../core/logger.ts'; | ||
import { between } from 'optic'; | ||
import { env } from '../core/env.ts'; | ||
import { Local } from '../types/core.ts'; | ||
|
||
class LocalSourceFactory { | ||
constructor(private readonly client: MongoClient) { | ||
logger.mark('mongo_connection_start'); | ||
client.on('timeout', () => { | ||
logger.warn( | ||
'common.mongo.factory:LocalSourceFactory: Connection timed out', | ||
); | ||
}); | ||
} | ||
constructor(private readonly client: MongoClient) {} | ||
|
||
connect = async (): Promise<Local> => { | ||
return await this.client.connect() | ||
logger.mark('mongo_connection_start'); | ||
return await this.client.connect(env<string>('MONGO_URL')) | ||
.then((client) => { | ||
logger.mark('mongo_connection_end'); | ||
logger.measure( | ||
between('mongo_connection_start', 'mongo_connection_end'), | ||
); | ||
return client.db(); | ||
return client; | ||
}) | ||
.catch((e) => { | ||
.catch((e: unknown) => { | ||
logger.error('common.mongo.factory:connect:', e); | ||
return undefined; | ||
}); | ||
}; | ||
|
||
disconnect = async () => { | ||
disconnect = () => { | ||
logger.mark('mongo_close_start'); | ||
await this.client.close(true) | ||
.then(() => { | ||
}).catch((e) => { | ||
logger.error('common.mongo.factory:disconnect:', e); | ||
}).finally(() => { | ||
logger.mark('mongo_close_end'); | ||
logger.measure(between('mongo_close_start', 'mongo_close_end')); | ||
}); | ||
try { | ||
this.client.close(); | ||
} catch (e) { | ||
logger.error('common.mongo.factory:disconnect:', e); | ||
} finally { | ||
logger.mark('mongo_close_end'); | ||
logger.measure(between('mongo_close_start', 'mongo_close_end')); | ||
} | ||
}; | ||
} | ||
|
||
const _localSourceFactory = new LocalSourceFactory( | ||
new MongoClient(env<string>('MONGO_URL'), { | ||
connectTimeoutMS: 1000, | ||
monitorCommands: true, | ||
}), | ||
new MongoClient(), | ||
); | ||
|
||
export default _localSourceFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import { Document, ObjectId, Sort } from 'npm/mongodb'; | ||
import { Document, ObjectId } from 'mongo'; | ||
import { ProjectionOption, SortOption } from './types.ts'; | ||
|
||
export const projectionOf = <T extends Document>( | ||
projection: ProjectionOption<T>, | ||
) => projection; | ||
|
||
export const sortOf = <T extends Document>(option: SortOption<T>): Sort => | ||
option as Sort; | ||
export const sortOf = <T extends Document>(option: SortOption<T>) => option; | ||
|
||
export const idOf = (id: ObjectId): string => id.toHexString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"deepmerge": "jsr:@rebeccastevens/[email protected]", | ||
"growthbook": "jsr:@growthbook/[email protected]", | ||
"xml": "jsr:@libs/[email protected]", | ||
"npm/logtail": "npm:@logtail/node@0.5.2", | ||
"npm/mongodb": "npm:[email protected]" | ||
"mongo": "jsr:@db/mongo@0.33.0", | ||
"npm/logtail": "npm:@logtail/[email protected]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.