@1sat/cli 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/cli",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "CLI for 1Sat Ordinals SDK",
5
5
  "type": "module",
6
6
  "main": "./src/cli.ts",
@@ -27,7 +27,6 @@
27
27
  "dependencies": {
28
28
  "@1sat/actions": "0.0.117",
29
29
  "@1sat/client": "0.0.27",
30
- "@1sat/knex-bun-sqlite": "0.0.1",
31
30
  "@1sat/types": "0.0.19",
32
31
  "@1sat/wallet-node": "0.0.43",
33
32
  "@1sat/wallet-server": "0.0.13",
@@ -2,18 +2,17 @@
2
2
  * `1sat serve messagebox` — launch the BSV message-box server using the
3
3
  * CLI's wallet identity.
4
4
  *
5
- * Storage mirrors the wallet's choice: SQLite via `@1sat/knex-bun-sqlite`
6
- * when wallet storage is `bun-sqlite`, Postgres when wallet storage is `pg`.
7
- *
8
5
  * messagebox-server boots itself as a side effect of `import` once env vars
9
6
  * are populated, so this handler:
10
7
  * 1. Reads CLI config + private key
11
8
  * 2. Composes env (SERVER_PRIVATE_KEY, PORT, KNEX_DB_*, WALLET_STORAGE_URL, …)
12
- * 3. Dynamically imports `messagebox-server`
13
- * 4. Awaits SIGINT/SIGTERM, then closes the HTTP and WebSocket servers
9
+ * 3. Switches cwd to the messagebox-server install dir so its knexfile's
10
+ * relative `./out/src/migrations` path resolves correctly
11
+ * 4. Dynamically imports `@bopen-io/messagebox-server`
12
+ * 5. Awaits SIGINT/SIGTERM, then closes the HTTP and WebSocket servers
14
13
  */
15
14
 
16
- import { join } from 'node:path'
15
+ import { dirname, join } from 'node:path'
17
16
  import { fileURLToPath } from 'node:url'
18
17
  import type { PrivateKey } from '@bsv/sdk'
19
18
  import type { GlobalFlags } from '../args'
@@ -65,33 +64,14 @@ export async function startMessagebox(
65
64
  `[messagebox] websockets: ${resolved.websockets ? 'enabled' : 'disabled'}`,
66
65
  )
67
66
 
68
- // When the env-driven knexfile resolves to 'sqlite3', swap in our
69
- // bun:sqlite-backed Knex dialect class and rewrite the migrations
70
- // directory to an absolute path. ESM singleton semantics mean
71
- // messagebox-server's app.ts gets the same (mutated) module instance
72
- // when it imports the knexfile next.
73
- if (resolved.knexClient === 'sqlite3') {
74
- const knexfileUrl = import.meta.resolve(
75
- '@bopen-io/messagebox-server/out/knexfile.js',
76
- )
77
- const migrationsDir = fileURLToPath(new URL('src/migrations/', knexfileUrl))
78
- const [knexfile, dialect] = await Promise.all([
79
- import('@bopen-io/messagebox-server/out/knexfile.js') as Promise<{
80
- default: Record<
81
- string,
82
- { client: unknown; migrations?: { directory: string } }
83
- >
84
- }>,
85
- import('@1sat/knex-bun-sqlite'),
86
- ])
87
- const Client = dialect.default
88
- for (const env of ['development', 'staging', 'production']) {
89
- const cfg = knexfile.default[env]
90
- if (!cfg) continue
91
- cfg.client = Client
92
- if (cfg.migrations) cfg.migrations.directory = migrationsDir
93
- }
94
- }
67
+ // messagebox-server's knexfile uses `./out/src/migrations` relative to
68
+ // cwd. Switch cwd to its install dir so that path resolves correctly
69
+ // regardless of where the CLI was invoked from.
70
+ const packageJsonUrl = import.meta.resolve(
71
+ '@bopen-io/messagebox-server/package.json',
72
+ )
73
+ const messageboxDir = dirname(fileURLToPath(packageJsonUrl))
74
+ process.chdir(messageboxDir)
95
75
 
96
76
  // messagebox-server boots itself when its index module is loaded.
97
77
  const mbox = (await import(
@@ -187,9 +167,6 @@ function resolveStorage(
187
167
  const dataDir = ensureDataDir()
188
168
  const filename =
189
169
  messagebox.dbPath ?? join(dataDir, `messagebox-${chain}.db`)
190
- // We pass `sqlite3` to satisfy the env-driven knexfile's alias check;
191
- // the actual Client class is swapped in via ESM module mutation
192
- // just before messagebox-server is imported.
193
170
  return {
194
171
  knexClient: 'sqlite3',
195
172
  knexConnection: { filename },
@@ -197,6 +174,17 @@ function resolveStorage(
197
174
  }
198
175
 
199
176
  if (storage.provider === 'pg') {
177
+ // Prefer a dedicated messagebox database when configured (recommended:
178
+ // avoids `knex_migrations` table collisions with wallet-toolbox).
179
+ // Fall back to schema isolation against the wallet's database — note
180
+ // the `messagebox` schema must exist in that database for table
181
+ // creation to land there instead of `public`.
182
+ if (messagebox.dbUrl) {
183
+ return {
184
+ knexClient: 'pg',
185
+ knexConnection: { connectionString: messagebox.dbUrl },
186
+ }
187
+ }
200
188
  const schema = messagebox.pgSchema ?? DEFAULT_PG_SCHEMA
201
189
  return {
202
190
  knexClient: 'pg',
package/src/config.ts CHANGED
@@ -52,9 +52,15 @@ export interface ServerMessageboxConfig {
52
52
  dbPath?: string
53
53
  /**
54
54
  * Postgres schema for messagebox tables. Used only when wallet storage
55
- * is `pg`. Defaults to `messagebox`.
55
+ * is `pg` AND `dbUrl` is unset. Defaults to `messagebox`.
56
56
  */
57
57
  pgSchema?: string
58
+ /**
59
+ * Override Postgres connection URL for messagebox storage. Use this
60
+ * to point messagebox at a separate Postgres database from the wallet
61
+ * (recommended — avoids `knex_migrations` table collisions).
62
+ */
63
+ dbUrl?: string
58
64
  /**
59
65
  * Override the wallet storage URL messagebox calls for BRC-31/BRC-29
60
66
  * operations. Defaults to the local wallet server URL (`http://<host>:<port>/`).
@@ -8,8 +8,3 @@ declare module '@bopen-io/messagebox-server' {
8
8
  export const ROUTING_PREFIX: string
9
9
  export function start(): Promise<void>
10
10
  }
11
-
12
- declare module '@bopen-io/messagebox-server/out/knexfile.js' {
13
- const knexfile: Record<string, { client: unknown; [k: string]: unknown }>
14
- export default knexfile
15
- }