@puzzle-ui/storage-mongodb 0.5.0 → 0.6.0
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/README.md +35 -7
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
# @puzzle-ui/storage-mongodb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A MongoDB implementation of the vendor-neutral contracts from `@puzzle-ui/storage`. It provides CRUD, shared query operators, conditional writes, cursor pagination, unique and TTL indexes, and versioned migrations. MongoDB's multi-document transactions and atomic batches are opt-in.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Documentation: [puzzle-ui.com/docs/storage](https://puzzle-ui.com/docs/storage#mongodb-adapter)**
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @puzzle-ui/storage @puzzle-ui/storage-mongodb
|
|
11
|
+
# or: bun add @puzzle-ui/storage @puzzle-ui/storage-mongodb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Use
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { MongoClient } from "mongodb";
|
|
18
|
+
import { MongoStorageAdapter } from "@puzzle-ui/storage-mongodb";
|
|
19
|
+
|
|
20
|
+
const client = new MongoClient(process.env.MONGODB_URI!);
|
|
21
|
+
await client.connect();
|
|
22
|
+
const storage = new MongoStorageAdapter({
|
|
23
|
+
database: client.db("app"),
|
|
24
|
+
client,
|
|
25
|
+
transactionsEnabled: true,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await storage.registerCollection({
|
|
29
|
+
name: "sessions",
|
|
30
|
+
indexes: [{ name: "by-user", fields: ["userId"] }],
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use a replica set or sharded deployment for multi-document transactions. Pass the client and set `transactionsEnabled: true` to opt in; otherwise `atomicBatch` is not available. The default collection prefix is `puzzle_`; set `collectionPrefix` to change it. A `StorageIndex` with `expireAfterSeconds` creates a MongoDB TTL index; TTL deletion is asynchronous, so enforce security-sensitive expiry in application logic as well. Close the client during application shutdown.
|
|
35
|
+
|
|
36
|
+
`MongoStorageMigrationAdapter` stores versioned migration status and a shared migration lock in prefixed collections. See the [storage guide](https://puzzle-ui.com/docs/storage) for adapter guarantees, index behavior, migration options, and custom adapter testing.
|
|
37
|
+
|
|
38
|
+
## Development
|
|
8
39
|
|
|
9
40
|
```sh
|
|
10
41
|
bun run build
|
|
@@ -12,7 +43,4 @@ bun run typecheck
|
|
|
12
43
|
bun run test
|
|
13
44
|
```
|
|
14
45
|
|
|
15
|
-
|
|
16
|
-
replica set and removes the test container and volume afterward. On failure, it
|
|
17
|
-
prints container status and MongoDB logs before cleanup so startup failures are
|
|
18
|
-
visible in CI.
|
|
46
|
+
The test script requires Docker and Docker Compose; it starts a MongoDB replica set for adapter tests.
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puzzle-ui/storage-mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "MongoDB storage adapter foundation for Puzzle Auth.",
|
|
5
|
+
"homepage": "https://puzzle-ui.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/senorprogramador/puzzle.git"
|
|
9
|
+
},
|
|
5
10
|
"license": "MIT",
|
|
6
11
|
"publishConfig": {
|
|
7
12
|
"access": "public",
|
|
@@ -43,7 +48,7 @@
|
|
|
43
48
|
"typescript": "^7.0.2"
|
|
44
49
|
},
|
|
45
50
|
"dependencies": {
|
|
46
|
-
"@puzzle-ui/storage": "^0.
|
|
51
|
+
"@puzzle-ui/storage": "^0.6.0",
|
|
47
52
|
"mongodb": "^7.8.0"
|
|
48
53
|
}
|
|
49
54
|
}
|