tokenwatch-sdk 0.2.0 → 0.2.1
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/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -0
- package/dist/server.d.ts +1 -2
- package/dist/server.js +13 -1
- package/dist/suppress-warnings.d.ts +1 -0
- package/dist/suppress-warnings.js +10 -0
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import './suppress-warnings.js';
|
package/dist/cli.js
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
3
2
|
export declare function createApp(dbPath: string): {
|
|
4
3
|
app: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
|
|
5
|
-
db: DatabaseSync;
|
|
4
|
+
db: import("node:sqlite").DatabaseSync;
|
|
6
5
|
};
|
|
7
6
|
export declare function startServer(opts: {
|
|
8
7
|
port: number;
|
package/dist/server.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
2
|
import { serve } from '@hono/node-server';
|
|
3
|
-
import {
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
4
|
import { computeCostUsd } from './pricing.js';
|
|
5
5
|
import { dashboardHtml } from './dashboard.js';
|
|
6
|
+
// Lazy-require node:sqlite so its ExperimentalWarning fires after our suppressor
|
|
7
|
+
// (static `import 'node:sqlite'` emits the warning during module linking).
|
|
8
|
+
const { DatabaseSync } = createRequire(import.meta.url)('node:sqlite');
|
|
6
9
|
const SCHEMA = `
|
|
7
10
|
CREATE TABLE IF NOT EXISTS events (
|
|
8
11
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -167,6 +170,15 @@ export function createApp(dbPath) {
|
|
|
167
170
|
export function startServer(opts) {
|
|
168
171
|
const { app } = createApp(opts.dbPath);
|
|
169
172
|
const server = serve({ fetch: app.fetch, port: opts.port });
|
|
173
|
+
server.on?.('error', (err) => {
|
|
174
|
+
if (err?.code === 'EADDRINUSE') {
|
|
175
|
+
console.error(`\nTokenWatch: port ${opts.port} is already in use.\n` +
|
|
176
|
+
`Probably another TokenWatch is running — open http://localhost:${opts.port} to check,\n` +
|
|
177
|
+
`or start on a different port: tokenwatch serve --port ${opts.port + 1}\n`);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
throw err;
|
|
181
|
+
});
|
|
170
182
|
console.log(`TokenWatch running → http://localhost:${opts.port} (db: ${opts.dbPath})`);
|
|
171
183
|
return server;
|
|
172
184
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Must be imported before any module that loads node:sqlite.
|
|
2
|
+
// node:sqlite is stable for our use; hide the scary first-run ExperimentalWarning.
|
|
3
|
+
const originalEmitWarning = process.emitWarning.bind(process);
|
|
4
|
+
process.emitWarning = ((warning, ...rest) => {
|
|
5
|
+
const text = typeof warning === 'string' ? warning : warning?.message ?? '';
|
|
6
|
+
if (text.includes('SQLite is an experimental feature'))
|
|
7
|
+
return;
|
|
8
|
+
originalEmitWarning(warning, ...rest);
|
|
9
|
+
});
|
|
10
|
+
export {};
|
package/package.json
CHANGED