Skip to content

Commit 2c874f3

Browse files
committed
feat(service-registry): add service registry documentation and enhance client SDK with analytics and hub management services
1 parent d4fe21b commit 2c874f3

10 files changed

Lines changed: 162 additions & 6 deletions

File tree

content/docs/references/system/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This section contains all protocol schemas for the system layer of ObjectStack.
2525
<Card href="./notification" title="Notification" description="Source: packages/spec/src/system/notification.zod.ts" />
2626
<Card href="./object-storage" title="Object Storage" description="Source: packages/spec/src/system/object-storage.zod.ts" />
2727
<Card href="./search-engine" title="Search Engine" description="Source: packages/spec/src/system/search-engine.zod.ts" />
28+
<Card href="./service-registry" title="Service Registry" description="Source: packages/spec/src/system/service-registry.zod.ts" />
2829
<Card href="./tracing" title="Tracing" description="Source: packages/spec/src/system/tracing.zod.ts" />
2930
<Card href="./translation" title="Translation" description="Source: packages/spec/src/system/translation.zod.ts" />
3031
<Card href="./worker" title="Worker" description="Source: packages/spec/src/system/worker.zod.ts" />

content/docs/references/system/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"notification",
1919
"object-storage",
2020
"search-engine",
21+
"service-registry",
2122
"tracing",
2223
"translation",
2324
"worker"

packages/client/src/index.ts

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,64 @@ export class ObjectStackClient {
208208
}
209209
};
210210

211+
/**
212+
* Analytics Services
213+
*/
214+
analytics = {
215+
query: async (payload: any) => {
216+
const route = this.getRoute('analytics');
217+
const res = await this.fetch(`${this.baseUrl}${route}/query`, {
218+
method: 'POST',
219+
body: JSON.stringify(payload)
220+
});
221+
return res.json();
222+
},
223+
meta: async (cube: string) => {
224+
const route = this.getRoute('analytics');
225+
const res = await this.fetch(`${this.baseUrl}${route}/meta/${cube}`);
226+
return res.json();
227+
},
228+
explain: async (payload: any) => {
229+
const route = this.getRoute('analytics');
230+
const res = await this.fetch(`${this.baseUrl}${route}/explain`, {
231+
method: 'POST',
232+
body: JSON.stringify(payload)
233+
});
234+
return res.json();
235+
}
236+
};
237+
238+
/**
239+
* Hub Management Services
240+
*/
241+
hub = {
242+
spaces: {
243+
list: async () => {
244+
const route = this.getRoute('hub');
245+
const res = await this.fetch(`${this.baseUrl}${route}/spaces`);
246+
return res.json();
247+
},
248+
create: async (payload: any) => {
249+
const route = this.getRoute('hub');
250+
const res = await this.fetch(`${this.baseUrl}${route}/spaces`, {
251+
method: 'POST',
252+
body: JSON.stringify(payload)
253+
});
254+
return res.json();
255+
}
256+
},
257+
plugins: {
258+
install: async (pkg: string, version?: string) => {
259+
const route = this.getRoute('hub');
260+
const res = await this.fetch(`${this.baseUrl}${route}/plugins/install`, {
261+
method: 'POST',
262+
body: JSON.stringify({ pkg, version })
263+
});
264+
return res.json();
265+
}
266+
}
267+
};
268+
211269
/**
212270
* Data Operations
213271
*/
@@ -443,15 +501,24 @@ export class ObjectStackClient {
443501

444502
/**
445503
* Get the conventional route path for a given API endpoint type
446-
* ObjectStack uses standard conventions: /api/v1/data, /api/v1/meta, /api/v1/ui
504+
* ObjectStack uses standard conventions: /api/v1/data, /api/v1/metadata, /api/v1/ui
447505
*/
448-
private getRoute(type: 'data' | 'metadata' | 'ui' | 'auth'): string {
449-
// Use conventional ObjectStack API paths
506+
private getRoute(type: 'data' | 'metadata' | 'ui' | 'auth' | 'analytics' | 'hub' | 'storage'): string {
507+
// 1. Use discovered routes if available
508+
if (this.discoveryInfo?.routes && (this.discoveryInfo.routes as any)[type]) {
509+
return (this.discoveryInfo.routes as any)[type];
510+
}
511+
512+
// 2. Fallback to conventions
513+
// Note: HttpDispatcher expects /metadata, not /meta
450514
const routeMap: Record<string, string> = {
451515
data: '/api/v1/data',
452-
metadata: '/api/v1/meta',
516+
metadata: '/api/v1/metadata',
453517
ui: '/api/v1/ui',
454-
auth: '/api/v1/auth'
518+
auth: '/api/v1/auth',
519+
analytics: '/api/v1/analytics',
520+
hub: '/api/v1/hub',
521+
storage: '/api/v1/storage'
455522
};
456523

457524
return routeMap[type] || `/api/v1/${type}`;

packages/runtime/src/http-dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ObjectKernel } from '@objectstack/core';
2-
import { CoreServiceName } from '@objectstack/spec/src/system/service-registry.zod';
2+
import { CoreServiceName } from '@objectstack/spec/system';
33

44
export interface HttpProtocolContext {
55
request: any;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$ref": "#/definitions/CoreServiceName",
3+
"definitions": {
4+
"CoreServiceName": {}
5+
},
6+
"$schema": "http://json-schema.org/draft-07/schema#"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$ref": "#/definitions/KernelServiceMap",
3+
"definitions": {
4+
"KernelServiceMap": {}
5+
},
6+
"$schema": "http://json-schema.org/draft-07/schema#"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$ref": "#/definitions/ServiceConfig",
3+
"definitions": {
4+
"ServiceConfig": {}
5+
},
6+
"$schema": "http://json-schema.org/draft-07/schema#"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$ref": "#/definitions/ServiceStatus",
3+
"definitions": {
4+
"ServiceStatus": {}
5+
},
6+
"$schema": "http://json-schema.org/draft-07/schema#"
7+
}

packages/spec/src/system/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ export * from './collaboration.zod';
3939
// Types
4040
export * from './types';
4141
export * from './service-registry.zod';
42+
export * from './service-registry.zod';

verify-refactor.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
import { ObjectKernel, ObjectRegistry } from './packages/objectql/src';
3+
import { CoreServiceName } from './packages/spec/src/system/service-registry.zod';
4+
import { HttpDispatcher } from './packages/runtime/src/http-dispatcher';
5+
import { ObjectStackClient } from './packages/client/src';
6+
7+
async function verify() {
8+
console.log("--- Verifying ObjectStack Components ---");
9+
10+
// 1. ObjectQL Engine & Registry
11+
console.log("\n1. Testing ObjectQL Engine Status:");
12+
const registry = new ObjectRegistry();
13+
const kernel = new ObjectKernel(registry);
14+
const status = kernel.getStatus();
15+
console.log("Kernel Status:", JSON.stringify(status, null, 2));
16+
17+
if (status.service !== CoreServiceName.data) {
18+
console.error("FAIL: Kernel service name mismatch.");
19+
} else {
20+
console.log("PASS: Kernel service name matches.");
21+
}
22+
23+
24+
// 2. Runtime Dispatcher
25+
console.log("\n2. Testing Runtime HttpDispatcher:");
26+
const dispatcher = new HttpDispatcher();
27+
const dataService = dispatcher.getService(CoreServiceName.data);
28+
const analyticsService = dispatcher.getService(CoreServiceName.analytics);
29+
30+
console.log(`Data Service URL: ${dataService?.url}`);
31+
console.log(`Analytics Service URL: ${analyticsService?.url}`);
32+
33+
if (dataService?.url && analyticsService?.url) {
34+
console.log("PASS: Services resolved correctly.");
35+
} else {
36+
console.error("FAIL: Service resolution failed.");
37+
}
38+
39+
// 3. Client SDK
40+
console.log("\n3. Testing Client SDK Structure:");
41+
const client = new ObjectStackClient({
42+
baseUrl: 'http://localhost:5000'
43+
});
44+
45+
if (typeof client.analytics === 'object' && typeof client.hub === 'object') {
46+
console.log("PASS: Client has 'analytics' and 'hub' namespaces.");
47+
if (typeof client.analytics.query === 'function' && typeof client.hub.spaces.list === 'function') {
48+
console.log("PASS: Client methods are functions.");
49+
} else {
50+
console.error("FAIL: Client methods are missing.");
51+
}
52+
} else {
53+
console.error("FAIL: Client missing namespaces.");
54+
}
55+
56+
}
57+
58+
verify().catch(console.error);

0 commit comments

Comments
 (0)