|
1 | 1 | import { ObjectKernel } from '@objectstack/core'; |
| 2 | +import { CoreServiceName } from '@objectstack/spec/src/system/service-registry.zod'; |
2 | 3 |
|
3 | 4 | export interface HttpProtocolContext { |
4 | 5 | request: any; |
@@ -49,12 +50,12 @@ export class HttpDispatcher { |
49 | 50 | getDiscoveryInfo(prefix: string) { |
50 | 51 | const services = this.getServicesMap(); |
51 | 52 |
|
52 | | - const hasGraphQL = !!(services['graphql'] || this.kernel.graphql); |
53 | | - const hasSearch = !!services['search']; |
54 | | - const hasWebSockets = !!services['realtime']; |
55 | | - const hasFiles = !!(services['file-storage'] || services['storage']?.supportsFiles); |
56 | | - const hasAnalytics = !!services['analytics']; |
57 | | - const hasHub = !!services['hub']; |
| 53 | + const hasGraphQL = !!(services[CoreServiceName.enum.graphql] || this.kernel.graphql); |
| 54 | + const hasSearch = !!services[CoreServiceName.enum.search]; |
| 55 | + const hasWebSockets = !!services[CoreServiceName.enum.realtime]; |
| 56 | + const hasFiles = !!(services[CoreServiceName.enum['file-storage']] || services['storage']?.supportsFiles); |
| 57 | + const hasAnalytics = !!services[CoreServiceName.enum.analytics]; |
| 58 | + const hasHub = !!services[CoreServiceName.enum.hub]; |
58 | 59 |
|
59 | 60 | return { |
60 | 61 | name: 'ObjectOS', |
@@ -108,7 +109,7 @@ export class HttpDispatcher { |
108 | 109 | */ |
109 | 110 | async handleAuth(path: string, method: string, body: any, context: HttpProtocolContext): Promise<HttpDispatcherResult> { |
110 | 111 | // 1. Try generic Auth Service |
111 | | - const authService = this.getService('auth'); |
| 112 | + const authService = this.getService(CoreServiceName.enum.auth); |
112 | 113 | if (authService && typeof authService.handler === 'function') { |
113 | 114 | const response = await authService.handler(context.request, context.response); |
114 | 115 | return { handled: true, result: response }; |
@@ -267,7 +268,7 @@ export class HttpDispatcher { |
267 | 268 | * path: sub-path after /analytics/ |
268 | 269 | */ |
269 | 270 | async handleAnalytics(path: string, method: string, body: any, context: HttpProtocolContext): Promise<HttpDispatcherResult> { |
270 | | - const analyticsService = this.getService('analytics'); |
| 271 | + const analyticsService = this.getService(CoreServiceName.enum.analytics); |
271 | 272 | if (!analyticsService) return { handled: false }; // 404 handled by caller if unhandled |
272 | 273 |
|
273 | 274 | const m = method.toUpperCase(); |
@@ -300,7 +301,7 @@ export class HttpDispatcher { |
300 | 301 | * path: sub-path after /hub/ |
301 | 302 | */ |
302 | 303 | async handleHub(path: string, method: string, body: any, query: any, context: HttpProtocolContext): Promise<HttpDispatcherResult> { |
303 | | - const hubService = this.getService('hub'); |
| 304 | + const hubService = this.getService(CoreServiceName.enum.hub); |
304 | 305 | if (!hubService) return { handled: false }; |
305 | 306 |
|
306 | 307 | const m = method.toUpperCase(); |
@@ -375,7 +376,7 @@ export class HttpDispatcher { |
375 | 376 | * path: sub-path after /storage/ |
376 | 377 | */ |
377 | 378 | async handleStorage(path: string, method: string, file: any, context: HttpProtocolContext): Promise<HttpDispatcherResult> { |
378 | | - const storageService = this.getService('file-storage') || this.kernel.services?.['file-storage']; |
| 379 | + const storageService = this.getService(CoreServiceName.enum['file-storage']) || this.kernel.services?.['file-storage']; |
379 | 380 | if (!storageService) { |
380 | 381 | return { handled: true, response: this.error('File storage not configured', 501) }; |
381 | 382 | } |
@@ -431,7 +432,7 @@ export class HttpDispatcher { |
431 | 432 | return this.kernel.services || {}; |
432 | 433 | } |
433 | 434 |
|
434 | | - private getService(name: string) { |
| 435 | + private getService(name: CoreServiceName) { |
435 | 436 | if (typeof this.kernel.getService === 'function') { |
436 | 437 | return this.kernel.getService(name); |
437 | 438 | } |
|
0 commit comments