dolphin-server-modules 2.2.1 → 2.2.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/DOLPHIN_MASTER_GUIDE_NEPALI.md +64 -24
- package/LICENSE +15 -0
- package/README.md +74 -143
- package/TUTORIAL_NEPALI.md +73 -193
- package/dist/adapters/mongoose/index.js.map +1 -1
- package/dist/adapters/mongoose/index.test.js.map +1 -1
- package/dist/adapters/mongoose/integration.test.js.map +1 -1
- package/dist/auth/auth.js.map +1 -1
- package/dist/auth/auth.test.js.map +1 -1
- package/dist/authController/authController.js.map +1 -1
- package/dist/authController/authController.test.js.map +1 -1
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +405 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/controller/controller.js.map +1 -1
- package/dist/controller/controller.test.js.map +1 -1
- package/dist/curd/crud.d.ts +1 -0
- package/dist/curd/crud.js +37 -12
- package/dist/curd/crud.js.map +1 -1
- package/dist/curd/crud.test.js.map +1 -1
- package/dist/demo-server.js.map +1 -1
- package/dist/djson/djson.js.map +1 -1
- package/dist/djson/djson.test.js.map +1 -1
- package/dist/dolphin-bench.d.ts +1 -0
- package/dist/dolphin-bench.js +68 -0
- package/dist/dolphin-bench.js.map +1 -0
- package/dist/hard-performance-test.d.ts +1 -0
- package/dist/hard-performance-test.js +102 -0
- package/dist/hard-performance-test.js.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/middleware/zod.js.map +1 -1
- package/dist/middleware/zod.test.js.map +1 -1
- package/dist/performance-test.d.ts +1 -0
- package/dist/performance-test.js +97 -0
- package/dist/performance-test.js.map +1 -0
- package/dist/real-test-mongoose.d.ts +1 -0
- package/dist/real-test-mongoose.js +109 -0
- package/dist/real-test-mongoose.js.map +1 -0
- package/dist/realtime/codec.js +5 -5
- package/dist/realtime/codec.js.map +1 -1
- package/dist/realtime/core.d.ts +1 -1
- package/dist/realtime/core.js +44 -14
- package/dist/realtime/core.js.map +1 -1
- package/dist/realtime/devicemanager.js.map +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime/plugins.js.map +1 -1
- package/dist/realtime/realtime.test.js.map +1 -1
- package/dist/realtime/trie.js.map +1 -1
- package/dist/router/router.js +1 -0
- package/dist/router/router.js.map +1 -1
- package/dist/router/router.test.js.map +1 -1
- package/dist/server/server.js +2 -1
- package/dist/server/server.js.map +1 -1
- package/dist/server/server.test.js.map +1 -1
- package/dist/signaling/index.js.map +1 -1
- package/dist/signaling/signaling.test.d.ts +1 -0
- package/dist/signaling/signaling.test.js +114 -0
- package/dist/signaling/signaling.test.js.map +1 -0
- package/dist/swagger/swagger.js.map +1 -1
- package/dist/swagger/swagger.test.js.map +1 -1
- package/dist/test-2fa-real.d.ts +1 -0
- package/dist/test-2fa-real.js +110 -0
- package/dist/test-2fa-real.js.map +1 -0
- package/dist/test-dolphin.d.ts +1 -0
- package/dist/test-dolphin.js +100 -0
- package/dist/test-dolphin.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +82 -20
- package/scripts/client.js +176 -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.
|
|
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.2.0 | Updated: 2026-04-09 | 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)
|
|
@@ -188,7 +196,7 @@ typescript
|
|
|
188
196
|
import { createAuth } from 'dolphin-server-modules/auth';
|
|
189
197
|
|
|
190
198
|
const auth = createAuth({
|
|
191
|
-
secret:
|
|
199
|
+
secret: process.env.ENCRYPTION_KEY,
|
|
192
200
|
tokenExpiry: '1h',
|
|
193
201
|
refreshExpiry: '7d'
|
|
194
202
|
});
|
|
@@ -236,7 +244,7 @@ import { createCrudController } from 'dolphin-server-modules/curd';
|
|
|
236
244
|
import mongoose from 'mongoose';
|
|
237
245
|
|
|
238
246
|
const app = createDolphinServer();
|
|
239
|
-
const auth = createAuth({ secret:
|
|
247
|
+
const auth = createAuth({ secret: process.env.ENCRYPTION_KEY });
|
|
240
248
|
|
|
241
249
|
const Product = mongoose.model('Product', new mongoose.Schema({
|
|
242
250
|
name: String, price: Number, stock: { type: Number, default: 0 }
|
|
@@ -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) प्राइभेट सब्सक्राइब
|
|
@@ -860,6 +894,7 @@ app.use(async (ctx, next) => {
|
|
|
860
894
|
|
|
861
895
|
२०. Frontend सँग जोड्ने (React & Dolphin Client v2.0)
|
|
862
896
|
फ्रन्टइन्डबाट Dolphin API र Realtime प्रयोग गर्न अहिलेको सबैभन्दा सजिलो र शक्तिशाली तरिका 'Dolphin Client V2.0' प्रयोग गर्नु हो। यसले Auth, API, र Realtime लाई एउटै अबजेक्टमा समेट्छ।
|
|
897
|
+
Dolphin v2.2 बाट नयाँ **Dynamic Proxy API** थपिएको छ, जसले API कललाई अझ सजिलो बनाउँछ।
|
|
863
898
|
|
|
864
899
|
React (Vite) मा Dolphin Client प्रयोग गर्ने उदाहरण:
|
|
865
900
|
|
|
@@ -885,9 +920,14 @@ function Dashboard() {
|
|
|
885
920
|
// १. सर्भरसँग कनेक्ट गर्ने
|
|
886
921
|
await dolphin.connect();
|
|
887
922
|
|
|
888
|
-
// २.
|
|
889
|
-
//
|
|
890
|
-
const products = await dolphin.api.products();
|
|
923
|
+
// २. Dynamic Proxy API (New v2.2)
|
|
924
|
+
// यसले 'products' प्रोपर्टीलाई अटोमेटिक /products URL मा म्याप गर्छ
|
|
925
|
+
const products = await dolphin.api.products();
|
|
926
|
+
|
|
927
|
+
// Nested paths र Methods पनि सजिलै चलाउन सकिन्छ
|
|
928
|
+
const profile = await dolphin.api.users.profile(); // GET /users/profile
|
|
929
|
+
await dolphin.api.products.post({ name: "New Product" }); // POST /products
|
|
930
|
+
|
|
891
931
|
await dolphin.api.call.get(); // Handles keywords correctly!
|
|
892
932
|
|
|
893
933
|
// ३. High-Frequency Data प्राप्त गर्ने
|
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,9 @@
|
|
|
1
|
-
# 🐬 Dolphin Framework (v2.2.
|
|
1
|
+
# 🐬 Dolphin Framework (v2.2.5)
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
2
7
|
|
|
3
8
|
**Dolphin** is a 2026-ready, ultra-lightweight, and 100% modular backend ecosystem built on native Node.js. It's not just a framework; it's a universal toolkit for Web, Microservices, and Industrial IoT.
|
|
4
9
|
|
|
@@ -20,8 +25,8 @@ Dolphin Framework को विस्तृत र आधिकारिक ग
|
|
|
20
25
|
- **Universal Compatibility**: Works with Mongoose, Zod, WebSocket, and Express-compatible middleware.
|
|
21
26
|
- **Multi-Handler Middleware**: Support for Express-style middleware chains `(ctx, next)`.
|
|
22
27
|
- **Auto-JSON Serialization**: Simply `return` an object from your handler!
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
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.
|
|
25
30
|
- **Server-Served Client Library**: Zero-dependency frontend library for API, Auth, and Realtime—directly from your server.
|
|
26
31
|
|
|
27
32
|
---
|
|
@@ -31,9 +36,22 @@ Dolphin Framework को विस्तृत र आधिकारिक ग
|
|
|
31
36
|
npm install dolphin-server-modules
|
|
32
37
|
```
|
|
33
38
|
|
|
39
|
+
### 🛠️ CLI Usage (v2.2.5)
|
|
40
|
+
Bootstrap a new project or run a server instantly:
|
|
41
|
+
```bash
|
|
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
|
|
50
|
+
```
|
|
51
|
+
|
|
34
52
|
---
|
|
35
53
|
|
|
36
|
-
## 🚀 Quick Start
|
|
54
|
+
## 🚀 Quick Start (Modern ESM)
|
|
37
55
|
|
|
38
56
|
### 1. High-Performance Web Server
|
|
39
57
|
```typescript
|
|
@@ -42,106 +60,58 @@ import { createDolphinServer } from 'dolphin-server-modules/server';
|
|
|
42
60
|
const app = createDolphinServer();
|
|
43
61
|
|
|
44
62
|
app.get('/ping', (ctx) => {
|
|
45
|
-
return { message: 'pong', version: '
|
|
63
|
+
return { message: 'pong', version: '2.2.5' };
|
|
46
64
|
});
|
|
47
65
|
|
|
48
66
|
app.listen(3000, () => console.log("🐬 Dolphin swimming on port 3000"));
|
|
49
67
|
```
|
|
50
68
|
|
|
51
|
-
### 2.
|
|
52
|
-
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.
|
|
53
71
|
|
|
54
72
|
```html
|
|
55
|
-
<!--
|
|
73
|
+
<!-- index.html -->
|
|
56
74
|
<script src="/dolphin-client.js"></script>
|
|
57
75
|
|
|
58
76
|
<script>
|
|
59
77
|
async function init() {
|
|
60
|
-
// 1.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// 2. API with Dynamic Proxy (New in v2.2)
|
|
64
|
-
const products = await dolphin.api.products();
|
|
65
|
-
const profile = await dolphin.api.users.profile();
|
|
66
|
-
await dolphin.api.products.post({ name: "Dolphin" });
|
|
67
|
-
await dolphin.api.call.get(); // Smart proxy handles reserved keywords like 'call' or 'apply'
|
|
68
|
-
|
|
69
|
-
// 3. Advanced Realtime (v2.2)
|
|
70
|
-
await dolphin.connect();
|
|
71
|
-
|
|
72
|
-
// Subscribe with cleanup support
|
|
73
|
-
const onTemp = (val) => console.log(val);
|
|
74
|
-
dolphin.subscribe('sensors/temp', onTemp);
|
|
75
|
-
// ... later
|
|
76
|
-
dolphin.unsubscribe('sensors/temp', onTemp);
|
|
77
|
-
|
|
78
|
-
// High-frequency data (30,000+ msgs/sec)
|
|
79
|
-
dolphin.pubPush('sensors/temp', { val: 24.5 });
|
|
80
|
-
|
|
81
|
-
// Demand-based pulling (Data saving)
|
|
82
|
-
dolphin.subscribe('pull:response/logs', (history) => console.log(history));
|
|
83
|
-
dolphin.subPull('logs', 50);
|
|
84
|
-
|
|
85
|
-
// Chunked File Transfer with Resume support
|
|
86
|
-
dolphin.subscribe('file:chunk/map-data', (chunk) => {
|
|
87
|
-
console.log(`Downloaded ${chunk.chunkIndex}/${chunk.totalChunks}`);
|
|
88
|
-
});
|
|
89
|
-
dolphin.subFile('map-data');
|
|
90
|
-
}
|
|
91
|
-
</script>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### 3. Full CRUD API with Mongoose (v1.7.0)
|
|
95
|
-
|
|
96
|
-
> **Important:** Use `enforceOwnership: false` for public APIs (no auth required).
|
|
97
|
-
> Default is `true` — requires `userId` from auth middleware.
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { createDolphinServer } from 'dolphin-server-modules/server';
|
|
101
|
-
import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
|
|
102
|
-
import { createCRUD } from 'dolphin-server-modules/crud';
|
|
103
|
-
import mongoose from 'mongoose';
|
|
104
|
-
|
|
105
|
-
// 1. Connect MongoDB
|
|
106
|
-
await mongoose.connect(process.env.MONGO_URI!);
|
|
78
|
+
// 1. Setup Collection
|
|
79
|
+
const products = dolphin.store.products;
|
|
107
80
|
|
|
108
|
-
// 2.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}));
|
|
81
|
+
// 2. State Tracking (Reactive)
|
|
82
|
+
if (products.loading) console.log("Loading products...");
|
|
83
|
+
if (products.error) console.log("Error:", products.error);
|
|
112
84
|
|
|
113
|
-
// 3.
|
|
114
|
-
|
|
115
|
-
|
|
85
|
+
// 3. Powerful Filtering & Sorting (Local & Reactive)
|
|
86
|
+
products
|
|
87
|
+
.where(p => p.price > 100)
|
|
88
|
+
.orderBy('name', 'asc');
|
|
116
89
|
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
app.get('/products', async (ctx) => ctx.json(await crud.read('Product')));
|
|
121
|
-
app.get('/products/:id', async (ctx) => {
|
|
122
|
-
const item = await crud.readOne('Product', ctx.params.id);
|
|
123
|
-
if (!item) return ctx.status(404).json({ error: 'Not Found' });
|
|
124
|
-
ctx.json(item);
|
|
125
|
-
});
|
|
126
|
-
app.post('/products', async (ctx) => ctx.status(201).json(await crud.create('Product', ctx.body)));
|
|
127
|
-
app.put('/products/:id', async (ctx) => ctx.json(await crud.updateOne('Product', ctx.params.id, ctx.body)));
|
|
128
|
-
app.delete('/products/:id', async (ctx) => ctx.json(await crud.deleteOne('Product', ctx.params.id)));
|
|
90
|
+
// items array always reflects current filter/sort + realtime updates
|
|
91
|
+
console.log(products.items);
|
|
129
92
|
|
|
130
|
-
|
|
93
|
+
// 4. Offline Persistence (Optional Plugin)
|
|
94
|
+
// Add dolphin-persist.js for offline cache
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
131
97
|
```
|
|
132
98
|
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
import { RealtimeCore } from 'dolphin-server-modules/realtime';
|
|
136
|
-
import { ModbusPlugin, HL7Plugin } from 'dolphin-server-modules/realtime/plugins';
|
|
99
|
+
---
|
|
137
100
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
rt.use(HL7Plugin);
|
|
101
|
+
## 🧩 DolphinPersist - Offline Caching
|
|
102
|
+
Include `dolphin-persist.js` to enable zero-config offline support for your store.
|
|
141
103
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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>
|
|
145
115
|
```
|
|
146
116
|
|
|
147
117
|
---
|
|
@@ -150,71 +120,28 @@ rt.subscribe('factory/machine/+', (data) => {
|
|
|
150
120
|
|
|
151
121
|
| Module | Path | Description |
|
|
152
122
|
| :--- | :--- | :--- |
|
|
153
|
-
| **Server** |
|
|
154
|
-
| **Router** |
|
|
155
|
-
| **Auth** |
|
|
156
|
-
| **CRUD** |
|
|
157
|
-
| **Auth Controller** |
|
|
158
|
-
| **Realtime** |
|
|
159
|
-
| **Validation** |
|
|
160
|
-
| **Swagger Docs** |
|
|
161
|
-
| **IoT Plugins** |
|
|
162
|
-
| **Signaling** |
|
|
163
|
-
| **Mongoose Adapter** |
|
|
164
|
-
| **Client Lib** | `/dolphin-client.js` | Zero-dependency full-stack JS client (
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
|
-
## ⚠️ Important: `enforceOwnership` Option
|
|
169
|
-
|
|
170
|
-
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`:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
// Public API — no auth needed
|
|
174
|
-
const crud = createCRUD(db, { enforceOwnership: false });
|
|
175
|
-
|
|
176
|
-
// Protected API — requires auth middleware to set ctx.req.user
|
|
177
|
-
const crud = createCRUD(db, { enforceOwnership: true });
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
---
|
|
181
|
-
|
|
182
|
-
## 🛣️ Advanced Middleware & Sub-Routing
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
import { createDolphinRouter } from 'dolphin-server-modules/router';
|
|
186
|
-
import { createDolphinAuthController } from 'dolphin-server-modules/auth-controller';
|
|
187
|
-
|
|
188
|
-
const auth = createDolphinAuthController(db, config);
|
|
189
|
-
const apiV1 = createDolphinRouter();
|
|
190
|
-
|
|
191
|
-
// Multi-handler: middleware + route handler
|
|
192
|
-
apiV1.get('/me', auth.requireAuth, async (ctx) => {
|
|
193
|
-
return { user: ctx.req.user };
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const mainApp = createDolphinServer();
|
|
197
|
-
mainApp.use('/api/v1', apiV1);
|
|
198
|
-
```
|
|
123
|
+
| **Server** | `dolphin-server-modules/server` | Native HTTP server with `ctx` API & Auto-JSON. |
|
|
124
|
+
| **Router** | `dolphin-server-modules/router` | Standalone sub-routers with multi-handler support. |
|
|
125
|
+
| **Auth** | `dolphin-server-modules/auth` | Argon2/JWT based secure auth with 2FA (TOTP). |
|
|
126
|
+
| **CRUD** | `dolphin-server-modules/curd` | Generic CRUD service with ownership & soft-delete. |
|
|
127
|
+
| **Auth Controller** | `dolphin-server-modules/auth-controller` | Pre-built auth routes (register, login, refresh). |
|
|
128
|
+
| **Realtime** | `dolphin-server-modules/realtime` | Pub/Sub engine with `TopicTrie` & binary codecs. |
|
|
129
|
+
| **Validation** | `dolphin-server-modules/middleware/zod` | Type-safe Zod validation middleware. |
|
|
130
|
+
| **Swagger Docs** | `dolphin-server-modules/swagger` | Auto-generated OpenAPI docs from Zod schemas. |
|
|
131
|
+
| **IoT Plugins** | `dolphin-server-modules/realtime/plugins` | Native parsers for HL7, Modbus, and DICOM. |
|
|
132
|
+
| **Signaling** | `dolphin-server-modules/signaling` | Universal WebRTC & Control Signaling module. |
|
|
133
|
+
| **Mongoose Adapter** | `dolphin-server-modules/adapters/mongoose` | Full Mongoose ↔ CRUD bridge with query mapping. |
|
|
134
|
+
| **Client Lib** | `/dolphin-client.js` | Zero-dependency full-stack JS client. Includes **Reactive Store (DolphinStore)** with filter/sort and loading states. |
|
|
199
135
|
|
|
200
136
|
---
|
|
201
137
|
|
|
202
138
|
## 🧪 Testing
|
|
203
|
-
|
|
204
139
|
The project uses **Jest** with **ts-jest**. Integration tests use `mongodb-memory-server` for real Mongoose testing without an external database.
|
|
205
140
|
|
|
206
141
|
```bash
|
|
207
|
-
npm test # Run all
|
|
142
|
+
npm test # Run all 200+ tests
|
|
208
143
|
```
|
|
209
144
|
|
|
210
|
-
| Suite | Tests |
|
|
211
|
-
| :--- | :--- |
|
|
212
|
-
| `adapters/mongoose/integration.test.ts` | 23 (real Mongoose) |
|
|
213
|
-
| `adapters/mongoose/index.test.ts` | 7 |
|
|
214
|
-
| `auth/auth.test.ts` | — |
|
|
215
|
-
| `curd/crud.test.ts` | — |
|
|
216
|
-
| + 8 more suites | — |
|
|
217
|
-
|
|
218
145
|
---
|
|
219
146
|
|
|
220
147
|
## 📊 2026 Performance Benchmarks
|
|
@@ -223,7 +150,7 @@ npm test # Run all 167 tests (12 suites)
|
|
|
223
150
|
| :--- | :--- | :--- | :--- |
|
|
224
151
|
| Express.js | ~15,000 | 180ms | N/A |
|
|
225
152
|
| Fastify | ~35,000 | 90ms | ~10,000 msgs/sec |
|
|
226
|
-
| **Dolphin V2** | **45,000+** | **< 10ms** | **35,000+ msgs/sec** |
|
|
153
|
+
| **Dolphin V2.2** | **45,000+** | **< 10ms** | **35,000+ msgs/sec** |
|
|
227
154
|
|
|
228
155
|
---
|
|
229
156
|
|
|
@@ -235,7 +162,11 @@ npm test # Run all 167 tests (12 suites)
|
|
|
235
162
|
- [x] Auto-JSON: Return objects directly from handlers
|
|
236
163
|
- [x] Real Mongoose adapter with `$like`, `id→_id` query mapping
|
|
237
164
|
- [x] Integration test suite with `mongodb-memory-server`
|
|
238
|
-
- [
|
|
165
|
+
- [x] **Server-Served Client Library**: `/dolphin-client.js` auto-serve
|
|
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
|
|
239
170
|
|
|
240
171
|
---
|
|
241
172
|
|