Skip to content

Commit

Permalink
feat(connect)!: remove connect.hb. Add modes and corresponding *_URL …
Browse files Browse the repository at this point in the history
…args to connect()
  • Loading branch information
TillaTheHun0 committed Feb 7, 2025
1 parent 0ccc9fc commit 38382c0
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 177 deletions.
2 changes: 1 addition & 1 deletion connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"build": "npm run build:types && npm run build:src",
"build:src": "node esbuild.js",
"build:types": "tsc src/index.js --skipLibCheck --declaration --allowJs --emitDeclarationOnly --outDir dist",
"test": "node --test ./src/**/*.test.js",
"test": "node --test ./src/**/*.test.js src/index.test.js",
"pretest:integration": "npm run build && npm link",
"test:integration": "cd ./test/e2e && npm test"
},
Expand Down
7 changes: 4 additions & 3 deletions connect/src/hb.playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { tap } from 'ramda'

import { connect } from './index.js'

describe('index - node', () => {
describe('hb playground', () => {
/**
* Generate a wallet in a temporary directory prior to running the tests
*/
Expand All @@ -30,9 +30,10 @@ describe('index - node', () => {
test('should relay the message through HyperBEAM', async () => {
const wallet = JSON.parse(readFileSync(tmpWallet).toString())

const { spawn, message, result, createDataItemSigner } = connect.hb({
const { spawn, message, result, createDataItemSigner } = connect({
MODE: 'mainnet',
wallet,
URL: process.env.HB_URL || 'http://localhost:8734'
AO_URL: process.env.AO_URL || 'http://localhost:8734'
})

const p = await spawn({
Expand Down
18 changes: 13 additions & 5 deletions connect/src/index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,33 @@ const GRAPHQL_URL = globalThis.GRAPHQL_URL || undefined
const GRAPHQL_MAX_RETRIES = globalThis.GRAPHQL_MAX_RETRIES || undefined
const GRAPHQL_RETRY_BACKOFF = globalThis.GRAPHQL_RETRY_BACKOFF || undefined

const HB_URL = globalThis.HB_URL || undefined
const RELAY_URL = globalThis.RELAY_URL || undefined
const AO_URL = globalThis.AO_URL = undefined

const connect = connectWith({
createDataItemSigner: WalletClient.createDataItemSigner,
createHbSigner: WalletClient.createHbSigner
})

/**
* hardcoded to legacy, since wallet is not provided here
*
* TODO: probably remove these at the top level, and require using connect
* so as to set the mode and provide the wallet
*/
const { result, results, message, spawn, monitor, unmonitor, dryrun, assign, createDataItemSigner } = connect({
MODE: 'legacy',
GATEWAY_URL,
MU_URL,
CU_URL,
RELAY_URL,
AO_URL,
GRAPHQL_URL,
GRAPHQL_MAX_RETRIES,
GRAPHQL_RETRY_BACKOFF
GRAPHQL_RETRY_BACKOFF,
noLog: true
})

const originalHb = connect.hb
connect.hb = ({ URL = HB_URL, ...rest }) => originalHb({ URL, ...rest })

export { result, results, message, spawn, monitor, unmonitor, dryrun, assign }
export { connect }
export { serializeCron }
Expand Down
Loading

0 comments on commit 38382c0

Please sign in to comment.