@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.
Files changed (2) hide show
  1. package/README.md +92 -99
  2. package/package.json +6 -3
package/README.md CHANGED
@@ -1,158 +1,151 @@
1
- # Prisma IndexedDB Client Generator
1
+ # Prisma IDB
2
2
 
3
- This library is a **Prisma generator** that creates a client with a similar syntax and behavior to the Prisma Client but is designed to operate with **IndexedDB** for local storage. It allows developers to interact with IndexedDB using a familiar Prisma-like API.
3
+ > You already write Prisma on the server. Now write it in the browser.
4
4
 
5
- **[๐Ÿ“– Documentation](https://prisma-idb.dev/) โ€ข [๐Ÿš€ Live Demo](https://kanban.prisma-idb.dev/) โ€ข [๐Ÿ“ฆ npm Package](https://www.npmjs.com/package/@prisma-idb/idb-client-generator) โ€ข [๐Ÿ—๏ธ Main Repository](https://github.com/prisma-idb/idb-client-generator)**
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
- ## โš ๏ธ Warning
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
- This library is not fully ready yet. Check [issue #52](https://github.com/prisma-idb/idb-client-generator/issues/52) for the current list of implemented features.
9
+ ---
10
10
 
11
- ## Features
11
+ ## What this package does
12
12
 
13
- - Prisma-like syntax and API for IndexedDB.
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
- ## Installation
15
+ ## The difference
19
16
 
20
- ```bash
21
- npm install @prisma-idb/idb-client-generator
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
- ## Usage
33
+ Prisma IDB:
25
34
 
26
- ### 1. Add to Prisma Schema
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
- Update your `prisma.schema` file to include the generator:
45
+ Same API shape as Prisma Client. Fully typed. Local-first.
29
46
 
30
- ```prisma
31
- datasource db {
32
- provider = "postgresql"
33
- url = env("DATABASE_URL")
34
- }
47
+ ## And when you need sync
35
48
 
36
- generator client {
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 = "idb-client-generator"
42
- output = "./prisma-idb"
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
- ### 2. Generate the Client
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
- Run the Prisma client generation command:
66
+ ### Install
55
67
 
56
68
  ```bash
57
- npx prisma generate
69
+ pnpm add idb
70
+ pnpm add -D @prisma-idb/idb-client-generator
58
71
  ```
59
72
 
60
- This will generate a client in your project.
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
- ```typescript
67
- import { PrismaIDBClient } from "./outputPath/prisma-idb-client";
75
+ ### Configure
68
76
 
69
- async function main() {
70
- const idbClient = await PrismaIDBClient.createClient();
77
+ Add the generator to your `schema.prisma`:
71
78
 
72
- await idbClient.user.create({
73
- data: { name: "Alice", email: "alice@example.com" },
74
- });
79
+ ```prisma
80
+ generator prismaIDB {
81
+ provider = "idb-client-generator"
82
+ output = "./prisma-idb"
83
+ }
75
84
 
76
- const users = await idbClient.user.findMany();
77
- console.log(users);
85
+ model Todo {
86
+ id String @id @default(cuid())
87
+ title String
88
+ done Boolean @default(false)
78
89
  }
79
90
  ```
80
91
 
81
- ## API
92
+ If you enable sync, use a single client-generated ID field such as `cuid()` or `uuid()` on syncable models.
82
93
 
83
- The API mimics Prisma Client's API for ease of use:
94
+ ### Generate
84
95
 
85
- ### `create`
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
- ### `findMany`
100
+ ### Use the generated client
98
101
 
99
- Retrieve all records:
100
-
101
- ```javascript
102
- idbClient.modelName.findMany();
103
- ```
104
-
105
- ### `findUnique`
102
+ ```typescript
103
+ import { PrismaIDBClient } from "./prisma-idb";
106
104
 
107
- Retrieve a single record by unique key:
105
+ const idb = await PrismaIDBClient.createClient();
108
106
 
109
- ```javascript
110
- idbClient.modelName.findUnique({
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
- Update a record:
111
+ const todos = await idb.todo.findMany({
112
+ where: { done: false },
113
+ });
118
114
 
119
- ```javascript
120
- idbClient.modelName.update({
121
- where: { key: value },
122
- data: { key: newValue },
115
+ await idb.todo.update({
116
+ where: { id: todoId },
117
+ data: { done: true },
123
118
  });
124
119
  ```
125
120
 
126
- ### `delete`
127
-
128
- Delete a record:
121
+ ## Features
129
122
 
130
- ```javascript
131
- idbClient.modelName.delete({
132
- where: { key: value },
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
- - **[๐Ÿ“– Full Documentation](https://prisma-idb.dev/)** - Complete API reference, sync guides, and schema requirements
139
- - **[๐Ÿš€ Kanban Example](https://kanban.prisma-idb.dev/)** - Live demonstration of the sync engine
140
- - **[๐Ÿ’ป Example Source Code](../../apps/pidb-kanban-example)** - Full working example with SvelteKit and sync workers
141
- - **[๐Ÿ—๏ธ Main Repository](https://github.com/prisma-idb/idb-client-generator)** - Source code and issue tracking
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
- We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project.
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
- If you discover a security vulnerability, please follow our SECURITY.md guidelines on reporting issues responsibly.
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
- This project is licensed under the MIT License. See the LICENSE file for more details.
147
+ MIT. See [LICENSE](https://github.com/prisma-idb/idb-client-generator/blob/main/LICENSE).
155
148
 
156
- ## Acknowledgements
149
+ ## Disclaimer
157
150
 
158
- Special thanks to the open-source community for their contributions to the tools and libraries used in this project.
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": "Generate types for idb from prisma schema",
4
- "version": "0.36.1",
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"