-
Notifications
You must be signed in to change notification settings - Fork 5
fix(MongoClient): use mongodb-connection-string-url for host parsing (#58) #61
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "effect-mongodb": patch | ||
| --- | ||
|
|
||
| fix(MongoClient): update tests for ConnectionString host parsing (#58) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,30 @@ import * as Data from "effect/Data" | |
| import * as Effect from "effect/Effect" | ||
| import * as F from "effect/Function" | ||
| import type * as Scope from "effect/Scope" | ||
| import type { DbOptions, MongoClientOptions } from "mongodb" | ||
| import type { DbOptions, MongoClientOptions, MongoParseError } from "mongodb" | ||
| import { MongoClient as MongoClient_ } from "mongodb" | ||
| import { ConnectionString } from "mongodb-connection-string-url" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would avoid installing another dependency just for error reporting. I would like to find other ways to parse the connection string, maybe there is something built-in in |
||
| import * as Db from "./Db.js" | ||
| import { mongoErrorOrDie } from "./internal/mongo-error.js" | ||
| import * as MongoError from "./MongoError.js" | ||
|
|
||
| export class MongoClient extends Data.TaggedClass("MongoClient")<{ client: MongoClient_ }> {} | ||
|
|
||
| const parseHosts = (url: string): Effect.Effect<ConnectionString, MongoParseError> => | ||
| Effect.try({ try: () => new ConnectionString(url), catch: (e) => e as MongoParseError }) | ||
|
|
||
| export const connect = ( | ||
| url: string, | ||
| options?: MongoClientOptions | ||
| ): Effect.Effect<MongoClient, MongoError.MongoError> => | ||
| Effect.promise(() => MongoClient_.connect(url, options)).pipe( | ||
| Effect.map((client) => new MongoClient({ client })), | ||
| Effect.catchAllDefect(mongoErrorOrDie(errorSource([new URL(url).host], "connect"))) | ||
| Effect.catchAllDefect((e) => | ||
| parseHosts(url).pipe( | ||
| Effect.catchAll((e) => Effect.succeed({ hosts: [e.message] })), | ||
| Effect.flatMap((cs) => mongoErrorOrDie(errorSource(cs.hosts, "connect"))(e)) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| export const close: { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "Fix MongoClient.connect connection string parsing for error reporting"