jotdb 0.1.4 โ 0.1.5
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 +49 -172
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,203 +1,78 @@
|
|
|
1
1
|
# JotDB
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, schema-less database built on Cloudflare Durable Objects. Perfect for quick prototyping and applications that need simple data storage without the complexity of traditional databases.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Why JotDB?
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
bun add jotdb
|
|
9
|
-
# or
|
|
10
|
-
npm install jotdb
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
### 2. **Bind the Durable Object in your wrangler.toml or wrangler.json**
|
|
14
|
-
|
|
15
|
-
```toml
|
|
16
|
-
[[durable_objects.bindings]]
|
|
17
|
-
name = "JOTDB"
|
|
18
|
-
class_name = "JotDB"
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### 3. **Register the Durable Object in your Worker**
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { JotDB } from 'jotdb';
|
|
25
|
-
|
|
26
|
-
export interface Env {
|
|
27
|
-
JOTDB: DurableObjectNamespace<JotDB>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default {
|
|
31
|
-
async fetch(request: Request, env: Env) {
|
|
32
|
-
// Get a stub for your JotDB instance
|
|
33
|
-
const id = env.JOTDB.idFromName("my-db");
|
|
34
|
-
const db = env.JOTDB.get(id);
|
|
35
|
-
|
|
36
|
-
// Use RPC (recommended, requires extends DurableObject)
|
|
37
|
-
await db.set("key", "value");
|
|
38
|
-
const value = await db.get("key");
|
|
39
|
-
|
|
40
|
-
return new Response(`Value: ${value}`);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 4. **Deploy or run locally**
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
wrangler dev
|
|
49
|
-
# or
|
|
50
|
-
wrangler deploy
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## ๐ Notes
|
|
56
|
-
|
|
57
|
-
- **RPC support:** JotDB uses Cloudflare's new JavaScript-native RPC. You can call methods directly on the stub (e.g., `db.set(...)`, `db.get(...)`).
|
|
58
|
-
- **No fetch needed:** You do not need to use HTTP fetch to communicate with your Durable Objectโjust call methods!
|
|
59
|
-
- **TypeScript:** Use `DurableObjectNamespace<JotDB>` for full type safety.
|
|
60
|
-
- **See the API section below for all available methods.**
|
|
61
|
-
|
|
62
|
-
---
|
|
7
|
+
I needed a quick way to save data without dealing with schemas, SQL, or complex database setup. While Firestore is great, it can be overkill for simple use cases. JotDB provides a simpler alternative by leveraging Cloudflare Durable Objects, making it perfect for:
|
|
63
8
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export interface Env {
|
|
70
|
-
JOTDB: DurableObjectNamespace<JotDB>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export default {
|
|
74
|
-
async fetch(request: Request, env: Env) {
|
|
75
|
-
const id = env.JOTDB.idFromName("my-db");
|
|
76
|
-
const db = env.JOTDB.get(id);
|
|
77
|
-
|
|
78
|
-
await db.setSchema({
|
|
79
|
-
name: "string",
|
|
80
|
-
age: "number",
|
|
81
|
-
email: "email"
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
await db.setAll({
|
|
85
|
-
name: "Alice",
|
|
86
|
-
age: 42,
|
|
87
|
-
email: "alice@example.com"
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const all = await db.getAll();
|
|
91
|
-
|
|
92
|
-
return new Response(JSON.stringify(all, null, 2), {
|
|
93
|
-
headers: { "Content-Type": "application/json" }
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
A lightweight, schema-validated key-value store built on Cloudflare Durable Objects.
|
|
102
|
-
|
|
103
|
-
## Features
|
|
104
|
-
|
|
105
|
-
- Schema validation using Zod
|
|
106
|
-
- Automatic schema inference
|
|
107
|
-
- Audit logging
|
|
108
|
-
- TypeScript support
|
|
109
|
-
- Read-only mode
|
|
110
|
-
- Auto-strip mode for schema validation
|
|
9
|
+
- Quick prototypes
|
|
10
|
+
- Small to medium applications
|
|
11
|
+
- Serverless environments
|
|
12
|
+
- Real-time data storage
|
|
13
|
+
- Collaborative applications
|
|
111
14
|
|
|
112
15
|
## Installation
|
|
113
16
|
|
|
114
17
|
```bash
|
|
18
|
+
# Using npm
|
|
115
19
|
npm install jotdb
|
|
116
|
-
|
|
117
|
-
|
|
20
|
+
|
|
21
|
+
# Using yarn
|
|
22
|
+
yarn add jotdb
|
|
23
|
+
|
|
24
|
+
# Using pnpm
|
|
25
|
+
pnpm add jotdb
|
|
118
26
|
```
|
|
119
27
|
|
|
120
|
-
##
|
|
28
|
+
## Full Example
|
|
121
29
|
|
|
122
30
|
```typescript
|
|
123
31
|
import { JotDB } from 'jotdb';
|
|
124
32
|
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export default {
|
|
131
|
-
async fetch(request: Request, env: Env) {
|
|
132
|
-
const id = env.JOTDB.idFromName("my-db");
|
|
133
|
-
const db = env.JOTDB.get(id);
|
|
134
|
-
|
|
135
|
-
// Set a value
|
|
136
|
-
await db.set("key", "value");
|
|
137
|
-
|
|
138
|
-
// Get a value
|
|
139
|
-
const value = await db.get("key");
|
|
140
|
-
|
|
141
|
-
// Set schema
|
|
142
|
-
await db.setSchema({
|
|
143
|
-
name: "string",
|
|
144
|
-
age: "number",
|
|
145
|
-
email: "email"
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Set multiple values
|
|
149
|
-
await db.setAll({
|
|
150
|
-
name: "John",
|
|
151
|
-
age: 30,
|
|
152
|
-
email: "john@example.com"
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
```
|
|
33
|
+
// Initialize the database
|
|
34
|
+
const jotId = env.JotDB.idFromName("my-db");
|
|
35
|
+
const db = env.JotDB.get(jotId);
|
|
157
36
|
|
|
158
|
-
|
|
37
|
+
// Set a value
|
|
38
|
+
await db.set("user:123", { name: "John", age: 30 });
|
|
159
39
|
|
|
160
|
-
|
|
40
|
+
// Get a value
|
|
41
|
+
const user = await db.get("user:123");
|
|
42
|
+
console.log(user); // { name: "John", age: 30 }
|
|
161
43
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
- `setAll(obj: Record<string, unknown>): Promise<void>`
|
|
166
|
-
- `delete(key: string): Promise<void>`
|
|
167
|
-
- `clear(): Promise<void>`
|
|
168
|
-
- `keys(): Promise<string[]>`
|
|
169
|
-
- `has(key: string): Promise<boolean>`
|
|
170
|
-
- `getSchema(): Promise<SchemaDefinition>`
|
|
171
|
-
- `setSchema(schema: SchemaDefinition): Promise<void>`
|
|
172
|
-
- `getOptions(): Promise<JotDBOptions>`
|
|
173
|
-
- `setOptions(opts: Partial<JotDBOptions>): Promise<void>`
|
|
174
|
-
- `getAuditLog(): Promise<AuditLogEntry[]>`
|
|
175
|
-
- `clearAuditLog(): Promise<void>`
|
|
44
|
+
// Delete a value
|
|
45
|
+
await db.delete("user:123");
|
|
46
|
+
```
|
|
176
47
|
|
|
177
|
-
|
|
48
|
+
## API Reference
|
|
178
49
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
50
|
+
| Method | Description | Parameters | Returns |
|
|
51
|
+
|--------|-------------|------------|---------|
|
|
52
|
+
| `set(key, value)` | Store a value | `key: string`, `value: any` | `Promise<void>` |
|
|
53
|
+
| `get(key)` | Retrieve a value | `key: string` | `Promise<any>` |
|
|
54
|
+
| `delete(key)` | Remove a value | `key: string` | `Promise<void>` |
|
|
55
|
+
| `list(prefix?)` | List all keys (optionally filtered by prefix) | `prefix?: string` | `Promise<string[]>` |
|
|
182
56
|
|
|
183
|
-
|
|
184
|
-
autoStrip: boolean;
|
|
185
|
-
readOnly: boolean;
|
|
186
|
-
}
|
|
57
|
+
## Types
|
|
187
58
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
59
|
+
```typescript
|
|
60
|
+
interface JotDB {
|
|
61
|
+
set(key: string, value: any): Promise<void>;
|
|
62
|
+
get(key: string): Promise<any>;
|
|
63
|
+
delete(key: string): Promise<void>;
|
|
64
|
+
list(prefix?: string): Promise<string[]>;
|
|
192
65
|
}
|
|
193
66
|
```
|
|
194
67
|
|
|
195
68
|
## License
|
|
196
69
|
|
|
197
|
-
MIT
|
|
70
|
+
MIT License - feel free to use this in your own projects!
|
|
198
71
|
|
|
199
72
|
## Contributing
|
|
200
73
|
|
|
74
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
75
|
+
|
|
201
76
|
1. Fork the repository
|
|
202
77
|
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
203
78
|
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
@@ -206,6 +81,8 @@ MIT
|
|
|
206
81
|
|
|
207
82
|
## Testing
|
|
208
83
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
84
|
+
Currently, testing is done manually in production. We're working on adding a comprehensive test suite. For now, you can test the functionality by:
|
|
85
|
+
|
|
86
|
+
1. Deploying to Cloudflare Workers
|
|
87
|
+
2. Using the example endpoints
|
|
88
|
+
3. Verifying data persistence
|