Skip to content

Commit 106d98f

Browse files
Copilothotlong
andcommitted
Address code review feedback - improve type safety and performance
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 4e57c9d commit 106d98f

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

packages/objectql/src/protocol.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
UpdateManyDataRequest,
99
DeleteManyDataRequest
1010
} from '@objectstack/spec/api';
11-
import type { MetadataCacheRequest, MetadataCacheResponse } from '@objectstack/spec/api';
11+
import type { MetadataCacheRequest, MetadataCacheResponse, ServiceInfo } from '@objectstack/spec/api';
1212

1313
// We import SchemaRegistry directly since this class lives in the same package
1414
import { SchemaRegistry } from './registry.js';
@@ -27,6 +27,27 @@ function simpleHash(str: string): string {
2727
return Math.abs(hash).toString(16);
2828
}
2929

30+
/**
31+
* Service Configuration for Discovery
32+
* Maps service names to their routes and plugin providers
33+
*/
34+
const SERVICE_CONFIG: Record<string, { route: string; plugin: string; capability?: string }> = {
35+
auth: { route: '/api/v1/auth', plugin: 'plugin-auth' },
36+
automation: { route: '/api/v1/automation', plugin: 'plugin-automation', capability: 'workflow' },
37+
cache: { route: '/api/v1/cache', plugin: 'plugin-redis' },
38+
queue: { route: '/api/v1/queue', plugin: 'plugin-bullmq' },
39+
job: { route: '/api/v1/jobs', plugin: 'job-scheduler' },
40+
ui: { route: '/api/v1/ui', plugin: 'ui-plugin' },
41+
workflow: { route: '/api/v1/workflow', plugin: 'plugin-workflow', capability: 'workflow' },
42+
realtime: { route: '/api/v1/realtime', plugin: 'plugin-realtime', capability: 'websockets' },
43+
notification: { route: '/api/v1/notifications', plugin: 'plugin-notifications', capability: 'notifications' },
44+
ai: { route: '/api/v1/ai', plugin: 'plugin-ai', capability: 'ai' },
45+
i18n: { route: '/api/v1/i18n', plugin: 'plugin-i18n', capability: 'i18n' },
46+
graphql: { route: '/graphql', plugin: 'plugin-graphql', capability: 'graphql' },
47+
'file-storage': { route: '/api/v1/storage', plugin: 'plugin-storage', capability: 'files' },
48+
search: { route: '/api/v1/search', plugin: 'plugin-search', capability: 'search' },
49+
};
50+
3051
export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
3152
private engine: IDataEngine;
3253
private getServicesRegistry?: () => Map<string, any>;
@@ -40,34 +61,16 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
4061
// Get registered services from kernel if available
4162
const registeredServices = this.getServicesRegistry ? this.getServicesRegistry() : new Map();
4263

43-
// Build dynamic service info
44-
const services: Record<string, any> = {
64+
// Build dynamic service info with proper typing
65+
const services: Record<string, ServiceInfo> = {
4566
// --- Kernel-provided (objectql is an example kernel implementation) ---
4667
metadata: { enabled: true, status: 'degraded' as const, route: '/api/meta', provider: 'objectql', message: 'In-memory registry only; DB persistence not yet implemented' },
4768
data: { enabled: true, status: 'available' as const, route: '/api/data', provider: 'objectql' },
4869
analytics: { enabled: true, status: 'available' as const, route: '/api/analytics', provider: 'objectql' },
4970
};
5071

51-
// Define service configuration for dynamic discovery
52-
const serviceConfig: Record<string, { route: string; plugin: string; capability?: string }> = {
53-
auth: { route: '/api/v1/auth', plugin: 'plugin-auth' },
54-
automation: { route: '/api/v1/automation', plugin: 'plugin-automation', capability: 'workflow' },
55-
cache: { route: '/api/v1/cache', plugin: 'plugin-redis' },
56-
queue: { route: '/api/v1/queue', plugin: 'plugin-bullmq' },
57-
job: { route: '/api/v1/jobs', plugin: 'job-scheduler' },
58-
ui: { route: '/api/v1/ui', plugin: 'ui-plugin' },
59-
workflow: { route: '/api/v1/workflow', plugin: 'plugin-workflow', capability: 'workflow' },
60-
realtime: { route: '/api/v1/realtime', plugin: 'plugin-realtime', capability: 'websockets' },
61-
notification: { route: '/api/v1/notifications', plugin: 'plugin-notifications', capability: 'notifications' },
62-
ai: { route: '/api/v1/ai', plugin: 'plugin-ai', capability: 'ai' },
63-
i18n: { route: '/api/v1/i18n', plugin: 'plugin-i18n', capability: 'i18n' },
64-
graphql: { route: '/graphql', plugin: 'plugin-graphql', capability: 'graphql' },
65-
'file-storage': { route: '/api/v1/storage', plugin: 'plugin-storage', capability: 'files' },
66-
search: { route: '/api/v1/search', plugin: 'plugin-search', capability: 'search' },
67-
};
68-
6972
// Check which services are actually registered
70-
for (const [serviceName, config] of Object.entries(serviceConfig)) {
73+
for (const [serviceName, config] of Object.entries(SERVICE_CONFIG)) {
7174
if (registeredServices.has(serviceName)) {
7275
// Service is registered and available
7376
services[serviceName] = {
@@ -107,7 +110,7 @@ export class ObjectStackProtocolImplementation implements ObjectStackProtocol {
107110
};
108111

109112
// Add routes for available plugin services
110-
for (const [serviceName, config] of Object.entries(serviceConfig)) {
113+
for (const [serviceName, config] of Object.entries(SERVICE_CONFIG)) {
111114
if (registeredServices.has(serviceName)) {
112115
// Map service name to endpoint key (some services use different names)
113116
const endpointKey = serviceName === 'file-storage' ? 'storage' : serviceName;

0 commit comments

Comments
 (0)