dolphin-server-modules 2.2.4 → 2.5.1
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/DOLPHIN_MASTER_GUIDE_NEPALI.md +53 -19
- package/LICENSE +15 -0
- package/README.md +55 -218
- package/TUTORIAL_NEPALI.md +73 -201
- package/dist/bin/cli.js +183 -4
- package/dist/bin/cli.js.map +1 -1
- package/dist/curd/crud.js +5 -4
- package/dist/curd/crud.js.map +1 -1
- package/dist/realtime/codec.js +5 -5
- package/dist/realtime/codec.js.map +1 -1
- package/dist/router/router.js +1 -0
- package/dist/router/router.js.map +1 -1
- package/package.json +77 -21
- package/scripts/client.js +85 -8
- package/scripts/dolphin-persist.js +211 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Dolphin Framework: Absolute Master Guide (100+ Pages Equivalent) 🐬🇳🇵
|
|
2
|
-
Latest Version: v2.
|
|
2
|
+
Latest Version: v2.2.5 | Updated: 2026-04-24 | License: ISC
|
|
3
3
|
|
|
4
4
|
यो डकुमेन्ट Dolphin Framework को आधिकारिक र विस्तृत गाइड हो। यसले तपाईँलाई एउटा साधारण कोड लेख्ने डेभलपरबाट "Framework Master" बनाउन मद्दत गर्नेछ।
|
|
5
5
|
|
|
@@ -52,7 +52,11 @@ Latest Version: v2.3.7 | Updated: 2026-04-20 | License: MIT
|
|
|
52
52
|
|
|
53
53
|
१५. स्वतन्त्र अटो-स्वैगर जेनेरेसन
|
|
54
54
|
|
|
55
|
-
१६.
|
|
55
|
+
१६. DolphinStore: रिएक्टिभ स्टेट म्यानेजमेन्ट र फिल्टरिङ (New v2.2.5)
|
|
56
|
+
|
|
57
|
+
१७. DolphinPersist: अफलाइन क्यासिङ र Persistence (New v2.2.5)
|
|
58
|
+
|
|
59
|
+
१८. API रेफरेन्स
|
|
56
60
|
|
|
57
61
|
०. परिचय र दर्शन (Introduction & Philosophy)
|
|
58
62
|
Dolphin किन जन्मियो?
|
|
@@ -80,7 +84,11 @@ TypeScript: Dolphin टाइप-सेफ छ, त्यसैले TS सि
|
|
|
80
84
|
१.२ प्रोजेक्ट सुरु गर्ने
|
|
81
85
|
bash
|
|
82
86
|
mkdir dolphin-master-app && cd dolphin-master-app
|
|
83
|
-
|
|
87
|
+
|
|
88
|
+
# १. आधुनिक CLI बाट सुरु गर्ने
|
|
89
|
+
npx dolphin init
|
|
90
|
+
|
|
91
|
+
# २. वा म्यानुअल्ली इन्स्टल गर्ने
|
|
84
92
|
npm install dolphin-server-modules mongoose zod ioredis
|
|
85
93
|
npm install -D typescript ts-node @types/node nodemon
|
|
86
94
|
१.३ TypeScript कन्फिगर (tsconfig.json)
|
|
@@ -781,23 +789,49 @@ app.get('/docs', (ctx) => {
|
|
|
781
789
|
});
|
|
782
790
|
|
|
783
791
|
app.get('/docs/json', (ctx) => ctx.json(apiDocs));
|
|
784
|
-
१६. API रेफरेन्स (API Reference)
|
|
785
|
-
Server
|
|
786
|
-
Method Description
|
|
787
|
-
app.listen(port, cb) सर्भर सुरु गर्ने
|
|
788
|
-
app.get/patch/post/put/delete(path, ...handlers) HTTP मेथड
|
|
789
|
-
app.use(path?, middleware/router) मिडलवेयर वा राउटर
|
|
790
|
-
app.group(prefix, callback) रूट ग्रुपिङ
|
|
791
|
-
RealtimeCore v2.0
|
|
792
|
-
Method Description
|
|
793
|
-
rt.subscribe(topic, fn, deviceId?) सब्सक्राइब
|
|
794
|
-
rt.publish(topic, payload, opts?, deviceId?) पब्लिस
|
|
795
|
-
rt.pubPush(topic, payload) हाई-फ्रिक्वेन्सी पब्लिस
|
|
796
|
-
rt.subPull(deviceId, topic, count?) बफरबाट तान्ने
|
|
797
|
-
rt.pubFile(fileId, filePath, chunkSize?) फाइल तयारी
|
|
798
|
-
rt.subFile(deviceId, fileId, startChunk?) फाइल डाउनलोड
|
|
799
|
-
rt.resumeFile(deviceId, fileId) डाउनलोड पुनः सुरु
|
|
800
792
|
rt.register(deviceId, socket?, metadata?) डिभाइस रजिस्टर
|
|
793
|
+
१६. DolphinStore: रिएक्टिभ स्टेट म्यानेजमेन्ट र फिल्टरिङ (Reactive State) 🐬
|
|
794
|
+
Dolphin v2.2.5 मा थपिएको `DolphinStore` ले फ्रन्टइन्डमा डेटा म्यानेजमेन्टलाई अर्को स्तरमा पुर्याउँछ। यसले ब्याकइन्डको डेटालाई अटोमेटिक सिङ्क मात्र गर्दैन, तर फिल्टरिङ, सर्टिङ र लोड स्टेटहरू पनि म्यानेज गर्छ।
|
|
795
|
+
|
|
796
|
+
१६.१ स्टेट ट्र्याकिङ (State Tracking)
|
|
797
|
+
प्रत्येक कलेक्सनमा अब निम्न स्टेटहरू हुन्छन्:
|
|
798
|
+
- `loading`: डेटा लोड हुँदै गर्दा `true` हुन्छ।
|
|
799
|
+
- `success`: डेटा सफलतापूर्वक आएपछि `true` हुन्छ।
|
|
800
|
+
- `error`: केही समस्या आएमा एरर मेसेज बस्छ।
|
|
801
|
+
- `items`: वास्तविक डाटाहरूको एरे।
|
|
802
|
+
|
|
803
|
+
१६.२ फिल्टरिङ र सर्टिङ (Filtering & Sorting)
|
|
804
|
+
तपाईंले सर्भरबाट आएको डेटालाई लोकलमा फिल्टर र सर्ट गर्न सक्नुहुन्छ, जुन रियल-टाइम अपडेटसँग पनि काम गर्छ।
|
|
805
|
+
|
|
806
|
+
typescript
|
|
807
|
+
// १. फिल्टर गर्ने
|
|
808
|
+
dolphin.store.products.where(p => p.price > 1000);
|
|
809
|
+
|
|
810
|
+
// २. सर्ट गर्ने
|
|
811
|
+
dolphin.store.products.orderBy('name', 'asc');
|
|
812
|
+
|
|
813
|
+
// ३. रिसेट गर्ने
|
|
814
|
+
dolphin.store.products.clear();
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
१७. DolphinPersist: अफलाइन क्यासिङ र Persistence 💾
|
|
818
|
+
इन्टरनेट नहुँदा पनि तपाईंको एपले पहिलेकै डेटा देखाउन सकोस् भन्नका लागि `DolphinPersist` प्लगइन बनाइएको हो।
|
|
819
|
+
|
|
820
|
+
१७.१ सेटअप (Setup)
|
|
821
|
+
typescript
|
|
822
|
+
import { DolphinPersist, enablePersist } from 'dolphin-server-modules/scripts/dolphin-persist';
|
|
823
|
+
|
|
824
|
+
const persist = new DolphinPersist({
|
|
825
|
+
driver: 'indexeddb', // 'indexeddb' वा 'localstorage'
|
|
826
|
+
prefix: 'my_app_',
|
|
827
|
+
ttl: 3600000 // १ घण्टा सम्म क्यास राख्ने
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// स्टोरमा प्लगइन जोड्ने
|
|
831
|
+
enablePersist(dolphin.store, persist);
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
१८. API रेफरेन्स (API Reference)
|
|
801
835
|
rt.sendTo(deviceId, payload) सिधै पठाउने
|
|
802
836
|
rt.kick(deviceId, reason?) डिभाइस हटाउने
|
|
803
837
|
rt.privateSub(deviceId, fn) प्राइभेट सब्सक्राइब
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Shankar Phuyal
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# 🐬 Dolphin Framework (v2.2.
|
|
1
|
+
# 🐬 Dolphin Framework (v2.2.5)
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
@@ -25,8 +25,8 @@ Dolphin Framework को विस्तृत र आधिकारिक ग
|
|
|
25
25
|
- **Universal Compatibility**: Works with Mongoose, Zod, WebSocket, and Express-compatible middleware.
|
|
26
26
|
- **Multi-Handler Middleware**: Support for Express-style middleware chains `(ctx, next)`.
|
|
27
27
|
- **Auto-JSON Serialization**: Simply `return` an object from your handler!
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
28
|
+
- **Reactive State Sync (DolphinStore)**: Automated frontend state synchronization with built-in loading/error tracking and filtering.
|
|
29
|
+
- **Offline Persistence**: Built-in support for localStorage/IndexedDB caching.
|
|
30
30
|
- **Server-Served Client Library**: Zero-dependency frontend library for API, Auth, and Realtime—directly from your server.
|
|
31
31
|
|
|
32
32
|
---
|
|
@@ -36,15 +36,22 @@ Dolphin Framework को विस्तृत र आधिकारिक ग
|
|
|
36
36
|
npm install dolphin-server-modules
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
### 🛠️ CLI Usage (
|
|
40
|
-
|
|
39
|
+
### 🛠️ CLI Usage (v2.2.5)
|
|
40
|
+
Bootstrap a new project or run a server instantly:
|
|
41
41
|
```bash
|
|
42
|
-
|
|
42
|
+
# Initialize a new project
|
|
43
|
+
npx dolphin init
|
|
44
|
+
|
|
45
|
+
# Scaffold a production project structure
|
|
46
|
+
npx dolphin init-prod
|
|
47
|
+
|
|
48
|
+
# Start a server instantly
|
|
49
|
+
npx dolphin serve --port=8080
|
|
43
50
|
```
|
|
44
51
|
|
|
45
52
|
---
|
|
46
53
|
|
|
47
|
-
## 🚀 Quick Start
|
|
54
|
+
## 🚀 Quick Start (Modern ESM)
|
|
48
55
|
|
|
49
56
|
### 1. High-Performance Web Server
|
|
50
57
|
```typescript
|
|
@@ -53,108 +60,58 @@ import { createDolphinServer } from 'dolphin-server-modules/server';
|
|
|
53
60
|
const app = createDolphinServer();
|
|
54
61
|
|
|
55
62
|
app.get('/ping', (ctx) => {
|
|
56
|
-
return { message: 'pong', version: '
|
|
63
|
+
return { message: 'pong', version: '2.2.5' };
|
|
57
64
|
});
|
|
58
65
|
|
|
59
66
|
app.listen(3000, () => console.log("🐬 Dolphin swimming on port 3000"));
|
|
60
67
|
```
|
|
61
68
|
|
|
62
|
-
### 2.
|
|
63
|
-
Dolphin
|
|
69
|
+
### 2. Reactive Frontend Store (New in v2.2.5)
|
|
70
|
+
The Dolphin client library now includes a powerful reactive store that syncs with your database and provides loading/error states.
|
|
64
71
|
|
|
65
72
|
```html
|
|
66
|
-
<!--
|
|
73
|
+
<!-- index.html -->
|
|
67
74
|
<script src="/dolphin-client.js"></script>
|
|
68
75
|
|
|
69
76
|
<script>
|
|
70
77
|
async function init() {
|
|
71
|
-
// 1.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// 2. API with Dynamic Proxy (New in v2.2)
|
|
75
|
-
const products = await dolphin.api.products();
|
|
76
|
-
const profile = await dolphin.api.users.profile();
|
|
77
|
-
await dolphin.api.products.post({ name: "Dolphin" });
|
|
78
|
-
await dolphin.api.call.get(); // Smart proxy handles reserved keywords like 'call' or 'apply'
|
|
79
|
-
|
|
80
|
-
// 3. Advanced Realtime (v2.2)
|
|
81
|
-
await dolphin.connect();
|
|
82
|
-
|
|
83
|
-
// Subscribe with cleanup support
|
|
84
|
-
const onTemp = (val) => console.log(val);
|
|
85
|
-
dolphin.subscribe('sensors/temp', onTemp);
|
|
86
|
-
// ... later
|
|
87
|
-
dolphin.unsubscribe('sensors/temp', onTemp);
|
|
88
|
-
|
|
89
|
-
// High-frequency data (30,000+ msgs/sec)
|
|
90
|
-
dolphin.pubPush('sensors/temp', { val: 24.5 });
|
|
91
|
-
|
|
92
|
-
// Demand-based pulling (Data saving)
|
|
93
|
-
dolphin.subscribe('pull:response/logs', (history) => console.log(history));
|
|
94
|
-
dolphin.subPull('logs', 50);
|
|
95
|
-
|
|
96
|
-
// Chunked File Transfer with Resume support
|
|
97
|
-
dolphin.subscribe('file:chunk/map-data', (chunk) => {
|
|
98
|
-
console.log(`Downloaded ${chunk.chunkIndex}/${chunk.totalChunks}`);
|
|
99
|
-
});
|
|
100
|
-
dolphin.subFile('map-data');
|
|
101
|
-
}
|
|
102
|
-
</script>
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### 3. Full CRUD API with Mongoose (v1.7.0)
|
|
106
|
-
|
|
107
|
-
> **Important:** Use `enforceOwnership: false` for public APIs (no auth required).
|
|
108
|
-
> Default is `true` — requires `userId` from auth middleware.
|
|
109
|
-
>
|
|
110
|
-
> Use `createCRUD()` for the service layer, or `createCrudController()` for ready-to-use route handlers.
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { createDolphinServer } from 'dolphin-server-modules/server';
|
|
114
|
-
import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
|
|
115
|
-
import { createCRUD } from 'dolphin-server-modules/crud';
|
|
116
|
-
import mongoose from 'mongoose';
|
|
78
|
+
// 1. Setup Collection
|
|
79
|
+
const products = dolphin.store.products;
|
|
117
80
|
|
|
118
|
-
//
|
|
119
|
-
|
|
81
|
+
// 2. State Tracking (Reactive)
|
|
82
|
+
if (products.loading) console.log("Loading products...");
|
|
83
|
+
if (products.error) console.log("Error:", products.error);
|
|
120
84
|
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
85
|
+
// 3. Powerful Filtering & Sorting (Local & Reactive)
|
|
86
|
+
products
|
|
87
|
+
.where(p => p.price > 100)
|
|
88
|
+
.orderBy('name', 'asc');
|
|
125
89
|
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
const crud = createCRUD(db, { enforceOwnership: false }); // public API
|
|
90
|
+
// items array always reflects current filter/sort + realtime updates
|
|
91
|
+
console.log(products.items);
|
|
129
92
|
|
|
130
|
-
// 4.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
app.get('/products/:id', async (ctx) => {
|
|
135
|
-
const item = await crud.readOne('Product', ctx.params.id);
|
|
136
|
-
if (!item) return ctx.status(404).json({ error: 'Not Found' });
|
|
137
|
-
ctx.json(item);
|
|
138
|
-
});
|
|
139
|
-
app.post('/products', async (ctx) => ctx.status(201).json(await crud.create('Product', ctx.body)));
|
|
140
|
-
app.put('/products/:id', async (ctx) => ctx.json(await crud.updateOne('Product', ctx.params.id, ctx.body)));
|
|
141
|
-
app.delete('/products/:id', async (ctx) => ctx.json(await crud.deleteOne('Product', ctx.params.id)));
|
|
142
|
-
|
|
143
|
-
app.listen(3000);
|
|
93
|
+
// 4. Offline Persistence (Optional Plugin)
|
|
94
|
+
// Add dolphin-persist.js for offline cache
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
144
97
|
```
|
|
145
98
|
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
import { RealtimeCore } from 'dolphin-server-modules/realtime';
|
|
149
|
-
import { ModbusPlugin, HL7Plugin } from 'dolphin-server-modules/realtime/plugins';
|
|
99
|
+
---
|
|
150
100
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
rt.use(HL7Plugin);
|
|
101
|
+
## 🧩 DolphinPersist - Offline Caching
|
|
102
|
+
Include `dolphin-persist.js` to enable zero-config offline support for your store.
|
|
154
103
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
104
|
+
```html
|
|
105
|
+
<script src="/dolphin-client.js"></script>
|
|
106
|
+
<!-- You can serve this file or include it from your assets -->
|
|
107
|
+
<script src="scripts/dolphin-persist.js"></script>
|
|
108
|
+
|
|
109
|
+
<script>
|
|
110
|
+
const persist = new DolphinPersist({ driver: 'indexeddb' }); // or 'localstorage'
|
|
111
|
+
enablePersist(dolphin.store, persist);
|
|
112
|
+
|
|
113
|
+
// Now dolphin.store will load from cache instantly before fetching from server
|
|
114
|
+
</script>
|
|
158
115
|
```
|
|
159
116
|
|
|
160
117
|
---
|
|
@@ -166,7 +123,7 @@ rt.subscribe('factory/machine/+', (data) => {
|
|
|
166
123
|
| **Server** | `dolphin-server-modules/server` | Native HTTP server with `ctx` API & Auto-JSON. |
|
|
167
124
|
| **Router** | `dolphin-server-modules/router` | Standalone sub-routers with multi-handler support. |
|
|
168
125
|
| **Auth** | `dolphin-server-modules/auth` | Argon2/JWT based secure auth with 2FA (TOTP). |
|
|
169
|
-
| **CRUD** | `dolphin-server-modules/
|
|
126
|
+
| **CRUD** | `dolphin-server-modules/curd` | Generic CRUD service with ownership & soft-delete. |
|
|
170
127
|
| **Auth Controller** | `dolphin-server-modules/auth-controller` | Pre-built auth routes (register, login, refresh). |
|
|
171
128
|
| **Realtime** | `dolphin-server-modules/realtime` | Pub/Sub engine with `TopicTrie` & binary codecs. |
|
|
172
129
|
| **Validation** | `dolphin-server-modules/middleware/zod` | Type-safe Zod validation middleware. |
|
|
@@ -174,137 +131,17 @@ rt.subscribe('factory/machine/+', (data) => {
|
|
|
174
131
|
| **IoT Plugins** | `dolphin-server-modules/realtime/plugins` | Native parsers for HL7, Modbus, and DICOM. |
|
|
175
132
|
| **Signaling** | `dolphin-server-modules/signaling` | Universal WebRTC & Control Signaling module. |
|
|
176
133
|
| **Mongoose Adapter** | `dolphin-server-modules/adapters/mongoose` | Full Mongoose ↔ CRUD bridge with query mapping. |
|
|
177
|
-
| **Client Lib** | `/dolphin-client.js` | Zero-dependency full-stack JS client
|
|
178
|
-
|
|
179
|
-
### 🧩 How to use individual modules:
|
|
180
|
-
```javascript
|
|
181
|
-
// Example: Using only the Auth module in Express/Fastify
|
|
182
|
-
const { createDolphinAuth } = require('dolphin-server-modules/auth');
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
---
|
|
186
|
-
|
|
187
|
-
## 🛡️ Auth Module - 2FA with Recovery Codes
|
|
188
|
-
|
|
189
|
-
Dolphin supports TOTP-based 2FA with recovery codes for account recovery:
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
const auth = createAuth({ secret: process.env.ENCRYPTION_KEY, issuer: 'MyApp' });
|
|
193
|
-
|
|
194
|
-
// Enable 2FA for user
|
|
195
|
-
const { secret, uri } = await auth.enable2FA(db, userId);
|
|
196
|
-
// Scan QR code with authenticator app
|
|
197
|
-
|
|
198
|
-
// Verify and activate
|
|
199
|
-
const { recoveryCodes } = await auth.verify2FA(db, userId, '123456');
|
|
200
|
-
// recoveryCodes: ['A3B2-C4D5', 'E6F7-G8H9', ...] (8 codes)
|
|
201
|
-
|
|
202
|
-
// Disable 2FA
|
|
203
|
-
await auth.disable2FA(db, userId, '123456');
|
|
204
|
-
|
|
205
|
-
// Regenerate recovery codes
|
|
206
|
-
const { recoveryCodes } = await auth.regenerateRecoveryCodes(db, userId, '123456');
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### secureCookies Configuration
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
const auth = createAuth({
|
|
213
|
-
secret: process.env.ENCRYPTION_KEY,
|
|
214
|
-
secureCookies: process.env.NODE_ENV === 'production' // true in prod
|
|
215
|
-
});
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
## ⚠️ Important: `enforceOwnership` Option
|
|
221
|
-
|
|
222
|
-
The `createCRUD` function has `enforceOwnership: true` by default. This means **every operation requires a `userId`** (from auth middleware). For public APIs, set it to `false`:
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
// Public API — no auth needed
|
|
226
|
-
const crud = createCRUD(db, { enforceOwnership: false });
|
|
227
|
-
|
|
228
|
-
// Protected API — requires auth middleware to set ctx.req.user
|
|
229
|
-
const crud = createCRUD(db, { enforceOwnership: true });
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Soft Delete
|
|
233
|
-
|
|
234
|
-
Enable soft delete to keep data but hide from queries:
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
const crud = createCRUD(db, {
|
|
238
|
-
enforceOwnership: true,
|
|
239
|
-
softDelete: true // Records marked with `deletedAt` timestamp
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// Delete (soft) — sets deletedAt timestamp
|
|
243
|
-
await crud.deleteOne('Product', id);
|
|
244
|
-
|
|
245
|
-
// Restore — removes deletedAt
|
|
246
|
-
await crud.restore('Product', id);
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
### Realtime Database Sync
|
|
250
|
-
|
|
251
|
-
Broadcast CRUD changes to connected clients automatically:
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
const crud = createCRUD(db, {
|
|
255
|
-
enforceOwnership: true,
|
|
256
|
-
realtime: rt // RealtimeCore instance
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// On create/update/delete, automatically publishes:
|
|
260
|
-
// - db:sync/product { type: 'create', data: {...} }
|
|
261
|
-
// - db:sync/product { type: 'update', data: {...} }
|
|
262
|
-
// - db:sync/product { type: 'delete', data: {...} }
|
|
263
|
-
|
|
264
|
-
// Client subscribes:
|
|
265
|
-
dolphin.subscribe('db:sync/product', (update) => {
|
|
266
|
-
console.log(update.type, update.data);
|
|
267
|
-
});
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## 🛣️ Advanced Middleware & Sub-Routing
|
|
273
|
-
|
|
274
|
-
```typescript
|
|
275
|
-
import { createDolphinRouter } from 'dolphin-server-modules/router';
|
|
276
|
-
import { createDolphinAuthController } from 'dolphin-server-modules/auth-controller';
|
|
277
|
-
|
|
278
|
-
const auth = createDolphinAuthController(db, config);
|
|
279
|
-
const apiV1 = createDolphinRouter();
|
|
280
|
-
|
|
281
|
-
// Multi-handler: middleware + route handler
|
|
282
|
-
apiV1.get('/me', auth.requireAuth, async (ctx) => {
|
|
283
|
-
return { user: ctx.req.user };
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const mainApp = createDolphinServer();
|
|
287
|
-
mainApp.use('/api/v1', apiV1);
|
|
288
|
-
```
|
|
134
|
+
| **Client Lib** | `/dolphin-client.js` | Zero-dependency full-stack JS client. Includes **Reactive Store (DolphinStore)** with filter/sort and loading states. |
|
|
289
135
|
|
|
290
136
|
---
|
|
291
137
|
|
|
292
138
|
## 🧪 Testing
|
|
293
|
-
|
|
294
139
|
The project uses **Jest** with **ts-jest**. Integration tests use `mongodb-memory-server` for real Mongoose testing without an external database.
|
|
295
140
|
|
|
296
141
|
```bash
|
|
297
|
-
npm test # Run all
|
|
142
|
+
npm test # Run all 200+ tests
|
|
298
143
|
```
|
|
299
144
|
|
|
300
|
-
| Suite | Tests |
|
|
301
|
-
| :--- | :--- |
|
|
302
|
-
| `adapters/mongoose/integration.test.ts` | 23 (real Mongoose) |
|
|
303
|
-
| `adapters/mongoose/index.test.ts` | 7 |
|
|
304
|
-
| `auth/auth.test.ts` | — |
|
|
305
|
-
| `curd/crud.test.ts` | — |
|
|
306
|
-
| + 8 more suites | — |
|
|
307
|
-
|
|
308
145
|
---
|
|
309
146
|
|
|
310
147
|
## 📊 2026 Performance Benchmarks
|
|
@@ -313,7 +150,7 @@ npm test # Run all 167 tests (12 suites)
|
|
|
313
150
|
| :--- | :--- | :--- | :--- |
|
|
314
151
|
| Express.js | ~15,000 | 180ms | N/A |
|
|
315
152
|
| Fastify | ~35,000 | 90ms | ~10,000 msgs/sec |
|
|
316
|
-
| **Dolphin V2** | **45,000+** | **< 10ms** | **35,000+ msgs/sec** |
|
|
153
|
+
| **Dolphin V2.2** | **45,000+** | **< 10ms** | **35,000+ msgs/sec** |
|
|
317
154
|
|
|
318
155
|
---
|
|
319
156
|
|
|
@@ -326,10 +163,10 @@ npm test # Run all 167 tests (12 suites)
|
|
|
326
163
|
- [x] Real Mongoose adapter with `$like`, `id→_id` query mapping
|
|
327
164
|
- [x] Integration test suite with `mongodb-memory-server`
|
|
328
165
|
- [x] **Server-Served Client Library**: `/dolphin-client.js` auto-serve
|
|
329
|
-
- [x] **
|
|
330
|
-
- [x] **
|
|
331
|
-
- [x] **
|
|
332
|
-
- [ ] **
|
|
166
|
+
- [x] **Reactive Store (DolphinStore)**: Filter, Sort, and State tracking
|
|
167
|
+
- [x] **Offline Persistence**: DolphinPersist plugin
|
|
168
|
+
- [x] **Dolphin CLI**: `npx dolphin init` and `init-prod`
|
|
169
|
+
- [ ] **AI-Driven Generation**: Advanced multi-file AI project scaffolding
|
|
333
170
|
|
|
334
171
|
---
|
|
335
172
|
|