dolphin-server-modules 2.10.0 → 2.11.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/dist/adapters/mongoose/index.d.ts +4 -4
- package/dist/adapters/mongoose/index.js.map +1 -1
- package/dist/ai/dolphin-agent/agent.js +13 -2
- package/dist/ai/dolphin-agent/agent.js.map +1 -1
- package/dist/ai/dolphin-agent/config.js +37 -39
- package/dist/ai/dolphin-agent/config.js.map +1 -1
- package/dist/authController/authController.js +1 -1
- package/dist/authController/authController.js.map +1 -1
- package/dist/bin/cli.js +45 -78
- package/dist/bin/cli.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/realtime/core.d.ts +5 -5
- package/dist/realtime/core.js +6 -6
- package/dist/realtime/core.js.map +1 -1
- package/dist/realtime/index.d.ts +4 -4
- package/dist/realtime/index.js +4 -4
- package/dist/realtime/index.js.map +1 -1
- package/dist/server/server.d.ts +8 -8
- package/dist/server/server.js +11 -2
- package/dist/server/server.js.map +1 -1
- package/dist/signaling/index.d.ts +1 -1
- package/dist/swagger/swagger.js +31 -31
- package/dist/templates/index.js +102 -102
- package/package.json +65 -144
- package/scripts/benchmark.js +12 -0
- package/scripts/benchmark.ts +12 -0
- package/scripts/list-models.js +34 -0
- package/scripts/run-real-ai-test.js +79 -0
- package/scripts/test-ai-logic.js +44 -0
- package/scripts/test-client.js +105 -0
- package/scripts/test-dolphin.js +36 -0
- package/TUTORIAL_NEPALI.md +0 -181
package/package.json
CHANGED
|
@@ -1,144 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dolphin-server-modules",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"homepage": "https://github.com/Phuyalshankar/dolphin-server-modules#readme",
|
|
6
|
-
"description": "Core utility modules for Auth, CRUD, and Controllers",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"dist"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
"./realtime/core": {
|
|
68
|
-
"types": "./dist/realtime/core.d.ts",
|
|
69
|
-
"default": "./dist/realtime/core.js"
|
|
70
|
-
},
|
|
71
|
-
"./realtime/trie": {
|
|
72
|
-
"types": "./dist/realtime/trie.d.ts",
|
|
73
|
-
"default": "./dist/realtime/trie.js"
|
|
74
|
-
},
|
|
75
|
-
"./realtime/codec": {
|
|
76
|
-
"types": "./dist/realtime/codec.d.ts",
|
|
77
|
-
"default": "./dist/realtime/codec.js"
|
|
78
|
-
},
|
|
79
|
-
"./realtime/plugins": {
|
|
80
|
-
"types": "./dist/realtime/plugins.d.ts",
|
|
81
|
-
"default": "./dist/realtime/plugins.js"
|
|
82
|
-
},
|
|
83
|
-
"./swagger": {
|
|
84
|
-
"types": "./dist/swagger/swagger.d.ts",
|
|
85
|
-
"default": "./dist/swagger/swagger.js"
|
|
86
|
-
},
|
|
87
|
-
"./djson": {
|
|
88
|
-
"types": "./dist/djson/djson.d.ts",
|
|
89
|
-
"default": "./dist/djson/djson.js"
|
|
90
|
-
},
|
|
91
|
-
"./signaling": {
|
|
92
|
-
"types": "./dist/signaling/index.d.ts",
|
|
93
|
-
"default": "./dist/signaling/index.js"
|
|
94
|
-
},
|
|
95
|
-
"./cli": "./dist/bin/cli.js",
|
|
96
|
-
"./client": "./scripts/client.js"
|
|
97
|
-
},
|
|
98
|
-
"scripts": {
|
|
99
|
-
"build": "tsc",
|
|
100
|
-
"start": "node dist/demo-server.js",
|
|
101
|
-
"dolphin": "node dist/bin/cli.js",
|
|
102
|
-
"dev": "npm run build && npm run start",
|
|
103
|
-
"test": "jest",
|
|
104
|
-
"prepublishOnly": "npm run build"
|
|
105
|
-
},
|
|
106
|
-
"keywords": [
|
|
107
|
-
"dolphin",
|
|
108
|
-
"server",
|
|
109
|
-
"auth",
|
|
110
|
-
"crud",
|
|
111
|
-
"controller",
|
|
112
|
-
"realtime",
|
|
113
|
-
"iot",
|
|
114
|
-
"2fa",
|
|
115
|
-
"jwt"
|
|
116
|
-
],
|
|
117
|
-
"author": "Shankar Phuyal",
|
|
118
|
-
"license": "ISC",
|
|
119
|
-
"dependencies": {
|
|
120
|
-
"argon2": "^0.40.1",
|
|
121
|
-
"ioredis": "^5.10.1",
|
|
122
|
-
"jsonwebtoken": "^9.0.3",
|
|
123
|
-
"mongodb-memory-server": "^11.0.1",
|
|
124
|
-
"ws": "^8.20.0",
|
|
125
|
-
"zod": "^4.3.6"
|
|
126
|
-
},
|
|
127
|
-
"devDependencies": {
|
|
128
|
-
"@types/jest": "^29.5.12",
|
|
129
|
-
"@types/jsonwebtoken": "^9.0.10",
|
|
130
|
-
"@types/node": "^20.11.30",
|
|
131
|
-
"@types/ws": "^8.18.1",
|
|
132
|
-
"jest": "^29.7.0",
|
|
133
|
-
"mongoose": "^9.3.2",
|
|
134
|
-
"ts-jest": "^29.1.2",
|
|
135
|
-
"typescript": "^5.4.3"
|
|
136
|
-
},
|
|
137
|
-
"repository": {
|
|
138
|
-
"type": "git",
|
|
139
|
-
"url": "git+https://github.com/Phuyalshankar/dolphin-server-modules.git"
|
|
140
|
-
},
|
|
141
|
-
"bugs": {
|
|
142
|
-
"url": "https://github.com/Phuyalshankar/dolphin-server-modules/issues"
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dolphin-server-modules",
|
|
3
|
+
"version": "2.11.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"homepage": "https://github.com/Phuyalshankar/dolphin-server-modules#readme",
|
|
6
|
+
"description": "Core utility modules for Auth, CRUD, and Controllers",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./server": "./dist/server/server.js",
|
|
11
|
+
"./router": "./dist/router/router.js",
|
|
12
|
+
"./adapters/mongoose": "./dist/adapters/mongoose/index.js",
|
|
13
|
+
"./auth-controller": "./dist/authController/authController.js",
|
|
14
|
+
"./crud": "./dist/curd/crud.js"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"dolphin": "dist/bin/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"scripts",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"DOLPHIN_MASTER_GUIDE_NEPALI.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc",
|
|
28
|
+
"dev": "tsc -w",
|
|
29
|
+
"test": "jest"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"dolphin",
|
|
33
|
+
"framework",
|
|
34
|
+
"server",
|
|
35
|
+
"auth",
|
|
36
|
+
"crud"
|
|
37
|
+
],
|
|
38
|
+
"author": "Phuyal Shankar",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@google/generative-ai": "^0.11.0",
|
|
42
|
+
"chalk": "^5.3.0",
|
|
43
|
+
"dotenv": "^16.4.5",
|
|
44
|
+
"express": "^4.19.2",
|
|
45
|
+
"mongoose": "^8.3.4",
|
|
46
|
+
"node-fetch": "^3.3.2",
|
|
47
|
+
"ora": "^8.0.1",
|
|
48
|
+
"ws": "^8.20.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/express": "^4.17.21",
|
|
52
|
+
"@types/ioredis": "^4.28.10",
|
|
53
|
+
"@types/jest": "^29.5.14",
|
|
54
|
+
"@types/node": "^20.12.11",
|
|
55
|
+
"@types/supertest": "^7.2.0",
|
|
56
|
+
"@types/ws": "^8.18.1",
|
|
57
|
+
"ioredis": "^5.10.1",
|
|
58
|
+
"jest": "^29.7.0",
|
|
59
|
+
"mongodb-memory-server": "^11.0.1",
|
|
60
|
+
"supertest": "^7.2.2",
|
|
61
|
+
"ts-jest": "^29.4.9",
|
|
62
|
+
"ts-node": "^10.9.2",
|
|
63
|
+
"typescript": "^5.4.5"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { createDolphinServer } = require('../dist/server/server');
|
|
2
|
+
|
|
3
|
+
const app = createDolphinServer();
|
|
4
|
+
|
|
5
|
+
app.get('/health', (ctx) => {
|
|
6
|
+
ctx.json({ status: 'ok' });
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const PORT = 5008;
|
|
10
|
+
app.listen(PORT, () => {
|
|
11
|
+
console.log(`Benchmark server running on port ${PORT}`);
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createDolphinServer } from '../src/server/server';
|
|
2
|
+
|
|
3
|
+
const app = createDolphinServer();
|
|
4
|
+
|
|
5
|
+
app.get('/health', (ctx: any) => {
|
|
6
|
+
ctx.json({ status: 'ok' });
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const PORT = 5002;
|
|
10
|
+
app.listen(PORT, () => {
|
|
11
|
+
console.log(`Benchmark server running on port ${PORT}`);
|
|
12
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🔍 Dolphin AI Diagnostic Tool
|
|
3
|
+
* यो स्क्रिप्टले तपाइँको API Key ले कुन-कुन मोडेलहरू एक्सेस गर्न सक्छ भनेर देखाउँछ।
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const https = require('https');
|
|
7
|
+
|
|
8
|
+
const API_KEY = process.env.GEMINI_API_KEY || "AIzaSyA3EFr62PEEXaIRpVfW_Qd2tYMu0jftj7Y";
|
|
9
|
+
const VERSION = "v1beta"; // सूची हेर्न प्राय: v1beta उत्तम हुन्छ
|
|
10
|
+
|
|
11
|
+
console.log(`📡 Fetching available models for your API Key...`);
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
hostname: 'generativelanguage.googleapis.com',
|
|
15
|
+
path: `/${VERSION}/models?key=${API_KEY}`,
|
|
16
|
+
method: 'GET'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const req = https.request(options, (res) => {
|
|
20
|
+
let body = '';
|
|
21
|
+
res.on('data', (d) => body += d);
|
|
22
|
+
res.on('end', () => {
|
|
23
|
+
const json = JSON.parse(body);
|
|
24
|
+
if (json.models) {
|
|
25
|
+
console.log('✅ Available Models:');
|
|
26
|
+
json.models.forEach(m => console.log(` - ${m.name.replace('models/', '')} (${m.supportedGenerationMethods.join(', ')})`));
|
|
27
|
+
} else {
|
|
28
|
+
console.error('❌ Error fetching models:', json);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
req.on('error', (e) => console.error('❌ Network Error:', e));
|
|
34
|
+
req.end();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚀 Dolphin Real AI Integration Test
|
|
3
|
+
* यो स्क्रिप्टले तपाइँको वास्तविक API Key प्रयोग गरेर
|
|
4
|
+
* Google Gemini बाट कोड मगाउँछ र 'ai-demo-result.js' मा लेख्छ।
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const https = require('https');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const API_KEY = process.env.GEMINI_API_KEY || "AIzaSyA3EFr62PEEXaIRpVfW_Qd2tYMu0jftj7Y";
|
|
12
|
+
const MODELS = ["gemini-flash-latest", "gemini-2.0-flash", "gemini-2.5-flash", "gemini-pro-latest"];
|
|
13
|
+
const VERSIONS = ["v1", "v1beta"];
|
|
14
|
+
|
|
15
|
+
const payload = JSON.stringify({
|
|
16
|
+
contents: [{ parts: [{ text: `Create a professional Dolphin Server app.
|
|
17
|
+
Context: Simple health check and system info.
|
|
18
|
+
Requirements:
|
|
19
|
+
1. Use ESM 'import' from 'dolphin-server-modules/server'.
|
|
20
|
+
2. Use 'createDolphinServer'.
|
|
21
|
+
3. Routes: GET '/health' (uptime) and GET '/info' (framework name).
|
|
22
|
+
4. Use unified context '(ctx) => ({ ... })'.
|
|
23
|
+
5. Include app.listen(3000).
|
|
24
|
+
Return ONLY the pure JavaScript code, no markdown, no explanations.`
|
|
25
|
+
}] }]
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const tryAI = (mIndex, vIndex) => {
|
|
29
|
+
if (mIndex >= MODELS.length) {
|
|
30
|
+
console.error('❌ All models failed. Ensure your API Key from https://aistudio.google.com/ is correct and has access to these models.');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (vIndex >= VERSIONS.length) {
|
|
35
|
+
return tryAI(mIndex + 1, 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const MODEL = MODELS[mIndex];
|
|
39
|
+
const VERSION = VERSIONS[vIndex];
|
|
40
|
+
console.log(`📡 Sending request to Gemini (${MODEL} via ${VERSION})...`);
|
|
41
|
+
|
|
42
|
+
const options = {
|
|
43
|
+
hostname: 'generativelanguage.googleapis.com',
|
|
44
|
+
path: `/${VERSION}/models/${MODEL}:generateContent?key=${API_KEY}`,
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'Content-Type': 'application/json' }
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const req = https.request(options, (res) => {
|
|
50
|
+
let body = '';
|
|
51
|
+
res.on('data', (d) => body += d);
|
|
52
|
+
res.on('end', () => {
|
|
53
|
+
try {
|
|
54
|
+
const json = JSON.parse(body);
|
|
55
|
+
if (json.error) {
|
|
56
|
+
console.warn(`⚠️ ${MODEL} (${VERSION}) failed: ${json.error.status}`);
|
|
57
|
+
return tryAI(mIndex, vIndex + 1);
|
|
58
|
+
}
|
|
59
|
+
const rawCode = json.candidates?.[0]?.content?.parts?.[0]?.text || '';
|
|
60
|
+
if (rawCode) {
|
|
61
|
+
const codeMatch = rawCode.match(/(import|const|let|var|app|function)[\s\S]*/);
|
|
62
|
+
const code = (codeMatch ? codeMatch[0] : rawCode).replace(/```javascript|```js|```/g, '').trim();
|
|
63
|
+
fs.writeFileSync(path.join(process.cwd(), 'ai-demo-result.js'), code);
|
|
64
|
+
console.log(`✅ Success! Code generated using ${MODEL} (${VERSION})`);
|
|
65
|
+
} else {
|
|
66
|
+
tryAI(mIndex, vIndex + 1);
|
|
67
|
+
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
tryAI(mIndex, vIndex + 1);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
req.on('error', (e) => tryAI(mIndex, vIndex + 1));
|
|
75
|
+
req.write(payload);
|
|
76
|
+
req.end();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
tryAI(0, 0);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🤖 Dolphin AI Logic Test
|
|
3
|
+
* यो स्क्रिप्टले AI बाट आएको कच्चा (raw) रेस्पोन्सलाई
|
|
4
|
+
* हाम्रो CLI ले कसरी सफा कोडमा बदल्छ भनेर जाँच्छ।
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
// Mock AI Response with Markdown backticks
|
|
11
|
+
const mockAiResponse = "```javascript\nconst { createDolphinServer } = require('dolphin-server-modules/server');\nconst app = createDolphinServer();\napp.get('/', (ctx) => ({ message: 'AI Works!' }));\napp.listen(3000);\n```";
|
|
12
|
+
|
|
13
|
+
function simulateParsing(rawText) {
|
|
14
|
+
// CLI.ts मा भएको रिप्लेस लजिक
|
|
15
|
+
return rawText.replace(/```javascript|```/g, '').trim();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function runTest() {
|
|
19
|
+
console.log('🧪 Running AI Logic Test...');
|
|
20
|
+
|
|
21
|
+
const cleanedCode = simulateParsing(mockAiResponse);
|
|
22
|
+
|
|
23
|
+
console.log('\n--- Cleaned Code Output ---');
|
|
24
|
+
console.log(cleanedCode);
|
|
25
|
+
console.log('---------------------------\n');
|
|
26
|
+
|
|
27
|
+
if (cleanedCode.includes('```') || cleanedCode.includes('javascript')) {
|
|
28
|
+
console.error('❌ FAIL: Markdown backticks are still present!');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!cleanedCode.includes('createDolphinServer')) {
|
|
33
|
+
console.error('❌ FAIL: Core code logic missing!');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log('✅ PASS: AI Response parsing logic is correct.');
|
|
38
|
+
|
|
39
|
+
// Test file creation
|
|
40
|
+
fs.writeFileSync(path.join(process.cwd(), 'ai-test-output.js'), cleanedCode);
|
|
41
|
+
console.log('✅ PASS: Simulated file written to ai-test-output.js');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
runTest();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dolphin Client Logic Test
|
|
3
|
+
* This script verifies the core logic of client.js without needing a real server.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { DolphinClient } = require('./client');
|
|
7
|
+
|
|
8
|
+
// --- Mocks ---
|
|
9
|
+
global.fetch = async (url, options) => {
|
|
10
|
+
console.log(`[Mock Fetch] ${options.method || 'GET'} ${url}`);
|
|
11
|
+
return {
|
|
12
|
+
ok: true,
|
|
13
|
+
headers: new Map([['content-type', 'application/json']]),
|
|
14
|
+
json: async () => ({ success: true, message: 'Mock response', data: { url, method: options.method } })
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
class MockWebSocket {
|
|
19
|
+
constructor(url) {
|
|
20
|
+
console.log(`[Mock WS] Connecting to ${url}`);
|
|
21
|
+
this.readyState = 1; // OPEN
|
|
22
|
+
setTimeout(() => this.onopen && this.onopen(), 10);
|
|
23
|
+
}
|
|
24
|
+
send(data) { console.log(`[Mock WS] Sending: ${data}`); }
|
|
25
|
+
close() { console.log(`[Mock WS] Closing`); }
|
|
26
|
+
}
|
|
27
|
+
global.WebSocket = MockWebSocket;
|
|
28
|
+
|
|
29
|
+
// Storage Mock
|
|
30
|
+
global.localStorage = {
|
|
31
|
+
getItem: () => null,
|
|
32
|
+
setItem: () => {},
|
|
33
|
+
removeItem: () => {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
async function runTests() {
|
|
37
|
+
console.log('--- Starting DolphinClient Tests ---');
|
|
38
|
+
|
|
39
|
+
// 1. Constructor & Protocol Test
|
|
40
|
+
console.log('\n[Test 1] Protocol Detection');
|
|
41
|
+
const c1 = new DolphinClient('https://api.example.com');
|
|
42
|
+
if (c1.httpUrl !== 'https://api.example.com') throw new Error(`Https protocol failed: ${c1.httpUrl}`);
|
|
43
|
+
|
|
44
|
+
const c2 = new DolphinClient('localhost:3000');
|
|
45
|
+
// Default should be http if not specified and not in browser
|
|
46
|
+
if (!c2.httpUrl.startsWith('http://')) throw new Error(`Default protocol failed: ${c2.httpUrl}`);
|
|
47
|
+
console.log('✅ Protocol detection passed');
|
|
48
|
+
|
|
49
|
+
// 2. API Proxy & Method Test
|
|
50
|
+
console.log('\n[Test 2] API Handler (Proxy & Methods)');
|
|
51
|
+
const dolphin = new DolphinClient('localhost:3000');
|
|
52
|
+
|
|
53
|
+
// Test direct get
|
|
54
|
+
await dolphin.api.get('/products');
|
|
55
|
+
|
|
56
|
+
// Test proxy path
|
|
57
|
+
// Under the hood, this calls this._createProxy(['users']).get()
|
|
58
|
+
await dolphin.api.users.get();
|
|
59
|
+
|
|
60
|
+
// Test post with body
|
|
61
|
+
await dolphin.api.post('/auth/login', { email: 'test@test.com' });
|
|
62
|
+
|
|
63
|
+
console.log('✅ API Proxy passed');
|
|
64
|
+
|
|
65
|
+
// 4. Clashing Property Test
|
|
66
|
+
console.log('\n[Test 4] Clashing Property Names (Function built-ins)');
|
|
67
|
+
try {
|
|
68
|
+
const callProp = dolphin.api.call;
|
|
69
|
+
const callType = typeof callProp;
|
|
70
|
+
console.log(`- Type of dolphin.api.call: ${callType}`);
|
|
71
|
+
|
|
72
|
+
// Since our proxy target is a function, typeof will be 'function'.
|
|
73
|
+
// To verify it's OUR proxy and not the built-in call, check for our methods.
|
|
74
|
+
const isOurProxy = typeof callProp.post === 'function';
|
|
75
|
+
console.log(`- Has .post() method: ${isOurProxy}`);
|
|
76
|
+
|
|
77
|
+
if (!isOurProxy) {
|
|
78
|
+
throw new Error(`Clashing property 'call' was not shadowed by our proxy.`);
|
|
79
|
+
}
|
|
80
|
+
console.log('✅ Clashing properties shadowed successfully');
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.log(`❌ Clashing property failed: ${e.message}`);
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 3. Subscription & Memory Cleanup Test
|
|
87
|
+
console.log('\n[Test 3] Subscriptions & Event Cleanup');
|
|
88
|
+
let callCount = 0;
|
|
89
|
+
const cb = () => callCount++;
|
|
90
|
+
|
|
91
|
+
dolphin.subscribe('test', cb);
|
|
92
|
+
if (!dolphin.handlers.has('test')) throw new Error('Subscribe failed');
|
|
93
|
+
|
|
94
|
+
dolphin.unsubscribe('test', cb);
|
|
95
|
+
if (dolphin.handlers.has('test')) throw new Error('Unsubscribe failed');
|
|
96
|
+
|
|
97
|
+
console.log('✅ Event management passed');
|
|
98
|
+
|
|
99
|
+
console.log('\n--- All Logic Tests Passed! 🐬 ---');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
runTests().catch(err => {
|
|
103
|
+
console.error('❌ Test Failed:', err);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { createDolphinServer } = require('../dist/server/server');
|
|
2
|
+
const http = require('node:http');
|
|
3
|
+
|
|
4
|
+
const app = createDolphinServer();
|
|
5
|
+
|
|
6
|
+
// Mock Express Middleware
|
|
7
|
+
app.use((req, res, next) => {
|
|
8
|
+
req.isExpress = true;
|
|
9
|
+
next();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
app.get('/test', (ctx) => {
|
|
13
|
+
ctx.json({
|
|
14
|
+
success: true,
|
|
15
|
+
isExpress: ctx.req.isExpress
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const PORT = 5005;
|
|
20
|
+
app.listen(PORT, () => {
|
|
21
|
+
console.log(`Test server running on port ${PORT}`);
|
|
22
|
+
|
|
23
|
+
// Make a request immediately
|
|
24
|
+
http.get(`http://127.0.0.1:${PORT}/test`, (res) => {
|
|
25
|
+
let data = '';
|
|
26
|
+
res.on('data', chunk => data += chunk);
|
|
27
|
+
res.on('end', () => {
|
|
28
|
+
console.log('STATUS:', res.statusCode);
|
|
29
|
+
console.log('BODY:', data);
|
|
30
|
+
process.exit(0);
|
|
31
|
+
});
|
|
32
|
+
}).on('error', (err) => {
|
|
33
|
+
console.error('Request Error:', err.message);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
36
|
+
});
|