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
feat!: accept database instance instead of path when creating server #93
Conversation
src/api/index.ts
Outdated
) => { | ||
if (dbPath == null) | ||
throw new Error('Map server option `dbPath` must be specified') | ||
if (database == null || !(database instanceof Db)) |
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.
I think this might be unreliable as a check. Because it is now a peer dependency, it is possible that an app using this code could create the instance with a different version of better-sqlite3 than the one that resolves here. Also requiring it in this file makes it not really a peer dependency (because this will break if it is not installed). I think we need to lean on typescript for checking, and it we really want to check then maybe check a property or method? However if it is not a BetterSqlite3.Database instance then something will throw later on pretty quick too.
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.
ah yes true! totally overlooked that. will remove the instanceOf
check but not sure i can think of a better check, so maybe okay to omit and let things break in that case
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.
Also requiring it in this file makes it not really a peer dependency (because this will break if it is not installed)
does this mean that I can't import the TS type from it either? guessing the answer is yes
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.
ah looks like this may be what i'm looking for: https://stackoverflow.com/questions/54392809/how-do-i-handle-optional-peer-dependencies-when-publishing-a-typescript-package/70096366#70096366
seems to work as expected when trying locally via npm pack
I'm not sure actually. But I think we need this to be typed, so leave it on
here maybe?
…On Tue, Jan 31, 2023 at 9:05 PM Andrew Chou ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/api/index.ts
<#93 (comment)>
:
> ) => {
- if (dbPath == null)
- throw new Error('Map server option `dbPath` must be specified')
+ if (database == null || !(database instanceof Db))
Also requiring it in this file makes it not really a peer dependency
(because this will break if it is not installed)
does this mean that I can't import the TS type from it either? guessing
the answer is yes
—
Reply to this email directly, view it on GitHub
<#93 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACG5GM3O3D6VHYPPIOUT63WVF5A7ANCNFSM6AAAAAAULOI4TY>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
// @ts-ignore | ||
import type { Database } from 'better-sqlite3' |
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.
we only want to work with the type, see #93 (comment)
Closes #92
This is a breaking change, as it updates the function signature of the export
createServer
function to accept an instance of a BetterSqlite3 database instead of a file path string.better-sqlite3
fromdepedencies
fieldbetter-sqlite3
topeerDependencies
anddevDependencies
fieldsMapServerOptions
from{ dbPath: string }
to{ database: Database }