@lastshotlabs/bunshot 0.0.1 → 0.0.3
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/CLAUDE.md +2 -2
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/lib/mongo.ts +12 -0
- package/src/lib/redis.ts +11 -0
package/CLAUDE.md
CHANGED
|
@@ -40,8 +40,8 @@ This is a **Bun + Hono API framework library** that consuming projects install a
|
|
|
40
40
|
|
|
41
41
|
| File | Purpose |
|
|
42
42
|
|------|---------|
|
|
43
|
-
| `mongo.ts` | Mongoose connection management |
|
|
44
|
-
| `redis.ts` | ioredis client |
|
|
43
|
+
| `mongo.ts` | Mongoose connection management; `disconnectMongo()` for clean shutdown |
|
|
44
|
+
| `redis.ts` | ioredis client; `disconnectRedis()` for clean shutdown |
|
|
45
45
|
| `jwt.ts` | `jose`-based JWT sign/verify |
|
|
46
46
|
| `session.ts` | Session CRUD — store set via `db.sessions` ("redis" \| "mongo" \| "sqlite" \| "memory") |
|
|
47
47
|
| `auth.ts` | Register/login/logout/password logic |
|
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@ A personal Bun + Hono API framework. Install it in any app and get auth, session
|
|
|
7
7
|
- **Runtime**: [Bun](https://bun.sh)
|
|
8
8
|
- **Framework**: [Hono](https://hono.dev) + [@hono/zod-openapi](https://github.com/honojs/middleware/tree/main/packages/zod-openapi)
|
|
9
9
|
- **Docs UI**: [Scalar](https://scalar.com)
|
|
10
|
-
- **
|
|
11
|
-
- **Cache / Sessions**: Redis via [ioredis](https://github.com/redis/ioredis)
|
|
10
|
+
- **Data / Auth**: MongoDB, SQLite, or in-memory — configurable via `db.auth` (default: MongoDB via [Mongoose](https://mongoosejs.com))
|
|
11
|
+
- **Cache / Sessions**: Redis, MongoDB, SQLite, or in-memory — configurable via `db.sessions` / `db.cache` (default: Redis via [ioredis](https://github.com/redis/ioredis))
|
|
12
12
|
- **Auth**: JWT via [jose](https://github.com/panva/jose), HttpOnly cookies + `x-user-token` header
|
|
13
13
|
- **Queues**: [BullMQ](https://docs.bullmq.io) (requires Redis with `noeviction` policy)
|
|
14
14
|
- **Validation**: [Zod v4](https://zod.dev)
|
|
@@ -1407,9 +1407,9 @@ import {
|
|
|
1407
1407
|
createServer, createApp,
|
|
1408
1408
|
|
|
1409
1409
|
// DB
|
|
1410
|
-
connectMongo, connectAuthMongo, connectAppMongo,
|
|
1410
|
+
connectMongo, connectAuthMongo, connectAppMongo, disconnectMongo,
|
|
1411
1411
|
authConnection, appConnection, mongoose,
|
|
1412
|
-
connectRedis, getRedis,
|
|
1412
|
+
connectRedis, disconnectRedis, getRedis,
|
|
1413
1413
|
|
|
1414
1414
|
// Jobs
|
|
1415
1415
|
createQueue, createWorker,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -12,8 +12,8 @@ export { createRouter } from "@lib/context";
|
|
|
12
12
|
export type { AppEnv, AppVariables } from "@lib/context";
|
|
13
13
|
export { signToken, verifyToken } from "@lib/jwt";
|
|
14
14
|
export { log } from "@lib/logger";
|
|
15
|
-
export { connectMongo, connectAuthMongo, connectAppMongo, authConnection, appConnection, mongoose } from "@lib/mongo";
|
|
16
|
-
export { connectRedis, getRedis } from "@lib/redis";
|
|
15
|
+
export { connectMongo, connectAuthMongo, connectAppMongo, disconnectMongo, authConnection, appConnection, mongoose } from "@lib/mongo";
|
|
16
|
+
export { connectRedis, disconnectRedis, getRedis } from "@lib/redis";
|
|
17
17
|
export { createQueue, createWorker } from "@lib/queue";
|
|
18
18
|
export type { Job } from "@lib/queue";
|
|
19
19
|
export { createSession, getSession, deleteSession, setSessionStore } from "@lib/session";
|
package/src/lib/mongo.ts
CHANGED
|
@@ -67,4 +67,16 @@ export const connectMongo = async (): Promise<void> => {
|
|
|
67
67
|
log(`[mongo] connected to ${host} as ${user}`);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Close both auth and app Mongo connections.
|
|
72
|
+
* Useful for one-off scripts that need a clean exit.
|
|
73
|
+
*/
|
|
74
|
+
export const disconnectMongo = async (): Promise<void> => {
|
|
75
|
+
await Promise.all([
|
|
76
|
+
authConnection.readyState !== 0 ? authConnection.close() : Promise.resolve(),
|
|
77
|
+
appConnection.readyState !== 0 ? appConnection.close() : Promise.resolve(),
|
|
78
|
+
]);
|
|
79
|
+
log("[mongo] disconnected");
|
|
80
|
+
};
|
|
81
|
+
|
|
70
82
|
export { mongoose };
|
package/src/lib/redis.ts
CHANGED
|
@@ -39,6 +39,17 @@ export const connectRedis = (): Promise<void> => {
|
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Gracefully close the Redis connection.
|
|
44
|
+
* Useful for one-off scripts that need a clean exit.
|
|
45
|
+
*/
|
|
46
|
+
export const disconnectRedis = async (): Promise<void> => {
|
|
47
|
+
if (!client) return;
|
|
48
|
+
await client.quit();
|
|
49
|
+
client = null;
|
|
50
|
+
log("[redis] disconnected");
|
|
51
|
+
};
|
|
52
|
+
|
|
42
53
|
export const getRedis = (): Redis => {
|
|
43
54
|
if (!client) throw new Error("Redis not connected — call connectRedis() first");
|
|
44
55
|
return client;
|