@objectstack/runtime 0.6.0 → 0.7.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/CHANGELOG.md +20 -0
- package/README.md +10 -8
- package/dist/app-plugin.d.ts +18 -0
- package/dist/app-plugin.js +80 -0
- package/dist/driver-plugin.js +6 -2
- package/dist/http-server.d.ts +84 -0
- package/dist/http-server.js +125 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +7 -5
- package/dist/middleware.d.ts +111 -0
- package/dist/middleware.js +176 -0
- package/dist/rest-server.d.ts +74 -0
- package/dist/rest-server.js +490 -0
- package/dist/route-manager.d.ts +153 -0
- package/dist/route-manager.js +251 -0
- package/package.json +4 -5
- package/src/app-plugin.ts +100 -0
- package/src/driver-plugin.ts +6 -2
- package/src/http-server.ts +140 -0
- package/src/index.ts +9 -6
- package/src/middleware.ts +220 -0
- package/src/rest-server.ts +579 -0
- package/src/route-manager.ts +305 -0
- package/dist/app-manifest-plugin.d.ts +0 -19
- package/dist/app-manifest-plugin.js +0 -33
- package/dist/test-interfaces.d.ts +0 -7
- package/dist/test-interfaces.js +0 -138
- package/src/app-manifest-plugin.ts +0 -48
- package/src/test-interfaces.ts +0 -170
package/src/test-interfaces.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test file to verify capability contract interfaces
|
|
3
|
-
*
|
|
4
|
-
* This file demonstrates how plugins can implement the IHttpServer
|
|
5
|
-
* and IDataEngine interfaces without depending on concrete implementations.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { IHttpServer, IDataEngine, RouteHandler, IHttpRequest, IHttpResponse, Middleware, DataEngineQueryOptions } from './index.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Example: Mock HTTP Server Plugin
|
|
12
|
-
*
|
|
13
|
-
* Shows how a plugin can implement the IHttpServer interface
|
|
14
|
-
* without depending on Express, Fastify, or any specific framework.
|
|
15
|
-
*/
|
|
16
|
-
class MockHttpServer implements IHttpServer {
|
|
17
|
-
private routes: Map<string, { method: string; handler: RouteHandler }> = new Map();
|
|
18
|
-
|
|
19
|
-
get(path: string, handler: RouteHandler): void {
|
|
20
|
-
this.routes.set(`GET:${path}`, { method: 'GET', handler });
|
|
21
|
-
console.log(`✅ Registered GET ${path}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
post(path: string, handler: RouteHandler): void {
|
|
25
|
-
this.routes.set(`POST:${path}`, { method: 'POST', handler });
|
|
26
|
-
console.log(`✅ Registered POST ${path}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
put(path: string, handler: RouteHandler): void {
|
|
30
|
-
this.routes.set(`PUT:${path}`, { method: 'PUT', handler });
|
|
31
|
-
console.log(`✅ Registered PUT ${path}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
delete(path: string, handler: RouteHandler): void {
|
|
35
|
-
this.routes.set(`DELETE:${path}`, { method: 'DELETE', handler });
|
|
36
|
-
console.log(`✅ Registered DELETE ${path}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
patch(path: string, handler: RouteHandler): void {
|
|
40
|
-
this.routes.set(`PATCH:${path}`, { method: 'PATCH', handler });
|
|
41
|
-
console.log(`✅ Registered PATCH ${path}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
use(path: string | Middleware, handler?: Middleware): void {
|
|
45
|
-
console.log(`✅ Registered middleware`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async listen(port: number): Promise<void> {
|
|
49
|
-
console.log(`✅ Mock HTTP server listening on port ${port}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async close(): Promise<void> {
|
|
53
|
-
console.log(`✅ Mock HTTP server closed`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Example: Mock Data Engine Plugin
|
|
59
|
-
*
|
|
60
|
-
* Shows how a plugin can implement the IDataEngine interface
|
|
61
|
-
* without depending on ObjectQL, Prisma, or any specific database.
|
|
62
|
-
*/
|
|
63
|
-
class MockDataEngine implements IDataEngine {
|
|
64
|
-
private store: Map<string, Map<string, any>> = new Map();
|
|
65
|
-
private idCounter = 0;
|
|
66
|
-
|
|
67
|
-
async insert(objectName: string, data: any): Promise<any> {
|
|
68
|
-
if (!this.store.has(objectName)) {
|
|
69
|
-
this.store.set(objectName, new Map());
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const id = `${objectName}_${++this.idCounter}`;
|
|
73
|
-
const record = { id, ...data };
|
|
74
|
-
this.store.get(objectName)!.set(id, record);
|
|
75
|
-
|
|
76
|
-
console.log(`✅ Inserted into ${objectName}:`, record);
|
|
77
|
-
return record;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async find(objectName: string, query?: DataEngineQueryOptions): Promise<any[]> {
|
|
81
|
-
const objectStore = this.store.get(objectName);
|
|
82
|
-
if (!objectStore) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const results = Array.from(objectStore.values());
|
|
87
|
-
console.log(`✅ Found ${results.length} records in ${objectName}`);
|
|
88
|
-
return results;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async update(objectName: string, id: any, data: any): Promise<any> {
|
|
92
|
-
const objectStore = this.store.get(objectName);
|
|
93
|
-
if (!objectStore || !objectStore.has(id)) {
|
|
94
|
-
throw new Error(`Record ${id} not found in ${objectName}`);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const existing = objectStore.get(id);
|
|
98
|
-
const updated = { ...existing, ...data };
|
|
99
|
-
objectStore.set(id, updated);
|
|
100
|
-
|
|
101
|
-
console.log(`✅ Updated ${objectName}/${id}:`, updated);
|
|
102
|
-
return updated;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async delete(objectName: string, id: any): Promise<boolean> {
|
|
106
|
-
const objectStore = this.store.get(objectName);
|
|
107
|
-
if (!objectStore) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const deleted = objectStore.delete(id);
|
|
112
|
-
console.log(`✅ Deleted ${objectName}/${id}: ${deleted}`);
|
|
113
|
-
return deleted;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Test the interfaces
|
|
119
|
-
*/
|
|
120
|
-
async function testInterfaces() {
|
|
121
|
-
console.log('\n=== Testing IHttpServer Interface ===\n');
|
|
122
|
-
|
|
123
|
-
const httpServer: IHttpServer = new MockHttpServer();
|
|
124
|
-
|
|
125
|
-
// Register routes using the interface
|
|
126
|
-
httpServer.get('/api/users', async (req, res) => {
|
|
127
|
-
res.json({ users: [] });
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
httpServer.post('/api/users', async (req, res) => {
|
|
131
|
-
res.status(201).json({ id: 1, ...req.body });
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
await httpServer.listen(3000);
|
|
135
|
-
|
|
136
|
-
console.log('\n=== Testing IDataEngine Interface ===\n');
|
|
137
|
-
|
|
138
|
-
const dataEngine: IDataEngine = new MockDataEngine();
|
|
139
|
-
|
|
140
|
-
// Use the data engine interface
|
|
141
|
-
const user1 = await dataEngine.insert('user', {
|
|
142
|
-
name: 'John Doe',
|
|
143
|
-
email: 'john@example.com'
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const user2 = await dataEngine.insert('user', {
|
|
147
|
-
name: 'Jane Smith',
|
|
148
|
-
email: 'jane@example.com'
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const users = await dataEngine.find('user');
|
|
152
|
-
console.log(`Found ${users.length} users after inserts`);
|
|
153
|
-
|
|
154
|
-
const updatedUser = await dataEngine.update('user', user1.id, {
|
|
155
|
-
name: 'John Updated'
|
|
156
|
-
});
|
|
157
|
-
console.log(`Updated user:`, updatedUser);
|
|
158
|
-
|
|
159
|
-
const deleted = await dataEngine.delete('user', user2.id);
|
|
160
|
-
console.log(`Delete result: ${deleted}`);
|
|
161
|
-
|
|
162
|
-
console.log('\n✅ All interface tests passed!\n');
|
|
163
|
-
|
|
164
|
-
if (httpServer.close) {
|
|
165
|
-
await httpServer.close();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Run tests
|
|
170
|
-
testInterfaces().catch(console.error);
|