Bump versions, move getAdapter to context

This commit is contained in:
Jon Staab
2025-04-01 14:24:32 -07:00
parent 540726531f
commit 1cbcb0ae4a
15 changed files with 91 additions and 126 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/net",
"version": "0.1.0",
"version": "0.1.1",
"author": "hodlbod",
"license": "MIT",
"description": "Utilities for connecting with nostr relays.",
@@ -26,9 +26,9 @@
"fix": "gts fix"
},
"dependencies": {
"@welshman/lib": "^0.1.0",
"@welshman/util": "^0.1.0",
"@welshman/relay": "^0.1.0",
"@welshman/lib": "^0.1.1",
"@welshman/util": "^0.1.2",
"@welshman/relay": "^0.1.1",
"isomorphic-ws": "^5.0.0",
"typed-emitter": "^2.1.0"
}
+1 -3
View File
@@ -99,9 +99,7 @@ export class MockAdapter extends AbstractAdapter {
}
}
export type AdapterContext = Partial<NetContext> & {
getAdapter?: (url: string, context: AdapterContext) => AbstractAdapter
}
export type AdapterContext = Partial<NetContext>
export const getAdapter = (url: string, adapterContext: AdapterContext = {}) => {
const context = mergeRight(netContext, adapterContext as any)
+2
View File
@@ -1,5 +1,6 @@
import {Repository} from "@welshman/relay"
import {verifyEvent, TrustedEvent, SignedEvent} from "@welshman/util"
import {AbstractAdapter} from "./adapter.js"
import {Pool} from "./pool.js"
export type NetContext = {
@@ -7,6 +8,7 @@ export type NetContext = {
repository: Repository
isEventValid: (event: TrustedEvent, url: string) => boolean
isEventDeleted: (event: TrustedEvent, url: string) => boolean
getAdapter?: (url: string, context: NetContext) => AbstractAdapter
}
export const netContext: NetContext = {
+2 -2
View File
@@ -124,8 +124,8 @@ export class SingleRequest extends (EventEmitter as new () => TypedEmitter<Singl
}
// Timeout our subscription
if (this.options.timeout) {
setTimeout(() => this.close(), this.options.timeout)
if (this.options.timeout || this.options.autoClose) {
setTimeout(() => this.close(), this.options.timeout || 10000)
}
// Start asynchronously so the caller can set up listeners