@prisma-idb/idb-client-generator 0.36.1 โ 0.36.2
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 +92 -99
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,158 +1,151 @@
|
|
|
1
|
-
# Prisma
|
|
1
|
+
# Prisma IDB
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> You already write Prisma on the server. Now write it in the browser.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`@prisma-idb/idb-client-generator` is the npm package that generates a type-safe IndexedDB client with the Prisma-style API you already know, plus an optional sync engine for offline-first apps.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**[Documentation](https://prisma-idb.dev/) ยท [Live Demo](https://kanban.prisma-idb.dev/) ยท [Repository](https://github.com/prisma-idb/idb-client-generator)**
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
---
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## What this package does
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- Supports CRUD operations with structured data.
|
|
15
|
-
- Integrates seamlessly with Prisma workflows.
|
|
16
|
-
- Generates a client tailored to your Prisma schema.
|
|
13
|
+
This package is a Prisma generator. You add it to your Prisma schema, run `prisma generate`, and it produces a client in your app that talks to IndexedDB with familiar Prisma-style queries.
|
|
17
14
|
|
|
18
|
-
##
|
|
15
|
+
## The difference
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
Even with the [`idb`](https://github.com/jakearchibald/idb) library, querying across relations means manual index lookups, joins in application code, and no generated types:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const db = await openDB("MyDB", 1);
|
|
21
|
+
|
|
22
|
+
const posts = await db.getAllFromIndex("posts", "byAuthor", userId);
|
|
23
|
+
|
|
24
|
+
const result = [];
|
|
25
|
+
for (const post of posts) {
|
|
26
|
+
if (!post.published) continue;
|
|
27
|
+
const comments = await db.getAllFromIndex("comments", "byPost", post.id);
|
|
28
|
+
result.push({ ...post, comments });
|
|
29
|
+
}
|
|
30
|
+
result.sort((a, b) => b.createdAt - a.createdAt);
|
|
22
31
|
```
|
|
23
32
|
|
|
24
|
-
|
|
33
|
+
Prisma IDB:
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
```typescript
|
|
36
|
+
const posts = await idb.post.findMany({
|
|
37
|
+
where: { authorId: userId, published: true },
|
|
38
|
+
include: {
|
|
39
|
+
comments: { orderBy: { createdAt: "desc" } },
|
|
40
|
+
},
|
|
41
|
+
orderBy: { createdAt: "desc" },
|
|
42
|
+
});
|
|
43
|
+
```
|
|
27
44
|
|
|
28
|
-
|
|
45
|
+
Same API shape as Prisma Client. Fully typed. Local-first.
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
datasource db {
|
|
32
|
-
provider = "postgresql"
|
|
33
|
-
url = env("DATABASE_URL")
|
|
34
|
-
}
|
|
47
|
+
## And when you need sync
|
|
35
48
|
|
|
36
|
-
|
|
37
|
-
provider = "prisma-client-js"
|
|
38
|
-
}
|
|
49
|
+
Most IndexedDB libraries stop at CRUD. Prisma IDB can also generate a bidirectional sync layer that handles the harder parts:
|
|
39
50
|
|
|
51
|
+
```prisma
|
|
40
52
|
generator prismaIDB {
|
|
41
|
-
provider
|
|
42
|
-
output
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
model User {
|
|
46
|
-
id Int @id @default(autoincrement())
|
|
47
|
-
name String
|
|
48
|
-
email String @unique
|
|
53
|
+
provider = "idb-client-generator"
|
|
54
|
+
output = "./prisma-idb"
|
|
55
|
+
outboxSync = true
|
|
56
|
+
rootModel = "User"
|
|
49
57
|
}
|
|
50
58
|
```
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
- Outbox pattern for reliable local mutations and retries
|
|
61
|
+
- Ownership DAG so sync authorization is structural
|
|
62
|
+
- Conflict handling through server-authoritative changelog materialization
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
### Install
|
|
55
67
|
|
|
56
68
|
```bash
|
|
57
|
-
|
|
69
|
+
pnpm add idb
|
|
70
|
+
pnpm add -D @prisma-idb/idb-client-generator
|
|
58
71
|
```
|
|
59
72
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
### 3. Use the Client
|
|
63
|
-
|
|
64
|
-
Import the generated client and use it in your code:
|
|
73
|
+
You will also need your normal Prisma setup, including `prisma` and `@prisma/client`.
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
import { PrismaIDBClient } from "./outputPath/prisma-idb-client";
|
|
75
|
+
### Configure
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
const idbClient = await PrismaIDBClient.createClient();
|
|
77
|
+
Add the generator to your `schema.prisma`:
|
|
71
78
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
```prisma
|
|
80
|
+
generator prismaIDB {
|
|
81
|
+
provider = "idb-client-generator"
|
|
82
|
+
output = "./prisma-idb"
|
|
83
|
+
}
|
|
75
84
|
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
model Todo {
|
|
86
|
+
id String @id @default(cuid())
|
|
87
|
+
title String
|
|
88
|
+
done Boolean @default(false)
|
|
78
89
|
}
|
|
79
90
|
```
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
If you enable sync, use a single client-generated ID field such as `cuid()` or `uuid()` on syncable models.
|
|
82
93
|
|
|
83
|
-
|
|
94
|
+
### Generate
|
|
84
95
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Insert a new record:
|
|
88
|
-
|
|
89
|
-
```javascript
|
|
90
|
-
idbClient.modelName.create({
|
|
91
|
-
data: {
|
|
92
|
-
field: value,
|
|
93
|
-
},
|
|
94
|
-
});
|
|
96
|
+
```bash
|
|
97
|
+
pnpm exec prisma generate
|
|
95
98
|
```
|
|
96
99
|
|
|
97
|
-
###
|
|
100
|
+
### Use the generated client
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
```javascript
|
|
102
|
-
idbClient.modelName.findMany();
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### `findUnique`
|
|
102
|
+
```typescript
|
|
103
|
+
import { PrismaIDBClient } from "./prisma-idb";
|
|
106
104
|
|
|
107
|
-
|
|
105
|
+
const idb = await PrismaIDBClient.createClient();
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
where: { key: value },
|
|
107
|
+
await idb.todo.create({
|
|
108
|
+
data: { title: "Ship it", done: false },
|
|
112
109
|
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### `update`
|
|
116
110
|
|
|
117
|
-
|
|
111
|
+
const todos = await idb.todo.findMany({
|
|
112
|
+
where: { done: false },
|
|
113
|
+
});
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
data: { key: newValue },
|
|
115
|
+
await idb.todo.update({
|
|
116
|
+
where: { id: todoId },
|
|
117
|
+
data: { done: true },
|
|
123
118
|
});
|
|
124
119
|
```
|
|
125
120
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
Delete a record:
|
|
121
|
+
## Features
|
|
129
122
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
123
|
+
- Prisma-compatible API for IndexedDB CRUD and queries
|
|
124
|
+
- Full type safety generated from your Prisma schema
|
|
125
|
+
- `include` and `select` support for relations
|
|
126
|
+
- Offline-first operation with no network dependency for local reads and writes
|
|
127
|
+
- Optional sync for bidirectional server reconciliation
|
|
128
|
+
- Client-generated IDs for local creates without round-trips
|
|
135
129
|
|
|
136
130
|
## Resources
|
|
137
131
|
|
|
138
|
-
-
|
|
139
|
-
-
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
- **[๐ฆ npm Package](https://www.npmjs.com/package/@prisma-idb/idb-client-generator)** - Install from npm registry
|
|
132
|
+
- [Documentation](https://prisma-idb.dev/)
|
|
133
|
+
- [Live Kanban Demo](https://kanban.prisma-idb.dev/)
|
|
134
|
+
- [Example App Source](https://github.com/prisma-idb/idb-client-generator/tree/main/apps/pidb-kanban-example)
|
|
135
|
+
- [Issue Tracker](https://github.com/prisma-idb/idb-client-generator/issues)
|
|
143
136
|
|
|
144
137
|
## Contributing
|
|
145
138
|
|
|
146
|
-
|
|
139
|
+
Contributions welcome. See [CONTRIBUTING.md](https://github.com/prisma-idb/idb-client-generator/blob/main/.github/CONTRIBUTING.md).
|
|
147
140
|
|
|
148
141
|
## Security
|
|
149
142
|
|
|
150
|
-
|
|
143
|
+
See [SECURITY.md](https://github.com/prisma-idb/idb-client-generator/blob/main/.github/SECURITY.md) for reporting vulnerabilities.
|
|
151
144
|
|
|
152
145
|
## License
|
|
153
146
|
|
|
154
|
-
|
|
147
|
+
MIT. See [LICENSE](https://github.com/prisma-idb/idb-client-generator/blob/main/LICENSE).
|
|
155
148
|
|
|
156
|
-
##
|
|
149
|
+
## Disclaimer
|
|
157
150
|
|
|
158
|
-
|
|
151
|
+
Prisma is a trademark of Prisma. Prisma IDB is an independent open-source project, not affiliated with or endorsed by Prisma.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-idb/idb-client-generator",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.36.
|
|
3
|
+
"description": "Prisma generator for a type-safe IndexedDB client with optional sync",
|
|
4
|
+
"version": "0.36.2",
|
|
5
5
|
"main": "dist/generator.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -45,7 +45,10 @@
|
|
|
45
45
|
"author": "Yash Kolekar (https://whyash5114.com/)",
|
|
46
46
|
"keywords": [
|
|
47
47
|
"prisma",
|
|
48
|
-
"generator"
|
|
48
|
+
"generator",
|
|
49
|
+
"indexeddb",
|
|
50
|
+
"offline-first",
|
|
51
|
+
"sync"
|
|
49
52
|
],
|
|
50
53
|
"bugs": {
|
|
51
54
|
"url": "https://github.com/prisma-idb/idb-client-generator/issues"
|